0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

Added edit stripe billing api method

refs https://github.com/TryGhost/members.js/issues/20

- Adds new editBilling method for stripe update billing info checkout flow
This commit is contained in:
Rish 2020-05-08 18:32:22 +05:30
parent 5a1fa6fdf4
commit e185c1ee47

View file

@ -127,7 +127,39 @@ function setupGhostApi() {
}
return res.json();
}).then(function (result) {
var stripe = window.Stripe(result.publicKey);
const stripe = window.Stripe(result.publicKey);
return stripe.redirectToCheckout({
sessionId: result.sessionId
});
}).then(function (result) {
if (result.error) {
throw new Error(result.error.message);
}
}).catch(function (err) {
throw err;
});
},
async editBilling() {
const identity = await api.member.identity();
const url = endpointFor({type: 'members', resource: 'create-stripe-update-session'});
return makeRequest({
url,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
identity: identity
})
}).then(function (res) {
if (!res.ok) {
throw new Error('Could not create stripe checkout session');
}
return res.json();
}).then(function (result) {
const stripe = window.Stripe(result.publicKey);
return stripe.redirectToCheckout({
sessionId: result.sessionId
});