UNPKG

@montarist/nestpay-api-v2

Version:

Unofficial comprehensive TypeScript API client for Nestpay payment gateway with 3D Secure support

252 lines 7.73 kB
import { EncodingType, HashAlgorithm } from '../types/enums'; import { HashParameters, ThreeDHashParameters } from '../types/interfaces'; /** * Hash Version 3 utility class for generating secure hashes for Nestpay API calls * Implementation follows Hash Version 3 specification where ALL parameters are included * in alphabetical order (except storeKey which goes last) */ export declare class HashUtil { private algorithm; private encoding; private version; constructor(algorithm?: HashAlgorithm, encoding?: EncodingType); /** * Generate Hash Version 3 for any Nestpay request * ALL parameters are included in alphabetical order (storeKey goes last) * @param params All parameters as key-value pairs * @param storeKey Store key (added at the end) * @param separator Separator character (default: '|' for pipe) * @returns Generated hash string */ generateHashV3(params: Record<string, string | number>, storeKey: string, separator?: string): string; /** * Generate hash for 3D Secure Classic model (Hash V3) */ generateThreeDClassicHashV3(params: { amount: string; callbackUrl: string; clientid: string; currency: string; failUrl?: string; hashAlgorithm?: string; Instalment?: string; lang?: string; okurl: string; refreshtime?: string; rnd: string; storetype: string; TranType: string; [key: string]: string | undefined; }, storeKey: string): string; /** * Generate hash for 3D Pay model (Hash V3) */ generateThreeDPayHashV3(params: { amount: string; callbackUrl: string; clientid: string; currency: string; failUrl?: string; hashAlgorithm?: string; Instalment?: string; lang?: string; okurl: string; refreshtime?: string; rnd: string; storetype: string; TranType: string; [key: string]: string | undefined; }, storeKey: string): string; /** * Generate hash for 3D Pay Hosting model (Hash V3) */ generateThreeDPayHostingHashV3(params: { amount: string; callbackUrl: string; clientid: string; currency: string; failUrl?: string; hashAlgorithm?: string; Instalment?: string; lang?: string; okurl: string; refreshtime?: string; rnd: string; storetype: string; TranType: string; [key: string]: string | undefined; }, storeKey: string): string; /** * Generate hash for direct payment (Hash V3) */ generateDirectPaymentHashV3(params: { amount: string; clientid: string; currency: string; hashAlgorithm?: string; Instalment?: string; lang?: string; oid: string; rnd: string; TranType: string; [key: string]: string | undefined; }, storeKey: string): string; /** * Generate hash for refund operation (Hash V3) */ generateRefundHashV3(params: { amount: string; clientid: string; currency: string; hashAlgorithm?: string; lang?: string; oid: string; rnd: string; TranType: string; [key: string]: string | undefined; }, storeKey: string): string; /** * Generate hash for void operation (Hash V3) */ generateVoidHashV3(params: { clientid: string; hashAlgorithm?: string; lang?: string; oid: string; rnd: string; TranType: string; [key: string]: string | undefined; }, storeKey: string): string; /** * Generate hash for preauth operation (Hash V3) */ generatePreauthHashV3(params: { amount: string; clientid: string; currency: string; hashAlgorithm?: string; Instalment?: string; lang?: string; oid: string; rnd: string; TranType: string; [key: string]: string | undefined; }, storeKey: string): string; /** * Generate hash for postauth operation (Hash V3) */ generatePostauthHashV3(params: { amount: string; clientid: string; currency: string; hashAlgorithm?: string; lang?: string; oid: string; rnd: string; TranType: string; [key: string]: string | undefined; }, storeKey: string): string; /** * Verify Hash Version 3 response */ verifyHashV3(receivedParams: Record<string, string>, receivedHash: string, storeKey: string, separator?: string): boolean; /** * Debug hash verification - shows detailed comparison */ debugHashVerification(receivedParams: Record<string, string>, receivedHash: string, storeKey: string, separator?: string): { isValid: boolean; expectedHash: string; receivedHash: string; parametersUsed: string[]; hashString: string; }; /** * Generate example hash according to documentation * Example from docs: amount|BillToCompany|BillToName|callbackUrl|clientid|currency|failUrl|hashAlgorithm|Instalment|lang|okurl|refreshtime|rnd|storetype|TranType|storeKey */ generateDocumentationExampleHash(separator?: string): string; /** * Test both separators and show results */ testSeparators(params: Record<string, string | number>, storeKey: string): { pipe: string; semicolon: string; }; /** * Test with provided example from bank documentation */ testBankExample(): { calculated: string; expected: string; matches: boolean; }; /** * @deprecated Use generateHashV3 instead for Hash Version 3 */ generatePaymentHash(params: HashParameters): string; /** * @deprecated Use generateHashV3 instead for Hash Version 3 */ generateThreeDHash(params: ThreeDHashParameters): string; /** * Create hash using specified algorithm and encoding with error handling */ private createHash; /** * Validate required parameters */ private validateRequired; /** * Constant-time string comparison to prevent timing attacks */ private constantTimeCompare; private validateHashParameters; private validateThreeDHashParameters; private build3DHashString; private buildHashString; /** * Set hash algorithm with validation */ setAlgorithm(algorithm: HashAlgorithm): void; /** * Get current hash algorithm */ getAlgorithm(): HashAlgorithm; /** * Set encoding type with validation */ setEncoding(encoding: EncodingType): void; /** * Get current encoding type */ getEncoding(): EncodingType; /** * Get hash utility version */ getVersion(): string; /** * Get supported algorithms */ static getSupportedAlgorithms(): HashAlgorithm[]; /** * Get supported encodings */ static getSupportedEncodings(): EncodingType[]; /** * Create a new instance with specific configuration */ static create(algorithm?: HashAlgorithm, encoding?: EncodingType): HashUtil; } /** * Default hash utility instance with SHA512 and Base64 (Hash Version 3 standard) */ export declare const hashUtil: HashUtil; /** * Utility function to create hash with SHA256 and Hex encoding */ export declare const createSHA256Hash: (data: string) => string; /** * Utility function to create hash with SHA512 and Base64 encoding */ export declare const createSHA512Hash: (data: string) => string; //# sourceMappingURL=hash.d.ts.map