我已经在 Rails 应用程序中实现了 Braintree 订阅支付。在开发中一切正常,但是当我切换到生产时(我已经在 Braintree 注册并获得了一个真实帐户,并且我更改了环境中的所有密钥)
我尝试提交无效的卡信息来测试应用程序,页面一直显示错误。
我查看应用程序日志,它说
NoMethodError (undefined method `customer' for #<Braintree::ErrorResult:0x007f6ed80f1d80>):
这是我的创建方法,我按照您的教程进行操作,并且在开发中运行良好
def create
if current_user.braintree_id?
customer = Braintree::Customer.find(current_user.braintree_id)
else
result = Braintree::Customer.create(
email: current_user.company_email,
company: current_user.company_name,
payment_method_nonce: params[:payment_method_nonce]
)
customer = result.customer
current_user.update(braintree_id: customer.id)
end
result = Braintree::Subscription.create(
payment_method_token: customer.payment_methods.find{ |pm| pm.default? }.token,
plan_id: params[:plan_id]
)
if result.success?
result.subscription.transactions.each do |transaction|
current_user.transactions.create(braintree_transaction_id: transaction.id,
plan_name: params[:plan_name],
price: transaction.amount.to_f,
start_date: transaction.subscription_details.billing_period_start_date,
end_date: transaction.subscription_details.billing_period_end_date,
subscription_id: result.subscription.id
)
end
current_user.update(braintree_subscription_id: result.subscription.id,
next_billing_date: result.subscription.next_billing_date,
billing_period_start_date: result.subscription.billing_period_start_date,
billing_period_end_date: result.subscription.billing_period_end_date,
status: result.subscription.status,
next_billing_period_amount: result.subscription.next_billing_period_amount,
paid_through_date: result.subscription.paid_through_date,
plan_id: params[:plan_id],
plan_name: params[:plan_name])
flash[:info] = "You've been subscribed successfully"
redirect_to @current_user
else
flash[:warning] = "Invalid card information"
render 'new'
end
end
奇怪的是它不会呈现结果不成功的闪光警告并重定向到原始的 new_subscription_path,而是将网站 url 重定向到这个
https://herokuappname.herokuapp.com/subscription.1
页面错误显示
This page isn’t working herokuappname.herokuapp.com is currently unable to handle this request.
HTTP ERROR 500
所以,我想知道是客户方法错误(我不这么认为,因为它在开发模式下没有任何问题)还是任何其他问题,例如为什么页面网址如此奇怪?
我查看了Braintree控制面板,订阅失败的原因是因为银行卡信息错误导致银行拒绝交易,我输入了错误的卡来测试,如果是无效的卡信息,为什么没有它显示闪光通知并重定向回new_subscription_path,而不是重定向到我上面提到的subscription.1 url?