google-pay / google-pay-button

Google Pay button - React, Angular, and custom element
Apache License 2.0
250 stars 60 forks source link

Type 'string' is not assignable to type 'PaymentMethodType' #229

Closed speedDaemonAmber closed 1 year ago

speedDaemonAmber commented 1 year ago

I am trying to integrate this into my existing React app, which uses Typescript. I am getting an incompatible types error: Type 'string' is not assignable to type 'PaymentMethodType'.

This is my payment request object where the payment method type is 'CARD', but it is not recognizing this as an acceptable value.

const paymentRequest = {
    apiVersion: 2,
    apiVersionMinor: 0,
    allowedPaymentMethods: [
        {
            type: 'CARD',
            parameters: {
                allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
                allowedCardNetworks: ['AMEX', 'DISCOVER', 'MASTERCARD', 'VISA']
            },
            tokenizationSpecification: {
                type: 'PAYMENT_GATEWAY',
                parameters: {
                    gateway: 'cardconnect',
                    gatewayMerchantId: gatewayMerchant,
                }
            }
        }
    ],
    merchantInfo: {
        merchantId: '12345678901234567890',
        merchantName: 'Test Merchant',
    },
    transactionInfo: {
        totalPriceStatus: 'FINAL',
        totalPrice: paymentAmount.toString(),
        currencyCode: 'USD',
        countryCode: 'US'
    }
};

Is there a way to get around this?

dmengelt commented 1 year ago

Hi @speedDaemonAmber Would it be possible to create a reproducer?

speedDaemonAmber commented 1 year ago

I created a repo here that reproduces this issue.

dmengelt commented 1 year ago

@speedDaemonAmber could you try with:

const paymentRequest: google.payments.api.PaymentDataRequest = {
    apiVersion: 2,
    apiVersionMinor: 0,
    allowedPaymentMethods: [
      {
        type: 'CARD',
        parameters: {
          allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
          allowedCardNetworks: ['MASTERCARD', 'VISA']
        },
        tokenizationSpecification: {
          type: 'PAYMENT_GATEWAY',
          parameters: {
            gateway: 'example',
            gatewayMerchantId: 'exampleGatewayMerchantID',
          }
        }
      }
    ],
    merchantInfo: {
      merchantId: '12345678901234567890',
      merchantName: 'Demo Merchant'
    },
    transactionInfo: {
      totalPriceStatus: 'FINAL',
      totalPriceLabel: 'Total',
      totalPrice: '100.00',
      currencyCode: 'USD',
      countryCode: 'US'
    }
  };
speedDaemonAmber commented 1 year ago

That worked. Thank you!