diff --git a/.husky/pre-commit b/.husky/pre-commit old mode 100644 new mode 100755 diff --git a/examples/Merchant/BillRequests.ts b/examples/Merchant/BillRequests.ts index 2cc230b..ecff3fa 100644 --- a/examples/Merchant/BillRequests.ts +++ b/examples/Merchant/BillRequests.ts @@ -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 { 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 { 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 { const client = ClientProvider.create(); const item = new Item() @@ -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 { const client = ClientProvider.create(); - client.deliverBill('someBillId', 'myBillToken'); + await client.deliverBill('someBillId', 'myBillToken'); } } \ No newline at end of file diff --git a/examples/Merchant/InvoiceRequests.ts b/examples/Merchant/InvoiceRequests.ts index fd25756..7e81881 100644 --- a/examples/Merchant/InvoiceRequests.ts +++ b/examples/Merchant/InvoiceRequests.ts @@ -3,7 +3,7 @@ import {Buyer} from "../../src/Model/Invoice/Buyer"; import {ClientProvider} from "../ClientProvider"; class InvoiceRequests { - public createInvoice(): void { + public async createInvoice(): Promise { const invoice = new Invoice(10.0, 'USD'); invoice.notificationEmail = 'some@email.com'; invoice.notificationURL = 'https://some-url.com'; @@ -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 { const client = ClientProvider.create(); const invoice = client.getInvoice('myInvoiceId'); @@ -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 { 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 { 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 { const client = ClientProvider.create(); - client.deliverBill('someBillId', 'myBillToken'); + await client.deliverBill('someBillId', 'myBillToken'); } } \ No newline at end of file diff --git a/examples/Merchant/LedgerRequests.ts b/examples/Merchant/LedgerRequests.ts index 64afc65..991f31c 100644 --- a/examples/Merchant/LedgerRequests.ts +++ b/examples/Merchant/LedgerRequests.ts @@ -1,13 +1,13 @@ import {ClientProvider} from "../ClientProvider"; class LedgerRequests { - public getLedgers(): void { + public async getLedgers(): Promise { const client = ClientProvider.create(); - const ledgers = client.getLedgers() + const ledgers = await client.getLedgers() } - public getLedgerEntries(): void { + public async getLedgerEntries(): Promise { const client = ClientProvider.create(); const oneMonthAgo = new Date(); @@ -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) } } \ No newline at end of file diff --git a/examples/Merchant/RefundRequests.ts b/examples/Merchant/RefundRequests.ts index 4860683..5e99de2 100644 --- a/examples/Merchant/RefundRequests.ts +++ b/examples/Merchant/RefundRequests.ts @@ -2,38 +2,47 @@ import {ClientProvider} from "../ClientProvider"; import {Refund} from "../../src/Model/Invoice/Refund"; class RefundRequests { - public createRefund(): void { + public async createRefund(): Promise { 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 { 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 { 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 { 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 { const client = ClientProvider.create(); - const result = client.sendRefundNotification('someRefundId'); + const result = await client.sendRefundNotification('someRefundId'); } } \ No newline at end of file diff --git a/examples/Merchant/SettlementRequests.ts b/examples/Merchant/SettlementRequests.ts index 50739b0..d56f3d4 100644 --- a/examples/Merchant/SettlementRequests.ts +++ b/examples/Merchant/SettlementRequests.ts @@ -2,11 +2,13 @@ import {ClientProvider} from "../ClientProvider"; import {Settlement} from "../../src/Model/Settlement/Settlement"; class SettlementRequests { - public getSettlement(): void { + public async getSettlement(): Promise { 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', @@ -14,14 +16,14 @@ class SettlementRequests { limit: 100, offset: 0 }; - const settlements = client.getSettlements(params) + const settlements = await client.getSettlements(params) } - public fetchReconciliationReport(): void { + public async fetchReconciliationReport(): Promise { const client = ClientProvider.create(); const settlement = new Settlement(); - const result = client.getSettlementReconciliationReport('settlementId', 'settlementToken'); + const result = await client.getSettlementReconciliationReport('settlementId', 'settlementToken'); } } \ No newline at end of file diff --git a/examples/Payout/PayoutRequests.ts b/examples/Payout/PayoutRequests.ts index 4ec9486..224f2f4 100644 --- a/examples/Payout/PayoutRequests.ts +++ b/examples/Payout/PayoutRequests.ts @@ -3,41 +3,46 @@ import {Payout} from "../../src/Model"; import {PayoutStatus} from "../../src"; class PayoutRequests { - public createPayout(): void { + public async createPayout(): Promise { 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 { 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 { 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 { const client = ClientProvider.create(); - const result = client.requestPayoutNotification('somePayoutId'); + const result = await client.requestPayoutNotification('somePayoutId'); } } \ No newline at end of file diff --git a/examples/Payout/RecipientRequests.ts b/examples/Payout/RecipientRequests.ts index 4fc69c9..e241378 100644 --- a/examples/Payout/RecipientRequests.ts +++ b/examples/Payout/RecipientRequests.ts @@ -2,36 +2,38 @@ import {ClientProvider} from "../ClientProvider"; import {PayoutRecipient, PayoutRecipients} from "../../src/Model"; class RecipientRequests { - public inviteRecipients(): void { + public async inviteRecipients(): Promise { 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 { 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 { 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 { const client = ClientProvider.create(); - const result = client.deletePayoutRecipient('somePayoutRecipientId'); + const result = await client.deletePayoutRecipient('somePayoutRecipientId'); } } \ No newline at end of file diff --git a/examples/Pos/BillRequests.ts b/examples/Pos/BillRequests.ts index b897ba8..e45bc98 100644 --- a/examples/Pos/BillRequests.ts +++ b/examples/Pos/BillRequests.ts @@ -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 { 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 { const client = ClientProvider.createPos(); - const bill = client.getBill('someBillId'); + const bill = await client.getBill('someBillId'); } - public deliverBillViaEmail(): void { + public async deliverBillViaEmail(): Promise { const client = ClientProvider.createPos(); - client.deliverBill('someBillId', 'myBillToken'); + await client.deliverBill('someBillId', 'myBillToken'); } } \ No newline at end of file diff --git a/examples/Pos/InvoiceRequests.ts b/examples/Pos/InvoiceRequests.ts index bdac1be..11ff0ab 100644 --- a/examples/Pos/InvoiceRequests.ts +++ b/examples/Pos/InvoiceRequests.ts @@ -3,7 +3,7 @@ import {Buyer} from "../../src/Model/Invoice/Buyer"; import {ClientProvider} from "../ClientProvider"; class InvoiceRequests { - public createInvoice(): void { + public async createInvoice(): Promise { const invoice = new Invoice(10.0, 'USD'); invoice.notificationEmail = 'some@email.com'; invoice.notificationURL = 'https://some-url.com'; @@ -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 { const client = ClientProvider.createPos(); - const invoice = client.getInvoice('myInvoiceId'); + const invoice = await client.getInvoice('myInvoiceId'); } } \ No newline at end of file diff --git a/examples/Public/RateRequests.ts b/examples/Public/RateRequests.ts index 95055eb..c2abb6a 100644 --- a/examples/Public/RateRequests.ts +++ b/examples/Public/RateRequests.ts @@ -1,11 +1,13 @@ import {ClientProvider} from "../ClientProvider"; class RateRequests { - public getRate(): void { + public async getRate(): Promise { const client = ClientProvider.create(); - const rate = client.getRate('BTC', 'USD'); + // Get one rate + const rate = await client.getRate('BTC', 'USD'); - const rates = client.getRates('BCH') + // Get multiple rates + const rates = await client.getRates('BCH') } } \ No newline at end of file diff --git a/examples/Public/WalletRequests.ts b/examples/Public/WalletRequests.ts index aa85d47..609885e 100644 --- a/examples/Public/WalletRequests.ts +++ b/examples/Public/WalletRequests.ts @@ -1,9 +1,9 @@ import {ClientProvider} from "../ClientProvider"; class WalletRequests { - public getSupportedWallets(): void { + public async getSupportedWallets(): Promise { const client = ClientProvider.create(); - const supportedWallets = client.getSupportedWallets(); + const supportedWallets = await client.getSupportedWallets(); } } \ No newline at end of file diff --git a/src/Client.ts b/src/Client.ts index d0f3c6e..f3d932b 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -270,7 +270,7 @@ export class Client { * autoVerify Skip the user verification on sandbox ONLY. * @return A BitPay generated Invoice object. */ - public async updateInvoice(invoiceId: string, params: []): Promise { + public async updateInvoice(invoiceId: string, params: object): Promise { return this.createInvoiceClient().update(invoiceId, params); } diff --git a/src/Client/InvoiceClient.ts b/src/Client/InvoiceClient.ts index d2ce120..fbee389 100644 --- a/src/Client/InvoiceClient.ts +++ b/src/Client/InvoiceClient.ts @@ -136,7 +136,7 @@ export class InvoiceClient { * @throws BitPayApiException BitPayApiException class * @throws BitPayGenericException BitPayGenericException class */ - public async update(invoiceId: string, params: []): Promise { + public async update(invoiceId: string, params: object): Promise { params['token'] = this.tokenContainer.getToken(Facade.Merchant); const result = await this.bitPayClient.put('invoices/' + invoiceId, params);