diff --git a/.gitignore b/.gitignore index 2df126b..9fdbee2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ App.java target/* .idea *.iml +.classpath +.project +.settings/* \ No newline at end of file diff --git a/README.md b/README.md index bcd676f..9220587 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,6 @@ interacting with the API using this library: | `MERCHANT_VPOS_TOKEN` | The API token provided by vPOS | true | | `PAYMENT_CALLBACK_URL` | The URL that will handle payment notifications | false | | `REFUND_CALLBACK_URL` | The URL that will handle refund notifications | false | -| `VPOS_ENVIRONMENT` | The vPOS environment, leave empty for `sandbox` mode and use `"prd"` for `production`. | false | or using one of the optional arguments @@ -83,7 +82,6 @@ or using one of the optional arguments | `supervisor_card` | Merchant Supervisor Card number provided by EMIS | `string` | `payment_callback_url` | Merchant application JSON endpoint to accept the callback payment response | `string` | `refund_callback_url` | Merchant application JSON endpoint to accept the callback refund response | `string` -| `environment` | The vPOS environment, leave empty for `sandbox` mode and use `"PRD"` for `production`. | `string` | Don't have this information? [Talk to us](suporte@vpos.ao) @@ -99,13 +97,6 @@ be able to authenticate and communicate effectively with our API using this libr The next section will show the various payment actions that can be performed by you, the merchant. -### Get all Transactions -This endpoint retrieves all transactions. - -```java -var transactions = merchant.getTransactions(); -``` - ### Get a specific Transaction Retrieves a transaction given a valid transaction ID. diff --git a/pom.xml b/pom.xml index f181e1c..4e6a78c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,10 +6,10 @@ ao.vpos.vpos vpos - 1.0.0 + 1.0.1 vpos - https://github.com/nextbss/vpos-java + https://github.com/v-pos/vpos-java UTF-8 diff --git a/src/main/java/ao/vpos/vpos/Vpos.java b/src/main/java/ao/vpos/vpos/Vpos.java index 0bde752..6519e44 100644 --- a/src/main/java/ao/vpos/vpos/Vpos.java +++ b/src/main/java/ao/vpos/vpos/Vpos.java @@ -8,10 +8,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.type.CollectionType; import com.fasterxml.jackson.databind.type.TypeFactory; -import org.jetbrains.annotations.NotNull; - import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; @@ -24,8 +21,7 @@ import java.util.UUID; public class Vpos { - private static final String PRODUCTION_BASE_URL = "https://api.vpos.ao"; - private static final String SANDBOX_BASE_URL = "https://sandbox.vpos.ao"; + private static final String HOST = "https://vpos.ao"; private final HttpClient client = HttpClient.newHttpClient(); private URL baseUrl; @@ -37,80 +33,52 @@ public class Vpos { private static final int BEGIN_LOCATION_INDEX = 18; - public enum Environment { - PRODUCTION, - SANDBOX - } - // constructors - public Vpos() { + public Vpos() throws MalformedURLException { this.token = System.getenv("MERCHANT_VPOS_TOKEN"); this.posId = System.getenv("GPO_POS_ID"); this.supervisorCard = System.getenv("GPO_SUPERVISOR_CARD"); this.paymentCallbackUrl = System.getenv("PAYMENT_CALLBACK_URL"); this.refundCallbackUrl = System.getenv("REFUND_CALLBACK_URL"); - - try { - String environmentValue = System.getenv("VPOS_ENVIRONMENT"); - if (environmentValue != null && - environmentValue.equalsIgnoreCase("prd")) { - this.baseUrl = new URL(PRODUCTION_BASE_URL); - } else { - this.baseUrl = new URL(SANDBOX_BASE_URL); - } - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } - } - - public Vpos(@Nonnull Environment environment) { - this(); - this.token = System.getenv("MERCHANT_VPOS_TOKEN"); - this.baseUrl = getBaseUrlFromEnvironment(environment); + this.baseUrl = new URL(HOST); } - public Vpos(@Nonnull String newToken) { + public Vpos(@Nonnull String newToken) throws MalformedURLException { this(); this.token = newToken; + this.baseUrl = new URL(HOST); } - public Vpos(@Nonnull Environment environment, @Nonnull String newToken) { + public Vpos(@Nonnull String newToken, @Nonnull String posId) throws MalformedURLException { this(newToken); - this.baseUrl = getBaseUrlFromEnvironment(environment); - } - - public Vpos(@Nonnull Environment environment, @Nonnull String newToken, @Nonnull String posId) { - this(environment, newToken); this.posId = posId; + this.baseUrl = new URL(HOST); } public Vpos( - @Nonnull Environment environment, @Nonnull String newToken, @Nonnull String posId, - @Nonnull String supervisorCard) { - this(environment, newToken, posId); + @Nonnull String supervisorCard) throws MalformedURLException { + this(newToken, posId); this.supervisorCard = supervisorCard; } public Vpos( - @Nonnull Environment environment, @Nonnull String newToken, @Nonnull String posId, @Nonnull String supervisorCard, - @Nonnull String paymentCallbackUrl) { - this(environment, newToken, posId, supervisorCard); + @Nonnull String paymentCallbackUrl) throws MalformedURLException { + this(newToken, posId, supervisorCard); this.paymentCallbackUrl = paymentCallbackUrl; } public Vpos( - @Nonnull Environment environment, @Nonnull String newToken, @Nonnull String posId, @Nonnull String supervisorCard, @Nonnull String paymentCallbackUrl, - @Nonnull String refundCallbackUrl) { - this(environment, newToken, posId, supervisorCard, paymentCallbackUrl); + @Nonnull String refundCallbackUrl) throws MalformedURLException { + this(newToken, posId, supervisorCard, paymentCallbackUrl); this.refundCallbackUrl = refundCallbackUrl; } @@ -576,13 +544,4 @@ public String getTransactionId(String location) throws IOException, InterruptedE var endLocationIndex = location.length() - 1; return location.substring(BEGIN_LOCATION_INDEX, endLocationIndex); } - - @NotNull - private URL getBaseUrlFromEnvironment(Environment environment) { - try { - return (environment == Environment.SANDBOX) ? new URL(PRODUCTION_BASE_URL) : new URL(SANDBOX_BASE_URL); - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } - } } diff --git a/src/test/java/ao/vpos/vpos/VposTest.java b/src/test/java/ao/vpos/vpos/VposTest.java index 9ca10dd..4d771a1 100644 --- a/src/test/java/ao/vpos/vpos/VposTest.java +++ b/src/test/java/ao/vpos/vpos/VposTest.java @@ -7,7 +7,6 @@ import org.junit.jupiter.api.Test; import java.io.IOException; -import java.util.List; import java.util.UUID; import java.util.concurrent.TimeUnit; @@ -15,21 +14,6 @@ public class VposTest { // NEGATIVES - @Test - public void itShouldNotGetAllTransactionsIfTokenInvalid() throws IOException, InterruptedException { - var merchant = new Vpos("invalid-token"); - ApiException exception = null; - Response> response = null; - try { - response = merchant.getTransactions(); - } catch (ApiException e) { - exception = e; - } - - assertEquals(401, exception.getStatus()); - assertEquals("\"Unauthorized\"", exception.getResponseBody()); - } - @Test public void itShouldNotGetSingleTransactionIfParentTransactionIdDoesNotExist() throws IOException, InterruptedException { @@ -140,21 +124,6 @@ public void itShouldGetSingleTransaction() throws IOException, InterruptedExcept assertEquals("900111222", returnedResponse.getData().getMobile()); } - @Test - public void itShouldGetAllTransactions() throws IOException, InterruptedException, ApiException { - var merchant = new Vpos(); - var response = merchant.getTransactions(); - assertEquals(200, response.getStatusCode()); - assertEquals("OK", response.getMessage()); - assertNotNull(response.getData().get(0).getAmount()); - assertNotNull(response.getData().get(0).getMobile()); - assertNotNull(response.getData().get(0).getId()); - assertNotNull(response.getData().get(0).getStatus()); - assertNotNull(response.getData().get(0).getPosId()); - assertNotNull(response.getData().get(0).getType()); - assertNotNull(response.getData().get(0).getStatusDatetime()); - } - @Test public void itShouldCreateNewPaymentTransaction() throws IOException, InterruptedException, ApiException { var merchant = new Vpos(); @@ -167,7 +136,7 @@ public void itShouldCreateNewPaymentTransaction() throws IOException, Interrupte @Test public void itShouldCreateNewRefundTransaction() throws IOException, InterruptedException, ApiException { var merchant = new Vpos(); - var response = merchant.newPayment("900111222", "123.45"); + var response = merchant.newPayment("900000000", "123.45"); var transactionId = merchant.getTransactionId(response.getLocation()); TimeUnit.SECONDS.sleep(10); @@ -185,7 +154,7 @@ public void itShouldCreateNewRefundTransaction() throws IOException, Interrupted @Test public void itShouldGetRequestWhileTransactionIsQueued() throws IOException, InterruptedException, ApiException { var merchant = new Vpos(); - var response = merchant.newPayment("900111222", "123.45"); + var response = merchant.newPayment("900000000", "123.45"); var transactionId = merchant.getTransactionId(response.getLocation()); Response request = merchant.getRequest(transactionId);