What Attributes Should I Set on a Stripe Submit Payment Form?

I’m working on a Stripe payment form, and documenting my experience as a tutorial along the way… see the links below!

I have some Wappler geeky questions about how to set up the form… maybe @Teodor or @patrick could answer these?

So to interface wtih Stripe, the form submit action happens through javascript code supplied by Stripe, rather than through a Server Action in Wappler. I have pasted the format of the code they supply below.

Question 1 - Page Refresh on Form Submission.

I’ve found that when the form is submitted in Wappler, the submit fails and the page is refreshed. I can prevent this by adding the attribute is="dmx-serverconnect-form" to the form… with this added, the form submit correctly and the page is not refreshed.

Is this behaviour supported by design in Wappler, or have I stumbled across something which could change in the future?

Question 2 - Adding a Spinner

I’d like to add a spinner to the [Pay Now] Button, but it isn’t selectable to show for state.executing in Wappler as the form does not have a server action. I’ve tried adding the spinner like this:

<span class="spinner-border spinner-border-sm text-light" role="status" dmx-show="state.executing"></span>

But it doesn’t spin during execution. How can I get my spinner to spin?

Many thanks!

Antony.

================= Stripe Supplied Form =================

<form id="payment-form">
  <div id="card-element">
    <!-- Elements will create input elements here -->
  </div>

  <!-- We'll put the error messages in this element -->
  <div id="card-errors" role="alert"></div>

  <button id="submit">Pay</button>
</form>

============= Stripe Supplied Javascript on form submit ==========

var form = document.getElementById('payment-form');

form.addEventListener('submit', function (ev) {
    ev.preventDefault();
    stripe.confirmCardPayment(clientSecret, {   
        payment_method: {
            card: card,
            billing_details: {
                name: 'Jenny Rosen'
            }
        }
    }).then(function (result) {
        if (result.error) {
            // Show error to your customer (e.g., insufficient funds)
            console.log(result.error.message);
        } else {
            // The payment has been processed!
            if (result.paymentIntent.status === 'succeeded') {
                // Show a success message to your customer
                // There's a risk of the customer closing the window before callback
                // execution. Set up a webhook or plugin to listen for the
                // payment_intent.succeeded event that handles any business critical
                // post-payment actions.
            }
        }
    });
});

Here are the tutorials… comments welcome! :slight_smile:

Quick thought, have you tried the API form rather than Server connect form? Or has the call got to come from the server?

@max_gb, I’m not sure I understand the question! :slight_smile:

Sorry I should have been more specific, have you tried changing the form in App connect to an API form and then posting to Stripe from there?

Thanks for the clarification!

I’ve only so far followed the Stripe instructions regarding how to submit the payment through javascript. I’m not sure if there is an API option when using Stripe Elements!

Ok, I will have a play…

Great work on the Stripe tutorials Antony!

I think this will get much more easy when we get to integrate the Stripe Elements as native Wappler App Connect components!

Maybe @patrick should add more priority to this.

3 Likes

What?! That got my attention. You guys rock!

2 Likes

The is="dmx-serverconnect-form" is not needed for the stripe form. Adding that attribute will let App Connect handle the submit, but you want the stripe script doing that. Not sure why it would refresh your page, are you sure it is running the script from stripe on submit, perhaps adding a console.log inside it to see if it actually runs.

The state.executing is something from the serverconnect-form, you can set your own executing state. At the start of the submit, directly after ev.preventDefault() add dmx.global.set('stripeExecuting', true), then after }).then(function (result) { you add dmx.global.set('stripeExecuting', false). Then you can use in your spinner dmx-show="stripeExecuting".

1 Like

Hi @George, is this still in the roadmap?

1 Like