Added support for dynamic stripe checkout redirects

no-issue

You can now use `data-members-success` and `data-members-cancel` on any
element which also has a valid `data-members-plan` attribute to set the
cancel and success redirects for stripe checkout.

The value will be used similar to how a `href` attribute would be.

e.g.

On a page https://site.com/membership

An attribute of "/success" would redirect to https://site.com/success
An attribute of "success" would redirect to https://site.com/membership/success
An attribute of "https://site.com/whatever" would redirect to https://site.com/whatever
This commit is contained in:
Fabien O'Carroll 2019-10-03 17:27:03 +07:00
parent cb431d758b
commit d4f71ade11

View File

@ -54,6 +54,18 @@ Array.prototype.forEach.call(document.querySelectorAll('[data-members-plan]'), f
event.preventDefault();
var plan = el.dataset.membersPlan;
var successUrl = el.dataset.membersSuccess;
var cancelUrl = el.dataset.membersCancel;
var checkoutSuccessUrl;
var checkoutCancelUrl;
if (successUrl) {
checkoutSuccessUrl = (new URL(successUrl, window.location.href)).href;
}
if (cancelUrl) {
checkoutCancelUrl = (new URL(cancelUrl, window.location.href)).href;
}
if (errorEl) {
errorEl.innerText = '';
@ -74,7 +86,9 @@ Array.prototype.forEach.call(document.querySelectorAll('[data-members-plan]'), f
},
body: JSON.stringify({
plan: plan,
identity: identity
identity: identity,
successUrl: checkoutSuccessUrl,
cancelUrl: checkoutCancelUrl
})
}).then(function (res) {
if (!res.ok) {