Claudio Shigueo Watanabe
Claudio Shigueo Watanabe

Reputation: 1003

Get first_name (and other info) from Paypal and create Rails Devise account using paypal-recurring gem

I have create the basics of subscription Paypal using the RailsCast and now I'm doing what is missing there.

Now I'm developing the process to do the Devise user registration together/just after the payment is done. For now, I'm trying something like this and this.

As the RailsCast got the e-mail from PayPal using this line:

@subscription.email = PayPal::Recurring.new(token: params[:token]).checkout_details.email

So, I thought that I could get first name, middle name and last name from PayPal as well. From PayPal documentation it seems that it is possible but I couldn't get it through paypal-recurring gem. I have tried to see if I can learn what I have to do from paypal-recurring GitHub docs and code but I couln't find and tried some possibilities without success.

Is it possible? Maybe in another way not using paypal-recurring gem?

If you have another recomendation/reference to do this registration process, please, let me know.

Update

As @Andrew suggested PayPal IPN, I thought it would be better update my question as I want to have the first_name from PayPal as a default value to ease the process to the user register in my database but he or she may want to change to another name.

The process that I want is something like:

  1. The user chooses his plan and to pay with PayPal
  2. User is sent to PayPal
  3. User fills payment info on PayPal site
  4. User is sent again to my site
  5. My site gets e-mail and name of the user from PayPal and asks the user to confirm or change the data, and provide his password to create the login to my site
  6. My site uses the user data provided to register the user and sends the request to PayPal to request the payment and create the recurring profile

Upvotes: 0

Views: 256

Answers (2)

Drew Angell
Drew Angell

Reputation: 26056

Ok, based on your current outline of steps you can handle that exact flow using Express Checkout.

SetExpressCheckout will generate a token for you, and you then redirect the user to PayPal. They review and approve the payment and are then redirected back to your site. There you can call GetExpressCheckoutDetails to obtain the email, name, address, etc. and display a final review page for the customer to confirm everything or make changes if necessary. Finally, you'd call DoExpressCheckoutPayment to finalize the payment using the customers confirmed details.

Upvotes: 1

Drew Angell
Drew Angell

Reputation: 26056

I would look at PayPal IPN (Instant Payment Notification). It'll POST transaction details to a listener script you have sitting on your server so you can process the data accordingly in real-time.

Upvotes: 1

Related Questions