【发布时间】:2021-09-02 06:12:29
【问题描述】:
我正在使用 PHP,并使用 invoice.created 生成了一个 webhook。创建发票后,Stripe 让草稿发票在那里放置大约一个小时,这让我们有时间编辑或调整发票。我利用这段时间检查数据库(通过 webhook),看看这个人在系统中有多少推荐人来相应地调整优惠券。我似乎无法正确调整发票,因为我尝试过的所有方法都出现错误,这些错误是:
$inv = {发票编号,发票编号不正确,我没有收到任何错误
define('STRIPE_API_KEY', 'sk_test_******************');
$stripe = new \Stripe\StripeClient(
STRIPE_API_KEY
);
$stripe->invoices->update(
$inv,
['discounts.coupon' => '20OFF']
);
错误是未知对象 discounts.coupon
和
$stripe->invoices->update(
$inv,
['discount' => '20OFF']
);
错误 = 致命错误:未捕获(状态 400)(请求 req_hsX1QTOxzWMiQn)收到未知参数:折扣。你说的是折扣吗?在 /home/searchoscn/public_html/vendor/stripe/stripe-php/lib/Exception/ApiErrorException.php 第 38 行
和
$stripe->invoices->update(
$inv,
['coupon' => '20OFF']
);
ERROR = 致命错误:未捕获(状态 400)(请求 req_yEwwOLoukR6j6Z)收到未知参数:在 /home/searchoscn/public_html/vendor/stripe/stripe-php/lib 中抛出的优惠券/Exception/ApiErrorException.php 第 38 行
$stripe->invoices->update(
$inv,
['discounts' => ['coupon' => '20OFF']]
);
致命错误:未捕获(状态 400)(请求 req_IDRP1Rjv1YoBZR)在 /home/searchoscn/public_html/vendor/stripe/stripe-php/lib/Exception/ApiErrorException 中抛出了无效数组。 php 上线 38
我很确定我需要使用“折扣”,但不知道如何构造数组以正确传递优惠券。
试图预测一些问题或cmets:
是的,我确实有一张 ID 为 20OFF 的现有优惠券。这是 20% 的折扣
$inv 会在发送 webhook 时获取正确的发票 ID。
这是我一直在阅读的the link of the API documentation,但它不是很有帮助。
【问题讨论】:
标签: php stripe-payments