Как запустить сценарий на стороне клиента после завершения PayPal API V2 onApproval - PullRequest
0 голосов
/ 23 марта 2019

Это мой текущий скрипт PayPal

<script language="javascript" type="text/javascript">
 function populatePayPalButtons() {
  paypal.Buttons({
   createOrder: function(data, actions) {
    return actions.order.create({
     purchase_units: [{
      description: 'Center Court Hire', 
      amount: { value: '30.00' }
     }]
    });
   },
   // --------- onApprove ---
   onApprove: function(data, actions) {
    // Capture the funds from the transaction
    return actions.order.capture().then(function(details) {
    // Call your server to save the transaction
    var url = 'http://localhost:50678/testPP.aspx';
    return fetch(url, {
       method: 'post',
       body: 'OrderData=30.00|Center Court|4698.01|4563' +'|' + data.orderID,
       headers: { 'Content-type': 'application/x-www-form-urlencoded' }
    });
   });
   },
   // --------- onCancel ---
   onCancel: function(data, actions) {
    // Show a cancel page, or return to cart
   },
   // --------- onError ---
   onError: function(err) {
    // Show an error page
    alert('An error has occurred');
   }
  }).render('#paypal-button-container');
 }
</script>

Кнопка отображается в ASPxPopupControl. У меня есть скрипт, который закроет этот ASPxPopupControl, и мне нужен способ выполнить этот скрипт как последний вызов в функции onApprove выше.

Если это невозможно, есть ли событие, которое я могу использовать / вызвать, чтобы закрыть ASPxPopupControl без нажатия пользователем кнопки.

Похоже, в ASPxPopupControl просто невозможно определить, что PayPal завершил обработку.

1 Ответ

0 голосов
/ 24 марта 2019

Это работает:

<script language="javascript" type="text/javascript">
 function populatePayPalButtons() {
  paypal.Buttons({
   createOrder: function(data, actions) {
    return actions.order.create({
     purchase_units: [{
      description: 'Court 4 Hire', 
      amount: { value: '50.00' }
     }]
    });
   },
   // --------- onApprove ---
   onApprove: function(data, actions) {
    var url = 'http://localhost:50678/testPP.aspx';
    // Capture the funds from the transaction
    return actions.order.capture().then(function(details) {
    // Call your server to save the transaction
    CloseAndReturnToParentPage();
    return fetch(url, {
       method: 'post',
       headers: { 'Content-type': 'application/x-www-form-urlencoded' },
       body: 'OrderData=50.00|Court 4|4731.01|4563' +'|' + data.orderID,
    });
   });
   },
   // --------- onCancel ---
   onCancel: function(data, actions) {
    // Show a cancel page, or return to cart
   },
   // --------- onError ---
   onError: function(err) {
    // Show an error page
    alert('PayPal: An error has occurred! ');
   }
  }).render('#paypal-button-container');
 }
</script>

На вызываемой странице:

		function CloseAndReturnToParentPage() {
			var parentWindow = window.parent;
			parentWindow.SelectAndClosePopup('Finished');
		}

На странице вызова:

	function SelectAndClosePopup(value) {
		if (value == "Finished")
			popupControlGetPayment.Hide();
		else { }

		cbPanel.PerformCallback('PayPalCompleted|Paid')
	}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...