Orkestapay iOS swift 创建支付方式并获取优惠
Orkestapay iOS 通过 CocoaPods 或 Swift 包管理器 提供。
- iOS SDK 14+
- Swift 5.7
要将 Orkestapay 包添加到 Xcode 项目中,选择文件 > 添加包,输入 https://github.com/orkestapay/orkestapay-ios.git
作为仓库 URL,或者按照 Apple 的 将包依赖项添加到您的应用程序指南添加 Swift 包依赖项。
import Orkestapay
为创建 Orkestapay 客户端实例,需要以下内容
- 商户 ID
- 公钥
let merchantId = "merchantId"
let publicKey = "publicKey"
var orkestapay: OrkestapayClient!
func myFunction() {
orkestapay = OrkestapayClient(merchantId: merchantId, publicKey: publicKey, isProductionMode: false)
}
如果您想切换到生产模式,您必须发送 isProductionMode 为 true
库包含生成设备会话 ID 的函数
var orkestapay: OrkestapayClient!
func myFunction() {
orkestapay = OrkestapayClient(merchantId: merchantId, publicKey: publicKey, isProductionMode: false)
orkestapay.createDeviceSession(successSessionID: successSessionId, failureSessionID: failureSessionId)
}
func successSessionId(sessionId: String) {
print("SessionId: \(sessionId)")
}
func failureSessionId(error: String) {
print("error: \(error)")
}
库包含创建支付方式的函数
var orkestapay: OrkestapayClient!
func myFunction() {
orkestapay = OrkestapayClient(merchantId: merchantId, publicKey: publicKey, isProductionMode: false)
let card = Card(number: "4111111111111111", expirationMonth: "12", expirationYear: "2025", cvv: "123", holderName: "Hector Rodriguez", oneTimeUse: false)
let paymentMethod = PaymentMethod(alias: "Test card", customerId: nil, deviceSessionId: deviceSessionId, card: card)
Task.init {
do {
let response = try await orkestapay.createPaymentMethod(paymentMethod: paymentMethod)
print(response)
} catch let error as OrkestapayError {
print(error.errorDescription!)
} catch {
print(error.localizedDescription)
}
}
}
库包含获取优惠的函数
var orkestapay: OrkestapayClient!
func myFunction() {
orkestapay = OrkestapayClient(merchantId: merchantId, publicKey: publicKey, isProductionMode: false)
Task.init {
do {
let response = try await orkestapay.getPromotions(binNumber: "123456", currency: "MXN", totalAmount: "1000")
print(response)
} catch let error as OrkestapayError {
print(error.errorDescription!)
} catch {
print(error.localizedDescription)
}
}
}