|
| 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 | +} |
0 commit comments