# Replay Exported Non-STK C2B Transactions/Especially is they were transmitted and still failed

This script replays exported transaction payloads from a JSON file to the application endpoint:

`/api/payment/c2b/nonstk/confirmation`

The endpoint queues each confirmation for async processing.

## Script

`php scripts/replay_exported_transactions.php`

## Purpose

- Read a JSON file containing transaction exports
- Extract the nested `payload` object from each record
- POST each payload to the non-STK C2B confirmation endpoint
- Print the HTTP response and status for each payload

## Expected JSON format

The script supports either:

- A JSON array of exported transaction objects where each record contains a `payload` object

Example:

```json
[
  {
    "id": 97,
    "type": "confirmation",
    "status": "forwarded",
    "created_at": "2026-06-22T07:26:25.000000Z",
    "payload": {
      "TransactionType": "Pay Bill",
      "TransID": "UFM5V8PXWE",
      "TransTime": "20260622102624",
      "TransAmount": "1700.00",
      "BusinessShortCode": "787306",
      "BillRefNumber": "8398423",
      "InvoiceNumber": null,
      "OrgAccountBalance": "34128.00",
      "ThirdPartyTransID": null,
      "MSISDN": "...",
      "FirstName": "ROZANA"
    }
  }
]
```

## Usage

```bash
php scripts/replay_exported_transactions.php --file="C:\Users\HomePC\Downloads\transactions_97_to_112_2026-06-22_13-59-07.json"
```

If you need to target a different host or port:

```bash
php scripts/replay_exported_transactions.php --file="C:\Users\HomePC\Downloads\transactions_97_to_112_2026-06-22_13-59-07.json" --url="http://localhost:8000/api/payment/c2b/nonstk/confirmation"
```

## Notes

- The script uses `.env` `APP_URL` to build the default endpoint if no `--url` is supplied.
- If the JSON file contains a top-level `payloads` array, the script can also extract from that.
- Each payload is posted as raw JSON with `Content-Type: application/json`.
- Responses are printed to the console, including HTTP status and response body.

## File location

`c:\xampp\htdocs\LendCore\scripts\replay_exported_transactions.php`
