Skip to content

Commit 75eb86a

Browse files
committed
fix(payment): CHECKOUT-3138 Fix Braintree Paypal cart flow initialization
1 parent 1a068ef commit 75eb86a

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/payment/strategies/braintree/braintree-paypal-payment-strategy.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,25 @@ describe('BraintreePaypalPaymentStrategy', () => {
118118
checkoutMock.getCart = jest.fn(() => getCart());
119119
checkoutMock.getBillingAddress = jest.fn(() => getBillingAddress());
120120
checkoutMock.getConfig = jest.fn(() => getAppConfig().storeConfig);
121-
122-
return braintreePaypalPaymentStrategy.initialize(options);
123121
});
124122

125123
it('calls submit order with the order request information', async () => {
124+
await braintreePaypalPaymentStrategy.initialize(options);
126125
await braintreePaypalPaymentStrategy.execute(orderRequestBody, options);
127126

128127
expect(orderActionCreator.submitOrder).toHaveBeenCalledWith(omit(orderRequestBody, 'payment'), expect.any(Boolean), expect.any(Object));
129128
expect(store.dispatch).toHaveBeenCalledWith(submitOrderAction);
130129
});
131130

132131
it('asks for cart verification', async () => {
132+
await braintreePaypalPaymentStrategy.initialize(options);
133133
await braintreePaypalPaymentStrategy.execute(orderRequestBody, options);
134134

135135
expect(orderActionCreator.submitOrder).toHaveBeenCalledWith(expect.any(Object), true, expect.any(Object));
136136
});
137137

138138
it('pass the options to submitOrder', async () => {
139+
await braintreePaypalPaymentStrategy.initialize(options);
139140
await braintreePaypalPaymentStrategy.execute(orderRequestBody, options);
140141

141142
expect(orderActionCreator.submitOrder).toHaveBeenCalledWith(expect.any(Object), expect.any(Boolean), options);
@@ -151,6 +152,7 @@ describe('BraintreePaypalPaymentStrategy', () => {
151152
},
152153
};
153154

155+
await braintreePaypalPaymentStrategy.initialize(options);
154156
await braintreePaypalPaymentStrategy.execute(orderRequestBody, options);
155157

156158
expect(braintreePaymentProcessorMock.paypal).toHaveBeenCalledWith(190, 'en_US', 'USD', false);
@@ -179,6 +181,7 @@ describe('BraintreePaypalPaymentStrategy', () => {
179181
it('converts any error returned by braintree in a StandardError', async () => {
180182
braintreePaymentProcessorMock.paypal = () => Promise.reject({ name: 'BraintreeError', message: 'my_message'});
181183

184+
await braintreePaypalPaymentStrategy.initialize(options);
182185
await expect(braintreePaypalPaymentStrategy.execute(orderRequestBody, options)).rejects.toEqual(expect.any(StandardError));
183186
});
184187

src/payment/strategies/braintree/braintree-paypal-payment-strategy.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ export default class BraintreePaypalPaymentStrategy extends PaymentStrategy {
2626

2727
initialize(options: PaymentInitializeOptions): Promise<CheckoutSelectors> {
2828
const { braintree: braintreeOptions, methodId } = options;
29-
const { nonce } = this._store.getState().checkout.getPaymentMethod(methodId) || { nonce: undefined };
3029

31-
if (nonce) {
30+
this._paymentMethod = this._store.getState().checkout.getPaymentMethod(methodId);
31+
32+
if (this._paymentMethod && this._paymentMethod.nonce) {
3233
return super.initialize(options);
3334
}
3435

0 commit comments

Comments
 (0)