CNBBASMPaymentImpl.m
6.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//
// CNBBASMPaymentImpl.m
// CNLiveNetAdd
//
// Created by CNLive on 2021/10/16.
// Copyright © 2021 cnlive. All rights reserved.
//
#import "CNBBASMPaymentImpl.h"
#import "CNBBASMPaymentHander.h"
/**
* 小程序统计支付
*/
typedef NS_ENUM(NSInteger, BBASMPayStatisticsType) {
BBASMPayStatisticsAliPay = 0, //支付宝直连
BBASMPayStatisticsPolymer = 1, //聚合收银台
BBASMPayStatisticsBDWallet = 2, //百度钱包
BBASMPayStatisticsWechat = 3, //微信端能力调用
};
@implementation CNBBASMPaymentImpl
RegisterBBASMAdapter()
+ (void)calculateBainuoPolymerPaymentPriceWithParams:(nonnull NSDictionary *)params completion:(nonnull void (^)(NSDictionary * _Nonnull, NSError * _Nonnull))completionBlock {
[[CNBBASMPaymentHander shareInstance] calculateBainuoPolymerPaymentPriceWithParams:params completion:completionBlock];
}
+ (void)requestBainuoPolymerPaymentChannelInfoWithParams:(nonnull NSDictionary *)params completion:(nonnull void (^)(NSDictionary * _Nonnull, NSError * _Nonnull))completionBlock {
[[CNBBASMPaymentHander shareInstance] requestBainuoPolymerPaymentChannelInfoWithParams:params completion:completionBlock];
}
+ (void)requestBainuoPolymerPaymentWithParams:(nonnull NSDictionary *)params bannedChannels:(nullable NSArray *)bannedChannels detailResultCallback:(nonnull void (^)(BBASMPaymentStatus, NSString * _Nonnull, NSDictionary * _Nonnull))detailResultCallback {
[[CNBBASMPaymentHander shareInstance] requestBainuoCashierPayment:[params copy]
bannedChannels:bannedChannels
successCallBack:^(NSString *payDesc, NSDictionary *data) {
detailResultCallback(BBASMPaymentStatusSuccess, payDesc, data);
[self cnPaymentUbcPayStatisticstype:BBASMPayStatisticsPolymer
payInfo:payDesc
succeed:YES];
} loadingCallBack:^(NSString *payDesc, NSDictionary *data) {
detailResultCallback(BBASMPaymentStatusLoading, payDesc, data);
} errorCallBack:^(NSString *payDesc, NSDictionary *data) {
detailResultCallback(BBASMPaymentStatusFailed, payDesc, data);
[self cnPaymentUbcPayStatisticstype:BBASMPayStatisticsPolymer
payInfo:payDesc
succeed:NO];
} cancelCallBack:^(NSString *payDesc, NSDictionary *data) {
detailResultCallback(BBASMPaymentStatusCanceled, payDesc, data);
[self cnPaymentUbcPayStatisticstype:BBASMPayStatisticsPolymer
payInfo:payDesc
succeed:NO];
}];
}
+ (void)requestPaymentWithType:(BBASMPaymentType)type orderInfo:(nonnull NSString *)orderInfo completion:(nonnull void (^)(BBASMPaymentStatus, NSDictionary * _Nonnull))completion {
}
+ (void)requestWalletRiskInfo:(nonnull NSString *)parameter source:(nonnull NSString *)source controller:(nonnull UIViewController *)controller completion:(nonnull void (^)(NSInteger, NSString * _Nonnull))completion {
}
+ (void)showBainuoCashierCouponPannel:(nonnull NSDictionary *)params fromViewController:(nonnull UIViewController *)fromViewController callback:(nonnull void (^)(NSDictionary * _Nonnull))callback {
[[CNBBASMPaymentHander shareInstance] showBainuoCashierCouponPannel:params fromViewController:fromViewController callback:callback];
}
+ (void)requestBainuoPolymerPaymentWithParams:(NSDictionary *)params
bannedChannels:(nullable NSArray *)bannedChannels
completion:(void (^)(BBASMPaymentStatus status, NSString *payResult))completionBlock{
[[CNBBASMPaymentHander shareInstance] requestBainuoCashierPayment:[params copy] bannedChannels:bannedChannels successCallBack:^(NSString * _Nonnull payDesc, NSDictionary * _Nonnull data) {
completionBlock(BBASMPaymentStatusSuccess, payDesc);
[self cnPaymentUbcPayStatisticstype:BBASMPayStatisticsPolymer
payInfo:payDesc
succeed:YES];
} loadingCallBack:^(NSString * _Nonnull payDesc, NSDictionary * _Nonnull data) {
completionBlock(BBASMPaymentStatusLoading, payDesc);
} errorCallBack:^(NSString * _Nonnull payDesc, NSDictionary * _Nonnull data) {
completionBlock(BBASMPaymentStatusFailed, payDesc);
[self cnPaymentUbcPayStatisticstype:BBASMPayStatisticsPolymer
payInfo:payDesc
succeed:NO];
} cancelCallBack:^(NSString * _Nonnull payDesc, NSDictionary * _Nonnull data) {
completionBlock(BBASMPaymentStatusCanceled, payDesc);
[self cnPaymentUbcPayStatisticstype:BBASMPayStatisticsPolymer
payInfo:payDesc
succeed:NO];
}];
}
#pragma mark - Private Method
/**
* @brief 统计小程序带来的订单量和支付成功的订单金额
*
* @param type 区分支付方式:支付宝-直连,聚合收银台,百度钱包
* @param payInfo 支付结果信息字符串
* @param succeed 支付成功失败
*/
+ (void)cnPaymentUbcPayStatisticstype:(BBASMPayStatisticsType)type payInfo:(NSString *)payInfo succeed:(BOOL)succeed {
NSString *value = succeed? @"success" : @"fail";
Class<BBASMServiceProtocol> serviceClass = [Pyramid createClassService:@protocol(BBASMServiceProtocol)];
NSString *appKey = [serviceClass currentBBASMAppId];
NSString *moneyInfo = payInfo;
if (!CHECK_STRING_VALID(moneyInfo)) {
moneyInfo = @"";
}
if (!CHECK_STRING_VALID(appKey)) {
appKey = @"";
}
// 支付方式
NSString *source = @"";
switch (type) {
case BBASMPayStatisticsBDWallet:{
source = @"baiduqianbao";
break;
}
case BBASMPayStatisticsAliPay:{
source = @"alipay";
break;
}
case BBASMPayStatisticsPolymer:{
source = @"nuomi";
} break;
case BBASMPayStatisticsWechat:{
source = @"wechatH5Action";
break;
}
default:
source = @"baiduqianbao";
break;
}
if (CHECK_STRING_VALID(appKey)) {
Class<BBASMServiceProtocol> serviceClass = [Pyramid createClassService:@protocol(BBASMServiceProtocol)];
NSString *appTypeString = [serviceClass appTypeString:appKey];
if (!appTypeString || [appTypeString isEqualToString:@"unknown"]) {
return;
}
NSDictionary *ubcDict = @{@"type": @"pay",
@"from": appTypeString,
@"value": value,
@"source": source,
@"ext": @{@"appid": appKey, @"money": moneyInfo,@"source" : BBASM_LOWERCASE_STR}};
[serviceClass sendWalletUBCMessage:ubcDict
appId:appKey];
}
}
@end