SecuXPaymentKit
Example
To run the example project, clone the repo, and run pod install
from the Example directory
Usage
Add bluetooth privacy permissions in the plist
Import the the module
import SecuXPaymentKit
Use SecuXAccountManager to get account balance and history
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: ) returns SecuXAccountBalance object
public struct SecuXAccountBalance: Codable {
public var balance: Double
public var formattedBalance: Double
public var balance_usd: Double
}
getAccountHistory(account:) returns SecuXAccountHistory object array
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
}
Use SecuXPaymentManager to get store info. and do payment
-
Implement SecuXPaymentManagerDelegate
func paymentDone(ret: Bool, errorMsg: String) Called when payment is completed. Returns payment result and error message.
func updatePaymentStatus(status: String) Called when payment status is changed. Payment status are: "Device connecting...", "DCT transferring..." and "Device verifying..."
func getStoreInfoDone(ret: Bool, storeName: String, storeLogo: UIImage) Called when get store information is completed. Returns store name and store logo.
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!")
}
}
}
- Get store information
var paymentMgr = SecuXPaymentManager()
paymentMgr!.delegate = self
let paymentInfo = "{\"amount\":\"100\", \"coinType\":\"DCT\", \"deviceID\":\"4ab10000726b\"}"
paymentMgr.getStoreInfo(paymentInfo: self.paymentInfo)
- Do payment
paymentMgr.doPayment(account: account!, storeName: storeName, paymentInfo: self.paymentInfo)
Requirements
- iOS 12.0+
- Swift 5.0
Installation
CocoaPod
SecuXPaymentKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SecuXPaymentKit'
Carthage
To integrate SecuXPaymentKit into your Xcode project using Carthage, specify it in your Cartfile file:
binary "https://maochuns.github.io/SPManager.json"
github "secuxtech/SecuXPaymentKit"
Author
SecuX, [email protected]
License
SecuXPaymentKit is available under the MIT license. See the LICENSE file for more info.