-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding new PaymentSheet FormElement for Blik payment method. (#7062)
* Added pln currency support * BLIK Localization * Added BLIK to PaymentSheet * Discovery * UI Form * Add parameter isOptions to data class IdentifierSpec * Parse isOptions IdentifierSpec * Ignore isOptions in Params parser * passing PaymentMethodOptionsParams through layers * Add blik * formatting * set options to Parsed form * cleanup discovery commit * cleanup discovery commit test * undo accidental deletion * undo accidental comment formatting * use IdentifierSpec.Code to lookup fieldValuePairs entry * use enum RequestDestination to determine api parameter * rename Code to BlikCode * Move Enum to Top-Level * Remove redundant if branch * removed unused function overrides * Revert "BLIK Localization" This reverts commit 62cf223. * run `./gradlew ktlint` * Formatting * Ran ./gradlew :stripe-ui-core:apiDump * Ran ./gradlew :stripe-ui-core:apiDump * Ran ./gradlew apiDump * Default null * use blik text * remove sectionFieldElement label * cleanup and pass parameters * remove unused import * remove unused parameter * restructure parameters * ran ./gradlew apiDump * Add data driven tests for BLIK * Fix data driven tests for BLIK * polling ctaText * using BLIK specific polling * Formatting * update test for multiple authenticators * fine tune validator * don't look for browser if polling * logic for PollingSucceedsAfterDelay * BLIK payment sheet test * Support PLN * Add Polling AuthorizeAction * Formatting and Grammar * Formatting * revert temp changes * Use polling specific logic when polling * Import success text * Make blik polling timeout 30 seconds * Specify blik instead of using automatic * remove waitPollingComplete * update logic to wait for polling to finish * update comment * format * revert temp debugging change * update changelog * remove redundant length check * make IdentifierSpec.BlikCode the default argument * remove comment * remove unused parameter * error instead of defaulting to UPI * remove comment * deduplicate declaration in if * validate argument of unregisterAuthenticator * mark Blik and BlikCode as RestrictTo.Scope.LIBRARY_GROUP * mark RequestDestination with RestrictTo.Scope.LIBRARY_GROUP * rename confirmPaymentMethodOptions to optionsParams * replace VALID_INPUT_RANGES with isDigit() * ktlint * fix MaximumLineLength exceeded * remove BLIK and RequestDestination * ktlint * rename RequestDestination to ApiParameterDestination * detekt * add @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) for transformToPaymentMethodOptionsParams and fix apiCheck * Fix BLIK PaymentSheet Changelog
- Loading branch information
1 parent
c889dff
commit 7501a0e
Showing
37 changed files
with
573 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
payments-ui-core/res/drawable/stripe_ic_paymentsheet_pm_blik.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<vector android:height="16dp" android:viewportHeight="32" | ||
android:viewportWidth="32" android:width="16dp" | ||
xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:pathData="M0,0h32v32H0z"> | ||
<aapt:attr name="android:fillColor"> | ||
<gradient android:endX="15.999" android:endY="0.123" | ||
android:startX="15.999" android:startY="31.772" android:type="linear"> | ||
<item android:color="#FF5A5A5A" android:offset="0"/> | ||
<item android:color="#FF494949" android:offset="0.146"/> | ||
<item android:color="#FF212121" android:offset="0.52"/> | ||
<item android:color="#FF090909" android:offset="0.817"/> | ||
<item android:color="#FF000000" android:offset="1"/> | ||
</gradient> | ||
</aapt:attr> | ||
</path> | ||
<path android:fillColor="#FFF" android:pathData="M16.276,13.305a6.269,6.269 0,0 0,-2.968 0.745L13.308,6.95L10,6.95v12.629a6.277,6.277 0,0 0,12.553 0,6.275 6.275,0 0,0 -6.277,-6.274ZM16.276,22.6a3.021,3.021 0,1 1,0 -6.042,3.021 3.021,0 0,1 0,6.042Z"/> | ||
<path android:pathData="M19.592,8.961m-2.961,0a2.961,2.961 0,1 1,5.922 0a2.961,2.961 0,1 1,-5.922 0"> | ||
<aapt:attr name="android:fillColor"> | ||
<gradient android:endX="21.686" android:endY="11.097" | ||
android:startX="17.497" android:startY="6.835" android:type="linear"> | ||
<item android:color="#FFE52F08" android:offset="0"/> | ||
<item android:color="#FFE94F96" android:offset="1"/> | ||
</gradient> | ||
</aapt:attr> | ||
</path> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
payments-ui-core/src/main/java/com/stripe/android/ui/core/elements/BlikConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.stripe.android.ui.core.elements | ||
|
||
import androidx.annotation.RestrictTo | ||
import androidx.annotation.StringRes | ||
import androidx.compose.ui.text.input.KeyboardCapitalization | ||
import androidx.compose.ui.text.input.KeyboardType | ||
import androidx.compose.ui.text.input.VisualTransformation | ||
import com.stripe.android.ui.core.R | ||
import com.stripe.android.uicore.elements.TextFieldConfig | ||
import com.stripe.android.uicore.elements.TextFieldIcon | ||
import com.stripe.android.uicore.elements.TextFieldState | ||
import com.stripe.android.uicore.elements.TextFieldStateConstants | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
|
||
private const val BLIK_MAX_LENGTH = 6 | ||
|
||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
class BlikConfig : TextFieldConfig { | ||
|
||
private val blikPattern: Regex by lazy { | ||
"^[0-9]{6}\$".toRegex() | ||
} | ||
|
||
@StringRes | ||
override val label: Int = R.string.stripe_blik_code | ||
|
||
override val capitalization: KeyboardCapitalization = KeyboardCapitalization.None | ||
override val debugLabel: String = "blik_code" | ||
override val keyboard: KeyboardType = KeyboardType.Number | ||
override val visualTransformation: VisualTransformation? = null | ||
override val trailingIcon: StateFlow<TextFieldIcon?> = MutableStateFlow(value = null) | ||
override val loading: StateFlow<Boolean> = MutableStateFlow(value = false) | ||
|
||
override fun determineState(input: String): TextFieldState { | ||
val isValid = blikPattern.matches(input) | ||
return if (input.isEmpty()) { | ||
TextFieldStateConstants.Error.Blank | ||
} else if (isValid) { | ||
TextFieldStateConstants.Valid.Limitless | ||
} else if (!input.all { it.isDigit() }) { | ||
TextFieldStateConstants.Error.Invalid( | ||
errorMessageResId = R.string.stripe_invalid_blik_code | ||
) | ||
} else if (input.length < BLIK_MAX_LENGTH) { | ||
TextFieldStateConstants.Error.Incomplete( | ||
errorMessageResId = R.string.stripe_incomplete_blik_code | ||
) | ||
} else { | ||
TextFieldStateConstants.Error.Invalid( | ||
errorMessageResId = R.string.stripe_invalid_blik_code | ||
) | ||
} | ||
} | ||
|
||
override fun filter(userTyped: String) = | ||
userTyped.filter { it.isDigit() }.take(BLIK_MAX_LENGTH) | ||
|
||
override fun convertToRaw(displayName: String): String = displayName | ||
|
||
override fun convertFromRaw(rawValue: String): String = rawValue | ||
} |
25 changes: 25 additions & 0 deletions
25
payments-ui-core/src/main/java/com/stripe/android/ui/core/elements/BlikElement.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.stripe.android.ui.core.elements | ||
|
||
import androidx.annotation.RestrictTo | ||
import com.stripe.android.uicore.elements.IdentifierSpec | ||
import com.stripe.android.uicore.elements.InputController | ||
import com.stripe.android.uicore.elements.SectionSingleFieldElement | ||
import com.stripe.android.uicore.elements.SimpleTextFieldController | ||
import com.stripe.android.uicore.forms.FormFieldEntry | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
|
||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) | ||
class BlikElement( | ||
override val identifier: IdentifierSpec = IdentifierSpec.BlikCode, | ||
override val controller: InputController = SimpleTextFieldController( | ||
textFieldConfig = BlikConfig() | ||
) | ||
) : SectionSingleFieldElement(identifier = identifier) { | ||
|
||
override fun getFormFieldValueFlow(): Flow<List<Pair<IdentifierSpec, FormFieldEntry>>> { | ||
return controller.formFieldValue.map { entry -> | ||
listOf(identifier to entry) | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
payments-ui-core/src/main/java/com/stripe/android/ui/core/elements/BlikSpec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.stripe.android.ui.core.elements | ||
|
||
import androidx.annotation.RestrictTo | ||
import com.stripe.android.uicore.elements.IdentifierSpec | ||
import com.stripe.android.uicore.elements.SectionElement | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX) | ||
@Serializable | ||
data class BlikSpec( | ||
@SerialName("api_path") | ||
override val apiPath: IdentifierSpec = IdentifierSpec.Blik | ||
) : FormItemSpec() { | ||
fun transform(): SectionElement { | ||
return createSectionElement( | ||
sectionFieldElement = BlikElement(), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
payments-ui-core/src/test/java/com/stripe/android/ui/core/elements/BlikConfigTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.stripe.android.ui.core.elements | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import com.stripe.android.uicore.elements.TextFieldStateConstants.Error.Blank | ||
import com.stripe.android.uicore.elements.TextFieldStateConstants.Error.Incomplete | ||
import com.stripe.android.uicore.elements.TextFieldStateConstants.Error.Invalid | ||
import com.stripe.android.uicore.elements.TextFieldStateConstants.Valid.Limitless | ||
import org.junit.Test | ||
|
||
class BlikConfigTest { | ||
private val config = BlikConfig() | ||
|
||
@Test | ||
fun `Treats empty input as blank`() { | ||
val state = config.determineState("") | ||
assertThat(state).isEqualTo(Blank) | ||
} | ||
|
||
@Test | ||
fun `Rejects blank input`() { | ||
assertThat(config.filter(" ")).isEqualTo("") | ||
} | ||
|
||
@Test | ||
fun `Rejects non-numeric input`() { | ||
assertThat(config.filter(" ")).isEqualTo("") | ||
} | ||
|
||
@Test | ||
fun `Treats input with less than six digits as incomplete`() { | ||
val state = config.determineState("12345") | ||
assertThat(state).isInstanceOf(Incomplete::class.java) | ||
} | ||
|
||
@Test | ||
fun `Treats input more than six digits as invalid`() { | ||
assertThat(config.determineState("1234567")).isInstanceOf(Invalid::class.java) | ||
} | ||
|
||
@Test | ||
fun `Treats non-numeric input as blank`() { | ||
assertThat(config.determineState("12a456")).isInstanceOf(Invalid::class.java) | ||
assertThat(config.determineState("abcdef")).isInstanceOf(Invalid::class.java) | ||
assertThat(config.determineState("stripe.com")).isInstanceOf(Invalid::class.java) | ||
} | ||
|
||
@Test | ||
fun `Treats valid input as valid and limitless`() { | ||
val state = config.determineState("123456") | ||
assertThat(state).isInstanceOf(Limitless::class.java) | ||
} | ||
} |
Oops, something went wrong.