diff --git a/src/StripePaymentAdapter.php b/src/StripePaymentAdapter.php index d695498..c6c82b5 100644 --- a/src/StripePaymentAdapter.php +++ b/src/StripePaymentAdapter.php @@ -46,8 +46,6 @@ public function createIntent(Cart $cart, array $meta = []): PaymentIntent /** @var Stripe\PaymentIntent $stripePaymentIntent */ $stripePaymentIntent = StripeFacade::createIntent($cart->calculate()); - $cart->update(['meta->payment_intent' => $stripePaymentIntent->id]); - $paymentIntent = new PaymentIntent( id: $stripePaymentIntent->id, amount: $stripePaymentIntent->amount, @@ -55,7 +53,7 @@ public function createIntent(Cart $cart, array $meta = []): PaymentIntent client_secret: $stripePaymentIntent->client_secret, ); - $this->createTransaction($paymentIntent); + $this->createTransaction($cart, $paymentIntent); return $paymentIntent; } @@ -97,8 +95,15 @@ public function handleWebhook(Request $request): JsonResponse ->where('meta->payment_intent', $paymentIntent->id) ->first(); + if (! $cart) { + return new JsonResponse([ + 'webhook_successful' => false, + 'message' => "Cart not find cart with payment_intent: {$paymentIntent->id}", + ], 200); + } + /** @var Order $order */ - $order = $cart->draftOrder ?: $cart->completedOrder; + $order = $cart->draftOrder ? $cart->draftOrder : $cart->completedOrder; switch ($paymentIntentStatus) { case 'succeeded':