【问题标题】:Paypal checkout with redirection?带有重定向的Paypal结帐?
【发布时间】:2017-05-05 07:30:47
【问题描述】:

我正在尝试实施贝宝结帐。我发现这段代码对我来说几乎是完美的,但并不完全:

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;
        document.querySelector('#recipient').innerText = shipping.recipient_name;
        document.querySelector('#line1').innerText     = shipping.line1;
        document.querySelector('#city').innerText      = shipping.city;
        document.querySelector('#state').innerText     = shipping.state;
        document.querySelector('#zip').innerText       = shipping.postal_code;
        document.querySelector('#country').innerText   = shipping.country_code;
        document.querySelector('#paypal-button-container').style.display = 'none';
        document.querySelector('#confirm').style.display = 'block';
        // Listen for click on confirm button
        document.querySelector('#confirmButton').addEventListener('click', function() {
            // Disable the button and show a loading message
            document.querySelector('#confirm').innerText = 'Loading...';
            document.querySelector('#confirm').disabled = true;
            // Execute the payment
            return actions.payment.execute().then(function() {
                // Show a thank-you note
                document.querySelector('#thanksname').innerText = shipping.recipient_name;
                document.querySelector('#confirm').style.display = 'none';
                document.querySelector('#thanks').style.display = 'block';
            });
        });
    });
}

当付款被授权时,我想在另一个 php 页面上重定向用户。我仍然可以调用函数 actions.payment.get() 和 actions.payment.execute() 吗?如果是,我应该如何继续打电话给他们?如果不是,为什么?

【问题讨论】:

    标签: javascript php paypal paypal-sandbox


    【解决方案1】:

    您可以在创建付款时使用 redirect_urls 属性将 url 传递给创建请求付款来配置您的 php url

    {
      intent: "sale",
      ...
      redirect_urls :
      {
        return_url : "http://youreturnurl.com/finished",
        cancel_url : "http://youreturnurl.com/canceled"
      },
      ...
      transactions: [ {
         ...
      }]
      ...
    }
    

    您只需要在get() 之后的 then 方法中调用 actions.redirect()

    onAuthorize: function(data, actions) {
      return actions.payment.get().then(function(data) {
       //do extra actions
       ...
       return actions.redirect();
    }}
    

    您可以对onCancel() 执行相同的操作,或者只需使用actions.close() 关闭弹出窗口。

    【讨论】:

      猜你喜欢
      • 2018-08-30
      • 2020-11-24
      • 2014-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-06
      • 2020-04-11
      相关资源
      最近更新 更多