From e81bd7c8f22e07b1971d2574bebf27aa21187030 Mon Sep 17 00:00:00 2001 From: "Matheus B. Nakaya" Date: Tue, 21 Aug 2018 15:42:14 -0300 Subject: [PATCH] [RELEASE] v1.0.0-beta --- README.md | 2 +- build.gradle | 2 +- .../java/br/com/moip/api/APIResources.java | 77 ++- .../br/com/moip/api/request/RequestMaker.java | 4 - .../br/com/moip/api/response/Response.java | 28 +- .../java/br/com/moip/models/Accounts.java | 183 ++++++ .../java/br/com/moip/models/Balances.java | 37 ++ .../java/br/com/moip/models/BankAccounts.java | 92 +++ src/main/java/br/com/moip/models/Connect.java | 95 ++++ .../models/{Customer.java => Customers.java} | 12 +- src/main/java/br/com/moip/models/Entries.java | 60 ++ src/main/java/br/com/moip/models/Escrows.java | 38 ++ .../java/br/com/moip/models/Multiorders.java | 91 +++ .../br/com/moip/models/Multipayments.java | 84 +++ ...ence.java => NotificationPreferences.java} | 10 +- .../moip/models/{Order.java => Orders.java} | 10 +- .../models/{Payment.java => Payments.java} | 12 +- .../moip/models/{Refund.java => Refunds.java} | 16 +- .../java/br/com/moip/models/Transfers.java | 106 ++++ .../models/{Webhook.java => Webhooks.java} | 12 +- .../moip/integration_tests/ConnectTest.java | 50 ++ .../moip/integration_tests/CustomerTest.java | 1 - .../moip/integration_tests/RefundTest.java | 2 +- .../br/com/moip/unit_tests/AccountTest.java | 348 ++++++++++++ .../br/com/moip/unit_tests/BalancesTest.java | 48 ++ .../com/moip/unit_tests/BankAccountTest.java | 120 ++++ .../br/com/moip/unit_tests/ConnectTest.java | 77 +++ .../br/com/moip/unit_tests/CustomerTest.java | 2 +- .../br/com/moip/unit_tests/EntryTest.java | 167 ++++++ .../br/com/moip/unit_tests/EscrowTest.java | 54 ++ .../com/moip/unit_tests/MultiorderTest.java | 535 ++++++++++++++++++ .../com/moip/unit_tests/MultipaymentTest.java | 197 +++++++ .../com/moip/unit_tests/NotificationTest.java | 2 +- .../br/com/moip/unit_tests/OrderTest.java | 2 +- .../br/com/moip/unit_tests/PaymentTest.java | 2 +- .../br/com/moip/unit_tests/RefundTest.java | 2 +- .../br/com/moip/unit_tests/TransferTest.java | 226 ++++++++ .../moip/unit_tests/setup/SetupFactory.java | 14 +- .../account/check_existence_by_email.yaml | 15 + .../check_existence_by_tax_document.yaml | 15 + .../plays/account/create_bank_account.yaml | 39 ++ .../account/create_classical_account.yaml | 99 ++++ .../account/create_transparent_account.yaml | 65 +++ src/test/resources/plays/account/get.yaml | 91 +++ .../resources/plays/account/get_keys.yaml | 23 + .../plays/account/list_bank_accounts.yaml | 66 +++ src/test/resources/plays/balances/get.yaml | 35 ++ src/test/resources/plays/bankaccount/get.yaml | 39 ++ .../resources/plays/bankaccount/update.yaml | 39 ++ .../plays/connect/generate_access_token.yaml | 25 + .../plays/connect/refresh_access_token.yaml | 25 + src/test/resources/plays/entry/get.yaml | 56 ++ src/test/resources/plays/entry/list.yaml | 95 ++++ src/test/resources/plays/escrow/release.yaml | 35 ++ .../resources/plays/multiorder/create.yaml | 362 ++++++++++++ src/test/resources/plays/multiorder/get.yaml | 362 ++++++++++++ .../multiorder/pay_with_credit_card.yaml | 214 +++++++ .../multipayment/cancel_pre_authorized.yaml | 265 +++++++++ .../multipayment/capture_pre_authorized.yaml | 240 ++++++++ .../resources/plays/multipayment/get.yaml | 232 ++++++++ src/test/resources/plays/transfer/create.yaml | 78 +++ src/test/resources/plays/transfer/get.yaml | 114 ++++ src/test/resources/plays/transfer/list.yaml | 78 +++ src/test/resources/plays/transfer/revert.yaml | 54 ++ 64 files changed, 5498 insertions(+), 83 deletions(-) create mode 100644 src/main/java/br/com/moip/models/Accounts.java create mode 100644 src/main/java/br/com/moip/models/Balances.java create mode 100644 src/main/java/br/com/moip/models/BankAccounts.java create mode 100644 src/main/java/br/com/moip/models/Connect.java rename src/main/java/br/com/moip/models/{Customer.java => Customers.java} (95%) create mode 100644 src/main/java/br/com/moip/models/Entries.java create mode 100644 src/main/java/br/com/moip/models/Escrows.java create mode 100644 src/main/java/br/com/moip/models/Multiorders.java create mode 100644 src/main/java/br/com/moip/models/Multipayments.java rename src/main/java/br/com/moip/models/{NotificationPreference.java => NotificationPreferences.java} (93%) rename src/main/java/br/com/moip/models/{Order.java => Orders.java} (95%) rename src/main/java/br/com/moip/models/{Payment.java => Payments.java} (96%) rename src/main/java/br/com/moip/models/{Refund.java => Refunds.java} (95%) create mode 100644 src/main/java/br/com/moip/models/Transfers.java rename src/main/java/br/com/moip/models/{Webhook.java => Webhooks.java} (86%) create mode 100644 src/test/java/br/com/moip/integration_tests/ConnectTest.java create mode 100644 src/test/java/br/com/moip/unit_tests/AccountTest.java create mode 100644 src/test/java/br/com/moip/unit_tests/BalancesTest.java create mode 100644 src/test/java/br/com/moip/unit_tests/BankAccountTest.java create mode 100644 src/test/java/br/com/moip/unit_tests/ConnectTest.java create mode 100644 src/test/java/br/com/moip/unit_tests/EntryTest.java create mode 100644 src/test/java/br/com/moip/unit_tests/EscrowTest.java create mode 100644 src/test/java/br/com/moip/unit_tests/MultiorderTest.java create mode 100644 src/test/java/br/com/moip/unit_tests/MultipaymentTest.java create mode 100644 src/test/java/br/com/moip/unit_tests/TransferTest.java create mode 100644 src/test/resources/plays/account/check_existence_by_email.yaml create mode 100644 src/test/resources/plays/account/check_existence_by_tax_document.yaml create mode 100644 src/test/resources/plays/account/create_bank_account.yaml create mode 100644 src/test/resources/plays/account/create_classical_account.yaml create mode 100644 src/test/resources/plays/account/create_transparent_account.yaml create mode 100644 src/test/resources/plays/account/get.yaml create mode 100644 src/test/resources/plays/account/get_keys.yaml create mode 100644 src/test/resources/plays/account/list_bank_accounts.yaml create mode 100644 src/test/resources/plays/balances/get.yaml create mode 100644 src/test/resources/plays/bankaccount/get.yaml create mode 100644 src/test/resources/plays/bankaccount/update.yaml create mode 100644 src/test/resources/plays/connect/generate_access_token.yaml create mode 100644 src/test/resources/plays/connect/refresh_access_token.yaml create mode 100644 src/test/resources/plays/entry/get.yaml create mode 100644 src/test/resources/plays/entry/list.yaml create mode 100644 src/test/resources/plays/escrow/release.yaml create mode 100644 src/test/resources/plays/multiorder/create.yaml create mode 100644 src/test/resources/plays/multiorder/get.yaml create mode 100644 src/test/resources/plays/multiorder/pay_with_credit_card.yaml create mode 100644 src/test/resources/plays/multipayment/cancel_pre_authorized.yaml create mode 100644 src/test/resources/plays/multipayment/capture_pre_authorized.yaml create mode 100644 src/test/resources/plays/multipayment/get.yaml create mode 100644 src/test/resources/plays/transfer/create.yaml create mode 100644 src/test/resources/plays/transfer/get.yaml create mode 100644 src/test/resources/plays/transfer/list.yaml create mode 100644 src/test/resources/plays/transfer/revert.yaml diff --git a/README.md b/README.md index 444b8c9..efa9c9a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# moip-sdk-java-2 +# moip-sdk-java diff --git a/build.gradle b/build.gradle index 58c4aa1..a5e11df 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ apply plugin: 'signing' group 'br.com.moip' archivesBaseName = "sdk-java" -version '0.1.0' +version '1.0.0-beta' description = "Java SDK for Moip APIs integration" diff --git a/src/main/java/br/com/moip/api/APIResources.java b/src/main/java/br/com/moip/api/APIResources.java index 2db03a1..8945f29 100644 --- a/src/main/java/br/com/moip/api/APIResources.java +++ b/src/main/java/br/com/moip/api/APIResources.java @@ -1,35 +1,66 @@ 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; +import br.com.moip.models.Customers; +import br.com.moip.models.Orders; +import br.com.moip.models.Payments; +import br.com.moip.models.Refunds; +import br.com.moip.models.NotificationPreferences; +import br.com.moip.models.Webhooks; +import br.com.moip.models.Accounts; +import br.com.moip.models.Connect; +import br.com.moip.models.Multiorders; +import br.com.moip.models.Multipayments; +import br.com.moip.models.BankAccounts; +import br.com.moip.models.Balances; +import br.com.moip.models.Entries; +import br.com.moip.models.Transfers; +import br.com.moip.models.Escrows; 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(); + private static Customers customerInstance = new Customers(); + private static Orders orderInstance = new Orders(); + private static Payments paymentInstance = new Payments(); + private static Refunds refundInstance = new Refunds(); + private static NotificationPreferences notificationPreferenceInstance = new NotificationPreferences(); + private static Webhooks webhookInstance = new Webhooks(); + private static Accounts accountInstance = new Accounts(); + private static Connect connectInstance = new Connect(); + private static Multiorders multiorderInstance = new Multiorders(); + private static Multipayments multipaymentsInstance = new Multipayments(); + private static BankAccounts bankAccountsInstance = new BankAccounts(); + private static Balances balancesInstance = new Balances(); + private static Entries entriesInstance = new Entries(); + private static Transfers transfersInstance = new Transfers(); + private static Escrows escrowsInstance = new Escrows(); - /** - * This method is used to get a instance of customer object. - * - * @return {@code Customer} - */ - public static Customer customers() { return customerInstance; } + public static Customers customers() { return customerInstance; } - public static Order orders() { return orderInstance; } + public static Orders orders() { return orderInstance; } - public static Payment payments() { return paymentInstance; } + public static Payments payments() { return paymentInstance; } - public static Refund refunds() { return refundInstance; } + public static Refunds refunds() { return refundInstance; } - public static NotificationPreference notificationPreferences() { return notificationPreferenceInstance; } + public static NotificationPreferences notificationPreferences() { return notificationPreferenceInstance; } - public static Webhook webhooks() { return webhookInstance; } + public static Webhooks webhooks() { return webhookInstance; } + + public static Accounts accounts() { return accountInstance; } + + public static Connect connect() { return connectInstance; } + + public static Multiorders multiorders() { return multiorderInstance; } + + public static Multipayments multipayments() { return multipaymentsInstance; } + + public static BankAccounts bankAccounts() { return bankAccountsInstance; } + + public static Balances balances() { return balancesInstance; } + + public static Entries entries() { return entriesInstance; } + + public static Transfers transfers() { return transfersInstance; } + + public static Escrows escrows() { return escrowsInstance; } } diff --git a/src/main/java/br/com/moip/api/request/RequestMaker.java b/src/main/java/br/com/moip/api/request/RequestMaker.java index fe2ef8b..bfb0a68 100644 --- a/src/main/java/br/com/moip/api/request/RequestMaker.java +++ b/src/main/java/br/com/moip/api/request/RequestMaker.java @@ -92,8 +92,6 @@ public Map doRequest(final RequestProperties requestProps) { 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); @@ -108,8 +106,6 @@ public Map doRequest(final RequestProperties requestProps) { wr.close(); } - // ---------------------------------------------------------------------------------------------- - LOGGER.debug("---> END HTTP"); int responseCode = connection.getResponseCode(); diff --git a/src/main/java/br/com/moip/api/response/Response.java b/src/main/java/br/com/moip/api/response/Response.java index 7c81047..7697a9e 100644 --- a/src/main/java/br/com/moip/api/response/Response.java +++ b/src/main/java/br/com/moip/api/response/Response.java @@ -23,6 +23,26 @@ public class Response extends HashMap { * @return {@code Map} */ public Map jsonToMap(String json) { + + /* + * This if block treats the /v2/accounts/exists response. Currently the endpoint returns the status + * code on its response body, breaking the JSON conversion. + */ + if ("200".equals(json)) { + this.responseBody.put("code", 200); + return this.responseBody; + } + + if ("400".equals(json)) { + this.responseBody.put("code", 400); + return this.responseBody; + } + + if ("404".equals(json)) { + this.responseBody.put("code", 404); + return this.responseBody; + } + if (!json.equals("")) { ObjectMapper mapper = new ObjectMapper(); try { @@ -49,11 +69,3 @@ public List> jsonToList(String json) { 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/models/Accounts.java b/src/main/java/br/com/moip/models/Accounts.java new file mode 100644 index 0000000..d6c69a4 --- /dev/null +++ b/src/main/java/br/com/moip/models/Accounts.java @@ -0,0 +1,183 @@ +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 Accounts { + + private static final String ENDPOINT = "/v2/accounts"; + private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON; + private RequestMaker requestMaker; + + /** + * This method is used to validate the argument of bellow method, if probably it's a tax document or not. + * + * @param argument + * {@code String} the received argument. + * + * @return {@code boolean} + */ + private boolean isTaxDocument(String argument) { + try { + Integer.parseInt(argument.substring(0,1)); + } catch (Exception ex) { + return false; + } + return true; + } + + /** + * This method allows you to check if a person already has a Moip account, by it's tax document or e-mail. + * The tax document must be write with punctuation, for example: 123.456.789-00. + * + * @param argument + * {@code String} the person's tax document or e-mail. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map checkExistence(String argument, Setup setup) { + this.requestMaker = new RequestMaker(setup); + String argumentType; + + if (isTaxDocument(argument)) argumentType = "tax_document"; + + else argumentType = "email"; + + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(String.format("%s/exists?%s=%s", ENDPOINT, argumentType, argument)) + .type(Accounts.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method allows you to create a Moip account (classical or transparent). To differentiate the + * two accounts types you have to set the boolean attribute {@code transparentAccount}, true value + * (you will create a transparent accounts) or false value (you will create a classical accounts). + * + * @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(Accounts.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to get a created accounts by Moip account external ID. + * + * @param id + * {@code String} the Moip account external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map get(String id, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(String.format("%s/%s", ENDPOINT, id)) + .type(Accounts.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to get the Basic Auth keys and the public key of a Moip account. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map getKeys(Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint("/v2/keys") + .type(Accounts.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method allows you to create a bank account to a Moip account. You can use a bank account to make + * transfers and refunds on Moip. + * + * @param body + * {@code Map} the request body. + * + * @param moipAccountId + * {@code String} the Moip account external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map createBankAccount(Map body, String moipAccountId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("POST") + .endpoint(String.format("%s/%s/bankaccounts", ENDPOINT, moipAccountId)) + .body(body) + .type(Accounts.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method allows you to list all bank account of a Moip account. + * + * @param moipAccountId + * {@code String} the Moip account external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public List> listBankAccounts(String moipAccountId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(String.format("%s/%s/bankaccounts", ENDPOINT, moipAccountId)) + .type(BankAccounts.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.getList(props); + } +} diff --git a/src/main/java/br/com/moip/models/Balances.java b/src/main/java/br/com/moip/models/Balances.java new file mode 100644 index 0000000..d648a6d --- /dev/null +++ b/src/main/java/br/com/moip/models/Balances.java @@ -0,0 +1,37 @@ +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 Balances { + + private static final String ENDPOINT = "/v2/balances"; + private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON; + private RequestMaker requestMaker; + + /** + * This method is used to get the balances values of a Moip account (unavailable, future, current). The + * request uses the accept version {@code 2.1}. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map get(Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(ENDPOINT) + .type(Balances.class) + .contentType(CONTENT_TYPE) + .accept("2.1") + .build(); + + return this.requestMaker.doRequest(props); + } +} diff --git a/src/main/java/br/com/moip/models/BankAccounts.java b/src/main/java/br/com/moip/models/BankAccounts.java new file mode 100644 index 0000000..341afbe --- /dev/null +++ b/src/main/java/br/com/moip/models/BankAccounts.java @@ -0,0 +1,92 @@ +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 BankAccounts { + + private static final String ENDPOINT = "/v2/bankaccounts"; + private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON; + private RequestMaker requestMaker; + + /** + * This method allows you to get the data of a created bank account by its Moip external ID. + * + * @param bankAccountId + * {@code String} the Moip bank account external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map get(String bankAccountId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(String.format("%s/%s", ENDPOINT, bankAccountId)) + .type(BankAccounts.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method allows you to update a created bank account. To make it, you have to send only the attributes + * that you want to change with its new values. For example, if you want to change the agencyNumber 12345 to + * 54321 and the agencyCheckNumber 4 to 6: + * {@code "agencyNumber": "54321"} + * {@code "agencyCheckNumber": "6"} + * + * @param body + * {@code Map} + */ + public Map update(Map body, String bankAccountId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("PUT") + .endpoint(String.format("%s/%s", ENDPOINT, bankAccountId)) + .body(body) + .type(BankAccounts.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method allows you to delete a created bank account by its Moip external ID. + * + * @param bankAccountId + * {@code String} the Moip bank account external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map delete(String bankAccountId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("DELETE") + .endpoint(String.format("%s/%s", ENDPOINT, bankAccountId)) + .type(BankAccounts.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } +} diff --git a/src/main/java/br/com/moip/models/Connect.java b/src/main/java/br/com/moip/models/Connect.java new file mode 100644 index 0000000..690f167 --- /dev/null +++ b/src/main/java/br/com/moip/models/Connect.java @@ -0,0 +1,95 @@ +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 Connect { + + private static final String ENDPOINT = "/oauth/token"; + private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_FORM_URLENCODED; + private RequestMaker requestMaker; + + /** + * This method is used to build the URL to request access permission for your seller. + * + * @param clientId + * {@code String} the APP ID. + * + * @param redirectUri + * {@code String} the address that you want to redirect your user after they grant the permission. + * + * @param scope + * {@code String array} the array of permissions that you want to request. + * Ex: RECEIVE_FUNDS, MANAGE_ACCOUNT_INFO, TRANSFER_FUNDS... + * + * @return {@code String} + */ + public String buildUrl(String clientId, String redirectUri, String[] scope) { + String url = "https://connect-sandbox.moip.com.br/oauth/authorize"; + + url += String.format("?response_type=code&client_id=%s&redirect_uri=%s&scope=", clientId, redirectUri); + + for (Integer index = 0; index < scope.length; ++index) { + + url += scope[index]; + + if ((index + 1) < scope.length) url += ','; + } + return url; + } + + /** + * This method allows you to generate access token for a Moip account. With this access token, you can + * make some request involving more than one Moip account. Before generate it, you must request + * access permission for your user to get the code returned on response to generate the token. + * + * @param body + * {@code Map} the request body. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map generateAccessToken(Map body, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("POST") + .endpoint(ENDPOINT) + .body(body) + .type(Connect.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method allows you to refresh the access token of a Moip account, if you lost the token + * or it has expired. + * + * @param body + * {@code Map} the request body. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map refreshAccessToken(Map body, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("POST") + .endpoint(ENDPOINT) + .body(body) + .type(Connect.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } +} diff --git a/src/main/java/br/com/moip/models/Customer.java b/src/main/java/br/com/moip/models/Customers.java similarity index 95% rename from src/main/java/br/com/moip/models/Customer.java rename to src/main/java/br/com/moip/models/Customers.java index ce153fa..c105422 100644 --- a/src/main/java/br/com/moip/models/Customer.java +++ b/src/main/java/br/com/moip/models/Customers.java @@ -7,7 +7,7 @@ import java.util.Map; -public class Customer { +public class Customers { private static final String ENDPOINT = "/v2/customers"; private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON; @@ -31,7 +31,7 @@ public Map create(Map body, Setup setup) { .method("POST") .endpoint(ENDPOINT) .body(body) - .type(Customer.class) + .type(Customers.class) .contentType(CONTENT_TYPE); return this.requestMaker.doRequest(props); @@ -57,7 +57,7 @@ public Map addCreditCard(Map body, String custom .method("POST") .endpoint(String.format("%s/%s/fundinginstruments", ENDPOINT, customerId)) .body(body) - .type(Customer.class) + .type(Customers.class) .contentType(CONTENT_TYPE) .build(); @@ -80,7 +80,7 @@ public Map deleteCreditCard(String creditCardId, Setup setup) { RequestProperties props = new RequestPropertiesBuilder() .method("DELETE") .endpoint(String.format("/v2/fundinginstruments/%s", creditCardId)) - .type(Customer.class) + .type(Customers.class) .contentType(CONTENT_TYPE) .build(); @@ -103,7 +103,7 @@ public Map get(String customerId, Setup setup) { RequestProperties props = new RequestPropertiesBuilder() .method("GET") .endpoint(String.format("%s/%s", ENDPOINT, customerId)) - .type(Customer.class) + .type(Customers.class) .contentType(CONTENT_TYPE) .build(); @@ -123,7 +123,7 @@ public Map list(Setup setup) { RequestProperties props = new RequestPropertiesBuilder() .method("GET") .endpoint(ENDPOINT) - .type(Customer.class) + .type(Customers.class) .contentType(CONTENT_TYPE) .build(); diff --git a/src/main/java/br/com/moip/models/Entries.java b/src/main/java/br/com/moip/models/Entries.java new file mode 100644 index 0000000..ef2119e --- /dev/null +++ b/src/main/java/br/com/moip/models/Entries.java @@ -0,0 +1,60 @@ +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 Entries { + + private static final String ENDPOINT = "/v2/entries"; + private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON; + private RequestMaker requestMaker; + + /** + * This method allows you to get the entry data by its Moip external ID. + * + * @param entryId + * {@code String} the Moip entry external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map get(String entryId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(String.format("%s/%s", ENDPOINT, entryId)) + .type(Entries.class) + .contentType(CONTENT_TYPE) + .accept("2.1") + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to list all entries. + * + * @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(Entries.class) + .contentType(CONTENT_TYPE) + .accept("2.1") + .build(); + + return this.requestMaker.doRequest(props); + } +} diff --git a/src/main/java/br/com/moip/models/Escrows.java b/src/main/java/br/com/moip/models/Escrows.java new file mode 100644 index 0000000..f08eb4f --- /dev/null +++ b/src/main/java/br/com/moip/models/Escrows.java @@ -0,0 +1,38 @@ +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 Escrows { + + private static final String ENDPOINT = "/v2/escrows"; + private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON; + private RequestMaker requestMaker; + + /** + * This method allows you to release a payment with escrow. + * + * @param escrowId + * {@code String} the Moip escrow external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map release(String escrowId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("POST") + .endpoint(String.format("%s/%s/release", ENDPOINT, escrowId)) + .type(Escrows.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } +} diff --git a/src/main/java/br/com/moip/models/Multiorders.java b/src/main/java/br/com/moip/models/Multiorders.java new file mode 100644 index 0000000..908920f --- /dev/null +++ b/src/main/java/br/com/moip/models/Multiorders.java @@ -0,0 +1,91 @@ +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 Multiorders { + + private static final String ENDPOINT = "/v2/multiorders"; + private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON; + private RequestMaker requestMaker; + + /** + * This method allows you to create a multiorder. The multiorder is a collection of orders, its used to + * transact with different sellers in the same shop cart. + * + * @param body + * {@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(Multiorders.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to create a multipayment, it means create a payment for each order from a multiorder + * with the same funding instrument (credit card, boleto, online bank debit). + * + * @param body + * {@code Map} the request body. + * + * @param multiorderId + * {@code String} the Moip multiorder external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map pay(Map body, String multiorderId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("POST") + .endpoint(String.format("%s/%s/multipayments", ENDPOINT, multiorderId)) + .body(body) + .type(Multipayments.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to get a created multiorder by Moip multiorder external ID. + * + * @param id + * {@code String} the Moip multiorder external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map get(String id, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(String.format("%s/%s", ENDPOINT, id)) + .type(Multiorders.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } +} diff --git a/src/main/java/br/com/moip/models/Multipayments.java b/src/main/java/br/com/moip/models/Multipayments.java new file mode 100644 index 0000000..4917d96 --- /dev/null +++ b/src/main/java/br/com/moip/models/Multipayments.java @@ -0,0 +1,84 @@ +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 Multipayments { + + private static final String ENDPOINT = "/v2/multipayments"; + private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON; + private RequestMaker requestMaker; + + /** + * This method is used to capture a pre-authorized multipayment by its Moip multipayment external ID. + * + * @param multipaymentId + * {@code String} the Moip multipayment external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map capturePreAuthorized(String multipaymentId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("POST") + .endpoint(String.format("%s/%s/capture", ENDPOINT, multipaymentId)) + .type(Multipayments.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to cancel a pre-authorized multipayment by its Moip multipayment external ID. + * + * @param multipaymentId + * {@code String} the Moip multipayment external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map cancelPreAuthorized(String multipaymentId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("POST") + .endpoint(String.format("%s/%s/void", ENDPOINT, multipaymentId)) + .type(Multipayments.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method allows you to get the data of a created multipayment by its Moip multipayment external ID. + * + * @param multipaymentId + * {@code String} the Moip multipayment external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map get(String multipaymentId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(String.format("%s/%s", ENDPOINT, multipaymentId)) + .type(Multipayments.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/NotificationPreferences.java similarity index 93% rename from src/main/java/br/com/moip/models/NotificationPreference.java rename to src/main/java/br/com/moip/models/NotificationPreferences.java index 31b153c..ada231f 100644 --- a/src/main/java/br/com/moip/models/NotificationPreference.java +++ b/src/main/java/br/com/moip/models/NotificationPreferences.java @@ -8,7 +8,7 @@ import java.util.List; import java.util.Map; -public class NotificationPreference { +public class NotificationPreferences { private static final String ENDPOINT = "/v2/preferences/notifications"; private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON; @@ -31,7 +31,7 @@ public Map create(Map body, Setup setup) { .method("POST") .endpoint(ENDPOINT) .body(body) - .type(NotificationPreference.class) + .type(NotificationPreferences.class) .contentType(CONTENT_TYPE) .build(); @@ -54,7 +54,7 @@ public Map get(String notificationPreferenceId, Setup setup) { RequestProperties props = new RequestPropertiesBuilder() .method("GET") .endpoint(String.format("%s/%s", ENDPOINT, notificationPreferenceId)) - .type(NotificationPreference.class) + .type(NotificationPreferences.class) .contentType(CONTENT_TYPE) .build(); @@ -74,7 +74,7 @@ public List> list(Setup setup) { RequestProperties props = new RequestPropertiesBuilder() .method("GET") .endpoint(ENDPOINT) - .type(NotificationPreference.class) + .type(NotificationPreferences.class) .contentType(CONTENT_TYPE) .build(); @@ -97,7 +97,7 @@ public Map remove(String notificationPreferenceId, Setup setup) RequestProperties props = new RequestPropertiesBuilder() .method("DELETE") .endpoint(String.format("%s/%s", ENDPOINT, notificationPreferenceId)) - .type(NotificationPreference.class) + .type(NotificationPreferences.class) .contentType(CONTENT_TYPE) .build(); diff --git a/src/main/java/br/com/moip/models/Order.java b/src/main/java/br/com/moip/models/Orders.java similarity index 95% rename from src/main/java/br/com/moip/models/Order.java rename to src/main/java/br/com/moip/models/Orders.java index fb46d1a..45887fd 100644 --- a/src/main/java/br/com/moip/models/Order.java +++ b/src/main/java/br/com/moip/models/Orders.java @@ -7,7 +7,7 @@ import java.util.Map; -public class Order { +public class Orders { private static final String ENDPOINT = "/v2/orders"; private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON; @@ -30,7 +30,7 @@ public Map create(Map body, Setup setup) { .method("POST") .endpoint(ENDPOINT) .body(body) - .type(Order.class) + .type(Orders.class) .contentType(CONTENT_TYPE) .build(); @@ -53,7 +53,7 @@ public Map get(String orderId, Setup setup) { RequestProperties props = new RequestPropertiesBuilder() .method("GET") .endpoint(String.format("%s/%s", ENDPOINT, orderId)) - .type(Order.class) + .type(Orders.class) .contentType(CONTENT_TYPE) .build(); @@ -73,7 +73,7 @@ public Map list(Setup setup) { RequestProperties props = new RequestPropertiesBuilder() .method("GET") .endpoint(ENDPOINT) - .type(Order.class) + .type(Orders.class) .contentType(CONTENT_TYPE) .build(); @@ -96,7 +96,7 @@ public Map listOrderPayments(String orderId, Setup setup) { RequestProperties props = new RequestPropertiesBuilder() .method("GET") .endpoint(String.format("%s/%s/payments", ENDPOINT, orderId)) - .type(Order.class) + .type(Orders.class) .contentType(CONTENT_TYPE) .build(); diff --git a/src/main/java/br/com/moip/models/Payment.java b/src/main/java/br/com/moip/models/Payments.java similarity index 96% rename from src/main/java/br/com/moip/models/Payment.java rename to src/main/java/br/com/moip/models/Payments.java index 0b1b9f4..9ed2e99 100644 --- a/src/main/java/br/com/moip/models/Payment.java +++ b/src/main/java/br/com/moip/models/Payments.java @@ -12,7 +12,7 @@ import static br.com.moip.Moip.SANDBOX_URL; -public class Payment { +public class Payments { private static final String ENDPOINT = "/v2/payments"; private static final String ENDPOINT_TO_PAY = "/v2/orders/%s/payments"; @@ -41,7 +41,7 @@ public Map pay(Map body, String orderId, Setup s .method("POST") .endpoint(String.format(ENDPOINT_TO_PAY, orderId)) .body(body) - .type(Payment.class) + .type(Payments.class) .contentType(CONTENT_TYPE) .build(); @@ -64,7 +64,7 @@ public Map capturePreAuthorized(String paymentId, Setup setup) { RequestProperties props = new RequestPropertiesBuilder() .method("POST") .endpoint(String.format("%s/%s/capture", ENDPOINT, paymentId)) - .type(Payment.class) + .type(Payments.class) .contentType(CONTENT_TYPE) .build(); @@ -87,7 +87,7 @@ public Map cancelPreAuthorized(String paymentId, Setup setup) { RequestProperties props = new RequestPropertiesBuilder() .method("POST") .endpoint(String.format("%s/%s/void", ENDPOINT, paymentId)) - .type(Payment.class) + .type(Payments.class) .contentType(CONTENT_TYPE) .build(); @@ -110,7 +110,7 @@ public Map get(String paymentId, Setup setup) { RequestProperties props = new RequestPropertiesBuilder() .method("GET") .endpoint(String.format("%s/%s", ENDPOINT, paymentId)) - .type(Payment.class) + .type(Payments.class) .contentType(CONTENT_TYPE) .build(); @@ -140,7 +140,7 @@ public Map authorize(String paymentId, int amount, Setup setup) RequestProperties props = new RequestPropertiesBuilder() .method("GET") .endpoint(String.format("%s?payment_id=%s&amount=%s", ENDPOINT_TO_AUTHORIZE, paymentId, amount)) - .type(Payment.class) + .type(Payments.class) .contentType(CONTENT_TYPE) .build(); diff --git a/src/main/java/br/com/moip/models/Refund.java b/src/main/java/br/com/moip/models/Refunds.java similarity index 95% rename from src/main/java/br/com/moip/models/Refund.java rename to src/main/java/br/com/moip/models/Refunds.java index a044fed..1855a8c 100644 --- a/src/main/java/br/com/moip/models/Refund.java +++ b/src/main/java/br/com/moip/models/Refunds.java @@ -7,7 +7,7 @@ import java.util.Map; -public class Refund { +public class Refunds { private static final String ENDPOINT = "/v2/refunds/%s"; private static final String ENDPOINT_REFUND_ORDER = "/v2/orders/%s/refunds"; @@ -32,7 +32,7 @@ public Map refundPayment(String paymentId, Setup setup) { RequestProperties props = new RequestPropertiesBuilder() .method("POST") .endpoint(String.format(ENDPOINT_REFUND_PAYMENT, paymentId)) - .type(Refund.class) + .type(Refunds.class) .contentType(CONTENT_TYPE) .build(); @@ -59,7 +59,7 @@ public Map refundPayment(Map body, String paymen .method("POST") .endpoint(String.format(ENDPOINT_REFUND_PAYMENT, paymentId)) .body(body) - .type(Refund.class) + .type(Refunds.class) .contentType(CONTENT_TYPE) .build(); @@ -83,7 +83,7 @@ public Map refundOrder(String orderId, Setup setup) { RequestProperties props = new RequestPropertiesBuilder() .method("POST") .endpoint(String.format(ENDPOINT_REFUND_ORDER, orderId)) - .type(Refund.class) + .type(Refunds.class) .contentType(CONTENT_TYPE) .build(); @@ -110,7 +110,7 @@ public Map refundOrder(Map body, String orderId, .method("POST") .endpoint(String.format(ENDPOINT_REFUND_ORDER, orderId)) .body(body) - .type(Refund.class) + .type(Refunds.class) .contentType(CONTENT_TYPE) .build(); @@ -133,7 +133,7 @@ public Map get(String refundId, Setup setup) { RequestProperties props = new RequestPropertiesBuilder() .method("GET") .endpoint(String.format(ENDPOINT, refundId)) - .type(Refund.class) + .type(Refunds.class) .contentType(CONTENT_TYPE) .build(); @@ -156,7 +156,7 @@ public Map listPaymentRefunds(String paymentId, Setup setup) { RequestProperties props = new RequestPropertiesBuilder() .method("GET") .endpoint(String.format(ENDPOINT_REFUND_PAYMENT, paymentId)) - .type(Refund.class) + .type(Refunds.class) .contentType(CONTENT_TYPE) .build(); @@ -179,7 +179,7 @@ public Map listOrderRefunds(String orderId, Setup setup) { RequestProperties props = new RequestPropertiesBuilder() .method("GET") .endpoint(String.format(ENDPOINT_REFUND_ORDER, orderId)) - .type(Refund.class) + .type(Refunds.class) .contentType(CONTENT_TYPE) .build(); diff --git a/src/main/java/br/com/moip/models/Transfers.java b/src/main/java/br/com/moip/models/Transfers.java new file mode 100644 index 0000000..15f715e --- /dev/null +++ b/src/main/java/br/com/moip/models/Transfers.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.Map; + +public class Transfers { + + private static final String ENDPOINT = "/v2/transfers"; + private static final ContentType CONTENT_TYPE = ContentType.APPLICATION_JSON; + private RequestMaker requestMaker; + + /** + * This method allows you to create a transfer. You can create a transfer to another Moip account or to + * an bank account. + * + * @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(Transfers.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to revert a transfer made to a Moip account. + * + * @param transferId + * {@code String} the Moip transfer external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map revert(String transferId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("POST") + .endpoint(String.format("%s/%s/reverse", ENDPOINT, transferId)) + .type(Transfers.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to get the data of a created transfer by its Moip external ID. + * + * @param transferId + * {@code String} the Moip transfer external ID. + * + * @param setup + * {@code Setup} the setup object. + * + * @return {@code Map} + */ + public Map get(String transferId, Setup setup) { + this.requestMaker = new RequestMaker(setup); + RequestProperties props = new RequestPropertiesBuilder() + .method("GET") + .endpoint(String.format("%s/%s", ENDPOINT, transferId)) + .type(Transfers.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } + + /** + * This method is used to list all created transfers. + * + * @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(Transfers.class) + .contentType(CONTENT_TYPE) + .build(); + + return this.requestMaker.doRequest(props); + } +} diff --git a/src/main/java/br/com/moip/models/Webhook.java b/src/main/java/br/com/moip/models/Webhooks.java similarity index 86% rename from src/main/java/br/com/moip/models/Webhook.java rename to src/main/java/br/com/moip/models/Webhooks.java index 3dbe379..5eaacbb 100644 --- a/src/main/java/br/com/moip/models/Webhook.java +++ b/src/main/java/br/com/moip/models/Webhooks.java @@ -7,18 +7,18 @@ import java.util.Map; -public class Webhook { +public class Webhooks { 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 + * 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...). + * {@code String} the Moip external ID of a resource (Orders, Payments, Refunds...). * * @param setup * {@code Setup} the setup object. @@ -30,7 +30,7 @@ public Map get(String resourceId, Setup setup) { RequestProperties props = new RequestPropertiesBuilder() .method("GET") .endpoint(ENDPOINT + String.format("?resourceId=%s", resourceId)) - .type(Webhook.class) + .type(Webhooks.class) .contentType(CONTENT_TYPE) .build(); @@ -38,7 +38,7 @@ public Map get(String resourceId, Setup setup) { } /** - * This method is used to get all sent Webhooks. + * This method is used to get all sent webhooks. * * @param setup * {@code Setup} the setup object. @@ -50,7 +50,7 @@ public Map list(Setup setup) { RequestProperties props = new RequestPropertiesBuilder() .method("GET") .endpoint(ENDPOINT) - .type(Webhook.class) + .type(Webhooks.class) .contentType(CONTENT_TYPE) .build(); diff --git a/src/test/java/br/com/moip/integration_tests/ConnectTest.java b/src/test/java/br/com/moip/integration_tests/ConnectTest.java new file mode 100644 index 0000000..3b469f6 --- /dev/null +++ b/src/test/java/br/com/moip/integration_tests/ConnectTest.java @@ -0,0 +1,50 @@ +package br.com.moip.integration_tests; + +import br.com.moip.Moip; +import br.com.moip.auth.Authentication; +import br.com.moip.auth.OAuth; +import br.com.moip.models.Setup; + +import java.util.HashMap; +import java.util.Map; + +public class ConnectTest { + + private static Authentication auth = new OAuth("8833c9eb036543b6b0acd685a76c9ead_v2"); + + private Setup setup = new Setup().setAuthentication(auth).setEnvironment(Setup.Environment.CONNECT_SANDBOX); + + public void buildUrlTest() { + + String[] scope = {"TRANSFER_FUNDS", "RECEIVE_FUNDS"}; + + String url = Moip.API.connect().buildUrl("APP-DVLJHW59IKOS", "http://www.exemplo.com.br/retorno", scope); + + System.out.println(url); + } + + public void generateAccessTokenTest() { + + Map body = new HashMap<>(); + body.put("client_id", "APP-DVLJHW59IKOS"); + body.put("client_secret", "31afe1ce89fe45b7975ade3024007370"); + body.put("redirect_uri", "http://www.exemplo.com.br/retorno"); + body.put("grant_type", "authorization_code"); + body.put("code", "b50f8d4c3932a38903d842bed70783db4183d04e"); + + Map accessToken = Moip.API.connect().generateAccessToken(body, setup); + + System.out.println(accessToken); + } + + public void refreshAccessTokenTest() { + + Map body = new HashMap<>(); + body.put("grant_type", "refresh_token"); + body.put("refresh_token", "599151f5954e401c8d169d5fa83c25ba_v2"); + + Map refreshToken = Moip.API.connect().refreshAccessToken(body, setup); + + System.out.println(refreshToken); + } +} diff --git a/src/test/java/br/com/moip/integration_tests/CustomerTest.java b/src/test/java/br/com/moip/integration_tests/CustomerTest.java index 35ef1cf..ccd7820 100644 --- a/src/test/java/br/com/moip/integration_tests/CustomerTest.java +++ b/src/test/java/br/com/moip/integration_tests/CustomerTest.java @@ -6,7 +6,6 @@ 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; diff --git a/src/test/java/br/com/moip/integration_tests/RefundTest.java b/src/test/java/br/com/moip/integration_tests/RefundTest.java index 3ad8f98..8cf69f1 100644 --- a/src/test/java/br/com/moip/integration_tests/RefundTest.java +++ b/src/test/java/br/com/moip/integration_tests/RefundTest.java @@ -67,7 +67,7 @@ public void refundBankAccountTest() { refundingInstrument.put("method", "BANK_ACCOUNT"); refundingInstrument.put("bankAccount", bankAccount); - // Refund order bank account // + // Refunds order bank account // Map refundBankAccountBody = new HashMap<>(); refundBankAccountBody.put("refundingInstrument", refundingInstrument); diff --git a/src/test/java/br/com/moip/unit_tests/AccountTest.java b/src/test/java/br/com/moip/unit_tests/AccountTest.java new file mode 100644 index 0000000..47cbf68 --- /dev/null +++ b/src/test/java/br/com/moip/unit_tests/AccountTest.java @@ -0,0 +1,348 @@ +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; + +public class AccountTest { + + @Rule + public Player player = new Player(); + private BankAccountTest bankAccountTest = new BankAccountTest(); + private Parser parser = new Parser(); + private Setup setup; + private Map body; + private Map variables; + + @Before + public void initialize() { + this.body = new HashMap<>(); + this.variables = new HashMap<>(); + this.setup = new SetupFactory().setupOAuth(player.getURL("").toString()); + } + + @Play("account/check_existence_by_tax_document") + @Test + public void checkExistenceByTaxDocumentTest() { + + Map checkExists = Moip.API.accounts().checkExistence("123.456.789-00", setup); + + assertEquals(200, checkExists.get("code")); + } + + @Play("account/check_existence_by_email") + @Test + public void checkExistenceByEmailTest() { + + Map checkExists = Moip.API.accounts().checkExistence("test@moip.com.br", setup); + + assertEquals(200, checkExists.get("code")); + } + + @Play("account/create_classical_account") + @Test + public void createClassicalAccountTest() { + + Map moipAccount = Moip.API.accounts().create(body, setup); + + assertEquals("MPA-6A4F2AF0CED7", moipAccount.get("id")); + assertEquals("my_test_0012930001@moip.com.br", moipAccount.get("login")); + assertEquals("8229ae27902746058561e2b9e71d12b9_v2", moipAccount.get("accessToken")); + assertEquals("APP-ML6Y8VWT7XFN", moipAccount.get("channelId")); + assertEquals("MERCHANT", moipAccount.get("type")); + assertEquals(false, moipAccount.get("transparentAccount")); + + Map email = parser.objectToMap(moipAccount.get("email")); + assertEquals("my_test_0012930001@moip.com.br", email.get("address")); + assertEquals(false, email.get("confirmed")); + + Map person = parser.objectToMap(moipAccount.get("person")); + assertEquals("Runscope", person.get("name")); + assertEquals("Random 9123", person.get("lastName")); + assertEquals("1990-01-01", person.get("birthDate")); + + Map taxDocument = parser.objectToMap(person.get("taxDocument")); + assertEquals("CPF", taxDocument.get("type")); + assertEquals("123.456.798-91", taxDocument.get("number")); + + Map address = parser.objectToMap(person.get("address")); + assertEquals("Av. Brigadeiro Faria Lima", address.get("street")); + assertEquals("2927", address.get("streetNumber")); + assertEquals("Itaim", address.get("district")); + assertEquals("São Paulo", address.get("city")); + assertEquals("SP", address.get("state")); + assertEquals("BRA", address.get("country")); + assertEquals("01234000", address.get("zipCode")); + + Map phone = parser.objectToMap(person.get("phone")); + assertEquals("55", phone.get("countryCode")); + assertEquals("11", phone.get("areaCode")); + assertEquals("965213244", phone.get("number")); + assertEquals(false, phone.get("verified")); + assertEquals("cellphone", phone.get("phoneType")); + + Map identityDocument = parser.objectToMap(person.get("identityDocument")); + assertEquals("434322344", identityDocument.get("number")); + assertEquals("SSP", identityDocument.get("issuer")); + assertEquals("2000-12-12", identityDocument.get("issueDate")); + assertEquals("RG", identityDocument.get("type")); + + Map company = parser.objectToMap(moipAccount.get("company")); + assertEquals("Empresa Moip", company.get("name")); + assertEquals("Moip Pagamentos", company.get("businessName")); + + Map taxDocumentCompany = parser.objectToMap(company.get("taxDocument")); + assertEquals("CNPJ", taxDocumentCompany.get("type")); + assertEquals("40.674.727/0001-79", taxDocumentCompany.get("number")); + + Map addressCompany = parser.objectToMap(company.get("address")); + assertEquals("Av. Brigadeiro Faria Lima", addressCompany.get("street")); + assertEquals("2927", addressCompany.get("streetNumber")); + assertEquals("Itaim", addressCompany.get("district")); + assertEquals("São Paulo", addressCompany.get("city")); + assertEquals("SP", addressCompany.get("state")); + assertEquals("BRA", addressCompany.get("country")); + assertEquals("01234000", addressCompany.get("zipCode")); + + Map phoneCompany = parser.objectToMap(company.get("phone")); + assertEquals("55", phoneCompany.get("countryCode")); + assertEquals("11", phoneCompany.get("areaCode")); + assertEquals("32234455", phoneCompany.get("number")); + assertEquals(false, phoneCompany.get("verified")); + assertEquals("not_informed", phoneCompany.get("phoneType")); + + assertEquals("2011-01-01", company.get("openingDate")); + + Map businessSegment = parser.objectToMap(moipAccount.get("businessSegment")); + assertEquals(3, businessSegment.get("id")); + assertEquals("Eletrônicos / Jogos de vídeo game", businessSegment.get("name")); + assertEquals(7622, businessSegment.get("mcc")); + + assertEquals("2018-07-31T22:33:09.497Z", moipAccount.get("createdAt")); + + Map links = parser.objectToMap(moipAccount.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/moipaccounts/MPA-6A4F2AF0CED7", self.get("href")); + assertNull(self.get("title")); + + Map setPassword = parser.objectToMap(links.get("setPassword")); + assertEquals("https://desenvolvedor.moip.com.br/sandbox/AskForNewPassword.do?method=confirm&email=my_test_0012930001%40moip.com.br&code=b1cdd30fbcf728cd530f4e13c3ff4e4b", setPassword.get("href")); + } + + @Play("account/create_transparent_account") + @Test + public void createTransparentAccountTest() { + + Map moipAccount = Moip.API.accounts().create(body, setup); + + assertEquals("MPA-51E0C7A09DF6", moipAccount.get("id")); + assertEquals("my_test_1204102@moip.com.br", moipAccount.get("login")); + assertEquals("4a2893051cfe490c8c1284d90fac8c02_v2", moipAccount.get("accessToken")); + assertEquals("APP-ML6Y8VWT7XFN", moipAccount.get("channelId")); + assertEquals("MERCHANT", moipAccount.get("type")); + assertEquals(true, moipAccount.get("transparentAccount")); + + Map email = parser.objectToMap(moipAccount.get("email")); + assertEquals("my_test_1204102@moip.com.br", email.get("address")); + assertEquals(false, email.get("confirmed")); + + Map person = parser.objectToMap(moipAccount.get("person")); + assertEquals("Runscope", person.get("name")); + assertEquals("Random 9123", person.get("lastName")); + assertEquals("1990-01-01", person.get("birthDate")); + + Map taxDocument = parser.objectToMap(person.get("taxDocument")); + assertEquals("CPF", taxDocument.get("type")); + assertEquals("123.456.798-91", taxDocument.get("number")); + + Map address = parser.objectToMap(person.get("address")); + assertEquals("Av. Brigadeiro Faria Lima", address.get("street")); + assertEquals("2927", address.get("streetNumber")); + assertEquals("Itaim", address.get("district")); + assertEquals("São Paulo", address.get("city")); + assertEquals("SP", address.get("state")); + assertEquals("BRA", address.get("country")); + assertEquals("01234000", address.get("zipCode")); + + Map phone = parser.objectToMap(person.get("phone")); + assertEquals("55", phone.get("countryCode")); + assertEquals("11", phone.get("areaCode")); + assertEquals("965213244", phone.get("number")); + assertEquals(false, phone.get("verified")); + assertEquals("cellphone", phone.get("phoneType")); + + Map identityDocument = parser.objectToMap(person.get("identityDocument")); + assertEquals("434322344", identityDocument.get("number")); + assertEquals("SSP", identityDocument.get("issuer")); + assertEquals("2000-12-12", identityDocument.get("issueDate")); + assertEquals("RG", identityDocument.get("type")); + + assertEquals("2018-08-01T16:26:45.903Z", moipAccount.get("createdAt")); + + Map links = parser.objectToMap(moipAccount.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/moipaccounts/MPA-51E0C7A09DF6", self.get("href")); + assertNull(self.get("title")); + } + + @Play("account/get") + @Test + public void getAccountTest() { + + Map moipAccount = Moip.API.accounts().get("MPA-6A4F2AF0CED7", setup); + + Map person = parser.objectToMap(moipAccount.get("person")); + assertEquals("Random 9123", person.get("lastName")); + + Map phone = parser.objectToMap(person.get("phone")); + assertEquals("11", phone.get("areaCode")); + assertEquals("55", phone.get("countryCode")); + assertEquals("965213244", phone.get("number")); + + Map parentsName = parser.objectToMap(person.get("parentsName")); + assertEquals("", parentsName.get("mother")); + assertEquals("", parentsName.get("father")); + + Map address = parser.objectToMap(person.get("address")); + assertEquals("01234-000", address.get("zipCode")); + assertEquals("Av. Brigadeiro Faria Lima", address.get("street")); + assertEquals("SP", address.get("state")); + assertEquals("2927", address.get("streetNumber")); + assertEquals("Itaim", address.get("district")); + assertEquals("BRA", address.get("country")); + assertEquals("São Paulo", address.get("city")); + + Map taxDocument = parser.objectToMap(person.get("taxDocument")); + assertEquals("123.456.798-91", taxDocument.get("number")); + assertEquals("CPF", taxDocument.get("type")); + + assertEquals("Runscope", person.get("name")); + assertEquals("1990-01-01", person.get("birthDate")); + + assertEquals(false, moipAccount.get("transparentAccount")); + + Map links = parser.objectToMap(moipAccount.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/accounts/MPA-6A4F2AF0CED7", self.get("href")); + + assertEquals(0, moipAccount.get("monthlyRevenueId")); + assertEquals("MERCHANT", moipAccount.get("type")); + assertEquals("MPA-6A4F2AF0CED7", moipAccount.get("id")); + + Map email = parser.objectToMap(moipAccount.get("email")); + assertEquals(true, email.get("confirmed")); + assertEquals("my_test_0012930001@moip.com.br", email.get("address")); + + assertEquals("2018-07-31T19:33:09.000-03:00", moipAccount.get("createdAt")); + + Map company = parser.objectToMap(moipAccount.get("company")); + assertEquals("", company.get("monthlyRevenue")); + assertEquals("Moip Pagamentos", company.get("businessName")); + + Map phoneCompany = parser.objectToMap(company.get("phone")); + assertEquals("11", phoneCompany.get("areaCode")); + assertEquals("55", phoneCompany.get("countryCode")); + assertEquals("32234455", phoneCompany.get("number")); + + assertEquals("2011-01-01", company.get("openingDate")); + + Map addressCompany = parser.objectToMap(company.get("address")); + assertEquals("", addressCompany.get("complement")); + assertEquals("01234-000", addressCompany.get("zipCode")); + assertEquals("Av. Brigadeiro Faria Lima", addressCompany.get("street")); + assertEquals("SP", addressCompany.get("state")); + assertEquals("2927", addressCompany.get("streetNumber")); + assertEquals("Itaim", addressCompany.get("district")); + assertEquals("BRA", addressCompany.get("country")); + assertEquals("São Paulo", addressCompany.get("city")); + + Map taxDocumentCompany = parser.objectToMap(company.get("taxDocument")); + assertEquals("40.674.727/0001-79", taxDocumentCompany.get("number")); + assertEquals("CNPJ", taxDocumentCompany.get("type")); + + assertEquals("Empresa Moip", company.get("name")); + assertEquals("", company.get("constitutionType")); + + Map businessSegment = parser.objectToMap(moipAccount.get("businessSegment")); + assertEquals(3, businessSegment.get("id")); + + assertEquals("FIXED_TABLE_FEE", moipAccount.get("feeType")); + assertEquals("my_test_0012930001@moip.com.br", moipAccount.get("login")); + assertEquals("Empresa Moip", moipAccount.get("softDescriptor")); + } + + @Play("account/get_keys") + @Test + public void getKeysTest() { + + Map getKeys = Moip.API.accounts().getKeys(setup); + + Map keys = parser.objectToMap(getKeys.get("keys")); + Map basicAuth = parser.objectToMap(keys.get("basicAuth")); + assertEquals("ABABABABABABABABABABABABABABABABABABABAB", basicAuth.get("secret")); + assertEquals("01010101010101010101010101010101", basicAuth.get("token")); + + assertEquals("-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoBttaXwRoI1Fbcond5mS\n7QOb7X2lykY5hvvDeLJelvFhpeLnS4YDwkrnziM3W00UNH1yiSDU+3JhfHu5G387\nO6uN9rIHXvL+TRzkVfa5iIjG+ap2N0/toPzy5ekpgxBicjtyPHEgoU6dRzdszEF4\nItimGk5ACx/lMOvctncS5j3uWBaTPwyn0hshmtDwClf6dEZgQvm/dNaIkxHKV+9j\nMn3ZfK/liT8A3xwaVvRzzuxf09xJTXrAd9v5VQbeWGxwFcW05oJulSFjmJA9Hcmb\nDYHJT+sG2mlZDEruCGAzCVubJwGY1aRlcs9AQc1jIm/l8JwH7le2kpk3QoX+gz0w\nWwIDAQAB\n-----END PUBLIC KEY-----\n", keys.get("encryption")); + } + + @Play("account/create_bank_account") + @Test + public void createBankAccountTest() { + + variables.put("id", "BKA-SD5MQZEBIM1E"); + variables.put("agencyNumber", "12345"); + variables.put("taxDocumentNumber", "255.328.259-12"); + variables.put("taxDocumentType", "CPF"); + variables.put("holderThirdParty", false); + variables.put("holderFullname", "Jose Silva dos Santos"); + variables.put("accountNumber", "12345678"); + variables.put("status", "NOT_VERIFIED"); + variables.put("createdAt", "2018-08-13T17:03:35.021-03:00"); + variables.put("accountCheckNumber", "7"); + variables.put("selfHref", "https://sandbox.moip.com.br//accounts/BKA-SD5MQZEBIM1E/bankaccounts"); + variables.put("bankName", "BANCO BRADESCO S.A."); + variables.put("type", "CHECKING"); + variables.put("agencyCheckNumber", "0"); + variables.put("bankNumber", "237"); + + Map bankAccount = Moip.API.accounts().createBankAccount(body, "MPA-CULBBYHD11", setup); + bankAccountTest.testBankAccountBody(bankAccount, variables); + } + + @Play("account/list_bank_accounts") + @Test + public void listBankAccountsTest() { + + variables.put("id", "BKA-KS1LVCCH0P25"); + variables.put("agencyNumber", "1111"); + variables.put("taxDocumentNumber", "255.328.259-12"); + variables.put("taxDocumentType", "CPF"); + variables.put("holderThirdParty", false); + variables.put("holderFullname", "Jose Silva dos Santos"); + variables.put("accountNumber", "11111111"); + variables.put("status", "NOT_VERIFIED"); + variables.put("createdAt", "2016-04-07T15:25:57.000-03:00"); + variables.put("accountCheckNumber", "1"); + variables.put("selfHref", "https://sandbox.moip.com.br//accounts/BKA-KS1LVCCH0P25/bankaccounts"); + variables.put("bankName", "BANCO DO BRASIL S.A."); + variables.put("type", "CHECKING"); + variables.put("agencyCheckNumber", "1"); + variables.put("bankNumber", "001"); + + List> list = Moip.API.accounts().listBankAccounts("MPA-CULBBYHD11", setup); + bankAccountTest.testBankAccountBody(list.get(0), variables); + } +} diff --git a/src/test/java/br/com/moip/unit_tests/BalancesTest.java b/src/test/java/br/com/moip/unit_tests/BalancesTest.java new file mode 100644 index 0000000..4f8e18b --- /dev/null +++ b/src/test/java/br/com/moip/unit_tests/BalancesTest.java @@ -0,0 +1,48 @@ +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.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + +public class BalancesTest { + + @Rule + public Player player = new Player(); + private Parser parser = new Parser(); + private Setup setup; + + @Before + public void initialize() { + this.setup = new SetupFactory().setupOAuth(player.getURL("").toString()); + } + + @Play("balances/get") + @Test + public void getBalancesTest() { + + Map balances = Moip.API.balances().get(setup); + + List> unavailable = parser.objectToList(balances.get("unavailable")); + assertEquals(0, unavailable.get(0).get("amount")); + assertEquals("BRL", unavailable.get(0).get("currency")); + + List> future = parser.objectToList(balances.get("future")); + assertEquals(64629427, future.get(0).get("amount")); + assertEquals("BRL", future.get(0).get("currency")); + + List> current = parser.objectToList(balances.get("current")); + assertEquals(1094194873, current.get(0).get("amount")); + assertEquals("BRL", current.get(0).get("currency")); + } +} diff --git a/src/test/java/br/com/moip/unit_tests/BankAccountTest.java b/src/test/java/br/com/moip/unit_tests/BankAccountTest.java new file mode 100644 index 0000000..96eab43 --- /dev/null +++ b/src/test/java/br/com/moip/unit_tests/BankAccountTest.java @@ -0,0 +1,120 @@ +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.Map; + +import static org.junit.Assert.assertEquals; + +public class BankAccountTest { + + @Rule + public Player player = new Player(); + private Setup setup; + private Map body; + private Parser parser = new Parser(); + private Map variables; + + @Before + public void initialize() { + this.body = new HashMap<>(); + this.setup = new SetupFactory().setupOAuth(player.getURL("").toString()); + this.variables = new HashMap<>(); + } + + @Play("bankaccount/get") + @Test + public void getBankAccountTest() { + + variables.put("id", "BKA-EQW51MWMAO22"); + variables.put("agencyNumber", "1111"); + variables.put("taxDocumentNumber", "255.328.259-12"); + variables.put("taxDocumentType", "CPF"); + variables.put("holderThirdParty", false); + variables.put("holderFullname", "Jose Silva dos Santos"); + variables.put("accountNumber", "11111111"); + variables.put("status", "IN_VERIFICATION"); + variables.put("createdAt", "2016-04-07T15:23:48.000-03:00"); + variables.put("accountCheckNumber", "1"); + variables.put("selfHref", "https://sandbox.moip.com.br//accounts/BKA-EQW51MWMAO22/bankaccounts"); + variables.put("bankName", "BANCO DO BRASIL S.A."); + variables.put("type", "CHECKING"); + variables.put("agencyCheckNumber", "1"); + variables.put("bankNumber", "001"); + + Map bankAccount = Moip.API.bankAccounts().get("BKA-EQW51MWMAO22", setup); + + testBankAccountBody(bankAccount, variables); + } + + @Play("bankaccount/update") + @Test + public void updateBankAccountTest() { + + variables.put("id", "BKA-EQW51MWMAO22"); + variables.put("agencyNumber", "2222"); + variables.put("taxDocumentNumber", "255.328.259-12"); + variables.put("taxDocumentType", "CPF"); + variables.put("holderThirdParty", false); + variables.put("holderFullname", "Jose Silva dos Santos"); + variables.put("accountNumber", "12365478"); + variables.put("status", "VERIFIED"); + variables.put("createdAt", "2016-04-07T15:23:48.000-03:00"); + variables.put("accountCheckNumber", "1"); + variables.put("selfHref", "https://sandbox.moip.com.br//accounts/BKA-EQW51MWMAO22/bankaccounts"); + variables.put("bankName", "BANCO DO BRASIL S.A."); + variables.put("type", "CHECKING"); + variables.put("agencyCheckNumber", "1"); + variables.put("bankNumber", "001"); + + Map bankAccount = Moip.API.bankAccounts().update(body, "BKA-EQW51MWMAO22", setup); + testBankAccountBody(bankAccount, variables); + } + + void testBankAccountBody(Map bankAccount, Map variables) { + + assertEquals(variables.get("id"), bankAccount.get("id")); + assertEquals(variables.get("agencyNumber"), bankAccount.get("agencyNumber")); + + Map holder = parser.objectToMap(bankAccount.get("holder")); + testBankAccountHolder(holder, variables); + + assertEquals(variables.get("accountNumber"), bankAccount.get("accountNumber")); + assertEquals(variables.get("status"), bankAccount.get("status")); + assertEquals(variables.get("createdAt"), bankAccount.get("createdAt")); + assertEquals(variables.get("accountCheckNumber"), bankAccount.get("accountCheckNumber")); + + Map links = parser.objectToMap(bankAccount.get("_links")); + testBankAccountLinks(links, variables); + + assertEquals(variables.get("bankName"), bankAccount.get("bankName")); + assertEquals(variables.get("type"), bankAccount.get("type")); + assertEquals(variables.get("agencyCheckNumber"), bankAccount.get("agencyCheckNumber")); + assertEquals(variables.get("bankNumber"), bankAccount.get("bankNumber")); + } + + private void testBankAccountHolder(Map holder, Map variables) { + + Map taxDocument = parser.objectToMap(holder.get("taxDocument")); + assertEquals(variables.get("taxDocumentNumber"), taxDocument.get("number")); + assertEquals(variables.get("taxDocumentType"), taxDocument.get("type")); + + assertEquals(variables.get("holderThirdParty"), holder.get("thirdParty")); + assertEquals(variables.get("holderFullname"), holder.get("fullname")); + } + + private void testBankAccountLinks(Map links, Map variables) { + + Map self = parser.objectToMap(links.get("self")); + assertEquals(variables.get("selfHref"), self.get("href")); + } +} diff --git a/src/test/java/br/com/moip/unit_tests/ConnectTest.java b/src/test/java/br/com/moip/unit_tests/ConnectTest.java new file mode 100644 index 0000000..019b794 --- /dev/null +++ b/src/test/java/br/com/moip/unit_tests/ConnectTest.java @@ -0,0 +1,77 @@ +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.Map; + +import static org.junit.Assert.assertEquals; + +public class ConnectTest { + + @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().setupOAuth(player.getURL("").toString()); + this.parser = new Parser(); + } + + @Test + public void buildUrl() { + + String[] scope = {"TRANSFER_FUNDS", "RECEIVE_FUNDS"}; + + String url = Moip.API.connect().buildUrl("APP-DVLJHW59IKOS", "http://www.exemplo.com.br/retorno", scope); + + assertEquals("https://connect-sandbox.moip.com.br/oauth/authorize?response_type=code&client_id=APP-DVLJHW59IKOS" + + "&redirect_uri=http://www.exemplo.com.br/retorno&scope=TRANSFER_FUNDS,RECEIVE_FUNDS", url); + } + + @Play("connect/generate_access_token") + @Test + public void generateAccessTokenTest() { + + Map accessToken = Moip.API.connect().generateAccessToken(body, setup); + + assertEquals("0c6937d062874507b9c19748d8e0f8df_v2", accessToken.get("accessToken")); + assertEquals("0c6937d062874507b9c19748d8e0f8df_v2", accessToken.get("access_token")); + assertEquals("2028-08-02", accessToken.get("expires_in")); + assertEquals("c1384b7aa4a8432b8fcfad26622cb917_v2", accessToken.get("refreshToken")); + assertEquals("c1384b7aa4a8432b8fcfad26622cb917_v2", accessToken.get("refresh_token")); + assertEquals("TRANSFER_FUNDS,RECEIVE_FUNDS", accessToken.get("scope")); + + Map moipAccount = parser.objectToMap(accessToken.get("moipAccount")); + assertEquals("MPA-14C9EE706C55", moipAccount.get("id")); + } + + @Play("connect/refresh_access_token") + @Test + public void refreshAccessTokenTest() { + + Map accessToken = Moip.API.connect().generateAccessToken(body, setup); + + assertEquals("fb65d9d88bdf47d39d90ead6b290e17b_v2", accessToken.get("accessToken")); + assertEquals("fb65d9d88bdf47d39d90ead6b290e17b_v2", accessToken.get("access_token")); + assertEquals("2028-08-02", accessToken.get("expires_in")); + assertEquals("e466a50bb6fb414aa0ea937ddf6ca71b_v2", accessToken.get("refreshToken")); + assertEquals("e466a50bb6fb414aa0ea937ddf6ca71b_v2", accessToken.get("refresh_token")); + assertEquals("TRANSFER_FUNDS,RECEIVE_FUNDS", accessToken.get("scope")); + + Map moipAccount = parser.objectToMap(accessToken.get("moipAccount")); + assertEquals("MPA-14C9EE706C55", moipAccount.get("id")); + } +} diff --git a/src/test/java/br/com/moip/unit_tests/CustomerTest.java b/src/test/java/br/com/moip/unit_tests/CustomerTest.java index 7643d4f..c86e4c6 100644 --- a/src/test/java/br/com/moip/unit_tests/CustomerTest.java +++ b/src/test/java/br/com/moip/unit_tests/CustomerTest.java @@ -27,7 +27,7 @@ public class CustomerTest { @Before public void initialize() { this.body = new HashMap<>(); - this.setup = new SetupFactory().setup(player.getURL("").toString()); + this.setup = new SetupFactory().setupBasicAuth(player.getURL("").toString()); this.parser = new Parser(); } diff --git a/src/test/java/br/com/moip/unit_tests/EntryTest.java b/src/test/java/br/com/moip/unit_tests/EntryTest.java new file mode 100644 index 0000000..3e2274a --- /dev/null +++ b/src/test/java/br/com/moip/unit_tests/EntryTest.java @@ -0,0 +1,167 @@ +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 EntryTest { + + @Rule + public Player player = new Player(); + private Parser parser = new Parser(); + private Map variables; + private Setup setup; + + @Before + public void initialize() { + this.setup = new SetupFactory().setupOAuth(player.getURL("").toString()); + this.variables = new HashMap<>(); + } + + + @Play("entry/get") + @Test + public void getEntryTest() { + + variables.put("scheduledFor", "2012-08-31T16:59:36.000Z"); + variables.put("status", "SETTLED"); + variables.put("moipAccountId", "MPA-CULBBYHD11"); + variables.put("selfTitle", "ENT-2JHP5A593QSW"); + variables.put("selfHref", "https://sandbox.moip.com.br/v2/entries/ENT-2JHP5A593QSW"); + variables.put("feesAmount", 150); + variables.put("feesType", "TRANSACTION"); + variables.put("type", "CREDIT_CARD"); + variables.put("ownId", ""); + variables.put("updatedAt", "2014-04-16T16:16:12.000Z"); + variables.put("id", "ENT-2JHP5A593QSW"); + variables.put("amountFee", 150); + variables.put("amountTotal", 150); + variables.put("amountLiquid", 0); + variables.put("amountCurrency", "BRL"); + variables.put("operation", "CREDIT"); + variables.put("createdAt", "2014-04-16T16:16:12.000Z"); + variables.put("event", "PAY-AQITTDNDKBU9"); + variables.put("description", "Cartao de credito - Pedido ORD-UF4E00XMFDL1"); + variables.put("occurrenceTo", 1); + variables.put("occurrenceIn", 1); + variables.put("blocked", false); + variables.put("settledAt", "2012-08-31T00:00:00.000Z"); + variables.put("additionalId", 145470); + + Map entry = Moip.API.entries().get("ENT-2JHP5A593QSW", setup); + testEntryBody(entry, variables); + } + + @Play("entry/list") + @Test + public void listEntriesTest() { + + variables.put("scheduledFor", "2012-08-31T16:59:36.000Z"); + variables.put("status", "SETTLED"); + variables.put("selfTitle", "ENT-2JHP5A593QSW"); + variables.put("selfHref", "https://sandbox.moip.com.br/v2/entries/ENT-2JHP5A593QSW"); + variables.put("feesAmount", 150); + variables.put("feesType", "TRANSACTION"); + variables.put("type", "CREDIT_CARD"); + variables.put("ownId", ""); + variables.put("updatedAt", "2014-04-16T16:16:12.000Z"); + variables.put("id", "ENT-2JHP5A593QSW"); + variables.put("amountFee", 150); + variables.put("amountTotal", 150); + variables.put("amountLiquid", 0); + variables.put("amountCurrency", "BRL"); + variables.put("operation", "CREDIT"); + variables.put("createdAt", "2014-04-16T16:16:12.000Z"); + variables.put("event", "PAY-AQITTDNDKBU9"); + variables.put("description", "Cartao de credito - Pedido ORD-UF4E00XMFDL1"); + variables.put("occurrenceTo", 1); + variables.put("occurrenceIn", 1); + variables.put("blocked", false); + variables.put("settledAt", "2012-08-31T00:00:00.000Z"); + variables.put("additionalId", 145470); + + Map list = Moip.API.entries().list(setup); + + Map summary = parser.objectToMap(list.get("summary")); + assertEquals(1494494396, summary.get("amount")); + assertEquals(48561, summary.get("count")); + + Map links = parser.objectToMap(list.get("_links")); + Map previous = parser.objectToMap(links.get("previous")); + assertEquals("https://sandbox.moip.com.br/v2/entries?offset=0&limit=20", previous.get("href")); + + Map next = parser.objectToMap(links.get("next")); + assertEquals("https://sandbox.moip.com.br/v2/entries?offset=20&limit=20", next.get("href")); + + List> entries = parser.objectToList(list.get("entries")); + testEntryBody(entries.get(0), variables); + } + + private void testEntryBody(Map entry, Map variables) { + + assertEquals(variables.get("scheduledFor"), entry.get("scheduledFor")); + assertEquals(variables.get("status"), entry.get("status")); + + if (entry.get("moipAccount") != null) { + Map moipAccount = parser.objectToMap(entry.get("moipAccount")); + assertEquals(variables.get("moipAccountId"), moipAccount.get("id")); + } + + Map links = parser.objectToMap(entry.get("_links")); + testLinks(links, variables); + + if (entry.get("fees") != null) { + List> fees = parser.objectToList(entry.get("fees")); + assertEquals(variables.get("feesAmount"), fees.get(0).get("amount")); + assertEquals(variables.get("feesType"), fees.get(0).get("type")); + } + + assertEquals(variables.get("type"), entry.get("type")); + assertEquals(variables.get("ownId"), entry.get("ownId")); + assertEquals(variables.get("updatedAt"), entry.get("updatedAt")); + assertEquals(variables.get("id"), entry.get("id")); + + Map amount = parser.objectToMap(entry.get("amount")); + testAmount(amount, variables); + + assertEquals(variables.get("operation"), entry.get("operation")); + assertEquals(variables.get("createdAt"), entry.get("createdAt")); + assertEquals(variables.get("event"), entry.get("event")); + assertEquals(variables.get("description"), entry.get("description")); + + Map occurrence = parser.objectToMap(entry.get("occurrence")); + assertEquals(variables.get("occurrenceTo"), occurrence.get("to")); + assertEquals(variables.get("occurrenceIn"), occurrence.get("in")); + + assertEquals(variables.get("blocked"), entry.get("blocked")); + assertEquals(variables.get("settledAt"), entry.get("settledAt")); + assertEquals(variables.get("additionalId"), entry.get("additionalId")); + } + + private void testLinks(Map links, Map variables) { + + Map self = parser.objectToMap(links.get("self")); + assertEquals(variables.get("selfTitle"), self.get("title")); + assertEquals(variables.get("selfHref"), self.get("href")); + } + + private void testAmount(Map amount, Map variables) { + + assertEquals(variables.get("amountFee"), amount.get("fee")); + assertEquals(variables.get("amountTotal"), amount.get("total")); + assertEquals(variables.get("amountLiquid"), amount.get("liquid")); + assertEquals(variables.get("amountCurrency"), amount.get("currency")); + } +} diff --git a/src/test/java/br/com/moip/unit_tests/EscrowTest.java b/src/test/java/br/com/moip/unit_tests/EscrowTest.java new file mode 100644 index 0000000..0712e94 --- /dev/null +++ b/src/test/java/br/com/moip/unit_tests/EscrowTest.java @@ -0,0 +1,54 @@ +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.Map; + +import static org.junit.Assert.assertEquals; + +public class EscrowTest { + + @Rule + public Player player = new Player(); + private Parser parser = new Parser(); + private Setup setup; + + @Before + public void initialize() { + this.setup = new SetupFactory().setupOAuth(player.getURL("").toString()); + } + + @Play("escrow/release") + @Test + public void releaseEscrowTest() { + + Map escrow = Moip.API.escrows().release("ECW-QI13E7A7ONDQ", setup); + + assertEquals("ECW-QI13E7A7ONDQ", escrow.get("id")); + assertEquals("RELEASED", escrow.get("status")); + assertEquals("Custódia de pagamento", escrow.get("description")); + assertEquals(23000, escrow.get("amount")); + assertEquals("2018-08-20T10:27:45.000-03", escrow.get("createdAt")); + assertEquals("2018-08-20T10:27:45.000-03", escrow.get("updatedAt")); + + Map links = parser.objectToMap(escrow.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/escrows/ECW-QI13E7A7ONDQ", self.get("href")); + + Map order = parser.objectToMap(links.get("order")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-FY97DC35UZ2W", order.get("href")); + assertEquals("ORD-FY97DC35UZ2W", order.get("title")); + + Map payment = parser.objectToMap(links.get("payment")); + assertEquals("https://sandbox.moip.com.br/v2/payments/PAY-ARF0D5ELVX5D", payment.get("href")); + assertEquals("PAY-ARF0D5ELVX5D", payment.get("title")); + } +} diff --git a/src/test/java/br/com/moip/unit_tests/MultiorderTest.java b/src/test/java/br/com/moip/unit_tests/MultiorderTest.java new file mode 100644 index 0000000..8b82a47 --- /dev/null +++ b/src/test/java/br/com/moip/unit_tests/MultiorderTest.java @@ -0,0 +1,535 @@ +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 MultiorderTest { + + @Rule + public Player player = new Player(); + private Parser parser = new Parser(); + private MultipaymentTest multipaymentTest = new MultipaymentTest(); + private Setup setup; + private Map body; + private Map variables; + + @Before + public void initialize() { + this.body = new HashMap<>(); + this.variables = new HashMap<>(); + this.setup = new SetupFactory().setupOAuth(player.getURL("").toString()); + } + + @Play("multiorder/create") + @Test + public void createMultiorderTest() { + + Map multiorder = Moip.API.multiorders().create(body, setup); + + assertEquals("MOR-R6Q839MNWWO2", multiorder.get("id")); + assertEquals("multiorder_id_121414", multiorder.get("ownId")); + assertEquals("CREATED", multiorder.get("status")); + assertEquals("2018-08-03T17:23:50.230-03", multiorder.get("createdAt")); + assertEquals("", multiorder.get("updatedAt")); + + Map amount = parser.objectToMap(multiorder.get("amount")); + assertEquals(8000, amount.get("total")); + assertEquals("BRL", amount.get("currency")); + + List> orders = parser.objectToList(multiorder.get("orders")); + firstOrderFromCreate(orders.get(0)); + secondOrderFromCreate(orders.get(1)); + + Map links = parser.objectToMap(multiorder.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/orders/MOR-R6Q839MNWWO2", self.get("href")); + + Map checkout = parser.objectToMap(links.get("checkout")); + Map payCreditCard = parser.objectToMap(checkout.get("payCreditCard")); + assertEquals("https://checkout-sandbox.moip.com.br/creditcard/MOR-R6Q839MNWWO2", payCreditCard.get("redirectHref")); + + Map payBoleto = parser.objectToMap(checkout.get("payBoleto")); + assertEquals("https://checkout-sandbox.moip.com.br/boleto/MOR-R6Q839MNWWO2", payBoleto.get("redirectHref")); + + Map payOnlineBankDebitItau = parser.objectToMap(checkout.get("payOnlineBankDebitItau")); + assertEquals("https://checkout-sandbox.moip.com.br/debit/itau/MOR-R6Q839MNWWO2", payOnlineBankDebitItau.get("redirectHref")); + } + + @Play("multiorder/get") + @Test + public void getMultiorderTest() { + + Map multiorder = Moip.API.multiorders().get("MOR-R6Q839MNWWO2", setup); + + assertEquals("MOR-R6Q839MNWWO2", multiorder.get("id")); + assertEquals("multiorder_id_121414", multiorder.get("ownId")); + assertEquals("CREATED", multiorder.get("status")); + assertEquals("2018-08-03T17:23:50.000-03", multiorder.get("createdAt")); + assertEquals("", multiorder.get("updatedAt")); + + Map amount = parser.objectToMap(multiorder.get("amount")); + assertEquals(8000, amount.get("total")); + assertEquals("BRL", amount.get("currency")); + + List> orders = parser.objectToList(multiorder.get("orders")); + firstOrderFromGet(orders.get(0)); + secondOrderFromGet(orders.get(1)); + + Map links1 = parser.objectToMap(orders.get(1).get("_links")); + Map self1 = parser.objectToMap(links1.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-GRZP5CX0LSSL", self1.get("href")); + + Map links = parser.objectToMap(multiorder.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/orders/MOR-R6Q839MNWWO2", self.get("href")); + + Map checkout = parser.objectToMap(links.get("checkout")); + Map payCreditCard = parser.objectToMap(checkout.get("payCreditCard")); + assertEquals("https://checkout-sandbox.moip.com.br/creditcard/MOR-R6Q839MNWWO2", payCreditCard.get("redirectHref")); + + Map payBoleto = parser.objectToMap(checkout.get("payBoleto")); + assertEquals("https://checkout-sandbox.moip.com.br/boleto/MOR-R6Q839MNWWO2", payBoleto.get("redirectHref")); + + Map payOnlineBankDebitItau = parser.objectToMap(checkout.get("payOnlineBankDebitItau")); + assertEquals("https://checkout-sandbox.moip.com.br/debit/itau/MOR-R6Q839MNWWO2", payOnlineBankDebitItau.get("redirectHref")); + } + + @Play("multiorder/pay_with_credit_card") + @Test + public void payWithCreditCardTest() { + + Map multipayment = Moip.API.multiorders().pay(body, "MOR-R6Q839MNWWO2", setup); + + assertEquals("MPY-TTNVH6J6KBNC", multipayment.get("id")); + assertEquals("WAITING", multipayment.get("status")); + + Map amount = parser.objectToMap(multipayment.get("amount")); + assertEquals(8000, amount.get("total")); + assertEquals("BRL", amount.get("currency")); + + assertEquals(1, multipayment.get("installmentCount")); + + List> payments = parser.objectToList(multipayment.get("payments")); + variables.put("id", "PAY-DY1WE4PCPMLZ"); + variables.put("status", "WAITING"); + variables.put("delayCapture", false); + multipaymentTest.testPaymentsFromMultipayment(payments.get(0), variables); + + variables.put("id", "PAY-7P670FWYIZ82"); + variables.put("status", "WAITING"); + variables.put("delayCapture", false); + multipaymentTest.testPaymentsFromMultipayment(payments.get(1),variables); + + Map links = parser.objectToMap(multipayment.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/multipayments/MPY-TTNVH6J6KBNC", self.get("href")); + + Map multiorder = parser.objectToMap(links.get("multiorder")); + assertEquals("https://sandbox.moip.com.br/v2/multiorders/MOR-R6Q839MNWWO2", multiorder.get("href")); + } + + private void customer(Map customer) { + + assertEquals("CUS-COEFORVOX64K", customer.get("id")); + assertEquals("customer[1234]", customer.get("ownId")); + assertEquals("Joao Sousa", customer.get("fullname")); + assertEquals("1988-12-30", customer.get("birthDate")); + assertEquals("joao.sousa@email.com", customer.get("email")); + + Map fundingInstrument = parser.objectToMap(customer.get("fundingInstrument")); + Map creditCard = parser.objectToMap(fundingInstrument.get("creditCard")); + assertEquals("CRC-A3ZNIT523OYB", creditCard.get("id")); + assertEquals("VISA", creditCard.get("brand")); + assertEquals("407302", creditCard.get("first6")); + assertEquals("0002", 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("66778899", phone.get("number")); + + Map taxDocument = parser.objectToMap(customer.get("taxDocument")); + assertEquals("CPF", taxDocument.get("type")); + assertEquals("22222222222", taxDocument.get("number")); + + Map shippingAddress = parser.objectToMap(customer.get("shippingAddress")); + assertEquals("01234000", shippingAddress.get("zipCode")); + assertEquals("Avenida Faria Lima", shippingAddress.get("street")); + assertEquals("2927", shippingAddress.get("streetNumber")); + assertEquals("8", shippingAddress.get("complement")); + assertEquals("Sao Paulo", shippingAddress.get("city")); + assertEquals("Itaim", shippingAddress.get("district")); + assertEquals("SP", shippingAddress.get("state")); + assertEquals("BRA", shippingAddress.get("country")); + + Map billingAddress = parser.objectToMap(customer.get("billingAddress")); + assertEquals("01234000", billingAddress.get("zipCode")); + assertEquals("Avenida Faria Lima", billingAddress.get("street")); + assertEquals("2927", billingAddress.get("streetNumber")); + assertEquals("8", billingAddress.get("complement")); + assertEquals("Sao Paulo", billingAddress.get("city")); + assertEquals("Itaim", billingAddress.get("district")); + assertEquals("SP", billingAddress.get("state")); + assertEquals("BRA", billingAddress.get("country")); + + Map moipAccount = parser.objectToMap(customer.get("moipAccount")); + assertEquals("MPA-PQ0H8UZYNNWY", moipAccount.get("id")); + + Map customerLinks = parser.objectToMap(customer.get("_links")); + Map customerSelf = parser.objectToMap(customerLinks.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/customers/CUS-COEFORVOX64K", customerSelf.get("href")); + + List> fundingInstruments = parser.objectToList(customer.get("fundingInstruments")); + + Map firstCreditCard = parser.objectToMap(fundingInstruments.get(0).get("creditCard")); + assertEquals("CRC-0DWSR8500SWI", firstCreditCard.get("id")); + assertEquals("VISA", firstCreditCard.get("brand")); + assertEquals("401200", firstCreditCard.get("first6")); + assertEquals("3335", firstCreditCard.get("last4")); + assertEquals(true, firstCreditCard.get("store")); + + assertEquals("CREDIT_CARD", fundingInstruments.get(0).get("method")); + + Map secondCreditCard = parser.objectToMap(fundingInstruments.get(1).get("creditCard")); + assertEquals("CRC-PMH3KO5OPWSC", secondCreditCard.get("id")); + assertEquals("VISA", secondCreditCard.get("brand")); + assertEquals("401200", secondCreditCard.get("first6")); + assertEquals("3335", secondCreditCard.get("last4")); + assertEquals(true, secondCreditCard.get("store")); + + assertEquals("CREDIT_CARD", fundingInstruments.get(1).get("method")); + } + + private void firstOrderFromCreate(Map order) { + + assertEquals("ORD-UMVGMZLNFQFW", order.get("id")); + assertEquals("order_1412", order.get("ownId")); + assertEquals("CREATED", order.get("status")); + assertEquals("V2", order.get("platform")); + assertEquals("2018-08-03T17:23:50.230-03", order.get("createdAt")); + assertEquals("2018-08-03T17:23:50.230-03", order.get("updatedAt")); + + Map amount = parser.objectToMap(order.get("amount")); + assertEquals(0, amount.get("paid")); + assertEquals(4000, 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(2000, subtotals.get("shipping")); + assertEquals(0, subtotals.get("addition")); + assertEquals(0, subtotals.get("discount")); + assertEquals(2000, subtotals.get("items")); + + List> items = parser.objectToList(order.get("items")); + assertEquals("Camisa Verde e Amarelo - Brasil", items.get(0).get("product")); + assertEquals(2000, items.get(0).get("price")); + assertEquals("Seleção Brasileira", items.get(0).get("detail")); + assertEquals(1, items.get(0).get("quantity")); + + Map customer = parser.objectToMap(order.get("customer")); + customer(customer); + + 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-08-03T17:23:50.230-03", events.get(0).get("createdAt")); + assertEquals("", events.get(0).get("description")); + + List> receivers = parser.objectToList(order.get("receivers")); + Map receiverMoipAccount = parser.objectToMap(receivers.get(0).get("moipAccount")); + assertEquals("MPA-VB5OGTVPCI52", receiverMoipAccount.get("id")); + assertEquals("lojista_1@labs.moip.com.br", receiverMoipAccount.get("login")); + assertEquals("Chris Coyier Moip", receiverMoipAccount.get("fullname")); + + assertEquals("PRIMARY", receivers.get(0).get("type")); + + Map receiverAmount = parser.objectToMap(receivers.get(0).get("amount")); + assertEquals(4000, receiverAmount.get("total")); + assertEquals("BRL", receiverAmount.get("currency")); + assertEquals(0, receiverAmount.get("fees")); + assertEquals(0, receiverAmount.get("refunds")); + + assertEquals(false, receivers.get(0).get("feePayor")); + + Map links0 = parser.objectToMap(order.get("_links")); + Map self0 = parser.objectToMap(links0.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-UMVGMZLNFQFW", self0.get("href")); + } + + private void secondOrderFromCreate(Map order) { + + assertEquals("ORD-GRZP5CX0LSSL", order.get("id")); + assertEquals("order_12441512", order.get("ownId")); + assertEquals("CREATED", order.get("status")); + assertEquals("V2", order.get("platform")); + assertEquals("2018-08-03T17:23:50.269-03", order.get("createdAt")); + assertEquals("2018-08-03T17:23:50.269-03", order.get("updatedAt")); + + Map amount = parser.objectToMap(order.get("amount")); + assertEquals(0, amount.get("paid")); + assertEquals(4000, 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(3000, subtotals.get("shipping")); + assertEquals(0, subtotals.get("addition")); + assertEquals(0, subtotals.get("discount")); + assertEquals(1000, subtotals.get("items")); + + List> items = parser.objectToList(order.get("items")); + assertEquals("Camisa Preta - Alemanha", items.get(0).get("product")); + assertEquals(1000, items.get(0).get("price")); + assertEquals("Camiseta da Copa 2014", items.get(0).get("detail")); + assertEquals(1, items.get(0).get("quantity")); + + Map customer = parser.objectToMap(order.get("customer")); + customer(customer); + + List> payments1 = parser.objectToList(order.get("payments")); + assertTrue(payments1.isEmpty()); + + List> escrows1 = parser.objectToList(order.get("escrows")); + assertTrue(escrows1.isEmpty()); + + List> refunds1 = parser.objectToList(order.get("refunds")); + assertTrue(refunds1.isEmpty()); + + List> entries1 = parser.objectToList(order.get("entries")); + assertTrue(entries1.isEmpty()); + + List> events1 = parser.objectToList(order.get("events")); + assertEquals("ORDER.CREATED", events1.get(0).get("type")); + assertEquals("2018-08-03T17:23:50.269-03", events1.get(0).get("createdAt")); + assertEquals("", events1.get(0).get("description")); + + List> receivers = parser.objectToList(order.get("receivers")); + + Map firstReceiverAccount = parser.objectToMap(receivers.get(0).get("moipAccount")); + assertEquals("MPA-IFYRB1HBL73Z", firstReceiverAccount.get("id")); + assertEquals("lojista_3@labs.moip.com.br", firstReceiverAccount.get("login")); + assertEquals("Lojista 3 Moip", firstReceiverAccount.get("fullname")); + + assertEquals("PRIMARY", receivers.get(0).get("type")); + + Map firstReceiverAmount = parser.objectToMap(receivers.get(0).get("amount")); + assertEquals(3945, firstReceiverAmount.get("total")); + assertEquals("BRL", firstReceiverAmount.get("currency")); + assertEquals(0, firstReceiverAmount.get("fees")); + assertEquals(0, firstReceiverAmount.get("refunds")); + + assertEquals(false, receivers.get(0).get("feePayor")); + + Map secondReceiverAccount = parser.objectToMap(receivers.get(1).get("moipAccount")); + assertEquals("MPA-KQB1QFWS6QNM", secondReceiverAccount.get("id")); + assertEquals("secundario_1@labs.moip.com.br", secondReceiverAccount.get("login")); + assertEquals("Maria da Silva Santos", secondReceiverAccount.get("fullname")); + + assertEquals("SECONDARY", receivers.get(1).get("type")); + + Map secondReceiverAmount = parser.objectToMap(receivers.get(1).get("amount")); + assertEquals(55, secondReceiverAmount.get("total")); + assertEquals("BRL", secondReceiverAmount.get("currency")); + assertEquals(0, secondReceiverAmount.get("fees")); + assertEquals(0, secondReceiverAmount.get("refunds")); + + assertEquals(false, receivers.get(1).get("feePayor")); + + Map links1 = parser.objectToMap(order.get("_links")); + Map self1 = parser.objectToMap(links1.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-GRZP5CX0LSSL", self1.get("href")); + } + + private void firstOrderFromGet(Map order) { + + assertEquals("ORD-UMVGMZLNFQFW", order.get("id")); + assertEquals("order_1412", order.get("ownId")); + assertEquals("CREATED", order.get("status")); + assertEquals("V2", order.get("platform")); + assertEquals("2018-08-03T17:23:50.000-03", order.get("createdAt")); + assertEquals("2018-08-03T17:23:50.000-03", order.get("updatedAt")); + + Map amount = parser.objectToMap(order.get("amount")); + assertEquals(0, amount.get("paid")); + assertEquals(4000, 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(2000, subtotals.get("shipping")); + assertEquals(0, subtotals.get("addition")); + assertEquals(0, subtotals.get("discount")); + assertEquals(2000, subtotals.get("items")); + + List> items = parser.objectToList(order.get("items")); + assertEquals("Camisa Verde e Amarelo - Brasil", items.get(0).get("product")); + assertEquals(2000, items.get(0).get("price")); + assertEquals("Seleção Brasileira", items.get(0).get("detail")); + assertEquals(1, items.get(0).get("quantity")); + + Map customer = parser.objectToMap(order.get("customer")); + customer(customer); + + 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-08-03T17:23:50.000-03", events.get(0).get("createdAt")); + assertEquals("", events.get(0).get("description")); + + List> receivers = parser.objectToList(order.get("receivers")); + Map receiverMoipAccount = parser.objectToMap(receivers.get(0).get("moipAccount")); + assertEquals("MPA-VB5OGTVPCI52", receiverMoipAccount.get("id")); + assertEquals("lojista_1@labs.moip.com.br", receiverMoipAccount.get("login")); + assertEquals("Chris Coyier Moip", receiverMoipAccount.get("fullname")); + + assertEquals("PRIMARY", receivers.get(0).get("type")); + + Map receiverAmount = parser.objectToMap(receivers.get(0).get("amount")); + assertEquals(4000, receiverAmount.get("total")); + assertEquals("BRL", receiverAmount.get("currency")); + assertEquals(0, receiverAmount.get("fees")); + assertEquals(0, receiverAmount.get("refunds")); + + assertEquals(false, receivers.get(0).get("feePayor")); + + Map links0 = parser.objectToMap(order.get("_links")); + Map self0 = parser.objectToMap(links0.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-UMVGMZLNFQFW", self0.get("href")); + } + + private void secondOrderFromGet(Map order) { + + assertEquals("ORD-GRZP5CX0LSSL", order.get("id")); + assertEquals("order_12441512", order.get("ownId")); + assertEquals("CREATED", order.get("status")); + assertEquals("V2", order.get("platform")); + assertEquals("2018-08-03T17:23:50.000-03", order.get("createdAt")); + assertEquals("2018-08-03T17:23:50.000-03", order.get("updatedAt")); + + Map amount = parser.objectToMap(order.get("amount")); + assertEquals(0, amount.get("paid")); + assertEquals(4000, 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(3000, subtotals.get("shipping")); + assertEquals(0, subtotals.get("addition")); + assertEquals(0, subtotals.get("discount")); + assertEquals(1000, subtotals.get("items")); + + List> items = parser.objectToList(order.get("items")); + assertEquals("Camisa Preta - Alemanha", items.get(0).get("product")); + assertEquals(1000, items.get(0).get("price")); + assertEquals("Camiseta da Copa 2014", items.get(0).get("detail")); + assertEquals(1, items.get(0).get("quantity")); + + Map customer = parser.objectToMap(order.get("customer")); + customer(customer); + + List> payments1 = parser.objectToList(order.get("payments")); + assertTrue(payments1.isEmpty()); + + List> escrows1 = parser.objectToList(order.get("escrows")); + assertTrue(escrows1.isEmpty()); + + List> refunds1 = parser.objectToList(order.get("refunds")); + assertTrue(refunds1.isEmpty()); + + List> entries1 = parser.objectToList(order.get("entries")); + assertTrue(entries1.isEmpty()); + + List> events1 = parser.objectToList(order.get("events")); + assertEquals("ORDER.CREATED", events1.get(0).get("type")); + assertEquals("2018-08-03T17:23:50.000-03", events1.get(0).get("createdAt")); + assertEquals("", events1.get(0).get("description")); + + List> receivers = parser.objectToList(order.get("receivers")); + + Map firstReceiverAccount = parser.objectToMap(receivers.get(0).get("moipAccount")); + assertEquals("MPA-IFYRB1HBL73Z", firstReceiverAccount.get("id")); + assertEquals("lojista_3@labs.moip.com.br", firstReceiverAccount.get("login")); + assertEquals("Lojista 3 Moip", firstReceiverAccount.get("fullname")); + + assertEquals("PRIMARY", receivers.get(0).get("type")); + + Map firstReceiverAmount = parser.objectToMap(receivers.get(0).get("amount")); + assertEquals(3945, firstReceiverAmount.get("total")); + assertEquals("BRL", firstReceiverAmount.get("currency")); + assertEquals(0, firstReceiverAmount.get("fees")); + assertEquals(0, firstReceiverAmount.get("refunds")); + + assertEquals(false, receivers.get(0).get("feePayor")); + + Map secondReceiverAccount = parser.objectToMap(receivers.get(1).get("moipAccount")); + assertEquals("MPA-KQB1QFWS6QNM", secondReceiverAccount.get("id")); + assertEquals("secundario_1@labs.moip.com.br", secondReceiverAccount.get("login")); + assertEquals("Maria da Silva Santos", secondReceiverAccount.get("fullname")); + + assertEquals("SECONDARY", receivers.get(1).get("type")); + + Map secondReceiverAmount = parser.objectToMap(receivers.get(1).get("amount")); + assertEquals(55, secondReceiverAmount.get("total")); + assertEquals("BRL", secondReceiverAmount.get("currency")); + assertEquals(0, secondReceiverAmount.get("fees")); + assertEquals(0, secondReceiverAmount.get("refunds")); + + assertEquals(false, receivers.get(1).get("feePayor")); + + Map links1 = parser.objectToMap(order.get("_links")); + Map self1 = parser.objectToMap(links1.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/orders/ORD-GRZP5CX0LSSL", self1.get("href")); + } +} diff --git a/src/test/java/br/com/moip/unit_tests/MultipaymentTest.java b/src/test/java/br/com/moip/unit_tests/MultipaymentTest.java new file mode 100644 index 0000000..3954608 --- /dev/null +++ b/src/test/java/br/com/moip/unit_tests/MultipaymentTest.java @@ -0,0 +1,197 @@ +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 MultipaymentTest { + + @Rule + public Player player = new Player(); + private Parser parser = new Parser(); + private Setup setup; + private Map variables; + + @Before + public void initialize() { + this.variables = new HashMap<>(); + this.setup = new SetupFactory().setupOAuth(player.getURL("").toString()); + } + + @Play("multipayment/capture_pre_authorized") + @Test + public void capturePreAuthorizedTest() { + + variables.put("id", "PAY-8JYH1UX882LL"); + variables.put("status", "AUTHORIZED"); + variables.put("delayCapture", true); + + Map multipayment = Moip.API.multipayments().capturePreAuthorized("MPY-EVAWT7HR8QEP", setup); + + assertEquals("MPY-EVAWT7HR8QEP", multipayment.get("id")); + assertEquals("AUTHORIZED", multipayment.get("status")); + + Map amount = parser.objectToMap(multipayment.get("amount")); + assertEquals(8000, amount.get("total")); + assertEquals("BRL", amount.get("currency")); + + assertEquals(1, multipayment.get("installmentCount")); + + List> payments = parser.objectToList(multipayment.get("payments")); + testPaymentsFromMultipayment(payments.get(0), variables); + + Map links = parser.objectToMap(multipayment.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/multipayments/MPY-EVAWT7HR8QEP", self.get("href")); + + Map multiorder = parser.objectToMap(links.get("multiorder")); + assertEquals("https://sandbox.moip.com.br/v2/multiorders/MOR-ZB4W3W0S0NUF", multiorder.get("href")); + } + + @Play("multipayment/cancel_pre_authorized") + @Test + public void cancelPreAuthorizedTest() { + + variables.put("id", "PAY-TEXWW7CUBHM1"); + variables.put("status", "CANCELLED"); + variables.put("delayCapture", true); + + Map multipayment = Moip.API.multipayments().cancelPreAuthorized("MPY-8X6E4HB9FNGK", setup); + + assertEquals("MPY-8X6E4HB9FNGK", multipayment.get("id")); + assertEquals("CANCELLED", multipayment.get("status")); + + Map amount = parser.objectToMap(multipayment.get("amount")); + assertEquals(8000, amount.get("total")); + assertEquals("BRL", amount.get("currency")); + + assertEquals(1, multipayment.get("installmentCount")); + + List> payments = parser.objectToList(multipayment.get("payments")); + testPaymentsFromMultipayment(payments.get(0), variables); + + Map links = parser.objectToMap(multipayment.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/multipayments/MPY-8X6E4HB9FNGK", self.get("href")); + + Map multiorder = parser.objectToMap(links.get("multiorder")); + assertEquals("https://sandbox.moip.com.br/v2/multiorders/MOR-2A6SGDFHQ54O", multiorder.get("href")); + } + + @Play("multipayment/get") + @Test + public void getMultipaymentTest() { + + variables.put("id", "PAY-DY1WE4PCPMLZ"); + variables.put("status", "AUTHORIZED"); + variables.put("delayCapture", false); + + Map multipayment = Moip.API.multipayments().get("MPY-TTNVH6J6KBNC", setup); + + assertEquals("MPY-TTNVH6J6KBNC", multipayment.get("id")); + assertEquals("AUTHORIZED", multipayment.get("status")); + + Map amount = parser.objectToMap(multipayment.get("amount")); + assertEquals(8000, amount.get("total")); + assertEquals("BRL", amount.get("currency")); + + assertEquals(1, multipayment.get("installmentCount")); + + List> payments = parser.objectToList(multipayment.get("payments")); + testPaymentsFromMultipayment(payments.get(0), variables); + + Map links = parser.objectToMap(multipayment.get("_links")); + Map self = parser.objectToMap(links.get("self")); + assertEquals("https://sandbox.moip.com.br/v2/multipayments/MPY-TTNVH6J6KBNC", self.get("href")); + + Map multiorder = parser.objectToMap(links.get("multiorder")); + assertEquals("https://sandbox.moip.com.br/v2/multiorders/MOR-R6Q839MNWWO2", multiorder.get("href")); + } + + void testPaymentsFromMultipayment(Map payment, Map variables) { + + assertEquals(variables.get("id"), payment.get("id")); + assertEquals(variables.get("status"), payment.get("status")); + assertEquals(variables.get("delayCapture"), payment.get("delayCapture")); + + if ("CANCELLED".equals(variables.get("status"))) { + Map cancellationDetails = parser.objectToMap(payment.get("cancellationDetails")); + assertEquals("7", cancellationDetails.get("code")); + assertEquals("Política do Moip", cancellationDetails.get("description")); + assertEquals("MOIP", cancellationDetails.get("cancelledBy")); + } + + Map amount = parser.objectToMap(payment.get("amount")); + assertEquals(4000, amount.get("total")); + assertEquals(4000, amount.get("gross")); + assertEquals(289, amount.get("fees")); + assertEquals(0, amount.get("refunds")); + assertEquals(3711, amount.get("liquid")); + assertEquals("BRL", amount.get("currency")); + + assertEquals(1, payment.get("installmentCount")); + + Map fundingInstrument = parser.objectToMap(payment.get("fundingInstrument")); + Map creditCard = parser.objectToMap(fundingInstrument.get("creditCard")); + assertEquals("CRC-2HY3YCJS9WPD", 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 taxDocument = parser.objectToMap(holder.get("taxDocument")); + assertEquals("CPF", taxDocument.get("type")); + assertEquals("33333333333", taxDocument.get("number")); + + assertEquals("Jose Portador da Silva", holder.get("fullname")); + + assertEquals("CREDIT_CARD", fundingInstrument.get("method")); + + Map acquirerDetails = parser.objectToMap(payment.get("acquirerDetails")); + + if (acquirerDetails.get("authorizationNumber") != null) + assertEquals("123456", acquirerDetails.get("authorizationNumber")); + + Map document = parser.objectToMap(acquirerDetails.get("taxDocument")); + assertEquals("CNPJ", document.get("type")); + assertEquals("01027058000191", document.get("number")); + + List> fees = parser.objectToList(payment.get("fees")); + assertEquals("TRANSACTION", fees.get(0).get("type")); + assertEquals(289, fees.get(0).get("amount")); + + List> receivers = parser.objectToList(payment.get("receivers")); + testReceivers(receivers.get(0)); + + if (1 < receivers.size()) testReceivers(receivers.get(1)); + } + + private void testReceivers(Map receiver) { + + Map moipAccount = parser.objectToMap(receiver.get("moipAccount")); + assertEquals("MPA-VB5OGTVPCI52", moipAccount.get("id")); + assertEquals("lojista_1@labs.moip.com.br", moipAccount.get("login")); + assertEquals("Chris Coyier Moip", moipAccount.get("fullname")); + + Map amount = parser.objectToMap(receiver.get("amount")); + assertEquals(4000, amount.get("total")); + assertEquals("BRL", amount.get("currency")); + assertEquals(289, amount.get("fees")); + assertEquals(0, amount.get("refunds")); + } +} diff --git a/src/test/java/br/com/moip/unit_tests/NotificationTest.java b/src/test/java/br/com/moip/unit_tests/NotificationTest.java index b50efdd..7902430 100644 --- a/src/test/java/br/com/moip/unit_tests/NotificationTest.java +++ b/src/test/java/br/com/moip/unit_tests/NotificationTest.java @@ -28,7 +28,7 @@ public class NotificationTest { @Before public void initialize() { this.body = new HashMap<>(); - this.setup = new SetupFactory().setup(player.getURL("").toString()); + this.setup = new SetupFactory().setupBasicAuth(player.getURL("").toString()); this.parser = new Parser(); } diff --git a/src/test/java/br/com/moip/unit_tests/OrderTest.java b/src/test/java/br/com/moip/unit_tests/OrderTest.java index 84d950c..8445726 100644 --- a/src/test/java/br/com/moip/unit_tests/OrderTest.java +++ b/src/test/java/br/com/moip/unit_tests/OrderTest.java @@ -29,7 +29,7 @@ public class OrderTest { @Before public void initialize() { this.body = new HashMap<>(); - this.setup = new SetupFactory().setup(player.getURL("").toString()); + this.setup = new SetupFactory().setupBasicAuth(player.getURL("").toString()); this.parser = new Parser(); } diff --git a/src/test/java/br/com/moip/unit_tests/PaymentTest.java b/src/test/java/br/com/moip/unit_tests/PaymentTest.java index 8e858b4..4349d4a 100644 --- a/src/test/java/br/com/moip/unit_tests/PaymentTest.java +++ b/src/test/java/br/com/moip/unit_tests/PaymentTest.java @@ -27,7 +27,7 @@ public class PaymentTest { @Before public void initialize() { this.body = new HashMap<>(); - this.setup = new SetupFactory().setup(player.getURL("").toString()); + this.setup = new SetupFactory().setupBasicAuth(player.getURL("").toString()); this.parser = new Parser(); } diff --git a/src/test/java/br/com/moip/unit_tests/RefundTest.java b/src/test/java/br/com/moip/unit_tests/RefundTest.java index 30cb605..c58c3e9 100644 --- a/src/test/java/br/com/moip/unit_tests/RefundTest.java +++ b/src/test/java/br/com/moip/unit_tests/RefundTest.java @@ -27,7 +27,7 @@ public class RefundTest { @Before public void initialize() { this.body = new HashMap<>(); - this.setup = new SetupFactory().setup(player.getURL("").toString()); + this.setup = new SetupFactory().setupBasicAuth(player.getURL("").toString()); this.parser = new Parser(); } diff --git a/src/test/java/br/com/moip/unit_tests/TransferTest.java b/src/test/java/br/com/moip/unit_tests/TransferTest.java new file mode 100644 index 0000000..4e21220 --- /dev/null +++ b/src/test/java/br/com/moip/unit_tests/TransferTest.java @@ -0,0 +1,226 @@ +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 TransferTest { + + @Rule + public Player player = new Player(); + private Parser parser = new Parser(); + private Setup setup; + private Map body; + private Map variables; + + @Before + public void initialize() { + this.body = new HashMap<>(); + this.variables = new HashMap<>(); + this.setup = new SetupFactory().setupOAuth(player.getURL("").toString()); + } + + @Play("transfer/create") + @Test + public void createTransferTest() { + + variables.put("fee", 0); + variables.put("amount", 500); + variables.put("updatedAt", "2018-08-17T17:45:15.804Z"); + variables.put("id", "TRA-EW1UQ14495JI"); + variables.put("moipAccountId", "MPA-92DC9F7EF8B5"); + variables.put("moipAccountEmail", "wemersonsantoos@hotmail.com"); + variables.put("moipAccountLogin", "wemersonsantoos@hotmail.com"); + variables.put("moipAccountFullname", "Wemerson Santos"); + variables.put("senderAccountId", "MPA-CULBBYHD11"); + variables.put("transferInstrumentMethod", "MOIP_ACCOUNT"); + variables.put("status", "REQUESTED"); + variables.put("eventCreatedAt", "2018-08-17T17:45:16.000Z"); + variables.put("eventDescription", "Requested"); + variables.put("eventType", "TRANSFER.REQUESTED"); + variables.put("createdAt", "2018-08-17T17:45:15.804Z"); + variables.put("role", "PAYER"); + variables.put("selfHref", "https://sandbox.moip.com.br/v2/transfers/TRA-EW1UQ14495JI"); + + Map transfer = Moip.API.transfers().create(body, setup); + + testTransferBody(transfer, variables); + } + + @Play("transfer/revert") + @Test + public void revertTransferTest() { + + variables.put("fee", 0); + variables.put("amount", 500); + variables.put("updatedAt", "2018-08-17T17:45:52.372Z"); + variables.put("id", "TRA-EW1UQ14495JI"); + variables.put("moipAccountId", "MPA-92DC9F7EF8B5"); + variables.put("moipAccountEmail", "wemersonsantoos@hotmail.com"); + variables.put("moipAccountLogin", "wemersonsantoos@hotmail.com"); + variables.put("moipAccountFullname", "Wemerson Santos"); + variables.put("senderAccountId", "MPA-CULBBYHD11"); + variables.put("transferInstrumentMethod", "MOIP_ACCOUNT"); + variables.put("status", "REVERSED"); + variables.put("eventCreatedAt", "2018-08-17T17:45:16.000Z"); + variables.put("eventDescription", "Requested"); + variables.put("eventType", "TRANSFER.REQUESTED"); + variables.put("eventCreatedAt2", "2018-08-17T17:45:52.000Z"); + variables.put("eventDescription2", "Reversed"); + variables.put("eventType2", "TRANSFER.REVERSED"); + variables.put("createdAt", "2018-08-17T17:45:16.000Z"); + variables.put("role", "RECEIVER"); + variables.put("reverseHref", "https://sandbox.moip.com.br/v2/transfers/TRA-EW1UQ14495JI/reverse"); + variables.put("selfHref", "https://sandbox.moip.com.br/v2/transfers/TRA-EW1UQ14495JI"); + + Map revert = Moip.API.transfers().revert("TRA-EW1UQ14495JI", setup); + + testTransferBody(revert, variables); + } + + @Play("transfer/get") + @Test + public void getTransferTest() { + + variables.put("fee", 0); + variables.put("amount", 500); + variables.put("updatedAt", "2018-08-17T17:45:52.000Z"); + variables.put("id", "TRA-EW1UQ14495JI"); + variables.put("moipAccountId", "MPA-92DC9F7EF8B5"); + variables.put("moipAccountEmail", "wemersonsantoos@hotmail.com"); + variables.put("moipAccountLogin", "wemersonsantoos@hotmail.com"); + variables.put("moipAccountFullname", "Wemerson Santos"); + variables.put("senderAccountId", "MPA-CULBBYHD11"); + variables.put("transferInstrumentMethod", "MOIP_ACCOUNT"); + variables.put("status", "REVERSED"); + variables.put("eventCreatedAt", "2018-08-17T17:45:16.000Z"); + variables.put("eventDescription", "Requested"); + variables.put("eventType", "TRANSFER.REQUESTED"); + variables.put("eventCreatedAt2", "2018-08-17T17:45:52.000Z"); + variables.put("eventDescription2", "Reversed"); + variables.put("eventType2", "TRANSFER.REVERSED"); + variables.put("createdAt", "2018-08-17T17:45:16.000Z"); + variables.put("role", "PAYER"); + variables.put("selfHref", "https://sandbox.moip.com.br/v2/transfers/TRA-EW1UQ14495JI"); + + Map transfer = Moip.API.transfers().get("TRA-EW1UQ14495JI", setup); + + testTransferBody(transfer, variables); + } + + @Play("transfer/list") + @Test + public void listTransfersTest() { + + variables.put("fee", 0); + variables.put("amount", 500); + variables.put("updatedAt", "2018-08-17T17:45:52.000Z"); + variables.put("id", "TRA-EW1UQ14495JI"); + variables.put("moipAccountId", "MPA-92DC9F7EF8B5"); + variables.put("moipAccountEmail", "wemersonsantoos@hotmail.com"); + variables.put("moipAccountLogin", "wemersonsantoos@hotmail.com"); + variables.put("moipAccountFullname", "Wemerson Santos"); + variables.put("senderAccountId", "MPA-CULBBYHD11"); + variables.put("transferInstrumentMethod", "MOIP_ACCOUNT"); + variables.put("status", "REVERSED"); + variables.put("eventCreatedAt", "2018-08-17T17:45:16.000Z"); + variables.put("eventDescription", "Requested"); + variables.put("eventType", "TRANSFER.REQUESTED"); + variables.put("eventCreatedAt2", "2018-08-17T17:45:52.000Z"); + variables.put("eventDescription2", "Reversed"); + variables.put("eventType2", "TRANSFER.REVERSED"); + variables.put("createdAt", "2018-08-17T17:45:16.000Z"); + variables.put("role", "PAYER"); + variables.put("selfHref", "https://sandbox.moip.com.br/v2/transfers/TRA-EW1UQ14495JI"); + + Map list = Moip.API.transfers().list(setup); + + Map summary = parser.objectToMap(list.get("summary")); + assertEquals(659741662, summary.get("amount")); + assertEquals(31776, summary.get("count")); + + List> transfers = parser.objectToList(list.get("transfers")); + testTransferBody(transfers.get(0), variables); + + Map links = parser.objectToMap(list.get("_links")); + Map previous = parser.objectToMap(links.get("previous")); + assertEquals("https://sandbox.moip.com.br/v2/transfers?offset=0&limit=20", previous.get("href")); + + Map next = parser.objectToMap(links.get("next")); + assertEquals("https://sandbox.moip.com.br/v2/transfers?offset=20&limit=20", next.get("href")); + } + + private void testTransferBody(Map transfer, Map variables) { + + assertEquals(variables.get("fee"), transfer.get("fee")); + assertEquals(variables.get("amount"), transfer.get("amount")); + assertEquals(variables.get("updatedAt"), transfer.get("updatedAt")); + assertEquals(variables.get("id"), transfer.get("id")); + + Map transferInstrument = parser.objectToMap(transfer.get("transferInstrument")); + testTransferInstrument(transferInstrument, variables); + + assertEquals(variables.get("status"), transfer.get("status")); + + if (transfer.get("events") != null) { + + List> events = parser.objectToList(transfer.get("events")); + testEvents(events.get(0), variables); + } + + assertEquals(variables.get("createdAt"), transfer.get("createdAt")); + assertEquals(variables.get("role"), transfer.get("role")); + + Map links = parser.objectToMap(transfer.get("_links")); + testLinks(links, variables); + } + + private void testTransferInstrument(Map transferInstrument, Map variables) { + + Map moipAccount = parser.objectToMap(transferInstrument.get("moipAccount")); + assertEquals(variables.get("moipAccountId"), moipAccount.get("id")); + assertEquals(variables.get("moipAccountEmail"), moipAccount.get("email")); + assertEquals(variables.get("moipAccountLogin"), moipAccount.get("login")); + assertEquals(variables.get("moipAccountFullname"), moipAccount.get("fullname")); + + assertEquals(variables.get("senderAccountId"), transferInstrument.get("senderAccountId")); + assertEquals(variables.get("transferInstrumentMethod"), transferInstrument.get("method")); + } + + private void testEvents(Map event, Map variables) { + + assertEquals(variables.get("eventCreatedAt"), event.get("createdAt")); + assertEquals(variables.get("eventDescription"), event.get("description")); + assertEquals(variables.get("eventType"), event.get("type")); + + if (event.get("eventCreatedAt2") != null) { + assertEquals(variables.get("eventCreatedAt2"), event.get("createdAt")); + assertEquals(variables.get("eventDescription2"), event.get("description")); + assertEquals(variables.get("eventType2"), event.get("type")); + } + } + + private void testLinks(Map links, Map variables) { + + if (links.get("reverse") != null) { + + Map reverse = parser.objectToMap(links.get("reverse")); + assertEquals(variables.get("reverseHref"), reverse.get("href")); + } + + Map self = parser.objectToMap(links.get("self")); + assertEquals(variables.get("selfHref"), self.get("href")); + } +} 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 index dce941c..fdde990 100644 --- a/src/test/java/br/com/moip/unit_tests/setup/SetupFactory.java +++ b/src/test/java/br/com/moip/unit_tests/setup/SetupFactory.java @@ -2,6 +2,7 @@ import br.com.moip.auth.Authentication; import br.com.moip.auth.BasicAuth; +import br.com.moip.auth.OAuth; import br.com.moip.models.Setup; public class SetupFactory { @@ -9,9 +10,16 @@ public class SetupFactory { private static final String token = "01010101010101010101010101010101"; private static final String key = "ABABABABABABABABABABABABABABABABABABABAB"; - private static final Authentication auth = new BasicAuth(token, key); + private static final String accessToken = "8833c9eb036543b6b0acd685a76c9ead_v2"; - public Setup setup(final String endpoint) { - return new Setup().setAuthentication(auth).setPlayerEndpoint(endpoint); + private static final Authentication basic = new BasicAuth(token, key); + private static final Authentication oauth = new OAuth(accessToken); + + public Setup setupBasicAuth(final String endpoint) { + return new Setup().setAuthentication(basic).setPlayerEndpoint(endpoint); + } + + public Setup setupOAuth(final String endpoint) { + return new Setup().setAuthentication(oauth).setPlayerEndpoint(endpoint); } } diff --git a/src/test/resources/plays/account/check_existence_by_email.yaml b/src/test/resources/plays/account/check_existence_by_email.yaml new file mode 100644 index 0000000..14729b8 --- /dev/null +++ b/src/test/resources/plays/account/check_existence_by_email.yaml @@ -0,0 +1,15 @@ +!play +interactions: +- + request: + uri: /v2/accounts/exists?email=test@moip.com.br + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + 200 \ No newline at end of file diff --git a/src/test/resources/plays/account/check_existence_by_tax_document.yaml b/src/test/resources/plays/account/check_existence_by_tax_document.yaml new file mode 100644 index 0000000..147b6da --- /dev/null +++ b/src/test/resources/plays/account/check_existence_by_tax_document.yaml @@ -0,0 +1,15 @@ +!play +interactions: +- + request: + uri: /v2/accounts/exists?tax_document=123.456.789-00 + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + 200 \ No newline at end of file diff --git a/src/test/resources/plays/account/create_bank_account.yaml b/src/test/resources/plays/account/create_bank_account.yaml new file mode 100644 index 0000000..6d16447 --- /dev/null +++ b/src/test/resources/plays/account/create_bank_account.yaml @@ -0,0 +1,39 @@ +!play +interactions: +- + request: + uri: /v2/accounts/MPA-CULBBYHD11/bankaccounts + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "id": "BKA-SD5MQZEBIM1E", + "agencyNumber": "12345", + "holder": { + "taxDocument": { + "number": "255.328.259-12", + "type": "CPF" + }, + "thirdParty": false, + "fullname": "Jose Silva dos Santos" + }, + "accountNumber": "12345678", + "status": "NOT_VERIFIED", + "createdAt": "2018-08-13T17:03:35.021-03:00", + "accountCheckNumber": "7", + "_links": { + "self": { + "href": "https://sandbox.moip.com.br//accounts/BKA-SD5MQZEBIM1E/bankaccounts" + } + }, + "bankName": "BANCO BRADESCO S.A.", + "type": "CHECKING", + "agencyCheckNumber": "0", + "bankNumber": "237" + } \ No newline at end of file diff --git a/src/test/resources/plays/account/create_classical_account.yaml b/src/test/resources/plays/account/create_classical_account.yaml new file mode 100644 index 0000000..64fbbfb --- /dev/null +++ b/src/test/resources/plays/account/create_classical_account.yaml @@ -0,0 +1,99 @@ +!play +interactions: +- + request: + uri: /v2/accounts + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "id": "MPA-6A4F2AF0CED7", + "login": "my_test_0012930001@moip.com.br", + "accessToken": "8229ae27902746058561e2b9e71d12b9_v2", + "channelId": "APP-ML6Y8VWT7XFN", + "type": "MERCHANT", + "transparentAccount": false, + "email": { + "address": "my_test_0012930001@moip.com.br", + "confirmed": false + }, + "person": { + "name": "Runscope", + "lastName": "Random 9123", + "birthDate": "1990-01-01", + "taxDocument": { + "type": "CPF", + "number": "123.456.798-91" + }, + "address": { + "street": "Av. Brigadeiro Faria Lima", + "streetNumber": "2927", + "district": "Itaim", + "zipcode": "01234000", + "zipCode": "01234000", + "city": "São Paulo", + "state": "SP", + "country": "BRA" + }, + "phone": { + "countryCode": "55", + "areaCode": "11", + "number": "965213244", + "verified": false, + "phoneType": "cellphone" + }, + "identityDocument": { + "number": "434322344", + "issuer": "SSP", + "issueDate": "2000-12-12", + "type": "RG" + } + }, + "company": { + "name": "Empresa Moip", + "businessName": "Moip Pagamentos", + "taxDocument": { + "type": "CNPJ", + "number": "40.674.727/0001-79" + }, + "address": { + "street": "Av. Brigadeiro Faria Lima", + "streetNumber": "2927", + "district": "Itaim", + "zipcode": "01234000", + "zipCode": "01234000", + "city": "São Paulo", + "state": "SP", + "country": "BRA" + }, + "phone": { + "countryCode": "55", + "areaCode": "11", + "number": "32234455", + "verified": false, + "phoneType": "not_informed" + }, + "openingDate": "2011-01-01" + }, + "businessSegment": { + "id": 3, + "name": "Eletrônicos / Jogos de vídeo game", + "mcc": 7622 + }, + "createdAt": "2018-07-31T22:33:09.497Z", + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/moipaccounts/MPA-6A4F2AF0CED7", + "title": null + }, + "setPassword": { + "href": "https://desenvolvedor.moip.com.br/sandbox/AskForNewPassword.do?method=confirm&email=my_test_0012930001%40moip.com.br&code=b1cdd30fbcf728cd530f4e13c3ff4e4b" + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/account/create_transparent_account.yaml b/src/test/resources/plays/account/create_transparent_account.yaml new file mode 100644 index 0000000..a54d1e8 --- /dev/null +++ b/src/test/resources/plays/account/create_transparent_account.yaml @@ -0,0 +1,65 @@ +!play +interactions: +- + request: + uri: /v2/accounts + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "id": "MPA-51E0C7A09DF6", + "login": "my_test_1204102@moip.com.br", + "accessToken": "4a2893051cfe490c8c1284d90fac8c02_v2", + "channelId": "APP-ML6Y8VWT7XFN", + "type": "MERCHANT", + "transparentAccount": true, + "email": { + "address": "my_test_1204102@moip.com.br", + "confirmed": false + }, + "person": { + "name": "Runscope", + "lastName": "Random 9123", + "birthDate": "1990-01-01", + "taxDocument": { + "type": "CPF", + "number": "123.456.798-91" + }, + "address": { + "street": "Av. Brigadeiro Faria Lima", + "streetNumber": "2927", + "district": "Itaim", + "zipcode": "01234000", + "zipCode": "01234000", + "city": "São Paulo", + "state": "SP", + "country": "BRA" + }, + "phone": { + "countryCode": "55", + "areaCode": "11", + "number": "965213244", + "verified": false, + "phoneType": "cellphone" + }, + "identityDocument": { + "number": "434322344", + "issuer": "SSP", + "issueDate": "2000-12-12", + "type": "RG" + } + }, + "createdAt": "2018-08-01T16:26:45.903Z", + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/moipaccounts/MPA-51E0C7A09DF6", + "title": null + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/account/get.yaml b/src/test/resources/plays/account/get.yaml new file mode 100644 index 0000000..257aee4 --- /dev/null +++ b/src/test/resources/plays/account/get.yaml @@ -0,0 +1,91 @@ +!play +interactions: +- + request: + uri: /v2/accounts/MPA-6A4F2AF0CED7 + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "person": { + "lastName": "Random 9123", + "phone": { + "areaCode": "11", + "countryCode": "55", + "number": "965213244" + }, + "parentsName": { + "mother": "", + "father": "" + }, + "address": { + "zipcode": "01234-000", + "zipCode": "01234-000", + "street": "Av. Brigadeiro Faria Lima", + "state": "SP", + "streetNumber": "2927", + "district": "Itaim", + "country": "BRA", + "city": "São Paulo" + }, + "taxDocument": { + "number": "123.456.798-91", + "type": "CPF" + }, + "name": "Runscope", + "birthDate": "1990-01-01" + }, + "transparentAccount": false, + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/accounts/MPA-6A4F2AF0CED7" + } + }, + "monthlyRevenueId": 0, + "type": "MERCHANT", + "id": "MPA-6A4F2AF0CED7", + "email": { + "confirmed": true, + "address": "my_test_0012930001@moip.com.br" + }, + "createdAt": "2018-07-31T19:33:09.000-03:00", + "company": { + "monthlyRevenue": "", + "businessName": "Moip Pagamentos", + "phone": { + "areaCode": "11", + "countryCode": "55", + "number": "32234455" + }, + "openingDate": "2011-01-01", + "address": { + "complement": "", + "zipcode": "01234-000", + "zipCode": "01234-000", + "street": "Av. Brigadeiro Faria Lima", + "state": "SP", + "streetNumber": "2927", + "district": "Itaim", + "country": "BRA", + "city": "São Paulo" + }, + "taxDocument": { + "number": "40.674.727/0001-79", + "type": "CNPJ" + }, + "name": "Empresa Moip", + "constitutionType": "" + }, + "businessSegment": { + "id": 3 + }, + "feeType": "FIXED_TABLE_FEE", + "login": "my_test_0012930001@moip.com.br", + "softDescriptor": "Empresa Moip" + } \ No newline at end of file diff --git a/src/test/resources/plays/account/get_keys.yaml b/src/test/resources/plays/account/get_keys.yaml new file mode 100644 index 0000000..c0d414b --- /dev/null +++ b/src/test/resources/plays/account/get_keys.yaml @@ -0,0 +1,23 @@ +!play +interactions: +- + request: + uri: /v2/keys + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "keys": { + "basicAuth": { + "secret": "ABABABABABABABABABABABABABABABABABABABAB", + "token": "01010101010101010101010101010101" + }, + "encryption": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoBttaXwRoI1Fbcond5mS\n7QOb7X2lykY5hvvDeLJelvFhpeLnS4YDwkrnziM3W00UNH1yiSDU+3JhfHu5G387\nO6uN9rIHXvL+TRzkVfa5iIjG+ap2N0/toPzy5ekpgxBicjtyPHEgoU6dRzdszEF4\nItimGk5ACx/lMOvctncS5j3uWBaTPwyn0hshmtDwClf6dEZgQvm/dNaIkxHKV+9j\nMn3ZfK/liT8A3xwaVvRzzuxf09xJTXrAd9v5VQbeWGxwFcW05oJulSFjmJA9Hcmb\nDYHJT+sG2mlZDEruCGAzCVubJwGY1aRlcs9AQc1jIm/l8JwH7le2kpk3QoX+gz0w\nWwIDAQAB\n-----END PUBLIC KEY-----\n" + } + } \ No newline at end of file diff --git a/src/test/resources/plays/account/list_bank_accounts.yaml b/src/test/resources/plays/account/list_bank_accounts.yaml new file mode 100644 index 0000000..b4ec155 --- /dev/null +++ b/src/test/resources/plays/account/list_bank_accounts.yaml @@ -0,0 +1,66 @@ +!play +interactions: +- + request: + uri: /v2/accounts/MPA-CULBBYHD11/bankaccounts + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + [ + { + "id": "BKA-KS1LVCCH0P25", + "agencyNumber": "1111", + "accountNumber": "11111111", + "holder": { + "thirdParty": false, + "taxDocument": { + "number": "255.328.259-12", + "type": "CPF" + }, + "fullname": "Jose Silva dos Santos" + }, + "status": "NOT_VERIFIED", + "createdAt": "2016-04-07T15:25:57.000-03:00", + "accountCheckNumber": "1", + "_links": { + "self": { + "href": "https://sandbox.moip.com.br//accounts/BKA-KS1LVCCH0P25/bankaccounts" + } + }, + "bankName": "BANCO DO BRASIL S.A.", + "type": "CHECKING", + "agencyCheckNumber": "1", + "bankNumber": "001" + }, + { + "id": "BKA-OHXN5SOS8RQR", + "agencyNumber": "12345", + "accountNumber": "12345678", + "holder": { + "thirdParty": false, + "taxDocument": { + "number": "255.328.259-12", + "type": "CPF" + }, + "fullname": "Jose Silva dos Santos" + }, + "status": "IN_VERIFICATION", + "createdAt": "2016-04-07T15:50:10.000-03:00", + "accountCheckNumber": "7", + "_links": { + "self": { + "href": "https://sandbox.moip.com.br//accounts/BKA-OHXN5SOS8RQR/bankaccounts" + } + }, + "bankName": "BANCO BRADESCO S.A.", + "type": "CHECKING", + "agencyCheckNumber": "0", + "bankNumber": "237" + } + ] \ No newline at end of file diff --git a/src/test/resources/plays/balances/get.yaml b/src/test/resources/plays/balances/get.yaml new file mode 100644 index 0000000..c22b1a7 --- /dev/null +++ b/src/test/resources/plays/balances/get.yaml @@ -0,0 +1,35 @@ +!play +interactions: +- + request: + uri: /v2/balances + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + Accept: application/json;version=2.1 + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "unavailable": [ + { + "amount": 0, + "currency": "BRL" + } + ], + "future": [ + { + "amount": 64629427, + "currency": "BRL" + } + ], + "current": [ + { + "amount": 1094194873, + "currency": "BRL" + } + ] + } \ No newline at end of file diff --git a/src/test/resources/plays/bankaccount/get.yaml b/src/test/resources/plays/bankaccount/get.yaml new file mode 100644 index 0000000..e2735db --- /dev/null +++ b/src/test/resources/plays/bankaccount/get.yaml @@ -0,0 +1,39 @@ +!play +interactions: +- + request: + uri: /v2/bankaccounts/BKA-EQW51MWMAO22 + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "id": "BKA-EQW51MWMAO22", + "agencyNumber": "1111", + "holder": { + "taxDocument": { + "number": "255.328.259-12", + "type": "CPF" + }, + "thirdParty": false, + "fullname": "Jose Silva dos Santos" + }, + "accountNumber": "11111111", + "status": "IN_VERIFICATION", + "createdAt": "2016-04-07T15:23:48.000-03:00", + "accountCheckNumber": "1", + "_links": { + "self": { + "href": "https://sandbox.moip.com.br//accounts/BKA-EQW51MWMAO22/bankaccounts" + } + }, + "bankName": "BANCO DO BRASIL S.A.", + "type": "CHECKING", + "agencyCheckNumber": "1", + "bankNumber": "001" + } \ No newline at end of file diff --git a/src/test/resources/plays/bankaccount/update.yaml b/src/test/resources/plays/bankaccount/update.yaml new file mode 100644 index 0000000..da114b7 --- /dev/null +++ b/src/test/resources/plays/bankaccount/update.yaml @@ -0,0 +1,39 @@ +!play +interactions: +- + request: + uri: /v2/bankaccounts/BKA-EQW51MWMAO22 + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: PUT + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "id": "BKA-EQW51MWMAO22", + "agencyNumber": "2222", + "holder": { + "taxDocument": { + "number": "255.328.259-12", + "type": "CPF" + }, + "thirdParty": false, + "fullname": "Jose Silva dos Santos" + }, + "accountNumber": "12365478", + "status": "VERIFIED", + "createdAt": "2016-04-07T15:23:48.000-03:00", + "accountCheckNumber": "1", + "_links": { + "self": { + "href": "https://sandbox.moip.com.br//accounts/BKA-EQW51MWMAO22/bankaccounts" + } + }, + "bankName": "BANCO DO BRASIL S.A.", + "type": "CHECKING", + "agencyCheckNumber": "1", + "bankNumber": "001" + } \ No newline at end of file diff --git a/src/test/resources/plays/connect/generate_access_token.yaml b/src/test/resources/plays/connect/generate_access_token.yaml new file mode 100644 index 0000000..5d5e438 --- /dev/null +++ b/src/test/resources/plays/connect/generate_access_token.yaml @@ -0,0 +1,25 @@ +!play +interactions: +- + request: + uri: /oauth/token + headers: + Content-Type: application/x-www-form-urlencoded + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "accessToken": "0c6937d062874507b9c19748d8e0f8df_v2", + "access_token": "0c6937d062874507b9c19748d8e0f8df_v2", + "expires_in": "2028-08-02", + "refreshToken": "c1384b7aa4a8432b8fcfad26622cb917_v2", + "refresh_token": "c1384b7aa4a8432b8fcfad26622cb917_v2", + "scope": "TRANSFER_FUNDS,RECEIVE_FUNDS", + "moipAccount": { + "id": "MPA-14C9EE706C55" + } + } \ No newline at end of file diff --git a/src/test/resources/plays/connect/refresh_access_token.yaml b/src/test/resources/plays/connect/refresh_access_token.yaml new file mode 100644 index 0000000..de1dae4 --- /dev/null +++ b/src/test/resources/plays/connect/refresh_access_token.yaml @@ -0,0 +1,25 @@ +!play +interactions: +- + request: + uri: /oauth/token + headers: + Content-Type: application/x-www-form-urlencoded + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "accessToken": "fb65d9d88bdf47d39d90ead6b290e17b_v2", + "access_token": "fb65d9d88bdf47d39d90ead6b290e17b_v2", + "expires_in": "2028-08-02", + "refreshToken": "e466a50bb6fb414aa0ea937ddf6ca71b_v2", + "refresh_token": "e466a50bb6fb414aa0ea937ddf6ca71b_v2", + "scope": "TRANSFER_FUNDS,RECEIVE_FUNDS", + "moipAccount": { + "id": "MPA-14C9EE706C55" + } + } \ No newline at end of file diff --git a/src/test/resources/plays/entry/get.yaml b/src/test/resources/plays/entry/get.yaml new file mode 100644 index 0000000..83ff18e --- /dev/null +++ b/src/test/resources/plays/entry/get.yaml @@ -0,0 +1,56 @@ +!play +interactions: +- + request: + uri: /v2/entries/ENT-2JHP5A593QSW + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + Accept: application/json;version=2.1 + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "reschedule": [], + "scheduledFor": "2012-08-31T16:59:36.000Z", + "status": "SETTLED", + "moipAccount": { + "id": "MPA-CULBBYHD11" + }, + "_links": { + "self": { + "title": "ENT-2JHP5A593QSW", + "href": "https://sandbox.moip.com.br/v2/entries/ENT-2JHP5A593QSW" + } + }, + "fees": [ + { + "amount": 150, + "type": "TRANSACTION" + } + ], + "type": "CREDIT_CARD", + "ownId": "", + "updatedAt": "2014-04-16T16:16:12.000Z", + "id": "ENT-2JHP5A593QSW", + "amount": { + "fee": 150, + "total": 150, + "liquid": 0, + "currency": "BRL" + }, + "operation": "CREDIT", + "createdAt": "2014-04-16T16:16:12.000Z", + "event": "PAY-AQITTDNDKBU9", + "description": "Cartao de credito - Pedido ORD-UF4E00XMFDL1", + "occurrence": { + "to": 1, + "in": 1 + }, + "blocked": false, + "settledAt": "2012-08-31T00:00:00.000Z", + "additionalId": 145470 + } \ No newline at end of file diff --git a/src/test/resources/plays/entry/list.yaml b/src/test/resources/plays/entry/list.yaml new file mode 100644 index 0000000..5bb2517 --- /dev/null +++ b/src/test/resources/plays/entry/list.yaml @@ -0,0 +1,95 @@ +!play +interactions: +- + request: + uri: /v2/entries + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + Accept: application/json;version=2.1 + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "summary": { + "amount": 1494494396, + "count": 48561 + }, + "_links": { + "previous": { + "href": "https://sandbox.moip.com.br/v2/entries?offset=0&limit=20" + }, + "next": { + "href": "https://sandbox.moip.com.br/v2/entries?offset=20&limit=20" + } + }, + "entries": [ + { + "reschedule": [], + "scheduledFor": "2012-08-31T16:59:36.000Z", + "status": "SETTLED", + "_links": { + "self": { + "title": "ENT-2JHP5A593QSW", + "href": "https://sandbox.moip.com.br/v2/entries/ENT-2JHP5A593QSW" + } + }, + "type": "CREDIT_CARD", + "ownId": "", + "updatedAt": "2014-04-16T16:16:12.000Z", + "id": "ENT-2JHP5A593QSW", + "amount": { + "fee": 150, + "total": 150, + "liquid": 0, + "currency": "BRL" + }, + "operation": "CREDIT", + "createdAt": "2014-04-16T16:16:12.000Z", + "event": "PAY-AQITTDNDKBU9", + "description": "Cartao de credito - Pedido ORD-UF4E00XMFDL1", + "occurrence": { + "to": 1, + "in": 1 + }, + "blocked": false, + "settledAt": "2012-08-31T00:00:00.000Z", + "additionalId": 145470 + }, + { + "reschedule": [], + "scheduledFor": "2012-09-07T00:00:00.000Z", + "status": "SETTLED", + "_links": { + "self": { + "title": "ENT-RSYUVS4C59PO", + "href": "https://sandbox.moip.com.br/v2/entries/ENT-RSYUVS4C59PO" + } + }, + "type": "MOIP_WALLET", + "ownId": "", + "updatedAt": "2014-04-16T16:16:12.000Z", + "id": "ENT-RSYUVS4C59PO", + "amount": { + "fee": 83, + "total": 1500, + "liquid": 1417, + "currency": "BRL" + }, + "operation": "CREDIT", + "createdAt": "2014-04-16T16:16:12.000Z", + "event": "PAY-VCOEO2GV65DE", + "description": "Conta Moip - Pedido ORD-F4LJ3TF0ZGRN", + "occurrence": { + "to": 1, + "in": 1 + }, + "blocked": false, + "settledAt": "2012-09-07T00:00:00.000Z", + "additionalId": 145466 + } + ] + } \ No newline at end of file diff --git a/src/test/resources/plays/escrow/release.yaml b/src/test/resources/plays/escrow/release.yaml new file mode 100644 index 0000000..8da0acb --- /dev/null +++ b/src/test/resources/plays/escrow/release.yaml @@ -0,0 +1,35 @@ +!play +interactions: +- + request: + uri: /v2/escrows/ECW-QI13E7A7ONDQ/release + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: POST + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "id": "ECW-QI13E7A7ONDQ", + "status": "RELEASED", + "description": "Custódia de pagamento", + "amount": 23000, + "createdAt": "2018-08-20T10:27:45.000-03", + "updatedAt": "2018-08-20T10:27:45.000-03", + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/escrows/ECW-QI13E7A7ONDQ" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-FY97DC35UZ2W", + "title": "ORD-FY97DC35UZ2W" + }, + "payment": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-ARF0D5ELVX5D", + "title": "PAY-ARF0D5ELVX5D" + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/multiorder/create.yaml b/src/test/resources/plays/multiorder/create.yaml new file mode 100644 index 0000000..88077a6 --- /dev/null +++ b/src/test/resources/plays/multiorder/create.yaml @@ -0,0 +1,362 @@ +!play +interactions: +- + request: + uri: /v2/multiorders + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "id": "MOR-R6Q839MNWWO2", + "ownId": "multiorder_id_121414", + "status": "CREATED", + "createdAt": "2018-08-03T17:23:50.230-03", + "updatedAt": "", + "amount": { + "total": 8000, + "currency": "BRL" + }, + "orders": [ + { + "id": "ORD-UMVGMZLNFQFW", + "ownId": "order_1412", + "status": "CREATED", + "platform": "V2", + "createdAt": "2018-08-03T17:23:50.230-03", + "updatedAt": "2018-08-03T17:23:50.230-03", + "amount": { + "paid": 0, + "total": 4000, + "fees": 0, + "refunds": 0, + "liquid": 0, + "otherReceivers": 0, + "currency": "BRL", + "subtotals": { + "shipping": 2000, + "addition": 0, + "discount": 0, + "items": 2000 + } + }, + "items": [ + { + "product": "Camisa Verde e Amarelo - Brasil", + "price": 2000, + "detail": "Seleção Brasileira", + "quantity": 1 + } + ], + "customer": { + "id": "CUS-COEFORVOX64K", + "ownId": "customer[1234]", + "fullname": "Joao Sousa", + "createdAt": "2015-07-01T18:12:33.000-03", + "updatedAt": "2018-08-03T17:23:50.256-03", + "birthDate": "1988-12-30", + "email": "joao.sousa@email.com", + "fundingInstrument": { + "creditCard": { + "id": "CRC-A3ZNIT523OYB", + "brand": "VISA", + "first6": "407302", + "last4": "0002", + "store": true + }, + "method": "CREDIT_CARD" + }, + "phone": { + "countryCode": "55", + "areaCode": "11", + "number": "66778899" + }, + "taxDocument": { + "type": "CPF", + "number": "22222222222" + }, + "shippingAddress": { + "zipCode": "01234000", + "street": "Avenida Faria Lima", + "streetNumber": "2927", + "complement": "8", + "city": "Sao Paulo", + "district": "Itaim", + "state": "SP", + "country": "BRA" + }, + "billingAddress": { + "zipCode": "01234000", + "street": "Avenida Faria Lima", + "streetNumber": "2927", + "complement": "8", + "city": "Sao Paulo", + "district": "Itaim", + "state": "SP", + "country": "BRA" + }, + "moipAccount": { + "id": "MPA-PQ0H8UZYNNWY" + }, + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/customers/CUS-COEFORVOX64K" + } + }, + "fundingInstruments": [ + { + "creditCard": { + "id": "CRC-0DWSR8500SWI", + "brand": "VISA", + "first6": "401200", + "last4": "3335", + "store": true + }, + "method": "CREDIT_CARD" + }, + { + "creditCard": { + "id": "CRC-PMH3KO5OPWSC", + "brand": "VISA", + "first6": "401200", + "last4": "3335", + "store": true + }, + "method": "CREDIT_CARD" + } + ] + }, + "payments": [], + "escrows": [], + "refunds": [], + "entries": [], + "events": [ + { + "type": "ORDER.CREATED", + "createdAt": "2018-08-03T17:23:50.230-03", + "description": "" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-VB5OGTVPCI52", + "login": "lojista_1@labs.moip.com.br", + "fullname": "Chris Coyier Moip" + }, + "type": "PRIMARY", + "amount": { + "total": 4000, + "currency": "BRL", + "fees": 0, + "refunds": 0 + }, + "feePayor": false + } + ], + "shippingAddress": { + "zipCode": "01234000", + "street": "Avenida Faria Lima", + "streetNumber": "2927", + "complement": "8", + "city": "Sao Paulo", + "district": "Itaim", + "state": "SP", + "country": "BRA" + }, + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-UMVGMZLNFQFW" + } + } + }, + { + "id": "ORD-GRZP5CX0LSSL", + "ownId": "order_12441512", + "status": "CREATED", + "platform": "V2", + "createdAt": "2018-08-03T17:23:50.269-03", + "updatedAt": "2018-08-03T17:23:50.269-03", + "amount": { + "paid": 0, + "total": 4000, + "fees": 0, + "refunds": 0, + "liquid": 0, + "otherReceivers": 0, + "currency": "BRL", + "subtotals": { + "shipping": 3000, + "addition": 0, + "discount": 0, + "items": 1000 + } + }, + "items": [ + { + "product": "Camisa Preta - Alemanha", + "price": 1000, + "detail": "Camiseta da Copa 2014", + "quantity": 1 + } + ], + "customer": { + "id": "CUS-COEFORVOX64K", + "ownId": "customer[1234]", + "fullname": "Joao Sousa", + "createdAt": "2015-07-01T18:12:33.000-03", + "updatedAt": "2018-08-03T17:23:50.274-03", + "birthDate": "1988-12-30", + "email": "joao.sousa@email.com", + "fundingInstrument": { + "creditCard": { + "id": "CRC-A3ZNIT523OYB", + "brand": "VISA", + "first6": "407302", + "last4": "0002", + "store": true + }, + "method": "CREDIT_CARD" + }, + "phone": { + "countryCode": "55", + "areaCode": "11", + "number": "66778899" + }, + "taxDocument": { + "type": "CPF", + "number": "22222222222" + }, + "shippingAddress": { + "zipCode": "01234000", + "street": "Avenida Faria Lima", + "streetNumber": "2927", + "complement": "8", + "city": "Sao Paulo", + "district": "Itaim", + "state": "SP", + "country": "BRA" + }, + "billingAddress": { + "zipCode": "01234000", + "street": "Avenida Faria Lima", + "streetNumber": "2927", + "complement": "8", + "city": "Sao Paulo", + "district": "Itaim", + "state": "SP", + "country": "BRA" + }, + "moipAccount": { + "id": "MPA-PQ0H8UZYNNWY" + }, + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/customers/CUS-COEFORVOX64K" + } + }, + "fundingInstruments": [ + { + "creditCard": { + "id": "CRC-0DWSR8500SWI", + "brand": "VISA", + "first6": "401200", + "last4": "3335", + "store": true + }, + "method": "CREDIT_CARD" + }, + { + "creditCard": { + "id": "CRC-PMH3KO5OPWSC", + "brand": "VISA", + "first6": "401200", + "last4": "3335", + "store": true + }, + "method": "CREDIT_CARD" + } + ] + }, + "payments": [], + "escrows": [], + "refunds": [], + "entries": [], + "events": [ + { + "type": "ORDER.CREATED", + "createdAt": "2018-08-03T17:23:50.269-03", + "description": "" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-IFYRB1HBL73Z", + "login": "lojista_3@labs.moip.com.br", + "fullname": "Lojista 3 Moip" + }, + "type": "PRIMARY", + "amount": { + "total": 3945, + "currency": "BRL", + "fees": 0, + "refunds": 0 + }, + "feePayor": false + }, + { + "moipAccount": { + "id": "MPA-KQB1QFWS6QNM", + "login": "secundario_1@labs.moip.com.br", + "fullname": "Maria da Silva Santos" + }, + "type": "SECONDARY", + "amount": { + "total": 55, + "currency": "BRL", + "fees": 0, + "refunds": 0 + }, + "feePayor": false + } + ], + "shippingAddress": { + "zipCode": "01234000", + "street": "Avenida Faria Lima", + "streetNumber": "2927", + "complement": "8", + "city": "Sao Paulo", + "district": "Itaim", + "state": "SP", + "country": "BRA" + }, + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-GRZP5CX0LSSL" + } + } + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/orders/MOR-R6Q839MNWWO2" + }, + "checkout": { + "payCreditCard": { + "redirectHref": "https://checkout-sandbox.moip.com.br/creditcard/MOR-R6Q839MNWWO2" + }, + "payBoleto": { + "redirectHref": "https://checkout-sandbox.moip.com.br/boleto/MOR-R6Q839MNWWO2" + }, + "payOnlineBankDebitItau": { + "redirectHref": "https://checkout-sandbox.moip.com.br/debit/itau/MOR-R6Q839MNWWO2" + } + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/multiorder/get.yaml b/src/test/resources/plays/multiorder/get.yaml new file mode 100644 index 0000000..3d8d858 --- /dev/null +++ b/src/test/resources/plays/multiorder/get.yaml @@ -0,0 +1,362 @@ +!play +interactions: +- + request: + uri: /v2/multiorders/MOR-R6Q839MNWWO2 + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "id": "MOR-R6Q839MNWWO2", + "ownId": "multiorder_id_121414", + "status": "CREATED", + "createdAt": "2018-08-03T17:23:50.000-03", + "updatedAt": "", + "amount": { + "total": 8000, + "currency": "BRL" + }, + "orders": [ + { + "id": "ORD-UMVGMZLNFQFW", + "ownId": "order_1412", + "status": "CREATED", + "platform": "V2", + "createdAt": "2018-08-03T17:23:50.000-03", + "updatedAt": "2018-08-03T17:23:50.000-03", + "amount": { + "paid": 0, + "total": 4000, + "fees": 0, + "refunds": 0, + "liquid": 0, + "otherReceivers": 0, + "currency": "BRL", + "subtotals": { + "shipping": 2000, + "addition": 0, + "discount": 0, + "items": 2000 + } + }, + "items": [ + { + "product": "Camisa Verde e Amarelo - Brasil", + "price": 2000, + "detail": "Seleção Brasileira", + "quantity": 1 + } + ], + "customer": { + "id": "CUS-COEFORVOX64K", + "ownId": "customer[1234]", + "fullname": "Joao Sousa", + "createdAt": "2015-07-01T18:12:33.000-03", + "updatedAt": "2018-08-03T17:23:50.000-03", + "birthDate": "1988-12-30", + "email": "joao.sousa@email.com", + "fundingInstrument": { + "creditCard": { + "id": "CRC-A3ZNIT523OYB", + "brand": "VISA", + "first6": "407302", + "last4": "0002", + "store": true + }, + "method": "CREDIT_CARD" + }, + "phone": { + "countryCode": "55", + "areaCode": "11", + "number": "66778899" + }, + "taxDocument": { + "type": "CPF", + "number": "22222222222" + }, + "shippingAddress": { + "zipCode": "01234000", + "street": "Avenida Faria Lima", + "streetNumber": "2927", + "complement": "8", + "city": "Sao Paulo", + "district": "Itaim", + "state": "SP", + "country": "BRA" + }, + "billingAddress": { + "zipCode": "01234000", + "street": "Avenida Faria Lima", + "streetNumber": "2927", + "complement": "8", + "city": "Sao Paulo", + "district": "Itaim", + "state": "SP", + "country": "BRA" + }, + "moipAccount": { + "id": "MPA-PQ0H8UZYNNWY" + }, + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/customers/CUS-COEFORVOX64K" + } + }, + "fundingInstruments": [ + { + "creditCard": { + "id": "CRC-0DWSR8500SWI", + "brand": "VISA", + "first6": "401200", + "last4": "3335", + "store": true + }, + "method": "CREDIT_CARD" + }, + { + "creditCard": { + "id": "CRC-PMH3KO5OPWSC", + "brand": "VISA", + "first6": "401200", + "last4": "3335", + "store": true + }, + "method": "CREDIT_CARD" + } + ] + }, + "payments": [], + "escrows": [], + "refunds": [], + "entries": [], + "events": [ + { + "type": "ORDER.CREATED", + "createdAt": "2018-08-03T17:23:50.000-03", + "description": "" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-VB5OGTVPCI52", + "login": "lojista_1@labs.moip.com.br", + "fullname": "Chris Coyier Moip" + }, + "type": "PRIMARY", + "amount": { + "total": 4000, + "currency": "BRL", + "fees": 0, + "refunds": 0 + }, + "feePayor": false + } + ], + "shippingAddress": { + "zipCode": "01234000", + "street": "Avenida Faria Lima", + "streetNumber": "2927", + "complement": "8", + "city": "Sao Paulo", + "district": "Itaim", + "state": "SP", + "country": "BRA" + }, + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-UMVGMZLNFQFW" + } + } + }, + { + "id": "ORD-GRZP5CX0LSSL", + "ownId": "order_12441512", + "status": "CREATED", + "platform": "V2", + "createdAt": "2018-08-03T17:23:50.000-03", + "updatedAt": "2018-08-03T17:23:50.000-03", + "amount": { + "paid": 0, + "total": 4000, + "fees": 0, + "refunds": 0, + "liquid": 0, + "otherReceivers": 0, + "currency": "BRL", + "subtotals": { + "shipping": 3000, + "addition": 0, + "discount": 0, + "items": 1000 + } + }, + "items": [ + { + "product": "Camisa Preta - Alemanha", + "price": 1000, + "detail": "Camiseta da Copa 2014", + "quantity": 1 + } + ], + "customer": { + "id": "CUS-COEFORVOX64K", + "ownId": "customer[1234]", + "fullname": "Joao Sousa", + "createdAt": "2015-07-01T18:12:33.000-03", + "updatedAt": "2018-08-03T17:23:50.000-03", + "birthDate": "1988-12-30", + "email": "joao.sousa@email.com", + "fundingInstrument": { + "creditCard": { + "id": "CRC-A3ZNIT523OYB", + "brand": "VISA", + "first6": "407302", + "last4": "0002", + "store": true + }, + "method": "CREDIT_CARD" + }, + "phone": { + "countryCode": "55", + "areaCode": "11", + "number": "66778899" + }, + "taxDocument": { + "type": "CPF", + "number": "22222222222" + }, + "shippingAddress": { + "zipCode": "01234000", + "street": "Avenida Faria Lima", + "streetNumber": "2927", + "complement": "8", + "city": "Sao Paulo", + "district": "Itaim", + "state": "SP", + "country": "BRA" + }, + "billingAddress": { + "zipCode": "01234000", + "street": "Avenida Faria Lima", + "streetNumber": "2927", + "complement": "8", + "city": "Sao Paulo", + "district": "Itaim", + "state": "SP", + "country": "BRA" + }, + "moipAccount": { + "id": "MPA-PQ0H8UZYNNWY" + }, + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/customers/CUS-COEFORVOX64K" + } + }, + "fundingInstruments": [ + { + "creditCard": { + "id": "CRC-0DWSR8500SWI", + "brand": "VISA", + "first6": "401200", + "last4": "3335", + "store": true + }, + "method": "CREDIT_CARD" + }, + { + "creditCard": { + "id": "CRC-PMH3KO5OPWSC", + "brand": "VISA", + "first6": "401200", + "last4": "3335", + "store": true + }, + "method": "CREDIT_CARD" + } + ] + }, + "payments": [], + "escrows": [], + "refunds": [], + "entries": [], + "events": [ + { + "type": "ORDER.CREATED", + "createdAt": "2018-08-03T17:23:50.000-03", + "description": "" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-IFYRB1HBL73Z", + "login": "lojista_3@labs.moip.com.br", + "fullname": "Lojista 3 Moip" + }, + "type": "PRIMARY", + "amount": { + "total": 3945, + "currency": "BRL", + "fees": 0, + "refunds": 0 + }, + "feePayor": false + }, + { + "moipAccount": { + "id": "MPA-KQB1QFWS6QNM", + "login": "secundario_1@labs.moip.com.br", + "fullname": "Maria da Silva Santos" + }, + "type": "SECONDARY", + "amount": { + "total": 55, + "currency": "BRL", + "fees": 0, + "refunds": 0 + }, + "feePayor": false + } + ], + "shippingAddress": { + "zipCode": "01234000", + "street": "Avenida Faria Lima", + "streetNumber": "2927", + "complement": "8", + "city": "Sao Paulo", + "district": "Itaim", + "state": "SP", + "country": "BRA" + }, + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-GRZP5CX0LSSL" + } + } + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/orders/MOR-R6Q839MNWWO2" + }, + "checkout": { + "payCreditCard": { + "redirectHref": "https://checkout-sandbox.moip.com.br/creditcard/MOR-R6Q839MNWWO2" + }, + "payBoleto": { + "redirectHref": "https://checkout-sandbox.moip.com.br/boleto/MOR-R6Q839MNWWO2" + }, + "payOnlineBankDebitItau": { + "redirectHref": "https://checkout-sandbox.moip.com.br/debit/itau/MOR-R6Q839MNWWO2" + } + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/multiorder/pay_with_credit_card.yaml b/src/test/resources/plays/multiorder/pay_with_credit_card.yaml new file mode 100644 index 0000000..36ab0f5 --- /dev/null +++ b/src/test/resources/plays/multiorder/pay_with_credit_card.yaml @@ -0,0 +1,214 @@ +!play +interactions: +- + request: + uri: /v2/multiorders/MOR-R6Q839MNWWO2/multipayments + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "id": "MPY-TTNVH6J6KBNC", + "status": "WAITING", + "amount": { + "total": 8000, + "currency": "BRL" + }, + "installmentCount": 1, + "payments": [ + { + "id": "PAY-DY1WE4PCPMLZ", + "status": "WAITING", + "delayCapture": false, + "amount": { + "total": 4000, + "gross": 4000, + "fees": 289, + "refunds": 0, + "liquid": 3711, + "currency": "BRL" + }, + "installmentCount": 1, + "fundingInstrument": { + "creditCard": { + "id": "CRC-2HY3YCJS9WPD", + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true, + "holder": { + "birthdate": "1988-12-30", + "birthDate": "1988-12-30", + "taxDocument": { + "type": "CPF", + "number": "33333333333" + }, + "fullname": "Jose Portador da Silva" + } + }, + "method": "CREDIT_CARD" + }, + "acquirerDetails": { + "taxDocument": { + "type": "CNPJ", + "number": "01027058000191" + } + }, + "fees": [ + { + "type": "TRANSACTION", + "amount": 289 + } + ], + "events": [ + { + "type": "PAYMENT.CREATED", + "createdAt": "2018-08-07T13:50:11.000-03" + }, + { + "type": "PAYMENT.WAITING", + "createdAt": "2018-08-07T13:50:11.000-03" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-VB5OGTVPCI52", + "login": "lojista_1@labs.moip.com.br", + "fullname": "Chris Coyier Moip" + }, + "type": "PRIMARY", + "amount": { + "total": 4000, + "currency": "BRL", + "fees": 289, + "refunds": 0 + }, + "feePayor": true + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-DY1WE4PCPMLZ" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-UMVGMZLNFQFW", + "title": "ORD-UMVGMZLNFQFW" + } + }, + "createdAt": "2018-08-07T13:50:11.000-03", + "updatedAt": "2018-08-07T13:50:11.000-03" + }, + { + "id": "PAY-7P670FWYIZ82", + "status": "WAITING", + "delayCapture": false, + "amount": { + "total": 4000, + "gross": 4000, + "fees": 289, + "refunds": 0, + "liquid": 3711, + "currency": "BRL" + }, + "installmentCount": 1, + "fundingInstrument": { + "creditCard": { + "id": "CRC-2HY3YCJS9WPD", + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true, + "holder": { + "birthdate": "1988-12-30", + "birthDate": "1988-12-30", + "taxDocument": { + "type": "CPF", + "number": "33333333333" + }, + "fullname": "Jose Portador da Silva" + } + }, + "method": "CREDIT_CARD" + }, + "acquirerDetails": { + "taxDocument": { + "type": "CNPJ", + "number": "01027058000191" + } + }, + "fees": [ + { + "type": "TRANSACTION", + "amount": 289 + } + ], + "events": [ + { + "type": "PAYMENT.CREATED", + "createdAt": "2018-08-07T13:50:11.000-03" + }, + { + "type": "PAYMENT.WAITING", + "createdAt": "2018-08-07T13:50:11.000-03" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-VB5OGTVPCI52", + "login": "lojista_1@labs.moip.com.br", + "fullname": "Chris Coyier Moip" + }, + "type": "PRIMARY", + "amount": { + "total": 4000, + "currency": "BRL", + "fees": 289, + "refunds": 0 + }, + "feePayor": true + }, + { + "moipAccount": { + "id": "MPA-VB5OGTVPCI52", + "login": "lojista_1@labs.moip.com.br", + "fullname": "Chris Coyier Moip" + }, + "type": "SECONDARY", + "amount": { + "total": 4000, + "currency": "BRL", + "fees": 289, + "refunds": 0 + }, + "feePayor": false + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-7P670FWYIZ82" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-GRZP5CX0LSSL", + "title": "ORD-GRZP5CX0LSSL" + } + }, + "createdAt": "2018-08-07T13:50:11.000-03", + "updatedAt": "2018-08-07T13:50:11.000-03" + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/multipayments/MPY-TTNVH6J6KBNC" + }, + "multiorder": { + "href": "https://sandbox.moip.com.br/v2/multiorders/MOR-R6Q839MNWWO2" + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/multipayment/cancel_pre_authorized.yaml b/src/test/resources/plays/multipayment/cancel_pre_authorized.yaml new file mode 100644 index 0000000..b1f1d60 --- /dev/null +++ b/src/test/resources/plays/multipayment/cancel_pre_authorized.yaml @@ -0,0 +1,265 @@ +!play +interactions: +- + request: + uri: /v2/multipayments/MPY-8X6E4HB9FNGK/void + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: POST + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "id": "MPY-8X6E4HB9FNGK", + "status": "CANCELLED", + "amount": { + "total": 8000, + "currency": "BRL" + }, + "installmentCount": 1, + "payments": [ + { + "id": "PAY-TEXWW7CUBHM1", + "status": "CANCELLED", + "delayCapture": true, + "cancellationDetails": { + "code": "7", + "description": "Política do Moip", + "cancelledBy": "MOIP" + }, + "amount": { + "total": 4000, + "gross": 4000, + "fees": 289, + "refunds": 0, + "liquid": 3711, + "currency": "BRL" + }, + "installmentCount": 1, + "fundingInstrument": { + "creditCard": { + "id": "CRC-2HY3YCJS9WPD", + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true, + "holder": { + "birthdate": "1988-12-30", + "birthDate": "1988-12-30", + "taxDocument": { + "type": "CPF", + "number": "33333333333" + }, + "fullname": "Jose Portador da Silva" + } + }, + "method": "CREDIT_CARD" + }, + "acquirerDetails": { + "authorizationNumber": "123456", + "taxDocument": { + "type": "CNPJ", + "number": "01027058000191" + } + }, + "fees": [ + { + "type": "TRANSACTION", + "amount": 289 + } + ], + "events": [ + { + "type": "PAYMENT.CANCELLED", + "createdAt": "2018-08-07T14:32:58.839-03" + }, + { + "type": "PAYMENT.PRE_AUTHORIZED", + "createdAt": "2018-08-07T14:31:58.000-03" + }, + { + "type": "PAYMENT.IN_ANALYSIS", + "createdAt": "2018-08-07T14:31:57.000-03" + }, + { + "type": "PAYMENT.CREATED", + "createdAt": "2018-08-07T14:31:56.000-03" + }, + { + "type": "PAYMENT.WAITING", + "createdAt": "2018-08-07T14:31:56.000-03" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-VB5OGTVPCI52", + "login": "lojista_1@labs.moip.com.br", + "fullname": "Chris Coyier Moip" + }, + "type": "PRIMARY", + "amount": { + "total": 4000, + "currency": "BRL", + "fees": 289, + "refunds": 0 + }, + "feePayor": true + }, + { + "moipAccount": { + "id": "MPA-VB5OGTVPCI52", + "login": "lojista_1@labs.moip.com.br", + "fullname": "Chris Coyier Moip" + }, + "type": "PRIMARY", + "amount": { + "total": 4000, + "currency": "BRL", + "fees": 289, + "refunds": 0 + }, + "feePayor": true + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-TEXWW7CUBHM1" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-SQ401AO1WPFI", + "title": "ORD-SQ401AO1WPFI" + } + }, + "createdAt": "2018-08-07T14:31:55.000-03", + "updatedAt": "2018-08-07T14:32:58.838-03" + }, + { + "id": "PAY-OVOSGINGN1E4", + "status": "CANCELLED", + "delayCapture": true, + "cancellationDetails": { + "code": "7", + "description": "Política do Moip", + "cancelledBy": "MOIP" + }, + "amount": { + "total": 4000, + "gross": 4000, + "fees": 289, + "refunds": 0, + "liquid": 3711, + "currency": "BRL" + }, + "installmentCount": 1, + "fundingInstrument": { + "creditCard": { + "id": "CRC-2HY3YCJS9WPD", + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true, + "holder": { + "birthdate": "1988-12-30", + "birthDate": "1988-12-30", + "taxDocument": { + "type": "CPF", + "number": "33333333333" + }, + "fullname": "Jose Portador da Silva" + } + }, + "method": "CREDIT_CARD" + }, + "acquirerDetails": { + "authorizationNumber": "123456", + "taxDocument": { + "type": "CNPJ", + "number": "01027058000191" + } + }, + "fees": [ + { + "type": "TRANSACTION", + "amount": 289 + } + ], + "events": [ + { + "type": "PAYMENT.CANCELLED", + "createdAt": "2018-08-07T14:32:58.840-03" + }, + { + "type": "PAYMENT.PRE_AUTHORIZED", + "createdAt": "2018-08-07T14:31:58.000-03" + }, + { + "type": "PAYMENT.IN_ANALYSIS", + "createdAt": "2018-08-07T14:31:57.000-03" + }, + { + "type": "PAYMENT.CREATED", + "createdAt": "2018-08-07T14:31:56.000-03" + }, + { + "type": "PAYMENT.WAITING", + "createdAt": "2018-08-07T14:31:56.000-03" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-IFYRB1HBL73Z", + "login": "lojista_3@labs.moip.com.br", + "fullname": "Lojista 3 Moip" + }, + "type": "PRIMARY", + "amount": { + "total": 3945, + "currency": "BRL", + "fees": 0, + "refunds": 0 + }, + "feePayor": true + }, + { + "moipAccount": { + "id": "MPA-KQB1QFWS6QNM", + "login": "secundario_1@labs.moip.com.br", + "fullname": "Maria da Silva Santos" + }, + "type": "SECONDARY", + "amount": { + "total": 55, + "currency": "BRL", + "fees": 0, + "refunds": 0 + }, + "feePayor": false + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-OVOSGINGN1E4" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-H14NOIQE9FV5", + "title": "ORD-H14NOIQE9FV5" + } + }, + "createdAt": "2018-08-07T14:31:56.000-03", + "updatedAt": "2018-08-07T14:32:58.839-03" + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/multipayments/MPY-8X6E4HB9FNGK" + }, + "multiorder": { + "href": "https://sandbox.moip.com.br/v2/multiorders/MOR-2A6SGDFHQ54O" + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/multipayment/capture_pre_authorized.yaml b/src/test/resources/plays/multipayment/capture_pre_authorized.yaml new file mode 100644 index 0000000..a8e9b3e --- /dev/null +++ b/src/test/resources/plays/multipayment/capture_pre_authorized.yaml @@ -0,0 +1,240 @@ +!play +interactions: +- + request: + uri: /v2/multipayments/MPY-EVAWT7HR8QEP/capture + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: POST + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "id": "MPY-EVAWT7HR8QEP", + "status": "AUTHORIZED", + "amount": { + "total": 8000, + "currency": "BRL" + }, + "installmentCount": 1, + "payments": [ + { + "id": "PAY-8JYH1UX882LL", + "status": "AUTHORIZED", + "delayCapture": true, + "amount": { + "total": 4000, + "gross": 4000, + "fees": 289, + "refunds": 0, + "liquid": 3711, + "currency": "BRL" + }, + "installmentCount": 1, + "fundingInstrument": { + "creditCard": { + "id": "CRC-2HY3YCJS9WPD", + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true, + "holder": { + "birthdate": "1988-12-30", + "birthDate": "1988-12-30", + "taxDocument": { + "type": "CPF", + "number": "33333333333" + }, + "fullname": "Jose Portador da Silva" + } + }, + "method": "CREDIT_CARD" + }, + "acquirerDetails": { + "authorizationNumber": "123456", + "taxDocument": { + "type": "CNPJ", + "number": "01027058000191" + } + }, + "fees": [ + { + "type": "TRANSACTION", + "amount": 289 + } + ], + "events": [ + { + "type": "PAYMENT.AUTHORIZED", + "createdAt": "2018-08-07T14:26:13.470-03" + }, + { + "type": "PAYMENT.IN_ANALYSIS", + "createdAt": "2018-08-07T14:25:47.000-03" + }, + { + "type": "PAYMENT.PRE_AUTHORIZED", + "createdAt": "2018-08-07T14:25:47.000-03" + }, + { + "type": "PAYMENT.CREATED", + "createdAt": "2018-08-07T14:25:46.000-03" + }, + { + "type": "PAYMENT.WAITING", + "createdAt": "2018-08-07T14:25:46.000-03" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-VB5OGTVPCI52", + "login": "lojista_1@labs.moip.com.br", + "fullname": "Chris Coyier Moip" + }, + "type": "PRIMARY", + "amount": { + "total": 4000, + "currency": "BRL", + "fees": 289, + "refunds": 0 + }, + "feePayor": true + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-8JYH1UX882LL" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-HTQ7DYWIBC6R", + "title": "ORD-HTQ7DYWIBC6R" + } + }, + "createdAt": "2018-08-07T14:25:46.000-03", + "updatedAt": "2018-08-07T14:26:13.469-03" + }, + { + "id": "PAY-CU2X09XRBJU4", + "status": "AUTHORIZED", + "delayCapture": true, + "amount": { + "total": 4000, + "gross": 4000, + "fees": 289, + "refunds": 0, + "liquid": 3711, + "currency": "BRL" + }, + "installmentCount": 1, + "fundingInstrument": { + "creditCard": { + "id": "CRC-2HY3YCJS9WPD", + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true, + "holder": { + "birthdate": "1988-12-30", + "birthDate": "1988-12-30", + "taxDocument": { + "type": "CPF", + "number": "33333333333" + }, + "fullname": "Jose Portador da Silva" + } + }, + "method": "CREDIT_CARD" + }, + "acquirerDetails": { + "authorizationNumber": "123456", + "taxDocument": { + "type": "CNPJ", + "number": "01027058000191" + } + }, + "fees": [ + { + "type": "TRANSACTION", + "amount": 289 + } + ], + "events": [ + { + "type": "PAYMENT.AUTHORIZED", + "createdAt": "2018-08-07T14:26:13.471-03" + }, + { + "type": "PAYMENT.IN_ANALYSIS", + "createdAt": "2018-08-07T14:25:47.000-03" + }, + { + "type": "PAYMENT.PRE_AUTHORIZED", + "createdAt": "2018-08-07T14:25:47.000-03" + }, + { + "type": "PAYMENT.CREATED", + "createdAt": "2018-08-07T14:25:46.000-03" + }, + { + "type": "PAYMENT.WAITING", + "createdAt": "2018-08-07T14:25:46.000-03" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-IFYRB1HBL73Z", + "login": "lojista_3@labs.moip.com.br", + "fullname": "Lojista 3 Moip" + }, + "type": "PRIMARY", + "amount": { + "total": 3945, + "currency": "BRL", + "fees": 289, + "refunds": 0 + }, + "feePayor": true + }, + { + "moipAccount": { + "id": "MPA-KQB1QFWS6QNM", + "login": "secundario_1@labs.moip.com.br", + "fullname": "Maria da Silva Santos" + }, + "type": "SECONDARY", + "amount": { + "total": 55, + "currency": "BRL", + "fees": 0, + "refunds": 0 + }, + "feePayor": false + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-CU2X09XRBJU4" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-0HS3WT81WLWH", + "title": "ORD-0HS3WT81WLWH" + } + }, + "createdAt": "2018-08-07T14:25:46.000-03", + "updatedAt": "2018-08-07T14:26:13.470-03" + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/multipayments/MPY-EVAWT7HR8QEP" + }, + "multiorder": { + "href": "https://sandbox.moip.com.br/v2/multiorders/MOR-ZB4W3W0S0NUF" + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/multipayment/get.yaml b/src/test/resources/plays/multipayment/get.yaml new file mode 100644 index 0000000..09543da --- /dev/null +++ b/src/test/resources/plays/multipayment/get.yaml @@ -0,0 +1,232 @@ +!play +interactions: +- + request: + uri: /v2/multipayments/MPY-TTNVH6J6KBNC + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "id": "MPY-TTNVH6J6KBNC", + "status": "AUTHORIZED", + "amount": { + "total": 8000, + "currency": "BRL" + }, + "installmentCount": 1, + "payments": [ + { + "id": "PAY-DY1WE4PCPMLZ", + "status": "AUTHORIZED", + "delayCapture": false, + "amount": { + "total": 4000, + "gross": 4000, + "fees": 289, + "refunds": 0, + "liquid": 3711, + "currency": "BRL" + }, + "installmentCount": 1, + "fundingInstrument": { + "creditCard": { + "id": "CRC-2HY3YCJS9WPD", + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true, + "holder": { + "birthdate": "1988-12-30", + "birthDate": "1988-12-30", + "taxDocument": { + "type": "CPF", + "number": "33333333333" + }, + "fullname": "Jose Portador da Silva" + } + }, + "method": "CREDIT_CARD" + }, + "acquirerDetails": { + "authorizationNumber": "123456", + "taxDocument": { + "type": "CNPJ", + "number": "01027058000191" + } + }, + "fees": [ + { + "type": "TRANSACTION", + "amount": 289 + } + ], + "events": [ + { + "type": "PAYMENT.AUTHORIZED", + "createdAt": "2018-08-07T13:50:13.000-03" + }, + { + "type": "PAYMENT.IN_ANALYSIS", + "createdAt": "2018-08-07T13:50:12.000-03" + }, + { + "type": "PAYMENT.CREATED", + "createdAt": "2018-08-07T13:50:11.000-03" + }, + { + "type": "PAYMENT.WAITING", + "createdAt": "2018-08-07T13:50:11.000-03" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-VB5OGTVPCI52", + "login": "lojista_1@labs.moip.com.br", + "fullname": "Chris Coyier Moip" + }, + "type": "PRIMARY", + "amount": { + "total": 4000, + "currency": "BRL", + "fees": 289, + "refunds": 0 + }, + "feePayor": true + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-DY1WE4PCPMLZ" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-UMVGMZLNFQFW", + "title": "ORD-UMVGMZLNFQFW" + } + }, + "createdAt": "2018-08-07T13:50:11.000-03", + "updatedAt": "2018-08-07T13:50:13.000-03" + }, + { + "id": "PAY-7P670FWYIZ82", + "status": "AUTHORIZED", + "delayCapture": false, + "amount": { + "total": 4000, + "gross": 4000, + "fees": 289, + "refunds": 0, + "liquid": 3711, + "currency": "BRL" + }, + "installmentCount": 1, + "fundingInstrument": { + "creditCard": { + "id": "CRC-2HY3YCJS9WPD", + "brand": "MASTERCARD", + "first6": "555566", + "last4": "8884", + "store": true, + "holder": { + "birthdate": "1988-12-30", + "birthDate": "1988-12-30", + "taxDocument": { + "type": "CPF", + "number": "33333333333" + }, + "fullname": "Jose Portador da Silva" + } + }, + "method": "CREDIT_CARD" + }, + "acquirerDetails": { + "authorizationNumber": "123456", + "taxDocument": { + "type": "CNPJ", + "number": "01027058000191" + } + }, + "fees": [ + { + "type": "TRANSACTION", + "amount": 289 + } + ], + "events": [ + { + "type": "PAYMENT.AUTHORIZED", + "createdAt": "2018-08-07T13:50:13.000-03" + }, + { + "type": "PAYMENT.IN_ANALYSIS", + "createdAt": "2018-08-07T13:50:12.000-03" + }, + { + "type": "PAYMENT.CREATED", + "createdAt": "2018-08-07T13:50:11.000-03" + }, + { + "type": "PAYMENT.WAITING", + "createdAt": "2018-08-07T13:50:11.000-03" + } + ], + "receivers": [ + { + "moipAccount": { + "id": "MPA-IFYRB1HBL73Z", + "login": "lojista_3@labs.moip.com.br", + "fullname": "Lojista 3 Moip" + }, + "type": "PRIMARY", + "amount": { + "total": 3945, + "currency": "BRL", + "fees": 289, + "refunds": 0 + }, + "feePayor": true + }, + { + "moipAccount": { + "id": "MPA-KQB1QFWS6QNM", + "login": "secundario_1@labs.moip.com.br", + "fullname": "Maria da Silva Santos" + }, + "type": "SECONDARY", + "amount": { + "total": 55, + "currency": "BRL", + "fees": 0, + "refunds": 0 + }, + "feePayor": false + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/payments/PAY-7P670FWYIZ82" + }, + "order": { + "href": "https://sandbox.moip.com.br/v2/orders/ORD-GRZP5CX0LSSL", + "title": "ORD-GRZP5CX0LSSL" + } + }, + "createdAt": "2018-08-07T13:50:11.000-03", + "updatedAt": "2018-08-07T13:50:13.000-03" + } + ], + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/multipayments/MPY-TTNVH6J6KBNC" + }, + "multiorder": { + "href": "https://sandbox.moip.com.br/v2/multiorders/MOR-R6Q839MNWWO2" + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/transfer/create.yaml b/src/test/resources/plays/transfer/create.yaml new file mode 100644 index 0000000..4b77a3c --- /dev/null +++ b/src/test/resources/plays/transfer/create.yaml @@ -0,0 +1,78 @@ +!play +interactions: +- + request: + uri: /v2/transfers + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "fee": 0, + "amount": 500, + "updatedAt": "2018-08-17T17:45:15.804Z", + "id": "TRA-EW1UQ14495JI", + "transferInstrument": { + "moipAccount": { + "id": "MPA-92DC9F7EF8B5", + "email": "wemersonsantoos@hotmail.com", + "login": "wemersonsantoos@hotmail.com", + "fullname": "Wemerson Santos" + }, + "senderAccountId": "MPA-CULBBYHD11", + "method": "MOIP_ACCOUNT" + }, + "status": "REQUESTED", + "events": [ + { + "createdAt": "2018-08-17T17:45:16.000Z", + "description": "Requested", + "type": "TRANSFER.REQUESTED" + } + ], + "createdAt": "2018-08-17T17:45:15.804Z", + "entries": [ + { + "external_id": "ENT-2AZIW958PIID", + "reschedule": [], + "scheduledFor": "2018-08-17T17:45:15.000Z", + "status": "SETTLED", + "moipAccount": { + "account": "MPA-CULBBYHD11" + }, + "fees": [], + "type": "TRANSFER_TO_MOIP_ACCOUNT_PAID", + "grossAmount": -500, + "moipAccountId": 4477, + "updatedAt": "2018-08-17T17:45:16.090Z", + "id": 36943353, + "installment": { + "amount": 1, + "number": 1 + }, + "references": [ + { + "value": "APP-ML6Y8VWT7XFN", + "type": "CHANNEL" + } + ], + "eventId": "TRA-EW1UQ14495JI", + "createdAt": "2018-08-17T17:45:16.031Z", + "description": "Transferencia entre contas Moip realizada - TRA-EW1UQ14495JI", + "blocked": false, + "settledAt": "2018-08-17T17:45:16.090Z", + "liquidAmount": -500 + } + ], + "role": "PAYER", + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/transfers/TRA-EW1UQ14495JI" + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/transfer/get.yaml b/src/test/resources/plays/transfer/get.yaml new file mode 100644 index 0000000..7e77e31 --- /dev/null +++ b/src/test/resources/plays/transfer/get.yaml @@ -0,0 +1,114 @@ +!play +interactions: +- + request: + uri: /v2/transfers/TRA-EW1UQ14495JI + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "fee": 0, + "amount": 500, + "updatedAt": "2018-08-17T17:45:52.000Z", + "id": "TRA-EW1UQ14495JI", + "transferInstrument": { + "moipAccount": { + "id": "MPA-92DC9F7EF8B5", + "email": "wemersonsantoos@hotmail.com", + "login": "wemersonsantoos@hotmail.com", + "fullname": "Wemerson Santos" + }, + "senderAccountId": "MPA-CULBBYHD11", + "method": "MOIP_ACCOUNT" + }, + "status": "REVERSED", + "events": [ + { + "createdAt": "2018-08-17T17:45:16.000Z", + "description": "Requested", + "type": "TRANSFER.REQUESTED" + }, + { + "createdAt": "2018-08-17T17:45:52.000Z", + "description": "Reversed", + "type": "TRANSFER.REVERSED" + } + ], + "createdAt": "2018-08-17T17:45:16.000Z", + "entries": [ + { + "external_id": "ENT-2AZIW958PIID", + "reschedule": [], + "scheduledFor": "2018-08-17T17:45:15.000Z", + "status": "SETTLED", + "moipAccount": { + "account": "MPA-CULBBYHD11" + }, + "fees": [], + "type": "TRANSFER_TO_MOIP_ACCOUNT_PAID", + "grossAmount": -500, + "moipAccountId": 4477, + "updatedAt": "2018-08-17T17:45:16.000Z", + "id": 36943353, + "installment": { + "amount": 1, + "number": 1 + }, + "references": [ + { + "value": "APP-ML6Y8VWT7XFN", + "type": "CHANNEL" + } + ], + "eventId": "TRA-EW1UQ14495JI", + "createdAt": "2018-08-17T17:45:16.000Z", + "description": "Transferencia entre contas Moip realizada - TRA-EW1UQ14495JI", + "blocked": false, + "settledAt": "2018-08-17T17:45:16.000Z", + "liquidAmount": -500 + }, + { + "external_id": "ENT-HAIB2LI7XWOI", + "reschedule": [], + "scheduledFor": "2018-08-17T17:45:52.000Z", + "status": "SETTLED", + "moipAccount": { + "account": "MPA-CULBBYHD11" + }, + "fees": [], + "type": "TRANSFER_TO_MOIP_ACCOUNT_PAID_REVERTED", + "grossAmount": 500, + "moipAccountId": 4477, + "updatedAt": "2018-08-17T17:45:52.000Z", + "id": 36943360, + "installment": { + "amount": 1, + "number": 1 + }, + "references": [ + { + "value": "REF-BT4DYML6K32R", + "type": "REFUND" + } + ], + "eventId": "TRA-EW1UQ14495JI", + "createdAt": "2018-08-17T17:45:52.000Z", + "description": "Transferencia entre contas revertida - TRA-EW1UQ14495JI", + "blocked": false, + "settledAt": "2018-08-17T17:45:52.000Z", + "liquidAmount": 500 + } + ], + "role": "PAYER", + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/transfers/TRA-EW1UQ14495JI" + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/transfer/list.yaml b/src/test/resources/plays/transfer/list.yaml new file mode 100644 index 0000000..8233494 --- /dev/null +++ b/src/test/resources/plays/transfer/list.yaml @@ -0,0 +1,78 @@ +!play +interactions: +- + request: + uri: /v2/transfers + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: GET + response: + status: 200 + headers: + "Content-Type": application/json + body: | + { + "summary": { + "amount": 659741662, + "count": 31776 + }, + "transfers": [ + { + "fee": 0, + "amount": 500, + "updatedAt": "2018-08-17T17:45:52.000Z", + "id": "TRA-EW1UQ14495JI", + "transferInstrument": { + "moipAccount": { + "id": "MPA-92DC9F7EF8B5", + "email": "wemersonsantoos@hotmail.com", + "login": "wemersonsantoos@hotmail.com", + "fullname": "Wemerson Santos" + }, + "senderAccountId": "MPA-CULBBYHD11", + "method": "MOIP_ACCOUNT" + }, + "status": "REVERSED", + "createdAt": "2018-08-17T17:45:16.000Z", + "role": "PAYER", + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/transfers/TRA-EW1UQ14495JI" + } + } + }, + { + "fee": 0, + "amount": 500, + "updatedAt": "2018-08-16T21:31:18.000Z", + "id": "TRA-0KMLJYRDL1XR", + "transferInstrument": { + "moipAccount": { + "id": "MPA-5D5053C0B4A4", + "email": "mbnakaya25@gmail.com", + "login": "mbnakaya25@gmail.com", + "fullname": "Matheus Barbosa Nakaya" + }, + "senderAccountId": "MPA-CULBBYHD11", + "method": "MOIP_ACCOUNT" + }, + "status": "COMPLETED", + "createdAt": "2018-08-16T21:31:18.000Z", + "role": "PAYER", + "_links": { + "self": { + "href": "https://sandbox.moip.com.br/v2/transfers/TRA-0KMLJYRDL1XR" + } + } + } + ], + "_links": { + "previous": { + "href": "https://sandbox.moip.com.br/v2/transfers?offset=0&limit=20" + }, + "next": { + "href": "https://sandbox.moip.com.br/v2/transfers?offset=20&limit=20" + } + } + } \ No newline at end of file diff --git a/src/test/resources/plays/transfer/revert.yaml b/src/test/resources/plays/transfer/revert.yaml new file mode 100644 index 0000000..55f07e9 --- /dev/null +++ b/src/test/resources/plays/transfer/revert.yaml @@ -0,0 +1,54 @@ +!play +interactions: +- + request: + uri: /v2/transfers/TRA-EW1UQ14495JI/reverse + headers: + Content-Type: application/json + Authorization: OAuth 8833c9eb036543b6b0acd685a76c9ead_v2 + method: POST + response: + status: 201 + headers: + "Content-Type": application/json + body: | + { + "fee": 0, + "amount": 500, + "updatedAt": "2018-08-17T17:45:52.372Z", + "id": "TRA-EW1UQ14495JI", + "transferInstrument": { + "moipAccount": { + "id": "MPA-92DC9F7EF8B5", + "email": "wemersonsantoos@hotmail.com", + "login": "wemersonsantoos@hotmail.com", + "fullname": "Wemerson Santos" + }, + "senderAccountId": "MPA-CULBBYHD11", + "method": "MOIP_ACCOUNT" + }, + "status": "REVERSED", + "events": [ + { + "createdAt": "2018-08-17T17:45:16.000Z", + "description": "Requested", + "type": "TRANSFER.REQUESTED" + }, + { + "createdAt": "2018-08-17T17:45:52.000Z", + "description": "Reversed", + "type": "TRANSFER.REVERSED" + } + ], + "createdAt": "2018-08-17T17:45:16.000Z", + "entries": [], + "role": "RECEIVER", + "_links": { + "reverse": { + "href": "https://sandbox.moip.com.br/v2/transfers/TRA-EW1UQ14495JI/reverse" + }, + "self": { + "href": "https://sandbox.moip.com.br/v2/transfers/TRA-EW1UQ14495JI" + } + } + } \ No newline at end of file