@Nullable public static SourceRedirect fromJson(@Nullable JSONObject jsonObject) { if (jsonObject == null) { return null; } String returnUrl = optString(jsonObject, FIELD_RETURN_URL); @Status String status = asStatus(optString(jsonObject, FIELD_STATUS)); String url = optString(jsonObject, FIELD_URL); return new SourceRedirect(returnUrl, status, url); }
@Nullable public static SourceRedirect fromString(@Nullable String jsonString) { try { JSONObject jsonObject = new JSONObject(jsonString); return fromJson(jsonObject); } catch (JSONException ignored) { return null; } }
@Before public void setup() { mSourceRedirect = SourceRedirect.fromString(EXAMPLE_JSON_REDIRECT); assertNotNull(mSourceRedirect); }
assertEquals(70000L, sofortSource.getAmount().longValue()); assertNotNull(sofortSource.getRedirect()); assertEquals("example://return", sofortSource.getRedirect().getReturnUrl()); JsonTestUtils.assertMapEquals(metamap, sofortSource.getMetaData()); } catch (StripeException stripeEx) {
/** * Show a dialog with a link to the external verification site. * * @param source the {@link Source} to verify */ void showDialog(final Source source) { // Caching the source object here because this app makes a lot of them. mRedirectSource = source; mRedirectDialogController.showDialog(source.getRedirect().getUrl()); }
@Test public void fromJsonString_toMap_createsExpectedMap() { assertMapEquals(EXAMPLE_MAP_REDIRECT, mSourceRedirect.toMap()); } }
@Test public void fromJsonString_backToJson_createsIdenticalElement() { try { JSONObject rawConversion = new JSONObject(EXAMPLE_JSON_REDIRECT); assertJsonEquals(rawConversion, mSourceRedirect.toJson()); } catch (JSONException jsonException) { fail("Test Data failure: " + jsonException.getLocalizedMessage()); } }
assertNotNull(idealSource.getRedirect()); assertEquals(bankName, idealSource.getSourceTypeData().get("bank")); assertEquals("example://return", idealSource.getRedirect().getReturnUrl()); JsonTestUtils.assertMapEquals(metamap, idealSource.getMetaData()); } catch (StripeException stripeEx) {
assertEquals(bankName, idealSource.getSourceTypeData().get("bank")); assertNull(idealSource.getOwner().getName()); assertEquals("example://return", idealSource.getRedirect().getReturnUrl()); JsonTestUtils.assertMapEquals(metamap, idealSource.getMetaData()); } catch (StripeException stripeEx) {
case FIELD_REDIRECT: return type.cast( SourceRedirect.fromJson(jsonObject.optJSONObject(FIELD_REDIRECT))); case CARD: return type.cast(
assertNotNull(bancontactSource.getRedirect()); assertEquals("John Doe", bancontactSource.getOwner().getName()); assertEquals("example://path", bancontactSource.getRedirect().getReturnUrl()); JsonTestUtils.assertMapEquals(metamap, bancontactSource.getMetaData()); } catch (StripeException stripeEx) {
@Test public void createSourceSynchronous_withAlipaySingleUseParams_passesIntegrationTest() { Stripe stripe = getNonLoggingStripe(mContext); SourceParams alipayParams = SourceParams.createAlipaySingleUseParams( 1000L, "usd", "Example Payer", "abc@def.com", "stripe://start"); try { Source alipaySource = stripe.createSourceSynchronous(alipayParams, FUNCTIONAL_SOURCE_PUBLISHABLE_KEY); assertNotNull(alipaySource); assertNotNull(alipaySource.getId()); assertNotNull(alipaySource.getClientSecret()); assertNotNull(alipaySource.getAmount()); assertEquals(1000L, alipaySource.getAmount().longValue()); assertEquals(Source.ALIPAY, alipaySource.getType()); assertEquals("redirect", alipaySource.getFlow()); assertNotNull(alipaySource.getOwner()); assertEquals("Example Payer", alipaySource.getOwner().getName()); assertEquals("abc@def.com", alipaySource.getOwner().getEmail()); assertEquals("usd", alipaySource.getCurrency()); assertEquals(Source.SINGLE_USE, alipaySource.getUsage()); assertNotNull(alipaySource.getRedirect()); assertEquals("stripe://start", alipaySource.getRedirect().getReturnUrl()); } catch (StripeException stripeEx) { fail("Unexpected error: " + stripeEx.getLocalizedMessage()); } }
assertEquals("Bond", idealSource.getOwner().getName()); assertNotNull(idealSource.getRedirect()); assertEquals("example://return", idealSource.getRedirect().getReturnUrl()); JsonTestUtils.assertMapEquals(metamap, idealSource.getMetaData()); } catch (StripeException stripeEx) {
assertNotNull(giropaySource.getRedirect()); assertEquals("Mr. X", giropaySource.getOwner().getName()); assertEquals("example://redirect", giropaySource.getRedirect().getReturnUrl()); assertAllLogsAreValid(listener, 2); JsonTestUtils.assertMapEquals(metamap, giropaySource.getMetaData());
@Test public void createSourceSynchronous_withAlipayReusableParams_passesIntegrationTest() { Stripe stripe = getNonLoggingStripe(mContext); SourceParams alipayParams = SourceParams.createAlipayReusableParams( "usd", "Example Payer", "abc@def.com", "stripe://start"); try { Source alipaySource = stripe.createSourceSynchronous(alipayParams, FUNCTIONAL_SOURCE_PUBLISHABLE_KEY); assertNotNull(alipaySource); assertNotNull(alipaySource.getId()); assertNotNull(alipaySource.getClientSecret()); assertEquals(Source.ALIPAY, alipaySource.getType()); assertEquals("redirect", alipaySource.getFlow()); assertNotNull(alipaySource.getOwner()); assertEquals("Example Payer", alipaySource.getOwner().getName()); assertEquals("abc@def.com", alipaySource.getOwner().getEmail()); assertEquals("usd", alipaySource.getCurrency()); assertEquals(Source.REUSABLE, alipaySource.getUsage()); assertNotNull(alipaySource.getRedirect()); assertEquals("stripe://start", alipaySource.getRedirect().getReturnUrl()); } catch (StripeException stripeEx) { fail("Unexpected error: " + stripeEx.getLocalizedMessage()); } }
@Test public void createSourceSynchronous_withP24Params_passesIntegrationTest() { Stripe stripe = getNonLoggingStripe(mContext); SourceParams p24Params = SourceParams.createP24Params( 100, "eur", "Example Payer", "abc@def.com", "stripe://start"); try { Source p24Source = stripe.createSourceSynchronous(p24Params, FUNCTIONAL_SOURCE_PUBLISHABLE_KEY); assertNotNull(p24Source); assertNotNull(p24Source.getId()); assertNotNull(p24Source.getClientSecret()); assertEquals(Source.P24, p24Source.getType()); assertEquals("redirect", p24Source.getFlow()); assertNotNull(p24Source.getOwner()); assertEquals("Example Payer", p24Source.getOwner().getName()); assertEquals("abc@def.com", p24Source.getOwner().getEmail()); assertEquals("eur", p24Source.getCurrency()); assertEquals(Source.SINGLE_USE, p24Source.getUsage()); assertNotNull(p24Source.getRedirect()); assertEquals("stripe://start", p24Source.getRedirect().getReturnUrl()); } catch (StripeException stripeEx) { fail("Unexpected error: " + stripeEx.getLocalizedMessage()); } }