xrocket-pay-api-sdk
Version:
TypeScript SDK for xRocket Pay API
68 lines (67 loc) • 2.24 kB
TypeScript
import { InvoicePaymentWebhook } from './types';
/**
* Custom error types for webhook operations
*/
export declare class WebhookSignatureError extends Error {
constructor(message: string);
}
export declare class WebhookParseError extends Error {
constructor(message: string);
}
/**
* Verify webhook signature using HMAC-SHA-256
*
* @param body - Raw request body as string
* @param signature - The rocket-pay-signature header value
* @param secret - Your webhook secret key
* @returns true if signature is valid, false otherwise
*/
export declare function verifyWebhookSignature(body: string, signature: string, token: string): boolean;
/**
* Parse and validate webhook payload
*
* @param body - Raw request body as string
* @returns Parsed webhook payload
* @throws WebhookParseError if payload is invalid
*/
export declare function parseWebhookPayload(body: string): InvoicePaymentWebhook;
/**
* Verify signature and parse webhook payload in one step
*
* @param body - Raw request body as string
* @param signature - The rocket-pay-signature header value
* @param secret - Your webhook secret key
* @returns Parsed webhook payload
* @throws WebhookSignatureError if signature is invalid
* @throws WebhookParseError if payload is invalid
*/
export declare function verifyAndParseWebhook(body: string, signature: string, secret: string): InvoicePaymentWebhook;
/**
* Check if a webhook payload represents a paid invoice
*
* @param webhook - Parsed webhook payload
* @returns true if the invoice is paid
*/
export declare function isInvoicePaid(webhook: InvoicePaymentWebhook): boolean;
/**
* Extract payment information from webhook
*
* @param webhook - Parsed webhook payload
* @returns Payment summary object
*/
export declare function extractPaymentInfo(webhook: InvoicePaymentWebhook): {
invoiceId: number;
amount: number;
currency: string;
status: "active" | "paid" | "expired";
userId: number;
paymentAmount: number;
paymentAmountReceived: number;
paymentNumber: number;
paidAt: string;
comment: string | undefined;
payload: string | undefined;
description: string | undefined;
activationsLeft: number;
totalActivations: number;
};