-
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.
Move
Link
to confirmation definition (#9747)
* Move `Link` to confirmation definition * Add tests & test utils for `Link` confirmation definition * Rebase on latest changes. * Address PR comments
- Loading branch information
1 parent
c1afa5d
commit a43b22d
Showing
36 changed files
with
1,188 additions
and
317 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
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
90 changes: 90 additions & 0 deletions
90
...in/java/com/stripe/android/paymentelement/confirmation/link/LinkConfirmationDefinition.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,90 @@ | ||
package com.stripe.android.paymentelement.confirmation.link | ||
|
||
import androidx.activity.result.ActivityResultCaller | ||
import com.stripe.android.common.exception.stripeErrorMessage | ||
import com.stripe.android.link.LinkActivityResult | ||
import com.stripe.android.link.LinkPaymentLauncher | ||
import com.stripe.android.link.account.LinkStore | ||
import com.stripe.android.model.StripeIntent | ||
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 | ||
|
||
internal class LinkConfirmationDefinition( | ||
private val linkPaymentLauncher: LinkPaymentLauncher, | ||
private val linkStore: LinkStore, | ||
) : ConfirmationDefinition<LinkConfirmationOption, LinkPaymentLauncher, Unit, LinkActivityResult> { | ||
override val key: String = "Link" | ||
|
||
override fun option(confirmationOption: ConfirmationHandler.Option): LinkConfirmationOption? { | ||
return confirmationOption as? LinkConfirmationOption | ||
} | ||
|
||
override fun createLauncher( | ||
activityResultCaller: ActivityResultCaller, | ||
onResult: (LinkActivityResult) -> Unit | ||
): LinkPaymentLauncher { | ||
return linkPaymentLauncher.apply { | ||
register(activityResultCaller, onResult) | ||
} | ||
} | ||
|
||
override fun unregister(launcher: LinkPaymentLauncher) { | ||
launcher.unregister() | ||
} | ||
|
||
override suspend fun action( | ||
confirmationOption: LinkConfirmationOption, | ||
intent: StripeIntent | ||
): ConfirmationDefinition.Action<Unit> { | ||
return ConfirmationDefinition.Action.Launch( | ||
launcherArguments = Unit, | ||
receivesResultInProcess = false, | ||
deferredIntentConfirmationType = null, | ||
) | ||
} | ||
|
||
override fun launch( | ||
launcher: LinkPaymentLauncher, | ||
arguments: Unit, | ||
confirmationOption: LinkConfirmationOption, | ||
intent: StripeIntent | ||
) { | ||
launcher.present(confirmationOption.configuration) | ||
} | ||
|
||
override fun toResult( | ||
confirmationOption: LinkConfirmationOption, | ||
deferredIntentConfirmationType: DeferredIntentConfirmationType?, | ||
intent: StripeIntent, | ||
result: LinkActivityResult | ||
): ConfirmationDefinition.Result { | ||
if ( | ||
result !is LinkActivityResult.Canceled || | ||
result.reason != LinkActivityResult.Canceled.Reason.BackPressed | ||
) { | ||
linkStore.markLinkAsUsed() | ||
} | ||
|
||
return when (result) { | ||
is LinkActivityResult.Completed -> ConfirmationDefinition.Result.NextStep( | ||
confirmationOption = PaymentMethodConfirmationOption.Saved( | ||
initializationMode = confirmationOption.initializationMode, | ||
shippingDetails = confirmationOption.shippingDetails, | ||
paymentMethod = result.paymentMethod, | ||
optionsParams = null, | ||
), | ||
intent = intent, | ||
) | ||
is LinkActivityResult.Failed -> ConfirmationDefinition.Result.Failed( | ||
cause = result.error, | ||
message = result.error.stripeErrorMessage(), | ||
type = ConfirmationHandler.Result.Failed.ErrorType.Payment, | ||
) | ||
is LinkActivityResult.Canceled -> ConfirmationDefinition.Result.Canceled( | ||
action = ConfirmationHandler.Result.Canceled.Action.InformCancellation, | ||
) | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...c/main/java/com/stripe/android/paymentelement/confirmation/link/LinkConfirmationModule.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,29 @@ | ||
package com.stripe.android.paymentelement.confirmation.link | ||
|
||
import com.stripe.android.link.LinkPaymentLauncher | ||
import com.stripe.android.link.account.LinkStore | ||
import com.stripe.android.link.injection.LinkAnalyticsComponent | ||
import com.stripe.android.paymentelement.confirmation.ConfirmationDefinition | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.multibindings.IntoSet | ||
|
||
@Module( | ||
subcomponents = [ | ||
LinkAnalyticsComponent::class, | ||
] | ||
) | ||
internal object LinkConfirmationModule { | ||
@JvmSuppressWildcards | ||
@Provides | ||
@IntoSet | ||
fun providesLinkConfirmationDefinition( | ||
linkStore: LinkStore, | ||
linkPaymentLauncher: LinkPaymentLauncher, | ||
): ConfirmationDefinition<*, *, *, *> { | ||
return LinkConfirmationDefinition( | ||
linkStore = linkStore, | ||
linkPaymentLauncher = linkPaymentLauncher, | ||
) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...c/main/java/com/stripe/android/paymentelement/confirmation/link/LinkConfirmationOption.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,14 @@ | ||
package com.stripe.android.paymentelement.confirmation.link | ||
|
||
import com.stripe.android.link.LinkConfiguration | ||
import com.stripe.android.paymentelement.confirmation.ConfirmationHandler | ||
import com.stripe.android.paymentsheet.addresselement.AddressDetails | ||
import com.stripe.android.paymentsheet.state.PaymentElementLoader | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
internal data class LinkConfirmationOption( | ||
val initializationMode: PaymentElementLoader.InitializationMode, | ||
val shippingDetails: AddressDetails?, | ||
val configuration: LinkConfiguration, | ||
) : ConfirmationHandler.Option |
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
Oops, something went wrong.