/** * Create parameters necessary for converting a token into a source * * @param tokenId the id of the {@link Token} to be converted into a source. * @return a {@link SourceParams} object that can be used to create a source. */ @NonNull public static SourceParams createSourceFromTokenParams(String tokenId) { SourceParams sourceParams = SourceParams.createCustomParams(); sourceParams.setType(Source.CARD); sourceParams.setToken(tokenId); return sourceParams; }
@Test public void setCustomType_forEmptyParams_setsTypeToUnknown() { final SourceParams params = SourceParams.createCustomParams(); params.setTypeRaw("dogecoin"); assertEquals(Source.UNKNOWN, params.getType()); assertEquals("dogecoin", params.getTypeRaw()); }
@Test public void createToken_createSource_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.createCustomParams(); sourceParams.setType(Source.CARD); sourceParams.setToken(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()); } }