From 06b53669d9681d2f68de326118450d8e595d7033 Mon Sep 17 00:00:00 2001 From: Marianne Bianca Date: Fri, 18 Oct 2024 16:34:05 -0300 Subject: [PATCH] adding post create order --- .../order/OrderCategoryDescriptorRequest.java | 18 +++++ .../mercadopago/client/order/OrderClient.java | 80 +++++++++++++++++++ .../client/order/OrderCouponRequest.java | 13 +++ .../client/order/OrderCreateRequest.java | 63 +++++++++++++++ .../client/order/OrderItemRequest.java | 35 ++++++++ .../client/order/OrderPassengerRequest.java | 20 +++++ .../client/order/OrderPayerRequest.java | 49 ++++++++++++ .../order/OrderPaymentMethodRequest.java | 28 +++++++ .../client/order/OrderPaymentRequest.java | 19 +++++ .../order/OrderReceiverAddressRequest.java | 29 +++++++ .../client/order/OrderRouteRequest.java | 23 ++++++ .../client/order/OrderShipmentRequest.java | 23 ++++++ .../client/order/OrderSplitRequest.java | 17 ++++ .../client/order/OrderTransactionRequest.java | 15 ++++ .../client/order/OrderTypeConfigRequest.java | 17 ++++ .../example/apis/order/createOrder.java | 58 ++++++++++++++ .../mercadopago/resources/order/Order.java | 77 ++++++++++++++++++ .../order/OrderCategoryDescriptor.java | 16 ++++ .../resources/order/OrderItem.java | 35 ++++++++ .../resources/order/OrderPassenger.java | 20 +++++ .../resources/order/OrderPayer.java | 47 +++++++++++ .../resources/order/OrderPayment.java | 29 +++++++ .../resources/order/OrderPaymentMethod.java | 25 ++++++ .../resources/order/OrderReceiverAddress.java | 29 +++++++ .../resources/order/OrderReference.java | 14 ++++ .../resources/order/OrderRefund.java | 23 ++++++ .../resources/order/OrderRoute.java | 22 +++++ .../resources/order/OrderShipment.java | 23 ++++++ .../resources/order/OrderTransaction.java | 16 ++++ .../resources/order/OrderTypeConfig.java | 17 ++++ .../client/order/OrderClientTest.java | 71 ++++++++++++++++ .../response/order/create_order_response.json | 37 +++++++++ 32 files changed, 1008 insertions(+) create mode 100644 src/main/java/com/mercadopago/client/order/OrderCategoryDescriptorRequest.java create mode 100644 src/main/java/com/mercadopago/client/order/OrderClient.java create mode 100644 src/main/java/com/mercadopago/client/order/OrderCouponRequest.java create mode 100644 src/main/java/com/mercadopago/client/order/OrderCreateRequest.java create mode 100644 src/main/java/com/mercadopago/client/order/OrderItemRequest.java create mode 100644 src/main/java/com/mercadopago/client/order/OrderPassengerRequest.java create mode 100644 src/main/java/com/mercadopago/client/order/OrderPayerRequest.java create mode 100644 src/main/java/com/mercadopago/client/order/OrderPaymentMethodRequest.java create mode 100644 src/main/java/com/mercadopago/client/order/OrderPaymentRequest.java create mode 100644 src/main/java/com/mercadopago/client/order/OrderReceiverAddressRequest.java create mode 100644 src/main/java/com/mercadopago/client/order/OrderRouteRequest.java create mode 100644 src/main/java/com/mercadopago/client/order/OrderShipmentRequest.java create mode 100644 src/main/java/com/mercadopago/client/order/OrderSplitRequest.java create mode 100644 src/main/java/com/mercadopago/client/order/OrderTransactionRequest.java create mode 100644 src/main/java/com/mercadopago/client/order/OrderTypeConfigRequest.java create mode 100644 src/main/java/com/mercadopago/example/apis/order/createOrder.java create mode 100644 src/main/java/com/mercadopago/resources/order/Order.java create mode 100644 src/main/java/com/mercadopago/resources/order/OrderCategoryDescriptor.java create mode 100644 src/main/java/com/mercadopago/resources/order/OrderItem.java create mode 100644 src/main/java/com/mercadopago/resources/order/OrderPassenger.java create mode 100644 src/main/java/com/mercadopago/resources/order/OrderPayer.java create mode 100644 src/main/java/com/mercadopago/resources/order/OrderPayment.java create mode 100644 src/main/java/com/mercadopago/resources/order/OrderPaymentMethod.java create mode 100644 src/main/java/com/mercadopago/resources/order/OrderReceiverAddress.java create mode 100644 src/main/java/com/mercadopago/resources/order/OrderReference.java create mode 100644 src/main/java/com/mercadopago/resources/order/OrderRefund.java create mode 100644 src/main/java/com/mercadopago/resources/order/OrderRoute.java create mode 100644 src/main/java/com/mercadopago/resources/order/OrderShipment.java create mode 100644 src/main/java/com/mercadopago/resources/order/OrderTransaction.java create mode 100644 src/main/java/com/mercadopago/resources/order/OrderTypeConfig.java create mode 100644 src/test/java/com/mercadopago/client/order/OrderClientTest.java create mode 100644 src/test/java/com/mercadopago/resources/mocks/response/order/create_order_response.json diff --git a/src/main/java/com/mercadopago/client/order/OrderCategoryDescriptorRequest.java b/src/main/java/com/mercadopago/client/order/OrderCategoryDescriptorRequest.java new file mode 100644 index 00000000..d31bbd5f --- /dev/null +++ b/src/main/java/com/mercadopago/client/order/OrderCategoryDescriptorRequest.java @@ -0,0 +1,18 @@ +package com.mercadopago.client.order; + +import lombok.Getter; + +/** OrderCategoryDescriptorRequest class. */ +@Getter +public class OrderCategoryDescriptorRequest { + + /** Event date. */ + private String eventDate; + + /** Passenger information. */ + private OrderPassengerRequest passenger; + + /** Route information. */ + private OrderRouteRequest route; +} + diff --git a/src/main/java/com/mercadopago/client/order/OrderClient.java b/src/main/java/com/mercadopago/client/order/OrderClient.java new file mode 100644 index 00000000..1dcb22dc --- /dev/null +++ b/src/main/java/com/mercadopago/client/order/OrderClient.java @@ -0,0 +1,80 @@ +package com.mercadopago.client.order; + +import com.mercadopago.MercadoPagoConfig; +import com.mercadopago.client.MercadoPagoClient; +import com.mercadopago.core.MPRequestOptions; +import com.mercadopago.exceptions.MPApiException; +import com.mercadopago.exceptions.MPException; +import com.mercadopago.net.HttpMethod; +import com.mercadopago.net.MPHttpClient; +import com.mercadopago.net.MPRequest; +import com.mercadopago.net.MPResponse; +import com.mercadopago.resources.order.Order; +import com.mercadopago.serialization.Serializer; + +import java.util.logging.Logger; +import java.util.logging.StreamHandler; + +import static com.mercadopago.MercadoPagoConfig.getStreamHandler; + +/** Client that use the Order API */ +public class OrderClient extends MercadoPagoClient { + private static final Logger LOGGER = Logger.getLogger(OrderClient.class.getName()); + + /** Default constructor. Uses the default http client used by the SDK. */ + public OrderClient() { + this(MercadoPagoConfig.getHttpClient()); + } + + /** + * MercadoPagoClient constructor. + * + * @param httpClient http client + */ + public OrderClient(MPHttpClient httpClient) { + super(httpClient); + StreamHandler streamHandler = getStreamHandler(); + streamHandler.setLevel(MercadoPagoConfig.getLoggingLevel()); + LOGGER.addHandler(streamHandler); + LOGGER.setLevel(MercadoPagoConfig.getLoggingLevel()); + } + + /** + * Method responsible for creating order with request options + * + * @param request request + * @param requestOptions metadata to customize the request + * @return order response + * @throws MPException an error if the request fails + * @throws MPApiException an error if the request fails + */ + public Order create(OrderCreateRequest request, MPRequestOptions requestOptions) + throws MPException, MPApiException { + LOGGER.info("Sending order creation request"); + + MPRequest mpRequest = MPRequest.builder() + .uri("/v1/orders") + .method(HttpMethod.POST) + .payload(Serializer.serializeToJson(request)) + .build(); + + MPResponse response = send(mpRequest, requestOptions); + Order result = Serializer.deserializeFromJson(Order.class, response.getContent()); + result.setResponse(response); + + return result; + } + + /** + * Method responsible for creating order with request options + * + * @param request request + * @return order response + * @throws MPException an error if the request fails + * @throws MPApiException an error if the request fails + */ + public Order create(OrderCreateRequest request) throws MPException, MPApiException { + return this.create(request, null); + } + +} diff --git a/src/main/java/com/mercadopago/client/order/OrderCouponRequest.java b/src/main/java/com/mercadopago/client/order/OrderCouponRequest.java new file mode 100644 index 00000000..0a592401 --- /dev/null +++ b/src/main/java/com/mercadopago/client/order/OrderCouponRequest.java @@ -0,0 +1,13 @@ +package com.mercadopago.client.order; + +import lombok.Getter; + +/** OrderCouponRequest class. */ +@Getter +public class OrderCouponRequest { + /** Coupon code. */ + private String code; + + /** Amount of the coupon discount. */ + private String amount; +} diff --git a/src/main/java/com/mercadopago/client/order/OrderCreateRequest.java b/src/main/java/com/mercadopago/client/order/OrderCreateRequest.java new file mode 100644 index 00000000..0aee1a57 --- /dev/null +++ b/src/main/java/com/mercadopago/client/order/OrderCreateRequest.java @@ -0,0 +1,63 @@ +package com.mercadopago.client.order; + +import com.mercadopago.net.MPResource; +import lombok.Builder; +import lombok.Getter; + +import java.util.List; + +/** Order class. */ +@Builder +@Getter +public class OrderCreateRequest extends MPResource { + /** Order type. */ + private String type; + + /** Total amount of the order. */ + private String totalAmount; + + /** Reference you can synchronize with your payment system. */ + private String externalReference; + + /** Order type configuration. */ + private OrderTypeConfigRequest typeConfig; + + /** Order transaction information. */ + private OrderTransactionRequest transactions; + + /** Currency information. */ + private String currency; + + /** Configures which processing modes to use. */ + private String processingMode; + + /** Description of the order. */ + private String description; + + /** Payer's information. */ + private OrderPayerRequest payer; + + /** Origin of the payment. */ + private String marketplace; + + /** Fee collected by a marketplace or MercadoPago Application. */ + private String marketplaceFee; + + /** Discount campaign ID. */ + private String campaignId; + + /** Items information. */ + private List items; + + /** Coupon information. */ + private OrderCouponRequest coupon; + + /** Information's about split payments. */ + private List splits; + + /** Shipping information. */ + private OrderShipmentRequest shipment; + + /** Expiration time of the order. */ + private String expirationTime; +} diff --git a/src/main/java/com/mercadopago/client/order/OrderItemRequest.java b/src/main/java/com/mercadopago/client/order/OrderItemRequest.java new file mode 100644 index 00000000..2ed0814c --- /dev/null +++ b/src/main/java/com/mercadopago/client/order/OrderItemRequest.java @@ -0,0 +1,35 @@ +package com.mercadopago.client.order; + +import lombok.Getter; + +/** OrderItemRequest class. */ +@Getter +public class OrderItemRequest { + + /** Title of the item. */ + private String title; + + /** Unit price of the item. */ + private String unitPrice; + + /** Quantity of the item. */ + private int quantity; + + /** Description of the item. */ + private String description; + + /** Code of the item. */ + private String code; + + /** Type of the item. */ + private String type; + + /** Picture URL of the item. */ + private String pictureUrl; + + /** True if you purchase the item with warranty, false if not. */ + private Boolean warranty; + + /** Category Descriptor information */ + private OrderCategoryDescriptorRequest categoryDescriptor; +} diff --git a/src/main/java/com/mercadopago/client/order/OrderPassengerRequest.java b/src/main/java/com/mercadopago/client/order/OrderPassengerRequest.java new file mode 100644 index 00000000..fb7540e8 --- /dev/null +++ b/src/main/java/com/mercadopago/client/order/OrderPassengerRequest.java @@ -0,0 +1,20 @@ +package com.mercadopago.client.order; + +import lombok.Getter; + +/** OrderPassengerRequest class. */ +@Getter +public class OrderPassengerRequest { + + /** Passenger first name. */ + private String firstName; + + /** Passenger last name. */ + private String lastName; + + /** Passenger identification type. */ + private String identificationType; + + /** Passenger identification number. */ + private String identificationNumber; +} diff --git a/src/main/java/com/mercadopago/client/order/OrderPayerRequest.java b/src/main/java/com/mercadopago/client/order/OrderPayerRequest.java new file mode 100644 index 00000000..51f9aca5 --- /dev/null +++ b/src/main/java/com/mercadopago/client/order/OrderPayerRequest.java @@ -0,0 +1,49 @@ +package com.mercadopago.client.order; + +import com.mercadopago.resources.common.Address; +import com.mercadopago.resources.common.Identification; +import com.mercadopago.resources.common.Phone; +import lombok.Builder; +import lombok.Getter; + +/** OrderPayerRequest class. */ +@Getter +@Builder +public class OrderPayerRequest { + + /** Payer's email. */ + private String email; + + /** Payer's first name. */ + private String firstName; + + /** Payer's last name. */ + private String lastName; + + /** Identification information. */ + private Identification identification; + + /** Phone information. */ + private Phone phone; + + /** Address information. */ + private Address address; + + /** Type of authentication. */ + private String authenticationType; + + /** Date of registration. */ + private String registrationDate; + + /** Date of last purchase. */ + private String lastPurchase; + + /** If payer is prime user. */ + private Boolean isPrimeUser; + + /** If is first online purchase. */ + private Boolean isFirstPurchaseOnline; + + /** Payer's entity type. */ + private String entityType; +} diff --git a/src/main/java/com/mercadopago/client/order/OrderPaymentMethodRequest.java b/src/main/java/com/mercadopago/client/order/OrderPaymentMethodRequest.java new file mode 100644 index 00000000..f3d507b7 --- /dev/null +++ b/src/main/java/com/mercadopago/client/order/OrderPaymentMethodRequest.java @@ -0,0 +1,28 @@ +package com.mercadopago.client.order; + +import lombok.Builder; +import lombok.Getter; + +/** OrderPaymentMethodCreateRequest class. */ +@Getter +@Builder +public class OrderPaymentMethodRequest { + + /** Payment method ID. */ + private String id; + + /** Payment method type. */ + private String type; + + /** Payment method token. */ + private String token; + + /** Number of installments. */ + private int installments; + + /** Payment method issuer. */ + private String issuerId; + + /** How will look the payment in the card bill (e.g.: MERCADOPAGO). */ + private String statementDescriptor; +} diff --git a/src/main/java/com/mercadopago/client/order/OrderPaymentRequest.java b/src/main/java/com/mercadopago/client/order/OrderPaymentRequest.java new file mode 100644 index 00000000..4c7d2e96 --- /dev/null +++ b/src/main/java/com/mercadopago/client/order/OrderPaymentRequest.java @@ -0,0 +1,19 @@ +package com.mercadopago.client.order; + +import lombok.Builder; +import lombok.Getter; + +/** OrderPaymentCreateRequest class. */ +@Getter +@Builder +public class OrderPaymentRequest { + + /** Payment amount. */ + private String amount; + + /** Payment currency. */ + private String currency; + + /** Payment method information. */ + private OrderPaymentMethodRequest paymentMethod; +} diff --git a/src/main/java/com/mercadopago/client/order/OrderReceiverAddressRequest.java b/src/main/java/com/mercadopago/client/order/OrderReceiverAddressRequest.java new file mode 100644 index 00000000..e8b1735a --- /dev/null +++ b/src/main/java/com/mercadopago/client/order/OrderReceiverAddressRequest.java @@ -0,0 +1,29 @@ +package com.mercadopago.client.order; + +import lombok.Getter; + +/** OrderReceiverAddressRequest class. */ +@Getter +public class OrderReceiverAddressRequest { + + /** Street name. */ + private String streetName; + + /** Street number. */ + private String streetNumber; + + /** Zip code. */ + private String zipCode; + + /** City name. */ + private String cityName; + + /** State name. */ + private String stateName; + + /** Floor. */ + private String floor; + + /** Apartment. */ + private String apartment; +} diff --git a/src/main/java/com/mercadopago/client/order/OrderRouteRequest.java b/src/main/java/com/mercadopago/client/order/OrderRouteRequest.java new file mode 100644 index 00000000..a3f3e185 --- /dev/null +++ b/src/main/java/com/mercadopago/client/order/OrderRouteRequest.java @@ -0,0 +1,23 @@ +package com.mercadopago.client.order; + +import lombok.Getter; + +/** OrderRouteRequest class. */ +@Getter +public class OrderRouteRequest { + + /** Departure city. */ + private String departure; + + /** Destination city. */ + private String destination; + + /** Departure date and time. */ + private String departureDateTime; + + /** Arrival date and time. */ + private String arrivalDateTime; + + /** Company name. */ + private String company; +} diff --git a/src/main/java/com/mercadopago/client/order/OrderShipmentRequest.java b/src/main/java/com/mercadopago/client/order/OrderShipmentRequest.java new file mode 100644 index 00000000..fb7c0b2f --- /dev/null +++ b/src/main/java/com/mercadopago/client/order/OrderShipmentRequest.java @@ -0,0 +1,23 @@ +package com.mercadopago.client.order; + +import lombok.Getter; + +/** OrderShipmentRequest class. */ +@Getter +public class OrderShipmentRequest { + + /** Receiver address information. */ + private OrderReceiverAddressRequest receiverAddress; + + /** Weight of the package. */ + private float width; + + /** Height of the package. */ + private float height; + + /** If the shipment is express. */ + private Boolean expressShipment; + + /** If to pick up on seller. */ + private Boolean pickUpOnSeller; +} diff --git a/src/main/java/com/mercadopago/client/order/OrderSplitRequest.java b/src/main/java/com/mercadopago/client/order/OrderSplitRequest.java new file mode 100644 index 00000000..e085cb7e --- /dev/null +++ b/src/main/java/com/mercadopago/client/order/OrderSplitRequest.java @@ -0,0 +1,17 @@ +package com.mercadopago.client.order; + +import lombok.Getter; + +/** Order split request. */ +@Getter +public class OrderSplitRequest { + + /** Access token. */ + private String oauthToken; + + /** Split type. */ + private String type; + + /** Split value. */ + private String value; +} diff --git a/src/main/java/com/mercadopago/client/order/OrderTransactionRequest.java b/src/main/java/com/mercadopago/client/order/OrderTransactionRequest.java new file mode 100644 index 00000000..a39e8d8c --- /dev/null +++ b/src/main/java/com/mercadopago/client/order/OrderTransactionRequest.java @@ -0,0 +1,15 @@ +package com.mercadopago.client.order; + +import lombok.Builder; +import lombok.Getter; + +import java.util.List; + +/** OrderTransactionRequest class. */ +@Builder +@Getter +public class OrderTransactionRequest { + + /** List of payments. */ + private List payments; +} diff --git a/src/main/java/com/mercadopago/client/order/OrderTypeConfigRequest.java b/src/main/java/com/mercadopago/client/order/OrderTypeConfigRequest.java new file mode 100644 index 00000000..28c38d00 --- /dev/null +++ b/src/main/java/com/mercadopago/client/order/OrderTypeConfigRequest.java @@ -0,0 +1,17 @@ +package com.mercadopago.client.order; + +import lombok.Getter; + +/** OrderTypeConfigRequest class. */ +@Getter +public class OrderTypeConfigRequest { + + /** Capture mode. */ + private String captureMode; + + /** IP Address. */ + private String ipAddress; + + /** URL where MercadoPago does the final redirect. */ + private String callbackUrl; +} diff --git a/src/main/java/com/mercadopago/example/apis/order/createOrder.java b/src/main/java/com/mercadopago/example/apis/order/createOrder.java new file mode 100644 index 00000000..dfd6c9f3 --- /dev/null +++ b/src/main/java/com/mercadopago/example/apis/order/createOrder.java @@ -0,0 +1,58 @@ +package com.mercadopago.example.apis.order; + +import com.mercadopago.MercadoPagoConfig; +import com.mercadopago.client.order.*; +import com.mercadopago.core.MPRequestOptions; +import com.mercadopago.resources.order.Order; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class createOrder { + + public static void main(String[] args) { + MercadoPagoConfig.setAccessToken("{{ACCESS_TOKEN}}"); + + OrderClient client = new OrderClient(); + + OrderPaymentRequest payment = OrderPaymentRequest.builder() + .amount("10.00") + .paymentMethod(OrderPaymentMethodRequest.builder() + .id("master") + .type("credit_card") + .token("{{CARD_TOKEN}}") + .installments(1) + .build()) + .build(); + + List payments = new ArrayList<>(); + payments.add(payment); + + OrderCreateRequest request = OrderCreateRequest.builder() + .type("online") + .totalAmount("10.00") + .externalReference("ext_ref") + .payer(OrderPayerRequest.builder().email("test@email.com").build()) + .transactions(OrderTransactionRequest.builder() + .payments(payments) + .build()) + .build(); + + Map headers = new HashMap<>(); + headers.put("X-Sandbox", "true"); + MPRequestOptions requestOptions = MPRequestOptions.builder() + .customHeaders(headers) + .build(); + + try { + Order order = client.create(request, requestOptions); + System.out.println("Order created: " + order.getId()); + } catch (Exception e) { + System.out.println("Error creating order: " + e.getMessage()); + } + + } + +} diff --git a/src/main/java/com/mercadopago/resources/order/Order.java b/src/main/java/com/mercadopago/resources/order/Order.java new file mode 100644 index 00000000..4ae326ed --- /dev/null +++ b/src/main/java/com/mercadopago/resources/order/Order.java @@ -0,0 +1,77 @@ +package com.mercadopago.resources.order; + +import com.mercadopago.net.MPResource; +import lombok.Getter; + +import java.util.List; + +/** Order class. */ +@Getter +public class Order extends MPResource { + + /** Order ID. */ + private String id; + + /** Configures which processing modes to use. */ + private String processingMode; + + /** External reference. */ + private String externalReference; + + /** Description of Order. */ + private String description; + + /** Origin of the order. */ + private String marketplace; + + /** Fee collected by a marketplace or MercadoPago Application. */ + private String marketplaceFee; + + /** Campaign ID. */ + private String campaignId; + + /** Total amount of the order. */ + private String totalAmount; + + /** Currency information. */ + private String currency; + + /** Date of expiration. */ + private String expirationTime; + + /** Site ID. */ + private String siteId; + + /** Unique ID that identifies your integration. You can get it in Your credentials. */ + private String clientId; + + /** ID of the collector associated with the order. */ + private String collectorId; + + /** Date of creation. */ + private String createdDate; + + /** Last modified date. */ + private String lastUpdatedDate; + + /** Type of Order. */ + private String type; + + /** Status of Order. */ + private String status; + + /** Order type configuration. */ + private OrderTypeConfig typeConfig; + + /** Payer information. */ + private OrderPayer payer; + + /** Transactions information. */ + private OrderTransaction transactions; + + /** Shipping information. */ + private OrderShipment shipment; + + /** Items information. */ + private List items; +} diff --git a/src/main/java/com/mercadopago/resources/order/OrderCategoryDescriptor.java b/src/main/java/com/mercadopago/resources/order/OrderCategoryDescriptor.java new file mode 100644 index 00000000..adbea6d5 --- /dev/null +++ b/src/main/java/com/mercadopago/resources/order/OrderCategoryDescriptor.java @@ -0,0 +1,16 @@ +package com.mercadopago.resources.order; + +import lombok.Getter; + +/** OrderCategoryDescriptor class. */ +@Getter +public class OrderCategoryDescriptor { + /** Event date. */ + private String eventDate; + + /** Passenger information. */ + private OrderPassenger passenger; + + /** Route information. */ + private OrderRoute route; +} diff --git a/src/main/java/com/mercadopago/resources/order/OrderItem.java b/src/main/java/com/mercadopago/resources/order/OrderItem.java new file mode 100644 index 00000000..5107f562 --- /dev/null +++ b/src/main/java/com/mercadopago/resources/order/OrderItem.java @@ -0,0 +1,35 @@ +package com.mercadopago.resources.order; + +import lombok.Getter; + +/** OrderItem class. */ +@Getter +public class OrderItem { + + /** Title of the item. */ + private String title; + + /** Description of the item. */ + private String description; + + /** Unit price of the item. */ + private String unitPrice; + + /** Code of the item. */ + private String code; + + /** Type of the item. */ + private String type; + + /** Picture URL of the item. */ + private String pictureUrl; + + /** Quantity of the item. */ + private int quantity; + + /** True if you purchase the item with warranty, false if not. */ + private Boolean warranty; + + /** Category Descriptor information */ + private OrderCategoryDescriptor categoryDescriptor; +} diff --git a/src/main/java/com/mercadopago/resources/order/OrderPassenger.java b/src/main/java/com/mercadopago/resources/order/OrderPassenger.java new file mode 100644 index 00000000..f0c0513a --- /dev/null +++ b/src/main/java/com/mercadopago/resources/order/OrderPassenger.java @@ -0,0 +1,20 @@ +package com.mercadopago.resources.order; + +import lombok.Getter; + +/** OrderPassenger class. */ +@Getter +public class OrderPassenger { + + /** Passenger first name. */ + private String firstName; + + /** Passenger last name. */ + private String lastName; + + /** Passenger identification type. */ + private String identificationType; + + /** Passenger identification number. */ + private String identificationNumber; +} diff --git a/src/main/java/com/mercadopago/resources/order/OrderPayer.java b/src/main/java/com/mercadopago/resources/order/OrderPayer.java new file mode 100644 index 00000000..69ed0163 --- /dev/null +++ b/src/main/java/com/mercadopago/resources/order/OrderPayer.java @@ -0,0 +1,47 @@ +package com.mercadopago.resources.order; + +import com.mercadopago.resources.common.Address; +import com.mercadopago.resources.common.Identification; +import com.mercadopago.resources.common.Phone; +import lombok.Getter; + +/** OrderPayer class. */ +@Getter +public class OrderPayer { + + /** Payer's email. */ + private String email; + + /** Payer's first name. */ + private String firstName; + + /** Payer's last name. */ + private String lastName; + + /** Type of authentication. */ + private String authenticationType; + + /** Date of registration. */ + private String registrationDate; + + /** Date of last purchase. */ + private String lastPurchase; + + /** Payer's entity type. */ + private String entityType; + + /** If payer is prime user. */ + private Boolean isPrimeUser; + + /** If is first online purchase. */ + private Boolean isFirstPurchaseOnline; + + /** Identification information. */ + private Identification identification; + + /** Phone information. */ + private Phone phone; + + /** Address information. */ + private Address address; +} diff --git a/src/main/java/com/mercadopago/resources/order/OrderPayment.java b/src/main/java/com/mercadopago/resources/order/OrderPayment.java new file mode 100644 index 00000000..c5682ca8 --- /dev/null +++ b/src/main/java/com/mercadopago/resources/order/OrderPayment.java @@ -0,0 +1,29 @@ +package com.mercadopago.resources.order; + +import lombok.Getter; + +/** OrderPayment class. */ +@Getter +public class OrderPayment { + + /** Payment ID. */ + private String id; + + /** Payment amount. */ + private String amount; + + /** Payment currency. */ + private String currency; + + /** Payment status. */ + private String status; + + /** Payment status detail. */ + private String statusDetail; + + /** Reference to the order. */ + private OrderReference reference; + + /** Payment method information. */ + private OrderPaymentMethod paymentMethod; +} diff --git a/src/main/java/com/mercadopago/resources/order/OrderPaymentMethod.java b/src/main/java/com/mercadopago/resources/order/OrderPaymentMethod.java new file mode 100644 index 00000000..390d0ed4 --- /dev/null +++ b/src/main/java/com/mercadopago/resources/order/OrderPaymentMethod.java @@ -0,0 +1,25 @@ +package com.mercadopago.resources.order; + +import lombok.Getter; + +/** OrderPaymentMethod class. */ +@Getter +public class OrderPaymentMethod { + /** Payment method ID. */ + private String id; + + /** Payment method type. */ + private String type; + + /** Payment method token. */ + private String token; + + /** Number of installments. */ + private int installments; + + /** Payment method issuer. */ + private String issuerId; + + /** How will look the payment in the card bill (e.g.: MERCADOPAGO). */ + private String StatementDescriptor; +} diff --git a/src/main/java/com/mercadopago/resources/order/OrderReceiverAddress.java b/src/main/java/com/mercadopago/resources/order/OrderReceiverAddress.java new file mode 100644 index 00000000..65135915 --- /dev/null +++ b/src/main/java/com/mercadopago/resources/order/OrderReceiverAddress.java @@ -0,0 +1,29 @@ +package com.mercadopago.resources.order; + +import lombok.Getter; + +/** OrderReceiverAddress class. */ +@Getter +public class OrderReceiverAddress { + + /** Street name. */ + private String streetName; + + /** Street number. */ + private String streetNumber; + + /** Zip code. */ + private String zipCode; + + /** City name. */ + private String cityName; + + /** State name. */ + private String stateName; + + /** Floor. */ + private String floor; + + /** Apartment. */ + private String apartment; +} diff --git a/src/main/java/com/mercadopago/resources/order/OrderReference.java b/src/main/java/com/mercadopago/resources/order/OrderReference.java new file mode 100644 index 00000000..a7a975cf --- /dev/null +++ b/src/main/java/com/mercadopago/resources/order/OrderReference.java @@ -0,0 +1,14 @@ +package com.mercadopago.resources.order; + +import lombok.Getter; + +/** OrderReferenceRefunds class. */ +@Getter +public class OrderReference { + + /** ID of Order Reference. */ + private String id; + + /** Source of Order Reference. */ + private String source; +} diff --git a/src/main/java/com/mercadopago/resources/order/OrderRefund.java b/src/main/java/com/mercadopago/resources/order/OrderRefund.java new file mode 100644 index 00000000..af744efd --- /dev/null +++ b/src/main/java/com/mercadopago/resources/order/OrderRefund.java @@ -0,0 +1,23 @@ +package com.mercadopago.resources.order; + +import lombok.Getter; + +/** OrderRefund class. */ +@Getter +public class OrderRefund { + + /** Refund ID. */ + private String id; + + /** Payment ID. */ + private String paymentId; + + /** Refund amount. */ + private String amount; + + /** Status of refund. */ + private String status; + + /** Reference of the refund. */ + private OrderReference reference; +} diff --git a/src/main/java/com/mercadopago/resources/order/OrderRoute.java b/src/main/java/com/mercadopago/resources/order/OrderRoute.java new file mode 100644 index 00000000..e2734866 --- /dev/null +++ b/src/main/java/com/mercadopago/resources/order/OrderRoute.java @@ -0,0 +1,22 @@ +package com.mercadopago.resources.order; + +import lombok.Getter; + +/** OrderRoute class. */ +@Getter +public class OrderRoute { + /** Departure city. */ + private String departure; + + /** Destination city. */ + private String destination; + + /** Departure date and time. */ + private String departureDateTime; + + /** Arrival date and time. */ + private String arrivalDateTime; + + /** Company name. */ + private String company; +} diff --git a/src/main/java/com/mercadopago/resources/order/OrderShipment.java b/src/main/java/com/mercadopago/resources/order/OrderShipment.java new file mode 100644 index 00000000..fadd3eed --- /dev/null +++ b/src/main/java/com/mercadopago/resources/order/OrderShipment.java @@ -0,0 +1,23 @@ +package com.mercadopago.resources.order; + +import lombok.Getter; + +/** OrderShipment class. */ +@Getter +public class OrderShipment { + + /** Receiver address information. */ + private OrderReceiverAddress receiverAddress; + + /** Weight of the package. */ + private float width; + + /** Height of the package. */ + private float height; + + /** If the shipment is express. */ + private Boolean expressShipment; + + /** If to pick up on seller. */ + private Boolean pickUpOnSeller; +} diff --git a/src/main/java/com/mercadopago/resources/order/OrderTransaction.java b/src/main/java/com/mercadopago/resources/order/OrderTransaction.java new file mode 100644 index 00000000..cdd3bff5 --- /dev/null +++ b/src/main/java/com/mercadopago/resources/order/OrderTransaction.java @@ -0,0 +1,16 @@ +package com.mercadopago.resources.order; + +import lombok.Getter; + +import java.util.List; + +/** OrderTransaction class. */ +@Getter +public class OrderTransaction { + + /** Payments information. */ + private List payments; + + /** Refunds information. */ + private List refunds; +} diff --git a/src/main/java/com/mercadopago/resources/order/OrderTypeConfig.java b/src/main/java/com/mercadopago/resources/order/OrderTypeConfig.java new file mode 100644 index 00000000..fba10f23 --- /dev/null +++ b/src/main/java/com/mercadopago/resources/order/OrderTypeConfig.java @@ -0,0 +1,17 @@ +package com.mercadopago.resources.order; + +import lombok.Getter; + +/** OrderTypeConfig class. */ +@Getter +public class OrderTypeConfig { + + /** Capture mode. */ + private String captureMode; + + /** IP Address. */ + private String ipAddress; + + /** Notification URL. */ + private String callbackUrl; +} diff --git a/src/test/java/com/mercadopago/client/order/OrderClientTest.java b/src/test/java/com/mercadopago/client/order/OrderClientTest.java new file mode 100644 index 00000000..f57c1547 --- /dev/null +++ b/src/test/java/com/mercadopago/client/order/OrderClientTest.java @@ -0,0 +1,71 @@ +package com.mercadopago.client.order; + +import com.mercadopago.BaseClientTest; +import com.mercadopago.exceptions.MPApiException; +import com.mercadopago.exceptions.MPException; +import com.mercadopago.helper.MockHelper; +import com.mercadopago.net.HttpStatus; +import com.mercadopago.resources.order.Order; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.protocol.HttpContext; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static org.mockito.Matchers.any; + +class OrderClientTest extends BaseClientTest { + + //File Mock Responses + private static final String CREATE_ORDER_RESPONSE_FILE = "order/create_order_response.json"; + + private final OrderClient client = new OrderClient(); + + @Test + void createSuccess() throws MPException, MPApiException, IOException { + //given + OrderCreateRequest request = getMinimumOrderCreateRequest(); + + //Mock HttpClient + HttpResponse response = MockHelper.generateHttpResponseFromFile(CREATE_ORDER_RESPONSE_FILE, HttpStatus.CREATED); + Mockito.doReturn(response).when(HTTP_CLIENT).execute(any(HttpRequestBase.class), any(HttpContext.class)); + + //when + Order order = client.create(request); + + //then + Assertions.assertNotNull(order); + Assertions.assertEquals(request.getTotalAmount() ,order.getTotalAmount()); + + } + + private static OrderCreateRequest getMinimumOrderCreateRequest() { + OrderPaymentRequest payment = OrderPaymentRequest.builder() + .amount("10.00") + .paymentMethod(OrderPaymentMethodRequest.builder() + .id("master") + .type("credit_card") + .token("card_token") + .installments(1) + .build()) + .build(); + + List payments = new ArrayList<>(); + payments.add(payment); + + return OrderCreateRequest.builder() + .type("online") + .totalAmount("10.00") + .externalReference("ext_ref") + .payer(OrderPayerRequest.builder().email("test@email.com").build()) + .transactions(OrderTransactionRequest.builder() + .payments(payments) + .build()) + .build(); + } +} \ No newline at end of file diff --git a/src/test/java/com/mercadopago/resources/mocks/response/order/create_order_response.json b/src/test/java/com/mercadopago/resources/mocks/response/order/create_order_response.json new file mode 100644 index 00000000..3c932674 --- /dev/null +++ b/src/test/java/com/mercadopago/resources/mocks/response/order/create_order_response.json @@ -0,0 +1,37 @@ +{ + "id": "123", + "type": "online", + "processing_mode": "automatic", + "external_reference": "ext_ref", + "total_amount": "10.00", + "site_id": "MLB", + "status": "failed", + "created_date": "2024-10-18T19:25:38.972924264Z", + "last_updated_date": "2024-10-18T19:25:39.690267719Z", + "integration_data": { + "application_id": "id" + }, + "payer": { + "email": "test@email.com" + }, + "transactions": { + "payments": [ + { + "id": "id", + "amount": "10.00", + "status": "failed", + "reference_id": "id", + "status_detail": "invalid_card_token", + "payment_method": { + "id": "master", + "type": "credit_card", + "token": "card_token", + "installments": 1 + } + } + ] + }, + "type_config": { + "capture_mode": "automatic" + } +} \ No newline at end of file