All files / app/payment/paymentMethod AmazonPayV2PaymentMethod.tsx

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43  24x     24x       24x 2x 2x 2x 2x   2x             2x   2x                                   24x  
import { PaymentInitializeOptions } from '@bigcommerce/checkout-sdk';
import React, { useCallback, FunctionComponent } from 'react';
import { Omit } from 'utility-types';
 
import HostedWidgetPaymentMethod , { HostedWidgetPaymentMethodProps } from './HostedWidgetPaymentMethod';
 
export type AmazonPayV2PaymentMethodProps = Omit<HostedWidgetPaymentMethodProps, 'buttonId' | 'containerId' | 'deinitializeCustomer' | 'hideWidget' | 'initializeCustomer' | 'isSignInRequired' | 'onSignOut' | 'paymentDescriptor' | 'shouldShow' | 'shouldShowDescriptor' | 'shouldShowEditButton'>;
 
const AmazonPayV2PaymentMethod: FunctionComponent<AmazonPayV2PaymentMethodProps> = ({
    initializePayment,
    method,
    method: { initializationData: { paymentDescriptor, paymentToken } },
    ...rest
}) => {
    const initializeAmazonPayV2Payment = useCallback((options: PaymentInitializeOptions) => initializePayment({
        ...options,
        amazonpay: {
            editButtonId: 'editButtonId',
        },
    }), [initializePayment]);
 
    const reload = useCallback(() => window.location.reload(), []);
 
    return <HostedWidgetPaymentMethod
        { ...rest }
        buttonId="editButtonId"
        containerId="paymentWidget"
        deinitializeCustomer={ undefined }
        hideWidget
        initializeCustomer={ undefined }
        initializePayment={ initializeAmazonPayV2Payment }
        isSignInRequired={ false }
        method={ method }
        onSignOut={ reload }
        paymentDescriptor={ paymentDescriptor }
        shouldShow={ !!paymentToken }
        shouldShowDescriptor={ !!paymentToken }
        shouldShowEditButton={ !!paymentToken }
    />;
};
 
export default AmazonPayV2PaymentMethod;