@NonNull private static Map<String, Object> hashMapFromCard( @Nullable UidProvider provider, @NonNull Context context, Card card) { Map<String, Object> tokenParams = new HashMap<>(); Map<String, Object> cardParams = new HashMap<>(); cardParams.put("number", StripeTextUtils.nullIfBlank(card.getNumber())); cardParams.put("cvc", StripeTextUtils.nullIfBlank(card.getCVC())); cardParams.put("exp_month", card.getExpMonth()); cardParams.put("exp_year", card.getExpYear()); cardParams.put("name", StripeTextUtils.nullIfBlank(card.getName())); cardParams.put("currency", StripeTextUtils.nullIfBlank(card.getCurrency())); cardParams.put("address_line1", StripeTextUtils.nullIfBlank(card.getAddressLine1())); cardParams.put("address_line2", StripeTextUtils.nullIfBlank(card.getAddressLine2())); cardParams.put("address_city", StripeTextUtils.nullIfBlank(card.getAddressCity())); cardParams.put("address_zip", StripeTextUtils.nullIfBlank(card.getAddressZip())); cardParams.put("address_state", StripeTextUtils.nullIfBlank(card.getAddressState())); cardParams.put("address_country", StripeTextUtils.nullIfBlank(card.getAddressCountry())); // Remove all null values; they cause validation errors removeNullAndEmptyParams(cardParams); // We store the logging items in this field, which is extracted from the parameters // sent to the API. tokenParams.put(LoggingUtils.FIELD_PRODUCT_USAGE, card.getLoggingTokens()); tokenParams.put(Token.TYPE_CARD, cardParams); addUidParams(provider, context, tokenParams); return tokenParams; }
@Test public void fromString_whenStringIsValidJson_returnsExpectedCard() { final Card expectedCard = buildEquivalentJsonCard(); final Card cardFromJson = Card.fromString(JSON_CARD); assertNotNull(cardFromJson); assertEquals(expectedCard.getBrand(), cardFromJson.getBrand()); assertEquals(expectedCard.getFunding(), cardFromJson.getFunding()); assertEquals(expectedCard.getCountry(), cardFromJson.getCountry()); assertEquals(expectedCard.getLast4(), cardFromJson.getLast4()); assertEquals(expectedCard.getExpMonth(), cardFromJson.getExpMonth()); assertEquals(expectedCard.getExpYear(), cardFromJson.getExpYear()); assertEquals(expectedCard.getCurrency(), cardFromJson.getCurrency()); assertEquals(expectedCard.getAddressCity(), cardFromJson.getAddressCity()); assertEquals(expectedCard.getAddressCountry(), cardFromJson.getAddressCountry()); assertEquals(expectedCard.getAddressLine1(), cardFromJson.getAddressLine1()); assertEquals(expectedCard.getAddressLine1Check(), cardFromJson.getAddressLine1Check()); assertEquals(expectedCard.getAddressLine2(), cardFromJson.getAddressLine2()); assertEquals(expectedCard.getAddressState(), cardFromJson.getAddressState()); assertEquals(expectedCard.getAddressZip(), cardFromJson.getAddressZip()); assertEquals(expectedCard.getAddressZipCheck(), cardFromJson.getAddressZipCheck()); assertEquals(expectedCard.getCvcCheck(), cardFromJson.getCvcCheck()); assertEquals(expectedCard.getName(), cardFromJson.getName()); assertEquals(expectedCard.getCustomerId(), cardFromJson.getCustomerId()); assertEquals(expectedCard.getFingerprint(), cardFromJson.getFingerprint()); assertEquals(expectedCard.getId(), cardFromJson.getId()); assertEquals(expectedCard.getMetadata(), cardFromJson.getMetadata()); }
addressMap.put(FIELD_COUNTRY, card.getAddressCountry()); addressMap.put(FIELD_STATE, card.getAddressState()); addressMap.put(FIELD_POSTAL_CODE, card.getAddressZip()); removeNullAndEmptyParams(addressMap);
@Test public void getCard_whenInputIsValidVisaAndNoZipRequired_returnsFullCardAndExpectedLogging() { // The input date here will be invalid after 2050. Please update the test. assertTrue(Calendar.getInstance().get(Calendar.YEAR) < 2050); mNoZipGroup.cardNumberEditText.setText(VALID_VISA_WITH_SPACES); mNoZipGroup.expiryDateEditText.append("12"); mNoZipGroup.expiryDateEditText.append("50"); mNoZipGroup.cvcEditText.append("123"); Card card = mNoZipCardMultilineWidget.getCard(); assertNotNull(card); assertEquals(VALID_VISA_NO_SPACES, card.getNumber()); assertNotNull(card.getExpMonth()); assertNotNull(card.getExpYear()); assertEquals(12, card.getExpMonth().intValue()); assertEquals(2050, card.getExpYear().intValue()); assertEquals("123", card.getCVC()); assertNull(card.getAddressZip()); assertTrue(card.validateCard()); assertArrayEquals(EXPECTED_LOGGING_ARRAY, card.getLoggingTokens().toArray()); }
@Test public void getCard_whenInputIsValidAmexAndNoZipRequiredAnd4DigitCvc_returnsFullCardAndExpectedLogging() { // The input date here will be invalid after 2050. Please update the test. assertTrue(Calendar.getInstance().get(Calendar.YEAR) < 2050); mNoZipGroup.cardNumberEditText.setText(VALID_AMEX_WITH_SPACES); mNoZipGroup.expiryDateEditText.append("12"); mNoZipGroup.expiryDateEditText.append("50"); mNoZipGroup.cvcEditText.append("1234"); Card card = mNoZipCardMultilineWidget.getCard(); assertNotNull(card); assertEquals(VALID_AMEX_NO_SPACES, card.getNumber()); assertNotNull(card.getExpMonth()); assertNotNull(card.getExpYear()); assertEquals(12, card.getExpMonth().intValue()); assertEquals(2050, card.getExpYear().intValue()); assertEquals("1234", card.getCVC()); assertNull(card.getAddressZip()); assertTrue(card.validateCard()); assertArrayEquals(EXPECTED_LOGGING_ARRAY, card.getLoggingTokens().toArray()); }
@Test public void getCard_whenInputIsValidAmexAndNoZipRequiredAnd3DigitCvc_returnsFullCardAndExpectedLogging() { // The input date here will be invalid after 2050. Please update the test. assertTrue(Calendar.getInstance().get(Calendar.YEAR) < 2050); mNoZipGroup.cardNumberEditText.setText(VALID_AMEX_WITH_SPACES); mNoZipGroup.expiryDateEditText.append("12"); mNoZipGroup.expiryDateEditText.append("50"); mNoZipGroup.cvcEditText.append("123"); Card card = mNoZipCardMultilineWidget.getCard(); assertNotNull(card); assertEquals(VALID_AMEX_NO_SPACES, card.getNumber()); assertNotNull(card.getExpMonth()); assertNotNull(card.getExpYear()); assertEquals(12, card.getExpMonth().intValue()); assertEquals(2050, card.getExpYear().intValue()); assertEquals("123", card.getCVC()); assertNull(card.getAddressZip()); assertTrue(card.validateCard()); assertArrayEquals(EXPECTED_LOGGING_ARRAY, card.getLoggingTokens().toArray()); }
@Test public void getCard_whenInputIsValidVisaWithZip_returnsCardObjectWithLoggingToken() { // The input date here will be invalid after 2050. Please update the test. assertTrue(Calendar.getInstance().get(Calendar.YEAR) < 2050); mFullGroup.cardNumberEditText.setText(VALID_VISA_WITH_SPACES); mFullGroup.expiryDateEditText.append("12"); mFullGroup.expiryDateEditText.append("50"); mFullGroup.cvcEditText.append("123"); mFullGroup.postalCodeEditText.append("12345"); Card card = mCardMultilineWidget.getCard(); assertNotNull(card); assertEquals(VALID_VISA_NO_SPACES, card.getNumber()); assertNotNull(card.getExpMonth()); assertNotNull(card.getExpYear()); assertEquals(12, card.getExpMonth().intValue()); assertEquals(2050, card.getExpYear().intValue()); assertEquals("123", card.getCVC()); assertEquals("12345", card.getAddressZip()); assertTrue(card.validateCard()); assertArrayEquals(EXPECTED_LOGGING_ARRAY, card.getLoggingTokens().toArray()); }