@@ -16,13 +16,13 @@ Use `https://github.com/payrails/ios-sdk` as the repository URL.
16
16
17
17
To enable Apple Pay in your app, you need to add the merchant ID in ` Signing & Capabilities ` in your project's target's settings.
18
18
19
- ## Initializing Payrails React Native SDK
19
+ ## Initializing Payrails SDK
20
20
21
21
Use the ` Payrails ` component to initialize a Payrails client context as shown below.
22
22
23
23
Async Await
24
24
25
- ``` ( swift)
25
+ ``` swift
26
26
import Payrails
27
27
28
28
private var payrails: Payrails.Session?
@@ -38,7 +38,7 @@ payrails = try await Payrails.configure(
38
38
39
39
Callback
40
40
41
- ``` ( swift)
41
+ ``` swift
42
42
Payrails.configure (with : .init (
43
43
version : version,
44
44
data : data,
@@ -59,30 +59,35 @@ Once your SDK is initialized, it is now allowed to interact directly with Payrai
59
59
60
60
## UI elemenents
61
61
62
- Payrails iOS SDK provides you buttons for Apple Pay and PayPal .
62
+ Payrails iOS SDK provides you buttons for Apple Pay, PayPal and Stored instuments (card buttons) .
63
63
64
64
1 . Initialize Tokenization context:
65
65
66
- ``` ( swift)
66
+ ``` swift
67
67
private let applePayButton = ApplePayButton (
68
68
paymentButtonType : .checkout ,
69
69
paymentButtonStyle : .black
70
70
)
71
71
applePayButton.onTap = { [weak self ] in
72
- //make payment
72
+ // Make payment
73
73
}
74
74
75
75
private let payPalButton = PayPalButton ()
76
76
payPalButton.onTap = { [weak self ] in
77
- //make payment
77
+ // Make payment
78
+ }
79
+
80
+ private let cardButton = CardSubmitButton ()
81
+ cardButton.onTap = { [weak self ] in
82
+ // Make payment
78
83
}
79
84
```
80
85
81
86
## Check for available payments
82
87
83
88
Payrails iOS SDK allows you to easily check if particular payment is available:
84
89
85
- ``` ( swift)
90
+ ``` swift
86
91
applePayButton.isHidden = ! payrails.isPaymentAvailable (type : .applePay )
87
92
payPalButton.isHidden = ! payrails.isPaymentAvailable (type : .payPal )
88
93
```
@@ -93,7 +98,7 @@ Payrails iOS SDK allows you to easily perform payment using:
93
98
94
99
Async Await
95
100
96
- ``` ( swift)
101
+ ``` swift
97
102
import Payrails
98
103
99
104
Task { [weak self , weak payrails] in
@@ -125,7 +130,7 @@ Task { [weak self, weak payrails] in
125
130
126
131
Callback
127
132
128
- ``` ( swift)
133
+ ``` swift
129
134
payrails.executePayment (
130
135
with : type, // .applePay or .payPal
131
136
saveInstrument : false , // set to true if you want to store payment
@@ -150,7 +155,7 @@ payrails.executePayment(
150
155
151
156
Where
152
157
153
- ``` ( swift)
158
+ ``` swift
154
159
extension YourPaymentViewController : PaymentPresenter {
155
160
func presentPayment (_ viewController : UIViewController) {
156
161
DispatchQueue.main .async {
@@ -164,7 +169,7 @@ extension YourPaymentViewController: PaymentPresenter {
164
169
165
170
Payrails iOS SDK allows you to retrieve and reuse stored payments:
166
171
167
- ``` ( swift)
172
+ ``` swift
168
173
payrails.storedInstruments .forEach { storedElement in
169
174
switch storedElement.type {
170
175
case .payPal :
@@ -209,6 +214,134 @@ private func pay(
209
214
}
210
215
```
211
216
217
+ ## Card Form Acceptance
218
+
219
+ After initializing your payrails SDK. You get a ` session ` object we use to interact with the payment controller.
220
+ There are 3 ways to integrate the Payrails SDK
221
+
222
+ 1 . Drop-in: an all-in-one payment form to accept payments on your website.
223
+ 2 . Elements: modular payment UI components you can assemble to build a modular payment form.
224
+ 3 . Secure fields: secure input fields for PCI-compliant cardholder data collection. ** (not supported yet)**
225
+
226
+ ### 1.Drop-in
227
+
228
+ #### Initilizing the drop-in view
229
+
230
+ ``` swift
231
+
232
+ let controller = try ? DropInViewController (configuration : .init (
233
+ initData : response,
234
+ option : .init (env : .dev )
235
+ ))
236
+ ```
237
+
238
+ #### Handling events
239
+
240
+ Handle events by setting the callback function of your controller.
241
+ Allowed result types:
242
+ | Result | Description |
243
+ | --------------------- | --------------------------------------------------------------- |
244
+ | .authorizationFailed | Couldn't authroize the payment |
245
+ | .cancelledByUser | User cancelled the execution |
246
+ | .failure | Payment failed |
247
+ | .success | Payment was successful |
248
+ | .error | An error occured with error values [ here] ( Payrails/Classes/Public/Domains/PayrailsError.swift ) |
249
+
250
+ ``` swift
251
+ controller? .callback = { [weak self ] result in
252
+ let message: String
253
+ switch result {
254
+ case .authorizationFailed :
255
+ message = " Authorization Failed"
256
+ case .cancelledByUser :
257
+ message = " Cancelled by user"
258
+ case .failure :
259
+ message = " Failure"
260
+ case .success :
261
+ message = " Success"
262
+ case let .error (error):
263
+ switch error {
264
+ case .invalidCardData :
265
+ return
266
+ default :
267
+ message = " Error " + error.localizedDescription
268
+ }
269
+ }
270
+ self ? .showResultAlert (message)
271
+ }
272
+ ```
273
+
274
+ #### Render your drop-in form
275
+
276
+ The controller exposes the drop-in view object, you can render it by adding it as a subview to your view controller
277
+
278
+ ``` swift
279
+ view.addSubview (controller.view )
280
+ ```
281
+
282
+ ### 2. Elements
283
+
284
+ ### Element Types
285
+
286
+ Before we integrate our secure fields form you need to be fimiliar with the Card Element types.
287
+ | Result | Description |
288
+ | --------------------- | --------------------------------------------------------------- |
289
+ | CARDHOLDER_NAME | Field type that requires Cardholder Name input formatting and validation |
290
+ | CARD_NUMBER | Field type that requires Credit Card Number input formatting and validation |
291
+ | EXPIRATION_DATE | Field type that requires Card Expiration Date input formatting and validation, format can be set through CollectElementOptions, defaul is MM/YY |
292
+ | CVV | Field type that requires Card CVV input formatting and validation |
293
+ | EXPIRATION_MONTH | Field type that requires Card Expiration Month formatting and validation (format: MM)|
294
+ | EXPIRATION_YEAR | Field type that requires Card Expiration Year formatting and validation, format can be set through CollectElementOptions for YY, defaul is YYYY |
295
+
296
+ They can be accessed as follows:
297
+
298
+ ``` swift
299
+ let type = CardFieldType.CARDHOLDER_NAME
300
+ ```
301
+
302
+ ### Initilize your secure fields view
303
+
304
+ ``` swift
305
+ func buildCardView {
306
+
307
+ guard let payrails, // This is your Payrails.Session object
308
+ payrails.isPaymentAvailable (type : .card ) else { return }
309
+
310
+
311
+ if let cardView = payrails.buildCardView (
312
+ with : .init (
313
+ style : .defaultStyle ,
314
+ showNameField : true ,
315
+ )
316
+ ) {
317
+ view.addSubview (cardView)
318
+ } else {
319
+ log (" Payment card is enabled but view was not generated" )
320
+ }
321
+ }
322
+ ```
323
+
324
+ ### Configure your view
325
+
326
+ You can pass a ` fieldConfigs ` parameter to your view, allowing you to customize specific elements
327
+
328
+ ``` swift
329
+ let cardView = payrails.buildCardView (
330
+ with : .init (
331
+ style : .defaultStyle ,
332
+ showNameField : true ,
333
+ fieldConfigs : [
334
+ CardFieldConfig.init (
335
+ type : CardFieldType.CARDHOLDER_NAME ,
336
+ placeholder : " Enter name as it appears on your credit card" ,
337
+ title : " Card holder name" ,
338
+ style : .defaultStyle
339
+ )
340
+ ]
341
+ )
342
+ )
343
+ ```
344
+
212
345
## Security Policy
213
346
214
347
### Reporting a Vulnerability
0 commit comments