CMS Development

AenghasHP
Participant

Sign Up Page - Javascript Redirect

SOLVE

Hi, 

 

We're looking at changing payment providers from ChargeBee over to Stripe. As a part of the swap over we need to change our sign up process, which I've begun on this page (https://npaq.redunion.com.au/join2-2

 

Ideally, customers will fill in their details and based on which option they select for both Employment Status (employmentStatusMap) and Preferred Billing Schedule (billingScheduleMap) it will spit out the correct redirect for the member to pay.

 

For example, if you select Employment Status: Part Time and Billing: Annual it should redirect the user to upon form submission to: https://buy.stripe.com/aEU01Q8gug2y43CdQX

 

I've tried to make this work with the code below, which I think is returning the URL successfully, but then isn't redirecting properly:

 

const stripeRedirect = (employmentStatusMap && billingScheduleMap)
if (employmentStatusMap === "Part Time (<48hrs / fortnight)" && billingScheduleMap === "Annually") {
return window.location = "https://buy.stripe.com/aEU01Q8gug2y43CdQX"
} else {
return window.location = "https://www.redunion.com.au"
}

window.location = stripeRedirect;

 

For context, this is all nested under an onFormSubmit so I believe it should fire when the form is submitted. It might be a bit of an ask, but any guidance on the matter would be much appreciated! Javascript kind of breaks my brain a little bit still.

0 Upvotes
1 Accepted solution
Kevin-C
Solution
Recognized Expert | Partner
Recognized Expert | Partner

Sign Up Page - Javascript Redirect

SOLVE

Hey @AenghasHP 

 

JS can be a hurdle but you're getting close!

We might be missing some context, but I do think you can refactor your code just a bit to get it working.

 

  1. First I might wrap the logic in a function, so I can use it later and/or scale the logic in the future.
  2. Then call the function when needed.

 

This pen might help!

 

Also onFormSubmit will redirect regardless of the form passing validation. I would look at capturing the data in the onFormSubmit event, then listening for the onFormSubmitted event to confirm that the form is valid before performing the redirect.

 

Hope this gets you moving!

Kevin Cornett - Sr. Solutions Architect @ BridgeRev

View solution in original post

0 Upvotes
1 Reply 1
Kevin-C
Solution
Recognized Expert | Partner
Recognized Expert | Partner

Sign Up Page - Javascript Redirect

SOLVE

Hey @AenghasHP 

 

JS can be a hurdle but you're getting close!

We might be missing some context, but I do think you can refactor your code just a bit to get it working.

 

  1. First I might wrap the logic in a function, so I can use it later and/or scale the logic in the future.
  2. Then call the function when needed.

 

This pen might help!

 

Also onFormSubmit will redirect regardless of the form passing validation. I would look at capturing the data in the onFormSubmit event, then listening for the onFormSubmitted event to confirm that the form is valid before performing the redirect.

 

Hope this gets you moving!

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
0 Upvotes