Mik*_*ike 5 php stripe-payments
我在一个具有订阅和一次性费用的应用程序中使用 Stripes PHP SDK。
我通过网络钩子跟踪以下事件:
// Handle the event
switch ($event->type) {
// Fired for every payment, including subscriptions and one-offs
case 'payment_intent.succeeded':
$payment = $event->data->object;
$this->handleOneOffPaymentSuccess($payment);
break;
// When a one-off payment fails
case 'charge.failed':
$payment = $event->data->object;
$this->handleOneOffPaymentFailed($payment);
break;
case 'payment_intent.payment_failed':
$payment = $event->data->object;
$this->handleOneOffPaymentFailed($payment, 'The payment was not authorized (#Virtuoso-3)');
break;
// Subscription handling
case 'invoice.payment_succeeded':
$payment = $event->data->object;
$this->handleSubscriptionPaymentSuccess($payment);
break;
// Subscription failure
case 'invoice.payment_failed':
$payment = $event->data->object;
$this->handleSubscriptionPaymentFailed($payment);
break;
// ... handle other event types
default:
// Unexpected event type
http_response_code(400);
exit();
}
Run Code Online (Sandbox Code Playgroud)
当进行一次性付款时,我会得到payment_intent.succeeded. 其中包含我的元字段数据,因此我可以将商品标记为已购买。都好。
当我订阅时,我会收到一个invoice.payment_succeeded事件。其中包含我的元字段数据,因此我可以将订阅标记为已付费。也都很好。
然而,除了订阅之外,我还收到了一个payment_intent.succeeded事件。我认为这是因为有收费。我对此表示同意,但它不包含我创建订阅时的任何元字段数据,因此我无法跟踪它的用途。目前它只是失败了,这似乎不对。
以下是我创建订阅的方法:
$subscription = \Stripe\Subscription::create([
'customer' => $payment_method->stripe_customer_id,
'items' => [
[
'plan' => App::environment('production') ? $user->userType->stripe_plan : $user->userType->stripe_plan_test,
],
],
'expand' => ['latest_invoice.payment_intent'],
'metadata' => [
'internal_subscription_id' => $internalSubscription->id,
'user_id' => $user_id,
]
]);
Run Code Online (Sandbox Code Playgroud)
理想情况下,我希望将其user_id作为费用的一部分,然后我可以将其记录在用户身上,并将其与一次性费用一起显示给他们。
有什么想法我会出错吗?
| 归档时间: |
|
| 查看次数: |
1766 次 |
| 最近记录: |