diff --git a/src/main/java/com/mercadopago/client/store/StoreClient.java b/src/main/java/com/mercadopago/client/store/StoreClient.java new file mode 100644 index 00000000..27c1d7bb --- /dev/null +++ b/src/main/java/com/mercadopago/client/store/StoreClient.java @@ -0,0 +1,275 @@ +package com.mercadopago.client.store; + +import static com.mercadopago.MercadoPagoConfig.getStreamHandler; + +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; +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.MPElementsResourcesPage; +import com.mercadopago.net.MPHttpClient; +import com.mercadopago.net.MPRequest; +import com.mercadopago.net.MPResponse; +import com.mercadopago.net.MPSearchRequest; +import com.mercadopago.resources.store.Store; +import com.mercadopago.serialization.Serializer; +import java.lang.reflect.Type; +import java.util.logging.Logger; +import java.util.logging.StreamHandler; + +/** + * Client for the MercadoPago Stores API. + * + *

Provides CRUD operations for stores (create, get, update, delete) and search with + * pagination. Stores represent physical or logical locations associated with a seller user. + * + *

Usage example: + *

{@code
+ * StoreClient client = new StoreClient();
+ * Store store = client.create(userId, storeCreateRequest);
+ * }
+ * + * @see + * Stores API reference + */ +public class StoreClient extends MercadoPagoClient { + + /** Class-level logger for store operations. */ + private static final Logger LOGGER = Logger.getLogger(StoreClient.class.getName()); + + /** Default constructor. Uses the default HTTP client provided by {@link MercadoPagoConfig}. */ + public StoreClient() { + this(MercadoPagoConfig.getHttpClient()); + } + + /** + * Constructs a {@code StoreClient} with a custom HTTP client. + * + * @param httpClient the {@link MPHttpClient} implementation used to execute HTTP requests + */ + public StoreClient(MPHttpClient httpClient) { + super(httpClient); + StreamHandler streamHandler = getStreamHandler(); + streamHandler.setLevel(MercadoPagoConfig.getLoggingLevel()); + LOGGER.addHandler(streamHandler); + LOGGER.setLevel(MercadoPagoConfig.getLoggingLevel()); + } + + /** + * Creates a new store for the given user. + * + * @param userId the unique identifier of the user that owns the store + * @param request the {@link StoreCreateRequest} with the store details + * @return the newly created {@link Store} + * @throws MPException if a transport-level or SDK-internal error occurs + * @throws MPApiException if the API returns a non-successful HTTP status code + */ + public Store create(Long userId, StoreCreateRequest request) throws MPException, MPApiException { + return this.create(userId, request, null); + } + + /** + * Creates a new store for the given user with custom request options. + * + * @param userId the unique identifier of the user that owns the store + * @param request the {@link StoreCreateRequest} with the store details + * @param requestOptions optional {@link MPRequestOptions} to override access token, headers, or + * timeouts for this single request; may be {@code null} + * @return the newly created {@link Store} + * @throws MPException if a transport-level or SDK-internal error occurs + * @throws MPApiException if the API returns a non-successful HTTP status code + */ + public Store create(Long userId, StoreCreateRequest request, MPRequestOptions requestOptions) + throws MPException, MPApiException { + LOGGER.info("Sending create store request"); + + JsonObject payload = Serializer.serializeToJson(request); + MPRequest mpRequest = + MPRequest.buildRequest( + String.format("/users/%s/stores", encodePathParam(userId)), + HttpMethod.POST, + payload, + null, + requestOptions); + MPResponse response = send(mpRequest); + + Store store = Serializer.deserializeFromJson(Store.class, response.getContent()); + store.setResponse(response); + return store; + } + + /** + * Retrieves a store by its unique identifier. + * + * @param storeId the unique identifier of the store + * @return the requested {@link Store} + * @throws MPException if a transport-level or SDK-internal error occurs + * @throws MPApiException if the API returns a non-successful HTTP status code + */ + public Store get(String storeId) throws MPException, MPApiException { + return this.get(storeId, null); + } + + /** + * Retrieves a store by its unique identifier with custom request options. + * + * @param storeId the unique identifier of the store + * @param requestOptions optional {@link MPRequestOptions} to override access token, headers, or + * timeouts for this single request; may be {@code null} + * @return the requested {@link Store} + * @throws MPException if a transport-level or SDK-internal error occurs + * @throws MPApiException if the API returns a non-successful HTTP status code + */ + public Store get(String storeId, MPRequestOptions requestOptions) + throws MPException, MPApiException { + LOGGER.info("Sending get store request"); + + MPResponse response = + send( + String.format("/stores/%s", encodePathParam(storeId)), + HttpMethod.GET, + null, + null, + requestOptions); + + Store store = Serializer.deserializeFromJson(Store.class, response.getContent()); + store.setResponse(response); + return store; + } + + /** + * Searches for stores belonging to the given user. + * + * @param userId the unique identifier of the user that owns the stores + * @param request the {@link MPSearchRequest} containing search filters and pagination parameters + * @return an {@link MPElementsResourcesPage} of {@link Store} with matching results + * @throws MPException if a transport-level or SDK-internal error occurs + * @throws MPApiException if the API returns a non-successful HTTP status code + */ + public MPElementsResourcesPage search(Long userId, MPSearchRequest request) + throws MPException, MPApiException { + return this.search(userId, request, null); + } + + /** + * Searches for stores belonging to the given user with custom request options. + * + * @param userId the unique identifier of the user that owns the stores + * @param request the {@link MPSearchRequest} containing search filters and pagination parameters + * @param requestOptions optional {@link MPRequestOptions} to override access token, headers, or + * timeouts for this single request; may be {@code null} + * @return an {@link MPElementsResourcesPage} of {@link Store} with matching results + * @throws MPException if a transport-level or SDK-internal error occurs + * @throws MPApiException if the API returns a non-successful HTTP status code + */ + public MPElementsResourcesPage search( + Long userId, MPSearchRequest request, MPRequestOptions requestOptions) + throws MPException, MPApiException { + LOGGER.info("Sending search store request"); + + MPResponse response = + search( + String.format("/users/%s/stores/search", encodePathParam(userId)), + request, + requestOptions); + + Type responseType = new TypeToken>() {}.getType(); + MPElementsResourcesPage result = + Serializer.deserializeElementsResourcesPageFromJson(responseType, response.getContent()); + result.setResponse(response); + return result; + } + + /** + * Updates an existing store. + * + * @param userId the unique identifier of the user that owns the store + * @param storeId the unique identifier of the store to update + * @param request the {@link StoreUpdateRequest} with the updated store details + * @return the updated {@link Store} + * @throws MPException if a transport-level or SDK-internal error occurs + * @throws MPApiException if the API returns a non-successful HTTP status code + */ + public Store update(Long userId, String storeId, StoreUpdateRequest request) + throws MPException, MPApiException { + return this.update(userId, storeId, request, null); + } + + /** + * Updates an existing store with custom request options. + * + * @param userId the unique identifier of the user that owns the store + * @param storeId the unique identifier of the store to update + * @param request the {@link StoreUpdateRequest} with the updated store details + * @param requestOptions optional {@link MPRequestOptions} to override access token, headers, or + * timeouts for this single request; may be {@code null} + * @return the updated {@link Store} + * @throws MPException if a transport-level or SDK-internal error occurs + * @throws MPApiException if the API returns a non-successful HTTP status code + */ + public Store update( + Long userId, String storeId, StoreUpdateRequest request, MPRequestOptions requestOptions) + throws MPException, MPApiException { + LOGGER.info("Sending update store request"); + + JsonObject payload = Serializer.serializeToJson(request); + MPRequest mpRequest = + MPRequest.buildRequest( + String.format("/users/%s/stores/%s", encodePathParam(userId), encodePathParam(storeId)), + HttpMethod.PUT, + payload, + null, + requestOptions); + MPResponse response = send(mpRequest); + + Store store = Serializer.deserializeFromJson(Store.class, response.getContent()); + store.setResponse(response); + return store; + } + + /** + * Deletes a store by its unique identifier. + * + * @param userId the unique identifier of the user that owns the store + * @param storeId the unique identifier of the store to delete + * @return the deleted {@link Store} + * @throws MPException if a transport-level or SDK-internal error occurs + * @throws MPApiException if the API returns a non-successful HTTP status code + */ + public Store delete(Long userId, String storeId) throws MPException, MPApiException { + return this.delete(userId, storeId, null); + } + + /** + * Deletes a store by its unique identifier with custom request options. + * + * @param userId the unique identifier of the user that owns the store + * @param storeId the unique identifier of the store to delete + * @param requestOptions optional {@link MPRequestOptions} to override access token, headers, or + * timeouts for this single request; may be {@code null} + * @return the deleted {@link Store} + * @throws MPException if a transport-level or SDK-internal error occurs + * @throws MPApiException if the API returns a non-successful HTTP status code + */ + public Store delete(Long userId, String storeId, MPRequestOptions requestOptions) + throws MPException, MPApiException { + LOGGER.info("Sending delete store request"); + + MPRequest mpRequest = + MPRequest.buildRequest( + String.format("/users/%s/stores/%s", encodePathParam(userId), encodePathParam(storeId)), + HttpMethod.DELETE, + null, + null, + requestOptions); + MPResponse response = send(mpRequest); + + Store store = Serializer.deserializeFromJson(Store.class, response.getContent()); + store.setResponse(response); + return store; + } +} diff --git a/src/main/java/com/mercadopago/client/store/StoreCreateRequest.java b/src/main/java/com/mercadopago/client/store/StoreCreateRequest.java new file mode 100644 index 00000000..e52db6ed --- /dev/null +++ b/src/main/java/com/mercadopago/client/store/StoreCreateRequest.java @@ -0,0 +1,82 @@ +package com.mercadopago.client.store; + +import lombok.Builder; +import lombok.Getter; + +/** + * Request DTO used to create a store in Mercado Pago via + * {@code POST /users/{user_id}/stores}. + * + *

Fields follow the Stores API schema. No requiredness or validation is enforced by the + * SDK beyond what the API specification exposes. + * + * @see StoreClient#create(Long, StoreCreateRequest) + * @see + * Stores API reference + */ +@Getter +@Builder +public class StoreCreateRequest { + /** Name of the store. */ + private final String name; + + /** Business hours of the store. */ + private final StoreBusinessHoursRequest businessHours; + + /** Geographic location of the store. */ + private final StoreLocationRequest location; + + /** External identifier used to correlate the store with the integrator's system. */ + private final String externalId; + + /** Opening hours for a single weekday, as exposed by the Stores API. */ + @Getter + @Builder + public static final class StoreBusinessHoursRequest { + /** Day of the week this entry applies to (e.g. {@code monday}). */ + private final String day; + + /** Opening time of the store on this day. */ + private final String open; + + /** Closing time of the store on this day. */ + private final String close; + } + + /** Geographic location of a store, as exposed by the Stores API. */ + @Getter + @Builder + public static final class StoreLocationRequest { + /** Street address lines of the store. */ + private final java.util.List addressLine; + + /** Additional reference to locate the store. */ + private final String reference; + + /** City where the store is located. */ + private final StoreCityRequest city; + + /** State where the store is located. */ + private final String state; + + /** Postal code of the store location. */ + private final String zipCode; + + /** Latitude of the store location. */ + private final Double latitude; + + /** Longitude of the store location. */ + private final Double longitude; + } + + /** City information of a store location, as exposed by the Stores API. */ + @Getter + @Builder + public static final class StoreCityRequest { + /** Identifier of the city. */ + private final String id; + + /** Name of the city. */ + private final String name; + } +} diff --git a/src/main/java/com/mercadopago/client/store/StoreUpdateRequest.java b/src/main/java/com/mercadopago/client/store/StoreUpdateRequest.java new file mode 100644 index 00000000..40e1dff4 --- /dev/null +++ b/src/main/java/com/mercadopago/client/store/StoreUpdateRequest.java @@ -0,0 +1,40 @@ +package com.mercadopago.client.store; + +import lombok.Builder; +import lombok.Getter; + +/** + * Request object for updating an existing store through the Stores API. + * + *

All fields are optional: the API accepts a partial payload and only updates the + * attributes that are present. No requiredness or validation is imposed beyond what the + * API specification exposes. + * + *

Usage example: + *

{@code
+ * StoreUpdateRequest request = StoreUpdateRequest.builder()
+ *     .name("Store name")
+ *     .businessHours(StoreBusinessHoursRequest.builder().build())
+ *     .location(StoreLocationRequest.builder().build())
+ *     .externalId("external-123")
+ *     .build();
+ * }
+ * + * @see StoreClient#update(Long, String, StoreUpdateRequest) + */ +@Getter +@Builder +public class StoreUpdateRequest { + + /** Name of the store. */ + private final String name; + + /** Business hours of the store. */ + private final StoreBusinessHoursRequest businessHours; + + /** Location of the store. */ + private final StoreLocationRequest location; + + /** External identifier used to correlate the store with the integrator's system. */ + private final String externalId; +} diff --git a/src/main/java/com/mercadopago/example/store/CreateStore.java b/src/main/java/com/mercadopago/example/store/CreateStore.java new file mode 100644 index 00000000..ce0a0c9c --- /dev/null +++ b/src/main/java/com/mercadopago/example/store/CreateStore.java @@ -0,0 +1,51 @@ +package com.mercadopago.example.store; + +import com.mercadopago.client.store.StoreClient; +import com.mercadopago.client.store.StoreCreateRequest; +import com.mercadopago.exceptions.MPApiException; +import com.mercadopago.exceptions.MPException; +import com.mercadopago.resources.store.Store; + +/** + * Creates a store associated to a Mercado Pago account. + * + *

Set your access token in the MERCADO_PAGO_ACCESS_TOKEN environment variable + * before running this example. + */ +public class CreateStore { + + /** Private constructor to prevent instantiation. */ + private CreateStore() {} + + /** + * Runs the store creation example. + * + * @param args command line arguments (not used) + */ + public static void main(String[] args) { + StoreClient client = new StoreClient(); + + StoreCreateRequest request = + StoreCreateRequest.builder() + .name("Official Store") + .externalId("store-123") + .build(); + + try { + Long userId = 123456789L; + Store store = client.create(userId, request); + System.out.println("Store created successfully:"); + System.out.println(" Id: " + store.getId()); + System.out.println(" Name: " + store.getName()); + System.out.println(" External reference: " + store.getExternalReference()); + } catch (MPApiException apiException) { + System.err.println( + "API error - status: " + + apiException.getStatusCode() + + ", content: " + + apiException.getApiResponse().getContent()); + } catch (MPException exception) { + System.err.println("MP error: " + exception.getMessage()); + } + } +} diff --git a/src/main/java/com/mercadopago/resources/store/Store.java b/src/main/java/com/mercadopago/resources/store/Store.java new file mode 100644 index 00000000..5982611f --- /dev/null +++ b/src/main/java/com/mercadopago/resources/store/Store.java @@ -0,0 +1,49 @@ +package com.mercadopago.resources.store; + +import com.google.gson.annotations.SerializedName; +import com.mercadopago.net.MPResource; +import java.time.OffsetDateTime; +import java.util.Map; +import lombok.Getter; + +/** + * Represents a store resource from the MercadoPago Stores API. + * + *

A store identifies one of the merchant's physical business locations, including its + * opening hours ({@code business_hours}) and geographic {@code location}. Stores are managed + * under a MercadoPago user account and can be referenced by point-of-sale and payment + * operations. + * + *

Instances of this class are returned by the store operations of the SDK and are populated + * by deserializing the JSON response payload of the API. + * + * @see + * Stores API reference + */ +@Getter +public class Store extends MPResource { + + /** Unique identifier of the store. */ + private String id; + + /** Unique identifier of the MercadoPago user that owns the store. */ + private Long userId; + + /** External identifier used by the integrator to correlate the store with its own systems. */ + private String externalId; + + /** Name that identifies the store. */ + private String name; + + /** Date and time when the store was created in MercadoPago. */ + private OffsetDateTime dateCreated; + + /** Business opening hours of the store, keyed by day of the week. */ + private Map businessHours; + + /** Geographic location of the store (address, city, state, coordinates, etc.). */ + private Map location; + + /** External identifier used by the integrator to correlate the store with its own systems. */ + private String externalReference; +} diff --git a/src/test/java/com/mercadopago/client/store/StoreClientTest.java b/src/test/java/com/mercadopago/client/store/StoreClientTest.java new file mode 100644 index 00000000..a8007750 --- /dev/null +++ b/src/test/java/com/mercadopago/client/store/StoreClientTest.java @@ -0,0 +1,238 @@ +package com.mercadopago.client.store; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doReturn; + +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.net.MPElementsResourcesPage; +import com.mercadopago.net.MPSearchRequest; +import com.mercadopago.resources.store.Store; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import org.apache.http.HttpHeaders; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.protocol.HttpContext; +import org.junit.jupiter.api.Test; + +/** StoreClientTest class. */ +public class StoreClientTest extends BaseClientTest { + private final StoreClient storeClient = new StoreClient(); + + private final Long userId = 471763245L; + + private final String storeId = "1234567"; + + @Test + public void createSuccess() throws MPException, MPApiException, IOException { + HttpResponse httpResponse = + MockHelper.generateHttpResponseFromFile("/store/store_base.json", HttpStatus.OK); + httpResponse.setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON); + + doReturn(httpResponse) + .when(HTTP_CLIENT) + .execute(any(HttpRequestBase.class), any(HttpContext.class)); + + Store store = storeClient.create(userId, buildStoreCreateRequest()); + + assertStoreFields(store); + } + + @Test + public void createWithRequestOptionsSuccess() throws MPException, MPApiException, IOException { + HttpResponse httpResponse = + MockHelper.generateHttpResponseFromFile("/store/store_base.json", HttpStatus.OK); + httpResponse.setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON); + + doReturn(httpResponse) + .when(HTTP_CLIENT) + .execute(any(HttpRequestBase.class), any(HttpContext.class)); + + Store store = storeClient.create(userId, buildStoreCreateRequest(), buildRequestOptions()); + + assertStoreFields(store); + } + + @Test + public void getSuccess() throws MPException, MPApiException, IOException { + HttpResponse httpResponse = + MockHelper.generateHttpResponseFromFile("/store/store_base.json", HttpStatus.OK); + httpResponse.setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON); + + doReturn(httpResponse) + .when(HTTP_CLIENT) + .execute(any(HttpRequestBase.class), any(HttpContext.class)); + + Store store = storeClient.get(storeId); + + assertStoreFields(store); + } + + @Test + public void getWithRequestOptionsSuccess() throws MPException, MPApiException, IOException { + HttpResponse httpResponse = + MockHelper.generateHttpResponseFromFile("/store/store_base.json", HttpStatus.OK); + httpResponse.setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON); + + doReturn(httpResponse) + .when(HTTP_CLIENT) + .execute(any(HttpRequestBase.class), any(HttpContext.class)); + + Store store = storeClient.get(storeId, buildRequestOptions()); + + assertStoreFields(store); + } + + @Test + public void searchSuccess() throws MPException, MPApiException, IOException { + Map filters = new HashMap<>(); + filters.put("external_reference", "store-123"); + + MPSearchRequest searchRequest = + MPSearchRequest.builder().limit(10).offset(0).filters(filters).build(); + HttpResponse httpResponse = + MockHelper.generateHttpResponseFromFile("/store/store_list.json", HttpStatus.OK); + + doReturn(httpResponse) + .when(HTTP_CLIENT) + .execute(any(HttpRequestBase.class), any(HttpContext.class)); + + MPElementsResourcesPage result = storeClient.search(userId, searchRequest); + + assertNotNull(result); + assertEquals(2, result.getTotal()); + assertEquals(2, result.getElements().size()); + assertStoreFields(result.getElements().get(0)); + } + + @Test + public void searchWithRequestOptionsSuccess() throws MPException, MPApiException, IOException { + Map filters = new HashMap<>(); + filters.put("external_reference", "store-123"); + + MPSearchRequest searchRequest = + MPSearchRequest.builder().limit(10).offset(0).filters(filters).build(); + HttpResponse httpResponse = + MockHelper.generateHttpResponseFromFile("/store/store_list.json", HttpStatus.OK); + + doReturn(httpResponse) + .when(HTTP_CLIENT) + .execute(any(HttpRequestBase.class), any(HttpContext.class)); + + MPElementsResourcesPage result = + storeClient.search(userId, searchRequest, buildRequestOptions()); + + assertNotNull(result); + assertEquals(2, result.getTotal()); + assertEquals(2, result.getElements().size()); + assertStoreFields(result.getElements().get(0)); + } + + @Test + public void updateSuccess() throws MPException, MPApiException, IOException { + HttpResponse httpResponse = + MockHelper.generateHttpResponseFromFile("/store/store_base.json", HttpStatus.OK); + httpResponse.setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON); + + doReturn(httpResponse) + .when(HTTP_CLIENT) + .execute(any(HttpRequestBase.class), any(HttpContext.class)); + + Store store = storeClient.update(userId, storeId, buildStoreUpdateRequest()); + + assertStoreFields(store); + } + + @Test + public void updateWithRequestOptionsSuccess() throws MPException, MPApiException, IOException { + HttpResponse httpResponse = + MockHelper.generateHttpResponseFromFile("/store/store_base.json", HttpStatus.OK); + httpResponse.setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON); + + doReturn(httpResponse) + .when(HTTP_CLIENT) + .execute(any(HttpRequestBase.class), any(HttpContext.class)); + + Store store = + storeClient.update(userId, storeId, buildStoreUpdateRequest(), buildRequestOptions()); + + assertStoreFields(store); + } + + @Test + public void deleteSuccess() throws MPException, MPApiException, IOException { + HttpResponse httpResponse = + MockHelper.generateHttpResponseFromFile("/store/store_base.json", HttpStatus.OK); + httpResponse.setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON); + + doReturn(httpResponse) + .when(HTTP_CLIENT) + .execute(any(HttpRequestBase.class), any(HttpContext.class)); + + Store store = storeClient.delete(userId, storeId); + + assertStoreFields(store); + } + + @Test + public void deleteWithRequestOptionsSuccess() throws MPException, MPApiException, IOException { + HttpResponse httpResponse = + MockHelper.generateHttpResponseFromFile("/store/store_base.json", HttpStatus.OK); + httpResponse.setHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON); + + doReturn(httpResponse) + .when(HTTP_CLIENT) + .execute(any(HttpRequestBase.class), any(HttpContext.class)); + + Store store = storeClient.delete(userId, storeId, buildRequestOptions()); + + assertStoreFields(store); + } + + private StoreCreateRequest buildStoreCreateRequest() { + return StoreCreateRequest.builder() + .name("Official Store") + .externalId("store-123") + .location( + StoreLocationRequest.builder() + .addressLine("Av. das Nações Unidas, 3003") + .reference("Floor 3") + .city(StoreCityRequest.builder().id("BR-SP-44").name("São Paulo").build()) + .latitude(-23.5966) + .longitude(-46.6835) + .build()) + .build(); + } + + private StoreUpdateRequest buildStoreUpdateRequest() { + return StoreUpdateRequest.builder() + .name("Updated Store") + .externalId("store-123") + .location( + StoreLocationRequest.builder() + .addressLine("Av. das Nações Unidas, 3003") + .reference("Floor 3") + .city(StoreCityRequest.builder().id("BR-SP-44").name("São Paulo").build()) + .latitude(-23.5966) + .longitude(-46.6835) + .build()) + .build(); + } + + private void assertStoreFields(Store store) { + assertNotNull(store); + assertEquals("1234567", store.getId()); + assertEquals(471763245L, store.getUserId()); + assertEquals("Official Store", store.getName()); + assertEquals("A12S3D4F5G", store.getExternalId()); + assertNotNull(store.getResponse().getContent()); + assertEquals(HttpStatus.OK, store.getResponse().getStatusCode()); + } +} diff --git a/src/test/java/com/mercadopago/resources/mocks/request/store/store_base.json b/src/test/java/com/mercadopago/resources/mocks/request/store/store_base.json new file mode 100644 index 00000000..ed965de0 --- /dev/null +++ b/src/test/java/com/mercadopago/resources/mocks/request/store/store_base.json @@ -0,0 +1,56 @@ +{ + "name": "Official Store", + "business_hours": { + "monday": [ + { + "open": "08:00", + "close": "12:00" + }, + { + "open": "14:00", + "close": "18:00" + } + ], + "tuesday": [ + { + "open": "08:00", + "close": "18:00" + } + ], + "wednesday": [ + { + "open": "08:00", + "close": "18:00" + } + ], + "thursday": [ + { + "open": "08:00", + "close": "18:00" + } + ], + "friday": [ + { + "open": "08:00", + "close": "18:00" + } + ] + }, + "external_id": "A12S34", + "location": { + "address_line": "Av. das Nações Unidas, 3003", + "reference": "Mercado Pago", + "city": { + "id": "TUxBQlNBTzQzNTVa", + "name": "Santo André" + }, + "latitude": -23.5967371, + "longitude": -46.6865163, + "open_hours": "08:00 - 18:00", + "zip_code": "06233-200", + "country_name": "Brasil", + "state_name": "São Paulo", + "street_name": "Av. das Nações Unidas", + "street_number": "3003" + } +} diff --git a/src/test/java/com/mercadopago/resources/mocks/request/store/store_update.json b/src/test/java/com/mercadopago/resources/mocks/request/store/store_update.json new file mode 100644 index 00000000..275651b5 --- /dev/null +++ b/src/test/java/com/mercadopago/resources/mocks/request/store/store_update.json @@ -0,0 +1,44 @@ +{ + "name": "Updated Store", + "location": { + "address_line": "Street, 123", + "reference": "Near the corner", + "city": { + "id": "TUxBQ0NBUGZlZG1zY3M" + }, + "state": { + "id": "TUxBUENBUGw3M2E1" + }, + "zip_code": "06000000", + "country_name": "Brazil", + "latitude": -23.5, + "longitude": -46.6 + }, + "business_hours": { + "monday": { + "open": "08:00", + "close": "18:00" + }, + "tuesday": { + "open": "08:00", + "close": "18:00" + }, + "wednesday": { + "open": "08:00", + "close": "18:00" + }, + "thursday": { + "open": "08:00", + "close": "18:00" + }, + "friday": { + "open": "08:00", + "close": "18:00" + }, + "saturday": { + "open": "08:00", + "close": "13:00" + }, + "sunday": null + } +} diff --git a/src/test/java/com/mercadopago/resources/mocks/response/store/store_base.json b/src/test/java/com/mercadopago/resources/mocks/response/store/store_base.json new file mode 100644 index 00000000..93d15727 --- /dev/null +++ b/src/test/java/com/mercadopago/resources/mocks/response/store/store_base.json @@ -0,0 +1,38 @@ +{ + "id": "1234567", + "user_id": 471763245, + "name": "Official Store", + "date_created": "2022-02-03T17:09:52.992+00:00", + "business_hours": { + "monday": { + "open": "08:00", + "close": "15:00" + }, + "tuesday": { + "open": "08:00", + "close": "15:00" + }, + "wednesday": { + "open": "08:00", + "close": "15:00" + }, + "thursday": { + "open": "08:00", + "close": "15:00" + }, + "friday": { + "open": "08:00", + "close": "15:00" + } + }, + "external_id": "A12S3D4F5G", + "location": { + "address_line": "Av. das Nações Unidas, 3003", + "reference": "3rd floor", + "city": "Osasco", + "state": "SP", + "zip_code": "06233-200", + "latitude": -23.5887, + "longitude": -46.6951 + } +} diff --git a/src/test/java/com/mercadopago/resources/mocks/response/store/store_list.json b/src/test/java/com/mercadopago/resources/mocks/response/store/store_list.json new file mode 100644 index 00000000..56d11278 --- /dev/null +++ b/src/test/java/com/mercadopago/resources/mocks/response/store/store_list.json @@ -0,0 +1,83 @@ +{ + "total": 2, + "next_offset": 2, + "elements": [ + { + "id": 1234567, + "user_id": 471763245, + "name": "Official Store", + "date_created": "2022-01-10T10:10:10.000-00:00", + "business_hours": { + "monday": [ + { + "open": "08:00", + "close": "15:00" + } + ], + "tuesday": [ + { + "open": "08:00", + "close": "15:00" + } + ], + "wednesday": [ + { + "open": "08:00", + "close": "15:00" + } + ], + "thursday": [ + { + "open": "08:00", + "close": "15:00" + } + ], + "friday": [ + { + "open": "08:00", + "close": "15:00" + } + ] + }, + "external_id": "store-123", + "location": { + "address_line": "Av. das Nações Unidas, 3003", + "reference": "Floor 12", + "city": "São Paulo", + "state": "SP", + "zip_code": "06233-200", + "latitude": -23.6104, + "longitude": -46.6972 + } + }, + { + "id": 30147862, + "name": "Updated Store", + "date_created": "2022-02-03T17:09:52.992+00:00", + "business_hours": { + "monday": [ + { + "open": "09:00", + "close": "18:00" + } + ], + "tuesday": [ + { + "open": "09:00", + "close": "18:00" + } + ] + }, + "external_id": "STORE-02", + "location": { + "address_line": "Street, 123", + "reference": null, + "city": "City", + "state": "ST", + "zip_code": "06000000", + "latitude": -23.5, + "longitude": -46.6 + } + } + ] +}