Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Fix checkout session webhook completion #326

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Fixed a bug where checkout session completion would not mark transactions as successful from webhooks. ([#318](https://github.com/craftcms/commerce-stripe/issues/318))
- Fixed the performance of loading plans in the control panel. ([#322](https://github.com/craftcms/commerce-stripe/issues/322))
- Fixed a PHP error that could occur when handling a webhook request.
- Fixed a bug where choosing bank transfer as a payment method wouldn’t complete an order. ([#315](https://github.com/craftcms/commerce-stripe/issues/315))
Expand Down
13 changes: 13 additions & 0 deletions src/base/SubscriptionGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,19 @@ public function handlePaymentIntentSucceeded(array $data): void
{
$paymentIntent = $data['data']['object'];
if ($paymentIntent['object'] === 'payment_intent') {

// Before we treat this as a normal payment intent, lets see if it was checkout session payment intent
$sessions = $this->getStripeClient()->checkout->sessions->all([
'payment_intent' => $paymentIntent['id'],
]);

if($session = $sessions->data[0] ?? null) {
$transaction = Plugin::getInstance()->getTransactions()->getTransactionByReference($session['id']);
$error = '';
Plugin::getInstance()->getPayments()->completePayment($transaction, $error);
return;
}

$transaction = Plugin::getInstance()->getTransactions()->getTransactionByReference($paymentIntent['id']);

if (!$transaction?->id) {
Expand Down
Loading