主题
IOS-SDK 收银台
接入流程
- 引入SDK
- 调用下单接口获取
transactionId
- 指定
environment
,subProductType
,传入transactionId
创建收银台对象 - 渲染支付按钮
- 创建支付回调
引入SDK
将 SDK 添加到您的app动态库
初始化SDK
如果用 Object C 开发,需要进行桥接
1. 调用下单接口
2. 收银台配置
swift
import SwiftUI
import UIKit
import SDK
import Combine
// transactionId: 流水号ID
// EnvironmentList 环境配置:
// EnvironmentList.SANDBOX:sandbox环境
// EnvironmentList.PRODUCTION: 正式环境
// EnvironmentList.BETA: 测试环境
// subProductType:支付类型:
// DIRECT:卡支付 TOKEN:toke支付
PacypayCheckout(environment: EnvironmentList.TEST,
subProductType: subProductType,
customConfig: customConfig,
transactionId: transactionId)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
3.1 内置支付按钮 推荐
swift
1.初始化sdk
PacypayCheckout(environment: EnvironmentList.TEST, subProductType: subProductType, customConfig: customConfig, transactionId: transactionId)
2.生成支付按钮
paymentSDK.creditCardView()//(subProductType:初始化传入的值是TOKEN,则自动唤起绑卡支付页面;如果传入的是DIRECT 自动唤起卡支付页面)
paymentSDK.applePayView()//applePay支付页面
1
2
3
4
5
6
2
3
4
5
6
3.2 自定义按钮支付
swift
VStack{
Button(action: {
//卡支付
paymentSDK().createPayment(transactionId:transactionId,payMethod:"DIRECT")
//绑卡支付
paymentSDK().createPayment(transactionId:transactionId,payMethod:"TOKEN")
//applePay支付
paymentSDK().createPayment(transactionId:transactionId,payMethod:"ApplePay")
}) {
Text("自定义支付按钮文案")
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
4. 支付回调
swift
// code:“F” 支付失败 "S" 支付成功 "N"取消支付 "P"支付中
// msg:支付结果信息,包含支付失败的信息提示,支付成功返回"Success"
.onReceive(NotificationCenter.default.publisher(for: .ronghanSDKCallBackData)) { notification in
if let userInfo = notification.userInfo as? [String: Any],
let code = userInfo["code"] as? String,
let msg = userInfo["msg"] as? String {
self.code = code
self.msg = msg
}
}
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
代码示例
swift
import SwiftUI
import UIKit
import SDK
import Combine
struct ContentView: View {
@State private var code: String = ""
@State private var msg: String = ""
@State private var showContainer = false
@State private var containerView: UIView? = nil
@State private var txnId: String = ""
@State private var subProductType: String = "TOKEN"
@State private var transactionId: String = "1795334853877956608"
@State private var subProductTypeList = ["TOKEN", "DIRECT"]
private var paymentMethodList = ["内置支付按钮支付", "自定义支付支付"]
@State private var paymentMethod = "内置支付按钮支付"
let customConfig = ronghan_sdk_customConfigModel(
Theme: Color(red: 67 / 255.0, green: 111 / 255.0, blue: 246 / 255.0, opacity: 1)
)
var body: some View {
VStack {
VStack {
HStack {
Text("流水号id:")
TextField("流水号Id", text: $transactionId)
.textFieldStyle(RoundedBorderTextFieldStyle())
}
.padding(EdgeInsets(top: 0, leading: 12, bottom: 0, trailing: 12))
}
VStack {
HStack {
Text("支付方式:")
Picker(selection: $subProductType, label: Text("")) {
ForEach(subProductTypeList, id: \.self) { subProductType in
Text(subProductType)
}
}
Spacer()
}
.padding(EdgeInsets(top: 0, leading: 12, bottom: 0, trailing: 12))
}
VStack {
Button("更新环境和transactionId") {
PacypayCheckout(environment: EnvironmentList.TEST, subProductType: subProductType, customConfig: customConfig, transactionId: transactionId)
}
}
VStack {
HStack{
Text("回调数据")
Text("Code: \(code)")
.padding()
Text("Message: \(msg)")
.padding()
}
}
VStack {
TabView {
VStack{
HStack {
VStack {
paymentSDK.creditCardView()
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(Color(red: 32 / 255.0, green: 32 / 255.0, blue: 32 / 255.0, opacity: 0.5), lineWidth: 0.5)
)
}
VStack {
paymentSDK.applePayView()
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(Color(red: 32 / 255.0, green: 32 / 255.0, blue: 32 / 255.0, opacity: 0.5), lineWidth: 0.5)
)
}
}
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 120, maxHeight: 120)
.padding(20)
Spacer()
}
.tabItem({
Image(systemName: "creditcard")
Text("默认支付") })
.tag(0)
VStack{
VStack{
Button(action: {
paymentSDK().createPayment(transactionId:transactionId,payMethod:"DIRECT")
}) {
Text("卡支付")
.font(.system(size: 18))
.foregroundColor(.white)
}
.frame(width: /*@START_MENU_TOKEN@*/100/*@END_MENU_TOKEN@*/,height: 22)
.padding(5)
.background(Color.blue)
}
VStack{
Button(action: {
paymentSDK().createPayment(transactionId:transactionId,payMethod:"TOKEN")
}) {
Text("token支付")
.font(.system(size: 18))
.foregroundColor(.white)
}
.frame(width: 100,height: 22)
.padding(5)
.background(Color.blue)
}
VStack{
Button(action: {
paymentSDK().createPayment(transactionId:transactionId,payMethod:"ApplePay")
}) {
Text("applePay支付")
.font(.system(size: 18))
.foregroundColor(.white)
}
.frame(width: /*@START_MENU_TOKEN@*/100/*@END_MENU_TOKEN@*/,height: 22)
.padding(5)
.background(Color.blue)
}
Spacer()
}
.tabItem({
Image(systemName: "creditcard")
Text("自定义支付按钮")
})
.tag(1)
}
}
Spacer()
}
.onReceive(NotificationCenter.default.publisher(for: .ronghanSDKCallBackData)) { notification in
if let userInfo = notification.userInfo as? [String: Any],
let code = userInfo["code"] as? String,
let msg = userInfo["msg"] as? String {
self.code = code
self.msg = msg
}
}
.onAppear {
PacypayCheckout(environment: EnvironmentList.TEST, subProductType: subProductType, customConfig: customConfig, transactionId: transactionId)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
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
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