Ottu
Ottu是一个iOS SDK,它可以让您快速轻松地在iOS应用中构建出色的支付体验。我们提供了强大且可定制的UI屏幕和元素,可以直接用于收集用户的支付信息。我们还暴露了支持这些UI的低级API,以便您可以构建完全自定义的体验。
功能
简化安全:我们使您收集如信用卡号等敏感数据变得简单,同时保持PCI合规性。这意味着敏感数据会直接发送到Ottu,而不是通过您的服务器。
苹果支付:我们提供了与Apple Pay的无缝集成。
原生UI:我们提供了用于收集支付详情的原生屏幕和元素。
本地化:我们支持以下本地化:英语、阿拉伯语。
推荐使用
如果您出售将在您的应用中消费的数字产品或服务(例如,订阅、游戏内货币、游戏关卡、访问高级内容或解锁完整版),则必须使用苹果的应用内购买API。有关更多信息,请参阅App Store审核指南。
隐私
Ottu SDK收集数据以帮助我们改进我们的产品并防止欺诈。这些数据永远不会用于广告,也不会出租、出售或提供给广告商。
要求
Ottu需要Xcode 13.0或更高版本,并且与目标iOS 12或更高版本的 应用兼容。
入门
要初始化SDK,您需要创建会话令牌。您可以使用我们的公共API创建会话令牌,点击此处了解更多关于我们公共API的详细信息。
注意:示例项目已在内repo中创建。如果遇到任何问题,请进行查看。
安装
使用 CocoaPods 安装
Ottu: Ottu 可通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile
pod 'Ottu', :git => 'https://github.com/ottuco/ottu-ios-sdk.git', :tag => '1.0.75'
使用 Swift 包管理器安装
Swift 包管理器 是一种用于自动化 Swift 代码发布的工具,并且集成到 swift
编译器中。
设置完您的 Swift 包后,将 Alamofire 添加为依赖项与将其添加到 Package.swift
的 dependencies
值一样简单。
dependencies: [
.package(url: "https://github.com/ottuco/ottu-ios-sdk.git")
]
手动安装
如果您不想使用上述任何依赖管理器,可以通过下载项目和将源文件夹保留在项目中手动将 Ottu 集成到项目中。
Swift 5.1、5.0、4.2、4.0
在 ViewController.swift 中,只需导入 Ottu 框架并初始化 Ottu SDK。
import Ottu
class ViewController: UIViewController,OttuDelegate {
var responseDict : [String:Any]?
var message = ""
//apikey: You will get the apikey from Ottu
//merchant_id: You will get the merchant id from Ottu
//sessionid: You will get the sessionid from the public API
//lang: This is for language. "en" for English and "ar" for Arabic
override func viewDidLoad() {
super.viewDidLoad()
//Intiate the SDK accordingly after getting session id from the public API documentation.
//session_id - It is generated when payment was created. See API documentation
//merchant_id - Merchant domain. See API documentation.
//apiKey - API Public key should be used. See API documentation.
//lang - You can use it to change the language. We support two languages english and arabic. You can use "en" for english and "ar" for arabic.
let session_id = "ENTER_YOUR_SESSION_ID"
_ = Ottu.init(session_id, merchant_id: "MERCHANT_ID", apiKey: "API_KEY" ,lang: "ENTER_LANGUAGE_ID_en_or_ar", viewController: self, delegate: self)
}
//The error callback is invoked when problems occur during a payment.
//Reason will be defined in the response attribute.
func errorCallback(message: String, response: [String : Any]?) {
responseDict = response
self.message = "Error"
self.dismissed()
}
//Called when a customer cancels the payment.
func cancelCallback(message: String, response: [String : Any]?) {
responseDict = response
self.message = "Cancel"
self.dismissed()
}
//Called when the payment completed successfully.
func successCallback(message: String, response: [String : Any]?) {
responseDict = response
self.message = "Success"
self.dismissed()
}
//It is a helper function that has to return a promise object, to create the redirect_url.
//This allows the merchant to redirect the user to the cart page and wait for a while before creating the redirect_url.
//In case the customer changes items in the cart, the due amount will be updated accordingly, then the merchant will wait for a while until the customer does not return, then the function returns a promise object, the cart will be frozen and marked as submitted, and the redirect_url will be generated.
func beforeRedirect() {
}
//After successCallback or cancelCallback or errorCallback you can show alert to the user accordingly.
func dismissed() {
DispatchQueue.main.asyncAfter(deadline: .now()+1) {
let alert = UIAlertController(title: self.message.capitalized, message: "\(String(describing: self.responseDict))", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
}
集成 Apple Pay
请按照以下步骤在 Storyboard 中集成 Apple Pay 按钮
现在为按钮创建一个动作,并用会话 ID 初始化 SDK。
let session_id = "ENTER_YOUR_SESSION_ID"
_ = Ottu.init(session_id, merchant_id: "MERCHANT_ID", apiKey: "API_KEY" ,lang: "ENTER_LANGUAGE_ID_en_or_ar",formsOfPayment: ["applePay"], viewController: self, delegate: self)
注意:您需要将 formsOfPayment 参数传递为 ["applePay"]。如果不传递,则将启动正常流程。
注意:要集成 Apple Pay,您需要在项目的功能中启用 Apple Pay。