-
Notifications
You must be signed in to change notification settings - Fork 662
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CVC recollection to confirmation definitions (#9890)
* Add CVC recollection to confirmation definitions * Add tests for CVC recollection confirmation definition
- Loading branch information
1 parent
b67e9c7
commit 7d51a49
Showing
26 changed files
with
1,141 additions
and
123 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
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
101 changes: 101 additions & 0 deletions
101
...m/stripe/android/paymentelement/confirmation/cvc/CvcRecollectionConfirmationDefinition.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,101 @@ | ||
package com.stripe.android.paymentelement.confirmation.cvc | ||
|
||
import androidx.activity.result.ActivityResultCaller | ||
import com.stripe.android.model.PaymentMethodOptionsParams | ||
import com.stripe.android.paymentelement.confirmation.ConfirmationDefinition | ||
import com.stripe.android.paymentelement.confirmation.ConfirmationHandler | ||
import com.stripe.android.paymentelement.confirmation.PaymentMethodConfirmationOption | ||
import com.stripe.android.paymentelement.confirmation.intent.DeferredIntentConfirmationType | ||
import com.stripe.android.paymentsheet.cvcrecollection.CvcRecollectionHandler | ||
import com.stripe.android.paymentsheet.paymentdatacollection.cvcrecollection.CvcRecollectionContract | ||
import com.stripe.android.paymentsheet.paymentdatacollection.cvcrecollection.CvcRecollectionLauncher | ||
import com.stripe.android.paymentsheet.paymentdatacollection.cvcrecollection.CvcRecollectionLauncherFactory | ||
import com.stripe.android.paymentsheet.paymentdatacollection.cvcrecollection.CvcRecollectionResult | ||
|
||
internal class CvcRecollectionConfirmationDefinition( | ||
private val handler: CvcRecollectionHandler, | ||
private val factory: CvcRecollectionLauncherFactory, | ||
) : ConfirmationDefinition< | ||
PaymentMethodConfirmationOption.Saved, | ||
CvcRecollectionLauncher, | ||
Unit, | ||
CvcRecollectionResult, | ||
> { | ||
override val key: String = "CvcRecollection" | ||
|
||
override fun option(confirmationOption: ConfirmationHandler.Option): PaymentMethodConfirmationOption.Saved? { | ||
return confirmationOption as? PaymentMethodConfirmationOption.Saved | ||
} | ||
|
||
override fun canConfirm( | ||
confirmationOption: PaymentMethodConfirmationOption.Saved, | ||
confirmationParameters: ConfirmationDefinition.Parameters, | ||
): Boolean { | ||
return handler.requiresCVCRecollection( | ||
stripeIntent = confirmationParameters.intent, | ||
initializationMode = confirmationParameters.initializationMode, | ||
paymentMethod = confirmationOption.paymentMethod, | ||
optionsParams = confirmationOption.optionsParams, | ||
) | ||
} | ||
|
||
override suspend fun action( | ||
confirmationOption: PaymentMethodConfirmationOption.Saved, | ||
confirmationParameters: ConfirmationDefinition.Parameters | ||
): ConfirmationDefinition.Action<Unit> { | ||
return ConfirmationDefinition.Action.Launch( | ||
launcherArguments = Unit, | ||
receivesResultInProcess = true, | ||
deferredIntentConfirmationType = null, | ||
) | ||
} | ||
|
||
override fun createLauncher( | ||
activityResultCaller: ActivityResultCaller, | ||
onResult: (CvcRecollectionResult) -> Unit | ||
): CvcRecollectionLauncher { | ||
return factory.create( | ||
activityResultLauncher = activityResultCaller.registerForActivityResult( | ||
CvcRecollectionContract(), | ||
onResult, | ||
), | ||
) | ||
} | ||
|
||
override fun launch( | ||
launcher: CvcRecollectionLauncher, | ||
arguments: Unit, | ||
confirmationOption: PaymentMethodConfirmationOption.Saved, | ||
confirmationParameters: ConfirmationDefinition.Parameters | ||
) { | ||
handler.launch(confirmationOption.paymentMethod) { recollectionData -> | ||
launcher.launch( | ||
data = recollectionData, | ||
appearance = confirmationParameters.appearance, | ||
isLiveMode = confirmationParameters.intent.isLiveMode, | ||
) | ||
} | ||
} | ||
|
||
override fun toResult( | ||
confirmationOption: PaymentMethodConfirmationOption.Saved, | ||
confirmationParameters: ConfirmationDefinition.Parameters, | ||
deferredIntentConfirmationType: DeferredIntentConfirmationType?, | ||
result: CvcRecollectionResult | ||
): ConfirmationDefinition.Result { | ||
return when (result) { | ||
is CvcRecollectionResult.Confirmed -> ConfirmationDefinition.Result.NextStep( | ||
confirmationOption = confirmationOption.copy( | ||
optionsParams = when (val params = confirmationOption.optionsParams) { | ||
is PaymentMethodOptionsParams.Card -> params.copy(cvc = result.cvc) | ||
else -> PaymentMethodOptionsParams.Card(cvc = result.cvc) | ||
} | ||
), | ||
parameters = confirmationParameters, | ||
) | ||
is CvcRecollectionResult.Cancelled -> ConfirmationDefinition.Result.Canceled( | ||
action = ConfirmationHandler.Result.Canceled.Action.None, | ||
) | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...a/com/stripe/android/paymentelement/confirmation/cvc/CvcRecollectionConfirmationModule.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,33 @@ | ||
package com.stripe.android.paymentelement.confirmation.cvc | ||
|
||
import com.stripe.android.paymentelement.confirmation.ConfirmationDefinition | ||
import com.stripe.android.paymentsheet.cvcrecollection.CvcRecollectionHandler | ||
import com.stripe.android.paymentsheet.cvcrecollection.CvcRecollectionHandlerImpl | ||
import com.stripe.android.paymentsheet.paymentdatacollection.cvcrecollection.CvcRecollectionLauncherFactory | ||
import com.stripe.android.paymentsheet.paymentdatacollection.cvcrecollection.DefaultCvcRecollectionLauncherFactory | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.multibindings.IntoSet | ||
|
||
@Module | ||
internal class CvcRecollectionConfirmationModule { | ||
@Provides | ||
fun provideCvcRecollectionLauncherFactory(): CvcRecollectionLauncherFactory { | ||
return DefaultCvcRecollectionLauncherFactory | ||
} | ||
|
||
@Provides | ||
fun provideCvcRecollectionHandler(): CvcRecollectionHandler { | ||
return CvcRecollectionHandlerImpl() | ||
} | ||
|
||
@JvmSuppressWildcards | ||
@Provides | ||
@IntoSet | ||
fun providesCvcConfirmationDefinition( | ||
cvcRecollectionLauncherFactory: CvcRecollectionLauncherFactory, | ||
cvcRecollectionHandler: CvcRecollectionHandler, | ||
): ConfirmationDefinition<*, *, *, *> { | ||
return CvcRecollectionConfirmationDefinition(cvcRecollectionHandler, cvcRecollectionLauncherFactory) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...android/paymentelement/confirmation/injection/ExtendedPaymentElementConfirmationModule.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,12 @@ | ||
package com.stripe.android.paymentelement.confirmation.injection | ||
|
||
import com.stripe.android.paymentelement.confirmation.cvc.CvcRecollectionConfirmationModule | ||
import dagger.Module | ||
|
||
@Module( | ||
includes = [ | ||
CvcRecollectionConfirmationModule::class, | ||
PaymentElementConfirmationModule::class, | ||
] | ||
) | ||
internal interface ExtendedPaymentElementConfirmationModule |
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
Oops, something went wrong.