Braintree无法执行收费:自定义字段无效:描述


Braintree was unable to perform a charge: Custom field is invalid: description

我们使用的是Laravel 5.2和收银员/Braintree。

我们有一个基于订阅的网站,可以找到。这些是每月定期会员套餐。

我们现在正试图在几天的品尝器中添加一次充电。它似乎都工作得很好,直到最后一步,当我们得到一个错误,说描述无效。查看文档和源代码,我们无法找到这不起作用的原因。

代码如下:

$plan = $request->get('plan');
$coupon = $request->get('coupon');
$user = $this->user;
if ( false === $user->hasBraintreeId() ){
    $customer = $user->createAsBraintreeCustomer($request->get('payment_method_nonce'), array());
    $user->setCustomerId($customer->id);
    $user->save();
} else {
    $customer = $user->asBraintreeCustomer();
}
if ( $plan == '5-day-taster' ){ // One off payment
    $this->user->invoiceFor('5-day-taster', 5.99);
} elseif ( $plan == '10-day-taster' ){ // One off payment
    $this->user->invoiceFor('10-day-taster', 9.99);
} elseif ( $plan == 'personal-standard' ){ // Subscription(s)
    if ( isset($coupon) && !empty($coupon) )
        $this->user->newSubscription($plan, $plan)
            ->withCoupon($coupon)
            ->create($request->get('payment_method_nonce'), [
                'email' => $this->user->email,
            ]);
    else
        $this->user->newSubscription($plan, $plan)
            ->create($request->get('payment_method_nonce'), [
                'email' => $this->user->email,
            ]);
} 

得到以下错误:

Exception in Billable.php line 41:
Braintree was unable to perform a charge: Custom field is invalid: description.

来自Braintree的源代码(未编辑,仅供参考):

/**
     * Make a "one off" charge on the customer for the given amount.
     *
     * @param  int  $amount
     * @param  array  $options
     * @return 'Braintree'Transaction
     */
    public function charge($amount, array $options = [])
    {
        $customer = $this->asBraintreeCustomer();
        $response = BraintreeTransaction::sale(array_merge([
            'amount' => $amount * (1 + ($this->taxPercentage() / 100)),
            'paymentMethodToken' => $customer->paymentMethods[0]->token,
            'options' => [
                'submitForSettlement' => true,
            ],
            'recurring' => true,
        ], $options));
        if (! $response->success) {
            throw new Exception('Braintree was unable to perform a charge: '.$response->message);
        }
        return $response;
    }
    /**
     * Invoice the customer for the given amount.
     *
     * @param  string  $description
     * @param  int  $amount
     * @param  array  $options
     * @return 'Braintree'Transaction
     */
    public function invoiceFor($description, $amount, array $options = [])
    {
        return $this->charge($amount, array_merge($options, [
            'customFields' => [
                'description' => $description,
            ],
        ]));
    }

提前感谢您给我的建议

全面披露:我在Braintree工作。如果您还有任何问题,请联系技术支持。

看起来Laravel'收银员有一个未记录的要求,要求您在Braintree控制面板中设置自定义字段。它似乎爆炸了,因为你没有这个自定义字段,它试图用它来存储数据。

我试图在Braintree配置的Laravel'收银员文档中找到一些东西,但我只找到了一行关于其他方法的内容,它们链接到Braintree文档的一些不相关的部分。但是Braintree自定义字段文档说:

  1. 登录控制面板
  2. 导航到设置>处理>自定义字段
  3. 在字段旁边,点击想要的字段
  4. 在编辑表单上,您可以更改字段的显示名称或在存储和返回和通过之间切换
  5. 单击Save

当您在控制面板中添加名为description的自定义字段并设置Store and Pass Back时,它应该会通过此错误。