diff --git a/README.md b/README.md index ec9676e..5952c02 100644 --- a/README.md +++ b/README.md @@ -13,20 +13,23 @@ JVM client implementing [kevin. platform API v0.3](https://api-reference.kevin.e ## Installation -Package and installation instructions are available at the [Maven Central Repository](https://maven-badges.herokuapp.com/maven-central/eu.kevin/kevin-jvm) +Package and installation instructions are available at +the [Maven Central Repository](https://maven-badges.herokuapp.com/maven-central/eu.kevin/kevin-jvm) ### Maven + ``` eu.kevin kevin-jvm - 0.2.7 + 0.2.8 ``` ### Gradle + ``` -implementation 'eu.kevin:kevin-jvm:0.2.7' +implementation 'eu.kevin:kevin-jvm:0.2.8' ``` ## Usage Examples @@ -49,14 +52,17 @@ val client = Client( ``` ### Call an API method + +#### Bank payment example: + ```kotlin -val request = InitiatePaymentRequest( +val request = InitiateBankPaymentRequest( redirectUrl = "https://yourapp.com/callback", amount = BigDecimal("12.34"), currencyCode = "EUR", description = "My payment", identifier = UserIdentifier(email = "jsmith@example.com"), - bankPaymentMethod = BankPaymentMethod( + mandatoryBankPaymentMethod = BankPaymentMethod( endToEndId = "123", creditorName = "John Doe", informationStructured = InformationStructured( @@ -69,6 +75,59 @@ val request = InitiatePaymentRequest( ) ) ) +``` + +#### Card payment example: +```kotlin +val request = InitiateCardPaymentRequest( + redirectUrl = "https://yourapp.com/callback", + amount = BigDecimal("12.34"), + currencyCode = "EUR", + description = "My payment", + identifier = UserIdentifier(email = "jsmith@example.com"), + mandatoryBankPaymentMethod = BankPaymentMethod( + endToEndId = "123", + creditorName = "John Doe", + informationStructured = InformationStructured( + reference = "00220055", + referenceType = "SCOR" + ), + requestedExecutionDate = LocalDate.of(2021, 3, 8), + creditorAccount = Account( + iban = "LT144010051005081586" + ) + ), + mandatoryCardPaymentMethod = CardPaymentMethod() +) +``` + +#### Hybrid payment example: +```kotlin +val request = InitiateHybridPaymentRequest( + redirectUrl = "https://yourapp.com/callback", + amount = BigDecimal("12.34"), + currencyCode = "EUR", + description = "My payment", + identifier = UserIdentifier(email = "jsmith@example.com"), + mandatoryBankPaymentMethod = BankPaymentMethod( + endToEndId = "123", + creditorName = "John Doe", + informationStructured = InformationStructured( + reference = "00220055", + referenceType = "SCOR" + ), + requestedExecutionDate = LocalDate.of(2021, 3, 8), + creditorAccount = Account( + iban = "LT144010051005081586" + ) + ), + mandatoryCardPaymentMethod = CardPaymentMethod() +) +``` + +### Handle the response + +```kotlin val response = try { client.paymentClient.initiatePayment(request) @@ -79,6 +138,7 @@ val response = try { ``` ### Parse the request body of a webhook response + ```kotlin import eu.kevin.api.services.Parser diff --git a/src/main/kotlin/eu/kevin/api/models/payment/payment/request/InitiateBankPaymentRequest.kt b/src/main/kotlin/eu/kevin/api/models/payment/payment/request/InitiateBankPaymentRequest.kt new file mode 100644 index 0000000..4b100c0 --- /dev/null +++ b/src/main/kotlin/eu/kevin/api/models/payment/payment/request/InitiateBankPaymentRequest.kt @@ -0,0 +1,31 @@ +package eu.kevin.api.models.payment.payment.request + +import java.math.BigDecimal + +data class InitiateBankPaymentRequest @JvmOverloads constructor( + override val redirectUrl: String, + override val amount: BigDecimal, + override val currencyCode: String, + override val description: String, + val mandatoryBankPaymentMethod: BankPaymentMethod, + override var identifier: UserIdentifier? = null, + override var accessToken: String? = null, + override var bankId: String? = null, + override var redirectPreferred: Boolean? = null, + override var webhookUrl: String? = null, + override var lang: String? = null +) : InitiatePaymentRequest( + redirectUrl, + amount, + currencyCode, + description, + bankPaymentMethod = mandatoryBankPaymentMethod, + cardPaymentMethod = null, + identifier, + accessToken, + bankId, + redirectPreferred, + paymentMethodPreferred = PaymentMethod.BANK, + webhookUrl, + lang +) diff --git a/src/main/kotlin/eu/kevin/api/models/payment/payment/request/InitiateCardPaymentRequest.kt b/src/main/kotlin/eu/kevin/api/models/payment/payment/request/InitiateCardPaymentRequest.kt new file mode 100644 index 0000000..47cf991 --- /dev/null +++ b/src/main/kotlin/eu/kevin/api/models/payment/payment/request/InitiateCardPaymentRequest.kt @@ -0,0 +1,32 @@ +package eu.kevin.api.models.payment.payment.request + +import java.math.BigDecimal + +data class InitiateCardPaymentRequest @JvmOverloads constructor( + override val redirectUrl: String, + override val amount: BigDecimal, + override val currencyCode: String, + override val description: String, + val mandatoryBankPaymentMethod: BankPaymentMethod, + val mandatoryCardPaymentMethod: CardPaymentMethod, + override var identifier: UserIdentifier? = null, + override var accessToken: String? = null, + override var bankId: String? = null, + override var redirectPreferred: Boolean? = null, + override var webhookUrl: String? = null, + override var lang: String? = null +) : InitiatePaymentRequest( + redirectUrl, + amount, + currencyCode, + description, + bankPaymentMethod = mandatoryBankPaymentMethod, + cardPaymentMethod = mandatoryCardPaymentMethod, + identifier, + accessToken, + bankId, + redirectPreferred, + paymentMethodPreferred = PaymentMethod.CARD, + webhookUrl, + lang +) diff --git a/src/main/kotlin/eu/kevin/api/models/payment/payment/request/InitiateHybridPaymentRequest.kt b/src/main/kotlin/eu/kevin/api/models/payment/payment/request/InitiateHybridPaymentRequest.kt new file mode 100644 index 0000000..ade46cd --- /dev/null +++ b/src/main/kotlin/eu/kevin/api/models/payment/payment/request/InitiateHybridPaymentRequest.kt @@ -0,0 +1,33 @@ +package eu.kevin.api.models.payment.payment.request + +import java.math.BigDecimal + +data class InitiateHybridPaymentRequest @JvmOverloads constructor( + override val redirectUrl: String, + override val amount: BigDecimal, + override val currencyCode: String, + override val description: String, + val mandatoryBankPaymentMethod: BankPaymentMethod, + val mandatoryCardPaymentMethod: CardPaymentMethod, + override var identifier: UserIdentifier? = null, + override var accessToken: String? = null, + override var bankId: String? = null, + override var redirectPreferred: Boolean? = null, + override var paymentMethodPreferred: PaymentMethod? = null, + override var webhookUrl: String? = null, + override var lang: String? = null +) : InitiatePaymentRequest( + redirectUrl, + amount, + currencyCode, + description, + bankPaymentMethod = mandatoryBankPaymentMethod, + cardPaymentMethod = mandatoryCardPaymentMethod, + identifier, + accessToken, + bankId, + redirectPreferred, + paymentMethodPreferred, + webhookUrl, + lang +) diff --git a/src/main/kotlin/eu/kevin/api/models/payment/payment/request/InitiatePaymentRequest.kt b/src/main/kotlin/eu/kevin/api/models/payment/payment/request/InitiatePaymentRequest.kt index 8f7410c..2cc21b8 100644 --- a/src/main/kotlin/eu/kevin/api/models/payment/payment/request/InitiatePaymentRequest.kt +++ b/src/main/kotlin/eu/kevin/api/models/payment/payment/request/InitiatePaymentRequest.kt @@ -2,18 +2,62 @@ package eu.kevin.api.models.payment.payment.request import java.math.BigDecimal -data class InitiatePaymentRequest @JvmOverloads constructor( - val redirectUrl: String, - val amount: BigDecimal, - val currencyCode: String, - val description: String, - var bankPaymentMethod: BankPaymentMethod? = null, - var cardPaymentMethod: CardPaymentMethod? = null, - var identifier: UserIdentifier? = null, - var accessToken: String? = null, - var bankId: String? = null, - var redirectPreferred: Boolean? = null, - var paymentMethodPreferred: PaymentMethod? = null, - var webhookUrl: String? = null, - var lang: String? = null -) +open class InitiatePaymentRequest @JvmOverloads constructor( + open val redirectUrl: String, + open val amount: BigDecimal, + open val currencyCode: String, + open val description: String, + open var bankPaymentMethod: BankPaymentMethod? = null, + open var cardPaymentMethod: CardPaymentMethod? = null, + open var identifier: UserIdentifier? = null, + open var accessToken: String? = null, + open var bankId: String? = null, + open var redirectPreferred: Boolean? = null, + open var paymentMethodPreferred: PaymentMethod? = null, + open var webhookUrl: String? = null, + open var lang: String? = null +) { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as InitiatePaymentRequest + + if (redirectUrl != other.redirectUrl) return false + if (amount != other.amount) return false + if (currencyCode != other.currencyCode) return false + if (description != other.description) return false + if (bankPaymentMethod != other.bankPaymentMethod) return false + if (cardPaymentMethod != other.cardPaymentMethod) return false + if (identifier != other.identifier) return false + if (accessToken != other.accessToken) return false + if (bankId != other.bankId) return false + if (redirectPreferred != other.redirectPreferred) return false + if (paymentMethodPreferred != other.paymentMethodPreferred) return false + if (webhookUrl != other.webhookUrl) return false + if (lang != other.lang) return false + + return true + } + + override fun hashCode(): Int { + var result = redirectUrl.hashCode() + result = 31 * result + amount.hashCode() + result = 31 * result + currencyCode.hashCode() + result = 31 * result + description.hashCode() + result = 31 * result + (bankPaymentMethod?.hashCode() ?: 0) + result = 31 * result + (cardPaymentMethod?.hashCode() ?: 0) + result = 31 * result + (identifier?.hashCode() ?: 0) + result = 31 * result + (accessToken?.hashCode() ?: 0) + result = 31 * result + (bankId?.hashCode() ?: 0) + result = 31 * result + (redirectPreferred?.hashCode() ?: 0) + result = 31 * result + (paymentMethodPreferred?.hashCode() ?: 0) + result = 31 * result + (webhookUrl?.hashCode() ?: 0) + result = 31 * result + (lang?.hashCode() ?: 0) + return result + } + + override fun toString(): String { + return "InitiatePaymentRequest(redirectUrl='$redirectUrl', amount=$amount, currencyCode='$currencyCode', description='$description', bankPaymentMethod=$bankPaymentMethod, cardPaymentMethod=$cardPaymentMethod, identifier=$identifier, accessToken=$accessToken, bankId=$bankId, redirectPreferred=$redirectPreferred, paymentMethodPreferred=$paymentMethodPreferred, webhookUrl=$webhookUrl, lang=$lang)" + } +}