Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

// API version: 1ff4822a-2dfd-4393-800e-a562edb3fe32

Expand All @@ -24,4 +25,7 @@ public class OrderAutomaticPaymentsRequest {

/** Due date for the payment, in ISO 8601 format. */
private String dueDate;

/** Subscription metadata (id, sequence, and invoice) for the automatic payment. */
private Map<String, Object> subscription;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
@Getter
@Builder
public class PaymentNetworkDataRequest {
private final String networkTransactionId;
private final String transactionId;
private final String transactionLinkId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
public class PaymentNetworkTransactionDataRequest {
/** Network transaction identifier assigned by the card brand (Visa/Mastercard). */
private final String networkTransactionId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ public class PaymentPointOfInteractionRequest {
/** Transaction data associated with the point of interaction. */
private final PaymentTransactionDataRequest transactionData;

private final PaymentNetworkDataRequest networkData;

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class PaymentTransactionDataRequest {
private String billingDate;
/** Legacy card-network transaction identifier within transaction data. */
private String networkTransactionId;
/** Card-network identifiers for this credential-on-file transaction. */
private PaymentNetworkDataRequest networkData;
/**
* Whether this is the first transaction for a CREDENTIAL_ON_FILE payment.
* Replaces the legacy {@code firstTimeUse} field in new integrations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

// API version: 1ff4822a-2dfd-4393-800e-a562edb3fe32

Expand All @@ -24,4 +25,7 @@ public class OrderAutomaticPayments {

/** ISO 8601 date-time by which the automatic payment must be completed. */
private String dueDate;
}

/** Subscription metadata (id, sequence, and invoice) returned for the automatic payment. */
private Map<String, Object> subscription;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.mercadopago.resources.payment;

import com.mercadopago.client.payment.PaymentNetworkTransactionDataRequest;
import lombok.Getter;

/**
Expand All @@ -25,6 +24,6 @@ public class PaymentExpanded {
@Getter
public static class Gateway {
/** Network transaction data reference from the payment gateway. */
private PaymentNetworkTransactionDataRequest reference;
private PaymentGatewayReference reference;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.mercadopago.resources.payment;

import lombok.Getter;

/**
* Network references returned by an expanded payment gateway response.
*/
@Getter
public class PaymentGatewayReference {
/** Card-network transaction identifier. */
private String networkTransactionId;

/** Card-network transaction and link identifiers. */
private PaymentNetworkData networkData;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

@Getter
public class PaymentNetworkData {
private String networkTransactionId;
private String transactionId;
private String transactionLinkId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ public class PaymentPointOfInteraction {
/** Transaction-level data from the interaction channel (e.g. QR code, ticket URL). */
private PaymentTransactionData transactionData;

private PaymentNetworkData networkData;
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public class PaymentTransactionData {

/** Legacy card-network transaction identifier within transaction data. */
private String networkTransactionId;
/** Card-network identifiers for this credential-on-file transaction. */
private PaymentNetworkData networkData;

/**
* Whether this is the first transaction for a CREDENTIAL_ON_FILE payment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gson.JsonObject;
import com.mercadopago.serialization.Serializer;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -116,4 +117,22 @@ void existingBuilderStillWorksWithoutNewFields() {
Assertions.assertFalse(json.has("currency"));
Assertions.assertFalse(json.has("integration_data"));
}

@Test
void automaticPaymentsSubscriptionSerializesWithItsNestedFields() {
OrderAutomaticPaymentsRequest request =
OrderAutomaticPaymentsRequest.builder()
.subscription(
Map.of(
"id", "subscription-1",
"sequence", Map.of("number", 1, "total", 12),
"invoice", Map.of("id", "invoice-1", "period", Map.of("interval", 1, "type", "month"))))
.build();

JsonObject subscription = Serializer.serializeToJson(request).getAsJsonObject("subscription");

Assertions.assertEquals("subscription-1", subscription.get("id").getAsString());
Assertions.assertEquals(12, subscription.getAsJsonObject("sequence").get("total").getAsInt());
Assertions.assertEquals("month", subscription.getAsJsonObject("invoice").getAsJsonObject("period").get("type").getAsString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mercadopago.resources.order;

import static org.junit.jupiter.api.Assertions.assertEquals;

import com.mercadopago.exceptions.MPJsonParseException;
import com.mercadopago.serialization.Serializer;
import java.util.Map;
import org.junit.jupiter.api.Test;

class OrderAutomaticPaymentsTest {

@Test
void subscriptionDeserializesFromResponse() throws MPJsonParseException {
Order order =
Serializer.deserializeFromJson(
Order.class,
"{\"transactions\":{\"payments\":[{\"automatic_payments\":{\"subscription\":{\"id\":\"subscription-1\",\"sequence\":{\"number\":1,\"total\":12}}}}]}}");

Map<String, Object> subscription =
order.getTransactions().getPayments().get(0).getAutomaticPayments().getSubscription();
assertEquals("subscription-1", subscription.get("id"));
assertEquals(12.0, ((Map<?, ?>) subscription.get("sequence")).get("total"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.mercadopago.resources.payment;

import static org.junit.jupiter.api.Assertions.assertEquals;

import com.mercadopago.exceptions.MPJsonParseException;
import com.mercadopago.serialization.Serializer;
import org.junit.jupiter.api.Test;

class PaymentExpandedTest {

@Test
void gatewayReferenceDeserializesNetworkData() throws MPJsonParseException {
Payment payment =
Serializer.deserializeFromJson(
Payment.class,
"{\"expanded\":{\"gateway\":{\"reference\":{\"network_data\":{\"transaction_id\":\"ABC123\",\"transaction_link_id\":\"550e8400\"}}}}}");

assertEquals("ABC123", payment.getExpanded().getGateway().getReference().getNetworkData().getTransactionId());
assertEquals("550e8400", payment.getExpanded().getGateway().getReference().getNetworkData().getTransactionLinkId());
}
}
Loading