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

Remove StripeJsonModel#toJson() #1082

Merged
merged 1 commit into from
Jun 10, 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 @@ -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())
);
Expand Down Expand Up @@ -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,
Expand Down
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
Expand Up @@ -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() {
Expand Down
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.
Expand Down
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
Expand Up @@ -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>
Expand Down Expand Up @@ -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 {
Expand Down
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
Expand Up @@ -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.
Expand Down Expand Up @@ -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() {
Expand Down
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
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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() {
Expand Down
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
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
Loading