I am trying to implement Apple Pay on checkout in a react project using Typescript. I have installed the braintree-web package and followed the instructions on braintree's website to initialize my ApplePaySession
. Although typescript allows me to compile the project, in the browser my call to new ApplePaySession(3, paymentRequest);
is undefined. I have wracked my brain, but I cannot understand what is going wrong. Here's a code snippet for how I have initialized 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;
}
This is what my browser says:
TypeError: undefined is not a constructor (evaluating 'new braintree_web__WEBPACK_IMPORTED_MODULE_1__["ApplePaySession"](3, paymentRequest)')
Any insight into what's going wrong would be greatly appreciated.