Skip to content

Commit

Permalink
Fix tokenization methods filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
AnasNaouchi committed Jul 9, 2024
1 parent 3db70af commit 31f9cc1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
16 changes: 1 addition & 15 deletions sdk/src/main/java/co/omise/android/models/Capability.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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!! }
)
}
}
Expand Down
24 changes: 12 additions & 12 deletions sdk/src/main/java/co/omise/android/ui/PaymentCreatorActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -218,36 +218,36 @@ 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<Capability?>(EXTRA_CAPABILITY)
var filteredPaymentMethods: List<PaymentMethod>? = null
var filteredTokenizationMethods: List<String>? = null

val filteredPaymentMethods: List<PaymentMethod>?
val filteredTokenizationMethods: List<String>?
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)
}
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
}

Expand Down

0 comments on commit 31f9cc1

Please sign in to comment.