Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline all StringDef values #1173

Merged
merged 1 commit into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 17 additions & 17 deletions stripe/src/main/java/com/stripe/android/CardUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -96,33 +96,33 @@ 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;
}
}

@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;
Expand All @@ -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;
}
}
}
81 changes: 40 additions & 41 deletions stripe/src/main/java/com/stripe/android/LoggingUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -118,7 +117,7 @@ Map<String, Object> getTokenCreationParams(
productUsageTokens,
null,
tokenType,
publishableApiKey, EVENT_TOKEN_CREATION);
publishableApiKey, EventName.TOKEN_CREATION);
}

@NonNull
Expand All @@ -129,7 +128,7 @@ Map<String, Object> getPaymentMethodCreationParams(
productUsageTokens,
null,
null,
publishableApiKey, EVENT_ADD_PAYMENT_METHOD);
publishableApiKey, EventName.ADD_PAYMENT_METHOD);
}

@NonNull
Expand All @@ -141,7 +140,7 @@ Map<String, Object> getSourceCreationParams(
productUsageTokens,
sourceType,
null,
publishableApiKey, EVENT_SOURCE_CREATION);
publishableApiKey, EventName.SOURCE_CREATION);
}

@NonNull
Expand All @@ -153,7 +152,7 @@ Map<String, Object> getAddSourceParams(
productUsageTokens,
sourceType,
null,
publishableKey, EVENT_ADD_SOURCE);
publishableKey, EventName.ADD_SOURCE);
}

@NonNull
Expand All @@ -164,7 +163,7 @@ Map<String, Object> getDeleteSourceParams(
productUsageTokens,
null,
null,
publishableKey, EVENT_DELETE_SOURCE);
publishableKey, EventName.DELETE_SOURCE);
}

@NonNull
Expand All @@ -175,7 +174,7 @@ Map<String, Object> getAttachPaymentMethodParams(
productUsageTokens,
null,
null,
publishableKey, EVENT_ATTACH_PAYMENT_METHOD);
publishableKey, EventName.ATTACH_PAYMENT_METHOD);
}

@NonNull
Expand All @@ -186,7 +185,7 @@ Map<String, Object> getDetachPaymentMethodParams(
productUsageTokens,
null,
null,
publishableKey, EVENT_DETACH_PAYMENT_METHOD);
publishableKey, EventName.DETACH_PAYMENT_METHOD);
}

@NonNull
Expand All @@ -198,7 +197,7 @@ Map<String, Object> getPaymentIntentConfirmationParams(
productUsageTokens,
sourceType,
null,
publishableApiKey, EVENT_CONFIRM_PAYMENT_INTENT);
publishableApiKey, EventName.CONFIRM_PAYMENT_INTENT);
}

@NonNull
Expand All @@ -209,7 +208,7 @@ Map<String, Object> getPaymentIntentRetrieveParams(
productUsageTokens,
null,
null,
publishableApiKey, EVENT_RETRIEVE_PAYMENT_INTENT);
publishableApiKey, EventName.RETRIEVE_PAYMENT_INTENT);
}

@NonNull
Expand All @@ -220,7 +219,7 @@ Map<String, Object> getSetupIntentConfirmationParams(
productUsageTokens,
null,
null,
publishableApiKey, EVENT_CONFIRM_SETUP_INTENT);
publishableApiKey, EventName.CONFIRM_SETUP_INTENT);
}

@NonNull
Expand All @@ -231,7 +230,7 @@ Map<String, Object> getSetupIntentRetrieveParams(
productUsageTokens,
null,
null,
publishableApiKey, EVENT_RETRIEVE_SETUP_INTENT);
publishableApiKey, EventName.RETRIEVE_SETUP_INTENT);
}

@NonNull
Expand All @@ -240,7 +239,7 @@ Map<String, Object> getEventLoggingParams(
@Nullable @Source.SourceType String sourceType,
@Nullable @Token.TokenType String tokenType,
@NonNull String publishableApiKey,
@NonNull @LoggingEventName String eventName) {
@NonNull @EventName String eventName) {
final Map<String, Object> paramsObject = new HashMap<>();
paramsObject.put(FIELD_ANALYTICS_UA, getAnalyticsUa());
paramsObject.put(FIELD_EVENT, getEventParamName(eventName));
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions stripe/src/main/java/com/stripe/android/Stripe.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public void createBankAccountToken(
createTokenFromParams(
mStripeNetworkUtils.createBankAccountTokenParams(bankAccount),
publishableKey,
Token.TYPE_BANK_ACCOUNT,
Token.TokenType.BANK_ACCOUNT,
executor,
callback);
}
Expand Down Expand Up @@ -321,7 +321,7 @@ public void createPiiToken(
createTokenFromParams(
createPersonalIdTokenParams(personalId),
publishableKey,
Token.TYPE_PII,
Token.TokenType.PII,
executor,
callback);
}
Expand Down Expand Up @@ -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
);
}

Expand Down Expand Up @@ -412,7 +412,7 @@ public void createCvcUpdateToken(
createTokenFromParams(
createUpdateCvcTokenParams(cvc),
publishableKey,
Token.TYPE_CVC_UPDATE,
Token.TokenType.CVC_UPDATE,
executor,
callback);
}
Expand Down Expand Up @@ -538,7 +538,7 @@ public void createToken(
createTokenFromParams(
mStripeNetworkUtils.createCardTokenParams(card),
publishableKey,
Token.TYPE_CARD,
Token.TokenType.CARD,
executor,
callback);
}
Expand Down Expand Up @@ -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
);
}

Expand Down Expand Up @@ -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
);
}

Expand Down Expand Up @@ -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
);
}

Expand Down Expand Up @@ -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.
Expand Down
Loading