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

One time checkout - get user type #6560

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

andrewHEguardian
Copy link
Contributor

@andrewHEguardian andrewHEguardian commented Nov 22, 2024

What are you doing in this PR?

Returning the identity user type for one time payments through the API, and using this information on the client to set a URL param on the thank you page.

This client side solution does not work for PayPal, as we redirect them to the site and can't set the URL params

How to test

Use the new one time checkout and see "userType=x" when redirected to the thank you page.

I used the always authenticate card to simulate 3DS, as that makes an additional API call

Screenshots

image

Copy link
Contributor

github-actions bot commented Nov 22, 2024

Size Change: +87 B (0%)

Total Size: 2.22 MB

ℹ️ View Unchanged
Filename Size Change
./public/compiled-assets/javascripts/[countryGroupId]/events/router.js 89.9 kB 0 B
./public/compiled-assets/javascripts/[countryGroupId]/router.js 254 kB +36 B (+0.01%)
./public/compiled-assets/javascripts/ausMomentMap.js 108 kB 0 B
./public/compiled-assets/javascripts/contributionsRedirectStyles.js 20 B 0 B
./public/compiled-assets/javascripts/digitalSubscriptionLandingPage.js 235 kB +28 B (+0.01%)
./public/compiled-assets/javascripts/downForMaintenancePage.js 70.2 kB 0 B
./public/compiled-assets/javascripts/error404Page.js 70.2 kB 0 B
./public/compiled-assets/javascripts/error500Page.js 70.1 kB 0 B
./public/compiled-assets/javascripts/favicons.js 617 B 0 B
./public/compiled-assets/javascripts/paperSubscriptionCheckoutPage.js 174 kB 0 B
./public/compiled-assets/javascripts/paperSubscriptionLandingPage.js 87 kB 0 B
./public/compiled-assets/javascripts/payPalErrorPage.js 68.4 kB 0 B
./public/compiled-assets/javascripts/payPalErrorPageStyles.js 20 B 0 B
./public/compiled-assets/javascripts/promotionTerms.js 73.1 kB 0 B
./public/compiled-assets/javascripts/subscriptionsLandingPage.js 72.4 kB 0 B
./public/compiled-assets/javascripts/subscriptionsRedemptionPage.js 126 kB 0 B
./public/compiled-assets/javascripts/supporterPlusLandingPage.js 306 kB +23 B (+0.01%)
./public/compiled-assets/javascripts/unsupportedBrowserStyles.js 20 B 0 B
./public/compiled-assets/javascripts/weeklySubscriptionCheckoutPage.js 171 kB 0 B
./public/compiled-assets/javascripts/weeklySubscriptionLandingPage.js 86.9 kB 0 B
./public/compiled-assets/webpack/136.js 2.17 kB 0 B
./public/compiled-assets/webpack/187.js 21.4 kB 0 B
./public/compiled-assets/webpack/344.js 2.01 kB 0 B
./public/compiled-assets/webpack/643.js 22.4 kB 0 B
./public/compiled-assets/webpack/706.js 107 kB 0 B

compressed-size-action

@andrewHEguardian andrewHEguardian changed the title One time user type One time checkout - get user type Nov 22, 2024
@andrewHEguardian andrewHEguardian marked this pull request as ready for review November 22, 2024 16:02
@@ -147,7 +148,10 @@ function paymentResultFromObject(
});
}

return Promise.resolve(PaymentSuccess);
const response = json as { data?: { userType: UserType } };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Admittedly a bit of a bodge 🤷‍♂️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth writing a zod schema to validate this, rather than casting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that would be ideal, there's another cast in this function so definitely a worthwhile refactor

Copy link
Member

@tjmw tjmw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! 👍

I left a few minor comments/questions but they aren't blockers.

@@ -147,7 +148,10 @@ function paymentResultFromObject(
});
}

return Promise.resolve(PaymentSuccess);
const response = json as { data?: { userType: UserType } };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth writing a zod schema to validate this, rather than casting?

@@ -463,6 +463,9 @@ export function OneTimeCheckoutComponent({
});
const thankYouUrlSearchParams = new URLSearchParams();
thankYouUrlSearchParams.set('contribution', finalAmount.toString());
'paymentStatus' in paymentResult &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to check this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

paymentResult could be PaymentResult | CreatePayPalPaymentResponse. userType isn't on the payPal type (although possibly could be). So it's a way of type switching that we use further down too

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Really sorry if I'm missing something obvious!) Should it not be 'userType' in paymentResult in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that makes more sense, it was a copy paste from below - my initial intent was to add it to PayPalResponse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants