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

Make StripeSourceTypeModel public #809

Merged
merged 1 commit into from
Feb 26, 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
34 changes: 19 additions & 15 deletions stripe/src/main/java/com/stripe/android/model/SourceCardData.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static com.stripe.android.model.StripeJsonUtils.optInteger;
import static com.stripe.android.model.StripeJsonUtils.optString;
Expand Down Expand Up @@ -51,6 +54,20 @@ public class SourceCardData extends StripeSourceTypeModel {
public static final String FIELD_THREE_D_SECURE = "three_d_secure";
public static final String FIELD_TOKENIZATION_METHOD = "tokenization_method";

private static final Set<String> STANDARD_FIELDS = new HashSet<>(Arrays.asList(
FIELD_ADDRESS_LINE1_CHECK,
FIELD_ADDRESS_ZIP_CHECK,
FIELD_BRAND,
FIELD_COUNTRY,
FIELD_CVC_CHECK,
FIELD_DYNAMIC_LAST4,
FIELD_EXP_MONTH,
FIELD_EXP_YEAR,
FIELD_FUNDING,
FIELD_LAST4,
FIELD_THREE_D_SECURE,
FIELD_TOKENIZATION_METHOD));

private String mAddressLine1Check;
private String mAddressZipCheck;
private @Card.CardBrand String mBrand;
Expand All @@ -65,20 +82,7 @@ public class SourceCardData extends StripeSourceTypeModel {
private String mTokenizationMethod;

private SourceCardData() {
super();
addStandardFields(
FIELD_ADDRESS_LINE1_CHECK,
FIELD_ADDRESS_ZIP_CHECK,
FIELD_BRAND,
FIELD_COUNTRY,
FIELD_CVC_CHECK,
FIELD_DYNAMIC_LAST4,
FIELD_EXP_MONTH,
FIELD_EXP_YEAR,
FIELD_FUNDING,
FIELD_LAST4,
FIELD_THREE_D_SECURE,
FIELD_TOKENIZATION_METHOD);
super(STANDARD_FIELDS);
}

@Nullable
Expand Down Expand Up @@ -286,7 +290,7 @@ static SourceCardData fromString(String jsonString) {

@Nullable
@ThreeDSecureStatus
static String asThreeDSecureStatus(@Nullable String threeDSecureStatus) {
private static String asThreeDSecureStatus(@Nullable String threeDSecureStatus) {
String nullChecked = StripeJsonUtils.nullIfNullOrEmpty(threeDSecureStatus);
if (nullChecked == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static com.stripe.android.model.StripeJsonUtils.optString;
import static com.stripe.android.model.StripeJsonUtils.putStringIfNotNull;
Expand All @@ -28,6 +31,15 @@ public class SourceSepaDebitData extends StripeSourceTypeModel {
private static final String FIELD_MANDATE_REFERENCE = "mandate_reference";
private static final String FIELD_MANDATE_URL = "mandate_url";

private static final Set<String> STANDARD_FIELDS = new HashSet<>(Arrays.asList(
FIELD_BANK_CODE,
FIELD_BRANCH_CODE,
FIELD_COUNTRY,
FIELD_FINGERPRINT,
FIELD_LAST4,
FIELD_MANDATE_REFERENCE,
FIELD_MANDATE_URL));

private String mBankCode;
private String mBranchCode;
private String mCountry;
Expand All @@ -37,15 +49,7 @@ public class SourceSepaDebitData extends StripeSourceTypeModel {
private String mMandateUrl;

private SourceSepaDebitData() {
super();
addStandardFields(
FIELD_BANK_CODE,
FIELD_BRANCH_CODE,
FIELD_COUNTRY,
FIELD_FINGERPRINT,
FIELD_LAST4,
FIELD_MANDATE_REFERENCE,
FIELD_MANDATE_URL);
super(STANDARD_FIELDS);
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
import java.util.Map;
import java.util.Set;

abstract class StripeSourceTypeModel extends StripeJsonModel {
public abstract class StripeSourceTypeModel extends StripeJsonModel {
private static final String NULL = "null";

Map<String, Object> mAdditionalFields;
Set<String> mStandardFields = new HashSet<>();
private static final String NULL = "null";
@NonNull final Set<String> mStandardFields;

StripeSourceTypeModel() {
StripeSourceTypeModel(@NonNull Set<String> standardFields) {
mStandardFields = standardFields;
mAdditionalFields = new HashMap<>();
}

Expand All @@ -29,10 +30,6 @@ public Map<String, Object> getAdditionalFields() {
return mAdditionalFields;
}

void addStandardFields(String... fields) {
Collections.addAll(mStandardFields, fields);
}

void setAdditionalFields(@NonNull Map<String, Object> additionalFields) {
mAdditionalFields = additionalFields;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public class SourceCardDataTest {

@Test
public void fromExampleJsonCard_createsExpectedObject() {
SourceCardData cardData = SourceCardData.fromString(EXAMPLE_JSON_SOURCE_CARD_DATA_WITH_APPLE_PAY);
final SourceCardData cardData = SourceCardData
.fromString(EXAMPLE_JSON_SOURCE_CARD_DATA_WITH_APPLE_PAY);
assertNotNull(cardData);
assertEquals(Card.VISA, cardData.getBrand());
assertEquals(0, cardData.getAdditionalFields().size());
Expand All @@ -41,9 +42,11 @@ public void fromExampleJsonCard_createsExpectedObject() {

@Test
public void fromExampleJsonCard_toMap_createsExpectedMapping() {
SourceCardData cardData = SourceCardData.fromString(EXAMPLE_JSON_SOURCE_CARD_DATA_WITH_APPLE_PAY);
Map<String, Object> cardDataMap = cardData.toMap();
final SourceCardData cardData = SourceCardData
.fromString(EXAMPLE_JSON_SOURCE_CARD_DATA_WITH_APPLE_PAY);
assertNotNull(cardData);

final Map<String, Object> cardDataMap = cardData.toMap();
assertNotNull(cardDataMap);
assertEquals("US", cardDataMap.get("country"));
assertEquals("4242", cardDataMap.get("last4"));
Expand Down