我正在尝试在使用 Typescript 的反应项目中在结帐时实施 Apple Pay。我已经安装了braintree-web 包并按照braintree 网站上的说明来初始化我的ApplePaySession
. 虽然打字稿允许我编译项目,但在浏览器中我的调用new ApplePaySession(3, paymentRequest);
是未定义的。我绞尽脑汁,但我不明白出了什么问题。这是我如何初始化 ApplePay 的代码片段。
import { applePay, ApplePayStatusCodes, ApplePaySession } from 'braintree-web';
...
beginApplePay() {
if (!this.btApplePayInstance) {
//throw an erro
}
const paymentRequest = this.createPaymentRequest();
const session = this.createSession(paymentRequest);
session && session.begin();
}
createSession(
paymentRequest: braintree.ApplePayPaymentRequest
): braintree.ApplePaySession | null {
let session: braintree.ApplePaySession;
console.log('creating session');
console.log('Sample payment request: ', paymentRequest);
console.log(
'Supports API v3: ' + window.ApplePaySession.supportsVersion(3)
);
try {
debugger;
session = new ApplePaySession(3, paymentRequest); //this is where it fails
console.log(session);
} catch (err) {
console.log(err);
//throw an error
return null;
}
这是我的浏览器所说的:
TypeError: undefined is not a constructor (evaluating 'new braintree_web__WEBPACK_IMPORTED_MODULE_1__["ApplePaySession"](3, paymentRequest)')
任何对出了什么问题的见解将不胜感激。