Skip to content

Commit

Permalink
Merge pull request #90 from delias-silva/master
Browse files Browse the repository at this point in the history
Add Taxes into Preference
  • Loading branch information
delias-silva authored Aug 28, 2019
2 parents 57a2f1b + 208c988 commit f9c1282
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>com.mercadopago</groupId>
<artifactId>dx-java</artifactId>
<version>1.0.36</version>
<version>1.1.0</version>
<packaging>jar</packaging>

<name>Mercadopago SDK</name>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/mercadopago/core/MPBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ private static <T extends MPBase> String parsePath(String path, HashMap<String,
.append(accessToken);


if (!mapParams.isEmpty()) {
if (mapParams != null && !mapParams.isEmpty()) {
for ( Map.Entry<String, String> entry : mapParams.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
Expand Down
23 changes: 21 additions & 2 deletions src/main/java/com/mercadopago/resources/Preference.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
*/
public class Preference extends MPBase {

@NotNull private ArrayList<Item> items = null;
@NotNull private Payer payer = null;
@NotNull
private ArrayList<Item> items = null;
@NotNull
private Payer payer = null;
private PaymentMethods paymentMethods = null;
private Shipments shipments = null;
private BackUrls backUrls = null;
Expand Down Expand Up @@ -60,6 +62,7 @@ public enum ProcessingMode {
}
private ArrayList<ProcessingMode> processingModes = null;
private Boolean binaryMode = null;
private ArrayList<Tax> taxes = null;

public ArrayList<Item> getItems() {
return items;
Expand Down Expand Up @@ -266,6 +269,22 @@ public Preference setBinaryMode(Boolean binaryMode) {
return this;
}

public ArrayList<Tax> getTaxes() { return this.taxes; }

public Preference setTaxes(ArrayList<Tax> taxes) {
this.taxes = taxes;
return this;
}

public Preference appendTax(Tax tax) {
if (this.taxes == null) {
this.taxes = new ArrayList<>();
}
this.taxes.add(tax);
return this;
}


public static Preference findById(String id) throws MPException {
return findById(id, WITHOUT_CACHE);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.mercadopago.resources.datastructures.preference;

/**
* Mercado Pago MercadoPago
* Preference Tax class
*
* Created by Danilo Elias on 26/08/2019.
*/
public class Tax {

private TaxType type = null;
public enum TaxType {
IVA,
INC
}
private Float value = null;

public TaxType getType() {
return type;
}

public Float getValue() {
return value;
}

public Tax setType(TaxType type) {
this.type = type;
return this;
}

public Tax setValue(Float value) {
this.value = value;
return this;
}

}
10 changes: 9 additions & 1 deletion src/test/java/mercadopago/resources/PreferenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.UUID;

Expand Down Expand Up @@ -100,6 +99,10 @@ public void preferenceGettersSettersTest() throws MPException {
DifferentialPricing differentialPricing = new DifferentialPricing();
differentialPricing.setId(0);

Tax tax = new Tax();
tax.setType(Tax.TaxType.IVA);
tax.setValue(500f);

Preference preference = new Preference();
preference.appendItem(item);
preference.setPayer(payer);
Expand All @@ -116,6 +119,7 @@ public void preferenceGettersSettersTest() throws MPException {
preference.setMarketplace("Marketplace");
preference.setMarketplaceFee(.01f);
preference.setDifferentialPricing(differentialPricing);
preference.appendTax(tax);

DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

Expand Down Expand Up @@ -186,6 +190,10 @@ public void preferenceGettersSettersTest() throws MPException {
JsonObject jsonDifferentialPricing = (JsonObject) jsonPreference.get("differential_pricing");
assertEquals(differentialPricing.getId().intValue(), jsonDifferentialPricing.get("id").getAsInt());

JsonObject jsonTax = (JsonObject) jsonPreference.get("taxes").getAsJsonArray().get(0);
assertEquals(tax.getType().toString(), jsonTax.get("type").getAsString());
assertEquals(tax.getValue(), jsonTax.get("value").getAsFloat(), 0.0f);

assertEquals(preference.getNotificationUrl(), jsonPreference.get("notification_url").getAsString());
assertNull(jsonPreference.get("id"));
assertNull(jsonPreference.get("init_point"));
Expand Down

0 comments on commit f9c1282

Please sign in to comment.