Skip to content

Commit

Permalink
fix: Remove postal code validation for DPM countries
Browse files Browse the repository at this point in the history
  • Loading branch information
julianajlk committed May 2, 2024
1 parent eef052d commit 7f2b372
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 41 deletions.
9 changes: 4 additions & 5 deletions src/payment/checkout/payment-form/CardHolderInformation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ export class CardHolderInformationComponent extends React.Component {
}

render() {
const { disabled, showBulkEnrollmentFields, isDynamicPaymentMethodsEnabled } = this.props;
const shouldRequirePostalCode = isPostalCodeRequired(this.state.selectedCountry, isDynamicPaymentMethodsEnabled)
&& this.props.enableStripePaymentProcessor;
const { disabled, showBulkEnrollmentFields } = this.props;
const shouldRequirePostalCode = isPostalCodeRequired(
this.state.selectedCountry,
) && this.props.enableStripePaymentProcessor;

return (
<div className="basket-section">
Expand Down Expand Up @@ -277,14 +278,12 @@ CardHolderInformationComponent.propTypes = {
intl: intlShape.isRequired,
disabled: PropTypes.bool,
enableStripePaymentProcessor: PropTypes.bool,
isDynamicPaymentMethodsEnabled: PropTypes.bool,
showBulkEnrollmentFields: PropTypes.bool,
};

CardHolderInformationComponent.defaultProps = {
disabled: false,
enableStripePaymentProcessor: false,
isDynamicPaymentMethodsEnabled: false,
showBulkEnrollmentFields: false,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('<CardHolderInformation />', () => {
fireEvent.change(screen.getByLabelText('Country (required)'), { target: { value: 'US' } });

expect(getCountryStatesMap).toHaveBeenCalledWith('US');
expect(isPostalCodeRequired).toHaveBeenCalledWith('US', false); // DPM enabled added to the call
expect(isPostalCodeRequired).toHaveBeenCalledWith('US');
});
});
describe('purchasedForOrganization field', () => {
Expand Down
1 change: 0 additions & 1 deletion src/payment/checkout/payment-form/StripePaymentForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ const StripePaymentForm = ({
showBulkEnrollmentFields={isBulkOrder}
disabled={submitting}
enableStripePaymentProcessor={enableStripePaymentProcessor}
isDynamicPaymentMethodsEnabled={isDynamicPaymentMethodsEnabled}
/>
<h5 aria-level="2">
<FormattedMessage
Expand Down
37 changes: 3 additions & 34 deletions src/payment/checkout/payment-form/utils/form-validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,10 @@ export const getCountryStatesMap = (country) => {
};

// eslint-disable-next-line import/prefer-default-export
export function isPostalCodeRequired(selectedCountry, isDynamicPaymentMethodsEnabled) {
// Stripe recommends to have state and zip code since it can have a material effect on
export function isPostalCodeRequired(selectedCountry) {
// Stripe recommends to have state and zip code required since it can have a material effect on
// our card authorization rates and fees that the card networks and issuers charge.
// 'CA', 'GB' and 'US' were alreay required prior to implementing Dynamic Payment Methods.
// The Stripe API also requires state and zip code for BNPL options (Affirm, Afterpay, Klarna)
// for the countries that these payment methods are compatible with.
let countryListRequiredPostalCode = [];
if (isDynamicPaymentMethodsEnabled) {
countryListRequiredPostalCode = [
'CA', // Affirm, Afterpay, Klarna
'GB', // Afterpay, Klarna
'US', // Affirm, Afterpay, Klarna
'AU', // Afterpay, Klarna
'AT', // Klarna
'BE', // Klarna
'CH', // Klarna
'CZ', // Klarna
'DE', // Klarna
'DK', // Klarna
'ES', // Klarna
'FI', // Klarna
'FR', // Klarna
'GR', // Klarna
'IE', // Klarna
'IT', // Klarna
'NL', // Klarna
'NO', // Klarna
'NZ', // Afterpay, Klarna
'PL', // Klarna
'PT', // Klarna
'SE', // Klarna
];
} else {
countryListRequiredPostalCode = ['CA', 'GB', 'US'];
}
const countryListRequiredPostalCode = ['CA', 'GB', 'US'];

const postalCodeRequired = countryListRequiredPostalCode.includes(selectedCountry);

Expand Down

0 comments on commit 7f2b372

Please sign in to comment.