2015-12-09 50 views
0

所以我一直在試圖整合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.})

+0

你在'stripeError'中得到了什麼? – jcaron

+0

以下是我得到的: 可選(錯誤域= com.stripe.lib代碼= 50「缺少必需的參數:exp_month。」UserInfo = {com.stripe.lib:ErrorMessageKey =缺少必需的參數:exp_month。,com .stripe.lib:ErrorParameterKey =卡[expMonth],NSLocalizedDescription =缺少必要PARAM:exp_month}) – audsssy

+0

月相關的代碼是: 如果(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

回答

0

條紋居然可以讓你瀏覽所有日誌在儀表板帳戶。因此,如果您前往https://dashboard.stripe.com/logs?method=not_get,您將能夠看到您是否成功發佈到/v1/tokens端點。

+0

有趣,不知道這個。但我在日誌中什麼都看不到。它看起來好像溝通因爲缺少「exp_month」而中斷,但我認爲我的代碼覆蓋了它? – audsssy

+0

啊,我明白你現在說的話。我將我的Stripe儀表板設置爲「Live」,這就是爲什麼我在日誌中沒有看到任何東西。現在我已將其設置爲「測試」,並看到錯誤。謝謝。 – audsssy

1

變化:

if (userExpiration.isEmpty) 

if (!userExpiration.isEmpty) 

讓你實際使用的截止日期時,那裏有什麼東西。

還添加一個else子句來抱怨,如果它是空的,並阻止提交(我想這個代碼是在用戶提交表單時運行的)。

+0

哦,謝謝你的收穫。我現在得到了令牌ID。最後! – audsssy

相關問題