我们正在使用Laravel 5.2和Cashier / 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,
],
]));
}
提前感谢您提供任何建议。
答案 0 :(得分:6)
完全披露:我在Braintree工作。如果您有任何其他问题,请随时联系support。
看起来Laravel \ Cashier对setup a custom field in your Braintree control panel的要求没有记录。它似乎正在爆炸,因为您没有此自定义字段,并且它正在尝试使用它来存储数据。
我试图在Laravel\Cashier Documentation for Braintree configuration中找到一些内容,但我只找到了关于其他方法的链接,它们链接到Braintree documentation的某些不相关的部分。但是Braintree Custom Fields docs说:
当您在控制面板中添加名为description
的自定义字段且设置为Store and Pass Back
时,应该会遇到此错误。