Skip to content

Commit

Permalink
1.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
plpt88 committed May 15, 2023
1 parent 204a50b commit e886a4a
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 22 deletions.
4 changes: 2 additions & 2 deletions GenesisAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'kotlin-kapt'

ext {
PUBLISH_GROUP_ID = 'com.emerchantpay.gateway'
PUBLISH_VERSION = '1.3.5'
PUBLISH_VERSION = '1.3.6'
PUBLISH_ARTIFACT_ID = 'genesis-android'
PUBLISH_DESCRIPTION = 'Genesis Android SDK'
PUBLISH_URL = 'https://github.com/GenesisGateway/android_sdk'
Expand All @@ -27,7 +27,7 @@ android {
minSdkVersion 19
targetSdkVersion 33
versionCode 1
versionName "1.3.5"
versionName "1.3.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ enum class WPFTransactionTypes(val value: String) {
SALE3D("sale3d"),

// Card verification without any financial impact
ACCOUNT_VERIFICATION("account_verification"),

// Payment using credit or debit cards connected to a consumer's Google account
GOOGLE_PAY("google_pay"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class TransactionTypesRequest : Request, CommonManagedRecurringAttributes {
}

if (isManagedRecurringEnabled())
builder!!.addElement("managed_recurring", buildManagedRecurringAttributes())
builder.addElement("managed_recurring", buildManagedRecurringAttributes().toXML())

return builder
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.emerchantpay.gateway.genesisandroid.api.constants.ErrorMessages.GOOGL
import com.emerchantpay.gateway.genesisandroid.api.constants.ErrorMessages.REQUIRED_PARAMS_THREE_DS_V2
import com.emerchantpay.gateway.genesisandroid.api.constants.ReminderConstants
import com.emerchantpay.gateway.genesisandroid.api.constants.WPFTransactionTypes
import com.emerchantpay.gateway.genesisandroid.api.constants.WPFTransactionTypes.*
import com.emerchantpay.gateway.genesisandroid.api.internal.request.KlarnaItemsRequest
import com.emerchantpay.gateway.genesisandroid.api.internal.request.PaymentRequest
import com.emerchantpay.gateway.genesisandroid.api.models.GenesisError
Expand All @@ -29,15 +30,10 @@ open class GenesisValidator {
private var requiredParametersValidator: RequiredParametersValidator? = null

// Validate amount
fun validateAmount(amount: BigDecimal?): Boolean? {
fun validateAmount(amount: BigDecimal?, transactionType: String?): Boolean? {
return when {
amount!!.toDouble() > 0 && amount != null -> true
else -> {
error = GenesisError(ErrorMessages.INVALID_AMOUNT)
notValidParamsList.add(amount.toString())

false
}
permitZeroAmount(transactionType) -> amount?.let { validateZeroAmount(it) }
else -> amount?.let { validateNonZeroAmount(it) }
}
}

Expand Down Expand Up @@ -256,14 +252,45 @@ open class GenesisValidator {
}

private fun isValidRegex(request: PaymentRequest): Boolean? {
val isValidAmount = validateAmount(request.amount)
val isValidAmount = validateAmount(request.amount, request.getTransactionType())
val isValidEmail = validateEmail(request.customerEmail)
val isValidPhone = validatePhone(request.customerPhone)
val isValidUrl = validateNotificationUrl(request.notificationUrl)

return isValidAmount!! && isValidEmail!! && isValidPhone!! && isValidUrl!!
}

private fun permitZeroAmount(transactionType: String?): Boolean {
return transactionType == AUTHORIZE.value
|| transactionType == AUTHORIZE3D.value
|| transactionType == SALE.value
|| transactionType == SALE3D.value
}

private fun validateNonZeroAmount(amount: BigDecimal): Boolean? {
return when {
amount != null && amount.toDouble() > 0 -> true
else -> {
error = GenesisError(ErrorMessages.INVALID_AMOUNT)
notValidParamsList.add(amount.toString())

false
}
}
}

private fun validateZeroAmount(amount: BigDecimal): Boolean? {
return when {
amount != null && amount.toDouble() >= 0 -> true
else -> {
error = GenesisError(ErrorMessages.INVALID_AMOUNT)
notValidParamsList.add(amount.toString())

false
}
}
}

companion object {
// Regular expressions
val VALID_EMAIL_REGEX = Pattern
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import com.emerchantpay.gateway.genesisandroid.api.constants.ErrorMessages
import com.emerchantpay.gateway.genesisandroid.api.constants.ReminderConstants
import com.emerchantpay.gateway.genesisandroid.api.constants.WPFTransactionTypes
import com.emerchantpay.gateway.genesisandroid.api.constants.WPFTransactionTypes.*
import com.emerchantpay.gateway.genesisandroid.api.constants.recurring.RecurringCategory
import com.emerchantpay.gateway.genesisandroid.api.constants.recurring.RecurringType
import com.emerchantpay.gateway.genesisandroid.api.interfaces.financial.googlepay.definitions.GooglePayPaymentSubtype
Expand Down Expand Up @@ -50,7 +51,7 @@ class GenesisValidatorUnitTest {
@Before
@Throws(IllegalAccessException::class)
fun setup() {
createPaymentRequest(listOf(WPFTransactionTypes.AUTHORIZE, WPFTransactionTypes.EZEEWALLET))
createPaymentRequest(listOf(AUTHORIZE, EZEEWALLET))
}

private fun createPaymentRequest(transactions: List<WPFTransactionTypes>) {
Expand Down Expand Up @@ -96,16 +97,33 @@ class GenesisValidatorUnitTest {
// Amount
@Test
fun testAmountValidationSuccess() {
assertTrue(validator!!.validateAmount(amount)!!)
assertTrue(validator!!.validateAmount(amount, AUTHORIZE.value)!!)

amount = BigDecimal("0.99")
assertTrue(validator!!.validateAmount(amount)!!)
assertTrue(validator!!.validateAmount(amount, AUTHORIZE.value)!!)
}

@Test
fun testAmountValidationFailed() {
fun testZeroAmountValidationSuccess() {
assertTrue(validator!!.validateAmount(amount, AUTHORIZE.value)!!)

amount = BigDecimal("0.00")
assertTrue(validator!!.validateAmount(amount, AUTHORIZE.value)!!)
}

@Test
fun testAmountValidationFailedWithAuthorize() {
amount = BigDecimal("-1.00")
assertFalse(validator!!.validateAmount(amount, AUTHORIZE.value)!!)

error = GenesisError(ErrorMessages.INVALID_AMOUNT)
assertEquals(error!!.message, ErrorMessages.INVALID_AMOUNT)
}

@Test
fun testAmountValidationFailedWithGooglePay() {
amount = BigDecimal("0.00")
assertFalse(validator!!.validateAmount(amount)!!)
assertFalse(validator!!.validateAmount(amount, GOOGLE_PAY.value)!!)

error = GenesisError(ErrorMessages.INVALID_AMOUNT)
assertEquals(error!!.message, ErrorMessages.INVALID_AMOUNT)
Expand Down Expand Up @@ -194,7 +212,7 @@ class GenesisValidatorUnitTest {
@Test
@Throws(IllegalAccessException::class)
fun testTransactionTypeValidionSuccess() {
assertTrue(validator!!.validateTransactionType(WPFTransactionTypes.AUTHORIZE.value)!!)
assertTrue(validator!!.validateTransactionType(AUTHORIZE.value)!!)
}

@Test
Expand Down Expand Up @@ -267,7 +285,7 @@ class GenesisValidatorUnitTest {

@Test
fun testValidDataWithGooglePayTransaction() {
createPaymentRequest(listOf(WPFTransactionTypes.GOOGLE_PAY))
createPaymentRequest(listOf(GOOGLE_PAY))

request?.setGooglePayPaymentSubtype(GooglePayPaymentSubtype.INIT_RECURRING_SALE)
assertTrue(request?.let { validator!!.isValidRequest(it) }!!)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cd GenesisAndroid
* Add the dependency in your build.gradle:
```
dependencies {
implementation 'com.emerchantpay.gateway:genesis-android:1.3.5'
implementation 'com.emerchantpay.gateway:genesis-android:1.3.6'
}
```

Expand Down

0 comments on commit e886a4a

Please sign in to comment.