IvanJiang123
IvanJiang123
  • 发布:2023-04-12 16:57
  • 更新:2024-03-26 14:05
  • 阅读:401

【报Bug】UTS插件中merchantCapabilities只要设置了PKMerchantCapability.capabilityEMV,支付的时候就会闪退

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: window10

HBuilderX类型: 正式

HBuilderX版本号: 3.7.9

手机系统: iOS

手机系统版本号: iOS 16

手机厂商: 苹果

手机机型: iphone

页面类型: vue

vue版本: vue2

打包方式: 云端

项目创建方式: HBuilderX

操作步骤:

调用apple pay插件

预期结果:

不会出现闪退并可以触发paymentAuthorizationViewController代理方法

实际结果:

输入完密码后就会闪退

bug描述:

在UTS插件中实现Apple pay,只要merchantCapabilities 设置了capabilityEMV后,在调用apple pay支付时输入密码后大概1秒左右则会出现app闪退.设置其他值则不会

import { PKPaymentRequest, PKPaymentNetwork, PKMerchantCapability, PKAddressField, PKPaymentSummaryItem, PKPaymentAuthorizationViewController, PKPaymentAuthorizationViewControllerDelegate, PKPayment, PKPaymentAuthorizationResult, PKPaymentAuthorizationStatus } from 'PassKit';  
import { NSDecimalNumber } from 'Foundation';  
import { UTSiOS } from "DCloudUTSFoundation";  
import { DispatchQueue } from 'Dispatch';  

type Pay = {  
    success ?: (res ?: object) => void;  
    fail ?: (res ?: object) => void;  
}  
var option:Pay = {}  

class ApplePay implements PKPaymentAuthorizationViewControllerDelegate {  

    pay(amount : String, options : Pay) {  
        DispatchQueue.main.async(execute = () : void => {  
            let request = new PKPaymentRequest()  
            // 商户id  
            let merchantIdentifier = 'merchant.demo.ApplePay'  
            request.merchantIdentifier = merchantIdentifier  

            // request.merchantCapabilities = [PKMerchantCapability.capability3DS]  
            // request.merchantCapabilities = [PKMerchantCapability.capability3DS,PKMerchantCapability.capabilityCredit,PKMerchantCapability.capabilityDebit]  
            request.merchantCapabilities = [PKMerchantCapability.capabilityEMV,PKMerchantCapability.capability3DS]  
            // 支持的支付类型和网络类型  
            var supportedNetworks : PKPaymentNetwork[] = []  

            if (UTSiOS.available("iOS 9.2, *")) {  
                supportedNetworks = [  
                    PKPaymentNetwork.amex,  
                    PKPaymentNetwork.masterCard,  
                    PKPaymentNetwork.visa,  
                    PKPaymentNetwork.chinaUnionPay,  
                ]  
            } else {  
                supportedNetworks = [  
                    PKPaymentNetwork.amex,  
                    PKPaymentNetwork.masterCard,  
                    PKPaymentNetwork.visa,  
                ]  
            }  

            request.supportedNetworks = supportedNetworks  

            // = supportedNetworks  
            // 货币代码  
            request.currencyCode = 'HKD'  
            // request.currencyCode = 'CNY'  
            // 国家代码  
            // request.countryCode = 'HKG'  
            request.countryCode = 'CN'  

            // 快递方式  
            request.requiredBillingAddressFields = new PKAddressField(rawValue = 0)  
            request.requiredShippingAddressFields = new PKAddressField(rawValue = 0)  

            // 商品  
            let amountNumber = new NSDecimalNumber(string = amount)  
            let newItem = new PKPaymentSummaryItem(label = '香港公共圖書館', amount = amountNumber)  

            request.paymentSummaryItems = [newItem]  
            if (!PKPaymentAuthorizationViewController.canMakePayments()) {  
                options.fail?.({  
                    type: 'canMakePayments'  
                })  
                return  
            }  
            if (!PKPaymentAuthorizationViewController.canMakePayments(usingNetworks = supportedNetworks)) {  
                console.log('不支持银行卡。。。。')  
                options.fail?.({  
                    type: 'supportedNetworks'  
                })  
                return  
            }  

            let authVC = new PKPaymentAuthorizationViewController(paymentRequest = request)  
            if (authVC != null) {  
                authVC!.delegate = this  
                UTSiOS.getCurrentViewController().present(authVC!, animated = true, completion = null)  
            }  
        })  
    }  
    paymentAuthorizationViewController(controller : PKPaymentAuthorizationViewController, @argumentLabel("didAuthorizePayment") payment : PKPayment, completion : (p : PKPaymentAuthorizationStatus) => any) {  
        console.log(payment)  
        console.log('paymentAuthorizationViewController')  
        // var a = new PKPaymentAuthorizationResult(status = PKPaymentAuthorizationStatus.success,errors = null)  
        setTimeout(() => {  
            completion(PKPaymentAuthorizationStatus.success)  
            option.success?.({})  
        }, 2000)  
    }  
    paymentAuthorizationViewControllerWillAuthorizePayment(controller : PKPaymentAuthorizationViewController) {  
        console.log('paymentAuthorizationViewControllerWillAuthorizePayment')  
        // console.log(payment)  
        // controller.dismiss(animated = true, completion = null)  
    }  
    paymentAuthorizationViewControllerDidFinish(controller : PKPaymentAuthorizationViewController) {  
        console.log('paymentAuthorizationViewControllerDidFinish')  
        controller.dismiss(animated = true, completion = null)  
    }  

}  
var applePay = new ApplePay()  
export default function applePayment(amount : String, options : Pay) {  
    option = options  
    applePay.pay(amount,options)  
}
2023-04-12 16:57 负责人:无 分享
已邀请:
DCloud_iOS_LZY

DCloud_iOS_LZY

麻烦提供一个最简的测试示例

  • IvanJiang123 (作者)

    已提供,下方评论里。已是最简单的

    2023-04-25 18:20

IvanJiang123

IvanJiang123 (作者)

import { PKPaymentRequest, PKPaymentNetwork, PKMerchantCapability, PKAddressField, PKPaymentSummaryItem, PKPaymentAuthorizationViewController, PKPaymentAuthorizationViewControllerDelegate, PKPayment, PKPaymentAuthorizationResult, PKPaymentAuthorizationStatus } from 'PassKit';    
import { NSDecimalNumber } from 'Foundation';    
import { UTSiOS } from "DCloudUTSFoundation";    
import { DispatchQueue } from 'Dispatch';    

type Pay = {    
    success ?: (res ?: object) => void;    
    fail ?: (res ?: object) => void;    
}    
var option:Pay = {}    

class ApplePay implements PKPaymentAuthorizationViewControllerDelegate {    

    pay(amount : String, options : Pay) {    
        DispatchQueue.main.async(execute = () : void => {    
            let request = new PKPaymentRequest()    
            // 商户id    
            let merchantIdentifier = 'merchant.demo.ApplePay'    
            request.merchantIdentifier = merchantIdentifier    

            // request.merchantCapabilities = [PKMerchantCapability.capability3DS]    
            // request.merchantCapabilities = [PKMerchantCapability.capability3DS,PKMerchantCapability.capabilityCredit,PKMerchantCapability.capabilityDebit]    
            request.merchantCapabilities = [PKMerchantCapability.capabilityEMV,PKMerchantCapability.capability3DS]    
            // 支持的支付类型和网络类型    
            var supportedNetworks : PKPaymentNetwork[] = []    

            if (UTSiOS.available("iOS 9.2, *")) {    
                supportedNetworks = [    
                    PKPaymentNetwork.amex,    
                    PKPaymentNetwork.masterCard,    
                    PKPaymentNetwork.visa,    
                    PKPaymentNetwork.chinaUnionPay,    
                ]    
            }    

            request.supportedNetworks = supportedNetworks    

            // = supportedNetworks    
            // 货币代码    
            request.currencyCode = 'HKD'    
            // request.currencyCode = 'CNY'    
            // 国家代码    
            // request.countryCode = 'HKG'    
            request.countryCode = 'CN'    

            // 商品    
            let amountNumber = new NSDecimalNumber(string = amount)    
            let newItem = new PKPaymentSummaryItem(label = '香港公共圖書館', amount = amountNumber)    

            request.paymentSummaryItems = [newItem]    

            let authVC = new PKPaymentAuthorizationViewController(paymentRequest = request)    
            if (authVC != null) {    
                authVC!.delegate = this    
                UTSiOS.getCurrentViewController().present(authVC!, animated = true, completion = null)    
            }    
        })    
    }    
    paymentAuthorizationViewController(controller : PKPaymentAuthorizationViewController, @argumentLabel("didAuthorizePayment") payment : PKPayment, completion : (p : PKPaymentAuthorizationStatus) => any) {    
        completion(PKPaymentAuthorizationStatus.success)    
    }    
    paymentAuthorizationViewControllerDidFinish(controller : PKPaymentAuthorizationViewController) {    
        controller.dismiss(animated = true, completion = null)    
    }    

}    
var applePay = new ApplePay()    
export default function applePayment(amount : String, options : Pay) {    
    option = options    
    applePay.pay(amount,options)    
}
文青哎

文青哎

您好,请问您的applePay uts插件是如何实现的?

要回复问题请先登录注册