CNBBASMPaymentHander.m
4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//
// CNBBASMPaymentHander.m
// BBASMDemo
//
// Created by CNLive on 2021/10/29.
//
#import "CNBBASMPaymentHander.h"
#import <BainuoCashierSDK/BDNCashierSDK.h>
#import <BainuoCashierSDK/BDNCashierSDKAlipayService.h>
#import <BainuoCashierSDK/BDNCashierSDKWechatService.h>
#import <BainuoCashierSDK/BDNCashierSDKBaifubaoService.h>
#import <CNLiveEnvironment/CNLiveEnvironment.h>
#import <AlipaySDK/AlipaySDK.h>r
#import "CNBainuoPayManagerDelegate.h"
static NSString * const CNPAY_WEICHAT_PAY_SCHEME = @"cnlive.baidu.com://";
@implementation CNBBASMPaymentHander
+ (instancetype)shareInstance
{
static dispatch_once_t onceToken;
static CNBBASMPaymentHander *hander = nil;
dispatch_once(&onceToken, ^{
hander = [[self alloc] init];
[hander registerPayment];
});
return hander;
}
- (void )registerPayment{
// 按需实现和注册支付能力(收银台SDK提供了微信、支付宝、百付宝的支付能力的默认实现)
[BDNCashierSDK registerPaymentServices:@[[BDNCashierSDKAlipayService defaultService],[BDNCashierSDKWechatService defaultService],[BDNCashierSDKBaifubaoService defaultService]]];
// 使用收银台提供的支付宝支付能力时,需要注册对应Scheme
[[BDNCashierSDKAlipayService defaultService] registerScheme:@"cnlive"];
// 使用收银台提供的微信支付能力时,需要注册对应的宿主App的universalLink
[[BDNCashierSDKWechatService defaultService] registerUniversalLink:[NSString stringWithFormat:@"%@/",API_Host]];
// 使用收银台提供的百付宝支付能力时,需要注册实现BDNCashierSDKBaifubaoDelegate协议的代理类
[[BDNCashierSDKBaifubaoService defaultService] registerDelegate:[CNBainuoPayManagerDelegate shareInstance]];
}
-(void)requestBainuoCashierPayment:(NSDictionary *)params bannedChannels:(NSArray *)bannedChannels successCallBack:(BBASMCashierPaymentCallBack)successCallBack loadingCallBack:(BBASMCashierPaymentCallBack)loadingCallBack errorCallBack:(BBASMCashierPaymentCallBack)errorCallBack cancelCallBack:(BBASMCashierPaymentCallBack)cancelCallBack{
[self doBainuoCashierPayment:params bannedChannels:bannedChannels callback:^(NSDictionary *info) {
// 支付渠道响应结果
NSNumber *resultCode = info[BDNCashierPaymentRespCodeKey];
NSString *payDesc = info[BDNCashierPaymentRespMsgKey];
NSDictionary *data = info[BDNCashierPaymentRespDataKey];
switch (resultCode.integerValue) {
case BDNCashierPaymentRespCodeSucceeded:
{
successCallBack(payDesc, data);
break;
}
case BDNCashierPaymentRespCodeLoading:
{
loadingCallBack(payDesc, data);
break;
}
case BDNCashierPaymentRespCodeCanceled:{
cancelCallBack(payDesc, data);
break;
}
case BDNCashierPaymentRespCodeFailed:{
errorCallBack(payDesc, data);
break;
}
default:
break;
}
}];
}
- (void)doBainuoCashierPayment:(NSDictionary *)params
bannedChannels:(NSArray *)bannedChannels
callback:(void (^)(NSDictionary *info))callback{
BDNCashierDealReq *dealReq = [[BDNCashierDealReq alloc] init];
dealReq.params = params;
dealReq.bannedChannels = bannedChannels;
dealReq.schemeForWechatH5Pay = CNPAY_WEICHAT_PAY_SCHEME;
dealReq.completion = ^(NSDictionary *info) {
callback ? callback(info) : nil;
};
// 调起收银台
[BDNCashierSDK showCashierDesk:dealReq];
}
-(void)requestBainuoPolymerPaymentChannelInfoWithParams:(NSDictionary *)params completion:(void (^)(NSDictionary * _Nullable, NSError * _Nullable))completionBlock
{
[BDNCashierSDK requestChannelInfoWithParams:params responseBlock:^(NSDictionary *response) {
completionBlock ? completionBlock(response, nil) : nil;
} failedBlock:^(NSError *error) {
completionBlock ? completionBlock (nil, error) : nil;
}];
}
- (void)calculateBainuoPolymerPaymentPriceWithParams:(NSDictionary *)params
completion:(void (^)(NSDictionary *_Nullable, NSError *_Nullable))completionBlock{
[BDNCashierSDK calculatePriceWithParams:params responseBlock:^(NSDictionary *response) {
completionBlock ? completionBlock(response, nil) : nil;
} failedBlock:^(NSError *error) {
completionBlock ? completionBlock(nil, error) : nil;
}];
}
- (void)showBainuoCashierCouponPannel:(NSDictionary *)params
fromViewController:(UIViewController *)fromViewController
callback:(void (^)(NSDictionary * _Nonnull))callback{
BDNCashierCouponReq *req = [BDNCashierCouponReq new];
req.params = params;
req.fromViewController = fromViewController;
req.completion = ^(NSDictionary *info) {
callback ? callback(info) : nil;
};
[BDNCashierSDK showCashierCoupon:req];
}
@end