Skip to content

Commit 48e8552

Browse files
refactor(payment): Moved BT Credit card payment strategy
1 parent 32f6203 commit 48e8552

19 files changed

+2349
-22
lines changed

packages/braintree-integration/src/braintree-credit-card/braintree-credit-card-payment-strategy.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import PaymentRequestTransformer from '../../payment-request-transformer';
4646

4747
import BraintreeCreditCardPaymentStrategy from './braintree-credit-card-payment-strategy';
4848
import { BraintreePaymentInitializeOptions } from './braintree-payment-options';
49-
import BraintreePaymentProcessor from './braintree-payment-processor';
49+
import BraintreePaymentProcessor from '../../../braintree-utils/src/braintree-payment-processor';
5050
import { getTokenizeResponseBody } from './braintree.mock';
5151

5252
describe('BraintreeCreditCardPaymentStrategy', () => {

packages/braintree-integration/src/braintree-credit-card/braintree-credit-card-payment-strategy.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { some } from 'lodash';
33
import {
44
BraintreeIntegrationService,
55
isBraintreeAcceleratedCheckoutCustomer,
6+
BraintreePaymentProcessor,
67
} from '@bigcommerce/checkout-sdk/braintree-utils';
78
import {
89
Address,
@@ -62,9 +63,9 @@ export default class BraintreeCreditCardPaymentStrategy implements PaymentStrate
6263
await this.braintreePaymentProcessor.initializeHostedForm(
6364
braintree.form,
6465
braintree.unsupportedCardBrands,
65-
); // TODO: FIX
66+
);
6667
this.isHostedFormInitialized =
67-
this.braintreePaymentProcessor.isInitializedHostedForm(); // TODO: FIX
68+
this.braintreePaymentProcessor.isInitializedHostedForm();
6869
}
6970

7071
this.is3dsEnabled = this.paymentMethod.config.is3dsEnabled;
@@ -89,7 +90,7 @@ export default class BraintreeCreditCardPaymentStrategy implements PaymentStrate
8990
}
9091

9192
if (this.isHostedFormInitialized) {
92-
this.braintreePaymentProcessor.validateHostedForm(); // TODO: FIX
93+
this.braintreePaymentProcessor.validateHostedForm();
9394
}
9495

9596
await this.paymentIntegrationService.submitOrder();
@@ -117,14 +118,8 @@ export default class BraintreeCreditCardPaymentStrategy implements PaymentStrate
117118
async deinitialize(): Promise<void> {
118119
this.isHostedFormInitialized = false;
119120

120-
// await Promise.all([
121-
// // this.braintreePaymentProcessor.deinitialize(), //TODO: FIX
122-
// this.braintreeIntegrationService.teardown(),
123-
// this.braintreePaymentProcessor.deinitializeHostedForm(), //TODO: FIX
124-
// ]);
125-
126-
await this.braintreeIntegrationService.teardown();
127-
await this.braintreePaymentProcessor.deinitializeHostedForm(); //TODO: FIX
121+
await this.braintreeIntegrationService.teardown();
122+
await this.braintreePaymentProcessor.deinitializeHostedForm();
128123

129124
return Promise.resolve();
130125
}
@@ -156,8 +151,8 @@ export default class BraintreeCreditCardPaymentStrategy implements PaymentStrate
156151
isHostedInstrumentLike(paymentData) ? paymentData : {};
157152

158153
const { nonce } = this.shouldPerform3DSVerification(payment)
159-
? await this.braintreePaymentProcessor.verifyCard(payment, billingAddress, orderAmount) //TODO:FIX
160-
: await this.braintreePaymentProcessor.tokenizeCard(payment, billingAddress); //TODO: FIX
154+
? await this.braintreePaymentProcessor.verifyCard(payment, billingAddress, orderAmount)
155+
: await this.braintreePaymentProcessor.tokenizeCard(payment, billingAddress);
161156

162157
return {
163158
...commonPaymentData,
@@ -177,7 +172,7 @@ export default class BraintreeCreditCardPaymentStrategy implements PaymentStrate
177172

178173
if (this.isSubmittingWithStoredCard(payment)) {
179174
const { nonce } =
180-
await this.braintreePaymentProcessor.tokenizeHostedFormForStoredCardVerification(); //TODO: FIX
175+
await this.braintreePaymentProcessor.tokenizeHostedFormForStoredCardVerification();
181176

182177
return {
183178
...commonPaymentData,
@@ -190,11 +185,11 @@ export default class BraintreeCreditCardPaymentStrategy implements PaymentStrate
190185
isHostedInstrumentLike(paymentData) ? paymentData : {};
191186

192187
const { nonce } = this.shouldPerform3DSVerification(payment)
193-
? await this.braintreePaymentProcessor.verifyCardWithHostedForm( //TODO: FIX
188+
? await this.braintreePaymentProcessor.verifyCardWithHostedForm(
194189
billingAddress,
195190
orderAmount,
196191
)
197-
: await this.braintreePaymentProcessor.tokenizeHostedForm(billingAddress); //TODO: FIX
192+
: await this.braintreePaymentProcessor.tokenizeHostedForm(billingAddress);
198193

199194
return {
200195
...commonPaymentData,
@@ -227,7 +222,7 @@ export default class BraintreeCreditCardPaymentStrategy implements PaymentStrate
227222
}
228223

229224
const instrument = state.getCardInstrumentOrThrow(paymentData.instrumentId);
230-
const { nonce } = await this.braintreePaymentProcessor.challenge3DSVerification( //TODO: FIX
225+
const { nonce } = await this.braintreePaymentProcessor.challenge3DSVerification(
231226
{
232227
nonce: storedCreditCardNonce,
233228
bin: instrument.iin,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { PaymentIntegrationService } from '@bigcommerce/checkout-sdk/payment-integration-api';
2+
import { PaymentIntegrationServiceMock } from '@bigcommerce/checkout-sdk/payment-integrations-test-utils';
3+
4+
import createBraintreeCreditCardPaymentStrategy from './create-braintree-credit-card-payment-strategy';
5+
import BraintreeCreditCardPaymentStrategy from './braintree-credit-card-payment-strategy';
6+
7+
describe('createBraintreeCreditCardPaymentStrategy', () => {
8+
let paymentIntegrationService: PaymentIntegrationService;
9+
10+
beforeEach(() => {
11+
paymentIntegrationService = new PaymentIntegrationServiceMock();
12+
});
13+
14+
it('instantiates braintree credit card payment strategy', () => {
15+
const strategy = createBraintreeCreditCardPaymentStrategy(paymentIntegrationService);
16+
17+
expect(strategy).toBeInstanceOf(BraintreeCreditCardPaymentStrategy);
18+
});
19+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { getScriptLoader } from '@bigcommerce/script-loader';
2+
3+
import {
4+
BraintreeHostWindow,
5+
BraintreeIntegrationService,
6+
BraintreePaymentProcessor,
7+
BraintreeScriptLoader,
8+
} from '@bigcommerce/checkout-sdk/braintree-utils';
9+
import {
10+
PaymentStrategyFactory,
11+
toResolvableModule,
12+
} from '@bigcommerce/checkout-sdk/payment-integration-api';
13+
import BraintreeCreditCardPaymentStrategy from './braintree-credit-card-payment-strategy';
14+
import { BraintreeHostedForm } from '@bigcommerce/checkout-sdk/braintree-integration';
15+
16+
const createBraintreeCreditCardPaymentStrategy: PaymentStrategyFactory<
17+
BraintreeCreditCardPaymentStrategy
18+
> = (paymentIntegrationService) => {
19+
const braintreeHostWindow: BraintreeHostWindow = window;
20+
const braintreeIntegrationService = new BraintreeIntegrationService(
21+
new BraintreeScriptLoader(getScriptLoader(), braintreeHostWindow),
22+
braintreeHostWindow,
23+
);
24+
const braintreeHostedForm = new BraintreeHostedForm(
25+
braintreeIntegrationService,
26+
new BraintreeScriptLoader(getScriptLoader(), braintreeHostWindow),
27+
);
28+
const braintreePaymentProcessor = new BraintreePaymentProcessor(
29+
braintreeIntegrationService,
30+
braintreeHostedForm,
31+
);
32+
33+
return new BraintreeCreditCardPaymentStrategy(
34+
paymentIntegrationService,
35+
braintreePaymentProcessor,
36+
braintreeIntegrationService
37+
);
38+
};
39+
40+
export default toResolvableModule(createBraintreeCreditCardPaymentStrategy, [
41+
{ id: 'braintree' },
42+
]);

0 commit comments

Comments
 (0)