diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..946164b --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,38 @@ +version: 2 +jobs: + build: + docker: + - image: circleci/openjdk:8-jdk + working_directory: ~/moip-sdk-java + + environment: + JVM_OPTS: -Xmx3200m + TERM: dumb + + steps: + - checkout + + - restore_cache: + keys: + - v1-dependencies-{{ checksum "build.gradle" }} + - v1-dependencies- + + - run: + name: Dependencies + command: ./gradlew clean dependencies -PossrhUsername=username -PossrhPassword=password + + - save_cache: + paths: + - ~/.gradle + key: v1-dependencies-{{ checksum "build.gradle" }} + + - run: + name: Build and test + command: ./gradlew clean test -PossrhUsername=username -PossrhPassword=password -i + +workflows: + version: 2 + moip_devx_tools: + jobs: + - build + diff --git a/.circleci/secring.gpg.enc b/.circleci/secring.gpg.enc new file mode 100644 index 0000000..5f7b2b9 --- /dev/null +++ b/.circleci/secring.gpg.enc @@ -0,0 +1,204 @@ +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 diff --git a/.gitignore b/.gitignore index 62c8935..ea90fe0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ -.idea/ \ No newline at end of file +.idea/ +.gradle +out/ +*.iml +build/ \ No newline at end of file diff --git a/.gradle/4.0/fileChanges/last-build.bin b/.gradle/4.0/fileChanges/last-build.bin deleted file mode 100644 index f76dd23..0000000 Binary files a/.gradle/4.0/fileChanges/last-build.bin and /dev/null differ diff --git a/.gradle/4.0/fileHashes/fileHashes.bin b/.gradle/4.0/fileHashes/fileHashes.bin deleted file mode 100644 index 6972080..0000000 Binary files a/.gradle/4.0/fileHashes/fileHashes.bin and /dev/null differ diff --git a/.gradle/4.0/fileHashes/fileHashes.lock b/.gradle/4.0/fileHashes/fileHashes.lock deleted file mode 100644 index a395599..0000000 Binary files a/.gradle/4.0/fileHashes/fileHashes.lock and /dev/null differ diff --git a/.gradle/4.0/taskHistory/fileSnapshots.bin b/.gradle/4.0/taskHistory/fileSnapshots.bin deleted file mode 100644 index 4353815..0000000 Binary files a/.gradle/4.0/taskHistory/fileSnapshots.bin and /dev/null differ diff --git a/.gradle/4.0/taskHistory/taskHistory.bin b/.gradle/4.0/taskHistory/taskHistory.bin deleted file mode 100644 index 7d4f5d6..0000000 Binary files a/.gradle/4.0/taskHistory/taskHistory.bin and /dev/null differ diff --git a/.gradle/4.0/taskHistory/taskHistory.lock b/.gradle/4.0/taskHistory/taskHistory.lock deleted file mode 100644 index 6378d29..0000000 Binary files a/.gradle/4.0/taskHistory/taskHistory.lock and /dev/null differ diff --git a/.gradle/buildOutputCleanup/built.bin b/.gradle/buildOutputCleanup/built.bin deleted file mode 100644 index e69de29..0000000 diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties deleted file mode 100644 index 585f421..0000000 --- a/.gradle/buildOutputCleanup/cache.properties +++ /dev/null @@ -1,2 +0,0 @@ -#Wed May 30 16:56:05 BRT 2018 -gradle.version=4.0 diff --git a/.gradle/buildOutputCleanup/cache.properties.lock b/.gradle/buildOutputCleanup/cache.properties.lock deleted file mode 100644 index 40fdece..0000000 --- a/.gradle/buildOutputCleanup/cache.properties.lock +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/README.md b/README.md index 80ba0b9..444b8c9 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# moip-sdk-java-2 \ No newline at end of file +# moip-sdk-java-2 + + diff --git a/build.gradle b/build.gradle index bf2758b..58c4aa1 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,99 @@ +apply plugin: 'java' +apply plugin: 'maven' +apply plugin: 'signing' + group 'br.com.moip' +archivesBaseName = "sdk-java" version '0.1.0' -apply plugin: 'java' +description = "Java SDK for Moip APIs integration" sourceCompatibility = 1.8 +targetCompatibility = 1.8 repositories { mavenCentral() } dependencies { + compile group: "org.apache.httpcomponents", name: "httpclient", version: "4.5.3" + compile group: "org.apache.commons", name: "commons-lang3", version: "3.6" + compile group: "org.slf4j", name: "slf4j-api", version: "1.7.12" + compile group: "com.google.code.gson", name: "gson", version: "2.4" + compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.5' + testCompile group: 'junit', name: 'junit', version: '4.12' + testCompile group: "org.slf4j", name: "slf4j-simple", version: "1.7.12" + testCompile group: "com.github.rodrigosaito", name: "mockwebserver-player", version: "1.1.0" +} + +task javadocJar(type: Jar) { + classifier = 'javadoc' + from javadoc +} + +task sourcesJar(type: Jar) { + classifier = 'sources' + from sourceSets.main.allSource +} + +artifacts { + archives javadocJar, sourcesJar +} + +signing { + sign configurations.archives +} + +uploadArchives { + repositories { + mavenDeployer { + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + + repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { + authentication(userName: System.getenv('MVN_USERNAME'), password: System.getenv('MVN_PASSWORD')) + } + + snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { + authentication(userName: System.getenv('MVN_USERNAME'), password: System.getenv('MVN_PASSWORD')) + } + + pom.project { + name 'Moip Java SDK' + packaging 'jar' + // the artifactId can be defined here (it's optional) + description 'Java SDK for Moip APIs integration' + url 'https://github.com/moip/moip-sdk-java' + + scm { + connection 'scm:git:ssh://git@github.com:moip/moip-sdk-java.git' + developerConnection 'scm:git:ssh://git@github.com:moip/moip-sdk-java.git' + url 'https://github.com/moip/moip-sdk-java' + } + + licenses { + license { + name 'The MIT License (MIT)' + url 'http://opensource.org/licenses/MIT' + } + } + + developers { + developer { + id 'matheus.nakaya' + name 'Matheus B. Nakaya' + email 'matheus.nakaya@moip.com.br' + } + } + } + } + } +} + +processResources { + filesMatching("**/moipJavaSDK.properties") { + expand([ + version: version + ]) + } } diff --git a/src/main/java/br/com/moip/Moip.java b/src/main/java/br/com/moip/Moip.java new file mode 100644 index 0000000..6f5c942 --- /dev/null +++ b/src/main/java/br/com/moip/Moip.java @@ -0,0 +1,44 @@ +package br.com.moip; + +import br.com.moip.api.APIResources; +import br.com.moip.api.request.RequestMaker; + +import java.io.InputStream; +import java.util.Properties; + +public class Moip { + + public static final String SANDBOX_URL = "https://sandbox.moip.com.br"; + + public static final String PRODUCTION_URL = "https://api.moip.com.br"; + + public static final String CONNECT_SANDBOX_URL = "https://connect-sandbox.moip.com.br"; + + public static final String CONNECT_PRODUCTION_URL = "https://connect.moip.com.br"; + + /** + * + */ + private static String USER_AGENT; + + static { + try { + InputStream inputStream = RequestMaker.class.getResourceAsStream("/moipJavaSDK.properties"); + Properties properties = new Properties(); + properties.load(inputStream); + + USER_AGENT = properties.getProperty("userAgent"); + } catch (Exception e) { // verificar tipo de exception + USER_AGENT = "MoipJavaSDK/UnknownVersion (+https://github.com/moip/moip-sdk-java/)"; + } + } + + /** + * This method returns the {@code USER_AGENT} value. + * + * @return {@code String} + */ + protected String getUserAgent() { return USER_AGENT; } + + public static class API extends APIResources {} +} diff --git a/src/main/java/br/com/moip/api/APIResources.java b/src/main/java/br/com/moip/api/APIResources.java new file mode 100644 index 0000000..2db03a1 --- /dev/null +++ b/src/main/java/br/com/moip/api/APIResources.java @@ -0,0 +1,35 @@ +package br.com.moip.api; + +import br.com.moip.models.Customer; +import br.com.moip.models.Order; +import br.com.moip.models.Payment; +import br.com.moip.models.Refund; +import br.com.moip.models.NotificationPreference; +import br.com.moip.models.Webhook; + +public class APIResources { + + private static Customer customerInstance = new Customer(); + private static Order orderInstance = new Order(); + private static Payment paymentInstance = new Payment(); + private static Refund refundInstance = new Refund(); + private static NotificationPreference notificationPreferenceInstance = new NotificationPreference(); + private static Webhook webhookInstance = new Webhook(); + + /** + * This method is used to get a instance of customer object. + * + * @return {@code Customer} + */ + public static Customer customers() { return customerInstance; } + + public static Order orders() { return orderInstance; } + + public static Payment payments() { return paymentInstance; } + + public static Refund refunds() { return refundInstance; } + + public static NotificationPreference notificationPreferences() { return notificationPreferenceInstance; } + + public static Webhook webhooks() { return webhookInstance; } +} diff --git a/src/main/java/br/com/moip/api/request/APIDateRequest.java b/src/main/java/br/com/moip/api/request/APIDateRequest.java new file mode 100644 index 0000000..45ea720 --- /dev/null +++ b/src/main/java/br/com/moip/api/request/APIDateRequest.java @@ -0,0 +1,20 @@ +package br.com.moip.api.request; + +import java.util.Date; + +public class APIDateRequest { + + private Date date; + + public Date getDate() { + return date; + } + + /** + * This constructor receive a APIDate object to fill the attribute date. + * + * @param date + * {@code APIDate} a numerical date. + */ + public void date(Date date) { this.date = date; } +} diff --git a/src/main/java/br/com/moip/api/request/RequestMaker.java b/src/main/java/br/com/moip/api/request/RequestMaker.java new file mode 100644 index 0000000..fe2ef8b --- /dev/null +++ b/src/main/java/br/com/moip/api/request/RequestMaker.java @@ -0,0 +1,276 @@ +package br.com.moip.api.request; + +import br.com.moip.Moip; +import br.com.moip.api.response.Response; +import br.com.moip.auth.Authentication; +import br.com.moip.exception.MoipAPIException; +import br.com.moip.exception.UnauthorizedException; +import br.com.moip.exception.UnexpectedException; +import br.com.moip.exception.ValidationException; +import br.com.moip.models.Setup; +import br.com.moip.models.error.Errors; +import br.com.moip.utilities.ssl.SSLSupport; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.net.ssl.HttpsURLConnection; +import java.io.BufferedWriter; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.net.URL; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class RequestMaker extends Moip { + + private final String moipEnvironment; + private final Authentication authentication; + private static final Logger LOGGER = LoggerFactory.getLogger(RequestMaker.class); + private RequestTools tools; + private Response response; + + + /** + * This constructor sets the Moip environment and the authentication received from parameter. + * + * @param setup + * {@code Setup} the setup object. + * + * @see br.com.moip.auth.Authentication + */ + public RequestMaker(Setup setup) { + + this.moipEnvironment = setup.getEnvironment(); + this.authentication = setup.getAuthentication(); + this.tools = new RequestTools(); + this.response = new Response(); + } + + /** + * This method is used to build the request, it set the environment (Sandbox or Production) + * and the headers, create the {@code connection} object to establish connection with Moip + * APIResources, authenticate the connection, load the request properties received from parameter, + * serialize the request object and send it to the API. Finally, this method receive the + * response JSON and deserialize it into the respective model object, sending the response + * code and response body to {@code responseBodyTreatment} method to treat the response. + * + * @param requestProps + * {@code RequestProperties} the object containing the properties of + * request, its like request method, endpoint, object, type, content type + * and if it accepts another JSON version. + * + * + * @return {@code Map} + */ + public Map doRequest(final RequestProperties requestProps) { + + try { + + URL url = new URL(moipEnvironment + requestProps.endpoint); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestProperty("User-Agent", getUserAgent()); + connection.setRequestProperty("Content-type", requestProps.getContentType().getMimeType()); + + if (requestProps.hasAccept()) connection.setRequestProperty("Accept", requestProps.accept); + + connection.setRequestMethod(requestProps.method); + + // This validation disable the TLS 1.0 + if (connection instanceof HttpsURLConnection) { + ((HttpsURLConnection) connection).setSSLSocketFactory(new SSLSupport()); + } + + if (this.authentication != null) authentication.authenticate(connection); + + LOGGER.debug("---> {} {}", requestProps.method, connection.getURL().toString()); + logHeaders(connection.getRequestProperties().entrySet()); + + // Verificar essa parte do código, pois o objeto serializado deve ser um Map, não mais um String + + if (requestProps.body != null) { + connection.setDoOutput(true); + String body = tools.getBody(requestProps.body, requestProps.contentType); + + LOGGER.debug("{}", body); + + DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(wr, "UTF-8")); + writer.write(body); + writer.close(); + wr.flush(); + wr.close(); + } + + // ---------------------------------------------------------------------------------------------- + + LOGGER.debug("---> END HTTP"); + + int responseCode = connection.getResponseCode(); + + LOGGER.debug("<--- {} {}", responseCode, connection.getResponseMessage()); + logHeaders(connection.getHeaderFields().entrySet()); + + StringBuilder responseBody = new StringBuilder(); + + responseBody = responseBodyTreatment(responseBody, responseCode, connection); + + LOGGER.debug("{}", responseBody.toString()); + LOGGER.debug("<-- END HTTP ({}-byte body)", connection.getContentLength()); + + // Return the parsed response from JSON to Map. + return this.response.jsonToMap(responseBody.toString()); + + } catch(IOException | KeyManagementException | NoSuchAlgorithmException e){ + throw new MoipAPIException("Error occurred connecting to Moip API: " + e.getMessage(), e); + } + } + + /** + * + * @param requestProps + * @return + */ + public List> getList(final RequestProperties requestProps) { + + try { + + URL url = new URL(moipEnvironment + requestProps.endpoint); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestProperty("User-Agent", getUserAgent()); + connection.setRequestProperty("Content-type", requestProps.getContentType().getMimeType()); + + if (requestProps.hasAccept()) connection.setRequestProperty("Accept", requestProps.accept); + + connection.setRequestMethod(requestProps.method); + + // This validation disable the TLS 1.0 + if (connection instanceof HttpsURLConnection) { + ((HttpsURLConnection) connection).setSSLSocketFactory(new SSLSupport()); + } + + if (this.authentication != null) authentication.authenticate(connection); + + LOGGER.debug("---> {} {}", requestProps.method, connection.getURL().toString()); + logHeaders(connection.getRequestProperties().entrySet()); + + if (requestProps.body != null) { + connection.setDoOutput(true); + String body = tools.getBody(requestProps.body, requestProps.contentType); + + LOGGER.debug("{}", body); + + DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(wr, "UTF-8")); + writer.write(body); + writer.close(); + wr.flush(); + wr.close(); + } + + LOGGER.debug("---> END HTTP"); + + int responseCode = connection.getResponseCode(); + + LOGGER.debug("<--- {} {}", responseCode, connection.getResponseMessage()); + logHeaders(connection.getHeaderFields().entrySet()); + + StringBuilder responseBody = new StringBuilder(); + + responseBody = responseBodyTreatment(responseBody, responseCode, connection); + + LOGGER.debug("{}", responseBody.toString()); + LOGGER.debug("<-- END HTTP ({}-byte body)", connection.getContentLength()); + + // Return the parsed response from JSON to Map. + return this.response.jsonToList(responseBody.toString()); + + } catch(IOException | KeyManagementException | NoSuchAlgorithmException e){ + throw new MoipAPIException("Error occurred connecting to Moip API: " + e.getMessage(), e); + } + } + + /** + * This method is used to check the response code and apply the correct treatment to the + * response body. Basically, if the response code is between 200 and 299, this method returns + * a response body charged with the right input stream. If the response code is 401, this + * method throws a {@code UnauthorizedException}. If the code is between 400 and 499 (except 401), + * this method create and charge an {@code Error} object with a deserialize JSON returned from + * Moip API to build a {@code ValidationException} and throw it. And finally, if the response + * code is 500 or higher, this method throws a {@code UnexpectedException}. + * + * @param responseBody + * {@code StringBuilder} the response body returned from API. + * + * @param responseCode + * {@code int} the response code returned from API. + * + * @param connection + * {@code HttpURLConnection} the object containing the connection + * with Moip API. + * + * @return {@code StringBuilder} response body. + */ + private StringBuilder responseBodyTreatment(StringBuilder responseBody, int responseCode, HttpURLConnection connection) { + + try { + + if (responseCode >= 200 && responseCode < 299) { + responseBody = tools.readBody(connection.getInputStream()); + } + + if (responseCode == 401) { + throw new UnauthorizedException(); + } + + if (responseCode >= 400 && responseCode < 499) { + responseBody = tools.readBody(connection.getErrorStream()); + LOGGER.debug("API ERROR {}", responseBody.toString()); + + Errors errors = new Errors(); + + try { + + errors = tools.getGsonInstance().fromJson(responseBody.toString(), Errors.class); + + } catch (Exception e) { + + LOGGER.debug("There was not possible cast the JSON to object"); + } + + throw new ValidationException(responseCode, connection.getResponseMessage(), errors); + } + + if (responseCode >= 500) { + throw new UnexpectedException(); + } + + } catch (IOException e) { + throw new MoipAPIException("Error occurred connecting to Moip API: " + e.getMessage(), e); + } + + return responseBody; + } + + /** + * This method is used to populate an {@code Map.Entry} with passed keys and values to + * charge the debug logger. + * + * @param entries + * {@code Map.Entry>} + */ + private void logHeaders(Set>> entries) { + for (Map.Entry> header : entries) { + if (header.getKey() != null) { + LOGGER.debug("{}: {}", header.getKey(), header.getValue()); + } + } + } +} diff --git a/src/main/java/br/com/moip/api/request/RequestProperties.java b/src/main/java/br/com/moip/api/request/RequestProperties.java new file mode 100644 index 0000000..9868605 --- /dev/null +++ b/src/main/java/br/com/moip/api/request/RequestProperties.java @@ -0,0 +1,40 @@ +package br.com.moip.api.request; + +import org.apache.http.entity.ContentType; + +import java.util.Map; + +public class RequestProperties { + + protected String method; + protected String endpoint; + protected Map body; + protected Class type; + protected ContentType contentType; + protected String accept; + + public String getMethod() { return method; } + + public String getEndpoint() { return endpoint; } + + public Object getObject() { return body; } + + public Class getType() { return type; } + + public ContentType getContentType() { return contentType; } + + public String getAccept() { return accept; } + + /** + * This method is used to verify if the {@code Accept} header was settled into properties. + * + * @return {@code boolean} + */ + public boolean hasAccept() { + + if (this.accept == null) { return false; } + + return true; + } + +} diff --git a/src/main/java/br/com/moip/api/request/RequestPropertiesBuilder.java b/src/main/java/br/com/moip/api/request/RequestPropertiesBuilder.java new file mode 100644 index 0000000..a3802e0 --- /dev/null +++ b/src/main/java/br/com/moip/api/request/RequestPropertiesBuilder.java @@ -0,0 +1,136 @@ +package br.com.moip.api.request; + +import org.apache.http.entity.ContentType; + +import java.util.Map; + +public class RequestPropertiesBuilder extends RequestProperties { + + // Default constructor. + public RequestPropertiesBuilder() {} + + /** + * This method is used to set the request method into super class. + * The possible values are POST, GET, PUT and DELETE. + * + * @param method + * {@code String} request method + * + * @return {@code this} (RequestPropertiesBuilder) + */ + public RequestPropertiesBuilder method(String method) { + super.method = method; + + return this; + } + + /** + * This method is used to set the request endpoint into super class. + * This is the endpoint that will be requested. + * Ex: {@code /v2/customers}, {@code /v2/accounts}, {@code /v2/transfers}. + * + * @param endpoint + * {@code String} request endpoint. + * + * @return {@code this} (RequestPropertiesBuilder) + */ + public RequestPropertiesBuilder endpoint(String endpoint) { + super.endpoint = endpoint; + + return this; + } + + /** + * This method is used to set the request object into super class. + * The object is the body of the request. + * + * @param body + * {@code Object} request object + * + * @see java.lang.Object + * + * @return {@code this} (RequestPropertiesBuilder) + */ + public RequestPropertiesBuilder body(Map body) { + super.body = body; + + return this; + } + + /** + * This method is used to set the model class type. If the request + * is successful, the class attributes will be filled with the response. + * + * @param type + * {@code Class} request class type + * + * @see java.lang.Class + * + * @return {@code this} (RequestPropertiesBuilder) + */ + public RequestPropertiesBuilder type(Class type) { + super.type = type; + + return this; + } + + /** + * This method is used to set the request content type. + * Actually, the only content type accept by Moip API is the {@code APPLICATION_JSON}. + * + * @param contentType + * {@code ContentType} request content type + * + * @see org.apache.http.entity.ContentType + * + * @return {@code this} (RequestPropertiesBuilder) + */ + public RequestPropertiesBuilder contentType(ContentType contentType) { + super.contentType = contentType; + + return this; + } + + /** + * This method is used to set the JSON version, if it takes. + * Actually, only some endpoints accept a different JSON version. + * Accept {@code application/json;version=2.1} + * Possible value: {@code "2.1"} + * + * @param acceptVersion + * {@code String} accept JSON version + * + * @see Saldo Moip + * @see Lançamentos + * + * @return {@code this} (RequestPropertiesBuilder) + */ + public RequestPropertiesBuilder accept(String acceptVersion) { + super.accept = acceptBuilder(acceptVersion); + + return this; + } + + /** + * This method is used to validate and build the accept JSON version. + * + * @param version + * {@code String} version + * + * @return {@code String} the mounted header value + */ + private String acceptBuilder(String version) { + String acceptValue = "application/json"; + if(version == "2.1") acceptValue += ";version=" + version; + + return acceptValue; + } + + /** + * This method is used to parse the object to RequestProperties type and + * complete the build. + * + * @return {@code this} (RequestProperties) + */ + public RequestProperties build() { return this; } +} diff --git a/src/main/java/br/com/moip/api/request/RequestTools.java b/src/main/java/br/com/moip/api/request/RequestTools.java new file mode 100644 index 0000000..c185931 --- /dev/null +++ b/src/main/java/br/com/moip/api/request/RequestTools.java @@ -0,0 +1,69 @@ +package br.com.moip.api.request; + +import br.com.moip.utilities.GsonFactory; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.apache.http.entity.ContentType; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import static br.com.moip.utilities.DataHelper.jsonToUrlEncodedString; + +public class RequestTools { + + private final Gson gson = GsonFactory.gson(); + + /** + * Method to get a Gson instance. + * + * @return {@code Gson} + */ + Gson getGsonInstance() { return gson; } + + /** + * This method is used to read a {@code InputStream} and build a body object with this stream. + * + * @param inputStream + * {@code InputStream} the stream that will charge the body object. + * + * @return {@code StringBuilder} + * + * @throws IOException + * This method throws a {@code IOException} if the inputted stream isn't correctly. + */ + StringBuilder readBody(final InputStream inputStream) throws IOException { + StringBuilder body = new StringBuilder(); + BufferedReader in = new BufferedReader(new InputStreamReader(inputStream)); + + String inputLine; + while ((inputLine = in.readLine()) != null) { + body.append(inputLine); + } + in.close(); + + return body; + } + + /** + * This method is used to get a serialized object into its equivalent JSON representation. + * + * @param object + * {@code Object} the body object. + * + * @param contentType + * {@ContentType} the content type header. + * + * @return {@code String} + */ + String getBody(Object object, ContentType contentType) { + if (contentType == ContentType.APPLICATION_FORM_URLENCODED) { + return jsonToUrlEncodedString((JsonObject) new JsonParser().parse(gson.toJson(object))); + } + + return gson.toJson(object); + } +} diff --git a/src/main/java/br/com/moip/api/response/Response.java b/src/main/java/br/com/moip/api/response/Response.java new file mode 100644 index 0000000..7c81047 --- /dev/null +++ b/src/main/java/br/com/moip/api/response/Response.java @@ -0,0 +1,59 @@ +package br.com.moip.api.response; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Response extends HashMap { + + private Map responseBody = new HashMap<>(); + private List> responseBodyList = new ArrayList<>(); + + /** + * This method is used to receive the JSON returned from API and cast it to a Map. + * + * @param json + * {@code String} the JSON returned from API, by {@code InputStream}. + * + * @return {@code Map} + */ + public Map jsonToMap(String json) { + if (!json.equals("")) { + ObjectMapper mapper = new ObjectMapper(); + try { + this.responseBody = mapper.readValue(json, new TypeReference>(){}); + } catch (IOException e) { + e.printStackTrace(); + } + } + return this.responseBody; + } + + /** + * + * @param json + * @return + */ + public List> jsonToList(String json) { + ObjectMapper mapper = new ObjectMapper(); + try { + this.responseBodyList = mapper.readValue(json, new TypeReference>>(){}); + } catch (IOException e) { + e.printStackTrace(); + } + return this.responseBodyList; + } +} + +/* Este método resolve grande parte do problema, porém não resolve o problema por completo. + * Precisamos fazer com que cada nó do JSON se converta em um objeto do seu respectivo model. + * Ex: o nó "taxDocument" precisa ser convertido em um objeto da classe TaxDocument. + * + * Talvez seja possível trabalhar com o [type], o atributo da classe RequestProperties, que tem + * como objetivo indicar a qual classe/model aquele objeto pertence. + */ \ No newline at end of file diff --git a/src/main/java/br/com/moip/auth/Authentication.java b/src/main/java/br/com/moip/auth/Authentication.java new file mode 100644 index 0000000..b663301 --- /dev/null +++ b/src/main/java/br/com/moip/auth/Authentication.java @@ -0,0 +1,8 @@ +package br.com.moip.auth; + +import java.net.HttpURLConnection; + +public interface Authentication { + + void authenticate(HttpURLConnection connection); +} diff --git a/src/main/java/br/com/moip/auth/Base64.java b/src/main/java/br/com/moip/auth/Base64.java new file mode 100644 index 0000000..5b94669 --- /dev/null +++ b/src/main/java/br/com/moip/auth/Base64.java @@ -0,0 +1,144 @@ +package br.com.moip.auth; + +import java.io.UnsupportedEncodingException; + +/** + * copied from okhttp + * + * @author Alexander Y. Kleymenov + */ +public class Base64 { + + public static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; + private static final byte[] MAP = new byte[]{ + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', + 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', + 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', + '5', '6', '7', '8', '9', '+', '/' + }; + + private Base64() { + } + + public static byte[] decode(byte[] in) { + return decode(in, in.length); + } + + public static byte[] decode(byte[] in, int len) { + // approximate output length + int length = len / 4 * 3; + // return an empty array on empty or short input without padding + if (length == 0) { + return EMPTY_BYTE_ARRAY; + } + // temporary array + byte[] out = new byte[length]; + // number of padding characters ('=') + int pad = 0; + byte chr; + // compute the number of the padding characters + // and adjust the length of the input + for (; ; len--) { + chr = in[len - 1]; + // skip the neutral characters + if ((chr == '\n') || (chr == '\r') || (chr == ' ') || (chr == '\t')) { + continue; + } + if (chr == '=') { + pad++; + } else { + break; + } + } + // index in the output array + int outIndex = 0; + // index in the input array + int inIndex = 0; + // holds the value of the input character + int bits = 0; + // holds the value of the input quantum + int quantum = 0; + for (int i = 0; i < len; i++) { + chr = in[i]; + // skip the neutral characters + if ((chr == '\n') || (chr == '\r') || (chr == ' ') || (chr == '\t')) { + continue; + } + if ((chr >= 'A') && (chr <= 'Z')) { + // char ASCII value + // A 65 0 + // Z 90 25 (ASCII - 65) + bits = chr - 65; + } else if ((chr >= 'a') && (chr <= 'z')) { + // char ASCII value + // a 97 26 + // z 122 51 (ASCII - 71) + bits = chr - 71; + } else if ((chr >= '0') && (chr <= '9')) { + // char ASCII value + // 0 48 52 + // 9 57 61 (ASCII + 4) + bits = chr + 4; + } else if (chr == '+') { + bits = 62; + } else if (chr == '/') { + bits = 63; + } else { + return null; + } + // append the value to the quantum + quantum = (quantum << 6) | (byte) bits; + if (inIndex % 4 == 3) { + // 4 characters were read, so make the output: + out[outIndex++] = (byte) (quantum >> 16); + out[outIndex++] = (byte) (quantum >> 8); + out[outIndex++] = (byte) quantum; + } + inIndex++; + } + if (pad > 0) { + // adjust the quantum value according to the padding + quantum = quantum << (6 * pad); + // make output + out[outIndex++] = (byte) (quantum >> 16); + if (pad == 1) { + out[outIndex++] = (byte) (quantum >> 8); + } + } + // create the resulting array + byte[] result = new byte[outIndex]; + System.arraycopy(out, 0, result, 0, outIndex); + return result; + } + + public static String encode(byte[] in) { + int length = (in.length + 2) * 4 / 3; + byte[] out = new byte[length]; + int index = 0, end = in.length - in.length % 3; + for (int i = 0; i < end; i += 3) { + out[index++] = MAP[(in[i] & 0xff) >> 2]; + out[index++] = MAP[((in[i] & 0x03) << 4) | ((in[i + 1] & 0xff) >> 4)]; + out[index++] = MAP[((in[i + 1] & 0x0f) << 2) | ((in[i + 2] & 0xff) >> 6)]; + out[index++] = MAP[(in[i + 2] & 0x3f)]; + } + switch (in.length % 3) { + case 1: + out[index++] = MAP[(in[end] & 0xff) >> 2]; + out[index++] = MAP[(in[end] & 0x03) << 4]; + out[index++] = '='; + out[index++] = '='; + break; + case 2: + out[index++] = MAP[(in[end] & 0xff) >> 2]; + out[index++] = MAP[((in[end] & 0x03) << 4) | ((in[end + 1] & 0xff) >> 4)]; + out[index++] = MAP[((in[end + 1] & 0x0f) << 2)]; + out[index++] = '='; + break; + } + try { + return new String(out, 0, index, "US-ASCII"); + } catch (UnsupportedEncodingException e) { + throw new AssertionError(e); + } + } +} diff --git a/src/main/java/br/com/moip/auth/BasicAuth.java b/src/main/java/br/com/moip/auth/BasicAuth.java new file mode 100644 index 0000000..4731604 --- /dev/null +++ b/src/main/java/br/com/moip/auth/BasicAuth.java @@ -0,0 +1,25 @@ +package br.com.moip.auth; + +import java.net.HttpURLConnection; + +public class BasicAuth implements Authentication { + + private final String token; + private final String key; + + public BasicAuth(String token, String key) { + this.token = token; + this.key = key; + } + + public String getToken() { return token; } + + public String getKey() { return key; } + + @Override + public void authenticate(HttpURLConnection connection) { + String authorization = Base64.encode((token + ":" + key).getBytes()); + + connection.setRequestProperty("Authorization", "Basic " + authorization); + } +} diff --git a/src/main/java/br/com/moip/auth/OAuth.java b/src/main/java/br/com/moip/auth/OAuth.java new file mode 100644 index 0000000..5cf5f50 --- /dev/null +++ b/src/main/java/br/com/moip/auth/OAuth.java @@ -0,0 +1,18 @@ +package br.com.moip.auth; + +import java.net.HttpURLConnection; + +public class OAuth implements Authentication { + + private final String accessToken; + + public OAuth(String accessToken) { + this.accessToken = accessToken; + } + + public String getAccessToken() { return accessToken; } + + public void authenticate(HttpURLConnection connection) { + connection.addRequestProperty("Authorization", "OAuth " + accessToken); + } +} diff --git a/src/main/java/br/com/moip/exception/MoipAPIException.java b/src/main/java/br/com/moip/exception/MoipAPIException.java new file mode 100644 index 0000000..90f35d6 --- /dev/null +++ b/src/main/java/br/com/moip/exception/MoipAPIException.java @@ -0,0 +1,63 @@ +package br.com.moip.exception; + +public class MoipAPIException extends RuntimeException { + + /** + * Default class constructor. + */ + public MoipAPIException() {} + + /** + * Constructor to receive the exception message. + * + * @param message + * {@code String} exception message + */ + public MoipAPIException(final String message) { + super(message); + } + + /** + * Constructor to receive the exception cause. + * + * @param cause + * {@code Throwable} exception cause. + */ + public MoipAPIException(final Throwable cause) { + super(cause); + } + + /** + * Constructor to receive the exception message and cause. + * + * @param message + * {@code String} exception message + * + * @param cause + * {@code Throwable} exception cause + */ + public MoipAPIException(final String message, final Throwable cause) { + super(message, cause); + } + + /** + * Constructor to receive the message and the cause of an exception + * and to able the suppression and the writable stack trace. + * + * @param message + * {@code String} exception message + * + * @param cause + * {@code Throwable} exception cause + * + * @param enableSuppression + * {@code boolean} exception suppression + * + * @param writableStackTrace + * {@code boolean} exception stack trace + */ + public MoipAPIException(final String message, final Throwable cause, + final boolean enableSuppression, final boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/src/main/java/br/com/moip/exception/UnauthorizedException.java b/src/main/java/br/com/moip/exception/UnauthorizedException.java new file mode 100644 index 0000000..6987195 --- /dev/null +++ b/src/main/java/br/com/moip/exception/UnauthorizedException.java @@ -0,0 +1,3 @@ +package br.com.moip.exception; + +public class UnauthorizedException extends MoipAPIException {} diff --git a/src/main/java/br/com/moip/exception/UnexpectedException.java b/src/main/java/br/com/moip/exception/UnexpectedException.java new file mode 100644 index 0000000..1e904f2 --- /dev/null +++ b/src/main/java/br/com/moip/exception/UnexpectedException.java @@ -0,0 +1,3 @@ +package br.com.moip.exception; + +public class UnexpectedException extends MoipAPIException {} diff --git a/src/main/java/br/com/moip/exception/ValidationException.java b/src/main/java/br/com/moip/exception/ValidationException.java new file mode 100644 index 0000000..c3a4ef4 --- /dev/null +++ b/src/main/java/br/com/moip/exception/ValidationException.java @@ -0,0 +1,35 @@ +package br.com.moip.exception; + +import br.com.moip.models.error.Errors; + +public class ValidationException extends MoipAPIException { + + private final int responseCode; + private final String responseStatus; + private final Errors errors; + + /** + * This constructor is used to set the code, status and errors + * from api response, when it trows a ValidationException. + * + * @param responseCode + * {@code int} api response code + * + * @param responseStatus + * {@code String} api response status + * + * @param errors + * {@code Errors} api errors + */ + public ValidationException(final int responseCode, final String responseStatus, final Errors errors) { + this.responseCode = responseCode; + this.responseStatus = responseStatus; + this.errors = errors; + } + + public int getResponseCode() { return responseCode; } + + public String getResponseStatus() { return responseStatus; } + + public Errors getErrors() { return errors; } +} diff --git a/src/main/java/br/com/moip/models/APIDate.java b/src/main/java/br/com/moip/models/APIDate.java new file mode 100644 index 0000000..c4dfc53 --- /dev/null +++ b/src/main/java/br/com/moip/models/APIDate.java @@ -0,0 +1,41 @@ +/** + * @author Danillo Souza paniko0 + */ + +package br.com.moip.models; + +import java.text.SimpleDateFormat; +import java.util.Date; + +public class APIDate { + + private Date date; + + /** + * This method receives an date to set it on {@code this.date}. + * + * @param date + * {@code APIDate} a numerical date. + */ + public void setDate(Date date) { this.date = date; } + + /** + * This method returns the value of {@code this.date}. + * + * @return {@code APIDate} + */ + public Date getDate() { return date; } + + /** + * This method process {@code this.date} to build the accept date + * format using the pattern {@code "yyyy-MM-dd"}. + * + * @return {@code String} + * The date format accept by API. + */ + public String getFormatedDate() { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + return simpleDateFormat.format(this.getDate()); + } + +} diff --git a/src/main/java/br/com/moip/models/Customer.java b/src/main/java/br/com/moip/models/Customer.java new file mode 100644 index 0000000..ce153fa --- /dev/null +++ b/src/main/java/br/com/moip/models/Customer.java @@ -0,0 +1,132 @@ +package br.com.moip.models; + +import br.com.moip.api.request.RequestMaker; +import br.com.moip.api.request.RequestProperties; +import br.com.moip.api.request.RequestPropertiesBuilder; +import org.apache.http.entity.ContentType; + +import java.util.Map; + +public class Customer { + + private static final String ENDPOINT = "/v2/customers"; + private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON; + private RequestMaker requestMaker; + + /** + * This method is used to create an customer. + * + * @param body + * {@code Map} the map charged with the correct request + * attributes. + * + * @param setup + * {@code Setup} the basic connection setup (authentication and timeouts). + * + * @return {@code Map create(Map body, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("POST") + .endpoint(ENDPOINT) + .body(body) + .type(Customer.class) + .contentType(CONTENT_TYPE); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to add a new credit card to a registered customer. + * + * @param body + * {@code Map} the request body. + * + * @param customerId + * {@code String} the Moip customer external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map addCreditCard(Map body, String customerId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("POST") + .endpoint(String.format("%s/%s/fundinginstruments", ENDPOINT, customerId)) + .body(body) + .type(Customer.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to delete a saved credit card of an customer. + * + * @param creditCardId + * {@code String} the Moip credit card external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map deleteCreditCard(String creditCardId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("DELETE") + .endpoint(String.format("/v2/fundinginstruments/%s", creditCardId)) + .type(Customer.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to get the data of a created customer by Moip customer external ID. + * + * @param customerId + * {@code String} the Moip customer external ID. Ex: CUS-XXXXXXXXXXXX. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map}. + */ + public Map get(String customerId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(String.format("%s/%s", ENDPOINT, customerId)) + .type(Customer.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to get all registered customers. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map list(Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(ENDPOINT) + .type(Customer.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } +} diff --git a/src/main/java/br/com/moip/models/NotificationPreference.java b/src/main/java/br/com/moip/models/NotificationPreference.java new file mode 100644 index 0000000..31b153c --- /dev/null +++ b/src/main/java/br/com/moip/models/NotificationPreference.java @@ -0,0 +1,106 @@ +package br.com.moip.models; + +import br.com.moip.api.request.RequestMaker; +import br.com.moip.api.request.RequestProperties; +import br.com.moip.api.request.RequestPropertiesBuilder; +import org.apache.http.entity.ContentType; + +import java.util.List; +import java.util.Map; + +public class NotificationPreference { + + private static final String ENDPOINT = "/v2/preferences/notifications"; + private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON; + private RequestMaker requestMaker; + + /** + * This method is used to create a notification preference to receive Webhooks. + * + * @param body + * {@code Map} the map charged with request attributes. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map create(Map body, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("POST") + .endpoint(ENDPOINT) + .body(body) + .type(NotificationPreference.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to get the data of a created notification preference. + * + * @param notificationPreferenceId + * {@code String} the Moip notification preference external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map get(String notificationPreferenceId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(String.format("%s/%s", ENDPOINT, notificationPreferenceId)) + .type(NotificationPreference.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to get all created notification preferences. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code List>} + */ + public List> list(Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(ENDPOINT) + .type(NotificationPreference.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.getList(props); + } + + /** + * This method is used to remove a created notification preference. + * + * @param notificationPreferenceId + * {@code String} the Moip notification preference external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map remove(String notificationPreferenceId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("DELETE") + .endpoint(String.format("%s/%s", ENDPOINT, notificationPreferenceId)) + .type(NotificationPreference.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } +} diff --git a/src/main/java/br/com/moip/models/Order.java b/src/main/java/br/com/moip/models/Order.java new file mode 100644 index 0000000..fb46d1a --- /dev/null +++ b/src/main/java/br/com/moip/models/Order.java @@ -0,0 +1,105 @@ +package br.com.moip.models; + +import br.com.moip.api.request.RequestMaker; +import br.com.moip.api.request.RequestProperties; +import br.com.moip.api.request.RequestPropertiesBuilder; +import org.apache.http.entity.ContentType; + +import java.util.Map; + +public class Order { + + private static final String ENDPOINT = "/v2/orders"; + private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON; + private RequestMaker requestMaker; + + /** + * This method is used to create a new order. + * + * @param body + * {@code Map} the request body. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map create(Map body, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("POST") + .endpoint(ENDPOINT) + .body(body) + .type(Order.class) + .contentType(CONTENT_TYPE) + .build(); + + return requestMaker.doRequest(props); + } + + /** + * This method is used to get the data of a created order by Moip order external ID. + * + * @param orderId + * {@code String} the Moip order external ID. Ex: ORD-XXXXXXXXXXXX + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map get(String orderId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(String.format("%s/%s", ENDPOINT, orderId)) + .type(Order.class) + .contentType(CONTENT_TYPE) + .build(); + + return requestMaker.doRequest(props); + } + + /** + * This method is used to get all created orders. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map list(Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(ENDPOINT) + .type(Order.class) + .contentType(CONTENT_TYPE) + .build(); + + return requestMaker.doRequest(props); + } + + /** + * This method is used to get all payments of an order by its Moip order external ID. + * + * @param orderId + * {@code String} the Moip order external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map listOrderPayments(String orderId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(String.format("%s/%s/payments", ENDPOINT, orderId)) + .type(Order.class) + .contentType(CONTENT_TYPE) + .build(); + + return requestMaker.doRequest(props); + } +} diff --git a/src/main/java/br/com/moip/models/Payment.java b/src/main/java/br/com/moip/models/Payment.java new file mode 100644 index 0000000..0b1b9f4 --- /dev/null +++ b/src/main/java/br/com/moip/models/Payment.java @@ -0,0 +1,161 @@ +package br.com.moip.models; + +import br.com.moip.api.request.RequestMaker; +import br.com.moip.api.request.RequestProperties; +import br.com.moip.api.request.RequestPropertiesBuilder; +import br.com.moip.exception.ValidationException; +import br.com.moip.models.error.Errors; +import br.com.moip.models.error.ErrorBuilder; +import org.apache.http.entity.ContentType; + +import java.util.Map; + +import static br.com.moip.Moip.SANDBOX_URL; + +public class Payment { + + private static final String ENDPOINT = "/v2/payments"; + private static final String ENDPOINT_TO_PAY = "/v2/orders/%s/payments"; + private static final String ENDPOINT_TO_AUTHORIZE = "/simulador/authorize"; + private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON; + private RequestMaker requestMaker; + + /** + * This method is used to create a payment. To make it, is necessary send the {@code body} + * filled with the payment data and the ID of the order that will be payed. + * + * @param body + * {@code Map} the request body. + * + * @param orderId + * {@code String} the Moip order external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map pay(Map body, String orderId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("POST") + .endpoint(String.format(ENDPOINT_TO_PAY, orderId)) + .body(body) + .type(Payment.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to capture a pre-authorized payment by its Moip payment external ID. + * + * @param paymentId + * {@code String} the Moip payment external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map capturePreAuthorized(String paymentId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("POST") + .endpoint(String.format("%s/%s/capture", ENDPOINT, paymentId)) + .type(Payment.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to cancel a pre-authorized payment by Moip payment external ID. + * + * @param paymentId + * {@code String} the Moip payment external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map cancelPreAuthorized(String paymentId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("POST") + .endpoint(String.format("%s/%s/void", ENDPOINT, paymentId)) + .type(Payment.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to get the data of a created payment by Moip payment external ID. + * + * @param paymentId + * {@code String} the Moip payment external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map get(String paymentId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(String.format("%s/%s", ENDPOINT, paymentId)) + .type(Payment.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to simulate the payment authorization. To make it, its necessary + * send the Moip payment external ID and the amount value. + * + * WARNING: This method can be used to request only Sandbox environment. + * + * @param paymentId + * {@code String} the Moip payment external ID. + * + * @param amount + * {@code int} the amount value that will be authorized. + * + * @param setup + * {@code Setup} the setup obeject. + * + * @return {@code Map} + */ + public Map authorize(String paymentId, int amount, Setup setup) { + if (setup.getEnvironment() == SANDBOX_URL) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(String.format("%s?payment_id=%s&amount=%s", ENDPOINT_TO_AUTHORIZE, paymentId, amount)) + .type(Payment.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + else { + ErrorBuilder error = new ErrorBuilder() + .code("404") + .path("") + .description("Wrong environment! Only payments created on Sandbox environment can be manually authorized."); + + Errors errors = new Errors(); + errors.setError(error); + + throw new ValidationException(404, "Not Found", errors); + } + } +} diff --git a/src/main/java/br/com/moip/models/Refund.java b/src/main/java/br/com/moip/models/Refund.java new file mode 100644 index 0000000..a044fed --- /dev/null +++ b/src/main/java/br/com/moip/models/Refund.java @@ -0,0 +1,188 @@ +package br.com.moip.models; + +import br.com.moip.api.request.RequestMaker; +import br.com.moip.api.request.RequestProperties; +import br.com.moip.api.request.RequestPropertiesBuilder; +import org.apache.http.entity.ContentType; + +import java.util.Map; + +public class Refund { + + private static final String ENDPOINT = "/v2/refunds/%s"; + private static final String ENDPOINT_REFUND_ORDER = "/v2/orders/%s/refunds"; + private static final String ENDPOINT_REFUND_PAYMENT = "/v2/payments/%s/refunds"; + private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON; + private RequestMaker requestMaker; + + /** + * This method is used to create a payment refund without request body. + * TIP: Actually, its possible make only refund by credit card with this method. + * + * @param paymentId + * {@code String} the Moip payment external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map refundPayment(String paymentId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("POST") + .endpoint(String.format(ENDPOINT_REFUND_PAYMENT, paymentId)) + .type(Refund.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to create a payment refund with request body. + * + * @param body + * {@code Map} the map charged with request attributes. + * + * @param paymentId + * {@code String} the Moip payment external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map refundPayment(Map body, String paymentId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("POST") + .endpoint(String.format(ENDPOINT_REFUND_PAYMENT, paymentId)) + .body(body) + .type(Refund.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to create a order refund without request body. + * TIP: Actually, its possible make only refund by credit card with this method. + * + * @param orderId + * {@code String} the Moip order external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map refundOrder(String orderId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("POST") + .endpoint(String.format(ENDPOINT_REFUND_ORDER, orderId)) + .type(Refund.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to create a order refund with request body. + * + * @param body + * {@code Map} the map charged with request attributes. + * + * @param orderId + * {@code String} the Moip order external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map refundOrder(Map body, String orderId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("POST") + .endpoint(String.format(ENDPOINT_REFUND_ORDER, orderId)) + .body(body) + .type(Refund.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to get the data of a created refund by Moip refund external ID. + * + * @param refundId + * {@code String} the Moip refund external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map get(String refundId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(String.format(ENDPOINT, refundId)) + .type(Refund.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to get all refunds of an payment by Moip payment external ID. + * + * @param paymentId + * {@code String} the Moip payment external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map listPaymentRefunds(String paymentId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(String.format(ENDPOINT_REFUND_PAYMENT, paymentId)) + .type(Refund.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to get all refunds of an order by Moip order external ID. + * + * @param orderId + * {@code String} the Moip order external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map listOrderRefunds(String orderId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(String.format(ENDPOINT_REFUND_ORDER, orderId)) + .type(Refund.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } +} diff --git a/src/main/java/br/com/moip/models/Setup.java b/src/main/java/br/com/moip/models/Setup.java new file mode 100644 index 0000000..5a3749c --- /dev/null +++ b/src/main/java/br/com/moip/models/Setup.java @@ -0,0 +1,142 @@ +package br.com.moip.models; + +import br.com.moip.auth.Authentication; + +import static br.com.moip.Moip.PRODUCTION_URL; +import static br.com.moip.Moip.SANDBOX_URL; +import static br.com.moip.Moip.CONNECT_PRODUCTION_URL; +import static br.com.moip.Moip.CONNECT_SANDBOX_URL; + +public class Setup { + + private Authentication authentication; + + private String environment; + + // Default connect timeout (in milliseconds) with default value. + private static int CONNECT_TIMEOUT = 60 * 1000; + + // Read timeout (in milliseconds) with default value. + private static int READ_TIMEOUT = 80 * 1000; + + /** + * This method is used to set the authentication that will be + * used to authorize the request. The authentication may be an + * BasicAuth or an OAuth. + * + * @see br.com.moip.auth.BasicAuth + * @see br.com.moip.auth.OAuth + * + * @param authentication + * {@code Authentication} to connect with Moip APIResources. + * + * @return {@code this} (Setup) + */ + public Setup setAuthentication(final Authentication authentication) { + this.authentication = authentication; + + return this; + } + + /** + * This method is used to set the Moip API environment where the requests will be sent. + * The only Moip environments that are possible request are {@code SANDBOX} or {@code PRODUCTION}. + * + * @param environment + * {@code String} the Moip API environment. + * + * @return {@code Setup} + */ + public Setup setEnvironment(final Environment environment) { + + switch (environment) { + + case SANDBOX : this.environment = SANDBOX_URL; break; + case PRODUCTION : this.environment = PRODUCTION_URL; break; + case CONNECT_SANDBOX : this.environment = CONNECT_SANDBOX_URL; break; + case CONNECT_PRODUCTION : this.environment = CONNECT_PRODUCTION_URL; break; + + default : this.environment = ""; + } + + return this; + } + + /** + * This method is used to set the {@code Player} endpoint for mock unit tests. + * + * @param endpoint + * {@code String} the endpoint for mock tests. + * + * @return {@code this} (Setup) + */ + public Setup setPlayerEndpoint(final String endpoint) { + this.environment = endpoint; + + return this; + } + + /** + * Use this method will change the connect timeout default value. + * It will be used to request the Moip APIResources. + * + * @param connectTimeout + * {@code int} timeout in milliseconds. + * + * @return {@code this} (Setup) + */ + public Setup setConnectTimeout(final int connectTimeout) { + CONNECT_TIMEOUT = connectTimeout; + + return this; + } + + /** + * Use this method will change the read timeout default value. + * It will be used to request the Moip APIResources. + * + * @param readTimeout + * {@code int} timeout in millisecond. + * + * @return {@code this} (Setup) + */ + public Setup setReadTimeout(final int readTimeout) { + READ_TIMEOUT = readTimeout; + + return this; + } + + /** + * This method is used to get the value of {@code authentication} attribute. + * + * @return {@code Authentication} + */ + public Authentication getAuthentication() { return this.authentication; } + + /** + * This method is used to get the value of {@code environment} attribute. + * + * @return {@code String} + */ + public String getEnvironment() { return this.environment; } + + /** + * This method is used to get the value of {@code CONNECT_TIMEOUT} attribute. + * + * @return {@code int} + */ + public static int getConnectTimeout() { return CONNECT_TIMEOUT; } + + /** + * This method is used to get the value of {@code READ_TIMEOUT} attribute. + * + * @return {@code int} + */ + public static int getReadTimeout() { return READ_TIMEOUT; } + + + /** + * These enums are used to difference all Moip API environments. + */ + public enum Environment { SANDBOX, CONNECT_SANDBOX, PRODUCTION, CONNECT_PRODUCTION } +} diff --git a/src/main/java/br/com/moip/models/Webhook.java b/src/main/java/br/com/moip/models/Webhook.java new file mode 100644 index 0000000..3dbe379 --- /dev/null +++ b/src/main/java/br/com/moip/models/Webhook.java @@ -0,0 +1,59 @@ +package br.com.moip.models; + +import br.com.moip.api.request.RequestMaker; +import br.com.moip.api.request.RequestProperties; +import br.com.moip.api.request.RequestPropertiesBuilder; +import org.apache.http.entity.ContentType; + +import java.util.Map; + +public class Webhook { + + private static final String ENDPOINT = "/v2/webhooks"; + private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON; + private RequestMaker requestMaker; + + /** + * This method is used to get the data of a specific Webhook sent from Moip by Moip + * resource external ID. + * + * @param resourceId + * {@code String} the Moip external ID of a resource (Order, Payment, Refund...). + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map get(String resourceId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(ENDPOINT + String.format("?resourceId=%s", resourceId)) + .type(Webhook.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to get all sent Webhooks. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map list(Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(ENDPOINT) + .type(Webhook.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } +} diff --git a/src/main/java/br/com/moip/models/error/Error.java b/src/main/java/br/com/moip/models/error/Error.java new file mode 100644 index 0000000..714a3ed --- /dev/null +++ b/src/main/java/br/com/moip/models/error/Error.java @@ -0,0 +1,41 @@ +/** + * Read more { + + /** + * + * @param src + * @param typeOfSrc + * @param context + * @return + */ + @Override + public JsonElement serialize(APIDateRequest src, Type typeOfSrc, JsonSerializationContext context) { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); + return new JsonPrimitive(format.format(src.getDate())); + } +} diff --git a/src/main/java/br/com/moip/utilities/BirthDateRequestSerializer.java b/src/main/java/br/com/moip/utilities/BirthDateRequestSerializer.java new file mode 100644 index 0000000..4768c8e --- /dev/null +++ b/src/main/java/br/com/moip/utilities/BirthDateRequestSerializer.java @@ -0,0 +1,54 @@ +package br.com.moip.utilities; + +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonParseException; + +import java.lang.reflect.Type; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +class BirthDateRequestSerializer implements JsonSerializer, JsonDeserializer { + + /** + * + * @param src + * @param typeOfSrc + * @param context + * @return + */ + @Override + public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(sdf().format(src)); + } + + /** + * + * @param jsonElement + * @param type + * @param jsonDeserializationContext + * @return + * @throws JsonParseException + */ + @Override + public Date deserialize(JsonElement jsonElement, Type type, + JsonDeserializationContext jsonDeserializationContext) + throws JsonParseException { + try { + return sdf().parse(jsonElement.getAsString()); + } catch (ParseException e) { + e.printStackTrace(); + } + return new Date(); + } + + private SimpleDateFormat sdf() { + return new SimpleDateFormat("yyyy-MM-dd"); + } + +} diff --git a/src/main/java/br/com/moip/utilities/DataHelper.java b/src/main/java/br/com/moip/utilities/DataHelper.java new file mode 100644 index 0000000..b150135 --- /dev/null +++ b/src/main/java/br/com/moip/utilities/DataHelper.java @@ -0,0 +1,47 @@ +package br.com.moip.utilities; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.Map; + +public class DataHelper { + + public static String jsonToUrlEncodedString(JsonObject jsonObject) { + return jsonToUrlEncodedString(jsonObject, ""); + } + + private static String jsonToUrlEncodedString(JsonObject jsonObject, String prefix) { + StringBuilder url = new StringBuilder(""); + Boolean firstEntry = true; + + try { + for (Map.Entry item : jsonObject.entrySet()) { + if (!firstEntry) { + url.append("&"); + } + + if (item.getValue() != null && item.getValue().isJsonObject()) { + url.append(jsonToUrlEncodedString( + item.getValue().getAsJsonObject(), + prefix.isEmpty() ? item.getKey() : prefix + "[" + item.getKey() + "]" + ) + ); + } else { + url.append(prefix.isEmpty() ? + item.getKey() + "=" + URLEncoder.encode(item.getValue().getAsString(), "UTF-8") : + prefix + "[" + item.getKey() + "]=" + URLEncoder.encode(item.getValue().getAsString(), "UTF-8") + ); + } + + firstEntry = false; + } + + } catch(UnsupportedEncodingException e) { + e.printStackTrace(); + } + return url.toString(); + } +} diff --git a/src/main/java/br/com/moip/utilities/GsonFactory.java b/src/main/java/br/com/moip/utilities/GsonFactory.java new file mode 100644 index 0000000..4ac91c9 --- /dev/null +++ b/src/main/java/br/com/moip/utilities/GsonFactory.java @@ -0,0 +1,24 @@ +package br.com.moip.utilities; + +import br.com.moip.api.request.APIDateRequest; +import br.com.moip.models.APIDate; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import java.util.Date; + +public class GsonFactory { + + /** + * + * @return + */ + public static Gson gson() { + return new GsonBuilder() + .setDateFormat("yyyy-MM-dd'T'HH:mm:ss") + .registerTypeAdapter(Date.class, new BirthDateRequestSerializer()) + .registerTypeAdapter(APIDateRequest.class, new ApiDateSerializer()) + .registerTypeAdapter(APIDate.class, new ApiDateDeserializer()) + .create(); + } +} diff --git a/src/main/java/br/com/moip/utilities/Parser.java b/src/main/java/br/com/moip/utilities/Parser.java new file mode 100644 index 0000000..e12e557 --- /dev/null +++ b/src/main/java/br/com/moip/utilities/Parser.java @@ -0,0 +1,37 @@ +package br.com.moip.utilities; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.util.List; +import java.util.Map; + +/** + * + */ +public class Parser { + + /** + * This method is used to cast a {@code Object} to {@code Map}. The main + * objective of this method is objectToMap the objects from response Map to make possible + * catch its attributes' values. + * + * @param object + * {@code Object} any Object type. + * + * @return {@code Map} + */ + public Map objectToMap(Object object) { + ObjectMapper mapper = new ObjectMapper(); + + return mapper.convertValue(object, Map.class); + } + + /** + * + * @param object + * @return + */ + public List> objectToList(Object object) { + return (List>)object; + } +} diff --git a/src/main/java/br/com/moip/utilities/ssl/SSLSupport.java b/src/main/java/br/com/moip/utilities/ssl/SSLSupport.java new file mode 100644 index 0000000..e356028 --- /dev/null +++ b/src/main/java/br/com/moip/utilities/ssl/SSLSupport.java @@ -0,0 +1,252 @@ +package br.com.moip.utilities.ssl; + +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.KeyManager; +import javax.net.ssl.TrustManager; +import javax.net.ssl.SSLSocket; +import java.io.IOException; +import java.net.InetAddress; +import java.net.Socket; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class SSLSupport extends SSLSocketFactory { + + private SSLContext mCtx; + + private String[] mCiphers; + private String[] mProtocols; + + public SSLSupport() throws NoSuchAlgorithmException, KeyManagementException, IOException { + initSSLSocketFactoryEx(null, null, null); + } + + public SSLSupport(KeyManager[] km, TrustManager[] tm, SecureRandom random) throws NoSuchAlgorithmException, KeyManagementException, IOException { + initSSLSocketFactoryEx(km, tm, random); + } + + public SSLSupport(SSLContext ctx) throws NoSuchAlgorithmException, KeyManagementException, IOException { + initSSLSocketFactoryEx(ctx); + } + + public String[] getDefaultCipherSuites() + { + return mCiphers; + } + + public String[] getSupportedCipherSuites() + { + return mCiphers; + } + + public String[] getDefaultProtocols() + { + return mProtocols; + } + + public String[] getSupportedProtocols() + { + return mProtocols; + } + + public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException + { + SSLSocketFactory factory = mCtx.getSocketFactory(); + SSLSocket ss = (SSLSocket)factory.createSocket(s, host, port, autoClose); + + ss.setEnabledProtocols(mProtocols); + ss.setEnabledCipherSuites(mCiphers); + + return ss; + } + + public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException + { + SSLSocketFactory factory = mCtx.getSocketFactory(); + SSLSocket ss = (SSLSocket)factory.createSocket(address, port, localAddress, localPort); + + ss.setEnabledProtocols(mProtocols); + ss.setEnabledCipherSuites(mCiphers); + + return ss; + } + + public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException + { + SSLSocketFactory factory = mCtx.getSocketFactory(); + SSLSocket ss = (SSLSocket)factory.createSocket(host, port, localHost, localPort); + + ss.setEnabledProtocols(mProtocols); + ss.setEnabledCipherSuites(mCiphers); + + return ss; + } + + public Socket createSocket(InetAddress host, int port) throws IOException + { + SSLSocketFactory factory = mCtx.getSocketFactory(); + SSLSocket ss = (SSLSocket)factory.createSocket(host, port); + + ss.setEnabledProtocols(mProtocols); + ss.setEnabledCipherSuites(mCiphers); + + return ss; + } + + public Socket createSocket(String host, int port) throws IOException + { + SSLSocketFactory factory = mCtx.getSocketFactory(); + SSLSocket ss = (SSLSocket)factory.createSocket(host, port); + + ss.setEnabledProtocols(mProtocols); + ss.setEnabledCipherSuites(mCiphers); + + return ss; + } + + private void initSSLSocketFactoryEx(KeyManager[] km, TrustManager[] tm, SecureRandom random) + throws NoSuchAlgorithmException, KeyManagementException, IOException { + mCtx = SSLContext.getInstance("TLS"); + mCtx.init(km, tm, random); + + mProtocols = getProtocolList(); + mCiphers = getCipherList(); + } + + private void initSSLSocketFactoryEx(SSLContext ctx) + throws NoSuchAlgorithmException, KeyManagementException, IOException { + mCtx = ctx; + + mProtocols = getProtocolList(); + mCiphers = getCipherList(); + } + + protected String[] getProtocolList() throws IOException { + String[] preferredProtocols = { "TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3" }; + String[] availableProtocols = null; + + SSLSocket socket = null; + + try + { + SSLSocketFactory factory = mCtx.getSocketFactory(); + socket = (SSLSocket)factory.createSocket(); + + availableProtocols = socket.getSupportedProtocols(); + Arrays.sort(availableProtocols); + } + catch(Exception e) + { + return new String[]{ "TLSv1" }; + } + finally + { + if(socket != null) + socket.close(); + } + + List aa = new ArrayList(); + for(int i = 0; i < preferredProtocols.length; i++) + { + int idx = Arrays.binarySearch(availableProtocols, preferredProtocols[i]); + if(idx >= 0) + aa.add(preferredProtocols[i]); + } + + return aa.toArray(new String[0]); + } + + protected String[] getCipherList() + { + String[] preferredCiphers = { + + // *_CHACHA20_POLY1305 are 3x to 4x faster than existing cipher suites. + // http://googleonlinesecurity.blogspot.com/2014/04/speeding-up-and-strengthening-https.html + // Use them if available. Normative names can be found at (TLS spec depends on IPSec spec): + // http://tools.ietf.org/html/draft-nir-ipsecme-chacha20-poly1305-01 + // http://tools.ietf.org/html/draft-mavrogiannopoulos-chacha-tls-02 + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_SHA", + "TLS_ECDHE_RSA_WITH_CHACHA20_SHA", + + "TLS_DHE_RSA_WITH_CHACHA20_POLY1305", + "TLS_RSA_WITH_CHACHA20_POLY1305", + "TLS_DHE_RSA_WITH_CHACHA20_SHA", + "TLS_RSA_WITH_CHACHA20_SHA", + + // Done with bleeding edge, back to TLS v1.2 and below + "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384", + "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", + + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256", + + // TLS v1.0 (with some SSLv3 interop) + "TLS_DHE_RSA_WITH_AES_256_CBC_SHA384", + "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256", + "TLS_DHE_RSA_WITH_AES_128_CBC_SHA", + "TLS_DHE_DSS_WITH_AES_128_CBC_SHA", + + "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA", + "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA", + "SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA", + "SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA", + + // RSA key transport sucks, but they are needed as a fallback. + // For example, microsoft.com fails under all versions of TLS + // if they are not included. If only TLS 1.0 is available at + // the client, then google.com will fail too. TLS v1.3 is + // trying to deprecate them, so it will be interesteng to see + // what happens. + "TLS_RSA_WITH_AES_256_CBC_SHA256", + "TLS_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_AES_128_CBC_SHA256", + "TLS_RSA_WITH_AES_128_CBC_SHA" + }; + + String[] availableCiphers = null; + + try + { + SSLSocketFactory factory = mCtx.getSocketFactory(); + availableCiphers = factory.getSupportedCipherSuites(); + Arrays.sort(availableCiphers); + } + catch(Exception e) + { + return new String[] { + "TLS_DHE_DSS_WITH_AES_128_CBC_SHA", + "TLS_DHE_DSS_WITH_AES_256_CBC_SHA", + "TLS_DHE_RSA_WITH_AES_128_CBC_SHA", + "TLS_DHE_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_AES_256_CBC_SHA256", + "TLS_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_AES_128_CBC_SHA256", + "TLS_RSA_WITH_AES_128_CBC_SHA", + "TLS_EMPTY_RENEGOTIATION_INFO_SCSV" + }; + } + + List aa = new ArrayList(); + for(int i = 0; i < preferredCiphers.length; i++) + { + int idx = Arrays.binarySearch(availableCiphers, preferredCiphers[i]); + if(idx >= 0) + aa.add(preferredCiphers[i]); + } + + aa.add("TLS_EMPTY_RENEGOTIATION_INFO_SCSV"); + + return aa.toArray(new String[0]); + } +} diff --git a/src/test/java/br/com/moip/integration_tests/CustomerTest.java b/src/test/java/br/com/moip/integration_tests/CustomerTest.java new file mode 100644 index 0000000..35ef1cf --- /dev/null +++ b/src/test/java/br/com/moip/integration_tests/CustomerTest.java @@ -0,0 +1,179 @@ +package br.com.moip.integration_tests; + +import br.com.moip.Moip; +import br.com.moip.auth.Authentication; +import br.com.moip.auth.BasicAuth; +import br.com.moip.exception.UnexpectedException; +import br.com.moip.exception.ValidationException; +import br.com.moip.models.Setup; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +public class CustomerTest { + + private final static String token = "01010101010101010101010101010101"; + private final static String key = "ABABABABABABABABABABABABABABABABABABABAB"; + + private static Authentication auth = new BasicAuth(token, key); + + private Setup setup = new Setup().setAuthentication(auth).setEnvironment(Setup.Environment.SANDBOX); + + private Map customerRequestBody = new HashMap<>(); + + private Map taxDocument = new HashMap<>(); + + private Map phone = new HashMap<>(); + + private Map shippingAddress = new HashMap<>(); + + public void createCustomerTest() { + + taxDocument.put("type", "CPF"); + taxDocument.put("number", "10013390023"); + + phone.put("countryCode", "55"); + phone.put("areaCode", "11"); + phone.put("number", "22226842"); + + shippingAddress.put("city", "Sao Paulo"); + shippingAddress.put("district", "Itaim BiBi"); + shippingAddress.put("street", "Av. Brigadeiro Faria Lima"); + shippingAddress.put("streetNumber", "3064"); + shippingAddress.put("state", "SP"); + shippingAddress.put("country", "BRA"); + shippingAddress.put("zipCode", "01451001"); + + customerRequestBody.put("ownId", "ffaajjsnoafg4qq1je24"); + customerRequestBody.put("fullname", "Test Moip da Silva"); + customerRequestBody.put("email", "test.moip@mail.com"); + customerRequestBody.put("birthDate", "1980-5-10"); + customerRequestBody.put("taxDocument", taxDocument); + customerRequestBody.put("phone", phone); + customerRequestBody.put("shippingAddress", shippingAddress); + + try { + + Map responseCreation = Moip.API.customers().create(customerRequestBody, setup); + + System.out.println("create: " + responseCreation); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } + + public void addCreditCardTest () { + + Map taxDocumentHolder = new HashMap<>(); + taxDocumentHolder.put("type", "CPF"); + taxDocumentHolder.put("number", "22288866644"); + + Map phoneHolder = new HashMap<>(); + phoneHolder.put("countryCode", "55"); + phoneHolder.put("areaCode", "11"); + phoneHolder.put("number", "55552266"); + + Map holder = new HashMap<>(); + holder.put("fullname", "Test Holder Moip"); + holder.put("birthdate", "1990-10-22"); + holder.put("taxDocument", taxDocumentHolder); + holder.put("phone", phoneHolder); + + Map creditCard = new HashMap<>(); + creditCard.put("expirationMonth", "05"); + creditCard.put("expirationYear", "22"); + creditCard.put("number", "4012001037141112"); + creditCard.put("cvc", "123"); + creditCard.put("holder", holder); + + Map addCreditCard = new HashMap<>(); + addCreditCard.put("method", "CREDIT_CARD"); + addCreditCard.put("creditCard", creditCard); + + try { + + Map addCCResponse = Moip.API.customers().addCreditCard(addCreditCard, "CUS-THU3I1K97KN0", setup); + + System.out.println("add credit card: " + addCCResponse); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } + + public void deleteCreditCardTest() { + + try { + + Map deleteCreditCardResponse = Moip.API.customers().deleteCreditCard("CRC-6KGGEP72ZREJ", setup); + + System.out.println("delete credit card: " + deleteCreditCardResponse); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } + + public void getCustomerTest() { + + try { + + Map responseGet = Moip.API.customers().get("CUS-THU3I1K97KN0", setup); + + System.out.println("get: " + responseGet); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } + + public void listCustomersTest() { + + try { + + Map listResponse = Moip.API.customers().list(setup); + + System.out.println("list: " + listResponse); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } +} diff --git a/src/test/java/br/com/moip/integration_tests/NotificationPreferenceTest.java b/src/test/java/br/com/moip/integration_tests/NotificationPreferenceTest.java new file mode 100644 index 0000000..3500b86 --- /dev/null +++ b/src/test/java/br/com/moip/integration_tests/NotificationPreferenceTest.java @@ -0,0 +1,112 @@ +package br.com.moip.integration_tests; + +import br.com.moip.Moip; +import br.com.moip.auth.Authentication; +import br.com.moip.auth.BasicAuth; +import br.com.moip.exception.UnexpectedException; +import br.com.moip.exception.ValidationException; +import br.com.moip.models.Setup; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class NotificationPreferenceTest { + + private final static String token = "01010101010101010101010101010101"; + private final static String key = "ABABABABABABABABABABABABABABABABABABABAB"; + + private static Authentication auth = new BasicAuth(token, key); + private Setup setup = new Setup().setAuthentication(auth).setEnvironment(Setup.Environment.SANDBOX); + + public void createNotificationPreferenceTest() { + List events = new ArrayList(); + events.add("ORDER.*"); + events.add("PAYMENT.AUTHORIZED"); + events.add("PAYMENT.CANCELLED"); + + // Create notification preference test // + Map body = new HashMap<>(); + body.put("events", events); + body.put("target", "http://requestb.in/1dhjesw1"); + body.put("media", "WEBHOOK"); + + try { + + Map response = Moip.API.notificationPreferences().create(body, setup); + + System.out.println(response); // id: NPR-PFDKZLYIROZW + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } + + public void getNotificationPreferenceTest() { + + try { + Map response = Moip.API.notificationPreferences().get("NPR-PFDKZLYIROZW", setup); + + System.out.println(response); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } + + public void listNotificationPreferenceTest() { + + try { + + List> response = Moip.API.notificationPreferences().list(setup); + + System.out.println(response); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } + + public void removeNotificationPreferenceTest() { + + try { + + Map response = Moip.API.notificationPreferences().remove("NPR-KSF5U90I3B20", setup); + + System.out.println(response); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } +} diff --git a/src/test/java/br/com/moip/integration_tests/OrderTest.java b/src/test/java/br/com/moip/integration_tests/OrderTest.java new file mode 100644 index 0000000..5d59a54 --- /dev/null +++ b/src/test/java/br/com/moip/integration_tests/OrderTest.java @@ -0,0 +1,138 @@ +package br.com.moip.integration_tests; + +import br.com.moip.Moip; +import br.com.moip.auth.Authentication; +import br.com.moip.auth.BasicAuth; +import br.com.moip.exception.UnexpectedException; +import br.com.moip.exception.ValidationException; +import br.com.moip.models.Setup; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class OrderTest { + + private final static String token = "01010101010101010101010101010101"; + private final static String key = "ABABABABABABABABABABABABABABABABABABABAB"; + + private static Authentication auth = new BasicAuth(token, key); + + private Setup setup = new Setup().setAuthentication(auth).setEnvironment(Setup.Environment.SANDBOX); + + public void createOrderTest() { + + Map subtotals = new HashMap<>(); + subtotals.put("shipping", 15000); + + Map amount = new HashMap<>(); + amount.put("currency", "BRL"); + amount.put("subtotals", subtotals); + + Map product1 = new HashMap<>(); + product1.put("product", "Product Description"); + product1.put("category", "CLOTHING"); + product1.put("quantity", 2); + product1.put("detail", "Anakin's Light Saber"); + product1.put("price", 1000000); + + Map product2 = new HashMap<>(); + product2.put("product", "Product 2 Description"); + product2.put("category", "SCIENCE_AND_LABORATORY"); + product2.put("quantity", 5); + product2.put("detail", "Pym particles"); + product2.put("price", 24500000); + + List> items = new ArrayList<>(); + items.add(product1); + items.add(product2); + + Map customer = new HashMap<>(); + customer.put("id", "CUS-XXOBPZ80QLYP"); + + Map orderBody = new HashMap<>(); + orderBody.put("ownId", "asagasfg121asd31as"); + orderBody.put("amount", amount); + orderBody.put("items", items); + orderBody.put("customer", customer); + + try { + + Map order = Moip.API.orders().create(orderBody, setup); + + System.out.println("create: " + order); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } + + public void getOrderTest() { + + try { + + Map responseGet = Moip.API.orders().get("ORD-LS7CZHW90N3Y", setup); + + System.out.println("get: " + responseGet); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } + + public void listOrdersTest() { + + try { + + Map responseList = Moip.API.orders().list(setup); + + System.out.println("list: " + responseList); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } + + public void listOrderPayments() { + + try { + + Map responseListOrderPayments = Moip.API.orders().listOrderPayments("ORD-S36MOUQ97AP6", setup); + + System.out.println("list of order payments: " + responseListOrderPayments); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } +} diff --git a/src/test/java/br/com/moip/integration_tests/PaymentTest.java b/src/test/java/br/com/moip/integration_tests/PaymentTest.java new file mode 100644 index 0000000..c87552c --- /dev/null +++ b/src/test/java/br/com/moip/integration_tests/PaymentTest.java @@ -0,0 +1,211 @@ +package br.com.moip.integration_tests; + +import br.com.moip.Moip; +import br.com.moip.auth.Authentication; +import br.com.moip.auth.BasicAuth; +import br.com.moip.exception.UnexpectedException; +import br.com.moip.exception.ValidationException; +import br.com.moip.models.Setup; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +public class PaymentTest { + + private final static String token = "01010101010101010101010101010101"; + private final static String key = "ABABABABABABABABABABABABABABABABABABABAB"; + + private static Authentication auth = new BasicAuth(token, key); + + private Setup setup = new Setup().setAuthentication(auth).setEnvironment(Setup.Environment.SANDBOX); + + public void createPaymentTest() { + + String hash = "CCbe2TVHIsINX+v+bVPP0KSKWfXs6AtrJlHznaSdTgmvNFOvsalZ7pFgoddc3fH7vEdpxCa55ed1DoNIz" + + "WWUo3+7KLQgV0Gi/ux0RShBiNzB0wiFf+OBef9x7b3IgcdulZqdNGn84AvGInJ9r6a2iZ8kY0xQ1xONOod5rVku" + + "GDvNgVVOIB7Zs5In9j3f4TENRU7aqx63srT3UPP+wsQBMNJ4wQturogjZBhDIQqEm2sC9Zzx+E8zP/aZ+YBF9O+" + + "nfeofF4S2E9bs4A9neWCivntqwENX0O755NamWX/up2MbyHu8N+cm493RrbUT76jibB0RyyT9nkKpSOuJIGU8vA=="; + + Map taxDocument = new HashMap<>(); + taxDocument.put("type", "CPF"); + taxDocument.put("number", "33333333333"); + + Map phone = new HashMap<>(); + phone.put("countryCode", "55"); + phone.put("areaCode", "11"); + phone.put("number", "66778899"); + + Map holder = new HashMap<>(); + holder.put("fullname", "Portador Teste Moip"); + holder.put("birthdate", "1988-12-30"); + holder.put("taxDocument", taxDocument); + holder.put("phone", phone); + + Map creditCard = new HashMap<>(); + creditCard.put("hash", hash); + creditCard.put("store", false); + creditCard.put("holder", holder); + + Map fundingInstrument = new HashMap<>(); + fundingInstrument.put("method", "CREDIT_CARD"); + fundingInstrument.put("creditCard", creditCard); + + Map paymentBody = new HashMap<>(); + paymentBody.put("installmentCount", 1); + paymentBody.put("statementDescriptor", "minhaLoja.com"); + paymentBody.put("fundingInstrument", fundingInstrument); + + try { + + Map payResponse = Moip.API.payments().pay(paymentBody, "ORD-WIBIQXIME7U7", setup); + + System.out.println("create: " + payResponse); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } + + public void createPreAuthorizedTest() { + + String hash = "CCbe2TVHIsINX+v+bVPP0KSKWfXs6AtrJlHznaSdTgmvNFOvsalZ7pFgoddc3fH7vEdpxCa55ed1DoNIz" + + "WWUo3+7KLQgV0Gi/ux0RShBiNzB0wiFf+OBef9x7b3IgcdulZqdNGn84AvGInJ9r6a2iZ8kY0xQ1xONOod5rVku" + + "GDvNgVVOIB7Zs5In9j3f4TENRU7aqx63srT3UPP+wsQBMNJ4wQturogjZBhDIQqEm2sC9Zzx+E8zP/aZ+YBF9O+" + + "nfeofF4S2E9bs4A9neWCivntqwENX0O755NamWX/up2MbyHu8N+cm493RrbUT76jibB0RyyT9nkKpSOuJIGU8vA=="; + + Map taxDocument = new HashMap<>(); + taxDocument.put("type", "CPF"); + taxDocument.put("number", "33333333333"); + + Map phone = new HashMap<>(); + phone.put("countryCode", "55"); + phone.put("areaCode", "11"); + phone.put("number", "66778899"); + + Map holder = new HashMap<>(); + holder.put("fullname", "Portador Teste Moip"); + holder.put("birthdate", "1988-12-30"); + holder.put("taxDocument", taxDocument); + holder.put("phone", phone); + + Map creditCard = new HashMap<>(); + creditCard.put("hash", hash); + creditCard.put("store", false); + creditCard.put("holder", holder); + + Map fundingInstrument = new HashMap<>(); + fundingInstrument.put("method", "CREDIT_CARD"); + fundingInstrument.put("creditCard", creditCard); + + Map paymentBody = new HashMap<>(); + paymentBody.put("installmentCount", 1); + paymentBody.put("statementDescriptor", "minhaLoja.com"); + paymentBody.put("fundingInstrument", fundingInstrument); + paymentBody.put("delayCapture", true); + + try { + + Map preAuthorized = Moip.API.payments().pay(paymentBody, "ORD-S4AAX3GYUDWR", setup); + + System.out.println("pre-authorized: " + preAuthorized); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } + + public void capturePreAuthorizedTest() { + + try { + + Map convert = Moip.API.payments().capturePreAuthorized("PAY-CUB8GVW4HGR7", setup); + + System.out.println("capture: " + convert); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } + + public void cancelPreAuthorizedTest() { + + try { + + Map cancel = Moip.API.payments().cancelPreAuthorized("PAY-I2RXHXRGJ6GO", setup); + + System.out.println("cancel: " + cancel); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } + + public void getPaymentTest() { + + try { + + Map getResponse = Moip.API.payments().get("PAY-I2RXHXRGJ6GO", setup); + + System.out.println("get: " + getResponse); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } + + public void authorizePaymentTest() { + + try { + + Map authorizeResponse = Moip.API.payments().authorize("PAY-7VC4M6K4IVG1", 9500, setup); + + System.out.println("authorize: " + authorizeResponse); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } +} diff --git a/src/test/java/br/com/moip/integration_tests/RefundTest.java b/src/test/java/br/com/moip/integration_tests/RefundTest.java new file mode 100644 index 0000000..3ad8f98 --- /dev/null +++ b/src/test/java/br/com/moip/integration_tests/RefundTest.java @@ -0,0 +1,142 @@ +package br.com.moip.integration_tests; + +import br.com.moip.Moip; +import br.com.moip.auth.Authentication; +import br.com.moip.auth.BasicAuth; +import br.com.moip.auth.OAuth; +import br.com.moip.exception.UnexpectedException; +import br.com.moip.exception.ValidationException; +import br.com.moip.models.Setup; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +public class RefundTest { + + private final static String token = "01010101010101010101010101010101"; + private final static String key = "ABABABABABABABABABABABABABABABABABABABAB"; + + private static Authentication auth = new BasicAuth(token, key); + + private static Authentication oAuth = new OAuth("8833c9eb036543b6b0acd685a76c9ead_v2"); + + private Setup setup = new Setup().setAuthentication(oAuth).setEnvironment(Setup.Environment.SANDBOX); + + public void refundPaymentTest() { + + try { + + Map refundCC = Moip.API.refunds().refundPayment("PAY-E9DCD2A51HK5", setup); + + System.out.println(refundCC); + + } catch (ValidationException e) { + System.out.println("Validation!"); + e.getErrors(); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } + + public void refundBankAccountTest() { + + Map taxDocument = new HashMap<>(); + taxDocument.put("type", "CPF"); + taxDocument.put("number", "57390209674"); + + + Map holder = new HashMap<>(); + holder.put("fullname", "Jose Silva"); + holder.put("taxDocument", taxDocument); + + Map bankAccount = new HashMap<>(); + bankAccount.put("type", "CHECKING"); + bankAccount.put("bankNumber", "001"); + bankAccount.put("agencyNumber", 4444444); + bankAccount.put("agencyCheckNumber", 2); + bankAccount.put("accountNumber", 1234); + bankAccount.put("accountCheckNumber", 1); + bankAccount.put("holder", holder); + + Map refundingInstrument = new HashMap<>(); + refundingInstrument.put("method", "BANK_ACCOUNT"); + refundingInstrument.put("bankAccount", bankAccount); + + // Refund order bank account // + Map refundBankAccountBody = new HashMap<>(); + refundBankAccountBody.put("refundingInstrument", refundingInstrument); + + try { + + Map refundBankAccount = Moip.API.refunds().refundOrder(refundBankAccountBody, "ORD-477LLUMK5J71", setup); + + System.out.println(refundBankAccount); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } + + public void refundMoipAccountTest() { + + Map moipAccount = new HashMap<>(); + moipAccount.put("id", "MPA-273HG64574Y7"); + + + Map refundingInstrument = new HashMap<>(); + refundingInstrument.put("method", "MOIP_ACCOUNT"); + refundingInstrument.put("moipAccount", moipAccount); + + // Partial refund payment Moip account test // + Map refundMoipAccountBody = new HashMap<>(); + refundMoipAccountBody.put("amount", "500"); + refundMoipAccountBody.put("refundingInstrument", refundingInstrument); + + try { + + Map refundMoipAccount = Moip.API.refunds().refundPayment(refundMoipAccountBody, "PAY-E9DCD2A51HK5", setup); + + System.out.println(refundMoipAccount); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } + + public void getRefundTest() { + Map get = Moip.API.refunds().get("REF-LA2XBT8UWNK5", setup); + + System.out.println(get); + } + + public void listPaymentRefundsTest() { + Map listPaymentRefund = Moip.API.refunds().listPaymentRefunds("PAY-E9DCD2A51HK5", setup); + + System.out.println(listPaymentRefund); + } + + public void listOrderRefundsTest() { + Map listOrderRefunds = Moip.API.refunds().listOrderRefunds("ORD-477LLUMK5J71", setup); + + System.out.println(listOrderRefunds); + } +} diff --git a/src/test/java/br/com/moip/integration_tests/WebhookTest.java b/src/test/java/br/com/moip/integration_tests/WebhookTest.java new file mode 100644 index 0000000..b5ded88 --- /dev/null +++ b/src/test/java/br/com/moip/integration_tests/WebhookTest.java @@ -0,0 +1,60 @@ +package br.com.moip.integration_tests; + +import br.com.moip.Moip; +import br.com.moip.auth.Authentication; +import br.com.moip.auth.BasicAuth; +import br.com.moip.exception.UnexpectedException; +import br.com.moip.exception.ValidationException; +import br.com.moip.models.Setup; +import org.junit.Test; + +import java.util.Map; + +public class WebhookTest { + + private final static String token = "01010101010101010101010101010101"; + private final static String key = "ABABABABABABABABABABABABABABABABABABABAB"; + + private static Authentication auth = new BasicAuth(token, key); + private Setup setup = new Setup().setAuthentication(auth).setEnvironment(Setup.Environment.SANDBOX); + + public void getWebhookTest() { + + try { + + Map response = Moip.API.webhooks().get("ORD-RVOF7BDJLWA8", setup); + + System.out.println(response); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } + + public void listWebhookTest() { + + try { + + Map response = Moip.API.webhooks().list(setup); + + System.out.println(response); + + } catch (ValidationException e) { + System.out.println("Validation!"); + System.out.println(e.getErrors().getErrors()); + System.out.println(e.getMessage()); + e.getStackTrace(); + } catch (UnexpectedException e) { + System.out.println("Unexpected!"); + System.out.println(e); + e.getStackTrace(); + } + } +} diff --git a/src/test/java/br/com/moip/unit_tests/CustomerTest.java b/src/test/java/br/com/moip/unit_tests/CustomerTest.java new file mode 100644 index 0000000..7643d4f --- /dev/null +++ b/src/test/java/br/com/moip/unit_tests/CustomerTest.java @@ -0,0 +1,221 @@ +package br.com.moip.unit_tests; + +import br.com.moip.Moip; +import br.com.moip.models.Setup; +import br.com.moip.unit_tests.setup.SetupFactory; +import br.com.moip.utilities.Parser; +import com.rodrigosaito.mockwebserver.player.Play; +import com.rodrigosaito.mockwebserver.player.Player; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + +public class CustomerTest { + + @Rule + public Player player = new Player(); + private Setup setup; + private Map body; + private Parser parser; + + @Before + public void initialize() { + this.body = new HashMap<>(); + this.setup = new SetupFactory().setup(player.getURL("").toString()); + this.parser = new Parser(); + } + + @Play("customer/create") + @Test + public void createCustomer() { + Map customer = Moip.API.customers().create(body, setup); + + assertEquals("CUS-Z83J8G3EMLIT", customer.get("id")); + assertEquals("moip_create_customer_unit_test", customer.get("ownId")); + assertEquals("SDK Java", customer.get("fullname")); + assertEquals("2018-07-11T18:26:51.000-03", customer.get("createdAt")); + assertEquals("1980-05-10", customer.get("birthDate")); + assertEquals("sdk.java@moip.com.br", customer.get("email")); + + Map phone = parser.objectToMap(customer.get("phone")); + assertEquals("55", phone.get("countryCode")); + assertEquals("11", phone.get("areaCode")); + assertEquals("22226842", phone.get("number")); + + Map taxDocument = parser.objectToMap(customer.get("taxDocument")); + assertEquals("CPF", taxDocument.get("type")); + assertEquals("10013390023", taxDocument.get("number")); + + Map shippingAddress = parser.objectToMap(customer.get("shippingAddress")); + assertEquals("01451001", shippingAddress.get("zipCode")); + assertEquals("Avenida Brigadeiro Faria Lima", shippingAddress.get("street")); + assertEquals("3064", shippingAddress.get("streetNumber")); + assertEquals("São Paulo", shippingAddress.get("city")); + assertEquals("Itaim Bibi", shippingAddress.get("district")); + assertEquals("SP", shippingAddress.get("state")); + assertEquals("BRA", shippingAddress.get("country")); + + Map links = parser.objectToMap(customer.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/customers/CUS-Z83J8G3EMLIT", self.get("href")); + + Map hostedAccount = parser.objectToMap(links.get("hostedAccount")); + assertEquals("https://hostedaccount-sandbox.moip.com.br?token=541a137d-f94a-4ab6-9e2b-40df67309c1b&id=CUS-Z83J8G3EMLIT&mpa=MPA-CULBBYHD11", hostedAccount.get("redirectHref")); + } + + @Play("customer/create_with_funding_instrument") + @Test + public void createCustomerWithFundingInstrumentTest() { + + Map customer = Moip.API.customers().create(body, setup); + + assertEquals("CUS-35TX8MWZ6SVX", customer.get("id").toString()); + assertEquals("moip_create_customer_unit_test", customer.get("ownId")); + assertEquals("SDK Java", customer.get("fullname")); + assertEquals("2018-07-11T11:57:22.000-03", customer.get("createdAt")); + assertEquals("1980-05-10", customer.get("birthDate")); + assertEquals("sdk.java@moip.com.br", customer.get("email")); + + Map fundingInstrument = parser.objectToMap(customer.get("fundingInstrument")); + Map creditCard = parser.objectToMap(fundingInstrument.get("creditCard")); + assertEquals("CRC-7GKFB3S2R8SS", creditCard.get("id")); + assertEquals("ELO", creditCard.get("brand")); + assertEquals("636297", creditCard.get("first6")); + assertEquals("7013", creditCard.get("last4")); + assertEquals(true, creditCard.get("store")); + + assertEquals("CREDIT_CARD", fundingInstrument.get("method")); + + Map phone = parser.objectToMap(customer.get("phone")); + assertEquals("55", phone.get("countryCode")); + assertEquals("11", phone.get("areaCode")); + assertEquals("22226842", phone.get("number")); + + Map taxDocument = parser.objectToMap(customer.get("taxDocument")); + assertEquals("CPF", taxDocument.get("type")); + assertEquals("10013390023", taxDocument.get("number")); + + Map shippingAddress = parser.objectToMap(customer.get("shippingAddress")); + assertEquals("01451001", shippingAddress.get("zipCode")); + assertEquals("Avenida Brigadeiro Faria Lima", shippingAddress.get("street")); + assertEquals("3064", shippingAddress.get("streetNumber")); + assertEquals("São Paulo", shippingAddress.get("city")); + assertEquals("Itaim Bibi", shippingAddress.get("district")); + assertEquals("SP", shippingAddress.get("state")); + assertEquals("BRA", shippingAddress.get("country")); + + Map links = parser.objectToMap(customer.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/customers/CUS-35TX8MWZ6SVX", self.get("href")); + + Map hostedAccount = parser.objectToMap(links.get("hostedAccount")); + assertEquals("https://hostedaccount-sandbox.moip.com.br?token=69ec54c3-c6a1-4f04-953b-af7d0f0fbee0&id=CUS-35TX8MWZ6SVX&mpa=MPA-CULBBYHD11", hostedAccount.get("redirectHref")); + } + + @Play("customer/add_credit_card") + @Test + public void addCreditCardTest() { + + Map fundingInstrument = Moip.API.customers().addCreditCard(body, "CUS-Z83J8G3EMLIT", setup); + + Map creditCard = parser.objectToMap(fundingInstrument.get("creditCard")); + assertEquals("CRC-9Y3RUBPCR30N", creditCard.get("id")); + assertEquals("VISA", creditCard.get("brand")); + assertEquals("401200", creditCard.get("first6")); + assertEquals("1112", creditCard.get("last4")); + assertEquals(true, creditCard.get("store")); + + Map card = parser.objectToMap(fundingInstrument.get("card")); + assertEquals("VISA", card.get("brand")); + assertEquals(true, card.get("store")); + + assertEquals(false, fundingInstrument.get("isPresential")); + assertEquals("CREDIT_CARD", fundingInstrument.get("method")); + } + + @Play("customer/get") + @Test + public void getCustomerTest() { + + Map customer = Moip.API.customers().get("CUS-Z83J8G3EMLIT", setup); + + assertEquals("CUS-Z83J8G3EMLIT", customer.get("id")); + assertEquals("moip_create_customer_unit_test", customer.get("ownId")); + assertEquals("SDK Java", customer.get("fullname")); + assertEquals("2018-07-11T18:26:51.000-03", customer.get("createdAt")); + assertEquals("1980-05-10", customer.get("birthDate")); + assertEquals("sdk.java@moip.com.br", customer.get("email")); + + Map phone = parser.objectToMap(customer.get("phone")); + assertEquals("55", phone.get("countryCode")); + assertEquals("11", phone.get("areaCode")); + assertEquals("22226842", phone.get("number")); + + Map taxDocument = parser.objectToMap(customer.get("taxDocument")); + assertEquals("CPF", taxDocument.get("type")); + assertEquals("10013390023", taxDocument.get("number")); + + Map shippingAddress = parser.objectToMap(customer.get("shippingAddress")); + assertEquals("01451001", shippingAddress.get("zipCode")); + assertEquals("Avenida Brigadeiro Faria Lima", shippingAddress.get("street")); + assertEquals("3064", shippingAddress.get("streetNumber")); + assertEquals("São Paulo", shippingAddress.get("city")); + assertEquals("Itaim Bibi", shippingAddress.get("district")); + assertEquals("SP", shippingAddress.get("state")); + assertEquals("BRA", shippingAddress.get("country")); + + Map links = parser.objectToMap(customer.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/customers/CUS-Z83J8G3EMLIT", self.get("href")); + + Map hostedAccount = parser.objectToMap(links.get("hostedAccount")); + assertEquals("https://hostedaccount-sandbox.moip.com.br?token=541a137d-f94a-4ab6-9e2b-40df67309c1b&id=CUS-Z83J8G3EMLIT&mpa=MPA-CULBBYHD11", hostedAccount.get("redirectHref")); + } + + @Play("customer/list") + @Test + public void listCustomersTest() { + + Map customersList = Moip.API.customers().list(setup); + + // Parse Object to Map List + List> customers = parser.objectToList(customersList.get("customers")); + + // customers[0] --- + assertEquals("CUS-GBQJHCRKF2ZJ", customers.get(0).get("id")); + + Map fundingInstrument0 = parser.objectToMap(customers.get(0).get("fundingInstrument")); + Map creditCard0 = parser.objectToMap(fundingInstrument0.get("creditCard")); + assertEquals("CRC-GX8ZN1HLBHU9", creditCard0.get("id")); + assertEquals("VISA", creditCard0.get("brand")); + assertEquals("407302", creditCard0.get("first6")); + assertEquals("0002", creditCard0.get("last4")); + + // customer[1] --- + assertEquals("CUS-U9JX31DJSX6O", customers.get(1).get("id")); + assertEquals("r@mail.co", customers.get(1).get("email")); + + Map fundingInstrument1 = parser.objectToMap(customers.get(1).get("fundingInstrument")); + Map creditCard1 = parser.objectToMap(fundingInstrument1.get("creditCard")); + assertEquals("CRC-QEQ0ZEC1WFCP", creditCard1.get("id")); + + Map shippingAddress1 = parser.objectToMap(customers.get(1).get("billingAddress")); + assertEquals("13030-290", shippingAddress1.get("zipCode")); + + // customers[2] --- + assertEquals("CUS-J44P8K7QLVLS", customers.get(2).get("id")); + assertEquals("Ray Batista", customers.get(2).get("fullname")); + + Map fundingInstrument2 = parser.objectToMap(customers.get(2).get("fundingInstrument")); + Map creditCard2 = parser.objectToMap(fundingInstrument2.get("creditCard")); + assertEquals("CRC-VWO246R7BXKX", creditCard2.get("id")); + assertEquals("407302", creditCard2.get("first6")); + assertEquals(true, creditCard2.get("store")); + } +} diff --git a/src/test/java/br/com/moip/unit_tests/NotificationTest.java b/src/test/java/br/com/moip/unit_tests/NotificationTest.java new file mode 100644 index 0000000..b50efdd --- /dev/null +++ b/src/test/java/br/com/moip/unit_tests/NotificationTest.java @@ -0,0 +1,237 @@ +package br.com.moip.unit_tests; + +import br.com.moip.Moip; +import br.com.moip.models.Setup; +import br.com.moip.unit_tests.setup.SetupFactory; +import br.com.moip.utilities.Parser; +import com.rodrigosaito.mockwebserver.player.Play; +import com.rodrigosaito.mockwebserver.player.Player; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class NotificationTest { + + @Rule + public Player player = new Player(); + private Setup setup; + private Map body; + private Parser parser; + + @Before + public void initialize() { + this.body = new HashMap<>(); + this.setup = new SetupFactory().setup(player.getURL("").toString()); + this.parser = new Parser(); + } + + @Play("notification/create_notification_preferences") + @Test + public void createNotificationPreferenceTest() { + + Map notification = Moip.API.notificationPreferences().create(body, setup); + + List events = parser.objectToList(notification.get("events")); + assertEquals("ORDER.*", events.get(0)); + assertEquals("PAYMENT.AUTHORIZED", events.get(1)); + assertEquals("PAYMENT.CANCELLED", events.get(2)); + + assertEquals("http://requestb.in/1dhjesw1", notification.get("target")); + assertEquals("WEBHOOK", notification.get("media")); + assertEquals("1457cbc9e2ab4bc7a62ab24951a9a878", notification.get("token")); + assertEquals("NPR-LQCZEI6Q7I1G", notification.get("id")); + } + + @Play("notification/get_notification_preferences") + @Test + public void getNotificationPreferenceTest() { + + Map notification = Moip.API.notificationPreferences().get("NPR-LQCZEI6Q7I1G", setup); + + List events = parser.objectToList(notification.get("events")); + assertEquals("ORDER.*", events.get(0)); + assertEquals("PAYMENT.AUTHORIZED", events.get(1)); + assertEquals("PAYMENT.CANCELLED", events.get(2)); + + assertEquals("http://requestb.in/1dhjesw1", notification.get("target")); + assertEquals("WEBHOOK", notification.get("media")); + assertEquals("1457cbc9e2ab4bc7a62ab24951a9a878", notification.get("token")); + assertEquals("NPR-LQCZEI6Q7I1G", notification.get("id")); + } + + @Play("notification/list_notification_preferences") + @Test + public void listNotificationPreferencesTest() { + + List> listPreferences = Moip.API.notificationPreferences().list(setup); + + // listPreferences[0] + List events0 = parser.objectToList(listPreferences.get(0).get("events")); + assertEquals("ORDER.*", events0.get(0)); + assertEquals("PAYMENT.AUTHORIZED", events0.get(1)); + assertEquals("PAYMENT.CANCELLED", events0.get(2)); + + assertEquals("http://my.uri/0", listPreferences.get(0).get("target")); + assertEquals("WEBHOOK", listPreferences.get(0).get("media")); + assertEquals("63c351458ccc4967aaa84f66a79c2be6", listPreferences.get(0).get("token")); + assertEquals("NPR-O019G1CWTFV5", listPreferences.get(0).get("id")); + + // listPreferences[1] + List events1 = parser.objectToList(listPreferences.get(1).get("events")); + assertEquals("ORDER.*", events1.get(0)); + assertEquals("PAYMENT.AUTHORIZED", events1.get(1)); + assertEquals("PAYMENT.CANCELLED", events1.get(2)); + + assertEquals("http://my.uri/1", listPreferences.get(1).get("target")); + assertEquals("WEBHOOK", listPreferences.get(1).get("media")); + assertEquals("688e2f2b75df4b968cad7d2b5c9c02d6", listPreferences.get(1).get("token")); + assertEquals("NPR-AV7URX6E5OUF", listPreferences.get(1).get("id")); + + // listPreferences[2] + List events2 = parser.objectToList(listPreferences.get(2).get("events")); + assertEquals("ORDER.*", events2.get(0)); + assertEquals("PAYMENT.AUTHORIZED", events2.get(1)); + assertEquals("PAYMENT.CANCELLED", events2.get(2)); + + assertEquals("http://my.uri/2", listPreferences.get(2).get("target")); + assertEquals("WEBHOOK", listPreferences.get(2).get("media")); + assertEquals("19160e43b6df4f58b31bfe57d291cb8a", listPreferences.get(2).get("token")); + assertEquals("NPR-KCC2M2IYRQXJ", listPreferences.get(2).get("id")); + + // listPreferences[3] + List events3 = parser.objectToList(listPreferences.get(3).get("events")); + assertEquals("ORDER.*", events3.get(0)); + assertEquals("PAYMENT.AUTHORIZED", events3.get(1)); + assertEquals("PAYMENT.CANCELLED", events3.get(2)); + + assertEquals("http://my.uri/3", listPreferences.get(3).get("target")); + assertEquals("WEBHOOK", listPreferences.get(3).get("media")); + assertEquals("a07451ff754449d18fedf60c6582e130", listPreferences.get(3).get("token")); + assertEquals("NPR-GFD5Q9JP0JHO", listPreferences.get(3).get("id")); + + // listPreferences[4] + List events4 = parser.objectToList(listPreferences.get(4).get("events")); + assertEquals("ORDER.*", events4.get(0)); + assertEquals("PAYMENT.AUTHORIZED", events4.get(1)); + assertEquals("PAYMENT.CANCELLED", events4.get(2)); + + assertEquals("http://my.uri/4", listPreferences.get(4).get("target")); + assertEquals("WEBHOOK", listPreferences.get(4).get("media")); + assertEquals("dc5c0470a44145baad470693b1ac7416", listPreferences.get(4).get("token")); + assertEquals("NPR-F0TNENDS2PW0", listPreferences.get(4).get("id")); + } + + @Play("notification/remove_notification_preferences") + @Test + public void deleteNotificationPreferenceTest() { + + Map removePreference = Moip.API.notificationPreferences().remove("NPR-KCC2M2IYRQXJ", setup); + + assertTrue(removePreference.isEmpty()); + } + + @Play("notification/get_webhooks") + @Test + public void getWebhooksTest() { + + Map getWebhooks = Moip.API.webhooks().get("ORD-W496X7T9FVGZ", setup); + + List> webhooks = parser.objectToList(getWebhooks.get("webhooks")); + + // webhooks[0] + assertEquals("ORD-W496X7T9FVGZ", webhooks.get(0).get("resourceId")); + assertEquals("ORDER.PAID", webhooks.get(0).get("event")); + assertEquals("https://requestb.in/16pw5ncfjleofweojfewbl1", webhooks.get(0).get("url")); + assertEquals("FAILED", webhooks.get(0).get("status")); + assertEquals("EVE-VP3PTS0QP294", webhooks.get(0).get("id")); + assertEquals("2018-07-17T18:11:07.473Z", webhooks.get(0).get("sentAt")); + + // webhooks[1] + assertEquals("ORD-W496X7T9FVGZ", webhooks.get(1).get("resourceId")); + assertEquals("ORDER.WAITING", webhooks.get(1).get("event")); + assertEquals("https://requestb.in/16pw5ncfjleofweojfewbl1", webhooks.get(1).get("url")); + assertEquals("FAILED", webhooks.get(1).get("status")); + assertEquals("EVE-YA8Z6XXDZJCY", webhooks.get(1).get("id")); + assertEquals("2018-07-17T18:11:06.047Z", webhooks.get(1).get("sentAt")); + + // webhooks[2] + assertEquals("ORD-W496X7T9FVGZ", webhooks.get(2).get("resourceId")); + assertEquals("ORDER.CREATED", webhooks.get(2).get("event")); + assertEquals("https://requestb.in/16pw5ncfjleofweojfewbl1", webhooks.get(2).get("url")); + assertEquals("FAILED", webhooks.get(2).get("status")); + assertEquals("EVE-FXFWBXTD4CBM", webhooks.get(2).get("id")); + assertEquals("2018-07-17T18:11:02.628Z", webhooks.get(2).get("sentAt")); + + // webhooks[3] + assertEquals("ORD-W496X7T9FVGZ", webhooks.get(3).get("resourceId")); + assertEquals("ORDER.PAID", webhooks.get(3).get("event")); + assertEquals("https://requestb.in/16pw5ncfjleofweojfewbl1", webhooks.get(3).get("url")); + assertEquals("FAILED", webhooks.get(3).get("status")); + assertEquals("EVE-Z0H3OSCO6CG4", webhooks.get(3).get("id")); + assertEquals("2018-07-17T18:10:57.162Z", webhooks.get(3).get("sentAt")); + + // webhooks[4] + assertEquals("ORD-W496X7T9FVGZ", webhooks.get(4).get("resourceId")); + assertEquals("ORDER.WAITING", webhooks.get(4).get("event")); + assertEquals("https://requestb.in/16pw5ncfjleofweojfewbl1", webhooks.get(4).get("url")); + assertEquals("FAILED", webhooks.get(4).get("status")); + assertEquals("EVE-BM1MIMKDV6VR", webhooks.get(4).get("id")); + assertEquals("2018-07-17T18:10:55.716Z", webhooks.get(4).get("sentAt")); + + // webhooks[5] + assertEquals("ORD-W496X7T9FVGZ", webhooks.get(5).get("resourceId")); + assertEquals("ORDER.CREATED", webhooks.get(5).get("event")); + assertEquals("https://requestb.in/16pw5ncfjleofweojfewbl1", webhooks.get(5).get("url")); + assertEquals("FAILED", webhooks.get(5).get("status")); + assertEquals("EVE-HR1TKRMBBV6P", webhooks.get(5).get("id")); + assertEquals("2018-07-17T18:10:52.241Z", webhooks.get(5).get("sentAt")); + } + + @Play("notification/list_webhooks") + @Test + public void listWebhooksTest() { + + Map listWebhooks = Moip.API.webhooks().list(setup); + + List> webhooks = parser.objectToList(listWebhooks.get("webhooks")); + + // webhooks[0] + assertEquals("ORD-W496X7T9FVGZ", webhooks.get(0).get("resourceId")); + assertEquals("ORDER.PAID", webhooks.get(0).get("event")); + assertEquals("https://requestb.in/16pw5ncfjleofweojfewbl1", webhooks.get(0).get("url")); + assertEquals("FAILED", webhooks.get(0).get("status")); + assertEquals("EVE-VP3PTS0QP294", webhooks.get(0).get("id")); + assertEquals("2018-07-17T18:11:07.473Z", webhooks.get(0).get("sentAt")); + + // webhooks[1] + assertEquals("PAY-NFSY35SXVCCN", webhooks.get(1).get("resourceId")); + assertEquals("PAYMENT.AUTHORIZED", webhooks.get(1).get("event")); + assertEquals("https://requestb.in/16pw5ncfjleofweojfewbl1", webhooks.get(1).get("url")); + assertEquals("FAILED", webhooks.get(1).get("status")); + assertEquals("EVE-O8EC0FBUBBAP", webhooks.get(1).get("id")); + assertEquals("2018-07-17T18:11:07.303Z", webhooks.get(1).get("sentAt")); + + // webhooks[2] + assertEquals("PAY-NFSY35SXVCCN", webhooks.get(2).get("resourceId")); + assertEquals("PAYMENT.IN_ANALYSIS", webhooks.get(2).get("event")); + assertEquals("https://requestb.in/16pw5ncfjleofweojfewbl1", webhooks.get(2).get("url")); + assertEquals("FAILED", webhooks.get(2).get("status")); + assertEquals("EVE-6QJN2PWF6SOD", webhooks.get(2).get("id")); + assertEquals("2018-07-17T18:11:06.228Z", webhooks.get(2).get("sentAt")); + + // webhooks[3] + assertEquals("ORD-W496X7T9FVGZ", webhooks.get(3).get("resourceId")); + assertEquals("ORDER.WAITING", webhooks.get(3).get("event")); + assertEquals("https://requestb.in/16pw5ncfjleofweojfewbl1", webhooks.get(3).get("url")); + assertEquals("FAILED", webhooks.get(3).get("status")); + assertEquals("EVE-YA8Z6XXDZJCY", webhooks.get(3).get("id")); + assertEquals("2018-07-17T18:11:06.047Z", webhooks.get(3).get("sentAt")); + } +} diff --git a/src/test/java/br/com/moip/unit_tests/OrderTest.java b/src/test/java/br/com/moip/unit_tests/OrderTest.java new file mode 100644 index 0000000..84d950c --- /dev/null +++ b/src/test/java/br/com/moip/unit_tests/OrderTest.java @@ -0,0 +1,510 @@ +package br.com.moip.unit_tests; + +import br.com.moip.Moip; +import br.com.moip.models.Setup; +import br.com.moip.unit_tests.setup.SetupFactory; +import br.com.moip.utilities.Parser; +import com.rodrigosaito.mockwebserver.player.Play; +import com.rodrigosaito.mockwebserver.player.Player; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +public class OrderTest { + + @Rule + public Player player = new Player(); + private Setup setup; + private Map body; + private Parser parser; + + @Before + public void initialize() { + this.body = new HashMap<>(); + this.setup = new SetupFactory().setup(player.getURL("").toString()); + this.parser = new Parser(); + } + + @Play("order/create") + @Test + public void createOrderTest() { + + Map order = Moip.API.orders().create(body, setup); + + assertEquals("ORD-A4HGZXSXARIV", order.get("id")); + assertEquals("my_order_ownId", order.get("ownId")); + assertEquals("CREATED", order.get("status")); + assertEquals("V2", order.get("platform")); + assertEquals("2018-07-12T14:53:46.683-03", order.get("createdAt")); + assertEquals("2018-07-12T14:53:46.683-03", order.get("updatedAt")); + + Map amount = parser.objectToMap(order.get("amount")); + assertEquals(0, amount.get("paid")); + assertEquals(11000, amount.get("total")); + assertEquals(0, amount.get("fees")); + assertEquals(0, amount.get("refunds")); + assertEquals(0, amount.get("liquid")); + assertEquals(0, amount.get("otherReceivers")); + assertEquals("BRL", amount.get("currency")); + + Map subtotals = parser.objectToMap(amount.get("subtotals")); + assertEquals(1500, subtotals.get("shipping")); + assertEquals(0, subtotals.get("addition")); + assertEquals(0, subtotals.get("discount")); + assertEquals(9500, subtotals.get("items")); + + List> items = parser.objectToList(order.get("items")); + assertEquals("Descrição do pedido", items.get(0).get("product")); + assertEquals(9500, items.get(0).get("price")); + assertEquals("Camiseta estampada branca", items.get(0).get("detail")); + assertEquals(1, items.get(0).get("quantity")); + assertEquals("CLOTHING", items.get(0).get("category")); + + List> addresses = parser.objectToList(order.get("addresses")); + assertEquals("Itaim Bibi", addresses.get(0).get("district")); + assertEquals("01451001", addresses.get(0).get("zipCode")); + assertEquals("3064", addresses.get(0).get("streetNumber")); + assertEquals("Avenida Brigadeiro Faria Lima", addresses.get(0).get("street")); + assertEquals("São Paulo", addresses.get(0).get("city")); + assertEquals("SP", addresses.get(0).get("state")); + assertEquals("SHIPPING", addresses.get(0).get("type")); + assertEquals("BRA", addresses.get(0).get("country")); + + Map customer = parser.objectToMap(order.get("customer")); + assertEquals("CUS-35TX8MWZ6SVX", customer.get("id")); + assertEquals("moip_create_customer_unit_test", customer.get("ownId")); + assertEquals("SDK Java", customer.get("fullname")); + assertEquals("2018-07-11T11:57:22.000-03", customer.get("createdAt")); + assertEquals("2018-07-12T14:53:46.687-03", customer.get("updatedAt")); + assertEquals("1980-05-10", customer.get("birthDate")); + assertEquals("sdk.java@moip.com.br", customer.get("email")); + + Map fundingInstrument = parser.objectToMap(customer.get("fundingInstrument")); + Map creditCard = parser.objectToMap(fundingInstrument.get("creditCard")); + assertEquals("CRC-7GKFB3S2R8SS", creditCard.get("id")); + assertEquals("ELO", creditCard.get("brand")); + assertEquals("636297", creditCard.get("first6")); + assertEquals("7013", creditCard.get("last4")); + assertEquals(true, creditCard.get("store")); + + assertEquals("CREDIT_CARD", fundingInstrument.get("method")); + + Map phone = parser.objectToMap(customer.get("phone")); + assertEquals("55", phone.get("countryCode")); + assertEquals("11", phone.get("areaCode")); + assertEquals("22226842", phone.get("number")); + + Map taxDocument = parser.objectToMap(customer.get("taxDocument")); + assertEquals("CPF", taxDocument.get("type")); + assertEquals("10013390023", taxDocument.get("number")); + + List> addressesCustomer = parser.objectToList(customer.get("addresses")); + assertEquals("Itaim Bibi", addressesCustomer.get(0).get("district")); + assertEquals("01451001", addressesCustomer.get(0).get("zipCode")); + assertEquals("3064", addressesCustomer.get(0).get("streetNumber")); + assertEquals("Avenida Brigadeiro Faria Lima", addressesCustomer.get(0).get("street")); + assertEquals("São Paulo", addressesCustomer.get(0).get("city")); + assertEquals("SP", addressesCustomer.get(0).get("state")); + assertEquals("SHIPPING", addressesCustomer.get(0).get("type")); + assertEquals("BRA", addressesCustomer.get(0).get("country")); + + Map shippingAddress = parser.objectToMap(customer.get("shippingAddress")); + assertEquals("01451001", shippingAddress.get("zipCode")); + assertEquals("Avenida Brigadeiro Faria Lima", shippingAddress.get("street")); + assertEquals("3064", shippingAddress.get("streetNumber")); + assertEquals("São Paulo", shippingAddress.get("city")); + assertEquals("Itaim Bibi", shippingAddress.get("district")); + assertEquals("SP", shippingAddress.get("state")); + assertEquals("BRA", shippingAddress.get("country")); + + Map moipAccount = parser.objectToMap(customer.get("moipAccount")); + assertEquals("MPA-8C2107EC8CCB", moipAccount.get("id")); + + Map linksCustomer = parser.objectToMap(customer.get("_links")); + Map selfCustomer = parser.objectToMap(linksCustomer.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/customers/CUS-35TX8MWZ6SVX", selfCustomer.get("href")); + + Map hostedAccountCustomer = parser.objectToMap(linksCustomer.get("hostedAccount")); + assertEquals("https://hostedaccount-sandbox.moip.com.br?token=69ec54c3-c6a1-4f04-953b-af7d0f0fbee0&id=CUS-35TX8MWZ6SVX&mpa=MPA-CULBBYHD11", hostedAccountCustomer.get("redirectHref")); + + List> fundingInstruments = parser.objectToList(customer.get("fundingInstruments")); + Map creditCardCustomer = parser.objectToMap(fundingInstruments.get(0).get("creditCard")); + assertEquals("CRC-7GKFB3S2R8SS", creditCardCustomer.get("id")); + assertEquals("ELO", creditCardCustomer.get("brand")); + assertEquals("636297", creditCardCustomer.get("first6")); + assertEquals("7013", creditCardCustomer.get("last4")); + assertEquals(true, creditCardCustomer.get("store")); + + assertEquals("CREDIT_CARD", fundingInstruments.get(0).get("method")); + + List> payments = parser.objectToList(order.get("payments")); + assertTrue(payments.isEmpty()); + + List> escrows = parser.objectToList(order.get("escrows")); + assertTrue(escrows.isEmpty()); + + List> refunds = parser.objectToList(order.get("refunds")); + assertTrue(refunds.isEmpty()); + + List> entries = parser.objectToList(order.get("entries")); + assertTrue(entries.isEmpty()); + + List> events = parser.objectToList(order.get("events")); + assertEquals("ORDER.CREATED", events.get(0).get("type")); + assertEquals("2018-07-12T14:53:46.683-03", events.get(0).get("createdAt")); + assertEquals("", events.get(0).get("description")); + + List> receivers = parser.objectToList(order.get("receivers")); + Map moipAccountReceiver = parser.objectToMap(receivers.get(0).get("moipAccount")); + assertEquals("MPA-CULBBYHD11", moipAccountReceiver.get("id")); + assertEquals("integracao@labs.moip.com.br", moipAccountReceiver.get("login")); + assertEquals("Moip SandBox", moipAccountReceiver.get("fullname")); + + assertEquals("PRIMARY", receivers.get(0).get("type")); + + Map amountReceiver = parser.objectToMap(receivers.get(0).get("amount")); + assertEquals(11000, amountReceiver.get("total")); + assertEquals("BRL", amountReceiver.get("currency")); + assertEquals(0, amountReceiver.get("fees")); + assertEquals(0, amountReceiver.get("refunds")); + + assertEquals(true, receivers.get(0).get("feePayor")); + + Map links = parser.objectToMap(order.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-A4HGZXSXARIV", self.get("href")); + + Map checkout = parser.objectToMap(links.get("checkout")); + Map payCheckout = parser.objectToMap(checkout.get("payCheckout")); + assertEquals("https://checkout-new-sandbox.moip.com.br?token=82678972-25ad-4d20-951a-ac9e384a6c04&id=ORD-A4HGZXSXARIV", payCheckout.get("redirectHref")); + + Map payCreditCard = parser.objectToMap(checkout.get("payCreditCard")); + assertEquals("https://checkout-new-sandbox.moip.com.br?token=82678972-25ad-4d20-951a-ac9e384a6c04&id=ORD-A4HGZXSXARIV&payment-method=credit-card", payCreditCard.get("redirectHref")); + + Map payBoleto = parser.objectToMap(checkout.get("payBoleto")); + assertEquals("https://checkout-new-sandbox.moip.com.br?token=82678972-25ad-4d20-951a-ac9e384a6c04&id=ORD-A4HGZXSXARIV&payment-method=boleto", payBoleto.get("redirectHref")); + + Map payOnlineBankDebitItau = parser.objectToMap(checkout.get("payOnlineBankDebitItau")); + assertEquals("https://checkout-sandbox.moip.com.br/debit/itau/ORD-A4HGZXSXARIV", payOnlineBankDebitItau.get("redirectHref")); + } + + @Play("order/get") + @Test + public void getOrderTest() { + + Map order = Moip.API.orders().get("ORD-A4HGZXSXARIV", setup); + + assertEquals("ORD-A4HGZXSXARIV", order.get("id")); + assertEquals("my_order_ownId", order.get("ownId")); + assertEquals("CREATED", order.get("status")); + assertEquals("V2", order.get("platform")); + assertEquals("2018-07-12T14:53:46.000-03", order.get("createdAt")); + assertEquals("2018-07-12T14:53:46.000-03", order.get("updatedAt")); + + Map amount = parser.objectToMap(order.get("amount")); + assertEquals(0, amount.get("paid")); + assertEquals(11000, amount.get("total")); + assertEquals(0, amount.get("fees")); + assertEquals(0, amount.get("refunds")); + assertEquals(0, amount.get("liquid")); + assertEquals(0, amount.get("otherReceivers")); + assertEquals("BRL", amount.get("currency")); + + Map subtotals = parser.objectToMap(amount.get("subtotals")); + assertEquals(1500, subtotals.get("shipping")); + assertEquals(0, subtotals.get("addition")); + assertEquals(0, subtotals.get("discount")); + assertEquals(9500, subtotals.get("items")); + + List> items = parser.objectToList(order.get("items")); + assertEquals("Descrição do pedido", items.get(0).get("product")); + assertEquals(9500, items.get(0).get("price")); + assertEquals("Camiseta estampada branca", items.get(0).get("detail")); + assertEquals(1, items.get(0).get("quantity")); + assertEquals("CLOTHING", items.get(0).get("category")); + + List> addresses = parser.objectToList(order.get("addresses")); + assertEquals("Itaim Bibi", addresses.get(0).get("district")); + assertEquals("01451001", addresses.get(0).get("zipCode")); + assertEquals("3064", addresses.get(0).get("streetNumber")); + assertEquals("Avenida Brigadeiro Faria Lima", addresses.get(0).get("street")); + assertEquals("São Paulo", addresses.get(0).get("city")); + assertEquals("SP", addresses.get(0).get("state")); + assertEquals("SHIPPING", addresses.get(0).get("type")); + assertEquals("BRA", addresses.get(0).get("country")); + + Map customer = parser.objectToMap(order.get("customer")); + assertEquals("CUS-35TX8MWZ6SVX", customer.get("id")); + assertEquals("moip_create_customer_unit_test", customer.get("ownId")); + assertEquals("SDK Java", customer.get("fullname")); + assertEquals("2018-07-11T11:57:22.000-03", customer.get("createdAt")); + assertEquals("2018-07-12T14:53:46.000-03", customer.get("updatedAt")); + assertEquals("1980-05-10", customer.get("birthDate")); + assertEquals("sdk.java@moip.com.br", customer.get("email")); + + Map fundingInstrument = parser.objectToMap(customer.get("fundingInstrument")); + Map creditCard = parser.objectToMap(fundingInstrument.get("creditCard")); + assertEquals("CRC-7GKFB3S2R8SS", creditCard.get("id")); + assertEquals("ELO", creditCard.get("brand")); + assertEquals("636297", creditCard.get("first6")); + assertEquals("7013", creditCard.get("last4")); + assertEquals(true, creditCard.get("store")); + + assertEquals("CREDIT_CARD", fundingInstrument.get("method")); + + Map phone = parser.objectToMap(customer.get("phone")); + assertEquals("55", phone.get("countryCode")); + assertEquals("11", phone.get("areaCode")); + assertEquals("22226842", phone.get("number")); + + Map taxDocument = parser.objectToMap(customer.get("taxDocument")); + assertEquals("CPF", taxDocument.get("type")); + assertEquals("10013390023", taxDocument.get("number")); + + List> addressesCustomer = parser.objectToList(customer.get("addresses")); + assertEquals("Itaim Bibi", addressesCustomer.get(0).get("district")); + assertEquals("01451001", addressesCustomer.get(0).get("zipCode")); + assertEquals("3064", addressesCustomer.get(0).get("streetNumber")); + assertEquals("Avenida Brigadeiro Faria Lima", addressesCustomer.get(0).get("street")); + assertEquals("São Paulo", addressesCustomer.get(0).get("city")); + assertEquals("SP", addressesCustomer.get(0).get("state")); + assertEquals("SHIPPING", addressesCustomer.get(0).get("type")); + assertEquals("BRA", addressesCustomer.get(0).get("country")); + + Map shippingAddress = parser.objectToMap(customer.get("shippingAddress")); + assertEquals("01451001", shippingAddress.get("zipCode")); + assertEquals("Avenida Brigadeiro Faria Lima", shippingAddress.get("street")); + assertEquals("3064", shippingAddress.get("streetNumber")); + assertEquals("São Paulo", shippingAddress.get("city")); + assertEquals("Itaim Bibi", shippingAddress.get("district")); + assertEquals("SP", shippingAddress.get("state")); + assertEquals("BRA", shippingAddress.get("country")); + + Map moipAccount = parser.objectToMap(customer.get("moipAccount")); + assertEquals("MPA-8C2107EC8CCB", moipAccount.get("id")); + + Map linksCustomer = parser.objectToMap(customer.get("_links")); + Map selfCustomer = parser.objectToMap(linksCustomer.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/customers/CUS-35TX8MWZ6SVX", selfCustomer.get("href")); + + Map hostedAccountCustomer = parser.objectToMap(linksCustomer.get("hostedAccount")); + assertEquals("https://hostedaccount-sandbox.moip.com.br?token=69ec54c3-c6a1-4f04-953b-af7d0f0fbee0&id=CUS-35TX8MWZ6SVX&mpa=MPA-CULBBYHD11", hostedAccountCustomer.get("redirectHref")); + + List> fundingInstruments = parser.objectToList(customer.get("fundingInstruments")); + Map creditCardCustomer = parser.objectToMap(fundingInstruments.get(0).get("creditCard")); + assertEquals("CRC-7GKFB3S2R8SS", creditCardCustomer.get("id")); + assertEquals("ELO", creditCardCustomer.get("brand")); + assertEquals("636297", creditCardCustomer.get("first6")); + assertEquals("7013", creditCardCustomer.get("last4")); + assertEquals(true, creditCardCustomer.get("store")); + + assertEquals("CREDIT_CARD", fundingInstruments.get(0).get("method")); + + List> payments = parser.objectToList(order.get("payments")); + assertTrue(payments.isEmpty()); + + List> escrows = parser.objectToList(order.get("escrows")); + assertTrue(escrows.isEmpty()); + + List> refunds = parser.objectToList(order.get("refunds")); + assertTrue(refunds.isEmpty()); + + List> entries = parser.objectToList(order.get("entries")); + assertTrue(entries.isEmpty()); + + List> events = parser.objectToList(order.get("events")); + assertEquals("ORDER.CREATED", events.get(0).get("type")); + assertEquals("2018-07-12T14:53:46.000-03", events.get(0).get("createdAt")); + assertEquals("", events.get(0).get("description")); + + List> receivers = parser.objectToList(order.get("receivers")); + Map moipAccountReceiver = parser.objectToMap(receivers.get(0).get("moipAccount")); + assertEquals("MPA-CULBBYHD11", moipAccountReceiver.get("id")); + assertEquals("integracao@labs.moip.com.br", moipAccountReceiver.get("login")); + assertEquals("Moip SandBox", moipAccountReceiver.get("fullname")); + + assertEquals("PRIMARY", receivers.get(0).get("type")); + + Map amountReceiver = parser.objectToMap(receivers.get(0).get("amount")); + assertEquals(11000, amountReceiver.get("total")); + assertEquals("BRL", amountReceiver.get("currency")); + assertEquals(0, amountReceiver.get("fees")); + assertEquals(0, amountReceiver.get("refunds")); + + assertEquals(true, receivers.get(0).get("feePayor")); + + Map links = parser.objectToMap(order.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-A4HGZXSXARIV", self.get("href")); + + Map checkout = parser.objectToMap(links.get("checkout")); + Map payCheckout = parser.objectToMap(checkout.get("payCheckout")); + assertEquals("https://checkout-new-sandbox.moip.com.br?token=82678972-25ad-4d20-951a-ac9e384a6c04&id=ORD-A4HGZXSXARIV", payCheckout.get("redirectHref")); + + Map payCreditCard = parser.objectToMap(checkout.get("payCreditCard")); + assertEquals("https://checkout-new-sandbox.moip.com.br?token=82678972-25ad-4d20-951a-ac9e384a6c04&id=ORD-A4HGZXSXARIV&payment-method=credit-card", payCreditCard.get("redirectHref")); + + Map payBoleto = parser.objectToMap(checkout.get("payBoleto")); + assertEquals("https://checkout-new-sandbox.moip.com.br?token=82678972-25ad-4d20-951a-ac9e384a6c04&id=ORD-A4HGZXSXARIV&payment-method=boleto", payBoleto.get("redirectHref")); + + Map payOnlineBankDebitItau = parser.objectToMap(checkout.get("payOnlineBankDebitItau")); + assertEquals("https://checkout-sandbox.moip.com.br/debit/itau/ORD-A4HGZXSXARIV", payOnlineBankDebitItau.get("redirectHref")); + } + + @Play("order/list") + @Test + public void listOrdersTest() { + + Map ordersList = Moip.API.orders().list(setup); + + Map links = parser.objectToMap(ordersList.get("_links")); + Map next = parser.objectToMap(links.get("next")); + assertEquals("https://test.moip.com.br/v2/orders?filters=&limit=0&offset=0", next.get("href")); + + Map previous = parser.objectToMap(links.get("previous")); + assertEquals("https://test.moip.com.br/v2/orders?filters=&limit=0&offset=0", previous.get("href")); + + Map summary = parser.objectToMap(ordersList.get("summary")); + assertEquals(48900, summary.get("count")); + assertEquals(7750393812L, summary.get("amount")); + + List> orders = parser.objectToList(ordersList.get("orders")); + + // orders[0] --- + assertEquals("ORD-PPKTLN8RH25E", orders.get(0).get("id")); + assertNull(orders.get(0).get("ownId")); + assertEquals("NOT_PAID", orders.get(0).get("status")); + assertEquals(false, orders.get(0).get("blocked")); + + Map amount0 = parser.objectToMap(orders.get(0).get("amount")); + assertEquals(690, amount0.get("total")); + assertEquals(0, amount0.get("addition")); + assertEquals(0, amount0.get("fees")); + assertEquals(0, amount0.get("otherReceivers")); + assertEquals("BRL", amount0.get("currency")); + + List> receivers0 = parser.objectToList(orders.get(0).get("receivers")); + assertEquals("PRIMARY", receivers0.get(0).get("type")); + + Map moipAccount0 = parser.objectToMap(receivers0.get(0).get("moipAccount")); + assertEquals("MPA-CULBBYHD11", moipAccount0.get("id")); + + // orders[1] --- + assertEquals("ORD-6MER91AAJI4I", orders.get(1).get("id")); + assertNull(orders.get(1).get("ownId")); + assertEquals("NOT_PAID", orders.get(1).get("status")); + assertEquals(false, orders.get(1).get("blocked")); + + Map amount1 = parser.objectToMap(orders.get(1).get("amount")); + assertEquals(690, amount1.get("total")); + assertEquals(0, amount1.get("addition")); + assertEquals(0, amount1.get("fees")); + assertEquals(0, amount1.get("otherReceivers")); + assertEquals("BRL", amount1.get("currency")); + + List> receivers1 = parser.objectToList(orders.get(1).get("receivers")); + assertEquals("PRIMARY", receivers1.get(0).get("type")); + + Map moipAccount1 = parser.objectToMap(receivers1.get(0).get("moipAccount")); + assertEquals("MPA-CULBBYHD11", moipAccount1.get("id")); + + // orders[2] --- + assertEquals("ORD-BN73SSJ1BO1K", orders.get(2).get("id")); + assertNull(orders.get(2).get("ownId")); + assertEquals("WAITING", orders.get(2).get("status")); + assertEquals(false, orders.get(2).get("blocked")); + + Map amount2 = parser.objectToMap(orders.get(2).get("amount")); + assertEquals(22000, amount2.get("total")); + assertEquals(0, amount2.get("addition")); + assertEquals(0, amount2.get("fees")); + assertEquals(0, amount2.get("otherReceivers")); + assertEquals("BRL", amount2.get("currency")); + + List> receivers2 = parser.objectToList(orders.get(2).get("receivers")); + assertEquals("PRIMARY", receivers2.get(0).get("type")); + + Map moipAccount2 = parser.objectToMap(receivers2.get(0).get("moipAccount")); + assertEquals("MPA-CULBBYHD11", moipAccount2.get("id")); + } + + @Play("order/list_order_payments") + @Test + public void listOrderPaymentsTest() { + + Map orderPayments = Moip.API.orders().listOrderPayments("ORD-BN73SSJ1BO1K", setup); + List> payments = parser.objectToList(orderPayments.get("payments")); + assertEquals("PAY-174FKBMG0OFD", payments.get(0).get("id")); + assertEquals("IN_ANALYSIS", payments.get(0).get("status")); + assertEquals(false, payments.get(0).get("delayCapture")); + + Map amount = parser.objectToMap(payments.get(0).get("amount")); + assertEquals(22000, amount.get("total")); + assertEquals(22000, amount.get("gross")); + assertEquals(1277, amount.get("fees")); + assertEquals(0, amount.get("refunds")); + assertEquals(20723, amount.get("liquid")); + assertEquals("BRL", amount.get("currency")); + + assertEquals(1, payments.get(0).get("installmentCount")); + + Map fundingInstrument = parser.objectToMap(payments.get(0).get("fundingInstrument")); + Map creditCard = parser.objectToMap(fundingInstrument.get("creditCard")); + assertEquals("CRC-TH09IN444CYO", creditCard.get("id")); + assertEquals("MASTERCARD", creditCard.get("brand")); + assertEquals("555566", creditCard.get("first6")); + assertEquals("8884", creditCard.get("last4")); + assertEquals(true, creditCard.get("store")); + + Map holder = parser.objectToMap(creditCard.get("holder")); + assertEquals("1986-04-26", holder.get("birthDate")); + + Map holderTaxDocument = parser.objectToMap(holder.get("taxDocument")); + assertEquals("UNKNOWN", holderTaxDocument.get("type")); + assertEquals("7847504910", holderTaxDocument.get("number")); + + assertEquals("Rafael Bosquetti Mateus", holder.get("fullname")); + + assertEquals("CREDIT_CARD", fundingInstrument.get("method")); + + Map acquirerDetails = parser.objectToMap(payments.get(0).get("acquirerDetails")); + assertEquals("T12996", acquirerDetails.get("authorizationNumber")); + + Map taxDocument = parser.objectToMap(acquirerDetails.get("taxDocument")); + assertEquals("CNPJ", taxDocument.get("type")); + assertEquals("01027058000191", taxDocument.get("number")); + + List> fees = parser.objectToList(payments.get(0).get("fees")); + assertEquals("TRANSACTION", fees.get(0).get("type")); + assertEquals(1277, fees.get(0).get("amount")); + + List> events = parser.objectToList(payments.get(0).get("events")); + + // events[0] --- + assertEquals("PAYMENT.IN_ANALYSIS", events.get(0).get("type")); + assertEquals("2018-07-12T14:15:39.000-03", events.get(0).get("createdAt")); + + // events[1] --- + assertEquals("PAYMENT.CREATED", events.get(1).get("type")); + assertEquals("2018-07-12T14:15:38.000-03", events.get(1).get("createdAt")); + + Map links = parser.objectToMap(payments.get(0).get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/payments/PAY-174FKBMG0OFD", self.get("href")); + + Map order = parser.objectToMap(links.get("order")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-BN73SSJ1BO1K", order.get("href")); + assertEquals("ORD-BN73SSJ1BO1K", order.get("title")); + + assertEquals("2018-07-12T14:15:38.000-03", payments.get(0).get("createdAt")); + assertEquals("2018-07-12T14:15:39.000-03", payments.get(0).get("updatedAt")); + } +} diff --git a/src/test/java/br/com/moip/unit_tests/PaymentTest.java b/src/test/java/br/com/moip/unit_tests/PaymentTest.java new file mode 100644 index 0000000..8e858b4 --- /dev/null +++ b/src/test/java/br/com/moip/unit_tests/PaymentTest.java @@ -0,0 +1,715 @@ +package br.com.moip.unit_tests; + +import br.com.moip.Moip; +import br.com.moip.models.Setup; +import br.com.moip.unit_tests.setup.SetupFactory; +import br.com.moip.utilities.Parser; +import com.rodrigosaito.mockwebserver.player.Play; +import com.rodrigosaito.mockwebserver.player.Player; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + +public class PaymentTest { + + @Rule + public Player player = new Player(); + private Setup setup; + private Map body; + private Parser parser; + + @Before + public void initialize() { + this.body = new HashMap<>(); + this.setup = new SetupFactory().setup(player.getURL("").toString()); + this.parser = new Parser(); + } + + @Play("payment/payment_with_credit_card") + @Test + public void paymentWithCreditCardTest() { + + Map payment = Moip.API.payments().pay(body, "ORD-MA1UMH2OJQIO", setup); + + assertEquals("PAY-WVCZZYDPRF22", payment.get("id")); + assertEquals("IN_ANALYSIS", payment.get("status")); + assertEquals(false, payment.get("delayCapture")); + + Map amount = parser.objectToMap(payment.get("amount")); + assertEquals(11000, amount.get("total")); + assertEquals(11000, amount.get("gross")); + assertEquals(0, amount.get("fees")); + assertEquals(0, amount.get("refunds")); + assertEquals(11000, amount.get("liquid")); + assertEquals("BRL", amount.get("currency")); + + assertEquals(1, payment.get("installmentCount")); + assertEquals("minhaLoja.com", payment.get("statementDescriptor")); + + Map fundingInstrument = parser.objectToMap(payment.get("fundingInstrument")); + Map creditCard = parser.objectToMap(fundingInstrument.get("creditCard")); + assertEquals("CRC-CQC2YNRA6UUT", creditCard.get("id")); + assertEquals("MASTERCARD", creditCard.get("brand")); + assertEquals("555566", creditCard.get("first6")); + assertEquals("8884", creditCard.get("last4")); + assertEquals(true, creditCard.get("store")); + + Map holder = parser.objectToMap(creditCard.get("holder")); + assertEquals("1988-12-30", holder.get("birthDate")); + + Map taxDocumentHolder = parser.objectToMap(holder.get("taxDocument")); + assertEquals("CPF", taxDocumentHolder.get("type")); + assertEquals("33333333333", taxDocumentHolder.get("number")); + + assertEquals("Teste Portador da Silva", holder.get("fullname")); + + assertEquals("CREDIT_CARD", fundingInstrument.get("method")); + + Map acquirerDetails = parser.objectToMap(payment.get("acquirerDetails")); + assertEquals("123456", acquirerDetails.get("authorizationNumber")); + + Map taxDocument = parser.objectToMap(acquirerDetails.get("taxDocument")); + assertEquals("CNPJ", taxDocument.get("type")); + assertEquals("01027058000191", taxDocument.get("number")); + + List> fees = parser.objectToList(payment.get("fees")); + assertEquals("TRANSACTION", fees.get(0).get("type")); + assertEquals(0, fees.get(0).get("amount")); + + List> events = parser.objectToList(payment.get("events")); + + // events[0] + assertEquals("PAYMENT.IN_ANALYSIS", events.get(0).get("type")); + assertEquals("2018-07-16T11:22:52.568-03", events.get(0).get("createdAt")); + + // events[1] + assertEquals("PAYMENT.CREATED", events.get(1).get("type")); + assertEquals("2018-07-16T11:22:50.088-03", events.get(1).get("createdAt")); + + List> receivers = parser.objectToList(payment.get("receivers")); + Map moipAccount = parser.objectToMap(receivers.get(0).get("moipAccount")); + assertEquals("MPA-CULBBYHD11", moipAccount.get("id")); + assertEquals("integracao@labs.moip.com.br", moipAccount.get("login")); + assertEquals("Moip SandBox", moipAccount.get("fullname")); + + assertEquals("PRIMARY", receivers.get(0).get("type")); + + Map amountReceived = parser.objectToMap(receivers.get(0).get("amount")); + assertEquals(11000, amountReceived.get("total")); + assertEquals("BRL", amountReceived.get("currency")); + assertEquals(0, amountReceived.get("fees")); + assertEquals(0, amountReceived.get("refunds")); + + assertEquals(true, receivers.get(0).get("feePayor")); + + Map device = parser.objectToMap(payment.get("device")); + assertEquals("127.0.0.1", device.get("ip")); + + Map geolocation = parser.objectToMap(device.get("geolocation")); + assertEquals(-33.867, geolocation.get("latitude")); + assertEquals(151.206, geolocation.get("longitude")); + + assertEquals("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36", device.get("userAgent")); + assertEquals("QAZXswedCVGrtgBNHyujMKIkolpQAZXswedCVGrtgBNHyujMKIkolpQAZXswedCVGrtgBNHyujMKIkolpQAZXswedCVGrtgBNHyujMKIkolp", device.get("fingerprint")); + + Map links = parser.objectToMap(payment.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/payments/PAY-WVCZZYDPRF22", self.get("href")); + + Map order = parser.objectToMap(links.get("order")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-MA1UMH2OJQIO", order.get("href")); + assertEquals("ORD-MA1UMH2OJQIO", order.get("title")); + + assertEquals("2018-07-16T11:22:50.061-03", payment.get("createdAt")); + assertEquals("2018-07-16T11:22:52.568-03", payment.get("updatedAt")); + } + + @Play("payment/payment_with_boleto") + @Test + public void paymentWithBoletoTest() { + + Map payment = Moip.API.payments().pay(body, "ORD-9S0XI6VIMTJ7", setup); + + assertEquals("PAY-9SGAMYL775UX", payment.get("id")); + assertEquals("WAITING", payment.get("status")); + assertEquals(false, payment.get("delayCapture")); + + Map amount = parser.objectToMap(payment.get("amount")); + assertEquals(11000, amount.get("total")); + assertEquals(11000, amount.get("gross")); + assertEquals(0, amount.get("fees")); + assertEquals(0, amount.get("refunds")); + assertEquals(11000, amount.get("liquid")); + assertEquals("BRL", amount.get("currency")); + + assertEquals(1, payment.get("installmentCount")); + + Map fundingInstrument = parser.objectToMap(payment.get("fundingInstrument")); + Map boleto = parser.objectToMap(fundingInstrument.get("boleto")); + assertEquals("2020-06-20", boleto.get("expirationDate")); + assertEquals("00190.00009 01014.051005 00000.787176 7 72370000001000", boleto.get("lineCode")); + assertEquals("http://www.lojaexemplo.com.br/logo.jpg", boleto.get("logoUri")); + + Map instructionLines = parser.objectToMap(boleto.get("instructionLines")); + assertEquals("Atenção,", instructionLines.get("first")); + assertEquals("fique atento à data de vencimento do boleto.", instructionLines.get("second")); + assertEquals("Pague em qualquer casa lotérica.", instructionLines.get("third")); + + assertEquals("BOLETO", fundingInstrument.get("method")); + + List> fees = parser.objectToList(payment.get("fees")); + assertEquals("TRANSACTION", fees.get(0).get("type")); + assertEquals(0, fees.get(0).get("amount")); + + List> events = parser.objectToList(payment.get("events")); + + // events[0] + assertEquals("PAYMENT.CREATED", events.get(0).get("type")); + assertEquals("2018-07-16T13:22:41.284-03", events.get(0).get("createdAt")); + + // events[1] + assertEquals("PAYMENT.WAITING", events.get(1).get("type")); + assertEquals("2018-07-16T13:22:41.284-03", events.get(1).get("createdAt")); + + List> receivers = parser.objectToList(payment.get("receivers")); + Map moipAccount = parser.objectToMap(receivers.get(0).get("moipAccount")); + assertEquals("MPA-CULBBYHD11", moipAccount.get("id")); + assertEquals("integracao@labs.moip.com.br", moipAccount.get("login")); + assertEquals("Moip SandBox", moipAccount.get("fullname")); + + Map amountReceived = parser.objectToMap(receivers.get(0).get("amount")); + assertEquals(11000, amountReceived.get("total")); + assertEquals("BRL", amountReceived.get("currency")); + assertEquals(0, amountReceived.get("fees")); + assertEquals(0, amountReceived.get("refunds")); + + assertEquals(true, receivers.get(0).get("feePayor")); + + Map links = parser.objectToMap(payment.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/payments/PAY-9SGAMYL775UX", self.get("href")); + + Map order = parser.objectToMap(links.get("order")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-9S0XI6VIMTJ7", order.get("href")); + assertEquals("ORD-9S0XI6VIMTJ7", order.get("title")); + + assertEquals("2018-07-16T13:22:41.282-03", payment.get("createdAt")); + assertEquals("2018-07-16T13:22:41.282-03", payment.get("updatedAt")); + } + + @Play("payment/payment_with_online_bank_debit") + @Test + public void paymentWithOnlineBankDebitTest() { + + Map payment = Moip.API.payments().pay(body, "ORD-GVEF677TOU7D", setup); + + assertEquals("PAY-SKEH9F7N532S", payment.get("id")); + assertEquals("WAITING", payment.get("status")); + assertEquals(false, payment.get("delayCapture")); + + Map amount = parser.objectToMap(payment.get("amount")); + assertEquals(11000, amount.get("total")); + assertEquals(11000, amount.get("gross")); + assertEquals(277, amount.get("fees")); + assertEquals(0, amount.get("refunds")); + assertEquals(10723, amount.get("liquid")); + assertEquals("BRL", amount.get("currency")); + + assertEquals(1, payment.get("installmentCount")); + + Map fundingInstrument = parser.objectToMap(payment.get("fundingInstrument")); + assertEquals("ONLINE_BANK_DEBIT", fundingInstrument.get("method")); + + Map onlineBankDebit = parser.objectToMap(fundingInstrument.get("onlineBankDebit")); + assertEquals("341", onlineBankDebit.get("bankNumber")); + assertEquals("2018-11-22", onlineBankDebit.get("expirationDate")); + assertEquals("BANCO ITAU S.A.", onlineBankDebit.get("bankName")); + + List> fees = parser.objectToList(payment.get("fees")); + assertEquals("TRANSACTION", fees.get(0).get("type")); + assertEquals(277, fees.get(0).get("amount")); + + List> events = parser.objectToList(payment.get("events")); + + // events[0] + assertEquals("PAYMENT.CREATED", events.get(0).get("type")); + assertEquals("2018-07-16T13:52:06.138-03", events.get(0).get("createdAt")); + + // events[1] + assertEquals("PAYMENT.WAITING", events.get(1).get("type")); + assertEquals("2018-07-16T13:52:06.138-03", events.get(1).get("createdAt")); + + List> receivers = parser.objectToList(payment.get("receivers")); + Map moipAccount = parser.objectToMap(receivers.get(0).get("moipAccount")); + assertEquals("MPA-CULBBYHD11", moipAccount.get("id")); + assertEquals("integracao@labs.moip.com.br", moipAccount.get("login")); + assertEquals("Moip SandBox", moipAccount.get("fullname")); + + Map amountReceived = parser.objectToMap(receivers.get(0).get("amount")); + assertEquals(11000, amountReceived.get("total")); + assertEquals("BRL", amountReceived.get("currency")); + assertEquals(0, amountReceived.get("fees")); + assertEquals(0, amountReceived.get("refunds")); + + assertEquals(true, receivers.get(0).get("feePayor")); + + Map links = parser.objectToMap(payment.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/payments/PAY-SKEH9F7N532S", self.get("href")); + + Map order = parser.objectToMap(links.get("order")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-GVEF677TOU7D", order.get("href")); + assertEquals("ORD-GVEF677TOU7D", order.get("title")); + + Map payOnlineBankDebitItau = parser.objectToMap(links.get("payOnlineBankDebitItau")); + assertEquals("https://checkout-sandbox.moip.com.br/debit/itau/PAY-SKEH9F7N532S", payOnlineBankDebitItau.get("redirectHref")); + + assertEquals("2018-07-16T13:52:06.136-03", payment.get("createdAt")); + assertEquals("2018-07-16T13:52:06.136-03", payment.get("updatedAt")); + } + + @Play("payment/pre_authorized_payment") + @Test + public void createPreAuthorizedPaymentTest() { + + Map payment = Moip.API.payments().pay(body, "ORD-J5F0JITE58DV", setup); + + assertEquals("PAY-MMU64JJBUI6Z", payment.get("id")); + assertEquals("IN_ANALYSIS", payment.get("status")); + assertEquals(true, payment.get("delayCapture")); + + Map amount = parser.objectToMap(payment.get("amount")); + assertEquals(11000, amount.get("total")); + assertEquals(11000, amount.get("gross")); + assertEquals(0, amount.get("fees")); + assertEquals(0, amount.get("refunds")); + assertEquals(11000, amount.get("liquid")); + assertEquals("BRL", amount.get("currency")); + + assertEquals(3, payment.get("installmentCount")); + assertEquals("Minha Loja", payment.get("statementDescriptor")); + + Map fundingInstrument = parser.objectToMap(payment.get("fundingInstrument")); + Map creditCard = parser.objectToMap(fundingInstrument.get("creditCard")); + assertEquals("CRC-CQC2YNRA6UUT", creditCard.get("id")); + assertEquals("MASTERCARD", creditCard.get("brand")); + assertEquals("555566", creditCard.get("first6")); + assertEquals("8884", creditCard.get("last4")); + assertEquals(true, creditCard.get("store")); + + Map holder = parser.objectToMap(creditCard.get("holder")); + assertEquals("1988-12-30", holder.get("birthDate")); + + Map taxDocumentHolder = parser.objectToMap(holder.get("taxDocument")); + assertEquals("CPF", taxDocumentHolder.get("type")); + assertEquals("78994193600", taxDocumentHolder.get("number")); + + Map billingAddress = parser.objectToMap(holder.get("billingAddress")); + assertEquals("Avenida Contorno", billingAddress.get("street")); + assertEquals("400", billingAddress.get("streetNumber")); + assertEquals("Savassi", billingAddress.get("district")); + assertEquals("Belo Horizonte", billingAddress.get("city")); + assertEquals("MG", billingAddress.get("state")); + assertEquals("BRA", billingAddress.get("country")); + assertEquals("76932800", billingAddress.get("zipCode")); + + assertEquals("Roberto Oliveira", holder.get("fullname")); + + assertEquals("CREDIT_CARD", fundingInstrument.get("method")); + + Map acquirerDetails = parser.objectToMap(payment.get("acquirerDetails")); + assertEquals("123456", acquirerDetails.get("authorizationNumber")); + + Map taxDocument = parser.objectToMap(acquirerDetails.get("taxDocument")); + assertEquals("CNPJ", taxDocument.get("type")); + assertEquals("01027058000191", taxDocument.get("number")); + + List> fees = parser.objectToList(payment.get("fees")); + assertEquals("TRANSACTION", fees.get(0).get("type")); + assertEquals(0, fees.get(0).get("amount")); + + List> events = parser.objectToList(payment.get("events")); + + // events[0] + assertEquals("PAYMENT.IN_ANALYSIS", events.get(0).get("type")); + assertEquals("2018-07-16T14:11:40.090-03", events.get(0).get("createdAt")); + + // events[1] + assertEquals("PAYMENT.CREATED", events.get(1).get("type")); + assertEquals("2018-07-16T14:11:34.179-03", events.get(1).get("createdAt")); + + List> receivers = parser.objectToList(payment.get("receivers")); + Map moipAccount = parser.objectToMap(receivers.get(0).get("moipAccount")); + assertEquals("MPA-CULBBYHD11", moipAccount.get("id")); + assertEquals("integracao@labs.moip.com.br", moipAccount.get("login")); + assertEquals("Moip SandBox", moipAccount.get("fullname")); + + assertEquals("PRIMARY", receivers.get(0).get("type")); + + Map amountReceived = parser.objectToMap(receivers.get(0).get("amount")); + assertEquals(11000, amountReceived.get("total")); + assertEquals("BRL", amountReceived.get("currency")); + assertEquals(0, amountReceived.get("fees")); + assertEquals(0, amountReceived.get("refunds")); + + assertEquals(true, receivers.get(0).get("feePayor")); + + Map links = parser.objectToMap(payment.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/payments/PAY-MMU64JJBUI6Z", self.get("href")); + + Map order = parser.objectToMap(links.get("order")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-J5F0JITE58DV", order.get("href")); + assertEquals("ORD-J5F0JITE58DV", order.get("title")); + + assertEquals("2018-07-16T14:11:34.152-03", payment.get("createdAt")); + assertEquals("2018-07-16T14:11:40.090-03", payment.get("updatedAt")); + } + + @Play("payment/capture_pre_authorized") + @Test + public void capturePreAuthorizedTest() { + + Map capture = Moip.API.payments().capturePreAuthorized("PAY-MMU64JJBUI6Z", setup); + + assertEquals("PAY-MMU64JJBUI6Z", capture.get("id")); + assertEquals("AUTHORIZED", capture.get("status")); + assertEquals(true, capture.get("delayCapture")); + + Map amount = parser.objectToMap(capture.get("amount")); + assertEquals(11000, amount.get("total")); + assertEquals(11000, amount.get("gross")); + assertEquals(1127, amount.get("fees")); + assertEquals(0, amount.get("refunds")); + assertEquals(9873, amount.get("liquid")); + assertEquals("BRL", amount.get("currency")); + + assertEquals(3, capture.get("installmentCount")); + assertEquals("Minha Loja", capture.get("statementDescriptor")); + + Map fundingInstrument = parser.objectToMap(capture.get("fundingInstrument")); + Map creditCard = parser.objectToMap(fundingInstrument.get("creditCard")); + assertEquals("CRC-CQC2YNRA6UUT", creditCard.get("id")); + assertEquals("MASTERCARD", creditCard.get("brand")); + assertEquals("555566", creditCard.get("first6")); + assertEquals("8884", creditCard.get("last4")); + assertEquals(true, creditCard.get("store")); + + Map holder = parser.objectToMap(creditCard.get("holder")); + assertEquals("1988-12-30", holder.get("birthDate")); + + Map taxDocumentHolder = parser.objectToMap(holder.get("taxDocument")); + assertEquals("CPF", taxDocumentHolder.get("type")); + assertEquals("78994193600", taxDocumentHolder.get("number")); + + Map billingAddress = parser.objectToMap(holder.get("billingAddress")); + assertEquals("Avenida Contorno", billingAddress.get("street")); + assertEquals("400", billingAddress.get("streetNumber")); + assertEquals("Savassi", billingAddress.get("district")); + assertEquals("Belo Horizonte", billingAddress.get("city")); + assertEquals("MG", billingAddress.get("state")); + assertEquals("BRA", billingAddress.get("country")); + assertEquals("76932800", billingAddress.get("zipCode")); + + assertEquals("Roberto Oliveira", holder.get("fullname")); + + assertEquals("CREDIT_CARD", fundingInstrument.get("method")); + + Map acquirerDetails = parser.objectToMap(capture.get("acquirerDetails")); + assertEquals("123456", acquirerDetails.get("authorizationNumber")); + + Map taxDocument = parser.objectToMap(acquirerDetails.get("taxDocument")); + assertEquals("CNPJ", taxDocument.get("type")); + assertEquals("01027058000191", taxDocument.get("number")); + + List> fees = parser.objectToList(capture.get("fees")); + + // fees[0] + assertEquals("TRANSACTION", fees.get(0).get("type")); + assertEquals(585, fees.get(0).get("amount")); + + // fees[1] + assertEquals("PRE_PAYMENT", fees.get(1).get("type")); + assertEquals(542, fees.get(1).get("amount")); + + List> events = parser.objectToList(capture.get("events")); + + // events[0] + assertEquals("PAYMENT.AUTHORIZED", events.get(0).get("type")); + assertEquals("2018-07-16T15:51:49.583-03", events.get(0).get("createdAt")); + + // events[1] + assertEquals("PAYMENT.IN_ANALYSIS", events.get(1).get("type")); + assertEquals("2018-07-16T14:11:40.000-03", events.get(1).get("createdAt")); + + // events[2] + assertEquals("PAYMENT.PRE_AUTHORIZED", events.get(2).get("type")); + assertEquals("2018-07-16T14:11:40.000-03", events.get(2).get("createdAt")); + + // events[3] + assertEquals("PAYMENT.CREATED", events.get(3).get("type")); + assertEquals("2018-07-16T14:11:34.000-03", events.get(3).get("createdAt")); + + List> receivers = parser.objectToList(capture.get("receivers")); + Map moipAccount = parser.objectToMap(receivers.get(0).get("moipAccount")); + assertEquals("MPA-CULBBYHD11", moipAccount.get("id")); + assertEquals("integracao@labs.moip.com.br", moipAccount.get("login")); + assertEquals("Moip SandBox", moipAccount.get("fullname")); + + assertEquals("PRIMARY", receivers.get(0).get("type")); + + Map amountReceived = parser.objectToMap(receivers.get(0).get("amount")); + assertEquals(11000, amountReceived.get("total")); + assertEquals("BRL", amountReceived.get("currency")); + assertEquals(1127, amountReceived.get("fees")); + assertEquals(0, amountReceived.get("refunds")); + + assertEquals(true, receivers.get(0).get("feePayor")); + + Map links = parser.objectToMap(capture.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/payments/PAY-MMU64JJBUI6Z", self.get("href")); + + Map order = parser.objectToMap(links.get("order")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-J5F0JITE58DV", order.get("href")); + assertEquals("ORD-J5F0JITE58DV", order.get("title")); + + assertEquals("2018-07-16T14:11:34.000-03", capture.get("createdAt")); + assertEquals("2018-07-16T15:51:49.582-03", capture.get("updatedAt")); + } + + @Play("payment/cancel_pre_authorized") + @Test + public void cancelPreAuthorized() { + + Map cancel = Moip.API.payments().cancelPreAuthorized("PAY-44R4XT17VP50", setup); + + assertEquals("PAY-44R4XT17VP50", cancel.get("id")); + assertEquals("CANCELLED", cancel.get("status")); + assertEquals(true, cancel.get("delayCapture")); + + Map cancellationDetails = parser.objectToMap(cancel.get("cancellationDetails")); + assertEquals("7", cancellationDetails.get("code")); + assertEquals("Política do Moip", cancellationDetails.get("description")); + assertEquals("MOIP", cancellationDetails.get("cancelledBy")); + + Map amount = parser.objectToMap(cancel.get("amount")); + assertEquals(11000, amount.get("total")); + assertEquals(11000, amount.get("gross")); + assertEquals(1127, amount.get("fees")); + assertEquals(0, amount.get("refunds")); + assertEquals(9873, amount.get("liquid")); + assertEquals("BRL", amount.get("currency")); + + assertEquals(3, cancel.get("installmentCount")); + assertEquals("Minha Loja", cancel.get("statementDescriptor")); + + Map fundingInstrument = parser.objectToMap(cancel.get("fundingInstrument")); + Map creditCard = parser.objectToMap(fundingInstrument.get("creditCard")); + assertEquals("CRC-CQC2YNRA6UUT", creditCard.get("id")); + assertEquals("MASTERCARD", creditCard.get("brand")); + assertEquals("555566", creditCard.get("first6")); + assertEquals("8884", creditCard.get("last4")); + assertEquals(true, creditCard.get("store")); + + Map holder = parser.objectToMap(creditCard.get("holder")); + assertEquals("1988-12-30", holder.get("birthDate")); + + Map taxDocumentHolder = parser.objectToMap(holder.get("taxDocument")); + assertEquals("CPF", taxDocumentHolder.get("type")); + assertEquals("78994193600", taxDocumentHolder.get("number")); + + Map billingAddress = parser.objectToMap(holder.get("billingAddress")); + assertEquals("Avenida Contorno", billingAddress.get("street")); + assertEquals("400", billingAddress.get("streetNumber")); + assertEquals("Savassi", billingAddress.get("district")); + assertEquals("Belo Horizonte", billingAddress.get("city")); + assertEquals("MG", billingAddress.get("state")); + assertEquals("BRA", billingAddress.get("country")); + assertEquals("76932800", billingAddress.get("zipCode")); + + assertEquals("Roberto Oliveira", holder.get("fullname")); + + assertEquals("CREDIT_CARD", fundingInstrument.get("method")); + + Map acquirerDetails = parser.objectToMap(cancel.get("acquirerDetails")); + assertEquals("123456", acquirerDetails.get("authorizationNumber")); + + Map taxDocument = parser.objectToMap(acquirerDetails.get("taxDocument")); + assertEquals("CNPJ", taxDocument.get("type")); + assertEquals("01027058000191", taxDocument.get("number")); + + List> fees = parser.objectToList(cancel.get("fees")); + + // fees[0] + assertEquals("TRANSACTION", fees.get(0).get("type")); + assertEquals(585, fees.get(0).get("amount")); + + // fees[1] + assertEquals("PRE_PAYMENT", fees.get(1).get("type")); + assertEquals(542, fees.get(1).get("amount")); + + List> events = parser.objectToList(cancel.get("events")); + + // events[0] + assertEquals("PAYMENT.CANCELLED", events.get(0).get("type")); + assertEquals("2018-07-16T16:12:26.499-03", events.get(0).get("createdAt")); + + // events[1] + assertEquals("PAYMENT.PRE_AUTHORIZED", events.get(1).get("type")); + assertEquals("2018-07-16T16:12:12.000-03", events.get(1).get("createdAt")); + + // events[2] + assertEquals("PAYMENT.IN_ANALYSIS", events.get(2).get("type")); + assertEquals("2018-07-16T16:12:11.000-03", events.get(2).get("createdAt")); + + // events[3] + assertEquals("PAYMENT.CREATED", events.get(3).get("type")); + assertEquals("2018-07-16T16:11:50.000-03", events.get(3).get("createdAt")); + + List> receivers = parser.objectToList(cancel.get("receivers")); + Map moipAccount = parser.objectToMap(receivers.get(0).get("moipAccount")); + assertEquals("MPA-CULBBYHD11", moipAccount.get("id")); + assertEquals("integracao@labs.moip.com.br", moipAccount.get("login")); + assertEquals("Moip SandBox", moipAccount.get("fullname")); + + assertEquals("PRIMARY", receivers.get(0).get("type")); + + Map amountReceived = parser.objectToMap(receivers.get(0).get("amount")); + assertEquals(11000, amountReceived.get("total")); + assertEquals("BRL", amountReceived.get("currency")); + assertEquals(0, amountReceived.get("fees")); + assertEquals(0, amountReceived.get("refunds")); + + assertEquals(true, receivers.get(0).get("feePayor")); + + Map links = parser.objectToMap(cancel.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/payments/PAY-44R4XT17VP50", self.get("href")); + + Map order = parser.objectToMap(links.get("order")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-3Y3NR4PS4HVP", order.get("href")); + assertEquals("ORD-3Y3NR4PS4HVP", order.get("title")); + + assertEquals("2018-07-16T16:11:50.000-03", cancel.get("createdAt")); + assertEquals("2018-07-16T16:12:26.498-03", cancel.get("updatedAt")); + } + + @Play("payment/get") + @Test + public void getPaymentTest() { + + Map payment = Moip.API.payments().get("PAY-MMU64JJBUI6Z", setup); + + assertEquals("PAY-MMU64JJBUI6Z", payment.get("id")); + assertEquals("AUTHORIZED", payment.get("status")); + assertEquals(true, payment.get("delayCapture")); + + Map amount = parser.objectToMap(payment.get("amount")); + assertEquals(11000, amount.get("total")); + assertEquals(11000, amount.get("gross")); + assertEquals(1127, amount.get("fees")); + assertEquals(0, amount.get("refunds")); + assertEquals(9873, amount.get("liquid")); + assertEquals("BRL", amount.get("currency")); + + assertEquals(3, payment.get("installmentCount")); + assertEquals("Minha Loja", payment.get("statementDescriptor")); + + Map fundingInstrument = parser.objectToMap(payment.get("fundingInstrument")); + Map creditCard = parser.objectToMap(fundingInstrument.get("creditCard")); + assertEquals("CRC-CQC2YNRA6UUT", creditCard.get("id")); + assertEquals("MASTERCARD", creditCard.get("brand")); + assertEquals("555566", creditCard.get("first6")); + assertEquals("8884", creditCard.get("last4")); + assertEquals(true, creditCard.get("store")); + + Map holder = parser.objectToMap(creditCard.get("holder")); + assertEquals("1988-12-30", holder.get("birthDate")); + + Map taxDocumentHolder = parser.objectToMap(holder.get("taxDocument")); + assertEquals("CPF", taxDocumentHolder.get("type")); + assertEquals("78994193600", taxDocumentHolder.get("number")); + + Map billingAddress = parser.objectToMap(holder.get("billingAddress")); + assertEquals("Avenida Contorno", billingAddress.get("street")); + assertEquals("400", billingAddress.get("streetNumber")); + assertEquals("Savassi", billingAddress.get("district")); + assertEquals("Belo Horizonte", billingAddress.get("city")); + assertEquals("MG", billingAddress.get("state")); + assertEquals("BRA", billingAddress.get("country")); + assertEquals("76932800", billingAddress.get("zipCode")); + + assertEquals("Roberto Oliveira", holder.get("fullname")); + + assertEquals("CREDIT_CARD", fundingInstrument.get("method")); + + Map acquirerDetails = parser.objectToMap(payment.get("acquirerDetails")); + assertEquals("123456", acquirerDetails.get("authorizationNumber")); + + Map taxDocument = parser.objectToMap(acquirerDetails.get("taxDocument")); + assertEquals("CNPJ", taxDocument.get("type")); + assertEquals("01027058000191", taxDocument.get("number")); + + List> fees = parser.objectToList(payment.get("fees")); + + // fees[0] + assertEquals("TRANSACTION", fees.get(0).get("type")); + assertEquals(585, fees.get(0).get("amount")); + + // fees[1] + assertEquals("PRE_PAYMENT", fees.get(1).get("type")); + assertEquals(542, fees.get(1).get("amount")); + + List> events = parser.objectToList(payment.get("events")); + + // events[0] + assertEquals("PAYMENT.AUTHORIZED", events.get(0).get("type")); + assertEquals("2018-07-16T15:51:49.000-03", events.get(0).get("createdAt")); + + // events[1] + assertEquals("PAYMENT.IN_ANALYSIS", events.get(1).get("type")); + assertEquals("2018-07-16T14:11:40.000-03", events.get(1).get("createdAt")); + + // events[2] + assertEquals("PAYMENT.PRE_AUTHORIZED", events.get(2).get("type")); + assertEquals("2018-07-16T14:11:40.000-03", events.get(2).get("createdAt")); + + // events[3] + assertEquals("PAYMENT.CREATED", events.get(3).get("type")); + assertEquals("2018-07-16T14:11:34.000-03", events.get(3).get("createdAt")); + + List> receivers = parser.objectToList(payment.get("receivers")); + Map moipAccount = parser.objectToMap(receivers.get(0).get("moipAccount")); + assertEquals("MPA-CULBBYHD11", moipAccount.get("id")); + assertEquals("integracao@labs.moip.com.br", moipAccount.get("login")); + assertEquals("Moip SandBox", moipAccount.get("fullname")); + + assertEquals("PRIMARY", receivers.get(0).get("type")); + + Map amountReceived = parser.objectToMap(receivers.get(0).get("amount")); + assertEquals(11000, amountReceived.get("total")); + assertEquals("BRL", amountReceived.get("currency")); + assertEquals(1127, amountReceived.get("fees")); + assertEquals(0, amountReceived.get("refunds")); + + assertEquals(true, receivers.get(0).get("feePayor")); + + Map links = parser.objectToMap(payment.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/payments/PAY-MMU64JJBUI6Z", self.get("href")); + + Map order = parser.objectToMap(links.get("order")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-J5F0JITE58DV", order.get("href")); + assertEquals("ORD-J5F0JITE58DV", order.get("title")); + + assertEquals("2018-07-16T14:11:34.000-03", payment.get("createdAt")); + assertEquals("2018-07-16T15:51:49.000-03", payment.get("updatedAt")); + } +} diff --git a/src/test/java/br/com/moip/unit_tests/RefundTest.java b/src/test/java/br/com/moip/unit_tests/RefundTest.java new file mode 100644 index 0000000..30cb605 --- /dev/null +++ b/src/test/java/br/com/moip/unit_tests/RefundTest.java @@ -0,0 +1,415 @@ +package br.com.moip.unit_tests; + +import br.com.moip.Moip; +import br.com.moip.models.Setup; +import br.com.moip.unit_tests.setup.SetupFactory; +import br.com.moip.utilities.Parser; +import com.rodrigosaito.mockwebserver.player.Play; +import com.rodrigosaito.mockwebserver.player.Player; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + +public class RefundTest { + + @Rule + public Player player = new Player(); + private Setup setup; + private Map body; + private Parser parser; + + @Before + public void initialize() { + this.body = new HashMap<>(); + this.setup = new SetupFactory().setup(player.getURL("").toString()); + this.parser = new Parser(); + } + + @Play("refund/full_refund_payment") + @Test + public void fullRefundPaymentTest() { + + Map refund = Moip.API.refunds().refundPayment("PAY-MMU64JJBUI6Z", setup); + + assertEquals("REF-DBM34ELHHHS6", refund.get("id")); + assertEquals("COMPLETED", refund.get("status")); + + List> events = parser.objectToList(refund.get("events")); + + // events[0] + assertEquals("REFUND.COMPLETED", events.get(0).get("type")); + assertEquals("2018-07-17T14:13:22.000-03", events.get(0).get("createdAt")); + + // events[1] + assertEquals("REFUND.REQUESTED", events.get(1).get("type")); + assertEquals("2018-07-17T14:13:22.000-03", events.get(1).get("createdAt")); + + Map amount = parser.objectToMap(refund.get("amount")); + assertEquals(11000, amount.get("total")); + assertEquals(0, amount.get("fees")); + assertEquals("BRL", amount.get("currency")); + + List> receiversDebited = parser.objectToList(refund.get("receiversDebited")); + assertEquals(9873, receiversDebited.get(0).get("amount")); + assertEquals("MPA-CULBBYHD11", receiversDebited.get(0).get("moipAccount")); + + assertEquals("FULL", refund.get("type")); + + Map refundingInstrument = parser.objectToMap(refund.get("refundingInstrument")); + Map creditCard = parser.objectToMap(refundingInstrument.get("creditCard")); + assertEquals("MASTERCARD", creditCard.get("brand")); + assertEquals("555566", creditCard.get("first6")); + assertEquals("8884", creditCard.get("last4")); + assertEquals(true, creditCard.get("store")); + + assertEquals("CREDIT_CARD", refundingInstrument.get("method")); + + assertEquals("2018-07-17T14:13:22.000-03", refund.get("createdAt")); + + Map links = parser.objectToMap(refund.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/refunds/REF-DBM34ELHHHS6", self.get("href")); + + Map order = parser.objectToMap(links.get("order")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-J5F0JITE58DV", order.get("href")); + assertEquals("ORD-J5F0JITE58DV", order.get("title")); + + Map payment = parser.objectToMap(links.get("payment")); + assertEquals("https://sandbox.moip.com.br/v2/payments/PAY-MMU64JJBUI6Z", payment.get("href")); + assertEquals("PAY-MMU64JJBUI6Z", payment.get("title")); + } + + @Play("refund/full_refund_order") + @Test + public void fullRefundOrderTest() { + + Map refund = Moip.API.refunds().refundOrder("ORD-BCLUATUQ8K4W", setup); + + assertEquals("REF-MYLT39W1ZWEU", refund.get("id")); + assertEquals("COMPLETED", refund.get("status")); + + List> events = parser.objectToList(refund.get("events")); + + // events[0] + assertEquals("REFUND.COMPLETED", events.get(0).get("type")); + assertEquals("2018-07-17T16:16:16.000-03", events.get(0).get("createdAt")); + + // events[1] + assertEquals("REFUND.REQUESTED", events.get(1).get("type")); + assertEquals("2018-07-17T16:16:16.000-03", events.get(1).get("createdAt")); + + Map amount = parser.objectToMap(refund.get("amount")); + assertEquals(11000, amount.get("total")); + assertEquals(0, amount.get("fees")); + assertEquals("BRL", amount.get("currency")); + + List> receiversDebited = parser.objectToList(refund.get("receiversDebited")); + assertEquals(10154, receiversDebited.get(0).get("amount")); + assertEquals("MPA-CULBBYHD11", receiversDebited.get(0).get("moipAccount")); + + assertEquals("FULL", refund.get("type")); + + Map refundingInstrument = parser.objectToMap(refund.get("refundingInstrument")); + Map creditCard = parser.objectToMap(refundingInstrument.get("creditCard")); + assertEquals("MASTERCARD", creditCard.get("brand")); + assertEquals("555566", creditCard.get("first6")); + assertEquals("8884", creditCard.get("last4")); + assertEquals(true, creditCard.get("store")); + + assertEquals("CREDIT_CARD", refundingInstrument.get("method")); + + assertEquals("2018-07-17T16:16:16.000-03", refund.get("createdAt")); + + Map links = parser.objectToMap(refund.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/refunds/REF-MYLT39W1ZWEU", self.get("href")); + + Map order = parser.objectToMap(links.get("order")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-BCLUATUQ8K4W", order.get("href")); + assertEquals("ORD-BCLUATUQ8K4W", order.get("title")); + + Map payment = parser.objectToMap(links.get("payment")); + assertEquals("https://sandbox.moip.com.br/v2/payments/PAY-FE5GR3YXP151", payment.get("href")); + assertEquals("PAY-FE5GR3YXP151", payment.get("title")); + } + + @Play("refund/partial_refund_payment") + @Test + public void partialRefundPaymentTest() { + + Map refund = Moip.API.refunds().refundPayment(body, "PAY-SB2B44QAXILI", setup); + + assertEquals("REF-1QXB9GKQJRNF", refund.get("id")); + assertEquals("COMPLETED", refund.get("status")); + + List> events = parser.objectToList(refund.get("events")); + + // events[0] + assertEquals("REFUND.COMPLETED", events.get(0).get("type")); + assertEquals("2018-07-17T16:26:09.000-03", events.get(0).get("createdAt")); + + // events[1] + assertEquals("REFUND.REQUESTED", events.get(1).get("type")); + assertEquals("2018-07-17T16:26:09.000-03", events.get(1).get("createdAt")); + + Map amount = parser.objectToMap(refund.get("amount")); + assertEquals(8500, amount.get("total")); + assertEquals(0, amount.get("fees")); + assertEquals("BRL", amount.get("currency")); + + List> receiversDebited = parser.objectToList(refund.get("receiversDebited")); + assertEquals(8500, receiversDebited.get(0).get("amount")); + assertEquals("MPA-CULBBYHD11", receiversDebited.get(0).get("moipAccount")); + + assertEquals("PARTIAL", refund.get("type")); + + Map refundingInstrument = parser.objectToMap(refund.get("refundingInstrument")); + Map creditCard = parser.objectToMap(refundingInstrument.get("creditCard")); + assertEquals("MASTERCARD", creditCard.get("brand")); + assertEquals("555566", creditCard.get("first6")); + assertEquals("8884", creditCard.get("last4")); + assertEquals(true, creditCard.get("store")); + + assertEquals("CREDIT_CARD", refundingInstrument.get("method")); + + assertEquals("2018-07-17T16:26:09.000-03", refund.get("createdAt")); + + Map links = parser.objectToMap(refund.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/refunds/REF-1QXB9GKQJRNF", self.get("href")); + + Map order = parser.objectToMap(links.get("order")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-FF9UACPDT5N6", order.get("href")); + assertEquals("ORD-FF9UACPDT5N6", order.get("title")); + + Map payment = parser.objectToMap(links.get("payment")); + assertEquals("https://sandbox.moip.com.br/v2/payments/PAY-SB2B44QAXILI", payment.get("href")); + assertEquals("PAY-SB2B44QAXILI", payment.get("title")); + } + + @Play("refund/partial_refund_order") + @Test + public void partialRefundOrderTest() { + + Map refund = Moip.API.refunds().refundOrder(body, "ORD-PCSMIB5VZWGN", setup); + + assertEquals("REF-ZRNB6YXA3DVN", refund.get("id")); + assertEquals("COMPLETED", refund.get("status")); + + List> events = parser.objectToList(refund.get("events")); + + // events[0] + assertEquals("REFUND.COMPLETED", events.get(0).get("type")); + assertEquals("2018-07-17T16:36:07.000-03", events.get(0).get("createdAt")); + + // events[1] + assertEquals("REFUND.REQUESTED", events.get(1).get("type")); + assertEquals("2018-07-17T16:36:06.000-03", events.get(1).get("createdAt")); + + Map amount = parser.objectToMap(refund.get("amount")); + assertEquals(8500, amount.get("total")); + assertEquals(0, amount.get("fees")); + assertEquals("BRL", amount.get("currency")); + + List> receiversDebited = parser.objectToList(refund.get("receiversDebited")); + assertEquals(8500, receiversDebited.get(0).get("amount")); + assertEquals("MPA-CULBBYHD11", receiversDebited.get(0).get("moipAccount")); + + assertEquals("PARTIAL", refund.get("type")); + + Map refundingInstrument = parser.objectToMap(refund.get("refundingInstrument")); + Map creditCard = parser.objectToMap(refundingInstrument.get("creditCard")); + assertEquals("MASTERCARD", creditCard.get("brand")); + assertEquals("555566", creditCard.get("first6")); + assertEquals("8884", creditCard.get("last4")); + assertEquals(true, creditCard.get("store")); + + assertEquals("CREDIT_CARD", refundingInstrument.get("method")); + + assertEquals("2018-07-17T16:36:06.000-03", refund.get("createdAt")); + + Map links = parser.objectToMap(refund.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/refunds/REF-ZRNB6YXA3DVN", self.get("href")); + + Map order = parser.objectToMap(links.get("order")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-PCSMIB5VZWGN", order.get("href")); + assertEquals("ORD-PCSMIB5VZWGN", order.get("title")); + + Map payment = parser.objectToMap(links.get("payment")); + assertEquals("https://sandbox.moip.com.br/v2/payments/PAY-NG0P224NUIWR", payment.get("href")); + assertEquals("PAY-NG0P224NUIWR", payment.get("title")); + } + + @Play("refund/get") + @Test + public void getRefundTest() { + + Map refund = Moip.API.refunds().get("REF-ZRNB6YXA3DVN", setup); + + assertEquals("REF-ZRNB6YXA3DVN", refund.get("id")); + assertEquals("COMPLETED", refund.get("status")); + + List> events = parser.objectToList(refund.get("events")); + + // events[0] + assertEquals("REFUND.COMPLETED", events.get(0).get("type")); + assertEquals("2018-07-17T16:36:07.000-03", events.get(0).get("createdAt")); + + // events[1] + assertEquals("REFUND.REQUESTED", events.get(1).get("type")); + assertEquals("2018-07-17T16:36:06.000-03", events.get(1).get("createdAt")); + + Map amount = parser.objectToMap(refund.get("amount")); + assertEquals(8500, amount.get("total")); + assertEquals(0, amount.get("fees")); + assertEquals("BRL", amount.get("currency")); + + List> receiversDebited = parser.objectToList(refund.get("receiversDebited")); + assertEquals(8500, receiversDebited.get(0).get("amount")); + assertEquals("MPA-CULBBYHD11", receiversDebited.get(0).get("moipAccount")); + + assertEquals("PARTIAL", refund.get("type")); + + Map refundingInstrument = parser.objectToMap(refund.get("refundingInstrument")); + Map creditCard = parser.objectToMap(refundingInstrument.get("creditCard")); + assertEquals("MASTERCARD", creditCard.get("brand")); + assertEquals("555566", creditCard.get("first6")); + assertEquals("8884", creditCard.get("last4")); + assertEquals(true, creditCard.get("store")); + + assertEquals("CREDIT_CARD", refundingInstrument.get("method")); + + assertEquals("2018-07-17T16:36:06.000-03", refund.get("createdAt")); + + Map links = parser.objectToMap(refund.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/refunds/REF-ZRNB6YXA3DVN", self.get("href")); + + Map order = parser.objectToMap(links.get("order")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-PCSMIB5VZWGN", order.get("href")); + assertEquals("ORD-PCSMIB5VZWGN", order.get("title")); + + Map payment = parser.objectToMap(links.get("payment")); + assertEquals("https://sandbox.moip.com.br/v2/payments/PAY-NG0P224NUIWR", payment.get("href")); + assertEquals("PAY-NG0P224NUIWR", payment.get("title")); + } + + @Play("refund/list_payment_refunds") + @Test + public void listPaymentRefundsTest() { + + Map listRefunds = Moip.API.refunds().listPaymentRefunds("PAY-NG0P224NUIWR", setup); + + List> refunds = parser.objectToList(listRefunds.get("refunds")); + + assertEquals("REF-ZRNB6YXA3DVN", refunds.get(0).get("id")); + assertEquals("COMPLETED", refunds.get(0).get("status")); + + List> events = parser.objectToList(refunds.get(0).get("events")); + + // events[0] + assertEquals("REFUND.COMPLETED", events.get(0).get("type")); + assertEquals("2018-07-17T16:36:07.000-03", events.get(0).get("createdAt")); + + // events[1] + assertEquals("REFUND.REQUESTED", events.get(1).get("type")); + assertEquals("2018-07-17T16:36:06.000-03", events.get(1).get("createdAt")); + + Map amount = parser.objectToMap(refunds.get(0).get("amount")); + assertEquals(8500, amount.get("total")); + assertEquals(0, amount.get("fees")); + assertEquals("BRL", amount.get("currency")); + + List> receiversDebited = parser.objectToList(refunds.get(0).get("receiversDebited")); + assertEquals(8500, receiversDebited.get(0).get("amount")); + assertEquals("MPA-CULBBYHD11", receiversDebited.get(0).get("moipAccount")); + + assertEquals("PARTIAL", refunds.get(0).get("type")); + + Map refundingInstrument = parser.objectToMap(refunds.get(0).get("refundingInstrument")); + Map creditCard = parser.objectToMap(refundingInstrument.get("creditCard")); + assertEquals("MASTERCARD", creditCard.get("brand")); + assertEquals("555566", creditCard.get("first6")); + assertEquals("8884", creditCard.get("last4")); + assertEquals(true, creditCard.get("store")); + + assertEquals("CREDIT_CARD", refundingInstrument.get("method")); + + assertEquals("2018-07-17T16:36:06.000-03", refunds.get(0).get("createdAt")); + + Map links = parser.objectToMap(refunds.get(0).get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/refunds/REF-ZRNB6YXA3DVN", self.get("href")); + + Map order = parser.objectToMap(links.get("order")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-PCSMIB5VZWGN", order.get("href")); + assertEquals("ORD-PCSMIB5VZWGN", order.get("title")); + + Map payment = parser.objectToMap(links.get("payment")); + assertEquals("https://sandbox.moip.com.br/v2/payments/PAY-NG0P224NUIWR", payment.get("href")); + assertEquals("PAY-NG0P224NUIWR", payment.get("title")); + } + + @Play("refund/list_order_refunds") + @Test + public void listOrderRefundsTest() { + + Map listRefunds = Moip.API.refunds().listOrderRefunds("ORD-PCSMIB5VZWGN", setup); + + List> refunds = parser.objectToList(listRefunds.get("refunds")); + + assertEquals("REF-ZRNB6YXA3DVN", refunds.get(0).get("id")); + assertEquals("COMPLETED", refunds.get(0).get("status")); + + List> events = parser.objectToList(refunds.get(0).get("events")); + + // events[0] + assertEquals("REFUND.COMPLETED", events.get(0).get("type")); + assertEquals("2018-07-17T16:36:07.000-03", events.get(0).get("createdAt")); + + // events[1] + assertEquals("REFUND.REQUESTED", events.get(1).get("type")); + assertEquals("2018-07-17T16:36:06.000-03", events.get(1).get("createdAt")); + + Map amount = parser.objectToMap(refunds.get(0).get("amount")); + assertEquals(8500, amount.get("total")); + assertEquals(0, amount.get("fees")); + assertEquals("BRL", amount.get("currency")); + + List> receiversDebited = parser.objectToList(refunds.get(0).get("receiversDebited")); + assertEquals(8500, receiversDebited.get(0).get("amount")); + assertEquals("MPA-CULBBYHD11", receiversDebited.get(0).get("moipAccount")); + + assertEquals("PARTIAL", refunds.get(0).get("type")); + + Map refundingInstrument = parser.objectToMap(refunds.get(0).get("refundingInstrument")); + Map creditCard = parser.objectToMap(refundingInstrument.get("creditCard")); + assertEquals("MASTERCARD", creditCard.get("brand")); + assertEquals("555566", creditCard.get("first6")); + assertEquals("8884", creditCard.get("last4")); + assertEquals(true, creditCard.get("store")); + + assertEquals("CREDIT_CARD", refundingInstrument.get("method")); + + assertEquals("2018-07-17T16:36:06.000-03", refunds.get(0).get("createdAt")); + + Map links = parser.objectToMap(refunds.get(0).get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/refunds/REF-ZRNB6YXA3DVN", self.get("href")); + + Map order = parser.objectToMap(links.get("order")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-PCSMIB5VZWGN", order.get("href")); + assertEquals("ORD-PCSMIB5VZWGN", order.get("title")); + + Map payment = parser.objectToMap(links.get("payment")); + assertEquals("https://sandbox.moip.com.br/v2/payments/PAY-NG0P224NUIWR", payment.get("href")); + assertEquals("PAY-NG0P224NUIWR", payment.get("title")); + } +} diff --git a/src/test/java/br/com/moip/unit_tests/setup/SetupFactory.java b/src/test/java/br/com/moip/unit_tests/setup/SetupFactory.java new file mode 100644 index 0000000..dce941c --- /dev/null +++ b/src/test/java/br/com/moip/unit_tests/setup/SetupFactory.java @@ -0,0 +1,17 @@ +package br.com.moip.unit_tests.setup; + +import br.com.moip.auth.Authentication; +import br.com.moip.auth.BasicAuth; +import br.com.moip.models.Setup; + +public class SetupFactory { + + private static final String token = "01010101010101010101010101010101"; + private static final String key = "ABABABABABABABABABABABABABABABABABABABAB"; + + private static final Authentication auth = new BasicAuth(token, key); + + public Setup setup(final String endpoint) { + return new Setup().setAuthentication(auth).setPlayerEndpoint(endpoint); + } +} diff --git a/src/test/resources/plays/customer/add_credit_card.yaml b/src/test/resources/plays/customer/add_credit_card.yaml new file mode 100644 index 0000000..5b2352e --- /dev/null +++ b/src/test/resources/plays/customer/add_credit_card.yaml @@ -0,0 +1,29 @@ +!play +interactions: +- + request: + uri: /v2/customers/CUS-Z83J8G3EMLIT/fundinginstruments + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "creditCard": { + "id": "CRC-9Y3RUBPCR30N", + "brand": "VISA", + "first6": "401200", + "last4": "1112", + "store": true + }, + "card": { + "brand": "VISA", + "store": true + }, + "isPresential": false, + "method": "CREDIT_CARD" + } diff --git a/src/test/resources/plays/customer/create.yaml b/src/test/resources/plays/customer/create.yaml new file mode 100644 index 0000000..54ff638 --- /dev/null +++ b/src/test/resources/plays/customer/create.yaml @@ -0,0 +1,48 @@ +!play +interactions: +- + request: + uri: /v2/customers + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "id": "CUS-Z83J8G3EMLIT", + "ownId": "moip_create_customer_unit_test", + "fullname": "SDK Java", + "createdAt": "2018-07-11T18:26:51.000-03", + "birthDate": "1980-05-10", + "email": "sdk.java@moip.com.br", + "phone": { + "countryCode": "55", + "areaCode": "11", + "number": "22226842" + }, + "taxDocument": { + "type": "CPF", + "number": "10013390023" + }, + "shippingAddress": { + "zipCode": "01451001", + "street": "Avenida Brigadeiro Faria Lima", + "streetNumber": "3064", + "city": "São Paulo", + "district": "Itaim Bibi", + "state": "SP", + "country": "BRA" + }, + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/customers/CUS-Z83J8G3EMLIT" + }, + "hostedAccount": { + "redirectHref": "https://hostedaccount-sandbox.moip.com.br?token=541a137d-f94a-4ab6-9e2b-40df67309c1b&id=CUS-Z83J8G3EMLIT&mpa=MPA-CULBBYHD11" + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/customer/create_with_funding_instrument.yaml b/src/test/resources/plays/customer/create_with_funding_instrument.yaml new file mode 100644 index 0000000..2dbfe5e --- /dev/null +++ b/src/test/resources/plays/customer/create_with_funding_instrument.yaml @@ -0,0 +1,70 @@ +!play +interactions: +- + request: + uri: /v2/customers + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "id": "CUS-35TX8MWZ6SVX", + "ownId": "moip_create_customer_unit_test", + "fullname": "SDK Java", + "createdAt": "2018-07-11T11:57:22.000-03", + "birthDate": "1980-05-10", + "email": "sdk.java@moip.com.br", + "fundingInstrument": { + "creditCard": { + "id": "CRC-7GKFB3S2R8SS", + "brand": "ELO", + "first6": "636297", + "last4": "7013", + "store": true + }, + "method": "CREDIT_CARD" + }, + "phone": { + "countryCode": "55", + "areaCode": "11", + "number": "22226842" + }, + "taxDocument": { + "type": "CPF", + "number": "10013390023" + }, + "shippingAddress": { + "zipCode": "01451001", + "street": "Avenida Brigadeiro Faria Lima", + "streetNumber": "3064", + "city": "São Paulo", + "district": "Itaim Bibi", + "state": "SP", + "country": "BRA" + }, + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/customers/CUS-35TX8MWZ6SVX" + }, + "hostedAccount": { + "redirectHref": "https://hostedaccount-sandbox.moip.com.br?token=69ec54c3-c6a1-4f04-953b-af7d0f0fbee0&id=CUS-35TX8MWZ6SVX&mpa=MPA-CULBBYHD11" + } + }, + "fundingInstruments": [ + { + "creditCard": { + "id": "CRC-7GKFB3S2R8SS", + "brand": "ELO", + "first6": "636297", + "last4": "7013", + "store": true + }, + "method": "CREDIT_CARD" + } + ] + } \ No newline at end of file diff --git a/src/test/resources/plays/customer/get.yaml b/src/test/resources/plays/customer/get.yaml new file mode 100644 index 0000000..b45f93f --- /dev/null +++ b/src/test/resources/plays/customer/get.yaml @@ -0,0 +1,48 @@ +!play +interactions: +- + request: + uri: /v2/customers/CUS-Z83J8G3EMLIT + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "id": "CUS-Z83J8G3EMLIT", + "ownId": "moip_create_customer_unit_test", + "fullname": "SDK Java", + "createdAt": "2018-07-11T18:26:51.000-03", + "birthDate": "1980-05-10", + "email": "sdk.java@moip.com.br", + "phone": { + "countryCode": "55", + "areaCode": "11", + "number": "22226842" + }, + "taxDocument": { + "type": "CPF", + "number": "10013390023" + }, + "shippingAddress": { + "zipCode": "01451001", + "street": "Avenida Brigadeiro Faria Lima", + "streetNumber": "3064", + "city": "São Paulo", + "district": "Itaim Bibi", + "state": "SP", + "country": "BRA" + }, + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/customers/CUS-Z83J8G3EMLIT" + }, + "hostedAccount": { + "redirectHref": "https://hostedaccount-sandbox.moip.com.br?token=541a137d-f94a-4ab6-9e2b-40df67309c1b&id=CUS-Z83J8G3EMLIT&mpa=MPA-CULBBYHD11" + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/customer/list.yaml b/src/test/resources/plays/customer/list.yaml new file mode 100644 index 0000000..dd99b81 --- /dev/null +++ b/src/test/resources/plays/customer/list.yaml @@ -0,0 +1,159 @@ +!play +interactions: +- + request: + uri: /v2/customers + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "customers": [ + { + "id": "CUS-GBQJHCRKF2ZJ", + "fullname": "Ray Batista", + "email": "r@mail.co", + "fundingInstrument": { + "creditCard": { + "id": "CRC-GX8ZN1HLBHU9", + "brand": "VISA", + "first6": "407302", + "last4": "0002", + "store": true + }, + "method": "CREDIT_CARD" + }, + "phone": { + "countryCode": "55", + "areaCode": "19", + "number": "33260064" + }, + "billingAddress": { + "zipCode": "13030-290", + "street": "Rua rio grande do sul", + "streetNumber": "0", + "complement": "s/n null", + "city": "Campinas", + "district": "Vila Santana", + "state": "São Paulo", + "country": "Brasil" + }, + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/customers/CUS-GBQJHCRKF2ZJ" + } + }, + "fundingInstruments": [ + { + "creditCard": { + "id": "CRC-GX8ZN1HLBHU9", + "brand": "VISA", + "first6": "407302", + "last4": "0002", + "store": true + }, + "method": "CREDIT_CARD" + } + ] + }, + { + "id": "CUS-U9JX31DJSX6O", + "fullname": "Ray Batista", + "email": "r@mail.co", + "fundingInstrument": { + "creditCard": { + "id": "CRC-QEQ0ZEC1WFCP", + "brand": "VISA", + "first6": "407302", + "last4": "0002", + "store": true + }, + "method": "CREDIT_CARD" + }, + "phone": { + "countryCode": "55", + "areaCode": "19", + "number": "33260064" + }, + "billingAddress": { + "zipCode": "13030-290", + "street": "Rua rio grande do sul", + "streetNumber": "0", + "complement": "s/n null", + "city": "Campinas", + "district": "Vila Santana", + "state": "São Paulo", + "country": "Brasil" + }, + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/customers/CUS-U9JX31DJSX6O" + } + }, + "fundingInstruments": [ + { + "creditCard": { + "id": "CRC-QEQ0ZEC1WFCP", + "brand": "VISA", + "first6": "407302", + "last4": "0002", + "store": true + }, + "method": "CREDIT_CARD" + } + ] + }, + { + "id": "CUS-J44P8K7QLVLS", + "fullname": "Ray Batista", + "email": "r@mail.co", + "fundingInstrument": { + "creditCard": { + "id": "CRC-VWO246R7BXKX", + "brand": "VISA", + "first6": "407302", + "last4": "0002", + "store": true + }, + "method": "CREDIT_CARD" + }, + "phone": { + "countryCode": "55", + "areaCode": "19", + "number": "33260064" + }, + "billingAddress": { + "zipCode": "13030-290", + "street": "Rua rio grande do sul", + "streetNumber": "0", + "complement": "s/n null", + "city": "Campinas", + "district": "Vila Santana", + "state": "São Paulo", + "country": "Brasil" + }, + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/customers/CUS-J44P8K7QLVLS" + } + }, + "fundingInstruments": [ + { + "creditCard": { + "id": "CRC-VWO246R7BXKX", + "brand": "VISA", + "first6": "407302", + "last4": "0002", + "store": true + }, + "method": "CREDIT_CARD" + } + ] + } + ] + } \ No newline at end of file diff --git a/src/test/resources/plays/notification/create_notification_preferences.yaml b/src/test/resources/plays/notification/create_notification_preferences.yaml new file mode 100644 index 0000000..4aad3b5 --- /dev/null +++ b/src/test/resources/plays/notification/create_notification_preferences.yaml @@ -0,0 +1,25 @@ +!play +interactions: +- + request: + uri: /v2/preferences/notifications + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "events": [ + "ORDER.*", + "PAYMENT.AUTHORIZED", + "PAYMENT.CANCELLED" + ], + "target": "http://requestb.in/1dhjesw1", + "media": "WEBHOOK", + "token": "1457cbc9e2ab4bc7a62ab24951a9a878", + "id": "NPR-LQCZEI6Q7I1G" + } \ No newline at end of file diff --git a/src/test/resources/plays/notification/get_notification_preferences.yaml b/src/test/resources/plays/notification/get_notification_preferences.yaml new file mode 100644 index 0000000..3af3a09 --- /dev/null +++ b/src/test/resources/plays/notification/get_notification_preferences.yaml @@ -0,0 +1,25 @@ +!play +interactions: +- + request: + uri: /v2/preferences/notifications/NPR-LQCZEI6Q7I1G + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "events": [ + "ORDER.*", + "PAYMENT.AUTHORIZED", + "PAYMENT.CANCELLED" + ], + "target": "http://requestb.in/1dhjesw1", + "media": "WEBHOOK", + "token": "1457cbc9e2ab4bc7a62ab24951a9a878", + "id": "NPR-LQCZEI6Q7I1G" + } \ No newline at end of file diff --git a/src/test/resources/plays/notification/get_webhooks.yaml b/src/test/resources/plays/notification/get_webhooks.yaml new file mode 100644 index 0000000..a5c6aa5 --- /dev/null +++ b/src/test/resources/plays/notification/get_webhooks.yaml @@ -0,0 +1,66 @@ +!play +interactions: +- + request: + uri: /v2/webhooks?resourceId=ORD-W496X7T9FVGZ + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "webhooks": [ + { + "resourceId": "ORD-W496X7T9FVGZ", + "event": "ORDER.PAID", + "url": "https://requestb.in/16pw5ncfjleofweojfewbl1", + "status": "FAILED", + "id": "EVE-VP3PTS0QP294", + "sentAt": "2018-07-17T18:11:07.473Z" + }, + { + "resourceId": "ORD-W496X7T9FVGZ", + "event": "ORDER.WAITING", + "url": "https://requestb.in/16pw5ncfjleofweojfewbl1", + "status": "FAILED", + "id": "EVE-YA8Z6XXDZJCY", + "sentAt": "2018-07-17T18:11:06.047Z" + }, + { + "resourceId": "ORD-W496X7T9FVGZ", + "event": "ORDER.CREATED", + "url": "https://requestb.in/16pw5ncfjleofweojfewbl1", + "status": "FAILED", + "id": "EVE-FXFWBXTD4CBM", + "sentAt": "2018-07-17T18:11:02.628Z" + }, + { + "resourceId": "ORD-W496X7T9FVGZ", + "event": "ORDER.PAID", + "url": "https://requestb.in/16pw5ncfjleofweojfewbl1", + "status": "FAILED", + "id": "EVE-Z0H3OSCO6CG4", + "sentAt": "2018-07-17T18:10:57.162Z" + }, + { + "resourceId": "ORD-W496X7T9FVGZ", + "event": "ORDER.WAITING", + "url": "https://requestb.in/16pw5ncfjleofweojfewbl1", + "status": "FAILED", + "id": "EVE-BM1MIMKDV6VR", + "sentAt": "2018-07-17T18:10:55.716Z" + }, + { + "resourceId": "ORD-W496X7T9FVGZ", + "event": "ORDER.CREATED", + "url": "https://requestb.in/16pw5ncfjleofweojfewbl1", + "status": "FAILED", + "id": "EVE-HR1TKRMBBV6P", + "sentAt": "2018-07-17T18:10:52.241Z" + } + ] + } \ No newline at end of file diff --git a/src/test/resources/plays/notification/list_notification_preferences.yaml b/src/test/resources/plays/notification/list_notification_preferences.yaml new file mode 100644 index 0000000..6a2f1b3 --- /dev/null +++ b/src/test/resources/plays/notification/list_notification_preferences.yaml @@ -0,0 +1,71 @@ +!play +interactions: +- + request: + uri: /v2/preferences/notifications + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + [ + { + "events": [ + "ORDER.*", + "PAYMENT.AUTHORIZED", + "PAYMENT.CANCELLED" + ], + "target": "http://my.uri/0", + "media": "WEBHOOK", + "token": "63c351458ccc4967aaa84f66a79c2be6", + "id": "NPR-O019G1CWTFV5" + }, + { + "events": [ + "ORDER.*", + "PAYMENT.AUTHORIZED", + "PAYMENT.CANCELLED" + ], + "target": "http://my.uri/1", + "media": "WEBHOOK", + "token": "688e2f2b75df4b968cad7d2b5c9c02d6", + "id": "NPR-AV7URX6E5OUF" + }, + { + "events": [ + "ORDER.*", + "PAYMENT.AUTHORIZED", + "PAYMENT.CANCELLED" + ], + "target": "http://my.uri/2", + "media": "WEBHOOK", + "token": "19160e43b6df4f58b31bfe57d291cb8a", + "id": "NPR-KCC2M2IYRQXJ" + }, + { + "events": [ + "ORDER.*", + "PAYMENT.AUTHORIZED", + "PAYMENT.CANCELLED" + ], + "target": "http://my.uri/3", + "media": "WEBHOOK", + "token": "a07451ff754449d18fedf60c6582e130", + "id": "NPR-GFD5Q9JP0JHO" + }, + { + "events": [ + "ORDER.*", + "PAYMENT.AUTHORIZED", + "PAYMENT.CANCELLED" + ], + "target": "http://my.uri/4", + "media": "WEBHOOK", + "token": "dc5c0470a44145baad470693b1ac7416", + "id": "NPR-F0TNENDS2PW0" + } + ] \ No newline at end of file diff --git a/src/test/resources/plays/notification/list_webhooks.yaml b/src/test/resources/plays/notification/list_webhooks.yaml new file mode 100644 index 0000000..ce1e3ca --- /dev/null +++ b/src/test/resources/plays/notification/list_webhooks.yaml @@ -0,0 +1,50 @@ +!play +interactions: +- + request: + uri: /v2/webhooks + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "webhooks": [ + { + "resourceId": "ORD-W496X7T9FVGZ", + "event": "ORDER.PAID", + "url": "https://requestb.in/16pw5ncfjleofweojfewbl1", + "status": "FAILED", + "id": "EVE-VP3PTS0QP294", + "sentAt": "2018-07-17T18:11:07.473Z" + }, + { + "resourceId": "PAY-NFSY35SXVCCN", + "event": "PAYMENT.AUTHORIZED", + "url": "https://requestb.in/16pw5ncfjleofweojfewbl1", + "status": "FAILED", + "id": "EVE-O8EC0FBUBBAP", + "sentAt": "2018-07-17T18:11:07.303Z" + }, + { + "resourceId": "PAY-NFSY35SXVCCN", + "event": "PAYMENT.IN_ANALYSIS", + "url": "https://requestb.in/16pw5ncfjleofweojfewbl1", + "status": "FAILED", + "id": "EVE-6QJN2PWF6SOD", + "sentAt": "2018-07-17T18:11:06.228Z" + }, + { + "resourceId": "ORD-W496X7T9FVGZ", + "event": "ORDER.WAITING", + "url": "https://requestb.in/16pw5ncfjleofweojfewbl1", + "status": "FAILED", + "id": "EVE-YA8Z6XXDZJCY", + "sentAt": "2018-07-17T18:11:06.047Z" + } + ] + } \ No newline at end of file diff --git a/src/test/resources/plays/notification/remove_notification_preferences.yaml b/src/test/resources/plays/notification/remove_notification_preferences.yaml new file mode 100644 index 0000000..4c40fef --- /dev/null +++ b/src/test/resources/plays/notification/remove_notification_preferences.yaml @@ -0,0 +1,14 @@ +!play +interactions: +- + request: + uri: /v2/preferences/notifications/NPR-KCC2M2IYRQXJ + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: DELETE + response: + status: 204 + headers: + "Content-Type": application/json + body: | \ No newline at end of file diff --git a/src/test/resources/plays/order/create.yaml b/src/test/resources/plays/order/create.yaml new file mode 100644 index 0000000..90b11eb --- /dev/null +++ b/src/test/resources/plays/order/create.yaml @@ -0,0 +1,177 @@ +!play +interactions: +- + request: + uri: /v2/orders + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "id": "ORD-A4HGZXSXARIV", + "ownId": "my_order_ownId", + "status": "CREATED", + "platform": "V2", + "createdAt": "2018-07-12T14:53:46.683-03", + "updatedAt": "2018-07-12T14:53:46.683-03", + "amount": { + "paid": 0, + "total": 11000, + "fees": 0, + "refunds": 0, + "liquid": 0, + "otherReceivers": 0, + "currency": "BRL", + "subtotals": { + "shipping": 1500, + "addition": 0, + "discount": 0, + "items": 9500 + } + }, + "items": [ + { + "product": "Descrição do pedido", + "price": 9500, + "detail": "Camiseta estampada branca", + "quantity": 1, + "category": "CLOTHING" + } + ], + "addresses": [ + { + "district": "Itaim Bibi", + "zipCode": "01451001", + "streetNumber": "3064", + "street": "Avenida Brigadeiro Faria Lima", + "city": "São Paulo", + "state": "SP", + "type": "SHIPPING", + "country": "BRA" + } + ], + "customer": { + "id": "CUS-35TX8MWZ6SVX", + "ownId": "moip_create_customer_unit_test", + "fullname": "SDK Java", + "createdAt": "2018-07-11T11:57:22.000-03", + "updatedAt": "2018-07-12T14:53:46.687-03", + "birthDate": "1980-05-10", + "email": "sdk.java@moip.com.br", + "fundingInstrument": { + "creditCard": { + "id": "CRC-7GKFB3S2R8SS", + "brand": "ELO", + "first6": "636297", + "last4": "7013", + "store": true + }, + "method": "CREDIT_CARD" + }, + "phone": { + "countryCode": "55", + "areaCode": "11", + "number": "22226842" + }, + "taxDocument": { + "type": "CPF", + "number": "10013390023" + }, + "addresses": [ + { + "district": "Itaim Bibi", + "zipCode": "01451001", + "streetNumber": "3064", + "street": "Avenida Brigadeiro Faria Lima", + "city": "São Paulo", + "state": "SP", + "type": "SHIPPING", + "country": "BRA" + } + ], + "shippingAddress": { + "zipCode": "01451001", + "street": "Avenida Brigadeiro Faria Lima", + "streetNumber": "3064", + "city": "São Paulo", + "district": "Itaim Bibi", + "state": "SP", + "country": "BRA" + }, + "moipAccount": { + "id": "MPA-8C2107EC8CCB" + }, + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/customers/CUS-35TX8MWZ6SVX" + }, + "hostedAccount": { + "redirectHref": "https://hostedaccount-sandbox.moip.com.br?token=69ec54c3-c6a1-4f04-953b-af7d0f0fbee0&id=CUS-35TX8MWZ6SVX&mpa=MPA-CULBBYHD11" + } + }, + "fundingInstruments": [ + { + "creditCard": { + "id": "CRC-7GKFB3S2R8SS", + "brand": "ELO", + "first6": "636297", + "last4": "7013", + "store": true + }, + "method": "CREDIT_CARD" + } + ] + }, + "payments": [], + "escrows": [], + "refunds": [], + "entries": [], + "events": [ + { + "type": "ORDER.CREATED", + "createdAt": "2018-07-12T14:53:46.683-03", + "description": "" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-CULBBYHD11", + "login": "integracao@labs.moip.com.br", + "fullname": "Moip SandBox" + }, + "type": "PRIMARY", + "amount": { + "total": 11000, + "currency": "BRL", + "fees": 0, + "refunds": 0 + }, + "feePayor": true + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-A4HGZXSXARIV" + }, + "checkout": { + "payCheckout": { + "redirectHref": "https://checkout-new-sandbox.moip.com.br?token=82678972-25ad-4d20-951a-ac9e384a6c04&id=ORD-A4HGZXSXARIV" + }, + "payCreditCard": { + "redirectHref": "https://checkout-new-sandbox.moip.com.br?token=82678972-25ad-4d20-951a-ac9e384a6c04&id=ORD-A4HGZXSXARIV&payment-method=credit-card" + }, + "payBoleto": { + "redirectHref": "https://checkout-new-sandbox.moip.com.br?token=82678972-25ad-4d20-951a-ac9e384a6c04&id=ORD-A4HGZXSXARIV&payment-method=boleto" + }, + "payOnlineBankDebitItau": { + "redirectHref": "https://checkout-sandbox.moip.com.br/debit/itau/ORD-A4HGZXSXARIV" + } + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/order/get.yaml b/src/test/resources/plays/order/get.yaml new file mode 100644 index 0000000..f44a2ee --- /dev/null +++ b/src/test/resources/plays/order/get.yaml @@ -0,0 +1,177 @@ +!play +interactions: +- + request: + uri: /v2/orders/ORD-A4HGZXSXARIV + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "id": "ORD-A4HGZXSXARIV", + "ownId": "my_order_ownId", + "status": "CREATED", + "platform": "V2", + "createdAt": "2018-07-12T14:53:46.000-03", + "updatedAt": "2018-07-12T14:53:46.000-03", + "amount": { + "paid": 0, + "total": 11000, + "fees": 0, + "refunds": 0, + "liquid": 0, + "otherReceivers": 0, + "currency": "BRL", + "subtotals": { + "shipping": 1500, + "addition": 0, + "discount": 0, + "items": 9500 + } + }, + "items": [ + { + "product": "Descrição do pedido", + "price": 9500, + "detail": "Camiseta estampada branca", + "quantity": 1, + "category": "CLOTHING" + } + ], + "addresses": [ + { + "district": "Itaim Bibi", + "zipCode": "01451001", + "streetNumber": "3064", + "street": "Avenida Brigadeiro Faria Lima", + "city": "São Paulo", + "state": "SP", + "type": "SHIPPING", + "country": "BRA" + } + ], + "customer": { + "id": "CUS-35TX8MWZ6SVX", + "ownId": "moip_create_customer_unit_test", + "fullname": "SDK Java", + "createdAt": "2018-07-11T11:57:22.000-03", + "updatedAt": "2018-07-12T14:53:46.000-03", + "birthDate": "1980-05-10", + "email": "sdk.java@moip.com.br", + "fundingInstrument": { + "creditCard": { + "id": "CRC-7GKFB3S2R8SS", + "brand": "ELO", + "first6": "636297", + "last4": "7013", + "store": true + }, + "method": "CREDIT_CARD" + }, + "phone": { + "countryCode": "55", + "areaCode": "11", + "number": "22226842" + }, + "taxDocument": { + "type": "CPF", + "number": "10013390023" + }, + "addresses": [ + { + "district": "Itaim Bibi", + "zipCode": "01451001", + "streetNumber": "3064", + "street": "Avenida Brigadeiro Faria Lima", + "city": "São Paulo", + "state": "SP", + "type": "SHIPPING", + "country": "BRA" + } + ], + "shippingAddress": { + "zipCode": "01451001", + "street": "Avenida Brigadeiro Faria Lima", + "streetNumber": "3064", + "city": "São Paulo", + "district": "Itaim Bibi", + "state": "SP", + "country": "BRA" + }, + "moipAccount": { + "id": "MPA-8C2107EC8CCB" + }, + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/customers/CUS-35TX8MWZ6SVX" + }, + "hostedAccount": { + "redirectHref": "https://hostedaccount-sandbox.moip.com.br?token=69ec54c3-c6a1-4f04-953b-af7d0f0fbee0&id=CUS-35TX8MWZ6SVX&mpa=MPA-CULBBYHD11" + } + }, + "fundingInstruments": [ + { + "creditCard": { + "id": "CRC-7GKFB3S2R8SS", + "brand": "ELO", + "first6": "636297", + "last4": "7013", + "store": true + }, + "method": "CREDIT_CARD" + } + ] + }, + "payments": [], + "escrows": [], + "refunds": [], + "entries": [], + "events": [ + { + "type": "ORDER.CREATED", + "createdAt": "2018-07-12T14:53:46.000-03", + "description": "" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-CULBBYHD11", + "login": "integracao@labs.moip.com.br", + "fullname": "Moip SandBox" + }, + "type": "PRIMARY", + "amount": { + "total": 11000, + "currency": "BRL", + "fees": 0, + "refunds": 0 + }, + "feePayor": true + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-A4HGZXSXARIV" + }, + "checkout": { + "payCheckout": { + "redirectHref": "https://checkout-new-sandbox.moip.com.br?token=82678972-25ad-4d20-951a-ac9e384a6c04&id=ORD-A4HGZXSXARIV" + }, + "payCreditCard": { + "redirectHref": "https://checkout-new-sandbox.moip.com.br?token=82678972-25ad-4d20-951a-ac9e384a6c04&id=ORD-A4HGZXSXARIV&payment-method=credit-card" + }, + "payBoleto": { + "redirectHref": "https://checkout-new-sandbox.moip.com.br?token=82678972-25ad-4d20-951a-ac9e384a6c04&id=ORD-A4HGZXSXARIV&payment-method=boleto" + }, + "payOnlineBankDebitItau": { + "redirectHref": "https://checkout-sandbox.moip.com.br/debit/itau/ORD-A4HGZXSXARIV" + } + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/order/list.yaml b/src/test/resources/plays/order/list.yaml new file mode 100644 index 0000000..08162e3 --- /dev/null +++ b/src/test/resources/plays/order/list.yaml @@ -0,0 +1,177 @@ +!play +interactions: +- + request: + uri: /v2/orders + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "_links": { + "next": { + "href": "https://test.moip.com.br/v2/orders?filters=&limit=0&offset=0" + }, + "previous": { + "href": "https://test.moip.com.br/v2/orders?filters=&limit=0&offset=0" + } + }, + "summary": { + "count": 48900, + "amount": 7750393812 + }, + "orders": [ + { + "id": "ORD-PPKTLN8RH25E", + "ownId": null, + "status": "NOT_PAID", + "blocked": false, + "amount": { + "total": 690, + "addition": 0, + "fees": 0, + "deduction": 0, + "otherReceivers": 0, + "currency": "BRL" + }, + "receivers": [ + { + "type": "PRIMARY", + "moipAccount": { + "id": "MPA-CULBBYHD11" + } + } + ], + "customer": { + "fullname": "ícaro raupp henrique", + "email": "icaro@bode.io" + }, + "items": [ + { + "product": null + } + ], + "payments": [ + { + "id": "PAY-RYMM1Y75ULVI", + "installmentCount": 1, + "fundingInstrument": { + "method": "CREDIT_CARD", + "brand": "VISA" + } + } + ], + "events": [], + "_links": { + "self": { + "href": "https://test.moip.com.br/v2/orders/ORD-PPKTLN8RH25E" + } + }, + "createdAt": "2018-07-12T19:37:41-0300", + "updatedAt": "2018-07-12T19:37:41-0300" + }, + { + "id": "ORD-6MER91AAJI4I", + "ownId": null, + "status": "NOT_PAID", + "blocked": false, + "amount": { + "total": 690, + "addition": 0, + "fees": 0, + "deduction": 0, + "otherReceivers": 0, + "currency": "BRL" + }, + "receivers": [ + { + "type": "PRIMARY", + "moipAccount": { + "id": "MPA-CULBBYHD11" + } + } + ], + "customer": { + "fullname": "ícaro raupp henrique", + "email": "icaro@bode.io" + }, + "items": [ + { + "product": null + } + ], + "payments": [ + { + "id": "PAY-YIMQW9VUSHG8", + "installmentCount": 1, + "fundingInstrument": { + "method": "CREDIT_CARD", + "brand": "VISA" + } + } + ], + "events": [], + "_links": { + "self": { + "href": "https://test.moip.com.br/v2/orders/ORD-6MER91AAJI4I" + } + }, + "createdAt": "2018-07-12T18:31:25-0300", + "updatedAt": "2018-07-12T18:31:25-0300" + }, + { + "id": "ORD-BN73SSJ1BO1K", + "ownId": null, + "status": "WAITING", + "blocked": false, + "amount": { + "total": 22000, + "addition": 0, + "fees": 0, + "deduction": 0, + "otherReceivers": 0, + "currency": "BRL" + }, + "receivers": [ + { + "type": "PRIMARY", + "moipAccount": { + "id": "MPA-CULBBYHD11" + } + } + ], + "customer": { + "fullname": "rafael mateus", + "email": "rafaelmateus@hotmail.com.br" + }, + "items": [ + { + "product": null + } + ], + "payments": [ + { + "id": "PAY-174FKBMG0OFD", + "installmentCount": 1, + "fundingInstrument": { + "method": "CREDIT_CARD", + "brand": "MASTERCARD" + } + } + ], + "events": [], + "_links": { + "self": { + "href": "https://test.moip.com.br/v2/orders/ORD-BN73SSJ1BO1K" + } + }, + "createdAt": "2018-07-12T14:15:38-0300", + "updatedAt": "2018-07-12T14:15:39-0300" + } + ] + } \ No newline at end of file diff --git a/src/test/resources/plays/order/list_order_payments.yaml b/src/test/resources/plays/order/list_order_payments.yaml new file mode 100644 index 0000000..92a704d --- /dev/null +++ b/src/test/resources/plays/order/list_order_payments.yaml @@ -0,0 +1,85 @@ +!play +interactions: +- + request: + uri: /v2/orders/ORD-BN73SSJ1BO1K/payments + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "payments": [ + { + "id": "PAY-174FKBMG0OFD", + "status": "IN_ANALYSIS", + "delayCapture": false, + "amount": { + "total": 22000, + "gross": 22000, + "fees": 1277, + "refunds": 0, + "liquid": 20723, + "currency": "BRL" + }, + "installmentCount": 1, + "fundingInstrument": { + "creditCard": { + "id": "CRC-TH09IN444CYO", + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true, + "holder": { + "birthdate": "1986-04-26", + "birthDate": "1986-04-26", + "taxDocument": { + "type": "UNKNOWN", + "number": "7847504910" + }, + "fullname": "Rafael Bosquetti Mateus" + } + }, + "method": "CREDIT_CARD" + }, + "acquirerDetails": { + "authorizationNumber": "T12996", + "taxDocument": { + "type": "CNPJ", + "number": "01027058000191" + } + }, + "fees": [ + { + "type": "TRANSACTION", + "amount": 1277 + } + ], + "events": [ + { + "type": "PAYMENT.IN_ANALYSIS", + "createdAt": "2018-07-12T14:15:39.000-03" + }, + { + "type": "PAYMENT.CREATED", + "createdAt": "2018-07-12T14:15:38.000-03" + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-174FKBMG0OFD" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-BN73SSJ1BO1K", + "title": "ORD-BN73SSJ1BO1K" + } + }, + "createdAt": "2018-07-12T14:15:38.000-03", + "updatedAt": "2018-07-12T14:15:39.000-03" + } + ] + } \ No newline at end of file diff --git a/src/test/resources/plays/payment/cancel_pre_authorized.yaml b/src/test/resources/plays/payment/cancel_pre_authorized.yaml new file mode 100644 index 0000000..d6e2731 --- /dev/null +++ b/src/test/resources/plays/payment/cancel_pre_authorized.yaml @@ -0,0 +1,125 @@ +!play +interactions: +- + request: + uri: /v2/payments/PAY-44R4XT17VP50/void + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: POST + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "id": "PAY-44R4XT17VP50", + "status": "CANCELLED", + "delayCapture": true, + "cancellationDetails": { + "code": "7", + "description": "Política do Moip", + "cancelledBy": "MOIP" + }, + "amount": { + "total": 11000, + "gross": 11000, + "fees": 1127, + "refunds": 0, + "liquid": 9873, + "currency": "BRL" + }, + "installmentCount": 3, + "statementDescriptor": "Minha Loja", + "fundingInstrument": { + "creditCard": { + "id": "CRC-CQC2YNRA6UUT", + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true, + "holder": { + "birthdate": "1988-12-30", + "birthDate": "1988-12-30", + "taxDocument": { + "type": "CPF", + "number": "78994193600" + }, + "billingAddress": { + "street": "Avenida Contorno", + "streetNumber": "400", + "district": "Savassi", + "city": "Belo Horizonte", + "state": "MG", + "country": "BRA", + "zipCode": "76932800" + }, + "fullname": "Roberto Oliveira" + } + }, + "method": "CREDIT_CARD" + }, + "acquirerDetails": { + "authorizationNumber": "123456", + "taxDocument": { + "type": "CNPJ", + "number": "01027058000191" + } + }, + "fees": [ + { + "type": "TRANSACTION", + "amount": 585 + }, + { + "type": "PRE_PAYMENT", + "amount": 542 + } + ], + "events": [ + { + "type": "PAYMENT.CANCELLED", + "createdAt": "2018-07-16T16:12:26.499-03" + }, + { + "type": "PAYMENT.PRE_AUTHORIZED", + "createdAt": "2018-07-16T16:12:12.000-03" + }, + { + "type": "PAYMENT.IN_ANALYSIS", + "createdAt": "2018-07-16T16:12:11.000-03" + }, + { + "type": "PAYMENT.CREATED", + "createdAt": "2018-07-16T16:11:50.000-03" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-CULBBYHD11", + "login": "integracao@labs.moip.com.br", + "fullname": "Moip SandBox" + }, + "type": "PRIMARY", + "amount": { + "total": 11000, + "currency": "BRL", + "fees": 0, + "refunds": 0 + }, + "feePayor": true + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-44R4XT17VP50" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-3Y3NR4PS4HVP", + "title": "ORD-3Y3NR4PS4HVP" + } + }, + "createdAt": "2018-07-16T16:11:50.000-03", + "updatedAt": "2018-07-16T16:12:26.498-03" + } \ No newline at end of file diff --git a/src/test/resources/plays/payment/capture_pre_authorized.yaml b/src/test/resources/plays/payment/capture_pre_authorized.yaml new file mode 100644 index 0000000..bc1e274 --- /dev/null +++ b/src/test/resources/plays/payment/capture_pre_authorized.yaml @@ -0,0 +1,120 @@ +!play +interactions: +- + request: + uri: /v2/payments/PAY-MMU64JJBUI6Z/capture + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: POST + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "id": "PAY-MMU64JJBUI6Z", + "status": "AUTHORIZED", + "delayCapture": true, + "amount": { + "total": 11000, + "gross": 11000, + "fees": 1127, + "refunds": 0, + "liquid": 9873, + "currency": "BRL" + }, + "installmentCount": 3, + "statementDescriptor": "Minha Loja", + "fundingInstrument": { + "creditCard": { + "id": "CRC-CQC2YNRA6UUT", + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true, + "holder": { + "birthdate": "1988-12-30", + "birthDate": "1988-12-30", + "taxDocument": { + "type": "CPF", + "number": "78994193600" + }, + "billingAddress": { + "street": "Avenida Contorno", + "streetNumber": "400", + "district": "Savassi", + "city": "Belo Horizonte", + "state": "MG", + "country": "BRA", + "zipCode": "76932800" + }, + "fullname": "Roberto Oliveira" + } + }, + "method": "CREDIT_CARD" + }, + "acquirerDetails": { + "authorizationNumber": "123456", + "taxDocument": { + "type": "CNPJ", + "number": "01027058000191" + } + }, + "fees": [ + { + "type": "TRANSACTION", + "amount": 585 + }, + { + "type": "PRE_PAYMENT", + "amount": 542 + } + ], + "events": [ + { + "type": "PAYMENT.AUTHORIZED", + "createdAt": "2018-07-16T15:51:49.583-03" + }, + { + "type": "PAYMENT.IN_ANALYSIS", + "createdAt": "2018-07-16T14:11:40.000-03" + }, + { + "type": "PAYMENT.PRE_AUTHORIZED", + "createdAt": "2018-07-16T14:11:40.000-03" + }, + { + "type": "PAYMENT.CREATED", + "createdAt": "2018-07-16T14:11:34.000-03" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-CULBBYHD11", + "login": "integracao@labs.moip.com.br", + "fullname": "Moip SandBox" + }, + "type": "PRIMARY", + "amount": { + "total": 11000, + "currency": "BRL", + "fees": 1127, + "refunds": 0 + }, + "feePayor": true + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-MMU64JJBUI6Z" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-J5F0JITE58DV", + "title": "ORD-J5F0JITE58DV" + } + }, + "createdAt": "2018-07-16T14:11:34.000-03", + "updatedAt": "2018-07-16T15:51:49.582-03" + } \ No newline at end of file diff --git a/src/test/resources/plays/payment/get.yaml b/src/test/resources/plays/payment/get.yaml new file mode 100644 index 0000000..104f37c --- /dev/null +++ b/src/test/resources/plays/payment/get.yaml @@ -0,0 +1,120 @@ +!play +interactions: +- + request: + uri: /v2/payments/PAY-MMU64JJBUI6Z + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "id": "PAY-MMU64JJBUI6Z", + "status": "AUTHORIZED", + "delayCapture": true, + "amount": { + "total": 11000, + "gross": 11000, + "fees": 1127, + "refunds": 0, + "liquid": 9873, + "currency": "BRL" + }, + "installmentCount": 3, + "statementDescriptor": "Minha Loja", + "fundingInstrument": { + "creditCard": { + "id": "CRC-CQC2YNRA6UUT", + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true, + "holder": { + "birthdate": "1988-12-30", + "birthDate": "1988-12-30", + "taxDocument": { + "type": "CPF", + "number": "78994193600" + }, + "billingAddress": { + "street": "Avenida Contorno", + "streetNumber": "400", + "district": "Savassi", + "city": "Belo Horizonte", + "state": "MG", + "country": "BRA", + "zipCode": "76932800" + }, + "fullname": "Roberto Oliveira" + } + }, + "method": "CREDIT_CARD" + }, + "acquirerDetails": { + "authorizationNumber": "123456", + "taxDocument": { + "type": "CNPJ", + "number": "01027058000191" + } + }, + "fees": [ + { + "type": "TRANSACTION", + "amount": 585 + }, + { + "type": "PRE_PAYMENT", + "amount": 542 + } + ], + "events": [ + { + "type": "PAYMENT.AUTHORIZED", + "createdAt": "2018-07-16T15:51:49.000-03" + }, + { + "type": "PAYMENT.IN_ANALYSIS", + "createdAt": "2018-07-16T14:11:40.000-03" + }, + { + "type": "PAYMENT.PRE_AUTHORIZED", + "createdAt": "2018-07-16T14:11:40.000-03" + }, + { + "type": "PAYMENT.CREATED", + "createdAt": "2018-07-16T14:11:34.000-03" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-CULBBYHD11", + "login": "integracao@labs.moip.com.br", + "fullname": "Moip SandBox" + }, + "type": "PRIMARY", + "amount": { + "total": 11000, + "currency": "BRL", + "fees": 1127, + "refunds": 0 + }, + "feePayor": true + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-MMU64JJBUI6Z" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-J5F0JITE58DV", + "title": "ORD-J5F0JITE58DV" + } + }, + "createdAt": "2018-07-16T14:11:34.000-03", + "updatedAt": "2018-07-16T15:51:49.000-03" + } \ No newline at end of file diff --git a/src/test/resources/plays/payment/payment_with_boleto.yaml b/src/test/resources/plays/payment/payment_with_boleto.yaml new file mode 100644 index 0000000..95440a3 --- /dev/null +++ b/src/test/resources/plays/payment/payment_with_boleto.yaml @@ -0,0 +1,89 @@ +!play +interactions: +- + request: + uri: /v2/orders/ORD-9S0XI6VIMTJ7/payments + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "id": "PAY-9SGAMYL775UX", + "status": "WAITING", + "delayCapture": false, + "amount": { + "total": 11000, + "gross": 11000, + "fees": 0, + "refunds": 0, + "liquid": 11000, + "currency": "BRL" + }, + "installmentCount": 1, + "fundingInstrument": { + "boleto": { + "expirationDate": "2020-06-20", + "lineCode": "00190.00009 01014.051005 00000.787176 7 72370000001000", + "logoUri": "http://www.lojaexemplo.com.br/logo.jpg", + "instructionLines": { + "first": "Atenção,", + "second": "fique atento à data de vencimento do boleto.", + "third": "Pague em qualquer casa lotérica." + } + }, + "method": "BOLETO" + }, + "fees": [ + { + "type": "TRANSACTION", + "amount": 0 + } + ], + "events": [ + { + "type": "PAYMENT.CREATED", + "createdAt": "2018-07-16T13:22:41.284-03" + }, + { + "type": "PAYMENT.WAITING", + "createdAt": "2018-07-16T13:22:41.284-03" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-CULBBYHD11", + "login": "integracao@labs.moip.com.br", + "fullname": "Moip SandBox" + }, + "type": "PRIMARY", + "amount": { + "total": 11000, + "currency": "BRL", + "fees": 0, + "refunds": 0 + }, + "feePayor": true + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-9SGAMYL775UX" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-9S0XI6VIMTJ7", + "title": "ORD-9S0XI6VIMTJ7" + }, + "payBoleto": { + "printHref": "https://sandbox.moip.com.br/v2/boleto/BOL-QW08VHD7QU31/print", + "redirectHref": "https://sandbox.moip.com.br/v2/boleto/BOL-QW08VHD7QU31" + } + }, + "createdAt": "2018-07-16T13:22:41.282-03", + "updatedAt": "2018-07-16T13:22:41.282-03" + } \ No newline at end of file diff --git a/src/test/resources/plays/payment/payment_with_credit_card.yaml b/src/test/resources/plays/payment/payment_with_credit_card.yaml new file mode 100644 index 0000000..55c34c8 --- /dev/null +++ b/src/test/resources/plays/payment/payment_with_credit_card.yaml @@ -0,0 +1,108 @@ +!play +interactions: +- + request: + uri: /v2/orders/ORD-MA1UMH2OJQIO/payments + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "id": "PAY-WVCZZYDPRF22", + "status": "IN_ANALYSIS", + "delayCapture": false, + "amount": { + "total": 11000, + "gross": 11000, + "fees": 0, + "refunds": 0, + "liquid": 11000, + "currency": "BRL" + }, + "installmentCount": 1, + "statementDescriptor": "minhaLoja.com", + "fundingInstrument": { + "creditCard": { + "id": "CRC-CQC2YNRA6UUT", + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true, + "holder": { + "birthdate": "1988-12-30", + "birthDate": "1988-12-30", + "taxDocument": { + "type": "CPF", + "number": "33333333333" + }, + "fullname": "Teste Portador da Silva" + } + }, + "method": "CREDIT_CARD" + }, + "acquirerDetails": { + "authorizationNumber": "123456", + "taxDocument": { + "type": "CNPJ", + "number": "01027058000191" + } + }, + "fees": [ + { + "type": "TRANSACTION", + "amount": 0 + } + ], + "events": [ + { + "type": "PAYMENT.IN_ANALYSIS", + "createdAt": "2018-07-16T11:22:52.568-03" + }, + { + "type": "PAYMENT.CREATED", + "createdAt": "2018-07-16T11:22:50.088-03" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-CULBBYHD11", + "login": "integracao@labs.moip.com.br", + "fullname": "Moip SandBox" + }, + "type": "PRIMARY", + "amount": { + "total": 11000, + "currency": "BRL", + "fees": 0, + "refunds": 0 + }, + "feePayor": true + } + ], + "device": { + "ip": "127.0.0.1", + "geolocation": { + "latitude": -33.867, + "longitude": 151.206 + }, + "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36", + "fingerprint": "QAZXswedCVGrtgBNHyujMKIkolpQAZXswedCVGrtgBNHyujMKIkolpQAZXswedCVGrtgBNHyujMKIkolpQAZXswedCVGrtgBNHyujMKIkolp" + }, + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-WVCZZYDPRF22" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-MA1UMH2OJQIO", + "title": "ORD-MA1UMH2OJQIO" + } + }, + "createdAt": "2018-07-16T11:22:50.061-03", + "updatedAt": "2018-07-16T11:22:52.568-03" + } \ No newline at end of file diff --git a/src/test/resources/plays/payment/payment_with_online_bank_debit.yaml b/src/test/resources/plays/payment/payment_with_online_bank_debit.yaml new file mode 100644 index 0000000..ed6ff73 --- /dev/null +++ b/src/test/resources/plays/payment/payment_with_online_bank_debit.yaml @@ -0,0 +1,83 @@ +!play +interactions: +- + request: + uri: /v2/orders/ORD-GVEF677TOU7D/payments + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "id": "PAY-SKEH9F7N532S", + "status": "WAITING", + "delayCapture": false, + "amount": { + "total": 11000, + "gross": 11000, + "fees": 277, + "refunds": 0, + "liquid": 10723, + "currency": "BRL" + }, + "installmentCount": 1, + "fundingInstrument": { + "method": "ONLINE_BANK_DEBIT", + "onlineBankDebit": { + "bankNumber": "341", + "expirationDate": "2018-11-22", + "bankName": "BANCO ITAU S.A." + } + }, + "fees": [ + { + "type": "TRANSACTION", + "amount": 277 + } + ], + "events": [ + { + "type": "PAYMENT.CREATED", + "createdAt": "2018-07-16T13:52:06.138-03" + }, + { + "type": "PAYMENT.WAITING", + "createdAt": "2018-07-16T13:52:06.138-03" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-CULBBYHD11", + "login": "integracao@labs.moip.com.br", + "fullname": "Moip SandBox" + }, + "type": "PRIMARY", + "amount": { + "total": 11000, + "currency": "BRL", + "fees": 0, + "refunds": 0 + }, + "feePayor": true + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-SKEH9F7N532S" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-GVEF677TOU7D", + "title": "ORD-GVEF677TOU7D" + }, + "payOnlineBankDebitItau": { + "redirectHref": "https://checkout-sandbox.moip.com.br/debit/itau/PAY-SKEH9F7N532S" + } + }, + "createdAt": "2018-07-16T13:52:06.136-03", + "updatedAt": "2018-07-16T13:52:06.136-03" + } \ No newline at end of file diff --git a/src/test/resources/plays/payment/pre_authorized_payment.yaml b/src/test/resources/plays/payment/pre_authorized_payment.yaml new file mode 100644 index 0000000..5dc93ba --- /dev/null +++ b/src/test/resources/plays/payment/pre_authorized_payment.yaml @@ -0,0 +1,108 @@ +!play +interactions: +- + request: + uri: /v2/orders/ORD-J5F0JITE58DV/payments + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "id": "PAY-MMU64JJBUI6Z", + "status": "IN_ANALYSIS", + "delayCapture": true, + "amount": { + "total": 11000, + "gross": 11000, + "fees": 0, + "refunds": 0, + "liquid": 11000, + "currency": "BRL" + }, + "installmentCount": 3, + "statementDescriptor": "Minha Loja", + "fundingInstrument": { + "creditCard": { + "id": "CRC-CQC2YNRA6UUT", + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true, + "holder": { + "birthdate": "1988-12-30", + "birthDate": "1988-12-30", + "taxDocument": { + "type": "CPF", + "number": "78994193600" + }, + "billingAddress": { + "street": "Avenida Contorno", + "streetNumber": "400", + "district": "Savassi", + "city": "Belo Horizonte", + "state": "MG", + "country": "BRA", + "zipCode": "76932800" + }, + "fullname": "Roberto Oliveira" + } + }, + "method": "CREDIT_CARD" + }, + "acquirerDetails": { + "authorizationNumber": "123456", + "taxDocument": { + "type": "CNPJ", + "number": "01027058000191" + } + }, + "fees": [ + { + "type": "TRANSACTION", + "amount": 0 + } + ], + "events": [ + { + "type": "PAYMENT.IN_ANALYSIS", + "createdAt": "2018-07-16T14:11:40.090-03" + }, + { + "type": "PAYMENT.CREATED", + "createdAt": "2018-07-16T14:11:34.179-03" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-CULBBYHD11", + "login": "integracao@labs.moip.com.br", + "fullname": "Moip SandBox" + }, + "type": "PRIMARY", + "amount": { + "total": 11000, + "currency": "BRL", + "fees": 0, + "refunds": 0 + }, + "feePayor": true + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-MMU64JJBUI6Z" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-J5F0JITE58DV", + "title": "ORD-J5F0JITE58DV" + } + }, + "createdAt": "2018-07-16T14:11:34.152-03", + "updatedAt": "2018-07-16T14:11:40.090-03" + } \ No newline at end of file diff --git a/src/test/resources/plays/refund/full_refund_order.yaml b/src/test/resources/plays/refund/full_refund_order.yaml new file mode 100644 index 0000000..6eb5b06 --- /dev/null +++ b/src/test/resources/plays/refund/full_refund_order.yaml @@ -0,0 +1,63 @@ +!play +interactions: +- + request: + uri: /v2/orders/ORD-BCLUATUQ8K4W/refunds + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "id": "REF-MYLT39W1ZWEU", + "status": "COMPLETED", + "events": [ + { + "type": "REFUND.COMPLETED", + "createdAt": "2018-07-17T16:16:16.000-03" + }, + { + "type": "REFUND.REQUESTED", + "createdAt": "2018-07-17T16:16:16.000-03" + } + ], + "amount": { + "total": 11000, + "fees": 0, + "currency": "BRL" + }, + "receiversDebited": [ + { + "amount": 10154, + "moipAccount": "MPA-CULBBYHD11" + } + ], + "type": "FULL", + "refundingInstrument": { + "creditCard": { + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true + }, + "method": "CREDIT_CARD" + }, + "createdAt": "2018-07-17T16:16:16.000-03", + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/refunds/REF-MYLT39W1ZWEU" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-BCLUATUQ8K4W", + "title": "ORD-BCLUATUQ8K4W" + }, + "payment": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-FE5GR3YXP151", + "title": "PAY-FE5GR3YXP151" + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/refund/full_refund_payment.yaml b/src/test/resources/plays/refund/full_refund_payment.yaml new file mode 100644 index 0000000..88aec45 --- /dev/null +++ b/src/test/resources/plays/refund/full_refund_payment.yaml @@ -0,0 +1,63 @@ +!play +interactions: +- + request: + uri: /v2/payments/PAY-MMU64JJBUI6Z/refunds + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "id": "REF-DBM34ELHHHS6", + "status": "COMPLETED", + "events": [ + { + "type": "REFUND.COMPLETED", + "createdAt": "2018-07-17T14:13:22.000-03" + }, + { + "type": "REFUND.REQUESTED", + "createdAt": "2018-07-17T14:13:22.000-03" + } + ], + "amount": { + "total": 11000, + "fees": 0, + "currency": "BRL" + }, + "receiversDebited": [ + { + "amount": 9873, + "moipAccount": "MPA-CULBBYHD11" + } + ], + "type": "FULL", + "refundingInstrument": { + "creditCard": { + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true + }, + "method": "CREDIT_CARD" + }, + "createdAt": "2018-07-17T14:13:22.000-03", + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/refunds/REF-DBM34ELHHHS6" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-J5F0JITE58DV", + "title": "ORD-J5F0JITE58DV" + }, + "payment": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-MMU64JJBUI6Z", + "title": "PAY-MMU64JJBUI6Z" + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/refund/get.yaml b/src/test/resources/plays/refund/get.yaml new file mode 100644 index 0000000..d634287 --- /dev/null +++ b/src/test/resources/plays/refund/get.yaml @@ -0,0 +1,63 @@ +!play +interactions: +- + request: + uri: /v2/refunds/REF-ZRNB6YXA3DVN + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "id": "REF-ZRNB6YXA3DVN", + "status": "COMPLETED", + "events": [ + { + "type": "REFUND.COMPLETED", + "createdAt": "2018-07-17T16:36:07.000-03" + }, + { + "type": "REFUND.REQUESTED", + "createdAt": "2018-07-17T16:36:06.000-03" + } + ], + "amount": { + "total": 8500, + "fees": 0, + "currency": "BRL" + }, + "receiversDebited": [ + { + "amount": 8500, + "moipAccount": "MPA-CULBBYHD11" + } + ], + "type": "PARTIAL", + "refundingInstrument": { + "creditCard": { + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true + }, + "method": "CREDIT_CARD" + }, + "createdAt": "2018-07-17T16:36:06.000-03", + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/refunds/REF-ZRNB6YXA3DVN" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-PCSMIB5VZWGN", + "title": "ORD-PCSMIB5VZWGN" + }, + "payment": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-NG0P224NUIWR", + "title": "PAY-NG0P224NUIWR" + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/refund/list_order_refunds.yaml b/src/test/resources/plays/refund/list_order_refunds.yaml new file mode 100644 index 0000000..4eb25ef --- /dev/null +++ b/src/test/resources/plays/refund/list_order_refunds.yaml @@ -0,0 +1,67 @@ +!play +interactions: +- + request: + uri: /v2/orders/ORD-PCSMIB5VZWGN/refunds + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "refunds": [ + { + "id": "REF-ZRNB6YXA3DVN", + "status": "COMPLETED", + "events": [ + { + "type": "REFUND.COMPLETED", + "createdAt": "2018-07-17T16:36:07.000-03" + }, + { + "type": "REFUND.REQUESTED", + "createdAt": "2018-07-17T16:36:06.000-03" + } + ], + "amount": { + "total": 8500, + "fees": 0, + "currency": "BRL" + }, + "receiversDebited": [ + { + "amount": 8500, + "moipAccount": "MPA-CULBBYHD11" + } + ], + "type": "PARTIAL", + "refundingInstrument": { + "creditCard": { + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true + }, + "method": "CREDIT_CARD" + }, + "createdAt": "2018-07-17T16:36:06.000-03", + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/refunds/REF-ZRNB6YXA3DVN" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-PCSMIB5VZWGN", + "title": "ORD-PCSMIB5VZWGN" + }, + "payment": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-NG0P224NUIWR", + "title": "PAY-NG0P224NUIWR" + } + } + } + ] + } \ No newline at end of file diff --git a/src/test/resources/plays/refund/list_payment_refunds.yaml b/src/test/resources/plays/refund/list_payment_refunds.yaml new file mode 100644 index 0000000..15bf5b9 --- /dev/null +++ b/src/test/resources/plays/refund/list_payment_refunds.yaml @@ -0,0 +1,67 @@ +!play +interactions: +- + request: + uri: /v2/payments/PAY-NG0P224NUIWR/refunds + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "refunds": [ + { + "id": "REF-ZRNB6YXA3DVN", + "status": "COMPLETED", + "events": [ + { + "type": "REFUND.COMPLETED", + "createdAt": "2018-07-17T16:36:07.000-03" + }, + { + "type": "REFUND.REQUESTED", + "createdAt": "2018-07-17T16:36:06.000-03" + } + ], + "amount": { + "total": 8500, + "fees": 0, + "currency": "BRL" + }, + "receiversDebited": [ + { + "amount": 8500, + "moipAccount": "MPA-CULBBYHD11" + } + ], + "type": "PARTIAL", + "refundingInstrument": { + "creditCard": { + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true + }, + "method": "CREDIT_CARD" + }, + "createdAt": "2018-07-17T16:36:06.000-03", + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/refunds/REF-ZRNB6YXA3DVN" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-PCSMIB5VZWGN", + "title": "ORD-PCSMIB5VZWGN" + }, + "payment": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-NG0P224NUIWR", + "title": "PAY-NG0P224NUIWR" + } + } + } + ] + } \ No newline at end of file diff --git a/src/test/resources/plays/refund/partial_refund_order.yaml b/src/test/resources/plays/refund/partial_refund_order.yaml new file mode 100644 index 0000000..b4b6f28 --- /dev/null +++ b/src/test/resources/plays/refund/partial_refund_order.yaml @@ -0,0 +1,63 @@ +!play +interactions: +- + request: + uri: /v2/orders/ORD-PCSMIB5VZWGN/refunds + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "id": "REF-ZRNB6YXA3DVN", + "status": "COMPLETED", + "events": [ + { + "type": "REFUND.COMPLETED", + "createdAt": "2018-07-17T16:36:07.000-03" + }, + { + "type": "REFUND.REQUESTED", + "createdAt": "2018-07-17T16:36:06.000-03" + } + ], + "amount": { + "total": 8500, + "fees": 0, + "currency": "BRL" + }, + "receiversDebited": [ + { + "amount": 8500, + "moipAccount": "MPA-CULBBYHD11" + } + ], + "type": "PARTIAL", + "refundingInstrument": { + "creditCard": { + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true + }, + "method": "CREDIT_CARD" + }, + "createdAt": "2018-07-17T16:36:06.000-03", + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/refunds/REF-ZRNB6YXA3DVN" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-PCSMIB5VZWGN", + "title": "ORD-PCSMIB5VZWGN" + }, + "payment": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-NG0P224NUIWR", + "title": "PAY-NG0P224NUIWR" + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/refund/partial_refund_payment.yaml b/src/test/resources/plays/refund/partial_refund_payment.yaml new file mode 100644 index 0000000..2caaf57 --- /dev/null +++ b/src/test/resources/plays/refund/partial_refund_payment.yaml @@ -0,0 +1,63 @@ +!play +interactions: +- + request: + uri: /v2/payments/PAY-SB2B44QAXILI/refunds + headers: + Content-Type: application/json + Authorization: Basic MDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDEwMTAxMDE6QUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQkFCQUJBQg== + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "id": "REF-1QXB9GKQJRNF", + "status": "COMPLETED", + "events": [ + { + "type": "REFUND.COMPLETED", + "createdAt": "2018-07-17T16:26:09.000-03" + }, + { + "type": "REFUND.REQUESTED", + "createdAt": "2018-07-17T16:26:09.000-03" + } + ], + "amount": { + "total": 8500, + "fees": 0, + "currency": "BRL" + }, + "receiversDebited": [ + { + "amount": 8500, + "moipAccount": "MPA-CULBBYHD11" + } + ], + "type": "PARTIAL", + "refundingInstrument": { + "creditCard": { + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true + }, + "method": "CREDIT_CARD" + }, + "createdAt": "2018-07-17T16:26:09.000-03", + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/refunds/REF-1QXB9GKQJRNF" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-FF9UACPDT5N6", + "title": "ORD-FF9UACPDT5N6" + }, + "payment": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-SB2B44QAXILI", + "title": "PAY-SB2B44QAXILI" + } + } + } \ No newline at end of file diff --git a/src/test/resources/simplelogger.properties b/src/test/resources/simplelogger.properties new file mode 100644 index 0000000..eafa2b0 --- /dev/null +++ b/src/test/resources/simplelogger.properties @@ -0,0 +1 @@ +org.slf4j.simpleLogger.defaultLogLevel=debug \ No newline at end of file