如何设置:ipn_url以正确地将IPN回调写入我的PaymentNotification模型.到目前为止我尝试了以下内容:
1)将ipn_url:“http://my-app-name.com/payment_notifications”添加到流程方法(在选项下)或payment_notifications_url
2)尝试在GitHub issue page底部建议的解决方案
3)使用Paypal的即时付款通知(IPN)模拟器发送到“http://my-app-name.com/payment_notifications”,但我收到一个错误:IPN传递失败. HTTP错误代码401:未经授权
编辑
我已经能够成功模拟IPN到我的payments_notifications_url的交付.现在我只需要弄清楚如何指出定期发送的gem将ipn发送到那里.
任何指针都将非常感激.以下是我目前的一些代码.如果我遗忘任何相关部分,请告诉我.
PaypalPayment模型
class PaypalPayment def initialize(subscription) @subscription = subscription end def checkout_details process :checkout_details end def checkout_url(options) process(:checkout,options).checkout_url end def make_recurring process :request_payment process :create_recurring_profile,period: :monthly,frequency: 1,start_at: Time.zone.now end def cancel_recurring process :cancel end private def process(action,options = {}) options = options.reverse_merge( token: @subscription.paypal_payment_token,payer_id: @subscription.paypal_customer_token,description: @subscription.plan.name,amount: @subscription.plan.monthly_price,currency: "JPY" ) response = PayPal::Recurring.new(options).send(action) raise response.errors.inspect if response.errors.present? response end end
PaymentNotifications控制器
class PaymentNotificationsController < ApplicationController protect_from_forgery :except => [:create] def create PaymentNotification.create!(:params => params,:status => params[:payment_status],:transaction_id => params[:txn_id]) render :nothing => true end end
解决方法
1)在我的订阅控制器中,我调用@ subscription.save而不是if @ subscription.save_with_payment,因此save_with_payment方法实际上从未被调用过.
2)在流程方法中我添加了ipn_url:“https://my-app-name.com/payment_notifications”,
def process(action,ipn_url: "https://my-app-name.com/payment_notifications",currency: "JPY" ) response = PayPal::Recurring.new(options).send(action) raise response.errors.inspect if response.errors.present? response end
3)在PayPal的开发人员沙箱中,单击“测试帐户”,然后单击“输入沙箱测试站点”橙色按钮.在那里,使用您的沙盒卖家凭据登录.进入“我的帐户”和“个人资料”并在“销售首选项”下点击“即时付款通知首选项”.设置通知网址以匹配您为接收IPN POST而设置的网址,并将邮件传递设置为已启用.