Skip to content

Commit

Permalink
Fix: stripe payment logged twice (#41)
Browse files Browse the repository at this point in the history
* Fix: stripe payment logged twice

* Avoid marking order as processed more than once

Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com>

Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com>
Co-authored-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com>
  • Loading branch information
philipxyc and sampoyigi authored Oct 30, 2022
1 parent 093ab32 commit 451703b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions payments/Stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ public function processPaymentForm($data, $host, $order)
'amount', 'currency', 'capture_method', 'setup_future_usage',
]), $stripeOptions);

// Avoid logging payment and updating the order status more than once
// For cases where the webhook is triggered before the user is redirected
if ($order->isPaymentProcessed())
return true;

if ($paymentIntent->status === 'requires_capture') {
$order->logPaymentAttempt('Payment authorized', 1, $data, $paymentIntent->toArray());
}
Expand Down Expand Up @@ -587,10 +592,10 @@ protected function webhookHandlePaymentIntentSucceeded($payload)
if ($order = Orders_model::find($payload['data']['object']['metadata']['order_id'])) {
if (!$order->isPaymentProcessed()) {
if ($payload['data']['object']['status'] === 'requires_capture') {
$order->logPaymentAttempt('Payment authorized', 1, [], $payload['data']['object']);
$order->logPaymentAttempt('Payment authorized via webhook', 1, [], $payload['data']['object']);
}
else {
$order->logPaymentAttempt('Payment successful', 1, [], $payload['data']['object'], true);
$order->logPaymentAttempt('Payment successful via webhook', 1, [], $payload['data']['object'], true);
}

$order->updateOrderStatus($this->model->order_status, ['notify' => false]);
Expand Down

0 comments on commit 451703b

Please sign in to comment.