Using Stripe Checkout with Formit

Hi there,

I’m trying to work out using Stripe checkout as a hook to Formit, but really have no idea how to do it.
https://stripe.com/docs/checkout/integration-builder

Has anyone tried this? Thank you in advance.

Hi there, stripe integration has 2 steps, the first one, it’s basically JS, which you use to render your secure checkout elements, then you’ll need a PHP (secure component), to process when a user clicks submit, and send the data from your secure components to your backend, then to stripe.

These steps are taken in order to avoid web user tampering with data, in the back end, you can check that all values are correct before sending the transaction to stripe.

On a final note, in many cases it’s important to store the transaction results, I’ll suggest having an additional “transactions” table where you can record trxs details and responses.

In the integration builder window, make sure you have selected PHP as your language, and it’ll give you the exact code you need, make sure you read the api key from system params instead of having it in the code, but everything else should be fairly simple

Thank you for the advise. I’m not familiar with PHP, not sure how to make those php to be a hook for Formit.

It would be tough to build a Stripe integration without knowing PHP.
If you’re looking for a pre-built integration, you could have a look at:

They both accept payments via Stripe (and many other options).

Oh, there’s also EasyCart which is a hosted shopping cart platform for MODX.
I’m not sure as to whether they include Stripe as an option however:

Note that Commerce uses the PaymentIntents integration for stripe, rather than Stripe Checkout.

PI keeps customers on-site for credit card payments within the checkout provided by Commerce, while Stripe Checkout replaces that entire flow. Each approach has pros and cons but Stripe is awesome either way. :wink:

Thank you Murray and Mark. I think the whole ecommerce system is a bit overwhelming for me. I just want a simple form selling a few online services. I already managed to get it done with Stripe V2, using the hook as per this post https://forums.modx.com/thread/104750/stripe-formit-integration, but want to change it to Stripe checkout, because it’s more secure and supports Apple Pay. Any idea that I can adapt the old code to the new one?

The PHP hook code used in your link receives a stripe token from the form (representing the CC details which have already been submitted to Stripe) and creates a charge. If successful, it allows the form to complete.

I just had a look through the Checkout code.
Integrating Stripe Checkout is a different flow. Instead of the FormIt form submitting and using a hook creating a charge, there’s some ajax and redirecting going on.

When you click the checkout button, the JavaScript sends the product info to your PHP file/snippet and creates a session with Stripe using that info. Once the session is created, the session id is returned to the JavaScript on your product page which then redirects the customer to the Stripe checkout page.

After the payment is successful/failed etc. it will then redirect the customer to your success or failed/cancelled page.

You don’t need FormIt for this and all the code is there if you want to use it “as is”. You’ll just need to create the pages it tells you to and copy the code.

Thanks Murray,

If I use it straight forward and not using FormIt, how can I send the email confirmation to customer and myself?

You can send emails yourself in your PHP code:

Thank you, will try to figure it out.

Hi @fab

You can enable emails on your Stripe account and send payment receipts directly.

If you want your own customised emails however, then that would need to be done with PHP as @halftrainedharry noted above.

Due to the redirect flow of Stripe Checkout it would need to be a snippet attached to your success/failure page. Or a webhook.
This would be rather involved as you’d need to send a request to the Stripe API and get the status and order data, and then send the related emails depending on the response.