Skip to content

Commit 61841ae

Browse files
committed
Minor fixes + split up tests
1 parent 4a80494 commit 61841ae

10 files changed

Lines changed: 286 additions & 125 deletions

File tree

.github/workflows/maven-build.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ jobs:
2222
with:
2323
distribution: 'adopt'
2424
java-version: ${{ matrix.java-version }}
25-
server-id: ossrh
26-
server-username: MAVEN_USERNAME # env variable for username in deploy
27-
server-password: MAVEN_CENTRAL_TOKEN # env variable for token in deploy
28-
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
29-
gpg-passphrase: MAVEN_GPG_PASSPHRASE
3025

3126
- name: Cache Maven packages
3227
uses: actions/cache@v1

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.twikey</groupId>
55
<artifactId>twikey-api-java</artifactId>
66
<packaging>jar</packaging>
7-
<version>0.1.1</version>
7+
<version>0.1.2</version>
88
<name>Twikey Api</name>
99
<url>http://maven.apache.org</url>
1010
<description>Official wrapper around the Twikey.com rest api</description>

src/main/java/com/twikey/InvoiceGateway.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public JSONObject create(long ct, Customer customer, Map<String, String> invoice
6363
JSONObject invoice = new JSONObject()
6464
.put("customer", customerAsJson)
6565
.put("date", invoiceDetails.getOrDefault("date", LocalDate.now().toString()))
66-
.put("duedate", invoiceDetails.getOrDefault("date", LocalDate.now().plusMonths(1).toString()))
66+
.put("duedate", invoiceDetails.getOrDefault("duedate", LocalDate.now().plusMonths(1).toString()))
6767
.put("ct", ct);
6868

6969
for (Map.Entry<String, String> entry : invoiceDetails.entrySet()) {

src/main/java/com/twikey/PaylinkGateway.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void feed(PaylinkCallback callback) throws IOException, TwikeyClient.User
116116
try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
117117
JSONObject json = new JSONObject(new JSONTokener(br));
118118

119-
JSONArray messagesArr = json.getJSONArray("Messages");
119+
JSONArray messagesArr = json.getJSONArray("Links");
120120
isEmpty = messagesArr.isEmpty();
121121
if (!isEmpty) {
122122
for (int i = 0; i < messagesArr.length(); i++) {
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.twikey;
2+
3+
import com.twikey.callback.DocumentCallback;
4+
import com.twikey.modal.Customer;
5+
import org.json.JSONObject;
6+
import org.junit.Assume;
7+
import org.junit.Before;
8+
import org.junit.Test;
9+
10+
import java.io.IOException;
11+
import java.util.HashMap;
12+
13+
import static org.junit.Assert.assertNotNull;
14+
15+
public class DocumentGatewayTest {
16+
17+
private final String apiKey = System.getenv("TWIKEY_API_KEY"); // found in https://www.twikey.com/r/admin#/c/settings/api
18+
19+
private final String ct = System.getenv("CT"); // found @ https://www.twikey.com/r/admin#/c/template
20+
21+
private Customer customer;
22+
23+
private TwikeyClient api;
24+
25+
@Before
26+
public void createCustomer(){
27+
customer = new Customer()
28+
.setNumber("customerNum123")
29+
.setEmail("no-reply@example.com")
30+
.setFirstname("Twikey")
31+
.setLastname("Support")
32+
.setStreet("Derbystraat 43")
33+
.setCity("Gent")
34+
.setZip("9000")
35+
.setCountry("BE")
36+
.setLang("nl")
37+
.setMobile("32498665995");
38+
39+
api = new TwikeyClient(apiKey,true)
40+
.withUserAgent("twikey-api-java/junit");
41+
}
42+
43+
@Test
44+
public void testInviteMandateWithoutCustomerDetails() throws IOException, TwikeyClient.UserException {
45+
Assume.assumeNotNull(apiKey);
46+
JSONObject response = api.document().create(Long.parseLong(ct), null, new HashMap<>());
47+
assertNotNull("Invite URL",response.getString("url"));
48+
assertNotNull("Document Reference",response.getString("mndtId"));
49+
}
50+
51+
@Test
52+
public void testInviteMandateCustomerDetails() throws IOException, TwikeyClient.UserException {
53+
Assume.assumeNotNull(apiKey);
54+
JSONObject response = api.document().create(Long.parseLong(ct), customer, new HashMap<>());
55+
assertNotNull("Invite URL",response.getString("url"));
56+
assertNotNull("Document Reference",response.getString("mndtId"));
57+
}
58+
59+
@Test
60+
public void getMandatesAndDetails() throws IOException, TwikeyClient.UserException {
61+
Assume.assumeNotNull(apiKey);
62+
api.document().feed(new DocumentCallback() {
63+
@Override
64+
public void newDocument(JSONObject newMandate) {
65+
System.out.println("New mandate: "+newMandate);
66+
}
67+
68+
@Override
69+
public void updatedDocument(JSONObject updatedMandate) {
70+
System.out.println("Updated mandate: "+updatedMandate);
71+
}
72+
73+
@Override
74+
public void cancelledDocument(JSONObject cancelledMandate) {
75+
System.out.println("Cancelled mandate: "+cancelledMandate);
76+
}
77+
});
78+
}
79+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.twikey;
2+
3+
import com.twikey.modal.Customer;
4+
import junit.framework.TestCase;
5+
import org.json.JSONObject;
6+
import org.junit.Assume;
7+
import org.junit.Before;
8+
import org.junit.Test;
9+
10+
import java.io.IOException;
11+
import java.util.HashMap;
12+
import java.util.Map;
13+
14+
import static org.junit.Assert.assertNotNull;
15+
16+
public class InvoiceGatewayTest {
17+
18+
private final String apiKey = System.getenv("TWIKEY_API_KEY"); // found in https://www.twikey.com/r/admin#/c/settings/api
19+
20+
private final String ct = System.getenv("CT"); // found @ https://www.twikey.com/r/admin#/c/template
21+
22+
private Customer customer;
23+
24+
private TwikeyClient api;
25+
26+
@Before
27+
public void createCustomer() {
28+
customer = new Customer()
29+
.setNumber("customerNum123")
30+
.setEmail("no-reply@example.com")
31+
.setFirstname("Twikey")
32+
.setLastname("Support")
33+
.setStreet("Derbystraat 43")
34+
.setCity("Gent")
35+
.setZip("9000")
36+
.setCountry("BE")
37+
.setLang("nl")
38+
.setMobile("32498665995");
39+
40+
api = new TwikeyClient(apiKey, true)
41+
.withUserAgent("twikey-api-java/junit");
42+
}
43+
44+
@Test
45+
public void testCreateInvoice() throws IOException, TwikeyClient.UserException {
46+
Assume.assumeNotNull(apiKey, ct);
47+
Map<String, String> invoiceDetails = new HashMap<>();
48+
invoiceDetails.put("number", "Invss123");
49+
invoiceDetails.put("title", "Invoice April");
50+
invoiceDetails.put("remittance", "123456789123");
51+
invoiceDetails.put("amount", "10.90");
52+
invoiceDetails.put("date", "2020-03-20");
53+
invoiceDetails.put("duedate", "2020-04-28");
54+
JSONObject invoiceResponse = api.invoice().create(Long.parseLong(ct), customer, invoiceDetails);
55+
assertNotNull("Payment URL", invoiceResponse.getString("url"));
56+
assertNotNull("Invoice Id", invoiceResponse.getString("id"));
57+
}
58+
59+
60+
@Test
61+
public void getInvoicesAndDetails() throws IOException, TwikeyClient.UserException {
62+
Assume.assumeNotNull(apiKey);
63+
api.invoice().feed(updatedInvoice -> System.out.println("Updated invoice: " + updatedInvoice));
64+
}
65+
66+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.twikey;
2+
3+
import com.twikey.modal.Customer;
4+
import org.json.JSONObject;
5+
import org.junit.Assume;
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
9+
import java.io.IOException;
10+
import java.util.HashMap;
11+
import java.util.Map;
12+
13+
import static org.junit.Assert.assertNotEquals;
14+
import static org.junit.Assert.assertNotNull;
15+
16+
public class PaylinkGatewayTest {
17+
18+
private final String apiKey = System.getenv("TWIKEY_API_KEY"); // found in https://www.twikey.com/r/admin#/c/settings/api
19+
20+
private final String ct = System.getenv("CT"); // found @ https://www.twikey.com/r/admin#/c/template
21+
22+
private Customer customer;
23+
24+
private TwikeyClient api;
25+
26+
@Before
27+
public void createCustomer() {
28+
customer = new Customer()
29+
.setNumber("customerNum123")
30+
.setEmail("no-reply@example.com")
31+
.setFirstname("Twikey")
32+
.setLastname("Support")
33+
.setStreet("Derbystraat 43")
34+
.setCity("Gent")
35+
.setZip("9000")
36+
.setCountry("BE")
37+
.setLang("nl")
38+
.setMobile("32498665995");
39+
40+
api = new TwikeyClient(apiKey, true)
41+
.withUserAgent("twikey-api-java/junit");
42+
}
43+
44+
@Test
45+
public void testCreate() throws IOException, TwikeyClient.UserException {
46+
Assume.assumeNotNull(apiKey, ct);
47+
Map<String, String> extra = new HashMap<>();
48+
extra.put("message", "Test Link");
49+
extra.put("amount", "10.00");
50+
JSONObject linkResponse = api.paylink().create(Long.parseLong(ct), customer, extra);
51+
assertNotNull("Payment URL", linkResponse.getString("url"));
52+
assertNotEquals(0, linkResponse.getLong("id"));
53+
54+
}
55+
56+
@Test
57+
public void testFeed() throws IOException, TwikeyClient.UserException {
58+
Assume.assumeNotNull(apiKey);
59+
api.paylink().feed(updatedLink -> System.out.println("Updated link: " + updatedLink));
60+
}
61+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.twikey;
2+
3+
import org.json.JSONObject;
4+
import org.junit.Assume;
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
8+
import java.io.IOException;
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
12+
import static org.junit.Assert.assertNotNull;
13+
14+
public class TransactionGatewayTest {
15+
16+
private final String apiKey = System.getenv("TWIKEY_API_KEY"); // found in https://www.twikey.com/r/admin#/c/settings/api
17+
18+
private final String mandateNumber = System.getenv("mndtNumber");
19+
20+
private TwikeyClient api;
21+
22+
@Before
23+
public void prepClient() {
24+
api = new TwikeyClient(apiKey, true)
25+
.withUserAgent("twikey-api-java/junit");
26+
}
27+
28+
@Test
29+
public void testCreate() throws IOException, TwikeyClient.UserException {
30+
Assume.assumeNotNull(apiKey,mandateNumber);
31+
Map<String, String> extra = new HashMap<>();
32+
extra.put("message", "Test Message");
33+
extra.put("amount", "10.00");
34+
JSONObject linkResponse = api.transaction().create(mandateNumber, extra);
35+
System.out.println(linkResponse);
36+
assertNotNull("Payment URL", linkResponse.getString("url"));
37+
assertNotNull("Invoice Id", linkResponse.getString("id"));
38+
}
39+
40+
@Test
41+
public void testFeed() throws IOException, TwikeyClient.UserException {
42+
Assume.assumeNotNull(apiKey);
43+
api.transaction().feed(updatedTransaction -> System.out.println("Updated transaction: " + updatedTransaction));
44+
}
45+
46+
}

0 commit comments

Comments
 (0)