PayPal经典API SetExpressCheckout重定向给出"交易无效"

时间:2014-08-09 22:37:57

标签: perl paypal express-checkout

正如stackoverflow上所建议的那样,我确保登录https://developer.paypal.com,在尝试我的SetExpressCheckout流之前为沙箱开发设置cookie。

我的SetExpressCheckout电话响应成功,回复如下:

  

TOKEN = EC%2d2D3179619P0352202&安培; TIMESTAMP = 2014%2d08%2d08T01%3a58%3a29Z&安培;的correlationID = ca8756c977f0&安培; ACK =成功&安培; 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." )

奇怪的是,如果我手动输入本来就是&#39; action =&#39;使用method = GET的表单的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会话缓存存在一些问题,因为我的表单网址转换为parms&#34; _cmd = flow&amp; SESSION = {long session ID},但我清楚( Safari)登录developer.paypal.com之前的浏览器cookie。

我使用Firefox和IE浏览器在不同的计算机上获得类似的行为。

1 个答案:

答案 0 :(得分:2)

PayPal无法接受您的令牌,因为您将其作为百分比编码两次发回。

SetExpressCheckout响应是一个包含一系列参数名称和值的字符串。此字符串为percent-encoded,表示您需要对其进行解码以提取实际值。

最重要的是,您对TOKEN=EC%2d2D3179619P0352202部分感兴趣,其中%2d代表字符-

当您将问题字符串中的字符串直接重新插入表单输入时,%2d只代表字符序列% 2 d。此外,当作为GET请求发送到PayPal时,序列将自行进行百分比编码,百分号符号编码为%25,从而产生序列% 2 {{1}您观察到的5 2。因此令牌在翻译中丢失了。

您需要输入的是令牌的解码版本:

d

在Perl中,可以使用例如CPAN的URI::Escape模块来实现解码。