diff --git a/example/src/main/java/com/stripe/example/activity/PaymentSessionActivity.java b/example/src/main/java/com/stripe/example/activity/PaymentSessionActivity.java index aa18b40432b..f0261a03963 100644 --- a/example/src/main/java/com/stripe/example/activity/PaymentSessionActivity.java +++ b/example/src/main/java/com/stripe/example/activity/PaymentSessionActivity.java @@ -123,8 +123,10 @@ private void setupPaymentSession(@NonNull CustomerSession customerSession) { new PaymentSessionListenerImpl(this, customerSession), new PaymentSessionConfig.Builder() .setPrepopulatedShippingInfo(getExampleShippingInfo()) - .setHiddenShippingInfoFields(ShippingInfoWidget.PHONE_FIELD, - ShippingInfoWidget.CITY_FIELD) + .setHiddenShippingInfoFields( + ShippingInfoWidget.CustomizableShippingField.PHONE_FIELD, + ShippingInfoWidget.CustomizableShippingField.CITY_FIELD + ) .build()); if (paymentSessionInitialized) { mPaymentSession.setCartTotal(2000L); diff --git a/example/src/main/java/com/stripe/example/activity/RedirectActivity.java b/example/src/main/java/com/stripe/example/activity/RedirectActivity.java index 6f3a9ab2251..a7950819c1d 100644 --- a/example/src/main/java/com/stripe/example/activity/RedirectActivity.java +++ b/example/src/main/java/com/stripe/example/activity/RedirectActivity.java @@ -142,8 +142,8 @@ void createCardSource(@NonNull Card card) { source.getType()); // If we need to get 3DS verification for this card, we // first create a 3DS Source. - if (SourceCardData.REQUIRED.equals(threeDSecureStatus)) { - + if (SourceCardData.ThreeDSecureStatus.REQUIRED + .equals(threeDSecureStatus)) { // The card Source can be used to create a 3DS Source createThreeDSecureSource(source.getId()); } else { diff --git a/example/src/main/java/com/stripe/example/adapter/RedirectAdapter.java b/example/src/main/java/com/stripe/example/adapter/RedirectAdapter.java index 3a3b312b9b6..50c4c768065 100644 --- a/example/src/main/java/com/stripe/example/adapter/RedirectAdapter.java +++ b/example/src/main/java/com/stripe/example/adapter/RedirectAdapter.java @@ -51,7 +51,7 @@ void setSourceId(@Nullable String sourceId) { void setSourceType(@Nullable String sourceType) { final String viewableType; - if (Source.THREE_D_SECURE.equals(sourceType)) { + if (Source.SourceType.THREE_D_SECURE.equals(sourceType)) { viewableType = "3DS"; } else { viewableType = sourceType; diff --git a/stripe/src/main/java/com/stripe/android/CardUtils.java b/stripe/src/main/java/com/stripe/android/CardUtils.java index b3714bcf2e6..948c0dfd5c4 100644 --- a/stripe/src/main/java/com/stripe/android/CardUtils.java +++ b/stripe/src/main/java/com/stripe/android/CardUtils.java @@ -17,12 +17,12 @@ public class CardUtils { private static final int LENGTH_DINERS_CLUB = 14; /** - * Returns a {@link Card.CardBrand} corresponding to a partial card number, - * or {@link Card#UNKNOWN} if the card brand can't be determined from the input value. + * Returns a {@link CardBrand} corresponding to a partial card number, + * or {@link Card.CardBrand#UNKNOWN} if the card brand can't be determined from the input value. * * @param cardNumber a credit card number or partial card number * @return the {@link Card.CardBrand} corresponding to that number, - * or {@link Card#UNKNOWN} if it can't be determined + * or {@link CardBrand#UNKNOWN} if it can't be determined */ @NonNull @Card.CardBrand @@ -96,21 +96,21 @@ static boolean isValidCardLength(@Nullable String cardNumber) { * the card. This function does not perform a Luhn check. * * @param cardNumber the card number with no spaces or dashes - * @param cardBrand a {@link CardBrand} used to get the correct size + * @param cardBrand a {@link Card.CardBrand} used to get the correct size * @return {@code true} if the card number is the correct length for the assumed brand */ static boolean isValidCardLength( @Nullable String cardNumber, @NonNull @CardBrand String cardBrand) { - if (cardNumber == null || Card.UNKNOWN.equals(cardBrand)) { + if (cardNumber == null || CardBrand.UNKNOWN.equals(cardBrand)) { return false; } int length = cardNumber.length(); switch (cardBrand) { - case Card.AMERICAN_EXPRESS: + case Card.CardBrand.AMERICAN_EXPRESS: return length == LENGTH_AMERICAN_EXPRESS; - case Card.DINERS_CLUB: + case CardBrand.DINERS_CLUB: return length == LENGTH_DINERS_CLUB; default: return length == LENGTH_COMMON_CARD; @@ -118,11 +118,11 @@ static boolean isValidCardLength( } @NonNull - @Card.CardBrand + @CardBrand private static String getPossibleCardType(@Nullable String cardNumber, boolean shouldNormalize) { if (StripeTextUtils.isBlank(cardNumber)) { - return Card.UNKNOWN; + return Card.CardBrand.UNKNOWN; } String spacelessCardNumber = cardNumber; @@ -131,21 +131,21 @@ private static String getPossibleCardType(@Nullable String cardNumber, } if (StripeTextUtils.hasAnyPrefix(spacelessCardNumber, Card.PREFIXES_AMERICAN_EXPRESS)) { - return Card.AMERICAN_EXPRESS; + return CardBrand.AMERICAN_EXPRESS; } else if (StripeTextUtils.hasAnyPrefix(spacelessCardNumber, Card.PREFIXES_DISCOVER)) { - return Card.DISCOVER; + return Card.CardBrand.DISCOVER; } else if (StripeTextUtils.hasAnyPrefix(spacelessCardNumber, Card.PREFIXES_JCB)) { - return Card.JCB; + return Card.CardBrand.JCB; } else if (StripeTextUtils.hasAnyPrefix(spacelessCardNumber, Card.PREFIXES_DINERS_CLUB)) { - return Card.DINERS_CLUB; + return Card.CardBrand.DINERS_CLUB; } else if (StripeTextUtils.hasAnyPrefix(spacelessCardNumber, Card.PREFIXES_VISA)) { - return Card.VISA; + return CardBrand.VISA; } else if (StripeTextUtils.hasAnyPrefix(spacelessCardNumber, Card.PREFIXES_MASTERCARD)) { - return Card.MASTERCARD; + return CardBrand.MASTERCARD; } else if (StripeTextUtils.hasAnyPrefix(spacelessCardNumber, Card.PREFIXES_UNIONPAY)) { - return Card.UNIONPAY; + return Card.CardBrand.UNIONPAY; } else { - return Card.UNKNOWN; + return Card.CardBrand.UNKNOWN; } } } diff --git a/stripe/src/main/java/com/stripe/android/LoggingUtils.java b/stripe/src/main/java/com/stripe/android/LoggingUtils.java index 7d40f0f25e5..682ca7cf398 100644 --- a/stripe/src/main/java/com/stripe/android/LoggingUtils.java +++ b/stripe/src/main/java/com/stripe/android/LoggingUtils.java @@ -31,36 +31,35 @@ class LoggingUtils { @Retention(RetentionPolicy.SOURCE) @StringDef({ - EVENT_TOKEN_CREATION, - EVENT_ADD_PAYMENT_METHOD, - EVENT_ATTACH_PAYMENT_METHOD, - EVENT_DETACH_PAYMENT_METHOD, - EVENT_SOURCE_CREATION, - EVENT_ADD_SOURCE, - EVENT_DEFAULT_SOURCE, - EVENT_DELETE_SOURCE, - EVENT_SET_SHIPPING_INFO, - EVENT_CONFIRM_PAYMENT_INTENT, - EVENT_RETRIEVE_PAYMENT_INTENT, - EVENT_CONFIRM_SETUP_INTENT, - EVENT_RETRIEVE_SETUP_INTENT}) - @interface LoggingEventName { + EventName.TOKEN_CREATION, + EventName.ADD_PAYMENT_METHOD, + EventName.ATTACH_PAYMENT_METHOD, + EventName.DETACH_PAYMENT_METHOD, + EventName.SOURCE_CREATION, + EventName.ADD_SOURCE, + EventName.DEFAULT_SOURCE, + EventName.DELETE_SOURCE, + EventName.SET_SHIPPING_INFO, + EventName.CONFIRM_PAYMENT_INTENT, + EventName.RETRIEVE_PAYMENT_INTENT, + EventName.CONFIRM_SETUP_INTENT, + EventName.RETRIEVE_SETUP_INTENT}) + @interface EventName { + String TOKEN_CREATION = "token_creation"; + String ADD_PAYMENT_METHOD = "add_payment_method"; + String ATTACH_PAYMENT_METHOD = "attach_payment_method"; + String DETACH_PAYMENT_METHOD = "detach_payment_method"; + String SOURCE_CREATION = "source_creation"; + String ADD_SOURCE = "add_source"; + String DEFAULT_SOURCE = "default_source"; + String DELETE_SOURCE = "delete_source"; + String SET_SHIPPING_INFO = "set_shipping_info"; + String CONFIRM_PAYMENT_INTENT = "payment_intent_confirmation"; + String RETRIEVE_PAYMENT_INTENT = "payment_intent_retrieval"; + String CONFIRM_SETUP_INTENT = "setup_intent_confirmation"; + String RETRIEVE_SETUP_INTENT = "setup_intent_retrieval"; } - static final String EVENT_TOKEN_CREATION = "token_creation"; - static final String EVENT_ADD_PAYMENT_METHOD = "add_payment_method"; - static final String EVENT_ATTACH_PAYMENT_METHOD = "attach_payment_method"; - static final String EVENT_DETACH_PAYMENT_METHOD = "detach_payment_method"; - static final String EVENT_SOURCE_CREATION = "source_creation"; - static final String EVENT_ADD_SOURCE = "add_source"; - static final String EVENT_DEFAULT_SOURCE = "default_source"; - static final String EVENT_DELETE_SOURCE = "delete_source"; - static final String EVENT_SET_SHIPPING_INFO = "set_shipping_info"; - static final String EVENT_CONFIRM_PAYMENT_INTENT = "payment_intent_confirmation"; - static final String EVENT_RETRIEVE_PAYMENT_INTENT = "payment_intent_retrieval"; - static final String EVENT_CONFIRM_SETUP_INTENT = "setup_intent_confirmation"; - static final String EVENT_RETRIEVE_SETUP_INTENT = "setup_intent_retrieval"; - static final String FIELD_PRODUCT_USAGE = "product_usage"; static final String FIELD_ANALYTICS_UA = "analytics_ua"; static final String FIELD_APP_NAME = "app_name"; @@ -118,7 +117,7 @@ Map getTokenCreationParams( productUsageTokens, null, tokenType, - publishableApiKey, EVENT_TOKEN_CREATION); + publishableApiKey, EventName.TOKEN_CREATION); } @NonNull @@ -129,7 +128,7 @@ Map getPaymentMethodCreationParams( productUsageTokens, null, null, - publishableApiKey, EVENT_ADD_PAYMENT_METHOD); + publishableApiKey, EventName.ADD_PAYMENT_METHOD); } @NonNull @@ -141,7 +140,7 @@ Map getSourceCreationParams( productUsageTokens, sourceType, null, - publishableApiKey, EVENT_SOURCE_CREATION); + publishableApiKey, EventName.SOURCE_CREATION); } @NonNull @@ -153,7 +152,7 @@ Map getAddSourceParams( productUsageTokens, sourceType, null, - publishableKey, EVENT_ADD_SOURCE); + publishableKey, EventName.ADD_SOURCE); } @NonNull @@ -164,7 +163,7 @@ Map getDeleteSourceParams( productUsageTokens, null, null, - publishableKey, EVENT_DELETE_SOURCE); + publishableKey, EventName.DELETE_SOURCE); } @NonNull @@ -175,7 +174,7 @@ Map getAttachPaymentMethodParams( productUsageTokens, null, null, - publishableKey, EVENT_ATTACH_PAYMENT_METHOD); + publishableKey, EventName.ATTACH_PAYMENT_METHOD); } @NonNull @@ -186,7 +185,7 @@ Map getDetachPaymentMethodParams( productUsageTokens, null, null, - publishableKey, EVENT_DETACH_PAYMENT_METHOD); + publishableKey, EventName.DETACH_PAYMENT_METHOD); } @NonNull @@ -198,7 +197,7 @@ Map getPaymentIntentConfirmationParams( productUsageTokens, sourceType, null, - publishableApiKey, EVENT_CONFIRM_PAYMENT_INTENT); + publishableApiKey, EventName.CONFIRM_PAYMENT_INTENT); } @NonNull @@ -209,7 +208,7 @@ Map getPaymentIntentRetrieveParams( productUsageTokens, null, null, - publishableApiKey, EVENT_RETRIEVE_PAYMENT_INTENT); + publishableApiKey, EventName.RETRIEVE_PAYMENT_INTENT); } @NonNull @@ -220,7 +219,7 @@ Map getSetupIntentConfirmationParams( productUsageTokens, null, null, - publishableApiKey, EVENT_CONFIRM_SETUP_INTENT); + publishableApiKey, EventName.CONFIRM_SETUP_INTENT); } @NonNull @@ -231,7 +230,7 @@ Map getSetupIntentRetrieveParams( productUsageTokens, null, null, - publishableApiKey, EVENT_RETRIEVE_SETUP_INTENT); + publishableApiKey, EventName.RETRIEVE_SETUP_INTENT); } @NonNull @@ -240,7 +239,7 @@ Map getEventLoggingParams( @Nullable @Source.SourceType String sourceType, @Nullable @Token.TokenType String tokenType, @NonNull String publishableApiKey, - @NonNull @LoggingEventName String eventName) { + @NonNull @EventName String eventName) { final Map paramsObject = new HashMap<>(); paramsObject.put(FIELD_ANALYTICS_UA, getAnalyticsUa()); paramsObject.put(FIELD_EVENT, getEventParamName(eventName)); @@ -312,7 +311,7 @@ static String getAnalyticsUa() { } @NonNull - static String getEventParamName(@NonNull @LoggingEventName String eventName) { + static String getEventParamName(@NonNull @EventName String eventName) { return ANALYTICS_NAME + '.' + eventName; } } diff --git a/stripe/src/main/java/com/stripe/android/PaymentSessionData.java b/stripe/src/main/java/com/stripe/android/PaymentSessionData.java index 449b20f4b10..40d059114ff 100644 --- a/stripe/src/main/java/com/stripe/android/PaymentSessionData.java +++ b/stripe/src/main/java/com/stripe/android/PaymentSessionData.java @@ -18,6 +18,7 @@ public class PaymentSessionData implements Parcelable { private long mCartTotal = 0L; private boolean mIsPaymentReadyToCharge; private long mShippingTotal = 0L; + @Nullable private ShippingInformation mShippingInformation; @Nullable private ShippingMethod mShippingMethod; @Nullable private PaymentMethod mPaymentMethod; diff --git a/stripe/src/main/java/com/stripe/android/Stripe.java b/stripe/src/main/java/com/stripe/android/Stripe.java index a7eb101d520..0da1b339164 100644 --- a/stripe/src/main/java/com/stripe/android/Stripe.java +++ b/stripe/src/main/java/com/stripe/android/Stripe.java @@ -285,7 +285,7 @@ public void createBankAccountToken( createTokenFromParams( mStripeNetworkUtils.createBankAccountTokenParams(bankAccount), publishableKey, - Token.TYPE_BANK_ACCOUNT, + Token.TokenType.BANK_ACCOUNT, executor, callback); } @@ -321,7 +321,7 @@ public void createPiiToken( createTokenFromParams( createPersonalIdTokenParams(personalId), publishableKey, - Token.TYPE_PII, + Token.TokenType.PII, executor, callback); } @@ -377,7 +377,7 @@ public Token createBankAccountTokenSynchronous(@NonNull final BankAccount bankAc return mApiHandler.createToken( mStripeNetworkUtils.createBankAccountTokenParams(bankAccount), ApiRequest.Options.create(publishableKey, mStripeAccount), - Token.TYPE_BANK_ACCOUNT + Token.TokenType.BANK_ACCOUNT ); } @@ -412,7 +412,7 @@ public void createCvcUpdateToken( createTokenFromParams( createUpdateCvcTokenParams(cvc), publishableKey, - Token.TYPE_CVC_UPDATE, + Token.TokenType.CVC_UPDATE, executor, callback); } @@ -538,7 +538,7 @@ public void createToken( createTokenFromParams( mStripeNetworkUtils.createCardTokenParams(card), publishableKey, - Token.TYPE_CARD, + Token.TokenType.CARD, executor, callback); } @@ -772,7 +772,7 @@ public Token createTokenSynchronous(@NonNull final Card card, @NonNull String pu return mApiHandler.createToken( mStripeNetworkUtils.createCardTokenParams(card), ApiRequest.Options.create(publishableKey, mStripeAccount), - Token.TYPE_CARD + Token.TokenType.CARD ); } @@ -822,7 +822,7 @@ public Token createPiiTokenSynchronous(@NonNull String personalId, return mApiHandler.createToken( createPersonalIdTokenParams(personalId), ApiRequest.Options.create(publishableKey, mStripeAccount), - Token.TYPE_PII + Token.TokenType.PII ); } @@ -872,7 +872,7 @@ public Token createCvcUpdateTokenSynchronous(@NonNull String cvc, return mApiHandler.createToken( createUpdateCvcTokenParams(cvc), ApiRequest.Options.create(publishableKey, mStripeAccount), - Token.TYPE_CVC_UPDATE + Token.TokenType.CVC_UPDATE ); } @@ -924,7 +924,7 @@ public Token createAccountTokenSynchronous( return mApiHandler.createToken( accountParams.toParamMap(), ApiRequest.Options.create(publishableKey, mStripeAccount), - Token.TYPE_ACCOUNT + Token.TokenType.ACCOUNT ); } catch (CardException exception) { // Should never occur. CardException is only for card related requests. diff --git a/stripe/src/main/java/com/stripe/android/StripeApiHandler.java b/stripe/src/main/java/com/stripe/android/StripeApiHandler.java index d4f2f53472f..9ca3cbee45b 100644 --- a/stripe/src/main/java/com/stripe/android/StripeApiHandler.java +++ b/stripe/src/main/java/com/stripe/android/StripeApiHandler.java @@ -561,7 +561,7 @@ Customer setDefaultCustomerSource( logApiCall( mLoggingUtils.getEventLoggingParams(productUsageTokens, sourceType, null, - publishableKey, LoggingUtils.EVENT_DEFAULT_SOURCE), + publishableKey, LoggingUtils.EventName.DEFAULT_SOURCE), ephemeralKey ); @@ -594,7 +594,7 @@ Customer setCustomerShippingInfo( logApiCall( mLoggingUtils.getEventLoggingParams(productUsageTokens, null, null, - publishableKey, LoggingUtils.EVENT_SET_SHIPPING_INFO), + publishableKey, LoggingUtils.EventName.SET_SHIPPING_INFO), publishableKey ); diff --git a/stripe/src/main/java/com/stripe/android/StripeNetworkUtils.java b/stripe/src/main/java/com/stripe/android/StripeNetworkUtils.java index 8f110e0db9a..bea790ab379 100644 --- a/stripe/src/main/java/com/stripe/android/StripeNetworkUtils.java +++ b/stripe/src/main/java/com/stripe/android/StripeNetworkUtils.java @@ -68,7 +68,7 @@ Map createCardTokenParams(@NonNull Card card) { // sent to the API. tokenParams.put(LoggingUtils.FIELD_PRODUCT_USAGE, card.getLoggingTokens()); - tokenParams.put(Token.TYPE_CARD, cardParams); + tokenParams.put(Token.TokenType.CARD, cardParams); tokenParams.putAll(createUidParams()); return tokenParams; @@ -79,7 +79,7 @@ static Map createPersonalIdTokenParams(@NonNull String personalI final Map tokenParams = new HashMap<>(); tokenParams.put("personal_id_number", personalId); final Map piiParams = new HashMap<>(); - piiParams.put(Token.TYPE_PII, tokenParams); + piiParams.put(Token.TokenType.PII, tokenParams); return piiParams; } @@ -88,7 +88,7 @@ static Map createUpdateCvcTokenParams(@NonNull String cvc) { final Map tokenParams = new HashMap<>(); tokenParams.put("cvc", cvc); final Map cvcParams = new HashMap<>(); - cvcParams.put(Token.TYPE_CVC_UPDATE, tokenParams); + cvcParams.put(Token.TokenType.CVC_UPDATE, tokenParams); return cvcParams; } @@ -116,7 +116,7 @@ Map createBankAccountTokenParams(@NonNull BankAccount bankAccoun // Remove all null values; they cause validation errors removeNullAndEmptyParams(accountParams); - tokenParams.put(Token.TYPE_BANK_ACCOUNT, accountParams); + tokenParams.put(Token.TokenType.BANK_ACCOUNT, accountParams); tokenParams.putAll(createUidParams()); return tokenParams; } diff --git a/stripe/src/main/java/com/stripe/android/model/BankAccount.java b/stripe/src/main/java/com/stripe/android/model/BankAccount.java index 5e60507f935..7e2724e1037 100644 --- a/stripe/src/main/java/com/stripe/android/model/BankAccount.java +++ b/stripe/src/main/java/com/stripe/android/model/BankAccount.java @@ -22,10 +22,11 @@ public final class BankAccount { @Retention(RetentionPolicy.SOURCE) - @StringDef({TYPE_COMPANY, TYPE_INDIVIDUAL}) - public @interface BankAccountType {} - public static final String TYPE_COMPANY = "company"; - public static final String TYPE_INDIVIDUAL = "individual"; + @StringDef({BankAccountType.COMPANY, BankAccountType.INDIVIDUAL}) + public @interface BankAccountType { + String COMPANY = "company"; + String INDIVIDUAL = "individual"; + } private static final String FIELD_ACCOUNT_HOLDER_NAME = "account_holder_name"; private static final String FIELD_ACCOUNT_HOLDER_TYPE = "account_holder_type"; @@ -170,10 +171,10 @@ public String getRoutingNumber() { @Nullable @BankAccountType public static String asBankAccountType(@Nullable String possibleAccountType) { - if (BankAccount.TYPE_COMPANY.equals(possibleAccountType)) { - return BankAccount.TYPE_COMPANY; - } else if (BankAccount.TYPE_INDIVIDUAL.equals(possibleAccountType)) { - return BankAccount.TYPE_INDIVIDUAL; + if (BankAccountType.COMPANY.equals(possibleAccountType)) { + return BankAccountType.COMPANY; + } else if (BankAccountType.INDIVIDUAL.equals(possibleAccountType)) { + return BankAccountType.INDIVIDUAL; } return null; diff --git a/stripe/src/main/java/com/stripe/android/model/Card.java b/stripe/src/main/java/com/stripe/android/model/Card.java index 0c70391607b..41d66e353a8 100644 --- a/stripe/src/main/java/com/stripe/android/model/Card.java +++ b/stripe/src/main/java/com/stripe/android/model/Card.java @@ -39,40 +39,42 @@ public final class Card extends StripeModel implements StripePaymentSource { @Retention(RetentionPolicy.SOURCE) @StringDef({ - AMERICAN_EXPRESS, - DISCOVER, - JCB, - DINERS_CLUB, - VISA, - MASTERCARD, - UNIONPAY, - UNKNOWN + CardBrand.AMERICAN_EXPRESS, + CardBrand.DISCOVER, + CardBrand.JCB, + CardBrand.DINERS_CLUB, + CardBrand.VISA, + CardBrand.MASTERCARD, + CardBrand.UNIONPAY, + CardBrand.UNKNOWN }) - public @interface CardBrand { } - public static final String AMERICAN_EXPRESS = "American Express"; - public static final String DISCOVER = "Discover"; - public static final String JCB = "JCB"; - public static final String DINERS_CLUB = "Diners Club"; - public static final String VISA = "Visa"; - public static final String MASTERCARD = "MasterCard"; - public static final String UNIONPAY = "UnionPay"; - public static final String UNKNOWN = "Unknown"; + public @interface CardBrand { + String AMERICAN_EXPRESS = "American Express"; + String DISCOVER = "Discover"; + String JCB = "JCB"; + String DINERS_CLUB = "Diners Club"; + String VISA = "Visa"; + String MASTERCARD = "MasterCard"; + String UNIONPAY = "UnionPay"; + String UNKNOWN = "Unknown"; + } public static final int CVC_LENGTH_AMERICAN_EXPRESS = 4; public static final int CVC_LENGTH_COMMON = 3; @Retention(RetentionPolicy.SOURCE) @StringDef({ - FUNDING_CREDIT, - FUNDING_DEBIT, - FUNDING_PREPAID, - FUNDING_UNKNOWN + FundingType.CREDIT, + FundingType.DEBIT, + FundingType.PREPAID, + FundingType.UNKNOWN }) - public @interface FundingType { } - public static final String FUNDING_CREDIT = "credit"; - public static final String FUNDING_DEBIT = "debit"; - public static final String FUNDING_PREPAID = "prepaid"; - public static final String FUNDING_UNKNOWN = "unknown"; + public @interface FundingType { + String CREDIT = "credit"; + String DEBIT = "debit"; + String PREPAID = "prepaid"; + String UNKNOWN = "unknown"; + } // Based on http://en.wikipedia.org/wiki/Bank_card_number#Issuer_identification_number_.28IIN.29 public static final String[] PREFIXES_AMERICAN_EXPRESS = {"34", "37"}; @@ -122,14 +124,14 @@ public final class Card extends StripeModel implements StripePaymentSource { private static final Map BRAND_RESOURCE_MAP = new HashMap() {{ - put(Card.AMERICAN_EXPRESS, R.drawable.ic_amex); - put(Card.DINERS_CLUB, R.drawable.ic_diners); - put(Card.DISCOVER, R.drawable.ic_discover); - put(Card.JCB, R.drawable.ic_jcb); - put(Card.MASTERCARD, R.drawable.ic_mastercard); - put(Card.VISA, R.drawable.ic_visa); - put(Card.UNIONPAY, R.drawable.ic_unionpay); - put(Card.UNKNOWN, R.drawable.ic_unknown); + put(CardBrand.AMERICAN_EXPRESS, R.drawable.ic_amex); + put(CardBrand.DINERS_CLUB, R.drawable.ic_diners); + put(CardBrand.DISCOVER, R.drawable.ic_discover); + put(CardBrand.JCB, R.drawable.ic_jcb); + put(CardBrand.MASTERCARD, R.drawable.ic_mastercard); + put(CardBrand.VISA, R.drawable.ic_visa); + put(CardBrand.UNIONPAY, R.drawable.ic_unionpay); + put(CardBrand.UNKNOWN, R.drawable.ic_unknown); }}; @Nullable private final String number; @@ -171,22 +173,22 @@ public static String asCardBrand(@Nullable String possibleCardType) { return null; } - if (Card.AMERICAN_EXPRESS.equalsIgnoreCase(possibleCardType)) { - return Card.AMERICAN_EXPRESS; - } else if (Card.MASTERCARD.equalsIgnoreCase(possibleCardType)) { - return Card.MASTERCARD; - } else if (Card.DINERS_CLUB.equalsIgnoreCase(possibleCardType)) { - return Card.DINERS_CLUB; - } else if (Card.DISCOVER.equalsIgnoreCase(possibleCardType)) { - return Card.DISCOVER; - } else if (Card.JCB.equalsIgnoreCase(possibleCardType)) { - return Card.JCB; - } else if (Card.VISA.equalsIgnoreCase(possibleCardType)) { - return Card.VISA; - } else if (Card.UNIONPAY.equalsIgnoreCase(possibleCardType)) { - return Card.UNIONPAY; + if (CardBrand.AMERICAN_EXPRESS.equalsIgnoreCase(possibleCardType)) { + return CardBrand.AMERICAN_EXPRESS; + } else if (CardBrand.MASTERCARD.equalsIgnoreCase(possibleCardType)) { + return CardBrand.MASTERCARD; + } else if (CardBrand.DINERS_CLUB.equalsIgnoreCase(possibleCardType)) { + return CardBrand.DINERS_CLUB; + } else if (CardBrand.DISCOVER.equalsIgnoreCase(possibleCardType)) { + return CardBrand.DISCOVER; + } else if (CardBrand.JCB.equalsIgnoreCase(possibleCardType)) { + return CardBrand.JCB; + } else if (CardBrand.VISA.equalsIgnoreCase(possibleCardType)) { + return CardBrand.VISA; + } else if (CardBrand.UNIONPAY.equalsIgnoreCase(possibleCardType)) { + return CardBrand.UNIONPAY; } else { - return Card.UNKNOWN; + return CardBrand.UNKNOWN; } } @@ -203,14 +205,14 @@ public static String asFundingType(@Nullable String possibleFundingType) { return null; } - if (Card.FUNDING_CREDIT.equalsIgnoreCase(possibleFundingType)) { - return Card.FUNDING_CREDIT; - } else if (Card.FUNDING_DEBIT.equalsIgnoreCase(possibleFundingType)) { - return Card.FUNDING_DEBIT; - } else if (Card.FUNDING_PREPAID.equalsIgnoreCase(possibleFundingType)) { - return Card.FUNDING_PREPAID; + if (FundingType.CREDIT.equalsIgnoreCase(possibleFundingType)) { + return FundingType.CREDIT; + } else if (FundingType.DEBIT.equalsIgnoreCase(possibleFundingType)) { + return FundingType.DEBIT; + } else if (FundingType.PREPAID.equalsIgnoreCase(possibleFundingType)) { + return FundingType.PREPAID; } else { - return Card.FUNDING_UNKNOWN; + return FundingType.UNKNOWN; } } @@ -380,7 +382,7 @@ public boolean validateCVC() { String updatedType = getBrand(); boolean validLength = (updatedType == null && cvcValue.length() >= 3 && cvcValue.length() <= 4) - || (AMERICAN_EXPRESS.equals(updatedType) && cvcValue.length() == 4) + || (CardBrand.AMERICAN_EXPRESS.equals(updatedType) && cvcValue.length() == 4) || cvcValue.length() == 3; return ModelUtils.isWholePositiveNumber(cvcValue) && validLength; diff --git a/stripe/src/main/java/com/stripe/android/model/CustomerSource.java b/stripe/src/main/java/com/stripe/android/model/CustomerSource.java index 73cded852e5..21240703ab6 100644 --- a/stripe/src/main/java/com/stripe/android/model/CustomerSource.java +++ b/stripe/src/main/java/com/stripe/android/model/CustomerSource.java @@ -47,7 +47,7 @@ public Source asSource() { public String getTokenizationMethod() { final Source paymentAsSource = asSource(); final Card paymentAsCard = asCard(); - if (paymentAsSource != null && Source.CARD.equals(paymentAsSource.getType())) { + if (paymentAsSource != null && Source.SourceType.CARD.equals(paymentAsSource.getType())) { final SourceCardData cardData = (SourceCardData) paymentAsSource.getSourceTypeModel(); if (cardData != null) { return cardData.getTokenizationMethod(); @@ -70,11 +70,11 @@ public Card asCard() { @Source.SourceType public String getSourceType() { if (mStripePaymentSource instanceof Card) { - return Source.CARD; + return Source.SourceType.CARD; } else if (mStripePaymentSource instanceof Source) { return ((Source) mStripePaymentSource).getType(); } else { - return Source.UNKNOWN; + return Source.SourceType.UNKNOWN; } } diff --git a/stripe/src/main/java/com/stripe/android/model/Source.java b/stripe/src/main/java/com/stripe/android/model/Source.java index 729b67a3df7..776baa7f854 100644 --- a/stripe/src/main/java/com/stripe/android/model/Source.java +++ b/stripe/src/main/java/com/stripe/android/model/Source.java @@ -13,6 +13,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.AbstractMap; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -35,76 +36,76 @@ public final class Source extends StripeModel implements StripePaymentSource { @Retention(RetentionPolicy.SOURCE) @StringDef({ - ALIPAY, - CARD, - THREE_D_SECURE, - GIROPAY, - SEPA_DEBIT, - IDEAL, - SOFORT, - BANCONTACT, - P24, - EPS, - MULTIBANCO, - UNKNOWN + SourceType.ALIPAY, + SourceType.CARD, + SourceType.THREE_D_SECURE, + SourceType.GIROPAY, + SourceType.SEPA_DEBIT, + SourceType.IDEAL, + SourceType.SOFORT, + SourceType.BANCONTACT, + SourceType.P24, + SourceType.EPS, + SourceType.MULTIBANCO, + SourceType.UNKNOWN }) - public @interface SourceType { } - public static final String ALIPAY = "alipay"; - public static final String CARD = "card"; - public static final String THREE_D_SECURE = "three_d_secure"; - public static final String GIROPAY = "giropay"; - public static final String SEPA_DEBIT = "sepa_debit"; - public static final String IDEAL = "ideal"; - public static final String SOFORT = "sofort"; - public static final String BANCONTACT = "bancontact"; - public static final String P24 = "p24"; - public static final String EPS = "eps"; - public static final String MULTIBANCO = "multibanco"; - public static final String UNKNOWN = "unknown"; - - private static final Set MODELED_TYPES = new HashSet<>(); - - static { - MODELED_TYPES.add(CARD); - MODELED_TYPES.add(SEPA_DEBIT); - } + public @interface SourceType { + String ALIPAY = "alipay"; + String CARD = "card"; + String THREE_D_SECURE = "three_d_secure"; + String GIROPAY = "giropay"; + String SEPA_DEBIT = "sepa_debit"; + String IDEAL = "ideal"; + String SOFORT = "sofort"; + String BANCONTACT = "bancontact"; + String P24 = "p24"; + String EPS = "eps"; + String MULTIBANCO = "multibanco"; + String UNKNOWN = "unknown"; + } + + private static final Set MODELED_TYPES = new HashSet<>( + Arrays.asList(SourceType.CARD, SourceType.SEPA_DEBIT)); @Retention(RetentionPolicy.SOURCE) @StringDef({ - PENDING, - CHARGEABLE, - CONSUMED, - CANCELED, - FAILED + SourceStatus.PENDING, + SourceStatus.CHARGEABLE, + SourceStatus.CONSUMED, + SourceStatus.CANCELED, + SourceStatus.FAILED }) - public @interface SourceStatus { } - public static final String PENDING = "pending"; - public static final String CHARGEABLE = "chargeable"; - public static final String CONSUMED = "consumed"; - public static final String CANCELED = "canceled"; - public static final String FAILED = "failed"; + public @interface SourceStatus { + String PENDING = "pending"; + String CHARGEABLE = "chargeable"; + String CONSUMED = "consumed"; + String CANCELED = "canceled"; + String FAILED = "failed"; + } @Retention(RetentionPolicy.SOURCE) @StringDef({ - REUSABLE, - SINGLE_USE + Usage.REUSABLE, + Usage.SINGLE_USE }) - public @interface Usage { } - public static final String REUSABLE = "reusable"; - public static final String SINGLE_USE = "single_use"; + public @interface Usage { + String REUSABLE = "reusable"; + String SINGLE_USE = "single_use"; + } @Retention(RetentionPolicy.SOURCE) @StringDef({ - REDIRECT, - RECEIVER, - CODE_VERIFICATION, - NONE + SourceFlow.REDIRECT, + SourceFlow.RECEIVER, + SourceFlow.CODE_VERIFICATION, + SourceFlow.NONE }) - public @interface SourceFlow { } - public static final String REDIRECT = "redirect"; - public static final String RECEIVER = "receiver"; - public static final String CODE_VERIFICATION = "code_verification"; - public static final String NONE = "none"; + public @interface SourceFlow { + String REDIRECT = "redirect"; + String RECEIVER = "receiver"; + String CODE_VERIFICATION = "code_verification"; + String NONE = "none"; + } static final String EURO = "eur"; static final String USD = "usd"; @@ -147,7 +148,7 @@ public final class Source extends StripeModel implements StripePaymentSource { private Source(@Nullable String id, @Nullable SourceCardData sourceTypeModel) { mId = id; - mType = CARD; + mType = SourceType.CARD; mSourceTypeModel = sourceTypeModel; } @@ -257,8 +258,8 @@ public StripeSourceTypeModel getSourceTypeModel() { /** * Gets the {@link SourceType} of this Source, as one of the enumerated values. - * If a custom source type has been created, this returns {@link #UNKNOWN}. To get - * the raw value of an {@link #UNKNOWN} type, use {@link #getTypeRaw()}. + * If a custom source type has been created, this returns {@link SourceType#UNKNOWN}. To get + * the raw value of an {@link SourceType#UNKNOWN} type, use {@link #getTypeRaw()}. * * @return the {@link SourceType} of this Source */ @@ -341,7 +342,7 @@ public void setSourceTypeData(Map sourceTypeData) { public void setTypeRaw(@NonNull @Size(min = 1) String typeRaw) { mTypeRaw = typeRaw; - setType(UNKNOWN); + setType(SourceType.UNKNOWN); } public void setType(@SourceType String type) { @@ -449,7 +450,7 @@ private static Source fromSourceJson(@NonNull JSONObject jsonObject) { @SourceStatus final String status = asSourceStatus(optString(jsonObject, FIELD_STATUS)); final String typeRawOpt = optString(jsonObject, FIELD_TYPE); - @SourceType final String typeRaw = typeRawOpt != null ? typeRawOpt : UNKNOWN; + @SourceType final String typeRaw = typeRawOpt != null ? typeRawOpt : SourceType.UNKNOWN; @SourceType final String type = asSourceType(typeRaw); // Until we have models for all types, keep the original hash and the @@ -495,9 +496,8 @@ private static T optStripeJsonModel( switch (key) { case FIELD_CODE_VERIFICATION: - return type.cast( - SourceCodeVerification.fromJson( - jsonObject.optJSONObject(FIELD_CODE_VERIFICATION))); + return type.cast(SourceCodeVerification.fromJson( + jsonObject.optJSONObject(FIELD_CODE_VERIFICATION))); case FIELD_OWNER: return type.cast( SourceOwner.fromJson(jsonObject.optJSONObject(FIELD_OWNER))); @@ -507,12 +507,12 @@ private static T optStripeJsonModel( case FIELD_REDIRECT: return type.cast( SourceRedirect.fromJson(jsonObject.optJSONObject(FIELD_REDIRECT))); - case CARD: - return type.cast( - SourceCardData.fromJson(jsonObject.optJSONObject(CARD))); - case SEPA_DEBIT: + case SourceType.CARD: return type.cast( - SourceSepaDebitData.fromJson(jsonObject.optJSONObject(SEPA_DEBIT))); + SourceCardData.fromJson(jsonObject.optJSONObject(SourceType.CARD))); + case SourceType.SEPA_DEBIT: + return type.cast(SourceSepaDebitData.fromJson( + jsonObject.optJSONObject(SourceType.SEPA_DEBIT))); default: return null; } @@ -521,16 +521,16 @@ private static T optStripeJsonModel( @Nullable @SourceStatus private static String asSourceStatus(@Nullable String sourceStatus) { - if (PENDING.equals(sourceStatus)) { - return PENDING; - } else if (CHARGEABLE.equals(sourceStatus)) { - return CHARGEABLE; - } else if (CONSUMED.equals(sourceStatus)) { - return CONSUMED; - } else if (CANCELED.equals(sourceStatus)) { - return CANCELED; - } else if (FAILED.equals(sourceStatus)) { - return FAILED; + if (SourceStatus.PENDING.equals(sourceStatus)) { + return SourceStatus.PENDING; + } else if (SourceStatus.CHARGEABLE.equals(sourceStatus)) { + return SourceStatus.CHARGEABLE; + } else if (SourceStatus.CONSUMED.equals(sourceStatus)) { + return SourceStatus.CONSUMED; + } else if (SourceStatus.CANCELED.equals(sourceStatus)) { + return SourceStatus.CANCELED; + } else if (SourceStatus.FAILED.equals(sourceStatus)) { + return SourceStatus.FAILED; } return null; } @@ -538,38 +538,38 @@ private static String asSourceStatus(@Nullable String sourceStatus) { @NonNull @SourceType static String asSourceType(@Nullable String sourceType) { - if (CARD.equals(sourceType)) { - return CARD; - } else if (THREE_D_SECURE.equals(sourceType)) { - return THREE_D_SECURE; - } else if (GIROPAY.equals(sourceType)) { - return GIROPAY; - } else if (SEPA_DEBIT.equals(sourceType)) { - return SEPA_DEBIT; - } else if (IDEAL.equals(sourceType)) { - return IDEAL; - } else if (SOFORT.equals(sourceType)) { - return SOFORT; - } else if (BANCONTACT.equals(sourceType)) { - return BANCONTACT; - } else if (ALIPAY.equals(sourceType)) { - return ALIPAY; - } else if (P24.equals(sourceType)) { - return P24; - } else if (UNKNOWN.equals(sourceType)) { - return UNKNOWN; + if (SourceType.CARD.equals(sourceType)) { + return SourceType.CARD; + } else if (SourceType.THREE_D_SECURE.equals(sourceType)) { + return SourceType.THREE_D_SECURE; + } else if (SourceType.GIROPAY.equals(sourceType)) { + return SourceType.GIROPAY; + } else if (SourceType.SEPA_DEBIT.equals(sourceType)) { + return SourceType.SEPA_DEBIT; + } else if (SourceType.IDEAL.equals(sourceType)) { + return SourceType.IDEAL; + } else if (SourceType.SOFORT.equals(sourceType)) { + return SourceType.SOFORT; + } else if (SourceType.BANCONTACT.equals(sourceType)) { + return SourceType.BANCONTACT; + } else if (SourceType.ALIPAY.equals(sourceType)) { + return SourceType.ALIPAY; + } else if (SourceType.P24.equals(sourceType)) { + return SourceType.P24; + } else if (SourceType.UNKNOWN.equals(sourceType)) { + return SourceType.UNKNOWN; } else { - return UNKNOWN; + return SourceType.UNKNOWN; } } @Nullable @Usage private static String asUsage(@Nullable String usage) { - if (REUSABLE.equals(usage)) { - return REUSABLE; - } else if (SINGLE_USE.equals(usage)) { - return SINGLE_USE; + if (Usage.REUSABLE.equals(usage)) { + return Usage.REUSABLE; + } else if (Usage.SINGLE_USE.equals(usage)) { + return Usage.SINGLE_USE; } return null; } @@ -577,14 +577,14 @@ private static String asUsage(@Nullable String usage) { @Nullable @SourceFlow private static String asSourceFlow(@Nullable String sourceFlow) { - if (REDIRECT.equals(sourceFlow)) { - return REDIRECT; - } else if (RECEIVER.equals(sourceFlow)) { - return RECEIVER; - } else if (CODE_VERIFICATION.equals(sourceFlow)) { - return CODE_VERIFICATION; - } else if (NONE.equals(sourceFlow)) { - return NONE; + if (SourceFlow.REDIRECT.equals(sourceFlow)) { + return SourceFlow.REDIRECT; + } else if (SourceFlow.RECEIVER.equals(sourceFlow)) { + return SourceFlow.RECEIVER; + } else if (SourceFlow.CODE_VERIFICATION.equals(sourceFlow)) { + return SourceFlow.CODE_VERIFICATION; + } else if (SourceFlow.NONE.equals(sourceFlow)) { + return SourceFlow.NONE; } return null; } diff --git a/stripe/src/main/java/com/stripe/android/model/SourceCardData.java b/stripe/src/main/java/com/stripe/android/model/SourceCardData.java index 17758c14975..e29bd1e9eab 100644 --- a/stripe/src/main/java/com/stripe/android/model/SourceCardData.java +++ b/stripe/src/main/java/com/stripe/android/model/SourceCardData.java @@ -31,18 +31,19 @@ public final class SourceCardData extends StripeSourceTypeModel { @Retention(RetentionPolicy.SOURCE) @StringDef({ - REQUIRED, - OPTIONAL, - NOT_SUPPORTED, - RECOMMENDED, - UNKNOWN + ThreeDSecureStatus.REQUIRED, + ThreeDSecureStatus.OPTIONAL, + ThreeDSecureStatus.NOT_SUPPORTED, + ThreeDSecureStatus.RECOMMENDED, + ThreeDSecureStatus.UNKNOWN }) - public @interface ThreeDSecureStatus { } - public static final String REQUIRED = "required"; - public static final String OPTIONAL = "optional"; - public static final String NOT_SUPPORTED = "not_supported"; - public static final String RECOMMENDED = "recommended"; - public static final String UNKNOWN = "unknown"; + public @interface ThreeDSecureStatus { + String REQUIRED = "required"; + String OPTIONAL = "optional"; + String NOT_SUPPORTED = "not_supported"; + String RECOMMENDED = "recommended"; + String UNKNOWN = "unknown"; + } private static final String FIELD_ADDRESS_LINE1_CHECK = "address_line1_check"; private static final String FIELD_ADDRESS_ZIP_CHECK = "address_zip_check"; @@ -73,7 +74,8 @@ public final class SourceCardData extends StripeSourceTypeModel { @Nullable private final String mAddressLine1Check; @Nullable private final String mAddressZipCheck; - @Nullable @Card.CardBrand private final String mBrand; + @Nullable @Card.CardBrand + private final String mBrand; @Nullable private final String mCountry; @Nullable private final String mCvcCheck; @Nullable private final String mDynamicLast4; @@ -230,16 +232,16 @@ static String asThreeDSecureStatus(@Nullable String threeDSecureStatus) { return null; } - if (REQUIRED.equalsIgnoreCase(threeDSecureStatus)) { - return REQUIRED; - } else if (OPTIONAL.equalsIgnoreCase(threeDSecureStatus)) { - return OPTIONAL; - } else if (NOT_SUPPORTED.equalsIgnoreCase(threeDSecureStatus)) { - return NOT_SUPPORTED; - } else if (RECOMMENDED.equalsIgnoreCase(threeDSecureStatus)) { - return RECOMMENDED; + if (ThreeDSecureStatus.REQUIRED.equalsIgnoreCase(threeDSecureStatus)) { + return ThreeDSecureStatus.REQUIRED; + } else if (ThreeDSecureStatus.OPTIONAL.equalsIgnoreCase(threeDSecureStatus)) { + return ThreeDSecureStatus.OPTIONAL; + } else if (ThreeDSecureStatus.NOT_SUPPORTED.equalsIgnoreCase(threeDSecureStatus)) { + return ThreeDSecureStatus.NOT_SUPPORTED; + } else if (ThreeDSecureStatus.RECOMMENDED.equalsIgnoreCase(threeDSecureStatus)) { + return ThreeDSecureStatus.RECOMMENDED; } else { - return UNKNOWN; + return ThreeDSecureStatus.UNKNOWN; } } @@ -274,7 +276,8 @@ public int hashCode() { private static final class Builder extends BaseBuilder { private String mAddressLine1Check; private String mAddressZipCheck; - @Card.CardBrand private String mBrand; + @Card.CardBrand + private String mBrand; private String mCountry; private String mCvcCheck; private String mDynamicLast4; diff --git a/stripe/src/main/java/com/stripe/android/model/SourceCodeVerification.java b/stripe/src/main/java/com/stripe/android/model/SourceCodeVerification.java index 5c602a91996..1c3c46cd261 100644 --- a/stripe/src/main/java/com/stripe/android/model/SourceCodeVerification.java +++ b/stripe/src/main/java/com/stripe/android/model/SourceCodeVerification.java @@ -27,14 +27,15 @@ public final class SourceCodeVerification extends StripeModel { // They don't have to stay the same forever, so they are redefined here. @Retention(RetentionPolicy.SOURCE) @StringDef({ - PENDING, - SUCCEEDED, - FAILED + Status.PENDING, + Status.SUCCEEDED, + Status.FAILED }) - @interface Status { } - static final String PENDING = "pending"; - static final String SUCCEEDED = "succeeded"; - static final String FAILED = "failed"; + @interface Status { + String PENDING = "pending"; + String SUCCEEDED = "succeeded"; + String FAILED = "failed"; + } private static final String FIELD_ATTEMPTS_REMAINING = "attempts_remaining"; private static final String FIELD_STATUS = "status"; @@ -92,12 +93,12 @@ public static SourceCodeVerification fromJson(@Nullable JSONObject jsonObject) { @Nullable @Status private static String asStatus(@Nullable String stringStatus) { - if (PENDING.equals(stringStatus)) { - return PENDING; - } else if (SUCCEEDED.equals(stringStatus)) { - return SUCCEEDED; - } else if (FAILED.equals(stringStatus)) { - return FAILED; + if (Status.PENDING.equals(stringStatus)) { + return Status.PENDING; + } else if (Status.SUCCEEDED.equals(stringStatus)) { + return Status.SUCCEEDED; + } else if (Status.FAILED.equals(stringStatus)) { + return Status.FAILED; } return null; diff --git a/stripe/src/main/java/com/stripe/android/model/SourceParams.java b/stripe/src/main/java/com/stripe/android/model/SourceParams.java index d267d4e5e59..9708ae1ef66 100644 --- a/stripe/src/main/java/com/stripe/android/model/SourceParams.java +++ b/stripe/src/main/java/com/stripe/android/model/SourceParams.java @@ -92,7 +92,7 @@ public static SourceParams createP24Params( @NonNull String returnUrl) { final SourceParams params = new SourceParams() .setAmount(amount) - .setType(Source.P24) + .setType(SourceType.P24) .setCurrency(currency) .setRedirect(createSimpleMap(FIELD_RETURN_URL, returnUrl)); @@ -128,10 +128,10 @@ public static SourceParams createAlipayReusableParams( @Nullable String email, @NonNull String returnUrl) { final SourceParams params = new SourceParams() - .setType(Source.ALIPAY) + .setType(SourceType.ALIPAY) .setCurrency(currency) .setRedirect(createSimpleMap(FIELD_RETURN_URL, returnUrl)) - .setUsage(Source.REUSABLE); + .setUsage(Source.Usage.REUSABLE); final AbstractMap ownerMap = new HashMap<>(); ownerMap.put(FIELD_NAME, name); @@ -168,7 +168,7 @@ public static SourceParams createAlipaySingleUseParams( @Nullable String email, @NonNull String returnUrl) { final SourceParams params = new SourceParams() - .setType(Source.ALIPAY) + .setType(SourceType.ALIPAY) .setCurrency(currency) .setAmount(amount) .setRedirect(createSimpleMap(FIELD_RETURN_URL, returnUrl)); @@ -209,7 +209,7 @@ public static SourceParams createBancontactParams( @Nullable String statementDescriptor, @Nullable String preferredLanguage) { final SourceParams params = new SourceParams() - .setType(Source.BANCONTACT) + .setType(SourceType.BANCONTACT) .setCurrency(Source.EURO) .setAmount(amount) .setOwner(createSimpleMap(FIELD_NAME, name)) @@ -248,7 +248,7 @@ public static SourceParams createCustomParams() { @NonNull public static SourceParams createSourceFromTokenParams(@NonNull String tokenId) { SourceParams sourceParams = SourceParams.createCustomParams(); - sourceParams.setType(Source.CARD); + sourceParams.setType(SourceType.CARD); sourceParams.setToken(tokenId); return sourceParams; } @@ -263,7 +263,7 @@ public static SourceParams createSourceFromTokenParams(@NonNull String tokenId) */ @NonNull public static SourceParams createCardParams(@NonNull Card card) { - final SourceParams params = new SourceParams().setType(Source.CARD); + final SourceParams params = new SourceParams().setType(SourceType.CARD); // Not enforcing all fields to exist at this level. // Instead, the server will return an error for invalid data. @@ -324,7 +324,7 @@ public static SourceParams createEPSParams( @NonNull String returnUrl, @Nullable String statementDescriptor) { final SourceParams params = new SourceParams() - .setType(Source.EPS) + .setType(SourceType.EPS) .setCurrency(Source.EURO) .setAmount(amount) .setOwner(createSimpleMap(FIELD_NAME, name)) @@ -359,7 +359,7 @@ public static SourceParams createGiropayParams( @NonNull String returnUrl, @Nullable String statementDescriptor) { final SourceParams params = new SourceParams() - .setType(Source.GIROPAY) + .setType(SourceType.GIROPAY) .setCurrency(Source.EURO) .setAmount(amount) .setOwner(createSimpleMap(FIELD_NAME, name)) @@ -396,7 +396,7 @@ public static SourceParams createIdealParams( @Nullable String statementDescriptor, @Nullable String bank) { final SourceParams params = new SourceParams() - .setType(Source.IDEAL) + .setType(SourceType.IDEAL) .setCurrency(Source.EURO) .setAmount(amount) .setRedirect(createSimpleMap(FIELD_RETURN_URL, returnUrl)); @@ -434,7 +434,7 @@ public static SourceParams createMultibancoParams( @NonNull String returnUrl, @NonNull String email) { return new SourceParams() - .setType(Source.MULTIBANCO) + .setType(SourceType.MULTIBANCO) .setCurrency(Source.EURO) .setAmount(amount) .setRedirect(createSimpleMap(FIELD_RETURN_URL, returnUrl)) @@ -476,7 +476,7 @@ public static SourceParams createSepaDebitParams( @Nullable String postalCode, @Nullable @Size(2) String country) { final SourceParams params = new SourceParams() - .setType(Source.SEPA_DEBIT) + .setType(SourceType.SEPA_DEBIT) .setCurrency(Source.EURO); final AbstractMap address = new HashMap<>(); @@ -515,7 +515,7 @@ public static SourceParams createSofortParams( @NonNull @Size(2) String country, @Nullable String statementDescriptor) { final SourceParams params = new SourceParams() - .setType(Source.SOFORT) + .setType(SourceType.SOFORT) .setCurrency(Source.EURO) .setAmount(amount) .setRedirect(createSimpleMap(FIELD_RETURN_URL, returnUrl)); @@ -548,7 +548,7 @@ public static SourceParams createThreeDSecureParams( @NonNull String returnUrl, @NonNull String cardID) { return new SourceParams() - .setType(Source.THREE_D_SECURE) + .setType(SourceType.THREE_D_SECURE) .setCurrency(currency) .setAmount(amount) .setRedirect(createSimpleMap(FIELD_RETURN_URL, returnUrl)) @@ -567,7 +567,7 @@ public static SourceParams createThreeDSecureParams( @NonNull public static SourceParams createVisaCheckoutParams(@NonNull String callId) { return new SourceParams() - .setType(Source.CARD) + .setType(SourceType.CARD) .setApiParameterMap( createSimpleMap(VISA_CHECKOUT, createSimpleMap(CALL_ID, callId))); } @@ -593,7 +593,7 @@ public static SourceParams createMasterpassParams( map.put(CART_ID, cartID); return new SourceParams() - .setType(Source.CARD) + .setType(SourceType.CARD) .setApiParameterMap(createSimpleMap(MASTERPASS, map)); } @@ -784,7 +784,7 @@ public SourceParams setType(@Source.SourceType String type) { /** * Sets a custom type for the source, and sets the {@link #mType type} for these parameters - * to be {@link Source#UNKNOWN}. + * to be {@link SourceType#UNKNOWN}. * * @param typeRaw the name of the source type * @return {@code this}, for chaining purposes diff --git a/stripe/src/main/java/com/stripe/android/model/SourceRedirect.java b/stripe/src/main/java/com/stripe/android/model/SourceRedirect.java index 494a29b3e26..05ff73e3dc5 100644 --- a/stripe/src/main/java/com/stripe/android/model/SourceRedirect.java +++ b/stripe/src/main/java/com/stripe/android/model/SourceRedirect.java @@ -27,16 +27,17 @@ public final class SourceRedirect extends StripeModel { @Retention(RetentionPolicy.SOURCE) @StringDef({ - PENDING, - SUCCEEDED, - FAILED, - NOT_REQUIRED + Status.PENDING, + Status.SUCCEEDED, + Status.FAILED, + Status.NOT_REQUIRED }) - @interface Status { } - public static final String PENDING = "pending"; - public static final String SUCCEEDED = "succeeded"; - public static final String FAILED = "failed"; - public static final String NOT_REQUIRED = "not_required"; + @interface Status { + String PENDING = "pending"; + String SUCCEEDED = "succeeded"; + String FAILED = "failed"; + String NOT_REQUIRED = "not_required"; + } private static final String FIELD_RETURN_URL = "return_url"; private static final String FIELD_STATUS = "status"; @@ -105,14 +106,14 @@ public static SourceRedirect fromJson(@Nullable JSONObject jsonObject) { @Status @VisibleForTesting static String asStatus(@Nullable String stringStatus) { - if (PENDING.equals(stringStatus)) { - return PENDING; - } else if (SUCCEEDED.equals(stringStatus)) { - return SUCCEEDED; - } else if (FAILED.equals(stringStatus)) { - return FAILED; - } else if (NOT_REQUIRED.equals(stringStatus)) { - return NOT_REQUIRED; + if (Status.PENDING.equals(stringStatus)) { + return Status.PENDING; + } else if (Status.SUCCEEDED.equals(stringStatus)) { + return Status.SUCCEEDED; + } else if (Status.FAILED.equals(stringStatus)) { + return Status.FAILED; + } else if (Status.NOT_REQUIRED.equals(stringStatus)) { + return Status.NOT_REQUIRED; } return null; diff --git a/stripe/src/main/java/com/stripe/android/model/Token.java b/stripe/src/main/java/com/stripe/android/model/Token.java index 1b53df224d4..54bade74633 100644 --- a/stripe/src/main/java/com/stripe/android/model/Token.java +++ b/stripe/src/main/java/com/stripe/android/model/Token.java @@ -22,18 +22,20 @@ public final class Token implements StripePaymentSource { @Retention(RetentionPolicy.SOURCE) - @StringDef({TYPE_CARD, TYPE_BANK_ACCOUNT, TYPE_PII, TYPE_ACCOUNT, TYPE_CVC_UPDATE}) - public @interface TokenType {} - public static final String TYPE_CARD = "card"; - public static final String TYPE_BANK_ACCOUNT = "bank_account"; - public static final String TYPE_PII = "pii"; - public static final String TYPE_ACCOUNT = "account"; - public static final String TYPE_CVC_UPDATE = "cvc_update"; + @StringDef({TokenType.CARD, TokenType.BANK_ACCOUNT, TokenType.PII, + TokenType.ACCOUNT, TokenType.CVC_UPDATE}) + public @interface TokenType { + String CARD = "card"; + String BANK_ACCOUNT = "bank_account"; + String PII = "pii"; + String ACCOUNT = "account"; + String CVC_UPDATE = "cvc_update"; + } // The key for these object fields is identical to their retrieved values // from the Type field. - private static final String FIELD_BANK_ACCOUNT = Token.TYPE_BANK_ACCOUNT; - private static final String FIELD_CARD = Token.TYPE_CARD; + private static final String FIELD_BANK_ACCOUNT = TokenType.BANK_ACCOUNT; + private static final String FIELD_CARD = TokenType.CARD; private static final String FIELD_CREATED = "created"; private static final String FIELD_ID = "id"; private static final String FIELD_LIVEMODE = "livemode"; @@ -60,7 +62,7 @@ public Token( @Nullable Boolean used, @Nullable Card card) { mId = id; - mType = TYPE_CARD; + mType = TokenType.CARD; mCreated = created; mLivemode = livemode; mCard = card; @@ -79,7 +81,7 @@ public Token( @Nullable Boolean used, @NonNull BankAccount bankAccount) { mId = id; - mType = TYPE_BANK_ACCOUNT; + mType = TokenType.BANK_ACCOUNT; mCreated = created; mLivemode = livemode; mCard = null; @@ -216,22 +218,22 @@ public static Token fromJson(@Nullable JSONObject jsonObject) { final Date date = new Date(createdTimeStamp * 1000); final Token token; - if (Token.TYPE_BANK_ACCOUNT.equals(tokenType)) { + if (TokenType.BANK_ACCOUNT.equals(tokenType)) { final JSONObject bankAccountObject = jsonObject.optJSONObject(FIELD_BANK_ACCOUNT); if (bankAccountObject == null) { return null; } token = new Token(tokenId, liveMode, date, used, BankAccount.fromJson(bankAccountObject)); - } else if (Token.TYPE_CARD.equals(tokenType)) { + } else if (TokenType.CARD.equals(tokenType)) { final JSONObject cardObject = jsonObject.optJSONObject(FIELD_CARD); if (cardObject == null) { return null; } token = new Token(tokenId, liveMode, date, used, Card.fromJson(cardObject)); - } else if (Token.TYPE_PII.equals(tokenType) || - Token.TYPE_ACCOUNT.equals(tokenType) || - Token.TYPE_CVC_UPDATE.equals(tokenType)) { + } else if (TokenType.PII.equals(tokenType) || + TokenType.ACCOUNT.equals(tokenType) || + TokenType.CVC_UPDATE.equals(tokenType)) { token = new Token(tokenId, tokenType, liveMode, date, used); } else { token = null; @@ -253,16 +255,16 @@ private static String asTokenType(@Nullable String possibleTokenType) { return null; } - if (Token.TYPE_CARD.equals(possibleTokenType)) { - return Token.TYPE_CARD; - } else if (Token.TYPE_BANK_ACCOUNT.equals(possibleTokenType)) { - return Token.TYPE_BANK_ACCOUNT; - } else if (Token.TYPE_PII.equals(possibleTokenType)) { - return Token.TYPE_PII; - } else if (Token.TYPE_ACCOUNT.equals(possibleTokenType)) { - return Token.TYPE_ACCOUNT; - } else if (Token.TYPE_CVC_UPDATE.equals(possibleTokenType)) { - return Token.TYPE_CVC_UPDATE; + if (TokenType.CARD.equals(possibleTokenType)) { + return TokenType.CARD; + } else if (TokenType.BANK_ACCOUNT.equals(possibleTokenType)) { + return TokenType.BANK_ACCOUNT; + } else if (TokenType.PII.equals(possibleTokenType)) { + return TokenType.PII; + } else if (TokenType.ACCOUNT.equals(possibleTokenType)) { + return TokenType.ACCOUNT; + } else if (TokenType.CVC_UPDATE.equals(possibleTokenType)) { + return TokenType.CVC_UPDATE; } return null; diff --git a/stripe/src/main/java/com/stripe/android/view/CardInputWidget.java b/stripe/src/main/java/com/stripe/android/view/CardInputWidget.java index df8ba87de16..3f4ab1bc668 100644 --- a/stripe/src/main/java/com/stripe/android/view/CardInputWidget.java +++ b/stripe/src/main/java/com/stripe/android/view/CardInputWidget.java @@ -632,7 +632,7 @@ public void onCardNumberComplete() { new CardNumberEditText.CardBrandChangeListener() { @Override public void onCardBrandChanged(@NonNull @Card.CardBrand String brand) { - mIsAmEx = Card.AMERICAN_EXPRESS.equals(brand); + mIsAmEx = Card.CardBrand.AMERICAN_EXPRESS.equals(brand); updateIcon(brand); updateCvc(brand); } @@ -826,7 +826,7 @@ public void onWindowFocusChanged(boolean hasWindowFocus) { * Determines whether or not the icon should show the card brand instead of the * CVC helper icon. * - * @param brand the {@link CardBrand} in question, used for determining max length + * @param brand the {@link Card.CardBrand} in question, used for determining max length * @param cvcHasFocus {@code true} if the CVC entry field has focus, {@code false} otherwise * @param cvcText the current content of {@link #mCvcNumberEditText} * @return {@code true} if we should show the brand of the card, or {@code false} if we @@ -872,8 +872,8 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { } @NonNull - private String getHiddenTextForBrand(@NonNull @Card.CardBrand String brand) { - if (Card.AMERICAN_EXPRESS.equals(brand)) { + private String getHiddenTextForBrand(@NonNull @CardBrand String brand) { + if (Card.CardBrand.AMERICAN_EXPRESS.equals(brand)) { return HIDDEN_TEXT_AMEX; } else { return HIDDEN_TEXT_COMMON; @@ -882,7 +882,7 @@ private String getHiddenTextForBrand(@NonNull @Card.CardBrand String brand) { @NonNull private String getCvcPlaceHolderForBrand(@NonNull @Card.CardBrand String brand) { - if (Card.AMERICAN_EXPRESS.equals(brand)) { + if (Card.CardBrand.AMERICAN_EXPRESS.equals(brand)) { return CVC_PLACEHOLDER_AMEX; } else { return CVC_PLACEHOLDER_COMMON; @@ -892,10 +892,10 @@ private String getCvcPlaceHolderForBrand(@NonNull @Card.CardBrand String brand) @NonNull private String getPeekCardTextForBrand(@NonNull @Card.CardBrand String brand) { switch (brand) { - case Card.AMERICAN_EXPRESS: { + case Card.CardBrand.AMERICAN_EXPRESS: { return PEEK_TEXT_AMEX; } - case Card.DINERS_CLUB: { + case Card.CardBrand.DINERS_CLUB: { return PEEK_TEXT_DINERS; } default: { @@ -905,7 +905,7 @@ private String getPeekCardTextForBrand(@NonNull @Card.CardBrand String brand) { } private void applyTint(boolean isCvc) { - if (isCvc || Card.UNKNOWN.equals(mCardNumberEditText.getCardBrand())) { + if (isCvc || Card.CardBrand.UNKNOWN.equals(mCardNumberEditText.getCardBrand())) { Drawable icon = mCardIconImageView.getDrawable(); Drawable compatIcon = DrawableCompat.wrap(icon); DrawableCompat.setTint(compatIcon.mutate(), mTintColorInt); @@ -914,7 +914,7 @@ private void applyTint(boolean isCvc) { } private void updateCvc(@NonNull @Card.CardBrand String brand) { - if (Card.AMERICAN_EXPRESS.equals(brand)) { + if (Card.CardBrand.AMERICAN_EXPRESS.equals(brand)) { mCvcNumberEditText.setFilters( new InputFilter[] { new InputFilter.LengthFilter(Card.CVC_LENGTH_AMERICAN_EXPRESS)}); @@ -927,7 +927,7 @@ private void updateCvc(@NonNull @Card.CardBrand String brand) { } private void updateIcon(@NonNull @Card.CardBrand String brand) { - if (Card.UNKNOWN.equals(brand)) { + if (Card.CardBrand.UNKNOWN.equals(brand)) { Drawable icon = getResources().getDrawable(R.drawable.ic_unknown); mCardIconImageView.setImageDrawable(icon); applyTint(false); @@ -937,13 +937,13 @@ private void updateIcon(@NonNull @Card.CardBrand String brand) { } private void updateIconCvc( - @NonNull @Card.CardBrand String brand, + @NonNull @CardBrand String brand, boolean hasFocus, @Nullable String cvcText) { if (shouldIconShowBrand(brand, hasFocus, cvcText)) { updateIcon(brand); } else { - updateIconForCvcEntry(Card.AMERICAN_EXPRESS.equals(brand)); + updateIconForCvcEntry(Card.CardBrand.AMERICAN_EXPRESS.equals(brand)); } } diff --git a/stripe/src/main/java/com/stripe/android/view/CardMultilineWidget.java b/stripe/src/main/java/com/stripe/android/view/CardMultilineWidget.java index 17f359c6d91..7b31100f05b 100644 --- a/stripe/src/main/java/com/stripe/android/view/CardMultilineWidget.java +++ b/stripe/src/main/java/com/stripe/android/view/CardMultilineWidget.java @@ -64,7 +64,8 @@ public class CardMultilineWidget extends LinearLayout { private boolean mHasAdjustedDrawable; @Nullable private String mCustomCvcLabel; - private @Card.CardBrand String mCardBrand; + private @Card.CardBrand + String mCardBrand; private @ColorInt int mTintColorInt; public CardMultilineWidget(@NonNull Context context) { @@ -103,7 +104,7 @@ public void clear() { mExpiryDateEditText.setShouldShowError(false); mCvcEditText.setShouldShowError(false); mPostalCodeEditText.setShouldShowError(false); - updateBrand(Card.UNKNOWN); + updateBrand(Card.CardBrand.UNKNOWN); } /** @@ -337,7 +338,7 @@ static boolean isPostalCodeMaximalLength(boolean isZip, @Nullable String text) { private boolean isCvcLengthValid() { int cvcLength = mCvcEditText.getText().toString().trim().length(); - if (TextUtils.equals(Card.AMERICAN_EXPRESS, mCardBrand) + if (TextUtils.equals(Card.CardBrand.AMERICAN_EXPRESS, mCardBrand) && cvcLength == Card.CVC_LENGTH_AMERICAN_EXPRESS) { return true; } @@ -368,7 +369,7 @@ private void flipToCvcIconIfNotFinished() { return; } - @DrawableRes int resourceId = Card.AMERICAN_EXPRESS.equals(mCardBrand) + @DrawableRes int resourceId = Card.CardBrand.AMERICAN_EXPRESS.equals(mCardBrand) ? R.drawable.ic_cvc_amex : R.drawable.ic_cvc; @@ -377,7 +378,7 @@ private void flipToCvcIconIfNotFinished() { @StringRes private int getCvcHelperText() { - return Card.AMERICAN_EXPRESS.equals(mCardBrand) + return Card.CardBrand.AMERICAN_EXPRESS.equals(mCardBrand) ? R.string.cvc_multiline_helper_amex : R.string.cvc_multiline_helper; } @@ -409,7 +410,7 @@ private void initView(@Nullable AttributeSet attrs, boolean shouldShowPostalCode mPostalCodeEditText.setAutofillHints(View.AUTOFILL_HINT_POSTAL_CODE); } - mCardBrand = Card.UNKNOWN; + mCardBrand = Card.CardBrand.UNKNOWN; // This sets the value of mShouldShowPostalCode checkAttributeSet(attrs); @@ -498,7 +499,7 @@ public void onTextChanged(String text) { }); mCardNumberEditText.updateLengthFilter(); - updateBrand(Card.UNKNOWN); + updateBrand(Card.CardBrand.UNKNOWN); setEnabled(true); } @@ -612,11 +613,11 @@ private void initTextInputLayoutErrorHandlers( private void updateBrand(@NonNull @Card.CardBrand String brand) { mCardBrand = brand; updateCvc(); - updateDrawable(Card.getBrandIcon(brand), Card.UNKNOWN.equals(brand)); + updateDrawable(Card.getBrandIcon(brand), Card.CardBrand.UNKNOWN.equals(brand)); } private void updateCvc() { - final int maxLength = Card.AMERICAN_EXPRESS.equals(mCardBrand) ? + final int maxLength = Card.CardBrand.AMERICAN_EXPRESS.equals(mCardBrand) ? Card.CVC_LENGTH_AMERICAN_EXPRESS : Card.CVC_LENGTH_COMMON; mCvcEditText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(maxLength)}); mCvcTextInputLayout.setHint(getCvcLabel()); @@ -628,7 +629,7 @@ private String getCvcLabel() { return mCustomCvcLabel; } - return getResources().getString(Card.AMERICAN_EXPRESS.equals(mCardBrand) ? + return getResources().getString(Card.CardBrand.AMERICAN_EXPRESS.equals(mCardBrand) ? R.string.cvc_amex_hint : R.string.cvc_number_hint); } diff --git a/stripe/src/main/java/com/stripe/android/view/CardNumberEditText.java b/stripe/src/main/java/com/stripe/android/view/CardNumberEditText.java index 1415a2b27d1..e981f2afc47 100644 --- a/stripe/src/main/java/com/stripe/android/view/CardNumberEditText.java +++ b/stripe/src/main/java/com/stripe/android/view/CardNumberEditText.java @@ -38,7 +38,8 @@ public class CardNumberEditText extends StripeEditText { private static final Set SPACE_SET_AMEX = new HashSet<>(Arrays.asList(SPACES_ARRAY_AMEX)); - @VisibleForTesting @Card.CardBrand String mCardBrand = Card.UNKNOWN; + @VisibleForTesting @Card.CardBrand + String mCardBrand = Card.CardBrand.UNKNOWN; private CardBrandChangeListener mCardBrandChangeListener; private CardNumberCompleteListener mCardNumberCompleteListener; private int mLengthMax = 19; @@ -133,7 +134,7 @@ int updateSelectionIndex( int editActionStart, int editActionAddition) { int newPosition, gapsJumped = 0; - Set gapSet = Card.AMERICAN_EXPRESS.equals(mCardBrand) + Set gapSet = Card.CardBrand.AMERICAN_EXPRESS.equals(mCardBrand) ? SPACE_SET_AMEX : SPACE_SET_COMMON; boolean skipBack = false; @@ -260,7 +261,8 @@ private void updateCardBrandFromNumber(String partialNumber) { } private static int getLengthForBrand(@Card.CardBrand String cardBrand) { - if (Card.AMERICAN_EXPRESS.equals(cardBrand) || Card.DINERS_CLUB.equals(cardBrand)) { + if (Card.CardBrand.AMERICAN_EXPRESS.equals(cardBrand) || + Card.CardBrand.DINERS_CLUB.equals(cardBrand)) { return MAX_LENGTH_AMEX_DINERS; } else { return MAX_LENGTH_COMMON; diff --git a/stripe/src/main/java/com/stripe/android/view/ShippingInfoWidget.java b/stripe/src/main/java/com/stripe/android/view/ShippingInfoWidget.java index 9791a8b7c6f..fa4a15131ce 100644 --- a/stripe/src/main/java/com/stripe/android/view/ShippingInfoWidget.java +++ b/stripe/src/main/java/com/stripe/android/view/ShippingInfoWidget.java @@ -31,19 +31,24 @@ public class ShippingInfoWidget extends LinearLayout { * Some fields cannot be hidden. */ @Retention(RetentionPolicy.SOURCE) - @StringDef({ADDRESS_LINE_ONE_FIELD, ADDRESS_LINE_TWO_FIELD, CITY_FIELD, POSTAL_CODE_FIELD, - STATE_FIELD, PHONE_FIELD}) + @StringDef({ + CustomizableShippingField.ADDRESS_LINE_ONE_FIELD, + CustomizableShippingField.ADDRESS_LINE_TWO_FIELD, + CustomizableShippingField.CITY_FIELD, + CustomizableShippingField.POSTAL_CODE_FIELD, + CustomizableShippingField.STATE_FIELD, + CustomizableShippingField.PHONE_FIELD + }) public @interface CustomizableShippingField { + String ADDRESS_LINE_ONE_FIELD = "address_line_one"; + // address line two is optional by default + String ADDRESS_LINE_TWO_FIELD = "address_line_two"; + String CITY_FIELD = "city"; + String POSTAL_CODE_FIELD = "postal_code"; + String STATE_FIELD = "state"; + String PHONE_FIELD = "phone"; } - public static final String ADDRESS_LINE_ONE_FIELD = "address_line_one"; - // address line two is optional by default - public static final String ADDRESS_LINE_TWO_FIELD = "address_line_two"; - public static final String CITY_FIELD = "city"; - public static final String POSTAL_CODE_FIELD = "postal_code"; - public static final String STATE_FIELD = "state"; - public static final String PHONE_FIELD = "phone"; - private List mOptionalShippingInfoFields = new ArrayList<>(); private List mHiddenShippingInfoFields = new ArrayList<>(); @@ -181,8 +186,10 @@ public boolean validateAllFields() { final String countrySelected = mCountryAutoCompleteTextView.getSelectedCountryCode(); if (mPostalCodeEditText.getText().toString().isEmpty() && - (mOptionalShippingInfoFields.contains(POSTAL_CODE_FIELD) || - mHiddenShippingInfoFields.contains(POSTAL_CODE_FIELD))) { + (mOptionalShippingInfoFields + .contains(CustomizableShippingField.POSTAL_CODE_FIELD) || + mHiddenShippingInfoFields + .contains(CustomizableShippingField.POSTAL_CODE_FIELD))) { postalCodeValid = true; } else if (countrySelected.equals(Locale.US.getCountry())) { postalCodeValid = CountryUtils.isUSZipCodeValid(mPostalCodeEditText.getText() @@ -201,27 +208,30 @@ public boolean validateAllFields() { mPostalCodeEditText.setShouldShowError(!postalCodeValid); final boolean requiredAddressLine1Empty = mAddressEditText.getText().toString().isEmpty() && - !mOptionalShippingInfoFields.contains(ADDRESS_LINE_ONE_FIELD) && - !mHiddenShippingInfoFields.contains(ADDRESS_LINE_ONE_FIELD); + !mOptionalShippingInfoFields + .contains(CustomizableShippingField.ADDRESS_LINE_ONE_FIELD) && + !mHiddenShippingInfoFields + .contains(CustomizableShippingField.ADDRESS_LINE_ONE_FIELD); mAddressEditText.setShouldShowError(requiredAddressLine1Empty); final boolean requiredCityEmpty = mCityEditText.getText().toString().isEmpty() && - !mOptionalShippingInfoFields.contains(CITY_FIELD) && !mHiddenShippingInfoFields - .contains(CITY_FIELD); + !mOptionalShippingInfoFields.contains(CustomizableShippingField.CITY_FIELD) && + !mHiddenShippingInfoFields.contains(CustomizableShippingField.CITY_FIELD); mCityEditText.setShouldShowError(requiredCityEmpty); final boolean requiredNameEmpty = mNameEditText.getText().toString().isEmpty(); mNameEditText.setShouldShowError(requiredNameEmpty); final boolean requiredStateEmpty = mStateEditText.getText().toString().isEmpty() && - !mOptionalShippingInfoFields.contains(STATE_FIELD) && !mHiddenShippingInfoFields - .contains(STATE_FIELD); + !mOptionalShippingInfoFields.contains(CustomizableShippingField.STATE_FIELD) && + !mHiddenShippingInfoFields.contains(CustomizableShippingField.STATE_FIELD); mStateEditText.setShouldShowError(requiredStateEmpty); final boolean requiredPhoneNumberEmpty = mPhoneNumberEditText.getText().toString().isEmpty() && - !mOptionalShippingInfoFields.contains(PHONE_FIELD) && - !mHiddenShippingInfoFields.contains(PHONE_FIELD); + !mOptionalShippingInfoFields + .contains(CustomizableShippingField.PHONE_FIELD) && + !mHiddenShippingInfoFields.contains(CustomizableShippingField.PHONE_FIELD); mPhoneNumberEditText.setShouldShowError(requiredPhoneNumberEmpty); return postalCodeValid && !requiredAddressLine1Empty && !requiredCityEmpty && @@ -259,13 +269,13 @@ private void setupErrorHandling() { private void renderLabels() { mNameTextInputLayout.setHint(getResources().getString(R.string.address_label_name)); - if (mOptionalShippingInfoFields.contains(CITY_FIELD)) { + if (mOptionalShippingInfoFields.contains(CustomizableShippingField.CITY_FIELD)) { mCityTextInputLayout.setHint(getResources().getString(R.string .address_label_city_optional)); } else { mCityTextInputLayout.setHint(getResources().getString(R.string.address_label_city)); } - if (mOptionalShippingInfoFields.contains(PHONE_FIELD)) { + if (mOptionalShippingInfoFields.contains(CustomizableShippingField.PHONE_FIELD)) { mPhoneNumberTextInputLayout.setHint(getResources().getString(R.string .address_label_phone_number_optional)); } else { @@ -276,22 +286,22 @@ private void renderLabels() { } private void hideHiddenFields() { - if (mHiddenShippingInfoFields.contains(ADDRESS_LINE_ONE_FIELD)) { + if (mHiddenShippingInfoFields.contains(CustomizableShippingField.ADDRESS_LINE_ONE_FIELD)) { mAddressLine1TextInputLayout.setVisibility(GONE); } - if (mHiddenShippingInfoFields.contains(ADDRESS_LINE_TWO_FIELD)) { + if (mHiddenShippingInfoFields.contains(CustomizableShippingField.ADDRESS_LINE_TWO_FIELD)) { mAddressLine2TextInputLayout.setVisibility(GONE); } - if (mHiddenShippingInfoFields.contains(STATE_FIELD)) { + if (mHiddenShippingInfoFields.contains(CustomizableShippingField.STATE_FIELD)) { mStateTextInputLayout.setVisibility(GONE); } - if (mHiddenShippingInfoFields.contains(CITY_FIELD)) { + if (mHiddenShippingInfoFields.contains(CustomizableShippingField.CITY_FIELD)) { mCityTextInputLayout.setVisibility(GONE); } - if (mHiddenShippingInfoFields.contains(POSTAL_CODE_FIELD)) { + if (mHiddenShippingInfoFields.contains(CustomizableShippingField.POSTAL_CODE_FIELD)) { mPostalCodeTextInputLayout.setVisibility(GONE); } - if (mHiddenShippingInfoFields.contains(PHONE_FIELD)) { + if (mHiddenShippingInfoFields.contains(CustomizableShippingField.PHONE_FIELD)) { mPhoneNumberTextInputLayout.setVisibility(GONE); } } @@ -307,8 +317,8 @@ private void renderCountrySpecificLabels(String countrySelected) { renderInternationalForm(); } - if (CountryUtils.doesCountryUsePostalCode(countrySelected) && !mHiddenShippingInfoFields - .contains(POSTAL_CODE_FIELD)) { + if (CountryUtils.doesCountryUsePostalCode(countrySelected) && + !mHiddenShippingInfoFields.contains(CustomizableShippingField.POSTAL_CODE_FIELD)) { mPostalCodeTextInputLayout.setVisibility(VISIBLE); } else { mPostalCodeTextInputLayout.setVisibility(GONE); @@ -316,7 +326,8 @@ private void renderCountrySpecificLabels(String countrySelected) { } private void renderUSForm() { - if (mOptionalShippingInfoFields.contains(ADDRESS_LINE_ONE_FIELD)) { + if (mOptionalShippingInfoFields + .contains(CustomizableShippingField.ADDRESS_LINE_ONE_FIELD)) { mAddressLine1TextInputLayout.setHint(getResources().getString(R.string .address_label_address_optional)); } else { @@ -325,14 +336,14 @@ private void renderUSForm() { } mAddressLine2TextInputLayout.setHint(getResources().getString(R.string .address_label_apt_optional)); - if (mOptionalShippingInfoFields.contains(POSTAL_CODE_FIELD)) { + if (mOptionalShippingInfoFields.contains(CustomizableShippingField.POSTAL_CODE_FIELD)) { mPostalCodeTextInputLayout.setHint(getResources().getString(R.string .address_label_zip_code_optional)); } else { mPostalCodeTextInputLayout.setHint(getResources().getString(R.string .address_label_zip_code)); } - if (mOptionalShippingInfoFields.contains(STATE_FIELD)) { + if (mOptionalShippingInfoFields.contains(CustomizableShippingField.STATE_FIELD)) { mStateTextInputLayout.setHint(getResources().getString(R.string .address_label_state_optional)); } else { @@ -343,7 +354,8 @@ private void renderUSForm() { } private void renderGreatBritainForm() { - if (mOptionalShippingInfoFields.contains(ADDRESS_LINE_ONE_FIELD)) { + if (mOptionalShippingInfoFields + .contains(CustomizableShippingField.ADDRESS_LINE_ONE_FIELD)) { mAddressLine1TextInputLayout.setHint(getResources().getString(R.string .address_label_address_line1_optional)); } else { @@ -352,14 +364,14 @@ private void renderGreatBritainForm() { } mAddressLine2TextInputLayout.setHint(getResources().getString(R.string .address_label_address_line2_optional)); - if (mOptionalShippingInfoFields.contains(POSTAL_CODE_FIELD)) { + if (mOptionalShippingInfoFields.contains(CustomizableShippingField.POSTAL_CODE_FIELD)) { mPostalCodeTextInputLayout.setHint(getResources().getString(R.string .address_label_postcode_optional)); } else { mPostalCodeTextInputLayout.setHint(getResources().getString(R.string .address_label_postcode)); } - if (mOptionalShippingInfoFields.contains(STATE_FIELD)) { + if (mOptionalShippingInfoFields.contains(CustomizableShippingField.STATE_FIELD)) { mStateTextInputLayout.setHint(getResources().getString(R.string .address_label_county_optional)); } else { @@ -371,7 +383,8 @@ private void renderGreatBritainForm() { } private void renderCanadianForm() { - if (mOptionalShippingInfoFields.contains(ADDRESS_LINE_ONE_FIELD)) { + if (mOptionalShippingInfoFields + .contains(CustomizableShippingField.ADDRESS_LINE_ONE_FIELD)) { mAddressLine1TextInputLayout.setHint(getResources().getString(R.string .address_label_address_optional)); } else { @@ -380,14 +393,14 @@ private void renderCanadianForm() { } mAddressLine2TextInputLayout.setHint(getResources().getString(R.string .address_label_apt_optional)); - if (mOptionalShippingInfoFields.contains(POSTAL_CODE_FIELD)) { + if (mOptionalShippingInfoFields.contains(CustomizableShippingField.POSTAL_CODE_FIELD)) { mPostalCodeTextInputLayout.setHint(getResources().getString(R.string .address_label_postal_code_optional)); } else { mPostalCodeTextInputLayout.setHint(getResources().getString(R.string .address_label_postal_code)); } - if (mOptionalShippingInfoFields.contains(STATE_FIELD)) { + if (mOptionalShippingInfoFields.contains(CustomizableShippingField.STATE_FIELD)) { mStateTextInputLayout.setHint(getResources().getString(R.string .address_label_province_optional)); } else { @@ -402,7 +415,8 @@ private void renderCanadianForm() { } private void renderInternationalForm() { - if (mOptionalShippingInfoFields.contains(ADDRESS_LINE_ONE_FIELD)) { + if (mOptionalShippingInfoFields + .contains(CustomizableShippingField.ADDRESS_LINE_ONE_FIELD)) { mAddressLine1TextInputLayout.setHint(getResources().getString(R.string .address_label_address_line1_optional)); } else { @@ -411,14 +425,14 @@ private void renderInternationalForm() { } mAddressLine2TextInputLayout.setHint(getResources().getString(R.string .address_label_address_line2_optional)); - if (mOptionalShippingInfoFields.contains(POSTAL_CODE_FIELD)) { + if (mOptionalShippingInfoFields.contains(CustomizableShippingField.POSTAL_CODE_FIELD)) { mPostalCodeTextInputLayout.setHint(getResources().getString(R.string .address_label_zip_postal_code_optional)); } else { mPostalCodeTextInputLayout.setHint(getResources().getString(R.string .address_label_zip_postal_code)); } - if (mOptionalShippingInfoFields.contains(STATE_FIELD)) { + if (mOptionalShippingInfoFields.contains(CustomizableShippingField.STATE_FIELD)) { mStateTextInputLayout.setHint(getResources().getString(R.string .address_label_region_generic_optional)); } else { diff --git a/stripe/src/main/java/com/stripe/android/view/ViewUtils.java b/stripe/src/main/java/com/stripe/android/view/ViewUtils.java index 19e053363d1..e0e4e81c56e 100644 --- a/stripe/src/main/java/com/stripe/android/view/ViewUtils.java +++ b/stripe/src/main/java/com/stripe/android/view/ViewUtils.java @@ -139,7 +139,7 @@ static boolean isCvcMaximalLength(@NonNull @Card.CardBrand String cardBrand, return false; } - if (Card.AMERICAN_EXPRESS.equals(cardBrand)) { + if (Card.CardBrand.AMERICAN_EXPRESS.equals(cardBrand)) { return cvcText.trim().length() == CVC_LENGTH_AMERICAN_EXPRESS; } else { return cvcText.trim().length() == CVC_LENGTH_COMMON; @@ -163,7 +163,7 @@ static String[] separateCardNumberGroups(@NonNull String spacelessCardNumber, spacelessCardNumber = spacelessCardNumber.substring(0, 16); } String[] numberGroups; - if (brand.equals(Card.AMERICAN_EXPRESS)) { + if (brand.equals(Card.CardBrand.AMERICAN_EXPRESS)) { numberGroups = new String[3]; int length = spacelessCardNumber.length(); diff --git a/stripe/src/test/java/com/stripe/android/CardUtilsTest.java b/stripe/src/test/java/com/stripe/android/CardUtilsTest.java index 13c71e663df..147de4cd1dc 100644 --- a/stripe/src/test/java/com/stripe/android/CardUtilsTest.java +++ b/stripe/src/test/java/com/stripe/android/CardUtilsTest.java @@ -15,62 +15,62 @@ public class CardUtilsTest { @Test public void getPossibleCardType_withEmptyCard_returnsUnknown() { - assertEquals(Card.UNKNOWN, CardUtils.getPossibleCardType(" ")); + assertEquals(Card.CardBrand.UNKNOWN, CardUtils.getPossibleCardType(" ")); } @Test public void getPossibleCardType_withNullCardNumber_returnsUnknown() { - assertEquals(Card.UNKNOWN, CardUtils.getPossibleCardType(null)); + assertEquals(Card.CardBrand.UNKNOWN, CardUtils.getPossibleCardType(null)); } @Test public void getPossibleCardType_withVisaPrefix_returnsVisa() { - assertEquals(Card.VISA, CardUtils.getPossibleCardType("4899 99")); - assertEquals(Card.VISA, CardUtils.getPossibleCardType("4")); + assertEquals(Card.CardBrand.VISA, CardUtils.getPossibleCardType("4899 99")); + assertEquals(Card.CardBrand.VISA, CardUtils.getPossibleCardType("4")); } @Test public void getPossibleCardType_withAmexPrefix_returnsAmex() { - assertEquals(Card.AMERICAN_EXPRESS, CardUtils.getPossibleCardType("345")); - assertEquals(Card.AMERICAN_EXPRESS, CardUtils.getPossibleCardType("37999999999")); + assertEquals(Card.CardBrand.AMERICAN_EXPRESS, CardUtils.getPossibleCardType("345")); + assertEquals(Card.CardBrand.AMERICAN_EXPRESS, CardUtils.getPossibleCardType("37999999999")); } @Test public void getPossibleCardType_withJCBPrefix_returnsJCB() { - assertEquals(Card.JCB, CardUtils.getPossibleCardType("3535 3535")); + assertEquals(Card.CardBrand.JCB, CardUtils.getPossibleCardType("3535 3535")); } @Test public void getPossibleCardType_withMasterCardPrefix_returnsMasterCard() { - assertEquals(Card.MASTERCARD, CardUtils.getPossibleCardType("2222 452")); - assertEquals(Card.MASTERCARD, CardUtils.getPossibleCardType("5050")); + assertEquals(Card.CardBrand.MASTERCARD, CardUtils.getPossibleCardType("2222 452")); + assertEquals(Card.CardBrand.MASTERCARD, CardUtils.getPossibleCardType("5050")); } @Test public void getPossibleCardType_withDinersClubPrefix_returnsDinersClub() { - assertEquals(Card.DINERS_CLUB, CardUtils.getPossibleCardType("303922 2234")); - assertEquals(Card.DINERS_CLUB, CardUtils.getPossibleCardType("36778 9098")); + assertEquals(Card.CardBrand.DINERS_CLUB, CardUtils.getPossibleCardType("303922 2234")); + assertEquals(Card.CardBrand.DINERS_CLUB, CardUtils.getPossibleCardType("36778 9098")); } @Test public void getPossibleCardType_withDiscoverPrefix_returnsDiscover() { - assertEquals(Card.DISCOVER, CardUtils.getPossibleCardType("60355")); - assertEquals(Card.DISCOVER, CardUtils.getPossibleCardType("6433 8 90923")); + assertEquals(Card.CardBrand.DISCOVER, CardUtils.getPossibleCardType("60355")); + assertEquals(Card.CardBrand.DISCOVER, CardUtils.getPossibleCardType("6433 8 90923")); // This one has too many numbers on purpose. Checking for length is not part of the // function under test. - assertEquals(Card.DISCOVER, CardUtils.getPossibleCardType("6523452309209340293423")); + assertEquals(Card.CardBrand.DISCOVER, CardUtils.getPossibleCardType("6523452309209340293423")); } @Test public void getPossibleCardType_withUnionPayPrefix_returnsUnionPay() { - assertEquals(Card.UNIONPAY, CardUtils.getPossibleCardType("62")); + assertEquals(Card.CardBrand.UNIONPAY, CardUtils.getPossibleCardType("62")); } @Test public void getPossibleCardType_withNonsenseNumber_returnsUnknown() { - assertEquals(Card.UNKNOWN, CardUtils.getPossibleCardType("1234567890123456")); - assertEquals(Card.UNKNOWN, CardUtils.getPossibleCardType("9999 9999 9999 9999")); - assertEquals(Card.UNKNOWN, CardUtils.getPossibleCardType("3")); + assertEquals(Card.CardBrand.UNKNOWN, CardUtils.getPossibleCardType("1234567890123456")); + assertEquals(Card.CardBrand.UNKNOWN, CardUtils.getPossibleCardType("9999 9999 9999 9999")); + assertEquals(Card.CardBrand.UNKNOWN, CardUtils.getPossibleCardType("3")); } @Test @@ -148,7 +148,7 @@ public void isValidCardLengthWithBrand_whenBrandUnknown_alwaysReturnsFalse() { String validVisa = "4242424242424242"; // Adding this check to ensure the input number is correct assertTrue(CardUtils.isValidCardLength(validVisa)); - assertFalse(CardUtils.isValidCardLength(validVisa, Card.UNKNOWN)); + assertFalse(CardUtils.isValidCardLength(validVisa, Card.CardBrand.UNKNOWN)); } @Test diff --git a/stripe/src/test/java/com/stripe/android/CustomerSessionTest.java b/stripe/src/test/java/com/stripe/android/CustomerSessionTest.java index f996b0de96b..aee6086450c 100644 --- a/stripe/src/test/java/com/stripe/android/CustomerSessionTest.java +++ b/stripe/src/test/java/com/stripe/android/CustomerSessionTest.java @@ -494,7 +494,7 @@ public void addSourceToCustomer_withUnExpiredCustomer_returnsAddedSourceAndEmpti customerSession.addCustomerSource( "abc123", - Source.CARD, + Source.SourceType.CARD, mockListener); assertTrue(customerSession.getProductUsageTokens().isEmpty()); @@ -505,7 +505,7 @@ public void addSourceToCustomer_withUnExpiredCustomer_returnsAddedSourceAndEmpti eq(ApiKeyFixtures.FAKE_PUBLISHABLE_KEY), mListArgumentCaptor.capture(), eq("abc123"), - eq(Source.CARD), + eq(Source.SourceType.CARD), eq(firstKey.getSecret()) ); final List productUsage = mListArgumentCaptor.getValue(); @@ -551,7 +551,7 @@ public void addSourceToCustomer_whenApiThrowsError_tellsListenerBroadcastsAndEmp setupErrorProxy(); customerSession.addCustomerSource( "abc123", - Source.CARD, + Source.SourceType.CARD, mockListener); verify(mBroadcastReceiver).onReceive(any(Context.class), mIntentArgumentCaptor.capture()); @@ -699,7 +699,7 @@ public void setDefaultSourceForCustomer_withUnExpiredCustomer_returnsCustomerAnd customerSession.setCustomerDefaultSource( "abc123", - Source.CARD, + Source.SourceType.CARD, mockListener); assertTrue(customerSession.getProductUsageTokens().isEmpty()); @@ -710,7 +710,7 @@ public void setDefaultSourceForCustomer_withUnExpiredCustomer_returnsCustomerAnd eq(ApiKeyFixtures.FAKE_PUBLISHABLE_KEY), mListArgumentCaptor.capture(), eq("abc123"), - eq(Source.CARD), + eq(Source.SourceType.CARD), eq(firstKey.getSecret())); final List productUsage = mListArgumentCaptor.getValue(); @@ -752,7 +752,7 @@ public void setDefaultSourceForCustomer_whenApiThrows_tellsListenerBroadcastsAnd mock(CustomerSession.CustomerRetrievalListener.class); setupErrorProxy(); - customerSession.setCustomerDefaultSource("abc123", Source.CARD, + customerSession.setCustomerDefaultSource("abc123", Source.SourceType.CARD, mockListener); final ArgumentCaptor intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class); diff --git a/stripe/src/test/java/com/stripe/android/LoggingUtilsTest.java b/stripe/src/test/java/com/stripe/android/LoggingUtilsTest.java index 4974b9fa433..3b49f9e40da 100644 --- a/stripe/src/test/java/com/stripe/android/LoggingUtilsTest.java +++ b/stripe/src/test/java/com/stripe/android/LoggingUtilsTest.java @@ -15,6 +15,7 @@ import org.robolectric.RobolectricTestRunner; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -32,10 +33,8 @@ public class LoggingUtilsTest { private static final String API_KEY = "pk_abc123"; - private static final List EXPECTED_SINGLE_TOKEN_LIST = new ArrayList<>(); - static { - EXPECTED_SINGLE_TOKEN_LIST.add("CardInputView"); - } + private static final List EXPECTED_SINGLE_TOKEN_LIST = + Collections.singletonList("CardInputView"); @NonNull private final LoggingUtils mLoggingUtils = new LoggingUtils(ApplicationProvider.getApplicationContext()); @@ -46,16 +45,16 @@ public void getTokenCreationParams_withValidInput_createsCorrectMap() { tokensList.add("CardInputView"); // Correctness of these methods will be tested elsewhere. Assume validity for this test. final String expectedTokenName = - LoggingUtils.getEventParamName(LoggingUtils.EVENT_TOKEN_CREATION); + LoggingUtils.getEventParamName(LoggingUtils.EventName.TOKEN_CREATION); final Map params = mLoggingUtils.getTokenCreationParams( tokensList, API_KEY, - Token.TYPE_PII); + Token.TokenType.PII); // Size is SIZE-1 because tokens don't have a source_type field assertEquals(LoggingUtils.VALID_PARAM_FIELDS.size() - 1, params.size()); assertEquals(expectedTokenName, params.get(LoggingUtils.FIELD_EVENT)); - assertEquals(Token.TYPE_PII, params.get(LoggingUtils.FIELD_TOKEN_TYPE)); + assertEquals(Token.TokenType.PII, params.get(LoggingUtils.FIELD_TOKEN_TYPE)); } @Test @@ -64,16 +63,16 @@ public void getCvcUpdateTokenCreationParams_withValidInput_createsCorrectMap() { tokensList.add("CardInputView"); // Correctness of these methods will be tested elsewhere. Assume validity for this test. final String expectedTokenName = - LoggingUtils.getEventParamName(LoggingUtils.EVENT_TOKEN_CREATION); + LoggingUtils.getEventParamName(LoggingUtils.EventName.TOKEN_CREATION); final Map params = mLoggingUtils.getTokenCreationParams( tokensList, API_KEY, - Token.TYPE_CVC_UPDATE); + Token.TokenType.CVC_UPDATE); // Size is SIZE-1 because tokens don't have a source_type field assertEquals(LoggingUtils.VALID_PARAM_FIELDS.size() - 1, params.size()); assertEquals(expectedTokenName, params.get(LoggingUtils.FIELD_EVENT)); - assertEquals(Token.TYPE_CVC_UPDATE, params.get(LoggingUtils.FIELD_TOKEN_TYPE)); + assertEquals(Token.TokenType.CVC_UPDATE, params.get(LoggingUtils.FIELD_TOKEN_TYPE)); } @Test @@ -85,11 +84,11 @@ public void getSourceCreationParams_withValidInput_createsCorrectMap() { final Map loggingParams = mLoggingUtils.getSourceCreationParams( tokenList, API_KEY, - Source.SEPA_DEBIT); + Source.SourceType.SEPA_DEBIT); assertEquals(expectedSize, loggingParams.size()); - assertEquals(Source.SEPA_DEBIT, loggingParams.get(LoggingUtils.FIELD_SOURCE_TYPE)); + assertEquals(Source.SourceType.SEPA_DEBIT, loggingParams.get(LoggingUtils.FIELD_SOURCE_TYPE)); assertEquals(API_KEY, loggingParams.get(LoggingUtils.FIELD_PUBLISHABLE_KEY)); - assertEquals(LoggingUtils.getEventParamName(LoggingUtils.EVENT_SOURCE_CREATION), + assertEquals(LoggingUtils.getEventParamName(LoggingUtils.EventName.SOURCE_CREATION), loggingParams.get(LoggingUtils.FIELD_EVENT)); assertEquals(LoggingUtils.getAnalyticsUa(), loggingParams.get(LoggingUtils.FIELD_ANALYTICS_UA)); @@ -101,7 +100,7 @@ public void getPaymentMethodCreationParams() { .getPaymentMethodCreationParams(null, API_KEY); assertNotNull(loggingParams); assertEquals(API_KEY, loggingParams.get(LoggingUtils.FIELD_PUBLISHABLE_KEY)); - assertEquals(LoggingUtils.getEventParamName(LoggingUtils.EVENT_ADD_PAYMENT_METHOD), + assertEquals(LoggingUtils.getEventParamName(LoggingUtils.EventName.ADD_PAYMENT_METHOD), loggingParams.get(LoggingUtils.FIELD_EVENT)); assertEquals(LoggingUtils.getAnalyticsUa(), loggingParams.get(LoggingUtils.FIELD_ANALYTICS_UA)); @@ -118,7 +117,7 @@ public void getPaymentIntentConfirmationParams_withValidInput_createsCorrectMap( null); assertEquals(expectedSize, loggingParams.size()); assertEquals(API_KEY, loggingParams.get(LoggingUtils.FIELD_PUBLISHABLE_KEY)); - assertEquals(LoggingUtils.getEventParamName(LoggingUtils.EVENT_CONFIRM_PAYMENT_INTENT), + assertEquals(LoggingUtils.getEventParamName(LoggingUtils.EventName.CONFIRM_PAYMENT_INTENT), loggingParams.get(LoggingUtils.FIELD_EVENT)); assertEquals(LoggingUtils.getAnalyticsUa(), loggingParams.get(LoggingUtils.FIELD_ANALYTICS_UA)); @@ -134,7 +133,7 @@ public void getPaymentIntentRetrieveParams_withValidInput_createsCorrectMap() { API_KEY); assertEquals(expectedSize, loggingParams.size()); assertEquals(API_KEY, loggingParams.get(LoggingUtils.FIELD_PUBLISHABLE_KEY)); - assertEquals(LoggingUtils.getEventParamName(LoggingUtils.EVENT_RETRIEVE_PAYMENT_INTENT), + assertEquals(LoggingUtils.getEventParamName(LoggingUtils.EventName.RETRIEVE_PAYMENT_INTENT), loggingParams.get(LoggingUtils.FIELD_EVENT)); assertEquals(LoggingUtils.getAnalyticsUa(), loggingParams.get(LoggingUtils.FIELD_ANALYTICS_UA)); @@ -147,7 +146,7 @@ public void getEventLoggingParams_withProductUsage_createsAllFields() tokensList.add("CardInputView"); // Correctness of these methods will be tested elsewhere. Assume validity for this test. final String expectedTokenName = - LoggingUtils.getEventParamName(LoggingUtils.EVENT_TOKEN_CREATION); + LoggingUtils.getEventParamName(LoggingUtils.EventName.TOKEN_CREATION); final String expectedUaName = LoggingUtils.getAnalyticsUa(); final int versionCode = 20; @@ -163,12 +162,12 @@ public void getEventLoggingParams_withProductUsage_createsAllFields() .getEventLoggingParams( tokensList, null, - Token.TYPE_CARD, - API_KEY, LoggingUtils.EVENT_TOKEN_CREATION); + Token.TokenType.CARD, + API_KEY, LoggingUtils.EventName.TOKEN_CREATION); assertEquals(LoggingUtils.VALID_PARAM_FIELDS.size() - 1, params.size()); assertEquals(API_KEY, params.get(LoggingUtils.FIELD_PUBLISHABLE_KEY)); assertEquals(EXPECTED_SINGLE_TOKEN_LIST, params.get(LoggingUtils.FIELD_PRODUCT_USAGE)); - assertEquals(Token.TYPE_CARD, params.get(LoggingUtils.FIELD_TOKEN_TYPE)); + assertEquals(Token.TokenType.CARD, params.get(LoggingUtils.FIELD_TOKEN_TYPE)); assertEquals(Build.VERSION.SDK_INT, params.get(LoggingUtils.FIELD_OS_VERSION)); assertNotNull(params.get(LoggingUtils.FIELD_OS_RELEASE)); assertNotNull(params.get(LoggingUtils.FIELD_OS_NAME)); @@ -187,17 +186,17 @@ public void getEventLoggingParams_withProductUsage_createsAllFields() public void getEventLoggingParams_withoutProductUsage_createsOnlyNeededFields() { // Correctness of these methods will be tested elsewhere. Assume validity for this test. final String expectedTokenName = - LoggingUtils.getEventParamName(LoggingUtils.EVENT_SOURCE_CREATION); + LoggingUtils.getEventParamName(LoggingUtils.EventName.SOURCE_CREATION); final String expectedUaName = LoggingUtils.getAnalyticsUa(); final Map params = mLoggingUtils.getEventLoggingParams( null, null, - Token.TYPE_BANK_ACCOUNT, - API_KEY, LoggingUtils.EVENT_SOURCE_CREATION); + Token.TokenType.BANK_ACCOUNT, + API_KEY, LoggingUtils.EventName.SOURCE_CREATION); assertEquals(LoggingUtils.VALID_PARAM_FIELDS.size() - 2, params.size()); assertEquals(API_KEY, params.get(LoggingUtils.FIELD_PUBLISHABLE_KEY)); - assertEquals(Token.TYPE_BANK_ACCOUNT, params.get(LoggingUtils.FIELD_TOKEN_TYPE)); + assertEquals(Token.TokenType.BANK_ACCOUNT, params.get(LoggingUtils.FIELD_TOKEN_TYPE)); assertEquals(Build.VERSION.SDK_INT, params.get(LoggingUtils.FIELD_OS_VERSION)); assertNotNull(params.get(LoggingUtils.FIELD_OS_RELEASE)); @@ -241,7 +240,7 @@ public void addNameAndVersion_whenPackageInfoNotFound_addsUnknownValues() { public void getEventParamName_withTokenCreation_createsExpectedParameter() { final String expectedEventParam = "stripe_android.token_creation"; assertEquals(expectedEventParam, - LoggingUtils.getEventParamName(LoggingUtils.EVENT_TOKEN_CREATION)); + LoggingUtils.getEventParamName(LoggingUtils.EventName.TOKEN_CREATION)); } @Test diff --git a/stripe/src/test/java/com/stripe/android/StripeNetworkUtilsTest.java b/stripe/src/test/java/com/stripe/android/StripeNetworkUtilsTest.java index bc5ab01ad9d..cbf29368432 100644 --- a/stripe/src/test/java/com/stripe/android/StripeNetworkUtilsTest.java +++ b/stripe/src/test/java/com/stripe/android/StripeNetworkUtilsTest.java @@ -77,7 +77,7 @@ public void hashMapFromCard_mapsCorrectFields() { @Test public void hashMapFromBankAccount_mapsCorrectFields() { final BankAccount bankAccount = new BankAccount(BANK_ACCOUNT_NUMBER, - BANK_ACCOUNT_HOLDER_NAME, BankAccount.TYPE_INDIVIDUAL, null, "US", + BANK_ACCOUNT_HOLDER_NAME, BankAccount.BankAccountType.INDIVIDUAL, null, "US", "usd", null, null, BANK_ROUTING_NUMBER); final Map bankAccountMap = getBankAccountTokenParamData(bankAccount); assertNotNull(bankAccountMap); @@ -87,7 +87,7 @@ public void hashMapFromBankAccount_mapsCorrectFields() { assertEquals("US", bankAccountMap.get("country")); assertEquals("usd", bankAccountMap.get("currency")); assertEquals(BANK_ACCOUNT_HOLDER_NAME, bankAccountMap.get("account_holder_name")); - assertEquals(BankAccount.TYPE_INDIVIDUAL, bankAccountMap.get("account_holder_type")); + assertEquals(BankAccount.BankAccountType.INDIVIDUAL, bankAccountMap.get("account_holder_type")); } @Test diff --git a/stripe/src/test/java/com/stripe/android/StripeTest.java b/stripe/src/test/java/com/stripe/android/StripeTest.java index e5827602b2c..11290f82c3f 100644 --- a/stripe/src/test/java/com/stripe/android/StripeTest.java +++ b/stripe/src/test/java/com/stripe/android/StripeTest.java @@ -220,12 +220,12 @@ public void createCardTokenSynchronous_withValidData_returnsToken() Card returnedCard = token.getCard(); assertNotNull(returnedCard); assertNull(token.getBankAccount()); - assertEquals(Token.TYPE_CARD, token.getType()); + assertEquals(Token.TokenType.CARD, token.getType()); assertEquals(CARD.getLast4(), returnedCard.getLast4()); - assertEquals(Card.VISA, returnedCard.getBrand()); + assertEquals(Card.CardBrand.VISA, returnedCard.getBrand()); assertEquals(CARD.getExpYear(), returnedCard.getExpYear()); assertEquals(CARD.getExpMonth(), returnedCard.getExpMonth()); - assertEquals(Card.FUNDING_CREDIT, returnedCard.getFunding()); + assertEquals(Card.FundingType.CREDIT, returnedCard.getFunding()); } @Test @@ -241,12 +241,12 @@ public void createCardTokenSynchronous_withValidDataAndConnectAccount_returnsTok Card returnedCard = token.getCard(); assertNotNull(returnedCard); assertNull(token.getBankAccount()); - assertEquals(Token.TYPE_CARD, token.getType()); + assertEquals(Token.TokenType.CARD, token.getType()); assertEquals(CARD.getLast4(), returnedCard.getLast4()); - assertEquals(Card.VISA, returnedCard.getBrand()); + assertEquals(Card.CardBrand.VISA, returnedCard.getBrand()); assertEquals(CARD.getExpYear(), returnedCard.getExpYear()); assertEquals(CARD.getExpMonth(), returnedCard.getExpMonth()); - assertEquals(Card.FUNDING_CREDIT, returnedCard.getFunding()); + assertEquals(Card.FundingType.CREDIT, returnedCard.getFunding()); } @Test @@ -257,7 +257,7 @@ public void createToken_createSource_returnsSource() assertNotNull(token); final SourceParams sourceParams = SourceParams.createCustomParams(); - sourceParams.setType(Source.CARD); + sourceParams.setType(Source.SourceType.CARD); sourceParams.setToken(token.getId()); final Source source = stripe.createSourceSynchronous(sourceParams); @@ -282,7 +282,7 @@ public void createBankAccountToken() { createNonLoggingStripe() .createBankAccountToken(new BankAccount( "Jane Austen", - BankAccount.TYPE_INDIVIDUAL, + BankAccount.BankAccountType.INDIVIDUAL, "STRIPE TEST BANK", "US", "usd", @@ -355,7 +355,7 @@ public void createBankAccountTokenSynchronous_withValidBankAccount_returnsToken( Token token = stripe.createBankAccountTokenSynchronous(BANK_ACCOUNT); assertNotNull(token); - assertEquals(Token.TYPE_BANK_ACCOUNT, token.getType()); + assertEquals(Token.TokenType.BANK_ACCOUNT, token.getType()); assertNull(token.getCard()); BankAccount returnedBankAccount = token.getBankAccount(); @@ -382,13 +382,13 @@ public void createSourceSynchronous_withAlipayReusableParams_passesIntegrationTe assertNotNull(alipaySource); assertNotNull(alipaySource.getId()); assertNotNull(alipaySource.getClientSecret()); - assertEquals(Source.ALIPAY, alipaySource.getType()); + assertEquals(Source.SourceType.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.REUSABLE, alipaySource.getUsage()); + assertEquals(Source.Usage.REUSABLE, alipaySource.getUsage()); assertNotNull(alipaySource.getRedirect()); assertEquals("stripe://start", alipaySource.getRedirect().getReturnUrl()); } @@ -410,13 +410,13 @@ public void createSourceSynchronous_withAlipaySingleUseParams_passesIntegrationT assertNotNull(alipaySource.getClientSecret()); assertNotNull(alipaySource.getAmount()); assertEquals(1000L, alipaySource.getAmount().longValue()); - assertEquals(Source.ALIPAY, alipaySource.getType()); + assertEquals(Source.SourceType.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()); + assertEquals(Source.Usage.SINGLE_USE, alipaySource.getUsage()); assertNotNull(alipaySource.getRedirect()); assertEquals("stripe://start", alipaySource.getRedirect().getReturnUrl()); } @@ -442,7 +442,7 @@ public void createSourceSynchronous_withBancontactParams_passesIntegrationTest() assertNotNull(bancontactSource.getId()); assertNotNull(bancontactSource.getClientSecret()); assertNotNull(bancontactSource.getAmount()); - assertEquals(Source.BANCONTACT, bancontactSource.getType()); + assertEquals(Source.SourceType.BANCONTACT, bancontactSource.getType()); assertEquals(1000L, bancontactSource.getAmount().longValue()); assertNotNull(bancontactSource.getSourceTypeData()); assertNull(bancontactSource.getSourceTypeModel()); @@ -479,7 +479,7 @@ public void createSourceSynchronous_withCardParams_passesIntegrationTest() assertNotNull(cardSource); assertNotNull(cardSource.getClientSecret()); assertNotNull(cardSource.getId()); - assertEquals(Source.CARD, cardSource.getType()); + assertEquals(Source.SourceType.CARD, cardSource.getType()); assertNotNull(cardSource.getSourceTypeData()); assertNotNull(cardSource.getSourceTypeModel()); assertTrue(cardSource.getSourceTypeModel() instanceof SourceCardData); @@ -524,7 +524,7 @@ public void createSourceSynchronous_with3DSParams_passesIntegrationTest() assertNotNull(threeDSource.getClientSecret()); assertNotNull(threeDSource.getId()); assertNull(threeDSource.getSourceTypeModel()); - assertEquals(Source.THREE_D_SECURE, threeDSource.getType()); + assertEquals(Source.SourceType.THREE_D_SECURE, threeDSource.getType()); assertNotNull(threeDSource.getSourceTypeData()); JsonTestUtils.assertMapEquals(metamap, threeDSource.getMetaData()); } @@ -551,7 +551,7 @@ public void createSourceSynchronous_withGiropayParams_passesIntegrationTest() assertNotNull(giropaySource.getAmount()); assertEquals("eur", giropaySource.getCurrency()); assertEquals(2000L, giropaySource.getAmount().longValue()); - assertEquals(Source.GIROPAY, giropaySource.getType()); + assertEquals(Source.SourceType.GIROPAY, giropaySource.getType()); assertNotNull(giropaySource.getSourceTypeData()); assertNull(giropaySource.getSourceTypeModel()); assertNotNull(giropaySource.getOwner()); @@ -576,13 +576,13 @@ public void createSourceSynchronous_withP24Params_passesIntegrationTest() assertNotNull(p24Source); assertNotNull(p24Source.getId()); assertNotNull(p24Source.getClientSecret()); - assertEquals(Source.P24, p24Source.getType()); + assertEquals(Source.SourceType.P24, p24Source.getType()); assertEquals("redirect", p24Source.getFlow()); assertNotNull(p24Source.getOwner()); assertEquals("Example Payer", p24Source.getOwner().getName()); assertEquals("abc@def.com", p24Source.getOwner().getEmail()); assertEquals("eur", p24Source.getCurrency()); - assertEquals(Source.SINGLE_USE, p24Source.getUsage()); + assertEquals(Source.Usage.SINGLE_USE, p24Source.getUsage()); assertNotNull(p24Source.getRedirect()); assertEquals("stripe://start", p24Source.getRedirect().getReturnUrl()); } @@ -611,7 +611,7 @@ public void createSourceSynchronous_withSepaDebitParams_passesIntegrationTest() assertNotNull(sepaDebitSource); assertNotNull(sepaDebitSource.getClientSecret()); assertNotNull(sepaDebitSource.getId()); - assertEquals(Source.SEPA_DEBIT, sepaDebitSource.getType()); + assertEquals(Source.SourceType.SEPA_DEBIT, sepaDebitSource.getType()); assertNotNull(sepaDebitSource.getSourceTypeData()); assertNotNull(sepaDebitSource.getOwner()); assertNotNull(sepaDebitSource.getOwner().getAddress()); @@ -650,7 +650,7 @@ public void createSourceSynchronous_withSepaDebitParamsWithMinimalValues_passesI assertNotNull(sepaDebitSource); assertNotNull(sepaDebitSource.getClientSecret()); assertNotNull(sepaDebitSource.getId()); - assertEquals(Source.SEPA_DEBIT, sepaDebitSource.getType()); + assertEquals(Source.SourceType.SEPA_DEBIT, sepaDebitSource.getType()); JsonTestUtils.assertMapEquals(metamap ,sepaDebitSource.getMetaData()); } @@ -677,7 +677,7 @@ public void createSourceSynchronous_withNoEmail_passesIntegrationTest() assertNotNull(sepaDebitSource); assertNotNull(sepaDebitSource.getClientSecret()); assertNotNull(sepaDebitSource.getId()); - assertEquals(Source.SEPA_DEBIT, sepaDebitSource.getType()); + assertEquals(Source.SourceType.SEPA_DEBIT, sepaDebitSource.getType()); assertNotNull(sepaDebitSource.getSourceTypeData()); assertNotNull(sepaDebitSource.getOwner()); assertNotNull(sepaDebitSource.getOwner().getAddress()); @@ -709,7 +709,7 @@ public void createSepaDebitSource_withNoAddress_passesIntegrationTest() throws S assertNotNull(sepaDebitSource); assertNotNull(sepaDebitSource.getClientSecret()); assertNotNull(sepaDebitSource.getId()); - assertEquals(Source.SEPA_DEBIT, sepaDebitSource.getType()); + assertEquals(Source.SourceType.SEPA_DEBIT, sepaDebitSource.getType()); assertNotNull(sepaDebitSource.getSourceTypeData()); assertNotNull(sepaDebitSource.getOwner()); assertNotNull(sepaDebitSource.getOwner().getAddress()); @@ -745,7 +745,7 @@ public void createSourceSynchronous_withiDEALParams_passesIntegrationTest() assertNotNull(idealSource.getId()); assertNotNull(idealSource.getAmount()); assertEquals(5500L, idealSource.getAmount().longValue()); - assertEquals(Source.IDEAL, idealSource.getType()); + assertEquals(Source.SourceType.IDEAL, idealSource.getType()); assertEquals("eur", idealSource.getCurrency()); assertNotNull(idealSource.getSourceTypeData()); assertNotNull(idealSource.getOwner()); @@ -780,7 +780,7 @@ public void createSourceSynchronous_withiDEALParamsNoStatement_doesNotIgnoreBank assertNotNull(idealSource.getId()); assertNotNull(idealSource.getAmount()); assertEquals(5500L, idealSource.getAmount().longValue()); - assertEquals(Source.IDEAL, idealSource.getType()); + assertEquals(Source.SourceType.IDEAL, idealSource.getType()); assertEquals("eur", idealSource.getCurrency()); assertNotNull(idealSource.getSourceTypeData()); assertNotNull(idealSource.getOwner()); @@ -816,7 +816,7 @@ public void createSourceSynchronous_withiDEALParamsNoName_passesIntegrationTest( assertNotNull(idealSource.getId()); assertNotNull(idealSource.getAmount()); assertEquals(5500L, idealSource.getAmount().longValue()); - assertEquals(Source.IDEAL, idealSource.getType()); + assertEquals(Source.SourceType.IDEAL, idealSource.getType()); assertEquals("eur", idealSource.getCurrency()); assertNotNull(idealSource.getSourceTypeData()); assertNotNull(idealSource.getOwner()); @@ -849,7 +849,7 @@ public void createSourceSynchronous_withSofortParams_passesIntegrationTest() assertNotNull(sofortSource.getClientSecret()); assertNotNull(sofortSource.getId()); assertNotNull(sofortSource.getAmount()); - assertEquals(Source.SOFORT, sofortSource.getType()); + assertEquals(Source.SourceType.SOFORT, sofortSource.getType()); assertEquals("eur", sofortSource.getCurrency()); assertNotNull(sofortSource.getSourceTypeData()); assertNull(sofortSource.getSourceTypeModel()); @@ -902,7 +902,7 @@ public void createTokenSynchronous_withValidPersonalId_passesIntegrationTest() final Stripe stripe = createLoggingStripe(); final Token token = stripe.createPiiTokenSynchronous("0123456789"); assertNotNull(token); - assertEquals(Token.TYPE_PII, token.getType()); + assertEquals(Token.TokenType.PII, token.getType()); assertFalse(token.getLivemode()); assertFalse(token.getUsed()); assertNotNull(token.getId()); @@ -915,7 +915,7 @@ public void createTokenSynchronous_withValidCvc_passesIntegrationTest() final Token token = stripe.createCvcUpdateTokenSynchronous("1234"); assertNotNull(token); - assertEquals(Token.TYPE_CVC_UPDATE, token.getType()); + assertEquals(Token.TokenType.CVC_UPDATE, token.getType()); assertFalse(token.getLivemode()); assertFalse(token.getUsed()); assertNotNull(token.getId()); @@ -942,7 +942,7 @@ public void createAccountTokenSynchronous_withIndividualEntity_passesIntegration AccountParams.createAccountParams(true, AccountParams.BusinessType.Individual, businessData)); assertNotNull(token); - assertEquals(Token.TYPE_ACCOUNT, token.getType()); + assertEquals(Token.TokenType.ACCOUNT, token.getType()); assertFalse(token.getLivemode()); assertFalse(token.getUsed()); assertNotNull(token.getId()); @@ -967,7 +967,7 @@ public void createAccountTokenSynchronous_withCompanyEntity_isSuccessful() AccountParams.createAccountParams(true, AccountParams.BusinessType.Company, businessData)); assertNotNull(token); - assertEquals(Token.TYPE_ACCOUNT, token.getType()); + assertEquals(Token.TokenType.ACCOUNT, token.getType()); assertFalse(token.getLivemode()); assertFalse(token.getUsed()); assertNotNull(token.getId()); @@ -992,7 +992,7 @@ public void createAccountTokenSynchronous_withoutTosShown_isSuccessful() AccountParams.createAccountParams(false, AccountParams.BusinessType.Individual, businessData)); assertNotNull(token); - assertEquals(Token.TYPE_ACCOUNT, token.getType()); + assertEquals(Token.TokenType.ACCOUNT, token.getType()); assertFalse(token.getLivemode()); assertFalse(token.getUsed()); assertNotNull(token.getId()); @@ -1006,7 +1006,7 @@ public void createAccountTokenSynchronous_withoutBusinessData_isValid() AccountParams.createAccountParams(false, AccountParams.BusinessType.Individual, null)); assertNotNull(token); - assertEquals(Token.TYPE_ACCOUNT, token.getType()); + assertEquals(Token.TokenType.ACCOUNT, token.getType()); assertFalse(token.getLivemode()); assertFalse(token.getUsed()); assertNotNull(token.getId()); @@ -1020,7 +1020,7 @@ public void createAccountTokenSynchronous_withoutBusinessType_isValid() AccountParams.createAccountParams(false, null, null)); assertNotNull(token); - assertEquals(Token.TYPE_ACCOUNT, token.getType()); + assertEquals(Token.TokenType.ACCOUNT, token.getType()); assertFalse(token.getLivemode()); assertFalse(token.getUsed()); assertNotNull(token.getId()); diff --git a/stripe/src/test/java/com/stripe/android/model/BankAccountTest.java b/stripe/src/test/java/com/stripe/android/model/BankAccountTest.java index 8c6fc06314c..4b65b3b5e0f 100644 --- a/stripe/src/test/java/com/stripe/android/model/BankAccountTest.java +++ b/stripe/src/test/java/com/stripe/android/model/BankAccountTest.java @@ -27,7 +27,7 @@ public class BankAccountTest { public void parseSampleAccount_returnsExpectedValue() { final BankAccount expectedAccount = new BankAccount( "Jane Austen", - BankAccount.TYPE_INDIVIDUAL, + BankAccount.BankAccountType.INDIVIDUAL, "STRIPE TEST BANK", "US", "usd", diff --git a/stripe/src/test/java/com/stripe/android/model/CardTest.java b/stripe/src/test/java/com/stripe/android/model/CardTest.java index c8f85fa0be0..0955375605c 100644 --- a/stripe/src/test/java/com/stripe/android/model/CardTest.java +++ b/stripe/src/test/java/com/stripe/android/model/CardTest.java @@ -103,62 +103,62 @@ public void asCardBrand_whenBlank_returnsNull() { @Test public void asCardBrand_whenNonemptyButWeird_returnsUnknown() { - assertEquals(Card.UNKNOWN, asCardBrand("Awesome New Brand")); + assertEquals(Card.CardBrand.UNKNOWN, asCardBrand("Awesome New CardBrand")); } @Test public void asCardBrand_whenMastercard_returnsMasterCard() { - assertEquals(Card.MASTERCARD, asCardBrand("MasterCard")); + assertEquals(Card.CardBrand.MASTERCARD, asCardBrand("MasterCard")); } @Test public void asCardBrand_whenCapitalizedStrangely_stillRecognizesCard() { - assertEquals(Card.MASTERCARD, asCardBrand("Mastercard")); + assertEquals(Card.CardBrand.MASTERCARD, asCardBrand("Mastercard")); } @Test public void asCardBrand_whenVisa_returnsVisa() { - assertEquals(Card.VISA, asCardBrand("visa")); + assertEquals(Card.CardBrand.VISA, asCardBrand("visa")); } @Test public void asCardBrand_whenJcb_returnsJcb() { - assertEquals(Card.JCB, asCardBrand("Jcb")); + assertEquals(Card.CardBrand.JCB, asCardBrand("Jcb")); } @Test public void asCardBrand_whenDiscover_returnsDiscover() { - assertEquals(Card.DISCOVER, asCardBrand("Discover")); + assertEquals(Card.CardBrand.DISCOVER, asCardBrand("Discover")); } @Test public void asCardBrand_whenDinersClub_returnsDinersClub() { - assertEquals(Card.DINERS_CLUB, asCardBrand("Diners Club")); + assertEquals(Card.CardBrand.DINERS_CLUB, asCardBrand("Diners Club")); } @Test public void asCardBrand_whenAmericanExpress_returnsAmericanExpress() { - assertEquals(Card.AMERICAN_EXPRESS, asCardBrand("American express")); + assertEquals(Card.CardBrand.AMERICAN_EXPRESS, asCardBrand("American express")); } @Test public void asCardBrand_whenUnionPay_returnsUnionPay() { - assertEquals(Card.UNIONPAY, asCardBrand("UnionPay")); + assertEquals(Card.CardBrand.UNIONPAY, asCardBrand("UnionPay")); } @Test public void asFundingType_whenDebit_returnsDebit() { - assertEquals(Card.FUNDING_DEBIT, asFundingType("debit")); + assertEquals(Card.FundingType.DEBIT, asFundingType("debit")); } @Test public void asFundingType_whenCredit_returnsCredit() { - assertEquals(Card.FUNDING_CREDIT, asFundingType("credit")); + assertEquals(Card.FundingType.CREDIT, asFundingType("credit")); } @Test public void asFundingType_whenCreditAndCapitalized_returnsCredit() { - assertEquals(Card.FUNDING_CREDIT, asFundingType("Credit")); + assertEquals(Card.FundingType.CREDIT, asFundingType("Credit")); } @Test @@ -173,12 +173,12 @@ public void asFundingType_whenBlank_returnsNull() { @Test public void asFundingType_whenUnknown_returnsUnknown() { - assertEquals(Card.FUNDING_UNKNOWN, asFundingType("unknown")); + assertEquals(Card.FundingType.UNKNOWN, asFundingType("unknown")); } @Test public void asFundingType_whenGobbledegook_returnsUnkown() { - assertEquals(Card.FUNDING_UNKNOWN, asFundingType("personal iou")); + assertEquals(Card.FundingType.UNKNOWN, asFundingType("personal iou")); } @Test @@ -190,43 +190,43 @@ public void canInitializeWithMinimalArguments() { @Test public void testTypeReturnsCorrectlyForAmexCard() { Card card = Card.create("3412123412341234", null, null, null); - assertEquals(Card.AMERICAN_EXPRESS, card.getBrand()); + assertEquals(Card.CardBrand.AMERICAN_EXPRESS, card.getBrand()); } @Test public void testTypeReturnsCorrectlyForDiscoverCard() { Card card = Card.create("6452123412341234", null, null, null); - assertEquals(Card.DISCOVER, card.getBrand()); + assertEquals(Card.CardBrand.DISCOVER, card.getBrand()); } @Test public void testTypeReturnsCorrectlyForJCBCard() { Card card = Card.create("3512123412341234", null, null, null); - assertEquals(Card.JCB, card.getBrand()); + assertEquals(Card.CardBrand.JCB, card.getBrand()); } @Test public void testTypeReturnsCorrectlyForDinersClubCard() { Card card = Card.create("3612123412341234", null, null, null); - assertEquals(Card.DINERS_CLUB, card.getBrand()); + assertEquals(Card.CardBrand.DINERS_CLUB, card.getBrand()); } @Test public void testTypeReturnsCorrectlyForVisaCard() { Card card = Card.create("4112123412341234", null, null, null); - assertEquals(Card.VISA, card.getBrand()); + assertEquals(Card.CardBrand.VISA, card.getBrand()); } @Test public void testTypeReturnsCorrectlyForMasterCard() { Card card = Card.create("5112123412341234", null, null, null); - assertEquals(Card.MASTERCARD, card.getBrand()); + assertEquals(Card.CardBrand.MASTERCARD, card.getBrand()); } @Test public void testTypeReturnsCorrectlyForUnionPay() { Card card = Card.create("6200000000000005", null, null, null); - assertEquals(Card.UNIONPAY, card.getBrand()); + assertEquals(Card.CardBrand.UNIONPAY, card.getBrand()); } @Test @@ -244,7 +244,7 @@ public void shouldFailValidateNumberIfNotLuhnNumber() { @Test public void shouldPassValidateNumberIfLuhnNumberAmex() { Card card = Card.create("378282246310005", null, null, null); - assertEquals(Card.AMERICAN_EXPRESS, card.getBrand()); + assertEquals(Card.CardBrand.AMERICAN_EXPRESS, card.getBrand()); assertTrue(card.validateNumber()); } @@ -281,7 +281,7 @@ public void shouldFailValidateNumberIfContainsLetters() { @Test public void shouldFailValidateNumberIfTooLong() { Card card = Card.create("4242 4242 4242 4242 6", null, null, null); - assertEquals(Card.VISA, card.getBrand()); + assertEquals(Card.CardBrand.VISA, card.getBrand()); assertFalse(card.validateNumber()); } @@ -658,6 +658,24 @@ public void last4ShouldBeNullWhenNumberIsNull() { assertNull(card.getLast4()); } + @Test + public void getLast4_whenNumberIsNullButLast4IsSet_returnsCorrectValue() { + final Card card = new Card.Builder(null, 2, 2020, "123") + .name("John Q Public") + .last4("1234") + .build(); + assertEquals("1234", card.getLast4()); + } + + @Test + public void getBrand_whenNumberIsNullButBrandIsSet_returnsCorrectValue() { + final Card card = new Card.Builder(null, 2, 2020, "123") + .name("John Q Public") + .brand(Card.CardBrand.AMERICAN_EXPRESS) + .build(); + assertEquals(Card.CardBrand.AMERICAN_EXPRESS, card.getBrand()); + } + @Test public void fromString_whenStringIsValidJson_returnsExpectedCard() { final Card expectedCard = createUsdCard(); @@ -705,8 +723,8 @@ private static Card createUsdCard() { metadata.put("animal", "dog"); return new Card.Builder(null, 8, 2017, null) - .brand(Card.VISA) - .funding(Card.FUNDING_CREDIT) + .brand(Card.CardBrand.VISA) + .funding(Card.FundingType.CREDIT) .last4("4242") .id("card_189fi32eZvKYlo2CHK8NPRME") .country("US") diff --git a/stripe/src/test/java/com/stripe/android/model/CustomerSourceTest.java b/stripe/src/test/java/com/stripe/android/model/CustomerSourceTest.java index e4ccc51dd00..eeb47783bef 100644 --- a/stripe/src/test/java/com/stripe/android/model/CustomerSourceTest.java +++ b/stripe/src/test/java/com/stripe/android/model/CustomerSourceTest.java @@ -80,13 +80,13 @@ public void fromExampleJsonSource_toJson_createsSameObject() { public void getSourceType_whenCard_returnsCard() throws JSONException { final CustomerSource sourceData = CustomerSource.fromJson(new JSONObject(JSON_CARD_USD)); assertNotNull(sourceData); - assertEquals(Source.CARD, sourceData.getSourceType()); + assertEquals(Source.SourceType.CARD, sourceData.getSourceType()); } @Test public void getSourceType_whenSourceThatIsNotCard_returnsSourceType() { final CustomerSource alipaySource = CustomerSource.fromString(EXAMPLE_ALIPAY_SOURCE); assertNotNull(alipaySource); - assertEquals(Source.ALIPAY, alipaySource.getSourceType()); + assertEquals(Source.SourceType.ALIPAY, alipaySource.getSourceType()); } } diff --git a/stripe/src/test/java/com/stripe/android/model/SourceCardDataTest.java b/stripe/src/test/java/com/stripe/android/model/SourceCardDataTest.java index 5e72a59cd61..5d773985763 100644 --- a/stripe/src/test/java/com/stripe/android/model/SourceCardDataTest.java +++ b/stripe/src/test/java/com/stripe/android/model/SourceCardDataTest.java @@ -28,8 +28,8 @@ public class SourceCardDataTest { @Test public void fromExampleJsonCard_createsExpectedObject() { assertNotNull(CARD_DATA); - assertEquals(Card.VISA, CARD_DATA.getBrand()); - assertEquals(Card.FUNDING_CREDIT, CARD_DATA.getFunding()); + assertEquals(Card.CardBrand.VISA, CARD_DATA.getBrand()); + assertEquals(Card.FundingType.CREDIT, CARD_DATA.getFunding()); assertEquals("4242", CARD_DATA.getLast4()); assertNotNull(CARD_DATA.getExpiryMonth()); assertNotNull(CARD_DATA.getExpiryYear()); @@ -49,8 +49,8 @@ public void fromExampleJsonCard_toMap_createsExpectedMapping() { assertEquals("4242", cardDataMap.get("last4")); assertEquals(12, cardDataMap.get("exp_month")); assertEquals(2050, cardDataMap.get("exp_year")); - assertEquals(Card.FUNDING_CREDIT, cardDataMap.get("funding")); - assertEquals(Card.VISA, cardDataMap.get("brand")); + assertEquals(Card.FundingType.CREDIT, cardDataMap.get("funding")); + assertEquals(Card.CardBrand.VISA, cardDataMap.get("brand")); assertEquals("optional", cardDataMap.get("three_d_secure")); assertEquals("apple_pay", cardDataMap.get("tokenization_method")); assertEquals("4242", cardDataMap.get("dynamic_last4")); @@ -73,13 +73,13 @@ public void testHashCode() { @Test public void testAsThreeDSecureStatus() { - assertEquals(SourceCardData.REQUIRED, SourceCardData.asThreeDSecureStatus("required")); - assertEquals(SourceCardData.OPTIONAL, SourceCardData.asThreeDSecureStatus("optional")); - assertEquals(SourceCardData.NOT_SUPPORTED, + assertEquals(SourceCardData.ThreeDSecureStatus.REQUIRED, SourceCardData.asThreeDSecureStatus("required")); + assertEquals(SourceCardData.ThreeDSecureStatus.OPTIONAL, SourceCardData.asThreeDSecureStatus("optional")); + assertEquals(SourceCardData.ThreeDSecureStatus.NOT_SUPPORTED, SourceCardData.asThreeDSecureStatus("not_supported")); - assertEquals(SourceCardData.RECOMMENDED, + assertEquals(SourceCardData.ThreeDSecureStatus.RECOMMENDED, SourceCardData.asThreeDSecureStatus("recommended")); - assertEquals(SourceCardData.UNKNOWN, SourceCardData.asThreeDSecureStatus("unknown")); + assertEquals(SourceCardData.ThreeDSecureStatus.UNKNOWN, SourceCardData.asThreeDSecureStatus("unknown")); assertNull(SourceCardData.asThreeDSecureStatus("")); } } diff --git a/stripe/src/test/java/com/stripe/android/model/SourceParamsTest.java b/stripe/src/test/java/com/stripe/android/model/SourceParamsTest.java index 93765146954..0b20a05d3db 100644 --- a/stripe/src/test/java/com/stripe/android/model/SourceParamsTest.java +++ b/stripe/src/test/java/com/stripe/android/model/SourceParamsTest.java @@ -49,8 +49,8 @@ public void createAlipayReusableParams_withAllFields_hasExpectedFields() { "jdog@lesmis.net", "stripe://start"); - assertEquals(Source.ALIPAY, params.getType()); - assertEquals(Source.REUSABLE, params.getUsage()); + assertEquals(Source.SourceType.ALIPAY, params.getType()); + assertEquals(Source.Usage.REUSABLE, params.getUsage()); assertNull(params.getAmount()); assertEquals("usd", params.getCurrency()); assertNotNull(params.getRedirect()); @@ -69,8 +69,8 @@ public void createAlipayReusableParams_withOnlyName_hasOnlyExpectedFields() { null, "stripe://start"); - assertEquals(Source.ALIPAY, params.getType()); - assertEquals(Source.REUSABLE, params.getUsage()); + assertEquals(Source.SourceType.ALIPAY, params.getType()); + assertEquals(Source.Usage.REUSABLE, params.getUsage()); assertNull(params.getAmount()); assertEquals("cad", params.getCurrency()); assertNotNull(params.getRedirect()); @@ -90,7 +90,7 @@ public void createAlipaySingleUseParams_withAllFields_hasExpectedFields() { "jane@test.com", "stripe://testactivity"); - assertEquals(Source.ALIPAY, params.getType()); + assertEquals(Source.SourceType.ALIPAY, params.getType()); assertNotNull(params.getAmount()); assertEquals(1000L, params.getAmount().longValue()); assertEquals("aud", params.getCurrency()); @@ -110,7 +110,7 @@ public void createAlipaySingleUseParams_withoutOwner_hasNoOwnerFields() { null, "stripe://testactivity2"); - assertEquals(Source.ALIPAY, params.getType()); + assertEquals(Source.SourceType.ALIPAY, params.getType()); assertNotNull(params.getAmount()); assertEquals(555L, params.getAmount().longValue()); assertEquals("eur", params.getCurrency()); @@ -130,7 +130,7 @@ public void createBancontactParams_hasExpectedFields() { "descriptor", "en"); - assertEquals(Source.BANCONTACT, params.getType()); + assertEquals(Source.SourceType.BANCONTACT, params.getType()); assertEquals(Source.EURO, params.getCurrency()); assertNotNull(params.getAmount()); assertEquals(1000L, params.getAmount().longValue()); @@ -155,13 +155,13 @@ public void createBancontactParams_toParamMap_createsExpectedMap() { "en"); Map expectedMap = new HashMap<>(); - expectedMap.put("type", Source.BANCONTACT); + expectedMap.put("type", Source.SourceType.BANCONTACT); expectedMap.put("currency", Source.EURO); expectedMap.put("amount", 1000L); expectedMap.put("owner", new HashMap() {{ put("name", "Stripe"); }}); expectedMap.put("redirect", new HashMap() {{ put("return_url", "return/url/3000"); }}); - expectedMap.put(Source.BANCONTACT, + expectedMap.put(Source.SourceType.BANCONTACT, new HashMap() {{ put("statement_descriptor", "descriptor"); put("preferred_language", "en"); @@ -284,7 +284,7 @@ public void createEPSParams_hasExpectedFields() { "stripe://return", "stripe descriptor"); - assertEquals(Source.EPS, params.getType()); + assertEquals(Source.SourceType.EPS, params.getType()); assertEquals(Source.EURO, params.getCurrency()); assertEquals("Stripe", Objects.requireNonNull(params.getOwner()).get("name")); assertEquals("stripe://return", @@ -303,13 +303,13 @@ public void createEPSParams_toParamMap_createsExpectedMap() { "stripe descriptor"); Map expectedMap = new HashMap<>(); - expectedMap.put("type", Source.EPS); + expectedMap.put("type", Source.SourceType.EPS); expectedMap.put("currency", Source.EURO); expectedMap.put("amount", 150L); expectedMap.put("owner", new HashMap() {{ put("name", "Stripe"); }}); expectedMap.put("redirect", new HashMap() {{ put("return_url", "stripe://return"); }}); - expectedMap.put(Source.EPS, + expectedMap.put(Source.SourceType.EPS, new HashMap() {{ put("statement_descriptor", "stripe descriptor"); }}); @@ -326,7 +326,7 @@ public void createEPSParams_toParamMap_createsExpectedMap_noStatementDescriptor( null); Map expectedMap = new HashMap<>(); - expectedMap.put("type", Source.EPS); + expectedMap.put("type", Source.SourceType.EPS); expectedMap.put("currency", Source.EURO); expectedMap.put("amount", 150L); expectedMap.put("owner", new HashMap() {{ put("name", "Stripe"); }}); @@ -344,7 +344,7 @@ public void createGiropayParams_hasExpectedFields() { "stripe://return", "stripe descriptor"); - assertEquals(Source.GIROPAY, params.getType()); + assertEquals(Source.SourceType.GIROPAY, params.getType()); assertEquals(Source.EURO, params.getCurrency()); assertNotNull(params.getAmount()); assertEquals(150L, params.getAmount().longValue()); @@ -366,13 +366,13 @@ public void createGiropayParams_toParamMap_createsExpectedMap() { "stripe descriptor"); Map expectedMap = new HashMap<>(); - expectedMap.put("type", Source.GIROPAY); + expectedMap.put("type", Source.SourceType.GIROPAY); expectedMap.put("currency", Source.EURO); expectedMap.put("amount", 150L); expectedMap.put("owner", new HashMap() {{ put("name", "Stripe"); }}); expectedMap.put("redirect", new HashMap() {{ put("return_url", "stripe://return"); }}); - expectedMap.put(Source.GIROPAY, + expectedMap.put(Source.SourceType.GIROPAY, new HashMap() {{ put("statement_descriptor", "stripe descriptor"); }}); @@ -388,7 +388,7 @@ public void createGiropayParams_withNullStatementDescriptor_hasExpectedFieldsBut "stripe://return", null); - assertEquals(Source.GIROPAY, params.getType()); + assertEquals(Source.SourceType.GIROPAY, params.getType()); assertEquals(Source.EURO, params.getCurrency()); assertNotNull(params.getAmount()); assertEquals(150L, params.getAmount().longValue()); @@ -407,7 +407,7 @@ public void createIdealParams_hasExpectedFields() { "stripe://anotherurl", "something you bought", "SVB"); - assertEquals(Source.IDEAL, params.getType()); + assertEquals(Source.SourceType.IDEAL, params.getType()); assertEquals(Source.EURO, params.getCurrency()); assertNotNull(params.getAmount()); assertEquals(900L, params.getAmount().longValue()); @@ -432,14 +432,14 @@ public void createIdealParams_toParamMap_createsExpectedMap() { "SVB"); Map expectedMap = new HashMap<>(); - expectedMap.put("type", Source.IDEAL); + expectedMap.put("type", Source.SourceType.IDEAL); expectedMap.put("currency", Source.EURO); expectedMap.put("amount", 900L); expectedMap.put("owner", new HashMap() {{ put("name", "Default Name"); }}); expectedMap.put("redirect", new HashMap() {{ put("return_url", "stripe://anotherurl"); }}); - expectedMap.put(Source.IDEAL, + expectedMap.put(Source.SourceType.IDEAL, new HashMap() {{ put("statement_descriptor", "something you bought"); put("bank", "SVB"); @@ -457,7 +457,7 @@ public void createP24Params_withAllFields_hasExpectedFields() { "jane@test.com", "stripe://testactivity"); - assertEquals(Source.P24, params.getType()); + assertEquals(Source.SourceType.P24, params.getType()); assertNotNull(params.getAmount()); assertEquals(1000L, params.getAmount().longValue()); assertEquals("eur", params.getCurrency()); @@ -477,7 +477,7 @@ public void createP24Params_withNullName_hasExpectedFields() { "jane@test.com", "stripe://testactivity"); - assertEquals(Source.P24, params.getType()); + assertEquals(Source.SourceType.P24, params.getType()); assertNotNull(params.getAmount()); assertEquals(1000L, params.getAmount().longValue()); assertEquals("eur", params.getCurrency()); @@ -495,7 +495,7 @@ public void createMultibancoParams_hasExpectedFields() { "stripe://testactivity", "multibancoholder@stripe.com"); - assertEquals(Source.MULTIBANCO, params.getType()); + assertEquals(Source.SourceType.MULTIBANCO, params.getType()); assertEquals(Source.EURO, params.getCurrency()); assertEquals(150L, Objects.requireNonNull(params.getAmount()).longValue()); assertEquals("stripe://testactivity", @@ -512,7 +512,7 @@ public void createMultibancoParams_toParamMap_createsExpectedMap() { "multibancoholder@stripe.com"); Map expectedMap = new HashMap<>(); - expectedMap.put("type", Source.MULTIBANCO); + expectedMap.put("type", Source.SourceType.MULTIBANCO); expectedMap.put("currency", Source.EURO); expectedMap.put("amount", 150L); expectedMap.put("owner", @@ -534,7 +534,7 @@ public void createSepaDebitParams_hasExpectedFields() { "90210", "EI"); - assertEquals(Source.SEPA_DEBIT, params.getType()); + assertEquals(Source.SourceType.SEPA_DEBIT, params.getType()); assertEquals(Source.EURO, params.getCurrency()); assertNotNull(params.getOwner()); assertEquals("Jai Testa", params.getOwner().get("name")); @@ -560,7 +560,7 @@ public void createSepaDebitParams_toParamMap_createsExpectedMap() { "EI"); Map expectedMap = new HashMap<>(); - expectedMap.put("type", Source.SEPA_DEBIT); + expectedMap.put("type", Source.SourceType.SEPA_DEBIT); expectedMap.put("currency", Source.EURO); final Map addressMap = new HashMap<>(); @@ -576,9 +576,9 @@ public void createSepaDebitParams_toParamMap_createsExpectedMap() { put("address", addressMap); }}); - expectedMap.put(Source.SEPA_DEBIT, + expectedMap.put(Source.SourceType.SEPA_DEBIT, new HashMap() {{ put("iban", "ibaniban"); }}); - assertEquals(Source.SEPA_DEBIT, params.getType()); + assertEquals(Source.SourceType.SEPA_DEBIT, params.getType()); Map actualMap = params.toParamMap(); JsonTestUtils.assertMapEquals(expectedMap, actualMap); @@ -592,7 +592,7 @@ public void createSofortParams_hasExpectedFields() { "UK", "a thing you bought"); - assertEquals(Source.SOFORT, params.getType()); + assertEquals(Source.SourceType.SOFORT, params.getType()); assertEquals(Source.EURO, params.getCurrency()); assertNotNull(params.getAmount()); assertEquals(50000L, params.getAmount().longValue()); @@ -614,12 +614,12 @@ public void createSofortParams_toParamMap_createsExpectedMap() { "a thing you bought"); Map expectedMap = new HashMap<>(); - expectedMap.put("type", Source.SOFORT); + expectedMap.put("type", Source.SourceType.SOFORT); expectedMap.put("currency", Source.EURO); expectedMap.put("amount", 50000L); expectedMap.put("redirect", new HashMap() {{ put("return_url", "example://return"); }}); - expectedMap.put(Source.SOFORT, + expectedMap.put(Source.SourceType.SOFORT, new HashMap() {{ put("country", "UK"); put("statement_descriptor", "a thing you bought"); @@ -636,7 +636,7 @@ public void createThreeDSecureParams_hasExpectedFields() { "stripe://returnaddress", "card_id_123"); - assertEquals(Source.THREE_D_SECURE, params.getType()); + assertEquals(Source.SourceType.THREE_D_SECURE, params.getType()); // Brazilian Real assertEquals("brl", params.getCurrency()); assertNotNull(params.getAmount()); @@ -659,12 +659,12 @@ public void createThreeDSecureParams_toParamMap_createsExpectedMap() { "card_id_123"); Map expectedMap = new HashMap<>(); - expectedMap.put("type", Source.THREE_D_SECURE); + expectedMap.put("type", Source.SourceType.THREE_D_SECURE); expectedMap.put("currency", "brl"); expectedMap.put("amount", 99000L); expectedMap.put("redirect", new HashMap() {{ put("return_url", "stripe://returnaddress"); }}); - expectedMap.put(Source.THREE_D_SECURE, + expectedMap.put(Source.SourceType.THREE_D_SECURE, new HashMap() {{ put("card", "card_id_123"); }}); JsonTestUtils.assertMapEquals(expectedMap, params.toParamMap()); @@ -701,7 +701,7 @@ public void createCustomParamsWithSourceTypeParameters_toParamMap_createsExpecte public void setCustomType_forEmptyParams_setsTypeToUnknown() { final SourceParams params = SourceParams.createCustomParams(); params.setTypeRaw("dogecoin"); - assertEquals(Source.UNKNOWN, params.getType()); + assertEquals(Source.SourceType.UNKNOWN, params.getType()); assertEquals("dogecoin", params.getTypeRaw()); } @@ -713,7 +713,7 @@ public void setCustomType_forStandardParams_overridesStandardType() { "stripe://returnaddress", "card_id_123"); params.setTypeRaw("bar_tab"); - assertEquals(Source.UNKNOWN, params.getType()); + assertEquals(Source.SourceType.UNKNOWN, params.getType()); assertEquals("bar_tab", params.getTypeRaw()); } diff --git a/stripe/src/test/java/com/stripe/android/model/SourceRedirectTest.java b/stripe/src/test/java/com/stripe/android/model/SourceRedirectTest.java index 151513e05dc..1ee78e2dd19 100644 --- a/stripe/src/test/java/com/stripe/android/model/SourceRedirectTest.java +++ b/stripe/src/test/java/com/stripe/android/model/SourceRedirectTest.java @@ -41,13 +41,13 @@ public void fromJsonString_toMap_createsExpectedMap() { @Test public void asStatus() { - assertEquals(SourceRedirect.FAILED, + assertEquals(SourceRedirect.Status.FAILED, SourceRedirect.asStatus("failed")); - assertEquals(SourceRedirect.SUCCEEDED, + assertEquals(SourceRedirect.Status.SUCCEEDED, SourceRedirect.asStatus("succeeded")); - assertEquals(SourceRedirect.PENDING, + assertEquals(SourceRedirect.Status.PENDING, SourceRedirect.asStatus("pending")); - assertEquals(SourceRedirect.NOT_REQUIRED, + assertEquals(SourceRedirect.Status.NOT_REQUIRED, SourceRedirect.asStatus("not_required")); assertNull(SourceRedirect.asStatus("something_else")); } diff --git a/stripe/src/test/java/com/stripe/android/model/SourceTest.java b/stripe/src/test/java/com/stripe/android/model/SourceTest.java index f29f20764a2..ac217664347 100644 --- a/stripe/src/test/java/com/stripe/android/model/SourceTest.java +++ b/stripe/src/test/java/com/stripe/android/model/SourceTest.java @@ -215,7 +215,7 @@ public void fromJsonStringWithNulls_toMap_createsExpectedMap() { public void fromJsonString_withCustomType_createsSourceWithCustomType() { Source customSource = Source.fromString(EXAMPLE_JSON_SOURCE_CUSTOM_TYPE); assertNotNull("Parsing failure", customSource); - assertEquals(Source.UNKNOWN, customSource.getType()); + assertEquals(Source.SourceType.UNKNOWN, customSource.getType()); assertEquals(DOGE_COIN, customSource.getTypeRaw()); assertNull(customSource.getSourceTypeModel()); assertNotNull("Failed to find custom api params", customSource.getSourceTypeData()); @@ -233,10 +233,10 @@ public void fromJsonString_withCreatedCardJson_shouldReturnSourceWithCardId() { final Source source = Source.fromString(CREATED_CARD_JSON); assertNotNull(source); assertEquals("card_1ELxrOCRMbs6FrXfdxOGjnaD", source.getId()); - assertEquals(Source.CARD, source.getType()); + assertEquals(Source.SourceType.CARD, source.getType()); assertTrue(source.getSourceTypeModel() instanceof SourceCardData); final SourceCardData sourceCardData = (SourceCardData) source.getSourceTypeModel(); - assertEquals(Card.VISA, sourceCardData.getBrand()); + assertEquals(Card.CardBrand.VISA, sourceCardData.getBrand()); } } diff --git a/stripe/src/test/java/com/stripe/android/model/TokenTest.java b/stripe/src/test/java/com/stripe/android/model/TokenTest.java index 41dcdcf8d3c..1fe244fdf1b 100644 --- a/stripe/src/test/java/com/stripe/android/model/TokenTest.java +++ b/stripe/src/test/java/com/stripe/android/model/TokenTest.java @@ -15,10 +15,10 @@ public class TokenTest { private static final Card CARD = new Card.Builder(null, 8, 2017, null) .id("card_189fi32eZvKYlo2CHK8NPRME") - .brand(Card.VISA) + .brand(Card.CardBrand.VISA) .country("US") .last4("4242") - .funding(Card.FUNDING_CREDIT) + .funding(Card.FundingType.CREDIT) .metadata(new HashMap()) .build(); @@ -167,7 +167,7 @@ public void parseToken_whenBankAccount_readsObject() { assertEquals(expectedToken.getLivemode(), answerToken.getLivemode()); assertEquals(expectedToken.getCreated(), answerToken.getCreated()); assertEquals(expectedToken.getUsed(), answerToken.getUsed()); - assertEquals(Token.TYPE_BANK_ACCOUNT, answerToken.getType()); + assertEquals(Token.TokenType.BANK_ACCOUNT, answerToken.getType()); assertNotNull(answerToken.getBankAccount()); assertNull(answerToken.getCard()); diff --git a/stripe/src/test/java/com/stripe/android/view/CardInputWidgetTest.java b/stripe/src/test/java/com/stripe/android/view/CardInputWidgetTest.java index 6462da394bf..da87616f514 100644 --- a/stripe/src/test/java/com/stripe/android/view/CardInputWidgetTest.java +++ b/stripe/src/test/java/com/stripe/android/view/CardInputWidgetTest.java @@ -713,7 +713,7 @@ public void setAllCardFields_whenValidValues_allowsGetCardWithExpectedValues() { assertEquals(12, (int) card.getExpMonth()); assertEquals(2079, (int) card.getExpYear()); assertEquals("1234", card.getCVC()); - assertEquals(Card.AMERICAN_EXPRESS, card.getBrand()); + assertEquals(Card.CardBrand.AMERICAN_EXPRESS, card.getBrand()); final PaymentMethodCreateParams.Card paymentMethodCard = mCardInputWidget.getPaymentMethodCard(); @@ -739,44 +739,44 @@ public void addValues_thenClear_leavesAllTextFieldsEmpty() { @Test public void shouldIconShowBrand_whenCvcNotFocused_isAlwaysTrue() { - assertTrue(shouldIconShowBrand(Card.AMERICAN_EXPRESS, false, "1234")); - assertTrue(shouldIconShowBrand(Card.AMERICAN_EXPRESS, false, "")); - assertTrue(shouldIconShowBrand(Card.VISA, false, "333")); - assertTrue(shouldIconShowBrand(Card.DINERS_CLUB, false, "12")); - assertTrue(shouldIconShowBrand(Card.DISCOVER, false, null)); - assertTrue(shouldIconShowBrand(Card.JCB, false, "7")); + assertTrue(shouldIconShowBrand(Card.CardBrand.AMERICAN_EXPRESS, false, "1234")); + assertTrue(shouldIconShowBrand(Card.CardBrand.AMERICAN_EXPRESS, false, "")); + assertTrue(shouldIconShowBrand(Card.CardBrand.VISA, false, "333")); + assertTrue(shouldIconShowBrand(Card.CardBrand.DINERS_CLUB, false, "12")); + assertTrue(shouldIconShowBrand(Card.CardBrand.DISCOVER, false, null)); + assertTrue(shouldIconShowBrand(Card.CardBrand.JCB, false, "7")); } @Test public void shouldIconShowBrand_whenAmexAndCvCStringLengthNotFour_isFalse() { - assertFalse(shouldIconShowBrand(Card.AMERICAN_EXPRESS, true, "")); - assertFalse(shouldIconShowBrand(Card.AMERICAN_EXPRESS, true, "1")); - assertFalse(shouldIconShowBrand(Card.AMERICAN_EXPRESS, true, "22")); - assertFalse(shouldIconShowBrand(Card.AMERICAN_EXPRESS, true, "333")); + assertFalse(shouldIconShowBrand(Card.CardBrand.AMERICAN_EXPRESS, true, "")); + assertFalse(shouldIconShowBrand(Card.CardBrand.AMERICAN_EXPRESS, true, "1")); + assertFalse(shouldIconShowBrand(Card.CardBrand.AMERICAN_EXPRESS, true, "22")); + assertFalse(shouldIconShowBrand(Card.CardBrand.AMERICAN_EXPRESS, true, "333")); } @Test public void shouldIconShowBrand_whenAmexAndCvcStringLengthIsFour_isTrue() { - assertTrue(shouldIconShowBrand(Card.AMERICAN_EXPRESS, true, "1234")); + assertTrue(shouldIconShowBrand(Card.CardBrand.AMERICAN_EXPRESS, true, "1234")); } @Test public void shouldIconShowBrand_whenNotAmexAndCvcStringLengthIsNotThree_isFalse() { - assertFalse(shouldIconShowBrand(Card.VISA, true, "")); - assertFalse(shouldIconShowBrand(Card.DISCOVER, true, "12")); - assertFalse(shouldIconShowBrand(Card.JCB, true, "55")); - assertFalse(shouldIconShowBrand(Card.MASTERCARD, true, "9")); - assertFalse(shouldIconShowBrand(Card.DINERS_CLUB, true, null)); - assertFalse(shouldIconShowBrand(Card.UNKNOWN, true, "12")); + assertFalse(shouldIconShowBrand(Card.CardBrand.VISA, true, "")); + assertFalse(shouldIconShowBrand(Card.CardBrand.DISCOVER, true, "12")); + assertFalse(shouldIconShowBrand(Card.CardBrand.JCB, true, "55")); + assertFalse(shouldIconShowBrand(Card.CardBrand.MASTERCARD, true, "9")); + assertFalse(shouldIconShowBrand(Card.CardBrand.DINERS_CLUB, true, null)); + assertFalse(shouldIconShowBrand(Card.CardBrand.UNKNOWN, true, "12")); } @Test public void shouldIconShowBrand_whenNotAmexAndCvcStringLengthIsThree_isTrue() { - assertTrue(shouldIconShowBrand(Card.VISA, true, "999")); - assertTrue(shouldIconShowBrand(Card.DISCOVER, true, "123")); - assertTrue(shouldIconShowBrand(Card.JCB, true, "555")); - assertTrue(shouldIconShowBrand(Card.MASTERCARD, true, "919")); - assertTrue(shouldIconShowBrand(Card.DINERS_CLUB, true, "415")); - assertTrue(shouldIconShowBrand(Card.UNKNOWN, true, "212")); + assertTrue(shouldIconShowBrand(Card.CardBrand.VISA, true, "999")); + assertTrue(shouldIconShowBrand(Card.CardBrand.DISCOVER, true, "123")); + assertTrue(shouldIconShowBrand(Card.CardBrand.JCB, true, "555")); + assertTrue(shouldIconShowBrand(Card.CardBrand.MASTERCARD, true, "919")); + assertTrue(shouldIconShowBrand(Card.CardBrand.DINERS_CLUB, true, "415")); + assertTrue(shouldIconShowBrand(Card.CardBrand.UNKNOWN, true, "212")); } } diff --git a/stripe/src/test/java/com/stripe/android/view/CardNumberEditTextTest.java b/stripe/src/test/java/com/stripe/android/view/CardNumberEditTextTest.java index 0f9ffc309d1..ba144a0bf94 100644 --- a/stripe/src/test/java/com/stripe/android/view/CardNumberEditTextTest.java +++ b/stripe/src/test/java/com/stripe/android/view/CardNumberEditTextTest.java @@ -51,7 +51,7 @@ public void setup() { @Test public void updateSelectionIndex_whenVisa_increasesIndexWhenGoingPastTheSpaces() { // Directly setting card brand as a testing hack (annotated in source) - mCardNumberEditText.mCardBrand = Card.VISA; + mCardNumberEditText.mCardBrand = Card.CardBrand.VISA; // Adding 1 character, starting at position 4, with a final string length 6 assertEquals(6, mCardNumberEditText.updateSelectionIndex(6, 4, 1)); @@ -62,14 +62,14 @@ public void updateSelectionIndex_whenVisa_increasesIndexWhenGoingPastTheSpaces() @Test public void updateSelectionIndex_whenAmEx_increasesIndexWhenGoingPastTheSpaces() { - mCardNumberEditText.mCardBrand = Card.AMERICAN_EXPRESS; + mCardNumberEditText.mCardBrand = Card.CardBrand.AMERICAN_EXPRESS; assertEquals(6, mCardNumberEditText.updateSelectionIndex(6, 4, 1)); assertEquals(13, mCardNumberEditText.updateSelectionIndex(13, 11, 1)); } @Test public void updateSelectionIndex_whenDinersClub_decreasesIndexWhenDeletingPastTheSpaces() { - mCardNumberEditText.mCardBrand = Card.DINERS_CLUB; + mCardNumberEditText.mCardBrand = Card.CardBrand.DINERS_CLUB; assertEquals(4, mCardNumberEditText.updateSelectionIndex(6, 5, 0)); assertEquals(9, mCardNumberEditText.updateSelectionIndex(13, 10, 0)); assertEquals(14, mCardNumberEditText.updateSelectionIndex(17, 15, 0)); @@ -77,38 +77,38 @@ public void updateSelectionIndex_whenDinersClub_decreasesIndexWhenDeletingPastTh @Test public void updateSelectionIndex_whenDeletingNotOnGaps_doesNotDecreaseIndex() { - mCardNumberEditText.mCardBrand = Card.DINERS_CLUB; + mCardNumberEditText.mCardBrand = Card.CardBrand.DINERS_CLUB; assertEquals(7, mCardNumberEditText.updateSelectionIndex(12, 7, 0)); } @Test public void updateSelectionIndex_whenAmEx_decreasesIndexWhenDeletingPastTheSpaces() { - mCardNumberEditText.mCardBrand = Card.AMERICAN_EXPRESS; + mCardNumberEditText.mCardBrand = Card.CardBrand.AMERICAN_EXPRESS; assertEquals(4, mCardNumberEditText.updateSelectionIndex(10, 5, 0)); assertEquals(11, mCardNumberEditText.updateSelectionIndex(13, 12, 0)); } @Test public void updateSelectionIndex_whenSelectionInTheMiddle_increasesIndexOverASpace() { - mCardNumberEditText.mCardBrand = Card.VISA; + mCardNumberEditText.mCardBrand = Card.CardBrand.VISA; assertEquals(6, mCardNumberEditText.updateSelectionIndex(10, 4, 1)); } @Test public void updateSelectionIndex_whenPastingIntoAGap_includesTheGapJump() { - mCardNumberEditText.mCardBrand = Card.UNKNOWN; + mCardNumberEditText.mCardBrand = Card.CardBrand.UNKNOWN; assertEquals(11, mCardNumberEditText.updateSelectionIndex(12, 8, 2)); } @Test public void updateSelectionIndex_whenPastingOverAGap_includesTheGapJump() { - mCardNumberEditText.mCardBrand = Card.UNKNOWN; + mCardNumberEditText.mCardBrand = Card.CardBrand.UNKNOWN; assertEquals(9, mCardNumberEditText.updateSelectionIndex(12, 3, 5)); } @Test public void updateSelectionIndex_whenIndexWouldGoOutOfBounds_setsToEndOfString() { - mCardNumberEditText.mCardBrand = Card.VISA; + mCardNumberEditText.mCardBrand = Card.CardBrand.VISA; // This case could happen when you paste over 5 digits with only 2 assertEquals(3, mCardNumberEditText.updateSelectionIndex(3, 3, 2)); } @@ -229,7 +229,7 @@ public void finishTypingAmEx_whenInvalid_setsErrorValueAndRemovesItAppropriately @Test public void setCardBrandChangeListener_callsSetCardBrand() { - verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.UNKNOWN); + verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.CardBrand.UNKNOWN); } @Test @@ -238,7 +238,7 @@ public void addVisaPrefix_callsBrandListener() { clearInvocations(mCardBrandChangeListener); // There is only one Visa Prefix. mCardNumberEditText.append(Card.PREFIXES_VISA[0]); - verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.VISA); + verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.CardBrand.VISA); } @Test @@ -247,7 +247,7 @@ public void addAmExPrefix_callsBrandListener() { // Reset inside the loop so we don't count each prefix clearInvocations(mCardBrandChangeListener); mCardNumberEditText.append(prefix); - verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.AMERICAN_EXPRESS); + verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.CardBrand.AMERICAN_EXPRESS); mCardNumberEditText.setText(""); } } @@ -257,7 +257,7 @@ public void addDinersClubPrefix_callsBrandListener() { for (String prefix : Card.PREFIXES_DINERS_CLUB) { clearInvocations(mCardBrandChangeListener); mCardNumberEditText.append(prefix); - verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.DINERS_CLUB); + verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.CardBrand.DINERS_CLUB); mCardNumberEditText.setText(""); } } @@ -267,7 +267,7 @@ public void addDiscoverPrefix_callsBrandListener() { for (String prefix : Card.PREFIXES_DISCOVER) { clearInvocations(mCardBrandChangeListener); mCardNumberEditText.append(prefix); - verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.DISCOVER); + verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.CardBrand.DISCOVER); mCardNumberEditText.setText(""); } } @@ -277,7 +277,7 @@ public void addMasterCardPrefix_callsBrandListener() { for (String prefix : Card.PREFIXES_MASTERCARD) { clearInvocations(mCardBrandChangeListener); mCardNumberEditText.append(prefix); - verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.MASTERCARD); + verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.CardBrand.MASTERCARD); mCardNumberEditText.setText(""); } } @@ -287,7 +287,7 @@ public void addJCBPrefix_callsBrandListener() { for (String prefix : Card.PREFIXES_JCB) { clearInvocations(mCardBrandChangeListener); mCardNumberEditText.append(prefix); - verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.JCB); + verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.CardBrand.JCB); mCardNumberEditText.setText(""); } } @@ -299,7 +299,7 @@ public void enterCompleteNumberInParts_onlyCallsBrandListenerOnce() { String suffix = VALID_AMEX_WITH_SPACES.substring(2); mCardNumberEditText.append(prefix); mCardNumberEditText.append(suffix); - verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.AMERICAN_EXPRESS); + verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.CardBrand.AMERICAN_EXPRESS); } @Test @@ -312,10 +312,10 @@ public void enterBrandPrefix_thenDelete_callsUpdateWithUnknown() { assertTrue(dinersPrefix.length() > 1); mCardNumberEditText.append(dinersPrefix); - verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.DINERS_CLUB); + verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.CardBrand.DINERS_CLUB); ViewTestUtils.sendDeleteKeyEvent(mCardNumberEditText); - verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.UNKNOWN); + verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.CardBrand.UNKNOWN); } @Test @@ -323,16 +323,16 @@ public void enterBrandPrefix_thenClearAllText_callsUpdateWithUnknown() { clearInvocations(mCardBrandChangeListener); String prefixVisa = Card.PREFIXES_VISA[0]; mCardNumberEditText.append(prefixVisa); - verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.VISA); + verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.CardBrand.VISA); // Just adding some other text. Not enough to invalidate the card or complete it. mCardNumberEditText.append("123"); - verify(mCardBrandChangeListener, times(0)).onCardBrandChanged(Card.UNKNOWN); + verify(mCardBrandChangeListener, times(0)).onCardBrandChanged(Card.CardBrand.UNKNOWN); // This simulates the user selecting all text and deleting it. mCardNumberEditText.setText(""); - verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.UNKNOWN); + verify(mCardBrandChangeListener, times(1)).onCardBrandChanged(Card.CardBrand.UNKNOWN); } @Test diff --git a/stripe/src/test/java/com/stripe/android/view/ShippingInfoWidgetTest.java b/stripe/src/test/java/com/stripe/android/view/ShippingInfoWidgetTest.java index 32197bde367..389ca6468cd 100644 --- a/stripe/src/test/java/com/stripe/android/view/ShippingInfoWidgetTest.java +++ b/stripe/src/test/java/com/stripe/android/view/ShippingInfoWidgetTest.java @@ -189,13 +189,13 @@ public void shippingInfoWidget_whenFieldsOptional_markedAsOptional(){ assertEquals(mPostalCodeTextInputLayout.getHint().toString(), mShippingInfoWidget.getResources().getString(R.string.address_label_zip_code)); assertEquals(mNameTextInputLayout.getHint().toString(), mShippingInfoWidget.getResources().getString(R.string.address_label_name)); List optionalFields = new ArrayList<>(); - optionalFields.add(ShippingInfoWidget.POSTAL_CODE_FIELD); + optionalFields.add(ShippingInfoWidget.CustomizableShippingField.POSTAL_CODE_FIELD); mShippingInfoWidget.setOptionalFields(optionalFields); assertEquals(mPostalCodeTextInputLayout.getHint().toString(), mShippingInfoWidget.getResources().getString(R.string.address_label_zip_code_optional)); assertEquals(mNameTextInputLayout.getHint().toString(), mShippingInfoWidget.getResources().getString(R.string.address_label_name)); mCountryAutoCompleteTextView.updateUIForCountryEntered(Locale.CANADA.getDisplayCountry()); assertEquals(mStateTextInputLayout.getHint().toString(), mShippingInfoWidget.getResources().getString(R.string.address_label_province)); - optionalFields.add(ShippingInfoWidget.STATE_FIELD); + optionalFields.add(ShippingInfoWidget.CustomizableShippingField.STATE_FIELD); mShippingInfoWidget.setOptionalFields(optionalFields); assertEquals(mStateTextInputLayout.getHint().toString(), mShippingInfoWidget.getResources().getString(R.string.address_label_province_optional)); } @@ -205,7 +205,7 @@ public void shippingInfoWidget_whenFieldsHidden_renderedHidden() { assertEquals(mNameTextInputLayout.getVisibility(), View.VISIBLE); assertEquals(mPostalCodeTextInputLayout.getVisibility(), View.VISIBLE); List hiddenFields = new ArrayList<>(); - hiddenFields.add(ShippingInfoWidget.POSTAL_CODE_FIELD); + hiddenFields.add(ShippingInfoWidget.CustomizableShippingField.POSTAL_CODE_FIELD); mShippingInfoWidget.setHiddenFields(hiddenFields); assertEquals(mPostalCodeTextInputLayout.getVisibility(), View.GONE); mCountryAutoCompleteTextView.updateUIForCountryEntered(Locale.CANADA.getDisplayCountry()); diff --git a/stripe/src/test/java/com/stripe/android/view/ViewUtilsTest.java b/stripe/src/test/java/com/stripe/android/view/ViewUtilsTest.java index fc0ab03a77b..6bc66c71ce6 100644 --- a/stripe/src/test/java/com/stripe/android/view/ViewUtilsTest.java +++ b/stripe/src/test/java/com/stripe/android/view/ViewUtilsTest.java @@ -72,7 +72,7 @@ public void isColorTransparent_whenColorIsNotCloseToTransparent_returnsFalse() { @Test public void separateCardNumberGroups_withVisa_returnsCorrectCardGroups() { String testCardNumber = "4000056655665556"; - String[] groups = ViewUtils.separateCardNumberGroups(testCardNumber, Card.VISA); + String[] groups = ViewUtils.separateCardNumberGroups(testCardNumber, Card.CardBrand.VISA); assertEquals(4, groups.length); assertEquals("4000", groups[0]); assertEquals("0566", groups[1]); @@ -84,7 +84,7 @@ public void separateCardNumberGroups_withVisa_returnsCorrectCardGroups() { public void separateCardNumberGroups_withAmex_returnsCorrectCardGroups() { String testCardNumber = "378282246310005"; String[] groups = - ViewUtils.separateCardNumberGroups(testCardNumber, Card.AMERICAN_EXPRESS); + ViewUtils.separateCardNumberGroups(testCardNumber, Card.CardBrand.AMERICAN_EXPRESS); assertEquals(3, groups.length); assertEquals("3782", groups[0]); assertEquals("822463", groups[1]); @@ -95,7 +95,7 @@ public void separateCardNumberGroups_withAmex_returnsCorrectCardGroups() { public void separateCardNumberGroups_withDinersClub_returnsCorrectCardGroups() { String testCardNumber = "38520000023237"; String[] groups = - ViewUtils.separateCardNumberGroups(testCardNumber, Card.DINERS_CLUB); + ViewUtils.separateCardNumberGroups(testCardNumber, Card.CardBrand.DINERS_CLUB); assertEquals(4, groups.length); assertEquals("3852", groups[0]); assertEquals("0000", groups[1]); @@ -106,7 +106,7 @@ public void separateCardNumberGroups_withDinersClub_returnsCorrectCardGroups() { @Test public void separateCardNumberGroups_withInvalid_returnsCorrectCardGroups() { String testCardNumber = "1234056655665556"; - String[] groups = ViewUtils.separateCardNumberGroups(testCardNumber, Card.UNKNOWN); + String[] groups = ViewUtils.separateCardNumberGroups(testCardNumber, Card.CardBrand.UNKNOWN); assertEquals(4, groups.length); assertEquals("1234", groups[0]); assertEquals("0566", groups[1]); @@ -118,21 +118,21 @@ public void separateCardNumberGroups_withInvalid_returnsCorrectCardGroups() { public void separateCardNumberGroups_withAmexPrefix_returnsPrefixGroups() { String testCardNumber = "378282246310005"; String[] groups = ViewUtils.separateCardNumberGroups( - testCardNumber.substring(0, 2), Card.AMERICAN_EXPRESS); + testCardNumber.substring(0, 2), Card.CardBrand.AMERICAN_EXPRESS); assertEquals(3, groups.length); assertEquals("37", groups[0]); assertNull(groups[1]); assertNull(groups[2]); groups = ViewUtils.separateCardNumberGroups( - testCardNumber.substring(0, 5), Card.AMERICAN_EXPRESS); + testCardNumber.substring(0, 5), Card.CardBrand.AMERICAN_EXPRESS); assertEquals(3, groups.length); assertEquals("3782", groups[0]); assertEquals("8", groups[1]); assertNull(groups[2]); groups = ViewUtils.separateCardNumberGroups( - testCardNumber.substring(0, 11), Card.AMERICAN_EXPRESS); + testCardNumber.substring(0, 11), Card.CardBrand.AMERICAN_EXPRESS); assertEquals(3, groups.length); assertEquals("3782", groups[0]); assertEquals("822463", groups[1]); @@ -143,7 +143,7 @@ public void separateCardNumberGroups_withAmexPrefix_returnsPrefixGroups() { public void separateCardNumberGroups_withVisaPrefix_returnsCorrectGroups() { String testCardNumber = "4000056655665556"; String[] groups = ViewUtils.separateCardNumberGroups( - testCardNumber.substring(0, 2), Card.VISA); + testCardNumber.substring(0, 2), Card.CardBrand.VISA); assertEquals(4, groups.length); assertEquals("40", groups[0]); assertNull(groups[1]); @@ -151,7 +151,7 @@ public void separateCardNumberGroups_withVisaPrefix_returnsCorrectGroups() { assertNull(groups[3]); groups = ViewUtils.separateCardNumberGroups( - testCardNumber.substring(0, 5), Card.VISA); + testCardNumber.substring(0, 5), Card.CardBrand.VISA); assertEquals(4, groups.length); assertEquals("4000", groups[0]); assertEquals("0", groups[1]); @@ -159,7 +159,7 @@ public void separateCardNumberGroups_withVisaPrefix_returnsCorrectGroups() { assertNull(groups[3]); groups = ViewUtils.separateCardNumberGroups( - testCardNumber.substring(0, 9), Card.VISA); + testCardNumber.substring(0, 9), Card.CardBrand.VISA); assertEquals(4, groups.length); assertEquals("4000", groups[0]); assertEquals("0566", groups[1]); @@ -167,7 +167,7 @@ public void separateCardNumberGroups_withVisaPrefix_returnsCorrectGroups() { assertNull(groups[3]); groups = ViewUtils.separateCardNumberGroups( - testCardNumber.substring(0, 15), Card.VISA); + testCardNumber.substring(0, 15), Card.CardBrand.VISA); assertEquals(4, groups.length); assertEquals("4000", groups[0]); assertEquals("0566", groups[1]); @@ -177,53 +177,53 @@ public void separateCardNumberGroups_withVisaPrefix_returnsCorrectGroups() { @Test public void isCvcMaximalLength_whenThreeDigitsAndNotAmEx_returnsTrue() { - assertTrue(ViewUtils.isCvcMaximalLength(Card.VISA, "123")); - assertTrue(ViewUtils.isCvcMaximalLength(Card.MASTERCARD, "345")); - assertTrue(ViewUtils.isCvcMaximalLength(Card.JCB, "678")); - assertTrue(ViewUtils.isCvcMaximalLength(Card.DINERS_CLUB, "910")); - assertTrue(ViewUtils.isCvcMaximalLength(Card.DISCOVER, "234")); - assertTrue(ViewUtils.isCvcMaximalLength(Card.UNKNOWN, "333")); + assertTrue(ViewUtils.isCvcMaximalLength(Card.CardBrand.VISA, "123")); + assertTrue(ViewUtils.isCvcMaximalLength(Card.CardBrand.MASTERCARD, "345")); + assertTrue(ViewUtils.isCvcMaximalLength(Card.CardBrand.JCB, "678")); + assertTrue(ViewUtils.isCvcMaximalLength(Card.CardBrand.DINERS_CLUB, "910")); + assertTrue(ViewUtils.isCvcMaximalLength(Card.CardBrand.DISCOVER, "234")); + assertTrue(ViewUtils.isCvcMaximalLength(Card.CardBrand.UNKNOWN, "333")); } @Test public void isCvcMaximalLength_whenThreeDigitsAndIsAmEx_returnsFalse() { - assertFalse(ViewUtils.isCvcMaximalLength(Card.AMERICAN_EXPRESS, "123")); + assertFalse(ViewUtils.isCvcMaximalLength(Card.CardBrand.AMERICAN_EXPRESS, "123")); } @Test public void isCvcMaximalLength_whenFourDigitsAndIsAmEx_returnsTrue() { - assertTrue(ViewUtils.isCvcMaximalLength(Card.AMERICAN_EXPRESS, "1234")); + assertTrue(ViewUtils.isCvcMaximalLength(Card.CardBrand.AMERICAN_EXPRESS, "1234")); } @Test public void isCvcMaximalLength_whenTooManyDigits_returnsFalse() { - assertFalse(ViewUtils.isCvcMaximalLength(Card.AMERICAN_EXPRESS, "12345")); - assertFalse(ViewUtils.isCvcMaximalLength(Card.VISA, "1234")); - assertFalse(ViewUtils.isCvcMaximalLength(Card.MASTERCARD, "123456")); - assertFalse(ViewUtils.isCvcMaximalLength(Card.DINERS_CLUB, "1234567")); - assertFalse(ViewUtils.isCvcMaximalLength(Card.DISCOVER, "12345678")); - assertFalse(ViewUtils.isCvcMaximalLength(Card.JCB, "123456789012345")); + assertFalse(ViewUtils.isCvcMaximalLength(Card.CardBrand.AMERICAN_EXPRESS, "12345")); + assertFalse(ViewUtils.isCvcMaximalLength(Card.CardBrand.VISA, "1234")); + assertFalse(ViewUtils.isCvcMaximalLength(Card.CardBrand.MASTERCARD, "123456")); + assertFalse(ViewUtils.isCvcMaximalLength(Card.CardBrand.DINERS_CLUB, "1234567")); + assertFalse(ViewUtils.isCvcMaximalLength(Card.CardBrand.DISCOVER, "12345678")); + assertFalse(ViewUtils.isCvcMaximalLength(Card.CardBrand.JCB, "123456789012345")); } @Test public void isCvcMaximalLength_whenNotEnoughDigits_returnsFalse() { - assertFalse(ViewUtils.isCvcMaximalLength(Card.AMERICAN_EXPRESS, "")); - assertFalse(ViewUtils.isCvcMaximalLength(Card.VISA, "1")); - assertFalse(ViewUtils.isCvcMaximalLength(Card.MASTERCARD, "12")); - assertFalse(ViewUtils.isCvcMaximalLength(Card.DINERS_CLUB, "")); - assertFalse(ViewUtils.isCvcMaximalLength(Card.DISCOVER, "8")); - assertFalse(ViewUtils.isCvcMaximalLength(Card.JCB, "1")); + assertFalse(ViewUtils.isCvcMaximalLength(Card.CardBrand.AMERICAN_EXPRESS, "")); + assertFalse(ViewUtils.isCvcMaximalLength(Card.CardBrand.VISA, "1")); + assertFalse(ViewUtils.isCvcMaximalLength(Card.CardBrand.MASTERCARD, "12")); + assertFalse(ViewUtils.isCvcMaximalLength(Card.CardBrand.DINERS_CLUB, "")); + assertFalse(ViewUtils.isCvcMaximalLength(Card.CardBrand.DISCOVER, "8")); + assertFalse(ViewUtils.isCvcMaximalLength(Card.CardBrand.JCB, "1")); } @Test public void isCvcMaximalLength_whenWhitespaceAndNotEnoughDigits_returnsFalse() { - assertFalse(ViewUtils.isCvcMaximalLength(Card.AMERICAN_EXPRESS, " ")); - assertFalse(ViewUtils.isCvcMaximalLength(Card.VISA, " 1")); + assertFalse(ViewUtils.isCvcMaximalLength(Card.CardBrand.AMERICAN_EXPRESS, " ")); + assertFalse(ViewUtils.isCvcMaximalLength(Card.CardBrand.VISA, " 1")); } @Test public void isCvcMaximalLength_whenNull_returnsFalse() { - assertFalse(ViewUtils.isCvcMaximalLength(Card.AMERICAN_EXPRESS, null)); + assertFalse(ViewUtils.isCvcMaximalLength(Card.CardBrand.AMERICAN_EXPRESS, null)); } @Test @@ -260,7 +260,7 @@ public void isColorDark_forExampleDarkColors_returnsTrue() { public void separateCardNumberGroups_forLongInputs_doesNotCrash() { String testCardNumber = "1234567890123456789"; String[] groups = ViewUtils.separateCardNumberGroups( - testCardNumber, Card.VISA); + testCardNumber, Card.CardBrand.VISA); assertEquals(4, groups.length); } }