tags,
+ String quantity,
+ Amount discountAmount,
+ Amount taxAmount,
+ Amount dueAmount,
+ Amount paidAmount) {
+ this.description = description;
+ this.unitAmount = unitAmount;
+ this.quantity = quantity;
+ this.discountAmount = discountAmount;
+ this.taxAmount = taxAmount;
+ this.dueAmount = dueAmount;
+ this.paidAmount = paidAmount;
+ this.externalId = externalId;
+ this.taxReportable = taxReportable;
+ this.tags = tags;
+ this.category = category;
+ this.forceUsTaxActivity = forceUsTaxActivity;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ /**
+ * Get invoiceLineId
for Update Invoice Line operation.
+ *
+ * NOTE: Only used for Update operation, may not be filled by other operations.
+ *
+ * See getId()
for accessing InvoiceLineId from a response
+ * @return String invoiceLineId the id of the invoice line that needs to be updated
+ */
+ public String getInvoiceLineId() {
+ return invoiceLineId;
+ }
+
+ /**
+ * Set invoiceLineId
for Update Invoice Line operation.
+ *
+ * NOTE: Only used for Update operation, may not be filled by other operations.
+ *
+ * See getId()
for accessing InvoiceLineId from a response
+ * @param invoiceLineId the id of the invoice line that needs to be updated
+ */
+ public void setInvoiceLineId(String invoiceLineId) {
+ this.invoiceLineId = invoiceLineId;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public Amount getUnitAmount() {
+ return unitAmount;
+ }
+
+ public void setUnitAmount(Amount unitAmount) {
+ this.unitAmount = unitAmount;
+ }
+
+ public String getQuantity() {
+ return quantity;
+ }
+
+ public void setQuantity(String quantity) {
+ this.quantity = quantity;
+ }
+
+ public Amount getDiscountAmount() {
+ return discountAmount;
+ }
+
+ public void setDiscountAmount(Amount discountAmount) {
+ this.discountAmount = discountAmount;
+ }
+
+ public Amount getTaxAmount() {
+ return taxAmount;
+ }
+
+ public void setTaxAmount(Amount taxAmount) {
+ this.taxAmount = taxAmount;
+ }
+
+ public Amount getTotalAmount() {
+ return totalAmount;
+ }
+
+ public void setTotalAmount(Amount totalAmount) {
+ this.totalAmount = totalAmount;
+ }
+
+ public Amount getDueAmount() {
+ return dueAmount;
+ }
+
+ public void setDueAmount(Amount dueAmount) {
+ this.dueAmount = dueAmount;
+ }
+
+ public Amount getPaidAmount() {
+ return paidAmount;
+ }
+
+ public void setPaidAmount(Amount paidAmount) {
+ this.paidAmount = paidAmount;
+ }
+
+ public String getExternalId() {
+ return externalId;
+ }
+
+ public void setExternalId(String externalId) {
+ this.externalId = externalId;
+ }
+
+ public boolean isTaxReportable() {
+ return taxReportable;
+ }
+
+ public void setTaxReportable(boolean taxReportable) {
+ this.taxReportable = taxReportable;
+ }
+
+ public List getTags() {
+ return tags;
+ }
+
+ public void setTags(List tags) {
+ this.tags = tags;
+ }
+
+ public InvoiceCategories getCategory() {
+ return category;
+ }
+
+ public void setCategory(InvoiceCategories category) {
+ this.category = category;
+ }
+
+ public boolean isForceUsTaxActivity() {
+ return forceUsTaxActivity;
+ }
+
+ public void setForceUsTaxActivity(boolean forceUsTaxActivity) {
+ this.forceUsTaxActivity = forceUsTaxActivity;
+ }
+
+ /**
+ * Factory method to create Invoice object from the response that was returned.
+ *
+ * The API responds with the full Invoice object where the newly created line is added,
+ * so instead of returning the individual line item, the Invoice object is returned.
+ *
+ *
+ * @param invoiceLineResponse JSON String received in the response
+ * @return Invoice object containing all the lines, including the newly created one
+ * @throws JsonProcessingException
+ * @throws JsonMappingException
+ */
+ public static Invoice invoiceLinesFactory(final String invoiceLineResponse) throws JsonMappingException, JsonProcessingException {
+ return Invoice.invoiceFactory(invoiceLineResponse);
+ }
+
+ /**
+ * InvoiceLine class' toString() method, returns a valid JSON String representation of this object
+ * @return String JSON String representation of this object
+ */
+ public String toString(){
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
+ String jsonString = null;
+ try {
+ jsonString = objectMapper.setSerializationInclusion(Include.NON_EMPTY).writeValueAsString(this);
+ } catch (JsonProcessingException e) {
+ e.printStackTrace();
+ }
+
+ return jsonString;
+ }
+}
diff --git a/src/main/java/com/trolley/trolley/InvoiceLineGateway.java b/src/main/java/com/trolley/trolley/InvoiceLineGateway.java
new file mode 100644
index 0000000..05a40a9
--- /dev/null
+++ b/src/main/java/com/trolley/trolley/InvoiceLineGateway.java
@@ -0,0 +1,184 @@
+package com.trolley.trolley;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.trolley.Exceptions.InvalidFieldException;
+
+public class InvoiceLineGateway
+{
+ Client client;
+
+ public InvoiceLineGateway(final Configuration config) {
+ this.client = new Client(config);
+ }
+
+ /**
+ * Create a single Invoice Line and add it to the Invoice whose ID is supplied.
+ *
+ * @param invoiceId Id of the invoice where this line will be added
+ * @param invoiceLine InvoiceLine object which will be created
+ * @return Invoice object of the updated invoice containing the newly created line
+ * @throws Exception
+ */
+ public Invoice create(final String invoiceId, final InvoiceLine invoiceLine) throws Exception {
+ final String endPoint = "/v1/invoices/create-lines/";
+ ArrayList invoiceLines = new ArrayList() {
+ {
+ add(invoiceLine);
+ }
+ };
+
+ final String body = "{"
+ +"\"invoiceId\":\"" +invoiceId+"\","
+ +"\"lines\":" +new ObjectMapper()
+ .setSerializationInclusion(Include.NON_EMPTY)
+ .writeValueAsString(invoiceLines)
+ +"}";
+
+ final String response = this.client.post(endPoint, body);
+ return InvoiceLine.invoiceLinesFactory(response);
+ }
+
+ /**
+ * Create multiple Invoice Lines and adds them to the Invoice whose ID is supplied.
+ * @param invoiceId Id of the invoice where this line will be added
+ * @param invoiceLines {@code List} object represnting the lines which will be created
+ * @return Invoice object of the updated invoice containing these lines
+ * @throws Exception
+ */
+ public Invoice create(final String invoiceId, final List invoiceLines) throws Exception {
+ final String endPoint = "/v1/invoices/create-lines/";
+
+ final String body = "{"
+ +"\"invoiceId\":\"" +invoiceId+"\","
+ +"\"lines\":" +new ObjectMapper()
+ .setSerializationInclusion(Include.NON_EMPTY)
+ .writeValueAsString(invoiceLines)
+ +"}";
+
+ final String response = this.client.post(endPoint, body);
+ return InvoiceLine.invoiceLinesFactory(response);
+ }
+
+ /**
+ * Update a single Invoice Line in an Invoice whose ID is supplied.
+ *
+ * NOTE: Make sure you set the {@code invoiceLineId} variable of the {@code invoiceLine}
+ * object supplied as parameter here. Not the {@code id}.
+ *
+ * @param invoiceId Id of the invoice where this line will be added
+ * @param invoiceLine InvoiceLine object which will be update
+ * @return Invoice object of the updated invoice containing the updated line
+ * @throws Exception
+ */
+ public Invoice update(final String invoiceId, final InvoiceLine invoiceLine) throws Exception {
+ final String endPoint = "/v1/invoices/update-lines/";
+
+ if( null == invoiceLine.getInvoiceLineId() ||
+ invoiceLine.getInvoiceLineId().length() == 0){
+ throw new InvalidFieldException("invoiceLineId of invoiceLine object must be set to denote which invoiceLine needs to be updated. Did you set id variable instead? Refer to method's Javadoc for more details.");
+ }
+
+ ArrayList invoiceLines = new ArrayList() {
+ {
+ add(invoiceLine);
+ }
+ };
+
+ final String body = "{"
+ +"\"invoiceId\":\"" +invoiceId+"\","
+ +"\"lines\" :" +new ObjectMapper()
+ .setSerializationInclusion(Include.NON_EMPTY)
+ .writeValueAsString(invoiceLines)
+ +"}";
+
+ final String response = this.client.post(endPoint, body);
+ return InvoiceLine.invoiceLinesFactory(response);
+ }
+
+ /**
+ * Update multiple Invoice Lines in an Invoice whose ID is supplied.
+ *
+ * NOTE: Make sure you set the {@code invoiceLineId} variable in all the objects supplied
+ * in the {@code invoiceLines} parameter.
+ * @param invoiceId Id of the invoice where this line will be added
+ * @param invoiceLines {@code List} object representing the lines which will be edited
+ * @return Invoice object of the updated invoice containing these lines
+ * @throws Exception
+ */
+ public Invoice update(final String invoiceId, final List invoiceLines) throws Exception {
+ final String endPoint = "/v1/invoices/update-lines/";
+
+ for (InvoiceLine invoiceLine : invoiceLines) {
+ if( null == invoiceLine.getInvoiceLineId() ||
+ invoiceLine.getInvoiceLineId().length() == 0){
+ throw new InvalidFieldException("invoiceLineId of invoiceLine object must be set to denote which invoiceLine needs to be updated. Please confirm all of the items have this set correctly. Refer to method's Javadoc for more details.");
+ }
+ }
+
+ final String body = "{"
+ +"\"invoiceId\":\"" +invoiceId+"\","
+ +"\"lines\":" +new ObjectMapper()
+ .setSerializationInclusion(Include.NON_EMPTY)
+ .writeValueAsString(invoiceLines)
+ +"}";
+
+ final String response = this.client.post(endPoint, body);
+ return InvoiceLine.invoiceLinesFactory(response);
+ }
+
+ /**
+ * Delete one invoice line by its ID
+ * @param invoiceId ID of the invoice from where this line needs to be deleted
+ * @param invoiceLineId ID of the invoice line which needs to be deleted
+ * @return boolean true if the delete operation was successful
+ * @throws Exception
+ */
+ public boolean delete(final String invoiceId, final String invoiceLineId) throws Exception {
+ final String endPoint = "/v1/invoices/delete-lines/";
+
+ ArrayList invoiceLineIds = new ArrayList() {
+ {
+ add(invoiceLineId);
+ }
+ };
+
+ final String body = "{"
+ +"\"invoiceId\":\""+invoiceId+"\","
+ +"\"invoiceLineIds\":"+new ObjectMapper().writeValueAsString(invoiceLineIds)
+ +"}";
+
+ final String response = this.client.post(endPoint, body);
+
+ final ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ final JsonNode node = mapper.readTree(response);
+ return node.get("ok").asBoolean(false);
+ }
+
+ /**
+ * Delete multiple invoices whose ID is provided as a List
+ * @param invoiceId
+ * @return boolean true if the delete operation was successful
+ * @throws Exception
+ */
+ public boolean delete(final String invoiceId, final List invoiceLineIds) throws Exception {
+ final String endPoint = "/v1/invoices/delete-lines/";
+
+ final String body = "{"
+ +"\"invoiceId\":\"" +invoiceId+"\","
+ +"\"invoiceLineIds\":" +new ObjectMapper().writeValueAsString(invoiceLineIds)
+ +"}";
+
+ final String response = this.client.post(endPoint, body);
+
+ final ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ final JsonNode node = mapper.readTree(response);
+ return node.get("ok").asBoolean(false);
+ }
+}
diff --git a/src/main/java/com/trolley/trolley/InvoicePayment.java b/src/main/java/com/trolley/trolley/InvoicePayment.java
new file mode 100644
index 0000000..61bc711
--- /dev/null
+++ b/src/main/java/com/trolley/trolley/InvoicePayment.java
@@ -0,0 +1,114 @@
+package com.trolley.trolley;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.exc.StreamReadException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.trolley.trolley.types.InvoicePaymentPart;
+import com.trolley.trolley.types.InvoicePayments;
+import com.trolley.trolley.types.Meta;
+
+public class InvoicePayment
+{
+ private String batchId;
+ private String paymentId;
+ private List invoicePayments;
+
+ public InvoicePayment() {}
+
+ public InvoicePayment(List invoicePayments) {
+ this.invoicePayments = invoicePayments;
+ }
+
+ public String getBatchId() {
+ return batchId;
+ }
+
+ public void setBatchId(String batchId) {
+ this.batchId = batchId;
+ }
+
+ public String getPaymentId() {
+ return paymentId;
+ }
+
+ public void setPaymentId(String paymentId) {
+ this.paymentId = paymentId;
+ }
+
+ public List getInvoicePayments() {
+ return invoicePayments;
+ }
+
+ public void setInvoicePayments(List invoicePayments) {
+ this.invoicePayments = invoicePayments;
+ }
+
+ /**
+ * Factory method to create InvoicePayment object from the response that was returned.
+ *
+ * @param invoicePaymentResponse JSON String received in the response
+ * @return InvoicePayment object containing all the lines, including the newly created one
+ * @throws JsonProcessingException
+ * @throws JsonMappingException
+ */
+ public static InvoicePayment invoicePaymentFactory(final String invoicePaymentResponse) throws JsonMappingException, JsonProcessingException {
+ final ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ final JsonNode node = mapper.readTree(invoicePaymentResponse);
+ String paymentId = node.get("invoicePayment").get("paymentId").asText();
+ InvoicePayment invoicePayment;
+ try{
+ invoicePayment = (InvoicePayment)mapper.readValue(node.get("invoicePayment").traverse(), (Class)InvoicePayment.class);
+ }catch(Exception e){
+ e.printStackTrace();
+ invoicePayment = new InvoicePayment(null);
+ invoicePayment.setPaymentId(paymentId);
+ }
+ return invoicePayment;
+ }
+
+ public static InvoicePayments invoicePaymentsFactory(final String invoicePaymentResponse) throws StreamReadException, IOException{
+ final ObjectMapper mapper = new ObjectMapper();
+ final JsonNode node = mapper.readTree(invoicePaymentResponse);
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ final Object invoicePayments = mapper.readValue(node.get("invoicePayments").traverse(), (Class)Object.class);
+ final List parsedInvoicePayments = (List)invoicePayments;
+ final ArrayList paymentPartsObjs = new ArrayList();
+
+ final Meta meta = (Meta)mapper.readValue(node.get("meta").traverse(), (Class)Meta.class);
+
+ //Creating List object to return
+ for (Object invoicePayment : parsedInvoicePayments) {
+ final InvoicePaymentPart pojo = (InvoicePaymentPart)mapper.convertValue((Object)invoicePayment, (Class)InvoicePaymentPart.class);
+ paymentPartsObjs.add(pojo);
+ }
+
+ return new InvoicePayments(paymentPartsObjs, meta);
+ }
+
+ /**
+ * InvoicePayment class' toString() method, returns a valid JSON String representation of this object
+ * @return String JSON String representation of this object
+ */
+ public String toString(){
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
+ String jsonString = null;
+ try {
+ jsonString = objectMapper.setSerializationInclusion(Include.NON_EMPTY).writeValueAsString(this);
+ } catch (JsonProcessingException e) {
+ e.printStackTrace();
+ }
+
+ return jsonString;
+ }
+}
diff --git a/src/main/java/com/trolley/trolley/InvoicePaymentGateway.java b/src/main/java/com/trolley/trolley/InvoicePaymentGateway.java
new file mode 100644
index 0000000..4a74414
--- /dev/null
+++ b/src/main/java/com/trolley/trolley/InvoicePaymentGateway.java
@@ -0,0 +1,197 @@
+package com.trolley.trolley;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.trolley.trolley.types.InvoicePaymentPart;
+import com.trolley.trolley.types.InvoicePayments;
+
+public class InvoicePaymentGateway
+{
+ Client client;
+
+ public InvoicePaymentGateway(final Configuration config) {
+ this.client = new Client(config);
+ }
+
+ /**
+ * Create a payment against an invoice.
+ *
+ * NOTE: If you provide a batch id, this method will try to add the payment to it. If you provide a
+ * {@code null} or blank ({@code ""}) batch id, a new batch will be created.
+ *
+ *
+ * @param batchId (Optional) Id of the batch you want to add these payments too.
+ * @param payment InvoicePaymentPart object representing the Invoice payment that needs to be created
+ * @return InvoicePayment object of representing the created payment for the Invoice
+ * @throws Exception
+ */
+ public InvoicePayment create(final String batchId, final InvoicePaymentPart payment) throws Exception {
+ final String endPoint = "/v1/invoices/payment/create/";
+
+ String body = "";
+
+ if(null != batchId && !batchId.isEmpty()){
+ body = "{ \"batchId\": \"" + batchId + "\",";
+ }else{
+ body = "{";
+ }
+ ArrayList invoicePaymentParts = new ArrayList() {
+ {
+ add(payment);
+ }
+ };
+
+ body+= "\"ids\":" +new ObjectMapper()
+ .setSerializationInclusion(Include.NON_EMPTY)
+ .writeValueAsString(invoicePaymentParts)
+ +"}";
+ final String response = this.client.post(endPoint, body);
+ return InvoicePayment.invoicePaymentFactory(response);
+ }
+
+ /**
+ * Create a payment against multiple invoices.
+ *
+ * NOTE: If you provide a batch id, this method will try to add the payment to it. If you provide a
+ * {@code null} or blank ({@code ""}) batch id, a new batch will be created.
+ *
+ * @param batchId (Optional) Id of the batch you want to add these payments too.
+ * @param invoicePaymentParts A List of InvoicePaymentPart objects representing the Invoice payments that need to be created.
+ * @return InvoicePayment object of representing the created payment for the Invoice
+ * @throws Exception
+ */
+ public InvoicePayment create(final String batchId, final List invoicePaymentParts) throws Exception {
+ final String endPoint = "/v1/invoices/payment/create/";
+
+ String body = "";
+
+ if(null != batchId && !batchId.isEmpty()){
+ body = "{ \"batchId\": \"" + batchId + "\",";
+ }else{
+ body = "{";
+ }
+
+ body+= "\"ids\":" +new ObjectMapper()
+ .setSerializationInclusion(Include.NON_EMPTY)
+ .writeValueAsString(invoicePaymentParts)
+ +"}";
+ final String response = this.client.post(endPoint, body);
+ return InvoicePayment.invoicePaymentFactory(response);
+ }
+
+ /**
+ * Update an Invoice Payment whose details are provided in invoicePaymentPart object.
+ *
+ * Refer to our docs for details
+ * about which parameters are required.
+ * @param invoicePaymentPart
+ * @return boolean true if the update was successful
+ * @throws Exception
+ */
+ public boolean update(final InvoicePaymentPart invoicePaymentPart) throws Exception {
+ final String endPoint = "/v1/invoices/payment/update/";
+
+ final String body = new ObjectMapper()
+ .setSerializationInclusion(Include.NON_EMPTY)
+ .writeValueAsString(invoicePaymentPart);
+
+ final String response = this.client.post(endPoint, body);
+
+ final ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ final JsonNode node = mapper.readTree(response);
+ return node.get("ok").asBoolean(false);
+ }
+
+ /**
+ * Search for invoice payments matching the list of paymentIds or invoiceIds provided.
+ *
+ * Either {@code paymentIds} or {@code invoiceIds} is required.
+ * @param paymentIds
+ * @param invoiceIds
+ * @return InvoicePayments object containing a list of found InvoicePaymentParts and Meta object for
+ * pagination information
+ * @throws Exception
+ */
+ public InvoicePayments search(final List paymentIds, final List invoiceIds) throws Exception {
+ final String endPoint = "/v1/invoices/payment/search/";
+
+ String body = "{";
+ if(null != paymentIds && !paymentIds.isEmpty()){
+ body+= "\"paymentIds\":" + new ObjectMapper()
+ .setSerializationInclusion(Include.NON_EMPTY)
+ .writeValueAsString(paymentIds);
+ }
+
+ if(null != invoiceIds && !invoiceIds.isEmpty()){
+ if(null != paymentIds && !paymentIds.isEmpty()){
+ body+=",";
+ }
+ body+="\"invoiceIds\":" + new ObjectMapper()
+ .setSerializationInclusion(Include.NON_EMPTY)
+ .writeValueAsString(invoiceIds);
+ }
+
+ body+= "}";
+
+ final String response = this.client.post(endPoint, body);
+
+ return InvoicePayment.invoicePaymentsFactory(response);
+ }
+
+ /**
+ * Remove the association between a payment and an invoice line ID.
+ * @param paymentId payment id to delete
+ * @param invoiceLineId
+ * @return boolean true if the delete operation was successful
+ * @throws Exception
+ */
+ public boolean delete(final String paymentId, final String invoiceLineId) throws Exception {
+ final String endPoint = "/v1/invoices/payment/delete/";
+
+ ArrayList invoiceLineIds = new ArrayList() {
+ {
+ add(invoiceLineId);
+ }
+ };
+
+ final String body = "{"
+ +"\"paymentId\":\""+paymentId+"\","
+ +"\"invoiceLineIds\":"+new ObjectMapper().writeValueAsString(invoiceLineIds)
+ +"}";
+
+ final String response = this.client.post(endPoint, body);
+
+ final ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ final JsonNode node = mapper.readTree(response);
+ return node.get("ok").asBoolean(false);
+ }
+
+ /**
+ * Remove the association between a payment and multiple invoice line IDs.
+ * @param paymentId payment id to delete
+ * @param invoiceLineIds a {@code List} of invoiceLineIds
+ * @return
+ * @throws Exception
+ */
+ public boolean delete(final String paymentId, final List invoiceLineIds) throws Exception {
+ final String endPoint = "/v1/invoices/payment/delete/";
+
+ final String body = "{"
+ +"\"paymentId\":\""+paymentId+"\","
+ +"\"invoiceLineIds\":"+new ObjectMapper().writeValueAsString(invoiceLineIds)
+ +"}";
+
+ final String response = this.client.post(endPoint, body);
+
+ final ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ final JsonNode node = mapper.readTree(response);
+ return node.get("ok").asBoolean(false);
+ }
+}
diff --git a/src/main/java/com/trolley/trolley/Payment.java b/src/main/java/com/trolley/trolley/Payment.java
new file mode 100644
index 0000000..14123a8
--- /dev/null
+++ b/src/main/java/com/trolley/trolley/Payment.java
@@ -0,0 +1,321 @@
+package com.trolley.trolley;
+
+import java.util.List;
+import com.fasterxml.jackson.annotation.JsonInclude;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class Payment
+{
+ private String id;
+ private Recipient recipient;
+ private String status;
+ private Boolean isSupplyPayment;
+ private String returnedAmount;
+ private String amount;
+ private String currency;
+ private String category;
+ private RecipientAccount account;
+ private List tags;
+ private String sourceAmount;
+ private String sourceCurrency;
+ private String targetAmount;
+ private String targetCurrency;
+ private String exchangeRate;
+ private String fees;
+ private String recipientFees;
+ private String fxRate;
+ private String memo;
+ private String externalId;
+ private Object processedAt;
+ private String createdAt;
+ private String updatedAt;
+ private String merchantFees;
+ private Compliance compliance;
+ private String payoutMethod;
+ private String methodDisplay;
+ Object batch;
+ String withholdingAmount;
+ String withholdingCurrency;
+ String equivalentWithholdingAmount;
+ String equivalentWithholdingCurrency;
+
+ public void setEquivalentWithholdingCurrency(final String equivalentWithholdingCurrency) {
+ this.equivalentWithholdingCurrency = equivalentWithholdingCurrency;
+ }
+
+ public String getEquivalentWithholdingCurrency() {
+ return this.equivalentWithholdingCurrency;
+ }
+
+ public void setEquivalentWithholdingAmount(final String equivalentWithholdingAmount) {
+ this.equivalentWithholdingAmount = equivalentWithholdingAmount;
+ }
+
+ public String getEquivalentWithholdingAmount() {
+ return this.equivalentWithholdingAmount;
+ }
+
+ public void setWithholdingCurrency(final String withholdingCurrency) {
+ this.withholdingCurrency = withholdingCurrency;
+ }
+
+ public List getTags() {
+ return this.tags;
+ }
+
+ public void setTags(final List tags) {
+ this.tags = tags;
+ }
+
+ public RecipientAccount getAccount() {
+ return this.account;
+ }
+
+ public void setAccount(final RecipientAccount account) {
+ this.account = account;
+ }
+
+ public String getCategory() {
+ return this.category;
+ }
+
+ public void setCategory(final String category) {
+ this.category = category;
+ }
+
+ public String getCurrency() {
+ return this.currency;
+ }
+
+ public void setCurrency(final String currency) {
+ this.currency = currency;
+ }
+
+ public String getAmount() {
+ return this.amount;
+ }
+
+ public void setAmount(final String amount) {
+ this.amount = amount;
+ }
+
+ public String getWithholdingCurrency() {
+ return this.withholdingCurrency;
+ }
+
+ public void setWithholdingAmount(final String withholdingAmount) {
+ this.withholdingAmount = withholdingAmount;
+ }
+
+ public String getWithholdingAmount() {
+ return this.withholdingAmount;
+ }
+
+ public String getId() {
+ return this.id;
+ }
+
+ public void setId(final String id) {
+ this.id = id;
+ }
+
+ public Recipient getRecipient() {
+ return this.recipient;
+ }
+
+ public void setRecipient(final Recipient recipient) {
+ this.recipient = recipient;
+ }
+
+ public String getStatus() {
+ return this.status;
+ }
+
+ public void setStatus(final String status) {
+ this.status = status;
+ }
+
+ public Boolean getIsSupplyPayment() {
+ return this.isSupplyPayment;
+ }
+
+ public void setIsSupplyPayment(final Boolean isSupplyPayment) {
+ this.isSupplyPayment = isSupplyPayment;
+ }
+
+ public String getReturnedAmount() {
+ return this.returnedAmount;
+ }
+
+ public void setReturnedAmount(final String returnedAmount) {
+ this.returnedAmount = returnedAmount;
+ }
+
+ public String getSourceAmount() {
+ return this.sourceAmount;
+ }
+
+ public void setSourceAmount(final String sourceAmount) {
+ this.sourceAmount = sourceAmount;
+ }
+
+ public String getSourceCurrency() {
+ return this.sourceCurrency;
+ }
+
+ public void setSourceCurrency(final String sourceCurrency) {
+ this.sourceCurrency = sourceCurrency;
+ }
+
+ public String getTargetAmount() {
+ return this.targetAmount;
+ }
+
+ public void setTargetAmount(final String targetAmount) {
+ this.targetAmount = targetAmount;
+ }
+
+ public String getTargetCurrency() {
+ return this.targetCurrency;
+ }
+
+ public void setTargetCurrency(final String targetCurrency) {
+ this.targetCurrency = targetCurrency;
+ }
+
+ public String getExchangeRate() {
+ return this.exchangeRate;
+ }
+
+ public void setExchangeRate(final String exchangeRate) {
+ this.exchangeRate = exchangeRate;
+ }
+
+ public String getFees() {
+ return this.fees;
+ }
+
+ public void setFees(final String fees) {
+ this.fees = fees;
+ }
+
+ public String getRecipientFees() {
+ return this.recipientFees;
+ }
+
+ public void setRecipientFees(final String recipientFees) {
+ this.recipientFees = recipientFees;
+ }
+
+ public String getFxRate() {
+ return this.fxRate;
+ }
+
+ public void setFxRate(final String fxRate) {
+ this.fxRate = fxRate;
+ }
+
+ public String getMemo() {
+ return this.memo;
+ }
+
+ public void setMemo(final String memo) {
+ this.memo = memo;
+ }
+
+ public String getExternalId() {
+ return this.externalId;
+ }
+
+ public void setExternalId(final String externalId) {
+ this.externalId = externalId;
+ }
+
+ public Object getProcessedAt() {
+ return this.processedAt;
+ }
+
+ public void setProcessedAt(final Object processedAt) {
+ this.processedAt = processedAt;
+ }
+
+ public String getCreatedAt() {
+ return this.createdAt;
+ }
+
+ public void setCreatedAt(final String createdAt) {
+ this.createdAt = createdAt;
+ }
+
+ public String getUpdatedAt() {
+ return this.updatedAt;
+ }
+
+ public void setUpdatedAt(final String updatedAt) {
+ this.updatedAt = updatedAt;
+ }
+
+ public String getMerchantFees() {
+ return this.merchantFees;
+ }
+
+ public void setMerchantFees(final String merchantFees) {
+ this.merchantFees = merchantFees;
+ }
+
+ public Compliance getCompliance() {
+ return this.compliance;
+ }
+
+ public void setCompliance(final Compliance compliance) {
+ this.compliance = compliance;
+ }
+
+ public String getPayoutMethod() {
+ return this.payoutMethod;
+ }
+
+ public void setPayoutMethod(final String payoutMethod) {
+ this.payoutMethod = payoutMethod;
+ }
+
+ public String getMethodDisplay() {
+ return this.methodDisplay;
+ }
+
+ public void setMethodDisplay(final String methodDisplay) {
+ this.methodDisplay = methodDisplay;
+ }
+
+ public static Payment find(final String payment_id, final String batch_id) throws Exception {
+ return Configuration.gateway().payment.find(payment_id, batch_id);
+ }
+
+ public static Payment create(final String body, final String batch_id) throws Exception {
+ return Configuration.gateway().payment.create(body, batch_id);
+ }
+
+ public static boolean update(final String payment_id, final String body, final String batch_id) throws Exception {
+ return Configuration.gateway().payment.update(payment_id, body, batch_id);
+ }
+
+ public static boolean delete(final String payment_id, final String batch_id) throws Exception {
+ return Configuration.gateway().payment.delete(payment_id, batch_id);
+ }
+
+ public static List query(final String batch_id, final int page, final int pageSize, final String message) throws Exception {
+ return Configuration.gateway().payment.query(batch_id, page, pageSize, message);
+ }
+
+ public static List query(final String batch_id, final String message) throws Exception {
+ return query(batch_id, 1, 10, message);
+ }
+
+ public static List query(final String batch_id) throws Exception {
+ return query(batch_id, 1, 10, "");
+ }
+
+ public static List query(final String batch_id, final int page, final int pageSize) throws Exception {
+ return query(batch_id, page, pageSize, "");
+ }
+}
diff --git a/src/main/java/ca/paymentrails/paymentrails/PaymentGateway.java b/src/main/java/com/trolley/trolley/PaymentGateway.java
similarity index 51%
rename from src/main/java/ca/paymentrails/paymentrails/PaymentGateway.java
rename to src/main/java/com/trolley/trolley/PaymentGateway.java
index d8df8a7..6f07423 100644
--- a/src/main/java/ca/paymentrails/paymentrails/PaymentGateway.java
+++ b/src/main/java/com/trolley/trolley/PaymentGateway.java
@@ -1,48 +1,46 @@
-package ca.paymentrails.paymentrails;
+package com.trolley.trolley;
-import ca.paymentrails.Exceptions.InvalidFieldException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import java.io.IOException;
import java.util.ArrayList;
+import java.io.IOException;
+import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
+import com.trolley.Exceptions.InvalidFieldException;
-public class PaymentGateway {
+public class PaymentGateway
+{
Client client;
-
- public PaymentGateway(Configuration config) {
+
+ public PaymentGateway(final Configuration config) {
this.client = new Client(config);
}
-
- public Payment find(String payment_id, String batch_id) throws Exception {
+
+ public Payment find(final String payment_id, final String batch_id) throws Exception {
if (batch_id == null || batch_id.isEmpty()) {
throw new InvalidFieldException("Batch id cannot be null or empty.");
}
if (payment_id == null || payment_id.isEmpty()) {
throw new InvalidFieldException("Payment id cannot be null or empty.");
}
-
- String endPoint = "/v1/batches/" + batch_id + "/payments/" + payment_id;
- String response = this.client.get(endPoint);
- return paymentFactory(response);
+ final String endPoint = "/v1/batches/" + batch_id + "/payments/" + payment_id;
+ final String response = this.client.get(endPoint);
+ return this.paymentFactory(response);
}
-
- public Payment create(String body, String batch_id) throws Exception {
+
+ public Payment create(final String body, final String batch_id) throws Exception {
if (batch_id == null || batch_id.isEmpty()) {
throw new InvalidFieldException("Batch id cannot be null or empty.");
}
if (body == null || body.isEmpty()) {
throw new InvalidFieldException("Body cannot be null or empty.");
}
-
- String endPoint = "/v1/batches/" + batch_id + "/payments";
- String response = this.client.post(endPoint, body);
-
- return paymentFactory(response);
+ final String endPoint = "/v1/batches/" + batch_id + "/payments";
+ final String response = this.client.post(endPoint, body);
+ return this.paymentFactory(response);
}
-
- public boolean update(String payment_id, String body, String batch_id) throws Exception {
+
+ public boolean update(final String payment_id, final String body, final String batch_id) throws Exception {
if (batch_id == null || batch_id.isEmpty()) {
throw new InvalidFieldException("Batch id cannot be null or empty.");
}
@@ -52,27 +50,24 @@ public boolean update(String payment_id, String body, String batch_id) throws Ex
if (body == null || body.isEmpty()) {
throw new InvalidFieldException("Body cannot be null or empty.");
}
-
- String endPoint = "/v1/batches/" + batch_id + "/payments/" + payment_id;
+ final String endPoint = "/v1/batches/" + batch_id + "/payments/" + payment_id;
this.client.patch(endPoint, body);
return true;
}
-
- public boolean delete(String payment_id, String batch_id) throws Exception {
+
+ public boolean delete(final String payment_id, final String batch_id) throws Exception {
if (batch_id == null || batch_id.isEmpty()) {
throw new InvalidFieldException("Batch id cannot be null or empty.");
}
if (payment_id == null || payment_id.isEmpty()) {
throw new InvalidFieldException("Payment id cannot be null or empty.");
}
-
- String endPoint = "/v1/batches/" + batch_id + "/payments/" + payment_id;
+ final String endPoint = "/v1/batches/" + batch_id + "/payments/" + payment_id;
this.client.delete(endPoint);
return true;
}
-
- public List query(String batch_id, int page, int pageSize, String message) throws Exception {
-
+
+ public List query(final String batch_id, final int page, final int pageSize, final String message) throws Exception {
if (batch_id == null || batch_id.isEmpty()) {
throw new InvalidFieldException("Batch id cannot be null or empty.");
}
@@ -85,34 +80,30 @@ public List query(String batch_id, int page, int pageSize, String messa
if (message == null) {
throw new InvalidFieldException("Message cannot be null");
}
-
- String endPoint = "/v1/batches/" + batch_id + "/payments/?" + "&search=" + message + "&page=" + page
- + "&pageSize=" + pageSize;
- String response = this.client.get(endPoint);
- return paymentListFactory(response);
+ final String endPoint = "/v1/batches/" + batch_id + "/payments/?&search=" + message + "&page=" + page + "&pageSize=" + pageSize;
+ final String response = this.client.get(endPoint);
+ return this.paymentListFactory(response);
}
-
- private Payment paymentFactory(String data) throws IOException {
- ObjectMapper mapper = new ObjectMapper();
+
+ private Payment paymentFactory(final String data) throws IOException {
+ final ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- JsonNode node = mapper.readTree(data);
- Payment payment = mapper.readValue(node.get("payment").traverse(), Payment.class);
+ final JsonNode node = mapper.readTree(data);
+ final Payment payment = (Payment)mapper.readValue(node.get("payment").traverse(), (Class)Payment.class);
return payment;
}
-
- private List paymentListFactory(String data) throws IOException {
- ObjectMapper mapper = new ObjectMapper();
- JsonNode node = mapper.readTree(data);
+
+ private List paymentListFactory(final String data) throws IOException {
+ final ObjectMapper mapper = new ObjectMapper();
+ final JsonNode node = mapper.readTree(data);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- Object payment = mapper.readValue(node.get("payments").traverse(), Object.class);
- @SuppressWarnings("unchecked")
- List paymens = (List) payment;
- List payments = new ArrayList();
- for (int i = 0; i < paymens.size(); i++) {
- Payment pojo = mapper.convertValue(paymens.get(i), Payment.class);
+ final Object payment = mapper.readValue(node.get("payments").traverse(), (Class)Object.class);
+ final List paymens = (List)payment;
+ final List payments = new ArrayList();
+ for (int i = 0; i < paymens.size(); ++i) {
+ final Payment pojo = (Payment)mapper.convertValue((Object)paymens.get(i), (Class)Payment.class);
payments.add(pojo);
}
-
return payments;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/trolley/trolley/Payments.java b/src/main/java/com/trolley/trolley/Payments.java
new file mode 100644
index 0000000..223f050
--- /dev/null
+++ b/src/main/java/com/trolley/trolley/Payments.java
@@ -0,0 +1,31 @@
+package com.trolley.trolley;
+
+import java.util.List;
+
+import com.trolley.trolley.types.Meta;
+
+public class Payments
+{
+ private List payments;
+ private Meta meta;
+
+ public Payments() {
+ this.payments = null;
+ }
+
+ public List getPayments() {
+ return this.payments;
+ }
+
+ public void setPayments(final List payments) {
+ this.payments = payments;
+ }
+
+ public Meta getMeta() {
+ return this.meta;
+ }
+
+ public void setMeta(final Meta meta) {
+ this.meta = meta;
+ }
+}
diff --git a/src/main/java/com/trolley/trolley/Recipient.java b/src/main/java/com/trolley/trolley/Recipient.java
new file mode 100644
index 0000000..fc077e5
--- /dev/null
+++ b/src/main/java/com/trolley/trolley/Recipient.java
@@ -0,0 +1,353 @@
+package com.trolley.trolley;
+
+import java.util.List;
+import com.fasterxml.jackson.annotation.JsonInclude;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class Recipient
+{
+ String id;
+ String routeType;
+ String routeMinimum;
+ String estimatedFees;
+ String referenceId;
+ String email;
+ String name;
+ String lastName;
+ String firstName;
+ String type;
+ String taxType;
+ String status;
+ String language;
+ String complianceStatus;
+ String dob;
+ String passport;
+ String updatedAt;
+ String createdAt;
+ String gravatarUrl;
+ String governmentId;
+ String ssn;
+ String primaryCurrency;
+ String placeOfBirth;
+ List tags;
+ String merchantId;
+ String payoutMethod;
+ public Object payout;
+ String emailAddress;
+ public Object inactiveReasons;
+ Compliance compliance;
+ List accounts;
+ Address address;
+ String taxForm;
+ String taxFormStatus;
+ String taxWithholdingPercentage;
+
+ public Recipient() {
+ this.taxWithholdingPercentage = "0.0";
+ }
+
+ public String getTaxFormStatus() {
+ return this.taxFormStatus;
+ }
+
+ public void setTaxFormStatus(final String taxFormStatus) {
+ this.taxFormStatus = this.taxForm;
+ }
+
+ public List getTags() {
+ return this.tags;
+ }
+
+ public void setTags(final List tags) {
+ this.tags = tags;
+ }
+
+ public String getTaxWithholdingPercentage() {
+ return this.taxWithholdingPercentage;
+ }
+
+ public void setTaxWithholdingPercentage(final String taxWithholdingPercentage) {
+ this.taxWithholdingPercentage = taxWithholdingPercentage;
+ }
+
+ public String getTaxForm() {
+ return this.taxForm;
+ }
+
+ public void setTaxForm(final String taxForm) {
+ this.taxForm = taxForm;
+ }
+
+ public Object getInactiveReasons() {
+ return this.inactiveReasons;
+ }
+
+ public void setInactiveReasons(final Object inactiveReasons) {
+ this.inactiveReasons = inactiveReasons;
+ }
+
+ public List getAccounts() {
+ return this.accounts;
+ }
+
+ public void setAccounts(final List accounts) {
+ this.accounts = accounts;
+ }
+
+ public void setAddress(final Address address) {
+ this.address = address;
+ }
+
+ public Address getAddress() {
+ return this.address;
+ }
+
+ public Compliance getCompliance() {
+ return this.compliance;
+ }
+
+ public void setCompliance(final Compliance compliance) {
+ this.compliance = compliance;
+ }
+
+ public String getLastName() {
+ return this.lastName;
+ }
+
+ public void setLastName(final String lastName) {
+ this.lastName = lastName;
+ }
+
+ public String getRouteType() {
+ return this.routeType;
+ }
+
+ public void setRouteType(final String routeType) {
+ this.routeType = routeType;
+ }
+
+ public String getRouteMinimum() {
+ return this.routeMinimum;
+ }
+
+ public void setRouteMinimum(String routeMinimum) {
+ this.routeMinimum = routeMinimum;
+ }
+
+ public String getEstimatedFees() {
+ return this.estimatedFees;
+ }
+
+ public void setEstimatedFees(final String estimatedFees) {
+ this.estimatedFees = estimatedFees;
+ }
+
+ public String getId() {
+ return this.id;
+ }
+
+ public void setId(final String id) {
+ this.id = id;
+ }
+
+ public String getReferenceId() {
+ return this.referenceId;
+ }
+
+ public void setReferenceId(final String referenceId) {
+ this.referenceId = referenceId;
+ }
+
+ public String getEmail() {
+ return this.email;
+ }
+
+ public void setEmail(final String email) {
+ this.email = email;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getFirstName() {
+ return this.firstName;
+ }
+
+ public void setFirstName(final String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getType() {
+ return this.type;
+ }
+
+ public void setType(final String type) {
+ this.type = type;
+ }
+
+ public String getTaxType() {
+ return this.taxType;
+ }
+
+ public void setTaxType(final String taxType) {
+ this.taxType = taxType;
+ }
+
+ public String getStatus() {
+ return this.status;
+ }
+
+ public void setStatus(final String status) {
+ this.status = status;
+ }
+
+ public String getLanguage() {
+ return this.language;
+ }
+
+ public void setLanguage(final String language) {
+ this.language = language;
+ }
+
+ public String getComplianceStatus() {
+ return this.complianceStatus;
+ }
+
+ public void setComplianceStatus(final String complianceStatus) {
+ this.complianceStatus = complianceStatus;
+ }
+
+ public String getDob() {
+ return this.dob;
+ }
+
+ public void setDob(final String dob) {
+ this.dob = dob;
+ }
+
+ public String getPassport() {
+ return this.passport;
+ }
+
+ public void setPassport(final String passport) {
+ this.passport = passport;
+ }
+
+ public String getUpdatedAt() {
+ return this.updatedAt;
+ }
+
+ public void setUpdatedAt(final String updatedAt) {
+ this.updatedAt = updatedAt;
+ }
+
+ public String getCreatedAt() {
+ return this.createdAt;
+ }
+
+ public void setCreatedAt(final String createdAt) {
+ this.createdAt = createdAt;
+ }
+
+ public String getGravatarUrl() {
+ return this.gravatarUrl;
+ }
+
+ public void setGravatarUrl(final String gravatarUrl) {
+ this.gravatarUrl = gravatarUrl;
+ }
+
+ public String getGovernmentId() {
+ return this.governmentId;
+ }
+
+ public void setGovernmentId(final String governmentId) {
+ this.governmentId = governmentId;
+ }
+
+ public String getSsn() {
+ return this.ssn;
+ }
+
+ public void setSsn(final String ssn) {
+ this.ssn = ssn;
+ }
+
+ public String getPrimaryCurrency() {
+ return this.primaryCurrency;
+ }
+
+ public void setPrimaryCurrency(final String primaryCurrency) {
+ this.primaryCurrency = primaryCurrency;
+ }
+
+ public String getPlaceOfBirth() {
+ return this.placeOfBirth;
+ }
+
+ public void setPlaceOfBirth(final String placeOfBirth) {
+ this.placeOfBirth = placeOfBirth;
+ }
+
+ public String getMerchantId() {
+ return this.merchantId;
+ }
+
+ public void setMerchantId(final String merchantId) {
+ this.merchantId = merchantId;
+ }
+
+ public String getPayoutMethod() {
+ return this.payoutMethod;
+ }
+
+ public void setPayoutMethod(final String payoutMethod) {
+ this.payoutMethod = payoutMethod;
+ }
+
+ public static Recipient find(final String recipient_id) throws Exception {
+ return Configuration.gateway().recipient.find(recipient_id);
+ }
+
+ public static String findLogs(final String recipient_id) throws Exception {
+ final String response = Configuration.gateway().recipient.findLogs(recipient_id);
+ return response;
+ }
+
+ public static List findPayments(final String recipient_id) throws Exception {
+ return Configuration.gateway().recipient.findPayments(recipient_id);
+ }
+
+ public static Recipient create(final String body) throws Exception {
+ return Configuration.gateway().recipient.create(body);
+ }
+
+ public static boolean update(final String recipient_id, final String body) throws Exception {
+ return Configuration.gateway().recipient.update(recipient_id, body);
+ }
+
+ public static boolean delete(final String recipient_id) throws Exception {
+ return Configuration.gateway().recipient.delete(recipient_id);
+ }
+
+ public static List search(final int page, final int pageSize, final String term) throws Exception {
+ return Configuration.gateway().recipient.search(page, pageSize, term);
+ }
+
+ public static List search(final String message) throws Exception {
+ return search(1, 10, message);
+ }
+
+ public static List search() throws Exception {
+ return search(1, 10, "");
+ }
+
+ public static List search(final int page, final int pageNumber) throws Exception {
+ return search(page, pageNumber, "");
+ }
+}
diff --git a/src/main/java/com/trolley/trolley/RecipientAccount.java b/src/main/java/com/trolley/trolley/RecipientAccount.java
new file mode 100644
index 0000000..e7d0648
--- /dev/null
+++ b/src/main/java/com/trolley/trolley/RecipientAccount.java
@@ -0,0 +1,237 @@
+
+package com.trolley.trolley;
+
+import java.util.List;
+import com.fasterxml.jackson.annotation.JsonInclude;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class RecipientAccount
+{
+ String type;
+ Boolean primary;
+ String currency;
+ String id;
+ String recipientId;
+ String recipientAccountId;
+ String routeType;
+ String recipientFees;
+ String country;
+ String iban;
+ String accountNum;
+ String accountHolderName;
+ String swiftBic;
+ String branchId;
+ String bankId;
+ String bankName;
+ String bankAddress;
+ String bankCity;
+ String bankRegionCode;
+ String bankPostalCode;
+ String emailAddress;
+ String status;
+ String disabledAt;
+
+ public String getEmailAddress() {
+ return this.emailAddress;
+ }
+
+ public void setEmailAddress(final String emailAddress) {
+ this.emailAddress = emailAddress;
+ }
+
+ public String getDisabledAt() {
+ return this.disabledAt;
+ }
+
+ public void setDisabledAt(final String disabledAt) {
+ this.disabledAt = disabledAt;
+ }
+
+ public String getStatus() {
+ return this.status;
+ }
+
+ public void setStatus(final String status) {
+ this.status = status;
+ }
+
+ public String getRecipientId() {
+ return this.recipientId;
+ }
+
+ public void setRecipientId(final String recipientId) {
+ this.recipientId = recipientId;
+ }
+
+ public String getType() {
+ return this.type;
+ }
+
+ public void setType(final String type) {
+ this.type = type;
+ }
+
+ public Boolean getPrimary() {
+ return this.primary;
+ }
+
+ public void setPrimary(final Boolean primary) {
+ this.primary = primary;
+ }
+
+ public String getCurrency() {
+ return this.currency;
+ }
+
+ public void setCurrency(final String currency) {
+ this.currency = currency;
+ }
+
+ public String getId() {
+ return this.id;
+ }
+
+ public void setId(final String id) {
+ this.id = id;
+ }
+
+ public String getRecipientAccountId() {
+ return this.recipientAccountId;
+ }
+
+ public void setRecipientAccountId(final String recipientAccountId) {
+ this.recipientAccountId = recipientAccountId;
+ }
+
+ public String getRouteType() {
+ return this.routeType;
+ }
+
+ public void setRouteType(final String routeType) {
+ this.routeType = routeType;
+ }
+
+ public String getRecipientFees() {
+ return this.recipientFees;
+ }
+
+ public void setRecipientFees(final String recipientFees) {
+ this.recipientFees = recipientFees;
+ }
+
+ public String getCountry() {
+ return this.country;
+ }
+
+ public void setCountry(final String country) {
+ this.country = country;
+ }
+
+ public String getIban() {
+ return this.iban;
+ }
+
+ public void setIban(final String iban) {
+ this.iban = iban;
+ }
+
+ public String getAccountNum() {
+ return this.accountNum;
+ }
+
+ public void setAccountNum(final String accountNum) {
+ this.accountNum = accountNum;
+ }
+
+ public String getAccountHolderName() {
+ return this.accountHolderName;
+ }
+
+ public void setAccountHolderName(final String accountHolderName) {
+ this.accountHolderName = accountHolderName;
+ }
+
+ public String getSwiftBic() {
+ return this.swiftBic;
+ }
+
+ public void setSwiftBic(final String swiftBic) {
+ this.swiftBic = swiftBic;
+ }
+
+ public String getBranchId() {
+ return this.branchId;
+ }
+
+ public void setBranchId(final String branchId) {
+ this.branchId = branchId;
+ }
+
+ public String getBankId() {
+ return this.bankId;
+ }
+
+ public void setBankId(final String bankId) {
+ this.bankId = bankId;
+ }
+
+ public String getBankName() {
+ return this.bankName;
+ }
+
+ public void setBankName(final String bankName) {
+ this.bankName = bankName;
+ }
+
+ public String getBankAddress() {
+ return this.bankAddress;
+ }
+
+ public void setBankAddress(final String bankAddress) {
+ this.bankAddress = bankAddress;
+ }
+
+ public String getBankCity() {
+ return this.bankCity;
+ }
+
+ public void setBankCity(final String bankCity) {
+ this.bankCity = bankCity;
+ }
+
+ public String getBankRegionCode() {
+ return this.bankRegionCode;
+ }
+
+ public void setBankRegionCode(final String bankRegionCode) {
+ this.bankRegionCode = bankRegionCode;
+ }
+
+ public String getBankPostalCode() {
+ return this.bankPostalCode;
+ }
+
+ public void setBankPostalCode(final String bankPostalCode) {
+ this.bankPostalCode = bankPostalCode;
+ }
+
+ public static List findAll(final String recipient_id) throws Exception {
+ return Configuration.gateway().recipientAccount.findAll(recipient_id);
+ }
+
+ public static RecipientAccount find(final String recipient_id, final String recipient_account_id) throws Exception {
+ return Configuration.gateway().recipientAccount.find(recipient_id, recipient_account_id);
+ }
+
+ public static RecipientAccount create(final String recipient_id, final String body) throws Exception {
+ return Configuration.gateway().recipientAccount.create(recipient_id, body);
+ }
+
+ public static RecipientAccount update(final String recipient_id, final String recipient_account_id, final String body) throws Exception {
+ return Configuration.gateway().recipientAccount.update(recipient_id, recipient_account_id, body);
+ }
+
+ public static boolean delete(final String recipient_id, final String recipient_account_id) throws Exception {
+ return Configuration.gateway().recipientAccount.delete(recipient_id, recipient_account_id);
+ }
+}
diff --git a/src/main/java/com/trolley/trolley/RecipientAccountGateway.java b/src/main/java/com/trolley/trolley/RecipientAccountGateway.java
new file mode 100644
index 0000000..1498645
--- /dev/null
+++ b/src/main/java/com/trolley/trolley/RecipientAccountGateway.java
@@ -0,0 +1,118 @@
+
+package com.trolley.trolley;
+
+import java.util.ArrayList;
+import java.io.IOException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.trolley.Exceptions.InvalidFieldException;
+import java.util.List;
+
+public class RecipientAccountGateway
+{
+ Client client;
+
+ public RecipientAccountGateway(final Configuration config) {
+ this.client = new Client(config);
+ }
+
+ public List findAll(final String recipient_id) throws Exception {
+ if (recipient_id == null || recipient_id.isEmpty()) {
+ throw new InvalidFieldException("Recipient id cannot be null or empty.");
+ }
+ final String endPoint = "/v1/recipients/" + recipient_id + "/accounts";
+ final String response = this.client.get(endPoint);
+ return this.recipientAccountListFactory(response);
+ }
+
+ public RecipientAccount find(final String recipient_id, final String recipient_account_id) throws Exception {
+ if (recipient_id == null || recipient_id.isEmpty()) {
+ throw new InvalidFieldException("Recipient id cannot be null or empty.");
+ }
+ final String endPoint = "/v1/recipients/" + recipient_id + "/accounts/" + recipient_account_id;
+ final String response = this.client.get(endPoint);
+ return this.recipientAccountFactory(response);
+ }
+
+ public RecipientAccount create(final String recipient_id, final String body) throws Exception {
+ if (recipient_id == null || recipient_id.isEmpty()) {
+ throw new InvalidFieldException("Recipient id cannot be null or empty.");
+ }
+ if (body == null || body.isEmpty()) {
+ throw new InvalidFieldException("Body cannot be null or empty");
+ }
+ final String endPoint = "/v1/recipients/" + recipient_id + "/accounts";
+ final String response = this.client.post(endPoint, body);
+ return this.recipientAccountFactory(response);
+ }
+
+ public RecipientAccount create(final String recipient_id, final RecipientAccount account) throws Exception {
+ if (recipient_id == null || recipient_id.isEmpty()) {
+ throw new InvalidFieldException("Recipient id cannot be null or empty.");
+ }
+ if (account == null) {
+ throw new InvalidFieldException("Body cannot be null or empty");
+ }
+ final String jsonAccount = new ObjectMapper().writeValueAsString((Object)account);
+ final String endPoint = "/v1/recipients/" + recipient_id + "/accounts";
+ final String response = this.client.post(endPoint, jsonAccount);
+ return this.recipientAccountFactory(response);
+ }
+
+ public RecipientAccount update(final String recipient_id, final String recipient_account_id, final String body) throws Exception {
+ if (recipient_id == null || recipient_id.isEmpty()) {
+ throw new InvalidFieldException("Recipient id cannot be null or empty.");
+ }
+ if (body == null || body.isEmpty()) {
+ throw new InvalidFieldException("Body cannot be null or empty");
+ }
+ final String endPoint = "/v1/recipients/" + recipient_id + "/accounts/" + recipient_account_id;
+ final String response = this.client.patch(endPoint, body);
+ return this.recipientAccountFactory(response);
+ }
+
+ public RecipientAccount update(final String recipient_id, final String recipient_account_id, final RecipientAccount account) throws Exception {
+ if (recipient_id == null || recipient_id.isEmpty()) {
+ throw new InvalidFieldException("Recipient id cannot be null or empty.");
+ }
+ if (account == null) {
+ throw new InvalidFieldException("Body cannot be null or empty");
+ }
+ final String jsonAccount = new ObjectMapper().writeValueAsString((Object)account);
+ final String endPoint = "/v1/recipients/" + recipient_id + "/accounts/" + recipient_account_id;
+ final String response = this.client.patch(endPoint, jsonAccount);
+ return this.recipientAccountFactory(response);
+ }
+
+ public boolean delete(final String recipient_id, final String recipient_account_id) throws Exception {
+ if (recipient_id == null || recipient_id.isEmpty()) {
+ throw new InvalidFieldException("Recipient id cannot be null or empty.");
+ }
+ final String endPoint = "/v1/recipients/" + recipient_id + "/accounts/" + recipient_account_id;
+ this.client.delete(endPoint);
+ return true;
+ }
+
+ private RecipientAccount recipientAccountFactory(final String data) throws IOException {
+ final ObjectMapper mapper = new ObjectMapper();
+ final JsonNode node = mapper.readTree(data);
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ final RecipientAccount recipientAccount = (RecipientAccount)mapper.readValue(node.get("account").traverse(), (Class)RecipientAccount.class);
+ return recipientAccount;
+ }
+
+ private List recipientAccountListFactory(final String data) throws IOException {
+ final ObjectMapper mapper = new ObjectMapper();
+ final JsonNode node = mapper.readTree(data);
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ final Object recipientAccount = mapper.readValue(node.get("accounts").traverse(), (Class)Object.class);
+ final List recipAccounts = (List)recipientAccount;
+ final List recipientAccounts = new ArrayList();
+ for (int i = 0; i < recipAccounts.size(); ++i) {
+ final RecipientAccount pojo = (RecipientAccount)mapper.convertValue((Object)recipAccounts.get(i), (Class)RecipientAccount.class);
+ recipientAccounts.add(pojo);
+ }
+ return recipientAccounts;
+ }
+}
diff --git a/src/main/java/com/trolley/trolley/RecipientGateway.java b/src/main/java/com/trolley/trolley/RecipientGateway.java
new file mode 100644
index 0000000..9da04a0
--- /dev/null
+++ b/src/main/java/com/trolley/trolley/RecipientGateway.java
@@ -0,0 +1,140 @@
+
+package com.trolley.trolley;
+
+import java.io.IOException;
+import com.fasterxml.jackson.databind.JsonNode;
+import java.util.ArrayList;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.List;
+import com.trolley.Exceptions.InvalidFieldException;
+
+public class RecipientGateway
+{
+ Client client;
+
+ public RecipientGateway(final Configuration config) {
+ this.client = new Client(config);
+ }
+
+ public Recipient find(final String recipient_id) throws Exception {
+ if (recipient_id == null || recipient_id.isEmpty()) {
+ throw new InvalidFieldException("Recipient id cannot be null or empty.");
+ }
+ final String endPoint = "/v1/recipients/" + recipient_id;
+ final String response = this.client.get(endPoint);
+ return this.recipientFactory(response);
+ }
+
+ public String findLogs(final String recipient_id) throws Exception {
+ final String endPoint = "/v1/recipients/" + recipient_id + "/logs";
+ final String response = this.client.get(endPoint);
+ return response;
+ }
+
+ public List findPayments(final String recipient_id) throws Exception {
+ final String endPoint = "/v1/recipients/" + recipient_id + "/payments";
+ final String response = this.client.get(endPoint);
+ final ObjectMapper mapper = new ObjectMapper();
+ final JsonNode node = mapper.readTree(response);
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ final Object payment = mapper.readValue(node.get("payments").traverse(), (Class)Object.class);
+ final List paymens = (List)payment;
+ final List payments = new ArrayList();
+ for (int i = 0; i < paymens.size(); ++i) {
+ final Payment pojo = (Payment)mapper.convertValue((Object)paymens.get(i), (Class)Payment.class);
+ payments.add(pojo);
+ }
+ return payments;
+ }
+
+ public Recipient create(final String body) throws Exception {
+ if (body == null || body.isEmpty()) {
+ throw new InvalidFieldException("Body cannot be null or empty");
+ }
+ final String endPoint = "/v1/recipients/";
+ final String response = this.client.post(endPoint, body);
+ return this.recipientFactory(response);
+ }
+
+ public Recipient create(final Recipient recipient) throws Exception {
+ if (recipient == null) {
+ throw new InvalidFieldException("Body cannot be null or empty");
+ }
+ final String jsonRecipient = new ObjectMapper().writeValueAsString((Object)recipient);
+ final String endPoint = "/v1/recipients/";
+ final String response = this.client.post(endPoint, jsonRecipient);
+ return this.recipientFactory(response);
+ }
+
+ public boolean update(final String recipient_id, final String body) throws Exception {
+ if (recipient_id == null || recipient_id.isEmpty()) {
+ throw new InvalidFieldException("Recipient id cannot be null or empty.");
+ }
+ if (body == null || body.isEmpty()) {
+ throw new InvalidFieldException("Body cannot be null or empty");
+ }
+ final String endPoint = "/v1/recipients/" + recipient_id;
+ this.client.patch(endPoint, body);
+ return true;
+ }
+
+ public boolean update(final String recipient_id, final Recipient recipient) throws Exception {
+ if (recipient_id == null || recipient_id.isEmpty()) {
+ throw new InvalidFieldException("Recipient id cannot be null or empty.");
+ }
+ if (recipient == null) {
+ throw new InvalidFieldException("Body cannot be null or empty");
+ }
+ final String jsonRecipient = new ObjectMapper().writeValueAsString((Object)recipient);
+ final String endPoint = "/v1/recipients/" + recipient_id;
+ this.client.patch(endPoint, jsonRecipient);
+ return true;
+ }
+
+ public boolean delete(final String recipient_id) throws Exception {
+ if (recipient_id == null || recipient_id.isEmpty()) {
+ throw new InvalidFieldException("Recipient id cannot be null or empty.");
+ }
+ final String endPoint = "/v1/recipients/" + recipient_id;
+ this.client.delete(endPoint);
+ return true;
+ }
+
+ public List search(final int page, final int pageSize, final String term) throws Exception {
+ if (page < 0) {
+ throw new InvalidFieldException("Page cannot be less than 0");
+ }
+ if (pageSize < 0) {
+ throw new InvalidFieldException("Page size cannot be less than 0");
+ }
+ if (term == null) {
+ throw new InvalidFieldException("Message cannot be null");
+ }
+ final String endPoint = "/v1/recipients/?&search=" + term + "&page=" + page + "&pageSize=" + pageSize;
+ final String response = this.client.get(endPoint);
+ return this.recipientListFactory(response);
+ }
+
+ private Recipient recipientFactory(final String data) throws IOException {
+ final ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ final JsonNode node = mapper.readTree(data);
+ final Recipient recipient = (Recipient)mapper.readValue(node.get("recipient").traverse(), (Class)Recipient.class);
+ return recipient;
+ }
+
+ private List recipientListFactory(final String data) throws IOException {
+ final ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ final JsonNode node = mapper.readTree(data);
+ final Object recipient = mapper.readValue(node.get("recipients").traverse(), (Class)Object.class);
+ final List recips = (List)recipient;
+ final List recipients = new ArrayList();
+ for (int i = 0; i < recips.size(); ++i) {
+ final Recipient pojo = (Recipient)mapper.convertValue((Object)recips.get(i), (Class)Recipient.class);
+ recipients.add(pojo);
+ }
+ return recipients;
+ }
+}
diff --git a/src/main/java/ca/paymentrails/paymentrails/Total.java b/src/main/java/com/trolley/trolley/Total.java
similarity index 71%
rename from src/main/java/ca/paymentrails/paymentrails/Total.java
rename to src/main/java/com/trolley/trolley/Total.java
index ef7e67b..48aadc1 100644
--- a/src/main/java/ca/paymentrails/paymentrails/Total.java
+++ b/src/main/java/com/trolley/trolley/Total.java
@@ -1,10 +1,11 @@
-package ca.paymentrails.paymentrails;
-public class Total {
+package com.trolley.trolley;
+public class Total
+{
public Integer count;
public String totalFees;
public String merchantFees;
public String debitAmount;
public String sendingAmount;
-}
\ No newline at end of file
+}
diff --git a/src/main/java/ca/paymentrails/paymentrails/USD.java b/src/main/java/com/trolley/trolley/USD.java
similarity index 51%
rename from src/main/java/ca/paymentrails/paymentrails/USD.java
rename to src/main/java/com/trolley/trolley/USD.java
index 2976037..80cd1c3 100644
--- a/src/main/java/ca/paymentrails/paymentrails/USD.java
+++ b/src/main/java/com/trolley/trolley/USD.java
@@ -1,59 +1,60 @@
-package ca.paymentrails.paymentrails;
-public class USD {
+package com.trolley.trolley;
+public class USD
+{
private Boolean primary;
private String amount;
private String currency;
private String type;
private String accountNumber;
private Boolean display;
-
+
public Boolean getPrimary() {
- return primary;
+ return this.primary;
}
-
- public void setPrimary(Boolean primary) {
+
+ public void setPrimary(final Boolean primary) {
this.primary = primary;
}
-
+
public String getAmount() {
- return amount;
+ return this.amount;
}
-
- public void setAmount(String amount) {
+
+ public void setAmount(final String amount) {
this.amount = amount;
}
-
+
public String getCurrency() {
- return currency;
+ return this.currency;
}
-
- public void setCurrency(String currency) {
+
+ public void setCurrency(final String currency) {
this.currency = currency;
}
-
+
public String getType() {
- return type;
+ return this.type;
}
-
- public void setType(String type) {
+
+ public void setType(final String type) {
this.type = type;
}
-
+
public String getAccountNumber() {
- return accountNumber;
+ return this.accountNumber;
}
-
- public void setAccountNumber(String accountNumber) {
+
+ public void setAccountNumber(final String accountNumber) {
this.accountNumber = accountNumber;
}
-
+
public Boolean getDisplay() {
- return display;
+ return this.display;
}
-
- public void setDisplay(Boolean display) {
+
+ public void setDisplay(final Boolean display) {
this.display = display;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/trolley/trolley/Version.java b/src/main/java/com/trolley/trolley/Version.java
new file mode 100644
index 0000000..dd9a28f
--- /dev/null
+++ b/src/main/java/com/trolley/trolley/Version.java
@@ -0,0 +1,10 @@
+package com.trolley.trolley;
+
+/**
+ * Public class provide SemVer information
+ */
+public class Version {
+ public static int MAJOR = 1;
+ public static int MINOR = 1;
+ public static int PATCH = 0;
+}
diff --git a/src/main/java/com/trolley/trolley/types/Amount.java b/src/main/java/com/trolley/trolley/types/Amount.java
new file mode 100644
index 0000000..0952e82
--- /dev/null
+++ b/src/main/java/com/trolley/trolley/types/Amount.java
@@ -0,0 +1,31 @@
+package com.trolley.trolley.types;
+
+public class Amount {
+
+ private String value;
+ private String currency;
+
+ public Amount(){
+ }
+
+ public Amount(String value, String currency){
+ this.value = value;
+ this.currency = currency;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getCurrency() {
+ return currency;
+ }
+
+ public void setCurrency(String currency) {
+ this.currency = currency;
+ }
+}
diff --git a/src/main/java/com/trolley/trolley/types/InvoicePaymentPart.java b/src/main/java/com/trolley/trolley/types/InvoicePaymentPart.java
new file mode 100644
index 0000000..dfb76ab
--- /dev/null
+++ b/src/main/java/com/trolley/trolley/types/InvoicePaymentPart.java
@@ -0,0 +1,50 @@
+package com.trolley.trolley.types;
+
+public class InvoicePaymentPart{
+ private String invoiceId;
+ private String invoiceLineId;
+ private String paymentId;
+ private Amount amount;
+
+ public InvoicePaymentPart() {
+ }
+
+ public InvoicePaymentPart(String invoiceId, String invoiceLineId, String paymentId, Amount amount) {
+ this.invoiceId = invoiceId;
+ this.invoiceLineId = invoiceLineId;
+ this.paymentId = paymentId;
+ this.amount = amount;
+ }
+
+ public String getInvoiceId() {
+ return invoiceId;
+ }
+
+ public void setInvoiceId(String invoiceId) {
+ this.invoiceId = invoiceId;
+ }
+
+ public String getInvoiceLineId() {
+ return invoiceLineId;
+ }
+
+ public void setInvoiceLineId(String invoiceLineId) {
+ this.invoiceLineId = invoiceLineId;
+ }
+
+ public String getPaymentId() {
+ return paymentId;
+ }
+
+ public void setPaymentId(String paymentId) {
+ this.paymentId = paymentId;
+ }
+
+ public Amount getAmount() {
+ return amount;
+ }
+
+ public void setAmount(Amount amount) {
+ this.amount = amount;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/trolley/trolley/types/InvoicePayments.java b/src/main/java/com/trolley/trolley/types/InvoicePayments.java
new file mode 100644
index 0000000..b7eff2b
--- /dev/null
+++ b/src/main/java/com/trolley/trolley/types/InvoicePayments.java
@@ -0,0 +1,30 @@
+package com.trolley.trolley.types;
+
+import java.util.List;
+
+public class InvoicePayments {
+
+ private List invoicePaymentParts;
+ private Meta meta;
+
+ public InvoicePayments(List invoicePaymentParts, Meta meta) {
+ this.invoicePaymentParts = invoicePaymentParts;
+ this.meta = meta;
+ }
+
+ public List getInvoicePaymentParts() {
+ return this.invoicePaymentParts;
+ }
+
+ public void setInvoicePaymentParts(final List invoicePaymentParts) {
+ this.invoicePaymentParts = invoicePaymentParts;
+ }
+
+ public Meta getMeta() {
+ return this.meta;
+ }
+
+ public void setMeta(final Meta meta) {
+ this.meta = meta;
+ }
+}
diff --git a/src/main/java/com/trolley/trolley/types/Invoices.java b/src/main/java/com/trolley/trolley/types/Invoices.java
new file mode 100644
index 0000000..570f862
--- /dev/null
+++ b/src/main/java/com/trolley/trolley/types/Invoices.java
@@ -0,0 +1,32 @@
+package com.trolley.trolley.types;
+
+import java.util.List;
+
+import com.trolley.trolley.Invoice;
+
+public class Invoices {
+
+ private List invoices;
+ private Meta meta;
+
+ public Invoices(List invoices, Meta meta) {
+ this.invoices = invoices;
+ this.meta = meta;
+ }
+
+ public List getInvoices() {
+ return this.invoices;
+ }
+
+ public void setInvoices(final List invoices) {
+ this.invoices = invoices;
+ }
+
+ public Meta getMeta() {
+ return this.meta;
+ }
+
+ public void setMeta(final Meta meta) {
+ this.meta = meta;
+ }
+}
diff --git a/src/main/java/com/trolley/trolley/types/Meta.java b/src/main/java/com/trolley/trolley/types/Meta.java
new file mode 100644
index 0000000..439c90f
--- /dev/null
+++ b/src/main/java/com/trolley/trolley/types/Meta.java
@@ -0,0 +1,41 @@
+package com.trolley.trolley.types;
+
+public class Meta
+{
+ private int page;
+ private int pages;
+ private int records;
+
+ public Meta() {
+ }
+
+ public Meta(int page, int pages, int records) {
+ this.page = page;
+ this.pages = pages;
+ this.records = records;
+ }
+
+ public int getPage() {
+ return this.page;
+ }
+
+ public void setPage(final int page) {
+ this.page = page;
+ }
+
+ public int getPages() {
+ return this.pages;
+ }
+
+ public void setPages(final int pages) {
+ this.pages = pages;
+ }
+
+ public int getRecords() {
+ return this.records;
+ }
+
+ public void setRecords(final int records) {
+ this.records = records;
+ }
+}
diff --git a/src/test/java/ca/paymentrails/paymentrails/integration/BatchTest.java b/src/test/java/ca/paymentrails/paymentrails/integration/BatchTest.java
deleted file mode 100644
index 302fa83..0000000
--- a/src/test/java/ca/paymentrails/paymentrails/integration/BatchTest.java
+++ /dev/null
@@ -1,144 +0,0 @@
-
-package ca.paymentrails.paymentrails.integration;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.util.UUID;
-
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-
-import ca.paymentrails.paymentrails.Batch;
-import ca.paymentrails.paymentrails.BatchSummary;
-import ca.paymentrails.paymentrails.Configuration;
-import ca.paymentrails.paymentrails.Gateway;
-import ca.paymentrails.paymentrails.Payment;
-import ca.paymentrails.paymentrails.Recipient;
-
-@PrepareForTest(Recipient.class)
-public class BatchTest {
-
- private static Configuration config;
-
- @BeforeClass
- public static void setupConfig() {
- final String ACCESS_KEY = "YourAccessKey";
- final String SECRET_KEY = "YourSecretKey";
- final String ENVIRONMENT = "production";
-
- // RecipientTest recipientTest = new RecipientTest();
- config = new Configuration(ACCESS_KEY, SECRET_KEY, ENVIRONMENT);
- }
-
-
- private Recipient createRecipient() throws Exception {
- Gateway client = new Gateway(config);
-
- UUID uuid = UUID.randomUUID();
-
- String email = "\"create.recipient" + uuid.toString() + "@example.com\"";
- String body = "{\"type\": \"individual\",\"firstName\": \"John\",\"lastName\": \"Smith\",\"email\":" + email
- + ",\"address\":{\"street1\": \"123 Main St\",\"city\": \"San Francisco\",\"region\": \"CA\",\"postalCode\": \"94131\",\"country\": \"DE\",\"phone\" : \"18005551212\"}}";
-
- Recipient recipient = client.recipient.create(body);
-
- body = "{\"type\": \"bank-transfer\", \"primary\": true, \"country\": \"DE\", \"currency\": \"EUR\", \"iban\": \"DE89 3704 0044 0532 0130 00\", \"accountHolderName\": \"John Smith\"}";
-
- client.recipientAccount.create(recipient.getId(), body);
-
- return recipient;
- }
-
- @Test
- public void testCreate() throws Exception {
- Gateway client = new Gateway(config);
-
- String body = "{\"sourceCurrency\": \"GBP\", \"description\":\"Integration Test Create\"}";
- Batch batch = client.batch.create(body);
- assertEquals(batch.getCurrency(), "GBP");
- }
-
- @Test
- public void testUpdate() throws Exception {
- Gateway client = new Gateway(config);
-
- String body = "{\"sourceCurrency\": \"GBP\", \"description\":\"Integration Test Create\"}";
- Batch batch = client.batch.create(body);
- assertEquals(batch.getCurrency(), "GBP");
-
- body = "{\"description\" : \"Integration Update\"}";
- boolean response = client.batch.update(batch.getId(), body);
- assertNotNull(response);
-
- Batch batch1 = client.batch.find(batch.getId());
- assertEquals(batch1.getDescription(), "Integration Update");
-
- response = client.batch.delete(batch1.getId());
- assertNotNull(response);
- }
-
- @Test
- public void testCreateWithPayments() throws Exception {
- Gateway client = new Gateway(config);
-
- Recipient recipientAlpha = createRecipient();
-
- String body = "{\"payments\": [{\"recipient\": {\"id\": " + "\"" + recipientAlpha.getId() + "\""
- + "},\"amount\": \"10.00\", \"currency\": \"EUR\"}]}";
- Batch batch = client.batch.create(body);
-
- assertNotNull(batch);
- assertNotNull(batch.getId());
-
- Batch batch1 = client.batch.find(batch.getId());
- assertNotNull(batch1);
-
- assertEquals(1, batch1.getPayments().getPayments().size());
- }
-
- @Test
- public void testPayments() throws Exception {
- Gateway client = new Gateway(config);
-
- String body = "{\"sourceCurrency\": \"GBP\", \"description\":\"Integration Test Create\"}";
- Batch batch = client.batch.create(body);
- assertEquals(batch.getCurrency(), "GBP");
-
- Recipient recipient = createRecipient();
- body = "{\"sourceAmount\":\"10.00\", \"recipient\": {\"id\": " + "\"" + recipient.getId() + "\"" + "}}";
- Payment payment = client.payment.create(body, batch.getId());
- assertNotNull(payment);
- assertNotNull(payment.getId());
- body = "{\"sourceAmount\":\"20.00\"}";
- boolean response = client.payment.update(payment.getId(), body, batch.getId());
- assertNotNull(response);
-
- response = client.payment.delete(payment.getId(), batch.getId());
- assertNotNull(response);
- }
-
- @Test
- public void testProcessing() throws Exception {
- Gateway client = new Gateway(config);
-
- Recipient recipientAlpha = createRecipient();
-
- String body = "{\"payments\": [{\"recipient\": {\"id\": " + "\"" + recipientAlpha.getId() + "\""
- + "},\"amount\": \"10.00\", \"currency\": \"EUR\"}]}";
-
- Batch batch = client.batch.create(body);
- assertNotNull(batch);
- assertNotNull(batch.getId());
-
- BatchSummary batchSummary = client.batch.summary(batch.getId());
- assertNotNull(batchSummary);
-
- String batch1 = client.batch.generateQuote(batch.getId());
- assertNotNull(batch1);
- String batch2 = client.batch.processBatch(batch.getId());
- assertNotNull(batch2);
-
- }
-}
\ No newline at end of file
diff --git a/src/test/java/ca/paymentrails/paymentrails/integration/RecipientTest.java b/src/test/java/ca/paymentrails/paymentrails/integration/RecipientTest.java
deleted file mode 100644
index f9d770e..0000000
--- a/src/test/java/ca/paymentrails/paymentrails/integration/RecipientTest.java
+++ /dev/null
@@ -1,126 +0,0 @@
-
-package ca.paymentrails.paymentrails.integration;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-
-import ca.paymentrails.paymentrails.Configuration;
-import ca.paymentrails.paymentrails.Recipient;
-import ca.paymentrails.paymentrails.RecipientAccount;
-import ca.paymentrails.paymentrails.Gateway;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
-@PrepareForTest(Recipient.class)
-public class RecipientTest {
-
- // Testing order: alphabetical
-
- private static Configuration config;
-
- @BeforeClass
- public static void setupConfig() {
- final String ACCESS_KEY = "YourAccessKey";
- final String SECRET_KEY = "YourSecretKey";
- final String ENVIRONMENT = "production";
-
- // RecipientTest recipientTest = new RecipientTest();
- config = new Configuration(ACCESS_KEY, SECRET_KEY, ENVIRONMENT);
- }
-
- @Test
- public void testCreateRecipient() throws Exception {
- Gateway client = new Gateway(config);
-
- UUID uuid = UUID.randomUUID();
-
- String body = "{\"type\": \"individual\",\"firstName\": \"Tom\",\"lastName\": \"Jones\",\"email\": \"test.create"
- + uuid.toString()
- + "@example.com\",\"address\":{\"street1\": \"123 Main St\",\"city\": \"San Francisco\",\"region\": \"CA\",\"postalCode\": \"94131\",\"country\": \"US\",\"phone\" : \"18005551212\"}}";
- Recipient recipient = client.recipient.create(body);
- assertEquals(recipient.getFirstName(), "Tom");
- assertEquals(recipient.getLastName(), "Jones");
- assertEquals(recipient.getEmail(), "test.create" + uuid.toString() + "@example.com");
- assertNotNull(recipient.getId());
- }
-
- @Test
- public void testLifecycle() throws Exception {
- Gateway client = new Gateway(config);
-
- UUID uuid = UUID.randomUUID();
-
- String body = "{\"type\": \"individual\",\"firstName\": \"Tom\",\"lastName\": \"Jones\",\"email\": \"test.create"
- + uuid.toString() + "@example.com\"}";
- Recipient recipient = client.recipient.create(body);
- assertEquals(recipient.getFirstName(), "Tom");
- assertEquals(recipient.getLastName(), "Jones");
- assertEquals(recipient.getEmail(), "test.create" + uuid.toString() + "@example.com");
- assertNotNull(recipient.getId());
-
- body = "{\"firstName\": \"Bob\"}";
- boolean response = client.recipient.update(recipient.getId(), body);
- assertNotNull(response);
-
- Recipient anotherRecipient = client.recipient.find(recipient.getId());
- assertEquals(anotherRecipient.getFirstName(), "Bob");
-
- response = client.recipient.delete(recipient.getId());
- assertNotNull(response);
-
- Recipient anotherNewRecipient = client.recipient.find(recipient.getId());
- assertEquals("archived", anotherNewRecipient.getStatus());
- }
-
- @Test
- public void testRecipientAccount() throws Exception {
- Gateway client = new Gateway(config);
-
- UUID uuid = UUID.randomUUID();
-
- String body = "{\"type\": \"individual\",\"firstName\": \"Tom\",\"lastName\": \"Jones\",\"email\": \"account.create"
- + uuid.toString() + "@example.com\"}";
- Recipient recipient = client.recipient.create(body);
- assertEquals(recipient.getFirstName(), "Tom");
- assertEquals(recipient.getLastName(), "Jones");
- assertEquals(recipient.getEmail(), "account.create" + uuid.toString() + "@example.com");
- assertNotNull(recipient.getId());
-
- body = "{\"type\": \"bank-transfer\", \"primary\": true, \"country\": \"DE\", \"currency\": \"EUR\", \"iban\": \"DE89 3704 0044 0532 0130 00\", \"accountHolderName\": \"Tom Jones\"}";
- RecipientAccount recipientAccount = client.recipientAccount.create(recipient.getId(), body);
- assertEquals("Tom Jones", recipientAccount.getAccountHolderName());
-
- body = "{\"type\": \"bank-transfer\", \"primary\": true, \"country\": \"DE\", \"currency\": \"EUR\", \"iban\": \"DE89 3704 0044 0532 0130 00\", \"accountHolderName\": \"Tom Jones2\"}";
- RecipientAccount recipientAccount1 = client.recipientAccount.create(recipient.getId(), body);
- assertEquals("Tom Jones2", recipientAccount1.getAccountHolderName());
-
- RecipientAccount recipAccount = client.recipientAccount.find(recipient.getId(), recipientAccount.getId());
- assertEquals(recipAccount.getCountry(), recipientAccount.getCountry());
-
- List recipientAccounts = client.recipientAccount.findAll(recipient.getId());
- assertEquals(2, recipientAccounts.size());
-
- boolean response = client.recipientAccount.delete(recipient.getId(), recipientAccount1.getId());
- assertNotNull(response);
-
- List recipientAccounts1 = client.recipientAccount.findAll(recipient.getId());
- assertEquals(1, recipientAccounts1.size());
- }
-
- @Test
- public void testRecipientRouteMinimum() throws Exception {
- Gateway client = new Gateway(config);
- ArrayList recipients = (ArrayList)client.recipient.search(1,20,"");
- //Making sure routeMinimum is not null before asserting it's value
- assertNotNull(recipients.get(0).getRouteMinimum());
- //Making sure routeMinium is set to a non-null value
- assertTrue(Integer.parseInt(recipients.get(0).getRouteMinimum()) >= 0);
- }
-}
\ No newline at end of file
diff --git a/src/test/java/com/trolley/sdk/integration/BatchTest.java b/src/test/java/com/trolley/sdk/integration/BatchTest.java
new file mode 100644
index 0000000..75b1b50
--- /dev/null
+++ b/src/test/java/com/trolley/sdk/integration/BatchTest.java
@@ -0,0 +1,185 @@
+
+package com.trolley.sdk.integration;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.trolley.trolley.Batch;
+import com.trolley.trolley.BatchSummary;
+import com.trolley.trolley.Configuration;
+import com.trolley.trolley.Gateway;
+import com.trolley.trolley.Payment;
+import com.trolley.trolley.Payments;
+import com.trolley.trolley.Recipient;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+
+@PrepareForTest(Batch.class)
+public class BatchTest {
+
+ private static Configuration config;
+ private static TestHelper testHelper;
+
+ @BeforeClass
+ public static void setupConfig() {
+ config = TestHelper.getConfig();
+ testHelper = new TestHelper();
+ }
+
+ @Test
+ public void testCreate() throws Exception {
+ Gateway client = new Gateway(config);
+
+ String body = "{\"sourceCurrency\": \"GBP\", \"description\":\"Integration Test Create\"}";
+ Batch batch = client.batch.create(body);
+ assertEquals(batch.getCurrency(), "GBP");
+
+ //Cleanup
+ boolean deleteResult = client.batch.delete(batch.getId());
+ assertTrue(deleteResult);
+ }
+
+ @Test
+ public void testCreateObject() throws Exception {
+ Gateway client = new Gateway(config);
+
+ Batch batchToCreate = new Batch();
+ batchToCreate.setCurrency("GBP");
+ batchToCreate.setDescription("Integration Test Create");
+
+ Batch createdBatch = client.batch.create(batchToCreate);
+ assertEquals(createdBatch.getCurrency(), "GBP");
+ assertEquals(createdBatch.getDescription(), "Integration Test Create");
+
+ //Cleanup
+ boolean deleteResult = client.batch.delete(createdBatch.getId());
+ assertTrue(deleteResult);
+ }
+
+ @Test
+ public void testUpdate() throws Exception {
+ Gateway client = new Gateway(config);
+
+ String body = "{\"sourceCurrency\": \"GBP\", \"description\":\"Integration Test Create\"}";
+ Batch batch = client.batch.create(body);
+ assertEquals(batch.getCurrency(), "GBP");
+
+ body = "{\"description\" : \"Integration Update\"}";
+ boolean response = client.batch.update(batch.getId(), body);
+ assertNotNull(response);
+
+ Batch batch1 = client.batch.find(batch.getId());
+ assertEquals(batch1.getDescription(), "Integration Update");
+
+ //Cleanup
+ response = client.batch.delete(batch1.getId());
+ assertNotNull(response);
+ }
+
+ @Test
+ public void testCreateWithPayments() throws Exception {
+ Gateway client = new Gateway(config);
+
+ Recipient recipientAlpha = testHelper.createRecipient();
+ Payment payment = new Payment();
+
+ payment.setAmount("15");
+ payment.setCurrency("USD");
+ payment.setRecipient(recipientAlpha);
+
+ List paymentList = new ArrayList();
+ paymentList.add(payment);
+
+ Payments payments = new Payments();
+ payments.setPayments(paymentList);
+
+ Batch batchToCreate = new Batch();
+ batchToCreate.setPayments(paymentList);
+
+ Batch batch = client.batch.create(batchToCreate);
+
+ assertNotNull(batch);
+ assertNotNull(batch.getId());
+
+ List batchPayments = batch.getPayments();
+ assertEquals(1, batchPayments.size());
+
+ assertEquals("15.00", batchPayments.get(0).getAmount());
+ assertEquals("USD", batchPayments.get(0).getCurrency());
+
+ //Cleanup
+ boolean recDelResult = testHelper.deleteRecipient(recipientAlpha);
+ assertTrue(recDelResult);
+
+ boolean batchDelResult = client.batch.delete(batch.getId());
+ assertTrue(batchDelResult);
+ }
+
+ @Test
+ public void testPayments() throws Exception {
+ Gateway client = new Gateway(config);
+
+ String body = "{\"sourceCurrency\": \"GBP\", \"description\":\"Integration Test Create\"}";
+ Batch batch = client.batch.create(body);
+ assertEquals(batch.getCurrency(), "GBP");
+
+ Recipient recipient = testHelper.createRecipient();
+ body = "{\"sourceAmount\":\"10.00\", \"recipient\": {\"id\": " + "\"" + recipient.getId() + "\"" + "}}";
+ Payment payment = client.payment.create(body, batch.getId());
+ assertNotNull(payment);
+ assertNotNull(payment.getId());
+ body = "{\"sourceAmount\":\"20.00\"}";
+ boolean response = client.payment.update(payment.getId(), body, batch.getId());
+ assertNotNull(response);
+
+ response = client.payment.delete(payment.getId(), batch.getId());
+ assertNotNull(response);
+
+ //Cleanup
+ boolean recDelResult = testHelper.deleteRecipient(recipient);
+ assertTrue(recDelResult);
+
+ boolean batchDelResult = client.batch.delete(batch.getId());
+ assertTrue(batchDelResult);
+ }
+
+ @Test
+ public void testProcessing() throws Exception {
+ Gateway client = new Gateway(config);
+
+ Recipient recipientAlpha = testHelper.createRecipient();
+
+ String body = "{\"payments\": [{\"recipient\": {\"id\": " + "\"" + recipientAlpha.getId() + "\""
+ + "},\"amount\": \"10.00\", \"currency\": \"EUR\"}]}";
+
+ Batch batch = client.batch.create(body);
+ assertNotNull(batch);
+ assertNotNull(batch.getId());
+
+ BatchSummary batchSummary = client.batch.summary(batch.getId());
+ assertNotNull(batchSummary);
+
+ try{
+ String batch1 = client.batch.generateQuote(batch.getId());
+ assertNotNull(batch1);
+
+ String batch2 = client.batch.processBatch(batch.getId());
+ assertNotNull(batch2);
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+
+ //Cleanup
+ boolean recDelResult = testHelper.deleteRecipient(recipientAlpha);
+ assertTrue(recDelResult);
+
+ boolean batchDelResult = client.batch.delete(batch.getId());
+ assertTrue(batchDelResult);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/com/trolley/sdk/integration/InvoiceTests.java b/src/test/java/com/trolley/sdk/integration/InvoiceTests.java
new file mode 100644
index 0000000..500a7b5
--- /dev/null
+++ b/src/test/java/com/trolley/sdk/integration/InvoiceTests.java
@@ -0,0 +1,283 @@
+
+package com.trolley.sdk.integration;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.trolley.trolley.Invoice;
+import com.trolley.trolley.InvoiceLine;
+import com.trolley.trolley.InvoicePayment;
+import com.trolley.trolley.Configuration;
+import com.trolley.trolley.Gateway;
+import com.trolley.trolley.Recipient;
+import com.trolley.trolley.types.Amount;
+import com.trolley.trolley.types.InvoicePaymentPart;
+import com.trolley.trolley.types.InvoicePayments;
+import com.trolley.trolley.types.Invoices;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+
+@PrepareForTest(Invoice.class)
+public class InvoiceTests {
+
+ private static Configuration config;
+ private static TestHelper testHelper;
+
+ @BeforeClass
+ public static void setupConfig() {
+ config = TestHelper.getConfig();
+ testHelper = new TestHelper();
+ }
+
+ @Test
+ public void testInvoices() throws Exception {
+ Gateway client = new Gateway(config);
+ final Recipient recipient = testHelper.createRecipient();
+
+ InvoiceLine invoiceLine = new InvoiceLine();
+ invoiceLine.setUnitAmount(new Amount("100", "USD"));
+
+ ArrayList invoiceLines = new ArrayList(){
+ {
+ add(invoiceLine);
+ }
+ };
+
+ // Create a new invoice
+ Invoice invoice = client.invoice.create(new Invoice(
+ recipient.getId(),
+ "invoice-123",
+ "test-invoice-create-java-sdk",
+ "ext-id-"+System.currentTimeMillis(),
+ null,
+ null,
+ null,
+ invoiceLines));
+ assertEquals(invoice.getRecipientId(), recipient.getId());
+
+ //Update an Invoice
+ final Invoice updatedInvoice = client.invoice.update(
+ invoice.getId(),
+ new Invoice(
+ null,
+ "invoice-123",
+ "test-invoice-update-java-sdk",
+ null,
+ null,
+ null,
+ null,
+ null
+ ));
+ assertEquals(updatedInvoice.getDescription(),"test-invoice-update-java-sdk");
+ assertEquals(updatedInvoice.getId(),invoice.getId());
+
+ //Fetch an Invoice
+ invoice = client.invoice.fetch(updatedInvoice.getId());
+ assertEquals(updatedInvoice.getId(),invoice.getId());
+
+ //Search for Invoices by recipientId - preparing params
+ ArrayList recipientIds = new ArrayList(){
+ {
+ add(recipient.getId());
+ }
+ };
+
+ // Search for Invoices by recipientId with pagination
+ Invoices invoices = client.invoice.search(Invoice.SearchBy.RECIPIENT_ID, recipientIds, null,1,2);
+ List invoiceList = invoices.getInvoices();
+ assertEquals(invoiceList.get(0).getRecipientId(),invoice.getRecipientId());
+ assertTrue(invoices.getMeta().getPages()>1);
+
+ //Cleanup - Delete Recipient
+ boolean recDelResult = testHelper.deleteRecipient(recipient);
+ assertTrue(recDelResult);
+
+ //Delete an Invoice
+ boolean invoiceDelResult = client.invoice.delete(invoice.getId());
+ assertTrue(invoiceDelResult);
+ }
+
+ @Test
+ public void testInvoiceLines() throws Exception {
+ Gateway client = new Gateway(config);
+
+ //Setup - create recipient
+ final Recipient recipient = testHelper.createRecipient();
+
+ //Setup - create Invoice
+ Invoice invoice = client.invoice.create(new Invoice(
+ recipient.getId(),
+ "invoice-123",
+ "test-invoice-create-java-sdk",
+ "ext-id-"+System.currentTimeMillis(),
+ null,
+ null,
+ null,
+ null));
+ assertEquals(invoice.getRecipientId(), recipient.getId());
+
+ //Add a new Invoice Line to the Invoice just created
+ Invoice invoiceWithLines = client.invoiceLine.create(invoice.getId(),
+ new InvoiceLine(
+ new Amount("100", "USD"),
+ InvoiceLine.InvoiceCategories.SERVICES,
+ "Invoice Line from Java SDK",
+ "ILine-ExtId-"+System.currentTimeMillis(),
+ true,
+ true,
+ null,
+ "2",
+ new Amount("10", "USD"),
+ new Amount("5", "USD"),
+ null,
+ null));
+ assertEquals(invoiceWithLines.getLines().get(0).getUnitAmount().getValue(), "100.00");
+
+ //Add multiple new Invoice Lines to the Invoice created
+ List invoiceLines = new ArrayList();
+ for (int i=1 ; i<=3; i++){
+ invoiceLines.add(new InvoiceLine(
+ new Amount("10"+i, "USD"),
+ InvoiceLine.InvoiceCategories.SERVICES,
+ "Invoice Line from Java SDK",
+ "ILine-ExtId-"+System.currentTimeMillis()+"-"+i,
+ true,
+ true,
+ null,
+ "2",
+ new Amount("1"+i, "USD"),
+ new Amount("5", "USD"),
+ null,
+ null));
+ }
+
+ invoiceWithLines = client.invoiceLine.create(invoice.getId(),
+ invoiceLines);
+ assertEquals(invoiceWithLines.getLines().size(),4);
+
+ //Update an invoice line
+ InvoiceLine lineToUpdate = invoiceWithLines.getLines().get(0);
+ lineToUpdate.setInvoiceLineId(lineToUpdate.getId());
+ lineToUpdate.setUnitAmount(new Amount("500","USD"));
+ invoiceWithLines = client.invoiceLine.update(invoice.getId(),
+ lineToUpdate);
+ assertEquals(invoiceWithLines.getLines().get(0).getUnitAmount().getValue(),"500.00");
+
+ //Update multiple invoice lines
+ ArrayList linesToUpdate = new ArrayList();
+ for (InvoiceLine invoiceLine : invoiceWithLines.getLines()) {
+ invoiceLine.setInvoiceLineId(invoiceLine.getId());
+ invoiceLine.setUnitAmount(new Amount("350","USD"));
+ linesToUpdate.add(invoiceLine);
+ }
+ invoiceWithLines = client.invoiceLine.update(invoice.getId(),
+ linesToUpdate);
+ assertEquals(invoiceWithLines.getLines().size(),4);
+ assertEquals(invoiceWithLines.getLines().get(3).getUnitAmount().getValue(),"350.00");
+
+ //Delete an invoice line
+ boolean delete = client.invoiceLine.delete(invoiceWithLines.getId(), invoiceWithLines.getLines().get(0).getId());
+ assertTrue(delete);
+
+ //Refreshing invoice object
+ invoiceWithLines = client.invoice.fetch(invoiceWithLines.getId());
+
+ //Delete multiple invoice lines
+ ArrayList lineIdsToDel = new ArrayList();
+ for (InvoiceLine line : invoiceWithLines.getLines()) {
+ lineIdsToDel.add(line.getId());
+ }
+ boolean deleteMultiple = client.invoiceLine.delete(invoiceWithLines.getId(), lineIdsToDel);
+ assertTrue(deleteMultiple);
+
+ // Assert that all lines were deleted
+ invoiceWithLines = client.invoice.fetch(invoiceWithLines.getId());
+ assertTrue(invoiceWithLines.getLines().size() == 0);
+
+ //Cleanup - delete invoice
+ boolean invoiceDelResult = client.invoice.delete(invoice.getId());
+ assertTrue(invoiceDelResult);
+
+ //Cleanup - delete recipient
+ boolean recDelResult = testHelper.deleteRecipient(recipient);
+ assertTrue(recDelResult);
+ }
+
+ @Test
+ public void testInvoicePayments() throws Exception {
+ Gateway client = new Gateway(config);
+ //Setup - Recipient
+ final Recipient recipient = testHelper.createRecipient();
+
+ //Setup - Invoice Line
+ InvoiceLine invoiceLine = new InvoiceLine();
+ invoiceLine.setUnitAmount(new Amount("100", "USD"));
+
+ ArrayList invoiceLines = new ArrayList(){
+ {
+ add(invoiceLine);
+ }
+ };
+
+ //Setup - Invoice
+ Invoice invoice = client.invoice.create(new Invoice(
+ recipient.getId(),
+ "invoice-123",
+ "test-invoice-create-java-sdk",
+ "ext-id-"+System.currentTimeMillis(),
+ null,
+ null,
+ null,
+ invoiceLines));
+ assertEquals(invoice.getRecipientId(), recipient.getId());
+
+ //Create a new Invoice Payment
+ InvoicePaymentPart paymentPart = new InvoicePaymentPart();
+ paymentPart.setInvoiceId(invoice.getId());
+ paymentPart.setInvoiceLineId(invoice.getLines().get(0).getId());
+ paymentPart.setAmount(new Amount("50", "USD"));
+
+ InvoicePayment invoicePayment = client.invoicePayment.create(null, paymentPart);
+
+ assertTrue(invoicePayment.getInvoicePayments().size()>0);
+
+ // Update an invoice payment
+ paymentPart = new InvoicePaymentPart();
+ paymentPart.setInvoiceId(invoice.getId());
+ paymentPart.setInvoiceLineId(invoice.getLines().get(0).getId());
+ paymentPart.setPaymentId(invoicePayment.getPaymentId());
+ paymentPart.setAmount(new Amount("10","USD"));
+
+ boolean paymentUpdateResult = client.invoicePayment.update(paymentPart);
+ assertTrue(paymentUpdateResult);
+
+ //Search an invoice payment
+ List paymentIds = new ArrayList();
+ paymentIds.add(invoicePayment.getPaymentId());
+
+ List invoiceIds = new ArrayList();
+ invoiceIds.add(invoice.getId());
+ InvoicePayments invoicePayments = client.invoicePayment.search(null, invoiceIds);
+ assertTrue(invoicePayments.getMeta().getRecords()>0);
+
+ //Delete an Invoice Payment
+ boolean deleteResult = client.invoicePayment.delete(
+ invoicePayment.getInvoicePayments().get(0).getPaymentId(),
+ invoicePayment.getInvoicePayments().get(0).getInvoiceLineId());
+ assertTrue(deleteResult);
+
+ //Cleanup - Delete Recipient
+ boolean recDelResult = testHelper.deleteRecipient(recipient);
+ assertTrue(recDelResult);
+
+ //Delete an Invoice
+ boolean invoiceDelResult = client.invoice.delete(invoice.getId());
+ assertTrue(invoiceDelResult);
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/com/trolley/sdk/integration/RecipientTest.java b/src/test/java/com/trolley/sdk/integration/RecipientTest.java
new file mode 100644
index 0000000..add2edf
--- /dev/null
+++ b/src/test/java/com/trolley/sdk/integration/RecipientTest.java
@@ -0,0 +1,111 @@
+package com.trolley.sdk.integration;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+
+import com.trolley.trolley.Configuration;
+import com.trolley.trolley.Gateway;
+import com.trolley.trolley.Recipient;
+import com.trolley.trolley.RecipientAccount;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@PrepareForTest(Recipient.class)
+public class RecipientTest {
+
+ private static Configuration config;
+ private static TestHelper testHelper;
+
+ @BeforeClass
+ public static void setupConfig() {
+ config = TestHelper.getConfig();
+ testHelper = new TestHelper();
+ }
+
+ @Test
+ public void testCreateRecipient() throws Exception {
+ Recipient recipient = testHelper.createRecipient();
+ assertEquals(recipient.getFirstName(), "John");
+ assertEquals(recipient.getLastName(), "Smith");
+ assertNotNull(recipient.getId());
+
+ //Cleanup
+ boolean deleteResult = testHelper.deleteRecipient(recipient);
+ assertTrue(deleteResult);
+ }
+
+ @Test
+ public void testLifecycle() throws Exception {
+ Gateway client = new Gateway(config);
+
+ Recipient recipient = testHelper.createRecipient();
+ assertEquals(recipient.getFirstName(), "John");
+ assertEquals(recipient.getLastName(), "Smith");
+ assertNotNull(recipient.getId());
+
+ String body = "{\"firstName\": \"Bob\"}";
+ boolean response = client.recipient.update(recipient.getId(), body);
+ assertNotNull(response);
+
+ Recipient anotherRecipient = client.recipient.find(recipient.getId());
+ assertEquals(anotherRecipient.getFirstName(), "Bob");
+
+ response = client.recipient.delete(recipient.getId());
+ assertNotNull(response);
+
+ Recipient anotherNewRecipient = client.recipient.find(recipient.getId());
+ assertEquals("archived", anotherNewRecipient.getStatus());
+ }
+
+ @Test
+ public void testAccount() throws Exception {
+ Gateway client = new Gateway(config);
+
+ Recipient recipient = testHelper.createRecipient();
+ assertEquals(recipient.getFirstName(), "John");
+ assertEquals(recipient.getLastName(), "Smith");
+ assertNotNull(recipient.getId());
+
+ String body = "{\"type\": \"bank-transfer\", \"primary\": true, \"country\": \"DE\", \"currency\": \"EUR\", \"iban\": \"DE89 3704 0044 0532 0130 00\", \"accountHolderName\": \"Tom Jones\"}";
+ RecipientAccount recipientAccount = testHelper.createRecipientAccount(recipient, body);
+ assertEquals("Tom Jones", recipientAccount.getAccountHolderName());
+
+ body = "{\"type\": \"bank-transfer\", \"primary\": true, \"country\": \"DE\", \"currency\": \"EUR\", \"iban\": \"DE89 3704 0044 0532 0130 00\", \"accountHolderName\": \"Tom Jones2\"}";
+ RecipientAccount recipientAccount1 = testHelper.createRecipientAccount(recipient, body);
+ assertEquals("Tom Jones2", recipientAccount1.getAccountHolderName());
+
+ RecipientAccount recAccFindResult = client.recipientAccount.find(recipient.getId(), recipientAccount.getId());
+ assertEquals(recAccFindResult.getCountry(), recipientAccount.getCountry());
+
+ List recipientAccounts = client.recipientAccount.findAll(recipient.getId());
+ assertEquals(2, recipientAccounts.size());
+
+ boolean response = client.recipientAccount.delete(recipient.getId(), recipientAccount1.getId());
+ assertNotNull(response);
+
+ List recipientAccounts1 = client.recipientAccount.findAll(recipient.getId());
+ assertEquals(1, recipientAccounts1.size());
+
+ //Cleanup
+ boolean deleteResult = testHelper.deleteRecipient(recipient);
+ assertTrue(deleteResult);
+ }
+
+
+ @Test
+ public void testRecipientRouteMinimum() throws Exception {
+ Gateway client = new Gateway(config);
+ ArrayList recipients = (ArrayList)client.recipient.search(1,20,"");
+ //Making sure routeMinimum is not null before asserting it's value
+ assertNotNull(recipients.get(0).getRouteMinimum());
+ //Making sure routeMinium is set to a non-null value
+ assertTrue(Integer.parseInt(recipients.get(0).getRouteMinimum()) >= 0);
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/com/trolley/sdk/integration/TestHelper.java b/src/test/java/com/trolley/sdk/integration/TestHelper.java
new file mode 100644
index 0000000..f722093
--- /dev/null
+++ b/src/test/java/com/trolley/sdk/integration/TestHelper.java
@@ -0,0 +1,85 @@
+package com.trolley.sdk.integration;
+
+import java.util.UUID;
+
+import com.trolley.trolley.Configuration;
+import com.trolley.trolley.Gateway;
+import com.trolley.trolley.Recipient;
+import com.trolley.trolley.RecipientAccount;
+
+import io.github.cdimascio.dotenv.Dotenv;
+
+public class TestHelper {
+
+ public static Configuration getConfig(){
+ Dotenv dotenv = Dotenv.load();
+
+ return new Configuration(
+ dotenv.get("ACCESS_KEY"),
+ dotenv.get("SECRET_KEY"),
+ "production");
+
+ }
+
+ /**
+ * Creates a new Recipient for all test classes to use.
+ * @return Recipient the object representing the new Recipient created
+ * @throws Exception
+ */
+ public Recipient createRecipient() throws Exception {
+ Gateway client = new Gateway(getConfig());
+
+ UUID uuid = UUID.randomUUID();
+
+ String email = "\"create.recipient.java-sdk." + uuid.toString() + "@example.com\"";
+ String body = "{\"type\": \"individual\",\"firstName\": \"John\",\"lastName\": \"Smith\",\"email\":" + email
+ + ",\"address\":{\"street1\": \"123 Main St\",\"city\": \"San Francisco\",\"region\": \"CA\",\"postalCode\": \"94131\",\"country\": \"DE\",\"phone\" : \"18005551212\"}}";
+
+ Recipient recipient = client.recipient.create(body);
+
+ return recipient;
+ }
+
+ /**
+ * Creates a new RecipientAccount for a Recipient.
+ * @param Recipient recipient to take recipientId from
+ * @return RecipientAccount
+ * @throws Exception
+ */
+ public RecipientAccount createRecipientAccount(Recipient recipient) throws Exception {
+ Gateway client = new Gateway(getConfig());
+
+ String body = "{\"type\": \"bank-transfer\", \"primary\": true, \"country\": \"DE\", \"currency\": \"EUR\", \"iban\": \"DE89 3704 0044 0532 0130 00\", \"accountHolderName\": \"John Smith\"}";
+
+ RecipientAccount recipientAcount = client.recipientAccount.create(recipient.getId(), body);
+
+ return recipientAcount;
+ }
+
+ /**
+ * Create a RecipientAccount with the provided body
+ * @param recipient
+ * @param body
+ * @return
+ * @throws Exception
+ */
+ public RecipientAccount createRecipientAccount(Recipient recipient, String body) throws Exception {
+ Gateway client = new Gateway(getConfig());
+
+ RecipientAccount recipientAcount = client.recipientAccount.create(recipient.getId(), body);
+
+ return recipientAcount;
+ }
+
+ /**
+ * Deletes a recipient
+ * @param recipient Recipient object of the recipient which needs to be deleted
+ * @return boolean indicating whether the delete operation was successful
+ * @throws Exception
+ */
+ public boolean deleteRecipient(Recipient recipient) throws Exception {
+ Gateway client = new Gateway(getConfig());
+
+ return client.recipient.delete(recipient.getId());
+ }
+}