Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"The token is invalid" when trying to setup Paypal recurring payments with ActiveMerchant

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

like image 739
Logan Serman Avatar asked Nov 10 '22 10:11

Logan Serman


1 Answers

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.

like image 148
Logan Serman Avatar answered Nov 14 '22 23:11

Logan Serman