Skip to content

Commit

Permalink
Merge pull request #107 from bobbrodie/SP-794
Browse files Browse the repository at this point in the history
SP-794 Update examples to use async
  • Loading branch information
bobbrodie authored May 24, 2024
2 parents f7382aa + aabba7d commit c8241d8
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 81 deletions.
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
22 changes: 13 additions & 9 deletions examples/Merchant/BillRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ import {Bill} from "../../src/Model";
import {Item} from "../../src/Model/Bill/Item";

class BillRequests {
public createBill(): void {
public async createBill(): Promise<void> {
const client = ClientProvider.create();

const bill = new Bill('someNumber', "USD", "some@email.com", [])
client.createBill(bill);
await client.createBill(bill);
}

public getBill(): void {
public async getBill(): Promise<void> {
const client = ClientProvider.create();

const bill = client.getBill('someBillId');
// Get one bill
const bill = await client.getBill('someBillId');

const bills = client.getBills('draft');
// Get bills by status
const bills = await client.getBills('draft');
}

public updateBill(): void {
public async updateBill(): Promise<void> {
const client = ClientProvider.create();

const item = new Item()
Expand All @@ -28,12 +30,14 @@ class BillRequests {

const bill = new Bill('someNumber', "USD", "some@email.com", []);

client.updateBill(bill, bill.id)
if (bill.id) {
await client.updateBill(bill, bill.id)
}
}

public deliverBillViaEmail(): void {
public async deliverBillViaEmail(): Promise<void> {
const client = ClientProvider.create();

client.deliverBill('someBillId', 'myBillToken');
await client.deliverBill('someBillId', 'myBillToken');
}
}
27 changes: 14 additions & 13 deletions examples/Merchant/InvoiceRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Buyer} from "../../src/Model/Invoice/Buyer";
import {ClientProvider} from "../ClientProvider";

class InvoiceRequests {
public createInvoice(): void {
public async createInvoice(): Promise<void> {
const invoice = new Invoice(10.0, 'USD');
invoice.notificationEmail = 'some@email.com';
invoice.notificationURL = 'https://some-url.com';
Expand All @@ -23,10 +23,10 @@ class InvoiceRequests {

const client = ClientProvider.create();

const createdInvoice = client.createInvoice(invoice);
const createdInvoice = await client.createInvoice(invoice);
}

public getInvoice(): void {
public async getInvoice(): Promise<void> {
const client = ClientProvider.create();

const invoice = client.getInvoice('myInvoiceId');
Expand All @@ -40,28 +40,29 @@ class InvoiceRequests {
limit: null,
offset: null
};
const invoices = client.getInvoices(params)
const invoices = await client.getInvoices(params)
}

public updateInvoice(): void {
public async updateInvoice(): Promise<void> {
const client = ClientProvider.create();
const params = [];
params['buyerSms'] = '123321312';
const params = {
buyerSms: '123321312'
};

const updatedInvoice = client.updateInvoice('someId', params)
const updatedInvoice = await client.updateInvoice('someId', params)
}

public cancelInvoice(): void {
public async cancelInvoice(): Promise<void> {
const client = ClientProvider.create();

client.cancelInvoice('someInvoiceId');
await client.cancelInvoice('someInvoiceId');

client.cancelInvoiceByGuid('someGuid');
await client.cancelInvoiceByGuid('someGuid');
}

public requestInvoiceWebhookToBeResent(): void {
public async requestInvoiceWebhookToBeResent(): Promise<void> {
const client = ClientProvider.create();

client.deliverBill('someBillId', 'myBillToken');
await client.deliverBill('someBillId', 'myBillToken');
}
}
8 changes: 4 additions & 4 deletions examples/Merchant/LedgerRequests.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {ClientProvider} from "../ClientProvider";

class LedgerRequests {
public getLedgers(): void {
public async getLedgers(): Promise<void> {
const client = ClientProvider.create();

const ledgers = client.getLedgers()
const ledgers = await client.getLedgers()
}

public getLedgerEntries(): void {
public async getLedgerEntries(): Promise<void> {
const client = ClientProvider.create();

const oneMonthAgo = new Date();
Expand All @@ -16,6 +16,6 @@ class LedgerRequests {
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);

const ledgerEntries = client.getLedgerEntries('USD', oneMonthAgo, tomorrow)
const ledgerEntries = await client.getLedgerEntries('USD', oneMonthAgo, tomorrow)
}
}
35 changes: 22 additions & 13 deletions examples/Merchant/RefundRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,47 @@ import {ClientProvider} from "../ClientProvider";
import {Refund} from "../../src/Model/Invoice/Refund";

class RefundRequests {
public createRefund(): void {
public async createRefund(): Promise<void> {
const client = ClientProvider.create();

const refund = new Refund(12, "someInvoiceId", "someToken");

const result = client.createRefund(refund);
const result = await client.createRefund(refund);
}

public updateRefund(): void {
public async updateRefund(): Promise<void> {
const client = ClientProvider.create();

const updateRefund = client.updateRefund('myRefundId','created');
const updatedRefundByGuid = client.updateRefundByGuid('myRefundId','created');
// Update a refund by ID
const updateRefund = await client.updateRefund('myRefundId','created');

// Update a refund by GUID
const updatedRefundByGuid = await client.updateRefundByGuid('myRefundId','created');
}

public getRefund(): void {
public async getRefund(): Promise<void> {
const client = ClientProvider.create();

const refund = client.getRefund('someRefundId');
const refundByGuid = client.getRefundByGuid('someGuid');
// Get a refund by ID
const refund = await client.getRefund('someRefundId');

// Get a refund by GUID
const refundByGuid = await client.getRefundByGuid('someGuid');
}

public cancelRefund(): void {
public async cancelRefund(): Promise<void> {
const client = ClientProvider.create();

const cancelRefund = client.cancelRefund('myRefundId');
const cancelRefundByGuid = client.cancelRefundByGuid('someGuid');
// Cancel a refund by ID
const cancelRefund = await client.cancelRefund('myRefundId');

// Cancel a refund by GUID
const cancelRefundByGuid = await client.cancelRefundByGuid('someGuid');
}

public requestRefundNotificationToBeResent(): void {
public async requestRefundNotificationToBeResent(): Promise<void> {
const client = ClientProvider.create();

const result = client.sendRefundNotification('someRefundId');
const result = await client.sendRefundNotification('someRefundId');
}
}
12 changes: 7 additions & 5 deletions examples/Merchant/SettlementRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@ import {ClientProvider} from "../ClientProvider";
import {Settlement} from "../../src/Model/Settlement/Settlement";

class SettlementRequests {
public getSettlement(): void {
public async getSettlement(): Promise<void> {
const client = ClientProvider.create();

const settlement = client.getSettlement('someSettlementId');
// Get one settlement
const settlement = await client.getSettlement('someSettlementId');

// Get settlements by filter
const params = {
startDate: '2021-05-10',
endDate: '2021-05-12',
status: 'processing',
limit: 100,
offset: 0
};
const settlements = client.getSettlements(params)
const settlements = await client.getSettlements(params)
}

public fetchReconciliationReport(): void {
public async fetchReconciliationReport(): Promise<void> {
const client = ClientProvider.create();

const settlement = new Settlement();

const result = client.getSettlementReconciliationReport('settlementId', 'settlementToken');
const result = await client.getSettlementReconciliationReport('settlementId', 'settlementToken');
}
}
27 changes: 16 additions & 11 deletions examples/Payout/PayoutRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,46 @@ import {Payout} from "../../src/Model";
import {PayoutStatus} from "../../src";

class PayoutRequests {
public createPayout(): void {
public async createPayout(): Promise<void> {
const client = ClientProvider.create();

const payout = new Payout(12.34, 'USD', 'USD');
payout.notificationEmail = 'myEmail@email.com';
payout.notificationURL = 'https://my-url.com';

const createdPayout = client.submitPayout(payout);
// Submit one payout
const createdPayout = await client.submitPayout(payout);

const payouts = client.submitPayouts([
// Submit multiple payouts
const payouts = await client.submitPayouts([
new Payout(12.34, 'USD', 'USD'),
new Payout(56.14, 'USD', 'USD'),
])
}

public getPayouts(): void {
public async getPayouts(): Promise<void> {
const client = ClientProvider.create();

const payout = client.getPayout('myPayoutId')
// Get one payout
const payout = await client.getPayout('myPayoutId')

const payouts = client.getPayouts({ status: PayoutStatus.New });
// Get payouts by filter
const payouts = await client.getPayouts({ status: PayoutStatus.New });
}

public cancelPayout(): void {
public async cancelPayout(): Promise<void> {
const client = ClientProvider.create();

const result = client.cancelPayout('somePayoutId');
// Cancel one payout
const result = await client.cancelPayout('somePayoutId');

// const payoutGroupId = payout.groupId;
// Cancel payout group
const cancelledPayouts = client.cancelPayouts('payoutGroupId');
}

public requestPayoutWebhookToBeResent(): void {
public async requestPayoutWebhookToBeResent(): Promise<void> {
const client = ClientProvider.create();

const result = client.requestPayoutNotification('somePayoutId');
const result = await client.requestPayoutNotification('somePayoutId');
}
}
20 changes: 11 additions & 9 deletions examples/Payout/RecipientRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,38 @@ import {ClientProvider} from "../ClientProvider";
import {PayoutRecipient, PayoutRecipients} from "../../src/Model";

class RecipientRequests {
public inviteRecipients(): void {
public async inviteRecipients(): Promise<void> {
const client = ClientProvider.create();

const payoutRecipient = new PayoutRecipient('some@email.com', 'someLabel', 'https://notification.com');

const payoutRecipients = new PayoutRecipients([payoutRecipient]);

const recipients = client.submitPayoutRecipients(payoutRecipients);
const recipients = await client.submitPayoutRecipients(payoutRecipients);
}

public getRecipient(): void {
public async getRecipient(): Promise<void> {
const client = ClientProvider.create();

const recipient = client.getPayoutRecipient('someRecipientId');
// Get one payout recipient
const recipient = await client.getPayoutRecipient('someRecipientId');

const recipients = client.getPayoutRecipients('invited');
// Get payout recipients by filter
const recipients = await client.getPayoutRecipients('invited');
}

public updateRecipient(): void {
public async updateRecipient(): Promise<void> {
const client = ClientProvider.create();

const payoutRecipient = new PayoutRecipient('some@email.com', 'someLabel', 'https://notification.com');
payoutRecipient.label = 'some label';

const recipient = client.updatePayoutRecipient(payoutRecipient.id, payoutRecipient);
const recipient = await client.updatePayoutRecipient(payoutRecipient.id, payoutRecipient);
}

public removeRecipient(): void {
public async removeRecipient(): Promise<void> {
const client = ClientProvider.create();

const result = client.deletePayoutRecipient('somePayoutRecipientId');
const result = await client.deletePayoutRecipient('somePayoutRecipientId');
}
}
12 changes: 6 additions & 6 deletions examples/Pos/BillRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import {Bill} from "../../src/Model";
import {Item} from "../../src/Model/Bill/Item";

class BillRequests {
public createBill(): void {
public async createBill(): Promise<void> {
const client = ClientProvider.createPos();

const bill = new Bill('someNumber', "USD", "some@email.com", [])
client.createBill(bill);
await client.createBill(bill);
}

public getBill(): void {
public async getBill(): Promise<void> {
const client = ClientProvider.createPos();

const bill = client.getBill('someBillId');
const bill = await client.getBill('someBillId');
}

public deliverBillViaEmail(): void {
public async deliverBillViaEmail(): Promise<void> {
const client = ClientProvider.createPos();

client.deliverBill('someBillId', 'myBillToken');
await client.deliverBill('someBillId', 'myBillToken');
}
}
8 changes: 4 additions & 4 deletions examples/Pos/InvoiceRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Buyer} from "../../src/Model/Invoice/Buyer";
import {ClientProvider} from "../ClientProvider";

class InvoiceRequests {
public createInvoice(): void {
public async createInvoice(): Promise<void> {
const invoice = new Invoice(10.0, 'USD');
invoice.notificationEmail = 'some@email.com';
invoice.notificationURL = 'https://some-url.com';
Expand All @@ -23,12 +23,12 @@ class InvoiceRequests {

const client = ClientProvider.createPos();

const createdInvoice = client.createInvoice(invoice);
const createdInvoice = await client.createInvoice(invoice);
}

public getInvoice(): void {
public async getInvoice(): Promise<void> {
const client = ClientProvider.createPos();

const invoice = client.getInvoice('myInvoiceId');
const invoice = await client.getInvoice('myInvoiceId');
}
}
Loading

0 comments on commit c8241d8

Please sign in to comment.