The secux-paymentkit-sample-for-springtrees-ios is a sample APP for showing how to scan the QRCode from P22 and confirm the promotion / payment / refill to the P22 device via secux-paymentkit-v2.
To run the example project, clone the repo, and run pod install
from the Example directory first.
secux-paymentkit-v2 is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'secux-paymentkit-v2'
import secux_paymentkit_v2
Create SecuXAccountManager object
let accManager = SecuXAccountManager()
- Merchant Login
Must login the assigned merchant account before calling payment related APIs.
Note: Login session is valid for 30 minutes. To continue use after 30 minutes, relogin is required.
SecuX Server API: /api/Admin/Login
func loginMerchantAccount(accountName:String, password:String)
-> (SecuXRequestResult, Data?)
accountName: Merchant account name.
password: Merchant account password.
SecuXRequestResult shows the operation result. If the result is SecuXRequestOK,
login is successful, otherwise login failed and data might contain an error message.
func login(name:String, password:String) -> Bool{
let (ret, data) = accountManager.loginMerchantAccount(accountName: name,
password: password)
guard ret == SecuXRequestResult.SecuXRequestOK else{
print("login failed!")
if let data = data,
let error = String(data: data, encoding: String.Encoding.utf8) {
print("Error: \(error)")
}
return false
}
return true
}
Create SecuXPaymentManager object
let paymentManager = SecuXPaymentManager()
- Get store information
Get store information via the hashed device ID in P22 QRCode.
SecuX Server API: /api/Terminal/GetStore
func getStoreInfo(devID:String) -> (SecuXRequestResult, String, SecuXStoreInfo?)
devID: Hashed device ID from P22 QRCode
SecuXRequestResult shows the operation result. If the result is SecuXRequestOK,
getting store information is successfully, store information is in the SecuXStoreInfo,
otherwise getting store information is failed and string might contain an error message.
Note: if return result is SecuXRequestNoToken / SecuXRequestUnauthorized, the login
session is timeout, please relogin the system.
SecuXStoreInfo contains store code, store name, store icon, store device id and
store supported coin/token array
let (ret, error, storeInfo) = paymentManager.getStoreInfo(devID: devIDHash)
guard ret == SecuXRequestResult.SecuXRequestOK else{
self.showMessageInMainThread(title: "Get store info. failed!",
message: "Error: \(error)")
return
}
guard let devID = storeInfo?.devID else{
self.showMessageInMainThread(title: "Invalid store info. no device ID",
message: "")
return
}
- Do promotation / payment / refill operation
Confirm the promotation/payment/refill operation to the P22 device.
SecuX Server API:
- Encrypt operation data /api/B2B/ProduceCipher
SecuX Device APIs:
Please refer to the secux_paymentdevicekit for the APIs below:
-
Get P22 ivKey API
-
Cancel operation
-
Send encrypted operation data to P22 API
func doActivity(userID:String,
devID:String,
coin:String,
token:String,
transID:String,
amount:String,
nonce:String,
type:String) ->(SecuXRequestResult, String)
userID: Merchant account name.
devID: Current device ID, which can be get via getStoreInfo API
coin: Coin info. from the QRCode.
token: Token info. from the QRCode.
transID: Transaction ID assigned by merchant.
amount: Amount info. from the QRCode.
nonce: Nonce info. from the QRCode.
type: Activity type: promotion / payment / refill.
SecuXRequestResult shows the operation result. If the result is SecuXRequestOK,
doActivity is successfully and P22 should show the successful message,
otherwise doActivity is failed and returned string might contain an error message.
Note: if return result is SecuXRequestNoToken / SecuXRequestUnauthorized, the login
session is timeout, please relogin the system.
var (doActivityRet, doActivityError) = paymentManager.doActivity(userID: self.accountName,
devID: devID,
coin: qrcodeParser.coin,
token: qrcodeParser.token,
transID: transID,
amount: qrcodeParser.amount,
nonce: qrcodeParser.nonce,
type: "promotion")
if doActivityRet == SecuXRequestResult.SecuXRequestUnauthorized{
//If login session timeout, relogin the merchant account
guard login(name: self.accountName, password: self.accountPwd) else{
self.showMessageInMainThread(title: "Login failed. doEncryptPaymentData abort!",
message: "")
return
}
(doActivityRet, doActivityError) = paymentManager.doActivity(userID: self.accountName,
devID: devID,
coin: qrcodeParser.coin,
token: qrcodeParser.token,
transID: transID,
amount: qrcodeParser.amount,
nonce: qrcodeParser.nonce,
type: "promotion")
}
if doActivityRet == SecuXRequestResult.SecuXRequestOK{
self.showMessageInMainThread(title: "doEncryptPaymentDataTest result successfully!",
message: "")
}else{
self.showMessageInMainThread(title: "doEncryptPaymentDataTest result failed!",
message: "\(doActivityError)")
}
maochuns, [email protected]
secux-paymentkit is available under the MIT license.