Skip to content

Commit ff78fec

Browse files
authored
Merge pull request #7 from payrails/PR-3761-payment-form-documentation
PR-3761: Payment form documentation
2 parents df47c52 + 1bb66a5 commit ff78fec

File tree

1 file changed

+145
-12
lines changed

1 file changed

+145
-12
lines changed

README.md

Lines changed: 145 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ Use `https://github.com/payrails/ios-sdk` as the repository URL.
1616

1717
To enable Apple Pay in your app, you need to add the merchant ID in `Signing & Capabilities` in your project's target's settings.
1818

19-
## Initializing Payrails React Native SDK
19+
## Initializing Payrails SDK
2020

2121
Use the `Payrails` component to initialize a Payrails client context as shown below.
2222

2323
Async Await
2424

25-
```(swift)
25+
```swift
2626
import Payrails
2727

2828
private var payrails: Payrails.Session?
@@ -38,7 +38,7 @@ payrails = try await Payrails.configure(
3838

3939
Callback
4040

41-
```(swift)
41+
```swift
4242
Payrails.configure(with: .init(
4343
version: version,
4444
data: data,
@@ -59,30 +59,35 @@ Once your SDK is initialized, it is now allowed to interact directly with Payrai
5959

6060
## UI elemenents
6161

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).
6363

6464
1. Initialize Tokenization context:
6565

66-
```(swift)
66+
```swift
6767
private let applePayButton = ApplePayButton(
6868
paymentButtonType: .checkout,
6969
paymentButtonStyle: .black
7070
)
7171
applePayButton.onTap = { [weak self] in
72-
//make payment
72+
// Make payment
7373
}
7474

7575
private let payPalButton = PayPalButton()
7676
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
7883
}
7984
```
8085

8186
## Check for available payments
8287

8388
Payrails iOS SDK allows you to easily check if particular payment is available:
8489

85-
```(swift)
90+
```swift
8691
applePayButton.isHidden = !payrails.isPaymentAvailable(type: .applePay)
8792
payPalButton.isHidden = !payrails.isPaymentAvailable(type: .payPal)
8893
```
@@ -93,7 +98,7 @@ Payrails iOS SDK allows you to easily perform payment using:
9398

9499
Async Await
95100

96-
```(swift)
101+
```swift
97102
import Payrails
98103

99104
Task { [weak self, weak payrails] in
@@ -125,7 +130,7 @@ Task { [weak self, weak payrails] in
125130

126131
Callback
127132

128-
```(swift)
133+
```swift
129134
payrails.executePayment(
130135
with: type, //.applePay or .payPal
131136
saveInstrument: false, //set to true if you want to store payment
@@ -150,7 +155,7 @@ payrails.executePayment(
150155

151156
Where
152157

153-
```(swift)
158+
```swift
154159
extension YourPaymentViewController: PaymentPresenter {
155160
func presentPayment(_ viewController: UIViewController) {
156161
DispatchQueue.main.async {
@@ -164,7 +169,7 @@ extension YourPaymentViewController: PaymentPresenter {
164169

165170
Payrails iOS SDK allows you to retrieve and reuse stored payments:
166171

167-
```(swift)
172+
```swift
168173
payrails.storedInstruments.forEach { storedElement in
169174
switch storedElement.type {
170175
case .payPal:
@@ -209,6 +214,134 @@ private func pay(
209214
}
210215
```
211216

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+
212345
## Security Policy
213346

214347
### Reporting a Vulnerability

0 commit comments

Comments
 (0)