From a61d2b8b6adf4dbbb7564f5b748190b6ad25eff2 Mon Sep 17 00:00:00 2001 From: Till Hellmund Date: Fri, 26 Aug 2022 11:05:23 -0400 Subject: [PATCH 1/5] Add country code to StripeIntent --- payments-core/api/payments-core.api | 53 ++++++++++--------- .../com/stripe/android/model/PaymentIntent.kt | 5 ++ .../com/stripe/android/model/SetupIntent.kt | 5 ++ .../com/stripe/android/model/StripeIntent.kt | 5 ++ .../model/parsers/PaymentIntentJsonParser.kt | 4 ++ .../PaymentMethodPreferenceJsonParser.kt | 7 +++ .../model/parsers/SetupIntentJsonParser.kt | 2 + .../stripe/android/PaymentIntentResultTest.kt | 5 ++ 8 files changed, 62 insertions(+), 24 deletions(-) diff --git a/payments-core/api/payments-core.api b/payments-core/api/payments-core.api index bed84e62f89..02f01aa4129 100644 --- a/payments-core/api/payments-core.api +++ b/payments-core/api/payments-core.api @@ -3152,29 +3152,30 @@ public final class com/stripe/android/model/PaymentIntent : com/stripe/android/m public static final field CREATOR Landroid/os/Parcelable$Creator; public static final field Companion Lcom/stripe/android/model/PaymentIntent$Companion; public final fun component1 ()Ljava/lang/String; - public final fun component10 ()Ljava/lang/String; + public final fun component10 ()J public final fun component11 ()Ljava/lang/String; - public final fun component12 ()Z - public final fun component13 ()Lcom/stripe/android/model/PaymentMethod; - public final fun component14 ()Ljava/lang/String; + public final fun component12 ()Ljava/lang/String; + public final fun component13 ()Z + public final fun component14 ()Lcom/stripe/android/model/PaymentMethod; public final fun component15 ()Ljava/lang/String; - public final fun component16 ()Lcom/stripe/android/model/StripeIntent$Status; - public final fun component17 ()Lcom/stripe/android/model/StripeIntent$Usage; - public final fun component18 ()Lcom/stripe/android/model/PaymentIntent$Error; - public final fun component19 ()Lcom/stripe/android/model/PaymentIntent$Shipping; + public final fun component16 ()Ljava/lang/String; + public final fun component17 ()Lcom/stripe/android/model/StripeIntent$Status; + public final fun component18 ()Lcom/stripe/android/model/StripeIntent$Usage; + public final fun component19 ()Lcom/stripe/android/model/PaymentIntent$Error; public final fun component2 ()Ljava/util/List; - public final fun component20 ()Ljava/util/List; + public final fun component20 ()Lcom/stripe/android/model/PaymentIntent$Shipping; public final fun component21 ()Ljava/util/List; - public final fun component22 ()Lcom/stripe/android/model/StripeIntent$NextActionData; + public final fun component22 ()Ljava/util/List; + public final fun component23 ()Lcom/stripe/android/model/StripeIntent$NextActionData; public final fun component3 ()Ljava/lang/Long; public final fun component4 ()J public final fun component5 ()Lcom/stripe/android/model/PaymentIntent$CancellationReason; public final fun component6 ()Lcom/stripe/android/model/PaymentIntent$CaptureMethod; public final fun component7 ()Ljava/lang/String; public final fun component8 ()Lcom/stripe/android/model/PaymentIntent$ConfirmationMethod; - public final fun component9 ()J - public final fun copy (Ljava/lang/String;Ljava/util/List;Ljava/lang/Long;JLcom/stripe/android/model/PaymentIntent$CancellationReason;Lcom/stripe/android/model/PaymentIntent$CaptureMethod;Ljava/lang/String;Lcom/stripe/android/model/PaymentIntent$ConfirmationMethod;JLjava/lang/String;Ljava/lang/String;ZLcom/stripe/android/model/PaymentMethod;Ljava/lang/String;Ljava/lang/String;Lcom/stripe/android/model/StripeIntent$Status;Lcom/stripe/android/model/StripeIntent$Usage;Lcom/stripe/android/model/PaymentIntent$Error;Lcom/stripe/android/model/PaymentIntent$Shipping;Ljava/util/List;Ljava/util/List;Lcom/stripe/android/model/StripeIntent$NextActionData;Ljava/lang/String;)Lcom/stripe/android/model/PaymentIntent; - public static synthetic fun copy$default (Lcom/stripe/android/model/PaymentIntent;Ljava/lang/String;Ljava/util/List;Ljava/lang/Long;JLcom/stripe/android/model/PaymentIntent$CancellationReason;Lcom/stripe/android/model/PaymentIntent$CaptureMethod;Ljava/lang/String;Lcom/stripe/android/model/PaymentIntent$ConfirmationMethod;JLjava/lang/String;Ljava/lang/String;ZLcom/stripe/android/model/PaymentMethod;Ljava/lang/String;Ljava/lang/String;Lcom/stripe/android/model/StripeIntent$Status;Lcom/stripe/android/model/StripeIntent$Usage;Lcom/stripe/android/model/PaymentIntent$Error;Lcom/stripe/android/model/PaymentIntent$Shipping;Ljava/util/List;Ljava/util/List;Lcom/stripe/android/model/StripeIntent$NextActionData;Ljava/lang/String;ILjava/lang/Object;)Lcom/stripe/android/model/PaymentIntent; + public final fun component9 ()Ljava/lang/String; + public final fun copy (Ljava/lang/String;Ljava/util/List;Ljava/lang/Long;JLcom/stripe/android/model/PaymentIntent$CancellationReason;Lcom/stripe/android/model/PaymentIntent$CaptureMethod;Ljava/lang/String;Lcom/stripe/android/model/PaymentIntent$ConfirmationMethod;Ljava/lang/String;JLjava/lang/String;Ljava/lang/String;ZLcom/stripe/android/model/PaymentMethod;Ljava/lang/String;Ljava/lang/String;Lcom/stripe/android/model/StripeIntent$Status;Lcom/stripe/android/model/StripeIntent$Usage;Lcom/stripe/android/model/PaymentIntent$Error;Lcom/stripe/android/model/PaymentIntent$Shipping;Ljava/util/List;Ljava/util/List;Lcom/stripe/android/model/StripeIntent$NextActionData;Ljava/lang/String;)Lcom/stripe/android/model/PaymentIntent; + public static synthetic fun copy$default (Lcom/stripe/android/model/PaymentIntent;Ljava/lang/String;Ljava/util/List;Ljava/lang/Long;JLcom/stripe/android/model/PaymentIntent$CancellationReason;Lcom/stripe/android/model/PaymentIntent$CaptureMethod;Ljava/lang/String;Lcom/stripe/android/model/PaymentIntent$ConfirmationMethod;Ljava/lang/String;JLjava/lang/String;Ljava/lang/String;ZLcom/stripe/android/model/PaymentMethod;Ljava/lang/String;Ljava/lang/String;Lcom/stripe/android/model/StripeIntent$Status;Lcom/stripe/android/model/StripeIntent$Usage;Lcom/stripe/android/model/PaymentIntent$Error;Lcom/stripe/android/model/PaymentIntent$Shipping;Ljava/util/List;Ljava/util/List;Lcom/stripe/android/model/StripeIntent$NextActionData;Ljava/lang/String;ILjava/lang/Object;)Lcom/stripe/android/model/PaymentIntent; public fun describeContents ()I public fun equals (Ljava/lang/Object;)Z public static final fun fromJson (Lorg/json/JSONObject;)Lcom/stripe/android/model/PaymentIntent; @@ -3184,6 +3185,7 @@ public final class com/stripe/android/model/PaymentIntent : com/stripe/android/m public final fun getCaptureMethod ()Lcom/stripe/android/model/PaymentIntent$CaptureMethod; public fun getClientSecret ()Ljava/lang/String; public final fun getConfirmationMethod ()Lcom/stripe/android/model/PaymentIntent$ConfirmationMethod; + public fun getCountryCode ()Ljava/lang/String; public fun getCreated ()J public final fun getCurrency ()Ljava/lang/String; public fun getDescription ()Ljava/lang/String; @@ -4820,27 +4822,29 @@ public final class com/stripe/android/model/SetupIntent : com/stripe/android/mod public static final field CREATOR Landroid/os/Parcelable$Creator; public static final field Companion Lcom/stripe/android/model/SetupIntent$Companion; public final fun component1 ()Ljava/lang/String; - public final fun component10 ()Lcom/stripe/android/model/StripeIntent$Status; - public final fun component11 ()Lcom/stripe/android/model/StripeIntent$Usage; - public final fun component12 ()Lcom/stripe/android/model/SetupIntent$Error; - public final fun component13 ()Ljava/util/List; + public final fun component10 ()Ljava/util/List; + public final fun component11 ()Lcom/stripe/android/model/StripeIntent$Status; + public final fun component12 ()Lcom/stripe/android/model/StripeIntent$Usage; + public final fun component13 ()Lcom/stripe/android/model/SetupIntent$Error; public final fun component14 ()Ljava/util/List; - public final fun component15 ()Lcom/stripe/android/model/StripeIntent$NextActionData; + public final fun component15 ()Ljava/util/List; + public final fun component16 ()Lcom/stripe/android/model/StripeIntent$NextActionData; public final fun component2 ()Lcom/stripe/android/model/SetupIntent$CancellationReason; public final fun component3 ()J public final fun component4 ()Ljava/lang/String; public final fun component5 ()Ljava/lang/String; - public final fun component6 ()Z - public final fun component7 ()Lcom/stripe/android/model/PaymentMethod; - public final fun component8 ()Ljava/lang/String; - public final fun component9 ()Ljava/util/List; - public final fun copy (Ljava/lang/String;Lcom/stripe/android/model/SetupIntent$CancellationReason;JLjava/lang/String;Ljava/lang/String;ZLcom/stripe/android/model/PaymentMethod;Ljava/lang/String;Ljava/util/List;Lcom/stripe/android/model/StripeIntent$Status;Lcom/stripe/android/model/StripeIntent$Usage;Lcom/stripe/android/model/SetupIntent$Error;Ljava/util/List;Ljava/util/List;Lcom/stripe/android/model/StripeIntent$NextActionData;)Lcom/stripe/android/model/SetupIntent; - public static synthetic fun copy$default (Lcom/stripe/android/model/SetupIntent;Ljava/lang/String;Lcom/stripe/android/model/SetupIntent$CancellationReason;JLjava/lang/String;Ljava/lang/String;ZLcom/stripe/android/model/PaymentMethod;Ljava/lang/String;Ljava/util/List;Lcom/stripe/android/model/StripeIntent$Status;Lcom/stripe/android/model/StripeIntent$Usage;Lcom/stripe/android/model/SetupIntent$Error;Ljava/util/List;Ljava/util/List;Lcom/stripe/android/model/StripeIntent$NextActionData;ILjava/lang/Object;)Lcom/stripe/android/model/SetupIntent; + public final fun component6 ()Ljava/lang/String; + public final fun component7 ()Z + public final fun component8 ()Lcom/stripe/android/model/PaymentMethod; + public final fun component9 ()Ljava/lang/String; + public final fun copy (Ljava/lang/String;Lcom/stripe/android/model/SetupIntent$CancellationReason;JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLcom/stripe/android/model/PaymentMethod;Ljava/lang/String;Ljava/util/List;Lcom/stripe/android/model/StripeIntent$Status;Lcom/stripe/android/model/StripeIntent$Usage;Lcom/stripe/android/model/SetupIntent$Error;Ljava/util/List;Ljava/util/List;Lcom/stripe/android/model/StripeIntent$NextActionData;)Lcom/stripe/android/model/SetupIntent; + public static synthetic fun copy$default (Lcom/stripe/android/model/SetupIntent;Ljava/lang/String;Lcom/stripe/android/model/SetupIntent$CancellationReason;JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;ZLcom/stripe/android/model/PaymentMethod;Ljava/lang/String;Ljava/util/List;Lcom/stripe/android/model/StripeIntent$Status;Lcom/stripe/android/model/StripeIntent$Usage;Lcom/stripe/android/model/SetupIntent$Error;Ljava/util/List;Ljava/util/List;Lcom/stripe/android/model/StripeIntent$NextActionData;ILjava/lang/Object;)Lcom/stripe/android/model/SetupIntent; public fun describeContents ()I public fun equals (Ljava/lang/Object;)Z public static final fun fromJson (Lorg/json/JSONObject;)Lcom/stripe/android/model/SetupIntent; public final fun getCancellationReason ()Lcom/stripe/android/model/SetupIntent$CancellationReason; public fun getClientSecret ()Ljava/lang/String; + public fun getCountryCode ()Ljava/lang/String; public fun getCreated ()J public fun getDescription ()Ljava/lang/String; public fun getId ()Ljava/lang/String; @@ -5920,6 +5924,7 @@ public final class com/stripe/android/model/Stripe3ds2Fingerprint$DirectoryServe public abstract interface class com/stripe/android/model/StripeIntent : com/stripe/android/core/model/StripeModel { public abstract fun getClientSecret ()Ljava/lang/String; + public abstract fun getCountryCode ()Ljava/lang/String; public abstract fun getCreated ()J public abstract fun getDescription ()Ljava/lang/String; public abstract fun getId ()Ljava/lang/String; diff --git a/payments-core/src/main/java/com/stripe/android/model/PaymentIntent.kt b/payments-core/src/main/java/com/stripe/android/model/PaymentIntent.kt index 4ae5048c9c1..f7d3fc63d1a 100644 --- a/payments-core/src/main/java/com/stripe/android/model/PaymentIntent.kt +++ b/payments-core/src/main/java/com/stripe/android/model/PaymentIntent.kt @@ -81,6 +81,11 @@ data class PaymentIntent internal constructor( */ val confirmationMethod: ConfirmationMethod = ConfirmationMethod.Automatic, + /** + * Country code of the user. + */ + override val countryCode: String?, + /** * Time at which the object was created. Measured in seconds since the Unix epoch. */ diff --git a/payments-core/src/main/java/com/stripe/android/model/SetupIntent.kt b/payments-core/src/main/java/com/stripe/android/model/SetupIntent.kt index d58beadcefa..d32a50dccc3 100644 --- a/payments-core/src/main/java/com/stripe/android/model/SetupIntent.kt +++ b/payments-core/src/main/java/com/stripe/android/model/SetupIntent.kt @@ -30,6 +30,11 @@ data class SetupIntent internal constructor( */ override val created: Long, + /** + * Country code of the user. + */ + override val countryCode: String?, + /** * The client secret of this SetupIntent. Used for client-side retrieval using a * publishable key. diff --git a/payments-core/src/main/java/com/stripe/android/model/StripeIntent.kt b/payments-core/src/main/java/com/stripe/android/model/StripeIntent.kt index 4417806bef4..276a2730f17 100644 --- a/payments-core/src/main/java/com/stripe/android/model/StripeIntent.kt +++ b/payments-core/src/main/java/com/stripe/android/model/StripeIntent.kt @@ -21,6 +21,11 @@ sealed interface StripeIntent : StripeModel { */ val created: Long + /** + * Country code of the user. + */ + val countryCode: String? + /** * An arbitrary string attached to the object. Often useful for displaying to users. */ diff --git a/payments-core/src/main/java/com/stripe/android/model/parsers/PaymentIntentJsonParser.kt b/payments-core/src/main/java/com/stripe/android/model/parsers/PaymentIntentJsonParser.kt index 8fb39cfcb68..8ea6cc54cd8 100644 --- a/payments-core/src/main/java/com/stripe/android/model/parsers/PaymentIntentJsonParser.kt +++ b/payments-core/src/main/java/com/stripe/android/model/parsers/PaymentIntentJsonParser.kt @@ -90,6 +90,8 @@ class PaymentIntentJsonParser( val linkFundingSources = jsonArrayToList(json.optJSONArray(FIELD_LINK_FUNDING_SOURCES)) .map { it.lowercase() } + val countryCode = optString(json, FIELD_COUNTRY_CODE) + return PaymentIntent( id = id, paymentMethodTypes = paymentMethodTypes, @@ -99,6 +101,7 @@ class PaymentIntentJsonParser( captureMethod = captureMethod, clientSecret = clientSecret, confirmationMethod = confirmationMethod, + countryCode = countryCode, created = created, currency = currency, description = description, @@ -181,6 +184,7 @@ class PaymentIntentJsonParser( private const val FIELD_CAPTURE_METHOD = "capture_method" private const val FIELD_CLIENT_SECRET = "client_secret" private const val FIELD_CONFIRMATION_METHOD = "confirmation_method" + private const val FIELD_COUNTRY_CODE = "country_code" private const val FIELD_CURRENCY = "currency" private const val FIELD_DESCRIPTION = "description" private const val FIELD_LAST_PAYMENT_ERROR = "last_payment_error" diff --git a/payments-core/src/main/java/com/stripe/android/model/parsers/PaymentMethodPreferenceJsonParser.kt b/payments-core/src/main/java/com/stripe/android/model/parsers/PaymentMethodPreferenceJsonParser.kt index da235352833..2ea3b074d15 100644 --- a/payments-core/src/main/java/com/stripe/android/model/parsers/PaymentMethodPreferenceJsonParser.kt +++ b/payments-core/src/main/java/com/stripe/android/model/parsers/PaymentMethodPreferenceJsonParser.kt @@ -22,6 +22,8 @@ internal sealed class PaymentMethodPreferenceJsonParser { cancellationReason = SetupIntent.CancellationReason.fromCode( optString(json, FIELD_CANCELLATION_REASON) ), + countryCode = optString(json, FIELD_COUNTRY_CODE), description = optString(json, FIELD_DESCRIPTION), isLiveMode = json.optBoolean(FIELD_LIVEMODE), paymentMethod = paymentMethod, @@ -91,6 +92,7 @@ class SetupIntentJsonParser : ModelJsonParser { private const val FIELD_CANCELLATION_REASON = "cancellation_reason" private const val FIELD_CREATED = "created" private const val FIELD_CLIENT_SECRET = "client_secret" + private const val FIELD_COUNTRY_CODE = "country_code" private const val FIELD_DESCRIPTION = "description" private const val FIELD_LAST_SETUP_ERROR = "last_setup_error" private const val FIELD_LIVEMODE = "livemode" diff --git a/payments-core/src/test/java/com/stripe/android/PaymentIntentResultTest.kt b/payments-core/src/test/java/com/stripe/android/PaymentIntentResultTest.kt index 2739e6d6fec..603aff1012f 100644 --- a/payments-core/src/test/java/com/stripe/android/PaymentIntentResultTest.kt +++ b/payments-core/src/test/java/com/stripe/android/PaymentIntentResultTest.kt @@ -26,6 +26,7 @@ class PaymentIntentResultTest { isLiveMode = false, id = "pi_12345", currency = "usd", + countryCode = null, paymentMethodTypes = listOf(PaymentMethod.Type.Oxxo.code), status = StripeIntent.Status.Processing, unactivatedPaymentMethods = emptyList(), @@ -69,6 +70,7 @@ class PaymentIntentResultTest { isLiveMode = false, id = "pi_12345", currency = "usd", + countryCode = null, paymentMethodTypes = listOf("card"), status = StripeIntent.Status.Processing, unactivatedPaymentMethods = emptyList() @@ -90,6 +92,7 @@ class PaymentIntentResultTest { isLiveMode = false, id = "pi_12345", currency = "usd", + countryCode = null, paymentMethodTypes = listOf(PaymentMethod.Type.Oxxo.code), status = StripeIntent.Status.Processing, unactivatedPaymentMethods = emptyList(), @@ -112,6 +115,7 @@ class PaymentIntentResultTest { isLiveMode = false, id = "pi_12345", currency = "usd", + countryCode = null, paymentMethodTypes = listOf(PaymentMethod.Type.USBankAccount.code), status = StripeIntent.Status.RequiresAction, unactivatedPaymentMethods = emptyList(), @@ -138,6 +142,7 @@ class PaymentIntentResultTest { isLiveMode = false, id = "pi_12345", currency = "usd", + countryCode = null, paymentMethodTypes = listOf("card"), status = StripeIntent.Status.Processing, unactivatedPaymentMethods = emptyList() From 71255af05942179aadf13a37b206a49d7465a166 Mon Sep 17 00:00:00 2001 From: Till Hellmund Date: Fri, 26 Aug 2022 13:44:11 -0400 Subject: [PATCH 2/5] Make `StripeIntent.countryCode` internal --- .../com/stripe/android/model/PaymentIntent.kt | 2 +- .../java/com/stripe/android/model/SetupIntent.kt | 2 +- .../java/com/stripe/android/model/StripeIntent.kt | 15 ++++++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/payments-core/src/main/java/com/stripe/android/model/PaymentIntent.kt b/payments-core/src/main/java/com/stripe/android/model/PaymentIntent.kt index f7d3fc63d1a..7b437171863 100644 --- a/payments-core/src/main/java/com/stripe/android/model/PaymentIntent.kt +++ b/payments-core/src/main/java/com/stripe/android/model/PaymentIntent.kt @@ -84,7 +84,7 @@ data class PaymentIntent internal constructor( /** * Country code of the user. */ - override val countryCode: String?, + internal val countryCode: String?, /** * Time at which the object was created. Measured in seconds since the Unix epoch. diff --git a/payments-core/src/main/java/com/stripe/android/model/SetupIntent.kt b/payments-core/src/main/java/com/stripe/android/model/SetupIntent.kt index d32a50dccc3..67105e97e4d 100644 --- a/payments-core/src/main/java/com/stripe/android/model/SetupIntent.kt +++ b/payments-core/src/main/java/com/stripe/android/model/SetupIntent.kt @@ -33,7 +33,7 @@ data class SetupIntent internal constructor( /** * Country code of the user. */ - override val countryCode: String?, + internal val countryCode: String?, /** * The client secret of this SetupIntent. Used for client-side retrieval using a diff --git a/payments-core/src/main/java/com/stripe/android/model/StripeIntent.kt b/payments-core/src/main/java/com/stripe/android/model/StripeIntent.kt index 276a2730f17..6f4c79f237e 100644 --- a/payments-core/src/main/java/com/stripe/android/model/StripeIntent.kt +++ b/payments-core/src/main/java/com/stripe/android/model/StripeIntent.kt @@ -21,11 +21,6 @@ sealed interface StripeIntent : StripeModel { */ val created: Long - /** - * Country code of the user. - */ - val countryCode: String? - /** * An arbitrary string attached to the object. Often useful for displaying to users. */ @@ -286,3 +281,13 @@ sealed interface StripeIntent : StripeModel { ) : NextActionData() } } + +/** + * Country code of the user. + */ +internal val StripeIntent.countryCode: String? + // We need to do this because an interface can't have an internal property + get() = when (this) { + is PaymentIntent -> countryCode + is SetupIntent -> countryCode + } From 25a6160a96c76dc645afde6090d87eca60e17bbb Mon Sep 17 00:00:00 2001 From: Till Hellmund Date: Fri, 26 Aug 2022 13:56:06 -0400 Subject: [PATCH 3/5] Add parser tests --- .../android/model/PaymentIntentFixtures.kt | 39 ++++++++++++++++++ .../android/model/SetupIntentFixtures.kt | 22 ++++++++++ .../parsers/PaymentIntentJsonParserTest.kt | 6 +++ .../PaymentMethodPreferenceJsonParserTest.kt | 41 +++++++++++++------ .../parsers/SetupIntentJsonParserTest.kt | 8 ++++ 5 files changed, 104 insertions(+), 12 deletions(-) diff --git a/payments-core/src/test/java/com/stripe/android/model/PaymentIntentFixtures.kt b/payments-core/src/test/java/com/stripe/android/model/PaymentIntentFixtures.kt index 83f3b7936c0..6aa2b14134e 100644 --- a/payments-core/src/test/java/com/stripe/android/model/PaymentIntentFixtures.kt +++ b/payments-core/src/test/java/com/stripe/android/model/PaymentIntentFixtures.kt @@ -2312,4 +2312,43 @@ internal object PaymentIntentFixtures { val PI_WITH_LINK_FUNDING_SOURCES by lazy { PARSER.parse(PI_WITH_LINK_FUNDING_SOURCES_JSON)!! } + + private val PI_WITH_COUNTRY_CODE_JSON by lazy { + JSONObject( + """ + { + "id": "pi_1F7J1aCRMbs6FrXfaJcvbxF6", + "object": "payment_intent", + "amount": 1099, + "canceled_at": null, + "cancellation_reason": null, + "capture_method": "manual", + "client_secret": "pi_1F7J1aCRMbs6FrXfaJcvbxF6_secret_mIuDLsSfoo1m6s", + "confirmation_method": "automatic", + "created": 1565775850, + "currency": "usd", + "description": "Example PaymentIntent", + "livemode": false, + "next_action": null, + "payment_method": null, + "payment_method_types": [ + "card" + ], + "receipt_email": null, + "setup_future_usage": null, + "shipping": null, + "source": null, + "status": "requires_payment_method", + "link_funding_sources": [ + "CARD", "BANK_ACCOUNT" + ], + "country_code": "US" + } + """.trimIndent() + ) + } + + internal val PI_WITH_COUNTRY_CODE by lazy { + PARSER.parse(PI_WITH_COUNTRY_CODE_JSON)!! + } } diff --git a/payments-core/src/test/java/com/stripe/android/model/SetupIntentFixtures.kt b/payments-core/src/test/java/com/stripe/android/model/SetupIntentFixtures.kt index dca17d69ccf..fa6dd1929b7 100644 --- a/payments-core/src/test/java/com/stripe/android/model/SetupIntentFixtures.kt +++ b/payments-core/src/test/java/com/stripe/android/model/SetupIntentFixtures.kt @@ -650,4 +650,26 @@ internal object SetupIntentFixtures { ) val SI_3DS2_PROCESSING = PARSER.parse(SI_3DS2_PROCESSING_JSON)!! + + internal val SI_WITH_COUNTRY_CODE = JSONObject( + """ + { + "id": "seti_1EqTSZGMT9dGPIDGVzCUs6dV", + "object": "setup_intent", + "cancellation_reason": null, + "client_secret": "seti_1EqTSZGMT9dGPIDGVzCUs6dV_secret_FL9mS9ILygVyGEOSmVNqHT83rxkqy0Y", + "created": 1561677666, + "description": "a description", + "last_setup_error": null, + "livemode": false, + "payment_method": "pm_1EqTSoGMT9dGPIDG7dgafX1H", + "payment_method_types": [ + "card" + ], + "status": "requires_action", + "usage": "off_session", + "country_code": "CA" + } + """.trimIndent() + ) } diff --git a/payments-core/src/test/java/com/stripe/android/model/parsers/PaymentIntentJsonParserTest.kt b/payments-core/src/test/java/com/stripe/android/model/parsers/PaymentIntentJsonParserTest.kt index f715a183ff5..3e943c2e2ac 100644 --- a/payments-core/src/test/java/com/stripe/android/model/parsers/PaymentIntentJsonParserTest.kt +++ b/payments-core/src/test/java/com/stripe/android/model/parsers/PaymentIntentJsonParserTest.kt @@ -231,4 +231,10 @@ class PaymentIntentJsonParserTest { val paymentIntent = PaymentIntentFixtures.PI_WITH_LINK_FUNDING_SOURCES assertThat(paymentIntent.linkFundingSources).containsExactly("card", "bank_account") } + + @Test + fun parse_withCountryCode_shouldCreateExpectedObject() { + val paymentIntent = PaymentIntentFixtures.PI_WITH_COUNTRY_CODE + assertThat(paymentIntent.countryCode).isEqualTo("US") + } } diff --git a/payments-core/src/test/java/com/stripe/android/model/parsers/PaymentMethodPreferenceJsonParserTest.kt b/payments-core/src/test/java/com/stripe/android/model/parsers/PaymentMethodPreferenceJsonParserTest.kt index 4077c4e34b6..3085d5b96ea 100644 --- a/payments-core/src/test/java/com/stripe/android/model/parsers/PaymentMethodPreferenceJsonParserTest.kt +++ b/payments-core/src/test/java/com/stripe/android/model/parsers/PaymentMethodPreferenceJsonParserTest.kt @@ -1,10 +1,11 @@ package com.stripe.android.model.parsers -import com.google.common.truth.Truth +import com.google.common.truth.Truth.assertThat import com.stripe.android.core.model.parsers.ModelJsonParser import com.stripe.android.model.PaymentIntentFixtures.PI_WITH_CARD_AFTERPAY_AU_BECS import com.stripe.android.model.PaymentIntentFixtures.PI_WITH_CARD_AFTERPAY_AU_BECS_NO_ORDERED_LPMS import com.stripe.android.model.PaymentMethodPreferenceFixtures +import com.stripe.android.model.countryCode import org.json.JSONObject import org.junit.Test @@ -21,9 +22,9 @@ class PaymentMethodPreferenceJsonParserTest { .optJSONArray("ordered_payment_method_types") ) - Truth.assertThat(paymentMethodPreference?.intent?.id) + assertThat(paymentMethodPreference?.intent?.id) .isEqualTo("pi_3JTDhYIyGgrkZxL71IDUGKps") - Truth.assertThat(paymentMethodPreference?.intent?.paymentMethodTypes) + assertThat(paymentMethodPreference?.intent?.paymentMethodTypes) .containsExactlyElementsIn(orderedPaymentMethods) .inOrder() } @@ -40,9 +41,9 @@ class PaymentMethodPreferenceJsonParserTest { .optJSONArray("ordered_payment_method_types") ) - Truth.assertThat(paymentMethodPreference?.intent?.id) + assertThat(paymentMethodPreference?.intent?.id) .isEqualTo("seti_1JTDqGIyGgrkZxL7reCXkpr5") - Truth.assertThat(paymentMethodPreference?.intent?.paymentMethodTypes) + assertThat(paymentMethodPreference?.intent?.paymentMethodTypes) .containsExactlyElementsIn(orderedPaymentMethods) .inOrder() } @@ -53,7 +54,7 @@ class PaymentMethodPreferenceJsonParserTest { PaymentMethodPreferenceFixtures.EXPANDED_PAYMENT_INTENT_WITH_LINK_FUNDING_SOURCES_JSON )!! - Truth.assertThat(paymentMethodPreference.intent.linkFundingSources) + assertThat(paymentMethodPreference.intent.linkFundingSources) .containsExactly("card", "bank_account") } @@ -63,7 +64,7 @@ class PaymentMethodPreferenceJsonParserTest { PaymentMethodPreferenceFixtures.EXPANDED_SETUP_INTENT_WITH_LINK_FUNDING_SOURCES_JSON )!! - Truth.assertThat(paymentMethodPreference.intent.linkFundingSources) + assertThat(paymentMethodPreference.intent.linkFundingSources) .containsExactly("card", "bank_account") } @@ -74,7 +75,7 @@ class PaymentMethodPreferenceJsonParserTest { PI_WITH_CARD_AFTERPAY_AU_BECS ) ) - Truth.assertThat(parsedData?.intent?.paymentMethodTypes).isEqualTo( + assertThat(parsedData?.intent?.paymentMethodTypes).isEqualTo( listOf( "au_becs_debit", "afterpay_clearpay", @@ -91,7 +92,7 @@ class PaymentMethodPreferenceJsonParserTest { ) ) // This is the order in the original payment intent - Truth.assertThat(parsedData?.intent?.paymentMethodTypes).isEqualTo( + assertThat(parsedData?.intent?.paymentMethodTypes).isEqualTo( listOf( "card", "afterpay_clearpay", @@ -115,7 +116,7 @@ class PaymentMethodPreferenceJsonParserTest { """.trimIndent() ) ) - Truth.assertThat(parsedData).isNull() + assertThat(parsedData).isNull() } @Test @@ -133,7 +134,7 @@ class PaymentMethodPreferenceJsonParserTest { """.trimIndent() ) ) - Truth.assertThat(parsedData).isNull() + assertThat(parsedData).isNull() } @Test @@ -149,6 +150,22 @@ class PaymentMethodPreferenceJsonParserTest { """.trimIndent() ) ) - Truth.assertThat(parsedData).isNull() + assertThat(parsedData).isNull() + } + + @Test + fun `Test PI with country code`() { + val parsedData = PaymentMethodPreferenceForPaymentIntentJsonParser().parse( + PaymentMethodPreferenceFixtures.EXPANDED_PAYMENT_INTENT_JSON + ) + assertThat(parsedData?.intent?.countryCode).isEqualTo("US") + } + + @Test + fun `Test SI with country code`() { + val parsedData = PaymentMethodPreferenceForSetupIntentJsonParser().parse( + PaymentMethodPreferenceFixtures.EXPANDED_SETUP_INTENT_JSON + ) + assertThat(parsedData?.intent?.countryCode).isEqualTo("US") } } diff --git a/payments-core/src/test/java/com/stripe/android/model/parsers/SetupIntentJsonParserTest.kt b/payments-core/src/test/java/com/stripe/android/model/parsers/SetupIntentJsonParserTest.kt index fc1e964bd12..7daf148fdaf 100644 --- a/payments-core/src/test/java/com/stripe/android/model/parsers/SetupIntentJsonParserTest.kt +++ b/payments-core/src/test/java/com/stripe/android/model/parsers/SetupIntentJsonParserTest.kt @@ -29,4 +29,12 @@ class SetupIntentJsonParserTest { assertThat(setupIntent.paymentMethod?.id) .isEqualTo("pm_1GSmaGCRMbs6F") } + + @Test + fun parse_withCountryCode_shouldCreateExpectedObject() { + val setupIntent = requireNotNull( + SetupIntentJsonParser().parse(SetupIntentFixtures.SI_WITH_COUNTRY_CODE) + ) + assertThat(setupIntent.countryCode).isEqualTo("CA") + } } From 5bb8a893002ae1595a6961993a26eec1724ac5ba Mon Sep 17 00:00:00 2001 From: Till Hellmund Date: Fri, 26 Aug 2022 15:26:20 -0400 Subject: [PATCH 4/5] Remove country code from StripeIntent for now Having the country code as a library-internal property in StripeIntent isn't easy right now. We're adding it as separate properties in SetupIntent and PaymentIntent for now, before we think about ways to refactor StripeIntent. --- .../com/stripe/android/model/PaymentIntent.kt | 3 ++- .../com/stripe/android/model/SetupIntent.kt | 4 +++- .../com/stripe/android/model/StripeIntent.kt | 10 --------- .../PaymentMethodPreferenceJsonParserTest.kt | 21 ++++++++++++++++--- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/payments-core/src/main/java/com/stripe/android/model/PaymentIntent.kt b/payments-core/src/main/java/com/stripe/android/model/PaymentIntent.kt index 7b437171863..8257a01bbc0 100644 --- a/payments-core/src/main/java/com/stripe/android/model/PaymentIntent.kt +++ b/payments-core/src/main/java/com/stripe/android/model/PaymentIntent.kt @@ -84,7 +84,8 @@ data class PaymentIntent internal constructor( /** * Country code of the user. */ - internal val countryCode: String?, + @get:RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) + val countryCode: String?, /** * Time at which the object was created. Measured in seconds since the Unix epoch. diff --git a/payments-core/src/main/java/com/stripe/android/model/SetupIntent.kt b/payments-core/src/main/java/com/stripe/android/model/SetupIntent.kt index 67105e97e4d..7ccca6e63fc 100644 --- a/payments-core/src/main/java/com/stripe/android/model/SetupIntent.kt +++ b/payments-core/src/main/java/com/stripe/android/model/SetupIntent.kt @@ -1,5 +1,6 @@ package com.stripe.android.model +import androidx.annotation.RestrictTo import com.stripe.android.core.model.StripeModel import com.stripe.android.model.parsers.SetupIntentJsonParser import kotlinx.parcelize.Parcelize @@ -33,7 +34,8 @@ data class SetupIntent internal constructor( /** * Country code of the user. */ - internal val countryCode: String?, + @get:RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) + val countryCode: String?, /** * The client secret of this SetupIntent. Used for client-side retrieval using a diff --git a/payments-core/src/main/java/com/stripe/android/model/StripeIntent.kt b/payments-core/src/main/java/com/stripe/android/model/StripeIntent.kt index 6f4c79f237e..4417806bef4 100644 --- a/payments-core/src/main/java/com/stripe/android/model/StripeIntent.kt +++ b/payments-core/src/main/java/com/stripe/android/model/StripeIntent.kt @@ -281,13 +281,3 @@ sealed interface StripeIntent : StripeModel { ) : NextActionData() } } - -/** - * Country code of the user. - */ -internal val StripeIntent.countryCode: String? - // We need to do this because an interface can't have an internal property - get() = when (this) { - is PaymentIntent -> countryCode - is SetupIntent -> countryCode - } diff --git a/payments-core/src/test/java/com/stripe/android/model/parsers/PaymentMethodPreferenceJsonParserTest.kt b/payments-core/src/test/java/com/stripe/android/model/parsers/PaymentMethodPreferenceJsonParserTest.kt index 3085d5b96ea..07ddbe8d32d 100644 --- a/payments-core/src/test/java/com/stripe/android/model/parsers/PaymentMethodPreferenceJsonParserTest.kt +++ b/payments-core/src/test/java/com/stripe/android/model/parsers/PaymentMethodPreferenceJsonParserTest.kt @@ -2,10 +2,11 @@ package com.stripe.android.model.parsers import com.google.common.truth.Truth.assertThat import com.stripe.android.core.model.parsers.ModelJsonParser +import com.stripe.android.model.PaymentIntent import com.stripe.android.model.PaymentIntentFixtures.PI_WITH_CARD_AFTERPAY_AU_BECS import com.stripe.android.model.PaymentIntentFixtures.PI_WITH_CARD_AFTERPAY_AU_BECS_NO_ORDERED_LPMS import com.stripe.android.model.PaymentMethodPreferenceFixtures -import com.stripe.android.model.countryCode +import com.stripe.android.model.SetupIntent import org.json.JSONObject import org.junit.Test @@ -158,7 +159,14 @@ class PaymentMethodPreferenceJsonParserTest { val parsedData = PaymentMethodPreferenceForPaymentIntentJsonParser().parse( PaymentMethodPreferenceFixtures.EXPANDED_PAYMENT_INTENT_JSON ) - assertThat(parsedData?.intent?.countryCode).isEqualTo("US") + + val countryCode = when (val intent = parsedData?.intent) { + is PaymentIntent -> intent.countryCode + is SetupIntent -> intent.countryCode + null -> null + } + + assertThat(countryCode).isEqualTo("US") } @Test @@ -166,6 +174,13 @@ class PaymentMethodPreferenceJsonParserTest { val parsedData = PaymentMethodPreferenceForSetupIntentJsonParser().parse( PaymentMethodPreferenceFixtures.EXPANDED_SETUP_INTENT_JSON ) - assertThat(parsedData?.intent?.countryCode).isEqualTo("US") + + val countryCode = when (val intent = parsedData?.intent) { + is PaymentIntent -> intent.countryCode + is SetupIntent -> intent.countryCode + null -> null + } + + assertThat(countryCode).isEqualTo("US") } } From 7268b00f971564e742082bdae44948cc53fe99ab Mon Sep 17 00:00:00 2001 From: Till Hellmund Date: Fri, 26 Aug 2022 15:37:58 -0400 Subject: [PATCH 5/5] Update API --- payments-core/api/payments-core.api | 3 --- 1 file changed, 3 deletions(-) diff --git a/payments-core/api/payments-core.api b/payments-core/api/payments-core.api index 02f01aa4129..8b13a9387d3 100644 --- a/payments-core/api/payments-core.api +++ b/payments-core/api/payments-core.api @@ -3185,7 +3185,6 @@ public final class com/stripe/android/model/PaymentIntent : com/stripe/android/m public final fun getCaptureMethod ()Lcom/stripe/android/model/PaymentIntent$CaptureMethod; public fun getClientSecret ()Ljava/lang/String; public final fun getConfirmationMethod ()Lcom/stripe/android/model/PaymentIntent$ConfirmationMethod; - public fun getCountryCode ()Ljava/lang/String; public fun getCreated ()J public final fun getCurrency ()Ljava/lang/String; public fun getDescription ()Ljava/lang/String; @@ -4844,7 +4843,6 @@ public final class com/stripe/android/model/SetupIntent : com/stripe/android/mod public static final fun fromJson (Lorg/json/JSONObject;)Lcom/stripe/android/model/SetupIntent; public final fun getCancellationReason ()Lcom/stripe/android/model/SetupIntent$CancellationReason; public fun getClientSecret ()Ljava/lang/String; - public fun getCountryCode ()Ljava/lang/String; public fun getCreated ()J public fun getDescription ()Ljava/lang/String; public fun getId ()Ljava/lang/String; @@ -5924,7 +5922,6 @@ public final class com/stripe/android/model/Stripe3ds2Fingerprint$DirectoryServe public abstract interface class com/stripe/android/model/StripeIntent : com/stripe/android/core/model/StripeModel { public abstract fun getClientSecret ()Ljava/lang/String; - public abstract fun getCountryCode ()Ljava/lang/String; public abstract fun getCreated ()J public abstract fun getDescription ()Ljava/lang/String; public abstract fun getId ()Ljava/lang/String;