Question

I feel like a lot of the documentation on this is outdated, but this is what I have been trying so far:

I am using the ActiveMerchant::Billing::PaypalExpressGateway gateway.

First I setup the purchase and redirect the user to Paypal:

response = gateway.setup_purchase price,
  return_url: <confirm url>,
  cancel_return_url: <cancel url>,
  items: [
    {
      name: 'My Item',
      quantity: 1,
      description: "My Item Description",
      amount: price
    }
  ]
redirect_to gateway.redirect_url_for(response.token)

This works, I can sign in as a sandboxed buyer and confirm the payment, which brings me back to <confirm url> from above. In the confirmation, I do:

response = gateway.recurring price, nil,
  token: params[:token],
  period: 'Year',
  frequency: 1,
  start_date: Time.now,
  description: 'My Item Subscription'

When I do this, I receive an invalid token error from Paypal in the response variable. The token seems to be fine, it is present in the URL when I am brought back to the confirmation URL. I'm then taking it directly (params[:token]) and sending it back to Paypal.

Am I doing something completely wrong? Like I said, it seems like a lot of the documentation for this type of process is outdated (or maybe what I am trying is the stuff that is outdated...)

Was it helpful?

Solution

After looking through the source code for ActiveMerchant's Paypal express checkout gateway, I came to the conclusion that it's simply outdated when dealing with recurring payments. I switched to the paypal-recurring gem instead and everything worked fine.

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