hmunoz-stripe

Stripe iOS Create BankAccount Token error handling

Jul 23rd, 2021 (edited)
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.99 KB | None | 0 0
  1. var bankAccountParams = STPBankAccountParams()
  2.     bankAccountParams.accountHolderName = "Jenny Rosen"
  3.     bankAccountParams.country = "US"
  4.     bankAccountParams.routingNumber = "110000000"
  5.     bankAccountParams.accountNumber = "00044"
  6.    
  7.     print("Bank account parameters: ")
  8.     print(bankAccountParams)
  9.    
  10.     STPAPIClient.shared.createToken(withBankAccount: bankAccountParams) { token, error in
  11.       if let error = error {
  12.         print(error)
  13.         if let detailedError = error as? NSError {
  14.           print("error_code: " + (detailedError.userInfo["com.stripe.lib:StripeErrorCodeKey"] as! String))
  15.           print("error_type: " + (detailedError.userInfo["com.stripe.lib:StripeErrorTypeKey"] as! String))
  16.           print("error parameter: " + (detailedError.userInfo["com.stripe.lib:ErrorParameterKey"] as! String))
  17.           print("error_message: " + (detailedError.userInfo["com.stripe.lib:ErrorMessageKey"] as! String))
  18.         }
  19.       }
  20.      
  21.       else {
  22.         print(token)
  23.       }
  24.     }
  25.  
  26. /*
  27. Output:
  28.  
  29. Bank account parameters:
  30. <Stripe.STPBankAccountParams: 0x600001912920; routingNumber = 110000000; last4 = 0044; country = US; currency = ;
  31.  
  32. Error Domain=com.stripe.lib Code=50 "There was an unexpected error -- try again in a few seconds" UserInfo={com.stripe.lib:StripeErrorTypeKey=invalid_request_error, com.stripe.lib:StripeErrorCodeKey=account_number_invalid, com.stripe.lib:ErrorMessageKey=You must use a test bank account number in test mode. Try 000123456789 or see more options at https://stripe.com/docs/connect/testing#account-numbers., com.stripe.lib:ErrorParameterKey=bankAccount[AccountNumber], NSLocalizedDescription=There was an unexpected error -- try again in a few seconds}
  33.  
  34. error_code: account_number_invalid
  35. error_type: invalid_request_error
  36. error parameter: bankAccount[AccountNumber]
  37. error_message: You must use a test bank account number in test mode. Try 000123456789 or see more options at https://stripe.com/docs/connect/testing#account-numbers.
  38. */
Add Comment
Please, Sign In to add comment