生产模式中的Braintree错误

时间:2018-03-27 16:38:24

标签: ruby-on-rails production-environment rails-routing braintree-rails

我已在rails app中实施了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

奇怪的是它没有呈现不成功结果的flash警告并重定向到原来的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

所以,我想知道是否是客户方法错误(我不这么认为,因为它在开发模式下没有任何问题)或任何其他问题,例如为什么页面网址如此奇怪? / p>

我查看了Braintree控制面板,订阅失败的原因是因为银行因错误的卡信息拒绝了交易,我输入了错误的卡以便测试它,如果它是无效的卡信息,为什么它没有显示flash通知并重定向回new_subscription_path,而是重定向到我上面提到的subscription.1 url?

1 个答案:

答案 0 :(得分:0)

完全披露:我在Braintree工作。如果您有任何其他问题,请随时联系enter image description here

我不确定您是否在沙盘中使用了相同的无效卡号进行生产测试,但我会尝试使用我们手头的信息回答您的问题:

NoMethodError(未定义的方法`customer&#39; for#):

尝试使用无效卡片support时,该API调用的结果是ErrorResult个对象。 ErrorResult个对象可以是create a customer with a payment methodvalidation errorprocessor decline或其他gateway rejection消息,也不包含customer方法。因此,undefined method错误。

您应该在所有Braintree API调用周围添加一些exception,以便在整个订阅过程中解决任何错误。

相关问题