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

Updated portal stripe actions

no refs

- Updates stripe actions via portal to use custom parameter values to show notifications
- Updated parameter don't interfere with existing theme notifications
This commit is contained in:
Rish 2020-11-20 10:27:06 +05:30
parent 9dac6d9435
commit 4dc22ca568
3 changed files with 11 additions and 11 deletions

View file

@ -188,9 +188,9 @@ export default class Notification extends React.Component {
const type = this.state.type; const type = this.state.type;
const deleteParams = []; const deleteParams = [];
if (['signin', 'signup'].includes(type)) { if (['signin', 'signup'].includes(type)) {
deleteParams.push('action', 'portal-action', 'success'); deleteParams.push('portal-action', 'success');
} else if (['stripe:checkout'].includes(type)) { } else if (['stripe:checkout'].includes(type)) {
deleteParams.push('stripe', 'portal-stripe'); deleteParams.push('stripe');
} }
clearURLParams(deleteParams); clearURLParams(deleteParams);
this.setState({ this.setState({

View file

@ -130,13 +130,13 @@ function setupGhostApi({siteUrl = window.location.origin}) {
const url = endpointFor({type: 'members', resource: 'create-stripe-checkout-session'}); const url = endpointFor({type: 'members', resource: 'create-stripe-checkout-session'});
if (!successUrl) { if (!successUrl) {
const checkoutSuccessUrl = new URL(siteUrl); const checkoutSuccessUrl = new URL(siteUrl);
checkoutSuccessUrl.searchParams.set('portal-stripe', 'success'); checkoutSuccessUrl.searchParams.set('stripe', 'portal-success');
successUrl = checkoutSuccessUrl.href; successUrl = checkoutSuccessUrl.href;
} }
if (!cancelUrl) { if (!cancelUrl) {
const checkoutCancelUrl = new URL(siteUrl); const checkoutCancelUrl = new URL(siteUrl);
checkoutCancelUrl.searchParams.set('portal-stripe', 'cancel'); checkoutCancelUrl.searchParams.set('stripe', 'portal-cancel');
cancelUrl = checkoutCancelUrl.href; cancelUrl = checkoutCancelUrl.href;
} }
return makeRequest({ return makeRequest({
@ -181,13 +181,13 @@ function setupGhostApi({siteUrl = window.location.origin}) {
const url = endpointFor({type: 'members', resource: 'create-stripe-update-session'}); const url = endpointFor({type: 'members', resource: 'create-stripe-update-session'});
if (!successUrl) { if (!successUrl) {
const checkoutSuccessUrl = new URL(siteUrl); const checkoutSuccessUrl = new URL(siteUrl);
checkoutSuccessUrl.searchParams.set('portal-stripe', 'success'); checkoutSuccessUrl.searchParams.set('stripe', 'portal-billing-update-success');
successUrl = checkoutSuccessUrl.href; successUrl = checkoutSuccessUrl.href;
} }
if (!cancelUrl) { if (!cancelUrl) {
const checkoutCancelUrl = new URL(siteUrl); const checkoutCancelUrl = new URL(siteUrl);
checkoutCancelUrl.searchParams.set('portal-stripe', 'cancel'); checkoutCancelUrl.searchParams.set('stripe', 'portal-billing-update-cancel');
cancelUrl = checkoutCancelUrl.href; cancelUrl = checkoutCancelUrl.href;
} }
return makeRequest({ return makeRequest({

View file

@ -12,8 +12,8 @@ export const handleAuthActions = ({qsParams, action, status}) => {
}; };
export const handleStripeActions = ({status, billingOnly}) => { export const handleStripeActions = ({status, billingOnly}) => {
if (!billingOnly && ['success'].includes(status)) { if (!billingOnly && ['portal-success'].includes(status)) {
const statusVal = status === 'success' ? 'success' : 'warning'; const statusVal = status === 'portal-success' ? 'success' : 'warning';
return { return {
type: 'stripe:checkout', type: 'stripe:checkout',
status: statusVal, status: statusVal,
@ -22,8 +22,8 @@ export const handleStripeActions = ({status, billingOnly}) => {
}; };
} }
if (billingOnly && ['billing-update-success', 'billing-update-cancel'].includes(status)) { if (billingOnly && ['portal-billing-update-success', 'portal-billing-update-cancel'].includes(status)) {
const statusVal = status === 'billing-update-success' ? 'success' : 'warning'; const statusVal = status === 'portal-billing-update-success' ? 'success' : 'warning';
return { return {
type: 'stripe:billing-update', type: 'stripe:billing-update',
status: statusVal, status: statusVal,
@ -53,7 +53,7 @@ export default function NotificationParser({billingOnly = false} = {}) {
const qsParams = new URLSearchParams(qs); const qsParams = new URLSearchParams(qs);
const action = qsParams.get('portal-action'); const action = qsParams.get('portal-action');
const successStatus = qsParams.get('success'); const successStatus = qsParams.get('success');
const stripeStatus = qsParams.get('stripe') || qsParams.get('portal-stripe'); const stripeStatus = qsParams.get('stripe');
let notificationData = null; let notificationData = null;
if (stripeStatus) { if (stripeStatus) {