From 093a8e8d05dc973a8aa3784aaf6d3b7ecfabfa66 Mon Sep 17 00:00:00 2001 From: spec-agent-generator Date: Wed, 11 Nov 2026 04:22:26 +0000 Subject: [PATCH] auto-gen: SDK changes --- .../mercadopago/client/order/OrderClient.java | 43 ++++++++++++++++ .../order/OrderSimulateEventRequest.java | 46 +++++++++++++++++ .../client/order/OrderClientTest.java | 51 +++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 src/main/java/com/mercadopago/client/order/OrderSimulateEventRequest.java diff --git a/src/main/java/com/mercadopago/client/order/OrderClient.java b/src/main/java/com/mercadopago/client/order/OrderClient.java index cee42c4d..fb88c648 100644 --- a/src/main/java/com/mercadopago/client/order/OrderClient.java +++ b/src/main/java/com/mercadopago/client/order/OrderClient.java @@ -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}. */ @@ -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}. * diff --git a/src/main/java/com/mercadopago/client/order/OrderSimulateEventRequest.java b/src/main/java/com/mercadopago/client/order/OrderSimulateEventRequest.java new file mode 100644 index 00000000..17ebe3a9 --- /dev/null +++ b/src/main/java/com/mercadopago/client/order/OrderSimulateEventRequest.java @@ -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; +} diff --git a/src/test/java/com/mercadopago/client/order/OrderClientTest.java b/src/test/java/com/mercadopago/client/order/OrderClientTest.java index 812254e5..855ccd49 100644 --- a/src/test/java/com/mercadopago/client/order/OrderClientTest.java +++ b/src/test/java/com/mercadopago/client/order/OrderClientTest.java @@ -595,4 +595,55 @@ void cancelWithRequestOptionsSuccess() throws MPException, MPApiException, IOExc 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 requestCaptor = ArgumentCaptor.forClass(HttpRequestBase.class); + 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 requestCaptor = ArgumentCaptor.forClass(HttpRequestBase.class); + 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")); + } }