Getting Started with the TTC Pay for iOS


The TTC TReE SDK can be installed by using CocoaPods.

#Open use_frameworks!

pod 'TTCPay'

Note: For Object-C projects, please select the swift version 4.1+.

Add the URL Scheme

Follow the followng naming guideline for the URL Scheme.

"TTC-" + APP Bundle identifier e.g : TTC-com.tataufo.TTC-SDK-iOS-Demo


This method is called when the DAPP starts.

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

        window = UIWindow(frame: UIScreen.main.bounds)
        window!.rootViewController = ViewController()

        TTCPay.shared.appId = "appid"
        TTCPay.shared.secretKey = "secretKey"

        return true

Create order

Build a TTCCreateOrder object in advance, use the background server signature, and successfully return the order number.

TTCPay.shared.createOrderAndPay(createOrder: createOrder) { (success, orderResult, error) in
    if success, orderResult != nil {
        print("create success : \(orderResult!.orderId.description)")
    } else {
        print("create failed:%@", error?.errorDescription ?? "")

Query exchange rate

1-CNY 2- USD 3-KRW 4-VND, the incoming parameters correspond to different currency exchange rates

TTCPay.shared.fetchPrice(currencyType: 2) { (success, price, error) in
   if success {
       self.TTCPrice = Double(price!) ?? 0

Query order information

Incoming order number returns a TTCOrder object containing the order information.

TTCPay.shared.fetchOrder(orderId: orderID) { [weak self] (success, data, error) in
    if success, let fetOrder = data {

Payment callback processing

The wallet payment success will call back sdk, add the following code to process the callback, process the success and go back to the query order and call back the order information in the place where TTCPay.shared.payBack is implemented.

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
  return TTCPay.receivePayCallBack(url: url)

TTCPay.shared.payBack = { success, order, error in
    if success, order != nil, !order!.txHash.isEmpty {
        print("txhash: ",order?.txHash ?? "txhash")

    } else {
        print(error?.errorDescription ?? "error")