Skip to content

Commit

Permalink
Make all StripeModels implement Parcelable (#1865)
Browse files Browse the repository at this point in the history
Remove unnecessary Builders from `StripeSourceTypeModel` subclasses
(i.e. `SourceCardData`, `SourceSepaDebitData`). Also remove unused
`StripeSourceTypeModel.BaseBuilder.additionalFields`.
  • Loading branch information
mshafrir-stripe authored Nov 25, 2019
1 parent b13641e commit 66a6cb4
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 366 deletions.
5 changes: 4 additions & 1 deletion stripe/src/main/java/com/stripe/android/model/BankAccount.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.stripe.android.model

import android.os.Parcelable
import androidx.annotation.Size
import androidx.annotation.StringDef
import kotlinx.android.parcel.Parcelize
import org.json.JSONObject

/**
Expand All @@ -10,6 +12,7 @@ import org.json.JSONObject
* [the Stripe
* documentation.](https://stripe.com/docs/api/java#create_bank_account_token)
*/
@Parcelize
data class BankAccount internal constructor(
val accountNumber: String?,
val accountHolderName: String?,
Expand All @@ -23,7 +26,7 @@ data class BankAccount internal constructor(
val fingerprint: String?,
val last4: String?,
val routingNumber: String?
) : StripeParamsModel {
) : StripeParamsModel, Parcelable {

@Retention(AnnotationRetention.SOURCE)
@StringDef(BankAccountType.COMPANY, BankAccountType.INDIVIDUAL)
Expand Down
4 changes: 3 additions & 1 deletion stripe/src/main/java/com/stripe/android/model/Customer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package com.stripe.android.model
import com.stripe.android.model.StripeJsonUtils.optBoolean
import com.stripe.android.model.StripeJsonUtils.optInteger
import com.stripe.android.model.StripeJsonUtils.optString
import kotlinx.android.parcel.Parcelize
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject

/**
* Model for a Stripe Customer object
*/
data class Customer private constructor(
@Parcelize
data class Customer internal constructor(
val id: String?,
val defaultSource: String?,
val shippingInformation: ShippingInformation?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.stripe.android.model

import com.stripe.android.model.StripeJsonUtils.optString
import kotlinx.android.parcel.Parcelize
import org.json.JSONObject

/**
* Model of the "data" object inside a [Customer] "source" object.
*/
data class CustomerSource private constructor(
@Parcelize
data class CustomerSource internal constructor(
private val stripePaymentSource: StripePaymentSource
) : StripeModel(), StripePaymentSource {

Expand Down
11 changes: 8 additions & 3 deletions stripe/src/main/java/com/stripe/android/model/PaymentIntent.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.stripe.android.model

import android.net.Uri
import android.os.Parcelable
import com.stripe.android.model.StripeJsonUtils.optBoolean
import com.stripe.android.model.StripeJsonUtils.optCurrency
import com.stripe.android.model.StripeJsonUtils.optLong
import com.stripe.android.model.StripeJsonUtils.optMap
import com.stripe.android.model.StripeJsonUtils.optString
import kotlinx.android.parcel.Parcelize
import kotlinx.android.parcel.RawValue
import org.json.JSONException
import org.json.JSONObject

Expand All @@ -15,6 +18,7 @@ import org.json.JSONObject
* - [Payment Intents Overview](https://stripe.com/docs/payments/payment-intents)
* - [PaymentIntents API](https://stripe.com/docs/api/payment_intents)
*/
@Parcelize
data class PaymentIntent internal constructor(
/**
* @return Unique identifier for the object.
Expand Down Expand Up @@ -103,7 +107,7 @@ data class PaymentIntent internal constructor(
* @return If present, this property tells you what actions you need to take in order for your
* customer to fulfill a payment using the provided source.
*/
val nextAction: Map<String, Any?>?,
val nextAction: Map<String, @RawValue Any?>?,

/**
* @return ID of the payment method (a PaymentMethod, Card, BankAccount, or saved Source object)
Expand Down Expand Up @@ -186,7 +190,8 @@ data class PaymentIntent internal constructor(
*
* See [last_payment_error](https://stripe.com/docs/api/payment_intents/object#payment_intent_object-last_payment_error).
*/
data class Error private constructor(
@Parcelize
data class Error internal constructor(

/**
* For card errors, the ID of the failed charge.
Expand Down Expand Up @@ -233,7 +238,7 @@ data class PaymentIntent internal constructor(
* The type of error returned.
*/
val type: Type?
) {
) : Parcelable {
enum class Type(val code: String) {
ApiConnectionError("api_connection_error"),
ApiError("api_error"),
Expand Down
13 changes: 9 additions & 4 deletions stripe/src/main/java/com/stripe/android/model/SetupIntent.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package com.stripe.android.model

import android.net.Uri
import android.os.Parcelable
import com.stripe.android.model.StripeJsonUtils.optMap
import com.stripe.android.model.StripeJsonUtils.optString
import kotlinx.android.parcel.Parcelize
import kotlinx.android.parcel.RawValue
import org.json.JSONException
import org.json.JSONObject

/**
* A SetupIntent guides you through the process of setting up a customer's payment credentials for
* future payments.
*/
data class SetupIntent private constructor(
@Parcelize
data class SetupIntent internal constructor(

/**
* @return Unique identifier for the object.
Expand Down Expand Up @@ -50,7 +54,7 @@ data class SetupIntent private constructor(
*/
override val isLiveMode: Boolean,

private val nextAction: Map<String, Any?>?,
private val nextAction: Map<String, @RawValue Any?>?,

override val nextActionType: StripeIntent.NextActionType? = null,

Expand Down Expand Up @@ -137,7 +141,8 @@ data class SetupIntent private constructor(
*
* See [last_setup_error](https://stripe.com/docs/api/setup_intents/object#setup_intent_object-last_setup_error).
*/
data class Error private constructor(
@Parcelize
data class Error internal constructor(

/**
* For some errors that could be handled programmatically, a short string indicating the
Expand Down Expand Up @@ -179,7 +184,7 @@ data class SetupIntent private constructor(
* The type of error returned.
*/
val type: Type?
) {
) : Parcelable {
enum class Type(val code: String) {
ApiConnectionError("api_connection_error"),
ApiError("api_error"),
Expand Down
9 changes: 7 additions & 2 deletions stripe/src/main/java/com/stripe/android/model/Source.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.stripe.android.model

import android.os.Parcelable
import androidx.annotation.Size
import androidx.annotation.StringDef
import com.stripe.android.model.Source.SourceFlow
import com.stripe.android.model.Source.SourceType
import com.stripe.android.model.StripeJsonUtils.optLong
import com.stripe.android.model.StripeJsonUtils.optString
import kotlinx.android.parcel.Parcelize
import kotlinx.android.parcel.RawValue
import org.json.JSONException
import org.json.JSONObject

Expand All @@ -14,6 +17,7 @@ import org.json.JSONObject
*
* See [Sources API Reference](https://stripe.com/docs/api/sources/object).
*/
@Parcelize
data class Source internal constructor(
/**
* Unique identifier for the object.
Expand Down Expand Up @@ -95,7 +99,8 @@ data class Source internal constructor(
@param:SourceStatus @field:SourceStatus @get:SourceStatus
val status: String? = null,

val sourceTypeData: Map<String, Any?>? = null,
val sourceTypeData: Map<String, @RawValue Any?>? = null,

val sourceTypeModel: StripeSourceTypeModel? = null,

/**
Expand Down Expand Up @@ -138,7 +143,7 @@ data class Source internal constructor(
* every time you charge the source.
*/
val statementDescriptor: String? = null
) : StripeModel(), StripePaymentSource {
) : StripeModel(), StripePaymentSource, Parcelable {

val weChat: WeChat
get() {
Expand Down
Loading

0 comments on commit 66a6cb4

Please sign in to comment.