Skip to content

Commit

Permalink
MBL-1520 Unhide Stripe Link on User Settings Payment Methods screen (#…
Browse files Browse the repository at this point in the history
…2047)

Co-authored-by: Isabel Martin <[email protected]>
  • Loading branch information
ycheng-kickstarter and Arkariang authored Jun 3, 2024
1 parent 42e034f commit a913189
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class PaymentMethodsSettingsActivity : AppCompatActivity() {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
flowControllerPresentPaymentOption(it)
flowControllerPresentPaymentOption(it.first, it.second)
}
)

Expand Down Expand Up @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ class PledgeFragment :
context?.let {
flowController.configureWithSetupIntent(
setupIntentClientSecret = clientSecret,
configuration = it.getPaymentSheetConfiguration(userEmail, false),
configuration = it.getPaymentSheetConfiguration(userEmail),
callback = ::onConfigured
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -58,7 +60,7 @@ interface Outputs {
fun successDeleting(): Observable<String>

/** Emits after calling CreateSetupIntent mutation with the SetupClientId. */
fun presentPaymentSheet(): Observable<String>
fun presentPaymentSheet(): Observable<Pair<String, String>>

/** Emits in case something went wrong with CreateSetupIntent mutation */
fun showError(): Observable<String>
Expand All @@ -82,7 +84,7 @@ class PaymentMethodsViewModel(environment: Environment) : ViewModel(), PaymentMe
private val showDeleteCardDialog = BehaviorSubject.create<Unit>()
private val successDeleting = BehaviorSubject.create<String>()
private val successSaving = BehaviorSubject.create<String>()
private val presentPaymentSheet = PublishSubject.create<String>()
private val presentPaymentSheet = PublishSubject.create<Pair<String, String>>()
private val showError = PublishSubject.create<String>()
private val loadingConfirmed = PublishSubject.create<Boolean>()

Expand Down Expand Up @@ -151,6 +153,7 @@ class PaymentMethodsViewModel(environment: Environment) : ViewModel(), PaymentMe
compositeDisposable.add(
shouldPresentPaymentSheet
.compose(valuesV2())
.compose(combineLatestPair(userEmail()))
.subscribe {
this.presentPaymentSheet.onNext(it)
}
Expand All @@ -171,7 +174,8 @@ class PaymentMethodsViewModel(environment: Environment) : ViewModel(), PaymentMe
.map {
SavePaymentMethodData(
reusable = true,
intentClientSecret = it
intentClientSecret = it.first

)
}
.switchMap {
Expand Down Expand Up @@ -243,6 +247,12 @@ class PaymentMethodsViewModel(environment: Environment) : ViewModel(), PaymentMe
.doAfterTerminate { this.progressBarIsVisible.onNext(false) }
}

private fun userEmail(): Observable<String> {
return this.apolloClient.userPrivacy()
.compose(neverErrorV2())
.map { it.email }
}

// - Inputs
override fun newCardButtonClicked() = this.newCardButtonPressed.onNext(Unit)

Expand Down Expand Up @@ -276,7 +286,7 @@ class PaymentMethodsViewModel(environment: Environment) : ViewModel(), PaymentMe
override fun successDeleting(): Observable<String> = this.successDeleting

@Override
override fun presentPaymentSheet(): Observable<String> =
override fun presentPaymentSheet(): Observable<Pair<String, String>> =
this.presentPaymentSheet

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,7 +26,7 @@ class PaymentMethodsViewModelTest : KSRobolectricTestCase() {
private val progressBarIsVisible = TestSubscriber<Boolean>()
private val showDeleteCardDialog = TestSubscriber<Unit>()
private val successDeleting = TestSubscriber<String>()
private val presentPaymentSheet = TestSubscriber<String>()
private val presentPaymentSheet = TestSubscriber<Pair<String, String>>()
private val showError = TestSubscriber<String>()
private val successSaving = TestSubscriber<String>()
private val compositeDisposable = CompositeDisposable()
Expand Down Expand Up @@ -148,6 +149,7 @@ class PaymentMethodsViewModelTest : KSRobolectricTestCase() {
@Test
fun testPresentPaymentSheetSuccess() {
val setupClientId = "seti_1KbABk4VvJ2PtfhKV8E7dvGe_secret_LHjfXxFl9UDucYtsL5a3WtySqjgqf5F"
val email = "[email protected]"

setUpEnvironment(
environment().toBuilder().apolloClientV2(object : MockApolloClientV2() {
Expand All @@ -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()
}
Expand All @@ -185,6 +187,7 @@ class PaymentMethodsViewModelTest : KSRobolectricTestCase() {
@Test
fun testSavePaymentMethodSuccess() {
val setupClientId = "seti_1KbABk4VvJ2PtfhKV8E7dvGe_secret_LHjfXxFl9UDucYtsL5a3WtySqjgqf5F"
val email = "[email protected]"
val card = StoredCardFactory.visa()
val cardsList = listOf(StoredCardFactory.discoverCard())
val cardsListUpdated = listOf(StoredCardFactory.discoverCard(), card)
Expand Down Expand Up @@ -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()

Expand All @@ -230,6 +233,7 @@ class PaymentMethodsViewModelTest : KSRobolectricTestCase() {
@Test
fun testSavePaymentMethodError() {
val setupClientId = "seti_1KbABk4VvJ2PtfhKV8E7dvGe_secret_LHjfXxFl9UDucYtsL5a3WtySqjgqf5F"
val email = "[email protected]"
val cardsList = listOf(StoredCardFactory.discoverCard())
var numberOfCalls = 1
val errorString = "Something went wrong"
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit a913189

Please sign in to comment.