代码之家  ›  专栏  ›  技术社区  ›  mvasco

支付后显示paypal交易详细信息

  •  0
  • mvasco  · 技术社区  · 6 年前

    在我的网站中使用Paypal成功付款后,浏览器只显示一个警报:

    // Execute the payment
      onAuthorize: function (data, actions) {
        return actions.payment.execute()
          .then(function () {
            // Show a confirmation message to the buyer
    
            window.alert('Compra realizada con éxito. Recibirá más detalles por email!');
    
          });
      }
    

    我现在正在使用sandbox选项,但我知道如何向用户提供有关事务的更多详细信息。

    我看到函数中有一个'data'参数,有事务细节吗?如果是,我如何读取它们以在以后向用户显示它们?

    2 回复  |  直到 6 年前
        1
  •  1
  •   Jeremy Thille    6 年前

    操作的结果将传递给回调函数,并可通过以下方式访问:

    .then( function(result) {
            console.log(result); // Logs all the stuff that gets back from Paypal
    });
    

    根据 the doc :

    // Execute the payment:
        // 1. Add an onAuthorize callback
        onAuthorize: function(data, actions) {
          // 2. Make a request to your server
          return actions.request.post('/my-api/execute-payment/', {
            paymentID: data.paymentID,
            payerID:   data.payerID
          })
            .then(function(res) {
              // 3. Show the buyer a confirmation message.
            });
        }
    
        2
  •  0
  •   Mohammad Raheem    6 年前

    成功的响应返回对事务的确认,带有已批准的状态和事务Id,或者您可以看到 here

        // Wait for the payment to be authorized by the customer
    
     onAuthorize: function(data, actions) {
    
        // Get the payment details
    
        return actions.payment.get().then(function(data) {
    
            // Display the payment details and a confirmation button
    
            var shipping = data.payer.payer_info.shipping_address;
    
               // Execute the payment
    
                return actions.payment.execute().then(function() {
    
                    // Show a thank-you note
       window.alert('Compra realizada con éxito. Recibirá más detalles por email!');
                });
            });
        });
    }