From 6199b9c7a8fe1787f8240be1a249afe559f6389d Mon Sep 17 00:00:00 2001 From: Sergio Maziano Date: Tue, 21 Sep 2021 20:49:30 +0100 Subject: [PATCH 1/3] Updates the project to handle sandbox --- .gitignore | 3 ++ src/main/java/ao/vpos/vpos/Vpos.java | 67 +++++------------------- src/test/java/ao/vpos/vpos/VposTest.java | 31 ----------- 3 files changed, 16 insertions(+), 85 deletions(-) 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/src/main/java/ao/vpos/vpos/Vpos.java b/src/main/java/ao/vpos/vpos/Vpos.java index 0bde752..8caca68 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://api.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..1287ab0 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(); From 84b8b58ba465ed39cf5e651804b62700f316bff6 Mon Sep 17 00:00:00 2001 From: Sergio Maziano Date: Tue, 21 Sep 2021 20:57:46 +0100 Subject: [PATCH 2/3] Updates documentation --- README.md | 9 --------- 1 file changed, 9 deletions(-) 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. From eb8595aacbe2c42107491e065bdbd9a3f821d2ac Mon Sep 17 00:00:00 2001 From: Sergio Maziano Date: Wed, 22 Sep 2021 17:41:19 +0100 Subject: [PATCH 3/3] Changes the api endpoint to the newer http://vpos.ao/api --- pom.xml | 4 ++-- src/main/java/ao/vpos/vpos/Vpos.java | 2 +- src/test/java/ao/vpos/vpos/VposTest.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) 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 8caca68..6519e44 100644 --- a/src/main/java/ao/vpos/vpos/Vpos.java +++ b/src/main/java/ao/vpos/vpos/Vpos.java @@ -21,7 +21,7 @@ import java.util.UUID; public class Vpos { - private static final String HOST = "https://api.vpos.ao"; + private static final String HOST = "https://vpos.ao"; private final HttpClient client = HttpClient.newHttpClient(); private URL baseUrl; diff --git a/src/test/java/ao/vpos/vpos/VposTest.java b/src/test/java/ao/vpos/vpos/VposTest.java index 1287ab0..4d771a1 100644 --- a/src/test/java/ao/vpos/vpos/VposTest.java +++ b/src/test/java/ao/vpos/vpos/VposTest.java @@ -136,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); @@ -154,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);