diff --git a/app/src/main/java/com/kickstarter/libs/utils/extensions/ContextExt.kt b/app/src/main/java/com/kickstarter/libs/utils/extensions/ContextExt.kt index 816b79d5c7..f4c8f486ba 100644 --- a/app/src/main/java/com/kickstarter/libs/utils/extensions/ContextExt.kt +++ b/app/src/main/java/com/kickstarter/libs/utils/extensions/ContextExt.kt @@ -103,25 +103,15 @@ fun Context.showAlertDialog( * Provides the configuration for the PaymentSheet, following the specs * @see [link](https://stripe.com/docs/payments/accept-a-payment?platform=android&ui=elements#android-flowcontroller) */ -fun Context.getPaymentSheetConfiguration(userEmail: String, alwaysHideLink: Boolean): PaymentSheet.Configuration { +fun Context.getPaymentSheetConfiguration(userEmail: String): PaymentSheet.Configuration { val stripeLinkEnabled = this.getEnvironment()?.featureFlagClient()?.getBoolean(FlagKey.ANDROID_STRIPE_LINK) ?: false - val billingDetailsCollectionConfiguration = - if (alwaysHideLink || !stripeLinkEnabled) { - PaymentSheet.BillingDetailsCollectionConfiguration( - email = PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always // Turn off Link - ) - } else { - PaymentSheet.BillingDetailsCollectionConfiguration( - email = PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Automatic - ) - } + // TODO: Wait for stripe to devise a client-side option for turning off link return PaymentSheet.Configuration( merchantDisplayName = getString(R.string.app_name), allowsDelayedPaymentMethods = true, appearance = this.getPaymentSheetAppearance(), - defaultBillingDetails = PaymentSheet.BillingDetails(email = userEmail), - billingDetailsCollectionConfiguration = billingDetailsCollectionConfiguration + defaultBillingDetails = PaymentSheet.BillingDetails(email = userEmail) ) } diff --git a/app/src/main/java/com/kickstarter/ui/activities/PaymentMethodsSettingsActivity.kt b/app/src/main/java/com/kickstarter/ui/activities/PaymentMethodsSettingsActivity.kt index 1a353421d1..75f3688d0b 100644 --- a/app/src/main/java/com/kickstarter/ui/activities/PaymentMethodsSettingsActivity.kt +++ b/app/src/main/java/com/kickstarter/ui/activities/PaymentMethodsSettingsActivity.kt @@ -114,7 +114,7 @@ class PaymentMethodsSettingsActivity : AppCompatActivity() { .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe { - flowControllerPresentPaymentOption(it) + flowControllerPresentPaymentOption(it.first, it.second) } ) @@ -143,10 +143,10 @@ class PaymentMethodsSettingsActivity : AppCompatActivity() { super.onDestroy() } - private fun flowControllerPresentPaymentOption(clientSecret: String) { + private fun flowControllerPresentPaymentOption(clientSecret: String, userEmail: String) { flowController.configureWithSetupIntent( setupIntentClientSecret = clientSecret, - configuration = this.getPaymentSheetConfiguration("", true), // Always hide Link on settings page + configuration = this.getPaymentSheetConfiguration(userEmail), callback = ::onConfigured ) } diff --git a/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt b/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt index f820e2b5c2..2a707ae3f4 100644 --- a/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt +++ b/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt @@ -1261,7 +1261,7 @@ class ProjectPageActivity : private fun flowControllerPresentPaymentOption(clientSecret: String, userEmail: String) { flowController.configureWithSetupIntent( setupIntentClientSecret = clientSecret, - configuration = getPaymentSheetConfiguration(userEmail, false), + configuration = getPaymentSheetConfiguration(userEmail), callback = ::onConfigured ) } diff --git a/app/src/main/java/com/kickstarter/ui/fragments/PledgeFragment.kt b/app/src/main/java/com/kickstarter/ui/fragments/PledgeFragment.kt index a018059364..daa8adfc12 100644 --- a/app/src/main/java/com/kickstarter/ui/fragments/PledgeFragment.kt +++ b/app/src/main/java/com/kickstarter/ui/fragments/PledgeFragment.kt @@ -701,7 +701,7 @@ class PledgeFragment : context?.let { flowController.configureWithSetupIntent( setupIntentClientSecret = clientSecret, - configuration = it.getPaymentSheetConfiguration(userEmail, false), + configuration = it.getPaymentSheetConfiguration(userEmail), callback = ::onConfigured ) } diff --git a/app/src/main/java/com/kickstarter/viewmodels/PaymentMethodsViewModel.kt b/app/src/main/java/com/kickstarter/viewmodels/PaymentMethodsViewModel.kt index d30a1d965e..5cdebd342f 100644 --- a/app/src/main/java/com/kickstarter/viewmodels/PaymentMethodsViewModel.kt +++ b/app/src/main/java/com/kickstarter/viewmodels/PaymentMethodsViewModel.kt @@ -1,9 +1,11 @@ package com.kickstarter.viewmodels import DeletePaymentSourceMutation +import android.util.Pair import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import com.kickstarter.libs.Environment +import com.kickstarter.libs.rx.transformers.Transformers.combineLatestPair import com.kickstarter.libs.rx.transformers.Transformers.errorsV2 import com.kickstarter.libs.rx.transformers.Transformers.neverErrorV2 import com.kickstarter.libs.rx.transformers.Transformers.takeWhenV2 @@ -58,7 +60,7 @@ interface Outputs { fun successDeleting(): Observable /** Emits after calling CreateSetupIntent mutation with the SetupClientId. */ - fun presentPaymentSheet(): Observable + fun presentPaymentSheet(): Observable> /** Emits in case something went wrong with CreateSetupIntent mutation */ fun showError(): Observable @@ -82,7 +84,7 @@ class PaymentMethodsViewModel(environment: Environment) : ViewModel(), PaymentMe private val showDeleteCardDialog = BehaviorSubject.create() private val successDeleting = BehaviorSubject.create() private val successSaving = BehaviorSubject.create() - private val presentPaymentSheet = PublishSubject.create() + private val presentPaymentSheet = PublishSubject.create>() private val showError = PublishSubject.create() private val loadingConfirmed = PublishSubject.create() @@ -151,6 +153,7 @@ class PaymentMethodsViewModel(environment: Environment) : ViewModel(), PaymentMe compositeDisposable.add( shouldPresentPaymentSheet .compose(valuesV2()) + .compose(combineLatestPair(userEmail())) .subscribe { this.presentPaymentSheet.onNext(it) } @@ -171,7 +174,8 @@ class PaymentMethodsViewModel(environment: Environment) : ViewModel(), PaymentMe .map { SavePaymentMethodData( reusable = true, - intentClientSecret = it + intentClientSecret = it.first + ) } .switchMap { @@ -243,6 +247,12 @@ class PaymentMethodsViewModel(environment: Environment) : ViewModel(), PaymentMe .doAfterTerminate { this.progressBarIsVisible.onNext(false) } } + private fun userEmail(): Observable { + return this.apolloClient.userPrivacy() + .compose(neverErrorV2()) + .map { it.email } + } + // - Inputs override fun newCardButtonClicked() = this.newCardButtonPressed.onNext(Unit) @@ -276,7 +286,7 @@ class PaymentMethodsViewModel(environment: Environment) : ViewModel(), PaymentMe override fun successDeleting(): Observable = this.successDeleting @Override - override fun presentPaymentSheet(): Observable = + override fun presentPaymentSheet(): Observable> = this.presentPaymentSheet @Override diff --git a/app/src/test/java/com/kickstarter/viewmodels/PaymentMethodsViewModelTest.kt b/app/src/test/java/com/kickstarter/viewmodels/PaymentMethodsViewModelTest.kt index 012fe30561..7b1902e2bf 100644 --- a/app/src/test/java/com/kickstarter/viewmodels/PaymentMethodsViewModelTest.kt +++ b/app/src/test/java/com/kickstarter/viewmodels/PaymentMethodsViewModelTest.kt @@ -1,6 +1,7 @@ package com.kickstarter.viewmodels import DeletePaymentSourceMutation +import android.util.Pair import com.kickstarter.KSRobolectricTestCase import com.kickstarter.libs.Environment import com.kickstarter.mock.factories.StoredCardFactory @@ -25,7 +26,7 @@ class PaymentMethodsViewModelTest : KSRobolectricTestCase() { private val progressBarIsVisible = TestSubscriber() private val showDeleteCardDialog = TestSubscriber() private val successDeleting = TestSubscriber() - private val presentPaymentSheet = TestSubscriber() + private val presentPaymentSheet = TestSubscriber>() private val showError = TestSubscriber() private val successSaving = TestSubscriber() private val compositeDisposable = CompositeDisposable() @@ -148,6 +149,7 @@ class PaymentMethodsViewModelTest : KSRobolectricTestCase() { @Test fun testPresentPaymentSheetSuccess() { val setupClientId = "seti_1KbABk4VvJ2PtfhKV8E7dvGe_secret_LHjfXxFl9UDucYtsL5a3WtySqjgqf5F" + val email = "some@email.com" setUpEnvironment( environment().toBuilder().apolloClientV2(object : MockApolloClientV2() { @@ -159,7 +161,7 @@ class PaymentMethodsViewModelTest : KSRobolectricTestCase() { this.vm.inputs.newCardButtonClicked() - this.presentPaymentSheet.assertValue(setupClientId) + this.presentPaymentSheet.assertValue(Pair.create(setupClientId, email)) this.progressBarIsVisible.assertValues(false, true, false, true, false) this.showError.assertNoValues() } @@ -185,6 +187,7 @@ class PaymentMethodsViewModelTest : KSRobolectricTestCase() { @Test fun testSavePaymentMethodSuccess() { val setupClientId = "seti_1KbABk4VvJ2PtfhKV8E7dvGe_secret_LHjfXxFl9UDucYtsL5a3WtySqjgqf5F" + val email = "some@email.com" val card = StoredCardFactory.visa() val cardsList = listOf(StoredCardFactory.discoverCard()) val cardsListUpdated = listOf(StoredCardFactory.discoverCard(), card) @@ -214,7 +217,7 @@ class PaymentMethodsViewModelTest : KSRobolectricTestCase() { // - Button clicked this.vm.inputs.newCardButtonClicked() - this.presentPaymentSheet.assertValue(setupClientId) + this.presentPaymentSheet.assertValue(Pair.create(setupClientId, email)) this.progressBarIsVisible.assertValues(false, true, false, true, false) this.showError.assertNoValues() @@ -230,6 +233,7 @@ class PaymentMethodsViewModelTest : KSRobolectricTestCase() { @Test fun testSavePaymentMethodError() { val setupClientId = "seti_1KbABk4VvJ2PtfhKV8E7dvGe_secret_LHjfXxFl9UDucYtsL5a3WtySqjgqf5F" + val email = "some@email.com" val cardsList = listOf(StoredCardFactory.discoverCard()) var numberOfCalls = 1 val errorString = "Something went wrong" @@ -258,7 +262,7 @@ class PaymentMethodsViewModelTest : KSRobolectricTestCase() { // - Button clicked this.vm.inputs.newCardButtonClicked() - this.presentPaymentSheet.assertValue(setupClientId) + this.presentPaymentSheet.assertValue((Pair.create(setupClientId, email))) this.progressBarIsVisible.assertValues(false, true, false, true, false) this.showError.assertNoValues()