Stripe payments 用户第一次为订阅付费时的条带
如果这是该特定客户首次为此特定订阅付费。 我必须根据所选的计划ID设置订阅的“取消”字段(我不想在创建订阅时设置)。为了第一次解决这个问题,我捕获了invoice.payment\u successed事件,并执行了以下操作:Stripe payments 用户第一次为订阅付费时的条带,stripe-payments,Stripe Payments,如果这是该特定客户首次为此特定订阅付费。 我必须根据所选的计划ID设置订阅的“取消”字段(我不想在创建订阅时设置)。为了第一次解决这个问题,我捕获了invoice.payment\u successed事件,并执行了以下操作: $invoices = \Stripe\Invoice::all([ "limit" => 3, //no need to get all of the invoices just checking i
$invoices = \Stripe\Invoice::all([
"limit" => 3, //no need to get all of the invoices just checking if their number is = 1.
"status" => 'paid',
"customer" => $customer_id,
"subscription" => $subscription_id,
"expand" => ["data.charge"],
]);
if ( count($invoices->data) == 1 ) {
//First time this user pays for this specific subscription;
你能告诉我这是否正确,或者我是否遗漏了什么,因为我对php和stripe都是新手。我应该做count($invoices)而不是我做的吗?您的代码看起来不错,但判断它是否有效的唯一方法是运行它,看看它是否达到了预期的效果。您可以使用测试模式API键和来测试流:
stripe trigger customer.subscription.created
这将创建一个测试客户、一个计划和一个订阅。后者将立即创建并支付发票,因此您应该获得一个发票。payment\u successed
webhook事件以进行测试