iOS Card Tokenization Guide
Swift Playground Available
The Omni iOS SDK includes a Swift Playground for you to try. All you need to get started is your webpayments token
, provided by your Fattmerchant account manager. This playground, named Tokenization.Playground
is located in the project root.
Requirements
- Xcode 8+
- iOS 9+
- Omni Webpayments Token
Installation
Use CocoaPods to install the Fattmerchant iOS SDK.
- Install CocoaPods
- Add
pod 'Fattmerchant'
to yourPodfile
- Run
pod install
Create a PaymentMethod
To accept a payment, you’ll need to collect information from the customer and tokenize it to create an Omni PaymentMethod
. You will then be able to use this PaymentMethod
with Fattmerchant’s Omni API to run the transaction.
Setup
You’ll first need to setup the FattmerchantClient
for usage. All you have to do here is set the webPaymentsToken
field on the shared FattmerchantConfiguration
. FattmerchantClient
will then use that configuration by default.
class MyApplication: Application() {
override fun onCreate() {
super.onCreate()
FattmerchantConfiguration.shared.webPaymentsToken = "mywebpaymentstoken"
}
}
Alternatively, you may create a configuration object and pass it to the new FattmerchantApi
instance as you need it.
val config = FattmerchantConfiguration("https://apidev01.fattlabs.com", "fattwars")
val client = FattmerchantClient(config)
Collect payment information
You first want to collect credit card information and populate a CreditCard
object.
val creditCard = CreditCard(personName = "Joan Parsnip",
cardNumber = "4111111111111111",
cardExp = "1230",
addressZip = "32822")
### Create the PaymentMethod
Once you have a `CreditCard` object, call the `tokenize(:)` method on `FattmerchantClient` object and pass a listener to be notified once tokenization is complete.
```kotlin
var fattClient = FattmerchantClient(config)
fattClient.tokenize(card) { (response) in
client.tokenize(card, object : FattmerchantClient.TokenizationListener {
override fun onPaymentMethodCreated(paymentMethod: PaymentMethod) {
// Success! You can now run a transaction with Fattmerchant using paymentToken as the PaymentMethod
}
override fun onPaymentMethodCreateError(errors: String) {
System.out.print(errors)
}
})
}
Testing
If you’d like to try tokenization without real payment information, you can use the CreditCard.testCreditCard()
method to get a test credit card.
let creditCard = CreditCard.testCreditCard()
If you want to test failures, you can use the following method
let failingCreditCard = CreditCard.failingTestCreditCard()
Or you can create the CreditCard
object with the following testing payment information:
Credit card numbers
Card Type | Good Card | Bad Card |
---|---|---|
VISA | 4111111111111111 | 4012888888881881 |
Mastercard | 5555555555554444 | 5105105105105100 |
Amex | 378282246310005 | 371449635398431 |
Discover | 6011111111111117 | 6011000990139424 |
JCB | 3569990010030400 | 3528327757705979 |
Diners Club | 30569309025904 | 30207712915383 |
Use any CVV number for the above
Taking a Payment
Now that you have the token representing the payment method, you can use the POST /charge
resource on the Omni API. this will allow you to create a transaction with the payment method. payment_method_id
is a required field, where you will need to pass in the id of the payment method that you received from the tokenize(:)
method.