Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Klarna with SI&PIwSFU. #8132

Merged
merged 8 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## XX.XX.XX - 2023-XX-XX

### PaymentSheet
* [Added] Support for Klarna with SetupIntents and PaymentIntents with `setup_future_usage`.

## 20.40.0 - 2024-03-18

### PaymentSheet
Expand Down
24 changes: 24 additions & 0 deletions payments-ui-core/api/payments-ui-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,30 @@ public final class com/stripe/android/ui/core/elements/KlarnaHeaderStaticTextSpe
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/ui/core/elements/KlarnaMandateTextSpec$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
public static final field $stable I
public static final field INSTANCE Lcom/stripe/android/ui/core/elements/KlarnaMandateTextSpec$$serializer;
public fun childSerializers ()[Lkotlinx/serialization/KSerializer;
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lcom/stripe/android/ui/core/elements/KlarnaMandateTextSpec;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lcom/stripe/android/ui/core/elements/KlarnaMandateTextSpec;)V
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
}

public final class com/stripe/android/ui/core/elements/KlarnaMandateTextSpec$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class com/stripe/android/ui/core/elements/KlarnaMandateTextSpec$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/ui/core/elements/KlarnaMandateTextSpec;
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
public final fun newArray (I)[Lcom/stripe/android/ui/core/elements/KlarnaMandateTextSpec;
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/ui/core/elements/KonbiniConfirmationNumberSpec$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/ui/core/elements/KonbiniConfirmationNumberSpec;
Expand Down
2 changes: 2 additions & 0 deletions payments-ui-core/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
<string name="stripe_invalid_upi_id">Invalid UPI ID</string>
<!-- Klarna buy now or pay later copy -->
<string name="stripe_klarna_buy_now_pay_later">Buy now or pay later with Klarna.</string>
<!-- Klarna mandate text -->
<string name="stripe_klarna_mandate">By continuing to Klarna, you allow %1$s to charge your Klarna account for future payments in accordance with their terms and Klarna\'s terms. You can change this at any time in your Klarna app or by reaching out to %2$s.</string>
<!-- Klarna pay later copy -->
<string name="stripe_klarna_pay_later">Pay later with Klarna.</string>
<!-- Caption for Phone field on address form -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ sealed class FormItemSpec : Parcelable {

object FormItemSpecSerializer :
JsonContentPolymorphicSerializer<FormItemSpec>(FormItemSpec::class) {
override fun selectDeserializer(element: JsonElement): DeserializationStrategy<out FormItemSpec> {
override fun selectDeserializer(element: JsonElement): DeserializationStrategy<FormItemSpec> {
return when (element.jsonObject["type"]?.jsonPrimitive?.content) {
"billing_address" -> AddressSpec.serializer()
"affirm_header" -> AffirmTextSpec.serializer()
Expand All @@ -49,7 +49,7 @@ object FormItemSpecSerializer :
"selector" -> DropdownSpec.serializer()
"email" -> EmailSpec.serializer()
"iban" -> IbanSpec.serializer()
"klarna_country" -> KlarnaCountrySpec.serializer()
"klarna_country" -> CountrySpec.serializer()
"klarna_header" -> KlarnaHeaderStaticTextSpec.serializer()
"static_text" -> StaticTextSpec.serializer()
"name" -> NameSpec.serializer()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.stripe.android.ui.core.elements

import androidx.annotation.RestrictTo
import com.stripe.android.ui.core.R
import com.stripe.android.uicore.elements.FormElement
import com.stripe.android.uicore.elements.IdentifierSpec
import kotlinx.parcelize.Parcelize
Expand All @@ -22,6 +23,6 @@ data class KlarnaHeaderStaticTextSpec(
// since it doesn't provide a form field we leave it out for now
StaticTextElement(
this.apiPath,
stringResId = KlarnaHelper.getKlarnaHeader()
stringResId = R.string.stripe_klarna_buy_now_pay_later
)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.stripe.android.ui.core.elements

import androidx.annotation.RestrictTo
import androidx.annotation.StringRes
import com.stripe.android.ui.core.R
import com.stripe.android.uicore.elements.FormElement
import com.stripe.android.uicore.elements.IdentifierSpec
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@Serializable
@Parcelize
data class KlarnaMandateTextSpec(
@SerialName("api_path")
override val apiPath: IdentifierSpec = IdentifierSpec.Generic("klarna_mandate"),
@StringRes
val stringResId: Int = R.string.stripe_klarna_mandate,
) : FormItemSpec() {

@IgnoredOnParcel
@Transient
private val mandateTextSpec = MandateTextSpec(apiPath, stringResId)

fun transform(merchantName: String): FormElement {
return mandateTextSpec.transform(merchantName, merchantName)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.style.TextAlign
Expand All @@ -24,5 +25,6 @@ fun MandateTextUI(
modifier = Modifier
.padding(vertical = 8.dp)
.semantics(mergeDescendants = true) {} // makes it a separate accessibile item
.testTag("mandate")
samer-stripe marked this conversation as resolved.
Show resolved Hide resolved
)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package com.stripe.android.lpm

import androidx.test.ext.junit.runners.AndroidJUnit4
import com.stripe.android.BasePlaygroundTest
import com.stripe.android.paymentsheet.example.playground.settings.AutomaticPaymentMethodsSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.CheckoutMode
import com.stripe.android.paymentsheet.example.playground.settings.CheckoutModeSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.Country
import com.stripe.android.paymentsheet.example.playground.settings.CountrySettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.Currency
import com.stripe.android.paymentsheet.example.playground.settings.CurrencySettingsDefinition
import com.stripe.android.test.core.TestParameters
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith

Expand All @@ -18,21 +20,40 @@ internal class TestKlarna : BasePlaygroundTest() {
) { settings ->
settings[CountrySettingsDefinition] = Country.US
settings[CurrencySettingsDefinition] = Currency.USD
settings[AutomaticPaymentMethodsSettingsDefinition] = true
}

@Ignore("Complex authorization handling required")
@Test
fun testKlarna() {
testDriver.confirmNewOrGuestComplete(
fun testKlarnaInCustomFlow() {
testDriver.confirmCustom(
testParameters = testParameters,
verifyCustomLpmFields = {
verifyMandateFieldDoesNotExists()
},
)
}

@Ignore("Complex authorization handling required")
@Test
fun testKlarnaInCustomFlow() {
fun testKlarnaSetupFutureUsage() {
testDriver.confirmCustom(
testParameters = testParameters,
testParameters = testParameters.copyPlaygroundSettings { settings ->
settings[CheckoutModeSettingsDefinition] = CheckoutMode.PAYMENT_WITH_SETUP
},
verifyCustomLpmFields = {
verifyMandateFieldExists()
},
)
}

@Test
fun testKlarnaSetupIntentInCustomFlow() {
testDriver.confirmCustom(
testParameters = testParameters.copyPlaygroundSettings { settings ->
settings[CheckoutModeSettingsDefinition] = CheckoutMode.SETUP
},
Comment on lines +51 to +53
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to test PI+SFU?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is tested in the testKlarnaSetupFutureUsage method.

verifyCustomLpmFields = {
verifyMandateFieldExists()
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.stripe.android.test.core

import androidx.compose.ui.test.SemanticsNodeInteraction
import androidx.compose.ui.test.assertContentDescriptionEquals
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsOff
import androidx.compose.ui.test.assertIsOn
import androidx.compose.ui.test.assertIsToggleable
Expand Down Expand Up @@ -267,6 +268,14 @@ internal class FieldPopulator(
.ifExistsAssertContentDescriptionEquals(accessibleCvc)
}

fun verifyMandateFieldExists() {
selectors.mandateText.assertIsDisplayed()
}

fun verifyMandateFieldDoesNotExists() {
selectors.mandateText.assertDoesNotExist()
}

private fun SemanticsNodeInteraction.ifExistsAssertContentDescriptionEquals(contentDescription: String) {
ifExistsAssert { assertContentDescriptionEquals(contentDescription) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ internal class Selectors(
testParameters.paymentMethodCode
)

val mandateText = composeTestRule.onNodeWithTag("mandate")

val buyButton = BuyButton(
composeTestRule = composeTestRule,
processingCompleteTimeout = if (testParameters.paymentMethodCode == CashAppPay.code) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import com.stripe.android.ui.core.elements.EmptyFormElement
import com.stripe.android.ui.core.elements.EmptyFormSpec
import com.stripe.android.ui.core.elements.FormItemSpec
import com.stripe.android.ui.core.elements.IbanSpec
import com.stripe.android.ui.core.elements.KlarnaCountrySpec
import com.stripe.android.ui.core.elements.KlarnaHeaderStaticTextSpec
import com.stripe.android.ui.core.elements.KlarnaMandateTextSpec
import com.stripe.android.ui.core.elements.KonbiniConfirmationNumberSpec
import com.stripe.android.ui.core.elements.LayoutSpec
import com.stripe.android.ui.core.elements.MandateTextSpec
Expand Down Expand Up @@ -107,7 +107,6 @@ class TransformSpecToElements(
is AuBankAccountNumberSpec -> it.transform(initialValues)
is IbanSpec -> it.transform(initialValues)
is KlarnaHeaderStaticTextSpec -> it.transform()
is KlarnaCountrySpec -> it.transform(amount?.currencyCode, initialValues)
is DropdownSpec -> it.transform(initialValues)
is CountrySpec -> it.transform(initialValues)
is AddressSpec -> it.transform(
Expand All @@ -128,6 +127,7 @@ class TransformSpecToElements(
is ContactInformationSpec -> it.transform(initialValues)
is PlaceholderSpec -> error("Placeholders should be processed before calling transform.")
is CashAppPayMandateTextSpec -> it.transform(merchantName)
is KlarnaMandateTextSpec -> it.transform(merchantName)
}
}.takeUnless { it.isEmpty() } ?: listOf(EmptyFormElement())
}
Expand Down
Loading
Loading