mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-03 00:15:11 +03:00
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:
parent
cb431d758b
commit
d4f71ade11
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user