0

当我尝试实施 Apple Pay 时,出现错误 react-native-payments-reborn 库。

我在下面的行中得到了错误

    const paymentRequest = new PaymentRequest(METHOD_DATA, DETAILS);

代码如下。提前致谢。

const PaymentRequest = require('react-native-payments-reborn').PaymentRequest;

const METHOD_DATA = [{
    supportedMethods: ['apple-pay'],
    data: {
        merchantIdentifier: 'merchant.apple.test',
        supportedNetworks: ['visa', 'mastercard', 'amex'],
        countryCode: 'US',
        currencyCode: 'USD'
    }
}];

const DETAILS = {
    id: 'basic-example',
    displayItems: [
        {
            label: 'Movie Ticket',
            amount: { currency: 'USD', value: '15.00' }
        },
        {
            label: 'Grocery',
            amount: { currency: 'USD', value: '5.00' }
        }
    ],
    /*shippingOptions: [{
        id: 'economy',
        label: 'Economy Shipping',
        amount: { currency: 'USD', value: '0.00' },
        detail: 'Arrives in 3-5 days' // `detail` is specific to React Native Payments
    }],*/
    total: {
        label: 'Enappd Store',
        amount: { currency: 'USD', value: '20.00' }
    }
};

const OPTIONS = {
    requestPayerName: true,
    requestPayerPhone: true,
    requestPayerEmail: true,
    requestShipping: true
};

export default class ApplePay extends React.Component {

    constructor(props) {
        super(props);
        this.state = {};

        const paymentRequest = new PaymentRequest(METHOD_DATA, DETAILS);

        paymentRequest.addEventListener('shippingaddresschange', e => {
            const updatedDetails = getUpdatedDetailsForShippingAddress(paymentRequest.shippingAddress);

            e.updateWith(updatedDetails);
        });

        paymentRequest.addEventListener('shippingoptionchange', e => {
            const updatedDetails = getUpdatedDetailsForShippingOption(paymentRequest.shippingOption);

            e.updateWith(updatedDetails);
        });
    }

    render() {
       .....
    }
}

PaymentRequest.js

 // Types
import type {
  PaymentMethodData,
  PaymentDetailsInit,
  PaymentOptions,
} from './types';
    
export default class PaymentRequest {

  constructor(
    methodData: Array<PaymentMethodData> = [],
    details?: PaymentDetailsInit = [],
    options?: PaymentOptions = {}) 
  {
       ......
  }

    ......          

}
4

1 回答 1

0

supportedMethods必须是而'https://apple.com/apple-pay'不是'apple-pay'

于 2020-12-24T00:31:14.200 回答