-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from mwarzybok-sumoheavy/feature/SP-753
SP-753 Code Examples: Node.js
- Loading branch information
Showing
16 changed files
with
408 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", "some@email.com", []) | ||
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", "some@email.com", []); | ||
|
||
client.updateBill(bill, bill.id) | ||
} | ||
|
||
public deliverBillViaEmail(): void { | ||
const client = ClientProvider.create(); | ||
|
||
client.deliverBill('someBillId', 'myBillToken'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = 'some@email.com'; | ||
invoice.notificationURL = 'https://some-url.com'; | ||
|
||
const buyer = new Buyer(); | ||
buyer.name = "Test"; | ||
buyer.email = "test@email.com"; | ||
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = 'myEmail@email.com'; | ||
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('some@email.com', '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('some@email.com', '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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", "some@email.com", []) | ||
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = 'some@email.com'; | ||
invoice.notificationURL = 'https://some-url.com'; | ||
|
||
const buyer = new Buyer(); | ||
buyer.name = "Test"; | ||
buyer.email = "test@email.com"; | ||
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
} | ||
} |
Oops, something went wrong.