iOS Apple Pay development process

One: Introduction

The payment function needs to be used in the project, which requires Alipay payment , Alipay web payment , WeChat payment , UnionPay payment , Apple pay, so I intend to summarize it for future reference and for everyone to avoid being scammed again where it is used.
Today we will mainly introduce UnionPay control payment, other payment also wrote corresponding tutorials, and gave the connection.

Organize 45 e-books

2: Introduction to the payment process

2.1 Apple Pay page demo

Apple Pay page demo

  1. Buyers purchase goods or services in mobile apps and display the Apple Pay button on the order page
  2. Through the UnionPay control, drop the Apple Pay payment page
  3. The user verifies Touch ID through the payment page. Whether the bank card password is required to enter the bank card password depends on the transaction limit and bank support
  4. If the payment is successful, the success page will be displayed in the merchant application
    (1) The payment success page should refer to the UI example and display the "UnionPay" logo and the "Cloud QuickPass" logo.
    (2) The UnionPay SDK control supports the discount function. During the discount event, the merchant application should refer to the instance UI to display the original amount and discount amount

2.2 Implementation of Apple Pay Payment

How to implement Apple Pay payment

1-2. The merchant generates an order and sends the order information to the UnionPay payment gateway through the merchant SERVER;
3-4. The UnionPay payment gateway records the order information, returns the TN number used to identify the order, and returns it to the merchant APP via the merchant SERVER;
5. Merchant APP calls UnionPay SDK and transfers the TN number to UnionPay SDK
6. UnionPay SDK initiates a payment request to Apple’s PASSKIT FRAMEWORK;
7. The interface returns encrypted payment token information;
8-9. UnionPay SDK passes the payment token to UnionPay payment gateway, complete the transaction authentication;
10-12. UnionPay returns the payment result to the merchant APP, the merchant SERVER, and the merchant APP is responsible for prompting the user of the transaction result.

Three: Engineering configuration

bundleID settings

bundleID settings

Enable Apple Pay permission in Capability and select merchantID. Apply for merchantID

Enable Apple Pay permissions

After that, the project will have one more Applepay configuration file ApplePayYasin.entitlements

project files

Four: Download Apple Pay SDK

Apple Pay SDK

After downloading, find the .h file and library file. To use UPPaymentControl, you need to add the UPAPayPlugin.h and UPAPayPluginDelegate.h files in the paymentcontrol/inc directory and the libUPAPayPlugin.a file in the paymentcontrol/libs directory to the merchant application project.

SDK path

Five: Call the payment interface

In calling the UnionPay payment class, first add a header file reference.

#import "UPAPayPlugin.h"

// TODO 商户需要换用自己的mertchantID
#define kAppleMerchantID        @"merchant.com.AgreePay.ApplePayAgree"

The code in the payment method is as follows:

//当获得的tn不为空时,调用支付接口
if (tn != nil && tn.length > 0) {
        [UPAPayPlugin startPay:tn 
        mode:@"01" 
        viewController:ViewController 
        delegate:self andAPMechantID:kAppleMerchantID];
}

The several parameters required by the method are written in the document. tn is the transaction serial number, which is sent back by the server. Only with this parameter can the client call the payment control for payment. Just call a method! ! !

Six: Callback of payment results

Just write the following code in the ViewController that calls up the payment

#pragma mark -
#pragma mark 响应控件返回的支付结果
#pragma mark -
- (void)UPAPayPluginResult:(UPPayResult *)result
{
    if(result.paymentResultStatus == UPPaymentResultStatusSuccess) {
        NSString *otherInfo = result.otherInfo?result.otherInfo:@"";
        NSString *successInfo = [NSString stringWithFormat:@"支付成功\n%@",otherInfo];
        
        NSLog(@"%@",successInfo);
       
    }else if(result.paymentResultStatus == UPPaymentResultStatusCancel){
        
        NSLog(@"支付取消");

    }else if (result.paymentResultStatus == UPPaymentResultStatusFailure) {
        
        NSString *errorInfo = [NSString stringWithFormat:@"%@",result.errorDescription];
        NSLog(@"支付失败%@",errorInfo);
    }else if (result.paymentResultStatus == UPPaymentResultStatusUnknownCancel)  {
        
        //TODO UPPAymentResultStatusUnknowCancel表示发起支付以后用户取消,导致支付状态不确认,需要查询商户后台确认真实的支付结果
//        NSString *errorInfo = [NSString stringWithFormat:@"支付过程中用户取消了,请查询后台确认订单"];
//        [self showAlertMessage:errorInfo];
        NSLog(@"支付过程中用户取消了,请查询后台确认订单");
        
    }
}

Screenshot of payment transfer

I hope I can help you.
If there is something wrong or insufficient, I also hope that readers can provide more comments or suggestions.
iOS Technology Exchange Group: 668562416

Guess you like

Origin blog.csdn.net/qq_36478920/article/details/78415537