@Test public void asCardBrand_whenBlank_returnsNull() { assertNull(asCardBrand(" ")); assertNull(asCardBrand(null)); }
@Test public void asCardBrand_whenVisa_returnsVisa() { assertEquals(Card.VISA, asCardBrand("visa")); }
@Test public void asCardBrand_whenMastercard_returnsMasterCard() { assertEquals(Card.MASTERCARD, asCardBrand("MasterCard")); }
@Test public void asCardBrand_whenCapitalizedStrangely_stillRecognizesCard() { assertEquals(Card.MASTERCARD, asCardBrand("Mastercard")); }
@Test public void asCardBrand_whenJcb_returnsJcb() { assertEquals(Card.JCB, asCardBrand("Jcb")); }
@Test public void asCardBrand_whenDiscover_returnsDiscover() { assertEquals(Card.DISCOVER, asCardBrand("Discover")); }
@Test public void asCardBrand_whenAmericanExpress_returnsAmericanExpress() { assertEquals(Card.AMERICAN_EXPRESS, asCardBrand("American express")); }
@Test public void asCardBrand_whenUnionPay_returnsUnionPay() { assertEquals(Card.UNIONPAY, asCardBrand("UnionPay")); }
@Test public void asCardBrand_whenNonemptyButWeird_returnsUnknown() { assertEquals(Card.UNKNOWN, asCardBrand("Awesome New Brand")); }
@Test public void asCardBrand_whenDinersClub_returnsDinersClub() { assertEquals(Card.DINERS_CLUB, asCardBrand("Diners Club")); }
@Nullable static SourceCardData fromJson(@Nullable JSONObject jsonObject) { if (jsonObject == null) { return null; } SourceCardData cardData = new SourceCardData(); cardData.setAddressLine1Check(optString(jsonObject, FIELD_ADDRESS_LINE1_CHECK)) .setAddressZipCheck(optString(jsonObject, FIELD_ADDRESS_ZIP_CHECK)) .setBrand(Card.asCardBrand(optString(jsonObject, FIELD_BRAND))) .setCountry(optString(jsonObject, FIELD_COUNTRY)) .setCvcCheck(optString(jsonObject, FIELD_CVC_CHECK)) .setDynamicLast4(optString(jsonObject, FIELD_DYNAMIC_LAST4)) .setExpiryMonth(optInteger(jsonObject, FIELD_EXP_MONTH)) .setExpiryYear(optInteger(jsonObject, FIELD_EXP_YEAR)) .setFunding(Card.asFundingType(optString(jsonObject, FIELD_FUNDING))) .setLast4(optString(jsonObject, FIELD_LAST4)) .setThreeDSecureStatus(asThreeDSecureStatus(optString(jsonObject, FIELD_THREE_D_SECURE))) .setTokenizationMethod(optString(jsonObject, FIELD_TOKENIZATION_METHOD)); Map<String, Object> nonStandardFields = jsonObjectToMapWithoutKeys(jsonObject, cardData.mStandardFields); if (nonStandardFields != null) { cardData.setAdditionalFields(nonStandardFields); } return cardData; }
builder.addressZip(optString(jsonObject, FIELD_ADDRESS_ZIP)); builder.addressZipCheck(optString(jsonObject, FIELD_ADDRESS_ZIP_CHECK)); builder.brand(asCardBrand(optString(jsonObject, FIELD_BRAND))); builder.country(optCountryCode(jsonObject, FIELD_COUNTRY)); builder.customer(optString(jsonObject, FIELD_CUSTOMER));
private Card(Builder builder) { this.number = StripeTextUtils.nullIfBlank(normalizeCardNumber(builder.number)); this.expMonth = builder.expMonth; this.expYear = builder.expYear; this.cvc = StripeTextUtils.nullIfBlank(builder.cvc); this.name = StripeTextUtils.nullIfBlank(builder.name); this.addressLine1 = StripeTextUtils.nullIfBlank(builder.addressLine1); this.addressLine1Check = StripeTextUtils.nullIfBlank(builder.addressLine1Check); this.addressLine2 = StripeTextUtils.nullIfBlank(builder.addressLine2); this.addressCity = StripeTextUtils.nullIfBlank(builder.addressCity); this.addressState = StripeTextUtils.nullIfBlank(builder.addressState); this.addressZip = StripeTextUtils.nullIfBlank(builder.addressZip); this.addressZipCheck = StripeTextUtils.nullIfBlank(builder.addressZipCheck); this.addressCountry = StripeTextUtils.nullIfBlank(builder.addressCountry); this.last4 = StripeTextUtils.nullIfBlank(builder.last4) == null ? getLast4() : builder.last4; this.brand = asCardBrand(builder.brand) == null ? getBrand() : builder.brand; this.fingerprint = StripeTextUtils.nullIfBlank(builder.fingerprint); this.funding = asFundingType(builder.funding); this.country = StripeTextUtils.nullIfBlank(builder.country); this.currency = StripeTextUtils.nullIfBlank(builder.currency); this.customerId = StripeTextUtils.nullIfBlank(builder.customer); this.cvcCheck = StripeTextUtils.nullIfBlank(builder.cvcCheck); this.id = StripeTextUtils.nullIfBlank(builder.id); this.tokenizationMethod = StripeTextUtils.nullIfBlank(builder.tokenizationMethod); this.metadata = builder.metadata; }
/** * Builder class for a {@link Card} model. */ public static class Builder { private final String number; private final String cvc; private final Integer expMonth; private final Integer expYear; private String name; private String addressLine1; private String addressLine1Check; private String addressLine2; private String addressCity; private String addressState; private String addressZip; private String addressZipCheck; private String addressCountry; private @CardBrand String brand; private @FundingType String funding; private @Size(4) String last4; private String fingerprint; private String country; private String currency; private String customer; private String cvcCheck; private String id; private String tokenizationMethod; private Map<String, String> metadata; /**