Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove StripeJsonModel#toJson()
Browse files Browse the repository at this point in the history
`toJson()` was previously used in the implementation of `equals()`
(see #813). Now that it is no longer used in `equals()`, it is
no longer needed.
mshafrir-stripe committed Jun 10, 2019
1 parent 84c6fdc commit 21f3061
Showing 48 changed files with 51 additions and 1,069 deletions.
Original file line number Diff line number Diff line change
@@ -158,7 +158,7 @@ private void retrievePaymentIntent() {
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
paymentIntent -> mPaymentIntentValue.setText(paymentIntent != null ?
paymentIntent.toJson().toString() :
new JSONObject(paymentIntent.toMap()).toString() :
getString(R.string.error_while_retrieving_payment_intent)),
throwable -> Log.e(TAG, throwable.toString())
);
@@ -188,7 +188,8 @@ private void confirmPaymentIntent(@NonNull final Card card) {
.subscribe(
paymentIntent -> {
if (paymentIntent != null) {
mPaymentIntentValue.setText(paymentIntent.toJson().toString());
mPaymentIntentValue
.setText(new JSONObject(paymentIntent.toMap()).toString());

if (paymentIntent.requiresAction()) {
Toast.makeText(PaymentIntentActivity.this,
29 changes: 0 additions & 29 deletions stripe/src/main/java/com/stripe/android/EphemeralKey.java
Original file line number Diff line number Diff line change
@@ -84,35 +84,6 @@ abstract class EphemeralKey extends StripeJsonModel implements Parcelable {
mType = type;
}

@NonNull
@Override
public JSONObject toJson() {
JSONObject jsonObject = new JSONObject();
JSONArray associatedObjectsArray = new JSONArray();
JSONObject associatedObject = new JSONObject();

try {
jsonObject.put(FIELD_CREATED, mCreated);
jsonObject.put(FIELD_EXPIRES, mExpires);
jsonObject.put(FIELD_OBJECT, mObject);
jsonObject.put(FIELD_ID, mId);
jsonObject.put(FIELD_SECRET, mSecret);
jsonObject.put(FIELD_LIVEMODE, mLiveMode);

associatedObject.put(FIELD_TYPE, mType);
associatedObject.put(FIELD_ID, mObjectId);
associatedObjectsArray.put(associatedObject);

jsonObject.put(FIELD_ASSOCIATED_OBJECTS, associatedObjectsArray);
} catch (JSONException impossible) {
// An exception can only be thrown from put operations if the key is null
// or the value is a non-finite number.
throw new IllegalArgumentException("JSONObject creation exception thrown.");
}

return jsonObject;
}

@NonNull
@Override
public Map<String, Object> toMap() {
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.stripe.android;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

/**
* Represents a listener for Ephemeral Key Update events.
14 changes: 0 additions & 14 deletions stripe/src/main/java/com/stripe/android/model/Address.java
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@
import java.util.Map;

import static com.stripe.android.model.StripeJsonUtils.optString;
import static com.stripe.android.model.StripeJsonUtils.putStringIfNotNull;

/**
* Model for an owner <a href="https://stripe.com/docs/api#source_object-owner-address">address</a>
@@ -141,19 +140,6 @@ public Map<String, Object> toMap() {
return map;
}

@NonNull
@Override
public JSONObject toJson() {
final JSONObject jsonObject = new JSONObject();
putStringIfNotNull(jsonObject, FIELD_CITY, mCity);
putStringIfNotNull(jsonObject, FIELD_COUNTRY, mCountry);
putStringIfNotNull(jsonObject, FIELD_LINE_1, mLine1);
putStringIfNotNull(jsonObject, FIELD_LINE_2, mLine2);
putStringIfNotNull(jsonObject, FIELD_POSTAL_CODE, mPostalCode);
putStringIfNotNull(jsonObject, FIELD_STATE, mState);
return jsonObject;
}

@Nullable
public static Address fromString(@Nullable String jsonString) {
try {
33 changes: 0 additions & 33 deletions stripe/src/main/java/com/stripe/android/model/Card.java
Original file line number Diff line number Diff line change
@@ -30,9 +30,6 @@
import static com.stripe.android.model.StripeJsonUtils.optHash;
import static com.stripe.android.model.StripeJsonUtils.optInteger;
import static com.stripe.android.model.StripeJsonUtils.optString;
import static com.stripe.android.model.StripeJsonUtils.putIntegerIfNotNull;
import static com.stripe.android.model.StripeJsonUtils.putStringHashIfNotNull;
import static com.stripe.android.model.StripeJsonUtils.putStringIfNotNull;

/**
* A model object representing a Card in the Android SDK.
@@ -790,36 +787,6 @@ public String getCvcCheck() {
return cvcCheck;
}

@NonNull
@Override
public JSONObject toJson() {
final JSONObject object = new JSONObject();
putStringIfNotNull(object, FIELD_NAME, name);
putStringIfNotNull(object, FIELD_ADDRESS_CITY, addressCity);
putStringIfNotNull(object, FIELD_ADDRESS_COUNTRY, addressCountry);
putStringIfNotNull(object, FIELD_ADDRESS_LINE1, addressLine1);
putStringIfNotNull(object, FIELD_ADDRESS_LINE1_CHECK, addressLine1Check);
putStringIfNotNull(object, FIELD_ADDRESS_LINE2, addressLine2);
putStringIfNotNull(object, FIELD_ADDRESS_STATE, addressState);
putStringIfNotNull(object, FIELD_ADDRESS_ZIP, addressZip);
putStringIfNotNull(object, FIELD_ADDRESS_ZIP_CHECK, addressZipCheck);
putStringIfNotNull(object, FIELD_BRAND, brand);
putStringIfNotNull(object, FIELD_CURRENCY, currency);
putStringIfNotNull(object, FIELD_COUNTRY, country);
putStringIfNotNull(object, FIELD_CUSTOMER, customerId);
putIntegerIfNotNull(object, FIELD_EXP_MONTH, expMonth);
putIntegerIfNotNull(object, FIELD_EXP_YEAR, expYear);
putStringIfNotNull(object, FIELD_FINGERPRINT, fingerprint);
putStringIfNotNull(object, FIELD_FUNDING, funding);
putStringIfNotNull(object, FIELD_CVC_CHECK, cvcCheck);
putStringIfNotNull(object, FIELD_LAST4, last4);
putStringIfNotNull(object, FIELD_ID, id);
putStringIfNotNull(object, FIELD_TOKENIZATION_METHOD, tokenizationMethod);
putStringHashIfNotNull(object, FIELD_METADATA, metadata);
putStringIfNotNull(object, FIELD_OBJECT, VALUE_CARD);
return object;
}

@NonNull
@Override
public Map<String, Object> toMap() {
26 changes: 0 additions & 26 deletions stripe/src/main/java/com/stripe/android/model/Customer.java
Original file line number Diff line number Diff line change
@@ -19,10 +19,6 @@
import static com.stripe.android.model.StripeJsonUtils.optBoolean;
import static com.stripe.android.model.StripeJsonUtils.optInteger;
import static com.stripe.android.model.StripeJsonUtils.optString;
import static com.stripe.android.model.StripeJsonUtils.putBooleanIfNotNull;
import static com.stripe.android.model.StripeJsonUtils.putIntegerIfNotNull;
import static com.stripe.android.model.StripeJsonUtils.putObjectIfNotNull;
import static com.stripe.android.model.StripeJsonUtils.putStringIfNotNull;

/**
* Model for a Stripe Customer object
@@ -105,28 +101,6 @@ public CustomerSource getSourceById(@NonNull String sourceId) {
return null;
}

@NonNull
@Override
public JSONObject toJson() {
JSONObject jsonObject = new JSONObject();
putStringIfNotNull(jsonObject, FIELD_ID, mId);
putStringIfNotNull(jsonObject, FIELD_OBJECT, VALUE_CUSTOMER);
putStringIfNotNull(jsonObject, FIELD_DEFAULT_SOURCE, mDefaultSource);
StripeJsonModel.putStripeJsonModelIfNotNull(jsonObject,
FIELD_SHIPPING,
mShippingInformation);
JSONObject sourcesObject = new JSONObject();
putStringIfNotNull(sourcesObject, FIELD_OBJECT, VALUE_LIST);
putBooleanIfNotNull(sourcesObject, FIELD_HAS_MORE, mHasMore);
putIntegerIfNotNull(sourcesObject, FIELD_TOTAL_COUNT, mTotalCount);
putStripeJsonModelListIfNotNull(sourcesObject, FIELD_DATA, mSources);
putStringIfNotNull(sourcesObject, FIELD_URL, mUrl);

putObjectIfNotNull(jsonObject, FIELD_SOURCES, sourcesObject);

return jsonObject;
}

@NonNull
@Override
public Map<String, Object> toMap() {
11 changes: 0 additions & 11 deletions stripe/src/main/java/com/stripe/android/model/CustomerSource.java
Original file line number Diff line number Diff line change
@@ -121,17 +121,6 @@ public Map<String, Object> toMap() {
return new HashMap<>();
}

@NonNull
@Override
public JSONObject toJson() {
if (mStripePaymentSource instanceof Source) {
return ((Source) mStripePaymentSource).toJson();
} else if (mStripePaymentSource instanceof Card) {
return ((Card) mStripePaymentSource).toJson();
}
return new JSONObject();
}

@Override
public boolean equals(@Nullable Object obj) {
return this == obj || (obj instanceof CustomerSource && typedEquals((CustomerSource) obj));
30 changes: 0 additions & 30 deletions stripe/src/main/java/com/stripe/android/model/PaymentIntent.java
Original file line number Diff line number Diff line change
@@ -19,17 +19,11 @@
import java.util.Map;
import java.util.Objects;

import static com.stripe.android.model.StripeJsonUtils.listToJsonArray;
import static com.stripe.android.model.StripeJsonUtils.optBoolean;
import static com.stripe.android.model.StripeJsonUtils.optCurrency;
import static com.stripe.android.model.StripeJsonUtils.optLong;
import static com.stripe.android.model.StripeJsonUtils.optMap;
import static com.stripe.android.model.StripeJsonUtils.optString;
import static com.stripe.android.model.StripeJsonUtils.putArrayIfNotNull;
import static com.stripe.android.model.StripeJsonUtils.putBooleanIfNotNull;
import static com.stripe.android.model.StripeJsonUtils.putLongIfNotNull;
import static com.stripe.android.model.StripeJsonUtils.putMapIfNotNull;
import static com.stripe.android.model.StripeJsonUtils.putStringIfNotNull;

/**
* A PaymentIntent tracks the process of collecting a payment from your customer.
@@ -328,30 +322,6 @@ private static List<String> jsonArrayToList(@Nullable JSONArray jsonArray) {
return list;
}

@NonNull
@Override
public JSONObject toJson() {
final JSONObject jsonObject = new JSONObject();
putStringIfNotNull(jsonObject, FIELD_ID, mId);
putStringIfNotNull(jsonObject, FIELD_OBJECT, mObjectType);
putArrayIfNotNull(jsonObject, FIELD_PAYMENT_METHOD_TYPES,
listToJsonArray(mPaymentMethodTypes));
putLongIfNotNull(jsonObject, FIELD_AMOUNT, mAmount);
putLongIfNotNull(jsonObject, FIELD_CANCELED, mCanceledAt);
putStringIfNotNull(jsonObject, FIELD_CAPTURE_METHOD, mCaptureMethod);
putStringIfNotNull(jsonObject, FIELD_CLIENT_SECRET, mClientSecret);
putStringIfNotNull(jsonObject, FIELD_CONFIRMATION_METHOD, mConfirmationMethod);
putLongIfNotNull(jsonObject, FIELD_CREATED, mCreated);
putStringIfNotNull(jsonObject, FIELD_CURRENCY, mCurrency);
putStringIfNotNull(jsonObject, FIELD_DESCRIPTION, mDescription);
putBooleanIfNotNull(jsonObject, FIELD_LIVEMODE, mLiveMode);
putMapIfNotNull(jsonObject, FIELD_NEXT_ACTION, mNextAction);
putStringIfNotNull(jsonObject, FIELD_RECEIPT_EMAIL, mReceiptEmail);
putStringIfNotNull(jsonObject, FIELD_SOURCE, mSource);
putStringIfNotNull(jsonObject, FIELD_STATUS, mStatus != null ? mStatus.code : null);
return jsonObject;
}

@NonNull
@Override
public Map<String, Object> toMap() {
103 changes: 0 additions & 103 deletions stripe/src/main/java/com/stripe/android/model/PaymentMethod.java
Original file line number Diff line number Diff line change
@@ -110,31 +110,6 @@ public Map<String, Object> toMap() {
return paymentMethod;
}

@NonNull
@Override
public JSONObject toJson() {
final JSONObject paymentMethod = new JSONObject();
try {
paymentMethod.put(FIELD_ID, id);
paymentMethod.put(FIELD_CREATED, created);
paymentMethod.put(FIELD_CUSTOMER, customerId);
paymentMethod.put(FIELD_LIVEMODE, liveMode);
paymentMethod.put(FIELD_METADATA, metadata != null ? new JSONObject(metadata) : null);
paymentMethod.put(FIELD_TYPE, type);
paymentMethod.put(FIELD_BILLING_DETAILS,
billingDetails != null ? billingDetails.toJson() : null);
paymentMethod.put(FIELD_CARD,
card != null ? card.toJson() : null);
paymentMethod.put(FIELD_CARD_PRESENT,
cardPresent != null ? cardPresent.toJson() : null);
paymentMethod.put(FIELD_IDEAL,
ideal != null ? ideal.toJson() : null);
} catch (JSONException e) {
throw new RuntimeException(e);
}
return paymentMethod;
}

@Nullable
public static PaymentMethod fromString(@Nullable String jsonString) {
if (jsonString == null) {
@@ -414,21 +389,6 @@ public Map<String, Object> toMap() {
return billingDetails;
}

@NonNull
@Override
public JSONObject toJson() {
final JSONObject billingDetails = new JSONObject();
try {
billingDetails.put(FIELD_ADDRESS, address != null ? address.toJson() : null);
billingDetails.put(FIELD_EMAIL, email);
billingDetails.put(FIELD_NAME, name);
billingDetails.put(FIELD_PHONE, phone);
} catch (JSONException e) {
throw new RuntimeException(e);
}
return billingDetails;
}

@Nullable
public static BillingDetails fromJson(@Nullable JSONObject billingDetails) {
if (billingDetails == null) {
@@ -625,26 +585,6 @@ public Map<String, Object> toMap() {
return map;
}

@NonNull
@Override
public JSONObject toJson() {
final JSONObject json = new JSONObject();
try {
json.put(FIELD_BRAND, brand);
json.put(FIELD_CHECKS, checks != null ? checks.toJson() : null);
json.put(FIELD_COUNTRY, country);
json.put(FIELD_EXP_MONTH, expiryMonth);
json.put(FIELD_EXP_YEAR, expiryYear);
json.put(FIELD_FUNDING, funding);
json.put(FIELD_LAST4, last4);
json.put(FIELD_THREE_D_SECURE_USAGE, threeDSecureUsage != null ?
threeDSecureUsage.toJson() : null);
json.put(FIELD_WALLET, wallet);
} catch (JSONException ignore) {
}
return json;
}

@Nullable
public static Card fromJson(@Nullable JSONObject cardJson) {
if (cardJson == null) {
@@ -816,19 +756,6 @@ public Map<String, Object> toMap() {
return map;
}

@NonNull
@Override
public JSONObject toJson() {
final JSONObject json = new JSONObject();
try {
json.put(FIELD_ADDRESS_LINE1_CHECK, addressLine1Check);
json.put(FIELD_ADDRESS_POSTAL_CODE_CHECK, addressPostalCodeCheck);
json.put(FIELD_CVC_CHECK, cvcCheck);
} catch (JSONException ignore) {
}
return json;
}

@Nullable
public static Checks fromJson(@Nullable JSONObject checksJson) {
if (checksJson == null) {
@@ -933,17 +860,6 @@ public Map<String, Object> toMap() {
return map;
}

@NonNull
@Override
public JSONObject toJson() {
final JSONObject json = new JSONObject();
try {
json.put(FIELD_IS_SUPPORTED, isSupported);
} catch (JSONException ignore) {
}
return json;
}

@Nullable
public static ThreeDSecureUsage fromJson(@Nullable JSONObject threeDSecureUsage) {
if (threeDSecureUsage == null) {
@@ -1018,12 +934,6 @@ public Map<String, Object> toMap() {
return new HashMap<>();
}

@NonNull
@Override
public JSONObject toJson() {
return new JSONObject();
}

@Override
public int hashCode() {
return ObjectUtils.hash(type);
@@ -1086,19 +996,6 @@ public Map<String, Object> toMap() {
return ideal;
}

@NonNull
@Override
public JSONObject toJson() {
final JSONObject ideal = new JSONObject();
try {
ideal.put(FIELD_BANK, bank);
ideal.put(FIELD_BIC, bankIdentifierCode);
} catch (JSONException e) {
throw new RuntimeException(e);
}
return ideal;
}

@Nullable
public static Ideal fromJson(@Nullable JSONObject ideal) {
if (ideal == null) {
Loading

0 comments on commit 21f3061

Please sign in to comment.