Added stripe url handling for checkout success

refs https://github.com/TryGhost/membersjs/issues/10

We use stripe query param `?stripe=<state>` for redirects from checkout session, this handles the magic link popup for checkout success state on redirect.
This commit is contained in:
Rish 2020-04-30 11:55:16 +05:30
parent 712ac5cd74
commit f813185cc3

View File

@ -25,28 +25,39 @@ export default class ParentContainer extends React.Component {
};
}
getStripeUrlParam() {
const url = new URL(window.location);
return url.searchParams.get('stripe');
}
componentDidMount() {
this.fetchData();
}
getDefaultPage(member) {
getDefaultPage({member, stripeParam}) {
// Change page here for testing local UI testing
if (process.env.NODE_ENV === 'development') {
return 'accountHome';
return {page: 'accountHome'};
}
return member ? 'accountHome' : 'signup';
if (!member && stripeParam === 'success') {
return {page: 'magiclink', showPopup: true};
}
return {
page: member ? 'accountHome' : 'signup'
};
}
async fetchApiData(adminUrl) {
try {
this.GhostApi = setupGhostApi({adminUrl});
let {site, member} = await this.GhostApi.init();
const {site, member} = await this.GhostApi.init();
const stripeParam = this.getStripeUrlParam();
const {page, showPopup = false} = this.getDefaultPage({member, stripeParam});
this.setState({
site,
member,
page: this.getDefaultPage(member),
page,
showPopup,
action: 'init:success',
initStatus: 'success'
});