final SourceParams cardSourceParams = SourceParams.createCardParams(card); final Observable<Source> cardSourceObservable = Observable.fromCallable(
/** * 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; }
@NonNull public static SourceParams createSepaDebitParams( @NonNull String name, @NonNull String iban, @Nullable String addressLine1, @NonNull String city, @NonNull String postalCode, @NonNull @Size(2) String country) { return createSepaDebitParams(name, iban, null, addressLine1, city, postalCode, country); }
/** * Create parameters needed to make a Visa Checkout source. * * @param callId The payment request ID (callId) from the Visa Checkout SDK. * @return a {@link SourceParams} object that can be used to create a Visa Checkout Card Source. * * @see <a href="https://stripe.com/docs/visa-checkout">https://stripe.com/docs/visa-checkout</a> * @see <a href="https://developer.visa.com/capabilities/visa_checkout/docs">https://developer.visa.com/capabilities/visa_checkout/docs</a> */ @NonNull public static SourceParams createVisaCheckoutParams(@NonNull String callId) { return new SourceParams() .setType(Source.CARD) .setApiParameterMap( createSimpleMap(VISA_CHECKOUT, createSimpleMap(CALL_ID, callId))); }
/** * Create parameters necessary to create a Multibanco source. * * @param amount A positive integer in the smallest currency unit representing the amount to * charge the customer (e.g., 1099 for a €10.99 payment). * @param returnUrl The URL the customer should be redirected to after the authorization * process. * @param email The full email address of the customer. * @return a {@link SourceParams} object that can be used to create a Multibanco source * * @see <a href="https://stripe.com/docs/sources/multibanco">https://stripe.com/docs/sources/multibanco</a> */ @NonNull public static SourceParams createMultibancoParams( @IntRange(from = 0) long amount, @NonNull String returnUrl, @NonNull String email) { return new SourceParams() .setType(Source.MULTIBANCO) .setCurrency(Source.EURO) .setAmount(amount) .setRedirect(createSimpleMap(FIELD_RETURN_URL, returnUrl)) .setOwner(createSimpleMap(FIELD_EMAIL, email)); }
@Test public void createGiropayParams_hasExpectedFields() { final SourceParams params = SourceParams.createGiropayParams( 150L, "Stripe", "stripe://return", "stripe descriptor"); assertEquals(Source.GIROPAY, params.getType()); assertEquals(Source.EURO, params.getCurrency()); assertNotNull(params.getAmount()); assertEquals(150L, params.getAmount().longValue()); assertNotNull(params.getOwner()); assertEquals("Stripe", params.getOwner().get("name")); assertNotNull(params.getRedirect()); assertEquals("stripe://return", params.getRedirect().get("return_url")); Map<String, Object> apiMap = params.getApiParameterMap(); assertEquals("stripe descriptor", apiMap.get("statement_descriptor")); }
@Test public void createAlipayReusableParams_withAllFields_hasExpectedFields() { final SourceParams params = SourceParams.createAlipayReusableParams( "usd", "Jean Valjean", "jdog@lesmis.net", "stripe://start"); assertEquals(Source.ALIPAY, params.getType()); assertEquals(Source.REUSABLE, params.getUsage()); assertNull(params.getAmount()); assertEquals("usd", params.getCurrency()); assertNotNull(params.getRedirect()); assertEquals("stripe://start", params.getRedirect().get("return_url")); assertNotNull(params.getOwner()); assertEquals("Jean Valjean", params.getOwner().get("name")); assertEquals("jdog@lesmis.net", params.getOwner().get("email")); }
@Nullable String email, @NonNull String returnUrl) { final SourceParams params = new SourceParams() .setType(Source.ALIPAY) .setCurrency(currency) .setRedirect(createSimpleMap(FIELD_RETURN_URL, returnUrl)) .setUsage(Source.REUSABLE); removeNullAndEmptyParams(ownerMap); if (ownerMap.keySet().size() > 0) { params.setOwner(ownerMap);
@Test public void createAlipaySingleUseParams_withoutOwner_hasNoOwnerFields() { final SourceParams params = SourceParams.createAlipaySingleUseParams( 555L, "eur", null, null, "stripe://testactivity2"); assertEquals(Source.ALIPAY, params.getType()); assertNotNull(params.getAmount()); assertEquals(555L, params.getAmount().longValue()); assertEquals("eur", params.getCurrency()); assertNull(params.getOwner()); assertNotNull(params.getRedirect()); assertEquals("stripe://testactivity2", params.getRedirect().get("return_url")); }
@Test public void createP24Params_withAllFields_hasExpectedFields() { final SourceParams params = SourceParams.createP24Params( 1000L, "eur", "Jane Tester", "jane@test.com", "stripe://testactivity"); assertEquals(Source.P24, params.getType()); assertNotNull(params.getAmount()); assertEquals(1000L, params.getAmount().longValue()); assertEquals("eur", params.getCurrency()); assertNotNull(params.getOwner()); assertEquals("Jane Tester", params.getOwner().get("name")); assertEquals("jane@test.com", params.getOwner().get("email")); assertNotNull(params.getRedirect()); assertEquals("stripe://testactivity", params.getRedirect().get("return_url")); }
Stripe stripe = getNonLoggingStripe(mContext); Card card = new Card(CardInputTestActivity.VALID_VISA_NO_SPACES, 12, 2050, "123"); SourceParams params = SourceParams.createCardParams(card); try { Source cardSource = SourceParams threeDParams = SourceParams.createThreeDSecureParams( 5000L, "brl", put("type", "beach ball"); }}; threeDParams.setMetaData(metamap); Source threeDSource = stripe.createSourceSynchronous(threeDParams, FUNCTIONAL_SOURCE_PUBLISHABLE_KEY);
@Test public void createIdealParams_hasExpectedFields() { final SourceParams params = SourceParams.createIdealParams( 900L, "Default Name", "stripe://anotherurl", "something you bought", "SVB"); assertEquals(Source.IDEAL, params.getType()); assertEquals(Source.EURO, params.getCurrency()); assertNotNull(params.getAmount()); assertEquals(900L, params.getAmount().longValue()); assertNotNull(params.getOwner()); assertEquals("Default Name", params.getOwner().get("name")); assertNotNull(params.getRedirect()); assertEquals("stripe://anotherurl", params.getRedirect().get("return_url")); Map<String, Object> apiMap = params.getApiParameterMap(); assertEquals("something you bought", apiMap.get("statement_descriptor")); assertEquals("SVB", apiMap.get("bank")); }
@Test public void createThreeDSecureParams_hasExpectedFields() { final SourceParams params = SourceParams.createThreeDSecureParams( 99000L, "brl", "stripe://returnaddress", "card_id_123"); assertEquals(Source.THREE_D_SECURE, params.getType()); // Brazilian Real assertEquals("brl", params.getCurrency()); assertNotNull(params.getAmount()); assertEquals(99000L, params.getAmount().longValue()); assertNotNull(params.getRedirect()); assertEquals("stripe://returnaddress", params.getRedirect().get("return_url")); Map<String, Object> apiMap = params.getApiParameterMap(); assertNotNull(apiMap); assertEquals(1, apiMap.size()); assertEquals("card_id_123", apiMap.get("card")); }
@Test public void createBancontactParams_hasExpectedFields() { final SourceParams params = SourceParams.createBancontactParams( 1000L, "Stripe", "return/url/3000", "descriptor", "en"); assertEquals(Source.BANCONTACT, params.getType()); assertEquals(Source.EURO, params.getCurrency()); assertNotNull(params.getAmount()); assertEquals(1000L, params.getAmount().longValue()); assertNotNull(params.getOwner()); assertEquals("Stripe", params.getOwner().get("name")); assertNotNull(params.getRedirect()); assertEquals("return/url/3000", params.getRedirect().get("return_url")); Map<String, Object> apiMap = params.getApiParameterMap(); assertNotNull(apiMap); assertEquals("descriptor", apiMap.get("statement_descriptor")); assertEquals("en", apiMap.get("preferred_language")); }
@Nullable String postalCode, @Nullable @Size(2) String country) { final SourceParams params = new SourceParams() .setType(Source.SEPA_DEBIT) .setCurrency(Source.EURO); .setOwner(ownerMap) .setApiParameterMap(createSimpleMap(FIELD_IBAN, iban));
@Test public void createMultibancoParams_hasExpectedFields() { final SourceParams params = SourceParams.createMultibancoParams( 150L, "stripe://testactivity", "multibancoholder@stripe.com"); assertEquals(Source.MULTIBANCO, params.getType()); assertEquals(Source.EURO, params.getCurrency()); assertEquals(150L, params.getAmount().longValue()); assertEquals("stripe://testactivity", params.getRedirect().get("return_url")); assertEquals("multibancoholder@stripe.com", params.getOwner().get("email")); }
@Test public void createEPSParams_hasExpectedFields() { final SourceParams params = SourceParams.createEPSParams( 150L, "Stripe", "stripe://return", "stripe descriptor"); assertEquals(Source.EPS, params.getType()); assertEquals(Source.EURO, params.getCurrency()); assertEquals("Stripe", params.getOwner().get("name")); assertEquals("stripe://return", params.getRedirect().get("return_url")); Map<String, Object> apiMap = params.getApiParameterMap(); assertEquals("stripe descriptor", apiMap.get("statement_descriptor")); }
final SourceParams params = new SourceParams().setType(Source.CARD); removeNullAndEmptyParams(basicInfoMap); params.setApiParameterMap(basicInfoMap); params.setOwner(ownerMap); params.setMetaData(metadata);
@Test public void createSofortParams_hasExpectedFields() { final SourceParams params = SourceParams.createSofortParams( 50000L, "example://return", "UK", "a thing you bought"); assertEquals(Source.SOFORT, params.getType()); assertEquals(Source.EURO, params.getCurrency()); assertNotNull(params.getAmount()); assertEquals(50000L, params.getAmount().longValue()); assertNotNull(params.getRedirect()); assertEquals("example://return", params.getRedirect().get("return_url")); Map<String, Object> apiMap = params.getApiParameterMap(); assertEquals("UK", apiMap.get("country")); assertEquals("a thing you bought", apiMap.get("statement_descriptor")); }
@Test public void createSepaDebitParams_hasExpectedFields() { final SourceParams params = SourceParams.createSepaDebitParams( "Jai Testa", "ibaniban", "sepaholder@stripe.com", "44 Fourth Street", "Test City", "90210", "EI"); assertEquals(Source.SEPA_DEBIT, params.getType()); assertEquals(Source.EURO, params.getCurrency()); assertNotNull(params.getOwner()); assertEquals("Jai Testa", params.getOwner().get("name")); Map<String, Object> addressMap = getMapFromOwner(params, "address"); assertEquals("44 Fourth Street", addressMap.get("line1")); assertEquals("Test City", addressMap.get("city")); assertEquals("90210", addressMap.get("postal_code")); assertEquals("EI", addressMap.get("country")); Map<String, Object> apiMap = params.getApiParameterMap(); assertEquals("ibaniban", apiMap.get("iban")); }