Skip to content

Commit

Permalink
1.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderDinov committed Apr 27, 2023
1 parent 957b5c6 commit 204a50b
Show file tree
Hide file tree
Showing 15 changed files with 286 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*.iml
.gradle
/local.properties
local.properties
.idea/
/.idea/libraries
/.idea/modules.xml
Expand Down
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.4'
PUBLISH_VERSION = '1.3.5'
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.4"
versionName "1.3.5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ object ErrorMessages {
const val INVALID_REMINDERS_NUMBER = "Maximum number of 3 allowed reminders reached. You can't add more reminders."
const val INVALID_CONSUMER_ID = "Invalid consumer_id. Max. length is 10 digits."
const val REQUIRED_PARAMS_THREE_DS_V2 = "3DSv2 parameters are required for the following transaction types: Authorize3d, Sale3d, InitRecurringSale3d"
const val GOOGLE_PAY_MISSING_PAYMENT_SUBTYPE = "Missing mandatory 'payment_subtype' parameter for Google Pay transaction!"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ enum class WPFTransactionTypes(val value: String) {
// 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"),

// Wallet-based payment
EZEEWALLET("ezeewallet"),

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.emerchantpay.gateway.genesisandroid.api.interfaces.financial

import com.emerchantpay.gateway.genesisandroid.api.util.RequestBuilder

interface DynamicDescriptorAttributes {
fun setMerchantName(merchantName: String): DynamicDescriptorAttributes {
requestBuilder.addElement("merchant_name", merchantName.take(MERCHANT_NAME_LENGTH))
return this
}

fun setMerchantCity(merchantCity: String): DynamicDescriptorAttributes {
requestBuilder.addElement("merchant_city", merchantCity.take(MERCHANT_CITY_LENGTH))
return this
}

fun setSubMerchantId(subMerchantId: String): DynamicDescriptorAttributes {
requestBuilder.addElement("sub_merchant_id", subMerchantId.take(SUB_MERCHANT_ID_LENGTH))
return this
}

fun buildDescriptorParams(): RequestBuilder {
return requestBuilder
}

companion object {
private val requestBuilder = RequestBuilder("")

private const val MERCHANT_NAME_LENGTH = 25
private const val MERCHANT_CITY_LENGTH = 13
private const val SUB_MERCHANT_ID_LENGTH = 15
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.emerchantpay.gateway.genesisandroid.api.interfaces.financial.googlepay

import com.emerchantpay.gateway.genesisandroid.api.interfaces.financial.googlepay.definitions.GooglePayPaymentSubtype
import com.emerchantpay.gateway.genesisandroid.api.util.RequestBuilder

interface GooglePayAttributes {
fun setPaymentSubtype(paymentSubtype: GooglePayPaymentSubtype): GooglePayAttributes = apply {
requestBuilder.addElement(PAYMENT_SUBTYPE, paymentSubtype.toString())
}

fun buildGooglePayParams(): RequestBuilder {
return requestBuilder
}

companion object {
private val requestBuilder = RequestBuilder("")

const val PAYMENT_SUBTYPE = "payment_subtype"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.emerchantpay.gateway.genesisandroid.api.interfaces.financial.googlepay.definitions

enum class GooglePayPaymentSubtype(private val value: String) {
AUTHORIZE("authorize"),
SALE("sale"),
INIT_RECURRING_SALE("init_recurring_sale");

override fun toString(): String {
return value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import com.emerchantpay.gateway.genesisandroid.api.interfaces.BaseAttributes
import com.emerchantpay.gateway.genesisandroid.api.interfaces.RiskParamsAttributes
import com.emerchantpay.gateway.genesisandroid.api.interfaces.customerinfo.CustomerInfoAttributes
import com.emerchantpay.gateway.genesisandroid.api.interfaces.financial.AsyncAttributes
import com.emerchantpay.gateway.genesisandroid.api.interfaces.financial.DescriptorAttributes
import com.emerchantpay.gateway.genesisandroid.api.interfaces.financial.DynamicDescriptorAttributes
import com.emerchantpay.gateway.genesisandroid.api.interfaces.financial.PaymentAttributes
import com.emerchantpay.gateway.genesisandroid.api.interfaces.financial.googlepay.GooglePayAttributes
import com.emerchantpay.gateway.genesisandroid.api.interfaces.financial.googlepay.definitions.GooglePayPaymentSubtype
import com.emerchantpay.gateway.genesisandroid.api.interfaces.financial.threedsv2.ThreeDsV2Attributes
import com.emerchantpay.gateway.genesisandroid.api.interfaces.financial.threedsv2.definitions.ThreeDsV2ControlDeviceType
import com.emerchantpay.gateway.genesisandroid.api.internal.validation.GenesisValidator
Expand All @@ -28,8 +30,8 @@ import java.math.MathContext
import java.util.*
import kotlin.math.pow

open class PaymentRequest : Request, PaymentAttributes, CustomerInfoAttributes, DescriptorAttributes,
AsyncAttributes, RiskParamsAttributes, ThreeDsV2Attributes {
open class PaymentRequest : Request, PaymentAttributes, CustomerInfoAttributes, DynamicDescriptorAttributes,
AsyncAttributes, RiskParamsAttributes, ThreeDsV2Attributes, GooglePayAttributes {
// Request Builder
private var paymentRequestBuilder: RequestBuilder? = null

Expand Down Expand Up @@ -107,6 +109,9 @@ open class PaymentRequest : Request, PaymentAttributes, CustomerInfoAttributes,
"authorize3d", "sale3d", "init_recurring_sale3d" ->
validator?.isValidThreeDsV2Request(this)!! && validator?.isValidRequest(this)!!

WPFTransactionTypes.GOOGLE_PAY.value ->
validator?.isValidGooglePayRequest(this)!! && validator?.isValidRequest(this)!!

else -> validator?.isValidRequest(this)!!
}
}
Expand All @@ -124,6 +129,9 @@ open class PaymentRequest : Request, PaymentAttributes, CustomerInfoAttributes,
private var recurringType: String? = null
private var recurringCategory: String? = null

// Google Pay
internal var googlePayPaymentSubtype: GooglePayPaymentSubtype? = null

@Throws(IllegalAccessException::class)
constructor(context: Context?, transactionId: String?, amount: BigDecimal?, currency: Currency, customerEmail: String?,
customerPhone: String?, billingAddress: PaymentAddress?, notificationUrl: String?,
Expand Down Expand Up @@ -394,6 +402,11 @@ open class PaymentRequest : Request, PaymentAttributes, CustomerInfoAttributes,
this.recurringCategory = recurringCategory.value
}

fun setGooglePayPaymentSubtype(googlePayPaymentSubtype: GooglePayPaymentSubtype?) {
this.googlePayPaymentSubtype = googlePayPaymentSubtype
googlePayPaymentSubtype?.let { setPaymentSubtype(it) }
}

override fun toXML(): String {
return buildRequest("wpf_payment")!!.toXML()
}
Expand Down Expand Up @@ -425,11 +438,15 @@ open class PaymentRequest : Request, PaymentAttributes, CustomerInfoAttributes,
.addElement("shipping_address", buildShippingAddress().toXML())
.addElement("transaction_types", transactionTypes)
.addElement("risk_params", buildRiskParams().toXML())
.addElement("threeds_v2_params", buildThreeDsV2Attributes().toXML())
.addElement("dynamic_descriptor_params", buildDescriptorParams().toXML())
.addElement(buildGooglePayParams().toXML())

val transactionTypesList = transactionTypes.transactionTypesList

if (canAddThreeDsV2Params(transactionTypesList)) {
paymentRequestBuilder?.addElement("threeds_v2_params", buildThreeDsV2Attributes().toXML())
}

if (transactionTypesList.contains("authorize")
|| transactionTypesList.contains("authorize3d")
|| transactionTypesList.contains("sale")
Expand Down Expand Up @@ -468,6 +485,9 @@ open class PaymentRequest : Request, PaymentAttributes, CustomerInfoAttributes,
}
}

private fun canAddThreeDsV2Params(transactionTypesList: ArrayList<String>) =
transactionTypesList.none { it == WPFTransactionTypes.GOOGLE_PAY.value }

fun getError(): GenesisError? {
when {
validator?.error != null -> error = validator?.error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.emerchantpay.gateway.genesisandroid.api.internal.validation

import com.emerchantpay.gateway.genesisandroid.api.constants.ErrorMessages
import com.emerchantpay.gateway.genesisandroid.api.constants.ErrorMessages.GOOGLE_PAY_MISSING_PAYMENT_SUBTYPE
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
Expand Down Expand Up @@ -247,6 +248,13 @@ open class GenesisValidator {
}
}

fun isValidGooglePayRequest(request: PaymentRequest): Boolean {
return if (request.googlePayPaymentSubtype == null) {
error = GenesisError(GOOGLE_PAY_MISSING_PAYMENT_SUBTYPE)
false
} else true
}

private fun isValidRegex(request: PaymentRequest): Boolean? {
val isValidAmount = validateAmount(request.amount)
val isValidEmail = validateEmail(request.customerEmail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ open class GenesisWebViewActivity : Activity() {
}

fun popCurrentWebView() {
genesisWebViews?.pop()
if (genesisWebViews!!.size > 1)
genesisWebViews?.pop()

genesisWebViews?.pop()?.let { pushNewWebView(it) }
}

Expand Down Expand Up @@ -98,7 +100,7 @@ open class GenesisWebViewActivity : Activity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when {
item.itemId == android.R.id.home -> {
setResult(Activity.RESULT_CANCELED)
setResult(RESULT_CANCELED)
finish()
return true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.emerchantpay.gateway.genesisandroid

import com.emerchantpay.gateway.genesisandroid.api.interfaces.financial.googlepay.GooglePayAttributes
import com.emerchantpay.gateway.genesisandroid.api.interfaces.financial.googlepay.definitions.GooglePayPaymentSubtype.*
import junit.framework.TestCase.assertEquals
import org.junit.Test
import org.junit.jupiter.api.DisplayName

internal class GooglePayAttributesUnitTest : GooglePayAttributes {
@Test
@DisplayName("Given attributes with assigned values, When serialized to XML, Then should be valid")
fun testValidXmlIsGeneratedOnSerialization() {
setPaymentSubtype(AUTHORIZE)

val generatedXml = buildGooglePayParams().toXML()

assertEquals(EXPECTED_XML, generatedXml)
}

companion object {
private val EXPECTED_XML =
"<payment_subtype>authorize</payment_subtype>"
}
}
Loading

0 comments on commit 204a50b

Please sign in to comment.