From 31f9cc1844eee21b950cd42cf54725f5c5e936d3 Mon Sep 17 00:00:00 2001 From: AnasNaouchi Date: Wed, 10 Jul 2024 00:31:01 +0700 Subject: [PATCH] Fix tokenization methods filtering --- .../co/omise/android/models/Capability.kt | 16 +------------ .../android/ui/PaymentCreatorActivity.kt | 24 +++++++++---------- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/sdk/src/main/java/co/omise/android/models/Capability.kt b/sdk/src/main/java/co/omise/android/models/Capability.kt index 24f8067d..53979e9b 100644 --- a/sdk/src/main/java/co/omise/android/models/Capability.kt +++ b/sdk/src/main/java/co/omise/android/models/Capability.kt @@ -34,19 +34,6 @@ data class Capability( override var created: DateTime? = null, override var deleted: Boolean = false, ) : Model { - init { - // Need to add them to payment methods as we use tokenization methods as payment methods as well - tokenizationMethods?.forEach { - tokenizationMethod -> - paymentMethods?.add( - ( - PaymentMethod( - name = tokenizationMethod, - ) - ), - ) - } - } /** * The {@link RequestBuilder} class for retrieving account Capabilities. @@ -81,13 +68,12 @@ data class Capability( paymentMethods.add(PaymentMethod.createCreditCardMethod()) } - paymentMethods.addAll(tokenizationMethods.map(::createTokenizationMethod)) paymentMethods.addAll(sourceTypes.map(::createSourceTypeMethod)) - return Capability( paymentMethods = paymentMethods, zeroInterestInstallments = zeroInterestInstallments, limits = Limits(InstallmentAmount(200000L)), + tokenizationMethods = tokenizationMethods.map { tokenizationMethod -> tokenizationMethod.name!! } ) } } diff --git a/sdk/src/main/java/co/omise/android/ui/PaymentCreatorActivity.kt b/sdk/src/main/java/co/omise/android/ui/PaymentCreatorActivity.kt index 26dce74c..dd74341e 100644 --- a/sdk/src/main/java/co/omise/android/ui/PaymentCreatorActivity.kt +++ b/sdk/src/main/java/co/omise/android/ui/PaymentCreatorActivity.kt @@ -218,20 +218,20 @@ class PaymentCreatorActivity : OmiseActivity() { // Filter the capabilities based on the merchant request and what is available in the capabilities of the merchant account private fun filterCapabilities(capability: Capability): Capability { val merchantPassedCapabilities = intent.parcelableNullable(EXTRA_CAPABILITY) - var filteredPaymentMethods: List? = null - var filteredTokenizationMethods: List? = null - + val filteredPaymentMethods: List? + val filteredTokenizationMethods: List? if (merchantPassedCapabilities != null) { val selectedPaymentMethods = merchantPassedCapabilities.paymentMethods val selectedTokenizationMethods = merchantPassedCapabilities.tokenizationMethods - if (selectedPaymentMethods != null) { + val isMerchantOnlyChangingInterest = selectedPaymentMethods.isNullOrEmpty() && selectedTokenizationMethods.isNullOrEmpty() + if (selectedPaymentMethods != null && !isMerchantOnlyChangingInterest) { filteredPaymentMethods = capability.paymentMethods?.filter { capMethod -> selectedPaymentMethods.map { it.name }.contains(capMethod.name) } capability.paymentMethods = filteredPaymentMethods?.toMutableList() } - if (selectedTokenizationMethods != null) { + if (selectedTokenizationMethods != null && !isMerchantOnlyChangingInterest) { filteredTokenizationMethods = capability.tokenizationMethods?.filter { selectedTokenizationMethods.contains(it) @@ -239,15 +239,15 @@ class PaymentCreatorActivity : OmiseActivity() { capability.tokenizationMethods = filteredTokenizationMethods } capability.zeroInterestInstallments = merchantPassedCapabilities.zeroInterestInstallments - // add the tokenization methods into payment methods since the SDK only shows paymentMethods - val combinedMethods = capability.paymentMethods?.toMutableList() - capability.tokenizationMethods?.forEach { method -> - run { - combinedMethods?.add(PaymentMethod(method)) - } + } + // Add the tokenization methods into payment methods since the SDK only shows paymentMethods + val combinedMethods = capability.paymentMethods?.toMutableList() + capability.tokenizationMethods?.forEach { method -> + run { + combinedMethods?.add(PaymentMethod(method)) } - capability.paymentMethods = combinedMethods } + capability.paymentMethods = combinedMethods return capability }