PayPal 与基于 iframe 的购物车集成

发布于 2024-12-02 12:31:19 字数 390 浏览 0 评论 0原文

我们使用 PayPal 的 Payments Pro NVP API 在我们的网站上提供无缝的信用卡和 Paypal 处理。我们创建了一个基于 iframe 的购物车小部件,我们的客户将其放置在他们的网站上,以便他们的用户可以购买商品并通过我们的 Paypal 帐户付款。

虽然信用卡交易工作正常,但当用户尝试使用 PayPal 帐户付款时,我们会遇到问题。单击 PayPal 徽标时,API 会使用重定向,但 PayPal 的代码似乎会运行框架破坏脚本,导致交易无法继续。

我正在寻求有关如何处理希望通过 iframe 使用 PayPal 付款的用户的建议或示例代码。一种选择是弹出一个新窗口,但这会使设计面临问题,因为用户可以在该窗口和包含 iframe 的窗口之间切换,并且可能会使购物车与 PayPal 窗口显示的内容不同步。

We use PayPal's Payments Pro NVP API to provide seamless credit card and paypal processing on our site. We've created an iframe-based cart widget that our customers put onto their site so their users can purchase items and pay via our Paypal account.

While credit card transactions work fine, we're seeing issues when a user tries to pay with their the PayPal account. The API uses a redirect when clicking the PayPal logo but then PayPal's code seems to run a framebusting script and the transaction can't continue.

I am seeking suggestions or sample code for how to handle users wishing to PayPal for their payment via the iframe. One option is to pop-up a new window but then it leaves the design open to issues since the user can switch between that window and the window containing the iframe and conceivably get the cart out of sync with what the PayPal window is displaying.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

℉絮湮 2024-12-09 12:31:19

上述两个答案都是正确的。不过,PayPal 技术支持提供了一套更全面的说明,我在下面提供了这些说明。希望他们能帮助别人。

修改您的 SetExpressCheckout 调用,以便 RETURNURL 和 CANCELURL 参数指向一个特殊的返回页面,该页面将为您关闭弹出窗口并继续正常的结帐过程(稍后将详细介绍)。

接下来,修改将买家重定向到 PayPal 网站的脚本。通常,此脚本会向浏览器返回“302 Found”(或类似)响应,告诉浏览器应该重定向到其他页面。 (在 PHP 中,这通常是通过“header”函数来完成的 - 例如 header(“Location: https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=$相反,此脚本应发出以下 HTML/JavaScript 代码(将“TOKEN”替换为您从 PayPal 收到的令牌)。这将打开一个弹出窗口,买家可以在其中继续在 PayPal 上进行结帐流程。您可以根据需要插入其他文本,以向买家表明他们应该使用弹出窗口来完成结账。为了避免弹出窗口阻止程序出现问题,您可以在页面上创建一个链接或按钮,向买家指示他们应该单击该链接/按钮继续,并将此代码用于对象的“onClick”处理程序。

<脚本类型=“text/javascript”>
window.open("https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=TOKEN","_blank","宽度=1024,高度=768,位置=1,可调整大小=1,滚动条=1,状态=1”,true);

现在,创建一个执行以下代码的新页面(或类似的代码 - 该代码基于 PHP,根据您使用的任何语言进行必要的调整)。此代码将关闭弹出窗口并继续在现有 iframe 中进行结帐过程。 SetExpressCheckout 调用的 RETURNURL 参数应指向此页面。将“paypalreturn.php”替换为您当前用于处理从 PayPal 返回购物车的买家的脚本。

<html>
<body>
<script type="text/javascript">
window.opener.location="http://www.regattacentral.com/paypalreturn.php?token=<? echo $_REQUEST["token"]; ?>&PayerID=<? echo $_REQUEST["PayerID"]; ?>";
window.close();
</script>
</body>
</html>

最后,对您的 CANCELURL 处理程序重复此步骤。

• 购买在iframe 内完成,并显示购买的交易ID。

Both of the above answers are correct. However, PayPal tech support provided a more thorough set of instructions which I've provided below. Hopefully they'll help someone else.

Modify your SetExpressCheckout calls so that the RETURNURL and CANCELURL parameters point to a special return page that will handle closing the pop-up window for you and continuing the normal checkout process (more on this later).

Next, modify the script that redirects the buyer over to the PayPal website. Normally, this script would return a “302 Found” (or similar) response to the browser, telling the browser that it should follow a redirect to some other page. (In PHP, this is usually accomplished with the “header” function – e.g., header(“Location: https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=$token”); .) Instead, this script should emit the following HTML/JavaScript code (replacing “TOKEN” with the token you received from PayPal). This will open a pop-up window where the buyer can continue the checkout process on PayPal. You can insert additional text, as you like, to indicate to the buyer that they should be using the pop-up window to complete their checkout. To avoid issues with pop-up blockers, you can create a link or button on your page, indicating to the buyer that they should click the link/button to continue, and use this code for the object’s “onClick” handler.

<script type="text/javascript">
window.open("https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=TOKEN","_blank","width=1024,height=768,location=1,resizable=1,scrollbars=1,status=1",true);
</script>

Now, create a new page that executes the following code (or similar – this code is based on PHP, adjust as necessary for whatever language you are using). This code will close the pop-up window and continue the checkout process in your existing iframe. The RETURNURL parameter of your SetExpressCheckout call should point to this page. Replace “paypalreturn.php” with the script you currently use to handle buyers returning to your shopping cart from PayPal.

<html>
<body>
<script type="text/javascript">
window.opener.location="http://www.regattacentral.com/paypalreturn.php?token=<? echo $_REQUEST["token"]; ?>&PayerID=<? echo $_REQUEST["PayerID"]; ?>";
window.close();
</script>
</body>
</html>

Lastly, repeat this step for your CANCELURL handler.

• The purchase completes inside of the iframe, and the transaction ID for the purchase is shown.

随波逐流 2024-12-09 12:31:19

出于安全原因,Pro Hosted 中的 PayPal Express Checkout/“使用 PayPal 付款”不支持 iframe。打开弹出窗口(或设置 target=_parent)是正确处理此问题的唯一方法。

PayPal Express Checkout / 'Pay with PayPal' in Pro Hosted does not support iframes for security reasons. Opening a pop up window (or setting target=_parent) is the only way to process this properly.

鹿童谣 2024-12-09 12:31:19

将表单目标设置为 - target="_top"

Set your form target to - target="_top"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文