diff --git a/payments-core/api/payments-core.api b/payments-core/api/payments-core.api index bed84e62f89..8b13a9387d3 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; @@ -4820,22 +4821,23 @@ 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; 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..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 @@ -81,6 +81,12 @@ data class PaymentIntent internal constructor( */ val confirmationMethod: ConfirmationMethod = ConfirmationMethod.Automatic, + /** + * Country code of the user. + */ + @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 d58beadcefa..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 @@ -30,6 +31,12 @@ data class SetupIntent internal constructor( */ override val created: Long, + /** + * Country code of the user. + */ + @get:RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) + 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/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() 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..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 @@ -1,10 +1,12 @@ 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.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.SetupIntent import org.json.JSONObject import org.junit.Test @@ -21,9 +23,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 +42,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 +55,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 +65,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 +76,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 +93,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 +117,7 @@ class PaymentMethodPreferenceJsonParserTest { """.trimIndent() ) ) - Truth.assertThat(parsedData).isNull() + assertThat(parsedData).isNull() } @Test @@ -133,7 +135,7 @@ class PaymentMethodPreferenceJsonParserTest { """.trimIndent() ) ) - Truth.assertThat(parsedData).isNull() + assertThat(parsedData).isNull() } @Test @@ -149,6 +151,36 @@ 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 + ) + + val countryCode = when (val intent = parsedData?.intent) { + is PaymentIntent -> intent.countryCode + is SetupIntent -> intent.countryCode + null -> null + } + + assertThat(countryCode).isEqualTo("US") + } + + @Test + fun `Test SI with country code`() { + val parsedData = PaymentMethodPreferenceForSetupIntentJsonParser().parse( + PaymentMethodPreferenceFixtures.EXPANDED_SETUP_INTENT_JSON + ) + + val countryCode = when (val intent = parsedData?.intent) { + is PaymentIntent -> intent.countryCode + is SetupIntent -> intent.countryCode + null -> null + } + + assertThat(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") + } }