diff --git a/.gitignore b/.gitignore index bf2f462..3113d20 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ *.iml .gradle -/local.properties +local.properties .idea/ /.idea/libraries /.idea/modules.xml diff --git a/GenesisAndroid/build.gradle b/GenesisAndroid/build.gradle index 8f1fd63..3a84a08 100644 --- a/GenesisAndroid/build.gradle +++ b/GenesisAndroid/build.gradle @@ -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' @@ -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 { diff --git a/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/constants/ErrorMessages.kt b/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/constants/ErrorMessages.kt index 87b9f86..3b0e8da 100644 --- a/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/constants/ErrorMessages.kt +++ b/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/constants/ErrorMessages.kt @@ -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!" } \ No newline at end of file diff --git a/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/constants/WPFTransactionTypes.kt b/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/constants/WPFTransactionTypes.kt index 908e410..348d864 100644 --- a/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/constants/WPFTransactionTypes.kt +++ b/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/constants/WPFTransactionTypes.kt @@ -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"), diff --git a/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/interfaces/financial/DescriptorAttributes.kt b/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/interfaces/financial/DescriptorAttributes.kt deleted file mode 100644 index 117cdd7..0000000 --- a/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/interfaces/financial/DescriptorAttributes.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.emerchantpay.gateway.genesisandroid.api.interfaces.financial - -import com.emerchantpay.gateway.genesisandroid.api.util.RequestBuilder - -interface DescriptorAttributes { - - // Descriptor Params - fun setDynamicMerchantName(dynamicMerchantName: String): DescriptorAttributes { - requestBuilder.addElement("merchant_name", dynamicMerchantName) - return this - } - - fun setDynamicMerchantCity(dynamicMerchantCity: String): DescriptorAttributes { - requestBuilder.addElement("merchant_city", dynamicMerchantCity) - return this - } - - fun buildDescriptorParams(): RequestBuilder { - return requestBuilder - } - - companion object { - - val requestBuilder = RequestBuilder("") - } -} \ No newline at end of file diff --git a/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/interfaces/financial/DynamicDescriptorAttributes.kt b/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/interfaces/financial/DynamicDescriptorAttributes.kt new file mode 100644 index 0000000..5fdd58c --- /dev/null +++ b/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/interfaces/financial/DynamicDescriptorAttributes.kt @@ -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 + } +} \ No newline at end of file diff --git a/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/interfaces/financial/googlepay/GooglePayAttributes.kt b/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/interfaces/financial/googlepay/GooglePayAttributes.kt new file mode 100644 index 0000000..b7fbc16 --- /dev/null +++ b/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/interfaces/financial/googlepay/GooglePayAttributes.kt @@ -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" + } +} \ No newline at end of file diff --git a/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/interfaces/financial/googlepay/definitions/GooglePayPaymentSubtype.kt b/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/interfaces/financial/googlepay/definitions/GooglePayPaymentSubtype.kt new file mode 100644 index 0000000..14ea862 --- /dev/null +++ b/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/interfaces/financial/googlepay/definitions/GooglePayPaymentSubtype.kt @@ -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 + } +} \ No newline at end of file diff --git a/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/internal/request/PaymentRequest.kt b/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/internal/request/PaymentRequest.kt index 98d8812..ba97eeb 100644 --- a/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/internal/request/PaymentRequest.kt +++ b/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/internal/request/PaymentRequest.kt @@ -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 @@ -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 @@ -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)!! } } @@ -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?, @@ -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() } @@ -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") @@ -468,6 +485,9 @@ open class PaymentRequest : Request, PaymentAttributes, CustomerInfoAttributes, } } + private fun canAddThreeDsV2Params(transactionTypesList: ArrayList) = + transactionTypesList.none { it == WPFTransactionTypes.GOOGLE_PAY.value } + fun getError(): GenesisError? { when { validator?.error != null -> error = validator?.error diff --git a/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/internal/validation/GenesisValidator.kt b/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/internal/validation/GenesisValidator.kt index a9f652c..0fcffd0 100644 --- a/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/internal/validation/GenesisValidator.kt +++ b/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/internal/validation/GenesisValidator.kt @@ -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 @@ -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) diff --git a/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/ui/GenesisWebViewActivity.kt b/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/ui/GenesisWebViewActivity.kt index bbf1453..99a4a90 100644 --- a/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/ui/GenesisWebViewActivity.kt +++ b/GenesisAndroid/src/main/java/com/emerchantpay/gateway/genesisandroid/api/ui/GenesisWebViewActivity.kt @@ -62,7 +62,9 @@ open class GenesisWebViewActivity : Activity() { } fun popCurrentWebView() { - genesisWebViews?.pop() + if (genesisWebViews!!.size > 1) + genesisWebViews?.pop() + genesisWebViews?.pop()?.let { pushNewWebView(it) } } @@ -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 } diff --git a/GenesisAndroid/src/test/java/com/emerchantpay/gateway/genesisandroid/GooglePayAttributesUnitTest.kt b/GenesisAndroid/src/test/java/com/emerchantpay/gateway/genesisandroid/GooglePayAttributesUnitTest.kt new file mode 100644 index 0000000..f66dd0e --- /dev/null +++ b/GenesisAndroid/src/test/java/com/emerchantpay/gateway/genesisandroid/GooglePayAttributesUnitTest.kt @@ -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 = + "authorize" + } +} \ No newline at end of file diff --git a/GenesisAndroid/src/test/java/com/emerchantpay/gateway/genesisandroid/internal/PaymentRequestUnitTest.kt b/GenesisAndroid/src/test/java/com/emerchantpay/gateway/genesisandroid/internal/PaymentRequestUnitTest.kt index 50a4b79..ec47c55 100644 --- a/GenesisAndroid/src/test/java/com/emerchantpay/gateway/genesisandroid/internal/PaymentRequestUnitTest.kt +++ b/GenesisAndroid/src/test/java/com/emerchantpay/gateway/genesisandroid/internal/PaymentRequestUnitTest.kt @@ -5,21 +5,29 @@ import com.emerchantpay.gateway.genesisandroid.api.constants.ReminderConstants 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 +import com.emerchantpay.gateway.genesisandroid.api.interfaces.financial.threedsv2.definitions.* import com.emerchantpay.gateway.genesisandroid.api.internal.request.PaymentRequest import com.emerchantpay.gateway.genesisandroid.api.internal.request.TransactionTypesRequest -import com.emerchantpay.gateway.genesisandroid.api.models.* +import com.emerchantpay.gateway.genesisandroid.api.models.Country import com.emerchantpay.gateway.genesisandroid.api.models.Currency +import com.emerchantpay.gateway.genesisandroid.api.models.PaymentAddress +import com.emerchantpay.gateway.genesisandroid.api.models.Reminder +import com.emerchantpay.gateway.genesisandroid.api.models.threedsv2.ThreeDsV2CardHolderAccountParams +import com.emerchantpay.gateway.genesisandroid.api.models.threedsv2.ThreeDsV2MerchantRiskParams +import com.emerchantpay.gateway.genesisandroid.api.models.threedsv2.ThreeDsV2Params +import com.emerchantpay.gateway.genesisandroid.api.models.threedsv2.ThreeDsV2RecurringParams import io.mockk.mockk import org.junit.Assert.* import org.junit.Before import org.junit.Test import java.math.BigDecimal import java.net.MalformedURLException +import java.text.SimpleDateFormat import java.util.* class PaymentRequestUnitTest { - private var context: Context? = null private var paymentRequest: PaymentRequest? = null @@ -30,7 +38,11 @@ class PaymentRequestUnitTest { @Before @Throws(IllegalAccessException::class) fun mockParams() { - context = mockk(relaxed = true) + createPaymentRequest() + } + + private fun createPaymentRequest(transactionType: WPFTransactionTypes = WPFTransactionTypes.SALE) { + context = mockk(relaxed = true) // Generate unique Id val uniqueId = UUID.randomUUID().toString() @@ -43,7 +55,7 @@ class PaymentRequestUnitTest { // Transaction types // Create Transaction types transactionTypes = TransactionTypesRequest() - transactionTypes!!.addTransaction(WPFTransactionTypes.SALE) + transactionTypes!!.addTransaction(transactionType) // Payment paymentRequest paymentRequest = PaymentRequest(context!!, uniqueId, @@ -52,6 +64,42 @@ class PaymentRequestUnitTest { "https://example.com", transactionTypes!!) paymentRequest?.setConsumerId("123456") + + val threeDsV2Params = ThreeDsV2Params.build { + purchaseCategory = ThreeDsV2PurchaseCategory.GOODS + + val merchantRiskPreorderDate = SimpleDateFormat("dd-MM-yyyy").calendar.apply { + time = Date() + add(Calendar.DATE, 5) + }.time + + merchantRisk = ThreeDsV2MerchantRiskParams( + ThreeDsV2MerchantRiskShippingIndicator.DIGITAL_GOODS, + ThreeDsV2MerchantRiskDeliveryTimeframe.SAME_DAY, + ThreeDsV2MerchantRiskReorderItemsIndicator.REORDERED, + ThreeDsV2MerchantRiskPreorderPurchaseIndicator.MERCHANDISE_AVAILABLE, + merchantRiskPreorderDate, + true, 3 + ) + + cardHolderAccount = ThreeDsV2CardHolderAccountParams( + SimpleDateFormat("dd-MM-yyyy").parse("11-02-2021"), + ThreeDsV2CardHolderAccountUpdateIndicator.UPDATE_30_TO_60_DAYS, + SimpleDateFormat("dd-MM-yyyy").parse("13-02-2021"), + ThreeDsV2CardHolderAccountPasswordChangeIndicator.PASSWORD_CHANGE_NO_CHANGE, + SimpleDateFormat("dd-MM-yyyy").parse("10-01-2021"), + ThreeDsV2CardHolderAccountShippingAddressUsageIndicator.ADDRESS_USAGE_MORE_THAN_60DAYS, + SimpleDateFormat("dd-MM-yyyy").parse("10-01-2021"), + 2, 129, 1, 31, + ThreeDsV2CardHolderAccountSuspiciousActivityIndicator.NO_SUSPICIOUS_OBSERVED, + ThreeDsV2CardHolderAccountRegistrationIndicator.REGISTRATION_30_TO_60_DAYS, + SimpleDateFormat("dd-MM-yyyy").parse("03-01-2021") + ) + + recurring = ThreeDsV2RecurringParams() + } + + paymentRequest?.setThreeDsV2Params(threeDsV2Params) } @Test @@ -194,11 +242,37 @@ class PaymentRequestUnitTest { paymentRequest!!.isValidData?.let { assertTrue(it) } } - @Test fun testRecurringParams() { paymentRequest?.setRecurringType(RecurringType.INITIAL) paymentRequest?.setRecurringCategory(RecurringCategory.SUBSCRIPTION) paymentRequest!!.isValidData?.let { assertTrue(it) } } + + @Test + fun testValidGooglePayTransactionRequest() { + createPaymentRequest(WPFTransactionTypes.GOOGLE_PAY) + paymentRequest?.setGooglePayPaymentSubtype(GooglePayPaymentSubtype.AUTHORIZE) + + paymentRequest?.transactionTypes?.transactionTypesList?.any { it == WPFTransactionTypes.GOOGLE_PAY.value } + ?.let { assertTrue(it) } + + paymentRequest?.toXML()?.let { it.run { + assertTrue(contains("payment_subtype")) + assertFalse(contains("threeds_v2_params")) + } } + } + + @Test + fun testInvvalidGooglePayTransactionRequest() { + createPaymentRequest(WPFTransactionTypes.GOOGLE_PAY) + + paymentRequest?.transactionTypes?.transactionTypesList?.any { it == WPFTransactionTypes.GOOGLE_PAY.value } + ?.let { assertTrue(it) } + + paymentRequest?.isValidData?.let { assertFalse(it) } + paymentRequest?.toXML()?.let { it.run { + assertFalse(contains("payment_subtype")) + } } + } } \ No newline at end of file diff --git a/GenesisAndroid/src/test/java/com/emerchantpay/gateway/genesisandroid/validation/GenesisValidatorUnitTest.kt b/GenesisAndroid/src/test/java/com/emerchantpay/gateway/genesisandroid/validation/GenesisValidatorUnitTest.kt index 8af8ddd..7093ff4 100644 --- a/GenesisAndroid/src/test/java/com/emerchantpay/gateway/genesisandroid/validation/GenesisValidatorUnitTest.kt +++ b/GenesisAndroid/src/test/java/com/emerchantpay/gateway/genesisandroid/validation/GenesisValidatorUnitTest.kt @@ -6,11 +6,12 @@ import com.emerchantpay.gateway.genesisandroid.api.constants.ReminderConstants 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 import com.emerchantpay.gateway.genesisandroid.api.internal.request.PaymentRequest import com.emerchantpay.gateway.genesisandroid.api.internal.request.TransactionTypesRequest import com.emerchantpay.gateway.genesisandroid.api.internal.validation.GenesisValidator -import com.emerchantpay.gateway.genesisandroid.api.models.* import com.emerchantpay.gateway.genesisandroid.api.models.Currency +import com.emerchantpay.gateway.genesisandroid.api.models.* import io.mockk.mockk import org.junit.Assert.* import org.junit.Before @@ -49,7 +50,11 @@ class GenesisValidatorUnitTest { @Before @Throws(IllegalAccessException::class) fun setup() { - context = mockk(relaxed = true) + createPaymentRequest(listOf(WPFTransactionTypes.AUTHORIZE, WPFTransactionTypes.EZEEWALLET)) + } + + private fun createPaymentRequest(transactions: List) { + context = mockk(relaxed = true) validator = GenesisValidator() // Intitial params @@ -64,22 +69,20 @@ class GenesisValidatorUnitTest { // Address billingAddress = PaymentAddress("John", "Doe", - "address1", "", "10000", "New York", - "state", Country().getCountry("United States")!!) + "address1", "", "10000", "New York", + "state", Country().getCountry("United States")!!) // Transaction types list transactionTypes = TransactionTypesRequest() - transactionTypes!!.addTransaction(WPFTransactionTypes.AUTHORIZE) - transactionTypes!!.addTransaction(WPFTransactionTypes.EZEEWALLET) + transactions.forEach { transactionTypes!!.addTransaction(it) } // Payment request request = context?.let { PaymentRequest(it, transactionId!!, amount!!, Currency.USD, - customerEmail!!, customerPhone!!, billingAddress!!, notificationUrl, transactionTypes!!) + customerEmail!!, customerPhone!!, billingAddress!!, notificationUrl, transactionTypes!!) } } - // Transaction Id @Test fun testTransactionId() { @@ -261,4 +264,12 @@ class GenesisValidatorUnitTest { request?.setRecurringCategory(RecurringCategory.SUBSCRIPTION) assertTrue(request?.let { validator!!.isValidRequest(it) }!!) } + + @Test + fun testValidDataWithGooglePayTransaction() { + createPaymentRequest(listOf(WPFTransactionTypes.GOOGLE_PAY)) + + request?.setGooglePayPaymentSubtype(GooglePayPaymentSubtype.INIT_RECURRING_SALE) + assertTrue(request?.let { validator!!.isValidRequest(it) }!!) + } } diff --git a/README.md b/README.md index 8d1e2a7..d2d67a8 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ cd GenesisAndroid * Add the dependency in your build.gradle: ``` dependencies { - implementation 'com.emerchantpay.gateway:genesis-android:1.3.4' + implementation 'com.emerchantpay.gateway:genesis-android:1.3.5' } ``` @@ -320,30 +320,30 @@ Set usage, description, lifetime ```kotlin paymentRequest.setUsage("TICKETS") - paymentRequest.setDescription("Description") - paymentRequest.setLifetime(60) +paymentRequest.setDescription("Description") +paymentRequest.setLifetime(60) ``` ```java -paymentRequest.setUsage("TICKETS") - paymentRequest.setDescription("Description") - paymentRequest.setLifetime(60); +paymentRequest.setUsage("TICKETS"); +paymentRequest.setDescription("Description"); +paymentRequest.setLifetime(60); ``` Set shipping address ```kotlin -val shippingAddress = PaymentAddress("John", "Doe", - "Fifth avenue 1", "Fifth avenue 1", "10000", "New York", - "Washington", Country.UnitedStates) +val shippingAddress = PaymentAddress("John", "Doe", + "Fifth avenue 1", "Fifth avenue 1", "10000", "New York", + "Washington", Country.UnitedStates) paymentRequest.setShippingAddress(shippingAddress) ``` ```java PaymentAddress shippingAddress = nnew PaymentAddress("John", "Doe", - "Fifth avenue 1", "Fifth avenue 1", "10000", "New York", - "Washington", new Country().Companion.getUnitedStates();); + "Fifth avenue 1", "Fifth avenue 1", "10000", "New York", + "Washington", new Country().Companion.getUnitedStates()); paymentRequest.setShippingAddress(shippingAddress); ``` @@ -353,12 +353,12 @@ Set Risk Params ```kotlin // Risk params val riskParams = RiskParams("1002547", "1DA53551-5C60-498C-9C18-8456BDBA74A9", - "987-65-4320", "12-34-56-78-9A-BC", "123456", - "emil@example.com", "+49301234567", "245.253.2.12", - "10000000000", "1234", "100000000", "John", - "Doe", "US", "test", "245.25 3.2.12", - "test", "test123456", "Bin name", - "+49301234567") + "987-65-4320", "12-34-56-78-9A-BC", "123456", + "emil@example.com", "+49301234567", "245.253.2.12", + "10000000000", "1234", "100000000", "John", + "Doe", "US", "test", "245.25 3.2.12", + "test", "test123456", "Bin name", + "+49301234567") paymentRequest.setRiskParams(riskParams) ``` @@ -366,12 +366,12 @@ paymentRequest.setRiskParams(riskParams) ```java // Risk params RiskParams riskParams = new RiskParams("1002547", "1DA53551-5C60-498C-9C18-8456BDBA74A9", - "987-65-4320", "12-34-56-78-9A-BC", "123456", - "emil@example.com", "+49301234567", "245.253.2.12", - "10000000000", "1234", "100000000", "John", - "Doe", "US", "test", "245.25 3.2.12", - "test", "test123456", "Bin name", - "+49301234567"); + "987-65-4320", "12-34-56-78-9A-BC", "123456", + "emil@example.com", "+49301234567", "245.253.2.12", + "10000000000", "1234", "100000000", "John", + "Doe", "US", "test", "245.25 3.2.12", + "test", "test123456", "Bin name", + "+49301234567"); paymentRequest.setRiskParams(riskParams); ``` @@ -465,7 +465,7 @@ paymentRequest.setThreeDsV2Params(threeDsV2Params); Set Recurring Params ```kotlin - // Create Transaction types +// Create Transaction types val transactionTypes = TransactionTypesRequest() transactionTypes.addTransaction(WPFTransactionTypes.SALE) @@ -477,7 +477,7 @@ transactionTypes.setMode(RecurringMode.AUTOMATIC) .setAmount(500) .setMaxCount(10) - // Init WPF API request +// Init WPF API request val paymentRequest = PaymentRequest(this, uniqueId, BigDecimal("2.00"), Currency.USD, "john@example.com", "+555555555", billingAddress, @@ -514,6 +514,39 @@ paymentRequest.setRecurringCategory(RecurringCategory.SUBSCRIPTION); // ... ``` +Set Google Pay + +```kotlin +// Create Transaction types and add Google Pay transaction +val transactionTypes = TransactionTypesRequest() +transactionTypes.addTransaction(WPFTransactionTypes.GOOGLE_PAY) + +// Init WPF API request +val paymentRequest = PaymentRequest(this, uniqueId, + BigDecimal("2.00"), Currency.USD, + "john@example.com", "+555555555", billingAddress, + "https://example.com", transactionTypes) + +// Add Google Pay transaction subtype (one of GooglePayPaymentSubtype.AUTHORIZE, +// GooglePayPaymentSubtype.SALE or GooglePayPaymentSubtype.INIT_RECURRING_SALE) +paymentRequest?.setGooglePayPaymentSubtype(GooglePayPaymentSubtype.SALE) +``` + +```java +// Create Transaction types and add Google Pay transaction +TransactionTypesRequest transactionTypes = new TransactionTypesRequest(); +transactionTypes.addTransaction(WPFTransactionTypes.GOOGLE_PAY); + +// Init WPF API request +PaymentRequest paymentRequest = new PaymentRequest(this, uniqueId, + new BigDecimal("2.00"), new Currency().Companion.getUSD(), + "john@example.com", "+555555555", billingAddress, + "https://example.com", transactionTypes); + +// Add Google Pay transaction subtype (one of GooglePayPaymentSubtype.AUTHORIZE, +// GooglePayPaymentSubtype.SALE or GooglePayPaymentSubtype.INIT_RECURRING_SALE) +paymentRequest.setGooglePayPaymentSubtype(GooglePayPaymentSubtype.SALE); +``` Running Tests --------------