Skip to content

Commit 973d870

Browse files
authored
Merge pull request #132 from swlodarski-sumoheavy/7.0.x
SP-1135 - Add exports to Node.js SDK
2 parents 6925c24 + e55e43a commit 973d870

16 files changed

+269
-137
lines changed

examples/Merchant/InvoiceRequests.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ export class InvoiceRequests {
6767
public async requestInvoiceWebhookToBeResent() {
6868
const client = ClientProvider.create();
6969

70-
return await client.deliverBill('someBillId', 'myBillToken');
70+
const invoiceId = 'myInvoiceId';
71+
const invoice = await client.getInvoice(invoiceId);
72+
73+
return await client.requestInvoiceWebhookToBeResent(invoiceId, invoice.token);
7174
}
7275
}

examples/Merchant/RefundRequests.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ClientProvider } from '../ClientProvider';
21
import { Refund } from '../../src/Model/Invoice/Refund';
2+
import { ClientProvider } from '../ClientProvider';
33

44
export class RefundRequests {
55
public async createRefund() {
@@ -49,6 +49,12 @@ export class RefundRequests {
4949
public async requestRefundNotificationToBeResent() {
5050
const client = ClientProvider.create();
5151

52-
return await client.sendRefundNotification('someRefundId');
52+
const refundId = 'someRefundId';
53+
const refund = await client.getRefund(refundId);
54+
if (!refund.token) {
55+
throw new Error('Refund token is required to request a refund notification to be resent.');
56+
}
57+
58+
return await client.sendRefundNotification(refundId, refund.token);
5359
}
5460
}

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
{
22
"name": "bitpay-sdk",
3-
"version": "6.3.0",
3+
"version": "6.3.1",
44
"description": "Complete version of the NodeJS library for the new cryptographically secure BitPay API",
55
"engines": {
66
"node": ">=18.0.0 <23.0.0"
77
},
88
"main": "dist/index",
9+
"exports": {
10+
".": "./dist/index.js",
11+
"./client": "./dist/Client/index.js",
12+
"./models": "./dist/Model/index.js",
13+
"./exceptions": "./dist/Exceptions/index.js",
14+
"./logger": "./dist/Logger/index.js"
15+
},
916
"typings": "dist/index",
1017
"bin": "./bin/index.js",
1118
"files": [

src/Client.ts

+30-26
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars*/
22

33
import { ec } from 'elliptic';
4+
import {
5+
BillClient,
6+
BitPayClient,
7+
CurrencyClient,
8+
InvoiceClient,
9+
LedgerClient,
10+
PayoutClient,
11+
PayoutGroupClient,
12+
PayoutRecipientClient,
13+
RateClient,
14+
RefundClient,
15+
SettlementClient,
16+
WalletClient
17+
} from './Client/index';
418
import { Env, Facade, KeyUtils } from './index';
519
import {
620
BillInterface,
721
InvoiceInterface,
822
LedgerEntryInterface,
923
LedgerInterface,
10-
PayoutInterface,
1124
PayoutGroupInterface,
25+
PayoutInterface,
1226
PayoutRecipientInterface,
1327
PayoutRecipients,
1428
RateInterface,
1529
Rates
1630
} from './Model';
17-
import {
18-
BitPayClient,
19-
RateClient,
20-
CurrencyClient,
21-
InvoiceClient,
22-
RefundClient,
23-
PayoutClient,
24-
PayoutGroupClient,
25-
PayoutRecipientClient,
26-
LedgerClient,
27-
BillClient,
28-
WalletClient,
29-
SettlementClient
30-
} from './Client/index';
3131

32-
import { TokenContainer } from './TokenContainer';
32+
import * as fs from 'fs';
3333
import { Environment } from './Environment';
34-
import { GuidGenerator } from './util/GuidGenerator';
34+
import { BitPayExceptionProvider } from './Exceptions/BitPayExceptionProvider';
35+
import { CurrencyInterface } from './Model/Currency/Currency';
3536
import { InvoiceEventTokenInterface } from './Model/Invoice/InvoiceEventToken';
3637
import { RefundInterface } from './Model/Invoice/Refund';
37-
import { ParamsRemover } from './util/ParamsRemover';
38-
import { WalletInterface } from './Model/Wallet/Wallet';
3938
import { SettlementInterface } from './Model/Settlement/Settlement';
39+
import { WalletInterface } from './Model/Wallet/Wallet';
4040
import { PosToken } from './PosToken';
4141
import { PrivateKey } from './PrivateKey';
42-
import { CurrencyInterface } from './Model/Currency/Currency';
43-
import * as fs from 'fs';
44-
import { BitPayExceptionProvider } from './Exceptions/BitPayExceptionProvider';
42+
import { TokenContainer } from './TokenContainer';
43+
import { GuidGenerator } from './util/GuidGenerator';
44+
import { ParamsRemover } from './util/ParamsRemover';
4545

4646
export class Client {
4747
private bitPayClient: BitPayClient;
@@ -311,10 +311,12 @@ export class Client {
311311
* The intent of this call is to address issues when BitPay sends a webhook but the client doesn't receive it,
312312
* so the client can request that BitPay resend it.
313313
* @param invoiceId The id of the invoice for which you want the last webhook to be resent.
314+
* @param invoiceToken The resource token for the invoiceId.
315+
* This token can be retrieved from the Bitpay's invoice object.
314316
* @return Boolean status of request
315317
*/
316-
public async requestInvoiceWebhookToBeResent(invoiceId: string): Promise<boolean> {
317-
return this.createInvoiceClient().requestInvoiceWebhookToBeResent(invoiceId);
318+
public async requestInvoiceWebhookToBeResent(invoiceId: string, invoiceToken: string): Promise<boolean> {
319+
return this.createInvoiceClient().requestInvoiceWebhookToBeResent(invoiceId, invoiceToken);
318320
}
319321

320322
/**
@@ -389,10 +391,12 @@ export class Client {
389391
* Send a refund notification.
390392
*
391393
* @param refundId A BitPay refund ID.
394+
* @param refundToken The resource token for the refundId.
395+
* This token can be retrieved from the Bitpay's refund object.
392396
* @return An updated Refund Object
393397
*/
394-
public async sendRefundNotification(refundId: string): Promise<boolean> {
395-
return this.createRefundClient().sendRefundNotification(refundId);
398+
public async sendRefundNotification(refundId: string, refundToken: string): Promise<boolean> {
399+
return this.createRefundClient().sendRefundNotification(refundId, refundToken);
396400
}
397401

398402
/**

src/Client/InvoiceClient.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { BitPayClient } from './BitPayClient';
1+
import { BitPayExceptionProvider } from '../Exceptions/BitPayExceptionProvider';
2+
import { Facade } from '../Facade';
23
import { Invoice, InvoiceInterface } from '../Model';
3-
import { TokenContainer } from '../TokenContainer';
4-
import { GuidGenerator } from '../util/GuidGenerator';
54
import { InvoiceEventTokenInterface } from '../Model/Invoice/InvoiceEventToken';
5+
import { TokenContainer } from '../TokenContainer';
66
import { BitPayResponseParser } from '../util/BitPayResponseParser';
7-
import { BitPayExceptionProvider } from '../Exceptions/BitPayExceptionProvider';
8-
import { Facade } from '../Facade';
7+
import { GuidGenerator } from '../util/GuidGenerator';
8+
import { BitPayClient } from './BitPayClient';
99

1010
export class InvoiceClient {
1111
private bitPayClient: BitPayClient;
@@ -225,12 +225,14 @@ export class InvoiceClient {
225225
* Request a BitPay Invoice Webhook.
226226
*
227227
* @param invoiceId A BitPay invoice ID.
228+
* @param invoiceToken The resource token for the invoiceId.
229+
* This token can be retrieved from the Bitpay's invoice object.
228230
* @returns boolean
229231
* @throws BitPayApiException BitPayApiException class
230232
* @throws BitPayGenericException BitPayGenericException class
231233
*/
232-
public async requestInvoiceWebhookToBeResent(invoiceId: string): Promise<boolean> {
233-
const params = { token: this.tokenContainer.getToken(Facade.Merchant) };
234+
public async requestInvoiceWebhookToBeResent(invoiceId: string, invoiceToken: string): Promise<boolean> {
235+
const params = { token: invoiceToken };
234236
const result = await this.bitPayClient.post('invoices/' + invoiceId + '/notifications', params);
235237

236238
try {

src/Client/RefundClient.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { BitPayClient } from './BitPayClient';
2-
import { TokenContainer } from '../TokenContainer';
3-
import { GuidGenerator } from '../util/GuidGenerator';
1+
import { BitPayExceptionProvider } from '../Exceptions/BitPayExceptionProvider';
42
import { Facade } from '../index';
53
import { RefundInterface } from '../Model/Invoice/Refund';
6-
import { ParamsRemover } from '../util/ParamsRemover';
4+
import { TokenContainer } from '../TokenContainer';
75
import { BitPayResponseParser } from '../util/BitPayResponseParser';
8-
import { BitPayExceptionProvider } from '../Exceptions/BitPayExceptionProvider';
6+
import { GuidGenerator } from '../util/GuidGenerator';
7+
import { ParamsRemover } from '../util/ParamsRemover';
8+
import { BitPayClient } from './BitPayClient';
99

1010
export class RefundClient {
1111
private bitPayClient: BitPayClient;
@@ -116,12 +116,14 @@ export class RefundClient {
116116
* Send a refund notification.
117117
*
118118
* @param refundId A BitPay refund ID.
119+
* @param refundToken The resource token for the refundId.
120+
* This token can be retrieved from the Bitpay's refund object.
119121
* @returns boolean An updated Refund Object
120122
* @throws BitPayApiException BitPayApiException class
121123
* @throws BitPayGenericException BitPayGenericException class
122124
*/
123-
public async sendRefundNotification(refundId: string): Promise<boolean> {
124-
const params = { token: this.tokenContainer.getToken(Facade.Merchant) };
125+
public async sendRefundNotification(refundId: string, refundToken: string): Promise<boolean> {
126+
const params = { token: refundToken };
125127
const result = await this.bitPayClient.post('refunds/' + refundId + '/notifications', params, true);
126128

127129
try {

src/Env.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export const Prod = 'PROD';
33
export const TestUrl = 'https://test.bitpay.com/';
44
export const ProdUrl = 'https://bitpay.com/';
55
export const BitpayApiVersion = '2.0.0';
6-
export const BitpayPluginInfo = 'BitPay_NodeJs_Client_v6.3.0';
6+
export const BitpayPluginInfo = 'BitPay_NodeJs_Client_v6.3.1';
77
export const BitpayApiFrame = 'std';
88
export const BitpayApiFrameVersion = '1.0.0';
99

src/Exceptions/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
* See the LICENSE file for more info.
1414
*/
1515

16-
import { BitPayGenericException as Generic } from './BitPayGenericException';
1716
import { BitPayApiException as Api } from './BitPayApiException';
17+
import { BitPayException } from './BitPayException';
18+
import { BitPayGenericException as Generic } from './BitPayGenericException';
1819
import { BitPayValidationException as Validation } from './BitPayValidationException';
1920

20-
export { Generic, Api, Validation };
21+
export { Api, BitPayException, Generic, Validation };

src/Logger/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { BitPayLogger } from './BitPayLogger';
2+
import { EmptyLogger } from './EmptyLogger';
3+
import { LoggerProvider } from './LoggerProvider';
4+
5+
export { BitPayLogger, EmptyLogger, LoggerProvider };

src/Model/Ledger/BuyerFields.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface BuyerFieldsInterface {
1111
buyerEmail?: string;
1212
}
1313

14-
export class BuyerFields implements BuyerFields {
14+
export class BuyerFields implements BuyerFieldsInterface {
1515
buyerName?: string;
1616
buyerAddress1?: string;
1717
buyerAddress2?: string;

src/Model/Webhook/InvoiceWebhook.zod.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { z } from 'zod';
2-
import { invoiceWebhookBuyerFieldsInterfaceSchema } from './InvoiceBuyerFields.zod';
2+
import { invoiceWebhookBuyerFieldsInterfaceSchema } from './InvoiceWebhookBuyerFields.zod';
33

44
export const invoiceWebhookSchema = z.object({
55
id: z.string().optional(),

0 commit comments

Comments
 (0)