如何在 stripe 结账前检查优惠券是否对客户有效 api
How to check if Coupon is valid for customer before checkout in stripe api
我有一个用例,在使用 Stripe 进行付款之前,我需要确定应用的代码是否对特定客户有效。假设在 Stripe 中创建了一个优惠券代码为“50%off”,并且只能被客户使用一次。会有两种情况:
- 如果客户是第一次使用,可以享受折扣。
- 如果客户第二次使用它,我不想在应用程序级别向他们显示折扣价。而在Stripe级别,同样不会提供折扣。
我没有在我的应用程序级别管理优惠券代码,也没有使用以下代码检索优惠券代码数据:
\Stripe\Stripe::setApiKey($this->config->item('stripe_secret_key'));
$couponData = \Stripe\Coupon::retrieve($coupon);
上面的代码和我分享下面的细节
[body] => {
"id": "50%off",
"object": "coupon",
"amount_off": 600,
"created": 1494427220,
"currency": "usd",
"duration": "once",
"duration_in_months": null,
"livemode": false,
"max_redemptions": null,
"metadata": {
},
"name": null,
"percent_off": null,
"percent_off_precise": null,
"redeem_by": null,
"times_redeemed": 4,
"valid": true
}
但我无法确定客户是否已经使用过此优惠券代码。我尝试传递客户 ID 以及以下内容:
\Stripe\Stripe::setApiKey($this->config->item('stripe_secret_key'));
$couponData = \Stripe\Coupon::retrieve($coupon, ['customer' => $stripe_customer_id]);
但它有相同的响应。
谁能帮我解决这个问题,谢谢!
Stripe 不会告诉您优惠券是否已被客户使用过。每次客户兑换优惠券时,您都需要在自己的数据库中跟踪这一点。
因为 提到了在 Active Redemptions
下的 Stripe 优惠券仪表板中看到的有关客户兑换的详细信息无法通过 API 获得。
This is not something that we support via the API at the moment. You would need to keep track of coupon redemptions on your end if you want to get the list and number of customers that have claimed those.
You can keep track of redemptions via webhooks.
这适用于 one-off 优惠券,但可通过 Stripe 客户和订阅对象的折扣属性获得循环优惠券:
Discount object 包含正在使用的优惠券或促销代码的详细信息。
因此应该可以解析 Stripe 客户或他们订阅的任何应用优惠券。
如果使用 promotion codes,可以应用一些限制,Stripe 会检查这些限制以阻止再次使用优惠券代码。
我有一个用例,在使用 Stripe 进行付款之前,我需要确定应用的代码是否对特定客户有效。假设在 Stripe 中创建了一个优惠券代码为“50%off”,并且只能被客户使用一次。会有两种情况:
- 如果客户是第一次使用,可以享受折扣。
- 如果客户第二次使用它,我不想在应用程序级别向他们显示折扣价。而在Stripe级别,同样不会提供折扣。
我没有在我的应用程序级别管理优惠券代码,也没有使用以下代码检索优惠券代码数据:
\Stripe\Stripe::setApiKey($this->config->item('stripe_secret_key'));
$couponData = \Stripe\Coupon::retrieve($coupon);
上面的代码和我分享下面的细节
[body] => {
"id": "50%off",
"object": "coupon",
"amount_off": 600,
"created": 1494427220,
"currency": "usd",
"duration": "once",
"duration_in_months": null,
"livemode": false,
"max_redemptions": null,
"metadata": {
},
"name": null,
"percent_off": null,
"percent_off_precise": null,
"redeem_by": null,
"times_redeemed": 4,
"valid": true
}
但我无法确定客户是否已经使用过此优惠券代码。我尝试传递客户 ID 以及以下内容:
\Stripe\Stripe::setApiKey($this->config->item('stripe_secret_key'));
$couponData = \Stripe\Coupon::retrieve($coupon, ['customer' => $stripe_customer_id]);
但它有相同的响应。
谁能帮我解决这个问题,谢谢!
Stripe 不会告诉您优惠券是否已被客户使用过。每次客户兑换优惠券时,您都需要在自己的数据库中跟踪这一点。
因为 Active Redemptions
下的 Stripe 优惠券仪表板中看到的有关客户兑换的详细信息无法通过 API 获得。
This is not something that we support via the API at the moment. You would need to keep track of coupon redemptions on your end if you want to get the list and number of customers that have claimed those. You can keep track of redemptions via webhooks.
这适用于 one-off 优惠券,但可通过 Stripe 客户和订阅对象的折扣属性获得循环优惠券:
Discount object 包含正在使用的优惠券或促销代码的详细信息。
因此应该可以解析 Stripe 客户或他们订阅的任何应用优惠券。
如果使用 promotion codes,可以应用一些限制,Stripe 会检查这些限制以阻止再次使用优惠券代码。