Skip to content

Commit

Permalink
1.3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
plpt88 committed Mar 10, 2023
1 parent a46fcda commit 957b5c6
Show file tree
Hide file tree
Showing 20 changed files with 415 additions and 50 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.3'
PUBLISH_VERSION = '1.3.4'
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.0"
versionName "1.3.4"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ enum class WPFTransactionTypes(val value: String) {
// 3D-Secure Sale
SALE3D("sale3d"),

// Standard initial recurring
INIT_RECURRING_SALE("init_recurring_sale"),

// 3D-based initial recurring
INIT_RECURRING_SALE3D("init_recurring_sale3d"),

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.emerchantpay.gateway.genesisandroid.api.constants

import java.util.*

enum class RecurringAmountType(val value: String) {
// Amount types
FIXED("fixed"),
MAX("max");

override fun toString(): String {
return name.lowercase(Locale.ROOT)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.emerchantpay.gateway.genesisandroid.api.constants.recurring

import java.util.*

enum class RecurringCategory(val value: String) {
SUBSCRIPTION("subscription"),
STANDING_ORDER("stanging_order");

override fun toString(): String {
return name.lowercase(Locale.ROOT)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.emerchantpay.gateway.genesisandroid.api.constants

import java.util.*

enum class RecurringFrequency(val value: String) {
// Frequency
DAYLY("daily"),
TWICE_WEEKLY("twice_weekly"),
WEEKLY("weekly"),
TEN_DAYS("ten_days"),
FORTNIGHTLY("fortnightly"),
MONTHLY("monthly"),
EVERY_TWO_MONTHS("every_two_months"),
TRIMESTER("trimester"),
QUARTERLY("quarterly"),
TWICE_YEARLY("twice_yearly"),
ANUALLY("annually"),
UNSCHEDULED("unscheduled");

override fun toString(): String {
return name.lowercase(Locale.ROOT)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.emerchantpay.gateway.genesisandroid.api.constants

import java.util.*

enum class RecurringInterval(val value: String) {
// Interval
DAYS("days"),
MONTHS("months");

override fun toString(): String {
return name.lowercase(Locale.ROOT)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.emerchantpay.gateway.genesisandroid.api.constants

import java.util.*

enum class RecurringMode(val value: String) {
// Mode
AUTOMATIC("automatic"),
MANUAL("manual");

override fun toString(): String {
return name.lowercase(Locale.ROOT)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.emerchantpay.gateway.genesisandroid.api.constants

import java.util.*

enum class RecurringPaymentType(val value: String) {
// Payment types
INITIAL("initial"),
SUBSEQUENT("subsequent"),
MODIFICATION("modification"),
CANCELLATION("cancellation");

override fun toString(): String {
return name.lowercase(Locale.ROOT)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.emerchantpay.gateway.genesisandroid.api.constants.recurring

import java.util.*

enum class RecurringType(val value: String) {
INITIAL("initial"),
MANAGED("managed");

override fun toString(): String {
return name.lowercase(Locale.ROOT)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.emerchantpay.gateway.genesisandroid.api.interfaces.recurring

import com.emerchantpay.gateway.genesisandroid.api.constants.RecurringInterval
import com.emerchantpay.gateway.genesisandroid.api.constants.RecurringMode
import com.emerchantpay.gateway.genesisandroid.api.util.RequestBuilder
import java.text.SimpleDateFormat
import java.util.*

interface CommonManagedRecurringAttributes: IndianManagedRecurringAttributes {

fun setMode(mode: RecurringMode) {
requestBuilder.addElement("mode", mode.toString())
}

fun setInterval(interval: RecurringInterval) {
requestBuilder.addElement("interval", interval.toString())
}

fun setFirstDate(firstDate: Date?) {
firstDate?.let { requestBuilder.addElement("first_date", SimpleDateFormat(DATE_FORMAT).format(it)) }
}

fun setTimeOfDay(timeOfDay: Int) {
requestBuilder.addElement("time_of_day", timeOfDay)
}

fun setPeriod(period: Int) {
requestBuilder.addElement("period", period)
}

fun setAmount(amount: Int) {
requestBuilder.addElement("amount", amount)
}

fun setMaxCount(maxCount: Int) {
requestBuilder.addElement("max_count", maxCount)
}

fun buildManagedRecurringAttributes(): RequestBuilder = requestBuilder

companion object {
private const val DATE_FORMAT = "yyyy-MM-dd"
private val requestBuilder = RequestBuilder("")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.emerchantpay.gateway.genesisandroid.api.interfaces.recurring

import com.emerchantpay.gateway.genesisandroid.api.constants.RecurringAmountType
import com.emerchantpay.gateway.genesisandroid.api.constants.RecurringFrequency
import com.emerchantpay.gateway.genesisandroid.api.constants.RecurringPaymentType
import com.emerchantpay.gateway.genesisandroid.api.util.RequestBuilder

interface IndianManagedRecurringAttributes {

fun setPaymentType(paymentType: RecurringPaymentType) {
requestBuilder.addElement("payment_type", paymentType.value)
}

fun setAmountType(amountType: RecurringAmountType) {
requestBuilder.addElement("amount_type", amountType.value)
}

fun setFrequency(frequency: RecurringFrequency) {
requestBuilder.addElement("frequency", frequency.value)
}

fun setRegistrationReferenceNumber(referenceNumber: Int) {
requestBuilder.addElement("registration_reference_number", referenceNumber.toString())
}

fun setMaxAmount(maxAmount: Int) {
requestBuilder.addElement("max_amount", maxAmount.toString())
}

fun setValidated(validated: Boolean) {
requestBuilder.addElement("validated", validated.toString())
}

fun buildIndianManagedRecurringAttributes(): RequestBuilder = requestBuilder

companion object {
private val requestBuilder = RequestBuilder("")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.content.Context
import com.emerchantpay.gateway.genesisandroid.api.constants.SharedPrefConstants
import com.emerchantpay.gateway.genesisandroid.api.constants.URLConstants
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.BaseAttributes
import com.emerchantpay.gateway.genesisandroid.api.interfaces.RiskParamsAttributes
import com.emerchantpay.gateway.genesisandroid.api.interfaces.customerinfo.CustomerInfoAttributes
Expand Down Expand Up @@ -118,11 +120,14 @@ open class PaymentRequest : Request, PaymentAttributes, CustomerInfoAttributes,
val returnCancelUrl: String
get() = URLConstants.CANCEL_URL

// Recurring
private var recurringType: String? = null
private var recurringCategory: String? = null

@Throws(IllegalAccessException::class)
constructor(
context: Context?, transactionId: String?, amount: BigDecimal?, currency: Currency, customerEmail: String?,
customerPhone: String?, billingAddress: PaymentAddress?, notificationUrl: String?,
transactionTypes: TransactionTypesRequest) : super() {
constructor(context: Context?, transactionId: String?, amount: BigDecimal?, currency: Currency, customerEmail: String?,
customerPhone: String?, billingAddress: PaymentAddress?, notificationUrl: String?,
transactionTypes: TransactionTypesRequest) : super() {

this.context = context
this.transactionId = transactionId!!
Expand All @@ -135,7 +140,7 @@ open class PaymentRequest : Request, PaymentAttributes, CustomerInfoAttributes,
this.transactionTypes = transactionTypes

when {
notificationUrl != null && notificationUrl.isNotEmpty() -> this.notificationUrl = notificationUrl
notificationUrl != null && notificationUrl.isNotBlank() -> this.notificationUrl = notificationUrl
}

// Init params
Expand Down Expand Up @@ -381,6 +386,14 @@ open class PaymentRequest : Request, PaymentAttributes, CustomerInfoAttributes,
return reminders.addReminder(channel, after)
}

fun setRecurringType(recurringType: RecurringType) {
this.recurringType = recurringType.value
}

fun setRecurringCategory(recurringCategory: RecurringCategory) {
this.recurringCategory = recurringCategory.value
}

override fun toXML(): String {
return buildRequest("wpf_payment")!!.toXML()
}
Expand Down Expand Up @@ -415,6 +428,20 @@ open class PaymentRequest : Request, PaymentAttributes, CustomerInfoAttributes,
.addElement("threeds_v2_params", buildThreeDsV2Attributes().toXML())
.addElement("dynamic_descriptor_params", buildDescriptorParams().toXML())

val transactionTypesList = transactionTypes.transactionTypesList

if (transactionTypesList.contains("authorize")
|| transactionTypesList.contains("authorize3d")
|| transactionTypesList.contains("sale")
|| transactionTypesList.contains("sale3d")) {
recurringType?.let {
paymentRequestBuilder?.addElement("recurring_type", it)
}
recurringCategory?.let {
paymentRequestBuilder?.addElement("recurring_category", it)
}
}

consumerId = getConsumerId()

when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package com.emerchantpay.gateway.genesisandroid.api.internal.request


import com.emerchantpay.gateway.genesisandroid.api.constants.WPFTransactionTypes
import com.emerchantpay.gateway.genesisandroid.api.interfaces.recurring.CommonManagedRecurringAttributes
import com.emerchantpay.gateway.genesisandroid.api.internal.validation.GenesisValidator
import com.emerchantpay.gateway.genesisandroid.api.util.Request
import com.emerchantpay.gateway.genesisandroid.api.util.RequestBuilderWithAttribute
import java.util.*

class TransactionTypesRequest : Request {
class TransactionTypesRequest : Request, CommonManagedRecurringAttributes {

private var parent: PaymentRequest? = null
val transactionTypesList = ArrayList<String>()
Expand Down Expand Up @@ -97,6 +98,13 @@ class TransactionTypesRequest : Request {
return buildRequest(root).toQueryString()
}

private fun isManagedRecurringEnabled(): Boolean {
return (transactionTypesList.contains(WPFTransactionTypes.AUTHORIZE.value)
|| transactionTypesList.contains(WPFTransactionTypes.AUTHORIZE3D.value)
|| transactionTypesList.contains(WPFTransactionTypes.SALE.value)
|| transactionTypesList.contains(WPFTransactionTypes.SALE3D.value))
}

protected fun buildRequest(root: String): RequestBuilderWithAttribute {

val builder = RequestBuilderWithAttribute(root, "")
Expand All @@ -105,6 +113,9 @@ class TransactionTypesRequest : Request {
builder.addElement("", attribute)
}

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

return builder
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ open class GenesisValidator {
val errorMessage = requiredParametersValidator!!.error!!.message
val errorTechnicalMessage = requiredParametersValidator!!.error!!.technicalMessage
error = GenesisError("is required for $transactionType transaction type",
"$errorTechnicalMessage parameter ")
"$errorTechnicalMessage parameter ")
}
}
}
Expand All @@ -160,7 +160,7 @@ open class GenesisValidator {
orderTaxAmount: BigDecimal?): Boolean? {
when {
klarnaRequest != null -> requiredParametersValidator = RequiredParametersValidator(requiredParameters
.getRequiredParametersForKlarnaItem(klarnaRequest))
.getRequiredParametersForKlarnaItem(klarnaRequest))
else -> {
error = GenesisError(ErrorMessages.REQUIRED_PARAMS, "items")
return false
Expand Down Expand Up @@ -209,7 +209,7 @@ open class GenesisValidator {
fun isValidAddress(address: PaymentAddress): Boolean? {
// Init Required Params Validator
requiredParametersValidator = RequiredParametersValidator(requiredParameters
.getRequiredParametersForAddress(address))
.getRequiredParametersForAddress(address))

return requiredParametersValidator!!.isValidRequiredParams!!
}
Expand Down Expand Up @@ -259,9 +259,9 @@ open class GenesisValidator {
companion object {
// Regular expressions
val VALID_EMAIL_REGEX = Pattern
.compile("[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}", Pattern.CASE_INSENSITIVE)
.compile("[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}", Pattern.CASE_INSENSITIVE)
val VALID_PHONE_REGEX = Pattern.compile("^[0-9\\+]{1,}[0-9\\\\-]{3,15}$")
val VALID_URL_REGEX = Pattern
.compile("\\b(https?)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]")
.compile("\\b(https?)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]")
}
}
}
Loading

0 comments on commit 957b5c6

Please sign in to comment.