How payu-intrepos/web-sdk-nodejs works
Project Type and Purpose
• This is an open-source Node.js SDK (library) that wraps the PayU payment gateway’s REST APIs.
• It abstracts low-level HTTP calls, handles request signing (hashing), error handling, and exposes a concise method interface for merchants to integrate payments, refunds, settlements, EMIs, invoices, etc.
File Structure Analysis
• Entry Point:
• index.js — exports the PayU client constructor.
• Core:
• lib/payu.js — the main PayU class, orchestrates calls.
• lib/Error.js — custom error types for SDK failures.
• HTTP Layer:
• lib/http/httpClient.js — wrapper around axios/fetch, handles request/response, base URL, headers, timeouts.
• Utilities:
• lib/utils/hasher.js — generates SHA-512 hash for PayU’s security requirements.
• Wrapper Modules (one per API group) under lib/wrapper:
• bin.js, checkout.js, downtime.js, emi.js, initiate.js, invoice.js, refund.js, settlement.js, transactionDetails.js, validateVPA.js, verify.js
• Each module constructs endpoint paths, payload schemas, calls httpClient, and returns parsed JSON.
• Documentation (docs/*.md) — method-level API docs.
• Tests (test/*.test.js) — unit tests exercising each wrapper method.
• Config — package.json, sonar-project.properties, lockfile.
README Insights
• Describes the PayU SDK’s capabilities (initiate payment, verify, refunds, invoices, EMIs, settlements, consulte downtime).
• Shows instantiation (new PayU({ key, salt }, ENV)) and method table mapping to docs.
a. Main Components
• Client Application (merchant’s code)
• PayU SDK Module
• Entry Point (index.js)
• PayU Core Class (lib/payu.js)
• Hashing Utility (lib/utils/hasher.js)
• HTTP Client (lib/http/httpClient.js)
• Wrapper Sub-modules (lib/wrapper/*)
• Error Handler (lib/Error.js)
• External System: PayU REST APIs
b. Relationships & Data Flow
1. Client App calls SDK method (e.g., payuClient.paymentInitiate(...)).
2. SDK Core delegates to the appropriate wrapper module.
3. Wrapper builds payload + parameters.
4. Payload is passed to the hasher to generate a security hash.
5. HTTP Client sends signed request to PayU REST endpoint.
6. PayU API processes and returns a response.
7. HTTP Client parses response or throws errors.
8. Wrapper module returns data or throws SDK Error.
9. Client App receives resolution or rejection.
c. Architectural Patterns & Principles
• Single Responsibility: each wrapper module handles one API domain.
• Abstraction: HTTP calls abstracted behind httpClient.
• Modularity: core, utils, wrappers are separate layers.
• Asynchronous Promises: all network calls return promises.
d. Key Technologies
• Node.js
• HTTP client library (axios or fetch)
• SHA-512 hashing (built-in crypto)
• CommonJS modules