Jump to content
asro2004

Stripe v3 module for SCA

Recommended Posts

I've added the unimplemented bits, so hopefully this should be close to a final version

  • webhook file name for account history info fixed
  • updated module configuration to include both live and test keys and use correct key when toggling between live and test selection
  • implemented authorise only transactions. Authorised transactions have to be captured using the Stripe dashboard, which will then fire the call to the webhook and complete the order

If you have installed a previous release of the module, it will show undefined variable errors when the admin modules page is displayed, but after you have edited the module configuration it will update variables and you won't get the error messages again.

stripe_sca_v1.0.2.zip

Share this post


Link to post
Share on other sites

@mhsuffolk thanks for your info regarding the stripe_cli.  I followed the instructions, installed stripe_cli then :

logged in using

stripe login --api-key '{{pk_test_mykey}}

stripe listen                   -     which returned a webhook secret key which i used in osc

but I still get the following when processing a test sale on my localhost

Fatal error: Uncaught Error: Cannot access empty property in D:\xxxxx\xxxx\xxxx\includes\modules\payment\stripe_sca.php:832

I'm not sure how the stripe_cli is working, so I'm stuck with thinking perhaps the installation of the stripe_sca module is wrong, but thats only a guess!

Hope you can help

Mike


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

Share this post


Link to post
Share on other sites

Sorry @Mikepo you have exhausted my ideas and knowledge.

Hopefully @asro2004 can help. Bear in mind he is in New Zealand so is probably fast asleep now.


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, it is past my bed time, but that line is a reference to a global $currencies which is set in application_top.php. Could there be a problem loading the Currencies class?

I'm afraid I have not used the stripe cli to text the webhook, but used something called ngrok. I posted instructions for it earlier.

Share this post


Link to post
Share on other sites

Some more small bugs, sorry!

1.  Webhook Signing Secret needs a live and test field. It took me a while to find the need for a separate test version originally.

2. In the confirmation email, the Payment Method field is not filled, see images

image.png.bd583edc7deda67ed9d8def8b7322943.pngimage.png.04efa5ffe020efa644faaabcecbe03fb.png


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

So, installed the latest version to my live shop, and again got this fatal error when attempting to go to checkout_confirmation.php

Fatal error: Uncaught Error: Cannot access empty property in /xxxx/xxxx/xxxx/includes/modules/payment/stripe_sca.php:393

So, it's not the problem with running on a local server, as the live shop is in direct communication to the stripe servers. 

I'll keep looking, but I'm a lose here now

I'm installing this on BS Frozen.


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

Share this post


Link to post
Share on other sites

@ars2004 ok, I have now added  the Stripe module on a fresh install of Phoenix 1.0.2.0, running php7.0.31, buntu unix, XAMPP for Linux 7.0.31 and still get the following error

Fatal error: Uncaught Error: Cannot access empty property in /xxx/xxxx/xxx/xxx/includes/modules/payment/stripe_sca.php:393 Stack trace: #0 /xxxx/xxxx/xxxx/xxxx/includes/classes/payment.php(161): stripe_sca->confirmation() #1 /xxxx/xxxxx/xxxx/xxxx/checkout_confirmation.php(212): payment->confirmation() #2 {main} thrown in /xxxx/xxx/xx/xxxxx/includes/modules/payment/stripe_sca.php on line 393

code is:

            $this->$intent = \Stripe\PaymentIntent::create($params);


As I'm not fully understanding OOP, I can't track down the error. So any help would be very much appreciated.

Thanks

Mike


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

Share this post


Link to post
Share on other sites

@Mikepo , sorry, I got distracted working on something else and did not check my emails.

After some puzzling over it and some googling, the penny eventually dropped, and looking at the code I now wonder how on earth it works for anyone.

I have used $this->$intent everywhere instead of $this->intent. It looks like I need to go back to a PHP beginners class.

I will include @mhsuffolk 's bugs in a new release today.

Share this post


Link to post
Share on other sites

Another update to fix some issues:

  • fix missing payment method in customer order confirmation email
  • separate web hook signing secrets for test and live
  • attempt to resolve 'cannot access empty property' error in stripe_sca.php, line 393

After installing the update, please go directly to the module configuration and re-enter the web hook signing secret for both test and live environments

stripe_sca_v1.0.3.zip

Share this post


Link to post
Share on other sites

@asro2004 Thank you again for all the work you have done on this. I have updated to 1.0.3 and now I have the issue as described in your instructions "If the payment is processed, and the checkout success page is displayed, but the order is not complete"

image.png.6888039508c3c23e2b154f41a42c5399.png

The icon under the arrow says there is 1 pending webhook.

image.png.9f2f3e6d7eef5d7b6568485dbce393fc.png

I have retried it and nothing happens apart from a second line in the dashboard stating error 400.

The order is in Preparing state with no order history and no emails. Apart from the email missing field bug that I reported before every thing worked correctly before these changes.

In the webhook.php file you have added several of these,

require_once(DIR_FS_CATALOG . 'includes/modules/payment/stripe_sca.php');

which has DIR_FS_CATALOG added which was not there before. I am NOT a coder but is that correct?

 

 

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

The webhook detail at the stripe dashboard should show the response received from your web site's webhook.php. That would be a PHP formatted error page if there was a PHP error encountered when the webhook.php was processed. But if you're getting 400 error, that suggests the URL in the stripe dashboard is not right. In test data mode at the stripe dashboard, you can send a test message to the webhook. If you are not getting a 200 response, it cannot reach the webhook using that url.

When the connection is eventually made, the order will complete.

I put the DIR_FS_CATALOG into the requires because I was having a problem with  the language file not being loaded, and I thought I'd better make it consistant with the paypal standard_ipn.php.

Share this post


Link to post
Share on other sites

I am at a loss. The URL in the webhook is the same for both live and test. I have reverted to 1.0.2, done a test transaction, all works correctly, no errors in the webhook log says 200 payment intent suceeded. However if I send a test webhook it fails even though the test transaction worked. I have not tested 1.0.3 in live mode but I have had a 1.0.2 live transaction work correctly.


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

Found the fault.

The Webhook secret keys fields in admin are transposed or not correct. Tested by having module in test mode and putting the test WH secret key in the live field and it successfully performed a test transaction. Have not tried a live one. Sending a test webhook works as well now.


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

Oh, good grief. Some days I should just stay in bed. It is still using the old webhook secret in the webhook.php code.

Share this post


Link to post
Share on other sites

Just had an email from Stripe reminding us to update for SCA and stating that there is an updated module available. That will be the one in this thread. Their dashboard also states that OSCommerce has been updated for SCA.

Many thanks to @asro2004 for all the work involved, I just did a bit of testing.

The new module can use existing card tokens saved by the old module, which can now be switched 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

Just uploaded and installed this addon.  After having an error which was my fault as I missed a file out when uploading to server, everything seems to be working well in both live and test mode.

Many thanks to those that wrote the module and tested it. I wish there was a way to buy someone a beer.


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

Just out of curiosity, is there a way to make the area where the card details are entered look a bit better. At first glance I didnt quite know where to enter the card number, and if I didnt know I am sure some of my older generation customers wont know either.


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

That area is created starting Line 346 of includes/modules/payment/stripe_sca.php

My understanding is that of the line where the customer actually inputs the card number, date and CVC is put there by the Stripe server, that is how it is PCI compliant because customers card details do not touch your server. I do not think that that can be changed.


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

@14steve14 @mhsuffolk

I agree it does not look great, and I was not sure how to adjust the look at the time, but I've just done some experimenting, and ignoring the Stripe documentation at https://stripe.com/docs/payments/cards/collecting/web which suggests creating a javascript variable containing the style and passing that to the elements.create function, I think it is easier to 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, so the code looks like:

Quote

        $js = <<<EOD
<style>
#stripe_table_new_card #card-element {
  background-color: #fff;
  padding: 6px 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
}
</style>
<script src="https://js.stripe.com/v3/"></script>

That makes the card area similar to the card name and it becomes a lot more obvious to us old folks.

Edited by asro2004
add border-radius

Share this post


Link to post
Share on other sites

Works fine.

But I found another issue. The text for the labels is hardcoded.

In stripe_sca.php lines 346-349 should be:

        $content .= '<div id="stripe_table_new_card">' .
                '<div class="form-group"><label for="cardholder-name" class="control-label">' . MODULE_PAYMENT_STRIPE_SCA_CREDITCARD_OWNER . '</label>' .
                '<div class="col-sm-16"><input type="text" id="cardholder-name" class="form-control" value="' . tep_output_string($order->billing['firstname'] . ' ' . $order->billing['lastname']) . '" required></text></div></div>' .
                '<div class="form-group"><label for="card-element" class="control-label">' . MODULE_PAYMENT_STRIPE_SCA_CREDITCARD_NUMBER . '</label>' .

 

Share this post


Link to post
Share on other sites

Hi, thanks for the great work.

I get this error trying to create a payment:

IntegrationError: Invalid value for stripe.handleCardPayment intent secret: value should be a client_secret string. You specified: undefined.

A webhook was made, secret key inserted in the module.....

 

Any ideas?
Thanks Peter.

 

Share this post


Link to post
Share on other sites

Did you add both events 'payment_intent.succeeded' and 'payment_intent.payment_failed' to both live and test webhooks when you created them?

image.png.0e1637bce3e9daac17b1d7a77713d2b0.png

If not click "Update Details"


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

Click on Developers in the Stripe dashboard.

At the bottom of the screen have you any errors. This was when I was testing, I get none in my live shop.

image.png.ebbb7ed28a108c1efac4860f5ad07d1c.png

If you hover over any errors a pop up appears, click the errors line of that pop up.

image.png.a96c66b2365cbb8e741470f7638ecbe5.png

You will get a list of failed webhooks, click on one and report back the contents of the Response box. Example above.


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

×