Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,31 @@ describe('BraintreeFastlaneUtils', () => {
);
});

it('does not authenticate customer if profileData is undefined', async () => {
jest.spyOn(
braintreeFastlaneMock.identity,
'triggerAuthenticationFlow',
).mockResolvedValue({
authenticationState: BraintreeFastlaneAuthenticationState.FAILED,
profileData: undefined,
});

const updatePaymentProviderCustomerPayload = {
authenticationState: BraintreeFastlaneAuthenticationState.FAILED,
addresses: [],
instruments: [],
};

await subject.initializeBraintreeFastlaneOrThrow(methodId, undefined);
await subject.runPayPalAuthenticationFlowOrThrow();

expect(CookieStorage.remove).toHaveBeenCalledWith('bc-fastlane-sessionId');
expect(braintreeFastlaneMock.identity.triggerAuthenticationFlow).toHaveBeenCalled();
expect(paymentIntegrationService.updatePaymentProviderCustomer).toHaveBeenCalledWith(
updatePaymentProviderCustomerPayload,
);
});

it('preselects billing address with first paypal fastlane billing address', async () => {
await subject.initializeBraintreeFastlaneOrThrow(methodId, undefined);
await subject.runPayPalAuthenticationFlowOrThrow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ export default class BraintreeFastlaneUtils {

const phoneNumber = profileData?.shippingAddress?.phoneNumber || '';

if (authenticationState === BraintreeFastlaneAuthenticationState.CANCELED) {
if (
authenticationState === BraintreeFastlaneAuthenticationState.CANCELED ||
!profileData
) {
await this.paymentIntegrationService.updatePaymentProviderCustomer({
authenticationState,
addresses: [],
Expand Down
4 changes: 2 additions & 2 deletions packages/braintree-utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,13 +515,13 @@ export interface BraintreeFastlaneStylesOption {
export enum BraintreeFastlaneAuthenticationState {
SUCCEEDED = 'succeeded',
FAILED = 'failed',
CANCELED = 'cancelled',
CANCELED = 'canceled',
UNRECOGNIZED = 'unrecognized',
}

export interface BraintreeFastlaneAuthenticationCustomerResult {
authenticationState: BraintreeFastlaneAuthenticationState;
profileData: BraintreeFastlaneProfileData;
profileData?: BraintreeFastlaneProfileData;
}

export interface BraintreeFastlaneProfileData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,42 @@ describe('BraintreeFastlaneShippingStrategy', () => {
});
});

it('update payment provider customer with empty addresses if profileData is undefined', async () => {
const updatePaymentProviderCustomerMock = jest.fn();

const lookupCustomerByEmailMock = () => ({ customerContextId: 'asd' });
const triggerAuthenticationFlowMock = jest.fn().mockImplementation(() => ({
authenticationState: BraintreeFastlaneAuthenticationState.FAILED,
profileData: undefined,
}));

jest.spyOn(braintreeIntegrationServiceMock, 'getBraintreeFastlane').mockImplementation(
() => ({
identity: {
lookupCustomerByEmail: lookupCustomerByEmailMock,
triggerAuthenticationFlow: triggerAuthenticationFlowMock,
},
}),
);

jest.spyOn(
paymentProviderCustomerActionCreator,
'updatePaymentProviderCustomer',
).mockImplementation(updatePaymentProviderCustomerMock);

const strategy = createStrategy();

await strategy.initialize(defaultOptions);

expect(triggerAuthenticationFlowMock).toHaveBeenCalled();
expect(CookieStorage.remove).toHaveBeenCalledWith('bc-fastlane-sessionId');
expect(updatePaymentProviderCustomerMock).toHaveBeenCalledWith({
authenticationState: BraintreeFastlaneAuthenticationState.FAILED,
addresses: [],
instruments: [],
});
});

it('update billing address for digital product', async () => {
const updatePaymentProviderCustomerMock = jest.fn();
const updateBillingAddressMock = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export default class BraintreeFastlaneShippingStrategy implements ShippingStrate
customerContextId,
);

if (authenticationState === BraintreeFastlaneAuthenticationState.CANCELED) {
if (authenticationState === BraintreeFastlaneAuthenticationState.CANCELED || !profileData) {
await this._store.dispatch(
this._paymentProviderCustomerActionCreator.updatePaymentProviderCustomer({
authenticationState,
Expand Down