未捕获的类型错误:未定义不是一个对象(评估'applePaySession.completeMerchantValidation')成功的Apple Pay付款

问题描述 投票:0回答:1

用户的付款正在进行中,但在检查兼容性时有些值未定义,我只是无法弄清楚这里出了什么问题。这是我生成错误的代码:

setCanDisplayApplePay() {
            var client = new window.usaepay.Client(this.publicKey);
            var applePayConfig = {
                targetDiv: 'apple-pay-compat-test',
                displayName: 'ApplePay',
                paymentRequest: {
                    total: {
                        label: this.name,
                        amount: 0.01,
                        type: 'final'
                    },
                    requiredBillingContactFields: [
                        'postalAddress'
                    ],
                    requiredShippingContactFields: [
                        'name',
                        'phone',
                        'email'
                    ],
                    countryCode: 'US',
                    currencyCode: 'USD'
                }
            };
            var applePay = client.createApplePayEntry(applePayConfig);
            applePay.checkCompatibility().then((res) => {
                this.canDisplayApplePay = true;
            }).catch((err) => {
                this.canDisplayApplePay = false;
            });
        },
javascript typescript applepay applepayjs
1个回答
0
投票

从提供的代码来看,您似乎正在尝试为支付流程设置 Apple Pay 兼容性。 该代码使用 usaepay 库来处理 Apple Pay 集成。

您提到的错误(“某些值未定义”)可能与 applePay.checkCompatibility() 方法有关。

确保您已正确导入所需的库,并且它在 window.usaepay 对象中可用。 检查 this.publicKey 变量是否正确定义并包含有效的 API 密钥。 验证 applePayConfig 对象中指定的 targetDiv 是否存在于 HTML 标记中。 检查控制台中是否存在任何错误,这些错误可能会为您提供有关未定义值的更多信息。 这是代码的稍微修改版本,其中包含附加日志语句以帮助诊断问题:

setCanDisplayApplePay() {
    var client = new window.usaepay.Client(this.publicKey);
    var applePayConfig = {
        targetDiv: 'apple-pay-compat-test',
        displayName: 'ApplePay',
        paymentRequest: {
            total: {
                label: this.name,
                amount: 0.01,
                type: 'final'
            },
            requiredBillingContactFields: [
                'postalAddress'
            ],
            requiredShippingContactFields: [
                'name',
                'phone',
                'email'
            ],
            countryCode: 'US',
            currencyCode: 'USD'
        }
    };
    var applePay = client.createApplePayEntry(applePayConfig);
    console.log("Checking Apple Pay compatibility...");
    applePay.checkCompatibility()
        .then((res) => {
            this.canDisplayApplePay = true;
            console.log("Apple Pay is compatible.");
        })
        .catch((err) => {
            this.canDisplayApplePay = false;
            console.error("Error checking Apple Pay compatibility:", err);
        });
}

希望这能有所帮助

© www.soinside.com 2019 - 2024. All rights reserved.