Skip to content

Commit

Permalink
Merge pull request #9 from konduto/2.12.0
Browse files Browse the repository at this point in the history
Merge 2.12.0 including new order [GET] and [POST] response fields, which are triggered decision lists and rules, and bureaux queries. Additionally, order [POST] requests accept payment amount/description.
  • Loading branch information
raphaelsampaio authored Jan 8, 2020
2 parents 93b15cf + 715a543 commit 31fb9e2
Show file tree
Hide file tree
Showing 26 changed files with 521 additions and 94 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ To get started add our SDK as a dependency in your **pom.xml**:
<dependency>
<groupId>com.konduto.sdk</groupId>
<artifactId>java-sdk</artifactId>
<version>2.11.0</version>
<version>2.12.0</version>
</dependency>
```

Expand Down Expand Up @@ -89,7 +89,7 @@ shipping_amount | _(optional)_ Shipping and handling amount.
tax_amount | _(optional)_ Taxes amount.
currency | _(optional)_ Currency code with 3 letters (ISO-4712).
installments | _(optional)_ Number of installments in the payment plan.
ip | _(optional)_ Customer's IPv4 address.
ip | _(optional)_ Customer's IPv4 or IPV6 address.
customer | _(required)_ Object containing the customer details.
payment | _(optional)_ Array containing the payment methods.
billing | _(optional)_ Object containing the billing information.
Expand Down Expand Up @@ -117,6 +117,12 @@ created_at | _(optional)_ Date when customer was created.

#### Payment information

Payments may contain a `description` and a `amount` field. The former is a
description of the payment, for example: "Thanksgiving discount voucher".
The latter is the amount that was charged in that specific payment type. For
example, a transaction total amount could be 100.00, of which 10.00 are
paid via a discount voucher and 90.00 via credit card.

##### Credit card
Parameter | Description
--- | ---
Expand Down
17 changes: 10 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,27 @@ repositories {
}

dependencies {
compile 'commons-httpclient:commons-httpclient:3.1'
compile 'com.google.code.gson:gson:2.2.4'
testCompile 'junit:junit:4.11'
testCompile 'com.github.tomakehurst:wiremock:1.18'
implementation 'commons-httpclient:commons-httpclient:3.1'
implementation 'com.google.code.gson:gson:2.2.4'
testImplementation 'junit:junit:4.11'
testImplementation 'com.github.tomakehurst:wiremock:1.18'
}

task sourcesJar(type: Jar) {
from sourceSets.main.allJava
archiveClassifier = 'sources'
archiveClassifier.set('sources')
}

task javadocJar(type: Jar) {
from javadoc
archiveClassifier = 'javadoc'
archiveClassifier.set('javadoc')
}

jar {
from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from configurations.compileClasspath.collect {
it.isDirectory() ? it : zipTree(it)
}
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,17 @@ public Collection<KondutoPayment> deserialize(JsonElement json, Type typeOfT, Js
Collection<KondutoPayment> payments = new ArrayList<KondutoPayment>();

for(JsonElement je : json.getAsJsonArray()) {
KondutoPaymentType type =
KondutoPaymentType.valueOf(((JsonObject) je).get("type").getAsString().toUpperCase());
switch (type){
case BOLETO:
KondutoBoletoPayment boletoPayment = new KondutoBoletoPayment();
String expirationDateAsStr = ((JsonObject) je).get("expiration_date").getAsString();
boletoPayment.setExpirationDate(expirationDateAsStr);
payments.add(boletoPayment);
break;
case CREDIT:
payments.add((KondutoCreditCardPayment) context.deserialize(je, KondutoCreditCardPayment.class));
break;
case DEBIT:
payments.add((KondutoDebitPayment) context.deserialize(je, KondutoDebitPayment.class));
break;
case TRANSFER:
payments.add((KondutoTransferPayment) context.deserialize(je, KondutoTransferPayment.class));
break;
case VOUCHER:
payments.add((KondutoVoucherPayment) context.deserialize(je, KondutoVoucherPayment.class));
break;
JsonObject jo = (JsonObject) je;
String pmtTypeUpper = jo.get("type").getAsString().toUpperCase();
KondutoPaymentType type = KondutoPaymentType.valueOf(pmtTypeUpper);
KondutoPayment pmt = type.deserialize(jo, context);
if(jo.has("description")) {
pmt.setDescription(jo.get("description").getAsString());
}
if(jo.has("amount")) {
pmt.setAmount(jo.get("amount").getAsDouble());
}
payments.add(pmt);
}

return payments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.konduto.sdk.models.KondutoPaymentType;

import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.RoundingMode;

/**
* Created by rsampaio on 9/8/16.
Expand All @@ -28,6 +30,14 @@ public class KondutoPaymentSerializer implements JsonSerializer<KondutoPayment>
public JsonElement serialize(KondutoPayment payment, Type typeOfSrc, JsonSerializationContext context) {
JsonObject paymentAsJson = new JsonObject();
paymentAsJson.addProperty("type", payment.getTypeAsString());
if(payment.getDescription() != null) {
paymentAsJson.addProperty("description", payment.getDescription());
}
if(payment.getAmount() != null) {
paymentAsJson.addProperty("amount",
BigDecimal.valueOf(payment.getAmount()).setScale(2,
RoundingMode.HALF_UP));
}
if(payment.getType().equals(KondutoPaymentType.CREDIT)) {
KondutoCreditCardPaymentSerializer creditCardPaymentSerializer = new KondutoCreditCardPaymentSerializer();
return creditCardPaymentSerializer.completeSerialization(paymentAsJson, (KondutoCreditCardPayment) payment);
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/com/konduto/sdk/models/KondutoBureauQuery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.konduto.sdk.models;

import com.google.gson.annotations.SerializedName;

import java.util.HashMap;
import java.util.Map;

public class KondutoBureauQuery extends KondutoModel {
@SerializedName("service")
private String kondutoBureauService;
@SerializedName("response")
private Map<String, Object> kondutoBureauResponse;

@Override
public boolean equals(Object obj) {
if(!(obj instanceof KondutoBureauQuery)) { return false; }
KondutoBureauQuery that = (KondutoBureauQuery) obj;
return this.kondutoBureauService == that.kondutoBureauService &&
this.kondutoBureauResponse.equals(that.kondutoBureauResponse);
}

public String getService() {
return kondutoBureauService;
}

public void setService(String kondutoBureauService) {
this.kondutoBureauService = kondutoBureauService;
}

public Map<String, Object> getResponse() {
return kondutoBureauResponse;
}

public void setResponse(Map<String, Object> kondutoBureauResponse) {
this.kondutoBureauResponse = kondutoBureauResponse;
}

/**
* Return the value of a field in a bureau response (e.g.
* email_domain_exists).
*
* @param field what field to look for
* @return the value of that field
*/
public Object getAttribute(String field) {
if(field == null || this.kondutoBureauResponse == null) { return null; }
return this.kondutoBureauResponse.get(field);
}

public void setAttribute(String key, Object value) {
if(this.kondutoBureauResponse == null) {
this.kondutoBureauResponse = new HashMap<String, Object>();
}
this.kondutoBureauResponse.put(key, value);
}
}
89 changes: 45 additions & 44 deletions src/main/java/com/konduto/sdk/models/KondutoCreditCardPayment.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
*/
public class KondutoCreditCardPayment extends KondutoPayment {

private String bin;
private String bin;

private String last4;
private String last4;

private String expirationDate;
private String expirationDate;

@Required private KondutoPaymentStatus status;

Expand All @@ -32,58 +32,59 @@ public String getStatusAsString() {
return getStatus().toString().toLowerCase();
}

public String getBin() {
return bin;
}
public String getBin() {
return bin;
}

public void setBin(String bin) {
this.bin = bin;
}
public void setBin(String bin) {
this.bin = bin;
}

public String getLast4() {
return last4;
}
public String getLast4() {
return last4;
}

public void setLast4(String last4) {
this.last4 = last4;
}
public void setLast4(String last4) {
this.last4 = last4;
}

public String getExpirationDate() {
return expirationDate;
}
public String getExpirationDate() {
return expirationDate;
}

public void setExpirationDate(String expirationDate) {
this.expirationDate = expirationDate;
}
public void setExpirationDate(String expirationDate) {
this.expirationDate = expirationDate;
}

@Override
public KondutoPaymentType getType() {
return KondutoPaymentType.CREDIT;
}
@Override
public KondutoPaymentType getType() {
return KondutoPaymentType.CREDIT;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof KondutoCreditCardPayment)) return false;
@Override
public boolean equals(Object o) {
if (!super.equals(o)) return false;
if (this == o) return true;
if (!(o instanceof KondutoCreditCardPayment)) return false;

KondutoCreditCardPayment that = (KondutoCreditCardPayment) o;
KondutoCreditCardPayment that = (KondutoCreditCardPayment) o;

if (bin != null ? !bin.equals(that.bin) : that.bin != null) return false;
if (expirationDate != null ? !expirationDate.equals(that.expirationDate) : that.expirationDate != null)
return false;
if (last4 != null ? !last4.equals(that.last4) : that.last4 != null) return false;
if (bin != null ? !bin.equals(that.bin) : that.bin != null) return false;
if (expirationDate != null ? !expirationDate.equals(that.expirationDate) : that.expirationDate != null)
return false;
if (last4 != null ? !last4.equals(that.last4) : that.last4 != null) return false;
return status == that.status;

}

/* This is required for correct deserialization since HashSet uses hashCode instead of equals. */
@Override
public int hashCode() {
int result = bin != null ? bin.hashCode() : 0;
result = 31 * result + (last4 != null ? last4.hashCode() : 0);
result = 31 * result + (expirationDate != null ? expirationDate.hashCode() : 0);
result = 31 * result + (status != null ? status.hashCode() : 0);
result = 31 * result + (getType()!= null ? getType().hashCode() : 0);
return result;
}
/* This is required for correct deserialization since HashSet uses hashCode instead of equals. */
@Override
public int hashCode() {
int result = bin != null ? bin.hashCode() : 0;
result = 31 * result + (last4 != null ? last4.hashCode() : 0);
result = 31 * result + (expirationDate != null ? expirationDate.hashCode() : 0);
result = 31 * result + (status != null ? status.hashCode() : 0);
result = 31 * result + (getType()!= null ? getType().hashCode() : 0);
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.konduto.sdk.models;

import com.google.gson.annotations.SerializedName;

public enum KondutoDecisionListTrigger {
@SerializedName("email")
EMAIL,
@SerializedName("billing")
BILLING,
@SerializedName("shipping")
SHIPPING,
@SerializedName("tax_id")
TAX_ID,
@SerializedName("phone_1")
PHONE_1,
@SerializedName("phone_2")
PHONE_2,
@SerializedName("ip")
IP,
@SerializedName("shipping_zip")
SHIPPING_ZIP,
@SerializedName("billing_zip")
BILLING_ZIP,
@SerializedName("hotel_zip")
HOTEL_ZIP,
@SerializedName("customer_name")
CUSTOMER_NAME,
@SerializedName("shipping_name")
SHIPPING_NAME,
@SerializedName("billing_name")
BILLING_NAME,
@SerializedName("bin_last4")
BIN_LAST4,
@SerializedName("passenger_name")
PASSENGER_NAME,
@SerializedName("passenger_document")
PASSENGER_DOCUMENT,
@SerializedName("guest_name")
GUEST_NAME,
@SerializedName("guest_document")
GUEST_DOCUMENT,
@SerializedName("device_ip")
DEVICE_IP
}
20 changes: 20 additions & 0 deletions src/main/java/com/konduto/sdk/models/KondutoDecisionListType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.konduto.sdk.models;

import com.google.gson.annotations.SerializedName;

public enum KondutoDecisionListType {
@SerializedName("email")
EMAIL,
@SerializedName("tax_id")
TAX_ID,
@SerializedName("phone")
PHONE,
@SerializedName("bin_last4")
BIN_LAST4,
@SerializedName("zip")
ZIP,
@SerializedName("name")
NAME,
@SerializedName("ip")
IP
}
10 changes: 10 additions & 0 deletions src/main/java/com/konduto/sdk/models/KondutoModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ public boolean isValid() {

}

/**
* Verify if two objects are equal
* @param a an object
* @param b another object
* @return whether they are equal
*/
public static boolean equals(Object a, Object b) {
return (a == b) || (a != null && a.equals(b));
}

public static List<Field> getAllFields(List<Field> fields, Class<?> type) {
fields.addAll(Arrays.asList(type.getDeclaredFields()));

Expand Down
Loading

0 comments on commit 31fb9e2

Please sign in to comment.