Skip to content

Commit

Permalink
Remove country code from StripeIntent for now
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tillh-stripe committed Aug 26, 2022
1 parent 25a6160 commit 5bb8a89
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -158,14 +159,28 @@ 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
fun `Test SI with country code`() {
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")
}
}

0 comments on commit 5bb8a89

Please sign in to comment.