按照 stackoverflow 上的建议,我确保登录 https://developer.paypal.com , 在尝试我的 SetExpressCheckout 流程之前为沙盒开发设置 cookie。
我从我的 SetExpressCheckout 调用中得到成功响应,回复如下:
TOKEN=EC%2d2D3179619P0352202&TIMESTAMP=2014%2d08%2d08T01%3a58%3a29Z&CORRELATIONID=ca8756c977f0&ACK=Success&VERSION=116&BUILD=12301660
我在尝试使用 _express-checkout 命令重定向到 PayPal 时遇到问题:
我提取 TOKEN 值,并以 HTTP 形式传递它,GET 和 POST 变体如下所示。我使用的是 Perl,但表单只是纯 HTML,下面的表单直接取自查看由我的 Perl CGI 脚本生成的页面源代码。
form using GET:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="GET">
<input type="hidden" name="cmd" value="_express-checkout">
<input type="hidden" name="token" value="EC%2d1BH04005UH441943R">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_SM.gif" border="0" alt="PayPal - The safer, easier way to pay online!">
</form>
form URL: https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC%252d1BH04005UH441943R&x=61&y=11
lands on: https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_flow&SESSION=S4XbHMPLePuv_A93vhHvqIo4GEYOpsQCYkn6iiIE6AeRfMEkXHzSPWYeH3G&dispatch=50a222a57771920b6a3d7b606239e4d529b525e0b7e69bf0224adecfb0124e9b61f737ba21b08198a0586321b47f5ae7b54ee269d9200b8b
( PayPal page with "This transaction is invalid. Please return to the recipient's website to complete your transaction using their regular checkout flow." )
form using POST:
<form action=https://www.sandbox.paypal.com/cgi-bin/webscr METHOD='POST'>
<input type=hidden name='cmd' value='_express-checkout'>
<input type=hidden name='token' value=EC%2d9MK58577ER8913409>
<input type=image src=https://www.paypalobjects.com/en_US/i/btn/btn_buynow_SM.gif border=0 alt='PayPal - The safer, easier way to pay online!'>
</form>
form URL: https://www.sandbox.paypal.com/cgi-bin/webscr
lands on: https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_flow&SESSION=MQjOoKQ1FNeHGrVOsukD0Ln8K8LvfvfrejsDm9XZq3JeLThBanMZ2vC1Wtm&dispatch=50a222a57771920b6a3d7b606239e4d529b525e0b7e69bf0224adecfb0124e9b61f737ba21b08198a0586321b47f5ae7b54ee269d9200b8b
( PayPal page with "This transaction is invalid. Please return to the recipient's website to complete your transaction using their regular checkout flow." )
奇怪的是,如果我使用 method=GET 手动输入本来应该是我表单的“action=”URL 的 URL,一切都有效:
Manual cut-n-paste of form URL: https://www.sandbox.paypal.com/cgi-bin/webscr&cmd=_express-checkout&token=EC%2d00D71751FM635411H (with or w/o appending &x=nn&y=nn)
lands on: https://www.sandbox.paypal.com/cgi-bin/webscr&cmd=_express-checkout&token=EC%2d00D71751FM635411H
( Sandbox test store, showing order summary and buyer PayPal account login prompts, as expected )
在我看来,PayPal 的 session 缓存存在一些问题,因为我的表单 URL 被转换为带有参数“_cmd=flow&SESSION={long session ID}”的 URL,但我在登录开发人员之前清除了 (Safari) 浏览器 cookie .paypal.com.
我在另一台使用 Firefox 和 IE 浏览器的计算机上遇到了类似的行为。
最佳答案
PayPal 不会接受您的 token ,因为您将其作为百分比编码两次发回。
SetExpressCheckout 响应是一个包含一系列参数名称和值的字符串。这个字符串是 percent-encoded ,这意味着您需要对其进行解码以提取实际值。
最重要的是,您对 TOKEN=EC%2d2D3179619P0352202
感兴趣部分,其中 %2d
代表字符 -
.
如问题所示,当您将字符串直接重新注入(inject)表单输入时,%2d
只代表字符序列 %
2
d
.此外,当作为 GET 请求发送到 PayPal 时,序列本身将进行百分号编码,百分号编码为 %25
。 , 导致序列 %
2
5
2
d
你观察到的。所以 token 在翻译中丢失了。
您需要输入的是token的解码版本:
<input type="hidden" name="token" value="EC-1BH04005UH441943R">
在 Perl 中,可以使用例如 CPAN 的 URI::Escape 来实现解码。模块。
关于perl - PayPal 经典 API SetExpressCheckout 重定向给出 "transaction is invalid",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25223780/