Skip to content

Commit

Permalink
Merge pull request #1722 from Adyen/fix/upi_drop_in_filtering
Browse files Browse the repository at this point in the history
UPI - Improve payment methods list
  • Loading branch information
araratthehero authored Aug 13, 2024
2 parents 65bb5ac + 9386c24 commit 225819a
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ object PaymentMethodTypes {
SEPA,
TWINT,
UPI,
UPI_INTENT,
UPI_COLLECT,
UPI_QR,
WECHAT_PAY_SDK,
)

Expand Down Expand Up @@ -178,8 +181,5 @@ object PaymentMethodTypes {
WECHAT_PAY_MINI_PROGRAM,
WECHAT_PAY_QR,
WECHAT_PAY_WEB,
UPI_INTENT,
UPI_COLLECT,
UPI_QR,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ internal class DropInViewModel(
val addressLookupCompleteFlow: Flow<AddressLookupResult> = _addressLookupCompleteFlow.receiveAsFlow()

fun getPaymentMethods(): List<PaymentMethod> {
return paymentMethodsApiResponse.paymentMethods.orEmpty()
return paymentMethodsApiResponse.paymentMethods?.filterNot { paymentMethod ->
IGNORED_PAYMENT_METHODS.any { it == paymentMethod.type }
}.orEmpty()
}

fun getStoredPaymentMethods(): List<StoredPaymentMethod> {
Expand Down Expand Up @@ -486,5 +488,11 @@ internal class DropInViewModel(
PaymentMethodTypes.TWINT,
PaymentMethodTypes.WECHAT_PAY_SDK,
)

private val IGNORED_PAYMENT_METHODS = listOf(
PaymentMethodTypes.UPI_INTENT,
PaymentMethodTypes.UPI_COLLECT,
PaymentMethodTypes.UPI_QR,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ internal class DropInViewModelTest(
whenever(bundleHandler.serviceComponentName) doReturn mock()
}

@ParameterizedTest
@MethodSource("getPaymentMethodsSource")
fun `when getPaymentMethods is called, then ignored payment methods are missing`(
paymentMethodsApiResponse: PaymentMethodsApiResponse,
expectedPaymentMethodsList: List<PaymentMethod>,
) {
whenever(bundleHandler.paymentMethodsApiResponse) doReturn paymentMethodsApiResponse
viewModel = createDropInViewModel()

val result = viewModel.getPaymentMethods()

assertEquals(expectedPaymentMethodsList, result)
}

@ParameterizedTest
@MethodSource("shouldSkipToSinglePaymentMethodSource")
fun `when payment methods response contains, then should skip to component`(
Expand Down Expand Up @@ -80,6 +94,106 @@ internal class DropInViewModelTest(

companion object {

@JvmStatic
fun getPaymentMethodsSource() = listOf(
// paymentMethodsApiResponse, expectedPaymentMethodsList
// Single non-ignored payment method
arguments(
PaymentMethodsApiResponse(paymentMethods = listOf(PaymentMethod(PaymentMethodTypes.SCHEME))),
listOf(PaymentMethod(PaymentMethodTypes.SCHEME)),
),

// Stored payment methods
arguments(
PaymentMethodsApiResponse(
storedPaymentMethods = listOf(
StoredPaymentMethod(PaymentMethodTypes.SCHEME),
StoredPaymentMethod(PaymentMethodTypes.TWINT),
),
),
listOf<PaymentMethod>(),
),

// Single non-ignored payment method with stored payment methods
arguments(
PaymentMethodsApiResponse(
paymentMethods = listOf(PaymentMethod(PaymentMethodTypes.SCHEME)),
storedPaymentMethods = listOf(StoredPaymentMethod(PaymentMethodTypes.TWINT)),
),
listOf(PaymentMethod(PaymentMethodTypes.SCHEME)),
),

// Multiple non-ignored payment methods
arguments(
PaymentMethodsApiResponse(
paymentMethods = listOf(
PaymentMethod(PaymentMethodTypes.SCHEME),
PaymentMethod(PaymentMethodTypes.UPI),
),
),
listOf(
PaymentMethod(PaymentMethodTypes.SCHEME),
PaymentMethod(PaymentMethodTypes.UPI),
),
),

// Single ignored payment method
arguments(
PaymentMethodsApiResponse(paymentMethods = listOf(PaymentMethod(PaymentMethodTypes.UPI_QR))),
listOf<PaymentMethod>(),
),
arguments(
PaymentMethodsApiResponse(paymentMethods = listOf(PaymentMethod(PaymentMethodTypes.UPI_INTENT))),
listOf<PaymentMethod>(),
),
arguments(
PaymentMethodsApiResponse(paymentMethods = listOf(PaymentMethod(PaymentMethodTypes.UPI_COLLECT))),
listOf<PaymentMethod>(),
),

// Multiple ignored payment methods
arguments(
PaymentMethodsApiResponse(
paymentMethods = listOf(
PaymentMethod(PaymentMethodTypes.UPI_QR),
PaymentMethod(PaymentMethodTypes.UPI_INTENT),
PaymentMethod(PaymentMethodTypes.UPI_COLLECT),
),
),
listOf<PaymentMethod>(),
),

// Multiple ignored payment methods with stored payment methods
arguments(
PaymentMethodsApiResponse(
paymentMethods = listOf(
PaymentMethod(PaymentMethodTypes.UPI_QR),
PaymentMethod(PaymentMethodTypes.UPI_INTENT),
PaymentMethod(PaymentMethodTypes.UPI_COLLECT),
),
storedPaymentMethods = listOf(StoredPaymentMethod(PaymentMethodTypes.TWINT)),
),
listOf<PaymentMethod>(),
),

// Multiple payment methods, but partially ignored
arguments(
PaymentMethodsApiResponse(
paymentMethods = listOf(
PaymentMethod(PaymentMethodTypes.SCHEME),
PaymentMethod(PaymentMethodTypes.UPI_INTENT),
PaymentMethod(PaymentMethodTypes.UPI),
PaymentMethod(PaymentMethodTypes.UPI_COLLECT),
),
storedPaymentMethods = listOf(StoredPaymentMethod(PaymentMethodTypes.TWINT)),
),
listOf(
PaymentMethod(PaymentMethodTypes.SCHEME),
PaymentMethod(PaymentMethodTypes.UPI),
),
),
)

@JvmStatic
fun shouldSkipToSinglePaymentMethodSource() = listOf(
// skipListWhenSinglePaymentMethodConfig, paymentMethodsApiResponse, expected
Expand Down

0 comments on commit 225819a

Please sign in to comment.