@Test public void parseToken_whenBankAccount_readsObject() { Date createdDate = new Date(1484765567L * 1000L); Token expectedToken = new Token( "btok_9xJAbronBnS9bH", false, createdDate, false, (BankAccount) null); Token answerToken = Token.fromString(RAW_BANK_TOKEN); assertNotNull(answerToken); assertEquals(expectedToken.getId(), answerToken.getId()); assertEquals(expectedToken.getLivemode(), answerToken.getLivemode()); assertEquals(expectedToken.getCreated(), answerToken.getCreated()); assertEquals(expectedToken.getUsed(), answerToken.getUsed()); assertEquals(Token.TYPE_BANK_ACCOUNT, answerToken.getType()); assertNotNull(answerToken.getBankAccount()); assertNull(answerToken.getCard()); }
final Boolean liveMode = StripeJsonUtils.optBoolean(jsonObject, FIELD_LIVEMODE); @TokenType final String tokenType = asTokenType(StripeJsonUtils.optString(jsonObject, FIELD_TYPE)); final Boolean used = StripeJsonUtils.optBoolean(jsonObject, FIELD_USED); return null; token = new Token(tokenId, liveMode, date, used, BankAccount.fromJson(bankAccountObject)); } else if (Token.TYPE_CARD.equals(tokenType)) { return null; token = new Token(tokenId, liveMode, date, used, Card.fromJson(cardObject)); } else if (Token.TYPE_PII.equals(tokenType) || Token.TYPE_ACCOUNT.equals(tokenType) || Token.TYPE_CVC_UPDATE.equals(tokenType)) { token = new Token(tokenId, tokenType, liveMode, date, used); } else { token = null;
@Nullable public static Token fromString(@Nullable String jsonString) { if (jsonString == null) { return null; } try { JSONObject tokenObject = new JSONObject(jsonString); return fromJson(tokenObject); } catch (JSONException exception) { return null; } }
@Test public void createTokenSynchronous_withValidCvc_passesIntegrationTest() throws CardException, APIException, AuthenticationException, InvalidRequestException, APIConnectionException { final Stripe stripe = new Stripe(mContext, FUNCTIONAL_PUBLISHABLE_KEY); final TestLoggingListener listener = new TestLoggingListener(true); stripe.setLoggingResponseListener(listener); final Token token = stripe.createCvcUpdateTokenSynchronous("1234"); assertNotNull(token); assertEquals(Token.TYPE_CVC_UPDATE, token.getType()); assertFalse(token.getLivemode()); assertFalse(token.getUsed()); assertNotNull(token.getId()); assertTrue(token.getId().startsWith("cvctok_")); assertAllLogsAreValid(listener, 2); }
@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()); } }
@Nullable private static Token requestToken( String url, Map<String, Object> params, @NonNull RequestOptions options) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException { final StripeResponse response = requestData(StripeApiHandler.POST, url, params, options); return Token.fromString(response.getResponseBody()); }
public void logEventSynchronous( @NonNull List<String> productUsageTokens, @NonNull StripePaymentSource paymentSource) { RequestOptions.RequestOptionsBuilder builder = RequestOptions.builder(mDefaultPublishableKey); if (mStripeAccount != null) { builder.setStripeAccount(mStripeAccount); } RequestOptions options = builder.build(); final Map<String, Object> loggingMap; if (paymentSource instanceof Token) { Token token = (Token) paymentSource; loggingMap = LoggingUtils.getTokenCreationParams( mContext, productUsageTokens, mDefaultPublishableKey, token.getType()); } else { Source source = (Source) paymentSource; loggingMap = LoggingUtils.getSourceCreationParams( mContext, productUsageTokens, mDefaultPublishableKey, source.getType()); } StripeApiHandler.logApiCall(loggingMap, options, mLoggingResponseListener); }
@Test public void createTokenSynchronous_withValidPersonalId_passesIntegrationTest() { try { Stripe stripe = new Stripe(mContext, FUNCTIONAL_PUBLISHABLE_KEY); TestLoggingListener listener = new TestLoggingListener(true); stripe.setLoggingResponseListener(listener); Token token = stripe.createPiiTokenSynchronous("0123456789"); assertNotNull(token); assertEquals(Token.TYPE_PII, token.getType()); assertFalse(token.getLivemode()); assertFalse(token.getUsed()); assertNotNull(token.getId()); assertAllLogsAreValid(listener, 2); } catch (StripeException stripeEx) { fail("Unexpected exception making PII token"); } }
@Test public void createCardTokenSynchronous_withValidData_returnsToken() { try { Stripe stripe = new Stripe(mContext, FUNCTIONAL_SOURCE_PUBLISHABLE_KEY); TestLoggingListener listener = new TestLoggingListener(true); stripe.setLoggingResponseListener(listener); Token token = stripe.createTokenSynchronous(mCard); assertNotNull(token); Card returnedCard = token.getCard(); assertNotNull(returnedCard); assertNull(token.getBankAccount()); assertEquals(Token.TYPE_CARD, token.getType()); assertEquals(mCard.getLast4(), returnedCard.getLast4()); assertEquals(Card.VISA, returnedCard.getBrand()); assertEquals(mCard.getExpYear(), returnedCard.getExpYear()); assertEquals(mCard.getExpMonth(), returnedCard.getExpMonth()); assertEquals(Card.FUNDING_CREDIT, returnedCard.getFunding()); assertAllLogsAreValid(listener, 2); } catch (AuthenticationException authEx) { fail("Unexpected error: " + authEx.getLocalizedMessage()); } catch (StripeException stripeEx) { fail("Unexpected error when connecting to Stripe API: " + stripeEx.getLocalizedMessage()); } }
@Override public void notify( Object callback ) { APaymentFragment paymentFragment = (APaymentFragment)callback; paymentFragment.submitOrderForPrinting( token.getId(), KiteSDK.getInstance( mContext ).getStripeAccountId(), PaymentMethod.CREDIT_CARD ); // Once the order has been submitted, we can be dismissed. remove(); } } );
Token stripeToken = Token.fromString(rawToken); if (stripeToken != null) {
@Test public void parseToken_readsObject() { Date createdDate = new Date(1462905355L * 1000L); Token partialExpectedToken = new Token( "tok_189fi32eZvKYlo2Ct0KZvU5Y", false, createdDate, false, (Card) null); Token answerToken = Token.fromString(RAW_TOKEN); assertNotNull(answerToken); assertEquals(partialExpectedToken.getId(), answerToken.getId()); assertEquals(partialExpectedToken.getLivemode(), answerToken.getLivemode()); assertEquals(partialExpectedToken.getCreated(), answerToken.getCreated()); assertEquals(partialExpectedToken.getUsed(), answerToken.getUsed()); assertEquals(Token.TYPE_CARD, answerToken.getType()); // Note: we test the validity of the card object in CardTest assertNotNull(answerToken.getCard()); assertNull(answerToken.getBankAccount()); }
@Test public void createTokenSynchronous_withValidAccount_passesIntegrationTest() { try { final Address exampleAddress = new Address .Builder() .setCity("SF") .setCountry("US") .setState("CA").build(); final Map<String, Object> exampleLegalEntity = new HashMap<String, Object>() {{ put("personal_address", exampleAddress.toMap()); put("type", "individual"); put("ssn_last_4", "1234"); put("first_name", "Kathy"); put("last_name", "Sun"); }}; Stripe stripe = new Stripe(mContext, FUNCTIONAL_PUBLISHABLE_KEY); TestLoggingListener listener = new TestLoggingListener(true); stripe.setLoggingResponseListener(listener); Token token = stripe.createAccountTokenSynchronous( AccountParams.createAccountParams(true, exampleLegalEntity)); assertNotNull(token); assertEquals(Token.TYPE_ACCOUNT, token.getType()); assertFalse(token.getLivemode()); assertFalse(token.getUsed()); assertNotNull(token.getId()); assertAllLogsAreValid(listener, 2); } catch (StripeException stripeEx) { fail(stripeEx.getMessage()); } }
@Test public void createCardTokenSynchronous_withValidDataAndConnectAccount_returnsToken() { try { Stripe stripe = new Stripe(mContext, "pk_test_fdjfCYpGSwAX24KUEiuaAAWX"); stripe.setStripeAccount("acct_1Acj2PBUgO3KuWzz"); TestLoggingListener listener = new TestLoggingListener(true); stripe.setLoggingResponseListener(listener); Token token = stripe.createTokenSynchronous(mCard); assertNotNull(token); Card returnedCard = token.getCard(); assertNotNull(returnedCard); assertNull(token.getBankAccount()); assertEquals(Token.TYPE_CARD, token.getType()); assertEquals(mCard.getLast4(), returnedCard.getLast4()); assertEquals(Card.VISA, returnedCard.getBrand()); assertEquals(mCard.getExpYear(), returnedCard.getExpYear()); assertEquals(mCard.getExpMonth(), returnedCard.getExpMonth()); assertEquals(Card.FUNDING_CREDIT, returnedCard.getFunding()); assertAllLogsAreValid(listener, 2); } catch (AuthenticationException authEx) { fail("Unexpected error: " + authEx.getLocalizedMessage()); } catch (StripeException stripeEx) { fail("Unexpected error when connecting to Stripe API: " + stripeEx.getLocalizedMessage()); } }
@Test public void createToken_createSourceWithTokenToSourceParams_returnsSource() { try { Stripe stripe = new Stripe(mContext, FUNCTIONAL_PUBLISHABLE_KEY); TestLoggingListener listener = new TestLoggingListener(true); stripe.setLoggingResponseListener(listener); Token token = stripe.createTokenSynchronous(mCard); assertNotNull(token); SourceParams sourceParams = SourceParams.createSourceFromTokenParams(token.getId()); Source source = stripe.createSourceSynchronous(sourceParams, FUNCTIONAL_PUBLISHABLE_KEY); assertNotNull(source); assertAllLogsAreValid(listener, 4); } catch (AuthenticationException authEx) { fail("Unexpected error: " + authEx.getLocalizedMessage()); } catch (StripeException stripeEx) { fail("Unexpected error when connecting to Stripe API: " + stripeEx.getLocalizedMessage()); } }
@Test public void parseToken_withoutType_returnsNull() { Token token = Token.fromString(RAW_BANK_TOKEN_NO_TYPE); assertNull(token); } }
AccountParams.createAccountParams(false, exampleLegalEntity)); assertNotNull(token); assertEquals(Token.TYPE_ACCOUNT, token.getType()); assertFalse(token.getLivemode()); assertFalse(token.getUsed()); assertNotNull(token.getId()); assertAllLogsAreValid(listener, 2); } catch (StripeException stripeEx) {