Skip to main content

iOS SDK

A powerful and flexible SDK for an easy payment processing with any iOS, watchOS, macOS, or tvOS app.

iOS SDK

Tuna iOS SDK#

The Tuna SDK for Apple's platforms will allow you to start a payment session, store credit cards, and generate tokens for payment through your backend. In this section, you will find all details needed to configure and use the Tuna's iOS SDK in your app.

Getting started: Configuration#

The Tuna iOS SDK is available as a Swift package. You can add it to your Xcode project by going to File > Swift Packages > Add Package Dependency.

You can also integrate it directly by editing your Package.swift file:

SWIFT
1let package = Package(
2    ...
3    dependencies: [
4    .package(url: "https://github.com/tuna-software/ios-sdk.git", from: "0.1.0")
5    ],
6 ...
7)

CocoaPods#

Support for CocoaPods coming soon.

Usage#

Initializing the SDK#

This must be done early in your app's lifecycle. For example, in your app delegate's application:didFinishLaunchingWithOptions: callback. The usage of the iOS SDK requires an app token located at your Account Settings section of your Console in the Developer tab.

Don't you have a Tuna Account? Click here to start your registration at Tuna.

Swift#

SWIFT
1import UIKit
2import Tuna
3@main
4class AppDelegate: UIResponder, UIApplicationDelegate {
5func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?)        Bool {
6TunaSDK.configure(appToken: "<your Tuna app token>")
7
8// ...
9
10return true
11}
12
13// ...

If you wish to operate in the sandbox environment, you have to pass in the optional sandbox parameter with a value of true:

Operate in sandbox
SWIFT
objectivec
1@import Tuna;
2
3@implementation AppDelegate
4
5
6- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
7    [TunaSDK configureWithAppToken:@"your Tuna app token" sandbox:YES];
8    
9    return YES;
10}

Tuna session#

Every interaction with the Tuna APIs happens within a session. You must provide a session ID obtained from Tuna in order to initialize the SDK. For security reasons, this session ID must be negotiated between your own server and Tuna's servers.

This is how initializing a session looks like:

  • Your app sends a request to your own backend
  • Your backend talks to Tuna's servers, to generate a new session ID for the customer
  • Tuna's servers send the newly generated session ID to your own backend
  • Your backend responds to your app with the new session ID
  • Your app calls the Tuna SDK in order to set the current session ID

You do not have to start a session on your app launch. A good trigger to start the session, for example, is when the customer starts your checkout flow.

Tuna Session
SWIFT
objectivec
1import Tuna
2
3// ...
4
5func startTunaSession() {
6// Method that calls your API service.
7MyAPI.generateSessionID(...) { result in
8    switch result {
9    case .success(let newSessionID):
10    // Set the new session ID on TunaSDK after obtaining it from your servers.
11    TunaSDK.sessionID = newSessionID
12    case .failure(let error):
13    // ...
14}
15}
16}

Adding a new card#

Use the addNewCard method to add a new card into the user's account. This method takes the credit card information: number, holder name, expiration month and year, the CVV (optional) and a save parameter. If the save parameter is true, the card will be saved and retrieved in the future when the same user logs in. If not, it can only be used within the current session.

The CVV parameter should be used when creating a card that is going to be used immediately. If the card is only going to be used later, you can save it without the CVV, then use bind later to get a usable token.

Add new card
SWIFT
objectivec
1[TunaSDK addNewCardWithNumber:@"card number goes here"
2cardHolderName:@"cardholder name goes here"
3expirationMonth:1 // expiration month, int from 1 to 12
4expirationYear:21 // expiration year, two digits
5           cvv:nil
6          save:YES
7    completion:^(TunaCard *newCard, TunaSDKError *error)
8{
9if (error) {
10// Something went wrong
11} else {
12// All good
13}
14}];

Binding a saved card with CVV#

Bind a saved card with cvv
SWIFT
objectivec
1[TunaSDK bindCard:card cvv:@"card CVV input by the user goes here" completion:^(TunaCard *card, TunaSDKError *error) {
2    if (error) {
3        // Something went wrong
4    } else {
5        // Ready to make money
6    }
7}];

What is next?#

Once you have your account and your integration concluded, you can start the setup up of your services and flows in Console. For further details, please check out the Console section.