Skip to content
Draft
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
43 changes: 43 additions & 0 deletions src/main/java/com/mercadopago/client/order/OrderClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public class OrderClient extends MercadoPagoClient {
/** URL template for a specific transaction within an order. */
private static final String URL_TRANSACTION_WITH_ID = URL_WITH_ID + "/transactions/%s";

/** URL template for the order event simulation endpoint. */
private static final String URL_EVENTS = URL_WITH_ID + "/events";

/**
* Default constructor. Uses the default HTTP client provided by {@link MercadoPagoConfig}.
*/
Expand Down Expand Up @@ -536,6 +539,46 @@ public OrderSearchResponse search(MPSearchRequest request, MPRequestOptions requ
return result;
}

/**
* Simulates an event for an order (e.g., payment status change).
*
* @param orderId the unique identifier of the order
* @param request the {@link OrderSimulateEventRequest} containing the event details
* @throws MPException if a transport-level or SDK-internal error occurs
* @throws MPApiException if the API returns a non-successful HTTP status code
*/
public void simulateEvent(String orderId, OrderSimulateEventRequest request)
throws MPException, MPApiException {
this.simulateEvent(orderId, request, null);
}

/**
* Simulates an event for an order with custom request options.
*
* @param orderId the unique identifier of the order
* @param request the {@link OrderSimulateEventRequest} containing the event details
* @param requestOptions optional {@link MPRequestOptions} to override access token, headers, or
* timeouts for this single request; may be {@code null}
* @throws MPException if a transport-level or SDK-internal error occurs
* @throws MPApiException if the API returns a non-successful HTTP status code
* @throws IllegalArgumentException if {@code orderId} is blank or {@code null}
*/
public void simulateEvent(String orderId, OrderSimulateEventRequest request, MPRequestOptions requestOptions)
throws MPException, MPApiException {
LOGGER.info("Sending order simulate event request");

validateOrderID(orderId);

MPRequest mpRequest =
MPRequest.builder()
.uri(String.format("/v1/orders/%s/events", encodePathParam(orderId)))
.method(HttpMethod.POST)
.payload(Serializer.serializeToJson(request))
.build();

send(mpRequest, requestOptions);
}

/**
* Validates that the given order ID is not blank or {@code null}.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.mercadopago.client.order;

import lombok.Builder;
import lombok.Getter;

/**
* Request object for simulating order events via POST /v1/orders/{order_id}/events.
* Used to test order state transitions without actual payment processing.
*/
@Getter
@Builder
public class OrderSimulateEventRequest {

/**
* Target status for the order simulation (required).
* Valid values: processed, expired, canceled, refunded, failed, action_required.
*/
private String status;

/**
* Payment method type for the simulation (optional).
* Valid values: credit_card, debit_card, qr, voucher_card, cash.
*/
private String paymentMethodType;

/**
* Number of installments (optional).
* Valid range: 1-36.
*/
private Integer installments;

/**
* Payment method identifier (optional).
* Maximum length: 17 characters.
*/
private String paymentMethodId;

/**
* Detailed status reason (optional).
* Valid values: accredited, check_on_terminal, bad_filled_card_data,
* rejected_authorization, required_call_for_authorize, card_disabled,
* card_type_not_allowed, duplicated_payment, high_risk, insufficient_amount,
* invalid_installments, max_attempts_exceeded, rejected_other_reason, processing_error.
*/
private String statusDetail;
}
51 changes: 51 additions & 0 deletions src/test/java/com/mercadopago/client/order/OrderClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -595,4 +595,55 @@
Assertions.assertNotNull(result);
Assertions.assertEquals(HttpStatus.OK, result.getResponse().getStatusCode());
}

@Test
void simulateEventSuccess() throws MPException, MPApiException, IOException {
HttpResponse httpResponse = MockHelper.generateHttpResponse(HttpStatus.NO_CONTENT);
Mockito.doReturn(httpResponse)
.when(HTTP_CLIENT)
.execute(any(HttpRequestBase.class), any(HttpContext.class));

String orderId = "123";
OrderSimulateEventRequest request =
OrderSimulateEventRequest.builder().status("processed").build();

Assertions.assertDoesNotThrow(() -> client.simulateEvent(orderId, request));

ArgumentCaptor<HttpRequestBase> requestCaptor = ArgumentCaptor.forClass(HttpRequestBase.class);

Check failure on line 612 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 11

cannot find symbol

Check failure on line 612 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 11

cannot find symbol

Check failure on line 612 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 11

cannot find symbol

Check failure on line 612 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 11

cannot find symbol

Check failure on line 612 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 17

cannot find symbol

Check failure on line 612 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 17

cannot find symbol

Check failure on line 612 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 17

cannot find symbol

Check failure on line 612 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 17

cannot find symbol

Check failure on line 612 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 21

cannot find symbol

Check failure on line 612 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 21

cannot find symbol

Check failure on line 612 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 21

cannot find symbol

Check failure on line 612 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 21

cannot find symbol
Mockito.verify(HTTP_CLIENT).execute(requestCaptor.capture(), any(HttpContext.class));

HttpRequestBase httpRequest = requestCaptor.getValue();
Assertions.assertEquals("POST", httpRequest.getMethod());
Assertions.assertTrue(httpRequest.getURI().toString().contains("/v1/orders/123/events"));

JsonObject body = MockHelper.generateJsonElementFromUriRequest(httpRequest).getAsJsonObject();
Assertions.assertEquals("processed", body.get("status").getAsString());
}

@Test
void simulateEventWithRequestOptionsSuccess() throws MPException, MPApiException, IOException {
HttpResponse httpResponse = MockHelper.generateHttpResponse(HttpStatus.NO_CONTENT);
Mockito.doReturn(httpResponse)
.when(HTTP_CLIENT)
.execute(any(HttpRequestBase.class), any(HttpContext.class));

String orderId = "123";
OrderSimulateEventRequest request =
OrderSimulateEventRequest.builder()
.status("processed")
.paymentMethodType("credit_card")
.installments(3)
.paymentMethodId("visa")
.statusDetail("accredited")
.build();

Assertions.assertDoesNotThrow(() -> client.simulateEvent(orderId, request, buildRequestOptions()));

ArgumentCaptor<HttpRequestBase> requestCaptor = ArgumentCaptor.forClass(HttpRequestBase.class);

Check failure on line 642 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 11

cannot find symbol

Check failure on line 642 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 11

cannot find symbol

Check failure on line 642 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 11

cannot find symbol

Check failure on line 642 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 11

cannot find symbol

Check failure on line 642 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 17

cannot find symbol

Check failure on line 642 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 17

cannot find symbol

Check failure on line 642 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 17

cannot find symbol

Check failure on line 642 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 17

cannot find symbol

Check failure on line 642 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 21

cannot find symbol

Check failure on line 642 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 21

cannot find symbol

Check failure on line 642 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 21

cannot find symbol

Check failure on line 642 in src/test/java/com/mercadopago/client/order/OrderClientTest.java

View workflow job for this annotation

GitHub Actions / Test on Java 21

cannot find symbol
Mockito.verify(HTTP_CLIENT).execute(requestCaptor.capture(), any(HttpContext.class));

HttpRequestBase httpRequest = requestCaptor.getValue();
Assertions.assertEquals("POST", httpRequest.getMethod());
Assertions.assertTrue(httpRequest.getURI().toString().contains("/v1/orders/123/events"));
}
}
Loading