User Registration Using Devise and Paypal

I want to integrate Paypal into the Devise user registration process. I want the standard rails to be formed based on the devise resource , which also have some user fields belonging to the user model.

When the user fills out these fields and clicks on registration, he will be redirected to Paypal , when he will clear PayPal and return to our website, then user data should be created.

For one scenario, when a user fills out PayPal but doesn’t return to our site, then it’s time we should keep a record of the user before redirecting to Paypal.

To do this, we can create a flag in the user model and use Paypal IPN , and when the user transaction notifies about this, set this flag.

But in the case when the user is redirected to Paypal, but did not complete the transaction, I want that if he came to register and register again, our model does not say that the email already exists in the table.

How can we handle all these scenarios, is there any gem or plugin to work?

+4
source share
1 answer

Here I submit the detailed code to complete the whole process.

registration_controller.rb

 module Auth class RegistrationController < Devise::RegistrationsController include Auth::RegistrationHelper def create @user = User.new params[:user] if @user.valid? redirect_to get_subscribe_url(@user, request) else super end end end end 

registration_helper.rb

 module Auth::RegistrationHelper def get_subscribe_url(user, request) url = Rails.env == "production" ? "https://www.paypal.com/cgi-bin/webscr/?" : "https://www.sandbox.paypal.com/cgi-bin/webscr/?" url + { :ip => request.remote_ip, :cmd => '_s-xclick', :hosted_button_id => (Rails.env == "production" ? "ID_FOR_BUTTON" : "ID_FOR_BUTTON"), :return_url => root_url, :cancel_return_url => root_url, :notify_url => payment_notifications_create_url, :allow_note => true, :custom => Base64.encode64("#{user.email}|#{user.organization_type_id}|#{user.password}") }.to_query end end 

payment_notification_controller.rb

 class PaymentNotificationsController < ApplicationController protect_from_forgery :except => [:create] layout "single_column", :only => :show def create @notification = PaymentNotification.new @notification.transaction_id = params[:ipn_track_id] @notification.params = params @notification.status = "paid" @custom = Base64.decode64(params[:custom]) @custom = @custom.split("|") @user = User.new @user.email = @custom[0] @user.organization_type_id = @custom[1].to_i @user.password = @custom[2] if @user.valid? @user.save @notification.user = @user @notification.save @user.send_confirmation_instructions end render :nothing => true end def show end end 
+7
source

Source: https://habr.com/ru/post/1399277/


All Articles