Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ It targets Quickpay API v10. Composer and GitHub releases distribute the same
tracked standalone PHAR without installing Laravel Zero at runtime.

Use `php quickpay` when running from source. See `README.md` for the public
command reference and `skills/quickpay/SKILL.md` for the agent-facing usage
command reference and `skills/quickpay-cli/SKILL.md` for the agent-facing usage
guide.

## Structure

- `app/Commands` — thin command adapters grouped by API, authentication,
- `app/Commands` — thin command adapters grouped by API, merchants,
callbacks, and payments.
- `app/Callbacks` — callback replay/watch workflows and their delivery,
resolution, signing, and input capabilities.
Expand Down Expand Up @@ -65,7 +65,7 @@ validation, and the locked-dependency audit.
- Preserve raw API JSON in `--json` mode after sanitization. Keep
machine-readable output on stdout and diagnostics or prompts on stderr.
- Restore environment variables and other global state changed by a test.
- Update `README.md`, command help, and `skills/quickpay/SKILL.md` when a command
- Update `README.md`, command help, and `skills/quickpay-cli/SKILL.md` when a command
or safety behavior changes.
- Check current Quickpay documentation before changing API behavior; do not
infer the remote contract solely from existing code.
Expand All @@ -74,9 +74,19 @@ validation, and the locked-dependency audit.

- Never expose an API key in output, errors, logs, fixtures, or command
arguments. Preserve redaction of raw, Basic-auth, and encoded forms.
- Credentials come from a non-empty `QUICKPAY_API_KEY` before
`~/.config/quickpay/config.json`. Stored credentials use atomic writes, a
`0700` directory, and a `0600` file.
- Named credentials live in `~/.config/quickpay-cli/config.json`; never read or
migrate the old `~/.config/quickpay/config.json`. Stored credentials use locked
atomic writes, a `0700` directory, and a `0600` file.
- Stored selection is explicit `--merchant`, nearest `.quickpay-cli.json`, then
global default. Invalid or stale selection never falls back silently.
- A non-empty `QUICKPAY_API_KEY` bypasses saved storage when no explicit or
project selection exists; combining them fails before API requests.
- Saved merchants carry a `read_only` flag that `QuickpayClient` enforces before
sending: a read-only merchant may send only `GET`. Commands that inspect or
confirm before mutating check it first. Only `merchants:access --read-write`
lifts it, in an interactive terminal; `QUICKPAY_API_KEY` has full access.
- Resolve credentials once per command, including long-running watchers. Plain
`merchants:active` is local status; `--check` verifies merchant API access.
- The client owns the Quickpay host, authentication, API version, and JSON
headers. Raw API input must not override them or escape the
`api.quickpay.net` origin.
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

## [Unreleased]

### Added

- Named merchants. `merchants:add`, `merchants:list`, `merchants:select`, `merchants:active` and `merchants:remove` save and choose between several Quickpay merchants, and every authenticated command takes `--merchant`.
- Project merchant bindings. `merchants:select <name> --local` writes `.quickpay-cli.json`, so commands in that folder and below use that merchant.
- Read-only merchants. `merchants:add --read-only` or `merchants:access --read-only` blocks every request except `GET` before anything is sent, and `merchants:access --read-write` allows writes again after a confirmation.
- Payment mutations, payment creation, raw mutations and callback watching name the merchant they use.
- `callbacks:watch` and `callbacks:replay` warn when `QUICKPAY_PRIVATE_KEY` is set while a saved merchant is selected.

### Changed

- The bundled agent skill is renamed from `quickpay` to `quickpay-cli`.

### Removed

- **Breaking:** the `login`, `logout` and `auth` commands. Save a merchant with `quickpay merchants:add <name>`, and use `merchants:active --check` instead of `auth --check`.
- **Breaking:** the single-key configuration in `~/.config/quickpay/config.json` is no longer read. Add your merchant again with `merchants:add`, then delete the old file. `merchants:add` reminds you while it still exists.

## [0.2.0] - 2026-08-10

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ alignment and the main structural boundaries.
- Preserve original API JSON in `--json` mode unless credential sanitization is
required.
- Use integer minor units for amounts.
- Update the README, command help, and `skills/quickpay/SKILL.md` when the CLI
- Update the README, command help, and `skills/quickpay-cli/SKILL.md` when the CLI
contract or safety workflow changes.
- Check current Quickpay documentation before changing API behavior; do not
infer the remote contract solely from existing code.
Expand Down
117 changes: 68 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
[![PHP 8.4+](https://img.shields.io/badge/PHP-8.4%2B-777BB4.svg)](https://www.php.net/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.md)

**Manage Quickpay payments and test callbacks from your terminal.**

Create payment links, manage payments through the [Quickpay API](https://learn.quickpay.net/tech-talk/api/), use JSON output in scripts or for agents, and receive signed callbacks on localhost without a tunnel.
Manage Quickpay payments, create payment links, and relay signed callbacks to localhost without a tunnel.

## Features

Expand All @@ -21,90 +19,111 @@ Create payment links, manage payments through the [Quickpay API](https://learn.q

⭐ If you like Quickpay CLI, [star it on GitHub](https://github.com/tehwave/quickpay-cli). It helps a lot!

## Installation
## Install

Quickpay CLI requires PHP 8.4 or newer.
Requires PHP 8.4 or newer.

```bash
composer global require tehwave/quickpay-cli
```

Install the bundled skill for coding agents:
## Authentication

Sign in to [Quickpay Manager](https://manage.quickpay.net/) and select your merchant
account. Open [Settings > Integration](https://quickpay.net/helpdesk/integration-setup/)
and copy the API key under **API User**. Then run:

```bash
skills add tehwave/quickpay-cli
quickpay merchants:add "My Website"
```

Authenticate with a Quickpay merchant API key:
Paste the key when prompted. Your input stays hidden, and the CLI saves the key in
`~/.config/quickpay-cli/config.json`. The first merchant becomes your default.

## Merchants

```bash
quickpay login
quickpay merchants:add "My Other Website"
quickpay merchants:select "My Other Website"
quickpay merchants:active --check
quickpay payments:list --merchant="My Website"
```

For automation, supply the API key through `QUICKPAY_API_KEY`.
To use a different merchant for a project, run
`quickpay merchants:select "My Website" --local` from the project folder. Commands in
that folder and its subfolders will use **My Website** instead of your default merchant.
You can still choose another merchant for a single command with `--merchant`.

## Usage
For scripts and CI, you can supply the API key through `QUICKPAY_API_KEY`
instead of saving a merchant. Use it outside folders with a project merchant
selected, and leave out `--merchant`.

```bash
quickpay list
```
### Read-only merchants

Use `--help` to explore any command and its options:
Keep a merchant safe from changes by blocking its write requests. It can still
list and inspect payments, but it can't create, capture, refund or cancel them,
or send a raw `POST`, `PUT`, `PATCH` or `DELETE`:

```bash
quickpay callbacks:watch --help
quickpay merchants:add "My Website" --read-only
quickpay merchants:access "My Website" --read-only
quickpay merchants:access "My Website" --read-write
```

### Watch for callbacks and relay them
A blocked request stops before anything reaches Quickpay. Replacing the key with
`merchants:add --replace` keeps the merchant read-only. `--read-write` asks you to
confirm in an interactive terminal, so a script or agent can't lift the
protection on its own.
A key in `QUICKPAY_API_KEY` always has full access.

## Payments

```bash
quickpay callbacks:watch --to=http://127.0.0.1:8000/quickpay/callback
quickpay payments:list
quickpay payments:get <payment-id> --json
quickpay payments:link <payment-id> 1000
```

Leave the watcher running while testing the payment flow. It signs and sends
payment updates to your local callback handler.
Amounts are in minor units: `1000` is DKK 10.00 for a DKK payment.
Capture, refund, cancel, and non-GET raw API requests require confirmation
or `--yes` when running unattended.

With no selector, the watcher forwards new operation callbacks for every
payment changed after it becomes ready. Pass a payment ID or `--order-id` to
narrow the watch to one payment. Existing operations are not replayed. The
watcher runs in the foreground and has no JSON mode.
Run `quickpay list` for all commands or `quickpay <command> --help` for options.

## Local callbacks

```bash
quickpay callbacks:replay <payment-id> --to=<corrected-url>
quickpay callbacks:watch --to=http://127.0.0.1:8000/quickpay/callback
```

## Development
Leave it running while testing your payment flow. It forwards new operations
for all payments in the selected merchant account. Add a payment ID to watch
one payment. Existing operations are not replayed.

To send a payment's current resource once:

```bash
composer install
composer check
composer verify
quickpay callbacks:replay <payment-id> --to=http://127.0.0.1:8000/quickpay/callback
```

`composer check` runs tests, static analysis, and formatting checks. `composer
verify` additionally enforces coverage, validates package metadata, and audits
the locked dependencies. The test suite uses HTTP fakes and does not contact
Quickpay API.

The versioned `builds/quickpay` PHAR is tracked so Packagist can install it
without Laravel Zero's dependency graph. Maintainers build it with Laravel
Zero's `app:build` command and commit it as described in `RELEASING.md`.

See [CONTRIBUTING.md](CONTRIBUTING.md) before changing commands or security behavior.

Maintainers should follow [RELEASING.md](RELEASING.md) for versioned releases.
Callbacks are signed with the merchant's private key, which the CLI fetches from
Quickpay. Set `QUICKPAY_PRIVATE_KEY` to use your own instead. Both commands warn
when it is set while a saved merchant is selected, because it may belong to
another merchant.

## Security
## For agents

Quickpay CLI keeps API keys out of command arguments and asks for confirmation before changing a payment.
Install the bundled [quickpay-cli skill](skills/quickpay-cli/SKILL.md):

See [SECURITY.md](SECURITY.md) to report a vulnerability. Never include credentials or merchant data in an issue.

## Credits
```bash
skills add tehwave/quickpay-cli
```

Created and maintained by [Peter 🌊 Jørgensen](https://peterchrjoergensen.dk).
## Contributing

Built with [Laravel Zero](https://laravel-zero.com/) and released under the [MIT License](LICENSE.md).
See [CONTRIBUTING.md](CONTRIBUTING.md), [RELEASING.md](RELEASING.md), and
[SECURITY.md](SECURITY.md).

Quickpay CLI is an independent open-source project. It is not affiliated with or endorsed by Quickpay.
Created by [Peter Jørgensen](https://peterchrjoergensen.dk). Built with
[Laravel Zero](https://laravel-zero.com/) and released under the [MIT License](LICENSE.md).
Independent of and not endorsed by Quickpay.
31 changes: 30 additions & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ Security-relevant areas include:
- callback private-key retrieval and in-memory-only handling;
- release artifact contents, checksums, and build provenance.

## Merchant credentials and selection

Saved merchant API keys live in `~/.config/quickpay-cli/config.json`, with a
`0700` directory and `0600` file. Credential updates use a persistent sibling
lock and atomic file replacement. `.quickpay-cli.json` selects an already saved
merchant by its local label; it cannot provide credentials, API headers or URLs.
Neither a binding nor selecting a merchant authorizes a payment mutation.

Explicit `--merchant` selection overrides a project binding and global default.
Malformed or stale bindings, and bindings owned by another user, fail without
selecting another merchant. A non-empty
`QUICKPAY_API_KEY` cannot be combined with an explicit or project selection.
Each command resolves its key once, so running watchers and inspect/confirm
workflows stay attached to the same credential even if local configuration
changes. Saved labels identify local configuration; actual merchant IDs come
from Quickpay resources, when available.

Each saved merchant also stores a `read_only` flag. For a read-only merchant,
`QuickpayClient` refuses every method except `GET` before sending it. Capture,
refund, cancel and raw mutations check the flag before inspecting a payment or
asking for confirmation. Making a merchant read-only works anywhere, and
`merchants:add --replace` keeps it read-only. Only `merchants:access --read-write`
allows writes again, and it needs an interactive terminal and a confirmation. A key from `QUICKPAY_API_KEY` has full
access. The flag is a local guardrail, not a Quickpay permission: anyone who can
edit the configuration file can change it.

## Local callback forwarding

`callbacks:replay` and `callbacks:watch` send a signed payment resource to the
Expand All @@ -53,7 +79,10 @@ API key, Basic authorization, or Quickpay API request headers to the callback
destination. The account private key comes from a non-empty
`QUICKPAY_PRIVATE_KEY` or the authenticated `/account/private-key` endpoint and
is retained in process memory only. It is never written to the CLI config,
stdout, stderr, or local response summaries.
stdout, stderr, or local response summaries. A manually supplied
`QUICKPAY_PRIVATE_KEY` must belong to the selected merchant. Because nothing ties
it to one, `callbacks:watch` and `callbacks:replay` warn when it is set while a
saved merchant is selected.

Because `--to` may name a public service, inspect it before running the command.
The explicit destination is the authorization to POST the payment payload; the
Expand Down
18 changes: 18 additions & 0 deletions app/Callbacks/Resolution/PrivateKeyResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Callbacks\Resolution;

use App\Credentials\ApiKey;
use App\Credentials\EnvironmentVariables;
use App\Quickpay\QuickpayClient;

Expand All @@ -28,4 +29,21 @@ public function resolve(QuickpayClient $quickpay): string

return $this->fetcher->fetch($quickpay);
}

/**
* Explains an environment private key used with a saved merchant.
*
* The override is not tied to any merchant, so it may sign callbacks with
* another merchant's key. An environment API key is paired with it on
* purpose and gets no warning.
*/
public function overrideWarning(ApiKey $apiKey): ?string
{
$merchant = $apiKey->merchant();
if ($merchant === null || $this->environment->get('QUICKPAY_PRIVATE_KEY') === null) {
return null;
}

return "Warning: QUICKPAY_PRIVATE_KEY is set, so callbacks are signed with it instead of the account private key of {$merchant}. Unset it if it belongs to another merchant.";
}
}
1 change: 0 additions & 1 deletion app/Callbacks/Signing/CallbackEnvelope.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ public function __construct(
public ?string $orderId,
public string $body,
public array $headers,
public ?string $operationId = null,
) {}
}
2 changes: 0 additions & 2 deletions app/Callbacks/Signing/CallbackEnvelopeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function make(
QuickpayResponse $response,
string $apiKey,
string $privateKey,
?string $operationId = null,
): CallbackEnvelope {
$resource = json_decode($response->rawBody);

Expand All @@ -46,7 +45,6 @@ public function make(
'QuickPay-API-Version' => QuickpayClient::API_VERSION,
'QuickPay-Checksum-Sha256' => hash_hmac('sha256', $body, $privateKey),
],
operationId: $operationId,
);
}

Expand Down
1 change: 0 additions & 1 deletion app/Callbacks/Watching/CallbackWatchRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ private function deliverOperation(
$payment,
$apiKey,
$privateKey,
$operationId,
);

$attempt = 0;
Expand Down
13 changes: 2 additions & 11 deletions app/Commands/Api/ApiRequestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ public function handle(
$this->option('data-json'),
(array) $this->option('header'),
);
$authenticated->client->authorize($request->method);

if ($request->mutation) {
$this->writeMerchantContext($authenticated);
$this->writeSafetyLine("Quickpay API request: {$request->method}");

if (! $confirmation->approve(
Expand Down Expand Up @@ -100,17 +102,6 @@ public function handle(
});
}

private function writeSafetyLine(string $message): void
{
// Keep stdout machine-readable in JSON mode without hiding mutation
// summaries and confirmation prompts from the operator.
$output = $this->option('json')
? $this->getOutput()->getErrorStyle()
: $this->getOutput();

$output->writeln($message, OutputInterface::OUTPUT_RAW);
}

private function confirmMutation(): bool
{
if (! $this->option('json')) {
Expand Down
Loading
Loading