Laravel 7.0收银员-条纹付款例外

时间:2020-07-18 09:34:57

标签: php stripe-payments

我在Laravel Cashier Stripe付款中遇到问题。我需要将计费和新订阅合并为一个,以便在发生IncompletePayment例外时,我仍然可以获得带区卷的webhooks。

try{
  $user->charge(1000, $creditCard->id, [
                'description' => 'Premium Registration',
            ])
  $user->newSubscription('premium_member', $recurring)
          ->create($creditCard->id);

}
} catch (IncompletePayment $e) {

            $intent = \Stripe\PaymentIntent::retrieve($e->payment->id);
            $intent->confirm([
                'return_url' => url('api/payments-3d-success'),
            ]);

            return response()->json([
                'e' => $intent,
            ]);
        }

另一种方法是捕获异常并像laravel一样构建处理不完整异常的方法。

try{

  $subscription = \Stripe\Subscription::create([
                'customer' => $customer->id,
                'items' => [[
                    'price' => $recurring,
                ]],
                'add_invoice_items' => [[
                    'price' => $oneTime,
                ]],
            ]);

}
//I need to catch the exception here from stripe and build like a laravel way like IncompletePayment exceptions
catch(Exception $e){
$intent = \Stripe\PaymentIntent::retrieve($e->payment->id);
            $intent->confirm([
                'return_url' => url('api/payments-3d-success'),
            ]);

            return response()->json([
                'e' => $intent,
            ]);
}

请让我知道您如何处理此问题。谢谢

1 个答案:

答案 0 :(得分:1)