mirror of
https://github.com/myronblair/tomsjavajive
synced 2026-06-30 17:50:32 -05:00
Fix duplicate order confirmation email on Stripe Checkout
When using Stripe Checkout, both checkout.session.completed and payment_intent.succeeded fire for the same payment. After the stripe.php change propagated order_id into PI metadata, the PI handler also found an order_id and sent a second confirmation email. Fix: fetch the order first in payment_intent.succeeded and skip if already confirmed. Also records stripe_payment_intent in this path for direct PI flows that bypass checkout.session.completed.
This commit is contained in:
+15
-11
@@ -57,21 +57,25 @@ switch ($eventType) {
|
||||
break;
|
||||
|
||||
case 'payment_intent.succeeded':
|
||||
// Payment Intent flow (embedded checkout) — metadata.order_id set directly on PI
|
||||
// Payment Intent flow (embedded/direct) - skip if already confirmed by checkout.session.completed
|
||||
$paymentIntentId = $data['id'] ?? '';
|
||||
$orderId = $data['metadata']['order_id'] ?? '';
|
||||
if ($orderId) {
|
||||
db()->update('orders',
|
||||
[
|
||||
'payment_status' => 'paid',
|
||||
'order_status' => 'confirmed',
|
||||
],
|
||||
'order_id = :id',
|
||||
['id' => $orderId]
|
||||
);
|
||||
$order = db()->fetch("SELECT * FROM orders WHERE order_id = :id", ['id' => $orderId]);
|
||||
if ($order) {
|
||||
sendOrderConfirmationEmail($order);
|
||||
if ($order && $order['order_status'] !== 'confirmed') {
|
||||
db()->update('orders',
|
||||
[
|
||||
'payment_status' => 'paid',
|
||||
'order_status' => 'confirmed',
|
||||
'stripe_payment_intent' => $paymentIntentId,
|
||||
],
|
||||
'order_id = :id',
|
||||
['id' => $orderId]
|
||||
);
|
||||
$order = db()->fetch("SELECT * FROM orders WHERE order_id = :id", ['id' => $orderId]);
|
||||
if ($order) {
|
||||
sendOrderConfirmationEmail($order);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user