Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用Desive和Paypal进行用户注册_Ruby On Rails_Ruby On Rails 3_Devise_Paypal_Paypal Sandbox - Fatal编程技术网

Ruby on rails 使用Desive和Paypal进行用户注册

Ruby on rails 使用Desive和Paypal进行用户注册,ruby-on-rails,ruby-on-rails-3,devise,paypal,paypal-sandbox,Ruby On Rails,Ruby On Rails 3,Devise,Paypal,Paypal Sandbox,我想将Paypal集成到design用户注册过程中。我想要的是一个基于设计资源的标准rails表单,它还具有属于用户模型的自定义字段 当用户填写这些字段并单击注册时,它将被重定向到Paypal,当他从Paypal清除并返回到我们的站点时,必须创建用户数据 对于用户填写paypal表单但不返回我们网站的情况,我们必须在重定向到paypal之前保留用户记录 为此,我们可以在用户模型中创建一个标志,并使用PaypalIPN,当通知用户交易时,设置该标志 但是,如果用户被重定向到Paypal,但没有完成

我想将
Paypal
集成到
design
用户注册过程中。我想要的是一个基于
设计资源的标准rails表单
,它还具有属于用户模型的自定义字段

当用户填写这些字段并单击注册时,它将被重定向到
Paypal
,当他从Paypal清除并返回到我们的站点时,必须创建用户数据

对于用户填写paypal表单但不返回我们网站的情况,我们必须在重定向到paypal之前保留用户记录

为此,我们可以在用户模型中创建一个标志,并使用Paypal
IPN
,当通知用户交易时,设置该标志

但是,如果用户被重定向到Paypal,但没有完成交易,那么如果用户返回注册并再次注册,我们的模型不应该抛出错误,说输入的电子邮件已经存在于表中


我们如何处理所有这些场景,是否有可用的gem或插件

这里我发布了执行整个过程的详细代码

注册\u 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
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
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
支付通知\u控制器.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
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
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
class PaymentNotificationsController[:创建]
布局“单列”,仅限=>:显示
def创建
@通知=PaymentNotification.new
@notification.transaction_id=参数[:ipn_track_id]
@notification.params=params
@notification.status=“已付款”
@custom=Base64.decode64(参数[:custom])
@自定义=@custom.split(“|”)
@user=user.new
@user.email=@custom[0]
@user.organization\u type\u id=@custom[1]。到\u i
@user.password=@custom[2]
如果@user.valid?
@user.save
@notification.user=@user
@通知.保存
@user.send\u确认\u说明
结束
render:nothing=>true
结束
def秀
结束
结束

请注意,您的示例将用户的密码base64编码(基本上是明文)发送到Paypal。我建议将待处理的注册数据存储在您这边,并且只通过Paypal传递对相应记录的引用。或者将密码全部保留在客户端的浏览器中,并将其存储为加密cookie或会话存储。