Cannot Pass Parameter to Page Flow Via dmx.parse

I have some javascript which uses some dmx.parse commands… the full code is below.

I am trying to make use of the javascript value result.error.message.

My previous code used this successfully to set the value of a variable in Wappler:

 dmx.parse('stripe_error_message.setValue("Sorry, there was an error processing your card payment: ' + result.error.message + '");');

I am now trying to pass this value into a flow so I can do more complex processing, but the value is not being passed in. The code I am using, as you can see below, is:

 dmx.parse("flow_stripe_error.run({stripe_error_message: result.error.message})");

This code is calling the flow, but the value of result.error.message is not being passed through.

Is this a Wappler bug, or am I doing something wrong here?

Best wishes,
Antony.

Full code:

<script>
    // ===================== STRIPE Pay Now - Form Submission ===============================

var form = document.getElementById('payment_form');

form.addEventListener('submit', function (ev) {
	console.log("Submitting Stripe Form...");
	dmx.parse("stripe_error_message.setValue('');");
    ev.preventDefault();
    stripe.confirmCardPayment(dmx.parse("stripe_client_secret.value"), {
        payment_method: {
            card: card,
            billing_details: {
                name: dmx.parse("to_be_paid_by.value"),
            }
        }
    }).then(function (result) {
        if (result.error) {
            // Show error to your customer (e.g., insufficient funds)
			console.log("There was an error processing the card details with Stripe...");
			console.log(result.error.message);
      dmx.parse("flow_stripe_error.run({stripe_error_message: result.error.message})");
      // dmx.parse("processing_status.setValue('stripe_error');"); // GOOD
			// dmx.parse('stripe_error_message.setValue("Sorry, there was an error processing your card payment: ' + result.error.message + '");'); // GOOD!
		} else {
            // The payment has been processed!
			console.log('result.paymentIntent.status: ' + result.paymentIntent.status);
            if (result.paymentIntent.status === 'succeeded') {
				console.log("Payment Successful.");
                dmx.parse("flow_payment_success.run();");
                // 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.
            }
        }
    });
});


  </script>

Here is the code of the flow…

<script is="dmx-flow" id="flow_stripe_error" type="text/dmx-flow">{
  meta: {
    $param: [
      {type: "text", name: "stripe_error_message"}
    ]
  },
  exec: {
    steps: [
      {
        run: {action: "{{processing_status.setValue('stripe_error')}}"}
      },
      {
        bootbox.alert: {message: "stripe_error_message: {{$param.stripe_error_message}}"}
      },
      {
        run: {
          action: "{{stripe_error_message.setValue('There was an error processing your card payment: '+$param.stripe_error_message)}}"
        }
      },
      {
        condition: {
          if: "{{$param.stripe_error_message.contains('pk_test')}}",
          then: {
            steps: {
              run: {
                action: "{{stripe_error_message.setValue('There was an error processing your card payment which we have been made aware of. Please try again later or book using another payment method.')}}"
              }
            }
          }
        }
      }
    ]
  }
}</script>

Try this

dmx.parse("flow_stripe_error.run({stripe_error_message: ‘“ + result.error.message + “‘})");

You’re up early Ken! :slight_smile:
So a single AND a double quote? I don’t follow the logic of this syntax but I’ll give it a go!

You are building up a string for dmx parse which is the double quote. The single quote is to quote the value you are passing. The single quotes become part of the parse string.

Ken, you are a genius beyond words… :innocent: it works perfectly, THANK YOU!

Time to enjoy your breakfast now! :slight_smile:

1 Like

:coffee:.

1 Like

Okay @mebeingken, here is another challenge on this same piece of code…

Sometimes the string contained within result.error.message contains a ' character, and it causes Wappler to fail the call to the flow.

What would you say is the best way to handle that? Can I escape the ' somehow in the javascript and then unescape it within the flow? :thinking:

Yes, experiment with escaping that character:

Try this:

result.error.message.replace("'","\'")

I haven’t tested, so if this doesn’t work, I can try to recreate and test.

You star Ken! :slight_smile:

It still didn’t work, so I just did a replace of ' with empty string… whether the message says “your card’s” or “your cards” really doesn’t matter too much!

Try with

result.error.message.replace("'","&#39;")

And if Jon’s doesn’t work, try adding another backslash.

1 Like

dmx.parse works in live app connect but not in browser. Need help to get it working.