生产模式下的 Braintree 错误
Braintree Error In Production Mode
我在 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
所以,我想知道是客户方法错误(我认为不是,因为它在开发模式下没有任何问题)还是其他问题,例如为什么页面 url 这么奇怪?
我查看了Braintree控制面板,订阅失败的原因是因为银行卡信息错误拒绝交易,我输入了错误的卡以测试它,如果卡信息无效,为什么它不显示 Flash 通知并重定向回 new_subscription_path,而是重定向到我上面提到的 subscription.1 url?
完全披露:我在 Braintree 工作。如果您有任何其他问题,请随时联系 support。
我不确定您在生产中是否使用了与在沙盒中相同的无效卡号进行测试,但我会尝试根据我们手头的信息回答您的问题:
NoMethodError(# 的未定义方法“客户”):
通过尝试 create a customer with a payment method with an invalid card, the result of that API call was an ErrorResult
object. ErrorResult
objects are either a validation error, processor decline, gateway rejection, or other exception 消息,并且不包含 customer
方法。因此,undefined method
错误。
您应该在所有 Braintree API 调用周围添加一些 error handling,以便您可以解决整个订阅过程中的任何错误。
我在 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
所以,我想知道是客户方法错误(我认为不是,因为它在开发模式下没有任何问题)还是其他问题,例如为什么页面 url 这么奇怪?
我查看了Braintree控制面板,订阅失败的原因是因为银行卡信息错误拒绝交易,我输入了错误的卡以测试它,如果卡信息无效,为什么它不显示 Flash 通知并重定向回 new_subscription_path,而是重定向到我上面提到的 subscription.1 url?
完全披露:我在 Braintree 工作。如果您有任何其他问题,请随时联系 support。
我不确定您在生产中是否使用了与在沙盒中相同的无效卡号进行测试,但我会尝试根据我们手头的信息回答您的问题:
NoMethodError(# 的未定义方法“客户”):
通过尝试 create a customer with a payment method with an invalid card, the result of that API call was an ErrorResult
object. ErrorResult
objects are either a validation error, processor decline, gateway rejection, or other exception 消息,并且不包含 customer
方法。因此,undefined method
错误。
您应该在所有 Braintree API 调用周围添加一些 error handling,以便您可以解决整个订阅过程中的任何错误。