Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SP-1135 - Add exports to Node.js SDK #132

Merged
merged 4 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion examples/Merchant/InvoiceRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export class InvoiceRequests {
public async requestInvoiceWebhookToBeResent() {
const client = ClientProvider.create();

return await client.deliverBill('someBillId', 'myBillToken');
const invoiceId = 'myInvoiceId';
const invoice = await client.getInvoice(invoiceId);

return await client.requestInvoiceWebhookToBeResent(invoiceId, invoice.token);
}
}
10 changes: 8 additions & 2 deletions examples/Merchant/RefundRequests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ClientProvider } from '../ClientProvider';
import { Refund } from '../../src/Model/Invoice/Refund';
import { ClientProvider } from '../ClientProvider';

export class RefundRequests {
public async createRefund() {
Expand Down Expand Up @@ -49,6 +49,12 @@ export class RefundRequests {
public async requestRefundNotificationToBeResent() {
const client = ClientProvider.create();

return await client.sendRefundNotification('someRefundId');
const refundId = 'someRefundId';
const refund = await client.getRefund(refundId);
if (!refund.token) {
throw new Error('Refund token is required to request a refund notification to be resent.');
}

return await client.sendRefundNotification(refundId, refund.token);
}
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
{
"name": "bitpay-sdk",
"version": "6.3.0",
"version": "6.3.1",
"description": "Complete version of the NodeJS library for the new cryptographically secure BitPay API",
"engines": {
"node": ">=18.0.0 <23.0.0"
},
"main": "dist/index",
"exports": {
".": "./dist/index.js",
"./client": "./dist/Client/index.js",
"./models": "./dist/Model/index.js",
"./exceptions": "./dist/Exceptions/index.js",
"./logger": "./dist/Logger/index.js"
},
"typings": "dist/index",
"bin": "./bin/index.js",
"files": [
Expand Down
56 changes: 30 additions & 26 deletions src/Client.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
/* eslint-disable @typescript-eslint/no-unused-vars*/

import { ec } from 'elliptic';
import {
BillClient,
BitPayClient,
CurrencyClient,
InvoiceClient,
LedgerClient,
PayoutClient,
PayoutGroupClient,
PayoutRecipientClient,
RateClient,
RefundClient,
SettlementClient,
WalletClient
} from './Client/index';
import { Env, Facade, KeyUtils } from './index';
import {
BillInterface,
InvoiceInterface,
LedgerEntryInterface,
LedgerInterface,
PayoutInterface,
PayoutGroupInterface,
PayoutInterface,
PayoutRecipientInterface,
PayoutRecipients,
RateInterface,
Rates
} from './Model';
import {
BitPayClient,
RateClient,
CurrencyClient,
InvoiceClient,
RefundClient,
PayoutClient,
PayoutGroupClient,
PayoutRecipientClient,
LedgerClient,
BillClient,
WalletClient,
SettlementClient
} from './Client/index';

import { TokenContainer } from './TokenContainer';
import * as fs from 'fs';
import { Environment } from './Environment';
import { GuidGenerator } from './util/GuidGenerator';
import { BitPayExceptionProvider } from './Exceptions/BitPayExceptionProvider';
import { CurrencyInterface } from './Model/Currency/Currency';
import { InvoiceEventTokenInterface } from './Model/Invoice/InvoiceEventToken';
import { RefundInterface } from './Model/Invoice/Refund';
import { ParamsRemover } from './util/ParamsRemover';
import { WalletInterface } from './Model/Wallet/Wallet';
import { SettlementInterface } from './Model/Settlement/Settlement';
import { WalletInterface } from './Model/Wallet/Wallet';
import { PosToken } from './PosToken';
import { PrivateKey } from './PrivateKey';
import { CurrencyInterface } from './Model/Currency/Currency';
import * as fs from 'fs';
import { BitPayExceptionProvider } from './Exceptions/BitPayExceptionProvider';
import { TokenContainer } from './TokenContainer';
import { GuidGenerator } from './util/GuidGenerator';
import { ParamsRemover } from './util/ParamsRemover';

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

/**
Expand Down Expand Up @@ -389,10 +391,12 @@ export class Client {
* Send a refund notification.
*
* @param refundId A BitPay refund ID.
* @param refundToken The resource token for the refundId.
* This token can be retrieved from the Bitpay's refund object.
* @return An updated Refund Object
*/
public async sendRefundNotification(refundId: string): Promise<boolean> {
return this.createRefundClient().sendRefundNotification(refundId);
public async sendRefundNotification(refundId: string, refundToken: string): Promise<boolean> {
return this.createRefundClient().sendRefundNotification(refundId, refundToken);
}

/**
Expand Down
16 changes: 9 additions & 7 deletions src/Client/InvoiceClient.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BitPayClient } from './BitPayClient';
import { BitPayExceptionProvider } from '../Exceptions/BitPayExceptionProvider';
import { Facade } from '../Facade';
import { Invoice, InvoiceInterface } from '../Model';
import { TokenContainer } from '../TokenContainer';
import { GuidGenerator } from '../util/GuidGenerator';
import { InvoiceEventTokenInterface } from '../Model/Invoice/InvoiceEventToken';
import { TokenContainer } from '../TokenContainer';
import { BitPayResponseParser } from '../util/BitPayResponseParser';
import { BitPayExceptionProvider } from '../Exceptions/BitPayExceptionProvider';
import { Facade } from '../Facade';
import { GuidGenerator } from '../util/GuidGenerator';
import { BitPayClient } from './BitPayClient';

export class InvoiceClient {
private bitPayClient: BitPayClient;
Expand Down Expand Up @@ -225,12 +225,14 @@ export class InvoiceClient {
* Request a BitPay Invoice Webhook.
*
* @param invoiceId A BitPay invoice ID.
* @param invoiceToken The resource token for the invoiceId.
* This token can be retrieved from the Bitpay's invoice object.
* @returns boolean
* @throws BitPayApiException BitPayApiException class
* @throws BitPayGenericException BitPayGenericException class
*/
public async requestInvoiceWebhookToBeResent(invoiceId: string): Promise<boolean> {
const params = { token: this.tokenContainer.getToken(Facade.Merchant) };
public async requestInvoiceWebhookToBeResent(invoiceId: string, invoiceToken: string): Promise<boolean> {
const params = { token: invoiceToken };
const result = await this.bitPayClient.post('invoices/' + invoiceId + '/notifications', params);

try {
Expand Down
16 changes: 9 additions & 7 deletions src/Client/RefundClient.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BitPayClient } from './BitPayClient';
import { TokenContainer } from '../TokenContainer';
import { GuidGenerator } from '../util/GuidGenerator';
import { BitPayExceptionProvider } from '../Exceptions/BitPayExceptionProvider';
import { Facade } from '../index';
import { RefundInterface } from '../Model/Invoice/Refund';
import { ParamsRemover } from '../util/ParamsRemover';
import { TokenContainer } from '../TokenContainer';
import { BitPayResponseParser } from '../util/BitPayResponseParser';
import { BitPayExceptionProvider } from '../Exceptions/BitPayExceptionProvider';
import { GuidGenerator } from '../util/GuidGenerator';
import { ParamsRemover } from '../util/ParamsRemover';
import { BitPayClient } from './BitPayClient';

export class RefundClient {
private bitPayClient: BitPayClient;
Expand Down Expand Up @@ -116,12 +116,14 @@ export class RefundClient {
* Send a refund notification.
*
* @param refundId A BitPay refund ID.
* @param refundToken The resource token for the refundId.
* This token can be retrieved from the Bitpay's refund object.
* @returns boolean An updated Refund Object
* @throws BitPayApiException BitPayApiException class
* @throws BitPayGenericException BitPayGenericException class
*/
public async sendRefundNotification(refundId: string): Promise<boolean> {
const params = { token: this.tokenContainer.getToken(Facade.Merchant) };
public async sendRefundNotification(refundId: string, refundToken: string): Promise<boolean> {
const params = { token: refundToken };
const result = await this.bitPayClient.post('refunds/' + refundId + '/notifications', params, true);

try {
Expand Down
2 changes: 1 addition & 1 deletion src/Env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const Prod = 'PROD';
export const TestUrl = 'https://test.bitpay.com/';
export const ProdUrl = 'https://bitpay.com/';
export const BitpayApiVersion = '2.0.0';
export const BitpayPluginInfo = 'BitPay_NodeJs_Client_v6.3.0';
export const BitpayPluginInfo = 'BitPay_NodeJs_Client_v6.3.1';
export const BitpayApiFrame = 'std';
export const BitpayApiFrameVersion = '1.0.0';

Expand Down
5 changes: 3 additions & 2 deletions src/Exceptions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
* See the LICENSE file for more info.
*/

import { BitPayGenericException as Generic } from './BitPayGenericException';
import { BitPayApiException as Api } from './BitPayApiException';
import { BitPayException } from './BitPayException';
import { BitPayGenericException as Generic } from './BitPayGenericException';
import { BitPayValidationException as Validation } from './BitPayValidationException';

export { Generic, Api, Validation };
export { Api, BitPayException, Generic, Validation };
5 changes: 5 additions & 0 deletions src/Logger/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { BitPayLogger } from './BitPayLogger';
import { EmptyLogger } from './EmptyLogger';
import { LoggerProvider } from './LoggerProvider';

export { BitPayLogger, EmptyLogger, LoggerProvider };
2 changes: 1 addition & 1 deletion src/Model/Ledger/BuyerFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface BuyerFieldsInterface {
buyerEmail?: string;
}

export class BuyerFields implements BuyerFields {
export class BuyerFields implements BuyerFieldsInterface {
buyerName?: string;
buyerAddress1?: string;
buyerAddress2?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Webhook/InvoiceWebhook.zod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { z } from 'zod';
import { invoiceWebhookBuyerFieldsInterfaceSchema } from './InvoiceBuyerFields.zod';
import { invoiceWebhookBuyerFieldsInterfaceSchema } from './InvoiceWebhookBuyerFields.zod';

export const invoiceWebhookSchema = z.object({
id: z.string().optional(),
Expand Down
Loading