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:
parent
5a1fa6fdf4
commit
e185c1ee47
1 changed files with 33 additions and 1 deletions
|
@ -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
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue