05-Specifications / 05.03.Payment-Receipt-Feature.spec

05.03.Payment Receipt Feature.spec

05.03. Payment Receipt Feature.spec

1. Objective

To provide an automated way to generate PDF payment receipts from the nda-edw-utl framework and deliver them via email or provide them as downloads.

2. Requirements

3. Architecture & Workflow

3.1 Proposed Actions

do_fetch_payment_data (New)

Fetches transaction details directly from the payment provider's API.

Arguments: | Argument | Description | Required | | :--- | :--- | :--- | | --provider | Payment provider (e.g., stripe, paypal) | No (Default: stripe) | | --id | Transaction/Payment Intent ID | Yes |

Workflow: 1. Auth: Load the provider's API key from ~/.osp/.trd/<provider>-api.conf.sh. 2. Request: Use curl to fetch JSON data from the provider's REST API. * Example (Stripe): curl https://api.stripe.com/v1/payment_intents/{{ID}} -u {{STRIPE_KEY}}: 3. Output: Store the raw JSON in dat/payments/{{ID}}.json for subsequent processing.

do_generate_payment_receipt (Updated)

Orchestrates the data fetching, template filling, and PDF generation.

Arguments: | Argument | Description | Required | | :--- | :--- | :--- | | --id | Transaction/Payment Intent ID | Yes | | --email | Recipient's email address | No (Overrides fetched email) | | --template | Path to custom Markdown template | No |

Workflow: 1. Data Fetch: Call do_fetch_payment_data --id {{ID}}. 2. Extraction: Use jq to extract amount, currency, description, customer_email, etc., from the JSON. 3. Templating: Inject extracted data into doc/md/templates/receipt.md. 4. Rendering: Convert to PDF via pandoc + pdflatex. 5. Delivery: Send PDF as an attachment if an email is available.

4. Feasibility Summary

The implementation is straightforward within the existing run.sh framework: - Direct API Call: Leveraging curl and jq makes it easy to integrate with any RESTful payment API. - Environment: pandoc, pdflatex, curl, and jq are already present. - Effort: ~4-6 development hours to implement both actions, templating, and provider-specific API logic.

5. Directory Updates

New directories and files needed: - doc/md/templates/receipt.md: The base Markdown template. - src/bash/run/generate-payment-receipt.func.sh: The core action logic. - dat/receipts/: Destination for generated PDF files.


Operational Specification v1.0.0 — NDA EDW Payment Systems