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
3 changes: 3 additions & 0 deletions lib/Gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Client } from "./Client";
import { InvoiceLineGateway } from "./InvoiceLineGateway";
import { InvoicePaymentGateway } from "./InvoicePaymentGateway";
import { VerificationGateway } from "./VerificationGateway";
import { PartnerGateway } from "./PartnerGateway";

export class Gateway {
config: Configuration;
Expand All @@ -25,6 +26,7 @@ export class Gateway {
invoicePayment: InvoicePaymentGateway;
verification: VerificationGateway;
trust: VerificationGateway;
partner: PartnerGateway;

/**
* This should be called by the connect() method to setup a client gateway
Expand All @@ -45,5 +47,6 @@ export class Gateway {
this.invoicePayment = new InvoicePaymentGateway(this);
this.verification = new VerificationGateway(this);
this.trust = this.verification;
this.partner = new PartnerGateway(this);
}
}
78 changes: 78 additions & 0 deletions lib/PartnerGateway.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { Configuration } from "./Configuration";
import { Gateway } from "./Gateway";

export class PartnerGateway {
gateway: Gateway;
config: Configuration;

constructor(gateway: Gateway) {
this.gateway = gateway;
this.config = gateway.config;
}

async getFees(currency?: string) {
const endpoint = currency
? `/v1/fees?currency=${encodeURIComponent(currency)}`
: "/v1/fees";
return this.gateway.client.get<any>(endpoint);
}

async updateFees(body: { [key: string]: any }) {
return this.gateway.client.patch<any>("/v1/fees", body);
}

async listPayoutMethods() {
return this.gateway.client.get<any>("/v1/payout-methods");
}

async getPayoutMethod(payoutMethod: string) {
return this.gateway.client.get<any>(`/v1/payout-methods/${encodeURIComponent(payoutMethod)}`);
}

async updatePayoutMethod(payoutMethod: string, body: { [key: string]: any }) {
return this.gateway.client.patch<any>(
`/v1/payout-methods/${encodeURIComponent(payoutMethod)}`,
body,
);
}

async getProcessingSettings() {
return this.gateway.client.get<any>("/v1/processing-settings");
}

async updateProcessingSettings(body: { [key: string]: any }) {
return this.gateway.client.patch<any>("/v1/processing-settings", body);
}

async getWhiteLabelDnsRecords() {
return this.gateway.client.get<any>("/v1/white-label/dns-records");
}

async verifyWhiteLabelDnsRecords() {
return this.gateway.client.post<any>("/v1/white-label/dns-records/verify", {});
}

async deleteWhiteLabelEmail() {
return this.gateway.client.remove<any>("/v1/white-label/email");
}

async updateWhiteLabelIcon(body: { [key: string]: any }) {
return this.gateway.client.patch<any>("/v1/white-label/icon", body);
}

async getWhiteLabelSettings() {
return this.gateway.client.get<any>("/v1/white-label");
}

async updateWhiteLabelSettings(body: { [key: string]: any }) {
return this.gateway.client.patch<any>("/v1/white-label", body);
}

async getWidgetConfiguration() {
return this.gateway.client.get<any>("/v1/iframe/config");
}

async updateWidgetConfiguration(body: { [key: string]: any } = {}) {
return this.gateway.client.post<any>("/v1/iframe/config", body);
}
}
60 changes: 60 additions & 0 deletions test/unit/partnerSpec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Configuration, Gateway } from "../../lib";

import * as assert from "assert";
import * as sinon from "sinon";

describe("Partner", () => {
let sandbox: sinon.SinonSandbox;
let gateway: Gateway;

beforeEach(() => {
sandbox = sinon.createSandbox();
gateway = new Gateway(new Configuration({ key: "access-code", secret: "secret-code" }));
});

afterEach(() => {
sandbox.restore();
});

it("calls each partner endpoint through a dedicated method", async () => {
const get = sandbox.stub(gateway.client, "get").resolves({ ok: true });
const patch = sandbox.stub(gateway.client, "patch").resolves({ ok: true });
const post = sandbox.stub(gateway.client, "post").resolves({ ok: true });
const remove = sandbox.stub(gateway.client, "remove").resolves({ ok: true });
const body = { enabled: true };

await gateway.partner.getFees();
await gateway.partner.getFees("USD");
await gateway.partner.updateFees(body);
await gateway.partner.listPayoutMethods();
await gateway.partner.getPayoutMethod("bank-transfer");
await gateway.partner.updatePayoutMethod("bank-transfer", body);
await gateway.partner.getProcessingSettings();
await gateway.partner.updateProcessingSettings(body);
await gateway.partner.getWhiteLabelDnsRecords();
await gateway.partner.verifyWhiteLabelDnsRecords();
await gateway.partner.deleteWhiteLabelEmail();
await gateway.partner.updateWhiteLabelIcon(body);
await gateway.partner.getWhiteLabelSettings();
await gateway.partner.updateWhiteLabelSettings(body);
await gateway.partner.getWidgetConfiguration();
await gateway.partner.updateWidgetConfiguration(body);

assert(get.calledWithExactly("/v1/fees"));
assert(get.calledWithExactly("/v1/fees?currency=USD"));
assert(get.calledWithExactly("/v1/payout-methods"));
assert(get.calledWithExactly("/v1/payout-methods/bank-transfer"));
assert(get.calledWithExactly("/v1/processing-settings"));
assert(get.calledWithExactly("/v1/white-label/dns-records"));
assert(get.calledWithExactly("/v1/white-label"));
assert(get.calledWithExactly("/v1/iframe/config"));
assert(patch.calledWithExactly("/v1/fees", body));
assert(patch.calledWithExactly("/v1/payout-methods/bank-transfer", body));
assert(patch.calledWithExactly("/v1/processing-settings", body));
assert(patch.calledWithExactly("/v1/white-label/icon", body));
assert(patch.calledWithExactly("/v1/white-label", body));
assert(post.calledWithExactly("/v1/white-label/dns-records/verify", {}));
assert(post.calledWithExactly("/v1/iframe/config", body));
assert(remove.calledWithExactly("/v1/white-label/email"));
});
});