Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
repl6669 committed Jan 12, 2024
1 parent 308146d commit 2a992be
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/StripePaymentAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,14 @@ 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,
status: 'intent',
client_secret: $stripePaymentIntent->client_secret,
);

$this->createTransaction($paymentIntent);
$this->createTransaction($cart, $paymentIntent);

return $paymentIntent;
}
Expand Down Expand Up @@ -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':
Expand Down

0 comments on commit 2a992be

Please sign in to comment.