Jump to content
asro2004

Stripe v3 module for SCA

Recommended Posts

Forgive me if you have done this already.

Are you using version 1.0.5 from here. https://apps.oscommerce.com/Get&EbCL1&fKidG

There should be six boxes in admin where keys have to be added, and they are all different, earlier versions had less.


OsC 2.3.4.1 CE Frozen   PHP 7.2   MySQL 10.1.36-MariaDB-cll-lve. Phoenix in development

Is your version of osC up to date? You'll find the latest osC community version (CE Phoenix 1.0.2.0) here.

Share this post


Link to post
Share on other sites

Yes I did,. It has 3 fields for the live module and another 3 for the test module. I made webhooks for live and test. Filled al 6 keys in.

I tried both, but always the same error when I try to make a payment.

 

Thanks so much for your help!

Share this post


Link to post
Share on other sites

The developer @asro2004 is in New Zealand.

He is normally active on the forums early morning UK time. I am sure he will have some ideas.


OsC 2.3.4.1 CE Frozen   PHP 7.2   MySQL 10.1.36-MariaDB-cll-lve. Phoenix in development

Is your version of osC up to date? You'll find the latest osC community version (CE Phoenix 1.0.2.0) here.

Share this post


Link to post
Share on other sites

@asro2004,

Tested v. 1.0.5 and all fine.

It seems I found an easy fix for the discount module which should also work for all other third party order total modules:

in stripe_sca.php line 127 add "order_total_modules->process();"

    function confirmation() {
        global $oscTemplate, $cartID, $cart_Stripe_SCA_ID, $customer_id, $languages_id, $order, $currencies, $currency, $stripe_payment_intent_id, $order_total_modules;

        $order_total_modules->process();

 

Share this post


Link to post
Share on other sites

I do not get the order confirmation mails with the stripe sca module.

I checked and I get it with the other payment module (PayPal express) I'm using.

I also checked with different languages including the original english language file, and the same, no order confirmation mail is sent.

Anybody else exprerience the same problem or do I need to analyse my store?

Share this post


Link to post
Share on other sites
15 minutes ago, mhsuffolk said:

No problem with confirmation emails here.

Thanks, I'll check, must be something in my store then. You are using v 1.0.5?

Share this post


Link to post
Share on other sites
12 hours ago, asro2004 said:

insert a <style> block before the <script src="https://js.stripe.com/v3/"></script> line at line 861 in includes/modules/payment/stripe_sca.php

@asro2004, I added the <style> block at the location specified, but it didn't work.  So I added the code to the user.css.  Now it works.  Why?  I don't know.  Just thought I would pass on the issue/solution.


osC BS gold live - osC CE in development (awesome)

Share this post


Link to post
Share on other sites

@MikepoNot sure about that, I thought it might be a phoenix thing because I had only tested with an older version, but I just retested with Phoenix 1.02 and it works there. Could it be some custom theme you have for your store that is getting in the way?

Share this post


Link to post
Share on other sites

@peterespana, the error relates to the 'client secret' that is generated by stripe when the payment intent is created. In this module, that is in the includes/modules/payment/stripe_sca.php code, around line 375.

It checks if it has a global stripe intent id set, which it would if the customer had made changes to the cart or other order details, in which case it retrieves the intent created when the customer first got to the page, and updates it with the current amount, currency and billing details in case any has changed. If it's the first time to the page, a new payment intent is created.

In either case, the Stripe API returns a payment intent object that includes a new 'client secret' id that has to be put in the payment form, for the javascript code to use to link the card details entered by the customer with the store so the store can be informed of the payment result via the web hook.

It sounds like it is not getting a successful payment intent created. I'd suggest turning on the 'log events' in the module configuration, retrying the payment, and then check the stripe_event_log' table. You should see a row with the action, 'page create intent', and the response field should contain a message indicating the problem.

Share this post


Link to post
Share on other sites

@raiwaI think the email problem may be in the $OSCOM_Hooks call immediately prior to generating the email. If there was a PHP error in there, that would stop it sending the customer email.

I'll add the '$order_total_modules->process();' to the next release.

You should find the card prompts have been fixed in 1.0.5.

Share this post


Link to post
Share on other sites
5 hours ago, asro2004 said:

@peterespana, the error relates to the 'client secret' that is generated by stripe when the payment intent is created. In this module, that is in the includes/modules/payment/stripe_sca.php code, around line 375.

It checks if it has a global stripe intent id set, which it would if the customer had made changes to the cart or other order details, in which case it retrieves the intent created when the customer first got to the page, and updates it with the current amount, currency and billing details in case any has changed. If it's the first time to the page, a new payment intent is created.

In either case, the Stripe API returns a payment intent object that includes a new 'client secret' id that has to be put in the payment form, for the javascript code to use to link the card details entered by the customer with the store so the store can be informed of the payment result via the web hook.

It sounds like it is not getting a successful payment intent created. I'd suggest turning on the 'log events' in the module configuration, retrying the payment, and then check the stripe_event_log' table. You should see a row with the action, 'page create intent', and the response field should contain a message indicating the problem.

This is the log that appears:

 

ID
req_LWmdlGmOiCG4W6
Time
9/14/19, 7:01:22 AM
Method
POST
URL
/v1/payment_intents/pi_1FITLjK4kydItoIjO
Status
200
IP address
81.169.144.135
Version
Source
Stripe/v1 PhpBindings/6.43.0
Related
payment_intent 
 
 
Thanks!!
Peter

Share this post


Link to post
Share on other sites

Oops, another bug.

In test mode if I try to save a card whilst checking out it hangs. The order appears in admin in preparing status and I get this in the servers error log.

[14-Sep-2019 07:22:01 Europe/London] PHP Fatal error:  Uncaught Stripe\Error\InvalidRequest: No such payment_intent: pi_xxxxxxxxxxxx; a similar object exists in test mode, but a live mode key was used to make this request. in /home/*******/public_html/includes/modules/payment/stripe_sca/lib/ApiRequestor.php:210 from API request 'req_*************'
Stack trace:
#0 /home/******/public_html/includes/modules/payment/stripe_sca/lib/ApiRequestor.php(173): Stripe\ApiRequestor::_specificAPIError('{\n  "error": {\n...', 404, Object(Stripe\Util\CaseInsensitiveArray), Array, Array)
#1 /home/*******/public_html/includes/modules/payment/stripe_sca/lib/ApiRequestor.php(473): Stripe\ApiRequestor->handleErrorResponse('{\n  "error": {\n...', 404, Object(Stripe\Util\CaseInsensitiveArray), Array)
#2 /home/*******/public_html/includes/modules/payment/stripe_sca/lib/ApiRequestor.php(126): Stripe\ApiRequestor->_interpretResponse('{\n  "error": {\n...', 404, Object(Stripe\Util\CaseInsensitiveArray))
#3 /home/********/public_html/includes/modules/payment/stripe_sca/lib/ApiResource.ph in /home/mhunt/public_html/includes/modules/payment/stripe_sca/lib/ApiRequestor.php on line 210

I have not tested in live mode but possibly the reverse error would exist. Also I have not yet tried to use a stored card.


OsC 2.3.4.1 CE Frozen   PHP 7.2   MySQL 10.1.36-MariaDB-cll-lve. Phoenix in development

Is your version of osC up to date? You'll find the latest osC community version (CE Phoenix 1.0.2.0) here.

Share this post


Link to post
Share on other sites
8 hours ago, asro2004 said:

@raiwaI think the email problem may be in the $OSCOM_Hooks call immediately prior to generating the email. If there was a PHP error in there, that would stop it sending the customer email.

I checked with the discount hook commented out and the same, no order mails.
I also observed that no order status history is saved to the database. Order status stays in "Preparing [Stripe SCA]" and order status history is empty.

I had a look and found that the Secret Key constant has not been updated in the webhook and payment_intent. It is still "MODULE_PAYMENT_STRIPE_SCA_SECRET_KEY".

I changed it in payment_intent.php to:

// supply an API key
$secret_key = MODULE_PAYMENT_STRIPE_SCA_TRANSACTION_SERVER == 'Live' ? MODULE_PAYMENT_STRIPE_SCA_LIVE_SECRET_KEY : MODULE_PAYMENT_STRIPE_SCA_TEST_SECRET_KEY;
\Stripe\Stripe::setApiKey($secret_key);

and in webhook.php line 55-56 to:

    $secret_key = MODULE_PAYMENT_STRIPE_SCA_TRANSACTION_SERVER == 'Live' ? MODULE_PAYMENT_STRIPE_SCA_LIVE_SECRET_KEY : MODULE_PAYMENT_STRIPE_SCA_TEST_SECRET_KEY;
    \Stripe\Stripe::setApiKey($secret_key);

But no luck, still no order mail and no order status history.

I guess that @mhsuffolk and others which have it correct working have still the old stripe module installed with the old constant defined.

It seems there is still some bug in the process_payment or update_order_status functions.

Any idea where to check else?

rgds
Rainer

Edited by raiwa

Share this post


Link to post
Share on other sites
1 minute ago, raiwa said:

which have it correct working have still the old stripe module installed with the old constant defined

Yes, that could be the problem. I have the old module installed but turned off.


OsC 2.3.4.1 CE Frozen   PHP 7.2   MySQL 10.1.36-MariaDB-cll-lve. Phoenix in development

Is your version of osC up to date? You'll find the latest osC community version (CE Phoenix 1.0.2.0) here.

Share this post


Link to post
Share on other sites
9 hours ago, asro2004 said:

@raiwaI think the email problem may be in the $OSCOM_Hooks call immediately prior to generating the email. If there was a PHP error in there, that would stop it sending the customer email.

Sorry, forgot this:  The discount code hook condition should be secured like this:

            if (defined('MODULE_ORDER_TOTAL_DISCOUNT_STATUS') && (MODULE_ORDER_TOTAL_DISCOUNT_STATUS == 'true' || MODULE_ORDER_TOTAL_DISCOUNT_STATUS == 'True') && file_exists(DIR_FS_CATALOG . 'includes/hooks/shop/checkout_process/discount_code.php') {

In the older versions lower case 'true'  is used, in the Phoenix version I updated to upper case 'True' to match other modules.

Edited by raiwa

Share this post


Link to post
Share on other sites
35 minutes ago, mhsuffolk said:

Yes, that could be the problem. I have the old module installed but turned off.

Sorry, I was wrong. The old module uses "MODULE_PAYMENT_STRIPE_SECRET_KEY", the first versions of the new module were using "MODULE_PAYMENT_STRIPE_SCA_SECRET_KEY".

The newer versions are using "MODULE_PAYMENT_STRIPE_SCA_LIVE_SECRET_KEY" and "MODULE_PAYMENT_STRIPE_SCA_TEST_SECRET_KEY".

So the explanation may be that you @mhsuffolk, didn't uninstall the module before updating to the version which uses both live and test constants.

Like this the old constant "MODULE_PAYMENT_STRIPE_SCA_SECRET_KEY" stays in the database.

Share this post


Link to post
Share on other sites

Yes my database still contains MODULE_PAYMENT_STRIPE_SCA_SECRET_KEY but it has the correct live key stored.

I have tried your modifications in payment_intent.php and webhook.php. Now it does not produce that error in the server log, the transaction completes and is stored in the database, but the card is not saved. Webhook comes back with a 500 error in Stripes dashboard logs.

Edited by mhsuffolk

OsC 2.3.4.1 CE Frozen   PHP 7.2   MySQL 10.1.36-MariaDB-cll-lve. Phoenix in development

Is your version of osC up to date? You'll find the latest osC community version (CE Phoenix 1.0.2.0) here.

Share this post


Link to post
Share on other sites

@mhsuffolk, OK, thanks for confirming. Then let's see what the author @asro2004 says about. He will better know how to further debug this.

Share this post


Link to post
Share on other sites

@raiwa, @mhsuffolk, @peterespana

The hanging and failure to complete the transactions was due to the apiKey not being set correctly in payment_intent.php and webhook.php. It was only working for those who had installed the module before 1.0.5 because it was using the configuration key generated in the earlier release. I have re-tested by deleting the earlier configuraition  keys and re-running transactions with new card with and without saving, and a saved card, and all seems ok now.

I've updated the market place module with 1.0.6

Share this post


Link to post
Share on other sites

Link to latest release version Latest version

Is it a case that all the files in this latest release need to re-uploaded to the site or is it just the odd one or two. Upgrade instruction would be nice.

 

Edited by 14steve14

REMEMBER BACKUP, BACKUP AND BACKUP

Get the latest Responsive osCommerce CE (community edition) here

It's very easy to over complicate what are simple things in life

Share this post


Link to post
Share on other sites

@14steve14

I believe it is just 3

ext/modules/payment/stripe_sca/payment_intent.php

ext/modules/payment/stripe_sca/webhook.php

includes/modules/payment/stripe_sca.php


OsC 2.3.4.1 CE Frozen   PHP 7.2   MySQL 10.1.36-MariaDB-cll-lve. Phoenix in development

Is your version of osC up to date? You'll find the latest osC community version (CE Phoenix 1.0.2.0) here.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×