Question

I'm trying to get the Adaptive payment stuff working (for paying multiple users at once). I'm trying the following SOAP request:

    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>|);

That gives me a ton of errors:

     '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'
        }
      ],

I'm a bit baffled as to why its saying all those values are undef, even though I'm clearly passing them in? Its detecting the different params I'm passing in, but it just doesn't seem to like getting the values from them

Can anyone suggest what I'm doing wrong?

UPDATE 2:

I'm still having problems getting the SetPaymentOptions feature to work fully for me.

Here is an example of the JSON request I'm making, to update the units/shipping etc:

 {
    "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"
}

Then when you re-grab the transaction using PaymentDetails, it doesn't have any of the new shipping/tax/unit changes in it:

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

The REALLY annoying part, is that if I change the shipping / total / tax values, to make it so the number doesn't match up to the original "Pay" request... then I get an error:

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

So it MUST be picking the values up - but it just refuses to show them in a PaymentDetails request with the same payID

Please help - as I'm at my witts end now with this!

Was it helpful?

Solution 3

Ok, so in the end I found out I can use JSON (for some reason the SOAP request just didn't wanna work for me - it kept moaning that I needed to use SOAP11 or SOAP12, which is was!)

Here is what I got working with PayPal Parallel Payments, using the JSON method:

    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|;

The only thing I can't work out, is how to have to provide different shipping prices for each person. Using the normal HTML forms you can just do:

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

However, trying to pass in "shipping" as a value, within the "receiver" section, doesn't seem to work. Not sure if anyones got any suggestions on that?

UPDATE:

Mmm actually, maybe its not working. According to this page: https://developer.paypal.com/docs/classic/api/adaptive-payments/SetPaymentOptions_API_Operation/ , the format should be like: &receiverOptions[0].receiver.email=test@test.com&receiverOptions[0].invoiceData.item[0].name=ITEM1&receiverOptions[0].invoiceData.item[0].price=50.0&receiverOptions[0].invoiceData.item[0].itemCount=2&receiverOptions[0].invoiceData.item[0].itemPrice=25.0&receiverOptions[0].invoiceData.totalTax=25.0&receiverOptions[0].invoiceData.totalShipping=25.0

My JSON being passed along comes up as:

{"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"}

The response comes back as:

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

...so its not fataling... but when I goto the payment page, I don't see any shipping, quantity (or anything else I add here). I'm a bit baffled as to why this is the case?

The more pretty version of that JSON (in a perl variable, before converting to JSON), which is easier to read:

    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,
              }]
            }
        }
    ]

Any suggestions?

OTHER TIPS

I think you need to add the namespace attribute to the XML params. Take a look at this sample request that works just fine.

<?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>

Call the Pay API with the action set to CREATE and then pass the paykey you get back from that into SetPaymentOptions. That lets you set additional parameters like items, shipping info, etc. for each receiver on the transaction.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top