@Test public void fromJsonString_backToJson_createsIdenticalElement() { try { JSONObject rawConversion = new JSONObject(EXAMPLE_JSON_SOURCE_WITHOUT_NULLS); JSONObject actualObject = mSource.toJson(); assertJsonEquals(rawConversion, actualObject); } catch (JSONException jsonException) { fail("Test Data failure: " + jsonException.getLocalizedMessage()); } }
@NonNull @Override public JSONObject toJson() { JSONObject jsonObject = new JSONObject(); try { putStringIfNotNull(jsonObject, FIELD_ID, mId); jsonObject.put(FIELD_OBJECT, VALUE_SOURCE); jsonObject.put(FIELD_AMOUNT, mAmount); putStringIfNotNull(jsonObject, FIELD_CLIENT_SECRET, mClientSecret); putStripeJsonModelIfNotNull(jsonObject, FIELD_CODE_VERIFICATION, mCodeVerification); jsonObject.put(FIELD_CREATED, mCreated); putStringIfNotNull(jsonObject, FIELD_CURRENCY, mCurrency); putStringIfNotNull(jsonObject, FIELD_FLOW, mFlow); jsonObject.put(FIELD_LIVEMODE, mLiveMode); JSONObject metaDataObject = StripeJsonUtils.mapToJsonObject(mMetaData); if (metaDataObject != null) { jsonObject.put(FIELD_METADATA, metaDataObject); } JSONObject sourceTypeJsonObject = mapToJsonObject(mSourceTypeData); if (sourceTypeJsonObject != null) { jsonObject.put(mTypeRaw, sourceTypeJsonObject); } putStripeJsonModelIfNotNull(jsonObject, FIELD_OWNER, mOwner); putStripeJsonModelIfNotNull(jsonObject, FIELD_RECEIVER, mReceiver); putStripeJsonModelIfNotNull(jsonObject, FIELD_REDIRECT, mRedirect); putStringIfNotNull(jsonObject, FIELD_STATUS, mStatus); putStringIfNotNull(jsonObject, FIELD_TYPE, mTypeRaw); putStringIfNotNull(jsonObject, FIELD_USAGE, mUsage); } catch (JSONException ignored) { } return jsonObject; }
Source extends StripeJsonModel implements StripePaymentSource { @NonNull @Override public JSONObject toJson() { JSONObject jsonObject = new JSONObject(); try { putStringIfNotNull(jsonObject, FIELD_ID, mId); jsonObject.put(FIELD_OBJECT, VALUE_SOURCE); jsonObject.put(FIELD_AMOUNT, mAmount); putStringIfNotNull(jsonObject, FIELD_CLIENT_SECRET, mClientSecret); putStripeJsonModelIfNotNull(jsonObject, FIELD_CODE_VERIFICATION, mCodeVerification); jsonObject.put(FIELD_CREATED, mCreated); putStringIfNotNull(jsonObject, FIELD_CURRENCY, mCurrency); putStringIfNotNull(jsonObject, FIELD_FLOW, mFlow); jsonObject.put(FIELD_LIVEMODE, mLiveMode); JSONObject metaDataObject = StripeJsonUtils.mapToJsonObject(mMetaData); if (metaDataObject != null) { jsonObject.put(FIELD_METADATA, metaDataObject); } JSONObject sourceTypeJsonObject = mapToJsonObject(mSourceTypeData); if (sourceTypeJsonObject != null) { jsonObject.put(mTypeRaw, sourceTypeJsonObject); } putStripeJsonModelIfNotNull(jsonObject, FIELD_OWNER, mOwner); putStripeJsonModelIfNotNull(jsonObject, FIELD_RECEIVER, mReceiver); putStripeJsonModelIfNotNull(jsonObject, FIELD_REDIRECT, mRedirect); putStringIfNotNull(jsonObject, FIELD_STATUS, mStatus); putStringIfNotNull(jsonObject, FIELD_TYPE, mTypeRaw); putStringIfNotNull(jsonObject, FIELD_USAGE, mUsage); } catch (JSONException ignored) { } return jsonObject; } }
Source extends StripeJsonModel implements StripePaymentSource { @NonNull @Override public JSONObject toJson() { JSONObject jsonObject = new JSONObject(); try { putStringIfNotNull(jsonObject, FIELD_ID, mId); jsonObject.put(FIELD_OBJECT, VALUE_SOURCE); jsonObject.put(FIELD_AMOUNT, mAmount); putStringIfNotNull(jsonObject, FIELD_CLIENT_SECRET, mClientSecret); putStripeJsonModelIfNotNull(jsonObject, FIELD_CODE_VERIFICATION, mCodeVerification); jsonObject.put(FIELD_CREATED, mCreated); putStringIfNotNull(jsonObject, FIELD_CURRENCY, mCurrency); putStringIfNotNull(jsonObject, FIELD_FLOW, mFlow); jsonObject.put(FIELD_LIVEMODE, mLiveMode); JSONObject metaDataObject = StripeJsonUtils.mapToJsonObject(mMetaData); if (metaDataObject != null) { jsonObject.put(FIELD_METADATA, metaDataObject); } JSONObject sourceTypeJsonObject = mapToJsonObject(mSourceTypeData); if (sourceTypeJsonObject != null) { jsonObject.put(mTypeRaw, sourceTypeJsonObject); } putStripeJsonModelIfNotNull(jsonObject, FIELD_OWNER, mOwner); putStripeJsonModelIfNotNull(jsonObject, FIELD_RECEIVER, mReceiver); putStripeJsonModelIfNotNull(jsonObject, FIELD_REDIRECT, mRedirect); putStringIfNotNull(jsonObject, FIELD_STATUS, mStatus); putStringIfNotNull(jsonObject, FIELD_TYPE, mTypeRaw); putStringIfNotNull(jsonObject, FIELD_USAGE, mUsage); } catch (JSONException ignored) { } return jsonObject; } Source(
            String id,
            Long amount,
            String clientSecret,
            SourceCodeVerification codeVerification,
            Long created,
            String currency,
            @SourceFlow String flow,
            Boolean liveMode,
            Map<String, String> metaData,
            SourceOwner owner,
            SourceReceiver receiver,
            SourceRedirect redirect,
            @SourceStatus String status,
            Map<String, Object> sourceTypeData,
            StripeSourceTypeModel sourceTypeModel,
            @SourceType String type,
            String rawType,
            @Usage String usage
    ); }
Source extends StripeJsonModel implements StripePaymentSource { @NonNull @Override public JSONObject toJson() { JSONObject jsonObject = new JSONObject(); try { putStringIfNotNull(jsonObject, FIELD_ID, mId); jsonObject.put(FIELD_OBJECT, VALUE_SOURCE); jsonObject.put(FIELD_AMOUNT, mAmount); putStringIfNotNull(jsonObject, FIELD_CLIENT_SECRET, mClientSecret); putStripeJsonModelIfNotNull(jsonObject, FIELD_CODE_VERIFICATION, mCodeVerification); jsonObject.put(FIELD_CREATED, mCreated); putStringIfNotNull(jsonObject, FIELD_CURRENCY, mCurrency); putStringIfNotNull(jsonObject, FIELD_FLOW, mFlow); jsonObject.put(FIELD_LIVEMODE, mLiveMode); JSONObject metaDataObject = StripeJsonUtils.mapToJsonObject(mMetaData); if (metaDataObject != null) { jsonObject.put(FIELD_METADATA, metaDataObject); } JSONObject sourceTypeJsonObject = mapToJsonObject(mSourceTypeData); if (sourceTypeJsonObject != null) { jsonObject.put(mTypeRaw, sourceTypeJsonObject); } putStripeJsonModelIfNotNull(jsonObject, FIELD_OWNER, mOwner); putStripeJsonModelIfNotNull(jsonObject, FIELD_RECEIVER, mReceiver); putStripeJsonModelIfNotNull(jsonObject, FIELD_REDIRECT, mRedirect); putStringIfNotNull(jsonObject, FIELD_STATUS, mStatus); putStringIfNotNull(jsonObject, FIELD_TYPE, mTypeRaw); putStringIfNotNull(jsonObject, FIELD_USAGE, mUsage); } catch (JSONException ignored) { } return jsonObject; } Source(
            String id,
            Long amount,
            String clientSecret,
            SourceCodeVerification codeVerification,
            Long created,
            String currency,
            @SourceFlow String flow,
            Boolean liveMode,
            Map<String, String> metaData,
            SourceOwner owner,
            SourceReceiver receiver,
            SourceRedirect redirect,
            @SourceStatus String status,
            Map<String, Object> sourceTypeData,
            StripeSourceTypeModel sourceTypeModel,
            @SourceType String type,
            String rawType,
            @Usage String usage
    ); @Override String getId(); Long getAmount(); String getClientSecret(); SourceCodeVerification getCodeVerification(); Long getCreated(); String getCurrency(); @SourceFlow String getFlow(); Boolean isLiveMode(); Map<String, String> getMetaData(); SourceOwner getOwner(); SourceReceiver getReceiver(); SourceRedirect getRedirect(); @SourceStatus String getStatus(); Map<String, Object> getSourceTypeData(); StripeSourceTypeModel getSourceTypeModel(); @SourceType String getType(); String getTypeRaw(); @Usage String getUsage(); void setId(String id); void setAmount(long amount); void setClientSecret(String clientSecret); void setCodeVerification(SourceCodeVerification codeVerification); void setCreated(long created); void setCurrency(String currency); void setFlow(@SourceFlow String flow); void setLiveMode(boolean liveMode); void setMetaData(Map<String, String> metaData); void setOwner(SourceOwner owner); void setReceiver(SourceReceiver receiver); void setRedirect(SourceRedirect redirect); void setStatus(@SourceStatus String status); void setSourceTypeData(Map<String, Object> sourceTypeData); void setTypeRaw(@NonNull @Size(min = 1) String typeRaw); void setType(@SourceType String type); void setUsage(@Usage String usage); @NonNull @Override Map<String, Object> toMap(); @NonNull @Override JSONObject toJson(); @Nullable static Source fromString(@Nullable String jsonString); @Nullable static Source fromJson(@Nullable JSONObject jsonObject); }
Source extends StripeJsonModel implements StripePaymentSource { @NonNull @Override public JSONObject toJson() { JSONObject jsonObject = new JSONObject(); try { putStringIfNotNull(jsonObject, FIELD_ID, mId); jsonObject.put(FIELD_OBJECT, VALUE_SOURCE); jsonObject.put(FIELD_AMOUNT, mAmount); putStringIfNotNull(jsonObject, FIELD_CLIENT_SECRET, mClientSecret); putStripeJsonModelIfNotNull(jsonObject, FIELD_CODE_VERIFICATION, mCodeVerification); jsonObject.put(FIELD_CREATED, mCreated); putStringIfNotNull(jsonObject, FIELD_CURRENCY, mCurrency); putStringIfNotNull(jsonObject, FIELD_FLOW, mFlow); jsonObject.put(FIELD_LIVEMODE, mLiveMode); JSONObject metaDataObject = StripeJsonUtils.mapToJsonObject(mMetaData); if (metaDataObject != null) { jsonObject.put(FIELD_METADATA, metaDataObject); } JSONObject sourceTypeJsonObject = mapToJsonObject(mSourceTypeData); if (sourceTypeJsonObject != null) { jsonObject.put(mTypeRaw, sourceTypeJsonObject); } putStripeJsonModelIfNotNull(jsonObject, FIELD_OWNER, mOwner); putStripeJsonModelIfNotNull(jsonObject, FIELD_RECEIVER, mReceiver); putStripeJsonModelIfNotNull(jsonObject, FIELD_REDIRECT, mRedirect); putStringIfNotNull(jsonObject, FIELD_STATUS, mStatus); putStringIfNotNull(jsonObject, FIELD_TYPE, mTypeRaw); putStringIfNotNull(jsonObject, FIELD_USAGE, mUsage); } catch (JSONException ignored) { } return jsonObject; } Source(
            String id,
            Long amount,
            String clientSecret,
            SourceCodeVerification codeVerification,
            Long created,
            String currency,
            @SourceFlow String flow,
            Boolean liveMode,
            Map<String, String> metaData,
            SourceOwner owner,
            SourceReceiver receiver,
            SourceRedirect redirect,
            @SourceStatus String status,
            Map<String, Object> sourceTypeData,
            StripeSourceTypeModel sourceTypeModel,
            @SourceType String type,
            String rawType,
            @Usage String usage
    ); @Override String getId(); Long getAmount(); String getClientSecret(); SourceCodeVerification getCodeVerification(); Long getCreated(); String getCurrency(); @SourceFlow String getFlow(); Boolean isLiveMode(); Map<String, String> getMetaData(); SourceOwner getOwner(); SourceReceiver getReceiver(); SourceRedirect getRedirect(); @SourceStatus String getStatus(); Map<String, Object> getSourceTypeData(); StripeSourceTypeModel getSourceTypeModel(); @SourceType String getType(); String getTypeRaw(); @Usage String getUsage(); void setId(String id); void setAmount(long amount); void setClientSecret(String clientSecret); void setCodeVerification(SourceCodeVerification codeVerification); void setCreated(long created); void setCurrency(String currency); void setFlow(@SourceFlow String flow); void setLiveMode(boolean liveMode); void setMetaData(Map<String, String> metaData); void setOwner(SourceOwner owner); void setReceiver(SourceReceiver receiver); void setRedirect(SourceRedirect redirect); void setStatus(@SourceStatus String status); void setSourceTypeData(Map<String, Object> sourceTypeData); void setTypeRaw(@NonNull @Size(min = 1) String typeRaw); void setType(@SourceType String type); void setUsage(@Usage String usage); @NonNull @Override Map<String, Object> toMap(); @NonNull @Override JSONObject toJson(); @Nullable static Source fromString(@Nullable String jsonString); @Nullable static Source fromJson(@Nullable JSONObject jsonObject); static final String ALIPAY; static final String BITCOIN; static final String CARD; static final String THREE_D_SECURE; static final String GIROPAY; static final String SEPA_DEBIT; static final String IDEAL; static final String SOFORT; static final String BANCONTACT; static final String P24; static final String UNKNOWN; static final Set<String> MODELED_TYPES; static final String PENDING; static final String CHARGEABLE; static final String CONSUMED; static final String CANCELED; static final String FAILED; static final String REUSABLE; static final String SINGLE_USE; static final String REDIRECT; static final String RECEIVER; static final String CODE_VERIFICATION; static final String NONE; }