Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Adding post to create order - Order SDK #297

Closed
wants to merge 1 commit into from
Closed
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
@@ -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;
}

80 changes: 80 additions & 0 deletions src/main/java/com/mercadopago/client/order/OrderClient.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
13 changes: 13 additions & 0 deletions src/main/java/com/mercadopago/client/order/OrderCouponRequest.java
Original file line number Diff line number Diff line change
@@ -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;
}
63 changes: 63 additions & 0 deletions src/main/java/com/mercadopago/client/order/OrderCreateRequest.java
Original file line number Diff line number Diff line change
@@ -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<OrderItemRequest> items;

/** Coupon information. */
private OrderCouponRequest coupon;

/** Information's about split payments. */
private List<OrderSplitRequest> splits;

/** Shipping information. */
private OrderShipmentRequest shipment;

/** Expiration time of the order. */
private String expirationTime;
}
35 changes: 35 additions & 0 deletions src/main/java/com/mercadopago/client/order/OrderItemRequest.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
49 changes: 49 additions & 0 deletions src/main/java/com/mercadopago/client/order/OrderPayerRequest.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
23 changes: 23 additions & 0 deletions src/main/java/com/mercadopago/client/order/OrderRouteRequest.java
Original file line number Diff line number Diff line change
@@ -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;
}
Loading
Loading