# payu-intrepos/web-sdk-nodejs architecture

> Architecture diagram of the GitHub repository payu-intrepos/web-sdk-nodejs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/payu-intrepos/web-sdk-nodejs
- Repository: https://github.com/payu-intrepos/web-sdk-nodejs

## Overview

##### 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

## Diagram (Mermaid)

```mermaid
flowchart TD
    classDef client fill:#f2f2f2,stroke:#333,stroke-width:1px;
    classDef sdk fill:#cce5ff,stroke:#004085,stroke-width:1px;
    classDef external fill:#d4edda,stroke:#155724,stroke-width:1px;

    App["Client Application"]:::client
    index["index.js"]:::sdk
    core["PayU Core (lib/payu.js)"]:::sdk
    wrappersContainer["Wrapper Modules"]:::sdk
    bin["bin.js"]:::sdk
    checkout["checkout.js"]:::sdk
    downtime["downtime.js"]:::sdk
    emi["emi.js"]:::sdk
    initiate["initiate.js"]:::sdk
    invoice["invoice.js"]:::sdk
    refund["refund.js"]:::sdk
    settlement["settlement.js"]:::sdk
    txnDetails["transactionDetails.js"]:::sdk
    validateVPA["validateVPA.js"]:::sdk
    verify["verify.js"]:::sdk
    utils["Hasher (hasher.js)"]:::sdk
    http["HTTP Client (httpClient.js)"]:::sdk
    error["Error Handler (Error.js)"]:::sdk
    api["PayU REST API"]:::external

    App -->|"calls SDK"| index
    index -->|"instantiates"| core
    core -->|"delegates to"| wrappersContainer

    wrappersContainer --> bin
    wrappersContainer --> checkout
    wrappersContainer --> downtime
    wrappersContainer --> emi
    wrappersContainer --> initiate
    wrappersContainer --> invoice
    wrappersContainer --> refund
    wrappersContainer --> settlement
    wrappersContainer --> txnDetails
    wrappersContainer --> validateVPA
    wrappersContainer --> verify

    wrappersContainer -->|"uses"| utils
    wrappersContainer -->|"sends signed request"| http
    utils -->|"returns hash"| wrappersContainer

    http -->|"forwards to"| api
    api -->|"response"| http
    http -->|"returns data/error"| wrappersContainer

    wrappersContainer -->|"returns data or throws error"| core
    core -->|"resolves/rejects promise"| App

    click index "https://github.com/payu-intrepos/web-sdk-nodejs/blob/main/index.js"
    click core "https://github.com/payu-intrepos/web-sdk-nodejs/blob/main/lib/payu.js"
    click error "https://github.com/payu-intrepos/web-sdk-nodejs/blob/main/lib/Error.js"
    click http "https://github.com/payu-intrepos/web-sdk-nodejs/blob/main/lib/http/httpClient.js"
    click utils "https://github.com/payu-intrepos/web-sdk-nodejs/blob/main/lib/utils/hasher.js"
    click bin "https://github.com/payu-intrepos/web-sdk-nodejs/blob/main/lib/wrapper/bin.js"
    click checkout "https://github.com/payu-intrepos/web-sdk-nodejs/blob/main/lib/wrapper/checkout.js"
    click downtime "https://github.com/payu-intrepos/web-sdk-nodejs/blob/main/lib/wrapper/downtime.js"
    click emi "https://github.com/payu-intrepos/web-sdk-nodejs/blob/main/lib/wrapper/emi.js"
    click initiate "https://github.com/payu-intrepos/web-sdk-nodejs/blob/main/lib/wrapper/initiate.js"
    click invoice "https://github.com/payu-intrepos/web-sdk-nodejs/blob/main/lib/wrapper/invoice.js"
    click refund "https://github.com/payu-intrepos/web-sdk-nodejs/blob/main/lib/wrapper/refund.js"
    click settlement "https://github.com/payu-intrepos/web-sdk-nodejs/blob/main/lib/wrapper/settlement.js"
    click txnDetails "https://github.com/payu-intrepos/web-sdk-nodejs/blob/main/lib/wrapper/transactionDetails.js"
    click validateVPA "https://github.com/payu-intrepos/web-sdk-nodejs/blob/main/lib/wrapper/validateVPA.js"
    click verify "https://github.com/payu-intrepos/web-sdk-nodejs/blob/main/lib/wrapper/verify.js"
```
