Page 1 of 1

Duplicate/unpaid orders

Posted: Sun Apr 06, 2025 9:18 pm
by notgreat
I just got my first order and it appears duplicated on the Phoenix order page, but I only have one payment in Stripe (which is my only payment option). Any idea how this can happen or how to prevent it? Am I going to have to manually check all my orders against stripe payments?

The earlier timestamp is what matches up with the payment:

Image

Code: Select all

Installed Version: CE Phoenix v1.1.0.1

Re: Duplicate/unpaid orders

Posted: Mon Apr 07, 2025 7:05 am
by raiwa
Hi,

Stripe saves all orders when the customer goes to the checkout confirmation page and they will stay at "Preparing [Stripe SCA]" status. DIfferent cart content will be saved as different orders. Completed and successful paid orders will be switched to the "Set Order Processed Status" status.
The Stripe hook will auto-delete the uncompleted orders after the amount of days entered in the module under "Days waiting to delete Preparing Stripe Orders." By default it's 2 days.

Re: Duplicate/unpaid orders

Posted: Mon Apr 07, 2025 8:38 pm
by notgreat
raiwa wrote: Mon Apr 07, 2025 7:05 am Hi,

Stripe saves all orders when the customer goes to the checkout confirmation page and they will stay at "Preparing [Stripe SCA]" status. DIfferent cart content will be saved as different orders. Completed and successful paid orders will be switched to the "Set Order Processed Status" status.
The Stripe hook will auto-delete the uncompleted orders after the amount of days entered in the module under "Days waiting to delete Preparing Stripe Orders." By default it's 2 days.
Are you saying I should not have money in Stripe for either of these orders because their status is "Preparing [Stripe SCA]"? I do have money in Stripe for one of them.

Re: Duplicate/unpaid orders

Posted: Tue Apr 08, 2025 7:25 am
by raiwa
If you received the payment, the order status should have changed to "Stripe SCA [Transactions]" and the payment details should be added to the order status history.
It it's not, then you probably didn't setup the webhook on your stripe account.

See Instructions (They are also linked on the help button in Modules -> Payment):
https://phoenixcart.org/phoenixcartwiki ... Stripe_SCA

Configuration

The basic configuration of the Stripe SCA module is the same as the standard Stripe module, requiring Publishable and Secret API keys, however as the order fulfillment has been moved to a webhook, you need to add the address of the Stripe SCA webhook at your store to your Stripe account dashboard, and add the webhook signing secret it generates to the Stripe SCA payment module configuration.
Login to your account at the Stripe web site, and select Developers > Webhooks

select '+ Add endpoint' at the upper right of the page
set the URL to: https://yourstore.url/ext/modules/payme ... ebhook.php
select version as 'Latest API version'
select event 'payment_intent.succeeded' and 'payment_intent.payment_failed'
click 'add endpoint' to save the webhook endpoint.

Then select the new endpoint URL from the list of end points, and then 'click to reveal' to see the Signing Secret. Copy and paste the text of the signing secret to the Webhook Signing Secret in the Stripe SCA module configuration form.

Note that the 'view test data' switch at the Stripe dashboard toggles between live and test modes, and there are seperate API keys and webhooks in each mode. You have to create a webhook endpoint in the test mode to be used in testing the module. If your test environment is on a local network machine that is not directly accessible from the internet, you can create a free account at ngrok.com, to create a tunnel to the webhook URL on your local test machine. See https://stripe.com/docs/webhooks/setup for more details.

The Stripe SCA module adds a log table, stripe_event_log, to the database, and if you select 'Log events?' in the Stripe SCA configuration, it will record each Stripe API call with the parameters that are passed to Stripe and the response received.

Re: Duplicate/unpaid orders

Posted: Tue Apr 08, 2025 8:59 pm
by notgreat
Thank you so much for the help!

I've configured the webhook, and now when I place an order myself it's listed as "pending". Does this indicate that the webhook is working correctly?
Image

Re: Duplicate/unpaid orders

Posted: Tue Apr 08, 2025 9:12 pm
by raiwa
Yes

Re: Duplicate/unpaid orders

Posted: Tue Apr 08, 2025 9:27 pm
by notgreat
raiwa wrote: Tue Apr 08, 2025 9:12 pmYes
Thank you! Do you have any idea about these PHP warnings?

Code: Select all

[root@www php-fpm]# cat www-error.log
[08-Apr-2025 15:55:43 America/Chicago] Stripe Notice: Undefined property of Stripe\PaymentIntent instance: charges
[08-Apr-2025 15:55:43 America/Chicago] PHP Warning:  Attempt to read property "data" on null in /var/www/html/shop/ext/modules/payment/stripe_sca/webhook.php on line 280
[08-Apr-2025 15:55:43 America/Chicago] PHP Warning:  Trying to access array offset on null in /var/www/html/shop/ext/modules/payment/stripe_sca/webhook.php on line 280
[08-Apr-2025 15:55:43 America/Chicago] PHP Warning:  Attempt to read property "billing_details" on null in /var/www/html/shop/ext/modules/payment/stripe_sca/webhook.php on line 282
[08-Apr-2025 15:55:43 America/Chicago] PHP Warning:  Trying to access array offset on null in /var/www/html/shop/ext/modules/payment/stripe_sca/webhook.php on line 282
[08-Apr-2025 15:55:43 America/Chicago] PHP Warning:  Attempt to read property "billing_details" on null in /var/www/html/shop/ext/modules/payment/stripe_sca/webhook.php on line 283
[08-Apr-2025 15:55:43 America/Chicago] PHP Warning:  Trying to access array offset on null in /var/www/html/shop/ext/modules/payment/stripe_sca/webhook.php on line 283

Re: Duplicate/unpaid orders

Posted: Wed Apr 09, 2025 7:42 am
by raiwa
I think this happens when the webhook is tested from Stripe site and therefore no valid event and no data is submitted.
To fix it you could try to change in:
ext\modules\payment\stripe_sca\webhook.php line 52 forward to:

Code: Select all

} else {
    $error_message = "unknown event";
    processFailure($intent, $stripe_sca, $error_message);
    http_response_code(200);
    exit();
}
So the whole block should be:

Code: Select all

if ($event->type == "payment_intent.succeeded") {
    $intent = $event->data->object;
    $customer_id = $intent->metadata['customer_id'];
    try {
        processPayment($intent, $stripe_sca, $currencies);
    } catch (Exception $e) {
        $stripe_sca->event_log($customer_id, "webhook error", $e->getMessage(), $e->getTraceAsString());
        echo MODULE_PAYMENT_STRIPE_SCA_WEBHOOK_SERVER;
        http_response_code(500);
        exit();
    }
    http_response_code(200);
    exit();
} elseif ($event->type == "payment_intent.payment_failed") {
    $intent = $event->data->object;
    $error_message = $intent->last_payment_error ? $intent->last_payment_error->message : "";
    processFailure($intent, $stripe_sca, $error_message);
    http_response_code(200);
    exit();
} else {
    $error_message = "unknown event";
    processFailure($intent, $stripe_sca, $error_message);
    http_response_code(200);
    exit();
}
Please report back and we will update the webhook.

Edit: Or maybe you added the unneeded event "charges" when you set up the webhook?