@Override public void onCustomerRetrieved(@NonNull Customer customer) { String sourceId = customer.getDefaultSource(); if (sourceId == null) { displayError("No payment method selected"); return; } CustomerSource source = customer.getSourceById(sourceId); proceedWithPurchaseIf3DSCheckIsNotNecessary(source.asSource(), customer.getId()); }
void addCustomerSourceIfSupported(CustomerSource... customerSources) { if (customerSources == null) { return; } for (CustomerSource customerSource : customerSources) { if (customerSource.asCard() != null || canDisplaySource(customerSource.asSource())) { // If it's a card, we can display it. mCustomerSourceList.add(customerSource); } } notifyDataSetChanged(); }
@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; }
CustomerSource source = mCustomer.getSourceById(data.getSelectedPaymentMethodId()); if (source != null) { Source cardSource = source.asSource(); stringBuilder.append("Payment Info:\n"); if (cardSource != null) {
/** * 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); } }
@Test public void fromJson_whenSource_createsCustomerSourceData() { CustomerSource sourceData = CustomerSource.fromString(EXAMPLE_JSON_SOURCE_WITHOUT_NULLS); assertNotNull(sourceData); assertNotNull(sourceData.asSource()); assertEquals("src_19t3xKBZqEXluyI4uz2dxAfQ", sourceData.getId()); }
@Test public void setCustomerSource_withNonCardSource_setsNoData() { CustomerSource customerSource = CustomerSource.fromString(EXAMPLE_JSON_SOURCE_BITCOIN); assertNotNull(customerSource); assertNotNull(customerSource.asSource()); mMaskedCardView.setCustomerSource(customerSource); assertNull(mMaskedCardView.getCardBrand()); assertNull(mMaskedCardView.getLast4()); assertFalse(mMaskedCardView.isSelected()); }
@Test public void setCustomerSource_withCardSource_setsCorrectData() { CustomerSource customerSource = CustomerSource.fromString(EXAMPLE_JSON_CARD_SOURCE); assertNotNull(customerSource); assertNotNull(customerSource.asSource()); mMaskedCardView.setCustomerSource(customerSource); assertEquals(Card.VISA, mMaskedCardView.getCardBrand()); assertEquals("4242", mMaskedCardView.getLast4()); assertFalse(mMaskedCardView.isSelected()); }
@Test public void setCustomerSource_withCardObject_setsCorrectData() { CustomerSource customerSource = CustomerSource.fromString(JSON_CARD); assertNotNull(customerSource); assertNotNull(customerSource.asCard()); assertNull(customerSource.asSource()); mMaskedCardView.setCustomerSource(customerSource); assertEquals(Card.MASTERCARD, mMaskedCardView.getCardBrand()); assertEquals("5555", mMaskedCardView.getLast4()); assertFalse(mMaskedCardView.isSelected()); }