diff --git a/examples/ClientProvider.ts b/examples/ClientProvider.ts new file mode 100644 index 0000000..2f6a609 --- /dev/null +++ b/examples/ClientProvider.ts @@ -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'); + } +} \ No newline at end of file diff --git a/examples/General/UseLogger.ts b/examples/General/UseLogger.ts new file mode 100644 index 0000000..75f28bc --- /dev/null +++ b/examples/General/UseLogger.ts @@ -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); + } +} \ No newline at end of file diff --git a/examples/Merchant/BillRequests.ts b/examples/Merchant/BillRequests.ts new file mode 100644 index 0000000..2cc230b --- /dev/null +++ b/examples/Merchant/BillRequests.ts @@ -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'); + } +} \ No newline at end of file diff --git a/examples/Merchant/InvoiceRequests.php.ts b/examples/Merchant/InvoiceRequests.php.ts new file mode 100644 index 0000000..fd25756 --- /dev/null +++ b/examples/Merchant/InvoiceRequests.php.ts @@ -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'); + } +} \ No newline at end of file diff --git a/examples/Merchant/LedgerRequests.ts b/examples/Merchant/LedgerRequests.ts new file mode 100644 index 0000000..64afc65 --- /dev/null +++ b/examples/Merchant/LedgerRequests.ts @@ -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) + } +} \ No newline at end of file diff --git a/examples/Merchant/RefundRequests.ts b/examples/Merchant/RefundRequests.ts new file mode 100644 index 0000000..4860683 --- /dev/null +++ b/examples/Merchant/RefundRequests.ts @@ -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'); + } +} \ No newline at end of file diff --git a/examples/Merchant/SettlementRequests.ts b/examples/Merchant/SettlementRequests.ts new file mode 100644 index 0000000..50739b0 --- /dev/null +++ b/examples/Merchant/SettlementRequests.ts @@ -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'); + } +} \ No newline at end of file diff --git a/examples/Payout/PayoutRequests.ts b/examples/Payout/PayoutRequests.ts new file mode 100644 index 0000000..4ec9486 --- /dev/null +++ b/examples/Payout/PayoutRequests.ts @@ -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'); + } +} \ No newline at end of file diff --git a/examples/Payout/RecipientRequests.ts b/examples/Payout/RecipientRequests.ts new file mode 100644 index 0000000..4fc69c9 --- /dev/null +++ b/examples/Payout/RecipientRequests.ts @@ -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'); + } +} \ No newline at end of file diff --git a/examples/Pos/BillRequests.ts b/examples/Pos/BillRequests.ts new file mode 100644 index 0000000..b897ba8 --- /dev/null +++ b/examples/Pos/BillRequests.ts @@ -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'); + } +} \ No newline at end of file diff --git a/examples/Pos/InvoiceRequests.php.ts b/examples/Pos/InvoiceRequests.php.ts new file mode 100644 index 0000000..bdac1be --- /dev/null +++ b/examples/Pos/InvoiceRequests.php.ts @@ -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'); + } +} \ No newline at end of file diff --git a/examples/Public/RateRequests.ts b/examples/Public/RateRequests.ts new file mode 100644 index 0000000..95055eb --- /dev/null +++ b/examples/Public/RateRequests.ts @@ -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') + } +} \ No newline at end of file diff --git a/examples/Public/WalletRequests.ts b/examples/Public/WalletRequests.ts new file mode 100644 index 0000000..aa85d47 --- /dev/null +++ b/examples/Public/WalletRequests.ts @@ -0,0 +1,9 @@ +import {ClientProvider} from "../ClientProvider"; + +class WalletRequests { + public getSupportedWallets(): void { + const client = ClientProvider.create(); + + const supportedWallets = client.getSupportedWallets(); + } +} \ No newline at end of file diff --git a/package.json b/package.json index 2e97a65..83c5737 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,8 @@ "coverage": "npm run unit -- --coverage", "format": "npm run prettier -- --write", "format:ci": "npm run prettier -- --check", - "lint": "eslint . --ext .ts", - "lint:fix": "eslint . --ext .ts --fix", + "lint": "eslint . --ext .ts --ignore-pattern 'examples/**/*'", + "lint:fix": "eslint . --ext .ts --fix --ignore-pattern 'examples/**/*'", "prepare": "npm run build && husky install", "prettier": "prettier --config .prettierrc 'src/**/*.ts' 'test/**/*.spec.ts'", "test": "npm run format:ci && npm run lint && npm run coverage", diff --git a/src/Model/Currency/Currency.ts b/src/Model/Currency/Currency.ts index f5583a1..a37e2d2 100644 --- a/src/Model/Currency/Currency.ts +++ b/src/Model/Currency/Currency.ts @@ -4,6 +4,13 @@ export interface CurrencyInterface { symbol: string; precision: number; decimals: number; + plural: string; + alts: string; + minimum: number; + sanctioned: boolean; + displayCode?: string; + chain?: string; + maxSupply?: string; } export class Currency implements CurrencyInterface { @@ -12,4 +19,11 @@ export class Currency implements CurrencyInterface { symbol: string; precision: number; decimals: number; + plural: string; + alts: string; + minimum: number; + sanctioned: boolean; + displayCode?: string; + chain?: string; + maxSupply?: string; } diff --git a/src/Model/Currency/Currency.zod.ts b/src/Model/Currency/Currency.zod.ts index 7994bb8..27b46a1 100644 --- a/src/Model/Currency/Currency.zod.ts +++ b/src/Model/Currency/Currency.zod.ts @@ -5,5 +5,12 @@ export const currencyInterfaceSchema = z.object({ name: z.string(), symbol: z.string(), precision: z.number(), - decimals: z.number() + decimals: z.number(), + plural: z.string(), + alts: z.string(), + minimum: z.number(), + sanctioned: z.boolean(), + displayCode: z.string().optional(), + chain: z.string().optional(), + maxSupply: z.string().optional(), });