【问题标题】:How to format a SOAP request?如何格式化 SOAP 请求?
【发布时间】:2014-05-11 07:46:11
【问题描述】:

我正在尝试让自适应支付功能正常工作(一次支付多个用户)。我正在尝试以下 SOAP 请求:

    my $content = sprintf( $format, qq|<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
             <soapenv:Body>
       <actionType>PayRequest</actionType>
       <PayRequest>
         <requestEnvelope>
          <errorLanguage>en_US</errorLanguage>
           <currencyCode>USD</currencyCode>
           <receiverList>
              <receiver>
                <amount>5</amount>
                <email>test email here -but wont let me post it!</email>
              </receiver>
           </receiverList>
          <returnUrl>silly forum wont let me post a test link here???</returnUrl>
          <cancelUrl>silly forum wont let me post a test link here???</cancelUrl>
         </requestEnvelope>
         <payKey>AP-xxxxxxxxxxxxx</payKey>',
       </PayRequest>
     </soapenv:Body>
     </soapenv:Envelope>|);

这给了我很多错误:

     'error' => [
        {
          'parameter' => [
                         'requestEnvelope',
                         'null'
                       ],
          'domain' => 'PLATFORM',
          'category' => 'Application',
          'subdomain' => 'Application',
          'errorId' => '580022',
          'severity' => 'Error',
          'message' => 'Invalid request parameter: requestEnvelope cannot be null'
        },
        {
          'parameter' => [
                         'actionType',
                         'null'
                       ],
          'domain' => 'PLATFORM',
          'category' => 'Application',
          'subdomain' => 'Application',
          'errorId' => '580022',
          'severity' => 'Error',
          'message' => 'Invalid request parameter: actionType cannot be null'
        },
        {
          'parameter' => [
                         'cancelUrl',
                         'null'
                       ],
          'domain' => 'PLATFORM',
          'category' => 'Application',
          'subdomain' => 'Application',
          'errorId' => '580022',
          'severity' => 'Error',
          'message' => 'Invalid request parameter: cancelUrl cannot be null'
        },
        {
          'parameter' => [
                         'currencyCode',
                         'null'
                       ],
          'domain' => 'PLATFORM',
          'category' => 'Application',
          'subdomain' => 'Application',
          'errorId' => '580022',
          'severity' => 'Error',
          'message' => 'Invalid request parameter: currencyCode cannot be null'
        },
        {
          'parameter' => [
                         'receiverList',
                         'null'
                       ],
          'domain' => 'PLATFORM',
          'category' => 'Application',
          'subdomain' => 'Application',
          'errorId' => '580022',
          'severity' => 'Error',
          'message' => 'Invalid request parameter: receiverList cannot be null'
        },
        {
          'parameter' => [
                         'returnUrl',
                         'null'
                       ],
          'domain' => 'PLATFORM',
          'category' => 'Application',
          'subdomain' => 'Application',
          'errorId' => '580022',
          'severity' => 'Error',
          'message' => 'Invalid request parameter: returnUrl cannot be null'
        }
      ],

我有点困惑为什么它说所有这些值都是 undef,即使我清楚地传递了它们?它检测我传入的不同参数,但它似乎不喜欢从它们那里获取值

谁能建议我做错了什么?

更新 2:

我仍然无法让SetPaymentOptions 功能完全为我工作。

这是我正在发出的 JSON 请求示例,用于更新单位/运输等:

 {
    "receiverOptions": [
                        {
                            "receiver":{
                                "email":"andyxxx@gmail.com"
                            },
                            "invoiceData":{
                                "totalShipping":10,
                                "totalTax":5,
                                "item":[
                                        {
                                            "itemPrice":25,
                                            "name":"ITEM1",
                                            "price":50,
                                            "itemCount":2
                                        }
                                       ]
                            },
                            "SenderOptions":{
                                "requireShippingAddressSelection":1,
                                "addressOverride":1
                            },
                            "customId":"foo123"
                        }
                       ],
    "requestEnvelope":{
                        "errorLanguage":"en_US",
                        "detailLevel":"ReturnAll"
                      },
    "payKey":"AP-8AK803068V089131W"
}

然后,当您使用 PaymentDetails 重新获取交易时,其中没有任何新的运费/税/单位更改:

'paymentInfoList' => {
                       'paymentInfo' => [
                                          {
                                            'pendingRefund' => 'false',
                                            'receiver' => {
                                                            'accountId' => 'AH92SPWMDXTHJ',
                                                            'email' => 'andyxxx@gmail.com',
                                                            'amount' => '65.00',
                                                            'primary' => 'false',
                                                            'paymentType' => 'GOODS'
                                                          }
                                          }
                                        ]
                     },

真正烦人的部分是,如果我更改运费/总计/税金值,以使数字与原始“付款”请求不匹配...然后我收到一个错误:

ERROR: The total invoiced amount for andyxxx@gmail.com does not match the amount in the pay request at test.cgi line 127.

所以它必须选择这些值 - 但它只是拒绝在 PaymentDetails 请求中显示它们,并使用相同的 payID

请帮忙 - 因为我现在对此束手无策!

【问题讨论】:

    标签: api soap paypal paypal-adaptive-payments


    【解决方案1】:

    我认为您需要将命名空间属性添加到 XML 参数中。看看这个运行良好的示例请求。

    <?xml version="1.0" encoding="utf-8"?>
    <PayRequest xmlns="http://svcs.paypal.com/types/ap">
      <requestEnvelope xmlns="">
        <detailLevel>ReturnAll</detailLevel>
        <errorLanguage>en_US</errorLanguage>
      </requestEnvelope>
      <actionType xmlns="">PAY</actionType>
      <cancelUrl xmlns="">http://paypal.angelleye.com/paypal/class/1.2/Pay_Cancel.php</cancelUrl>
      <clientDetails xmlns="">
        <applicationId xmlns="">APP-80W284485P519543T</applicationId>
        <ipAddress xmlns="">37.187.79.225</ipAddress>
        <partnerName xmlns="">Always Give Back</partnerName>
      </clientDetails>
      <currencyCode xmlns="">USD</currencyCode>
      <receiverList xmlns="">
        <receiver xmlns="">
          <amount xmlns="">10.00</amount>
          <email xmlns="">sandbo_1204199080_biz@angelleye.com</email>
        </receiver>
        <receiver xmlns="">
          <amount xmlns="">5.00</amount>
          <email xmlns="">usb_1329725429_biz@angelleye.com</email>
          <invoiceId xmlns="">123-ABCDEF</invoiceId>
        </receiver>
      </receiverList>
      <sender>
        <useCredentials xmlns=""></useCredentials>
      </sender>
      <account xmlns="">
        <phone xmlns=""></phone>
      </account>
      <returnUrl xmlns="">http://paypal.angelleye.com/paypal/class/1.2/Pay_Return.php</returnUrl>
    </PayRequest>
    

    【讨论】:

    • 感谢您的指点。我仍然无法让 SOAP 工作,所以我最终使用了我在上面发布的 JSON 代码。不确定您是否知道如何按人传递运费?我假设这是可能的 - 但同样,我找不到任何关于它的文档:/
    【解决方案2】:

    使用设置为 CREATE 的操作调用支付 API,然后将您从中获取的支付密钥传递给 SetPaymentOptions。这使您可以为交易中的每个接收者设置额外的参数,例如物品、运输信息等。

    【讨论】:

    • 谢谢 - 出于某种原因,它不想为我工作。在我的recieveList 中,我有:amount =&gt; 50, email =&gt; 'andy.newby@gmail.com',然后是SetPaymentOptions,我传入了:invoiceData =&gt; { name=&gt; "ITEM1", price =&gt; 50, itemCount =&gt; 2, itemPrice =&gt; 25, totalTax =&gt; 0 },但由于某种原因,我得到了一个错误:The total invoiced amount for andy.newby@gmail.com does not match the amount in the pay request ... 当然,第二个请求中的价格只需要来计算我在第一个 Pay 请求中得到的信息?
    • 啊,我明白了 :) 它需要是一个子数组,而不是我如何拥有它。所以格式需要是:invoiceData =&gt; { item =&gt; { name =&gt; "ITEM1", price =&gt; 50, itemCount =&gt; 2, itemPrice =&gt; 25, totalTax =&gt; 0 } } ...有点复杂,但现在似乎可以工作了。感谢您的帮助!
    • 嗯实际上,那不是这样做的(我的价值观似乎都没有得到保存)。请查看我上次回复中“更新”后的更新(我添加了更多示例代码,并解释了更多发生的情况)
    • 抱歉出现错误。但只是想知道您是否看到了上述问题? stackoverflow.com/a/22784356/2006878更新更新2)。在我能做到之前,我处于一个死胡同:(
    • 有什么想法吗?我真的在这里画了一个空白。我确实有一个灵光乍现的时刻,我想可能是因为我没有将项目设置为paymentType =&gt; "GOODS" - 但这似乎仍然没有什么区别:/请参阅我上面的帖子以获取更多信息我尝试过的更改。
    【解决方案3】:

    好的,所以最后我发现我可以使用 JSON(出于某种原因,SOAP 请求只是不想为我工作 - 它一直在抱怨我需要使用 SOAP11 或 SOAP12,原来是这样!)

    这是我使用 JSON 方法使用 PayPal Parallel Payments 得到的结果:

        use HTTP::Request::Common;
        use LWP::UserAgent;my $user           = 'foobar.user';
        my $password       = '1396280437';
        my $signature      = 'the secret sig';
        my $application_id = 'APP-80W284485P519543T';
    
        my $url            = 'https://svcs.sandbox.paypal.com/AdaptivePayments/Pay';
    
        my $ua      = LWP::UserAgent->new();
        my $headers = HTTP::Headers->new(
                'X-PAYPAL-SECURITY-USERID'    => $user,
                'X-PAYPAL-SECURITY-PASSWORD'  => $password,
                'X-PAYPAL-SECURITY-SIGNATURE' => $signature,
                'X-PAYPAL-APPLICATION-ID'     => $application_id,
                'X-PAYPAL-DEVICE-IPADDRESS'   => $ENV{REMOTE_ADDR},
                'X-PAYPAL-REQUEST-DATA-FORMAT'   => 'JSON',
                'X-PAYPAL-RESPONSE-DATA-FORMAT'   => 'JSON'
                );
    
          my $json_var = {
                requestEnvelope => { 
                  detailLevel => "ReturnAll",
                  errorLanguage =>  "en_US",
                },
                actionType => "PAY",
                currencyCode => "USD",
                receiverList => {
                   receiver => [
                     {
                        amount => 5,
                        email  => 'testing@gmail.com'
                     },
                     {
                        amount => 15,
                        email  => 'foobar@gmail.com'
                     }
                   ],  
                },
                returnUrl => 'http://sitexx.com/return.cgi',
                cancelUrl => 'http://sitexx.com/cancel.html'
          };
    
          use JSON;
          my $new_json = JSON::to_json($json_var);
    
        my $request  = HTTP::Request->new( 'POST', $url, $headers, $new_json );
        my $response = $ua->request( $request );
    
        my $json_returned = decode_json($response->decoded_content);
    
        print qq|Location: https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_ap-payment&paykey=$json_returned->{payKey} \n\n|;
    

    我唯一无法解决的问题是如何为每个人提供不同的运费。使用普通的 HTML 表单,您可以这样做:

    <input type="hidden" name="shipping" value="9">
    

    但是,在“receiver”部分中尝试将“shipping”作为值传递,似乎不起作用。不确定是否有人对此有任何建议?

    更新:

    实际上,也许它不起作用。根据这个页面:https://developer.paypal.com/docs/classic/api/adaptive-payments/SetPaymentOptions_API_Operation/,格式应该是:&amp;receiverOptions[0].receiver.email=test@test.com&amp;receiverOptions[0].invoiceData.item[0].name=ITEM1&amp;receiverOptions[0].invoiceData.item[0].price=50.0&amp;receiverOptions[0].invoiceData.item[0].itemCount=2&amp;receiverOptions[0].invoiceData.item[0].itemPrice=25.0&amp;receiverOptions[0].invoiceData.totalTax=25.0&amp;receiverOptions[0].invoiceData.totalShipping=25.0

    我传递的 JSON 格式如下:

    {"receiverOptions":[{"receiver":{"email":"andyxxx@gmail.com"},"invoiceData":{"item":[{"name","ITEM1","price",50,"itemCount",2,"itemPrice",25,"totalTax",5,"totalShipping",10}]}},{"receiver":{"email":"foobar@gmail.com"},"invoiceData":{"item":[{"name","ITEM2","price",15,"itemCount",1,"itemPrice",15,"totalTax",0,"totalShipping",20}]}}],"requestEnvelope":{"errorLanguage":"en_US","detailLevel":"ReturnAll"},"payKey":"AP-2LN695598Y955615N"}

    响应返回为:

         'responseEnvelope' => {
                                  'correlationId' => '0ba8c3bf33425',
                                  'timestamp' => '2014-04-01T07:10:07.752-07:00',
                                  'ack' => 'Success',
                                  'build' => '10273932'
                                }
    

    ...所以它不是致命的...但是当我进入付款页面时,我没有看到任何运费、数量(或我在此处添加的任何其他内容)。我有点困惑为什么会这样?

    更漂亮的 JSON 版本(在 perl 变量中,在转换为 JSON 之前),更易于阅读:

        receiverOptions => [
            {
                 receiver => {
                    email => 'andyxxx@gmail.com'
                 }, 
                 invoiceData => {
                  item => [{
                    name      => "ITEM1",
                    price     => 50,
                    itemCount => 2,
                    itemPrice => 25,
                    totalTax  => 5,
                    totalShipping => 10,
                  }]
                }
    
            },{
                 receiver => {
                    email => 'foobar@gmail.com'
                 }, 
                 invoiceData => {
                  item => [{
                    name      => "ITEM2",
                    price     => 15,
                    itemCount => 1,
                    itemPrice => 15,
                    totalTax  => 0,
                    totalShipping => 20,
                  }]
                }
            }
        ]
    

    有什么建议吗?

    【讨论】:

      猜你喜欢
      • 2015-11-15
      • 1970-01-01
      • 1970-01-01
      • 2022-06-17
      • 1970-01-01
      • 2017-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多