TypeError: Object is not a constructor (evaluating 'new PaymentRequest(METHOD_DATA, DETAILS)')
TypeError: Object is not a constructor (evaluating 'new PaymentRequest(METHOD_DATA, DETAILS)')
我在尝试实现 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 = {})
{
......
}
......
}
supportedMethods
必须是 'https://apple.com/apple-pay'
而不是 'apple-pay'
。
我在尝试实现 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 = {})
{
......
}
......
}
supportedMethods
必须是 'https://apple.com/apple-pay'
而不是 'apple-pay'
。