使用CocoaPods安装
#需要打开 use_frameworks!
use_frameworks!
pod 'TTCPay'
注意: 如果使用的Object-c语言接入的SDK,请指定SDK引用库的swift版本号为4.1
添加规则为:"TTC" + "-" + "APP的Bundle identifier"。 例如TTC-com.tataufo.TTC-SDK-iOS-Demo
在程序启动时调用
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window!.rootViewController = ViewController()
window!.makeKeyAndVisible()
TTCPay.shared.appId = "appid"
TTCPay.shared.secretKey = "secretKey"
return true
}
提前构建一个TTCCreateOrder对象,使用后台服务器签名,成功返回订单号等。
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 ?? "")
}
}
1-CNY 2- USD 3-KRW 4-VND,传入参数对应不同的货币汇率
TTCPay.shared.fetchPrice(currencyType: 2) { (success, price, error) in
if success {
self.TTCPrice = Double(price!) ?? 0
}
}
传入订单号,返回包含订单信息的TTCOrder对象。
TTCPay.shared.fetchOrder(orderId: orderID) { [weak self] (success, data, error) in
if success, let fetOrder = data {
print(fetOrder.txHash)
}
}
钱包支付成功会回调sdk,添加以下代码处理回调,处理成功回去查询订单并在实现TTCPay.shared.payBack的地方回调订单信息。
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")
}
}