Skip to content

Commit

Permalink
Merge pull request #252 from mercadopago/feature/fine-discount-and-3ds
Browse files Browse the repository at this point in the history
Improvements for boleto (fees, fines and discount) and credit card payments (3DS 2.0)
  • Loading branch information
romerosilva-meli authored Feb 28, 2023
2 parents 540f64f + f183582 commit 6516511
Show file tree
Hide file tree
Showing 27 changed files with 1,072 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ repos:
- id: checkstyle
args:
- -c
- .code_quality/checkstyle_rules.xml
- .code_quality/checkstyle_rules.xml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ already.
<dependency>
<groupId>com.mercadopago</groupId>
<artifactId>sdk-java</artifactId>
<version>2.1.5</version>
<version>2.1.6</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.mercadopago</groupId>
<artifactId>sdk-java</artifactId>
<version>2.1.5</version>
<version>2.1.6</version>
<packaging>jar</packaging>

<name>Mercadopago SDK</name>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/mercadopago/MercadoPagoConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/** Mercado Pago configuration class. */
public class MercadoPagoConfig {

public static final String CURRENT_VERSION = "2.1.5";
public static final String CURRENT_VERSION = "2.1.6";

public static final String PRODUCT_ID = "BC32A7VTRPP001U8NHJ0";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,10 @@ public class PaymentCreateRequest {

/** Taxes for payments. */
private final List<PaymentTaxRequest> taxes;

/** Payment Method. */
private final PaymentMethodRequest paymentMethod;

/** 3DS. */
private final String threeDSecureMode;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mercadopago.client.payment;

import lombok.Builder;
import lombok.Getter;

/** PaymentDataRequest class. */
@Getter
@Builder
public class PaymentDataRequest {

/** Rules. */
private final PaymentRulesRequest rules;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.mercadopago.client.payment;

import java.math.BigDecimal;
import java.time.LocalDate;
import lombok.Builder;
import lombok.Getter;

/** PaymentDiscountRequest class. */
@Getter
@Builder
public class PaymentDiscountRequest {

/** Discount type. */
private String type;

/** Discount value. */
private BigDecimal value;

/** Discount Limit Date. */
private LocalDate limitDate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.mercadopago.client.payment;

import java.math.BigDecimal;
import lombok.Builder;
import lombok.Getter;

/** PaymentFeeRequest class. */
@Getter
@Builder
public class PaymentFeeRequest {

/** Fee type. */
private String type;

/** Fee value. */
private BigDecimal value;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mercadopago.client.payment;

import lombok.Builder;
import lombok.Getter;

/** PaymentMethodRequest class. */
@Getter
@Builder
public class PaymentMethodRequest {

/** Data. */
private final PaymentDataRequest data;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
@Getter
@Builder
public class PaymentPointOfInteractionRequest {

/** Linked to information. */
private final String linkedTo;

/** Type. */
private final String type;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.mercadopago.client.payment;

import java.util.List;
import lombok.Builder;
import lombok.Getter;

/** PaymentRulesRequest class. */
@Getter
@Builder
public class PaymentRulesRequest {

/** Discounts. */
private List<PaymentDiscountRequest> discounts;

/** Fine. */
private PaymentFeeRequest fine;

/** Interest. */
private PaymentFeeRequest interest;
}
14 changes: 14 additions & 0 deletions src/main/java/com/mercadopago/resources/payment/Payment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mercadopago.resources.payment;

import com.google.gson.annotations.SerializedName;
import com.mercadopago.net.MPResource;
import java.math.BigDecimal;
import java.time.OffsetDateTime;
Expand Down Expand Up @@ -185,4 +186,17 @@ public class Payment extends MPResource {

/** Point of interaction. */
private PaymentPointOfInteraction pointOfInteraction;

/** PaymentMethod. */
private PaymentMethod paymentMethod;

/** 3DS Info. */
@SerializedName("three_dsinfo")
private PaymentThreeDSInfo threeDSInfo;

/**
* Internal data that can be attached to the payment to record additional attributes of the
* merchant.
*/
private Map<String, Object> internalMetadata;
}
11 changes: 11 additions & 0 deletions src/main/java/com/mercadopago/resources/payment/PaymentData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mercadopago.resources.payment;

import lombok.Getter;

/** PaymentData class. */
@Getter
public class PaymentData {

/** PaymentRules. */
private PaymentRules rules;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mercadopago.resources.payment;

import java.math.BigDecimal;
import java.time.LocalDate;
import lombok.Getter;

/** PaymentDiscount class. */
@Getter
public class PaymentDiscount {

/** Discount type. */
private String type;

/** Discount value. */
private BigDecimal value;

/** Discount Limit Date. */
private LocalDate limitDate;
}
15 changes: 15 additions & 0 deletions src/main/java/com/mercadopago/resources/payment/PaymentFee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.mercadopago.resources.payment;

import java.math.BigDecimal;
import lombok.Getter;

/** PaymentFee class. */
@Getter
public class PaymentFee {

/** Fee type. */
private String type;

/** Fee value. */
private BigDecimal value;
}
11 changes: 11 additions & 0 deletions src/main/java/com/mercadopago/resources/payment/PaymentMethod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mercadopago.resources.payment;

import lombok.Getter;

/** PaymentMethod class. */
@Getter
public class PaymentMethod {

/** PaymentData. */
private PaymentData data;
}
18 changes: 18 additions & 0 deletions src/main/java/com/mercadopago/resources/payment/PaymentRules.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.mercadopago.resources.payment;

import java.util.List;
import lombok.Getter;

/** PaymentRules class. */
@Getter
public class PaymentRules {

/** Discounts. */
private List<PaymentDiscount> discounts;

/** Fine. */
private PaymentFee fine;

/** Interest. */
private PaymentFee interest;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.mercadopago.resources.payment;

import lombok.Getter;

/** 3DS Info. */
@Getter
public class PaymentThreeDSInfo {
/** External Resource Url. */
private String externalResourceUrl;

/** creq. */
private String creq;
}
10 changes: 10 additions & 0 deletions src/main/java/com/mercadopago/serialization/Serializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.Type;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
Expand Down Expand Up @@ -73,6 +74,15 @@ private static OffsetDateTime parseDateTime(JsonElement json) {
new JsonPrimitive(
DateTimeFormatter.ofPattern(SERIALIZE_DATE_FORMAT_ISO8601)
.format(offsetDateTime)))
.registerTypeAdapter(
LocalDate.class,
(JsonSerializer<LocalDate>)
(localDate, type, context) ->
new JsonPrimitive(localDate.format(DateTimeFormatter.ISO_LOCAL_DATE)))
.registerTypeAdapter(
LocalDate.class,
(JsonDeserializer<LocalDate>)
(localDate, type, context) -> LocalDate.parse(localDate.getAsString()))
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create();

Expand Down
29 changes: 29 additions & 0 deletions src/test/java/com/mercadopago/client/payment/PaymentClientIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.mercadopago.resources.payment.Payment;
import com.mercadopago.resources.payment.PaymentRefund;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
Expand Down Expand Up @@ -430,6 +431,32 @@ private PaymentCreateRequest newPayment(String paymentStatus) throws MPException
.ipAddress("127.0.0.1")
.build();

PaymentFeeRequest fine =
PaymentFeeRequest.builder().type("percentage").value(new BigDecimal(2)).build();

PaymentFeeRequest interest =
PaymentFeeRequest.builder().type("percentage").value(new BigDecimal("0.03")).build();

PaymentDiscountRequest discount =
PaymentDiscountRequest.builder()
.type("fixed")
.value(new BigDecimal(5))
.limitDate(LocalDate.of(2022, 10, 25))
.build();

List<PaymentDiscountRequest> discounts = new ArrayList<>();
discounts.add(discount);

PaymentRulesRequest rules =
PaymentRulesRequest.builder().fine(fine).interest(interest).discounts(discounts).build();

PaymentDataRequest data = PaymentDataRequest.builder().rules(rules).build();

PaymentMethodRequest paymentMethod = PaymentMethodRequest.builder().data(data).build();

PaymentPointOfInteractionRequest pointOfInteraction =
PaymentPointOfInteractionRequest.builder().type("TYPE").build();

return PaymentCreateRequest.builder()
.transactionAmount(new BigDecimal("100"))
.token(cardToken.getId())
Expand All @@ -439,6 +466,8 @@ private PaymentCreateRequest newPayment(String paymentStatus) throws MPException
.metadata(new HashMap<>())
.paymentMethodId("master")
.additionalInfo(additionalInfo)
.pointOfInteraction(pointOfInteraction)
.paymentMethod(paymentMethod)
.build();
}
}
Loading

0 comments on commit 6516511

Please sign in to comment.