Skip to content
Draft
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
@@ -0,0 +1,57 @@
import { createBigCommercePaymentsInvoicesPaymentStrategy } from '@bigcommerce/checkout-sdk/integrations/bigcommerce-payments';
import { type FunctionComponent, useEffect } from 'react';

import {
type PaymentMethodProps,
type PaymentMethodResolveId,
PaymentMethodId,
toResolvableComponent,
} from '@bigcommerce/checkout/payment-integration-api';

const BigCommercePaymentsInvoicesPaymentMethod: FunctionComponent<PaymentMethodProps> = ({
method,
checkoutService,
onUnhandledError,
}) => {
useEffect(() => {
const initializePayment = async () => {
try {
await checkoutService.initializePayment({
gatewayId: method.gateway,
methodId: method.id,
integrations: [createBigCommercePaymentsInvoicesPaymentStrategy],
});
} catch (error) {
if (error instanceof Error) {
onUnhandledError(error);
}
}
};

void initializePayment();

return () => {
const deinitializePayment = async () => {
try {
await checkoutService.deinitializePayment({
gatewayId: method.gateway,
methodId: method.id,
});
} catch (error) {
if (error instanceof Error) {
onUnhandledError(error);
}
}
};

void deinitializePayment();
};
}, [checkoutService, method.gateway, method.id, onUnhandledError]);

return null;
};

export default toResolvableComponent<PaymentMethodProps, PaymentMethodResolveId>(
BigCommercePaymentsInvoicesPaymentMethod,
[{ id: PaymentMethodId.BigCommercePaymentsInvoices }],
);
7 changes: 7 additions & 0 deletions packages/bigcommerce-payments-integration/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@ export { default as BigCommercePaymentsVenmoPaymentMethod } from './BigCommerceP
*
* */
export { default as BigCommercePaymentsRatePayPaymentMethod } from './BigCommercePaymentsRatePay/BigCommercePaymentsRatePayPaymentMethod';

/**
*
* BigCommerce Payments Invoice
*
* */
export { default as BigCommercePaymentsInvoicesPaymentMethod } from './BigCommercePaymentsInvoices/BigCommercePaymentsInvoicesPaymentMethod';
1 change: 1 addition & 0 deletions packages/payment-integration-api/src/PaymentMethodId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ enum PaymentMethodId {
BigCommercePaymentsVenmo = 'bigcommerce_payments_venmo',
BigCommercePaymentsFastLane = 'bigcommerce_payments_fastlane',
BigCommercePaymentsGooglePay = 'googlepay_bigcommerce_payments',
BigCommercePaymentsInvoices = 'bigcommerce_payments_invoices',
Qpay = 'qpay',
Quadpay = 'quadpay',
Ratepay = 'ratepay',
Expand Down