PayBy-inApp-iOS
具有 In-app 支付场景的 ios 的 PayBy 支付网关集成 SDK
术语定义
- deviceId:每个设备都有自己的唯一 deviceId。预览环境 [联动调试] 修复:deviceId123
- partnerId:申请支付服务时,每个商户都会分配一个 partnerId。
- appId:申请支付服务时,每个商户的应用都会分配一个 appId。
- token:它包含订单信息。
- Sign:首先,通过按照以下顺序排列 deviceId、partnerId、appId、tokenn 生成 signString。规则如下:String signString = "iapAppId=" + appId + "&iapDeviceId=" + deviceId + "&iapPartnerId=" + partnerId + "&token=" + token; 第二,使用 privateKey 对 signString 进行签名,加密规则请参见示例。注意:出于示例目的,签名是在应用客户端生成的。出于安全考虑,签名应由服务器生成,然后返回给客户端。
适用版本
使用 Xcode 10 及以上版本使用 SLDPayByPayment SDK 的新版本,ios 10.0 及以上版本
安装
使用 CocoaPods 进行安装
[1] 在 XCode 中构建您的项目。
[2] 要使用 CocoaPods 将 SLDPayByPayment 集成到您的 Xcode 项目中,请在 Podfile 中指定它:
pod 'PXRPPayByPayment'
保存并执行 pod install,然后用以 .xcworkspace 为后缀的文件打开项目。注意:如果您现在正在使用 SLDPayByPayment
,请将其替换为 PXRPPayByPayment
,运行 pod install
进行安装,新的 SLDPayByPayment.framework
将集成到您的项目中。SLDPayByPayment
pod 不再维护。
[3] 在 Xcode 中,选择您的项目设置,选择“TARGETS”列,并在“info”选项卡上的“URL type”中为注册的应用程序“payby” + iapAppId 添加“URL scheme”(如下图)。
[4] 在 Xcode 中,选择您的项目设置,选择“TARGETS”列,并在“info”选项卡中将 payby 添加到“LSApplicationQueriesSchemes”(如下图)。
[5] 在需要使用 PayBy 终端 API 的文件中,导入头文件 <SLDPayByPayment/SLDPayByPayment.h>
。
#import <UIKit/UIKit.h>
#import <SLDPayByPayment/SLDPayByPayment.h>
@interface AppDelegate : UIResponder<UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
用法
初始化 SDK(必需)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//Setting up the development environment
[SDLPayByPaymentInterface paymentEnvironment:SDLPaymentEnvironmentTest];
[SDLPayByPaymentInterface initInApp:appId partnerId:partnerId];
return YES;
}
SDLPaymentEnvironment 描述:
- SDLPaymentEnvironmentDev:开发测试环境。
- SDLPaymentEnvironmentTest:客户调试环境。
- SDLPaymentEnvironmentRelease:产品上线环境。
调用您类中的方法
[SDLPayByPaymentInterface payInAppWithViewContorller:self orderCallback:^(OrderSuccessCallback _Nonnull orderSuccessCallback, OrderFailCallback _Nonnull orderFailCallback) {
//get order token
NSString *token = [self getTokenMock];
if (token && token.length > 0) {
orderSuccessCallback(token,deviceId,sigin);
}else{
orderFailCallback();
}
} success:^(id _Nonnull result) {
if([result isKindOfClass:[NSString class]]){
[self alertView:result];
}
} fail:^(NSError * _Nonnull error) {
[self alertView:error.userInfo[@"errorInfo"]];
}];
获取支付结果 AppDelegate 添加代理监控[低于 ios12]
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
NSURLComponents *components = [[NSURLComponents alloc] initWithString:url.absoluteString];
for(NSURLQueryItem *info in components.queryItems){
if([info.name isEqualToString:@"result"]){
NSLog(@"result = %@",info.value);
break;
}
}
return YES;
}
添加代理监控到项目 SceneDelegate[iOS13 或以上]
- (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts API_AVAILABLE(ios(13.0)){
for (UIOpenURLContext *obj in URLContexts) {
NSURL *tempUrl = obj.URL;
if([tempUrl.absoluteString hasPrefix:@"payby"]){
NSURLComponents *components = [[NSURLComponents alloc] initWithString:tempUrl.absoluteString];
for(NSURLQueryItem *info in components.queryItems){
if([info.name isEqualToString:@"result"]){
NSLog(@"result = %@",info.value);
break;
}
}
break;;
}
}
}
支付结果代码描述
- 成功:收款人已成功收到支付,订单的整个支付流程已完成。
- 失败:支付失败。
- 已支付:付款人已成功付款。等待收款人接收支付,同时,您也可以通过订单号查询和跟踪订单的支付状态。
- 支付中:处理中。等待支付过程完成并返回最终的支付结果。