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
source share