@internal-labs/hoodpay
v0.1.6
Published
Lightweight TypeScript SDK for the HoodPay API (customers, payments).
Downloads
25
Maintainers
Readme
@internal-labs/hoodpay
Lightweight TypeScript SDK for the HoodPay API (customers, payments).
Installation
npm install @internal-labs/hoodpayor
pnpm add @internal-labs/hoodpaySetup
Before using the SDK, you'll need to obtain your Business ID and generate an API key from your HoodPay account.
- Log in to your HoodPay account
- Navigate to Settings > Developer
- Copy your Business ID and generate a new API key, then copy it securely
⚠️ Important: Keep your API key secure and never commit it to version control.
Usage
import { HoodPayClient } from '@internal-labs/hoodpay';
const client = new HoodPayClient({
apiKey: 'your-api-key-here',
businessId: 'your-business-id-here',
});
// Create a payment
const payment = await client.payments.create({
amount: 5,
currency: 'USD',
name: 'Subscription Test',
});
console.log(payment);
// List payments with pagination
const payments = await client.payments.list({
searchString: 'test',
pageSize: 10,
pageNumber: 1,
});
console.log(payments);
// Get a single payment
const singlePayment = await client.payments.get('payment-id');
console.log(singlePayment);
// List customers
const customers = await client.customers.list({
searchString: '[email protected]',
pageSize: 10,
pageNumber: 1,
});
console.log(customers);
// Get a single customer
const customer = await client.customers.get(123);
console.log(customer);
// Search for customers and payments
const searchResults = await client.search('alice');
console.log(searchResults);
// Select payment method (public endpoint, no auth required)
const selectResult = await client.livePayments.selectPaymentMethod('payment-id', 'ETHEREUM');
console.log(selectResult);
// Fill customer email (public endpoint)
const emailResult = await client.livePayments.fillCustomerEmail(
'payment-id',
'[email protected]',
);
console.log(emailResult);
// Cancel payment (public endpoint)
const cancelResult = await client.livePayments.cancelPayment('payment-id');
console.log(cancelResult);API Reference
HoodPayClient
Main client class for interacting with the HoodPay API.
Constructor Options
apiKey(string): Your HoodPay API keybaseUrl(string, optional): API base URL (defaults to production)businessId(string): Your business ID
Payments
create(data: CreatePaymentRequest): Promise
Creates a new payment.
Parameters:
data: Payment creation datapaymentMethods(optional): Object specifying allowed payment methods. If not provided, all available payment methods will be used.
list(options?: { searchString?: string; pageSize?: number; pageNumber?: number }): Promise
Lists payments with optional search and pagination.
Parameters:
options.searchString: Search string for filteringoptions.pageSize: Number of payments per pageoptions.pageNumber: Page number
get(paymentId: string): Promise
Gets a single payment by ID.
Parameters:
paymentId: Payment ID
Customers
list(options?: { searchString?: string; pageSize?: number; pageNumber?: number }): Promise
Lists customers with optional search and pagination.
Parameters:
options.searchString: Search string for filteringoptions.pageSize: Number of customers per pageoptions.pageNumber: Page number
search(query: string): Promise
Searches for customers and payments matching the provided query string.
Parameters:
query: Search query string
Returns a SearchResponse containing matching customers and payments.
Live Payments
selectPaymentMethod(paymentId: string, crypto: CryptoCode): Promise
Selects a payment method for a hosted payment page. Automatically detects whether to use XPUB (for LITECOIN/BITCOIN) or direct crypto submission.
Parameters:
paymentId: Payment ID from the hosted pagecrypto: Crypto code (automatically handled for XPUB vs direct)
Returns a SelectPaymentMethodResponse with charge details.
fillCustomerEmail(paymentId: string, email: string): Promise<{ message: string }>
Fills the customer email for a hosted payment page.
Parameters:
paymentId: Payment ID from the hosted pageemail: Customer email address
Returns a response with a success message.
cancelPayment(paymentId: string): Promise<{ message: string }>
Cancels a payment on the hosted page.
Parameters:
paymentId: Payment ID from the hosted page
Returns a response with a success message.
Types
CreatePaymentRequest
description?: string- Optional description of the paymentamount: number- The amount of the paymentcurrency: string- The currency code for the payment (ISO 4217 format, e.g. USD)name: string- The name associated with the paymentredirectUrl?: string- Optional URL to redirect after paymentnotifyUrl?: string- Optional URL for payment notificationscustomerEmail?: string- Optional email of the customercustomerIp?: string | null- Optional IP address of the customercustomerUserAgent?: string | null- Optional user agent of the customer
Payment
id: string- Payment IDname?: string- Optional namedescription?: string- Optional descriptionendAmount: number- Payment amountprePaymentAmount?: number- Pre-payment amountcurrency: string- Currency codestatus: string- Payment statuscreatedAt: string- Creation timestampexpiresAt?: string- Optional expiration timestamptimeline?: TimelineEntry[]- Optional status timelinecustomer?: Customer- Optional customer infopaymentMethod?: string- Optional payment methodselectedPaymentMethod?: string- Optional selected payment methoddirectCryptoCharge?: HoodPayCryptoCharge- Optional crypto charge detailshoodPayFee?: number- Optional feeonBehalfOfBusinessId?: number- Optional business IDnetAmountUsd?: number- Optional net amount in USDcustomerEmail?: string- Optional customer email
CustomerStat
id: number- Customer IDemail: string- Customer emailtotalPayments: number- Total paymentstotalSpend: number- Total spendfirstSeen: string- First seen timestamplastPayment?: string- Optional last payment timestamp
SearchResult
customers: SearchCustomer[]- Matching customerspayments: Payment[]- Matching payments
SelectPaymentMethodResponse
data.chargeId: string- Charge IDdata.chargeCryptoAmount: string- Crypto amount to paydata.chargeCryptoName: string- Crypto namedata.chargeCryptoAddress: string- Crypto address to send tomessage: string- Response message
Supported Crypto Codes
The following crypto codes are supported in paymentMethods.hoodPayCrypto:
- BITCOIN
- ETHEREUM
- LITECOIN
- BITCOIN_CASH
- ETH_USD_COIN
- ETH_TETHER
- MONERO
- ETH_BNB
- ETH_BUSD
- ETH_MATIC
- ETH_SHIBA_INU
- ETH_APE_COIN
- ETH_CRONOS
- ETH_DAI
- ETH_UNISWAP
Development
# Install dependencies
pnpm install
# Build
pnpm run build
# Run example
pnpm run example
# Lint
pnpm run lint
# Format
pnpm run formatContributing
Contributions are welcome. Please open an issue or submit a pull request.
License
MIT
