Search code examples
perlpaypalpaypal-adaptive-payments

PayPal Adaptive Payment SetPaymentOptions - does it work?


I've been trying (fruitlessly!) to get PayPals SetPaymentOptions API feature to work, as per: https://developer.paypal.com/docs/classic/api/adaptive-payments/SetPaymentOptions_API_Operation/

FWIW - I'm aware the below isn't truly JSON, but its the Perl object I'm creating - which gets converted into JSON before sending (its just easier to read like this, compared to having it all on one line =))

So far I create the initial payment using the "Pay" feature (https://svcs.sandbox.paypal.com/AdaptivePayments/Pay):

{
      requestEnvelope => { 
        detailLevel => "ReturnAll",
        errorLanguage =>  "en_US",
      },
      actionType => "PAY",
      currencyCode => "USD",
      receiverList => {
         receiver => [
           {
              amount => 65,
              email  => '[email protected]',
              paymentType => "GOODS",
              invoiceId => "test"
           },
            {
              amount => 15,
              email  => '[email protected]',
              paymentType => "GOODS",               
              invoiceId => "test 2"
           }
         ],  
      },
      returnUrl => 'http://xx.com/thanks.html',
      cancelUrl => 'http://xx.com/cancel.html',
}

This creates it fine, and I get returned back the payKey just fine. The problem starts when I try and add shipping/units prices/taxes etc via SetPaymentOptions. Here is an example request I'm making:

{
  payKey => $json_returned->{payKey},
  requestEnvelope => { 
          detailLevel => "ReturnAll",
          errorLanguage =>  "en_US",
  },  
  receiverOptions => [
      {
           customId => "foo123",
           receiver => {
              email => '[email protected]'
           }, 
           invoiceData => {
             item => [{
                            name      => "ITEM1",
                            price     => 50,
                            itemCount => 2,
                            itemPrice => 25,
                          }],
              totalTax  => 5,
              totalShipping => 10,
           },
          SenderOptions  => {
              addressOverride => 1,
              requireShippingAddressSelection => 1
          }
      }
  ]
}

I then grab back that transaction to see if it all got saved ok, by using a PaymentDetails request (https://svcs.sandbox.paypal.com/AdaptivePayments/PaymentDetails)

This always comes back with no shipping, tax, unit numbers, etc. I'm at a real loss as to whats going on - because if I were to change (for example) the number of units in this 2nd request, or the delivery price... it gives me an error that the numbers don't match up! So it has to be recognizing it - but just not doing anything with it

I'm really at my witts end here (I wish they'd hurry up and get the REST APIs finished up - as they look more promising than this... but for now, I've got to make do with what we have here with the Adaptive Payments)

UPDATE:

Is this what you mean with regards to running the ExecutePayment?

my $pass_in_params = {
  payKey => $json_returned->{payKey},
  requestEnvelope => { 
          detailLevel => "ReturnAll",
          errorLanguage =>  "en_US",
  },
  actionType => "CREATE"
};

WAHOO - Finally got it working! As per Andrews info, the reason I wasn't seeing the shipping/units/tax stuff with the ExecutePayment request, is because we hadn't sent them to the payment page yet (and you can't grab it until the payment is complete). With the Sandbox, you can login to a test account and see all the units etc perfectly.


Solution

  • When you use Pay with CREATE and then call SetPaymentOptions behind that, no payment occurs until you finish it up with ExecutePayment. As such, when you call PaymentDetails there are no details to obtain.

    Try calling ExecutePayment to finish things off and then see if PaymentDetails works better for you.