iOS SDK
A library is available to evaluate customers in iOS mobile apps. The whole process takes place in the same way as with the Twisto.js library on the web.
Just as on the web, you need to have encrypted data from your e-shop server. The public key is also used to identify requests.
Warning: The secret key must never get into the mobile application code. Perform all requests with the secret key only from the server.
Installation
You can either add the library manually to the project or use the CocoaPods.
CocoaPods
To install the library via CocoaPods, simply add a line to the Podfile
file:
pod 'Twisto'
Then run the command in the console:
$ pod install
Manual installation
First, download the Twisto library.
A distributed zip file contains a directory Twisto.framework
. Use drag & drop to drag the package to your project from the directory where you unpack the archive. In the project settings in the General section, add Twisto.framework
to the Embedded Binaries section.
Implementation
First, you need to initialize a class instance Twisto
:
import UIKit
class ViewController: UIViewController {
var twisto: Twisto!
override func viewDidLoad() {
super.viewDidLoad()
let publicKey = "" // You can find your public key in administration
twisto = Twisto(publicKey: publicKey)
}
}
After submitting the order data to the eshop server, adding the previous orders data, and encrypting with secret key, the data will be sent back to the application where it will be passed to Twisto library by calling checkWithPayload
method:
let payload = "…".data(using: String.Encoding.utf8)
twisto.check(
withPayload: payload!,
acceptedCompletionHandler: {
(transactionId) in
}, rejectedCompletionHandler: {
(transactionId, reason) in
}, errorCompletionHandler:{
(error) in
}, willDisplayLoginDialogHandler: {
}, didHideLoginDialogHandler: {
}
)
The method checkWithPayload
will send customer data to Twisto servers and trigger asynchronous evaluation. Your requests, including error messages, can be found in the e-shop administration.
The response is asynchronous, it is necessary to ensure that the Twisto object is not prematurely released by automatic memory management
The evaluation ends by calling one of the return blocks:
acceptedCompletionHandler
- the order was approved, the argument transactionId contains the transaction ID used to create the order on the eshop server side.rejectedCompletionHandler
- the order was declined, the argumentreason
contains the text of the error message that should be displayed to the user. The user should be offered an alternative payment method.errorCompletionHandler
- an error occurred due to invalid request or connection failure.
If the order is evaluated on a previously unknown address, a user login is required for authentication first. The block will be called before the login request dialog is displayed willDisplayLoginDialogHandler
. In this block, stop any animation that may be in progress that could block the displayed dialog. After you enter your login information or close the user dialog, didHideLoginDialog
block will be called where you can re-display the animation informing the user of the ongoing user order evaluation activity.