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(); }
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(); }
/** * Set the card data displayed using a {@link CustomerSource} object. If the object * is not a {@link Source} object that represents a card and the object returns {@code null} * from its {@link CustomerSource#asCard()} method, then no values will be set on this control. * * @param customerSource the {@link CustomerSource} to be partially displayed */ void setCustomerSource(@NonNull CustomerSource customerSource) { Source source = customerSource.asSource(); if (source != null && source.getSourceTypeModel() != null && Source.CARD.equals(source.getType()) && source.getSourceTypeModel() instanceof SourceCardData) { SourceCardData sourceCardData = (SourceCardData) source.getSourceTypeModel(); setSourceCardData(sourceCardData); return; } Card card = customerSource.asCard(); if (card != null) { setCard(card); } }
@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)); } } }
@Nullable public String getTokenizationMethod() { Source paymentAsSource = asSource(); Card paymentAsCard = asCard(); if (paymentAsSource != null && paymentAsSource.getType().equals(Source.CARD)) { SourceCardData cardData = (SourceCardData) paymentAsSource.getSourceTypeModel(); if (cardData != null) { return cardData.getTokenizationMethod(); } } else if (paymentAsCard != null) { return paymentAsCard.getTokenizationMethod(); } return null; }
private void proceedWithPurchaseIf3DSCheckIsNotNecessary(Source source, String customerId) { if (source == null || !Source.CARD.equals(source.getType())) { displayError("Something went wrong - this should be rare"); return; } SourceCardData cardData = (SourceCardData) source.getSourceTypeModel(); if (SourceCardData.REQUIRED.equals(cardData.getThreeDSecureStatus())) { // In this case, you would need to ask the user to verify the purchase. // You can see an example of how to do this in the 3DS example application. // In stripe-android/example. } else { // If 3DS is not required, you can charge the source. completePurchase(source.getId(), customerId); } }
stringBuilder.append("Payment Info:\n"); if (cardSource != null) { SourceCardData scd = (SourceCardData) cardSource.getSourceTypeModel(); stringBuilder.append(scd.getBrand()) .append(" ending in ")
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (data == null) { // Data might be null if user tapped the back button from credit card selection return; } 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(); TextView methodTextView = findViewById(R.id.selected_payment_method_text_view); TextView cardBrandTextView = findViewById(R.id.selected_payment_method_brand_text_view); methodTextView.setText(buildCardString(cardData)); cardBrandTextView.setText(cardData.getBrand()); selectMethodSwitcher.showNext(); didSelectPaymentMethod = true; updateBuyButton(); } }
@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 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()); } }
assertNotNull(idealSource.getSourceTypeData()); assertNotNull(idealSource.getOwner()); assertNull(idealSource.getSourceTypeModel()); assertNotNull(idealSource.getRedirect()); assertEquals(bankName, idealSource.getSourceTypeData().get("bank"));
assertNotNull(sepaDebitSource.getOwner()); assertNotNull(sepaDebitSource.getOwner().getAddress()); assertNotNull(sepaDebitSource.getSourceTypeModel()); assertTrue(sepaDebitSource.getSourceTypeModel() instanceof SourceSepaDebitData); assertEquals("eur", sepaDebitSource.getCurrency()); assertEquals("Eureka", sepaDebitSource.getOwner().getAddress().getCity());
assertNotNull(idealSource.getSourceTypeData()); assertNotNull(idealSource.getOwner()); assertNull(idealSource.getSourceTypeModel()); assertEquals("Bond", idealSource.getOwner().getName()); assertNotNull(idealSource.getRedirect());
assertEquals("eur", sofortSource.getCurrency()); assertNotNull(sofortSource.getSourceTypeData()); assertNull(sofortSource.getSourceTypeModel()); assertEquals(70000L, sofortSource.getAmount().longValue()); assertNotNull(sofortSource.getRedirect());
assertNotNull(threeDSource.getClientSecret()); assertNotNull(threeDSource.getId()); assertNull(threeDSource.getSourceTypeModel()); assertEquals(Source.THREE_D_SECURE, threeDSource.getType()); assertNotNull(threeDSource.getSourceTypeData());
assertEquals(1000L, bancontactSource.getAmount().longValue()); assertNotNull(bancontactSource.getSourceTypeData()); assertNull(bancontactSource.getSourceTypeModel()); assertNotNull(bancontactSource.getOwner()); assertNotNull(bancontactSource.getRedirect());
assertNotNull(idealSource.getSourceTypeData()); assertNotNull(idealSource.getOwner()); assertNull(idealSource.getSourceTypeModel()); assertEquals("Bond", idealSource.getOwner().getName()); assertNotNull(idealSource.getRedirect());
assertNotNull(sepaDebitSource.getOwner()); assertNotNull(sepaDebitSource.getOwner().getAddress()); assertNotNull(sepaDebitSource.getSourceTypeModel()); assertTrue(sepaDebitSource.getSourceTypeModel() instanceof SourceSepaDebitData); assertEquals("eur", sepaDebitSource.getCurrency()); assertEquals("Eureka", sepaDebitSource.getOwner().getAddress().getCity());
assertNotNull(sepaDebitSource.getOwner()); assertNotNull(sepaDebitSource.getOwner().getAddress()); assertNotNull(sepaDebitSource.getSourceTypeModel()); assertTrue(sepaDebitSource.getSourceTypeModel() instanceof SourceSepaDebitData); assertEquals("eur", sepaDebitSource.getCurrency()); assertEquals("Eureka", sepaDebitSource.getOwner().getAddress().getCity());
assertEquals(Source.GIROPAY, giropaySource.getType()); assertNotNull(giropaySource.getSourceTypeData()); assertNull(giropaySource.getSourceTypeModel()); assertNotNull(giropaySource.getOwner()); assertNotNull(giropaySource.getRedirect());