Create Token
iOS
If you want to know the latest SDK version and the difference between each version, please refer to Github Release Page: TapPay iOS Github
Overview
- Get Prime from your frontend , send prime to your server.
- Send prime, frontend_redirect_url, backend_notify_url to TapPay Server.
- Get payment_url, pass to frontend and use TPDPlusPay.redirect, let customer use Plus Pay.
- After transaction, via universal link redirect to your App, backend will receive TapPay notify in backend_notify_url.
TPDSetup
+ (instancetype _Nonnull)setWithAppId:(int)appId
withAppKey:(NSString *_Nonnull)appKey
withServerType:(TPDServerType)serverType;
class func setWithAppKey(_ appKey: String, withAppId appId: Int32, with serverType: TPDServerType) -> Self
Name | Type | Usage |
---|---|---|
appID | int | Please refer to appid. |
appKey | String | Please refer to appkey. |
serverType | TPDServerType | Use “TPDServerType.Sandbox” for sandbox environment, and “TPDServerType.Production” for production environment. |
1 .Import TPDirect in your AppDelegate, and use TPDSetup to set up your environment in didFinishLaunchingWithOptions.
#import <TPDirect/TPDirect.h>
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[TPDSetup setWithAppId:AppId withAppKey:@"AppKey" withServerType:TPDServer_SandBox];
return YES;
}
import TPDirect
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:
[UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
TPDSetup.setWithAppId(AppId, withAppKey: AppKey, with: TPDServerType.sandBox)
return true
}
Setup TPDPlusPay
Use this method to initilize TPDPlusPay instance with your universal link.
TPDPlusPay * plusPay = [TPDPlusPay setupWithReturnUrl:@"URL"];
let plusPay = TPDPlusPay.setup(withReturnUrl: "URL")
isPlusPayAvailable
Use this method to check current device installed Plus Pay App.
Open Xcode info.plist file.
Add a Key named LSApplicationQueriesSchemes, and set the type of the value to Array.
Add an item of type String to the Array and set its value to pluspay-fm.
[plusPay isPaymentAvailable];
plusPay.isPaymentAvailable()
Setup universal link
1. Go to xCode TARGET and Signing & Capabilities page and click + Capability button
2. Choose Associated Domains
3. In Associated Domains section click + button add domain
4. Domain should be applinks:{your domain without https://}
5. Setup a config need to upload a file on your server.
create a folder /.well-known in your server then create a file ‘apple-app-site-association’
appID format : <TeamID>.<bundle identifier>
{
"applinks": {
"apps": [],
"details": [
{
"appID": "T9G64ZZGC4.Cherri.PlusPayExample",
"paths": [ "*" ]
}
]
}
}
Get teamID from apple developer membership
Get bundle identifier from xCode
Get Prime
Call getPrime function , obtain Prime or error message via onSuccessCallback, onFailureCallback, send Prime to your backend server and call Pay By Prime API.
[[[plusPay onSuccessCallback:^(NSString * _Nullable prime) {
NSLog(@"Prime : %@",prime);
}] onFailureCallback:^(NSInteger status, NSString * _Nonnull message) {
NSLog(@"status : %ld , message : %@", status, message);
}] getPrime];
plusPay.onSuccessCallback { (Prime) in
print("Prime : \(Prime!)")
}.onFailureCallback { (status, msg) in
print("status : \(status), msg : \(msg)")
}.getPrime()
Redirect to Plus Pay App
After Pay by Prime success, pass paymentURL to your frontend and call redirect
Redirect to Plus Pay app , you can get Plus Pay result via callback.
[plusPay redirect:paymentUrl completion:^(TPDPlusPayResult * _Nonnull result) {
NSString *plusPayResult = [NSString stringWithFormat:@"status : %ld \n recTradeId : %@ \n bankTransactionId : %@ \n orederNumber : %@", (long)result.status, result.recTradeId, result.bankTransactionId, result.orderNumber];
NSLog(@"result : %@", plusPayResult);
}];
plusPay.redirect(payment_url) { (result) in
print("status : \(result.status), rec_trade_id : \(result.recTradeId), order_number : \(result.orderNumber), bank_transaction_id : \(result.bankTransactionId)")
}
Handle handlePlusPayUniversalLink
Implement handlePlusPayUniversalLink in AppDelegate continueUserActivity, use this method to check URL come from TapPay and get Plus Pay result.
(iOS version lower than 13.0, please use following method)
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
NSURL * url = userActivity.webpageURL;
BOOL plusPayHandled = [TPDPlusPay handlePlusPayUniversalLink:url];
if (plusPayHandled) {
return YES;
}
return NO;
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
let url = userActivity.webpageURL
let plusPayHandled = TPDPlusPay.handleUniversalLink(url)
if (plusPayHandled) {
return true
}
return false
}
Exception Handle
1. Implement TPDPlusPay addExceptionObserver in AppDelegate didFinishLaunchingWithOptions to observer exception.
[TPDPlusPay addExceptionObserver:(@selector(tappayPlusPayExceptionHandler:))];
TPDPlusPay.addExceptionObserver(#selector(tappayPlusPayExceptionHandler(notofication:)))
2. In AppDelegate add tappayPlusPayExceptionHandler function , receive notification when exception happen and implement parseURL to get Plus Pay result.
- (void)tappayPlusPayExceptionHandler:(NSNotification *)notification {
TPDPlusPayResult * result = [TPDPlusPay parseURL:notification];
NSLog(@"status : %@ , orderNumber : %@ , recTradeId : %@ , bankTransactionId : %@",result.status , result.orderNumber , result.recTradeId , result.bankTransactionId);
}
@objc func tappayPlusPayExceptionHandler(notofication: Notification) {
let result : TPDPlusPayResult = TPDPlusPay.parseURL(notofication)
print("status : \(result.status) , orderNumber : \(result.orderNumber) , recTradeid : \(result.recTradeId) , bankTransactionId : \(result.bankTransactionId) ")
}
Test Method in sandbox
Please contact TapPay Support
Email : Support@cherri.tech