# fredsoares/sisp_payments_js architecture

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

- Interactive diagram: https://gitdiagram.com/fredsoares/sisp_payments_js
- Repository: https://github.com/fredsoares/sisp_payments_js

## Overview

##### Project type and purpose
- This is an open-source Node.js SDK (library) called “sisp-payments” that simplifies integrating SISP (Vinti4) card payments into any Node.js application.
- It exposes two primary methods:
- generatePaymentRequestForm(...) – builds an HTML form to redirect the user to SISP’s payment page
- validatePayment(...) – validates the incoming webhook from SISP and normalizes error codes

##### File structure
- Root files (.eslintrc.js, .prettierrc, package.json, README.md, LICENSE) indicate a published npm module with linting, formatting, tests, and CI config.
- src/index.js – entry point, exports the Sisp class.
- src/sisp.js – the main class, holds credentials and implements the two public methods.
- src/utils/paymentErrors.js – maps SISP error codes to descriptions for validatePayment.
- src/*.test.js & jest.config.js – unit tests validating both functions.

##### README for additional insights
- Describes usage in a host Node.js application:
- Instantiation with credentials (posID, posAutCode).
- Embedding the returned HTML form in a frontend.
- Handling SISP’s POST webhook.
- No internal persistence or database—purely request/response interactions with SISP.

##### Detail without overthinking
- Every named component: “Sisp class,” “paymentErrors util,” “webhookUrl handler.”
- Call out configuration injection (posID, posAutCode) at instantiation.
- Both happy path (success) and error path (validatePayment → error code).

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Host Application"
        HostApp["Host Application"]:::host
        subgraph "sisp-payments SDK"
            SDKEntry["SDK Entry Point"]:::sdk
            SispClass["Sisp Class"]:::sdk
            ErrorUtil["Error Code Utility"]:::sdk
        end
        WebhookHandler["Webhook Handler Endpoint"]:::host
    end

    Client["Client Browser"]:::client
    SISP["SISP Payment Gateway"]:::external

    HostApp -->|"instantiates Sisp({posID,posAutCode})"| SDKEntry
    HostApp -->|"generatePaymentRequestForm() → HTML form"| Client
    Client -->|"POST form"| SISP
    SISP -->|"POST /webhook"| WebhookHandler
    WebhookHandler -->|"validatePayment(body)"| SispClass

    subgraph "Project Files & Configs"
        EntryTests["Entry Point Tests"]:::config
        SispTests["Sisp Class Tests"]:::config
        Package["package.json"]:::config
        ESLint[".eslintrc.js"]:::config
        Prettier[".prettierrc"]:::config
        JestConfig["jest.config.js"]:::config
        Readme["README.md"]:::config
        License["LICENSE"]:::config
    end

    click SDKEntry "https://github.com/fredsoares/sisp_payments_js/blob/main/src/index.js"
    click SispClass "https://github.com/fredsoares/sisp_payments_js/blob/main/src/sisp.js"
    click ErrorUtil "https://github.com/fredsoares/sisp_payments_js/blob/main/src/utils/paymentErrors.js"
    click EntryTests "https://github.com/fredsoares/sisp_payments_js/blob/main/src/index.test.js"
    click SispTests "https://github.com/fredsoares/sisp_payments_js/blob/main/src/sisp.test.js"
    click Package "https://github.com/fredsoares/sisp_payments_js/blob/main/package.json"
    click ESLint "https://github.com/fredsoares/sisp_payments_js/blob/main/.eslintrc.js"
    click Prettier "https://github.com/fredsoares/sisp_payments_js/blob/main/.prettierrc"
    click JestConfig "https://github.com/fredsoares/sisp_payments_js/blob/main/jest.config.js"
    click Readme "https://github.com/fredsoares/sisp_payments_js/blob/main/README.md"
    click License "https://github.com/fredsoares/sisp_payments_js/tree/main/LICENSE"

    classDef host fill:#D7E8FF,stroke:#0366d6
    classDef sdk fill:#BEE1FA,stroke:#1B4F72
    classDef client fill:#DFF2BF,stroke:#4F8A10
    classDef external fill:#FDEBD0,stroke:#E67E22
    classDef config fill:#F0F0F0,stroke:#333
```
