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';
class ApplePay implements PKPaymentAuthorizationViewControllerDelegate {
pay() {
DispatchQueue.main.async(execute = () : void => {
let request = new PKPaymentRequest()
// 商户id
let merchantIdentifier = 'merchant.demo.ApplePay'
request.merchantIdentifier = merchantIdentifier
// request.merchantCapabilities = PKMerchantCapability.capabilityEMV
request.merchantCapabilities = [PKMerchantCapability.capability3DS, PKMerchantCapability.capabilityDebit]
// 支持的支付类型和网络类型
var supportedNetworks : PKPaymentNetwork[] = []
if (UTSiOS.available("iOS 9.2, *")) {
supportedNetworks = [
PKPaymentNetwork.amex,
PKPaymentNetwork.discover,
PKPaymentNetwork.masterCard,
PKPaymentNetwork.privateLabel,
PKPaymentNetwork.visa,
PKPaymentNetwork.chinaUnionPay,
]
} else {
supportedNetworks = [
PKPaymentNetwork.amex,
PKPaymentNetwork.discover,
PKPaymentNetwork.masterCard,
PKPaymentNetwork.privateLabel,
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 = '0.1')
let newItem = new PKPaymentSummaryItem(label = 'test', amount = amountNumber)
let amountNumber2 = new NSDecimalNumber(string = '0.1')
let newItem2 = new PKPaymentSummaryItem(label = 'test2', amount = amountNumber2)
request.paymentSummaryItems = [newItem, newItem2]
if (!PKPaymentAuthorizationViewController.canMakePayments(usingNetworks = supportedNetworks)) {
console.log('不支持银行卡。。。。')
}
let authVC = new PKPaymentAuthorizationViewController(paymentRequest = request)
console.log('authVC', authVC)
if (authVC != null) {
console.log(this)
console.log(this.paymentAuthorizationViewController)
authVC!.delegate = this
var u = UTSiOS.getCurrentViewController().present(authVC!, animated = true, completion = null)
console.log('present', u)
}
})
}
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)
},2000)
}
paymentAuthorizationViewControllerDidFinish(controller : PKPaymentAuthorizationViewController) {
console.log('paymentAuthorizationViewControllerDidFinish')
controller.dismiss(animated = true, completion = null)
}
}
var applePay = new ApplePay()
export default function applePayment(type : boolean = false) {
applePay.pay()
}
人脸识别后输入完密码,没有触发到paymentAuthorizationViewController这个代理方法
1 个回复
文青哎
你这是uts插件吗?怎么实现?