Question

Man, I'm tearing my hair out over this one. Paypal's documentation is so complicated and incomplete, and there is little native ruby support for Adaptive Payments.

Anyway, I'm building a web app from which I want to be able to set up preapproved payments using PayPal Adaptive Payments. I've gotten the active_paypal_adaptive_payment gem to work, but there's no documentation on the process for going from preapproval to capturing payments.

I can use the preapprove_payment method of the gem to get a preapproval key from PayPal:

response = ADAPTIVE_GATEWAY.preapprove_payment ({
  :return_url => admin_preapproved_payments_url,
  :cancel_url => admin_preapproved_payments_url,
  :senderEmail => @payment.sender_email,
  :start_date => @payment.start_date,
  :end_date => @payment.end_date,
  :currency_code =>"USD",
  :max_amount => @payment.max_amount.to_s,
  :maxNumberOfPayments => @payment.max_number_of_payments.to_s
  })
  puts response.preapproval_key

But the sender needs to authorize the preapproval key before I can use it to capture funds from their account.

enter image description here

Where do I redirect the sender so they can authorize the preapproval key? I don't want to capture funds immediately – I just need their approval so I can do so in the future.

Was it helpful?

Solution

I would suggest to try out ActiveMerchant with paypal

OTHER TIPS

The method redirect_pre_approval_url_for(token) is what you need, it returns a URL to which you should (well, obviously) redirect the user in order to authorize the preapproved payment.

redirect_pre_approval_url_for(token)

So, in a rails application things should look like this:

redirect_to ADAPTIVE_GATEWAY.redirect_pre_approval_url_for(response.preapproval_key)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top