Php Laravel-条带集成-在创建时将折扣优惠券应用于发票对象

Php Laravel-条带集成-在创建时将折扣优惠券应用于发票对象,php,laravel,stripe-payments,Php,Laravel,Stripe Payments,在我的Laravel 5.8应用程序中,我试图在创建时将条带优惠券应用于条带发票对象,但到目前为止运气不佳。 这是我的控制器中的代码: $options = [ 'api_key' => 'sk_test_xxxxxxxxxxxxxxxx', 'stripe_version' => "2019-08-14" ]; $coupon = \Stripe\Coupon::retrieve('xfpwySG1'); // I´m retrieving t

在我的Laravel 5.8应用程序中,我试图在创建时将条带优惠券应用于条带发票对象,但到目前为止运气不佳。 这是我的控制器中的代码:

$options = [
    'api_key' => 'sk_test_xxxxxxxxxxxxxxxx',
    'stripe_version' => "2019-08-14"
];

$coupon = \Stripe\Coupon::retrieve('xfpwySG1'); // I´m retrieving the coupon solely to use it for testing.

// $parameters = ['customer' => Auth::user()->stripe_id]; // This works fine (no discounts applied)
//This are all the different versions of parameters array I´ve tried, none of them work
// $parameters = ['customer' => Auth::user()->stripe_id, ['discounts' => ['coupon' => 'xfpwySG1']] ]; //Invalid array
// $parameters = ['customer' => Auth::user()->stripe_id, 'discounts' => ['coupon' => 'xfpwySG1'] ]; //Invalid array
// $parameters = ['customer' => Auth::user()->stripe_id, 'discounts' => ['coupon' => $coupon] ]; //Invalid array
// $parameters = ['customer' => Auth::user()->stripe_id, 'discounts' => ['coupon' => 'xfpwySG1'] ]; //Invalid array
// $parameters = ['customer' => Auth::user()->stripe_id, 'discounts' => $coupon ]; //Invalid array
// $parameters = ['customer' => Auth::user()->stripe_id, ['discounts' => ['xfpwySG1']] ]; //Invalid object
$parameters = ['customer' => Auth::user()->stripe_id, ['discounts' => 'xfpwySG1'] ]; //Invalid object
// $parameters = ['customer' => Auth::user()->stripe_id, 'discounts' => ['xfpwySG1'] ]; //Invalid object
// $parameters = ['customer' => Auth::user()->stripe_id, 'discounts' => 'xfpwySG1' ]; //Invalid array

// This is where I create the invoice object, using the info above.
$invoice = \Stripe\Invoice::create($parameters, $options);
请注意,如果我没有像在第一行$parameters中那样尝试包含“折扣”参数,那么一切都正常;就在我试图分发免费的东西时,我的应用程序失败了。。。哈哈!此外,我还尝试将优惠券应用于InvoiceItem对象,得到了类似的结果

我在理解Stripe生态系统以及所有部件是如何组合在一起时遇到了一些困难,因此,如果有任何帮助,我将不胜感激。
提前感谢

您应该为“折扣”键使用数组。试试这个

$parameters = ['customer' => Auth::user()->stripe_id, [['coupon' => 'xfpwySG1', 'discount' => null]];