Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow one click upsell for the plan upgrade nudge #47774

Merged
merged 5 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions client/my-sites/checkout/checkout/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export class Checkout extends React.Component {
}
}

getCheckoutCompleteRedirectPath = ( shouldHideUpsellNudges = false ) => {
getCheckoutCompleteRedirectPath = ( shouldHideUpsellNudges = false, currentRecieptId ) => {
// TODO: Cleanup and simplify this function.
// I wouldn't be surprised if it doesn't work as intended in some scenarios.
// Especially around the Concierge / Checklist logic.
Expand Down Expand Up @@ -285,15 +285,19 @@ export class Checkout extends React.Component {
}
}

// Note: this function is called early on for redirect-type payment methods, when the receipt isn't set yet.
// The `:receiptId` string is filled in by our callback page after the PayPal checkout
let pendingOrReceiptId;

if ( get( stepResult, 'receipt_id', false ) ) {
if ( currentRecieptId && ! isNaN( currentRecieptId ) ) {
//The relevant receipt Id can be passed in by the checkoutComplete
//command whenever applicable and takes highest precedence
//Specially used in one click upsell (i.e. calypso/my-sites/checkout/upsell-nudge/purchase-modal/util.js::onComplete callback)
pendingOrReceiptId = currentRecieptId;
} else if ( get( stepResult, 'receipt_id', false ) ) {
pendingOrReceiptId = stepResult.receipt_id;
} else if ( get( stepResult, 'orderId', false ) ) {
pendingOrReceiptId = 'pending/' + stepResult.orderId;
} else {
// Note: this function is called early on for redirect-type payment methods, when the receipt isn't set yet.
// The `:receiptId` string is filled in by our callback page after the PayPal checkout
pendingOrReceiptId = this.props.purchaseId ? this.props.purchaseId : ':receiptId';
}

Expand Down Expand Up @@ -377,7 +381,7 @@ export class Checkout extends React.Component {
window.location.href = redirectUrl;
}

handleCheckoutCompleteRedirect = ( shouldHideUpsellNudges = false ) => {
handleCheckoutCompleteRedirect = ( shouldHideUpsellNudges = false, currentRecieptId ) => {
let product;
let purchasedProducts;
let renewalItem;
Expand All @@ -391,7 +395,10 @@ export class Checkout extends React.Component {
translate,
} = this.props;

const redirectPath = this.getCheckoutCompleteRedirectPath( shouldHideUpsellNudges );
const redirectPath = this.getCheckoutCompleteRedirectPath(
shouldHideUpsellNudges,
currentRecieptId
);
const destinationFromCookie = retrieveSignupDestination();

this.props.clearPurchases();
Expand Down
10 changes: 7 additions & 3 deletions client/my-sites/checkout/upsell-nudge/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,12 @@ export class UpsellNudge extends React.Component {

isEligibleForOneClickUpsell = ( buttonAction ) => {
const { cards, siteSlug, upsellType } = this.props;
const supportedUpsellTypes = [ 'concierge-quickstart-session', 'premium-plan-upgrade-upsell' ];

const supportedUpsellTypes = [
CONCIERGE_QUICKSTART_SESSION,
PREMIUM_PLAN_UPGRADE_UPSELL,
BUSINESS_PLAN_UPGRADE_UPSELL,
];
if ( 'accept' !== buttonAction || ! supportedUpsellTypes.includes( upsellType ) ) {
return false;
}
Expand All @@ -251,8 +255,8 @@ export class UpsellNudge extends React.Component {
return true;
};

handleOneClickUpsellComplete = () => {
this.props.handleCheckoutCompleteRedirect( true );
handleOneClickUpsellComplete = ( currentRecieptId ) => {
this.props.handleCheckoutCompleteRedirect( true, currentRecieptId );
};

renderPurchaseModal = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function useSubmitTransaction( {
persistent: true,
} );
recordTracksEvent( 'calypso_oneclick_upsell_payment_success', {} );
onComplete?.();
onComplete?.( data?.receipt_id );
}
} );
}, [ cart, storedCard, setStep, onClose, onComplete, successMessage ] );
Expand Down