Quick start
Follow this integration guide for either iOS or Android.
Once you have access to our SDKs, you can begin to integrate them into your iOS or Android mobile applications.
1. Integration
iOS
For iOS, you can add the SDK to your project by adding a new Swift package dependency in Xcode and pointing to the GitHub Repository. For the default behaviour, enable all packages presented in the package selection. If you are building an App Clip project, you can select only the required packages, which will depend on your payment methods and flows. Reach out to our support team if you are unsure about the packages you require.
Instead of adding packages via a Swift package dependency, you can also add the SDK via Cocoapods with pod 'Datatrans'
.
Additional requirements for iOS
For the card scanner to work, a usage description for camera use will be required in your .plist
file. If you do not provide a description for camera use, the app will crash when starting the card scanner.
Key : Privacy - Camera Usage Description
Value : $(PRODUCT_NAME) requires camera access to scan cards.
Android
For Android projects, you can link the repository and dependencies as demonstrated here:
repositories {
...
maven { url 'https://datatrans.jfrog.io/artifactory/mobile-sdk/' }
}
dependencies {
...
implementation 'ch.datatrans:android-sdk:3.3.0' // check release notes for latest version
}
If you are building an Instant app, you may exclude specific packages that are not required in your project. This will depend on your tokenization process, however, you should be able to exclude all components by default. Reach out to our support team if you are unsure about the packages you can exclude.
dependencies {
...
implementation ('ch.datatrans:android-sdk:3.3.0') { // check release notes for latest version
exclude group: 'io.card', module: 'android-sdk'
}
}
The following dependencies can be excluded:
Feature | Group | Module |
---|---|---|
Credit Card Scanner | io.card | android-sdk |
Google Pay | com.google.android.gms | play-services-wallet |
Samsung Pay | com.samsung.android.sdk | samsungpay |
2. SDK initialization
Create a tokenization object with your merchantId
and paymentMethodTypes
to start a tokenization. Below are some example of the suggested minimum options to start a tokenization on iOS (Swift) and Android (Kotlin, Java).
let tokenizationRequest = PCIPTokenization(merchantId: merchantId, paymentMethodTypes: [ .Visa, .Mastercard])
tokenizationRequest.delegate = self
tokenizationRequest.start(presentingController: navigationController)
val tokenization = PCIPTokenization(merchantId, [VISA, MASTER_CARD])
tokenizationRequest.listener = this
PCIPTokenizationRegistry.startTokenization(this, tokenizationRequest)
PCIPTokenization tokenization = new PCIPTokenization(merchantId, [VISA, MASTER_CARD]);
tokenization.setListener(this);
PCIPTokenizationRegistry.INSTANCE.startTokenization(this, tokenization);
Check out our detailed class descriptions for iOS and Android to discover more initialization options.
After the tokenization has been completed, your PCIPTokenizationDelegate
(iOS) or PCIPTokenizationListener
(Android) is notified about the success, error or cancel state of the processed tokenization. The tokenizationId
, as well as additional card metadata are returned in the PCIPTokenizationSuccess
class.
It is also possible to collect only the CVV code of a card.
That is, without collecting the credit card number, or PAN.
Check
init(merchantId:cvvOnlyCard:)
for iOS andPCIPTokenization(merchantId: String, cvvOnlyCard: CvvOnlyCard)
for Android in the respective API references to learn more.
3. Obtain tokens
To obtain the tokenized values, you first need to submit the tokenizationId
returned by the SDK to your server.
Then, call the Tokenzation
API from your server together with the tokenizationId
to obtain the tokens for the card number and the CVV code. Additionally, the API returns the expiry dates, fingerprint of the card number and the cardInfo
object.
Example
curl --request POST \
--url 'https://api.sandbox.datatrans.com/v1/tokenizations/{{tokenizationId}}' \
--header 'Authorization: Basic {{basicAuth}}'
{
"paymentMethod": "VIS",
"alias": "7LHXscqwAAEAAAGCpe2M7PXWj2StAOG6",
"fingerprint": "F-fgxnFwN-gsIw7y80T-kpBB",
"maskedCard": "489537xxxxxx6287",
"aliasCVV": "aYsIbb_KTQSbmWDrqlPp7hXM",
"expiryYear": "23",
"expiryMonth": "02",
"cardInfo": {
"brand": "VISA",
"type": "debit",
"usage": "consumer",
"country": "US",
"issuer": "U.S. REGION"
}
}
Updated 8 months ago