Search code examples
ruby-on-railsjsonpaypalpaypal-adaptive-payments

What's the JSON for PayPal Adaptive Payments Chained Payment


I've successfully implemented creating simple payments in Rails using the paypal-sdk-adaptivepayments gem. The JSON is as follows from the documentation:

  {
    :actionType => "PAY",
    :cancelUrl => "http://localhost:3000/samples/adaptive_payments/pay",
    :currencyCode => "USD",
    :feesPayer => "EACHRECEIVER",
    :ipnNotificationUrl => "http://localhost:3000/samples/adaptive_payments/ipn_notify",
    :receiverList => {
      :receiver => [{
        :amount => self.amount,
        :email => self.help_request.creator.master_profile.paypal_email }] },
    :returnUrl => "http://localhost:3000/samples/adaptive_payments/pay"
  }

I need, however, to set up a similar JSON string but with multiple receivers (one primary) for a chained payment. The PayPal docs show how to do this, but it's not in JSON which is what I need for the SDK:

&actionType=PAY
&cancelUrl=http:\\example.com\cancel.htm
&currencyCode=USD
&receiverList.receiver(0).amount=9.00
&receiverList.receiver(0)[email protected]
&receiverList.receiver(1).amount=5.00
&receiverList.receiver(1)[email protected]
&requestEnvelope.errorLanguage=en_US
&returnUrl=http:\\example.com\return.htm

Anybody know how to set this up? It's not immediately obvious


Solution

  • I found out the format, and it's not intuitive. The basic structure can be seen here where they show it this way:

    params = { 
            'requestEnvelope' : {'errorLanguage' : 'en_US', 'detailLevel' : 'ReturnAll'},
            'actionType' : 'PAY',
            'receiverList' : { 
                    'receiver' : [ 
                        {'email' : receiver1, 'amount' : amount1, 'primary' : True },
                        {'email' : receiver2, 'amount' : amount2, 'primary' : False},
                        {'email' : receiver3, 'amount' : amount2, 'primary' : False}
                    ],  
            },  
        'currencyCode' : 'USD',
        'memo' : 'Chained payment example.',
        'cancelUrl' : cancel_url,
        'returnUrl' : return_url,
    }
    

    Here's roughly what I used in my application:

      {
        :actionType => "PAY",
        :cancelUrl => "http://localhost:3000/samples/adaptive_payments/pay",
        :currencyCode => "USD",
        :feesPayer => "PRIMARYRECEIVER",
        :ipnNotificationUrl => "http://localhost:3000/samples/adaptive_payments/ipn_notify",
        :receiverList => {
          :receiver => [{
            :amount => self.amount,
            :email => self.help_request.creator.master_profile.paypal_email,
            :primary => 'true' },
            {
            :amount => self.fee_amount,
            :email => '[email protected]',
            :primary => 'false' }
            ]
          },
        :returnUrl => "http://localhost:3000/samples/adaptive_payments/pay"
      }