Skip to content

Commit

Permalink
SP-731 Node.js - Review Types
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarzybok-sumoheavy committed Feb 5, 2024
1 parent f2dd54b commit 5bded72
Show file tree
Hide file tree
Showing 18 changed files with 216 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/Model/Invoice/Invoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { InvoiceUniversalCodes } from './InvoiceUniversalCodes';
import { BitPayExceptionProvider } from '../../Exceptions/BitPayExceptionProvider';
import { MinerFeesItem } from './MinerFeesItem';
import { SupportedTransactionCurrency } from './SupportedTransactionCurrency';
import {InvoiceRefundAddresses} from "./InvoiceRefundAddresses";

export interface InvoiceInterface {
// API fields
Expand Down Expand Up @@ -53,7 +54,7 @@ export interface InvoiceInterface {
exceptionStatus?: boolean | string;
targetConfirmations?: number;
transactions?: InvoiceTransaction[];
refundAddresses?: unknown;
refundAddresses?: Array<{ [key: string]: InvoiceRefundAddresses }>;
refundAddressRequestPending?: boolean;
buyerProvidedEmail?: string;
buyerProvidedInfo?: InvoiceBuyerProvidedInfo;
Expand Down Expand Up @@ -129,7 +130,7 @@ export class Invoice implements InvoiceInterface {
exceptionStatus?: boolean | string;
targetConfirmations?: number;
transactions?: InvoiceTransaction[];
refundAddresses?: unknown;
refundAddresses?: Array<{ [key: string]: InvoiceRefundAddresses }>;
refundAddressRequestPending?: boolean;
buyerProvidedEmail?: string;
buyerProvidedInfo?: InvoiceBuyerProvidedInfo;
Expand Down
3 changes: 2 additions & 1 deletion src/Model/Invoice/Invoice.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { refundInfoSchema } from './RefundInfo.zod';
import { shopperSchema } from './Shopper.zod';
import { minerFeesItemSchema } from './MinerFeesItem.zod';
import { supportedTransactionCurrencySchema } from './SupportedTransactionCurrency.zod';
import {invoiceRefundAddressesSchema} from "./InvoiceRefundAddresses.zod";

export const invoiceSchema = z.object({
buyer: buyerInterfaceSchema.optional(),
Expand Down Expand Up @@ -47,7 +48,7 @@ export const invoiceSchema = z.object({
currentTime: z.number().optional(),
exceptionStatus: z.union([z.boolean(), z.string()]).optional(),
targetConfirmations: z.number().optional(),
refundAddresses: z.unknown().optional(),
refundAddresses: z.array(z.record(z.string(), invoiceRefundAddressesSchema)).optional(),
refundAddressRequestPending: z.boolean().optional(),
buyerProvidedEmail: z.string().optional(),
billId: z.string().optional(),
Expand Down
6 changes: 6 additions & 0 deletions src/Model/Invoice/InvoiceRefundAddresses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface InvoiceRefundAddresses {
type: string;
date: string;
tag?: number;
email?: string;
}
8 changes: 8 additions & 0 deletions src/Model/Invoice/InvoiceRefundAddresses.zod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {z} from "zod";

export const invoiceRefundAddressesSchema = z.object({
type: z.string(),
date: z.string(),
tag: z.number().optional().nullable(),
email: z.string().optional().nullable(),
});
2 changes: 2 additions & 0 deletions src/Model/Invoice/InvoiceTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ export interface InvoiceTransaction {
time?: string;
receivedTime?: string;
txid?: string;
exRates?: Record<string, number>;
outputIndex?: number
}
4 changes: 3 additions & 1 deletion src/Model/Invoice/InvoiceTransaction.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ export const invoiceTransactionSchema = z.object({
confirmations: z.number().optional(),
time: z.string().optional(),
receivedTime: z.string().optional(),
txid: z.string().optional()
txid: z.string().optional(),
exRates: z.record(z.string(), z.number()).optional(),
outputIndex: z.number().optional()
});
2 changes: 2 additions & 0 deletions src/Model/Payout/PayoutTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ export interface PayoutTransactionInterface {
txid: string;
amount: number;
date: string;
confirmations?: number;
}

export class PayoutTransaction implements PayoutTransactionInterface {
txid: string;
amount: number;
date: string;
confirmations?: number;

public constructor() {}
}
3 changes: 2 additions & 1 deletion src/Model/Payout/PayoutTransaction.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import { z } from 'zod';
export const payoutTransactionInterfaceSchema = z.object({
txid: z.string(),
amount: z.number(),
date: z.string()
date: z.string(),
confirmations: z.number().optional()
});
14 changes: 14 additions & 0 deletions src/Model/Webhook/InvoiceBuyerFields.zod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { z } from 'zod';

export const invoiceWebhookBuyerFieldsInterfaceSchema = z.object({
buyerName: z.string().optional(),
buyerAddress1: z.string().optional(),
buyerAddress2: z.string().optional(),
buyerCity: z.string().optional(),
buyerState: z.string().optional(),
buyerZip: z.string().optional(),
buyerCountry: z.string().optional(),
buyerPhone: z.string().optional(),
buyerNotify: z.boolean().optional(),
buyerEmail: z.string().optional()
});
23 changes: 23 additions & 0 deletions src/Model/Webhook/InvoiceWebhook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {BuyerFields} from "../Ledger/BuyerFields";

Check failure on line 1 in src/Model/Webhook/InvoiceWebhook.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

'BuyerFields' is defined but never used
import {InvoiceWebhookBuyerFields} from "./InvoiceWebhookBuyerFields";

export interface InvoiceWebhook {
id?: string;
url?: string;
posData?: string;
status?: string;
price?: string;
currency?: string;
invoiceTime?: string;
currencyTime?: string;
exceptionStatus?: string;
buyerFields?: InvoiceWebhookBuyerFields;
paymentSubtotals?: Record<string, number>;
paymentTotals?: Record<string, number>;
exchangeRates?: Record<string, Record<string, number>>;
amountPaid?: number;
orderId?: string;
transactionCurrency?: string;
inInvoiceId?: string;
inPaymentRequest?: string;
}
23 changes: 23 additions & 0 deletions src/Model/Webhook/InvoiceWebhook.zod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { z } from 'zod';
import {invoiceWebhookBuyerFieldsInterfaceSchema} from "./InvoiceBuyerFields.zod";

export const invoiceWebhookSchema = z.object({
id: z.string().optional(),
url: z.string().optional(),
posData: z.string().optional(),
status: z.string().optional(),
price: z.string().optional(),
currency: z.string().optional(),
invoiceTime: z.string().optional(),
currencyTime: z.string().optional(),
exceptionStatus: z.string().optional(),
buyerFields: invoiceWebhookBuyerFieldsInterfaceSchema.optional(),
paymentSubtotals: z.record(z.number()).nullable(),
paymentTotals: z.record(z.number()).nullable(),
exchangeRates: z.record(z.record(z.number())).nullable(),
amountPaid: z.number().optional(),
orderId: z.string().optional(),
transactionCurrency: z.string().optional(),
inInvoiceId: z.string().optional(),
inPaymentRequest: z.string().optional(),
})
27 changes: 27 additions & 0 deletions src/Model/Webhook/InvoiceWebhookBuyerFields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export interface InvoiceWebhookBuyerFieldsInterface {
buyerName?: string;
buyerAddress1?: string;
buyerAddress2?: string;
buyerCity?: string;
buyerState?: string;
buyerZip?: string;
buyerCountry?: string;
buyerPhone?: string;
buyerNotify?: boolean;
buyerEmail?: string;
}

export class InvoiceWebhookBuyerFields implements InvoiceWebhookBuyerFieldsInterface {
buyerName?: string;
buyerAddress1?: string;
buyerAddress2?: string;
buyerCity?: string;
buyerState?: string;
buyerZip?: string;
buyerCountry?: string;
buyerPhone?: string;
buyerNotify?: boolean;
buyerEmail?: string;

public constructor() {}
}
23 changes: 23 additions & 0 deletions src/Model/Webhook/PayoutWebhook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {PayoutTransaction} from "../Payout/PayoutTransaction";

export interface PayoutWebhookInterface {
id?: string;
recipientId?: string;
shopperId?: string;
price?: number;
currency?: string;
ledgerCurrency?: string;
exchangeRates?: Record<string, Record<string, number>>;
email?: string;
reference?: string;
label?: string;
notificationUrl?: string;
notificationEmail?: string;
effectiveDate?: string;
requestDate?: string;
status?: string;
transactions?: PayoutTransaction[];
accountId?: string;
date?: string;
groupId?: string;
}
24 changes: 24 additions & 0 deletions src/Model/Webhook/PayoutWebhook.zod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { z } from 'zod';
import {payoutTransactionInterfaceSchema} from "../Payout/PayoutTransaction.zod";

export const payoutWebhookSchema = z.object({
id: z.string().optional(),
recipientId: z.string().optional(),
shopperId: z.string().optional(),
price: z.number().optional(),
currency: z.string().optional(),
ledgerCurrency: z.string().optional(),
exchangeRates: z.record(z.record(z.number())).optional(),
email: z.string().optional(),
reference: z.string().optional(),
label: z.string().optional(),
notificationUrl: z.string().optional(),
notificationEmail: z.string().optional(),
effectiveDate: z.string().optional(),
requestDate: z.string().optional(),
status: z.string().optional(),
transactions: z.array(payoutTransactionInterfaceSchema).optional(),
accountId: z.string().optional(),
date: z.string().optional(),
groupId: z.string().optional(),
})
21 changes: 21 additions & 0 deletions src/Model/Webhook/RefundWebhook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export interface RefundWebhook {
amount?: number;
buyerPaysRefundFee?: boolean;
currency?: string;
id?: string;
immediate?: boolean;
invoice?: string;
lastRefundNotification?: string;
refundFee?: number;
requestDate?: string;
status?: string;
supportRequest?: string;
reference?: string;
guid?: string;
refundAddress?: string;
type?: string;
txid?: string;
transactionCurrency?: string;
transactionAmount?: number;
transactionRefundFee?: number;
}
23 changes: 23 additions & 0 deletions src/Model/Webhook/RefundWebhook.zod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { z } from 'zod';

export const refundWebhookSchema = z.object({
amount: z.number().nullable(),
buyerPaysRefundFee: z.boolean().nullable(),
currency: z.string().nullable(),
id: z.string().nullable(),
immediate: z.boolean().nullable(),
invoice: z.string().nullable(),
lastRefundNotification: z.string().nullable(),
refundFee: z.number().nullable(),
requestDate: z.string().nullable(),
status: z.string().nullable(),
supportRequest: z.string().nullable(),
reference: z.string().nullable(),
guid: z.string().nullable(),
refundAddress: z.string().nullable(),
type: z.string().nullable(),
txid: z.string().nullable(),
transactionCurrency: z.string().nullable(),
transactionAmount: z.number().nullable(),
transactionRefundFee: z.number().nullable(),
})
1 change: 1 addition & 0 deletions test/clientUnit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ describe('BitPaySDK.Client', () => {
expect(result.url).toBe('https://bitpay.com/invoice?id=G3viJEJgE8Jk2oekSdgT2A');
expect(result.buyerProvidedInfo.emailAddress).toBe('[email protected]');
expect(result.universalCodes.paymentString).toBe('https://link.bitpay.com/i/G3viJEJgE8Jk2oekSdgT2A');
expect(result.refundAddresses[0].n2MDYgEhxCAnuoVd1JpPmvxZShE6rQA6zv.type).toBe("buyerSupplied")
});

it('should get invoice', async () => {
Expand Down
10 changes: 9 additions & 1 deletion test/json/createInvoiceResponse.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@
"redirectURL": "https://merchantwebsite.com/shop/return",
"autoRedirect": false,
"closeURL": "https://merchantwebsite.com/shop/cancel",
"refundAddresses": [],
"refundAddresses": [
{
"n2MDYgEhxCAnuoVd1JpPmvxZShE6rQA6zv": {
"type": "buyerSupplied",
"date": "2024-01-08T23:50:56.556Z",
"email": "[email protected]"
}
}
],
"refundAddressRequestPending": false,
"buyerProvidedEmail": "[email protected]",
"buyerProvidedInfo": {
Expand Down

0 comments on commit 5bded72

Please sign in to comment.