2014-03-31 76 views
0

我試圖讓自適應付款的東西工作(一次支付多個用戶)。我想下面的SOAP請求:如何格式化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":"[email protected]" 
          }, 
          "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' => '[email protected]', 
                  'amount' => '65.00', 
                  'primary' => 'false', 
                  'paymentType' => 'GOODS' 
                  } 
              } 
             ] 
        }, 

真正惱人的一部分,如果我改變運輸/總/稅值,它使數不作馬TCH了原來的「支付」的請求......然後我得到一個錯誤:

ERROR: The total invoiced amount for [email protected] does not match the amount in the pay request at test.cgi line 127.

所以它必須是採摘值高達 - 但它只是拒絕向他們展示一個PaymentDetails請求具有相同payID

請幫助 - 因爲我在我的智慧結束現在這個!

回答

0

好,所以最後我發現我可以使用JSON(出於某種原因,SOAP請求只是沒有想爲我工作 - 它不停地呻吟,我需要使用SOAP11或SOAP12,這是是)

這是我得到了使用PayPal付款並行工作,使用JSON方法:

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 => '[email protected]' 
       }, 
       { 
        amount => 15, 
        email => '[email protected]' 
       } 
       ], 
      }, 
      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"> 

然而,試圖「出貨」來傳遞的值時,「接收器」部分中,似乎並沒有工作。不確定是否有人對此有任何建議?

UPDATE:

嗯實際上,也許它不能正常工作。根據這一頁:https://developer.paypal.com/docs/classic/api/adaptive-payments/SetPaymentOptions_API_Operation/,格式應該是這樣的:​​

沿通過我的JSON出現爲:

{"receiverOptions":[{"receiver":{"email":"[email protected]"},"invoiceData":{"item":[{"name","ITEM1","price",50,"itemCount",2,"itemPrice",25,"totalTax",5,"totalShipping",10}]}},{"receiver":{"email":"[email protected]"},"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 => '[email protected]' 
      }, 
      invoiceData => { 
       item => [{ 
       name  => "ITEM1", 
       price  => 50, 
       itemCount => 2, 
       itemPrice => 25, 
       totalTax => 5, 
       totalShipping => 10, 
       }] 
      } 

     },{ 
      receiver => { 
       email => '[email protected]' 
      }, 
      invoiceData => { 
       item => [{ 
       name  => "ITEM2", 
       price  => 15, 
       itemCount => 1, 
       itemPrice => 15, 
       totalTax => 0, 
       totalShipping => 20, 
       }] 
      } 
     } 
    ] 

有什麼建議?

1

我認爲您需要將namespace屬性添加到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="">[email protected]</email> 
    </receiver> 
    <receiver xmlns=""> 
     <amount xmlns="">5.00</amount> 
     <email xmlns="">[email protected]</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> 
+0

感謝您的指針。我仍然無法使用SOAP工作,所以我最終使用了上面發佈的JSON代碼。不知道您是否知道如何在每人的基礎上通過運輸?我假設這是可能的 - 但我再次找不到任何有關它的文檔:/ –

1

使用設置爲CREATE的操作調用Pay API,然後將您從中獲得的PayKey傳遞給SetPaymentOptions。這樣可以爲交易中的每個接收方設置其他參數,如項目,運輸信息等。

+0

謝謝 - 由於某種原因它不想爲我工作。在我的recieveList中,我有:'amount => 50,email =>'andy.newby @ gmail.com'',然後用'SetPaymentOptions'傳入: 'invoiceData => {name =>「ITEM1」, price => 50,itemCount => 2,itemPrice => 25,totalTax => 0}',但由於某種原因,我收到一個錯誤:'[email protected]的總開票金額與支付請求......當然,第二個請求中的價格只需要符合我在第一個「支付」請求中獲得的價格? –

+0

啊,我明白了:)它需要是一個子數組,而不是我如何擁有它。所以格式需要爲:'invoiceData => {item => {name =>「ITEM1」,price => 50,itemCount => 2,itemPrice => 25,totalTax => 0}} ...複雜,但現在似乎工作。謝謝你的幫助! –

+0

嗯實際上,這不是它(我的價值似乎沒有得到保存)。請在我上一次回覆中的「UPDATE」後面看到更新(我已經添加了更多示例代碼,並且解釋了更多內容) –