@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_SELECT_SOURCE && resultCode == RESULT_OK) { String selectedSource = data.getStringExtra(PaymentMethodsActivity.EXTRA_SELECTED_PAYMENT); Source source = Source.fromString(selectedSource); // Note: it isn't possible for a null or non-card source to be returned. if (source != null && Source.CARD.equals(source.getType())) { SourceCardData cardData = (SourceCardData) source.getSourceTypeModel(); mSelectedSourceTextView.setText(buildCardString(cardData)); } } }
private void addToList(@Nullable Source source) { if (source == null || !Source.CARD.equals(source.getType())) { return; } SourceCardData sourceCardData = (SourceCardData) source.getSourceTypeModel(); String endingIn = getString(R.string.endingIn); Map<String, String> map = new HashMap<>(); map.put("last4", endingIn + " " + sourceCardData.getLast4()); map.put("tokenId", source.getId()); mCardSources.add(map); mSimpleAdapter.notifyDataSetChanged(); }
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); if (intent.getData() != null && intent.getData().getQuery() != null) { // The client secret and source ID found here is identical to // that of the source used to get the redirect URL. String clientSecret = intent.getData().getQueryParameter(QUERY_CLIENT_SECRET); String sourceId = intent.getData().getQueryParameter(QUERY_SOURCE_ID); if (clientSecret != null && sourceId != null && clientSecret.equals(mRedirectSource.getClientSecret()) && sourceId.equals(mRedirectSource.getId())) { updateSourceList(mRedirectSource); mRedirectSource = null; } mRedirectDialogController.dismissDialog(); } }
stripe.createSourceSynchronous(params, FUNCTIONAL_SOURCE_PUBLISHABLE_KEY); assertNotNull(idealSource); assertNotNull(idealSource.getClientSecret()); assertNotNull(idealSource.getId()); assertEquals(5500L, idealSource.getAmount().longValue()); assertEquals(Source.IDEAL, idealSource.getType()); assertEquals("eur", idealSource.getCurrency()); assertNotNull(idealSource.getSourceTypeData()); assertNotNull(idealSource.getOwner()); assertNull(idealSource.getSourceTypeModel()); assertNotNull(idealSource.getRedirect()); assertEquals(bankName, idealSource.getSourceTypeData().get("bank")); assertNull(idealSource.getOwner().getName()); assertEquals("example://return", idealSource.getRedirect().getReturnUrl()); JsonTestUtils.assertMapEquals(metamap, idealSource.getMetaData()); } catch (StripeException stripeEx) { fail("Unexpected error: " + stripeEx.getLocalizedMessage());
@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()); } }
@Test public void fromJsonString_withCustomType_createsSourceWithCustomType() { Source customSource = Source.fromString(EXAMPLE_JSON_SOURCE_CUSTOM_TYPE); assertNotNull("Parsing failure", customSource); assertEquals(Source.UNKNOWN, customSource.getType()); assertEquals(DOGE_COIN, customSource.getTypeRaw()); assertNull(customSource.getSourceTypeModel()); assertNotNull("Failed to find custom api params", customSource.getSourceTypeData()); } }
private String formatSourceDescription(Source source) { if (Source.CARD.equals(source.getType())) { SourceCardData sourceCardData = (SourceCardData) source.getSourceTypeModel(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(sourceCardData.getBrand()).append(getString(R.string.ending_in)).append(sourceCardData.getLast4()); return stringBuilder.toString(); } return source.getType(); }
assertEquals(Source.CARD, params.getType()); callback.onSuccess(Source.fromString(CardInputTestActivity.EXAMPLE_JSON_CARD_SOURCE)); assertEquals(RESULT_OK, mShadowActivity.getResultCode()); Intent intent = mShadowActivity.getResultIntent(); assertTrue(intent.hasExtra(AddSourceActivity.EXTRA_NEW_SOURCE)); Source source = Source.fromString(intent.getStringExtra(AddSourceActivity.EXTRA_NEW_SOURCE)); assertNotNull(source); assertEquals(Source.CARD, source.getType());
assertEquals(Source.CARD, params.getType()); Source expectedSource = Source.fromString(CardInputTestActivity.EXAMPLE_JSON_CARD_SOURCE); assertNotNull(expectedSource); callback.onSuccess(expectedSource); listenerArgumentCaptor.capture()); assertEquals(expectedSource.getId(), sourceIdCaptor.getValue()); CustomerSession.SourceRetrievalListener listener = listenerArgumentCaptor.getValue(); assertNotNull(listener); assertTrue(intent.hasExtra(AddSourceActivity.EXTRA_NEW_SOURCE)); Source source = Source.fromString(intent.getStringExtra(AddSourceActivity.EXTRA_NEW_SOURCE)); assertNotNull(source); assertEquals(Source.CARD, source.getType());
@Test public void createSourceSynchronous_withSepaDebitParamsWithMinimalValues_passesIntegrationTest() { Stripe stripe = getNonLoggingStripe(mContext); String validIban = "DE89370400440532013000"; SourceParams params = SourceParams.createSepaDebitParams( "Sepa Account Holder", validIban, null, null, null, null, null); Map<String, String> metamap = new HashMap<String, String>() {{ put("water source", "well"); put("type", "brackish"); put("value", "100000"); }}; params.setMetaData(metamap); try { Source sepaDebitSource = stripe.createSourceSynchronous(params, FUNCTIONAL_SOURCE_PUBLISHABLE_KEY); assertNotNull(sepaDebitSource); assertNotNull(sepaDebitSource.getClientSecret()); assertNotNull(sepaDebitSource.getId()); assertEquals(Source.SEPA_DEBIT, sepaDebitSource.getType()); JsonTestUtils.assertMapEquals(metamap ,sepaDebitSource.getMetaData()); } catch (StripeException stripeEx) { fail("Unexpected error: " + stripeEx.getLocalizedMessage()); } }
return Source.fromString(response.getResponseBody());
@NonNull @Source.SourceType public String getSourceType() { if (mStripePaymentSource instanceof Card) { return Source.CARD; } else if (mStripePaymentSource instanceof Source) { return ((Source) mStripePaymentSource).getType(); } else { return Source.UNKNOWN; } }
@Test public void setSourceCardData_withCardSource_setsCorrectData() { Source source = Source.fromString(EXAMPLE_JSON_CARD_SOURCE); assertNotNull(source); assertTrue(source.getSourceTypeModel() instanceof SourceCardData); SourceCardData sourceCardData = (SourceCardData) source.getSourceTypeModel(); assertNotNull(sourceCardData); mMaskedCardView.setSourceCardData(sourceCardData); assertEquals(Card.VISA, mMaskedCardView.getCardBrand()); assertEquals("4242", mMaskedCardView.getLast4()); assertFalse(mMaskedCardView.isSelected()); }
@Test public void onActivityResult_withValidSource_refreshesCustomer() { Customer customer = Customer.fromString(CustomerSessionTest.FIRST_TEST_CUSTOMER_OBJECT); when(mCustomerSessionProxy.getCachedCustomer()).thenReturn(customer); mPaymentMethodsActivity.initializeCustomerSourceData(); Source source = Source.fromString(CardInputTestActivity.EXAMPLE_JSON_CARD_SOURCE); assertNotNull(source); Intent resultIntent = new Intent(); resultIntent.putExtra(AddSourceActivity.EXTRA_NEW_SOURCE, source.toString()); ArgumentCaptor<CustomerSession.CustomerRetrievalListener> listenerArgumentCaptor = ArgumentCaptor.forClass(CustomerSession.CustomerRetrievalListener.class); mPaymentMethodsActivity.onActivityResult(REQUEST_CODE_ADD_CARD, RESULT_OK, resultIntent); assertEquals(View.VISIBLE, mProgressBar.getVisibility()); verify(mCustomerSessionProxy).updateCurrentCustomer(listenerArgumentCaptor.capture()); CustomerSession.CustomerRetrievalListener listener = listenerArgumentCaptor.getValue(); assertNotNull(listener); // Note - this doesn't make sense as the actual update; just testing that the customer // changes Customer updatedCustomer = Customer.fromString(TEST_CUSTOMER_OBJECT_WITH_SOURCES); assertNotNull(updatedCustomer); listener.onCustomerRetrieved(updatedCustomer); assertEquals(View.GONE, mProgressBar.getVisibility()); assertEquals(2, mRecyclerView.getAdapter().getItemCount()); }
assertNotNull(cardSource.getId()); SourceParams threeDParams = SourceParams.createThreeDSecureParams( 5000L, "brl", "example://return", cardSource.getId()); stripe.createSourceSynchronous(threeDParams, FUNCTIONAL_SOURCE_PUBLISHABLE_KEY); String sourceId = threeDSource.getId(); String clientSecret = threeDSource.getClientSecret(); JsonTestUtils.assertMapEquals(threeDSource.toMap(), retrievedSource.toMap()); } catch (StripeException stripeEx) { fail("Unexpected error: " + stripeEx.getLocalizedMessage());
assertEquals(Source.CARD, params.getType()); Source expectedSource = Source.fromString(CardInputTestActivity.EXAMPLE_JSON_CARD_SOURCE); assertNotNull(expectedSource); callback.onSuccess(expectedSource); listenerArgumentCaptor.capture()); assertEquals(expectedSource.getId(), sourceIdCaptor.getValue()); CustomerSession.SourceRetrievalListener listener = listenerArgumentCaptor.getValue(); assertNotNull(listener);
@Test public void fromJsonStringWithNulls_toMap_createsExpectedMap() { Source sourceWithNulls = Source.fromString(EXAMPLE_JSON_SOURCE_WITH_NULLS); assertNotNull("Test Data failure during parsing", sourceWithNulls); assertMapEquals(EXAMPLE_SOURCE_MAP, sourceWithNulls.toMap()); }
assertNotNull(manipulatedApplePayCard); Source sourceCardWithApplePay = Source.fromString(EXAMPLE_JSON_SOURCE_WITHOUT_NULLS); Source alipaySource = Source.fromString(EXAMPLE_ALIPAY_SOURCE); assertNotNull(sourceCardWithApplePay); assertNotNull(alipaySource); sourcesArray.put(sourceCardWithApplePay.toJson()); sourcesArray.put(alipaySource.toJson());
stringBuilder.append("Payment Info:\n"); if (cardSource != null) { SourceCardData scd = (SourceCardData) cardSource.getSourceTypeModel(); stringBuilder.append(scd.getBrand()) .append(" ending in ")