Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/com/trolley/Gateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Gateway
public InvoicePaymentGateway invoicePayment;
public VerificationGateway verification;
public VerificationGateway trust;
public PartnerGateway partner;

public Gateway(final Configuration config) {
this.config = config;
Expand All @@ -30,5 +31,6 @@ public Gateway(final Configuration config) {
this.invoicePayment = new InvoicePaymentGateway(config);
this.verification = new VerificationGateway(config);
this.trust = this.verification;
this.partner = new PartnerGateway(config);
}
}
97 changes: 97 additions & 0 deletions src/main/java/com/trolley/PartnerGateway.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.trolley;

import java.net.URLEncoder;

import com.fasterxml.jackson.databind.ObjectMapper;

public class PartnerGateway {
private final Client client;
private final ObjectMapper objectMapper;

public PartnerGateway(final Configuration config) {
this.client = new Client(config);
this.objectMapper = new ObjectMapper();
}

public String getFees() throws Exception {
return this.client.get("/v1/fees");
}

public String getFees(final String currency) throws Exception {
if (currency == null || currency.isEmpty()) {
return getFees();
}
return this.client.get("/v1/fees?currency=" + pathSegment(currency));
}

public String updateFees(final Object body) throws Exception {
return this.client.patch("/v1/fees", json(body));
}

public String listPayoutMethods() throws Exception {
return this.client.get("/v1/payout-methods");
}

public String getPayoutMethod(final String payoutMethod) throws Exception {
return this.client.get("/v1/payout-methods/" + pathSegment(payoutMethod));
}

public String updatePayoutMethod(final String payoutMethod, final Object body) throws Exception {
return this.client.patch("/v1/payout-methods/" + pathSegment(payoutMethod), json(body));
}

public String getProcessingSettings() throws Exception {
return this.client.get("/v1/processing-settings");
}

public String updateProcessingSettings(final Object body) throws Exception {
return this.client.patch("/v1/processing-settings", json(body));
}

public String getWhiteLabelDnsRecords() throws Exception {
return this.client.get("/v1/white-label/dns-records");
}

public String verifyWhiteLabelDnsRecords() throws Exception {
return this.client.post("/v1/white-label/dns-records/verify", "{}");
}

public String deleteWhiteLabelEmail() throws Exception {
return this.client.delete("/v1/white-label/email");
}

public String updateWhiteLabelIcon(final Object body) throws Exception {
return this.client.patch("/v1/white-label/icon", json(body));
}

public String getWhiteLabelSettings() throws Exception {
return this.client.get("/v1/white-label");
}

public String updateWhiteLabelSettings(final Object body) throws Exception {
return this.client.patch("/v1/white-label", json(body));
}

public String getWidgetConfiguration() throws Exception {
return this.client.get("/v1/iframe/config");
}

public String updateWidgetConfiguration() throws Exception {
return updateWidgetConfiguration(new Object());
}

public String updateWidgetConfiguration(final Object body) throws Exception {
return this.client.post("/v1/iframe/config", json(body));
}

private String json(final Object body) throws Exception {
if (body instanceof String) {
return (String) body;
}
return this.objectMapper.writeValueAsString(body);
}

private String pathSegment(final String value) throws Exception {
return URLEncoder.encode(value, "UTF-8").replace("+", "%20");
}
}