所以我一直在試圖整合Stripe和我的swift代碼,到目前爲止我有以下代碼進行測試。我打印了信用卡號碼,因爲它需要在Stripe的結尾創建一個令牌,並且它正確地反映了Stripe使用的測試信用卡號(例如4242424242424242)(我也爲cvc和exp日期輸入了隨機數),但是, 「validateCardReturningError」總是跳過「createTokenWithCard」函數執行「print(」Error「)」。在試圖進行調試時,我還評論了「validateCardReturningError」以查看是否收回了令牌,但是我將其作爲令牌的值取爲零。Stripe iOS集成 - 我如何知道Stripe是否實際上正在接收我的測試輸入?
此行爲使我相信與Stripe的通信實際上並未發生,因此不會生成令牌。如果是這樣,有沒有辦法測試通信?或者,有沒有辦法檢查從「validateCardReturningError」返回什麼值?
if (userExpiration.isEmpty){ let expArr = userExpiration.componentsSeparatedByString("/")
if (expArr.count > 1) {
let expMonth: NSNumber = Int(expArr[0])!
let expYear: NSNumber = Int(expArr[1])!
creditCard.expMonth = expMonth.unsignedLongValue
creditCard.expYear = expYear.unsignedLongValue } }
print(creditCard.number)
do {
try creditCard.validateCardReturningError()
STPAPIClient.sharedClient().createTokenWithCard(
creditCard,
completion: { (token: STPToken?, stripeError: NSError?) -> Void in
print(token)
})
} catch {
print("Error")
}
我是說我打印stripeError的錯誤是: Optional(Error Domain=com.stripe.lib Code=50 "Missing required param: exp_month." UserInfo={com.stripe.lib:ErrorMessageKey=Missing required param: exp_month., com.stripe.lib:ErrorParameterKey=card[expMonth], NSLocalizedDescription=Missing required param: exp_month.})
你在'stripeError'中得到了什麼? – jcaron
以下是我得到的: 可選(錯誤域= com.stripe.lib代碼= 50「缺少必需的參數:exp_month。」UserInfo = {com.stripe.lib:ErrorMessageKey =缺少必需的參數:exp_month。,com .stripe.lib:ErrorParameterKey =卡[expMonth],NSLocalizedDescription =缺少必要PARAM:exp_month}) – audsssy
月相關的代碼是: 如果(userExpiration.isEmpty){ 讓expArr = userExpiration.componentsSeparatedByString(「/如果(expArr.count> 1) {expMonth:NSNumber = Int(expArr [0])讓expYear:NSNumber = Int(expArr [1])! creditCard.expMonth = expMonth.unsignedLongValue creditCard.expYear = expYear.unsignedLongValue }} 您 – audsssy