CheckoutSdkIos - Beta
Beta - Do not use before speaking to [email protected]
Requirements
- iOS 10.0+
- Xcode 9.0+
- Swift 4.1+
Documentation
You can find the CheckoutSdkIos documentation on this website.
- Usage
- Customizing the card view
- Walkthrough
Installation
CocoaPods
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
CocoaPods 1.1+ is required to build CheckoutSdkIos 1.0+.
To integrate CheckoutSdkIos into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target '<Your Target Name>' do
pod 'CheckoutSdkIos', :git => 'https://github.com/floriel-fedry-cko/frames-ios.git'
end
Then, run the following command:
$ pod install
Carthage
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate CheckoutSdkIos into your Xcode project using Carthage, specify it in your Cartfile
:
github "floriel-fedry-cko/frames-ios" ~> 0.2
Run carthage update
to build the framework and drag the built CheckoutSdkIos
into your Xcode project.
Usage
Import the SDK:
import CheckoutSdkIos
CardViewController
Using class ViewController: UIViewController, CardViewControllerDelegate {
let checkoutAPIClient = CheckoutAPIClient(publicKey: "pk_test_6ff46046-30af-41d9-bf58-929022d2cd14",
environment: .sandbox)
let cardViewController = CardViewController(cardHolderNameState: .hidden, billingDetailsState: .hidden)
override func viewDidLoad() {
super.viewDidLoad()
// set the card view controller delegate
cardViewController.delegate = self
// replace the bar button by Pay
cardViewController.rightBarButtonItem = UIBarButtonItem(title: "Pay", style: .done, target: nil, action: nil)
// specified which schemes are allowed
cardViewController.availableSchemes = [.visa, .mastercard]
navigationController?.pushViewController(cardViewController, animated: false)
}
func onTapDone(card: CkoCardTokenRequest) {
checkoutAPIClient.createCardToken(card: card, successHandler: { cardToken in
print(cardToken.id)
}, errorHandler: { error in
print(error)
})
}
}
Using Methods available in CheckoutSdkIos
You can find more examples on the usage guide.
CheckoutAPIClient
:
Create the API Client // replace "pk_test_6ff46046-30af-41d9-bf58-929022d2cd14" by your own public key
let checkoutAPIClient = CheckoutAPIClient(publicKey: "pk_test_6ff46046-30af-41d9-bf58-929022d2cd14",
environment: .sandbox)
CardUtils
instance:
Create the let cardUtils = CardUtils()
CardUtils
to verify card number:
Use /// verify card number
let cardNumber = "4242424242424242"
let isCardValid = cardUtils.isValid(cardNumber: cardNumber)
CardTokenRequest
:
Create the card token request // create the phone number
let phoneNumber = CkoPhoneNumber(countryCode:number:)
// create the address
let address = CkoAddress(name:addressLine1:addressLine2:city:state:postcode:country:phone:)
// create the card token request
let cardTokenRequest = CkoCardTokenRequest(number:expiryMonth:expiryYear:cvv:name:billingAddress:)
Create a card token:
let checkoutAPIClient = CheckoutAPIClient(publicKey: "pk_......", environment: .live)
// create the phone number
let phoneNumber = CkoPhoneNumber(countryCode:number:)
// create the address
let address = CkoAddress(name:addressLine1:addressLine2:city:state:postcode:country:phone:)
// create the card token request
let cardTokenRequest = CkoCardTokenRequest(number:expiryMonth:expiryYear:cvv:name:billingAddress:)
checkoutAPIClient.createCardToken(card: cardTokenRequest, successHandler: { cardTokenResponse in
// success
}, errorHandler { error in
// error
})
The success handler takes an array of CkoCardTokenResponse
as a parameter.
The error handler takes an ErrorResponse
as a parameter.
License
CheckoutSdkIos is released under the MIT license. See LICENSE for details.