Jump to content

asro2004

Members
  • Content count

    30
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by asro2004

  1. asro2004

    Stripe v3 module for SCA

    I have created a fork of the standard Stripe payments module to provide support for SCA. I tried uploading it to the market place, but it does not seem to be accepting it. A copy of the zip is attached. Stripe SCA Payment module Stripe SCA is a refactored version of the standard Stripe payments to update the Stripe API to v3 and support the SCA process flow. Other than using different Stripe API calls to set up and process payments, the main change is to defer order fulfillment to a web hook called by Stripe after the payment has been authorised. This module is installed as a separate payment method from the standard Stripe module and can be run in parallel. Note that it shares the customer_stripe_tokens table created by the standard Stripe module, and cards saved using the standard Stripe module can be reused by the Stripe SCA module, however, cards stored by the Stripe SCA module cannot be reused by the standard Stripe module. They will be rejected by Stripe with a message 'You cannot create a charge with a PaymentMethod. Use the Payment Intents API instead.' Install Copy the contents of this zip to the root osCommerce folder of your store. Login to the osCommerce Admin page of your store and go to Modules > Payment. - Click on the Install button at the upper right of the page - Choose 'Stripe SCA' from the module list and select Install Module. If you are allowing cards to be saved, add the cards management page: - go to Modules > Content - click on the Install Module button at the upper right of the page - select 'Stripe SCA Cards Management Page' and select Install Module. That will add the 'Manage saved payment cards' link to the customers' My Account page. 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/payment/stripe_sca/webhook.php - select version as 'Latest API version' - select event 'payment_intent.succeeded' and 'payment_event.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. 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. As the process flow has changed to use a web hook, the order has to be created in a pending state, and then updated to completed status after the payment has been authorised. Consequently, you need to set the new order status to 'Preparing [Stripe SCA]', and the order status is set to the status the order is to be set to, after the payment is authorised. Technical Notes The current stripe-php library, as at module publish date, has been included in in the module install. Calls to the Stripe library functions have replaced directly sending transactions to the Stripe gateway. You should be able to replace the includes/modules/payment/stripe_sca folder with the complete contents of the stripe-php library when Stripe releases updates to their library. If you do so, set the new API version in includes/modules/payment/stripe_sca.php. The Stripe v3 process flow now requires a PaymentIntent to be created before the payment page is displayed, and a 'data secret' it generates to be included in the HTML form. If a saved card is used, the Stripe customer id and payment method id has to be added to the PaymentIntent. During coding, it was found that a payment method could not be removed from a PaymentIntent, so rather than update the PaymentIntent with a server call as the saved card/new card is selected, the adding of the customer and payment method is deferred until immediately before submitting the payment to Stripe in a Javascript call when the form is submitted. The payment_intent.php server hook is also used to save the value of the 'save card' check box in the PaymentIntent so it is accessible to the webhook called after the payment is authorised. Stripe v3 provides UI elements to collect card details. A 'card-element' element is required for the new card to show card number, expiry and CVC fields, but is also required for saved cards in order to provide a place holder that Stripe can use to display authorisation prompts if required. Consequently, two occurrences of the 'card-element' element were created with the name of each toggled depending on whether a saved card or new card is selected. Otherwise, trying to reuse the same element for both purposes block the authorisation of saved card when the new card details was hidden. All order fulfilment and card saving code has been moved to ext/modules/payment/stripe_sca/webhook.php. Note the DIR_FS_CATALOG constant should be set to a path string, rather than the value dirname($_SERVER['SCRIPT_FILENAME']) . '/' because the includes/modules/payment/stripe_sca.php has a require that references the stripe-php library, and is executed at different locations in the directory structure and fails when the DIR_FS_CATALOG value varies with location. stripe_sca_v1.0.zip
  2. asro2004

    Stripe v3 module for SCA

    The prompts are declared in includes/languages/english/modules/payment/stripe_sca.php. It's probably best to just copy the ext and includes directories from the install/update and let it replace all the corresponding files in the web site. It should only be necessary to make sure the ownership and permissions of the files allow them to be read by apache/nginx. Check your site's error logs for any PHP errors.
  3. asro2004

    Stripe v3 module for SCA

    The card details form is generated by Stripe using a placeholder passed to it by the module's javascript in includes/modules/paymant/stripe_sca.php around lines 974-977: var card = elements.create('card', {hidePostalCode: true}); // Add an instance of the card Element into the `card-element` <div>. card.mount('#card-element'); Stripe's documentation about elements: https://stripe.com/docs/stripe-js
  4. asro2004

    Stripe v3 module for SCA

    Module has been updated to 1.0.12 to fix some issues with the stripe payment amount apparent when used in conjunction with some odler discount modules. Also, a problem with duplicate orders in 'preparing' state being created when the customer returns to the cart from the payment page. @peterespana, please use the 'send test webhook...' link in the stripe dashboard to check the link to the webhook on your server. It should show a 400 response code, with the message 'Invalid webhook signature: No signatures found matching the expected signature for payload'. If that is ok, please double check you stripe configuration 'transaction method' is set to 'capture' and not authorise. If that's the problem, it won't send to the webhook until you capture the payment in the stripe dashboard.
  5. asro2004

    Stripe v3 module for SCA

    @mhsuffolk, @raiwa, @John P, @peterespana I've fixed the order totals missing form the customer email, and the error that occured when a number of items were ordered. I removed the cart items from the Stripe transaction metadata. The marketplace module has been updated with version 1.0.11, and this one includes the correct version number in the app signature.
  6. asro2004

    Stripe v3 module for SCA

    I have fixed a couple of issues where stripe errors were not being shown to the user. Nothing else changed from 1.0.9 The market place app has been updated to 1.0.10.
  7. asro2004

    Stripe v3 module for SCA

    1.0.8 has been uploaded to the market place. It fixes missing customer emails, and order status history information. If would be a good idea to copy the entire contents of the ext and includes folders in the update to the corresponding folders of the store to ensure that all files get to the right places.
  8. asro2004

    Stripe v3 module for SCA

    Thanks, they have been fixed in 1.0.7
  9. asro2004

    Stripe v3 module for SCA

    I'm pretty sure the problem is something in the checkout_confirmation.php form. Raiwa had provided some refactoring to the handling of order processing, moving it from the webhook to the payment module, so I took the opportunity to re-check the javascript in the checkout-confirmation.php page, and removed some redundant fields and a dependency on a specific class name on the button. It was possible that a custom theme may disrupt the completion of the payment process, so this could fix it if that was the case for you. I reset the configuration and re-installed the module from scratch on a standard system, and then re-run tests for new cards, saving a new card, and using a saved card, and all worked ok. Please download and install the latest version 1.0.7 from the market place. All files should be replaced. If still no luck, please PM me a copy of the page source of checkout_confirmation.php page.
  10. asro2004

    Stripe v3 module for SCA

    Is that the 'Manage save cards' in the my account page? Please check your PHP or Apache/Nginx web site log for any errors. The account page is loading the code from includes/modules/content/account/cm_account_stripe_sca_cards.php, with the English text from includes/languages/english/modules/content/account/cm_account_stripe_sca_cards.php
  11. asro2004

    Stripe v3 module for SCA

    @peterespanaWere you able to see the stripe_event_log mysql table in your store database? It should create a row with the 'action' 'page create intent', and a request something like: {"amount":"7500","currency":"USD","setup_future_usage":"off_session","capture_method":"automatic","metadata":{"customer_id":"26","order_id":"2640","company":"","product_1_name":"Grillage for 6 beam 3 span bridge","product_1_model":"","product_1_id":"72{6}14","product_1_qty":"1","product_1_price":"75.0000","product_1_tax":0}} and the response should be the payment intent object returned by stripe, or an error message. You should see a line in the response 'client_secret', and it is that value that is placed in a hidden field in the payment form by the code in the confirmation function of stripe_sca.php. With the error message you are getting, would suggest an error response from Stripe when the intent is created, but your Stripe log shows a response code 200. Try looking in your PHP error log, or Apache/Nginx log, or check the browser console for any javascript error. Have a look at the page source of the checkout_payment.php page, and search for id="secret". The value of that field should be the client secret returned by Stripe in the payment intent object.
  12. asro2004

    Stripe v3 module for SCA

    It's probably easiest to just overwrite all of them.
  13. asro2004

    Stripe v3 module for SCA

    @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
  14. asro2004

    Stripe v3 module for SCA

    @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.
  15. asro2004

    Stripe v3 module for SCA

    @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.
  16. asro2004

    Stripe v3 module for SCA

    @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?
  17. asro2004

    Stripe v3 module for SCA

    @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: That makes the card area similar to the card name and it becomes a lot more obvious to us old folks.
  18. asro2004

    Stripe v3 module for SCA

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

    Stripe v3 module for SCA

    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.
  20. asro2004

    Stripe v3 module for SCA

    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
  21. asro2004

    Stripe v3 module for SCA

    @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.
  22. asro2004

    Stripe v3 module for SCA

    @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.
  23. asro2004

    Stripe v3 module for SCA

    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
  24. asro2004

    Stripe v3 module for SCA

    I'm sorry, I mis-read the code. The sort order is working for the Stripe SCA module, as long as the value is non-zero.
  25. asro2004

    Stripe v3 module for SCA

    I'm sorry but this is outside the cope of the payment module itself. The sequence shown on the checkout page is simply the order in which the payment modules are listed in the MODULE_PAYMENT_INSTALLED configuration record. It looks like admin/modules.php has to be updated to save the payment modules, whenever any module is changed, into the configuration value in the sequence of the sort order whereas at the moment it just adds any new module to the end of the list. Alternatively, includes/classes/payment.php changed to sort the $selection_array array into sort order in the selection() function. I've fixed this for a next release, but will wait to see if there is anything else that needs to be updated. Raiwa is having an issue with the being redirected to the cart page after clicking finalise and pay, and I have not been able to reproduce this. Is anyone else having a similar problem?
×