diff --git a/.gitignore b/.gitignore
index 4513824..9b4ff1a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,8 @@ local.properties
.settings/
.project
.classpath
+.idea/
+*.iml
# Maven
diff --git a/api30.sdk/pom.xml b/api30.sdk/pom.xml
index 91c3e3b..ec622a7 100644
--- a/api30.sdk/pom.xml
+++ b/api30.sdk/pom.xml
@@ -4,7 +4,7 @@
br.cielo.cieloecommerce
api30.sdk
- 0.0.1-SNAPSHOT
+ 0.0.8-SNAPSHOT
jar
api30.sdk
@@ -32,4 +32,14 @@
4.5.2
+
+
+ nexus-snapshots
+ https://repos.evoluservices.com/repository/maven-snapshots/
+
+
+ nexus-releases
+ https://repos.evoluservices.com/repository/maven-releases/
+
+
diff --git a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/CieloEcommerce.java b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/CieloEcommerce.java
index 79b5ae7..67e3098 100644
--- a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/CieloEcommerce.java
+++ b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/CieloEcommerce.java
@@ -2,7 +2,7 @@
import cieloecommerce.sdk.Merchant;
import cieloecommerce.sdk.ecommerce.request.*;
-import org.apache.http.client.HttpClient;
+import org.apache.http.impl.client.CloseableHttpClient;
import java.io.IOException;
@@ -12,7 +12,7 @@
public class CieloEcommerce {
private final Merchant merchant;
private final Environment environment;
- private HttpClient httpClient;
+ private CloseableHttpClient httpClient;
/**
* Create an instance of CieloEcommerce choosing the environment where the
@@ -39,7 +39,7 @@ public CieloEcommerce(Merchant merchant) {
this(merchant, Environment.PRODUCTION);
}
- public void setHttpClient(HttpClient httpClient) {
+ public void setHttpClient(CloseableHttpClient httpClient) {
this.httpClient = httpClient;
}
@@ -69,7 +69,7 @@ public Sale createSale(Sale sale) throws IOException, CieloRequestException {
/**
* Create a card token to be stored on store
- *
+ *
* @param cardToken
* The credit card data
* @return The card token
@@ -113,6 +113,31 @@ public Sale querySale(String paymentId) throws IOException, CieloRequestExceptio
return sale;
}
+ /**
+ * Query a Sale on Cielo by paymentId
+ *
+ * @param paymentId
+ * The paymentId to be queried
+ * @return The Sale with authorization, tid, etc. returned by Cielo.
+ * @throws IOException
+ * @throws CieloRequestException
+ * if anything gets wrong.
+ * @see Error
+ * Codes
+ */
+ public QueryMerchantOrderResponse queryMerchantOrder(String merchantOrderId) throws IOException, CieloRequestException {
+ QueryMerchantOrderRequest querySaleRequest = new QueryMerchantOrderRequest(merchant, environment);
+
+ querySaleRequest.setHttpClient(httpClient);
+
+ QueryMerchantOrderResponse merchantOrder = querySaleRequest.execute(merchantOrderId);
+
+ return merchantOrder;
+ }
+
+
+
/**
* Query a RecurrentSale on Cielo by recurrentPaymentId
*
diff --git a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/DebitCard.java b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/DebitCard.java
new file mode 100644
index 0000000..805fde7
--- /dev/null
+++ b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/DebitCard.java
@@ -0,0 +1,71 @@
+package cieloecommerce.sdk.ecommerce;
+
+import com.google.gson.annotations.SerializedName;
+
+public class DebitCard {
+
+ @SerializedName("CardNumber")
+ private String cardNumber;
+
+ @SerializedName("Holder")
+ private String holder;
+
+ @SerializedName("ExpirationDate")
+ private String expirationDate;
+
+ @SerializedName("SecurityCode")
+ private String securityCode;
+
+ @SerializedName("Brand")
+ private String brand;
+
+ public DebitCard(String securityCode, String brand) {
+ setSecurityCode(securityCode);
+ setBrand(brand);
+ }
+
+ public String getBrand() {
+ return brand;
+ }
+
+ public DebitCard setBrand(String brand) {
+ this.brand = brand;
+ return this;
+ }
+
+ public String getCardNumber() {
+ return cardNumber;
+ }
+
+ public DebitCard setCardNumber(String cardNumber) {
+ this.cardNumber = cardNumber;
+ return this;
+ }
+
+ public String getExpirationDate() {
+ return expirationDate;
+ }
+
+ public DebitCard setExpirationDate(String expirationDate) {
+ this.expirationDate = expirationDate;
+ return this;
+ }
+
+ public String getHolder() {
+ return holder;
+ }
+
+ public DebitCard setHolder(String holder) {
+ this.holder = holder;
+ return this;
+ }
+
+ public String getSecurityCode() {
+ return securityCode;
+ }
+
+ public DebitCard setSecurityCode(String securityCode) {
+ this.securityCode = securityCode;
+ return this;
+ }
+}
diff --git a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/ExternalAuthentication.java b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/ExternalAuthentication.java
new file mode 100644
index 0000000..5ab3ff5
--- /dev/null
+++ b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/ExternalAuthentication.java
@@ -0,0 +1,81 @@
+package cieloecommerce.sdk.ecommerce;
+
+import com.google.gson.annotations.SerializedName;
+
+public class ExternalAuthentication {
+
+ @SerializedName("Cavv")
+ private String cavv;
+
+ @SerializedName("Xid")
+ private String xid;
+
+ @SerializedName("Eci")
+ private String eci;
+
+ @SerializedName("Version")
+ private String version;
+
+ @SerializedName("ReferenceID")
+ private String referenceId;
+
+ public ExternalAuthentication(String cavv,
+ String xid,
+ String eci,
+ String version,
+ String referenceId) {
+ this.cavv = cavv;
+ this.xid = xid;
+ this.eci = eci;
+ this.version = version;
+ this.referenceId = referenceId;
+ }
+
+ public ExternalAuthentication() {
+ }
+
+ public String getCavv() {
+ return cavv;
+ }
+
+ public ExternalAuthentication setCavv(String cavv) {
+ this.cavv = cavv;
+ return this;
+ }
+
+ public String getXid() {
+ return xid;
+ }
+
+ public ExternalAuthentication setXid(String xid) {
+ this.xid = xid;
+ return this;
+ }
+
+ public String getEci() {
+ return eci;
+ }
+
+ public ExternalAuthentication setEci(String eci) {
+ this.eci = eci;
+ return this;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public ExternalAuthentication setVersion(String version) {
+ this.version = version;
+ return this;
+ }
+
+ public String getReferenceId() {
+ return referenceId;
+ }
+
+ public ExternalAuthentication setReferenceId(String referenceId) {
+ this.referenceId = referenceId;
+ return this;
+ }
+}
diff --git a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/InitiatedTransactionIndicator.java b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/InitiatedTransactionIndicator.java
new file mode 100644
index 0000000..ba695be
--- /dev/null
+++ b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/InitiatedTransactionIndicator.java
@@ -0,0 +1,55 @@
+package cieloecommerce.sdk.ecommerce;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ *
+ * Identifica se a transação foi iniciada pelo titular do cartão ou pela loja. Válido apenas para
+ * bandeira Mastercard.
+ *
+ * Category: Categoria do indicador de início da transação.
+ * Valores possíveis:
+ * - “C1”: transação inciada pelo portador do cartão;
+ * - “M1”: transação recorrente ou parcelada iniciada pela loja;
+ * - “M2”: transação iniciada pela loja.
+ *
+ * Subcategory: Subcategoria do indicador.
+ * Valores possíveis:
+ *
+ * Se Category = “C1” ou “M1”
+ * - CredentialsOnFile
+ * - StandingOrder
+ * - Subscription
+ * - Installment
+ *
+ * Se Category = “M2”
+ * - PartialShipment
+ * - RelatedOrDelayedCharge
+ * - NoShow
+ * - Resubmission
+ */
+public class InitiatedTransactionIndicator {
+ @SerializedName("Category")
+ private String category;
+
+ @SerializedName("Subcategory")
+ private String subcategory;
+
+ public String getCategory() {
+ return this.category;
+ }
+
+ public InitiatedTransactionIndicator setCategory(String category) {
+ this.category = category;
+ return this;
+ }
+
+ public String getSubcategory() {
+ return this.subcategory;
+ }
+
+ public InitiatedTransactionIndicator setSubcategory(String subcategory) {
+ this.subcategory = subcategory;
+ return this;
+ }
+}
diff --git a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/Payment.java b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/Payment.java
index ea4a0ca..dd54028 100644
--- a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/Payment.java
+++ b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/Payment.java
@@ -19,6 +19,8 @@ public class Payment {
private RecurrentPayment recurrentPayment;
@SerializedName("CreditCard")
private CreditCard creditCard;
+ @SerializedName("DebitCard")
+ private DebitCard debitCard;
@SerializedName("Tid")
private String tid;
@SerializedName("ProofOfSale")
@@ -27,6 +29,8 @@ public class Payment {
private String authorizationCode;
@SerializedName("SoftDescriptor")
private String softDescriptor = "";
+ @SerializedName("PaymentFacilitator")
+ private PaymentFacilitator paymentFacilitator;
@SerializedName("ReturnUrl")
private String returnUrl;
@SerializedName("Provider")
@@ -37,7 +41,7 @@ public class Payment {
private Type type;
@SerializedName("Amount")
private Integer amount;
- @SerializedName("ReceiveDate")
+ @SerializedName("ReceivedDate")
private String receivedDate;
@SerializedName("CapturedAmount")
private Integer capturedAmount;
@@ -69,6 +73,30 @@ public class Payment {
private String digitableLine;
@SerializedName("Address")
private String address;
+ @SerializedName("BoletoNumber")
+ private String boletoNumber;
+ @SerializedName("Assignor")
+ private String assignor;
+ @SerializedName("Demonstrative")
+ private String demonstrative;
+ @SerializedName("Identification")
+ private String identification;
+ @SerializedName("Instructions")
+ private String instructions;
+ @SerializedName("AuthenticationUrl")
+ private String authenticationUrl;
+ @SerializedName("VoidedAmount")
+ private Integer voidedAmount;
+ @SerializedName("VoidedDate")
+ private String voidedDate;
+ @SerializedName("SolutionType")
+ private PaymentSolutionType solutionType;
+ @SerializedName("QrCodeBase64Image")
+ private String qrCodeBase64Image;
+ @SerializedName("ExternalAuthentication")
+ private ExternalAuthentication externalAuthentication;
+ @SerializedName("InitiatedTransactionIndicator")
+ private InitiatedTransactionIndicator initiatedTransactionIndicator;
public Payment(Integer amount, Integer installments) {
setAmount(amount);
@@ -86,6 +114,14 @@ public CreditCard creditCard(String securityCode, String brand) {
return getCreditCard();
}
+ public DebitCard debitCard(String securityCode, String brand) {
+ setType(Type.DebitCard);
+ setDebitCard(new DebitCard(securityCode, brand));
+
+ return getDebitCard();
+ }
+
+
public RecurrentPayment recurrentPayment(boolean authorizeNow) {
setRecurrentPayment(new RecurrentPayment(authorizeNow));
@@ -109,6 +145,10 @@ public String getAuthorizationCode() {
return authorizationCode;
}
+ public String getAuthenticationUrl() {
+ return authenticationUrl;
+ }
+
public Payment setAuthorizationCode(String authorizationCode) {
this.authorizationCode = authorizationCode;
return this;
@@ -154,6 +194,15 @@ public Payment setCreditCard(CreditCard creditCard) {
return this;
}
+ public Payment setDebitCard(DebitCard debitCard) {
+ this.debitCard = debitCard;
+ return this;
+ }
+
+ public DebitCard getDebitCard() {
+ return debitCard;
+ }
+
public Currency getCurrency() {
return currency;
}
@@ -280,6 +329,13 @@ public Payment setSoftDescriptor(String softDescriptor) {
return this;
}
+ public PaymentFacilitator getPaymentFacilitator() { return paymentFacilitator; }
+
+ public Payment setPaymentFacilitator(PaymentFacilitator paymentFacilitator) {
+ this.paymentFacilitator = paymentFacilitator;
+ return this;
+ }
+
public Integer getStatus() {
return status;
}
@@ -333,6 +389,42 @@ public Payment setCapture(boolean capture) {
return this;
}
+ public String getBoletoNumber() {
+ return boletoNumber;
+ }
+
+ public Payment setBoletoNumber(String boletoNumber) {
+ this.boletoNumber = boletoNumber;
+ return this;
+ }
+
+ public String getDemonstrative() {
+ return demonstrative;
+ }
+
+ public Payment setDemonstrative(String demonstrative) {
+ this.demonstrative = demonstrative;
+ return this;
+ }
+
+ public String getIdentification() {
+ return identification;
+ }
+
+ public Payment setIdentification(String identification) {
+ this.identification = identification;
+ return this;
+ }
+
+ public String getInstructions() {
+ return instructions;
+ }
+
+ public Payment setInstructions(String instructions) {
+ this.instructions = instructions;
+ return this;
+ }
+
public String getDigitableLine() {
return digitableLine;
}
@@ -357,15 +449,110 @@ public String getUrl() {
return url;
}
+ public Integer getVoidedAmount() {
+ return voidedAmount;
+ }
+
+ public String getVoidedDate() {
+ return voidedDate;
+ }
+
+ public PaymentSolutionType getSolutionType() {
+ return solutionType;
+ }
+
+ public Payment setSolutionType(PaymentSolutionType solutionType) {
+ this.solutionType = solutionType;
+ return this;
+ }
+
+ public String getQrCodeBase64Image() {
+ return qrCodeBase64Image;
+ }
+
+ public void setQrCodeBase64Image(String qrCodeBase64Image) {
+ this.qrCodeBase64Image = qrCodeBase64Image;
+ }
+
public enum Provider {
Bradesco, BancoDoBrasil, Simulado
}
public enum Type {
- CreditCard, DebitCard, ElectronicTransfer, Boleto
+ CreditCard, DebitCard, ElectronicTransfer, Boleto, QRCode
}
public enum Currency {
BRL, USD, MXN, COP, CLP, ARS, PEN, EUR, PYN, UYU, VEB, VEF, GBP
}
-}
\ No newline at end of file
+
+ /**
+ * Representa os tipos de solução de pagamento aceitos pela Cielo.
+ *
+ * Este enum é utilizado para serializar e desserializar o campo JSON
+ * Payment.SolutionType, obrigatório em transações com a bandeira Elo
+ * oriundas de link de pagamento.
+ */
+ public enum PaymentSolutionType {
+ ExternalLinkPay
+ }
+
+ public ExternalAuthentication getExternalAuthentication() {
+ return externalAuthentication;
+ }
+
+ public Payment setExternalAuthentication(ExternalAuthentication externalAuthentication) {
+ this.externalAuthentication = externalAuthentication;
+ return this;
+ }
+
+ public InitiatedTransactionIndicator getInitiatedTransactionIndicator() {
+ return this.initiatedTransactionIndicator;
+ }
+
+ public Payment setInitiatedTransactionIndicator(InitiatedTransactionIndicator initiatedTransactionIndicator) {
+ this.initiatedTransactionIndicator = initiatedTransactionIndicator;
+ return this;
+ }
+
+ /**
+ * Categoria do indicador de início da transação. Válido apenas para bandeira Mastercard.
+ *
+ * Valores possíveis:
+ * - “C1”: transação inciada pelo portador do cartão;
+ * - “M1”: transação recorrente ou parcelada iniciada pela loja;
+ * - “M2”: transação iniciada pela loja.
+ */
+ public enum Category {
+ C1,
+ M1,
+ M2
+ }
+
+ /**
+ * Subcategoria do indicador. Válido apenas para bandeira Mastercard.
+ * Valores possíveis:
+ *
+ * Se InitiatedTransactionIndicator.Category = “C1” ou “M1”
+ * - CredentialsOnFile
+ * - StandingOrder
+ * - Subscription
+ * - Installment
+ *
+ * Se InitiatedTransactionIndicator.Category = “M2”
+ * - PartialShipment
+ * - RelatedOrDelayedCharge
+ * - NoShow
+ * - Resubmission
+ */
+ public enum Subcategory {
+ CredentialsOnFile,
+ StandingOrder,
+ Subscription,
+ Installment,
+ PartialShipment,
+ RelatedOrDelayedCharge,
+ NoShow,
+ Resubmission
+ }
+}
diff --git a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/PaymentFacilitator.java b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/PaymentFacilitator.java
new file mode 100644
index 0000000..5de2202
--- /dev/null
+++ b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/PaymentFacilitator.java
@@ -0,0 +1,27 @@
+package cieloecommerce.sdk.ecommerce;
+
+import com.google.gson.annotations.SerializedName;
+
+public class PaymentFacilitator {
+
+ @SerializedName("EstablishmentCode")
+ private String establishmentCode;
+ @SerializedName("SubEstablishment")
+ private SubEstablishment subEstablishment;
+
+ public String getEstablishmentCode() {
+ return this.establishmentCode;
+ }
+
+ public PaymentFacilitator setEstablishmentCode(String establishmentCode) {
+ this.establishmentCode = establishmentCode;
+ return this;
+ }
+
+ public SubEstablishment getSubEstablishment() { return this.subEstablishment; }
+
+ public PaymentFacilitator setSubEstablishment(SubEstablishment subEstablishment) {
+ this.subEstablishment = subEstablishment;
+ return this;
+ }
+}
diff --git a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/QueryMerchantOrderResponse.java b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/QueryMerchantOrderResponse.java
new file mode 100644
index 0000000..14f85be
--- /dev/null
+++ b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/QueryMerchantOrderResponse.java
@@ -0,0 +1,25 @@
+package cieloecommerce.sdk.ecommerce;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * Created by gustavo.kruger
+ */
+public class QueryMerchantOrderResponse {
+
+ @SerializedName("Payments")
+ private Payment[] payments;
+
+ public QueryMerchantOrderResponse() {
+ }
+
+ public Payment[] getPayments() {
+ return payments;
+ }
+
+ public void setPayment(Payment[] payments) {
+ this.payments = payments;
+ }
+
+
+}
\ No newline at end of file
diff --git a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/SaleResponse.java b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/SaleResponse.java
index 8973e76..9a20fe7 100644
--- a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/SaleResponse.java
+++ b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/SaleResponse.java
@@ -7,6 +7,9 @@
*/
public class SaleResponse {
+ @SerializedName("MerchantOrderId")
+ private String merchantOrderId;
+
@SerializedName("Status")
private String status;
@@ -28,6 +31,9 @@ public class SaleResponse {
@SerializedName("ReturnMessage")
private String returnMessage;
+ @SerializedName("AuthenticationUrl")
+ private String authenticationUrl;
+
@SerializedName("Links")
private Links[] links;
@@ -49,7 +55,15 @@ public String getStatus() {
return status;
}
- public void setStatus(String status) {
+ public String getMerchantOrderId() {
+ return merchantOrderId;
+ }
+
+ public void setMerchantOrderId(String merchantOrderId) {
+ this.merchantOrderId = merchantOrderId;
+ }
+
+ public void setStatus(String status) {
this.status = status;
}
@@ -101,7 +115,15 @@ public void setReturnMessage(String returnMessage) {
this.returnMessage = returnMessage;
}
- public Links[] getLinks() {
+ public String getAuthenticationUrl() {
+ return authenticationUrl;
+ }
+
+ public void setAuthenticationUrl(String authenticationUrl) {
+ this.authenticationUrl = authenticationUrl;
+ }
+
+ public Links[] getLinks() {
return links;
}
diff --git a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/SubEstablishment.java b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/SubEstablishment.java
new file mode 100644
index 0000000..fbf3ffe
--- /dev/null
+++ b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/SubEstablishment.java
@@ -0,0 +1,117 @@
+package cieloecommerce.sdk.ecommerce;
+
+import com.google.gson.annotations.SerializedName;
+
+public class SubEstablishment {
+
+ @SerializedName("EstablishmentCode")
+ private String establishmentCode;
+ @SerializedName("CompanyName")
+ private String companyName;
+ @SerializedName("Identity")
+ private String identity;
+ @SerializedName("Mcc")
+ private String mcc;
+ @SerializedName("Address")
+ private String address;
+ @SerializedName("City")
+ private String city;
+ @SerializedName("State")
+ private String state;
+ @SerializedName("PostalCode")
+ private String postalCode;
+ @SerializedName("CountryCode")
+ private String countryCode;
+ @SerializedName("PhoneNumber")
+ private String phoneNumber;
+
+ public String getEstablishmentCode() {
+ return this.establishmentCode;
+ }
+
+ public SubEstablishment setEstablishmentCode(String establishmentCode) {
+ this.establishmentCode = establishmentCode;
+ return this;
+ }
+
+ public SubEstablishment setCompanyName(String companyName) {
+ this.companyName = companyName;
+ return this;
+ }
+
+ public String getCompanyName() {
+ return companyName;
+ }
+
+ public String getIdentity() {
+ return this.identity;
+ }
+
+ public SubEstablishment setIdentity(String identity) {
+ this.identity = identity;
+ return this;
+ }
+
+ public String getMcc() {
+ return this.mcc;
+ }
+
+ public SubEstablishment setMcc(String mcc) {
+ this.mcc = mcc;
+ return this;
+ }
+
+ public String getAddress() {
+ return this.address;
+ }
+
+ public SubEstablishment setAddress(String address) {
+ this.address = address;
+ return this;
+ }
+
+ public String getCity() {
+ return this.city;
+ }
+
+ public SubEstablishment setCity(String city) {
+ this.city = city;
+ return this;
+ }
+
+ public String getState() {
+ return this.state;
+ }
+
+ public SubEstablishment setState(String state) {
+ this.state = state;
+ return this;
+ }
+
+ public String getPostalCode() {
+ return this.postalCode;
+ }
+
+ public SubEstablishment setPostalCode(String postalCode) {
+ this.postalCode = postalCode;
+ return this;
+ }
+
+ public String getCountryCode() {
+ return this.countryCode;
+ }
+
+ public SubEstablishment setCountryCode(String countryCode) {
+ this.countryCode = countryCode;
+ return this;
+ }
+
+ public String getPhoneNumber() {
+ return this.phoneNumber;
+ }
+
+ public SubEstablishment setPhoneNumber(String phoneNumber) {
+ this.phoneNumber = phoneNumber;
+ return this;
+ }
+}
diff --git a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/AbstractSaleRequest.java b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/AbstractSaleRequest.java
index 6a7ee79..ed03325 100644
--- a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/AbstractSaleRequest.java
+++ b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/AbstractSaleRequest.java
@@ -1,22 +1,18 @@
package cieloecommerce.sdk.ecommerce.request;
-import java.io.BufferedReader;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
import java.util.UUID;
-import java.util.zip.GZIPInputStream;
-import org.apache.http.Header;
import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import com.google.gson.Gson;
import cieloecommerce.sdk.Environment;
import cieloecommerce.sdk.Merchant;
+import org.apache.http.util.EntityUtils;
/**
* Abstraction to reuse most of the code that send and receive the HTTP
@@ -25,7 +21,7 @@
public abstract class AbstractSaleRequest {
final Environment environment;
private final Merchant merchant;
- private HttpClient httpClient;
+ private CloseableHttpClient httpClient;
AbstractSaleRequest(Merchant merchant, Environment environment) {
this.merchant = merchant;
@@ -34,7 +30,7 @@ public abstract class AbstractSaleRequest {
public abstract Response execute(Request param) throws IOException, CieloRequestException;
- public void setHttpClient(HttpClient httpClient) {
+ public void setHttpClient(CloseableHttpClient httpClient) {
this.httpClient = httpClient;
}
@@ -48,7 +44,7 @@ public void setHttpClient(HttpClient httpClient) {
* @throws IOException
* yeah, deal with it
*/
- HttpResponse sendRequest(HttpUriRequest request) throws IOException {
+ CloseableHttpResponse sendRequest(HttpUriRequest request) throws IOException {
if (httpClient == null) {
httpClient = HttpClientBuilder.create().build();
}
@@ -67,33 +63,22 @@ HttpResponse sendRequest(HttpUriRequest request) throws IOException {
/**
* Read the response body sent by Cielo
*
- * @param response
- * HttpResponse by Cielo, with headers, status code, etc.
+ * @param response HttpResponse by Cielo, with headers, status code, etc.
* @return An instance of Sale with the response entity sent by Cielo.
- * @throws IOException
- * yeah, deal with it
+ * @throws IOException yeah, deal with it
* @throws CieloRequestException
*/
- Response readResponse(HttpResponse response, Class responseClassOf)
- throws IOException, CieloRequestException {
- HttpEntity responseEntity = response.getEntity();
- InputStream responseEntityContent = responseEntity.getContent();
-
- Header contentEncoding = response.getFirstHeader("Content-Encoding");
-
- if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
- responseEntityContent = new GZIPInputStream(responseEntityContent);
+ Response readResponse(CloseableHttpResponse response, Class responseClassOf)
+ throws IOException, CieloRequestException {
+ try {
+ HttpEntity responseEntity = response.getEntity();
+ final String responseBody = EntityUtils.toString(responseEntity);
+ EntityUtils.consume(responseEntity);
+ return parseResponse(response.getStatusLine().getStatusCode(), responseBody,
+ responseClassOf);
+ } finally {
+ response.close();
}
-
- BufferedReader responseReader = new BufferedReader(new InputStreamReader(responseEntityContent));
- StringBuilder responseBuilder = new StringBuilder();
- String line;
-
- while ((line = responseReader.readLine()) != null) {
- responseBuilder.append(line);
- }
-
- return parseResponse(response.getStatusLine().getStatusCode(), responseBuilder.toString(), responseClassOf);
}
/**
diff --git a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/CreateCartTokenRequest.java b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/CreateCartTokenRequest.java
index 08dba25..c061e46 100644
--- a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/CreateCartTokenRequest.java
+++ b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/CreateCartTokenRequest.java
@@ -2,7 +2,7 @@
import java.io.IOException;
-import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
@@ -24,7 +24,7 @@ public CardToken execute(CardToken param) throws IOException, CieloRequestExcept
request.setEntity(new StringEntity(new GsonBuilder().create().toJson(param)));
- HttpResponse response = sendRequest(request);
+ CloseableHttpResponse response = sendRequest(request);
return readResponse(response, CardToken.class);
}
diff --git a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/CreateSaleRequest.java b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/CreateSaleRequest.java
index 5654490..6c033a2 100644
--- a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/CreateSaleRequest.java
+++ b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/CreateSaleRequest.java
@@ -2,8 +2,10 @@
import java.io.IOException;
-import org.apache.http.HttpResponse;
+import org.apache.commons.codec.Charsets;
+import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import com.google.gson.GsonBuilder;
@@ -25,9 +27,9 @@ public Sale execute(Sale param) throws IOException, CieloRequestException {
String url = environment.getApiUrl() + "1/sales/";
HttpPost request = new HttpPost(url);
- request.setEntity(new StringEntity(new GsonBuilder().create().toJson(param)));
-
- HttpResponse response = sendRequest(request);
+ request.setEntity(new StringEntity(new GsonBuilder().create().toJson(param),
+ ContentType.create(ContentType.APPLICATION_JSON.getMimeType(), Charsets.UTF_8.name())));
+ CloseableHttpResponse response = sendRequest(request);
return readResponse(response, Sale.class);
}
diff --git a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/DeactivateRecurrentSaleRequest.java b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/DeactivateRecurrentSaleRequest.java
index e767cfb..7cffac0 100644
--- a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/DeactivateRecurrentSaleRequest.java
+++ b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/DeactivateRecurrentSaleRequest.java
@@ -3,7 +3,7 @@
import cieloecommerce.sdk.Environment;
import cieloecommerce.sdk.Merchant;
import cieloecommerce.sdk.ecommerce.RecurrentSale;
-import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPut;
import java.io.IOException;
@@ -18,7 +18,7 @@ public RecurrentSale execute(String recurrentPaymentId) throws IOException, Ciel
String url = environment.getApiUrl() + "1/RecurrentPayment/" + recurrentPaymentId + "/Deactivate";
HttpPut request = new HttpPut(url);
- HttpResponse response = sendRequest(request);
+ CloseableHttpResponse response = sendRequest(request);
return readResponse(response, RecurrentSale.class);
}
diff --git a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/QueryMerchantOrderRequest.java b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/QueryMerchantOrderRequest.java
new file mode 100644
index 0000000..1a33e1d
--- /dev/null
+++ b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/QueryMerchantOrderRequest.java
@@ -0,0 +1,30 @@
+package cieloecommerce.sdk.ecommerce.request;
+
+import java.io.IOException;
+
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+
+import cieloecommerce.sdk.Environment;
+import cieloecommerce.sdk.Merchant;
+import cieloecommerce.sdk.ecommerce.QueryMerchantOrderResponse;
+
+/**
+ * Query a Sale by it's Merchant Order Id to retrieve Cielo's paymentId
+ */
+public class QueryMerchantOrderRequest extends AbstractSaleRequest {
+ public QueryMerchantOrderRequest(Merchant merchant, Environment environment) {
+ super(merchant, environment);
+ }
+
+ @Override
+ public QueryMerchantOrderResponse execute(String merchnatOrderId) throws IOException, CieloRequestException {
+ String url = environment.getApiQueryURL() + "1/sales?merchantOrderId=" + merchnatOrderId;
+
+ HttpGet request = new HttpGet(url);
+ CloseableHttpResponse response = sendRequest(request);
+
+ return readResponse(response, QueryMerchantOrderResponse.class);
+ }
+
+}
diff --git a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/QueryRecurrentSaleRequest.java b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/QueryRecurrentSaleRequest.java
index e28d1de..2aa9d68 100644
--- a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/QueryRecurrentSaleRequest.java
+++ b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/QueryRecurrentSaleRequest.java
@@ -1,13 +1,13 @@
package cieloecommerce.sdk.ecommerce.request;
+import java.io.IOException;
+
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+
import cieloecommerce.sdk.Environment;
import cieloecommerce.sdk.Merchant;
import cieloecommerce.sdk.ecommerce.RecurrentSale;
-import cieloecommerce.sdk.ecommerce.Sale;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpGet;
-
-import java.io.IOException;
public class QueryRecurrentSaleRequest extends AbstractSaleRequest {
public QueryRecurrentSaleRequest(Merchant merchant, Environment environment) {
@@ -19,7 +19,7 @@ public RecurrentSale execute(String recurrentPaymentId) throws IOException, Ciel
String url = environment.getApiQueryURL() + "1/RecurrentPayment/" + recurrentPaymentId;
HttpGet request = new HttpGet(url);
- HttpResponse response = sendRequest(request);
+ CloseableHttpResponse response = sendRequest(request);
return readResponse(response, RecurrentSale.class);
}
diff --git a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/QuerySaleRequest.java b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/QuerySaleRequest.java
index 817ba85..9899a11 100644
--- a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/QuerySaleRequest.java
+++ b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/QuerySaleRequest.java
@@ -2,7 +2,7 @@
import java.io.IOException;
-import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import cieloecommerce.sdk.Environment;
@@ -22,7 +22,7 @@ public Sale execute(String paymentId) throws IOException, CieloRequestException
String url = environment.getApiQueryURL() + "1/sales/" + paymentId;
HttpGet request = new HttpGet(url);
- HttpResponse response = sendRequest(request);
+ CloseableHttpResponse response = sendRequest(request);
return readResponse(response, Sale.class);
}
diff --git a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/UpdateSaleRequest.java b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/UpdateSaleRequest.java
index fd4a1eb..23dbf1f 100644
--- a/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/UpdateSaleRequest.java
+++ b/api30.sdk/src/main/java/cieloecommerce/sdk/ecommerce/request/UpdateSaleRequest.java
@@ -3,7 +3,7 @@
import cieloecommerce.sdk.Environment;
import cieloecommerce.sdk.Merchant;
import cieloecommerce.sdk.ecommerce.SaleResponse;
-import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.utils.URIBuilder;
@@ -43,7 +43,7 @@ public SaleResponse execute(String paymentId) throws IOException, CieloRequestEx
request = new HttpPut(builder.build().toString());
- HttpResponse response = sendRequest(request);
+ CloseableHttpResponse response = sendRequest(request);
sale = readResponse(response, SaleResponse.class);
} catch (URISyntaxException e) {