paypal:在上下文快速结账后留在页面上

时间:2015-08-21 07:04:02

标签: javascript paypal express-checkout

用户通过In-context Express Checkout付款后,PayPal会重新加载页面并将用户重定向到后端“returnUrl”参数指定的页面。

然而,这将删除当前页面。

有没有办法避免在成功结帐后重新加载页面?

1 个答案:

答案 0 :(得分:3)

Include an iframe into your page and use that iframe to start the process. Since the iframe is the one initiating the PayPal in-context window, it's the iframe that will be redirected to your returnURL. Thus, your original page stays in the exact state it was before the call, variable and all.

Here's an example...

I've got checkout.html with an invisible iframe named paypaliframe. There is no UI in the paypaliframe, it only contains js functions related to PayPal.

In the checkout.html page, I click on my checkout button while PayPal is selected as the payment option. The "onclick" event tells the iframe to setup the transaction:

paypaliframe.contentWindow.setupAutorization()

The iframe executes the setupAutorization() function, gets the transaction token from Paypal then starts the in-context checkout process:

paypal.checkout.initXO();
paypal.checkout.startFlow(paypal.checkout.urlPrefix + token)

The in-context checkout window is now displayed and we see the new window redirect to the PayPal site. The customer enter his login, agree to your transaction then Paypal redirects the iframe to your returnUrl.

After the returnURL page is loaded in the iframe, you simply tell the parent page to follow thru with the next steps:

$(window).load(function() {
    parent.continueAfterPaypal();
});

TLDR; Use an iframe to start the in-context checkout and then use the iframe returnURL page to tell the parent to continue where things left off.