美文网首页
Swift银联支付及ApplePay开发

Swift银联支付及ApplePay开发

作者: 歌手的剑 | 来源:发表于2018-08-20 16:06 被阅读90次

    银联控件接入流程:


    银联控件接入流程

    根据提供的流程图,作为app端,我们需要做的四件事如下:
    1.调用后端的接口传入参数发起订单请求,并接收tn

    2.调银联的startpay方法


    startpay

    3.实现UPAPayPluginDelegate的方法,根据result处理逻辑


    回调处理

    以上,就是银联sdk的集成,在此之前需要去银联官网注册登录完善商户信息,大概需要两三个工作日就好,第6步需要一点时间,但是等就行了。

    官网注册地址:https://open.unionpay.com/tjweb/index
    demo地址:https://open.unionpay.com/ajweb/help/file/techFile?productId=80
    
    image.png

    银联的集成可以说是非常简单的,下面介绍一下原生iOS支付处理;

    直接上代码:

    // MARK: - applepay原生支付
    extension Demo: PKPaymentAuthorizationViewControllerDelegate  {
        
        func payaction(){
            let request = PKPaymentRequest()
            if #available(iOS 9.2, *) {
                request.supportedNetworks = [PKPaymentNetwork.amex, PKPaymentNetwork.masterCard, PKPaymentNetwork.visa, PKPaymentNetwork.chinaUnionPay]
            } else {
                request.supportedNetworks = [PKPaymentNetwork.amex, PKPaymentNetwork.masterCard, PKPaymentNetwork.visa]
            }
            
            if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: request.supportedNetworks) {
                noticeOnlyText("可以支付,开始建立支付请求")
                
                request.countryCode = "CN"
                request.currencyCode = "CNY"
                request.merchantIdentifier = "merchant.com.xxxx"
                request.merchantCapabilities = PKMerchantCapability.capability3DS
                
                
                let wax = PKPaymentSummaryItem(label: "订单金额", amount: NSDecimalNumber(string: "\(self.allPrice)"))
                let total = PKPaymentSummaryItem(label: "xxx", amount: wax.amount)
                
                request.paymentSummaryItems = [wax, total]
                
                let vc = PKPaymentAuthorizationViewController(paymentRequest: request)
                vc?.delegate = self
                present(vc!, animated: true, completion: nil)
            }
            else {
                noticeOnlyText("您没有绑定任何银行卡或者当前设备不支持ApplePay")
            }
        }
        
        func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {
            noticeOnlyText("支付结束")
            dismiss(animated: true, completion: nil)
    
        }
        
        func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, completion: @escaping (PKPaymentAuthorizationStatus) -> Void) {
            // 调后端接口返回success或者fail
            completion(PKPaymentAuthorizationStatus.success)
            
            //订单ID 暂时
            let vc = KeMyTicketVc.init(orderId: "")
            navigationController?.pushViewController(vc, animated: true)
        }
    }
    

    相关文章

      网友评论

          本文标题:Swift银联支付及ApplePay开发

          本文链接:https://www.haomeiwen.com/subject/xqsliftx.html