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

feat: make MMA aware of new Stripe Membership USA account #1371

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 16 additions & 0 deletions client/__tests__/components/payment/stripe.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
guardianWeeklySubscriptionAustralia,
guardianWeeklySubscriptionCard,
guardianWeeklySubscriptionUnitedStates,
} from '../../../fixtures/subscription';
import { getStripeKey } from '../../../utilities/stripe';

Expand All @@ -10,6 +11,10 @@ window.guardian = {
test: 'testKeyAustralia',
default: 'defaultKeyAustralia',
},
stripeKeyUnitedStates: {
test: 'testKeyUnitedStates',
default: 'defaultKeyUnitedStates',
},
stripeKeyDefaultCurrencies: {
test: 'testKeyDefaultCurrencies',
default: 'defaultKeyDefaultCurrencies',
Expand Down Expand Up @@ -37,3 +42,14 @@ test('Uses Australian Stripe key for Australian delivery address', () => {
window.guardian.stripeKeyAustralia?.default,
);
});

test('Uses United States Stripe key for United States delivery address', () => {
const stripePublicKey = getStripeKey(
guardianWeeklySubscriptionUnitedStates.deliveryAddress?.country,
Copy link
Member

Choose a reason for hiding this comment

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

why create the whole guardianWeeklySubscriptionUnitedStates object only to pick out just the delivery country?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks John - I have refactored here: 28d8365

false,
);

expect(stripePublicKey).toEqual(
window.guardian.stripeKeyUnitedStates?.default,
);
});
54 changes: 54 additions & 0 deletions client/fixtures/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,60 @@ export const guardianWeeklySubscriptionAustralia: Subscription = {
deliveryAddressChangeEffectiveDate: '2021-12-24',
};

export const guardianWeeklySubscriptionUnitedStates: Subscription = {
paymentMethod: 'Card',
card: {
last4: '4242',
expiry: {
month: 3,
year: 2033,
},
type: 'Visa',
stripePublicKeyForUpdate: 'pk_test_123',
Copy link
Member

Choose a reason for hiding this comment

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

I haven't traced the code fully, but it seems like the public key is coming from MDAPI in some? cases and it would be based off the billing country. https://github.com/guardian/members-data-api/blob/7094e7fd2927c97101fa11c7b29050aa55afd31b/membership-attribute-service/app/services/AccountDetailsFromZuora.scala#L52

If it's all tested with GW and other products and works ok then it's probably ok, I think GW is the most tricky with the billing vs delivery country plus currencies. (we lock the delivery country and currency together IIRC so that people definitely pay the right price)

email: 'test.user@example.com',
},
contactId: '0039E00001KA26BQAT',
deliveryAddress: {
addressLine1: 'Kings Place',
addressLine2: '90 York Way',
town: 'New York',
region: 'NY',
postcode: '10001',
country: 'United States',
},
safeToUpdatePaymentMethod: true,
start: '2021-12-24',
end: '2022-12-15',
nextPaymentPrice: 3250,
nextPaymentDate: '2021-12-24',
lastPaymentDate: null,
potentialCancellationDate: null,
chargedThroughDate: null,
renewalDate: '2022-12-15',
anniversaryDate: '2022-12-24',
cancelledAt: false,
subscriptionId: 'A-S00293857',
trialLength: 9,
autoRenew: true,
currentPlans: [],
futurePlans: [
{
name: null,
start: '2021-12-24',
end: '2022-12-15',
shouldBeVisible: true,
chargedThrough: null,
price: 3250,
currency: '$',
currencyISO: 'AUD',
billingPeriod: 'month',
},
],
readerType: 'Direct',
accountId: '8ad0965d7dbcc507017dbe20afd33ac4',
deliveryAddressChangeEffectiveDate: '2021-12-24',
};

export const digitalSubscriptionDD: Subscription = {
paymentMethod: 'DirectDebit',
account: {
Expand Down
5 changes: 5 additions & 0 deletions client/utilities/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export function getStripeKey(
? window.guardian?.stripeKeyAustralia?.test
: window.guardian?.stripeKeyAustralia?.default;

case 'United States':
return isTestUser
? window.guardian?.stripeKeyUnitedStates?.test
: window.guardian?.stripeKeyUnitedStates?.default;

default:
return isTestUser
? window.guardian?.stripeKeyDefaultCurrencies?.test
Expand Down
1 change: 1 addition & 0 deletions server/stripeSetupIntentConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface StripePublicKeySet {
}
export interface StripePublicKeys {
stripeKeyAustralia: StripePublicKeySet;
stripeKeyUnitedStates: StripePublicKeySet;
stripeKeyDefaultCurrencies: StripePublicKeySet;
}

Expand Down
1 change: 1 addition & 0 deletions shared/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface Globals extends CommonGlobals {
identityDetails: IdentityDetails;
recaptchaPublicKey?: string;
stripeKeyAustralia?: StripePublicKeySet;
stripeKeyUnitedStates?: StripePublicKeySet;
stripeKeyDefaultCurrencies?: StripePublicKeySet;
}
declare global {
Expand Down
Loading