Skip to content

Commit

Permalink
Merge pull request #101 from mwarzybok-sumoheavy/feature/SP-753
Browse files Browse the repository at this point in the history
SP-753 Code Examples: Node.js
  • Loading branch information
bobbrodie authored Jan 12, 2024
2 parents e6a8dda + a7d7ad6 commit f2dd54b
Show file tree
Hide file tree
Showing 16 changed files with 408 additions and 3 deletions.
11 changes: 11 additions & 0 deletions examples/ClientProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {Client} from "../src";

export class ClientProvider {
static create(): Client {
return Client.createClientByConfig('someConfigFile');
}

static createPos(): Client {
return Client.createPosClient('somePosToken');
}
}
22 changes: 22 additions & 0 deletions examples/General/UseLogger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {LoggerProvider} from "../../src/Logger/LoggerProvider";
import {BitPayLogger} from "../../src/Logger/BitPayLogger";

class UseLogger {
public execute(): void {
const logger: BitPayLogger = {
logError(message: string): void {
console.log(message);
},

logRequest(method: string, endpoint: string, json: string | null): void {
console.log(method + ' ' + endpoint + ' ' + json)
},

logResponse(method: string, endpoint: string, json: string): void {
console.log(method + ' ' + endpoint + ' ' + json)
}
}

LoggerProvider.setLogger(logger);
}
}
39 changes: 39 additions & 0 deletions examples/Merchant/BillRequests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {ClientProvider} from "../ClientProvider";
import {Bill} from "../../src/Model";
import {Item} from "../../src/Model/Bill/Item";

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

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

public getBill(): void {
const client = ClientProvider.create();

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

const bills = client.getBills('draft');
}

public updateBill(): void {
const client = ClientProvider.create();

const item = new Item()
item.price = 12.34;
item.quantity = 2;
item.description = 'someDescription';

const bill = new Bill('someNumber', "USD", "[email protected]", []);

client.updateBill(bill, bill.id)
}

public deliverBillViaEmail(): void {
const client = ClientProvider.create();

client.deliverBill('someBillId', 'myBillToken');
}
}
67 changes: 67 additions & 0 deletions examples/Merchant/InvoiceRequests.php.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {Invoice} from "../../src/Model";
import {Buyer} from "../../src/Model/Invoice/Buyer";
import {ClientProvider} from "../ClientProvider";

class InvoiceRequests {
public createInvoice(): void {
const invoice = new Invoice(10.0, 'USD');
invoice.notificationEmail = '[email protected]';
invoice.notificationURL = 'https://some-url.com';

const buyer = new Buyer();
buyer.name = "Test";
buyer.email = "[email protected]";
buyer.address1 = "168 General Grove";
buyer.country = "AD";
buyer.locality = "Port Horizon";
buyer.notify = true;
buyer.phone = "+990123456789";
buyer.postalCode = "KY7 1TH";
buyer.region = "New Port";

invoice.buyer = buyer

const client = ClientProvider.create();

const createdInvoice = client.createInvoice(invoice);
}

public getInvoice(): void {
const client = ClientProvider.create();

const invoice = client.getInvoice('myInvoiceId');
const invoiceByGuid = client.getInvoiceByGuid('invoiceGuid'); // we can add a GUID during the invoice creation

const params = {
dateStart: '2023-04-14',
dateEnd: '2023-04-17',
status: null,
orderId: null,
limit: null,
offset: null
};
const invoices = client.getInvoices(params)
}

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

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

public cancelInvoice(): void {
const client = ClientProvider.create();

client.cancelInvoice('someInvoiceId');

client.cancelInvoiceByGuid('someGuid');
}

public requestInvoiceWebhookToBeResent(): void {
const client = ClientProvider.create();

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

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

const ledgers = client.getLedgers()
}

public getLedgerEntries(): void {
const client = ClientProvider.create();

const oneMonthAgo = new Date();
oneMonthAgo.setDate(oneMonthAgo.getDate() - 30);

const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);

const ledgerEntries = client.getLedgerEntries('USD', oneMonthAgo, tomorrow)
}
}
39 changes: 39 additions & 0 deletions examples/Merchant/RefundRequests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {ClientProvider} from "../ClientProvider";
import {Refund} from "../../src/Model/Invoice/Refund";

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

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

const result = client.createRefund(refund);
}

public updateRefund(): void {
const client = ClientProvider.create();

const updateRefund = client.updateRefund('myRefundId','created');
const updatedRefundByGuid = client.updateRefundByGuid('myRefundId','created');
}

public getRefund(): void {
const client = ClientProvider.create();

const refund = client.getRefund('someRefundId');
const refundByGuid = client.getRefundByGuid('someGuid');
}

public cancelRefund(): void {
const client = ClientProvider.create();

const cancelRefund = client.cancelRefund('myRefundId');
const cancelRefundByGuid = client.cancelRefundByGuid('someGuid');
}

public requestRefundNotificationToBeResent(): void {
const client = ClientProvider.create();

const result = client.sendRefundNotification('someRefundId');
}
}
27 changes: 27 additions & 0 deletions examples/Merchant/SettlementRequests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {ClientProvider} from "../ClientProvider";
import {Settlement} from "../../src/Model/Settlement/Settlement";

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

const settlement = client.getSettlement('someSettlementId');

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

public fetchReconciliationReport(): void {
const client = ClientProvider.create();

const settlement = new Settlement();

const result = client.getSettlementReconciliationReport('settlementId', 'settlementToken');
}
}
43 changes: 43 additions & 0 deletions examples/Payout/PayoutRequests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {ClientProvider} from "../ClientProvider";
import {Payout} from "../../src/Model";
import {PayoutStatus} from "../../src";

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

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

const createdPayout = client.submitPayout(payout);

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

public getPayouts(): void {
const client = ClientProvider.create();

const payout = client.getPayout('myPayoutId')

const payouts = client.getPayouts({ status: PayoutStatus.New });
}

public cancelPayout(): void {
const client = ClientProvider.create();

const result = client.cancelPayout('somePayoutId');

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

public requestPayoutWebhookToBeResent(): void {
const client = ClientProvider.create();

const result = client.requestPayoutNotification('somePayoutId');
}
}
37 changes: 37 additions & 0 deletions examples/Payout/RecipientRequests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {ClientProvider} from "../ClientProvider";
import {PayoutRecipient, PayoutRecipients} from "../../src/Model";

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

const payoutRecipient = new PayoutRecipient('[email protected]', 'someLabel', 'https://notification.com');

const payoutRecipients = new PayoutRecipients([payoutRecipient]);

const recipients = client.submitPayoutRecipients(payoutRecipients);
}

public getRecipient(): void {
const client = ClientProvider.create();

const recipient = client.getPayoutRecipient('someRecipientId');

const recipients = client.getPayoutRecipients('invited');
}

public updateRecipient(): void {
const client = ClientProvider.create();

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

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

public removeRecipient(): void {
const client = ClientProvider.create();

const result = client.deletePayoutRecipient('somePayoutRecipientId');
}
}
24 changes: 24 additions & 0 deletions examples/Pos/BillRequests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {ClientProvider} from "../ClientProvider";
import {Bill} from "../../src/Model";
import {Item} from "../../src/Model/Bill/Item";

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

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

public getBill(): void {
const client = ClientProvider.createPos();

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

public deliverBillViaEmail(): void {
const client = ClientProvider.createPos();

client.deliverBill('someBillId', 'myBillToken');
}
}
34 changes: 34 additions & 0 deletions examples/Pos/InvoiceRequests.php.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {Invoice} from "../../src/Model";
import {Buyer} from "../../src/Model/Invoice/Buyer";
import {ClientProvider} from "../ClientProvider";

class InvoiceRequests {
public createInvoice(): void {
const invoice = new Invoice(10.0, 'USD');
invoice.notificationEmail = '[email protected]';
invoice.notificationURL = 'https://some-url.com';

const buyer = new Buyer();
buyer.name = "Test";
buyer.email = "[email protected]";
buyer.address1 = "168 General Grove";
buyer.country = "AD";
buyer.locality = "Port Horizon";
buyer.notify = true;
buyer.phone = "+990123456789";
buyer.postalCode = "KY7 1TH";
buyer.region = "New Port";

invoice.buyer = buyer

const client = ClientProvider.createPos();

const createdInvoice = client.createInvoice(invoice);
}

public getInvoice(): void {
const client = ClientProvider.createPos();

const invoice = client.getInvoice('myInvoiceId');
}
}
11 changes: 11 additions & 0 deletions examples/Public/RateRequests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {ClientProvider} from "../ClientProvider";

class RateRequests {
public getRate(): void {
const client = ClientProvider.create();

const rate = client.getRate('BTC', 'USD');

const rates = client.getRates('BCH')
}
}
Loading

0 comments on commit f2dd54b

Please sign in to comment.