paymentAuthorizationViewControllerDidAuthorizePaymentHandler中的本机空PKPayment

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

我正在尝试通过使用本机代码在NativeScript应用中制作Apple Pay。

<script>
    var PKPaymentAuthorizationViewControllerDelegateIml = (function (_super) {
        __extends(PKPaymentAuthorizationViewControllerDelegateIml, _super);
        function PKPaymentAuthorizationViewControllerDelegateIml() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        PKPaymentAuthorizationViewControllerDelegateIml.new = function () {
            return _super.new.call(this);
        };

        PKPaymentAuthorizationViewControllerDelegateIml.prototype.paymentAuthorizationViewControllerDidFinish = function(controller){
            console.log('did finish', controller)
            controller.dismissViewControllerAnimatedCompletion(true, null);
        }

        PKPaymentAuthorizationViewControllerDelegateIml.prototype.paymentAuthorizationViewControllerDidAuthorizePaymentHandler = function(controller, payment, completion){
            console.log('authorization',  payment.token.paymentData)
            completion(PKPaymentAuthorizationStatus.Success)
        }

        PKPaymentAuthorizationViewControllerDelegateIml.ObjCProtocols = [PKPaymentAuthorizationViewControllerDelegate];

        return PKPaymentAuthorizationViewControllerDelegateIml;
    }(NSObject));

    export default {
        methods:{
            applePay(){
                let SupportedPaymentNetworks = [PKPaymentNetworkVisa, PKPaymentNetworkMasterCard]
                let ApplePaySwagMerchantID = "merchant.APPLICATION_ID"

                let paymentRequest = new PKPaymentRequest();
                paymentRequest.merchantIdentifier = ApplePaySwagMerchantID
                paymentRequest.supportedNetworks = SupportedPaymentNetworks
                paymentRequest.merchantCapabilities = PKMerchantCapability.Capability3DS
                paymentRequest.countryCode = "RU"
                paymentRequest.currencyCode = "RUB"


                let item = new PKPaymentSummaryItem();
                item.label = 'Test payment';
                item.amount = new NSDecimalNumber({ string: '1' });

                paymentRequest.paymentSummaryItems = [
                    item
                ]

                var listener = PKPaymentAuthorizationViewControllerDelegateIml.new();

                let applePayController = new PKPaymentAuthorizationViewController(paymentRequest);
                applePayController.delegate = listener;

                var rootViewController = UIApplication.sharedApplication.keyWindow.rootViewController;
                rootViewController.presentViewControllerAnimatedCompletion(applePayController, true, null)
            }
        }
    }
</script>

我正在使用沙盒测试帐户运行应用程序。但是PKPaymentAuthorizationViewControllerDelegateIml.prototype.paymentAuthorizationViewControllerDidAuthorizePaymentHandlerpayment变量为空。在使用真实信用卡的TestFlight中,同样的错误。

nativescript applepay
1个回答
0
投票

谢谢,@ Manoj,我制作了插件,它可以正常工作!https://docs.nativescript.org/plugins/building-plugins

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