Documentation

 Back to top

Tapbuy SDK for iOS, version 1.0.0-beta1

Tapbuy SDK for iOS is the easiest way to use Tapbuy in your iOS app : sell your products through the Tapbuy express checkout solution.

Conditions: Xcode 8 and iOS 8 or later. Xcode 8 requires a Mac running macOS Sierra 10.12 or OS X El Capitan 10.11.5 or later.

Installation

1. Create a Tapbuy app

If your app is not yet registered with a Tapbuy app ID, you first have to create it. You can share an app ID between several platforms.

Connect on the Tapbuy backend and access to the Home > Apps section.

Simply click on Add an app and give it a name to create a new app ID.

2. Install the SDK

The TapbuySDK comes in an Objective-C version and a Swift 3 version.

If your app is written in Swift version < 3 you have to use the Objective-C version of TapbuySDK.

2.1. Install with Cocoapods (recommended)

Cocoapods is a dependency manager for Objective-C / Swift projects. You can install it with the following command:

$ sudo gem install cocoapods

To integrate TapbuySDK into your Xcode project, add it to your Podfile.

Objective-C version

Integrate the Objective-C version of TapbuySDK in your Podfile :

target '<Your Target Name>' do
    use_frameworks!
    pod 'TapbuySDK_iOS_objc', "1.0.0-beta1"
end

Swift version

Integrate the Swift version of TapbuySDK in your Podfile :

target '<Your Target Name>' do
    use_frameworks!
    pod 'TapbuySDK_iOS_swift', "1.0.0-beta1"
end

If your app is written in Objective-C, you should specify the SWIFT_VERSION in the Pod target build settings. This can be done automatically by adding the following lines in your Podfile :

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['SWIFT_VERSION'] = '3.0'
        end
    end
end

Pod install

Then, run the following command :

$ pod install

If not already the case, it will create a .xcworkspace file for your project. Be sure to open your project in Xcode with this file from now (close Xcode if you were working with the .xcodeproj and open the .xcworkspace file).

2.2. Install manually

Download the SDK and uncompress the archive.

To add the SDK in Xcode :

  1. In your target General settings tab, find the Embedded binaries section and drag TapbuySDK_iOS_objc.framework (or TapbuySDK_iOS_swift.framework) on it.

  2. Select Copy items if needed in the popup window and click on Finish. Now you should find the framework under both Embedded binaries and Linked frameworks and libraries.

  3. In the Project Navigator you can create a new group called Frameworks and move TapbuySDK_iOS_objc.framework (or TapbuySDK_iOS_swift.framework) into it.

Screenshots:

If you want to manually install the Swift version of TapbuySDK in a pure Objective-C project, you may encounter a runtime error. To fix this, simply go to your target Build Settings and set Always Embed Swift Standard Libraries to Yes.

3. Configure the Xcode project

Now, configure the .plist file for your project :

  1. In Xcode, right-click on your .plist file and select “Open as Source Code”.

  2. Copy and paste the following XML extract in the body of your file (<dict></dict>) and replace :

  • tapbuy{your-app-id} by your Tapbuy app ID preceeded by the tapbuy prefix. For example: tapbuy1234.

  • {your-app-id} by your Tapbuy app ID.

<key>TapbuyAppID</key>
<string>{your-app-id}</string>
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>tapbuy{your-app-id}</string>
    </array>
  </dict>
</array>

4. Connect AppDelegate

In order to handle the results of the payment process, you have to connect your AppDelegate to TapbuySDKAppDelegate.

// Swift

// AppDelegate.swift
import TapbuySDK_iOS_swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {

    return TapbuySDKAppDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

    return TapbuySDKAppDelegate.sharedInstance().application(app, open: url, options: options)

}
// Objective-C

// AppDelegate.m
@import TapbuySDK_iOS_objc;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    return [[TapbuySDKAppDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];

}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {

    return [[TapbuySDKAppDelegate sharedInstance] application:app openURL:url options:options];

}

Usage

1. Note about Objective-C / Swift

The TapbuySDK comes in an Objective-C version and a Swift 3 version.

Your app is written in Objective-C

If your app is written in Objective-C you can use this statement to import TapbuySDK in your file headers :

// Objective-C
@import TapbuySDK_iOS_objc;

Your app is written in Swift

If your app is written in Swift 3 you can use this statement to import TapbuySDK in your file headers :

// Swift 3
import TapbuySDK_iOS_swift

If your app is written in a previous version of Swift you can use the Objective-C version of TapbuySDK :

// Swift < 3
import TapbuySDK_iOS_objc

Connect on the Tapbuy backend and access to the Link builder section.

Paste a target product URL of your website, activate the SDK option and click on Generate link.

Then you should obtain a Tapbuy direct link that you can use to launch the Tapbuy checkout process on the selected product.

3. Start a new Tapbuy checkout process

// Swift

// Display the checkout view controller for a given product URL and parameters
TapbuySDK.sharedInstance().checkout(URL(string: "PRODUCT URL HERE")!, parameters: nil, viewController: nil)
// Objective-C
// Display the checkout view controller for a given product URL and parameters
[[TapbuySDK sharedInstance] checkout:[[NSURL alloc] initWithString:@"PRODUCT URL HERE"] parameters:nil viewController:nil];

4. Start a new custom Tapbuy checkout process

// Swift

// Build custom parameters for checkout
let checkoutParams = TapbuySDKCheckoutParameters()
checkoutParams.userEmail = "firstname.lastname@domain.com"
checkoutParams.userAddress = "1, infinite loop street"
checkoutParams.userCountryIsoCode = "fr"
checkoutParams.displayOptions = [TapbuySDKCheckoutDisplayOption.similarProducts.rawValue, TapbuySDKCheckoutDisplayOption.complementaryProducts.rawValue]

// Display the checkout view controller for a given product URL and parameters
TapbuySDK.sharedInstance().checkout(URL(string: "PRODUCT URL HERE")!, parameters: checkoutParams, viewController: nil)
// Objective-C

// Build custom parameters for checkout
TapbuySDKCheckoutParameters *checkoutParams = [[TapbuySDKCheckoutParameters alloc] init];
checkoutParams.userEmail = @"firstname.lastname@domain.com";
checkoutParams.userAddress = @"1, infinite loop street";
checkoutParams.userCountryIsoCode = @"fr";
checkoutParams.displayOptions = @[@(TapbuySDKCheckoutDisplayOptionSimilarProducts), @(TapbuySDKCheckoutDisplayOptionComplementaryProducts)];

// Display the checkout view controller for a given product URL and parameters
[[TapbuySDK sharedInstance] checkout:[[NSURL alloc] initWithString:@"PRODUCT URL HERE"] parameters:checkoutParams viewController:nil];

Customize checkout UI

Change Tapbuy control tint color

Requires iOS 9 or later.

You can customize the checkout control tint color.

You can define a tint color in the .plist file, by copying and pasting the following XML extract, and by replacing :

  • {hex-value} by an hexadecimal color value, like “#0000ff”
<key>TapbuyBrowserControlTintColor</key>
<string>{hex-value}</string>

Change Tapbuy bar tint color

Requires iOS 10 or later.

You can customize the checkout bar tint color.

You can define a tint color in the .plist file, by copying and pasting the following XML extract, and by replacing :

  • {hex-value} by an hexadecimal color value, like “#c3c3c3”
<key>TapbuyBrowserBarTintColor</key>
<string>{hex-value}</string>

Help

Changelog

Check the SDK Changelog file for changes and updates.

Testing and debugging

Debug and sandbox modes are available to help SDK integration. They can be activated separately or together.

  • Sandbox : in this mode you can use your own product links. No payment or purchases will be effectively executed.

  • Debug : unlocks technical custom error messages

// Swift

// Build SDK global parameters
let globalParams = TapbuySDKGlobalParameters()
globalParams.debug = true
globalParams.sandbox = true

// Apply SDK global parameters
TapbuySDK.sharedInstance().setParameters(globalParams)

// Call the checkout process here
// Objective-C

// Build SDK global parameters
TapbuySDKGlobalParameters *globalParams = [[TapbuySDKGlobalParameters alloc] init];
globalParams.debug = YES;
globalParams.sandbox = YES;

// Apply SDK global parameters
[[TapbuySDK sharedInstance] setParameters:globalParams];

// Call the checkout process here

Sample application

A sample application (the source is in the repository) is available to check how the Tapbuy SDK can be implemented.

Bugs and feedback

For more details, bug feedback, or support contact us at support@tapbuy.io

License

Copyright (c) 2016. Tapbuy

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Login
Request a new password

Votre formulaire a été soumis. Nous revenons vers vous dans les plus brefs délais. N'hésitez pas à nous contacter si vous avez des questions, nous serons ravis d'y répondre !
L'équipe Tapbuy

Best,

The Tapbuy Team

Close

Best,

The Tapbuy Team

Close