I thought it might be useful to show how we solved the 3d secure implementation.
Stripe Payment Process
include <script src=“https://js.stripe.com/v3/”></script>
in dom header (Site, Environment, DOM Header Insertions)
Add the following html element to form (uses tailwind classes for styling but could be customised). We use a modal specifically for payments so the paymentIntent can be generated and passed into the modal when it is loaded.
<div id=“card-element” class=” bg-gray-100 border rounded-lg px-2 py-3 sm:p-6 sm:h-16" w-full>
</div>
Run the following javascript on form load (for page/modal containing abover html)
window.stripe = Stripe(app.stripeKey {locale:‘en’});
var elements = window.stripe.elements();
var card = elements.create(‘card’);
window.card = card
card.mount(‘#card-element’);
card.addEventListener(‘change’, function(event) {
_.set(model, ‘payment.cardComplete’, event.complete);
if (event.error) {
_.set(model, ‘payment.errorMsg’, event.error.message);
}else {
_.set(model, ‘payment.errorMsg’, ‘’);
}
});
Generate a payment intent on fms and send back to bf (either on form load or when items to be purchased are confirmed)
Have a payment button which runs the following
window.stripe
.confirmCardPayment(model.paymentIntent.body.client_secret, {
payment_method: {
card: window.card,
}
})
.then(function(result) {
if (result.error) {
console.log(result);
model.payment.stripeResult = result.error.message;
window.EventBus.$emit(‘processNamedAction’, {
“action”: “namedAction”,
“name”: “paymentError”,
“options”: {}
});
}
if (result.paymentIntent) {
model.paid = true;
model.payment.stripeResult = result;
window.EventBus.$emit(‘processNamedAction’, {
“action”: “namedAction”,
“name”: “paymentSuccess”,
“options”: {}
});
}
});
This will emit one of two named actions: paymentSuccess or paymentError
We use keys such as model.paying and model.paid to keep track of how far through the process the client has got, e.g. so buttons can be disabled to prevent double activation.