@NonNull private static Map<String, Object> hashMapFromBankAccount( @Nullable UidProvider provider, @NonNull Context context, @NonNull BankAccount bankAccount) { Map<String, Object> tokenParams = new HashMap<>(); Map<String, Object> accountParams = new HashMap<>(); accountParams.put("country", bankAccount.getCountryCode()); accountParams.put("currency", bankAccount.getCurrency()); accountParams.put("account_number", bankAccount.getAccountNumber()); accountParams.put("routing_number", StripeTextUtils.nullIfBlank(bankAccount.getRoutingNumber())); accountParams.put("account_holder_name", StripeTextUtils.nullIfBlank(bankAccount.getAccountHolderName())); accountParams.put("account_holder_type", StripeTextUtils.nullIfBlank(bankAccount.getAccountHolderType())); // Remove all null values; they cause validation errors removeNullAndEmptyParams(accountParams); tokenParams.put(Token.TYPE_BANK_ACCOUNT, accountParams); addUidParams(provider, context, tokenParams); return tokenParams; }
@Test public void createBankAccountTokenSynchronous_withValidBankAccount_returnsToken() { try { Stripe stripe = getNonLoggingStripe(mContext, FUNCTIONAL_PUBLISHABLE_KEY); Token token = stripe.createBankAccountTokenSynchronous(mBankAccount); assertNotNull(token); assertEquals(Token.TYPE_BANK_ACCOUNT, token.getType()); assertNull(token.getCard()); BankAccount returnedBankAccount = token.getBankAccount(); String expectedLast4 = TEST_BANK_ACCOUNT_NUMBER .substring(TEST_BANK_ACCOUNT_NUMBER.length() - 4); assertEquals(expectedLast4, returnedBankAccount.getLast4()); assertEquals(mBankAccount.getCountryCode(), returnedBankAccount.getCountryCode()); assertEquals(mBankAccount.getCurrency(), returnedBankAccount.getCurrency()); assertEquals(mBankAccount.getRoutingNumber(), returnedBankAccount.getRoutingNumber()); } catch (AuthenticationException authEx) { fail("Unexpected error: " + authEx.getLocalizedMessage()); } catch (StripeException stripeEx) { fail("Unexpected error when connecting to Stripe API: " + stripeEx.getLocalizedMessage()); } }
@Test public void parseSampleAccount_returnsExpectedValue() { BankAccount expectedAccount = new BankAccount( "Jane Austen", BankAccount.TYPE_INDIVIDUAL, "STRIPE TEST BANK", "US", "usd", "1JWtPxqbdX5Gamtc", "6789", "110000000"); BankAccount actualAccount = BankAccount.fromString(RAW_BANK_ACCOUNT); assertNotNull(actualAccount); assertEquals(expectedAccount.getAccountHolderName(), actualAccount.getAccountHolderName()); assertEquals(expectedAccount.getAccountHolderType(), actualAccount.getAccountHolderType()); assertEquals(expectedAccount.getBankName(), actualAccount.getBankName()); assertEquals(expectedAccount.getCountryCode(), actualAccount.getCountryCode()); assertEquals(expectedAccount.getCurrency(), actualAccount.getCurrency()); assertEquals(expectedAccount.getFingerprint(), actualAccount.getFingerprint()); assertEquals(expectedAccount.getLast4(), actualAccount.getLast4()); assertEquals(expectedAccount.getRoutingNumber(), actualAccount.getRoutingNumber()); } }