SecuXPaymentKit
示例
要运行示例项目,请克隆仓库,然后从 Example 目录运行 pod install
用法
在 plist 中添加蓝牙隐私权限
导入模块
import SecuXPaymentKit
使用 SecuXAccountManager 获取账户余额和历史记录
let accountMgr = SecuXAccountManager()
let account = SecuXAccount(name: "xxxx", type: .DCT, path: "", address: "", key: "")
let (ret, balance) = accountMgr!.getAccountBalance(account: account)
if ret{
print("Get account balance succssfully! \(balance?.balance ?? 0) USD Balance = \(balance?.balance_usd ?? 0) Balance = \(balance?.formattedBalance ?? 0)")
}
let (ret, historyArr) = accountMgr!.getAccountHistory(account: account)
if ret{
for item in historyArr{
print("\(item.timestamp) \(item.tx_type) \(item.formatted_amount) \(item.amount_usd) \(item.detailsUrl)")
}
}
getAccountBalance(account: ) 返回 SecuXAccountBalance 对象
public struct SecuXAccountBalance: Codable {
public var balance: Double
public var formattedBalance: Double
public var balance_usd: Double
}
getAccountHistory(account:) 返回 SecuXAccountHistory 对象数组
public struct SecuXAccountHistory: Codable {
public var address: String //Send to or receive from address
public var tx_type: String //"Send" or "Receive"
public var amount: Double
public var amount_symbol: String? //Coin type, e.g. DCT
public var formatted_amount: Double
public var amount_usd: Double
public var timestamp: String //YYYY-MM-DD hh:mm:ss
public var detailsUrl: String //Transaction details link
}
使用 SecuXPaymentManager 获取商店信息并进行支付
-
实现 SecuXPaymentManagerDelegate
func paymentDone(ret: Bool, errorMsg: String) 当支付完成后被调用。返回支付结果和错误消息。
func updatePaymentStatus(status: String) 当支付状态改变时被调用。支付状态有:"设备连接中...","DCT 转账中..." 和 "设备验证中..."
func getStoreInfoDone(ret: Bool, storeName: String, storeLogo: UIImage) 当获取商店信息完成时被调用。返回商店名称和商店标志。
extension ViewController: SecuXPaymentManagerDelegate{
func paymentDone(ret: Bool, errorMsg: String) {
print("paymentDone \(ret) \(errorMsg)")
}
func updatePaymentStatus(status: String) {
print("updatePaymentStatus \(status)")
}
func getStoreInfoDone(ret: Bool, storeName: String, storeLogo: UIImage) {
print("getStoreInfoDone")
if ret{
paymentMgr!.doPayment(account: decentAccount!, storeName: storeName, paymentInfo: self.paymentInfo)
}else{
print("Get store info. faied!")
}
}
}
- 获取商店信息
var paymentMgr = SecuXPaymentManager()
paymentMgr!.delegate = self
let paymentInfo = "{\"amount\":\"100\", \"coinType\":\"DCT\", \"deviceID\":\"4ab10000726b\"}"
paymentMgr.getStoreInfo(paymentInfo: self.paymentInfo)
- 进行支付
paymentMgr.doPayment(account: account!, storeName: storeName, paymentInfo: self.paymentInfo)
要求
- iOS 12.0+
- Swift 5.0
安装
CocoaPod
SecuXPaymentKit 通过 CocoaPods 提供。要安装,只需将以下行添加到您的 Podfile 文件中
pod 'SecuXPaymentKit'
Carthage
要将 SecuXPaymentKit 集成到您的 Xcode 项目中,使用 Carthage,在您的 Cartfile 文件中指定它
binary "https://maochuns.github.io/SPManager.json"
github "secuxtech/SecuXPaymentKit"
作者
SecuX,[邮箱地址保护]
许可
SecuXPaymentKit 在 MIT 许可下可用。更多信息请参见 LICENSE 文件。