From 38189ee0bcfac6a65549d30cda3599975fc715fc Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Wed, 13 Mar 2024 09:09:54 -0400 Subject: [PATCH 01/26] docs: add javadocs comments to public classes and interfaces --- .../cl/transbank/common/ApiConstants.java | 33 +- .../cl/transbank/common/BaseTransaction.java | 8 +- .../transbank/common/IntegrationApiKeys.java | 16 +- .../common/IntegrationCommerceCodes.java | 3 + .../common/IntegrationTypeHelper.java | 61 ++- .../exception/TransbankException.java | 100 +++-- .../transbank/model/BaseRefundResponse.java | 26 +- .../java/cl/transbank/model/CardDetail.java | 12 +- src/main/java/cl/transbank/model/Options.java | 126 ++++-- .../cl/transbank/model/WebpayApiRequest.java | 10 +- .../cl/transbank/patpass/PatpassByWebpay.java | 107 ++++- .../cl/transbank/patpass/PatpassComercio.java | 115 +++-- .../transbank/patpass/model/PatPassInfo.java | 23 +- .../patpass/model/PatpassOptions.java | 33 +- ...atpassComercioInscriptionStartRequest.java | 3 + ...tpassComercioTransactionStatusRequest.java | 11 +- .../requests/TransactionCreateRequest.java | 113 +++-- ...passByWebpayTransactionCommitResponse.java | 35 +- ...passByWebpayTransactionCreateResponse.java | 15 +- ...passByWebpayTransactionRefundResponse.java | 7 +- ...passByWebpayTransactionStatusResponse.java | 35 +- ...tpassComercioInscriptionStartResponse.java | 8 +- ...passComercioTransactionStatusResponse.java | 10 +- .../PatpassTransactionCreateDetails.java | 179 ++++++-- src/main/java/cl/transbank/util/HttpUtil.java | 80 ++-- src/main/java/cl/transbank/util/JsonUtil.java | 30 +- .../java/cl/transbank/util/JsonUtilImpl.java | 81 ++-- .../java/cl/transbank/util/StringUtils.java | 16 +- .../cl/transbank/util/ValidationUtil.java | 86 +++- .../cl/transbank/util/WebpayApiResource.java | 233 +++++++--- .../common/MallTransactionCaptureRequest.java | 18 +- .../common/MallTransactionRefundRequest.java | 10 +- .../common/TransactionCaptureRequest.java | 16 +- .../common/TransactionRefundRequest.java | 12 +- .../webpay/common/WebpayOptions.java | 29 +- .../exception/InscriptionDeleteException.java | 30 +- .../exception/InscriptionFinishException.java | 28 +- .../exception/InscriptionStartException.java | 29 +- .../TransactionAuthorizeException.java | 30 +- .../TransactionCaptureException.java | 33 +- .../exception/TransactionCommitException.java | 33 +- .../exception/TransactionCreateException.java | 31 +- .../TransactionInstallmentException.java | 33 +- .../exception/TransactionRefundException.java | 33 +- .../exception/TransactionStatusException.java | 33 +- .../exception/TransbankHttpApiException.java | 40 +- .../webpay/exception/WebpayException.java | 51 ++- .../webpay/modal/WebpayPlusModal.java | 89 +++- .../ModalTransactionCreateRequest.java | 16 +- .../ModalTransactionCommitResponse.java | 7 +- .../ModalTransactionCreateResponse.java | 12 +- .../ModalTransactionRefundResponse.java | 7 +- .../ModalTransactionStatusResponse.java | 7 +- .../transbank/webpay/oneclick/Oneclick.java | 113 +++-- .../oneclick/OneclickMallInscription.java | 143 ++++-- .../requests/InscriptionDeleteRequest.java | 16 +- .../requests/InscriptionStartRequest.java | 28 +- .../MallTransactionRefundRequest.java | 17 +- .../requests/TransactionAuthorizeRequest.java | 22 +- .../responses/InscriptionStartResponse.java | 17 +- ...OneclickMallInscriptionDeleteResponse.java | 10 +- ...OneclickMallInscriptionFinishResponse.java | 21 +- .../OneclickMallInscriptionStartResponse.java | 15 +- ...clickMallTransactionAuthorizeResponse.java | 57 ++- ...neclickMallTransactionCaptureResponse.java | 19 +- ...OneclickMallTransactionRefundResponse.java | 7 +- ...OneclickMallTransactionStatusResponse.java | 59 ++- .../transaccioncompleta/FullTransaction.java | 398 +++++++++++++---- .../MallFullTransaction.java | 420 +++++++++++++----- .../model/MallTransactionCommitDetails.java | 154 +++++-- .../MallFullTransactionCommitRequest.java | 12 +- .../MallFullTransactionCreateRequest.java | 19 +- ...allFullTransactionInstallmentsRequest.java | 10 +- .../requests/TransactionCommitRequest.java | 14 +- .../requests/TransactionCreateRequest.java | 26 +- .../TransactionInstallmentsRequest.java | 6 +- .../FullTransactionCaptureResponse.java | 15 +- .../FullTransactionCommitResponse.java | 9 +- .../FullTransactionCreateResponse.java | 6 +- .../FullTransactionInstallmentResponse.java | 32 +- .../FullTransactionRefundResponse.java | 18 +- .../FullTransactionStatusResponse.java | 36 +- .../MallFullTransactionCaptureResponse.java | 7 +- .../MallFullTransactionCommitResponse.java | 9 +- .../MallFullTransactionCreateResponse.java | 7 +- ...allFullTransactionInstallmentResponse.java | 26 +- ...allFullTransactionInstallmentsDetails.java | 117 ++++- ...llFullTransactionInstallmentsResponse.java | 71 +-- .../MallFullTransactionRefundResponse.java | 7 +- .../MallFullTransactionStatusResponse.java | 58 +-- .../webpay/webpayplus/WebpayPlus.java | 145 ++++-- .../MallTransactionCreateRequest.java | 21 +- .../requests/TransactionCreateRequest.java | 33 +- ...payPlusMallTransactionCaptureResponse.java | 8 +- ...bpayPlusMallTransactionCommitResponse.java | 10 +- ...bpayPlusMallTransactionCreateResponse.java | 8 +- ...bpayPlusMallTransactionRefundResponse.java | 7 +- ...bpayPlusMallTransactionStatusResponse.java | 65 +-- .../WebpayPlusTransactionCaptureResponse.java | 18 +- .../WebpayPlusTransactionCommitResponse.java | 8 +- .../WebpayPlusTransactionCreateResponse.java | 14 +- .../WebpayPlusTransactionRefundResponse.java | 6 +- .../WebpayPlusTransactionStatusResponse.java | 41 +- 103 files changed, 3345 insertions(+), 1302 deletions(-) diff --git a/src/main/java/cl/transbank/common/ApiConstants.java b/src/main/java/cl/transbank/common/ApiConstants.java index f032d8f6..38bdbea3 100644 --- a/src/main/java/cl/transbank/common/ApiConstants.java +++ b/src/main/java/cl/transbank/common/ApiConstants.java @@ -1,19 +1,24 @@ package cl.transbank.common; +/** + * This class contains the constants used in the API. + */ public class ApiConstants { - public static String WEBPAY_ENDPOINT = "rswebpaytransaction/api/webpay/v1.2"; - public static String ONECLICK_ENDPOINT = "rswebpaytransaction/api/oneclick/v1.2"; - public static String PATPASS_COMERCIO_ENDPOINT = "restpatpass/v1/services"; - public static int BUY_ORDER_LENGTH = 26; - public static int SESSION_ID_LENGTH = 61; - public static int RETURN_URL_LENGTH = 255; - public static int AUTHORIZATION_CODE_LENGTH = 6; - public static int CARD_EXPIRATION_DATE_LENGTH = 5; - public static int CARD_NUMBER_LENGTH = 19; - public static int TBK_USER_LENGTH = 40; - public static int USER_NAME_LENGTH = 40; - public static int COMMERCE_CODE_LENGTH = 12; - public static int TOKEN_LENGTH = 64; - public static int EMAIL_LENGTH = 100; + public static String WEBPAY_ENDPOINT = "rswebpaytransaction/api/webpay/v1.2"; + public static String ONECLICK_ENDPOINT = + "rswebpaytransaction/api/oneclick/v1.2"; + public static String PATPASS_COMERCIO_ENDPOINT = "restpatpass/v1/services"; + + public static int BUY_ORDER_LENGTH = 26; + public static int SESSION_ID_LENGTH = 61; + public static int RETURN_URL_LENGTH = 255; + public static int AUTHORIZATION_CODE_LENGTH = 6; + public static int CARD_EXPIRATION_DATE_LENGTH = 5; + public static int CARD_NUMBER_LENGTH = 19; + public static int TBK_USER_LENGTH = 40; + public static int USER_NAME_LENGTH = 40; + public static int COMMERCE_CODE_LENGTH = 12; + public static int TOKEN_LENGTH = 64; + public static int EMAIL_LENGTH = 100; } diff --git a/src/main/java/cl/transbank/common/BaseTransaction.java b/src/main/java/cl/transbank/common/BaseTransaction.java index 1c66a353..42a72b71 100644 --- a/src/main/java/cl/transbank/common/BaseTransaction.java +++ b/src/main/java/cl/transbank/common/BaseTransaction.java @@ -2,7 +2,13 @@ import cl.transbank.model.Options; +/** + * This abstract class represents a base transaction with common properties and methods. + */ public abstract class BaseTransaction { - protected Options options = null; + /** + * The options for the transaction. + */ + protected Options options = null; } diff --git a/src/main/java/cl/transbank/common/IntegrationApiKeys.java b/src/main/java/cl/transbank/common/IntegrationApiKeys.java index 8e4aa940..70295408 100644 --- a/src/main/java/cl/transbank/common/IntegrationApiKeys.java +++ b/src/main/java/cl/transbank/common/IntegrationApiKeys.java @@ -1,6 +1,18 @@ package cl.transbank.common; +/** + * This class holds the API keys for the integration environment. + */ public class IntegrationApiKeys { - public static String WEBPAY = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; - public static String PATPASS_COMERCIO = "cxxXQgGD9vrVe4M41FIt"; + + /** + * The API key for Webpay in the integration environment. + */ + public static String WEBPAY = + "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; + + /** + * The API key for Patpass Comercio in the integration environment. + */ + public static String PATPASS_COMERCIO = "cxxXQgGD9vrVe4M41FIt"; } diff --git a/src/main/java/cl/transbank/common/IntegrationCommerceCodes.java b/src/main/java/cl/transbank/common/IntegrationCommerceCodes.java index 37f8ebbe..7bf713ea 100644 --- a/src/main/java/cl/transbank/common/IntegrationCommerceCodes.java +++ b/src/main/java/cl/transbank/common/IntegrationCommerceCodes.java @@ -1,5 +1,8 @@ package cl.transbank.common; +/** + * This class contains the commerce codes for integration. + */ public class IntegrationCommerceCodes { public static String WEBPAY_PLUS = "597055555532"; public static String WEBPAY_PLUS_MODAL = "597055555584"; diff --git a/src/main/java/cl/transbank/common/IntegrationTypeHelper.java b/src/main/java/cl/transbank/common/IntegrationTypeHelper.java index 41042b27..0b73d78d 100644 --- a/src/main/java/cl/transbank/common/IntegrationTypeHelper.java +++ b/src/main/java/cl/transbank/common/IntegrationTypeHelper.java @@ -1,30 +1,47 @@ package cl.transbank.common; +/** + * This class provides helper methods to get the integration type for Webpay and Patpass. + */ public class IntegrationTypeHelper { - public static String getWebpayIntegrationType(IntegrationType integrationType){ - switch(integrationType){ - case LIVE: - return "https://webpay3g.transbank.cl"; - case MOCK: - return ""; - case TEST: - return "https://webpay3gint.transbank.cl"; - case SERVER_MOCK: - return "http://localhost:8888"; - } + + /** + * Returns the Webpay integration type based on the provided integration type. + */ + public static String getWebpayIntegrationType( + IntegrationType integrationType + ) { + switch (integrationType) { + case LIVE: + return "https://webpay3g.transbank.cl"; + case MOCK: + return ""; + case TEST: + return "https://webpay3gint.transbank.cl"; + case SERVER_MOCK: + return "http://localhost:8888"; + default: return "https://webpay3gint.transbank.cl"; } - public static String getPatpassIntegrationType(IntegrationType integrationType){ - switch(integrationType){ - case LIVE: - return "https://www.pagoautomaticocontarjetas.cl"; - case MOCK: - return ""; - case TEST: - return "https://pagoautomaticocontarjetasint.transbank.cl"; - case SERVER_MOCK: - return "http://localhost:8888"; - } + } + + /** + * Returns the Patpass integration type based on the provided integration type. + */ + public static String getPatpassIntegrationType( + IntegrationType integrationType + ) { + switch (integrationType) { + case LIVE: + return "https://www.pagoautomaticocontarjetas.cl"; + case MOCK: return ""; + case TEST: + return "https://pagoautomaticocontarjetasint.transbank.cl"; + case SERVER_MOCK: + return "http://localhost:8888"; + default: + return "https://pagoautomaticocontarjetasint.transbank.cl"; } + } } diff --git a/src/main/java/cl/transbank/exception/TransbankException.java b/src/main/java/cl/transbank/exception/TransbankException.java index 3637851c..61d04c49 100644 --- a/src/main/java/cl/transbank/exception/TransbankException.java +++ b/src/main/java/cl/transbank/exception/TransbankException.java @@ -2,39 +2,71 @@ import lombok.Getter; +/** + * This class represents a general exception that is thrown when a Transbank operation fails. + */ public class TransbankException extends Exception { - @Getter private int code; - - public TransbankException() { - super(); - } - - public TransbankException(String message) { - super(message); - this.code = -1; - } - - public TransbankException(int code, String message) { - super(message); - this.code = code; - } - - public TransbankException(int code, String message, Throwable cause) { - super(message, cause); - this.code = code; - } - - public TransbankException(Throwable cause) { - super(cause); - } - - public TransbankException(int code, Throwable cause) { - super(cause); - this.code = code; - } - - public TransbankException(int code, String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - this.code = code; - } + + @Getter + private int code; + + /** + * Constructs a new TransbankException with no detail message. + */ + public TransbankException() { + super(); + } + + /** + * Constructs a new TransbankException with the specified detail message. + */ + public TransbankException(String message) { + super(message); + this.code = -1; + } + + /** + * Constructs a new TransbankException with the specified detail message and error code. + */ + public TransbankException(int code, String message) { + super(message); + this.code = code; + } + + /** + * Constructs a new TransbankException with the specified detail message, error code, and cause. + */ + public TransbankException(int code, String message, Throwable cause) { + super(message, cause); + this.code = code; + } + + /** + * Constructs a new TransbankException with the specified cause. + */ + public TransbankException(Throwable cause) { + super(cause); + } + + /** + * Constructs a new TransbankException with the specified Ccode and cause. + */ + public TransbankException(int code, Throwable cause) { + super(cause); + this.code = code; + } + + /** + * Constructs a new TransbankException with the specified error code and cause. + */ + public TransbankException( + int code, + String message, + Throwable cause, + boolean enableSuppression, + boolean writableStackTrace + ) { + super(message, cause, enableSuppression, writableStackTrace); + this.code = code; + } } diff --git a/src/main/java/cl/transbank/model/BaseRefundResponse.java b/src/main/java/cl/transbank/model/BaseRefundResponse.java index 4bcc7352..936b52f0 100644 --- a/src/main/java/cl/transbank/model/BaseRefundResponse.java +++ b/src/main/java/cl/transbank/model/BaseRefundResponse.java @@ -2,14 +2,22 @@ import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter @ToString +/** + * This class represents a base response for a refund operation. + * It is abstract and should be extended by specific refund response classes. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString public abstract class BaseRefundResponse { - private String type; - private double balance; - private String authorizationCode; - private byte responseCode; - private String authorizationDate; - private double nullifiedAmount; - private Double prepaidBalance; + + private String type; + private double balance; + private String authorizationCode; + private byte responseCode; + private String authorizationDate; + private double nullifiedAmount; + private Double prepaidBalance; } diff --git a/src/main/java/cl/transbank/model/CardDetail.java b/src/main/java/cl/transbank/model/CardDetail.java index 72723860..8400625e 100644 --- a/src/main/java/cl/transbank/model/CardDetail.java +++ b/src/main/java/cl/transbank/model/CardDetail.java @@ -2,9 +2,15 @@ import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter +/** + * This class represents the details of a card. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter @ToString public class CardDetail { - private String cardNumber; + + private String cardNumber; } diff --git a/src/main/java/cl/transbank/model/Options.java b/src/main/java/cl/transbank/model/Options.java index 0c13fcb7..10ebf3cd 100644 --- a/src/main/java/cl/transbank/model/Options.java +++ b/src/main/java/cl/transbank/model/Options.java @@ -3,52 +3,108 @@ import cl.transbank.common.IntegrationType; import lombok.*; +/** + * This abstract class represents the options that can be set for a transaction. + */ @NoArgsConstructor @AllArgsConstructor -public abstract class Options implements Cloneable{ - @Setter @Getter private String commerceCode; - @Setter @Getter private String apiKey; - @Setter @Getter private IntegrationType integrationType; +public abstract class Options implements Cloneable { - public abstract String getHeaderCommerceCodeName(); - public abstract String getHeaderApiKeyName(); + @Setter + @Getter + private String commerceCode; - public Options buildOptions(Options options){ - Options alt = clone(); + @Setter + @Getter + private String apiKey; - // If the method receives an options object then rewrite each property, this is mandatory - if (null != options) { - if (null != options.getCommerceCode() && !options.getCommerceCode().trim().isEmpty()) - alt.setCommerceCode(options.getCommerceCode()); + @Setter + @Getter + private IntegrationType integrationType; - if (null != options.getApiKey() && !options.getApiKey().trim().isEmpty()) - alt.setApiKey(options.getApiKey()); + /** + * Returns the name of the commerce code header. + * @return The name of the commerce code header. + */ + public abstract String getHeaderCommerceCodeName(); - if (null != options.getIntegrationType()) - alt.setIntegrationType(options.getIntegrationType()); - } + /** + * Returns the name of the API key header. + * @return The name of the API key header. + */ + public abstract String getHeaderApiKeyName(); - return alt; - } + /** + * Builds the options for a transaction. + * @param options The options to set. + * @return The built options. + */ + public Options buildOptions(Options options) { + Options alt = clone(); - @Override - public Options clone() { - try { - return (Options) super.clone(); - } catch (CloneNotSupportedException e) { - return null; - } - } + // If the method receives an options object then rewrite each property, this is mandatory + if (null != options) { + if ( + null != options.getCommerceCode() && + !options.getCommerceCode().trim().isEmpty() + ) alt.setCommerceCode(options.getCommerceCode()); + + if ( + null != options.getApiKey() && !options.getApiKey().trim().isEmpty() + ) alt.setApiKey(options.getApiKey()); - public boolean isEmpty() { - return (null == this.getCommerceCode() || this.getCommerceCode().trim().isEmpty()) && - (null == this.getApiKey() || this.getApiKey().trim().isEmpty()) && - (null == this.getIntegrationType() || this.getIntegrationType().toString().isEmpty()); + if (null != options.getIntegrationType()) alt.setIntegrationType( + options.getIntegrationType() + ); } - public static boolean isEmpty(Options options) { - return (null == options || (null == options.getCommerceCode() || options.getCommerceCode().trim().isEmpty()) && - (null == options.getApiKey() || options.getApiKey().trim().isEmpty()) && - (null == options.getIntegrationType() || options.getIntegrationType().toString().isEmpty())); + return alt; + } + + /** + * Creates and returns a copy of this object. + * @return A clone of this instance. + * @throws CloneNotSupportedException If the object's class does not support the Cloneable interface. + */ + @Override + public Options clone() { + try { + return (Options) super.clone(); + } catch (CloneNotSupportedException e) { + return null; } + } + + /** + * Checks if the options are empty. + * @return true if the options are empty, false otherwise. + */ + public boolean isEmpty() { + return ( + ( + null == this.getCommerceCode() || + this.getCommerceCode().trim().isEmpty() + ) && + (null == this.getApiKey() || this.getApiKey().trim().isEmpty()) && + ( + null == this.getIntegrationType() || + this.getIntegrationType().toString().isEmpty() + ) + ); + } + + public static boolean isEmpty(Options options) { + return ( + null == options || + ( + null == options.getCommerceCode() || + options.getCommerceCode().trim().isEmpty() + ) && + (null == options.getApiKey() || options.getApiKey().trim().isEmpty()) && + ( + null == options.getIntegrationType() || + options.getIntegrationType().toString().isEmpty() + ) + ); + } } diff --git a/src/main/java/cl/transbank/model/WebpayApiRequest.java b/src/main/java/cl/transbank/model/WebpayApiRequest.java index 03557917..7d316542 100644 --- a/src/main/java/cl/transbank/model/WebpayApiRequest.java +++ b/src/main/java/cl/transbank/model/WebpayApiRequest.java @@ -2,7 +2,11 @@ import lombok.*; +/** + * This abstract class represents a Webpay API request. + */ @NoArgsConstructor -@Getter @Setter @ToString -public abstract class WebpayApiRequest { -} +@Getter +@Setter +@ToString +public abstract class WebpayApiRequest {} diff --git a/src/main/java/cl/transbank/patpass/PatpassByWebpay.java b/src/main/java/cl/transbank/patpass/PatpassByWebpay.java index c73b3bc2..e21d6d58 100644 --- a/src/main/java/cl/transbank/patpass/PatpassByWebpay.java +++ b/src/main/java/cl/transbank/patpass/PatpassByWebpay.java @@ -5,42 +5,101 @@ import cl.transbank.patpass.model.PatpassOptions; import cl.transbank.webpay.common.WebpayOptions; +/** + * This class provides methods to configure and perform transactions with the PatpassByWebpay service. + */ public class PatpassByWebpay { - private static Options options; - public static class Transaction extends PatpassByWebpayTransaction { - public Transaction() { - this.options = PatpassByWebpay.options!=null ? PatpassByWebpay.options : new WebpayOptions(IntegrationCommerceCodes.PATPASS_BY_WEBPAY, IntegrationApiKeys.WEBPAY, IntegrationType.TEST); - } - public Transaction(Options options) { - this.options = options; - } + private static Options options; + /** + * This class provides methods to configure and perform transactions with the PatpassByWebpay service. + */ + public static class Transaction extends PatpassByWebpayTransaction { + + public Transaction() { + this.options = + PatpassByWebpay.options != null + ? PatpassByWebpay.options + : new WebpayOptions( + IntegrationCommerceCodes.PATPASS_BY_WEBPAY, + IntegrationApiKeys.WEBPAY, + IntegrationType.TEST + ); + } + + public Transaction(Options options) { + this.options = options; } + } - /* + /* |-------------------------------------------------------------------------- | Environment Configuration |-------------------------------------------------------------------------- */ - public static void configureForIntegration(String commerceCode, String apiKey){ - PatpassByWebpay.options = new PatpassOptions(commerceCode, apiKey, IntegrationType.TEST); - } + /** + * Configures the environment for integration. + * @param commerceCode The commerce code. + * @param apiKey The API key. + */ + public static void configureForIntegration( + String commerceCode, + String apiKey + ) { + PatpassByWebpay.options = + new PatpassOptions(commerceCode, apiKey, IntegrationType.TEST); + } - public static void configureForProduction(String commerceCode, String apiKey){ - PatpassByWebpay.options = new PatpassOptions(commerceCode, apiKey, IntegrationType.LIVE); - } + /** + * Configures the environment for integration. + * @param commerceCode The commerce code. + * @param apiKey The API key. + */ + public static void configureForProduction( + String commerceCode, + String apiKey + ) { + PatpassByWebpay.options = + new PatpassOptions(commerceCode, apiKey, IntegrationType.LIVE); + } - public static void configureForTesting(){ - configureForIntegration(IntegrationCommerceCodes.PATPASS_BY_WEBPAY, IntegrationApiKeys.WEBPAY); - } + /** + * Configures the environment for testing. + * @param commerceCode The commerce code. + * @param apiKey The API key. + */ + public static void configureForTesting() { + configureForIntegration( + IntegrationCommerceCodes.PATPASS_BY_WEBPAY, + IntegrationApiKeys.WEBPAY + ); + } - public static void configureForTestingDeferred(){ - configureForIntegration(IntegrationCommerceCodes.PATPASS_BY_WEBPAY, IntegrationApiKeys.WEBPAY); - } + /** + * Configures the environment for testing deferred transactions. + * @param commerceCode The commerce code. + * @param apiKey The API key. + */ + public static void configureForTestingDeferred() { + configureForIntegration( + IntegrationCommerceCodes.PATPASS_BY_WEBPAY, + IntegrationApiKeys.WEBPAY + ); + } - public static void configureForMock(){ - PatpassByWebpay.options = new PatpassOptions(IntegrationCommerceCodes.PATPASS_BY_WEBPAY, IntegrationApiKeys.WEBPAY, IntegrationType.SERVER_MOCK); - } + /** + * Configures the environment for mock testing. + * @param commerceCode The commerce code. + * @param apiKey The API key. + */ + public static void configureForMock() { + PatpassByWebpay.options = + new PatpassOptions( + IntegrationCommerceCodes.PATPASS_BY_WEBPAY, + IntegrationApiKeys.WEBPAY, + IntegrationType.SERVER_MOCK + ); + } } diff --git a/src/main/java/cl/transbank/patpass/PatpassComercio.java b/src/main/java/cl/transbank/patpass/PatpassComercio.java index 7380b703..63234422 100644 --- a/src/main/java/cl/transbank/patpass/PatpassComercio.java +++ b/src/main/java/cl/transbank/patpass/PatpassComercio.java @@ -4,43 +4,108 @@ import cl.transbank.model.Options; import cl.transbank.patpass.model.PatpassOptions; -public class PatpassComercio { - private static Options options; +/** + * This class represents the details of a MallTransactionCommit. + */ +public class PatpassComercio { - public static class Inscription extends PatpassComercioInscription { - public Inscription() { - this.options = PatpassComercio.options!=null ? PatpassComercio.options : new PatpassOptions(IntegrationCommerceCodes.PATPASS_COMERCIO, IntegrationApiKeys.PATPASS_COMERCIO, IntegrationType.TEST); - } + private static Options options; - public Inscription(Options options) { - this.options = options; - } + /** + * This class represents the details of a MallTransactionCommit. + */ + public static class Inscription extends PatpassComercioInscription { + /** + * Default constructor. Uses default options if none are provided. + */ + public Inscription() { + this.options = + PatpassComercio.options != null + ? PatpassComercio.options + : new PatpassOptions( + IntegrationCommerceCodes.PATPASS_COMERCIO, + IntegrationApiKeys.PATPASS_COMERCIO, + IntegrationType.TEST + ); } - /* + /** + * Constructor with options. Uses provided options. + * @param options The options to use for this transaction. + */ + public Inscription(Options options) { + this.options = options; + } + } + + /* |-------------------------------------------------------------------------- | Environment Configuration |-------------------------------------------------------------------------- */ - public static void configureForIntegration(String commerceCode, String apiKey){ - PatpassComercio.options = new PatpassOptions(commerceCode, apiKey, IntegrationType.TEST); - } + /** + * Configures the environment for integration. + * @param commerceCode The commerce code. + * @param apiKey The API key. + */ + public static void configureForIntegration( + String commerceCode, + String apiKey + ) { + PatpassComercio.options = + new PatpassOptions(commerceCode, apiKey, IntegrationType.TEST); + } - public static void configureForProduction(String commerceCode, String apiKey){ - PatpassComercio.options = new PatpassOptions(commerceCode, apiKey, IntegrationType.LIVE); - } + /** + * Configures the environment for integration. + * @param commerceCode The commerce code. + * @param apiKey The API key. + */ + public static void configureForProduction( + String commerceCode, + String apiKey + ) { + PatpassComercio.options = + new PatpassOptions(commerceCode, apiKey, IntegrationType.LIVE); + } - public static void configureForTesting(){ - configureForIntegration(IntegrationCommerceCodes.PATPASS_COMERCIO, IntegrationApiKeys.PATPASS_COMERCIO); - } + /** + * Configures the environment for testing. + * @param commerceCode The commerce code. + * @param apiKey The API key. + */ + public static void configureForTesting() { + configureForIntegration( + IntegrationCommerceCodes.PATPASS_COMERCIO, + IntegrationApiKeys.PATPASS_COMERCIO + ); + } - public static void configureForTestingDeferred(){ - configureForIntegration(IntegrationCommerceCodes.PATPASS_COMERCIO, IntegrationApiKeys.PATPASS_COMERCIO); - } + /** + * Configures the environment for testing deferred transactions. + * @param commerceCode The commerce code. + * @param apiKey The API key. + */ + public static void configureForTestingDeferred() { + configureForIntegration( + IntegrationCommerceCodes.PATPASS_COMERCIO, + IntegrationApiKeys.PATPASS_COMERCIO + ); + } - public static void configureForMock(){ - PatpassComercio.options = new PatpassOptions(IntegrationCommerceCodes.PATPASS_COMERCIO, IntegrationApiKeys.PATPASS_COMERCIO, IntegrationType.SERVER_MOCK); - } + /** + * Configures the environment for mock testing. + * @param commerceCode The commerce code. + * @param apiKey The API key. + */ + public static void configureForMock() { + PatpassComercio.options = + new PatpassOptions( + IntegrationCommerceCodes.PATPASS_COMERCIO, + IntegrationApiKeys.PATPASS_COMERCIO, + IntegrationType.SERVER_MOCK + ); + } } diff --git a/src/main/java/cl/transbank/patpass/model/PatPassInfo.java b/src/main/java/cl/transbank/patpass/model/PatPassInfo.java index 0566d9b0..dfd46530 100644 --- a/src/main/java/cl/transbank/patpass/model/PatPassInfo.java +++ b/src/main/java/cl/transbank/patpass/model/PatPassInfo.java @@ -1,23 +1,26 @@ package cl.transbank.patpass.model; +import java.util.GregorianCalendar; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.experimental.Accessors; -import java.util.GregorianCalendar; - +/** + * This class represents the information of a PatPass. + */ @Getter @Setter @Accessors(chain = true) @NoArgsConstructor public class PatPassInfo { - private String serviceId; - private String cardHolderId; - private String cardHolderName; - private String cardHolderLastName1; - private String cardHolderLastName2; - private String cardHolderMail; - private String cellPhoneNumber; - private GregorianCalendar expirationDate; + + private String serviceId; + private String cardHolderId; + private String cardHolderName; + private String cardHolderLastName1; + private String cardHolderLastName2; + private String cardHolderMail; + private String cellPhoneNumber; + private GregorianCalendar expirationDate; } diff --git a/src/main/java/cl/transbank/patpass/model/PatpassOptions.java b/src/main/java/cl/transbank/patpass/model/PatpassOptions.java index 1e50dde2..999671ea 100644 --- a/src/main/java/cl/transbank/patpass/model/PatpassOptions.java +++ b/src/main/java/cl/transbank/patpass/model/PatpassOptions.java @@ -4,13 +4,30 @@ import cl.transbank.model.Options; import lombok.*; -@ToString @AllArgsConstructor -public class PatpassOptions extends Options { - @Getter final String headerCommerceCodeName = "commercecode"; - @Getter final String headerApiKeyName = "Authorization"; +/** + * This class represents the options for a Patpass transaction. + */ +@ToString +@AllArgsConstructor +public class PatpassOptions extends Options { - public PatpassOptions(String commerceCode, String apiKey,IntegrationType integrationType ){ - super(commerceCode,apiKey,integrationType); - } -} + @Getter + final String headerCommerceCodeName = "commercecode"; + + @Getter + final String headerApiKeyName = "Authorization"; + /** + * Constructs a new PatpassOptions with the specified commerce code, API key, and integration type. + * @param commerceCode The commerce code. + * @param apiKey The API key. + * @param integrationType The integration type. + */ + public PatpassOptions( + String commerceCode, + String apiKey, + IntegrationType integrationType + ) { + super(commerceCode, apiKey, integrationType); + } +} diff --git a/src/main/java/cl/transbank/patpass/requests/PatpassComercioInscriptionStartRequest.java b/src/main/java/cl/transbank/patpass/requests/PatpassComercioInscriptionStartRequest.java index a0a64b9c..81e92044 100644 --- a/src/main/java/cl/transbank/patpass/requests/PatpassComercioInscriptionStartRequest.java +++ b/src/main/java/cl/transbank/patpass/requests/PatpassComercioInscriptionStartRequest.java @@ -4,6 +4,9 @@ import com.google.gson.annotations.SerializedName; import lombok.*; +/** + * This class represents a request to start an inscription for a Patpass Comercio transaction. + */ @NoArgsConstructor @RequiredArgsConstructor @AllArgsConstructor diff --git a/src/main/java/cl/transbank/patpass/requests/PatpassComercioTransactionStatusRequest.java b/src/main/java/cl/transbank/patpass/requests/PatpassComercioTransactionStatusRequest.java index 81baf807..268187cc 100644 --- a/src/main/java/cl/transbank/patpass/requests/PatpassComercioTransactionStatusRequest.java +++ b/src/main/java/cl/transbank/patpass/requests/PatpassComercioTransactionStatusRequest.java @@ -3,11 +3,16 @@ import cl.transbank.model.WebpayApiRequest; import lombok.*; +/** + * This class represents a request to get the status of a Patpass Comercio transaction. + */ @NoArgsConstructor @RequiredArgsConstructor @Data -@EqualsAndHashCode(callSuper=true) -@ToString(callSuper=true) +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) public class PatpassComercioTransactionStatusRequest extends WebpayApiRequest { - @NonNull private String token; + + @NonNull + private String token; } diff --git a/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java b/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java index 9bea2785..0f49a1e7 100644 --- a/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java +++ b/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java @@ -1,35 +1,92 @@ package cl.transbank.patpass.requests; import cl.transbank.model.WebpayApiRequest; -import com.google.gson.annotations.SerializedName; import lombok.*; -@NoArgsConstructor @RequiredArgsConstructor -@Getter @Setter @ToString +/** + * This class represents a request to create a transaction. + */ +@NoArgsConstructor +@RequiredArgsConstructor +@Getter +@Setter +@ToString public class TransactionCreateRequest extends WebpayApiRequest { - @NonNull private String buyOrder; - @NonNull private String sessionId; - @NonNull private double amount; - @NonNull private String returnUrl; - private Detail wpmDetail; - - public void setDetails(String serviceId, String cardHolderId, String cardHolderName, String cardHolderLastName1, - String cardHolderLastName2, String cardHolderMail, String cellphoneNumber, String expirationDate, String commerceMail, boolean ufFlag) { - wpmDetail = new Detail(serviceId, cardHolderId, cardHolderName, cardHolderLastName1, cardHolderLastName2, cardHolderMail, cellphoneNumber, expirationDate, commerceMail, ufFlag); - } - - @NoArgsConstructor @AllArgsConstructor - @Getter @Setter @ToString - public class Detail { - private String serviceId; - private String cardHolderId; - private String cardHolderName; - private String cardHolderLastName1; - private String cardHolderLastName2; - private String cardHolderMail; - private String cellphoneNumber; - private String expirationDate; - private String commerceMail; - private boolean ufFlag; - } + + @NonNull + private String buyOrder; + + @NonNull + private String sessionId; + + @NonNull + private double amount; + + @NonNull + private String returnUrl; + + private Detail wpmDetail; + + /** + * Sets the details for the transaction. + * @param serviceId The service ID. + * @param cardHolderId The card holder ID. + * @param cardHolderName The card holder name. + * @param cardHolderLastName1 The card holder's first last name. + * @param cardHolderLastName2 The card holder's second last name. + * @param cardHolderMail The card holder's mail. + * @param cellphoneNumber The cellphone number. + * @param expirationDate The expiration date. + * @param commerceMail The commerce mail. + * @param ufFlag The UF flag. + */ + + public void setDetails( + String serviceId, + String cardHolderId, + String cardHolderName, + String cardHolderLastName1, + String cardHolderLastName2, + String cardHolderMail, + String cellphoneNumber, + String expirationDate, + String commerceMail, + boolean ufFlag + ) { + wpmDetail = + new Detail( + serviceId, + cardHolderId, + cardHolderName, + cardHolderLastName1, + cardHolderLastName2, + cardHolderMail, + cellphoneNumber, + expirationDate, + commerceMail, + ufFlag + ); + } + + /** + * This class represents the detail of a transaction. + */ + @NoArgsConstructor + @AllArgsConstructor + @Getter + @Setter + @ToString + public class Detail { + + private String serviceId; + private String cardHolderId; + private String cardHolderName; + private String cardHolderLastName1; + private String cardHolderLastName2; + private String cardHolderMail; + private String cellphoneNumber; + private String expirationDate; + private String commerceMail; + private boolean ufFlag; + } } diff --git a/src/main/java/cl/transbank/patpass/responses/PatpassByWebpayTransactionCommitResponse.java b/src/main/java/cl/transbank/patpass/responses/PatpassByWebpayTransactionCommitResponse.java index f4b88365..93d14386 100644 --- a/src/main/java/cl/transbank/patpass/responses/PatpassByWebpayTransactionCommitResponse.java +++ b/src/main/java/cl/transbank/patpass/responses/PatpassByWebpayTransactionCommitResponse.java @@ -3,19 +3,26 @@ import cl.transbank.model.CardDetail; import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter @ToString +/** + * This class represents a response to a commit operation for a Patpass By Webpay transaction. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString public class PatpassByWebpayTransactionCommitResponse { - private String vci; - private double amount; - private String status; - private String buyOrder; - private String sessionId; - private CardDetail cardDetail; - private String accountingDate; - private String transactionDate; - private String authorizationCode; - private String paymentTypeCode; - private byte responseCode; - private byte installmentsNumber; + + private String vci; + private double amount; + private String status; + private String buyOrder; + private String sessionId; + private CardDetail cardDetail; + private String accountingDate; + private String transactionDate; + private String authorizationCode; + private String paymentTypeCode; + private byte responseCode; + private byte installmentsNumber; } diff --git a/src/main/java/cl/transbank/patpass/responses/PatpassByWebpayTransactionCreateResponse.java b/src/main/java/cl/transbank/patpass/responses/PatpassByWebpayTransactionCreateResponse.java index f94965e7..652ba2b7 100644 --- a/src/main/java/cl/transbank/patpass/responses/PatpassByWebpayTransactionCreateResponse.java +++ b/src/main/java/cl/transbank/patpass/responses/PatpassByWebpayTransactionCreateResponse.java @@ -2,9 +2,16 @@ import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter @ToString +/** + * This class represents a response to a create operation for a Patpass by Webpay transaction. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString public class PatpassByWebpayTransactionCreateResponse { - private String token; - private String url; + + private String token; + private String url; } diff --git a/src/main/java/cl/transbank/patpass/responses/PatpassByWebpayTransactionRefundResponse.java b/src/main/java/cl/transbank/patpass/responses/PatpassByWebpayTransactionRefundResponse.java index b6b94e9f..d9b6d8e8 100644 --- a/src/main/java/cl/transbank/patpass/responses/PatpassByWebpayTransactionRefundResponse.java +++ b/src/main/java/cl/transbank/patpass/responses/PatpassByWebpayTransactionRefundResponse.java @@ -2,5 +2,8 @@ import cl.transbank.model.BaseRefundResponse; -public class PatpassByWebpayTransactionRefundResponse extends BaseRefundResponse { -} +/** + * This class represents the response of a refund transaction in Patpass by Webpay. + */ +public class PatpassByWebpayTransactionRefundResponse + extends BaseRefundResponse {} diff --git a/src/main/java/cl/transbank/patpass/responses/PatpassByWebpayTransactionStatusResponse.java b/src/main/java/cl/transbank/patpass/responses/PatpassByWebpayTransactionStatusResponse.java index b847d6d3..361a389c 100644 --- a/src/main/java/cl/transbank/patpass/responses/PatpassByWebpayTransactionStatusResponse.java +++ b/src/main/java/cl/transbank/patpass/responses/PatpassByWebpayTransactionStatusResponse.java @@ -3,19 +3,26 @@ import cl.transbank.model.CardDetail; import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter @ToString +/** + * This class represents a response to a status request for a Patpass by Webpay transaction. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString public class PatpassByWebpayTransactionStatusResponse { - private String vci; - private double amount; - private String status; - private double balance; - private String buyOrder; - private String sessionId; - private CardDetail cardDetail; - private String accountingDate; - private String transactionDate; - private String authorizationCode; - private String paymentTypeCode; - private byte installmentsNumber; + + private String vci; + private double amount; + private String status; + private double balance; + private String buyOrder; + private String sessionId; + private CardDetail cardDetail; + private String accountingDate; + private String transactionDate; + private String authorizationCode; + private String paymentTypeCode; + private byte installmentsNumber; } diff --git a/src/main/java/cl/transbank/patpass/responses/PatpassComercioInscriptionStartResponse.java b/src/main/java/cl/transbank/patpass/responses/PatpassComercioInscriptionStartResponse.java index f6fa6194..0c92e401 100644 --- a/src/main/java/cl/transbank/patpass/responses/PatpassComercioInscriptionStartResponse.java +++ b/src/main/java/cl/transbank/patpass/responses/PatpassComercioInscriptionStartResponse.java @@ -4,10 +4,14 @@ import lombok.Data; import lombok.NoArgsConstructor; +/** + * This class represents the response of starting an inscription in Patpass Comercio. + */ @NoArgsConstructor @AllArgsConstructor @Data public class PatpassComercioInscriptionStartResponse { - private String token; - private String url; + + private String token; + private String url; } diff --git a/src/main/java/cl/transbank/patpass/responses/PatpassComercioTransactionStatusResponse.java b/src/main/java/cl/transbank/patpass/responses/PatpassComercioTransactionStatusResponse.java index f44bdbb6..8da4272b 100644 --- a/src/main/java/cl/transbank/patpass/responses/PatpassComercioTransactionStatusResponse.java +++ b/src/main/java/cl/transbank/patpass/responses/PatpassComercioTransactionStatusResponse.java @@ -5,10 +5,16 @@ import lombok.Data; import lombok.NoArgsConstructor; +/** + * This class represents a response to a status check operation for a Patpass Comercio transaction. + */ @NoArgsConstructor @AllArgsConstructor @Data public class PatpassComercioTransactionStatusResponse { - private boolean authorized; - @SerializedName("voucherUrl") private String voucherUrl; + + private boolean authorized; + + @SerializedName("voucherUrl") + private String voucherUrl; } diff --git a/src/main/java/cl/transbank/patpass/responses/PatpassTransactionCreateDetails.java b/src/main/java/cl/transbank/patpass/responses/PatpassTransactionCreateDetails.java index 9e0767e2..9f647a6b 100644 --- a/src/main/java/cl/transbank/patpass/responses/PatpassTransactionCreateDetails.java +++ b/src/main/java/cl/transbank/patpass/responses/PatpassTransactionCreateDetails.java @@ -1,52 +1,143 @@ package cl.transbank.patpass.responses; -import com.google.gson.annotations.SerializedName; -import lombok.*; - import java.util.ArrayList; import java.util.Collections; import java.util.List; +import lombok.*; +/** + * Configures the environment for mock testing. + * @param commerceCode The commerce code. + * @param apiKey The API key. + */ public class PatpassTransactionCreateDetails { - private List detailList = new ArrayList<>(); - - private PatpassTransactionCreateDetails() {} - - public static PatpassTransactionCreateDetails build() { - return new PatpassTransactionCreateDetails(); - } - - public static PatpassTransactionCreateDetails build( - String serviceId, String cardHolderId, String cardHolderName, String cardHolderLastName1, String cardHolderLastName2, - String cardHolderMail, String cellphoneNumber, String expirationDate, String commerceMail, boolean ufFlag) { - return PatpassTransactionCreateDetails.build().add( - serviceId, cardHolderId, cardHolderName, cardHolderLastName1, cardHolderLastName2, cardHolderMail, cellphoneNumber, expirationDate, commerceMail, ufFlag); - } - - public PatpassTransactionCreateDetails add( - String serviceId, String cardHolderId, String cardHolderName, String cardHolderLastName1, String cardHolderLastName2, - String cardHolderMail, String cellphoneNumber, String expirationDate, String commerceMail, boolean ufFlag) { - detailList.add(new Detail( - serviceId, cardHolderId, cardHolderName, cardHolderLastName1, cardHolderLastName2, cardHolderMail, cellphoneNumber, expirationDate, commerceMail, ufFlag)); - return this; - } - - public List getDetails() { - return Collections.unmodifiableList(detailList); - } - - @NoArgsConstructor @AllArgsConstructor - @Getter @Setter @ToString - public class Detail { - private String serviceId; - private String cardHolderId; - private String cardHolderName; - private String cardHolderLastName1; - private String cardHolderLastName2; - private String cardHolderMail; - private String cellphoneNumber; - private String expirationDate; - private String commerceMail; - private boolean ufFlag; - } + + private List detailList = new ArrayList<>(); + + /** + * Configures the environment for mock testing. + * @param commerceCode The commerce code. + * @param apiKey The API key. + */ + private PatpassTransactionCreateDetails() {} + + /** + * Configures the environment for mock testing. + * @param commerceCode The commerce code. + * @param apiKey The API key. + */ + public static PatpassTransactionCreateDetails build() { + return new PatpassTransactionCreateDetails(); + } + + /** + * Builds a new PatpassTransactionCreateDetails with the provided parameters. + * @param serviceId The service ID. + * @param cardHolderId The card holder ID. + * @param cardHolderName The card holder name. + * @param cardHolderLastName1 The card holder's first last name. + * @param cardHolderLastName2 The card holder's second last name. + * @param cardHolderMail The card holder's mail. + * @param cellphoneNumber The cellphone number. + * @param expirationDate The expiration date. + * @param commerceMail The commerce mail. + * @param ufFlag The UF flag. + * @return A new PatpassTransactionCreateDetails. + */ + public static PatpassTransactionCreateDetails build( + String serviceId, + String cardHolderId, + String cardHolderName, + String cardHolderLastName1, + String cardHolderLastName2, + String cardHolderMail, + String cellphoneNumber, + String expirationDate, + String commerceMail, + boolean ufFlag + ) { + return PatpassTransactionCreateDetails + .build() + .add( + serviceId, + cardHolderId, + cardHolderName, + cardHolderLastName1, + cardHolderLastName2, + cardHolderMail, + cellphoneNumber, + expirationDate, + commerceMail, + ufFlag + ); + } + + /** + * Adds a new detail to the PatpassTransactionCreateDetails. + * @param serviceId The service ID. + * @param cardHolderId The card holder ID. + * @param cardHolderName The card holder name. + * @param cardHolderLastName1 The card holder's first last name. + * @param cardHolderLastName2 The card holder's second last name. + * @param cardHolderMail The card holder's mail. + * @param cellphoneNumber The cellphone number. + * @param expirationDate The expiration date. + * @param commerceMail The commerce mail. + * @param ufFlag The UF flag. + * @return The PatpassTransactionCreateDetails with the new detail added. + */ + public PatpassTransactionCreateDetails add( + String serviceId, + String cardHolderId, + String cardHolderName, + String cardHolderLastName1, + String cardHolderLastName2, + String cardHolderMail, + String cellphoneNumber, + String expirationDate, + String commerceMail, + boolean ufFlag + ) { + detailList.add( + new Detail( + serviceId, + cardHolderId, + cardHolderName, + cardHolderLastName1, + cardHolderLastName2, + cardHolderMail, + cellphoneNumber, + expirationDate, + commerceMail, + ufFlag + ) + ); + return this; + } + + public List getDetails() { + return Collections.unmodifiableList(detailList); + } + + /** + * This class represents the details of a PatpassTransactionCreate. + */ + @NoArgsConstructor + @AllArgsConstructor + @Getter + @Setter + @ToString + public class Detail { + + private String serviceId; + private String cardHolderId; + private String cardHolderName; + private String cardHolderLastName1; + private String cardHolderLastName2; + private String cardHolderMail; + private String cellphoneNumber; + private String expirationDate; + private String commerceMail; + private boolean ufFlag; + } } diff --git a/src/main/java/cl/transbank/util/HttpUtil.java b/src/main/java/cl/transbank/util/HttpUtil.java index 3e46eb89..0279aa57 100644 --- a/src/main/java/cl/transbank/util/HttpUtil.java +++ b/src/main/java/cl/transbank/util/HttpUtil.java @@ -1,40 +1,66 @@ package cl.transbank.util; import cl.transbank.webpay.exception.WebpayException; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NonNull; - import java.io.IOException; import java.net.URL; import java.util.List; import java.util.Map; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NonNull; +/** + * This interface provides methods for HTTP requests. + */ public interface HttpUtil { - T request(@NonNull URL url, RequestMethod method, Object request, Map headers, - Class clazz) throws IOException, WebpayException; - List requestList(@NonNull URL url, RequestMethod method, Object request, Map headers, - Class clazz) throws IOException, WebpayException; - String request(URL url, HttpUtilImpl.RequestMethod method, String query) throws IOException, WebpayException; - String request(URL url, HttpUtilImpl.RequestMethod method, String query, HttpUtil.ContentType contentType) - throws IOException, WebpayException; - String request(@NonNull URL url, RequestMethod method, String query, Map headers) - throws IOException, WebpayException; - String request(@NonNull URL url, RequestMethod method, String query, ContentType contentType, Map headers) throws IOException, WebpayException; + T request( + @NonNull URL url, + RequestMethod method, + Object request, + Map headers, + Class clazz + ) throws IOException, WebpayException; + List requestList( + @NonNull URL url, + RequestMethod method, + Object request, + Map headers, + Class clazz + ) throws IOException, WebpayException; + String request(URL url, HttpUtilImpl.RequestMethod method, String query) + throws IOException, WebpayException; + String request( + URL url, + HttpUtilImpl.RequestMethod method, + String query, + HttpUtil.ContentType contentType + ) throws IOException, WebpayException; + String request( + @NonNull URL url, + RequestMethod method, + String query, + Map headers + ) throws IOException, WebpayException; + String request( + @NonNull URL url, + RequestMethod method, + String query, + ContentType contentType, + Map headers + ) throws IOException, WebpayException; - @AllArgsConstructor - enum ContentType { - JSON("application/json"); + @AllArgsConstructor + enum ContentType { + JSON("application/json"); - @Getter - private String contentType; - } + @Getter + private String contentType; + } - enum RequestMethod { - GET, - POST, - DELETE, - PUT - } + enum RequestMethod { + GET, + POST, + DELETE, + PUT, + } } diff --git a/src/main/java/cl/transbank/util/JsonUtil.java b/src/main/java/cl/transbank/util/JsonUtil.java index 854c94a8..0dd64b9f 100644 --- a/src/main/java/cl/transbank/util/JsonUtil.java +++ b/src/main/java/cl/transbank/util/JsonUtil.java @@ -2,8 +2,32 @@ import java.util.List; +/** + * This interface provides methods for JSON encoding and decoding. + */ public interface JsonUtil { - String jsonEncode(Object o); - T jsonDecode(String json, Class clazz); - List jsonDecodeToList(String json, Class clazz); + /** + * Encodes an object into a JSON string. + * @param o The object to encode. + * @return The JSON string. + */ + String jsonEncode(Object o); + + /** + * Decodes a JSON string into an object of the specified class. + * @param json The JSON string. + * @param clazz The class of the object. + * @param The type of the object. + * @return The decoded object. + */ + T jsonDecode(String json, Class clazz); + + /** + * Decodes a JSON string into a list of objects of the specified class. + * @param json The JSON string. + * @param clazz The class of the objects. + * @param The type of the objects. + * @return The list of decoded objects. + */ + List jsonDecodeToList(String json, Class clazz); } diff --git a/src/main/java/cl/transbank/util/JsonUtilImpl.java b/src/main/java/cl/transbank/util/JsonUtilImpl.java index cbb53c39..b1347da2 100644 --- a/src/main/java/cl/transbank/util/JsonUtilImpl.java +++ b/src/main/java/cl/transbank/util/JsonUtilImpl.java @@ -3,40 +3,69 @@ import com.google.gson.FieldNamingPolicy; import com.google.gson.Gson; import com.google.gson.GsonBuilder; - import java.util.Arrays; import java.util.List; +/** + * This class provides utility methods for JSON encoding and decoding. + */ public final class JsonUtilImpl implements JsonUtil { - private static volatile JsonUtilImpl instance; - private Gson gson; - - private JsonUtilImpl() { - super(); - gson = new GsonBuilder() - .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) - .create(); - } - public String jsonEncode(Object o) { - return gson.toJson(o); - } + private static volatile JsonUtilImpl instance; + private Gson gson; - public T jsonDecode(String json, Class clazz) { - return gson.fromJson(json, clazz); - } + /** + * Private constructor. Initializes the Gson object with specific settings. + */ + private JsonUtilImpl() { + super(); + gson = + new GsonBuilder() + .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) + .create(); + } - public List jsonDecodeToList(String json, Class clazz) { - return Arrays.asList(gson.fromJson(json, clazz)); - } + /** + * Encodes an object into a JSON string. + * @param o The object to encode. + * @return The JSON string representation of the object. + */ + public String jsonEncode(Object o) { + return gson.toJson(o); + } + + /** + * Decodes a JSON string into an object of the specified class. + * @param json The JSON string to decode. + * @param clazz The class of the object. + * @return The object decoded from the JSON string. + */ + public T jsonDecode(String json, Class clazz) { + return gson.fromJson(json, clazz); + } - public static JsonUtilImpl getInstance() { - if (null == instance) { - synchronized (JsonUtilImpl.class) { - instance = new JsonUtilImpl(); - } - } + /** + * Decodes a JSON string into a list of objects of the specified class. + * @param json The JSON string to decode. + * @param clazz The class of the objects. + * @return The list of objects decoded from the JSON string. + */ + public List jsonDecodeToList(String json, Class clazz) { + return Arrays.asList(gson.fromJson(json, clazz)); + } - return instance; + /** + * This method provides a global access point to the instance of the JsonUtilImpl class. + * It follows the singleton pattern. + * @return The single instance of JsonUtilImpl. + */ + public static JsonUtilImpl getInstance() { + if (null == instance) { + synchronized (JsonUtilImpl.class) { + instance = new JsonUtilImpl(); + } } + + return instance; + } } diff --git a/src/main/java/cl/transbank/util/StringUtils.java b/src/main/java/cl/transbank/util/StringUtils.java index f058eb24..d3ba4b91 100644 --- a/src/main/java/cl/transbank/util/StringUtils.java +++ b/src/main/java/cl/transbank/util/StringUtils.java @@ -1,10 +1,16 @@ package cl.transbank.util; +/** + * This class provides utility methods for string operations. + */ public class StringUtils { - public static boolean isEmpty(String str) { - return str == null || str.trim().length() == 0; - } - - + /** + * Checks if a string is null or empty after trimming. + * @param str The string to check. + * @return True if the string is null or empty after trimming, false otherwise. + */ + public static boolean isEmpty(String str) { + return str == null || str.trim().length() == 0; + } } diff --git a/src/main/java/cl/transbank/util/ValidationUtil.java b/src/main/java/cl/transbank/util/ValidationUtil.java index 2247b888..312b9ba7 100644 --- a/src/main/java/cl/transbank/util/ValidationUtil.java +++ b/src/main/java/cl/transbank/util/ValidationUtil.java @@ -2,27 +2,73 @@ import java.util.List; +/** + * This class provides utility methods for validation. + */ public class ValidationUtil { - public static void hasText(String value, String valueName){ - if (StringUtils.isEmpty(value)) - throw new IllegalArgumentException("'" + valueName + "'" + " can't be null or white space"); - } + /** + * Checks if the specified string has text. + * @param value The string to check. + * @param valueName The name of the string. + * @throws IllegalArgumentException If the string is null or white space. + */ + public static void hasText(String value, String valueName) { + if (StringUtils.isEmpty(value)) throw new IllegalArgumentException( + "'" + valueName + "'" + " can't be null or white space" + ); + } - public static void hasTextWithMaxLength(String value, int length, String valueName){ - ValidationUtil.hasText(value, valueName); - if (value.length() > length) - throw new IllegalArgumentException ("'" + valueName + "'" + " is too long, the maximum length is " + length); - } - public static void hasTextTrimWithMaxLength(String value, int length, String valueName){ - ValidationUtil.hasText(value, valueName); - if (value.length() > value.trim().length()) - throw new IllegalArgumentException ("'" + valueName + "'" + " has spaces at the begining or the end"); - if (value.length() > length) - throw new IllegalArgumentException ("'" + valueName + "'" + " is too long, the maximum length is " + length); - } - public static void hasElements(List value, String valueName){ - if (value == null || value.size() == 0) - throw new IllegalArgumentException ("list '" + valueName + "'" + " can't be null or empty"); - } + /** + * Checks if the specified string has text and does not exceed the specified length. + * @param value The string to check. + * @param length The maximum length. + * @param valueName The name of the string. + * @throws IllegalArgumentException If the string is null, white space, or too long. + */ + public static void hasTextWithMaxLength( + String value, + int length, + String valueName + ) { + ValidationUtil.hasText(value, valueName); + if (value.length() > length) throw new IllegalArgumentException( + "'" + valueName + "'" + " is too long, the maximum length is " + length + ); + } + + /** + * Checks if the specified string has text, does not exceed the specified length, and does not have leading or trailing spaces. + * @param value The string to check. + * @param length The maximum length. + * @param valueName The name of the string. + * @throws IllegalArgumentException If the string is null, white space, too long, or has leading or trailing spaces. + */ + public static void hasTextTrimWithMaxLength( + String value, + int length, + String valueName + ) { + ValidationUtil.hasText(value, valueName); + if ( + value.length() > value.trim().length() + ) throw new IllegalArgumentException( + "'" + valueName + "'" + " has spaces at the begining or the end" + ); + if (value.length() > length) throw new IllegalArgumentException( + "'" + valueName + "'" + " is too long, the maximum length is " + length + ); + } + + /** + * Checks if the specified list has elements. + * @param value The list to check. + * @param valueName The name of the list. + * @throws IllegalArgumentException If the list is null or empty. + */ + public static void hasElements(List value, String valueName) { + if (value == null || value.size() == 0) throw new IllegalArgumentException( + "list '" + valueName + "'" + " can't be null or empty" + ); + } } diff --git a/src/main/java/cl/transbank/util/WebpayApiResource.java b/src/main/java/cl/transbank/util/WebpayApiResource.java index 75bad83c..e50939cc 100644 --- a/src/main/java/cl/transbank/util/WebpayApiResource.java +++ b/src/main/java/cl/transbank/util/WebpayApiResource.java @@ -1,91 +1,184 @@ package cl.transbank.util; import cl.transbank.common.IntegrationTypeHelper; -import cl.transbank.model.Options; import cl.transbank.exception.TransbankException; +import cl.transbank.model.Options; import cl.transbank.model.WebpayApiRequest; import cl.transbank.webpay.common.WebpayOptions; -import lombok.Getter; -import lombok.Setter; - import java.io.IOException; import java.net.URL; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import lombok.Getter; +import lombok.Setter; +/** + * This abstract class represents a resource for the Webpay API. + */ public abstract class WebpayApiResource { - @Getter @Setter private static HttpUtil httpUtil = HttpUtilImpl.getInstance(); - - public static Map buildHeaders(Options options) { - if (null == options) - return null; - - Map headers = new HashMap<>(); - headers.put(options.getHeaderCommerceCodeName(), options.getCommerceCode()); - headers.put(options.getHeaderApiKeyName(), options.getApiKey()); - return headers; + @Getter + @Setter + private static HttpUtil httpUtil = HttpUtilImpl.getInstance(); + + /** + * Builds the headers for a Webpay API request. + * @param options The options for the request. + * @return A map of headers for the request. + */ + public static Map buildHeaders(Options options) { + if (null == options) return null; + + Map headers = new HashMap<>(); + headers.put(options.getHeaderCommerceCodeName(), options.getCommerceCode()); + headers.put(options.getHeaderApiKeyName(), options.getApiKey()); + + return headers; + } + + /** + * Executes a Webpay API request. + * @param endpoint The endpoint for the request. + * @param method The HTTP method for the request. + * @param options The options for the request. + * @param clazz The class of the response. + * @return The response to the request. + */ + public static T execute( + final String endpoint, + HttpUtil.RequestMethod method, + final Options options, + Class clazz + ) throws TransbankException, IOException { + return execute(endpoint, method, null, options, clazz); + } + + /** + * Executes a Webpay API request with a request body. + * @param endpoint The endpoint for the request. + * @param method The HTTP method for the request. + * @param request The request body. + * @param options The options for the request. + * @return The response to the request. + */ + public static T execute( + final String endpoint, + HttpUtil.RequestMethod method, + final WebpayApiRequest request, + final Options options + ) throws TransbankException, IOException { + return execute(endpoint, method, request, options, null); + } + + /** + * Executes a Webpay API request with a request body. + * @param endpoint The endpoint for the request. + * @param method The HTTP method for the request. + * @param request The request body. + * @param options The options for the request. + * @param clazz The class of the response. + * @return The response to the request. + */ + public static T execute( + final String endpoint, + HttpUtil.RequestMethod method, + final WebpayApiRequest request, + final Options options, + Class clazz + ) throws TransbankException, IOException { + String urlBase = null; + if (options instanceof WebpayOptions) { + urlBase = + IntegrationTypeHelper.getWebpayIntegrationType( + options.getIntegrationType() + ); + } else { + urlBase = + IntegrationTypeHelper.getPatpassIntegrationType( + options.getIntegrationType() + ); } - - public static T execute(final String endpoint, HttpUtil.RequestMethod method, final Options options, Class clazz) - throws TransbankException, IOException { - return execute(endpoint, method, null, options, clazz); - } - - public static T execute(final String endpoint, HttpUtil.RequestMethod method, final WebpayApiRequest request, final Options options) - throws TransbankException, IOException { - return execute(endpoint, method, request, options, null); + final URL url = new URL(String.format("%s/%s", urlBase, endpoint)); + + final T out = WebpayApiResource + .getHttpUtil() + .request( + url, + method, + request, + WebpayApiResource.buildHeaders(options), + clazz + ); + + if (null == out) return null; + + if (null == clazz) return null; + + return out; + } + + /** + * Executes a Webpay API request and returns a list of responses. + * @param endpoint The endpoint for the request. + * @param method The HTTP method for the request. + * @param options The options for the request. + * @param clazz The class of the response. + * @return A list of responses to the request. + */ + public static List executeToList( + final String endpoint, + HttpUtil.RequestMethod method, + final Options options, + Class clazz + ) throws TransbankException, IOException { + return executeToList(endpoint, method, null, options, clazz); + } + + /** + * Executes a Webpay API request with a request body and returns a list of responses. + * @param endpoint The endpoint for the request. + * @param method The HTTP method for the request. + * @param request The request body. + * @param options The options for the request. + * @param clazz The class of the response. + * @return A list of responses to the request. + */ + public static List executeToList( + final String endpoint, + HttpUtil.RequestMethod method, + final WebpayApiRequest request, + final Options options, + Class clazz + ) throws TransbankException, IOException { + String urlBase = null; + if (options instanceof WebpayOptions) { + urlBase = + IntegrationTypeHelper.getWebpayIntegrationType( + options.getIntegrationType() + ); + } else { + urlBase = + IntegrationTypeHelper.getPatpassIntegrationType( + options.getIntegrationType() + ); } + final URL url = new URL(String.format("%s/%s", urlBase, endpoint)); - public static T execute(final String endpoint, HttpUtil.RequestMethod method, final WebpayApiRequest request, final Options options, Class clazz) - throws TransbankException, IOException { + final List out = WebpayApiResource + .getHttpUtil() + .requestList( + url, + method, + request, + WebpayApiResource.buildHeaders(options), + clazz + ); - String urlBase = null; - if(options instanceof WebpayOptions){ - urlBase = IntegrationTypeHelper.getWebpayIntegrationType(options.getIntegrationType()); - } - else{ - urlBase = IntegrationTypeHelper.getPatpassIntegrationType(options.getIntegrationType()); - } - final URL url = new URL(String.format("%s/%s", urlBase, endpoint)); + if (null == out) return null; - final T out = WebpayApiResource.getHttpUtil().request(url, method, request, WebpayApiResource.buildHeaders(options), clazz); - - if (null == out) - return null; - - if (null == clazz) - return null; - - return out; - } - public static List executeToList(final String endpoint, HttpUtil.RequestMethod method, final Options options, Class clazz) - throws TransbankException, IOException { - return executeToList(endpoint, method, null, options, clazz); - } - public static List executeToList(final String endpoint, HttpUtil.RequestMethod method, final WebpayApiRequest request, final Options options, Class clazz) - throws TransbankException, IOException { - - String urlBase = null; - if(options instanceof WebpayOptions){ - urlBase = IntegrationTypeHelper.getWebpayIntegrationType(options.getIntegrationType()); - } - else{ - urlBase = IntegrationTypeHelper.getPatpassIntegrationType(options.getIntegrationType()); - } - final URL url = new URL(String.format("%s/%s", urlBase, endpoint)); - - final List out = WebpayApiResource.getHttpUtil().requestList(url, method, request, WebpayApiResource.buildHeaders(options), clazz); - - if (null == out) - return null; - - if (null == clazz) - return null; - - return out; - } + if (null == clazz) return null; + return out; + } } diff --git a/src/main/java/cl/transbank/webpay/common/MallTransactionCaptureRequest.java b/src/main/java/cl/transbank/webpay/common/MallTransactionCaptureRequest.java index 35db2433..25300b4c 100644 --- a/src/main/java/cl/transbank/webpay/common/MallTransactionCaptureRequest.java +++ b/src/main/java/cl/transbank/webpay/common/MallTransactionCaptureRequest.java @@ -3,12 +3,18 @@ import cl.transbank.model.WebpayApiRequest; import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter +/** + * This class represents a request to capture a mall transaction. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter @ToString public class MallTransactionCaptureRequest extends WebpayApiRequest { - private String commerceCode; - private String buyOrder; - private String authorizationCode; - private double captureAmount; + + private String commerceCode; + private String buyOrder; + private String authorizationCode; + private double captureAmount; } diff --git a/src/main/java/cl/transbank/webpay/common/MallTransactionRefundRequest.java b/src/main/java/cl/transbank/webpay/common/MallTransactionRefundRequest.java index ee22ba5c..112ef564 100644 --- a/src/main/java/cl/transbank/webpay/common/MallTransactionRefundRequest.java +++ b/src/main/java/cl/transbank/webpay/common/MallTransactionRefundRequest.java @@ -3,13 +3,17 @@ import cl.transbank.model.WebpayApiRequest; import lombok.*; +/** + * This class represents a request to refund a Mall transaction. + */ @NoArgsConstructor @AllArgsConstructor @Getter @Setter @ToString public class MallTransactionRefundRequest extends WebpayApiRequest { - private String buyOrder; - private String commerceCode; - private double amount; + + private String buyOrder; + private String commerceCode; + private double amount; } diff --git a/src/main/java/cl/transbank/webpay/common/TransactionCaptureRequest.java b/src/main/java/cl/transbank/webpay/common/TransactionCaptureRequest.java index 9ddf3bb7..c40ac65b 100644 --- a/src/main/java/cl/transbank/webpay/common/TransactionCaptureRequest.java +++ b/src/main/java/cl/transbank/webpay/common/TransactionCaptureRequest.java @@ -3,11 +3,17 @@ import cl.transbank.model.WebpayApiRequest; import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter +/** + * This class represents a request to capture a transaction. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter @ToString public class TransactionCaptureRequest extends WebpayApiRequest { - private String buyOrder; - private String authorizationCode; - private double captureAmount; + + private String buyOrder; + private String authorizationCode; + private double captureAmount; } diff --git a/src/main/java/cl/transbank/webpay/common/TransactionRefundRequest.java b/src/main/java/cl/transbank/webpay/common/TransactionRefundRequest.java index 4895735d..3e8a66a5 100644 --- a/src/main/java/cl/transbank/webpay/common/TransactionRefundRequest.java +++ b/src/main/java/cl/transbank/webpay/common/TransactionRefundRequest.java @@ -3,9 +3,15 @@ import cl.transbank.model.WebpayApiRequest; import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter +/** + * This class represents a request to refund a transaction. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter @ToString public class TransactionRefundRequest extends WebpayApiRequest { - private double amount; + + private double amount; } diff --git a/src/main/java/cl/transbank/webpay/common/WebpayOptions.java b/src/main/java/cl/transbank/webpay/common/WebpayOptions.java index f830fa0c..ab42eef0 100644 --- a/src/main/java/cl/transbank/webpay/common/WebpayOptions.java +++ b/src/main/java/cl/transbank/webpay/common/WebpayOptions.java @@ -4,13 +4,30 @@ import cl.transbank.model.Options; import lombok.*; -@ToString @AllArgsConstructor +/** + * This class represents the options for a Webpay transaction. + */ +@ToString +@AllArgsConstructor public class WebpayOptions extends Options { - @Getter final String headerCommerceCodeName = "Tbk-Api-Key-Id"; - @Getter final String headerApiKeyName = "Tbk-Api-Key-Secret"; - public WebpayOptions(String commerceCode, String apiKey,IntegrationType integrationType ){ - super(commerceCode,apiKey,integrationType); + @Getter + final String headerCommerceCodeName = "Tbk-Api-Key-Id"; - } + @Getter + final String headerApiKeyName = "Tbk-Api-Key-Secret"; + + /** + * Constructs a new WebpayOptions with the specified commerce code, API key, and integration type. + * @param commerceCode The commerce code. + * @param apiKey The API key. + * @param integrationType The integration type. + */ + public WebpayOptions( + String commerceCode, + String apiKey, + IntegrationType integrationType + ) { + super(commerceCode, apiKey, integrationType); + } } diff --git a/src/main/java/cl/transbank/webpay/exception/InscriptionDeleteException.java b/src/main/java/cl/transbank/webpay/exception/InscriptionDeleteException.java index 46b484b0..12f1ed1d 100644 --- a/src/main/java/cl/transbank/webpay/exception/InscriptionDeleteException.java +++ b/src/main/java/cl/transbank/webpay/exception/InscriptionDeleteException.java @@ -1,14 +1,28 @@ package cl.transbank.webpay.exception; +/** + * This class represents an exception that is thrown when an inscription deletion operation fails. + */ public class InscriptionDeleteException extends WebpayException { - public InscriptionDeleteException() { - } - public InscriptionDeleteException(Exception e) { - super(e); - } + /** + * Constructs a new InscriptionDeleteException with no detail message. + */ + public InscriptionDeleteException() {} - public InscriptionDeleteException(String message) { - super(message); - } + /** + * Constructs a new InscriptionDeleteException with the specified cause. + * @param e The cause of the exception. + */ + public InscriptionDeleteException(Exception e) { + super(e); + } + + /** + * Constructs a new InscriptionDeleteException with the specified detail message. + * @param message The detail message. + */ + public InscriptionDeleteException(String message) { + super(message); + } } diff --git a/src/main/java/cl/transbank/webpay/exception/InscriptionFinishException.java b/src/main/java/cl/transbank/webpay/exception/InscriptionFinishException.java index ad65b714..4da9ba3c 100644 --- a/src/main/java/cl/transbank/webpay/exception/InscriptionFinishException.java +++ b/src/main/java/cl/transbank/webpay/exception/InscriptionFinishException.java @@ -1,14 +1,26 @@ package cl.transbank.webpay.exception; +/** + * This class represents an exception that is thrown when an inscription finish operation fails. + */ public class InscriptionFinishException extends WebpayException { - public InscriptionFinishException() { - } - public InscriptionFinishException(Exception e) { - super(e); - } + /** + * Constructs a new InscriptionFinishException with no detail message. + */ + public InscriptionFinishException() {} - public InscriptionFinishException(String message) { - super(message); - } + /** + * Constructs a new InscriptionFinishException with the specified cause. + */ + public InscriptionFinishException(Exception e) { + super(e); + } + + /** + * Constructs a new InscriptionFinishException with the specified detail message. + */ + public InscriptionFinishException(String message) { + super(message); + } } diff --git a/src/main/java/cl/transbank/webpay/exception/InscriptionStartException.java b/src/main/java/cl/transbank/webpay/exception/InscriptionStartException.java index 495d5ffb..fb1293c2 100644 --- a/src/main/java/cl/transbank/webpay/exception/InscriptionStartException.java +++ b/src/main/java/cl/transbank/webpay/exception/InscriptionStartException.java @@ -1,7 +1,30 @@ package cl.transbank.webpay.exception; +/** + * This class represents an exception that is thrown when an inscription start operation fails. + */ public class InscriptionStartException extends WebpayException { - public InscriptionStartException() { super(); } - public InscriptionStartException(Exception e) { super(e); } - public InscriptionStartException(String message) { super(message); } + + /** + * Constructs a new InscriptionStartException with no detail message. + */ + public InscriptionStartException() { + super(); + } + + /** + * Constructs a new InscriptionStartException with the specified cause. + * @param e The cause of the exception. + */ + public InscriptionStartException(Exception e) { + super(e); + } + + /** + * Constructs a new InscriptionStartException with the specified detail message. + * @param message The detail message. + */ + public InscriptionStartException(String message) { + super(message); + } } diff --git a/src/main/java/cl/transbank/webpay/exception/TransactionAuthorizeException.java b/src/main/java/cl/transbank/webpay/exception/TransactionAuthorizeException.java index c41f60de..e0c555e3 100644 --- a/src/main/java/cl/transbank/webpay/exception/TransactionAuthorizeException.java +++ b/src/main/java/cl/transbank/webpay/exception/TransactionAuthorizeException.java @@ -1,14 +1,28 @@ package cl.transbank.webpay.exception; +/** + * This class represents an exception that is thrown when a transaction authorization fails. + */ public class TransactionAuthorizeException extends WebpayException { - public TransactionAuthorizeException() { - } - public TransactionAuthorizeException(Exception e) { - super(e); - } + /** + * Constructs a new TransactionAuthorizeException with no detail message. + */ + public TransactionAuthorizeException() {} - public TransactionAuthorizeException(String message) { - super(message); - } + /** + * Constructs a new TransactionAuthorizeException with the specified cause. + * @param e The cause of the exception. + */ + public TransactionAuthorizeException(Exception e) { + super(e); + } + + /** + * Constructs a new TransactionAuthorizeException with the specified detail message. + * @param message The detail message. + */ + public TransactionAuthorizeException(String message) { + super(message); + } } diff --git a/src/main/java/cl/transbank/webpay/exception/TransactionCaptureException.java b/src/main/java/cl/transbank/webpay/exception/TransactionCaptureException.java index c609a9dd..87343a04 100644 --- a/src/main/java/cl/transbank/webpay/exception/TransactionCaptureException.java +++ b/src/main/java/cl/transbank/webpay/exception/TransactionCaptureException.java @@ -1,15 +1,30 @@ package cl.transbank.webpay.exception; +/** + * This class represents an exception that is thrown when a transaction capture operation fails. + */ public class TransactionCaptureException extends WebpayException { - public TransactionCaptureException() { - super(); - } - public TransactionCaptureException(Exception e) { - super(e); - } + /** + * Constructs a new TransactionCaptureException with null as its detail message. + */ + public TransactionCaptureException() { + super(); + } - public TransactionCaptureException(String message) { - super(message); - } + /** + * Constructs a new TransactionCaptureException with the specified cause. + * @param e The cause of the exception. + */ + public TransactionCaptureException(Exception e) { + super(e); + } + + /** + * Constructs a new TransactionCaptureException with the specified detail message. + * @param message The detail message. + */ + public TransactionCaptureException(String message) { + super(message); + } } diff --git a/src/main/java/cl/transbank/webpay/exception/TransactionCommitException.java b/src/main/java/cl/transbank/webpay/exception/TransactionCommitException.java index 35f034fc..1194c4b2 100644 --- a/src/main/java/cl/transbank/webpay/exception/TransactionCommitException.java +++ b/src/main/java/cl/transbank/webpay/exception/TransactionCommitException.java @@ -1,15 +1,30 @@ package cl.transbank.webpay.exception; +/** + * This class represents an exception that is thrown when a transaction commit operation fails. + */ public class TransactionCommitException extends WebpayException { - public TransactionCommitException() { - super(); - } - public TransactionCommitException(Exception e) { - super(e); - } + /** + * Constructs a new TransactionCommitException with no detail message. + */ + public TransactionCommitException() { + super(); + } - public TransactionCommitException(String message) { - super(message); - } + /** + * Constructs a new TransactionCommitException with the specified cause. + * @param e The cause of the exception. + */ + public TransactionCommitException(Exception e) { + super(e); + } + + /** + * Constructs a new TransactionCommitException with the specified detail message. + * @param message The detail message. + */ + public TransactionCommitException(String message) { + super(message); + } } diff --git a/src/main/java/cl/transbank/webpay/exception/TransactionCreateException.java b/src/main/java/cl/transbank/webpay/exception/TransactionCreateException.java index 0311b43c..4db87111 100644 --- a/src/main/java/cl/transbank/webpay/exception/TransactionCreateException.java +++ b/src/main/java/cl/transbank/webpay/exception/TransactionCreateException.java @@ -1,15 +1,28 @@ package cl.transbank.webpay.exception; +/** + * This class represents an exception that is thrown when a transaction creation fails. + */ public class TransactionCreateException extends WebpayException { - public TransactionCreateException() { - super(); - } - public TransactionCreateException(Exception e) { - super(e); - } + /** + * Constructs a new TransactionCreateException with no detail message. + */ + public TransactionCreateException() { + super(); + } - public TransactionCreateException(String message) { - super(message); - } + /** + * Constructs a new TransactionCreateException with the specified cause. + */ + public TransactionCreateException(Exception e) { + super(e); + } + + /** + * Constructs a new TransactionCreateException with the specified detail message. + */ + public TransactionCreateException(String message) { + super(message); + } } diff --git a/src/main/java/cl/transbank/webpay/exception/TransactionInstallmentException.java b/src/main/java/cl/transbank/webpay/exception/TransactionInstallmentException.java index ecfa14c0..009e91ff 100644 --- a/src/main/java/cl/transbank/webpay/exception/TransactionInstallmentException.java +++ b/src/main/java/cl/transbank/webpay/exception/TransactionInstallmentException.java @@ -1,15 +1,30 @@ package cl.transbank.webpay.exception; +/** + * This class represents an exception that is thrown when a transaction installment operation fails. + */ public class TransactionInstallmentException extends WebpayException { - public TransactionInstallmentException() { - super(); - } - public TransactionInstallmentException(Exception e) { - super(e); - } + /** + * Constructs a new TransactionInstallmentException with no detail message. + */ + public TransactionInstallmentException() { + super(); + } - public TransactionInstallmentException(String message) { - super(message); - } + /** + * Constructs a new TransactionInstallmentException with the specified cause. + * @param e The cause of the exception. + */ + public TransactionInstallmentException(Exception e) { + super(e); + } + + /** + * Constructs a new TransactionInstallmentException with the specified detail message. + * @param message The detail message. + */ + public TransactionInstallmentException(String message) { + super(message); + } } diff --git a/src/main/java/cl/transbank/webpay/exception/TransactionRefundException.java b/src/main/java/cl/transbank/webpay/exception/TransactionRefundException.java index 56481fd4..0af364a5 100644 --- a/src/main/java/cl/transbank/webpay/exception/TransactionRefundException.java +++ b/src/main/java/cl/transbank/webpay/exception/TransactionRefundException.java @@ -1,15 +1,30 @@ package cl.transbank.webpay.exception; +/** + * This class represents an exception that is thrown when a transaction refund operation fails. + */ public class TransactionRefundException extends WebpayException { - public TransactionRefundException() { - super(); - } - public TransactionRefundException(Exception e) { - super(e); - } + /** + * Constructs a new TransactionRefundException with no detail message. + */ + public TransactionRefundException() { + super(); + } - public TransactionRefundException(String message) { - super(message); - } + /** + * Constructs a new TransactionRefundException with the specified cause. + * @param e The cause of the exception. + */ + public TransactionRefundException(Exception e) { + super(e); + } + + /** + * Constructs a new TransactionRefundException with the specified detail message. + * @param message The detail message. + */ + public TransactionRefundException(String message) { + super(message); + } } diff --git a/src/main/java/cl/transbank/webpay/exception/TransactionStatusException.java b/src/main/java/cl/transbank/webpay/exception/TransactionStatusException.java index 30c71082..3b527ee2 100644 --- a/src/main/java/cl/transbank/webpay/exception/TransactionStatusException.java +++ b/src/main/java/cl/transbank/webpay/exception/TransactionStatusException.java @@ -1,15 +1,30 @@ package cl.transbank.webpay.exception; +/** + * This class represents an exception that is thrown when a transaction status operation fails. + */ public class TransactionStatusException extends WebpayException { - public TransactionStatusException() { - super(); - } - public TransactionStatusException(Exception e) { - super(e); - } + /** + * Constructs a new TransactionStatusException with no detail message. + */ + public TransactionStatusException() { + super(); + } - public TransactionStatusException(String message) { - super(message); - } + /** + * Constructs a new TransactionStatusException with the specified cause. + * @param e The cause of the exception. + */ + public TransactionStatusException(Exception e) { + super(e); + } + + /** + * Constructs a new TransactionStatusException with the specified detail message. + * @param message The detail message. + */ + public TransactionStatusException(String message) { + super(message); + } } diff --git a/src/main/java/cl/transbank/webpay/exception/TransbankHttpApiException.java b/src/main/java/cl/transbank/webpay/exception/TransbankHttpApiException.java index 077cca87..3e44491a 100644 --- a/src/main/java/cl/transbank/webpay/exception/TransbankHttpApiException.java +++ b/src/main/java/cl/transbank/webpay/exception/TransbankHttpApiException.java @@ -1,21 +1,33 @@ package cl.transbank.webpay.exception; -import cl.transbank.exception.TransbankException; -import lombok.Getter; - +/** + * This class represents an exception that is thrown when a Transbank HTTP API operation fails. + */ public class TransbankHttpApiException extends WebpayException { - public TransbankHttpApiException() { - } - public TransbankHttpApiException(Exception e) { - super(e); - } + /** + * Constructs a new TransbankHttpApiException with no detail message. + */ + public TransbankHttpApiException() {} + + /** + * Constructs a new TransbankHttpApiException with the specified cause. + */ + public TransbankHttpApiException(Exception e) { + super(e); + } - public TransbankHttpApiException(String message) { - super(message); - } + /** + * Constructs a new TransbankHttpApiException with the specified detail message. + */ + public TransbankHttpApiException(String message) { + super(message); + } - public TransbankHttpApiException(int code, String message) { - super(code, message); - } + /** + * Constructs a new TransbankHttpApiException with the specified detail message and error code. + */ + public TransbankHttpApiException(int code, String message) { + super(code, message); + } } diff --git a/src/main/java/cl/transbank/webpay/exception/WebpayException.java b/src/main/java/cl/transbank/webpay/exception/WebpayException.java index 1d0ad159..b5ebec88 100644 --- a/src/main/java/cl/transbank/webpay/exception/WebpayException.java +++ b/src/main/java/cl/transbank/webpay/exception/WebpayException.java @@ -2,25 +2,44 @@ import cl.transbank.exception.TransbankException; +/** + * This class represents an exception that is thrown when a Webpay operation fails. + */ public class WebpayException extends TransbankException { - public WebpayException() { - super(); - } - public WebpayException(Exception e) { - super(e); - } + /** + * Constructs a new WebpayException with no detail message. + */ + public WebpayException() { + super(); + } - public WebpayException(String message) { - super(message); - } + /** + * Constructs a new WebpayException with the specified cause. + */ + public WebpayException(Exception e) { + super(e); + } - public WebpayException(int code, String message) { - super(code, message); - } + /** + * Constructs a new WebpayException with the specified detail message. + */ + public WebpayException(String message) { + super(message); + } - @Override - public String toString() { - return super.toString().concat(String.format(" | code : %s", getCode())); - } + /** + * Constructs a new WebpayException with the specified detail message and error code. + */ + public WebpayException(int code, String message) { + super(code, message); + } + + /** + * Returns a string representation of this exception. + */ + @Override + public String toString() { + return super.toString().concat(String.format(" | code : %s", getCode())); + } } diff --git a/src/main/java/cl/transbank/webpay/modal/WebpayPlusModal.java b/src/main/java/cl/transbank/webpay/modal/WebpayPlusModal.java index b374f8ec..c18c9452 100644 --- a/src/main/java/cl/transbank/webpay/modal/WebpayPlusModal.java +++ b/src/main/java/cl/transbank/webpay/modal/WebpayPlusModal.java @@ -6,37 +6,80 @@ import cl.transbank.model.Options; import cl.transbank.webpay.common.WebpayOptions; +/** + * This class provides methods to configure and perform transactions with the PatpassByWebpay service. + */ public class WebpayPlusModal { - private static Options options; - - public static class Transaction extends WebpayModalTransaction { - public Transaction() { - super(WebpayPlusModal.options!=null ? WebpayPlusModal.options : new WebpayOptions(IntegrationCommerceCodes.WEBPAY_PLUS_MODAL, IntegrationApiKeys.WEBPAY, IntegrationType.TEST)); - } - public Transaction(Options options) { - super(options); - } + + private static Options options; + + /** + * This class provides methods to configure and perform transactions with the WebpayPlusModal service. + */ + public static class Transaction extends WebpayModalTransaction { + + /** + * Default constructor. Uses default options if none are provided. + */ + public Transaction() { + super( + WebpayPlusModal.options != null + ? WebpayPlusModal.options + : new WebpayOptions( + IntegrationCommerceCodes.WEBPAY_PLUS_MODAL, + IntegrationApiKeys.WEBPAY, + IntegrationType.TEST + ) + ); + } + + /** + * Constructor with options. Uses provided options. + * @param options The options to use for this transaction. + */ + public Transaction(Options options) { + super(options); } + } - /* + /* |-------------------------------------------------------------------------- | Environment Configuration |-------------------------------------------------------------------------- */ - public static void configureForIntegration(String commerceCode, String apiKey){ - options = new WebpayOptions(commerceCode, apiKey, IntegrationType.TEST); - } + /** + * Configures the environment for integration. + * @param commerceCode The commerce code. + * @param apiKey The API key. + */ + public static void configureForIntegration( + String commerceCode, + String apiKey + ) { + options = new WebpayOptions(commerceCode, apiKey, IntegrationType.TEST); + } - public static void configureForProduction(String commerceCode, String apiKey){ - options = new WebpayOptions(commerceCode, apiKey, IntegrationType.LIVE); - } + public static void configureForProduction( + String commerceCode, + String apiKey + ) { + options = new WebpayOptions(commerceCode, apiKey, IntegrationType.LIVE); + } - public static void configureForTesting(){ - configureForIntegration(IntegrationCommerceCodes.WEBPAY_PLUS_MODAL, IntegrationApiKeys.WEBPAY); - } + public static void configureForTesting() { + configureForIntegration( + IntegrationCommerceCodes.WEBPAY_PLUS_MODAL, + IntegrationApiKeys.WEBPAY + ); + } - public static void configureForMock(){ - options = new WebpayOptions(IntegrationCommerceCodes.WEBPAY_PLUS_MODAL, IntegrationApiKeys.WEBPAY, IntegrationType.SERVER_MOCK); - } -} \ No newline at end of file + public static void configureForMock() { + options = + new WebpayOptions( + IntegrationCommerceCodes.WEBPAY_PLUS_MODAL, + IntegrationApiKeys.WEBPAY, + IntegrationType.SERVER_MOCK + ); + } +} diff --git a/src/main/java/cl/transbank/webpay/modal/requests/ModalTransactionCreateRequest.java b/src/main/java/cl/transbank/webpay/modal/requests/ModalTransactionCreateRequest.java index cc8a09be..501ee57e 100644 --- a/src/main/java/cl/transbank/webpay/modal/requests/ModalTransactionCreateRequest.java +++ b/src/main/java/cl/transbank/webpay/modal/requests/ModalTransactionCreateRequest.java @@ -3,11 +3,17 @@ import cl.transbank.model.WebpayApiRequest; import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter +/** + * This class represents a request to create a modal transaction. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter @ToString public class ModalTransactionCreateRequest extends WebpayApiRequest { - private String buyOrder; - private String sessionId; - private double amount; + + private String buyOrder; + private String sessionId; + private double amount; } diff --git a/src/main/java/cl/transbank/webpay/modal/responses/ModalTransactionCommitResponse.java b/src/main/java/cl/transbank/webpay/modal/responses/ModalTransactionCommitResponse.java index 1411d1ad..f3f3b774 100644 --- a/src/main/java/cl/transbank/webpay/modal/responses/ModalTransactionCommitResponse.java +++ b/src/main/java/cl/transbank/webpay/modal/responses/ModalTransactionCommitResponse.java @@ -2,5 +2,8 @@ import cl.transbank.webpay.webpayplus.responses.WebpayPlusTransactionCommitResponse; -public class ModalTransactionCommitResponse extends WebpayPlusTransactionCommitResponse { -} +/** + * This class represents a response to a commit operation for a Modal transaction. + */ +public class ModalTransactionCommitResponse + extends WebpayPlusTransactionCommitResponse {} diff --git a/src/main/java/cl/transbank/webpay/modal/responses/ModalTransactionCreateResponse.java b/src/main/java/cl/transbank/webpay/modal/responses/ModalTransactionCreateResponse.java index 8216e405..ea2b03c6 100644 --- a/src/main/java/cl/transbank/webpay/modal/responses/ModalTransactionCreateResponse.java +++ b/src/main/java/cl/transbank/webpay/modal/responses/ModalTransactionCreateResponse.java @@ -2,9 +2,15 @@ import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter +/** + * This class represents a response to a create operation for a Modal transaction. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter @ToString public class ModalTransactionCreateResponse { - private String token; + + private String token; } diff --git a/src/main/java/cl/transbank/webpay/modal/responses/ModalTransactionRefundResponse.java b/src/main/java/cl/transbank/webpay/modal/responses/ModalTransactionRefundResponse.java index 843ab4f4..a3a5c312 100644 --- a/src/main/java/cl/transbank/webpay/modal/responses/ModalTransactionRefundResponse.java +++ b/src/main/java/cl/transbank/webpay/modal/responses/ModalTransactionRefundResponse.java @@ -2,5 +2,8 @@ import cl.transbank.webpay.webpayplus.responses.WebpayPlusTransactionRefundResponse; -public class ModalTransactionRefundResponse extends WebpayPlusTransactionRefundResponse { -} +/** + * This class represents a response to a refund operation for a Modal transaction. + */ +public class ModalTransactionRefundResponse + extends WebpayPlusTransactionRefundResponse {} diff --git a/src/main/java/cl/transbank/webpay/modal/responses/ModalTransactionStatusResponse.java b/src/main/java/cl/transbank/webpay/modal/responses/ModalTransactionStatusResponse.java index b7415469..79d6184a 100644 --- a/src/main/java/cl/transbank/webpay/modal/responses/ModalTransactionStatusResponse.java +++ b/src/main/java/cl/transbank/webpay/modal/responses/ModalTransactionStatusResponse.java @@ -2,5 +2,8 @@ import cl.transbank.webpay.webpayplus.responses.WebpayPlusTransactionStatusResponse; -public class ModalTransactionStatusResponse extends WebpayPlusTransactionStatusResponse { -} +/** + * This class represents a response to a status request for a modal transaction. + */ +public class ModalTransactionStatusResponse + extends WebpayPlusTransactionStatusResponse {} diff --git a/src/main/java/cl/transbank/webpay/oneclick/Oneclick.java b/src/main/java/cl/transbank/webpay/oneclick/Oneclick.java index 4866c43e..7eed1c19 100644 --- a/src/main/java/cl/transbank/webpay/oneclick/Oneclick.java +++ b/src/main/java/cl/transbank/webpay/oneclick/Oneclick.java @@ -6,50 +6,97 @@ import cl.transbank.model.Options; import cl.transbank.webpay.common.WebpayOptions; -public class Oneclick{ - private static Options options; - - public static class MallInscription extends OneclickMallInscription{ - public MallInscription() { - super(Oneclick.options!=null ? Oneclick.options : new WebpayOptions(IntegrationCommerceCodes.ONECLICK_MALL, IntegrationApiKeys.WEBPAY, IntegrationType.TEST)); - } - public MallInscription(Options options) { - super(options); - } +/** + * This class provides methods to configure and perform transactions with the Oneclick service. + */ +public class Oneclick { + + private static Options options; + + /** + * This class provides methods to perform Oneclick Mall Inscriptions. + */ + public static class MallInscription extends OneclickMallInscription { + + public MallInscription() { + super( + Oneclick.options != null + ? Oneclick.options + : new WebpayOptions( + IntegrationCommerceCodes.ONECLICK_MALL, + IntegrationApiKeys.WEBPAY, + IntegrationType.TEST + ) + ); } - public static class MallTransaction extends OneclickMallTransaction { - public MallTransaction() { - super(Oneclick.options!=null ? Oneclick.options : new WebpayOptions(IntegrationCommerceCodes.ONECLICK_MALL, IntegrationApiKeys.WEBPAY, IntegrationType.TEST)); - } - public MallTransaction(Options options) { - super(options); - } + public MallInscription(Options options) { + super(options); } + } + + /** + * Default constructor. Uses default options if none are provided. + */ + public static class MallTransaction extends OneclickMallTransaction { - /* + public MallTransaction() { + super( + Oneclick.options != null + ? Oneclick.options + : new WebpayOptions( + IntegrationCommerceCodes.ONECLICK_MALL, + IntegrationApiKeys.WEBPAY, + IntegrationType.TEST + ) + ); + } + + public MallTransaction(Options options) { + super(options); + } + } + + /* |-------------------------------------------------------------------------- | Environment Configuration |-------------------------------------------------------------------------- */ - public static void configureForIntegration(String commerceCode, String apiKey){ - options = new WebpayOptions(commerceCode, apiKey, IntegrationType.TEST); - } + public static void configureForIntegration( + String commerceCode, + String apiKey + ) { + options = new WebpayOptions(commerceCode, apiKey, IntegrationType.TEST); + } - public static void configureForProduction(String commerceCode, String apiKey){ - options = new WebpayOptions(commerceCode, apiKey, IntegrationType.LIVE); - } + public static void configureForProduction( + String commerceCode, + String apiKey + ) { + options = new WebpayOptions(commerceCode, apiKey, IntegrationType.LIVE); + } - public static void configureForTesting(){ - configureForIntegration(IntegrationCommerceCodes.ONECLICK_MALL, IntegrationApiKeys.WEBPAY); - } + public static void configureForTesting() { + configureForIntegration( + IntegrationCommerceCodes.ONECLICK_MALL, + IntegrationApiKeys.WEBPAY + ); + } - public static void configureForTestingDeferred(){ - configureForIntegration(IntegrationCommerceCodes.ONECLICK_MALL_DEFERRED, IntegrationApiKeys.WEBPAY); - } + public static void configureForTestingDeferred() { + configureForIntegration( + IntegrationCommerceCodes.ONECLICK_MALL_DEFERRED, + IntegrationApiKeys.WEBPAY + ); + } - public static void configureForMock(){ - options = new WebpayOptions(IntegrationCommerceCodes.ONECLICK_MALL, IntegrationApiKeys.WEBPAY, IntegrationType.SERVER_MOCK); - } + public static void configureForMock() { + options = + new WebpayOptions( + IntegrationCommerceCodes.ONECLICK_MALL, + IntegrationApiKeys.WEBPAY, + IntegrationType.SERVER_MOCK + ); + } } diff --git a/src/main/java/cl/transbank/webpay/oneclick/OneclickMallInscription.java b/src/main/java/cl/transbank/webpay/oneclick/OneclickMallInscription.java index ceb72ccb..c0858469 100644 --- a/src/main/java/cl/transbank/webpay/oneclick/OneclickMallInscription.java +++ b/src/main/java/cl/transbank/webpay/oneclick/OneclickMallInscription.java @@ -2,8 +2,8 @@ import cl.transbank.common.ApiConstants; import cl.transbank.common.BaseTransaction; -import cl.transbank.model.Options; import cl.transbank.exception.TransbankException; +import cl.transbank.model.Options; import cl.transbank.model.WebpayApiRequest; import cl.transbank.util.HttpUtil; import cl.transbank.util.ValidationUtil; @@ -15,47 +15,122 @@ import cl.transbank.webpay.oneclick.requests.InscriptionStartRequest; import cl.transbank.webpay.oneclick.responses.OneclickMallInscriptionFinishResponse; import cl.transbank.webpay.oneclick.responses.OneclickMallInscriptionStartResponse; - import java.io.IOException; +/** + * This abstract class represents the OneclickMallInscription and provides methods to handle Oneclick Mall Inscriptions. + */ abstract class OneclickMallInscription extends BaseTransaction { - public OneclickMallInscription(Options options){ - this.options = options; - } - public OneclickMallInscriptionStartResponse start(String username, String email, String responseUrl) throws IOException, InscriptionStartException { - ValidationUtil.hasTextTrimWithMaxLength(username, ApiConstants.USER_NAME_LENGTH, "username"); - ValidationUtil.hasTextTrimWithMaxLength(email, ApiConstants.EMAIL_LENGTH, "email"); - ValidationUtil.hasTextWithMaxLength(responseUrl, ApiConstants.RETURN_URL_LENGTH, "responseUrl"); + /** + * This abstract class represents the OneclickMallInscription and provides methods to handle Oneclick Mall Inscriptions. + */ + public OneclickMallInscription(Options options) { + this.options = options; + } + + /** + * Starts a new Oneclick Mall Inscription. + * @param username The username of the user. + * @param email The email of the user. + * @param responseUrl The URL to redirect the user to after the inscription is completed. + * @return The response from the start inscription request. + * @throws IOException If there is an error during the execution of the request. + * @throws InscriptionStartException If there is an error during the start of the inscription. + */ + public OneclickMallInscriptionStartResponse start( + String username, + String email, + String responseUrl + ) throws IOException, InscriptionStartException { + ValidationUtil.hasTextTrimWithMaxLength( + username, + ApiConstants.USER_NAME_LENGTH, + "username" + ); + ValidationUtil.hasTextTrimWithMaxLength( + email, + ApiConstants.EMAIL_LENGTH, + "email" + ); + ValidationUtil.hasTextWithMaxLength( + responseUrl, + ApiConstants.RETURN_URL_LENGTH, + "responseUrl" + ); - final WebpayApiRequest request = new InscriptionStartRequest(username, email, responseUrl); - String endpoint = String.format("%s/inscriptions", ApiConstants.ONECLICK_ENDPOINT); - try { - return WebpayApiResource.execute(endpoint, HttpUtil.RequestMethod.POST, request, options, OneclickMallInscriptionStartResponse.class); - } catch (TransbankException e) { - throw new InscriptionStartException(e); - } + final WebpayApiRequest request = new InscriptionStartRequest( + username, + email, + responseUrl + ); + String endpoint = String.format( + "%s/inscriptions", + ApiConstants.ONECLICK_ENDPOINT + ); + try { + return WebpayApiResource.execute( + endpoint, + HttpUtil.RequestMethod.POST, + request, + options, + OneclickMallInscriptionStartResponse.class + ); + } catch (TransbankException e) { + throw new InscriptionStartException(e); } + } - public OneclickMallInscriptionFinishResponse finish(String token) throws IOException, InscriptionFinishException { - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); - String endpoint = String.format("%s/inscriptions/%s", ApiConstants.ONECLICK_ENDPOINT, token); - try { - return WebpayApiResource.execute(endpoint, HttpUtil.RequestMethod.PUT, options, OneclickMallInscriptionFinishResponse.class); - } catch (TransbankException e) { - throw new InscriptionFinishException(e); - } + public OneclickMallInscriptionFinishResponse finish(String token) + throws IOException, InscriptionFinishException { + ValidationUtil.hasTextWithMaxLength( + token, + ApiConstants.TOKEN_LENGTH, + "token" + ); + String endpoint = String.format( + "%s/inscriptions/%s", + ApiConstants.ONECLICK_ENDPOINT, + token + ); + try { + return WebpayApiResource.execute( + endpoint, + HttpUtil.RequestMethod.PUT, + options, + OneclickMallInscriptionFinishResponse.class + ); + } catch (TransbankException e) { + throw new InscriptionFinishException(e); } + } - public void delete(String tbkUser, String username) throws IOException, InscriptionDeleteException { - ValidationUtil.hasTextTrimWithMaxLength(username, ApiConstants.USER_NAME_LENGTH, "username"); - ValidationUtil.hasTextWithMaxLength(tbkUser, ApiConstants.TBK_USER_LENGTH, "tbkUser"); - WebpayApiRequest request = new InscriptionDeleteRequest(username, tbkUser); - String endpoint = String.format("%s/inscriptions", ApiConstants.ONECLICK_ENDPOINT); - try { - WebpayApiResource.execute(endpoint, HttpUtil.RequestMethod.DELETE, request, options); - } catch (TransbankException e) { - throw new InscriptionDeleteException(e); - } + public void delete(String tbkUser, String username) + throws IOException, InscriptionDeleteException { + ValidationUtil.hasTextTrimWithMaxLength( + username, + ApiConstants.USER_NAME_LENGTH, + "username" + ); + ValidationUtil.hasTextWithMaxLength( + tbkUser, + ApiConstants.TBK_USER_LENGTH, + "tbkUser" + ); + WebpayApiRequest request = new InscriptionDeleteRequest(username, tbkUser); + String endpoint = String.format( + "%s/inscriptions", + ApiConstants.ONECLICK_ENDPOINT + ); + try { + WebpayApiResource.execute( + endpoint, + HttpUtil.RequestMethod.DELETE, + request, + options + ); + } catch (TransbankException e) { + throw new InscriptionDeleteException(e); } + } } diff --git a/src/main/java/cl/transbank/webpay/oneclick/requests/InscriptionDeleteRequest.java b/src/main/java/cl/transbank/webpay/oneclick/requests/InscriptionDeleteRequest.java index 7c8f85ea..90611ecf 100644 --- a/src/main/java/cl/transbank/webpay/oneclick/requests/InscriptionDeleteRequest.java +++ b/src/main/java/cl/transbank/webpay/oneclick/requests/InscriptionDeleteRequest.java @@ -1,12 +1,18 @@ package cl.transbank.webpay.oneclick.requests; import cl.transbank.model.WebpayApiRequest; -import com.google.gson.annotations.SerializedName; import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter @ToString +/** + * This class represents a request to delete an inscription. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString public class InscriptionDeleteRequest extends WebpayApiRequest { - private String username; - private String tbkUser; + + private String username; + private String tbkUser; } diff --git a/src/main/java/cl/transbank/webpay/oneclick/requests/InscriptionStartRequest.java b/src/main/java/cl/transbank/webpay/oneclick/requests/InscriptionStartRequest.java index abcbc183..2430fbcb 100644 --- a/src/main/java/cl/transbank/webpay/oneclick/requests/InscriptionStartRequest.java +++ b/src/main/java/cl/transbank/webpay/oneclick/requests/InscriptionStartRequest.java @@ -1,14 +1,30 @@ package cl.transbank.webpay.oneclick.requests; import cl.transbank.model.WebpayApiRequest; -import com.google.gson.annotations.SerializedName; import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter +/** + * This class represents a request to start an inscription. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter @ToString public class InscriptionStartRequest extends WebpayApiRequest { - private String username; - private String email; - private String responseUrl; + + /** + * The username for the inscription. + */ + private String username; + + /** + * The email for the inscription. + */ + private String email; + + /** + * The response URL for the inscription. + */ + private String responseUrl; } diff --git a/src/main/java/cl/transbank/webpay/oneclick/requests/MallTransactionRefundRequest.java b/src/main/java/cl/transbank/webpay/oneclick/requests/MallTransactionRefundRequest.java index 509ddf78..9fc3d2de 100644 --- a/src/main/java/cl/transbank/webpay/oneclick/requests/MallTransactionRefundRequest.java +++ b/src/main/java/cl/transbank/webpay/oneclick/requests/MallTransactionRefundRequest.java @@ -3,10 +3,17 @@ import cl.transbank.model.WebpayApiRequest; import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter @ToString +/** + * This class represents a request to refund a transaction for a mall. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString public class MallTransactionRefundRequest extends WebpayApiRequest { - private String commerceCode; - private String detailBuyOrder; - private double amount; + + private String commerceCode; + private String detailBuyOrder; + private double amount; } diff --git a/src/main/java/cl/transbank/webpay/oneclick/requests/TransactionAuthorizeRequest.java b/src/main/java/cl/transbank/webpay/oneclick/requests/TransactionAuthorizeRequest.java index c640a74b..51e863bc 100644 --- a/src/main/java/cl/transbank/webpay/oneclick/requests/TransactionAuthorizeRequest.java +++ b/src/main/java/cl/transbank/webpay/oneclick/requests/TransactionAuthorizeRequest.java @@ -2,15 +2,21 @@ import cl.transbank.model.WebpayApiRequest; import cl.transbank.webpay.oneclick.model.MallTransactionCreateDetails; -import lombok.*; - import java.util.List; +import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter @ToString +/** + * This class represents a request to authorize a transaction. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString public class TransactionAuthorizeRequest extends WebpayApiRequest { - private String username; - private String tbkUser; - private String buyOrder; - private List details; + + private String username; + private String tbkUser; + private String buyOrder; + private List details; } diff --git a/src/main/java/cl/transbank/webpay/oneclick/responses/InscriptionStartResponse.java b/src/main/java/cl/transbank/webpay/oneclick/responses/InscriptionStartResponse.java index ec0d1606..ccbf6fda 100644 --- a/src/main/java/cl/transbank/webpay/oneclick/responses/InscriptionStartResponse.java +++ b/src/main/java/cl/transbank/webpay/oneclick/responses/InscriptionStartResponse.java @@ -1,13 +1,18 @@ package cl.transbank.webpay.oneclick.responses; -import com.google.gson.annotations.SerializedName; import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter +/** + * This class represents a response to a start operation for an inscription. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter @ToString public class InscriptionStartResponse { - private String token; - private String urlWebpay; - private String errorMessage; + + private String token; + private String urlWebpay; + private String errorMessage; } diff --git a/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallInscriptionDeleteResponse.java b/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallInscriptionDeleteResponse.java index 3ac3f7df..1dcf3dfd 100644 --- a/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallInscriptionDeleteResponse.java +++ b/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallInscriptionDeleteResponse.java @@ -5,7 +5,11 @@ import lombok.Setter; import lombok.ToString; +/** + * This class represents a response to a delete operation for a OneClick Mall inscription. + */ @NoArgsConstructor -@Getter @Setter @ToString -public class OneclickMallInscriptionDeleteResponse { -} +@Getter +@Setter +@ToString +public class OneclickMallInscriptionDeleteResponse {} diff --git a/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallInscriptionFinishResponse.java b/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallInscriptionFinishResponse.java index c49b6c4c..154e378a 100644 --- a/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallInscriptionFinishResponse.java +++ b/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallInscriptionFinishResponse.java @@ -2,12 +2,19 @@ import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter @ToString +/** + * This class represents a response to a finish operation for a OneClick Mall inscription. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString public class OneclickMallInscriptionFinishResponse { - private byte responseCode; - private String tbkUser; - private String authorizationCode; - private String cardType; - private String cardNumber; + + private byte responseCode; + private String tbkUser; + private String authorizationCode; + private String cardType; + private String cardNumber; } diff --git a/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallInscriptionStartResponse.java b/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallInscriptionStartResponse.java index 1b9343b3..74e2dcde 100644 --- a/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallInscriptionStartResponse.java +++ b/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallInscriptionStartResponse.java @@ -2,9 +2,16 @@ import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter @ToString +/** + * This class represents a response to a start operation for a OneClick Mall inscription. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString public class OneclickMallInscriptionStartResponse { - private String token; - private String urlWebpay; + + private String token; + private String urlWebpay; } diff --git a/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallTransactionAuthorizeResponse.java b/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallTransactionAuthorizeResponse.java index 91968d16..ec1033bd 100644 --- a/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallTransactionAuthorizeResponse.java +++ b/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallTransactionAuthorizeResponse.java @@ -1,30 +1,43 @@ package cl.transbank.webpay.oneclick.responses; import cl.transbank.model.CardDetail; -import lombok.*; - import java.util.List; +import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter @ToString +/** + * This class represents the response from the OneclickMallTransaction authorization request. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString public class OneclickMallTransactionAuthorizeResponse { - private String transactionDate; - private String accountingDate; - private CardDetail cardDetail; - private String buyOrder; - private List details; - @NoArgsConstructor @AllArgsConstructor - @Getter @Setter @ToString - public class Detail { - private double amount; - private String status; - private String authorizationCode; - private String paymentTypeCode; - private byte installmentsNumber; - private String commerceCode; - private String buyOrder; - private byte responseCode; - private double installmentsAmount; - } + private String transactionDate; + private String accountingDate; + private CardDetail cardDetail; + private String buyOrder; + private List details; + + /** + * This class represents the details of the OneclickMallTransaction authorization response. + */ + @NoArgsConstructor + @AllArgsConstructor + @Getter + @Setter + @ToString + public class Detail { + + private double amount; + private String status; + private String authorizationCode; + private String paymentTypeCode; + private byte installmentsNumber; + private String commerceCode; + private String buyOrder; + private byte responseCode; + private double installmentsAmount; + } } diff --git a/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallTransactionCaptureResponse.java b/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallTransactionCaptureResponse.java index 18200f2b..2f8c47af 100644 --- a/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallTransactionCaptureResponse.java +++ b/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallTransactionCaptureResponse.java @@ -6,11 +6,18 @@ import lombok.Setter; import lombok.ToString; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter @ToString +/** + * This class represents a response to a capture operation for a OneClick Mall transaction. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString public class OneclickMallTransactionCaptureResponse { - private String authorizationCode; - private String authorizationDate; - private double capturedAmount; - private byte responseCode; + + private String authorizationCode; + private String authorizationDate; + private double capturedAmount; + private byte responseCode; } diff --git a/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallTransactionRefundResponse.java b/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallTransactionRefundResponse.java index 01c58ed8..9c6892cd 100644 --- a/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallTransactionRefundResponse.java +++ b/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallTransactionRefundResponse.java @@ -1,7 +1,8 @@ package cl.transbank.webpay.oneclick.responses; - import cl.transbank.model.BaseRefundResponse; -public class OneclickMallTransactionRefundResponse extends BaseRefundResponse { -} +/** + * This class represents a response to a refund operation for a OneClick Mall transaction. + */ +public class OneclickMallTransactionRefundResponse extends BaseRefundResponse {} diff --git a/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallTransactionStatusResponse.java b/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallTransactionStatusResponse.java index 12c9f2ed..97722dc4 100644 --- a/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallTransactionStatusResponse.java +++ b/src/main/java/cl/transbank/webpay/oneclick/responses/OneclickMallTransactionStatusResponse.java @@ -1,31 +1,44 @@ package cl.transbank.webpay.oneclick.responses; import cl.transbank.model.CardDetail; -import lombok.*; - import java.util.List; +import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter @ToString +/** + * This class represents the response from the transaction status request in the Oneclick Mall service. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString public class OneclickMallTransactionStatusResponse { - private String buyOrder; - private CardDetail cardDetail; - private String accountingDate; - private String transactionDate; - private List details; - @NoArgsConstructor @AllArgsConstructor - @Getter @Setter @ToString - public class Detail { - private double amount; - private String status; - private String authorizationCode; - private String paymentTypeCode; - private byte responseCode; - private byte installmentsNumber; - private String commerceCode; - private String buyOrder; - private Double balance; - private double installmentsAmount; - } + private String buyOrder; + private CardDetail cardDetail; + private String accountingDate; + private String transactionDate; + private List details; + + /** + * This class represents the details of a transaction in the Oneclick Mall service. + */ + @NoArgsConstructor + @AllArgsConstructor + @Getter + @Setter + @ToString + public class Detail { + + private double amount; + private String status; + private String authorizationCode; + private String paymentTypeCode; + private byte responseCode; + private byte installmentsNumber; + private String commerceCode; + private String buyOrder; + private Double balance; + private double installmentsAmount; + } } diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java index 65606dcc..2abc9acc 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java @@ -4,123 +4,347 @@ import cl.transbank.exception.TransbankException; import cl.transbank.model.Options; import cl.transbank.model.WebpayApiRequest; +import cl.transbank.util.HttpUtil; import cl.transbank.util.ValidationUtil; +import cl.transbank.util.WebpayApiResource; import cl.transbank.webpay.common.TransactionCaptureRequest; import cl.transbank.webpay.common.TransactionRefundRequest; -import cl.transbank.webpay.transaccioncompleta.requests.*; -import cl.transbank.webpay.transaccioncompleta.responses.*; -import cl.transbank.util.HttpUtil; -import cl.transbank.util.WebpayApiResource; import cl.transbank.webpay.common.WebpayOptions; import cl.transbank.webpay.exception.*; - +import cl.transbank.webpay.transaccioncompleta.requests.*; +import cl.transbank.webpay.transaccioncompleta.responses.*; import java.io.IOException; +/** + * Constructor with options. Uses provided options. + * @param options The options to use for this transaction. + */ public class FullTransaction extends BaseTransaction { - private static Options defaultOptions = null; + private static Options defaultOptions = null; - public FullTransaction() { - this.options = FullTransaction.defaultOptions!=null ? FullTransaction.defaultOptions : new WebpayOptions(IntegrationCommerceCodes.TRANSACCION_COMPLETA, IntegrationApiKeys.WEBPAY, IntegrationType.TEST); - } + /** + * Default constructor. Uses default options if none are provided. + */ + public FullTransaction() { + this.options = + FullTransaction.defaultOptions != null + ? FullTransaction.defaultOptions + : new WebpayOptions( + IntegrationCommerceCodes.TRANSACCION_COMPLETA, + IntegrationApiKeys.WEBPAY, + IntegrationType.TEST + ); + } - public FullTransaction(Options options) { - this.options = options; - } + /** + * Constructor with options. Uses provided options. + * @param options The options to use for this transaction. + */ + public FullTransaction(Options options) { + this.options = options; + } - public FullTransactionCreateResponse create(String buyOrder, String sessionId, double amount, short cvv, String cardNumber, String cardExpirationDate) throws IOException, TransactionCreateException { - ValidationUtil.hasTextWithMaxLength(buyOrder, ApiConstants.BUY_ORDER_LENGTH, "buyOrder"); - ValidationUtil.hasTextWithMaxLength(sessionId, ApiConstants.SESSION_ID_LENGTH, "sessionId"); - ValidationUtil.hasTextWithMaxLength(cardNumber, ApiConstants.CARD_NUMBER_LENGTH, "cardNumber"); - ValidationUtil.hasTextWithMaxLength(cardExpirationDate, ApiConstants.CARD_EXPIRATION_DATE_LENGTH, "cardExpirationDate"); - - String endpoint = String.format("%s/transactions", ApiConstants.WEBPAY_ENDPOINT); - final WebpayApiRequest request = new TransactionCreateRequest(buyOrder, sessionId, amount, cardNumber, cvv, cardExpirationDate); - try { - return WebpayApiResource.execute(endpoint, HttpUtil.RequestMethod.POST, request, options, FullTransactionCreateResponse.class); - } catch (TransbankException e) { - throw new TransactionCreateException(e); - } - } + /** + * Creates a new FullTransaction. + * @param buyOrder The buy order. + * @param sessionId The session id. + * @param amount The amount. + * @param cvv The cvv of the card. + * @param cardNumber The number of the card. + * @param cardExpirationDate The expiration date of the card. + * @return The response of the FullTransaction creation. + * @throws IOException If there's an error in the communication with the server. + * @throws TransactionCreateException If there's an error in the creation of the transaction. + */ + public FullTransactionCreateResponse create( + String buyOrder, + String sessionId, + double amount, + short cvv, + String cardNumber, + String cardExpirationDate + ) throws IOException, TransactionCreateException { + ValidationUtil.hasTextWithMaxLength( + buyOrder, + ApiConstants.BUY_ORDER_LENGTH, + "buyOrder" + ); + ValidationUtil.hasTextWithMaxLength( + sessionId, + ApiConstants.SESSION_ID_LENGTH, + "sessionId" + ); + ValidationUtil.hasTextWithMaxLength( + cardNumber, + ApiConstants.CARD_NUMBER_LENGTH, + "cardNumber" + ); + ValidationUtil.hasTextWithMaxLength( + cardExpirationDate, + ApiConstants.CARD_EXPIRATION_DATE_LENGTH, + "cardExpirationDate" + ); - public FullTransactionInstallmentResponse installments(String token, byte installmentsNumber) throws IOException, TransactionInstallmentException { - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); - String endpoint = String.format("%s/transactions/%s/installments", ApiConstants.WEBPAY_ENDPOINT, token); - final WebpayApiRequest request = new TransactionInstallmentsRequest(installmentsNumber); - try { - return WebpayApiResource.execute(endpoint, HttpUtil.RequestMethod.POST, request, options, FullTransactionInstallmentResponse.class); - } catch (TransbankException e) { - throw new TransactionInstallmentException(e); - } + String endpoint = String.format( + "%s/transactions", + ApiConstants.WEBPAY_ENDPOINT + ); + final WebpayApiRequest request = new TransactionCreateRequest( + buyOrder, + sessionId, + amount, + cardNumber, + cvv, + cardExpirationDate + ); + try { + return WebpayApiResource.execute( + endpoint, + HttpUtil.RequestMethod.POST, + request, + options, + FullTransactionCreateResponse.class + ); + } catch (TransbankException e) { + throw new TransactionCreateException(e); } + } - public FullTransactionCommitResponse commit(String token, Long idQueryInstallments, Byte deferredPeriodIndex, Boolean gracePeriod) throws IOException, TransactionCommitException { - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); - String endpoint = String.format("%s/transactions/%s", ApiConstants.WEBPAY_ENDPOINT, token); - final WebpayApiRequest request = new TransactionCommitRequest(idQueryInstallments, deferredPeriodIndex, gracePeriod); - try { - return WebpayApiResource.execute(endpoint, HttpUtil.RequestMethod.PUT, request, options, FullTransactionCommitResponse.class); - } catch (TransbankException e) { - throw new TransactionCommitException(e); - } + /** + * Starts the process of creating installments for the transaction. + * @param token The token of the transaction. + * @param installmentsNumber The number of installments. + * @return The response of the installments creation process. + */ + public FullTransactionInstallmentResponse installments( + String token, + byte installmentsNumber + ) throws IOException, TransactionInstallmentException { + ValidationUtil.hasTextWithMaxLength( + token, + ApiConstants.TOKEN_LENGTH, + "token" + ); + String endpoint = String.format( + "%s/transactions/%s/installments", + ApiConstants.WEBPAY_ENDPOINT, + token + ); + final WebpayApiRequest request = new TransactionInstallmentsRequest( + installmentsNumber + ); + try { + return WebpayApiResource.execute( + endpoint, + HttpUtil.RequestMethod.POST, + request, + options, + FullTransactionInstallmentResponse.class + ); + } catch (TransbankException e) { + throw new TransactionInstallmentException(e); } + } - public FullTransactionStatusResponse status(String token) throws IOException, TransactionStatusException { - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); - String endpoint = String.format("%s/transactions/%s", ApiConstants.WEBPAY_ENDPOINT, token); - try { - return WebpayApiResource.execute(endpoint, HttpUtil.RequestMethod.GET, options, FullTransactionStatusResponse.class); - } catch (TransbankException e) { - throw new TransactionStatusException(e); - } + /** + * Commits the transaction. + * @param token The token of the transaction. + * @return The response of the commit process. + */ + public FullTransactionCommitResponse commit( + String token, + Long idQueryInstallments, + Byte deferredPeriodIndex, + Boolean gracePeriod + ) throws IOException, TransactionCommitException { + ValidationUtil.hasTextWithMaxLength( + token, + ApiConstants.TOKEN_LENGTH, + "token" + ); + String endpoint = String.format( + "%s/transactions/%s", + ApiConstants.WEBPAY_ENDPOINT, + token + ); + final WebpayApiRequest request = new TransactionCommitRequest( + idQueryInstallments, + deferredPeriodIndex, + gracePeriod + ); + try { + return WebpayApiResource.execute( + endpoint, + HttpUtil.RequestMethod.PUT, + request, + options, + FullTransactionCommitResponse.class + ); + } catch (TransbankException e) { + throw new TransactionCommitException(e); } + } - public FullTransactionRefundResponse refund(String token, double amount) throws IOException, TransactionRefundException { - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); - String endpoint = String.format("%s/transactions/%s/refunds", ApiConstants.WEBPAY_ENDPOINT, token); - final WebpayApiRequest request = new TransactionRefundRequest(amount); - try { - return WebpayApiResource.execute(endpoint, HttpUtil.RequestMethod.POST, request, options, FullTransactionRefundResponse.class); - } catch (TransbankException e) { - throw new TransactionRefundException(e); - } + /** + * Gets the status of the transaction. + * @param token The token of the transaction. + * @return The status of the transaction. + */ + public FullTransactionStatusResponse status(String token) + throws IOException, TransactionStatusException { + ValidationUtil.hasTextWithMaxLength( + token, + ApiConstants.TOKEN_LENGTH, + "token" + ); + String endpoint = String.format( + "%s/transactions/%s", + ApiConstants.WEBPAY_ENDPOINT, + token + ); + try { + return WebpayApiResource.execute( + endpoint, + HttpUtil.RequestMethod.GET, + options, + FullTransactionStatusResponse.class + ); + } catch (TransbankException e) { + throw new TransactionStatusException(e); } + } - public FullTransactionCaptureResponse capture(String token, String buyOrder, String authorizationCode, double captureAmount) throws IOException, TransactionCaptureException { - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); - ValidationUtil.hasTextWithMaxLength(buyOrder, ApiConstants.BUY_ORDER_LENGTH, "buyOrder"); - ValidationUtil.hasTextWithMaxLength(authorizationCode, ApiConstants.AUTHORIZATION_CODE_LENGTH, "authorizationCode"); - - String endpoint = String.format("%s/transactions/%s/capture", ApiConstants.WEBPAY_ENDPOINT, token); - final WebpayApiRequest request = new TransactionCaptureRequest(buyOrder, authorizationCode, captureAmount); - try { - return WebpayApiResource.execute(endpoint, HttpUtil.RequestMethod.PUT, request, options, FullTransactionCaptureResponse.class); - } catch (TransbankException e){ - throw new TransactionCaptureException(e); - } + /** + * Starts the process of refunding the transaction. + * @param token The token of the transaction. + * @param amount The amount to be refunded. + * @return The response of the refund process. + */ + public FullTransactionRefundResponse refund(String token, double amount) + throws IOException, TransactionRefundException { + ValidationUtil.hasTextWithMaxLength( + token, + ApiConstants.TOKEN_LENGTH, + "token" + ); + String endpoint = String.format( + "%s/transactions/%s/refunds", + ApiConstants.WEBPAY_ENDPOINT, + token + ); + final WebpayApiRequest request = new TransactionRefundRequest(amount); + try { + return WebpayApiResource.execute( + endpoint, + HttpUtil.RequestMethod.POST, + request, + options, + FullTransactionRefundResponse.class + ); + } catch (TransbankException e) { + throw new TransactionRefundException(e); } + } + /** + * Captures the transaction. + * @param token The token of the transaction. + * @param buyOrder The buy order of the transaction. + * @param authorizationCode The authorization code of the transaction. + * @param captureAmount The amount to be captured. + * @return The response of the capture process. + */ + public FullTransactionCaptureResponse capture( + String token, + String buyOrder, + String authorizationCode, + double captureAmount + ) throws IOException, TransactionCaptureException { + ValidationUtil.hasTextWithMaxLength( + token, + ApiConstants.TOKEN_LENGTH, + "token" + ); + ValidationUtil.hasTextWithMaxLength( + buyOrder, + ApiConstants.BUY_ORDER_LENGTH, + "buyOrder" + ); + ValidationUtil.hasTextWithMaxLength( + authorizationCode, + ApiConstants.AUTHORIZATION_CODE_LENGTH, + "authorizationCode" + ); - /* + String endpoint = String.format( + "%s/transactions/%s/capture", + ApiConstants.WEBPAY_ENDPOINT, + token + ); + final WebpayApiRequest request = new TransactionCaptureRequest( + buyOrder, + authorizationCode, + captureAmount + ); + try { + return WebpayApiResource.execute( + endpoint, + HttpUtil.RequestMethod.PUT, + request, + options, + FullTransactionCaptureResponse.class + ); + } catch (TransbankException e) { + throw new TransactionCaptureException(e); + } + } + + /* |-------------------------------------------------------------------------- | Environment Configuration |-------------------------------------------------------------------------- */ - public static void configureForIntegration(String commerceCode, String apiKey){ - FullTransaction.defaultOptions = new WebpayOptions(commerceCode, apiKey, IntegrationType.TEST); - } + /** + * Configures the transaction for integration environment. + */ + public static void configureForIntegration( + String commerceCode, + String apiKey + ) { + FullTransaction.defaultOptions = + new WebpayOptions(commerceCode, apiKey, IntegrationType.TEST); + } - public static void configureForProduction(String commerceCode, String apiKey){ - FullTransaction.defaultOptions = new WebpayOptions(commerceCode, apiKey, IntegrationType.LIVE); - } - - public static void configureForTesting(){ - configureForIntegration(IntegrationCommerceCodes.TRANSACCION_COMPLETA, IntegrationApiKeys.WEBPAY); - } + /** + * Configures the transaction for production environment. + */ + public static void configureForProduction( + String commerceCode, + String apiKey + ) { + FullTransaction.defaultOptions = + new WebpayOptions(commerceCode, apiKey, IntegrationType.LIVE); + } - public static void configureForTestingDeferred(){ - configureForIntegration(IntegrationCommerceCodes.TRANSACCION_COMPLETA_DEFERRED, IntegrationApiKeys.WEBPAY); - } + /** + * Configures the transaction for testing environment. + */ + public static void configureForTesting() { + configureForIntegration( + IntegrationCommerceCodes.TRANSACCION_COMPLETA, + IntegrationApiKeys.WEBPAY + ); + } + /** + * Configures the transaction for testing deferred environment. + */ + public static void configureForTestingDeferred() { + configureForIntegration( + IntegrationCommerceCodes.TRANSACCION_COMPLETA_DEFERRED, + IntegrationApiKeys.WEBPAY + ); + } } diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/MallFullTransaction.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/MallFullTransaction.java index 82a6c0a5..acd8681a 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/MallFullTransaction.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/MallFullTransaction.java @@ -5,144 +5,358 @@ import cl.transbank.model.MallTransactionCreateDetails; import cl.transbank.model.Options; import cl.transbank.model.WebpayApiRequest; +import cl.transbank.util.HttpUtil; import cl.transbank.util.ValidationUtil; +import cl.transbank.util.WebpayApiResource; import cl.transbank.webpay.common.MallTransactionCaptureRequest; import cl.transbank.webpay.common.MallTransactionRefundRequest; +import cl.transbank.webpay.common.WebpayOptions; +import cl.transbank.webpay.exception.*; import cl.transbank.webpay.transaccioncompleta.model.*; import cl.transbank.webpay.transaccioncompleta.requests.*; import cl.transbank.webpay.transaccioncompleta.responses.*; -import cl.transbank.util.HttpUtil; -import cl.transbank.util.WebpayApiResource; -import cl.transbank.webpay.common.WebpayOptions; -import cl.transbank.webpay.exception.*; import java.io.IOException; +/** + * This class provides methods to configure and perform transactions with the MallFullTransaction service. + */ public class MallFullTransaction extends BaseTransaction { - private static Options defaultOptions = null; + private static Options defaultOptions = null; - public MallFullTransaction() { - this.options = MallFullTransaction.defaultOptions!=null ? MallFullTransaction.defaultOptions : new WebpayOptions(IntegrationCommerceCodes.TRANSACCION_COMPLETA_MALL, IntegrationApiKeys.WEBPAY, IntegrationType.TEST); - } + /** + * Default constructor. Uses default options if none are provided. + */ + public MallFullTransaction() { + this.options = + MallFullTransaction.defaultOptions != null + ? MallFullTransaction.defaultOptions + : new WebpayOptions( + IntegrationCommerceCodes.TRANSACCION_COMPLETA_MALL, + IntegrationApiKeys.WEBPAY, + IntegrationType.TEST + ); + } - public MallFullTransaction(Options options) { - this.options = options; - } + /** + * Constructor with options. Uses provided options. + * @param options The options to use for this transaction. + */ + public MallFullTransaction(Options options) { + this.options = options; + } - public MallFullTransactionCreateResponse create(String buyOrder, String sessionId, String cardNumber, String cardExpirationDate, MallTransactionCreateDetails details) throws IOException, TransactionCreateException { - return create(buyOrder, sessionId, cardNumber, cardExpirationDate, details, null); - } + public MallFullTransactionCreateResponse create( + String buyOrder, + String sessionId, + String cardNumber, + String cardExpirationDate, + MallTransactionCreateDetails details + ) throws IOException, TransactionCreateException { + return create( + buyOrder, + sessionId, + cardNumber, + cardExpirationDate, + details, + null + ); + } + + public MallFullTransactionCreateResponse create( + String buyOrder, + String sessionId, + String cardNumber, + String cardExpirationDate, + MallTransactionCreateDetails details, + Short cvv + ) throws IOException, TransactionCreateException { + ValidationUtil.hasTextWithMaxLength( + buyOrder, + ApiConstants.BUY_ORDER_LENGTH, + "buyOrder" + ); + ValidationUtil.hasTextWithMaxLength( + sessionId, + ApiConstants.SESSION_ID_LENGTH, + "sessionId" + ); + ValidationUtil.hasTextWithMaxLength( + cardNumber, + ApiConstants.CARD_NUMBER_LENGTH, + "cardNumber" + ); + ValidationUtil.hasTextWithMaxLength( + cardExpirationDate, + ApiConstants.CARD_EXPIRATION_DATE_LENGTH, + "cardExpirationDate" + ); + ValidationUtil.hasElements(details.getDetails(), "details"); - public MallFullTransactionCreateResponse create(String buyOrder, String sessionId, String cardNumber, String cardExpirationDate, MallTransactionCreateDetails details, Short cvv) throws IOException, TransactionCreateException { - ValidationUtil.hasTextWithMaxLength(buyOrder, ApiConstants.BUY_ORDER_LENGTH, "buyOrder"); - ValidationUtil.hasTextWithMaxLength(sessionId, ApiConstants.SESSION_ID_LENGTH, "sessionId"); - ValidationUtil.hasTextWithMaxLength(cardNumber, ApiConstants.CARD_NUMBER_LENGTH, "cardNumber"); - ValidationUtil.hasTextWithMaxLength(cardExpirationDate, ApiConstants.CARD_EXPIRATION_DATE_LENGTH, "cardExpirationDate"); - ValidationUtil.hasElements(details.getDetails(), "details"); - - for(int i=0; i detailList = new ArrayList<>(); - private MallTransactionCommitDetails() {} + private List detailList = new ArrayList<>(); - public static MallTransactionCommitDetails build() { - return new MallTransactionCommitDetails(); - } + private MallTransactionCommitDetails() {} - public static MallTransactionCommitDetails build(String commerceCode, String buyOrder,Long idQueryInstallments,Byte deferredPeriodIndex, boolean gracePeriod) { - return MallTransactionCommitDetails.build().add(commerceCode, buyOrder, idQueryInstallments, deferredPeriodIndex, gracePeriod); - } + /** + * Builds a new MallTransactionCommitDetails. + * @return A new MallTransactionCommitDetails. + */ + public static MallTransactionCommitDetails build() { + return new MallTransactionCommitDetails(); + } - public MallTransactionCommitDetails add(String commerceCode, String buyOrder, Long idQueryInstallments,Byte deferredPeriodIndex, boolean gracePeriod) { - detailList.add(new MallTransactionCommitDetails.Detail(commerceCode, buyOrder, idQueryInstallments, deferredPeriodIndex, gracePeriod)); - return this; - } + /** + * Builds a new MallTransactionCommitDetails with the provided parameters. + * @param commerceCode The commerce code. + * @param buyOrder The buy order. + * @param idQueryInstallments The id query installments. + * @param deferredPeriodIndex The deferred period index. + * @param gracePeriod The grace period. + * @return A new MallTransactionCommitDetails. + */ + public static MallTransactionCommitDetails build( + String commerceCode, + String buyOrder, + Long idQueryInstallments, + Byte deferredPeriodIndex, + boolean gracePeriod + ) { + return MallTransactionCommitDetails + .build() + .add( + commerceCode, + buyOrder, + idQueryInstallments, + deferredPeriodIndex, + gracePeriod + ); + } - public boolean remove(String commerceCode, String buyOrder, Long idQueryInstallments,Byte deferredPeriodIndex, boolean gracePeriod) { - return getDetails().remove(new MallTransactionCommitDetails.Detail(commerceCode, buyOrder, idQueryInstallments, deferredPeriodIndex, gracePeriod)); - } + /** + * Adds a new detail to the MallTransactionCommitDetails. + * @param commerceCode The commerce code. + * @param buyOrder The buy order. + * @param idQueryInstallments The id query installments. + * @param deferredPeriodIndex The deferred period index. + * @param gracePeriod The grace period. + * @return The MallTransactionCommitDetails with the new detail added. + */ + public MallTransactionCommitDetails add( + String commerceCode, + String buyOrder, + Long idQueryInstallments, + Byte deferredPeriodIndex, + boolean gracePeriod + ) { + detailList.add( + new MallTransactionCommitDetails.Detail( + commerceCode, + buyOrder, + idQueryInstallments, + deferredPeriodIndex, + gracePeriod + ) + ); + return this; + } - public List getDetails() { - return Collections.unmodifiableList(detailList); - } + /** + * Removes a detail from the MallTransactionCommitDetails. + * @param commerceCode The commerce code. + * @param buyOrder The buy order. + * @param idQueryInstallments The id query installments. + * @param deferredPeriodIndex The deferred period index. + * @param gracePeriod The grace period. + * @return True if the detail was removed, false otherwise. + */ + public boolean remove( + String commerceCode, + String buyOrder, + Long idQueryInstallments, + Byte deferredPeriodIndex, + boolean gracePeriod + ) { + return getDetails() + .remove( + new MallTransactionCommitDetails.Detail( + commerceCode, + buyOrder, + idQueryInstallments, + deferredPeriodIndex, + gracePeriod + ) + ); + } + + /** + * Gets the details of the MallTransactionCommitDetails. + * @return The details of the MallTransactionCommitDetails. + */ + public List getDetails() { + return Collections.unmodifiableList(detailList); + } - @Data - @EqualsAndHashCode(callSuper=true) - @ToString(callSuper=true) - @AllArgsConstructor - public class Detail extends TransactionCommitRequest { - private String commerceCode; - private String buyOrder; + /** + * This class represents the details of a MallTransactionCommit. + */ + @Data + @EqualsAndHashCode(callSuper = true) + @ToString(callSuper = true) + @AllArgsConstructor + public class Detail extends TransactionCommitRequest { - Detail(String commerceCode, String buyOrder,Long idQueryInstallments,Byte deferredPeriodIndex,boolean gracePeriod){ - super(idQueryInstallments, deferredPeriodIndex, gracePeriod); - this.commerceCode = commerceCode; - this.buyOrder = buyOrder; - } + private String commerceCode; + private String buyOrder; + Detail( + String commerceCode, + String buyOrder, + Long idQueryInstallments, + Byte deferredPeriodIndex, + boolean gracePeriod + ) { + super(idQueryInstallments, deferredPeriodIndex, gracePeriod); + this.commerceCode = commerceCode; + this.buyOrder = buyOrder; } + } } diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/MallFullTransactionCommitRequest.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/MallFullTransactionCommitRequest.java index 845d2c72..335a2053 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/MallFullTransactionCommitRequest.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/MallFullTransactionCommitRequest.java @@ -2,16 +2,18 @@ import cl.transbank.model.WebpayApiRequest; import cl.transbank.webpay.transaccioncompleta.model.MallTransactionCommitDetails; -import lombok.*; - import java.util.List; +import lombok.*; +/** + * This class represents a request to commit a full transaction in the mall. + */ @NoArgsConstructor @AllArgsConstructor @Data -@EqualsAndHashCode(callSuper=true) -@ToString(callSuper=true) +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) public class MallFullTransactionCommitRequest extends WebpayApiRequest { - private List details; + private List details; } diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/MallFullTransactionCreateRequest.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/MallFullTransactionCreateRequest.java index 67cd1745..6964eb4a 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/MallFullTransactionCreateRequest.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/MallFullTransactionCreateRequest.java @@ -2,20 +2,23 @@ import cl.transbank.model.MallTransactionCreateDetails; import cl.transbank.model.WebpayApiRequest; -import lombok.*; - import java.util.List; +import lombok.*; +/** + * This class represents a request to create a full transaction for a mall. + */ @NoArgsConstructor @AllArgsConstructor @Getter @Setter @ToString public class MallFullTransactionCreateRequest extends WebpayApiRequest { - private String buyOrder; - private String sessionId; - private String cardNumber; - private String cardExpirationDate; - private List details; - private Short cvv; + + private String buyOrder; + private String sessionId; + private String cardNumber; + private String cardExpirationDate; + private List details; + private Short cvv; } diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/MallFullTransactionInstallmentsRequest.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/MallFullTransactionInstallmentsRequest.java index 2bd5dfa9..bd5a6651 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/MallFullTransactionInstallmentsRequest.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/MallFullTransactionInstallmentsRequest.java @@ -3,13 +3,17 @@ import cl.transbank.model.WebpayApiRequest; import lombok.*; +/** + * This class represents a request to get the installments information for a Mall Full Transaction. + */ @NoArgsConstructor @AllArgsConstructor @Getter @Setter @ToString public class MallFullTransactionInstallmentsRequest extends WebpayApiRequest { - private String commerceCode; - private String buyOrder; - private byte installmentsNumber; + + private String commerceCode; + private String buyOrder; + private byte installmentsNumber; } diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/TransactionCommitRequest.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/TransactionCommitRequest.java index f5d62022..24cfba37 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/TransactionCommitRequest.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/TransactionCommitRequest.java @@ -3,13 +3,17 @@ import cl.transbank.model.WebpayApiRequest; import lombok.*; +/** + * This class represents a request to commit a transaction. + */ @Data -@EqualsAndHashCode(callSuper=true) -@ToString(callSuper=true) +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) @AllArgsConstructor @NoArgsConstructor public class TransactionCommitRequest extends WebpayApiRequest { - private Long idQueryInstallments; - private Byte deferredPeriodIndex; - private Boolean gracePeriod; + + private Long idQueryInstallments; + private Byte deferredPeriodIndex; + private Boolean gracePeriod; } diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/TransactionCreateRequest.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/TransactionCreateRequest.java index 5bed49e4..55457080 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/TransactionCreateRequest.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/TransactionCreateRequest.java @@ -3,14 +3,20 @@ import cl.transbank.model.WebpayApiRequest; import lombok.*; -@NoArgsConstructor @AllArgsConstructor @Getter @Setter @ToString -public -class TransactionCreateRequest extends WebpayApiRequest { - private String buyOrder; - private String sessionId; - private double amount; - private String cardNumber; - private short cvv; - private String cardExpirationDate; - +/** + * This class represents a request to create a transaction. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString +public class TransactionCreateRequest extends WebpayApiRequest { + + private String buyOrder; + private String sessionId; + private double amount; + private String cardNumber; + private short cvv; + private String cardExpirationDate; } diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/TransactionInstallmentsRequest.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/TransactionInstallmentsRequest.java index f5c00ae5..ee3d76bd 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/TransactionInstallmentsRequest.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/requests/TransactionInstallmentsRequest.java @@ -3,11 +3,15 @@ import cl.transbank.model.WebpayApiRequest; import lombok.*; +/** + * This class represents a request to get the installments information for a Transaccion Completa transaction. + */ @NoArgsConstructor @AllArgsConstructor @Getter @Setter @ToString public class TransactionInstallmentsRequest extends WebpayApiRequest { - private byte installmentsNumber; + + private byte installmentsNumber; } diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionCaptureResponse.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionCaptureResponse.java index d8ebc138..4fdd463c 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionCaptureResponse.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionCaptureResponse.java @@ -2,13 +2,18 @@ import lombok.*; +/** + * This class represents a response to a capture operation for a full transaction. + */ @NoArgsConstructor @AllArgsConstructor -@Getter @Setter +@Getter +@Setter @ToString public class FullTransactionCaptureResponse { - private String authorizationCode; - private String authorizationDate; - private double capturedAmount; - private byte responseCode; + + private String authorizationCode; + private String authorizationDate; + private double capturedAmount; + private byte responseCode; } diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionCommitResponse.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionCommitResponse.java index b677903c..1e609cbf 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionCommitResponse.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionCommitResponse.java @@ -1,6 +1,7 @@ package cl.transbank.webpay.transaccioncompleta.responses; -public class FullTransactionCommitResponse extends FullTransactionStatusResponse { - -} - +/** + * This class represents a response to a commit operation for a Full transaction. + */ +public class FullTransactionCommitResponse + extends FullTransactionStatusResponse {} diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionCreateResponse.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionCreateResponse.java index 1c13e124..74bdf180 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionCreateResponse.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionCreateResponse.java @@ -2,11 +2,15 @@ import lombok.*; +/** + * This class represents a response to a create operation for a Full Transaction. + */ @NoArgsConstructor @AllArgsConstructor @Getter @Setter @ToString public class FullTransactionCreateResponse { - private String token; + + private String token; } diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionInstallmentResponse.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionInstallmentResponse.java index 90017269..1db8419b 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionInstallmentResponse.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionInstallmentResponse.java @@ -1,23 +1,33 @@ package cl.transbank.webpay.transaccioncompleta.responses; -import lombok.*; - import java.util.List; +import lombok.*; +/** + * This class represents the details of the OneclickMallTransaction authorization response. + */ @NoArgsConstructor @AllArgsConstructor @Getter @Setter @ToString public class FullTransactionInstallmentResponse { - private double installmentsAmount; - private Long idQueryInstallments; - private List deferredPeriods; - @NoArgsConstructor @AllArgsConstructor - @Getter @Setter @ToString - public class DeferredPeriod { - private double amount; - private byte period; - } + private double installmentsAmount; + private Long idQueryInstallments; + private List deferredPeriods; + + /** + * This class represents the details of the FullTransaction installment response. + */ + @NoArgsConstructor + @AllArgsConstructor + @Getter + @Setter + @ToString + public class DeferredPeriod { + + private double amount; + private byte period; + } } diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionRefundResponse.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionRefundResponse.java index a8edbde3..9bbf8adc 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionRefundResponse.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionRefundResponse.java @@ -2,17 +2,21 @@ import lombok.*; +/** + * This class represents the response of a refund operation in a Full Transaction. + */ @NoArgsConstructor @AllArgsConstructor @Getter @Setter @ToString public class FullTransactionRefundResponse { - private String type; - private String authorizationCode; - private String authorizationDate; - private double nullifiedAmount; - private double balance; - private byte responseCode; - private Double prepaidBalance; + + private String type; + private String authorizationCode; + private String authorizationDate; + private double nullifiedAmount; + private double balance; + private byte responseCode; + private Double prepaidBalance; } diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionStatusResponse.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionStatusResponse.java index 4603090b..98be90e7 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionStatusResponse.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/FullTransactionStatusResponse.java @@ -3,26 +3,30 @@ import cl.transbank.model.CardDetail; import lombok.*; +/** + * This class represents the status response of a full transaction. + */ @NoArgsConstructor @AllArgsConstructor @Getter @Setter @ToString public class FullTransactionStatusResponse { - private String vci; - private double amount; - private String status; - private String buyOrder; - private String sessionId; - private String cardNumber; - private String accountingDate; - private String transactionDate; - private String authorizationCode; - private String paymentTypeCode; - private byte responseCode; - private byte installmentsNumber; - private double installmentsAmount; - private String balance; - private Double prepaidBalance; - private CardDetail cardDetail; + + private String vci; + private double amount; + private String status; + private String buyOrder; + private String sessionId; + private String cardNumber; + private String accountingDate; + private String transactionDate; + private String authorizationCode; + private String paymentTypeCode; + private byte responseCode; + private byte installmentsNumber; + private double installmentsAmount; + private String balance; + private Double prepaidBalance; + private CardDetail cardDetail; } diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionCaptureResponse.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionCaptureResponse.java index 673f9aec..0fba1d3e 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionCaptureResponse.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionCaptureResponse.java @@ -1,4 +1,7 @@ package cl.transbank.webpay.transaccioncompleta.responses; -public class MallFullTransactionCaptureResponse extends FullTransactionCaptureResponse{ -} +/** + * This class represents a response to a capture operation for a Mall Full transaction. + */ +public class MallFullTransactionCaptureResponse + extends FullTransactionCaptureResponse {} diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionCommitResponse.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionCommitResponse.java index 03ae5a19..ad3c8190 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionCommitResponse.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionCommitResponse.java @@ -1,6 +1,7 @@ package cl.transbank.webpay.transaccioncompleta.responses; -public class MallFullTransactionCommitResponse extends MallFullTransactionStatusResponse { - -} - +/** + * This class represents a response to a commit request for a mall full transaction. + */ +public class MallFullTransactionCommitResponse + extends MallFullTransactionStatusResponse {} diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionCreateResponse.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionCreateResponse.java index d01d5941..0f478039 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionCreateResponse.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionCreateResponse.java @@ -1,4 +1,7 @@ package cl.transbank.webpay.transaccioncompleta.responses; -public class MallFullTransactionCreateResponse extends FullTransactionCreateResponse { -} +/** + * This class represents the response of a refund operation in a Full Transaction. + */ +public class MallFullTransactionCreateResponse + extends FullTransactionCreateResponse {} diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionInstallmentResponse.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionInstallmentResponse.java index 4d982ab8..1ff21528 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionInstallmentResponse.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionInstallmentResponse.java @@ -1,12 +1,26 @@ package cl.transbank.webpay.transaccioncompleta.responses; -import lombok.NoArgsConstructor; - import java.util.List; +import lombok.NoArgsConstructor; +/** + * This class represents the response of an installment operation in a Mall Full Transaction. + */ @NoArgsConstructor -public class MallFullTransactionInstallmentResponse extends FullTransactionInstallmentResponse { - MallFullTransactionInstallmentResponse(double installmentsAmount, Long idQueryInstallments, List deferredPeriods){ - super(installmentsAmount, idQueryInstallments, deferredPeriods); - } +public class MallFullTransactionInstallmentResponse + extends FullTransactionInstallmentResponse { + + /** + * Constructs a new MallFullTransactionInstallmentResponse with the specified parameters. + * @param installmentsAmount The amount of the installments. + * @param idQueryInstallments The ID of the query installments. + * @param deferredPeriods The list of deferred periods. + */ + MallFullTransactionInstallmentResponse( + double installmentsAmount, + Long idQueryInstallments, + List deferredPeriods + ) { + super(installmentsAmount, idQueryInstallments, deferredPeriods); + } } diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionInstallmentsDetails.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionInstallmentsDetails.java index deeeb03d..ae005f86 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionInstallmentsDetails.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionInstallmentsDetails.java @@ -1,41 +1,112 @@ package cl.transbank.webpay.transaccioncompleta.responses; import cl.transbank.webpay.transaccioncompleta.requests.MallFullTransactionInstallmentsRequest; - import java.util.ArrayList; import java.util.Collections; import java.util.List; +/** + * This class represents the details of a MallFullTransactionInstallments. + */ public class MallFullTransactionInstallmentsDetails { - private List detailList = new ArrayList<>(); - private MallFullTransactionInstallmentsDetails() {} + private List detailList = new ArrayList<>(); - public static MallFullTransactionInstallmentsDetails build() { - return new MallFullTransactionInstallmentsDetails(); - } + /** + * Private constructor. Prevents direct instantiation. + */ + private MallFullTransactionInstallmentsDetails() {} - public static MallFullTransactionInstallmentsDetails build(String commerceCode, String buyOrder,byte installmentsNumber) { - return MallFullTransactionInstallmentsDetails.build().add(commerceCode, buyOrder, installmentsNumber); - } + /** + * Builds a new MallFullTransactionInstallmentsDetails. + * @return A new MallFullTransactionInstallmentsDetails. + */ + public static MallFullTransactionInstallmentsDetails build() { + return new MallFullTransactionInstallmentsDetails(); + } - public MallFullTransactionInstallmentsDetails add(String commerceCode, String buyOrder,byte installmentsNumber) { - detailList.add(new MallFullTransactionInstallmentsDetails.Detail(commerceCode, buyOrder, installmentsNumber)); - return this; - } + /** + * Builds a new MallFullTransactionInstallmentsDetails with the provided parameters. + * @param commerceCode The commerce code. + * @param buyOrder The buy order. + * @param installmentsNumber The number of installments. + * @return A new MallFullTransactionInstallmentsDetails. + */ + public static MallFullTransactionInstallmentsDetails build( + String commerceCode, + String buyOrder, + byte installmentsNumber + ) { + return MallFullTransactionInstallmentsDetails + .build() + .add(commerceCode, buyOrder, installmentsNumber); + } - public boolean remove(String commerceCode, String buyOrder,byte installmentsNumber) { - return getDetails().remove(new MallFullTransactionInstallmentsDetails.Detail(commerceCode, buyOrder, installmentsNumber)); - } + /** + * Adds a new detail to the MallFullTransactionInstallmentsDetails. + * @param commerceCode The commerce code. + * @param buyOrder The buy order. + * @param installmentsNumber The number of installments. + * @return The MallFullTransactionInstallmentsDetails with the new detail added. + */ + public MallFullTransactionInstallmentsDetails add( + String commerceCode, + String buyOrder, + byte installmentsNumber + ) { + detailList.add( + new MallFullTransactionInstallmentsDetails.Detail( + commerceCode, + buyOrder, + installmentsNumber + ) + ); + return this; + } - public List getDetails() { - return Collections.unmodifiableList(detailList); - } + /** + * Removes a detail from the MallFullTransactionInstallmentsDetails. + * @param commerceCode The commerce code. + * @param buyOrder The buy order. + * @param installmentsNumber The number of installments. + * @return True if the detail was removed, false otherwise. + */ + public boolean remove( + String commerceCode, + String buyOrder, + byte installmentsNumber + ) { + return getDetails() + .remove( + new MallFullTransactionInstallmentsDetails.Detail( + commerceCode, + buyOrder, + installmentsNumber + ) + ); + } + + /** + * Gets the details of the MallFullTransactionInstallmentsDetails. + * @return The details of the MallFullTransactionInstallmentsDetails. + */ + public List getDetails() { + return Collections.unmodifiableList(detailList); + } + /** + * This class represents the detail of a MallFullTransactionInstallments. + */ + public class Detail extends MallFullTransactionInstallmentsRequest { - public class Detail extends MallFullTransactionInstallmentsRequest { - Detail(String commerceCode, String buyOrder,byte installmentsNumber){ - super(commerceCode, buyOrder, installmentsNumber); - } + /** + * Constructor with parameters. + * @param commerceCode The commerce code. + * @param buyOrder The buy order. + * @param installmentsNumber The number of installments. + */ + Detail(String commerceCode, String buyOrder, byte installmentsNumber) { + super(commerceCode, buyOrder, installmentsNumber); } + } } diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionInstallmentsResponse.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionInstallmentsResponse.java index e73ab0be..9554ed49 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionInstallmentsResponse.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionInstallmentsResponse.java @@ -4,31 +4,52 @@ import java.util.Collections; import java.util.List; - +/** + * This class represents a response to an installments operation for a Mall Full transaction. + */ public class MallFullTransactionInstallmentsResponse { - private List responseList = new ArrayList<>(); - - private MallFullTransactionInstallmentsResponse() {} - - public static MallFullTransactionInstallmentsResponse build() { - return new MallFullTransactionInstallmentsResponse(); - } - - public static MallFullTransactionInstallmentsResponse build(MallFullTransactionInstallmentResponse response) { - return MallFullTransactionInstallmentsResponse.build().add(response); - } - - public MallFullTransactionInstallmentsResponse add(MallFullTransactionInstallmentResponse response) { - responseList.add(response); - return this; - } - - public boolean remove(MallFullTransactionInstallmentResponse response) { - return getResponseList().remove(response); - } - - public List getResponseList() { - return Collections.unmodifiableList(responseList); - } + private List responseList = new ArrayList<>(); + + private MallFullTransactionInstallmentsResponse() {} + + /** + * Builds a new MallFullTransactionInstallmentsResponse. + */ + public static MallFullTransactionInstallmentsResponse build() { + return new MallFullTransactionInstallmentsResponse(); + } + + /** + * Builds a new MallFullTransactionInstallmentsResponse with the provided list of responses. + */ + public static MallFullTransactionInstallmentsResponse build( + MallFullTransactionInstallmentResponse response + ) { + return MallFullTransactionInstallmentsResponse.build().add(response); + } + + /** + * Adds a new item to the response list. + */ + public MallFullTransactionInstallmentsResponse add( + MallFullTransactionInstallmentResponse response + ) { + responseList.add(response); + return this; + } + + /** + * Removes an item from the response list. + */ + public boolean remove(MallFullTransactionInstallmentResponse response) { + return getResponseList().remove(response); + } + + /** + * Returns the response list. + */ + public List getResponseList() { + return Collections.unmodifiableList(responseList); + } } diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionRefundResponse.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionRefundResponse.java index 654cdf90..7df2958b 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionRefundResponse.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionRefundResponse.java @@ -1,4 +1,7 @@ package cl.transbank.webpay.transaccioncompleta.responses; -public class MallFullTransactionRefundResponse extends FullTransactionRefundResponse { -} +/** + * This class represents the response of a refund operation in a Mall Full Transaction. + */ +public class MallFullTransactionRefundResponse + extends FullTransactionRefundResponse {} diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionStatusResponse.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionStatusResponse.java index 8bea1286..23b983b4 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionStatusResponse.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionStatusResponse.java @@ -1,38 +1,46 @@ package cl.transbank.webpay.transaccioncompleta.responses; import cl.transbank.model.CardDetail; -import lombok.*; - import java.util.List; +import lombok.*; +/** + * This class represents the response from the MallFullTransaction status request. + */ @NoArgsConstructor @AllArgsConstructor @Getter @Setter @ToString public class MallFullTransactionStatusResponse { - private String buyOrder; - private String sessionId; - private String cardNumber; - private String expirationDate; - private String accountingDate; - private String transactionDate; - private List details; - private Double prepaidBalance; - private CardDetail cardDetail; - @NoArgsConstructor @AllArgsConstructor - @Data - public class Detail { - private String authorizationCode; - private String paymentTypeCode; - private byte responseCode; - private double installmentsAmount; - private byte installmentsNumber; - private double amount; - private String commerceCode; - private String buyOrder; - private String status; - private double balance; - } + private String buyOrder; + private String sessionId; + private String cardNumber; + private String expirationDate; + private String accountingDate; + private String transactionDate; + private List details; + private Double prepaidBalance; + private CardDetail cardDetail; + + /** + * This class represents the details of the MallFullTransaction status response. + */ + @NoArgsConstructor + @AllArgsConstructor + @Data + public class Detail { + + private String authorizationCode; + private String paymentTypeCode; + private byte responseCode; + private double installmentsAmount; + private byte installmentsNumber; + private double amount; + private String commerceCode; + private String buyOrder; + private String status; + private double balance; + } } diff --git a/src/main/java/cl/transbank/webpay/webpayplus/WebpayPlus.java b/src/main/java/cl/transbank/webpay/webpayplus/WebpayPlus.java index 8f2f7fd9..d6769bd1 100644 --- a/src/main/java/cl/transbank/webpay/webpayplus/WebpayPlus.java +++ b/src/main/java/cl/transbank/webpay/webpayplus/WebpayPlus.java @@ -6,28 +6,72 @@ import cl.transbank.model.Options; import cl.transbank.webpay.common.WebpayOptions; +/** + * This class provides methods to configure and perform transactions with the WebpayPlus service. + */ public class WebpayPlus { - private static Options options; - - public static class Transaction extends WebpayTransaction { - public Transaction() { - super(WebpayPlus.options!=null ? WebpayPlus.options : new WebpayOptions(IntegrationCommerceCodes.WEBPAY_PLUS, IntegrationApiKeys.WEBPAY, IntegrationType.TEST)); - } - public Transaction(Options options) { - super(options); - } + + private static Options options; + + /** + * This class provides methods to perform WebpayPlus Transactions. + */ + public static class Transaction extends WebpayTransaction { + + /** + * Default constructor. Uses default options if none are provided. + */ + public Transaction() { + super( + WebpayPlus.options != null + ? WebpayPlus.options + : new WebpayOptions( + IntegrationCommerceCodes.WEBPAY_PLUS, + IntegrationApiKeys.WEBPAY, + IntegrationType.TEST + ) + ); + } + + /** + * Constructor with options. Uses provided options. + * @param options The options to use for this transaction. + */ + public Transaction(Options options) { + super(options); + } + } + + /** + * This class provides methods to perform WebpayPlus Mall Transactions. + */ + public static class MallTransaction extends WebpayMallTransaction { + + /** + * Default constructor. Uses default options if none are provided. + */ + public MallTransaction() { + super( + WebpayPlus.options != null + ? WebpayPlus.options + : new WebpayOptions( + IntegrationCommerceCodes.WEBPAY_PLUS_MALL, + IntegrationApiKeys.WEBPAY, + IntegrationType.TEST + ) + ); } - public static class MallTransaction extends WebpayMallTransaction { - public MallTransaction() { - super(WebpayPlus.options!=null ? WebpayPlus.options : new WebpayOptions(IntegrationCommerceCodes.WEBPAY_PLUS_MALL, IntegrationApiKeys.WEBPAY, IntegrationType.TEST)); - } - public MallTransaction(Options options) { - super(options); - } + /** + * Constructor with options. Uses provided options. + * @param options The options to use for this transaction. + */ + public MallTransaction(Options options) { + super(options); } + } - /* + /* @@ -36,31 +80,54 @@ public MallTransaction(Options options) { |-------------------------------------------------------------------------- */ - public static void configureForIntegration(String commerceCode, String apiKey){ - options = new WebpayOptions(commerceCode, apiKey, IntegrationType.TEST); - } + public static void configureForIntegration( + String commerceCode, + String apiKey + ) { + options = new WebpayOptions(commerceCode, apiKey, IntegrationType.TEST); + } - public static void configureForProduction(String commerceCode, String apiKey){ - options = new WebpayOptions(commerceCode, apiKey, IntegrationType.LIVE); - } + public static void configureForProduction( + String commerceCode, + String apiKey + ) { + options = new WebpayOptions(commerceCode, apiKey, IntegrationType.LIVE); + } - public static void configureForTesting(){ - configureForIntegration(IntegrationCommerceCodes.WEBPAY_PLUS, IntegrationApiKeys.WEBPAY); - } + public static void configureForTesting() { + configureForIntegration( + IntegrationCommerceCodes.WEBPAY_PLUS, + IntegrationApiKeys.WEBPAY + ); + } - public static void configureForTestingDeferred(){ - configureForIntegration(IntegrationCommerceCodes.WEBPAY_PLUS_DEFERRED, IntegrationApiKeys.WEBPAY); - } + public static void configureForTestingDeferred() { + configureForIntegration( + IntegrationCommerceCodes.WEBPAY_PLUS_DEFERRED, + IntegrationApiKeys.WEBPAY + ); + } - public static void configureForTestingMall(){ - configureForIntegration(IntegrationCommerceCodes.WEBPAY_PLUS_MALL, IntegrationApiKeys.WEBPAY); - } + public static void configureForTestingMall() { + configureForIntegration( + IntegrationCommerceCodes.WEBPAY_PLUS_MALL, + IntegrationApiKeys.WEBPAY + ); + } - public static void configureForTestingMallDeferred(){ - configureForIntegration(IntegrationCommerceCodes.WEBPAY_PLUS_MALL_DEFERRED, IntegrationApiKeys.WEBPAY); - } + public static void configureForTestingMallDeferred() { + configureForIntegration( + IntegrationCommerceCodes.WEBPAY_PLUS_MALL_DEFERRED, + IntegrationApiKeys.WEBPAY + ); + } - public static void configureForMock(){ - options = new WebpayOptions(IntegrationCommerceCodes.WEBPAY_PLUS, IntegrationApiKeys.WEBPAY, IntegrationType.SERVER_MOCK); - } -} \ No newline at end of file + public static void configureForMock() { + options = + new WebpayOptions( + IntegrationCommerceCodes.WEBPAY_PLUS, + IntegrationApiKeys.WEBPAY, + IntegrationType.SERVER_MOCK + ); + } +} diff --git a/src/main/java/cl/transbank/webpay/webpayplus/requests/MallTransactionCreateRequest.java b/src/main/java/cl/transbank/webpay/webpayplus/requests/MallTransactionCreateRequest.java index 3fa63eba..aaf90548 100644 --- a/src/main/java/cl/transbank/webpay/webpayplus/requests/MallTransactionCreateRequest.java +++ b/src/main/java/cl/transbank/webpay/webpayplus/requests/MallTransactionCreateRequest.java @@ -2,16 +2,21 @@ import cl.transbank.model.MallTransactionCreateDetails; import cl.transbank.model.WebpayApiRequest; -import lombok.*; - import java.util.List; +import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter +/** + * This class represents a request to create a Mall Transaction. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter @ToString public class MallTransactionCreateRequest extends WebpayApiRequest { - private String buyOrder; - private String sessionId; - private String returnUrl; - private List details; + + private String buyOrder; + private String sessionId; + private String returnUrl; + private List details; } diff --git a/src/main/java/cl/transbank/webpay/webpayplus/requests/TransactionCreateRequest.java b/src/main/java/cl/transbank/webpay/webpayplus/requests/TransactionCreateRequest.java index ab2e0fd5..f119181c 100644 --- a/src/main/java/cl/transbank/webpay/webpayplus/requests/TransactionCreateRequest.java +++ b/src/main/java/cl/transbank/webpay/webpayplus/requests/TransactionCreateRequest.java @@ -3,12 +3,33 @@ import cl.transbank.model.WebpayApiRequest; import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter +/** + * This class represents a request to create a transaction. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter @ToString public class TransactionCreateRequest extends WebpayApiRequest { - private String buyOrder; - private String sessionId; - private double amount; - private String returnUrl; + + /** + * The buy order of the transaction. + */ + private String buyOrder; + + /** + * The session ID of the transaction. + */ + private String sessionId; + + /** + * The amount of the transaction. + */ + private double amount; + + /** + * The return URL of the transaction. + */ + private String returnUrl; } diff --git a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionCaptureResponse.java b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionCaptureResponse.java index 6dc32b9f..f74017c7 100644 --- a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionCaptureResponse.java +++ b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionCaptureResponse.java @@ -1,5 +1,7 @@ package cl.transbank.webpay.webpayplus.responses; -public class WebpayPlusMallTransactionCaptureResponse extends WebpayPlusTransactionCaptureResponse { - -} +/** + * This class represents a response to a capture operation for a Webpay Plus Mall transaction. + */ +public class WebpayPlusMallTransactionCaptureResponse + extends WebpayPlusTransactionCaptureResponse {} diff --git a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionCommitResponse.java b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionCommitResponse.java index 821a2637..1b4cf022 100644 --- a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionCommitResponse.java +++ b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionCommitResponse.java @@ -1,7 +1,7 @@ package cl.transbank.webpay.webpayplus.responses; -public class WebpayPlusMallTransactionCommitResponse extends WebpayPlusMallTransactionStatusResponse { - -} - - +/** + * This class represents a response to a commit operation for a Webpay Plus Mall transaction. + */ +public class WebpayPlusMallTransactionCommitResponse + extends WebpayPlusMallTransactionStatusResponse {} diff --git a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionCreateResponse.java b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionCreateResponse.java index daad1771..3469b9cc 100644 --- a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionCreateResponse.java +++ b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionCreateResponse.java @@ -1,5 +1,7 @@ package cl.transbank.webpay.webpayplus.responses; -public class WebpayPlusMallTransactionCreateResponse extends WebpayPlusTransactionCreateResponse { - -} +/** + * This class represents a response to a create operation for a Webpay Plus Mall transaction. + */ +public class WebpayPlusMallTransactionCreateResponse + extends WebpayPlusTransactionCreateResponse {} diff --git a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionRefundResponse.java b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionRefundResponse.java index 3a446e7d..779e886a 100644 --- a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionRefundResponse.java +++ b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionRefundResponse.java @@ -1,4 +1,7 @@ package cl.transbank.webpay.webpayplus.responses; -public class WebpayPlusMallTransactionRefundResponse extends WebpayPlusTransactionRefundResponse { -} +/** + * This class represents a response to a refund operation for a Webpay Plus Mall transaction. + */ +public class WebpayPlusMallTransactionRefundResponse + extends WebpayPlusTransactionRefundResponse {} diff --git a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionStatusResponse.java b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionStatusResponse.java index e5c42712..3abae08e 100644 --- a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionStatusResponse.java +++ b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusMallTransactionStatusResponse.java @@ -1,34 +1,47 @@ package cl.transbank.webpay.webpayplus.responses; import cl.transbank.model.CardDetail; -import lombok.*; - import java.util.List; +import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter @ToString +/** + * This class represents the response of a WebpayPlusMallTransactionStatus. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter +@ToString public class WebpayPlusMallTransactionStatusResponse { - private String vci; - private String buyOrder; - private String sessionId; - private CardDetail cardDetail; - private String accountingDate; - private String transactionDate; - private List details; - @NoArgsConstructor @AllArgsConstructor - @Getter @Setter @ToString - public class Detail { - private double amount; - private String status; - private String authorizationCode; - private String paymentTypeCode; - private byte responseCode; - private double installmentsAmount; - private byte installmentsNumber; - private String commerceCode; - private String buyOrder; - private Double prepaidBalance; - private Double balance; - } + private String vci; + private String buyOrder; + private String sessionId; + private CardDetail cardDetail; + private String accountingDate; + private String transactionDate; + private List details; + + /** + * This class represents the detail of a WebpayPlusMallTransactionStatus. + */ + @NoArgsConstructor + @AllArgsConstructor + @Getter + @Setter + @ToString + public class Detail { + + private double amount; + private String status; + private String authorizationCode; + private String paymentTypeCode; + private byte responseCode; + private double installmentsAmount; + private byte installmentsNumber; + private String commerceCode; + private String buyOrder; + private Double prepaidBalance; + private Double balance; + } } diff --git a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionCaptureResponse.java b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionCaptureResponse.java index 8f749703..5aae0df4 100644 --- a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionCaptureResponse.java +++ b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionCaptureResponse.java @@ -2,12 +2,18 @@ import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter +/** + * This class represents a response to a capture operation for a Webpay Plus transaction. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter @ToString public class WebpayPlusTransactionCaptureResponse { - private String authorizationCode; - private String authorizationDate; - private double capturedAmount; - private byte responseCode; + + private String authorizationCode; + private String authorizationDate; + private double capturedAmount; + private byte responseCode; } diff --git a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionCommitResponse.java b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionCommitResponse.java index 1c9a4f84..bcbbf679 100644 --- a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionCommitResponse.java +++ b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionCommitResponse.java @@ -1,5 +1,7 @@ package cl.transbank.webpay.webpayplus.responses; -public class WebpayPlusTransactionCommitResponse extends WebpayPlusTransactionStatusResponse { - -} +/** + * This class represents a response to a commit operation for a Webpay Plus transaction. + */ +public class WebpayPlusTransactionCommitResponse + extends WebpayPlusTransactionStatusResponse {} diff --git a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionCreateResponse.java b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionCreateResponse.java index 9ecde1dd..c6f76e01 100644 --- a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionCreateResponse.java +++ b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionCreateResponse.java @@ -2,10 +2,16 @@ import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter +/** + * This class represents a response to a create operation for a Webpay Plus transaction. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter @ToString public class WebpayPlusTransactionCreateResponse { - private String token; - private String url; + + private String token; + private String url; } diff --git a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionRefundResponse.java b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionRefundResponse.java index ec303c16..fe7b0527 100644 --- a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionRefundResponse.java +++ b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionRefundResponse.java @@ -2,5 +2,7 @@ import cl.transbank.model.BaseRefundResponse; -public class WebpayPlusTransactionRefundResponse extends BaseRefundResponse { -} +/** + * This class represents a response to a refund operation for a Webpay Plus transaction. + */ +public class WebpayPlusTransactionRefundResponse extends BaseRefundResponse {} diff --git a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionStatusResponse.java b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionStatusResponse.java index 519489fe..b05455d4 100644 --- a/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionStatusResponse.java +++ b/src/main/java/cl/transbank/webpay/webpayplus/responses/WebpayPlusTransactionStatusResponse.java @@ -1,25 +1,30 @@ package cl.transbank.webpay.webpayplus.responses; import cl.transbank.model.CardDetail; -import com.google.gson.annotations.SerializedName; import lombok.*; -@NoArgsConstructor @AllArgsConstructor -@Getter @Setter +/** + * This class represents the status response of a Webpay Plus Transaction. + */ +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Setter @ToString public class WebpayPlusTransactionStatusResponse { - private String vci; - private double amount; - private String status; - private String buyOrder; - private String sessionId; - private CardDetail cardDetail; - private String accountingDate; - private String transactionDate; - private String authorizationCode; - private String paymentTypeCode; - private byte responseCode; - private double installmentsAmount; - private byte installmentsNumber; - private double balance; -} \ No newline at end of file + + private String vci; + private double amount; + private String status; + private String buyOrder; + private String sessionId; + private CardDetail cardDetail; + private String accountingDate; + private String transactionDate; + private String authorizationCode; + private String paymentTypeCode; + private byte responseCode; + private double installmentsAmount; + private byte installmentsNumber; + private double balance; +} From 5b3ca75496daa553a25b905fa6d098d595f47097 Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Wed, 13 Mar 2024 09:13:53 -0400 Subject: [PATCH 02/26] docs: add missing javadocs --- .../model/MallTransactionCreateDetails.java | 138 +++-- .../java/cl/transbank/util/HttpUtilImpl.java | 512 +++++++++++------- .../model/MallTransactionCreateDetails.java | 134 +++-- 3 files changed, 520 insertions(+), 264 deletions(-) diff --git a/src/main/java/cl/transbank/model/MallTransactionCreateDetails.java b/src/main/java/cl/transbank/model/MallTransactionCreateDetails.java index 80e15b2a..75158ae1 100644 --- a/src/main/java/cl/transbank/model/MallTransactionCreateDetails.java +++ b/src/main/java/cl/transbank/model/MallTransactionCreateDetails.java @@ -1,53 +1,117 @@ package cl.transbank.model; -import lombok.*; - import java.util.ArrayList; import java.util.Collections; import java.util.List; +import lombok.*; +/** + * This class represents the details of the FullTransaction installment response. + */ public class MallTransactionCreateDetails { - private List detailList = new ArrayList<>(); - private MallTransactionCreateDetails() {} + private List detailList = new ArrayList<>(); - public static MallTransactionCreateDetails build() { - return new MallTransactionCreateDetails(); - } + /** + * This class represents the details of the FullTransaction installment response. + */ + private MallTransactionCreateDetails() {} - public static MallTransactionCreateDetails build(double amount, String commerceCode, String buyOrder) { - return MallTransactionCreateDetails.build().add(amount, commerceCode, buyOrder); - } + /** + * Builds a new MallTransactionCreateDetails instance. + * @return A new MallTransactionCreateDetails instance. + */ + public static MallTransactionCreateDetails build() { + return new MallTransactionCreateDetails(); + } - public MallTransactionCreateDetails add(double amount, String commerceCode, String buyOrder) { - detailList.add(new MallTransactionCreateDetails.Detail(amount, commerceCode, buyOrder)); - return this; - } + /** + * Builds a new MallTransactionCreateDetails instance and adds the provided detail. + * @param amount The amount of the transaction. + * @param commerceCode The commerce code. + * @param buyOrder The buy order. + * @return A new MallTransactionCreateDetails instance with the provided detail added. + */ + public static MallTransactionCreateDetails build( + double amount, + String commerceCode, + String buyOrder + ) { + return MallTransactionCreateDetails + .build() + .add(amount, commerceCode, buyOrder); + } - public boolean remove(double amount, String commerceCode, String buyOrder) { - return getDetails().remove(new MallTransactionCreateDetails.Detail(amount, commerceCode, buyOrder)); - } + /** + * Adds a new detail to this MallTransactionCreateDetails. + * @param amount The amount of the transaction. + * @param commerceCode The commerce code. + * @param buyOrder The buy order. + * @return This MallTransactionCreateDetails instance. + */ + public MallTransactionCreateDetails add( + double amount, + String commerceCode, + String buyOrder + ) { + detailList.add( + new MallTransactionCreateDetails.Detail(amount, commerceCode, buyOrder) + ); + return this; + } - public List getDetails() { - return Collections.unmodifiableList(detailList); - } + /** + * Removes a detail from this MallTransactionCreateDetails. + * @param amount The amount of the transaction. + * @param commerceCode The commerce code. + * @param buyOrder The buy order. + * @return True if the detail was removed, false otherwise. + */ + public boolean remove(double amount, String commerceCode, String buyOrder) { + return getDetails() + .remove( + new MallTransactionCreateDetails.Detail(amount, commerceCode, buyOrder) + ); + } + + /** + * Gets the details of this MallTransactionCreateDetails. + * @return The details of this MallTransactionCreateDetails. + */ + public List getDetails() { + return Collections.unmodifiableList(detailList); + } + + /** + * Gets the details of this MallTransactionCreateDetails. + * @return The details of this MallTransactionCreateDetails. + */ + @NoArgsConstructor + @AllArgsConstructor + @Getter + @Setter + @ToString + public class Detail { - @NoArgsConstructor @AllArgsConstructor - @Getter @Setter @ToString - public class Detail { - private double amount; - private String commerceCode; - private String buyOrder; - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof MallTransactionCreateDetails.Detail)) - return false; - - MallTransactionCreateDetails.Detail another = (MallTransactionCreateDetails.Detail) obj; - return getAmount() == another.getAmount() && getCommerceCode().equals(another.getBuyOrder()) && - getBuyOrder().equals(another.getBuyOrder()); - } + private double amount; + private String commerceCode; + private String buyOrder; + + /** + * Checks if this Detail is equal to another object. + * @param obj The object to compare with. + * @return True if the objects are equal, false otherwise. + */ + @Override + public boolean equals(Object obj) { + if (!(obj instanceof MallTransactionCreateDetails.Detail)) return false; + + MallTransactionCreateDetails.Detail another = (MallTransactionCreateDetails.Detail) obj; + return ( + getAmount() == another.getAmount() && + getCommerceCode().equals(another.getBuyOrder()) && + getBuyOrder().equals(another.getBuyOrder()) + ); } + } } - diff --git a/src/main/java/cl/transbank/util/HttpUtilImpl.java b/src/main/java/cl/transbank/util/HttpUtilImpl.java index 2bc5feda..8af2d489 100644 --- a/src/main/java/cl/transbank/util/HttpUtilImpl.java +++ b/src/main/java/cl/transbank/util/HttpUtilImpl.java @@ -1,12 +1,9 @@ package cl.transbank.util; +import static cl.transbank.util.HttpUtil.RequestMethod.*; + import cl.transbank.webpay.exception.TransbankHttpApiException; import cl.transbank.webpay.exception.WebpayException; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NonNull; -import lombok.Setter; - import java.io.*; import java.net.HttpURLConnection; import java.net.URL; @@ -17,211 +14,340 @@ import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NonNull; +import lombok.Setter; -import static cl.transbank.util.HttpUtil.RequestMethod.*; - +/** + * This class provides utility methods for HTTP requests. + */ public class HttpUtilImpl implements HttpUtil { - private static Logger logger = Logger.getLogger(HttpUtilImpl.class.getName()); - - private static volatile HttpUtilImpl instance; - - @Setter @Getter(AccessLevel.PRIVATE) private JsonUtil jsonUtil = JsonUtilImpl.getInstance(); - - public T request(@NonNull URL url, RequestMethod method, Object request, Map headers, - Class clazz) throws IOException, WebpayException { - final String jsonIn = getJsonUtil().jsonEncode(request); - final String jsonOut = request(url, method, jsonIn, headers, true); - return getJsonUtil().jsonDecode(jsonOut, clazz); - } - - public List requestList(@NonNull URL url, RequestMethod method, Object request, Map headers, - Class clazz) throws IOException, WebpayException { - final String jsonIn = getJsonUtil().jsonEncode(request); - final String jsonOut = request(url, method, jsonIn, headers, true); - return getJsonUtil().jsonDecodeToList(jsonOut, clazz); - } - - public String request(@NonNull URL url, RequestMethod method, String query) - throws IOException, WebpayException { - return request(url, method, query, (ContentType) null, (Map) null); - } - - public String request(@NonNull URL url, RequestMethod method, String query, - ContentType contentType) throws IOException, WebpayException { - return request(url, method, query, contentType, null); - } - - public String request(@NonNull URL url, RequestMethod method, String query, Map headers) - throws IOException, WebpayException { - return request(url, method, query, null, headers); - } - - public String request(@NonNull URL url, RequestMethod method, String query, Map headers, boolean useException) - throws IOException, WebpayException { - return request(url, method, query, null, headers); - } - - public String request(@NonNull URL url, RequestMethod method, String query, - ContentType contentType, Map headers) throws IOException, WebpayException { - if (null == method) - method = GET; - - if (null == contentType) - contentType = ContentType.JSON; - - HttpURLConnection conn = null; - try { - logger.log(Level.FINE, String.format("HTTP URL : %s", url)); - logger.log(Level.FINE, String.format("HTTP Method : %s", method)); - - if (null != headers) { - for (String key : headers.keySet()) { - if (!StringUtils.isEmpty(key)) { - String value = headers.get(key); - - if (key.equalsIgnoreCase("Tbk-Api-Key-Secret")) { - value = "NOT DISPLAYED BY SECURITY REASON"; - } - - logger.log(Level.FINE, String.format("HTTP Header [%s] : %s", key, value)); - } - } - } - - logger.log(Level.FINE, String.format("HTTP Request Query : %s", query)); - switch (method) { - case POST: - conn = createPOSTConnection(url, query, contentType, headers); - break; - case DELETE: - conn = createDeleteConnection(url, query, contentType, headers); - break; - case PUT: - conn = createPUTConnection(url, query, contentType, headers); - break; - case GET: - default: - conn = createGETConnection(url, query, headers); - } - - int responseCode = conn.getResponseCode(); - - logger.log(Level.FINE, String.format("HTTP Response Code : %s", responseCode)); - final boolean isHttpErrorCode = !(responseCode >= 200 && responseCode < 300); - InputStream input = !isHttpErrorCode ? - conn.getInputStream() : - conn.getErrorStream(); - - final String responseBody = getResponseBody(input); - if (isHttpErrorCode) { - Object errorMessage = "Could not obtain a response message from Webpay API"; - if (responseBody != null) { - final Map errorMap = getJsonUtil().jsonDecode(responseBody, HashMap.class); - errorMessage = errorMap.get("error_message"); - } - - if (null == errorMessage) - errorMessage = "Unspecified message by Webpay API"; - throw new TransbankHttpApiException(responseCode, errorMessage.toString()); + private static Logger logger = Logger.getLogger(HttpUtilImpl.class.getName()); + + private static volatile HttpUtilImpl instance; + + @Setter + @Getter(AccessLevel.PRIVATE) + private JsonUtil jsonUtil = JsonUtilImpl.getInstance(); + + /** + * Sends a HTTP request and returns the response. + * This method uses the provided URL, request method, request body, headers, and response type to send the request. + */ + public T request( + @NonNull URL url, + RequestMethod method, + Object request, + Map headers, + Class clazz + ) throws IOException, WebpayException { + final String jsonIn = getJsonUtil().jsonEncode(request); + final String jsonOut = request(url, method, jsonIn, headers, true); + return getJsonUtil().jsonDecode(jsonOut, clazz); + } + + public List requestList( + @NonNull URL url, + RequestMethod method, + Object request, + Map headers, + Class clazz + ) throws IOException, WebpayException { + final String jsonIn = getJsonUtil().jsonEncode(request); + final String jsonOut = request(url, method, jsonIn, headers, true); + return getJsonUtil().jsonDecodeToList(jsonOut, clazz); + } + + /** + * Sends a HTTP request and returns the response. + * This method uses the provided URL, request method, request body, and response type to send the request. + * It uses default headers. + */ + public String request(@NonNull URL url, RequestMethod method, String query) + throws IOException, WebpayException { + return request( + url, + method, + query, + (ContentType) null, + (Map) null + ); + } + + /** + * Sends a HTTP request and returns the response. + * This method uses the provided URL, request method, and response type to send the request. + * It uses default headers and does not send a request body. + */ + public String request( + @NonNull URL url, + RequestMethod method, + String query, + ContentType contentType + ) throws IOException, WebpayException { + return request(url, method, query, contentType, null); + } + + /** + * Sends a HTTP request and returns the response. + * This method uses the provided URL, request method, and response type to send the request. + * It uses default headers and a default request body. + */ + public String request( + @NonNull URL url, + RequestMethod method, + String query, + Map headers + ) throws IOException, WebpayException { + return request(url, method, query, null, headers); + } + + /** + * Sends a HTTP request and returns the response. + * This method uses the provided URL and request method to send the request. + * It uses default headers, a default response type, and does not send a request body. + */ + public String request( + @NonNull URL url, + RequestMethod method, + String query, + Map headers, + boolean useException + ) throws IOException, WebpayException { + return request(url, method, query, null, headers); + } + + /** + * Sends a HTTP request and returns the response. + * This method uses the provided URL to send the request. + * It uses a default request method, default headers, a default response type, and does not send a request body. + */ + public String request( + @NonNull URL url, + RequestMethod method, + String query, + ContentType contentType, + Map headers + ) throws IOException, WebpayException { + if (null == method) method = GET; + + if (null == contentType) contentType = ContentType.JSON; + + HttpURLConnection conn = null; + + try { + logger.log(Level.FINE, String.format("HTTP URL : %s", url)); + logger.log(Level.FINE, String.format("HTTP Method : %s", method)); + + if (null != headers) { + for (String key : headers.keySet()) { + if (!StringUtils.isEmpty(key)) { + String value = headers.get(key); + + if (key.equalsIgnoreCase("Tbk-Api-Key-Secret")) { + value = "NOT DISPLAYED BY SECURITY REASON"; } - if (responseBody != null && !responseBody.trim().startsWith("[")) { - final Map tempMap = getJsonUtil().jsonDecode(responseBody, HashMap.class); - if (tempMap.containsKey("error_message") && tempMap.get("error_message")!=null){ - throw new WebpayException(tempMap.get("error_message").toString()); - } - } - - return responseBody; - } finally { - if (null != conn) - conn.disconnect(); + logger.log( + Level.FINE, + String.format("HTTP Header [%s] : %s", key, value) + ); + } } - } - - private HttpURLConnection createPOSTConnection(URL url, String query, ContentType contentType, Map headers) - throws IOException { - return createSendingDataConnection(POST, url, query, contentType, headers); - } - - private HttpURLConnection createGETConnection(URL url, String query, Map headers) throws IOException { - String getUrl = formatUrl(url.toString(), query); - HttpURLConnection conn = (HttpURLConnection) new URL(getUrl).openConnection(); - conn.setRequestMethod(GET.toString()); - - if (null != headers) { - for (Map.Entry header : headers.entrySet()) { - conn.setRequestProperty(header.getKey(), header.getValue()); - } + } + + logger.log(Level.FINE, String.format("HTTP Request Query : %s", query)); + switch (method) { + case POST: + conn = createPOSTConnection(url, query, contentType, headers); + break; + case DELETE: + conn = createDeleteConnection(url, query, contentType, headers); + break; + case PUT: + conn = createPUTConnection(url, query, contentType, headers); + break; + case GET: + default: + conn = createGETConnection(url, query, headers); + } + + int responseCode = conn.getResponseCode(); + + logger.log( + Level.FINE, + String.format("HTTP Response Code : %s", responseCode) + ); + final boolean isHttpErrorCode = + !(responseCode >= 200 && responseCode < 300); + InputStream input = !isHttpErrorCode + ? conn.getInputStream() + : conn.getErrorStream(); + + final String responseBody = getResponseBody(input); + if (isHttpErrorCode) { + Object errorMessage = + "Could not obtain a response message from Webpay API"; + if (responseBody != null) { + final Map errorMap = getJsonUtil() + .jsonDecode(responseBody, HashMap.class); + errorMessage = errorMap.get("error_message"); } - return conn; - } + if (null == errorMessage) errorMessage = + "Unspecified message by Webpay API"; + throw new TransbankHttpApiException( + responseCode, + errorMessage.toString() + ); + } + + if (responseBody != null && !responseBody.trim().startsWith("[")) { + final Map tempMap = getJsonUtil() + .jsonDecode(responseBody, HashMap.class); + if ( + tempMap.containsKey("error_message") && + tempMap.get("error_message") != null + ) { + throw new WebpayException(tempMap.get("error_message").toString()); + } + } - private HttpURLConnection createDeleteConnection(URL url, String query, ContentType contentType, Map headers) throws IOException { - return createSendingDataConnection(DELETE, url, query, contentType, headers); + return responseBody; + } finally { + if (null != conn) conn.disconnect(); } - - private HttpURLConnection createPUTConnection( - URL url, String query, ContentType contentType, Map headers) throws IOException { - return createSendingDataConnection(PUT, url, query, contentType, headers); + } + + private HttpURLConnection createPOSTConnection( + URL url, + String query, + ContentType contentType, + Map headers + ) throws IOException { + return createSendingDataConnection(POST, url, query, contentType, headers); + } + + private HttpURLConnection createGETConnection( + URL url, + String query, + Map headers + ) throws IOException { + String getUrl = formatUrl(url.toString(), query); + HttpURLConnection conn = (HttpURLConnection) new URL(getUrl) + .openConnection(); + conn.setRequestMethod(GET.toString()); + + if (null != headers) { + for (Map.Entry header : headers.entrySet()) { + conn.setRequestProperty(header.getKey(), header.getValue()); + } } - private HttpURLConnection createSendingDataConnection( - RequestMethod method, URL url, String query, ContentType contentType, Map headers) throws IOException { - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.setUseCaches(false); - conn.setDoOutput(true); - conn.setRequestMethod(method.toString()); - conn.setRequestProperty("Accept-Charset", StandardCharsets.UTF_8.name()); - conn.setRequestProperty("Accept", "application/json"); - conn.setRequestProperty("Content-Type", String.format( - "%s;charset=%s", contentType.getContentType(), StandardCharsets.UTF_8.name().toLowerCase())); - - if (null != headers) { - for (Map.Entry header : headers.entrySet()) { - conn.setRequestProperty(header.getKey(), header.getValue()); - } - } - - try (OutputStream out = conn.getOutputStream()) { - out.write(query.getBytes(StandardCharsets.UTF_8)); - } - - return conn; + return conn; + } + + private HttpURLConnection createDeleteConnection( + URL url, + String query, + ContentType contentType, + Map headers + ) throws IOException { + return createSendingDataConnection( + DELETE, + url, + query, + contentType, + headers + ); + } + + private HttpURLConnection createPUTConnection( + URL url, + String query, + ContentType contentType, + Map headers + ) throws IOException { + return createSendingDataConnection(PUT, url, query, contentType, headers); + } + + private HttpURLConnection createSendingDataConnection( + RequestMethod method, + URL url, + String query, + ContentType contentType, + Map headers + ) throws IOException { + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setUseCaches(false); + conn.setDoOutput(true); + conn.setRequestMethod(method.toString()); + conn.setRequestProperty("Accept-Charset", StandardCharsets.UTF_8.name()); + conn.setRequestProperty("Accept", "application/json"); + conn.setRequestProperty( + "Content-Type", + String.format( + "%s;charset=%s", + contentType.getContentType(), + StandardCharsets.UTF_8.name().toLowerCase() + ) + ); + + if (null != headers) { + for (Map.Entry header : headers.entrySet()) { + conn.setRequestProperty(header.getKey(), header.getValue()); + } } - private String formatUrl(String url, String query) { - if (null == query || query.trim().isEmpty()) - return url; - - String separator = url.contains("?") ? "&" : "?"; - return String.format("%s%s%s", url, separator, query); + try (OutputStream out = conn.getOutputStream()) { + out.write(query.getBytes(StandardCharsets.UTF_8)); } - private static String getResponseBody(InputStream responseStream) { - try (final Scanner scanner = new Scanner(responseStream, StandardCharsets.UTF_8.name())) { - final String responseBody = scanner.useDelimiter("\\A").next(); - responseStream.close(); - - logger.log(Level.FINE, String.format("HTTP Response Body : %s", responseBody)); - return responseBody; - } catch (Exception e) { - return null; - } + return conn; + } + + private String formatUrl(String url, String query) { + if (null == query || query.trim().isEmpty()) return url; + + String separator = url.contains("?") ? "&" : "?"; + return String.format("%s%s%s", url, separator, query); + } + + private static String getResponseBody(InputStream responseStream) { + try ( + final Scanner scanner = new Scanner( + responseStream, + StandardCharsets.UTF_8.name() + ) + ) { + final String responseBody = scanner.useDelimiter("\\A").next(); + responseStream.close(); + + logger.log( + Level.FINE, + String.format("HTTP Response Body : %s", responseBody) + ); + return responseBody; + } catch (Exception e) { + return null; } - - private HttpUtilImpl() { - super(); + } + + private HttpUtilImpl() { + super(); + } + + /** + * Returns the singleton instance of HttpUtilImpl. + * If the instance does not exist, it is created. + */ + public static HttpUtilImpl getInstance() { + if (null == instance) synchronized (HttpUtilImpl.class) { + instance = new HttpUtilImpl(); } - public static HttpUtilImpl getInstance() { - if (null == instance) - synchronized (HttpUtilImpl.class) { - instance = new HttpUtilImpl(); - } - - return instance; - } + return instance; + } } diff --git a/src/main/java/cl/transbank/webpay/oneclick/model/MallTransactionCreateDetails.java b/src/main/java/cl/transbank/webpay/oneclick/model/MallTransactionCreateDetails.java index ad5940ca..0b976031 100644 --- a/src/main/java/cl/transbank/webpay/oneclick/model/MallTransactionCreateDetails.java +++ b/src/main/java/cl/transbank/webpay/oneclick/model/MallTransactionCreateDetails.java @@ -1,50 +1,116 @@ package cl.transbank.webpay.oneclick.model; -import lombok.*; - import java.util.ArrayList; import java.util.List; +import java.util.Objects; +import lombok.*; +/** + * This class represents the details for creating a mall transaction. + */ @ToString public class MallTransactionCreateDetails { - @Getter - private List details = new ArrayList<>(); - private MallTransactionCreateDetails() {} + @Getter + private List details = new ArrayList<>(); - public static MallTransactionCreateDetails build() { - return new MallTransactionCreateDetails(); - } + private MallTransactionCreateDetails() {} - public static MallTransactionCreateDetails build(double amount, String commerceCode, String buyOrder, byte installmentsNumber) { - return MallTransactionCreateDetails.build().add(amount, commerceCode, buyOrder, installmentsNumber); - } + /** + * Builds a new MallTransactionCreateDetails. + * @return A new MallTransactionCreateDetails. + */ + public static MallTransactionCreateDetails build() { + return new MallTransactionCreateDetails(); + } - public MallTransactionCreateDetails add(double amount, String commerceCode, String buyOrder, byte installmentsNumber) { - getDetails().add(new Detail(amount, commerceCode, buyOrder, installmentsNumber)); - return this; - } + /** + * Builds a new MallTransactionCreateDetails with the specified amount, commerce code, buy order, and installments number. + * @param amount The amount of the transaction. + * @param commerceCode The commerce code of the transaction. + * @param buyOrder The buy order of the transaction. + * @param installmentsNumber The number of installments for the transaction. + * @return A new MallTransactionCreateDetails. + */ + public static MallTransactionCreateDetails build( + double amount, + String commerceCode, + String buyOrder, + byte installmentsNumber + ) { + return MallTransactionCreateDetails + .build() + .add(amount, commerceCode, buyOrder, installmentsNumber); + } + + /** + * Adds a new detail to the details of the transaction. + * @param amount The amount of the detail. + * @param commerceCode The commerce code of the detail. + * @param buyOrder The buy order of the detail. + * @param installmentsNumber The number of installments for the detail. + * @return This MallTransactionCreateDetails. + */ + public MallTransactionCreateDetails add( + double amount, + String commerceCode, + String buyOrder, + byte installmentsNumber + ) { + getDetails() + .add(new Detail(amount, commerceCode, buyOrder, installmentsNumber)); + return this; + } + + /** + * Removes a detail from the details of the transaction. + * @param amount The amount of the detail. + * @param commerceCode The commerce code of the detail. + * @param buyOrder The buy order of the detail. + * @param installmentsNumber The number of installments for the detail. + * @return True if the detail was removed, false otherwise. + */ + public boolean remove( + double amount, + String commerceCode, + String buyOrder, + byte installmentsNumber + ) { + return getDetails() + .remove(new Detail(amount, commerceCode, buyOrder, installmentsNumber)); + } + + /** + * This class represents a detail of a mall transaction. + */ + @NoArgsConstructor + @AllArgsConstructor + @Getter + @Setter + @ToString + public class Detail { + + private double amount; + private String commerceCode; + private String buyOrder; + private byte installmentsNumber; + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Detail)) return false; - public boolean remove(double amount, String commerceCode, String buyOrder, byte installmentsNumber) { - return getDetails().remove(new Detail(amount, commerceCode, buyOrder, installmentsNumber)); + Detail another = (Detail) obj; + return ( + getAmount() == another.getAmount() && + getCommerceCode().equals(another.getBuyOrder()) && + getBuyOrder().equals(another.getBuyOrder()) && + getInstallmentsNumber() == another.getInstallmentsNumber() + ); } - @NoArgsConstructor @AllArgsConstructor - @Getter @Setter @ToString - public class Detail { - private double amount; - private String commerceCode; - private String buyOrder; - private byte installmentsNumber; - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Detail)) - return false; - - Detail another = (Detail) obj; - return getAmount() == another.getAmount() && getCommerceCode().equals(another.getBuyOrder()) && - getBuyOrder().equals(another.getBuyOrder()) && getInstallmentsNumber() == another.getInstallmentsNumber(); - } + @Override + public int hashCode() { + return Objects.hash(commerceCode, buyOrder, amount, installmentsNumber); } + } } From c917a7feb7dfd0e7c021bc317cbcf84e534a899c Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Wed, 13 Mar 2024 09:17:09 -0400 Subject: [PATCH 03/26] fix: add ssl exception handling --- .../model/MallTransactionCreateDetails.java | 6 + .../java/cl/transbank/util/HttpUtilImpl.java | 212 ++++++++++-------- 2 files changed, 128 insertions(+), 90 deletions(-) diff --git a/src/main/java/cl/transbank/model/MallTransactionCreateDetails.java b/src/main/java/cl/transbank/model/MallTransactionCreateDetails.java index 75158ae1..a7ebb6f4 100644 --- a/src/main/java/cl/transbank/model/MallTransactionCreateDetails.java +++ b/src/main/java/cl/transbank/model/MallTransactionCreateDetails.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; import lombok.*; /** @@ -113,5 +114,10 @@ public boolean equals(Object obj) { getBuyOrder().equals(another.getBuyOrder()) ); } + + @Override + public int hashCode() { + return Objects.hash(commerceCode, buyOrder, amount); + } } } diff --git a/src/main/java/cl/transbank/util/HttpUtilImpl.java b/src/main/java/cl/transbank/util/HttpUtilImpl.java index 8af2d489..ab0e7298 100644 --- a/src/main/java/cl/transbank/util/HttpUtilImpl.java +++ b/src/main/java/cl/transbank/util/HttpUtilImpl.java @@ -14,6 +14,7 @@ import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; +import javax.net.ssl.SSLException; import lombok.AccessLevel; import lombok.Getter; import lombok.NonNull; @@ -113,8 +114,7 @@ public String request( @NonNull URL url, RequestMethod method, String query, - Map headers, - boolean useException + Map headers ) throws IOException, WebpayException { return request(url, method, query, null, headers); } @@ -132,92 +132,124 @@ public String request( Map headers ) throws IOException, WebpayException { if (null == method) method = GET; - if (null == contentType) contentType = ContentType.JSON; - HttpURLConnection conn = null; + logRequestDetails(url, method, headers, query); + HttpURLConnection conn = null; + int responseCode = 0; + String responseBody = ""; try { - logger.log(Level.FINE, String.format("HTTP URL : %s", url)); - logger.log(Level.FINE, String.format("HTTP Method : %s", method)); - - if (null != headers) { - for (String key : headers.keySet()) { - if (!StringUtils.isEmpty(key)) { - String value = headers.get(key); - - if (key.equalsIgnoreCase("Tbk-Api-Key-Secret")) { - value = "NOT DISPLAYED BY SECURITY REASON"; - } - - logger.log( - Level.FINE, - String.format("HTTP Header [%s] : %s", key, value) - ); - } - } - } - - logger.log(Level.FINE, String.format("HTTP Request Query : %s", query)); - switch (method) { - case POST: - conn = createPOSTConnection(url, query, contentType, headers); - break; - case DELETE: - conn = createDeleteConnection(url, query, contentType, headers); - break; - case PUT: - conn = createPUTConnection(url, query, contentType, headers); - break; - case GET: - default: - conn = createGETConnection(url, query, headers); - } - - int responseCode = conn.getResponseCode(); + conn = createConnection(url, method, query, contentType, headers); + responseCode = conn.getResponseCode(); logger.log( Level.FINE, String.format("HTTP Response Code : %s", responseCode) ); + final boolean isHttpErrorCode = !(responseCode >= 200 && responseCode < 300); InputStream input = !isHttpErrorCode ? conn.getInputStream() : conn.getErrorStream(); - final String responseBody = getResponseBody(input); - if (isHttpErrorCode) { - Object errorMessage = - "Could not obtain a response message from Webpay API"; - if (responseBody != null) { - final Map errorMap = getJsonUtil() - .jsonDecode(responseBody, HashMap.class); - errorMessage = errorMap.get("error_message"); - } + responseBody = getResponseBody(input); + handleResponse(responseCode, responseBody, isHttpErrorCode); + } catch (SSLException e) { + throw new IOException("SSL error", e); + } + + return responseBody; + } + + private void logRequestDetails( + URL url, + RequestMethod method, + Map headers, + String query + ) { + logger.log(Level.FINE, String.format("HTTP URL : %s", url)); + logger.log(Level.FINE, String.format("HTTP Method : %s", method)); - if (null == errorMessage) errorMessage = - "Unspecified message by Webpay API"; - throw new TransbankHttpApiException( - responseCode, - errorMessage.toString() - ); + if (null != headers) { + for (String key : headers.keySet()) { + if (!StringUtils.isEmpty(key)) { + String value = headers.get(key); + + if (key.equalsIgnoreCase("Tbk-Api-Key-Secret")) { + value = "NOT DISPLAYED BY SECURITY REASON"; + } + + logger.log( + Level.FINE, + String.format("HTTP Header [%s] : %s", key, value) + ); + } } + } + + logger.log(Level.FINE, String.format("HTTP Request Query : %s", query)); + } - if (responseBody != null && !responseBody.trim().startsWith("[")) { - final Map tempMap = getJsonUtil() + private HttpURLConnection createConnection( + URL url, + RequestMethod method, + String query, + ContentType contentType, + Map headers + ) throws IOException { + HttpURLConnection conn; + switch (method) { + case POST: + conn = createPOSTConnection(url, query, contentType, headers); + break; + case DELETE: + conn = createDeleteConnection(url, query, contentType, headers); + break; + case PUT: + conn = createPUTConnection(url, query, contentType, headers); + break; + case GET: + conn = createGETConnection(url, query, headers); + break; + default: + conn = createGETConnection(url, query, headers); + break; + } + return conn; + } + + private void handleResponse( + int responseCode, + String responseBody, + boolean isHttpErrorCode + ) throws WebpayException { + if (isHttpErrorCode) { + Object errorMessage = + "Could not obtain a response message from Webpay API"; + if (responseBody != null) { + final Map errorMap = getJsonUtil() .jsonDecode(responseBody, HashMap.class); - if ( - tempMap.containsKey("error_message") && - tempMap.get("error_message") != null - ) { - throw new WebpayException(tempMap.get("error_message").toString()); - } + errorMessage = errorMap.get("error_message"); } - return responseBody; - } finally { - if (null != conn) conn.disconnect(); + if (null == errorMessage) errorMessage = + "Unspecified message by Webpay API"; + throw new TransbankHttpApiException( + responseCode, + errorMessage.toString() + ); + } + + if (responseBody != null && !responseBody.trim().startsWith("[")) { + final Map tempMap = getJsonUtil().jsonDecode(responseBody, HashMap.class); + if ( + tempMap.containsKey("error_message") && + tempMap.get("error_message") != null + ) { + throw new WebpayException(tempMap.get("error_message").toString()); + } } } @@ -280,29 +312,33 @@ private HttpURLConnection createSendingDataConnection( ContentType contentType, Map headers ) throws IOException { - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.setUseCaches(false); - conn.setDoOutput(true); - conn.setRequestMethod(method.toString()); - conn.setRequestProperty("Accept-Charset", StandardCharsets.UTF_8.name()); - conn.setRequestProperty("Accept", "application/json"); - conn.setRequestProperty( - "Content-Type", - String.format( - "%s;charset=%s", - contentType.getContentType(), - StandardCharsets.UTF_8.name().toLowerCase() - ) - ); + OutputStream out = null; + try { + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setUseCaches(false); + conn.setDoOutput(true); + conn.setRequestMethod(method.toString()); + conn.setRequestProperty("Accept-Charset", StandardCharsets.UTF_8.name()); + conn.setRequestProperty("Accept", "application/json"); + conn.setRequestProperty( + "Content-Type", + String.format( + "%s;charset=%s", + contentType.getContentType(), + StandardCharsets.UTF_8.name().toLowerCase() + ) + ); - if (null != headers) { - for (Map.Entry header : headers.entrySet()) { - conn.setRequestProperty(header.getKey(), header.getValue()); + if (null != headers) { + for (Map.Entry header : headers.entrySet()) { + conn.setRequestProperty(header.getKey(), header.getValue()); + } } - } - try (OutputStream out = conn.getOutputStream()) { + out = conn.getOutputStream(); out.write(query.getBytes(StandardCharsets.UTF_8)); + } catch (SSLException e) { + throw new IOException("SSL error", e); } return conn; @@ -325,10 +361,6 @@ private static String getResponseBody(InputStream responseStream) { final String responseBody = scanner.useDelimiter("\\A").next(); responseStream.close(); - logger.log( - Level.FINE, - String.format("HTTP Response Body : %s", responseBody) - ); return responseBody; } catch (Exception e) { return null; From 566cfd68fb7dc2aa45d75d295f3c9b9276b37e82 Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Wed, 13 Mar 2024 17:35:45 -0400 Subject: [PATCH 04/26] fix: add useException back to request --- src/main/java/cl/transbank/util/HttpUtilImpl.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/cl/transbank/util/HttpUtilImpl.java b/src/main/java/cl/transbank/util/HttpUtilImpl.java index ab0e7298..61cfe7c3 100644 --- a/src/main/java/cl/transbank/util/HttpUtilImpl.java +++ b/src/main/java/cl/transbank/util/HttpUtilImpl.java @@ -114,7 +114,8 @@ public String request( @NonNull URL url, RequestMethod method, String query, - Map headers + Map headers, + boolean useException ) throws IOException, WebpayException { return request(url, method, query, null, headers); } @@ -313,8 +314,9 @@ private HttpURLConnection createSendingDataConnection( Map headers ) throws IOException { OutputStream out = null; + HttpURLConnection conn = null; try { - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn = (HttpURLConnection) url.openConnection(); conn.setUseCaches(false); conn.setDoOutput(true); conn.setRequestMethod(method.toString()); From 981d1c6e808a29566f22a4455bc2c05eefc841d6 Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Thu, 14 Mar 2024 17:36:20 -0400 Subject: [PATCH 05/26] docs: fix parameters on comments --- .../cl/transbank/model/MallTransactionCreateDetails.java | 1 - src/main/java/cl/transbank/model/Options.java | 1 - src/main/java/cl/transbank/patpass/PatpassByWebpay.java | 6 ------ src/main/java/cl/transbank/patpass/PatpassComercio.java | 6 ------ .../patpass/responses/PatpassTransactionCreateDetails.java | 6 ------ .../webpay/transaccioncompleta/FullTransaction.java | 7 +++++-- 6 files changed, 5 insertions(+), 22 deletions(-) diff --git a/src/main/java/cl/transbank/model/MallTransactionCreateDetails.java b/src/main/java/cl/transbank/model/MallTransactionCreateDetails.java index a7ebb6f4..f7998bc5 100644 --- a/src/main/java/cl/transbank/model/MallTransactionCreateDetails.java +++ b/src/main/java/cl/transbank/model/MallTransactionCreateDetails.java @@ -85,7 +85,6 @@ public List getDetails() { /** * Gets the details of this MallTransactionCreateDetails. - * @return The details of this MallTransactionCreateDetails. */ @NoArgsConstructor @AllArgsConstructor diff --git a/src/main/java/cl/transbank/model/Options.java b/src/main/java/cl/transbank/model/Options.java index 10ebf3cd..1be980de 100644 --- a/src/main/java/cl/transbank/model/Options.java +++ b/src/main/java/cl/transbank/model/Options.java @@ -64,7 +64,6 @@ public Options buildOptions(Options options) { /** * Creates and returns a copy of this object. * @return A clone of this instance. - * @throws CloneNotSupportedException If the object's class does not support the Cloneable interface. */ @Override public Options clone() { diff --git a/src/main/java/cl/transbank/patpass/PatpassByWebpay.java b/src/main/java/cl/transbank/patpass/PatpassByWebpay.java index e21d6d58..539805f4 100644 --- a/src/main/java/cl/transbank/patpass/PatpassByWebpay.java +++ b/src/main/java/cl/transbank/patpass/PatpassByWebpay.java @@ -67,8 +67,6 @@ public static void configureForProduction( /** * Configures the environment for testing. - * @param commerceCode The commerce code. - * @param apiKey The API key. */ public static void configureForTesting() { configureForIntegration( @@ -79,8 +77,6 @@ public static void configureForTesting() { /** * Configures the environment for testing deferred transactions. - * @param commerceCode The commerce code. - * @param apiKey The API key. */ public static void configureForTestingDeferred() { configureForIntegration( @@ -91,8 +87,6 @@ public static void configureForTestingDeferred() { /** * Configures the environment for mock testing. - * @param commerceCode The commerce code. - * @param apiKey The API key. */ public static void configureForMock() { PatpassByWebpay.options = diff --git a/src/main/java/cl/transbank/patpass/PatpassComercio.java b/src/main/java/cl/transbank/patpass/PatpassComercio.java index 63234422..c7283427 100644 --- a/src/main/java/cl/transbank/patpass/PatpassComercio.java +++ b/src/main/java/cl/transbank/patpass/PatpassComercio.java @@ -73,8 +73,6 @@ public static void configureForProduction( /** * Configures the environment for testing. - * @param commerceCode The commerce code. - * @param apiKey The API key. */ public static void configureForTesting() { configureForIntegration( @@ -85,8 +83,6 @@ public static void configureForTesting() { /** * Configures the environment for testing deferred transactions. - * @param commerceCode The commerce code. - * @param apiKey The API key. */ public static void configureForTestingDeferred() { configureForIntegration( @@ -97,8 +93,6 @@ public static void configureForTestingDeferred() { /** * Configures the environment for mock testing. - * @param commerceCode The commerce code. - * @param apiKey The API key. */ public static void configureForMock() { PatpassComercio.options = diff --git a/src/main/java/cl/transbank/patpass/responses/PatpassTransactionCreateDetails.java b/src/main/java/cl/transbank/patpass/responses/PatpassTransactionCreateDetails.java index 9f647a6b..3575be33 100644 --- a/src/main/java/cl/transbank/patpass/responses/PatpassTransactionCreateDetails.java +++ b/src/main/java/cl/transbank/patpass/responses/PatpassTransactionCreateDetails.java @@ -7,8 +7,6 @@ /** * Configures the environment for mock testing. - * @param commerceCode The commerce code. - * @param apiKey The API key. */ public class PatpassTransactionCreateDetails { @@ -16,15 +14,11 @@ public class PatpassTransactionCreateDetails { /** * Configures the environment for mock testing. - * @param commerceCode The commerce code. - * @param apiKey The API key. */ private PatpassTransactionCreateDetails() {} /** * Configures the environment for mock testing. - * @param commerceCode The commerce code. - * @param apiKey The API key. */ public static PatpassTransactionCreateDetails build() { return new PatpassTransactionCreateDetails(); diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java index 2abc9acc..3a41991c 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java @@ -16,8 +16,11 @@ import java.io.IOException; /** - * Constructor with options. Uses provided options. - * @param options The options to use for this transaction. + * The FullTransaction class extends the BaseTransaction class and provides methods for creating, committing, + * checking the status of, refunding, and capturing transactions. It also provides methods for creating installments + * for a transaction. This class also provides methods for configuring the transaction for different environments + * such as integration, production, testing, and testing deferred. + * */ public class FullTransaction extends BaseTransaction { From ff01bb1d37ca39558d9da1d224fcbcbc2d41e9fe Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Thu, 14 Mar 2024 17:37:15 -0400 Subject: [PATCH 06/26] refactor: adjust loggin method --- src/main/java/cl/transbank/util/HttpUtilImpl.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/cl/transbank/util/HttpUtilImpl.java b/src/main/java/cl/transbank/util/HttpUtilImpl.java index 61cfe7c3..08c34316 100644 --- a/src/main/java/cl/transbank/util/HttpUtilImpl.java +++ b/src/main/java/cl/transbank/util/HttpUtilImpl.java @@ -144,10 +144,7 @@ public String request( conn = createConnection(url, method, query, contentType, headers); responseCode = conn.getResponseCode(); - logger.log( - Level.FINE, - String.format("HTTP Response Code : %s", responseCode) - ); + logger.log(Level.FINE, "HTTP Response Code : {0}", responseCode); final boolean isHttpErrorCode = !(responseCode >= 200 && responseCode < 300); From 495be4fb2dfa1e022d36f1b1e94619cd4741fc82 Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Thu, 14 Mar 2024 17:52:03 -0400 Subject: [PATCH 07/26] refactor: return an empty object instead of a null value on clone for Options --- src/main/java/cl/transbank/model/Options.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/cl/transbank/model/Options.java b/src/main/java/cl/transbank/model/Options.java index 1be980de..f62cc321 100644 --- a/src/main/java/cl/transbank/model/Options.java +++ b/src/main/java/cl/transbank/model/Options.java @@ -70,7 +70,7 @@ public Options clone() { try { return (Options) super.clone(); } catch (CloneNotSupportedException e) { - return null; + return (Options) new Object(); } } From d58e4ecd6877161fd9111024829876966d315aa4 Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Mon, 18 Mar 2024 13:59:01 -0400 Subject: [PATCH 08/26] refactor: add final or static to constants --- .../cl/transbank/common/ApiConstants.java | 35 +++++++++++-------- .../transbank/common/IntegrationApiKeys.java | 11 ++++-- .../webpay/common/WebpayOptions.java | 4 +-- .../transaccioncompleta/FullTransaction.java | 11 +++--- .../MallFullTransaction.java | 19 +++++----- 5 files changed, 48 insertions(+), 32 deletions(-) diff --git a/src/main/java/cl/transbank/common/ApiConstants.java b/src/main/java/cl/transbank/common/ApiConstants.java index 38bdbea3..e5d51479 100644 --- a/src/main/java/cl/transbank/common/ApiConstants.java +++ b/src/main/java/cl/transbank/common/ApiConstants.java @@ -4,21 +4,26 @@ * This class contains the constants used in the API. */ public class ApiConstants { - - public static String WEBPAY_ENDPOINT = "rswebpaytransaction/api/webpay/v1.2"; - public static String ONECLICK_ENDPOINT = + public static final String WEBPAY_ENDPOINT = "rswebpaytransaction/api/webpay/v1.2"; + public static final String ONECLICK_ENDPOINT = "rswebpaytransaction/api/oneclick/v1.2"; - public static String PATPASS_COMERCIO_ENDPOINT = "restpatpass/v1/services"; + public static final String PATPASS_COMERCIO_ENDPOINT = "restpatpass/v1/services"; + public static final int BUY_ORDER_LENGTH = 26; + public static final int SESSION_ID_LENGTH = 61; + public static final int RETURN_URL_LENGTH = 255; + public static final int AUTHORIZATION_CODE_LENGTH = 6; + public static final int CARD_EXPIRATION_DATE_LENGTH = 5; + public static final int CARD_NUMBER_LENGTH = 19; + public static final int TBK_USER_LENGTH = 40; + public static final int USER_NAME_LENGTH = 40; + public static final int COMMERCE_CODE_LENGTH = 12; + public static final int TOKEN_LENGTH = 64; + public static final int EMAIL_LENGTH = 100; - public static int BUY_ORDER_LENGTH = 26; - public static int SESSION_ID_LENGTH = 61; - public static int RETURN_URL_LENGTH = 255; - public static int AUTHORIZATION_CODE_LENGTH = 6; - public static int CARD_EXPIRATION_DATE_LENGTH = 5; - public static int CARD_NUMBER_LENGTH = 19; - public static int TBK_USER_LENGTH = 40; - public static int USER_NAME_LENGTH = 40; - public static int COMMERCE_CODE_LENGTH = 12; - public static int TOKEN_LENGTH = 64; - public static int EMAIL_LENGTH = 100; + /** + * Private constructor to prevent instantiation. + */ + private ApiConstants() { + // This constructor is intentionally empty. Nothing to see here. + } } diff --git a/src/main/java/cl/transbank/common/IntegrationApiKeys.java b/src/main/java/cl/transbank/common/IntegrationApiKeys.java index 70295408..1909838b 100644 --- a/src/main/java/cl/transbank/common/IntegrationApiKeys.java +++ b/src/main/java/cl/transbank/common/IntegrationApiKeys.java @@ -8,11 +8,18 @@ public class IntegrationApiKeys { /** * The API key for Webpay in the integration environment. */ - public static String WEBPAY = + public static final String WEBPAY = "579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C"; /** * The API key for Patpass Comercio in the integration environment. */ - public static String PATPASS_COMERCIO = "cxxXQgGD9vrVe4M41FIt"; + public static final String PATPASS_COMERCIO = "cxxXQgGD9vrVe4M41FIt"; + + /** + * Private constructor to prevent instantiation. + */ + private IntegrationApiKeys() { + // This constructor is intentionally empty. + } } diff --git a/src/main/java/cl/transbank/webpay/common/WebpayOptions.java b/src/main/java/cl/transbank/webpay/common/WebpayOptions.java index ab42eef0..83c2b667 100644 --- a/src/main/java/cl/transbank/webpay/common/WebpayOptions.java +++ b/src/main/java/cl/transbank/webpay/common/WebpayOptions.java @@ -12,10 +12,10 @@ public class WebpayOptions extends Options { @Getter - final String headerCommerceCodeName = "Tbk-Api-Key-Id"; + static final String headerCommerceCodeName = "Tbk-Api-Key-Id"; @Getter - final String headerApiKeyName = "Tbk-Api-Key-Secret"; + static final String headerApiKeyName = "Tbk-Api-Key-Secret"; /** * Constructs a new WebpayOptions with the specified commerce code, API key, and integration type. diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java index 3a41991c..7bde68aa 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java @@ -24,6 +24,7 @@ */ public class FullTransaction extends BaseTransaction { + static final String tokenText = "token"; private static Options defaultOptions = null; /** @@ -127,7 +128,7 @@ public FullTransactionInstallmentResponse installments( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - "token" + FullTransaction.tokenText ); String endpoint = String.format( "%s/transactions/%s/installments", @@ -164,7 +165,7 @@ public FullTransactionCommitResponse commit( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - "token" + FullTransaction.tokenText ); String endpoint = String.format( "%s/transactions/%s", @@ -199,7 +200,7 @@ public FullTransactionStatusResponse status(String token) ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - "token" + FullTransaction.tokenText ); String endpoint = String.format( "%s/transactions/%s", @@ -229,7 +230,7 @@ public FullTransactionRefundResponse refund(String token, double amount) ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - "token" + FullTransaction.tokenText ); String endpoint = String.format( "%s/transactions/%s/refunds", @@ -267,7 +268,7 @@ public FullTransactionCaptureResponse capture( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - "token" + FullTransaction.tokenText ); ValidationUtil.hasTextWithMaxLength( buyOrder, diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/MallFullTransaction.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/MallFullTransaction.java index acd8681a..6b48c5cf 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/MallFullTransaction.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/MallFullTransaction.java @@ -22,6 +22,9 @@ */ public class MallFullTransaction extends BaseTransaction { + static final String buyOrderText = "buyOrder"; + static final String tokenText = "token"; + private static Options defaultOptions = null; /** @@ -74,7 +77,7 @@ public MallFullTransactionCreateResponse create( ValidationUtil.hasTextWithMaxLength( buyOrder, ApiConstants.BUY_ORDER_LENGTH, - "buyOrder" + MallFullTransaction.buyOrderText ); ValidationUtil.hasTextWithMaxLength( sessionId, @@ -139,7 +142,7 @@ public MallFullTransactionInstallmentsResponse installments( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - "token" + MallFullTransaction.tokenText ); String endpoint = String.format( @@ -178,7 +181,7 @@ public MallFullTransactionCommitResponse commit( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - "token" + MallFullTransaction.tokenText ); String endpoint = String.format( @@ -207,7 +210,7 @@ public MallFullTransactionStatusResponse status(String token) ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - "token" + MallFullTransaction.tokenText ); String endpoint = String.format( @@ -236,7 +239,7 @@ public MallFullTransactionRefundResponse refund( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - "token" + MallFullTransaction.tokenText ); ValidationUtil.hasTextWithMaxLength( childCommerceCode, @@ -246,7 +249,7 @@ public MallFullTransactionRefundResponse refund( ValidationUtil.hasTextWithMaxLength( buyOrder, ApiConstants.BUY_ORDER_LENGTH, - "buyOrder" + MallFullTransaction.buyOrderText ); String endpoint = String.format( @@ -282,7 +285,7 @@ public MallFullTransactionCaptureResponse capture( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - "token" + MallFullTransaction.tokenText ); ValidationUtil.hasTextWithMaxLength( commerceCode, @@ -292,7 +295,7 @@ public MallFullTransactionCaptureResponse capture( ValidationUtil.hasTextWithMaxLength( buyOrder, ApiConstants.BUY_ORDER_LENGTH, - "buyOrder" + MallFullTransaction.buyOrderText ); ValidationUtil.hasTextWithMaxLength( authorizationCode, From 44a73b04a52c4c89981ce3a77a89ec9a61539a80 Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Mon, 18 Mar 2024 13:59:21 -0400 Subject: [PATCH 09/26] refactor: use HttpUtil instead of HttpUtilImpl --- src/main/java/cl/transbank/util/HttpUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/cl/transbank/util/HttpUtil.java b/src/main/java/cl/transbank/util/HttpUtil.java index 0279aa57..e906cffe 100644 --- a/src/main/java/cl/transbank/util/HttpUtil.java +++ b/src/main/java/cl/transbank/util/HttpUtil.java @@ -27,11 +27,11 @@ List requestList( Map headers, Class clazz ) throws IOException, WebpayException; - String request(URL url, HttpUtilImpl.RequestMethod method, String query) + String request(URL url, HttpUtil.RequestMethod method, String query) throws IOException, WebpayException; String request( URL url, - HttpUtilImpl.RequestMethod method, + HttpUtil.RequestMethod method, String query, HttpUtil.ContentType contentType ) throws IOException, WebpayException; From 21d75cc8222b2811c6dcd88aa319ae52a47ff980 Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Mon, 18 Mar 2024 13:59:43 -0400 Subject: [PATCH 10/26] refactor: remove String.format method on logs --- src/main/java/cl/transbank/util/HttpUtilImpl.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/cl/transbank/util/HttpUtilImpl.java b/src/main/java/cl/transbank/util/HttpUtilImpl.java index 08c34316..7e850668 100644 --- a/src/main/java/cl/transbank/util/HttpUtilImpl.java +++ b/src/main/java/cl/transbank/util/HttpUtilImpl.java @@ -167,8 +167,8 @@ private void logRequestDetails( Map headers, String query ) { - logger.log(Level.FINE, String.format("HTTP URL : %s", url)); - logger.log(Level.FINE, String.format("HTTP Method : %s", method)); + logger.log(Level.FINE, "HTTP URL : {0}", url); + logger.log(Level.FINE, "HTTP Method : {0}", method); if (null != headers) { for (String key : headers.keySet()) { @@ -181,13 +181,14 @@ private void logRequestDetails( logger.log( Level.FINE, - String.format("HTTP Header [%s] : %s", key, value) + "HTTP Header [{0}] : {1}", + new Object[] { key, value } ); } } } - logger.log(Level.FINE, String.format("HTTP Request Query : %s", query)); + logger.log(Level.FINE, "HTTP Request Query : {0}", query); } private HttpURLConnection createConnection( From 532dff70dc21e35e1b8c98e9a1fd5f955c02d6f6 Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Mon, 18 Mar 2024 14:00:03 -0400 Subject: [PATCH 11/26] refactor: return empty collection instead of null --- src/main/java/cl/transbank/util/ValidationUtil.java | 2 +- src/main/java/cl/transbank/util/WebpayApiResource.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/cl/transbank/util/ValidationUtil.java b/src/main/java/cl/transbank/util/ValidationUtil.java index 312b9ba7..b4b25636 100644 --- a/src/main/java/cl/transbank/util/ValidationUtil.java +++ b/src/main/java/cl/transbank/util/ValidationUtil.java @@ -67,7 +67,7 @@ public static void hasTextTrimWithMaxLength( * @throws IllegalArgumentException If the list is null or empty. */ public static void hasElements(List value, String valueName) { - if (value == null || value.size() == 0) throw new IllegalArgumentException( + if (value == null || value.isEmpty()) throw new IllegalArgumentException( "list '" + valueName + "'" + " can't be null or empty" ); } diff --git a/src/main/java/cl/transbank/util/WebpayApiResource.java b/src/main/java/cl/transbank/util/WebpayApiResource.java index e50939cc..02cd1b90 100644 --- a/src/main/java/cl/transbank/util/WebpayApiResource.java +++ b/src/main/java/cl/transbank/util/WebpayApiResource.java @@ -7,6 +7,7 @@ import cl.transbank.webpay.common.WebpayOptions; import java.io.IOException; import java.net.URL; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -28,7 +29,7 @@ public abstract class WebpayApiResource { * @return A map of headers for the request. */ public static Map buildHeaders(Options options) { - if (null == options) return null; + if (null == options) return Collections.emptyMap(); Map headers = new HashMap<>(); headers.put(options.getHeaderCommerceCodeName(), options.getCommerceCode()); @@ -175,9 +176,9 @@ public static List executeToList( clazz ); - if (null == out) return null; + if (null == out) return Collections.emptyList(); - if (null == clazz) return null; + if (null == clazz) return Collections.emptyList(); return out; } From dfafdb0bc443a6d538979e2aad40c752748a7ad4 Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Mon, 18 Mar 2024 17:39:52 -0400 Subject: [PATCH 12/26] refactor: move constant to api constants --- src/main/java/cl/transbank/common/ApiConstants.java | 9 +++++++-- src/main/java/cl/transbank/model/Options.java | 12 ------------ .../cl/transbank/patpass/model/PatpassOptions.java | 6 ------ .../java/cl/transbank/util/WebpayApiResource.java | 8 ++++++-- .../cl/transbank/webpay/common/WebpayOptions.java | 6 ------ 5 files changed, 13 insertions(+), 28 deletions(-) diff --git a/src/main/java/cl/transbank/common/ApiConstants.java b/src/main/java/cl/transbank/common/ApiConstants.java index e5d51479..bda4b7cc 100644 --- a/src/main/java/cl/transbank/common/ApiConstants.java +++ b/src/main/java/cl/transbank/common/ApiConstants.java @@ -4,10 +4,15 @@ * This class contains the constants used in the API. */ public class ApiConstants { - public static final String WEBPAY_ENDPOINT = "rswebpaytransaction/api/webpay/v1.2"; + + public static final String WEBPAY_ENDPOINT = + "rswebpaytransaction/api/webpay/v1.2"; public static final String ONECLICK_ENDPOINT = "rswebpaytransaction/api/oneclick/v1.2"; - public static final String PATPASS_COMERCIO_ENDPOINT = "restpatpass/v1/services"; + public static final String PATPASS_COMERCIO_ENDPOINT = + "restpatpass/v1/services"; + public static final String HEADER_COMMERCE_CODE_NAME = "Tbk-Api-Key-Id"; + public static final String HEADER_API_KEY_NAME = "Tbk-Api-Key-Secret"; public static final int BUY_ORDER_LENGTH = 26; public static final int SESSION_ID_LENGTH = 61; public static final int RETURN_URL_LENGTH = 255; diff --git a/src/main/java/cl/transbank/model/Options.java b/src/main/java/cl/transbank/model/Options.java index f62cc321..f784e092 100644 --- a/src/main/java/cl/transbank/model/Options.java +++ b/src/main/java/cl/transbank/model/Options.java @@ -22,18 +22,6 @@ public abstract class Options implements Cloneable { @Getter private IntegrationType integrationType; - /** - * Returns the name of the commerce code header. - * @return The name of the commerce code header. - */ - public abstract String getHeaderCommerceCodeName(); - - /** - * Returns the name of the API key header. - * @return The name of the API key header. - */ - public abstract String getHeaderApiKeyName(); - /** * Builds the options for a transaction. * @param options The options to set. diff --git a/src/main/java/cl/transbank/patpass/model/PatpassOptions.java b/src/main/java/cl/transbank/patpass/model/PatpassOptions.java index 999671ea..3d3c6a44 100644 --- a/src/main/java/cl/transbank/patpass/model/PatpassOptions.java +++ b/src/main/java/cl/transbank/patpass/model/PatpassOptions.java @@ -11,12 +11,6 @@ @AllArgsConstructor public class PatpassOptions extends Options { - @Getter - final String headerCommerceCodeName = "commercecode"; - - @Getter - final String headerApiKeyName = "Authorization"; - /** * Constructs a new PatpassOptions with the specified commerce code, API key, and integration type. * @param commerceCode The commerce code. diff --git a/src/main/java/cl/transbank/util/WebpayApiResource.java b/src/main/java/cl/transbank/util/WebpayApiResource.java index 02cd1b90..92e0c571 100644 --- a/src/main/java/cl/transbank/util/WebpayApiResource.java +++ b/src/main/java/cl/transbank/util/WebpayApiResource.java @@ -1,5 +1,6 @@ package cl.transbank.util; +import cl.transbank.common.ApiConstants; import cl.transbank.common.IntegrationTypeHelper; import cl.transbank.exception.TransbankException; import cl.transbank.model.Options; @@ -32,8 +33,11 @@ public static Map buildHeaders(Options options) { if (null == options) return Collections.emptyMap(); Map headers = new HashMap<>(); - headers.put(options.getHeaderCommerceCodeName(), options.getCommerceCode()); - headers.put(options.getHeaderApiKeyName(), options.getApiKey()); + headers.put( + ApiConstants.HEADER_COMMERCE_CODE_NAME, + options.getCommerceCode() + ); + headers.put(ApiConstants.HEADER_API_KEY_NAME, options.getApiKey()); return headers; } diff --git a/src/main/java/cl/transbank/webpay/common/WebpayOptions.java b/src/main/java/cl/transbank/webpay/common/WebpayOptions.java index 83c2b667..e2ddfdff 100644 --- a/src/main/java/cl/transbank/webpay/common/WebpayOptions.java +++ b/src/main/java/cl/transbank/webpay/common/WebpayOptions.java @@ -11,12 +11,6 @@ @AllArgsConstructor public class WebpayOptions extends Options { - @Getter - static final String headerCommerceCodeName = "Tbk-Api-Key-Id"; - - @Getter - static final String headerApiKeyName = "Tbk-Api-Key-Secret"; - /** * Constructs a new WebpayOptions with the specified commerce code, API key, and integration type. * @param commerceCode The commerce code. From 1da0e9dd751b30d3b59322196dcc352fa0936869 Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Mon, 18 Mar 2024 17:40:13 -0400 Subject: [PATCH 13/26] refactor: typos on full transaction --- .../transaccioncompleta/FullTransaction.java | 12 +++++------ .../MallFullTransaction.java | 20 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java index 7bde68aa..aad36fe6 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java @@ -24,7 +24,7 @@ */ public class FullTransaction extends BaseTransaction { - static final String tokenText = "token"; + static final String TOKEN_TEXT = "token"; private static Options defaultOptions = null; /** @@ -128,7 +128,7 @@ public FullTransactionInstallmentResponse installments( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - FullTransaction.tokenText + FullTransaction.TOKEN_TEXT ); String endpoint = String.format( "%s/transactions/%s/installments", @@ -165,7 +165,7 @@ public FullTransactionCommitResponse commit( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - FullTransaction.tokenText + FullTransaction.TOKEN_TEXT ); String endpoint = String.format( "%s/transactions/%s", @@ -200,7 +200,7 @@ public FullTransactionStatusResponse status(String token) ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - FullTransaction.tokenText + FullTransaction.TOKEN_TEXT ); String endpoint = String.format( "%s/transactions/%s", @@ -230,7 +230,7 @@ public FullTransactionRefundResponse refund(String token, double amount) ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - FullTransaction.tokenText + FullTransaction.TOKEN_TEXT ); String endpoint = String.format( "%s/transactions/%s/refunds", @@ -268,7 +268,7 @@ public FullTransactionCaptureResponse capture( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - FullTransaction.tokenText + FullTransaction.TOKEN_TEXT ); ValidationUtil.hasTextWithMaxLength( buyOrder, diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/MallFullTransaction.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/MallFullTransaction.java index 6b48c5cf..cdd81ae1 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/MallFullTransaction.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/MallFullTransaction.java @@ -22,8 +22,8 @@ */ public class MallFullTransaction extends BaseTransaction { - static final String buyOrderText = "buyOrder"; - static final String tokenText = "token"; + static final String BUY_ORDER_TEXT = "buyOrder"; + static final String TOKEN_TEXT = "token"; private static Options defaultOptions = null; @@ -77,7 +77,7 @@ public MallFullTransactionCreateResponse create( ValidationUtil.hasTextWithMaxLength( buyOrder, ApiConstants.BUY_ORDER_LENGTH, - MallFullTransaction.buyOrderText + MallFullTransaction.BUY_ORDER_TEXT ); ValidationUtil.hasTextWithMaxLength( sessionId, @@ -142,7 +142,7 @@ public MallFullTransactionInstallmentsResponse installments( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - MallFullTransaction.tokenText + MallFullTransaction.TOKEN_TEXT ); String endpoint = String.format( @@ -181,7 +181,7 @@ public MallFullTransactionCommitResponse commit( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - MallFullTransaction.tokenText + MallFullTransaction.TOKEN_TEXT ); String endpoint = String.format( @@ -210,7 +210,7 @@ public MallFullTransactionStatusResponse status(String token) ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - MallFullTransaction.tokenText + MallFullTransaction.TOKEN_TEXT ); String endpoint = String.format( @@ -239,7 +239,7 @@ public MallFullTransactionRefundResponse refund( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - MallFullTransaction.tokenText + MallFullTransaction.TOKEN_TEXT ); ValidationUtil.hasTextWithMaxLength( childCommerceCode, @@ -249,7 +249,7 @@ public MallFullTransactionRefundResponse refund( ValidationUtil.hasTextWithMaxLength( buyOrder, ApiConstants.BUY_ORDER_LENGTH, - MallFullTransaction.buyOrderText + MallFullTransaction.BUY_ORDER_TEXT ); String endpoint = String.format( @@ -285,7 +285,7 @@ public MallFullTransactionCaptureResponse capture( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - MallFullTransaction.tokenText + MallFullTransaction.TOKEN_TEXT ); ValidationUtil.hasTextWithMaxLength( commerceCode, @@ -295,7 +295,7 @@ public MallFullTransactionCaptureResponse capture( ValidationUtil.hasTextWithMaxLength( buyOrder, ApiConstants.BUY_ORDER_LENGTH, - MallFullTransaction.buyOrderText + MallFullTransaction.BUY_ORDER_TEXT ); ValidationUtil.hasTextWithMaxLength( authorizationCode, From b253e83e58b3ea44e605825d15944ac9080ce7f6 Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Wed, 20 Mar 2024 09:52:48 -0400 Subject: [PATCH 14/26] refactor: move duplicated strings to api constants --- .../cl/transbank/common/ApiConstants.java | 2 ++ .../webpay/modal/WebpayModalTransaction.java | 6 +++--- .../oneclick/OneclickMallInscription.java | 2 +- .../transaccioncompleta/FullTransaction.java | 11 +++++------ .../MallFullTransaction.java | 19 ++++++++----------- .../webpayplus/WebpayMallTransaction.java | 8 ++++---- .../webpay/webpayplus/WebpayTransaction.java | 8 ++++---- .../webpayplus/OneclickMallDeferredTest.java | 2 +- .../java/webpayplus/OneclickMallTest.java | 2 +- .../java/webpayplus/PatpassByWebpayTest.java | 2 +- .../java/webpayplus/PatpassComercioTest.java | 2 +- src/test/java/webpayplus/WebpayModalTest.java | 2 +- .../webpayplus/WebpayPlusDeferredTest.java | 2 +- .../WebpayPlusMallDeferredTest.java | 2 +- .../java/webpayplus/WebpayPlusMallTest.java | 2 +- src/test/java/webpayplus/WebpayPlusTest.java | 2 +- 16 files changed, 36 insertions(+), 38 deletions(-) diff --git a/src/main/java/cl/transbank/common/ApiConstants.java b/src/main/java/cl/transbank/common/ApiConstants.java index bda4b7cc..877afeaa 100644 --- a/src/main/java/cl/transbank/common/ApiConstants.java +++ b/src/main/java/cl/transbank/common/ApiConstants.java @@ -24,6 +24,8 @@ public class ApiConstants { public static final int COMMERCE_CODE_LENGTH = 12; public static final int TOKEN_LENGTH = 64; public static final int EMAIL_LENGTH = 100; + public static final String TOKEN_TEXT = "token"; + public static final String BUY_ORDER_TEXT = "buyOrder"; /** * Private constructor to prevent instantiation. diff --git a/src/main/java/cl/transbank/webpay/modal/WebpayModalTransaction.java b/src/main/java/cl/transbank/webpay/modal/WebpayModalTransaction.java index 1e18864e..ece080d1 100644 --- a/src/main/java/cl/transbank/webpay/modal/WebpayModalTransaction.java +++ b/src/main/java/cl/transbank/webpay/modal/WebpayModalTransaction.java @@ -35,7 +35,7 @@ public ModalTransactionCreateResponse create(String buyOrder, String sessionId, } public ModalTransactionCommitResponse commit(String token) throws IOException, TransactionCommitException { - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); + ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, ApiConstants.TOKEN_TEXT); String endpoint = String.format("%s/transactions/%s", ApiConstants.WEBPAY_ENDPOINT,token); try { @@ -46,7 +46,7 @@ public ModalTransactionCommitResponse commit(String token) throws IOException, T } public ModalTransactionStatusResponse status(String token) throws IOException, TransactionStatusException { - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); + ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, ApiConstants.TOKEN_TEXT); String endpoint = String.format("%s/transactions/%s", ApiConstants.WEBPAY_ENDPOINT,token); try { @@ -57,7 +57,7 @@ public ModalTransactionStatusResponse status(String token) throws IOException, T } public ModalTransactionRefundResponse refund(String token, double amount) throws IOException, TransactionRefundException { - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); + ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, ApiConstants.TOKEN_TEXT); String endpoint = String.format("%s/transactions/%s/refunds", ApiConstants.WEBPAY_ENDPOINT,token); try { diff --git a/src/main/java/cl/transbank/webpay/oneclick/OneclickMallInscription.java b/src/main/java/cl/transbank/webpay/oneclick/OneclickMallInscription.java index c0858469..b32013c6 100644 --- a/src/main/java/cl/transbank/webpay/oneclick/OneclickMallInscription.java +++ b/src/main/java/cl/transbank/webpay/oneclick/OneclickMallInscription.java @@ -86,7 +86,7 @@ public OneclickMallInscriptionFinishResponse finish(String token) ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - "token" + ApiConstants.TOKEN_TEXT ); String endpoint = String.format( "%s/inscriptions/%s", diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java index aad36fe6..c41c24a1 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java @@ -24,7 +24,6 @@ */ public class FullTransaction extends BaseTransaction { - static final String TOKEN_TEXT = "token"; private static Options defaultOptions = null; /** @@ -128,7 +127,7 @@ public FullTransactionInstallmentResponse installments( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - FullTransaction.TOKEN_TEXT + ApiConstants.TOKEN_TEXT ); String endpoint = String.format( "%s/transactions/%s/installments", @@ -165,7 +164,7 @@ public FullTransactionCommitResponse commit( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - FullTransaction.TOKEN_TEXT + ApiConstants.TOKEN_TEXT ); String endpoint = String.format( "%s/transactions/%s", @@ -200,7 +199,7 @@ public FullTransactionStatusResponse status(String token) ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - FullTransaction.TOKEN_TEXT + ApiConstants.TOKEN_TEXT ); String endpoint = String.format( "%s/transactions/%s", @@ -230,7 +229,7 @@ public FullTransactionRefundResponse refund(String token, double amount) ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - FullTransaction.TOKEN_TEXT + ApiConstants.TOKEN_TEXT ); String endpoint = String.format( "%s/transactions/%s/refunds", @@ -268,7 +267,7 @@ public FullTransactionCaptureResponse capture( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - FullTransaction.TOKEN_TEXT + ApiConstants.TOKEN_TEXT ); ValidationUtil.hasTextWithMaxLength( buyOrder, diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/MallFullTransaction.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/MallFullTransaction.java index cdd81ae1..b0224ed9 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/MallFullTransaction.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/MallFullTransaction.java @@ -22,9 +22,6 @@ */ public class MallFullTransaction extends BaseTransaction { - static final String BUY_ORDER_TEXT = "buyOrder"; - static final String TOKEN_TEXT = "token"; - private static Options defaultOptions = null; /** @@ -77,7 +74,7 @@ public MallFullTransactionCreateResponse create( ValidationUtil.hasTextWithMaxLength( buyOrder, ApiConstants.BUY_ORDER_LENGTH, - MallFullTransaction.BUY_ORDER_TEXT + ApiConstants.BUY_ORDER_TEXT ); ValidationUtil.hasTextWithMaxLength( sessionId, @@ -142,7 +139,7 @@ public MallFullTransactionInstallmentsResponse installments( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - MallFullTransaction.TOKEN_TEXT + ApiConstants.TOKEN_TEXT ); String endpoint = String.format( @@ -181,7 +178,7 @@ public MallFullTransactionCommitResponse commit( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - MallFullTransaction.TOKEN_TEXT + ApiConstants.TOKEN_TEXT ); String endpoint = String.format( @@ -210,7 +207,7 @@ public MallFullTransactionStatusResponse status(String token) ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - MallFullTransaction.TOKEN_TEXT + ApiConstants.TOKEN_TEXT ); String endpoint = String.format( @@ -239,7 +236,7 @@ public MallFullTransactionRefundResponse refund( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - MallFullTransaction.TOKEN_TEXT + ApiConstants.TOKEN_TEXT ); ValidationUtil.hasTextWithMaxLength( childCommerceCode, @@ -249,7 +246,7 @@ public MallFullTransactionRefundResponse refund( ValidationUtil.hasTextWithMaxLength( buyOrder, ApiConstants.BUY_ORDER_LENGTH, - MallFullTransaction.BUY_ORDER_TEXT + ApiConstants.BUY_ORDER_TEXT ); String endpoint = String.format( @@ -285,7 +282,7 @@ public MallFullTransactionCaptureResponse capture( ValidationUtil.hasTextWithMaxLength( token, ApiConstants.TOKEN_LENGTH, - MallFullTransaction.TOKEN_TEXT + ApiConstants.TOKEN_TEXT ); ValidationUtil.hasTextWithMaxLength( commerceCode, @@ -295,7 +292,7 @@ public MallFullTransactionCaptureResponse capture( ValidationUtil.hasTextWithMaxLength( buyOrder, ApiConstants.BUY_ORDER_LENGTH, - MallFullTransaction.BUY_ORDER_TEXT + ApiConstants.BUY_ORDER_TEXT ); ValidationUtil.hasTextWithMaxLength( authorizationCode, diff --git a/src/main/java/cl/transbank/webpay/webpayplus/WebpayMallTransaction.java b/src/main/java/cl/transbank/webpay/webpayplus/WebpayMallTransaction.java index 064f7643..622ee85b 100644 --- a/src/main/java/cl/transbank/webpay/webpayplus/WebpayMallTransaction.java +++ b/src/main/java/cl/transbank/webpay/webpayplus/WebpayMallTransaction.java @@ -44,7 +44,7 @@ public WebpayPlusMallTransactionCreateResponse create(String buyOrder, String se } public WebpayPlusMallTransactionCommitResponse commit(String token) throws IOException, TransactionCommitException { - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); + ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, ApiConstants.TOKEN_TEXT); String endpoint = String.format("%s/transactions/%s", ApiConstants.WEBPAY_ENDPOINT,token); try { @@ -55,7 +55,7 @@ public WebpayPlusMallTransactionCommitResponse commit(String token) throws IOExc } public WebpayPlusMallTransactionStatusResponse status(String token) throws IOException, TransactionStatusException { - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); + ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, ApiConstants.TOKEN_TEXT); String endpoint = String.format("%s/transactions/%s", ApiConstants.WEBPAY_ENDPOINT,token); try { return WebpayApiResource.execute(endpoint, HttpUtil.RequestMethod.GET, options, WebpayPlusMallTransactionStatusResponse.class); @@ -65,7 +65,7 @@ public WebpayPlusMallTransactionStatusResponse status(String token) throws IOExc } public WebpayPlusMallTransactionRefundResponse refund(String token, String buyOrder, String childCommerceCode, double amount) throws IOException, TransactionRefundException { - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); + ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, ApiConstants.TOKEN_TEXT); ValidationUtil.hasTextWithMaxLength(childCommerceCode, ApiConstants.COMMERCE_CODE_LENGTH, "childCommerceCode"); ValidationUtil.hasTextWithMaxLength(buyOrder, ApiConstants.BUY_ORDER_LENGTH, "buyOrder"); @@ -78,7 +78,7 @@ public WebpayPlusMallTransactionRefundResponse refund(String token, String buyOr } public WebpayPlusMallTransactionCaptureResponse capture(String childCommerceCode, String token, String buyOrder, String authorizationCode, double captureAmount) throws IOException, TransactionCaptureException { - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); + ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, ApiConstants.TOKEN_TEXT); ValidationUtil.hasTextWithMaxLength(childCommerceCode, ApiConstants.COMMERCE_CODE_LENGTH, "childCommerceCode"); ValidationUtil.hasTextWithMaxLength(buyOrder, ApiConstants.BUY_ORDER_LENGTH, "buyOrder"); ValidationUtil.hasTextWithMaxLength(authorizationCode, ApiConstants.AUTHORIZATION_CODE_LENGTH, "authorizationCode"); diff --git a/src/main/java/cl/transbank/webpay/webpayplus/WebpayTransaction.java b/src/main/java/cl/transbank/webpay/webpayplus/WebpayTransaction.java index 5557d5a8..c411e654 100644 --- a/src/main/java/cl/transbank/webpay/webpayplus/WebpayTransaction.java +++ b/src/main/java/cl/transbank/webpay/webpayplus/WebpayTransaction.java @@ -38,7 +38,7 @@ public WebpayPlusTransactionCreateResponse create(String buyOrder, String sessio public WebpayPlusTransactionCommitResponse commit(String token) throws IOException, TransactionCommitException { - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); + ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, ApiConstants.TOKEN_TEXT); String endpoint = String.format("%s/transactions/%s", ApiConstants.WEBPAY_ENDPOINT,token); try { @@ -49,7 +49,7 @@ public WebpayPlusTransactionCommitResponse commit(String token) throws IOExcepti } public WebpayPlusTransactionStatusResponse status(String token) throws IOException, TransactionStatusException { - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); + ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, ApiConstants.TOKEN_TEXT); String endpoint = String.format("%s/transactions/%s", ApiConstants.WEBPAY_ENDPOINT,token); try { return WebpayApiResource.execute(endpoint, HttpUtil.RequestMethod.GET, options, WebpayPlusTransactionStatusResponse.class); @@ -59,7 +59,7 @@ public WebpayPlusTransactionStatusResponse status(String token) throws IOExcepti } public WebpayPlusTransactionRefundResponse refund(String token, double amount) throws IOException, TransactionRefundException { - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); + ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, ApiConstants.TOKEN_TEXT); String endpoint = String.format("%s/transactions/%s/refunds", ApiConstants.WEBPAY_ENDPOINT,token); try { return WebpayApiResource.execute(endpoint, HttpUtil.RequestMethod.POST, new TransactionRefundRequest(amount), options, WebpayPlusTransactionRefundResponse.class); @@ -69,7 +69,7 @@ public WebpayPlusTransactionRefundResponse refund(String token, double amount) t } public WebpayPlusTransactionCaptureResponse capture(String token, String buyOrder, String authorizationCode, double captureAmount) throws IOException, TransactionCaptureException { - ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, "token"); + ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, ApiConstants.TOKEN_TEXT); ValidationUtil.hasTextWithMaxLength(buyOrder, ApiConstants.BUY_ORDER_LENGTH, "buyOrder"); ValidationUtil.hasTextWithMaxLength(authorizationCode, ApiConstants.AUTHORIZATION_CODE_LENGTH, "authorizationCode"); String endpoint = String.format("%s/transactions/%s/capture", ApiConstants.WEBPAY_ENDPOINT, token); diff --git a/src/test/java/webpayplus/OneclickMallDeferredTest.java b/src/test/java/webpayplus/OneclickMallDeferredTest.java index 88b766a3..9099ce49 100644 --- a/src/test/java/webpayplus/OneclickMallDeferredTest.java +++ b/src/test/java/webpayplus/OneclickMallDeferredTest.java @@ -67,7 +67,7 @@ public void start() throws IOException, InscriptionStartException { String urlResponse = "https://webpay3gint.transbank.cl/webpayserver/bp_multicode_inscription.cgi"; Map mapResponse = new HashMap(); - mapResponse.put("token", testToken); + mapResponse.put(ApiConstants.TOKEN_TEXT, testToken); mapResponse.put("url_webpay", urlResponse); Gson gson = new GsonBuilder().create(); diff --git a/src/test/java/webpayplus/OneclickMallTest.java b/src/test/java/webpayplus/OneclickMallTest.java index 25331af5..5f85a69c 100644 --- a/src/test/java/webpayplus/OneclickMallTest.java +++ b/src/test/java/webpayplus/OneclickMallTest.java @@ -67,7 +67,7 @@ public void start() throws IOException, InscriptionStartException { String urlResponse = "https://webpay3gint.transbank.cl/webpayserver/bp_multicode_inscription.cgi"; Map mapResponse = new HashMap(); - mapResponse.put("token", testToken); + mapResponse.put(ApiConstants.TOKEN_TEXT, testToken); mapResponse.put("url_webpay", urlResponse); Gson gson = new GsonBuilder().create(); diff --git a/src/test/java/webpayplus/PatpassByWebpayTest.java b/src/test/java/webpayplus/PatpassByWebpayTest.java index 8df8e767..8379b3c6 100644 --- a/src/test/java/webpayplus/PatpassByWebpayTest.java +++ b/src/test/java/webpayplus/PatpassByWebpayTest.java @@ -72,7 +72,7 @@ public void start() throws IOException, TransactionCreateException { String urlResponse = "https://webpay3gint.transbank.cl/webpayserver/initTransaction"; Map mapResponse = new HashMap(); - mapResponse.put("token", testToken); + mapResponse.put(ApiConstants.TOKEN_TEXT, testToken); mapResponse.put("url", urlResponse); Gson gson = new GsonBuilder().create(); diff --git a/src/test/java/webpayplus/PatpassComercioTest.java b/src/test/java/webpayplus/PatpassComercioTest.java index 073535ec..f60e2725 100644 --- a/src/test/java/webpayplus/PatpassComercioTest.java +++ b/src/test/java/webpayplus/PatpassComercioTest.java @@ -41,7 +41,7 @@ public void start() throws IOException, InscriptionStartException { String urlResponse = "https://pagoautomaticocontarjetasint.transbank.cl/nuevo-ic-rest/tokenComercioLogin"; Map mapResponse = new HashMap(); - mapResponse.put("token", testToken); + mapResponse.put(ApiConstants.TOKEN_TEXT, testToken); mapResponse.put("url", urlResponse); Gson gson = new GsonBuilder().create(); diff --git a/src/test/java/webpayplus/WebpayModalTest.java b/src/test/java/webpayplus/WebpayModalTest.java index fd7a6615..0a9adabb 100644 --- a/src/test/java/webpayplus/WebpayModalTest.java +++ b/src/test/java/webpayplus/WebpayModalTest.java @@ -57,7 +57,7 @@ public void create() throws IOException, TransactionCreateException { String urlResponse = "https://webpay3gint.transbank.cl/webpayserver/initTransaction"; Map mapResponse = new HashMap(); - mapResponse.put("token", testToken); + mapResponse.put(ApiConstants.TOKEN_TEXT, testToken); Gson gson = new GsonBuilder().create(); String jsonResponse = gson.toJson(mapResponse); diff --git a/src/test/java/webpayplus/WebpayPlusDeferredTest.java b/src/test/java/webpayplus/WebpayPlusDeferredTest.java index ffbc8cf7..28c39fcd 100644 --- a/src/test/java/webpayplus/WebpayPlusDeferredTest.java +++ b/src/test/java/webpayplus/WebpayPlusDeferredTest.java @@ -57,7 +57,7 @@ public void create() throws IOException, TransactionCreateException { String urlResponse = "https://webpay3gint.transbank.cl/webpayserver/initTransaction"; Map mapResponse = new HashMap(); - mapResponse.put("token", testToken); + mapResponse.put(ApiConstants.TOKEN_TEXT, testToken); mapResponse.put("url", urlResponse); Gson gson = new GsonBuilder().create(); diff --git a/src/test/java/webpayplus/WebpayPlusMallDeferredTest.java b/src/test/java/webpayplus/WebpayPlusMallDeferredTest.java index accda33e..4a1a12ab 100644 --- a/src/test/java/webpayplus/WebpayPlusMallDeferredTest.java +++ b/src/test/java/webpayplus/WebpayPlusMallDeferredTest.java @@ -68,7 +68,7 @@ public void create() throws IOException, TransactionCreateException { String urlResponse = "https://webpay3gint.transbank.cl/webpayserver/initTransaction"; Map mapResponse = new HashMap(); - mapResponse.put("token", testToken); + mapResponse.put(ApiConstants.TOKEN_TEXT, testToken); mapResponse.put("url", urlResponse); Gson gson = new GsonBuilder().create(); diff --git a/src/test/java/webpayplus/WebpayPlusMallTest.java b/src/test/java/webpayplus/WebpayPlusMallTest.java index 43a1b02e..c3199196 100644 --- a/src/test/java/webpayplus/WebpayPlusMallTest.java +++ b/src/test/java/webpayplus/WebpayPlusMallTest.java @@ -73,7 +73,7 @@ public void create() throws IOException, TransactionCreateException { String urlResponse = "https://webpay3gint.transbank.cl/webpayserver/initTransaction"; Map mapResponse = new HashMap(); - mapResponse.put("token", testToken); + mapResponse.put(ApiConstants.TOKEN_TEXT, testToken); mapResponse.put("url", urlResponse); Gson gson = new GsonBuilder().create(); diff --git a/src/test/java/webpayplus/WebpayPlusTest.java b/src/test/java/webpayplus/WebpayPlusTest.java index 03e135ad..158c000c 100644 --- a/src/test/java/webpayplus/WebpayPlusTest.java +++ b/src/test/java/webpayplus/WebpayPlusTest.java @@ -66,7 +66,7 @@ public void create() throws IOException, TransactionCreateException { String urlResponse = "https://webpay3gint.transbank.cl/webpayserver/initTransaction"; Map mapResponse = new HashMap(); - mapResponse.put("token", testToken); + mapResponse.put(ApiConstants.TOKEN_TEXT, testToken); mapResponse.put("url", urlResponse); Gson gson = new GsonBuilder().create(); From 83268c08588a7b42d9e87bc476659d1128232f0d Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Wed, 20 Mar 2024 11:50:06 -0400 Subject: [PATCH 15/26] refactor: add type check for handleResponse --- src/main/java/cl/transbank/util/HttpUtilImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/cl/transbank/util/HttpUtilImpl.java b/src/main/java/cl/transbank/util/HttpUtilImpl.java index 7e850668..53d64c19 100644 --- a/src/main/java/cl/transbank/util/HttpUtilImpl.java +++ b/src/main/java/cl/transbank/util/HttpUtilImpl.java @@ -228,8 +228,10 @@ private void handleResponse( Object errorMessage = "Could not obtain a response message from Webpay API"; if (responseBody != null) { - final Map errorMap = getJsonUtil() + @SuppressWarnings("unchecked") + final Map errorMap = (Map) getJsonUtil() .jsonDecode(responseBody, HashMap.class); + errorMessage = errorMap.get("error_message"); } From 53bed13459b3d5d4d4a2b20e2e051dfb06ac6292 Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Thu, 21 Mar 2024 08:30:52 -0400 Subject: [PATCH 16/26] refactor: use build pattern to avoid methods with more than 4 arguments --- .../patpass/PatpassByWebpayTransaction.java | 15 ++- .../requests/TransactionCreateRequest.java | 107 ++++++++++++++---- 2 files changed, 95 insertions(+), 27 deletions(-) diff --git a/src/main/java/cl/transbank/patpass/PatpassByWebpayTransaction.java b/src/main/java/cl/transbank/patpass/PatpassByWebpayTransaction.java index 3d090d5c..f8a5baf0 100644 --- a/src/main/java/cl/transbank/patpass/PatpassByWebpayTransaction.java +++ b/src/main/java/cl/transbank/patpass/PatpassByWebpayTransaction.java @@ -26,8 +26,19 @@ public PatpassByWebpayTransactionCreateResponse create( String expirationDate, String commerceMail, boolean ufFlag) throws IOException, TransactionCreateException { String endpoint = String.format("%s/transactions", ApiConstants.WEBPAY_ENDPOINT); final TransactionCreateRequest request = new TransactionCreateRequest(buyOrder, sessionId, amount, returnUrl); - request.setDetails(serviceId, cardHolderId, cardHolderName, cardHolderLastName1, cardHolderLastName2, - cardHolderMail, cellphoneNumber, expirationDate, commerceMail, ufFlag); + TransactionCreateRequest.Detail transactionDetails = request.new Detail(); + transactionDetails.setServiceId(serviceId); + transactionDetails.setCardHolderId(cardHolderId); + transactionDetails.setCardHolderName(cardHolderName); + transactionDetails.setCardHolderLastName1(cardHolderLastName1); + transactionDetails.setCardHolderLastName2(cardHolderLastName2); + transactionDetails.setCardHolderMail(cardHolderMail); + transactionDetails.setCellphoneNumber(cellphoneNumber); + transactionDetails.setExpirationDate(expirationDate); + transactionDetails.setCommerceMail(commerceMail); + transactionDetails.setUfFlag(ufFlag); + + request.setDetails(transactionDetails); try { return WebpayApiResource.execute(endpoint, HttpUtil.RequestMethod.POST, request, options, PatpassByWebpayTransactionCreateResponse.class); } catch (TransbankException e) { diff --git a/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java b/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java index 0f49a1e7..75e29846 100644 --- a/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java +++ b/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java @@ -41,31 +41,8 @@ public class TransactionCreateRequest extends WebpayApiRequest { * @param ufFlag The UF flag. */ - public void setDetails( - String serviceId, - String cardHolderId, - String cardHolderName, - String cardHolderLastName1, - String cardHolderLastName2, - String cardHolderMail, - String cellphoneNumber, - String expirationDate, - String commerceMail, - boolean ufFlag - ) { - wpmDetail = - new Detail( - serviceId, - cardHolderId, - cardHolderName, - cardHolderLastName1, - cardHolderLastName2, - cardHolderMail, - cellphoneNumber, - expirationDate, - commerceMail, - ufFlag - ); + public void setDetails(Detail detail) { + wpmDetail = detail; } /** @@ -88,5 +65,85 @@ public class Detail { private String expirationDate; private String commerceMail; private boolean ufFlag; + + public String getServiceId() { + return serviceId; + } + + public void setServiceId(String serviceId) { + this.serviceId = serviceId; + } + + public String getCardHolderId() { + return cardHolderId; + } + + public void setCardHolderId(String cardHolderId) { + this.cardHolderId = cardHolderId; + } + + public String getCardHolderName() { + return cardHolderName; + } + + public void setCardHolderName(String cardHolderName) { + this.cardHolderName = cardHolderName; + } + + public String getCardHolderLastName1() { + return cardHolderLastName1; + } + + public void setCardHolderLastName1(String cardHolderLastName1) { + this.cardHolderLastName1 = cardHolderLastName1; + } + + public String getCardHolderLastName2() { + return cardHolderLastName2; + } + + public void setCardHolderLastName2(String cardHolderLastName2) { + this.cardHolderLastName2 = cardHolderLastName2; + } + + public String getCardHolderMail() { + return cardHolderMail; + } + + public void setCardHolderMail(String cardHolderMail) { + this.cardHolderMail = cardHolderMail; + } + + public String getCellphoneNumber() { + return cellphoneNumber; + } + + public void setCellphoneNumber(String cellphoneNumber) { + this.cellphoneNumber = cellphoneNumber; + } + + public String getExpirationDate() { + return expirationDate; + } + + public void setExpirationDate(String expirationDate) { + this.expirationDate = expirationDate; + } + + public String getCommerceMail() { + return commerceMail; + } + + public void setCommerceMail(String commerceMail) { + this.commerceMail = commerceMail; + } + + public boolean isUfFlag() { + return ufFlag; + } + + public void setUfFlag(boolean ufFlag) { + this.ufFlag = ufFlag; + } } } From 1d7f31f903a87daddc0e8d31b2cec2dd5d78cc1c Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Thu, 21 Mar 2024 08:31:18 -0400 Subject: [PATCH 17/26] refactor: remove unused argument and add new private constant --- .../java/cl/transbank/util/HttpUtilImpl.java | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/main/java/cl/transbank/util/HttpUtilImpl.java b/src/main/java/cl/transbank/util/HttpUtilImpl.java index 53d64c19..3f0b1aae 100644 --- a/src/main/java/cl/transbank/util/HttpUtilImpl.java +++ b/src/main/java/cl/transbank/util/HttpUtilImpl.java @@ -28,6 +28,7 @@ public class HttpUtilImpl implements HttpUtil { private static Logger logger = Logger.getLogger(HttpUtilImpl.class.getName()); private static volatile HttpUtilImpl instance; + private static final String ERROR_MESSAGE = "error_message"; @Setter @Getter(AccessLevel.PRIVATE) @@ -45,7 +46,7 @@ public T request( Class clazz ) throws IOException, WebpayException { final String jsonIn = getJsonUtil().jsonEncode(request); - final String jsonOut = request(url, method, jsonIn, headers, true); + final String jsonOut = request(url, method, jsonIn, headers); return getJsonUtil().jsonDecode(jsonOut, clazz); } @@ -57,7 +58,7 @@ public List requestList( Class clazz ) throws IOException, WebpayException { final String jsonIn = getJsonUtil().jsonEncode(request); - final String jsonOut = request(url, method, jsonIn, headers, true); + final String jsonOut = request(url, method, jsonIn, headers); return getJsonUtil().jsonDecodeToList(jsonOut, clazz); } @@ -105,21 +106,6 @@ public String request( return request(url, method, query, null, headers); } - /** - * Sends a HTTP request and returns the response. - * This method uses the provided URL and request method to send the request. - * It uses default headers, a default response type, and does not send a request body. - */ - public String request( - @NonNull URL url, - RequestMethod method, - String query, - Map headers, - boolean useException - ) throws IOException, WebpayException { - return request(url, method, query, null, headers); - } - /** * Sends a HTTP request and returns the response. * This method uses the provided URL to send the request. @@ -232,7 +218,7 @@ private void handleResponse( final Map errorMap = (Map) getJsonUtil() .jsonDecode(responseBody, HashMap.class); - errorMessage = errorMap.get("error_message"); + errorMessage = errorMap.get(ERROR_MESSAGE); } if (null == errorMessage) errorMessage = @@ -246,10 +232,9 @@ private void handleResponse( if (responseBody != null && !responseBody.trim().startsWith("[")) { final Map tempMap = getJsonUtil().jsonDecode(responseBody, HashMap.class); if ( - tempMap.containsKey("error_message") && - tempMap.get("error_message") != null + tempMap.containsKey(ERROR_MESSAGE) && tempMap.get(ERROR_MESSAGE) != null ) { - throw new WebpayException(tempMap.get("error_message").toString()); + throw new WebpayException(tempMap.get(ERROR_MESSAGE).toString()); } } } From a4befe76a14ac13267d9f706a1cbc4054116e6ec Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Thu, 21 Mar 2024 08:47:14 -0400 Subject: [PATCH 18/26] docs: javadocs adjustments --- .../cl/transbank/common/IntegrationTypeHelper.java | 4 ++++ .../cl/transbank/exception/TransbankException.java | 12 ++++++++++++ src/main/java/cl/transbank/util/HttpUtilImpl.java | 1 + .../java/cl/transbank/util/WebpayApiResource.java | 5 +++++ 4 files changed, 22 insertions(+) diff --git a/src/main/java/cl/transbank/common/IntegrationTypeHelper.java b/src/main/java/cl/transbank/common/IntegrationTypeHelper.java index 0b73d78d..42b5719c 100644 --- a/src/main/java/cl/transbank/common/IntegrationTypeHelper.java +++ b/src/main/java/cl/transbank/common/IntegrationTypeHelper.java @@ -7,6 +7,8 @@ public class IntegrationTypeHelper { /** * Returns the Webpay integration type based on the provided integration type. + * @param integrationType The integration type. + * @return The Webpay integration URL. */ public static String getWebpayIntegrationType( IntegrationType integrationType @@ -27,6 +29,8 @@ public static String getWebpayIntegrationType( /** * Returns the Patpass integration type based on the provided integration type. + * @param integrationType The integration type. + * @return The Patpass integration URL. */ public static String getPatpassIntegrationType( IntegrationType integrationType diff --git a/src/main/java/cl/transbank/exception/TransbankException.java b/src/main/java/cl/transbank/exception/TransbankException.java index 61d04c49..f2e63dfd 100644 --- a/src/main/java/cl/transbank/exception/TransbankException.java +++ b/src/main/java/cl/transbank/exception/TransbankException.java @@ -27,6 +27,8 @@ public TransbankException(String message) { /** * Constructs a new TransbankException with the specified detail message and error code. + * @param code The error code. + * @param message The detail message. */ public TransbankException(int code, String message) { super(message); @@ -35,6 +37,8 @@ public TransbankException(int code, String message) { /** * Constructs a new TransbankException with the specified detail message, error code, and cause. + * @param code The error code. + * @param message The detail message. */ public TransbankException(int code, String message, Throwable cause) { super(message, cause); @@ -43,6 +47,7 @@ public TransbankException(int code, String message, Throwable cause) { /** * Constructs a new TransbankException with the specified cause. + * @param cause The cause. */ public TransbankException(Throwable cause) { super(cause); @@ -50,6 +55,8 @@ public TransbankException(Throwable cause) { /** * Constructs a new TransbankException with the specified Ccode and cause. + * @param code The error code. + * @param cause The cause. */ public TransbankException(int code, Throwable cause) { super(cause); @@ -58,6 +65,11 @@ public TransbankException(int code, Throwable cause) { /** * Constructs a new TransbankException with the specified error code and cause. + * @param code The error code. + * @param message The detail message. + * @param cause The cause. + * @param enableSuppression Whether or not suppression is enabled or disabled. + * @param writableStackTrace Whether or not the stack trace should be writable. */ public TransbankException( int code, diff --git a/src/main/java/cl/transbank/util/HttpUtilImpl.java b/src/main/java/cl/transbank/util/HttpUtilImpl.java index 3f0b1aae..0cc56f5a 100644 --- a/src/main/java/cl/transbank/util/HttpUtilImpl.java +++ b/src/main/java/cl/transbank/util/HttpUtilImpl.java @@ -361,6 +361,7 @@ private HttpUtilImpl() { /** * Returns the singleton instance of HttpUtilImpl. * If the instance does not exist, it is created. + * @return The singleton instance of HttpUtilImpl. */ public static HttpUtilImpl getInstance() { if (null == instance) synchronized (HttpUtilImpl.class) { diff --git a/src/main/java/cl/transbank/util/WebpayApiResource.java b/src/main/java/cl/transbank/util/WebpayApiResource.java index 92e0c571..7237daa7 100644 --- a/src/main/java/cl/transbank/util/WebpayApiResource.java +++ b/src/main/java/cl/transbank/util/WebpayApiResource.java @@ -49,6 +49,7 @@ public static Map buildHeaders(Options options) { * @param options The options for the request. * @param clazz The class of the response. * @return The response to the request. + * @throws TransbankException If an error occurs during the request. */ public static T execute( final String endpoint, @@ -66,6 +67,7 @@ public static T execute( * @param request The request body. * @param options The options for the request. * @return The response to the request. + * @throws TransbankException If an error occurs during the request. */ public static T execute( final String endpoint, @@ -84,6 +86,7 @@ public static T execute( * @param options The options for the request. * @param clazz The class of the response. * @return The response to the request. + * @throws TransbankException If an error occurs during the request. */ public static T execute( final String endpoint, @@ -130,6 +133,7 @@ public static T execute( * @param options The options for the request. * @param clazz The class of the response. * @return A list of responses to the request. + * @throws TransbankException If an error occurs during the request. */ public static List executeToList( final String endpoint, @@ -148,6 +152,7 @@ public static List executeToList( * @param options The options for the request. * @param clazz The class of the response. * @return A list of responses to the request. + * @throws TransbankException If an error occurs during the request. */ public static List executeToList( final String endpoint, From bd63216683845a0047e5560b3d770d932939d21a Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Thu, 21 Mar 2024 09:30:42 -0400 Subject: [PATCH 19/26] docs: add more javadocs on missing params --- .../transbank/exception/TransbankException.java | 1 + .../cl/transbank/util/WebpayApiResource.java | 10 ++++++++++ .../exception/InscriptionFinishException.java | 2 ++ .../exception/TransactionCreateException.java | 2 ++ .../exception/TransbankHttpApiException.java | 4 ++++ .../webpay/exception/WebpayException.java | 4 ++++ .../transaccioncompleta/FullTransaction.java | 17 +++++++++++++++++ 7 files changed, 40 insertions(+) diff --git a/src/main/java/cl/transbank/exception/TransbankException.java b/src/main/java/cl/transbank/exception/TransbankException.java index f2e63dfd..7ada3afd 100644 --- a/src/main/java/cl/transbank/exception/TransbankException.java +++ b/src/main/java/cl/transbank/exception/TransbankException.java @@ -19,6 +19,7 @@ public TransbankException() { /** * Constructs a new TransbankException with the specified detail message. + * @param message The detail message. */ public TransbankException(String message) { super(message); diff --git a/src/main/java/cl/transbank/util/WebpayApiResource.java b/src/main/java/cl/transbank/util/WebpayApiResource.java index 7237daa7..4a7f562c 100644 --- a/src/main/java/cl/transbank/util/WebpayApiResource.java +++ b/src/main/java/cl/transbank/util/WebpayApiResource.java @@ -44,12 +44,14 @@ public static Map buildHeaders(Options options) { /** * Executes a Webpay API request. + * @param The type of the response. * @param endpoint The endpoint for the request. * @param method The HTTP method for the request. * @param options The options for the request. * @param clazz The class of the response. * @return The response to the request. * @throws TransbankException If an error occurs during the request. + * @throws IOException If an error occurs during the request. */ public static T execute( final String endpoint, @@ -62,12 +64,14 @@ public static T execute( /** * Executes a Webpay API request with a request body. + * @param The type of the response. * @param endpoint The endpoint for the request. * @param method The HTTP method for the request. * @param request The request body. * @param options The options for the request. * @return The response to the request. * @throws TransbankException If an error occurs during the request. + * @throws IOException If an error occurs during the request. */ public static T execute( final String endpoint, @@ -80,6 +84,7 @@ public static T execute( /** * Executes a Webpay API request with a request body. + * @param The type of the response. * @param endpoint The endpoint for the request. * @param method The HTTP method for the request. * @param request The request body. @@ -87,6 +92,7 @@ public static T execute( * @param clazz The class of the response. * @return The response to the request. * @throws TransbankException If an error occurs during the request. + * @throws IOException If an error occurs during the request. */ public static T execute( final String endpoint, @@ -128,12 +134,14 @@ public static T execute( /** * Executes a Webpay API request and returns a list of responses. + * @param The type of the response. * @param endpoint The endpoint for the request. * @param method The HTTP method for the request. * @param options The options for the request. * @param clazz The class of the response. * @return A list of responses to the request. * @throws TransbankException If an error occurs during the request. + * @throws IOException If an error occurs during the request. */ public static List executeToList( final String endpoint, @@ -146,6 +154,7 @@ public static List executeToList( /** * Executes a Webpay API request with a request body and returns a list of responses. + * @param The type of the response. * @param endpoint The endpoint for the request. * @param method The HTTP method for the request. * @param request The request body. @@ -153,6 +162,7 @@ public static List executeToList( * @param clazz The class of the response. * @return A list of responses to the request. * @throws TransbankException If an error occurs during the request. + * @throws IOException If an error occurs during the request. */ public static List executeToList( final String endpoint, diff --git a/src/main/java/cl/transbank/webpay/exception/InscriptionFinishException.java b/src/main/java/cl/transbank/webpay/exception/InscriptionFinishException.java index 4da9ba3c..1d7e0c20 100644 --- a/src/main/java/cl/transbank/webpay/exception/InscriptionFinishException.java +++ b/src/main/java/cl/transbank/webpay/exception/InscriptionFinishException.java @@ -12,6 +12,7 @@ public InscriptionFinishException() {} /** * Constructs a new InscriptionFinishException with the specified cause. + * @param e Exception that caused the error. */ public InscriptionFinishException(Exception e) { super(e); @@ -19,6 +20,7 @@ public InscriptionFinishException(Exception e) { /** * Constructs a new InscriptionFinishException with the specified detail message. + * @param message The detail message. */ public InscriptionFinishException(String message) { super(message); diff --git a/src/main/java/cl/transbank/webpay/exception/TransactionCreateException.java b/src/main/java/cl/transbank/webpay/exception/TransactionCreateException.java index 4db87111..6a4b8f70 100644 --- a/src/main/java/cl/transbank/webpay/exception/TransactionCreateException.java +++ b/src/main/java/cl/transbank/webpay/exception/TransactionCreateException.java @@ -14,6 +14,7 @@ public TransactionCreateException() { /** * Constructs a new TransactionCreateException with the specified cause. + * @param e Exception that caused the error. */ public TransactionCreateException(Exception e) { super(e); @@ -21,6 +22,7 @@ public TransactionCreateException(Exception e) { /** * Constructs a new TransactionCreateException with the specified detail message. + * @param message The detail message. */ public TransactionCreateException(String message) { super(message); diff --git a/src/main/java/cl/transbank/webpay/exception/TransbankHttpApiException.java b/src/main/java/cl/transbank/webpay/exception/TransbankHttpApiException.java index 3e44491a..88f16c34 100644 --- a/src/main/java/cl/transbank/webpay/exception/TransbankHttpApiException.java +++ b/src/main/java/cl/transbank/webpay/exception/TransbankHttpApiException.java @@ -12,6 +12,7 @@ public TransbankHttpApiException() {} /** * Constructs a new TransbankHttpApiException with the specified cause. + * @param e Exception that caused the error. */ public TransbankHttpApiException(Exception e) { super(e); @@ -19,6 +20,7 @@ public TransbankHttpApiException(Exception e) { /** * Constructs a new TransbankHttpApiException with the specified detail message. + * @param message The detail message. */ public TransbankHttpApiException(String message) { super(message); @@ -26,6 +28,8 @@ public TransbankHttpApiException(String message) { /** * Constructs a new TransbankHttpApiException with the specified detail message and error code. + * @param code The error code. + * @param message The detail message. */ public TransbankHttpApiException(int code, String message) { super(code, message); diff --git a/src/main/java/cl/transbank/webpay/exception/WebpayException.java b/src/main/java/cl/transbank/webpay/exception/WebpayException.java index b5ebec88..d1e5115d 100644 --- a/src/main/java/cl/transbank/webpay/exception/WebpayException.java +++ b/src/main/java/cl/transbank/webpay/exception/WebpayException.java @@ -16,6 +16,7 @@ public WebpayException() { /** * Constructs a new WebpayException with the specified cause. + * @param e Exception that caused the error. */ public WebpayException(Exception e) { super(e); @@ -23,6 +24,7 @@ public WebpayException(Exception e) { /** * Constructs a new WebpayException with the specified detail message. + * @param message The detail message. */ public WebpayException(String message) { super(message); @@ -30,6 +32,8 @@ public WebpayException(String message) { /** * Constructs a new WebpayException with the specified detail message and error code. + * @param code The error code. + * @param message The detail message. */ public WebpayException(int code, String message) { super(code, message); diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java index c41c24a1..f1459553 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/FullTransaction.java @@ -119,6 +119,8 @@ public FullTransactionCreateResponse create( * @param token The token of the transaction. * @param installmentsNumber The number of installments. * @return The response of the installments creation process. + * @throws TransactionInstallmentException If there's an error in the creation of the installments. + * @throws IOException If there's an error in the communication with the server. */ public FullTransactionInstallmentResponse installments( String token, @@ -153,7 +155,12 @@ public FullTransactionInstallmentResponse installments( /** * Commits the transaction. * @param token The token of the transaction. + * @param idQueryInstallments The id of the query installments. + * @param deferredPeriodIndex The index of the deferred period. + * @param gracePeriod The grace period. * @return The response of the commit process. + * @throws IOException If there's an error in the communication with the server. + * @throws TransactionCommitException If there's an error in the commit process. */ public FullTransactionCommitResponse commit( String token, @@ -193,6 +200,8 @@ public FullTransactionCommitResponse commit( * Gets the status of the transaction. * @param token The token of the transaction. * @return The status of the transaction. + * @throws IOException If there's an error in the communication with the server. + * @throws TransactionStatusException If there's an error in the status process. */ public FullTransactionStatusResponse status(String token) throws IOException, TransactionStatusException { @@ -223,6 +232,8 @@ public FullTransactionStatusResponse status(String token) * @param token The token of the transaction. * @param amount The amount to be refunded. * @return The response of the refund process. + * @throws IOException If there's an error in the communication with the server. + * @throws TransactionRefundException If there's an error in the refund process. */ public FullTransactionRefundResponse refund(String token, double amount) throws IOException, TransactionRefundException { @@ -257,6 +268,8 @@ public FullTransactionRefundResponse refund(String token, double amount) * @param authorizationCode The authorization code of the transaction. * @param captureAmount The amount to be captured. * @return The response of the capture process. + * @throws IOException If there's an error in the communication with the server. + * @throws TransactionCaptureException If there's an error in the capture process. */ public FullTransactionCaptureResponse capture( String token, @@ -311,6 +324,8 @@ public FullTransactionCaptureResponse capture( /** * Configures the transaction for integration environment. + * @param commerceCode The commerce code. + * @param apiKey The api key. */ public static void configureForIntegration( String commerceCode, @@ -322,6 +337,8 @@ public static void configureForIntegration( /** * Configures the transaction for production environment. + * @param commerceCode The commerce code. + * @param apiKey The api key. */ public static void configureForProduction( String commerceCode, From 16691cfce18a12e0a79004c2524398f9cc9b721a Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Thu, 21 Mar 2024 09:56:58 -0400 Subject: [PATCH 20/26] docs: more javadocs adjustments --- .../cl/transbank/exception/TransbankException.java | 1 + .../patpass/requests/TransactionCreateRequest.java | 11 +---------- .../responses/PatpassTransactionCreateDetails.java | 1 + .../MallFullTransactionInstallmentsResponse.java | 8 ++++++++ 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/cl/transbank/exception/TransbankException.java b/src/main/java/cl/transbank/exception/TransbankException.java index 7ada3afd..8f4b56d6 100644 --- a/src/main/java/cl/transbank/exception/TransbankException.java +++ b/src/main/java/cl/transbank/exception/TransbankException.java @@ -40,6 +40,7 @@ public TransbankException(int code, String message) { * Constructs a new TransbankException with the specified detail message, error code, and cause. * @param code The error code. * @param message The detail message. + * @param cause The cause. */ public TransbankException(int code, String message, Throwable cause) { super(message, cause); diff --git a/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java b/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java index 75e29846..1c7d303b 100644 --- a/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java +++ b/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java @@ -29,16 +29,7 @@ public class TransactionCreateRequest extends WebpayApiRequest { /** * Sets the details for the transaction. - * @param serviceId The service ID. - * @param cardHolderId The card holder ID. - * @param cardHolderName The card holder name. - * @param cardHolderLastName1 The card holder's first last name. - * @param cardHolderLastName2 The card holder's second last name. - * @param cardHolderMail The card holder's mail. - * @param cellphoneNumber The cellphone number. - * @param expirationDate The expiration date. - * @param commerceMail The commerce mail. - * @param ufFlag The UF flag. + * @param detail The details for the transaction. */ public void setDetails(Detail detail) { diff --git a/src/main/java/cl/transbank/patpass/responses/PatpassTransactionCreateDetails.java b/src/main/java/cl/transbank/patpass/responses/PatpassTransactionCreateDetails.java index 3575be33..ea55339a 100644 --- a/src/main/java/cl/transbank/patpass/responses/PatpassTransactionCreateDetails.java +++ b/src/main/java/cl/transbank/patpass/responses/PatpassTransactionCreateDetails.java @@ -19,6 +19,7 @@ private PatpassTransactionCreateDetails() {} /** * Configures the environment for mock testing. + * @return A new PatpassTransactionCreateDetails. */ public static PatpassTransactionCreateDetails build() { return new PatpassTransactionCreateDetails(); diff --git a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionInstallmentsResponse.java b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionInstallmentsResponse.java index 9554ed49..524f6e58 100644 --- a/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionInstallmentsResponse.java +++ b/src/main/java/cl/transbank/webpay/transaccioncompleta/responses/MallFullTransactionInstallmentsResponse.java @@ -15,6 +15,7 @@ private MallFullTransactionInstallmentsResponse() {} /** * Builds a new MallFullTransactionInstallmentsResponse. + * @return A new MallFullTransactionInstallmentsResponse. */ public static MallFullTransactionInstallmentsResponse build() { return new MallFullTransactionInstallmentsResponse(); @@ -22,6 +23,8 @@ public static MallFullTransactionInstallmentsResponse build() { /** * Builds a new MallFullTransactionInstallmentsResponse with the provided list of responses. + * @param response The list of responses. + * @return A new MallFullTransactionInstallmentsResponse. */ public static MallFullTransactionInstallmentsResponse build( MallFullTransactionInstallmentResponse response @@ -31,6 +34,8 @@ public static MallFullTransactionInstallmentsResponse build( /** * Adds a new item to the response list. + * @param response The response to add. + * @return The same MallFullTransactionInstallmentsResponse instance. */ public MallFullTransactionInstallmentsResponse add( MallFullTransactionInstallmentResponse response @@ -41,6 +46,8 @@ public MallFullTransactionInstallmentsResponse add( /** * Removes an item from the response list. + * @param response The response to remove. + * @return True if the response was removed, false otherwise. */ public boolean remove(MallFullTransactionInstallmentResponse response) { return getResponseList().remove(response); @@ -48,6 +55,7 @@ public boolean remove(MallFullTransactionInstallmentResponse response) { /** * Returns the response list. + * @return The response list. */ public List getResponseList() { return Collections.unmodifiableList(responseList); From cc8475748013320a22a6be2580404690aebcf542 Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Thu, 21 Mar 2024 09:59:40 -0400 Subject: [PATCH 21/26] refactor: use lombok to generate getters and setters --- .../requests/TransactionCreateRequest.java | 80 ------------------- 1 file changed, 80 deletions(-) diff --git a/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java b/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java index 1c7d303b..8219efca 100644 --- a/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java +++ b/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java @@ -56,85 +56,5 @@ public class Detail { private String expirationDate; private String commerceMail; private boolean ufFlag; - - public String getServiceId() { - return serviceId; - } - - public void setServiceId(String serviceId) { - this.serviceId = serviceId; - } - - public String getCardHolderId() { - return cardHolderId; - } - - public void setCardHolderId(String cardHolderId) { - this.cardHolderId = cardHolderId; - } - - public String getCardHolderName() { - return cardHolderName; - } - - public void setCardHolderName(String cardHolderName) { - this.cardHolderName = cardHolderName; - } - - public String getCardHolderLastName1() { - return cardHolderLastName1; - } - - public void setCardHolderLastName1(String cardHolderLastName1) { - this.cardHolderLastName1 = cardHolderLastName1; - } - - public String getCardHolderLastName2() { - return cardHolderLastName2; - } - - public void setCardHolderLastName2(String cardHolderLastName2) { - this.cardHolderLastName2 = cardHolderLastName2; - } - - public String getCardHolderMail() { - return cardHolderMail; - } - - public void setCardHolderMail(String cardHolderMail) { - this.cardHolderMail = cardHolderMail; - } - - public String getCellphoneNumber() { - return cellphoneNumber; - } - - public void setCellphoneNumber(String cellphoneNumber) { - this.cellphoneNumber = cellphoneNumber; - } - - public String getExpirationDate() { - return expirationDate; - } - - public void setExpirationDate(String expirationDate) { - this.expirationDate = expirationDate; - } - - public String getCommerceMail() { - return commerceMail; - } - - public void setCommerceMail(String commerceMail) { - this.commerceMail = commerceMail; - } - - public boolean isUfFlag() { - return ufFlag; - } - - public void setUfFlag(boolean ufFlag) { - this.ufFlag = ufFlag; - } } } From 8eaa05d07fe6ce7d8107563bb723701cb934f17a Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Fri, 22 Mar 2024 15:56:41 -0400 Subject: [PATCH 22/26] refactor: add final to variable on TransbankException --- src/main/java/cl/transbank/exception/TransbankException.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/cl/transbank/exception/TransbankException.java b/src/main/java/cl/transbank/exception/TransbankException.java index 8f4b56d6..1c77938f 100644 --- a/src/main/java/cl/transbank/exception/TransbankException.java +++ b/src/main/java/cl/transbank/exception/TransbankException.java @@ -8,13 +8,14 @@ public class TransbankException extends Exception { @Getter - private int code; + private final int code; /** * Constructs a new TransbankException with no detail message. */ public TransbankException() { super(); + this.code = -1; } /** @@ -53,6 +54,7 @@ public TransbankException(int code, String message, Throwable cause) { */ public TransbankException(Throwable cause) { super(cause); + this.code = -1; } /** From bfcb87827c84ebf1000d8e0a076da156131e0bb4 Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Fri, 22 Mar 2024 15:57:04 -0400 Subject: [PATCH 23/26] Revert "refactor: use build pattern to avoid methods with more than 4 arguments" This reverts commit 53bed13459b3d5d4d4a2b20e2e051dfb06ac6292. --- .../patpass/PatpassByWebpayTransaction.java | 15 ++--------- .../requests/TransactionCreateRequest.java | 27 +++++++++++++++++-- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/main/java/cl/transbank/patpass/PatpassByWebpayTransaction.java b/src/main/java/cl/transbank/patpass/PatpassByWebpayTransaction.java index f8a5baf0..3d090d5c 100644 --- a/src/main/java/cl/transbank/patpass/PatpassByWebpayTransaction.java +++ b/src/main/java/cl/transbank/patpass/PatpassByWebpayTransaction.java @@ -26,19 +26,8 @@ public PatpassByWebpayTransactionCreateResponse create( String expirationDate, String commerceMail, boolean ufFlag) throws IOException, TransactionCreateException { String endpoint = String.format("%s/transactions", ApiConstants.WEBPAY_ENDPOINT); final TransactionCreateRequest request = new TransactionCreateRequest(buyOrder, sessionId, amount, returnUrl); - TransactionCreateRequest.Detail transactionDetails = request.new Detail(); - transactionDetails.setServiceId(serviceId); - transactionDetails.setCardHolderId(cardHolderId); - transactionDetails.setCardHolderName(cardHolderName); - transactionDetails.setCardHolderLastName1(cardHolderLastName1); - transactionDetails.setCardHolderLastName2(cardHolderLastName2); - transactionDetails.setCardHolderMail(cardHolderMail); - transactionDetails.setCellphoneNumber(cellphoneNumber); - transactionDetails.setExpirationDate(expirationDate); - transactionDetails.setCommerceMail(commerceMail); - transactionDetails.setUfFlag(ufFlag); - - request.setDetails(transactionDetails); + request.setDetails(serviceId, cardHolderId, cardHolderName, cardHolderLastName1, cardHolderLastName2, + cardHolderMail, cellphoneNumber, expirationDate, commerceMail, ufFlag); try { return WebpayApiResource.execute(endpoint, HttpUtil.RequestMethod.POST, request, options, PatpassByWebpayTransactionCreateResponse.class); } catch (TransbankException e) { diff --git a/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java b/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java index 8219efca..5b074446 100644 --- a/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java +++ b/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java @@ -32,8 +32,31 @@ public class TransactionCreateRequest extends WebpayApiRequest { * @param detail The details for the transaction. */ - public void setDetails(Detail detail) { - wpmDetail = detail; + public void setDetails( + String serviceId, + String cardHolderId, + String cardHolderName, + String cardHolderLastName1, + String cardHolderLastName2, + String cardHolderMail, + String cellphoneNumber, + String expirationDate, + String commerceMail, + boolean ufFlag + ) { + wpmDetail = + new Detail( + serviceId, + cardHolderId, + cardHolderName, + cardHolderLastName1, + cardHolderLastName2, + cardHolderMail, + cellphoneNumber, + expirationDate, + commerceMail, + ufFlag + ); } /** From 528e4bf7d00d2ead64f72c4abd3e42a502d92faf Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Fri, 22 Mar 2024 16:05:33 -0400 Subject: [PATCH 24/26] docs: revert previous javadocs for setDetails on TransactionCreateRequest --- .../patpass/requests/TransactionCreateRequest.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java b/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java index 5b074446..0f49a1e7 100644 --- a/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java +++ b/src/main/java/cl/transbank/patpass/requests/TransactionCreateRequest.java @@ -29,7 +29,16 @@ public class TransactionCreateRequest extends WebpayApiRequest { /** * Sets the details for the transaction. - * @param detail The details for the transaction. + * @param serviceId The service ID. + * @param cardHolderId The card holder ID. + * @param cardHolderName The card holder name. + * @param cardHolderLastName1 The card holder's first last name. + * @param cardHolderLastName2 The card holder's second last name. + * @param cardHolderMail The card holder's mail. + * @param cellphoneNumber The cellphone number. + * @param expirationDate The expiration date. + * @param commerceMail The commerce mail. + * @param ufFlag The UF flag. */ public void setDetails( From 4291ae3ff6d3f273ebe63c46aa6b600293964c77 Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Fri, 15 Mar 2024 15:15:04 -0400 Subject: [PATCH 25/26] docs: changelog updated for version 5.0.0 --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24c56ac5..296a6ef0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,15 @@ Todos los cambios notables a este proyecto serán documentados en este archivo. El formato está basado en [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) y este proyecto adhiere a [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [5.0.0] - 2024-03-15 + +### Changed +- Downgrade del API de la versión 1.3 a la versión 1.2 + +### Added +- Javadocs para todas las clases e interfaces publicas +- Mejora de manejo de excepciones SSL + ## [4.0.0] - 2022-09-01 ### Changed From f9a7670b377470023e19231b46903e3d509a4548 Mon Sep 17 00:00:00 2001 From: Carlos Tribiec Date: Fri, 15 Mar 2024 15:15:36 -0400 Subject: [PATCH 26/26] chore: add version 5.0.0 on pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d10ab6ca..d0e2b77a 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ com.github.transbankdevelopers transbank-sdk-java - 4.0.1-SNAPSHOT + 5.0.0 Transbank Java SDK 2018