|
| 1 | +# twoctl |
| 2 | + |
| 3 | +Command-line interface for the [Two](https://two.inc) merchant APIs. Generated from the [public OpenAPI specs](https://github.com/two-inc/docs/tree/main/openapi), so every endpoint is exposed as a subcommand. |
| 4 | + |
| 5 | +## Install |
| 6 | + |
| 7 | +### Homebrew |
| 8 | + |
| 9 | +```sh |
| 10 | +brew install two-inc/tap/twoctl |
| 11 | +``` |
| 12 | + |
| 13 | +### Binary releases |
| 14 | + |
| 15 | +Download from [releases](https://github.com/two-inc/twoctl/releases) and place on `$PATH`. |
| 16 | + |
| 17 | +### From source |
| 18 | + |
| 19 | +```sh |
| 20 | +go install github.com/two-inc/twoctl/cmd/twoctl@latest |
| 21 | +``` |
| 22 | + |
| 23 | +## Authenticate |
| 24 | + |
| 25 | +`twoctl` reads your API key from (in order): |
| 26 | + |
| 27 | +1. `--api-key` flag |
| 28 | +2. `TWO_API_KEY` env var |
| 29 | +3. `~/.config/two/config.yaml` |
| 30 | + |
| 31 | +```sh |
| 32 | +twoctl auth login # prompts for an API key |
| 33 | +twoctl auth whoami # verify the key works |
| 34 | +``` |
| 35 | + |
| 36 | +API keys are obtained from the [Two merchant portal](https://portal.two.inc). |
| 37 | +Sandbox keys are prefixed `secret_test_`; production keys `secret_prod_`. `twoctl` |
| 38 | +infers the environment from the prefix; override with `--env sandbox|prod`. |
| 39 | + |
| 40 | +## Usage |
| 41 | + |
| 42 | +The command tree mirrors the API surface: |
| 43 | + |
| 44 | +``` |
| 45 | +twoctl checkout order-create --file order.json |
| 46 | +twoctl checkout order-get <order-id> |
| 47 | +twoctl billing-account list |
| 48 | +twoctl repay payment-create ... |
| 49 | +twoctl recourse ... |
| 50 | +twoctl company search --org-no 123456789 --country NO |
| 51 | +twoctl limits buyer-get <buyer-id> |
| 52 | +``` |
| 53 | + |
| 54 | +Every subcommand supports `--help` listing flags derived from the OpenAPI |
| 55 | +operation. Request bodies can be passed via `--file path.json` or `--data '{...}'`. |
| 56 | + |
| 57 | +## APIs covered |
| 58 | + |
| 59 | +| API | Subcommand | Spec | |
| 60 | +| --- | --- | --- | |
| 61 | +| Checkout (Order) | `twoctl checkout` | [checkout-api.yaml](openapi/checkout-api.yaml) | |
| 62 | +| Billing Account | `twoctl billing-account` | [billing-account-api.yaml](openapi/billing-account-api.yaml) | |
| 63 | +| Repay | `twoctl repay` | [repay-api.yaml](openapi/repay-api.yaml) | |
| 64 | +| Recourse | `twoctl recourse` | [recourse-api.yaml](openapi/recourse-api.yaml) | |
| 65 | +| Company | `twoctl company` | [company-api.yaml](openapi/company-api.yaml) | |
| 66 | +| Limits | `twoctl limits` | [limits-api.yaml](openapi/limits-api.yaml) | |
| 67 | + |
| 68 | +## Regeneration |
| 69 | + |
| 70 | +The `openapi/` specs are vendored from [`two-inc/docs`](https://github.com/two-inc/docs/tree/main/openapi). |
| 71 | +When that source changes, a `repository_dispatch` event fires the [`regenerate.yml`](.github/workflows/regenerate.yml) workflow, |
| 72 | +which pulls fresh specs, runs codegen, and opens a PR. |
| 73 | + |
| 74 | +To regenerate locally: |
| 75 | + |
| 76 | +```sh |
| 77 | +./scripts/codegen.sh |
| 78 | +go build ./... |
| 79 | +``` |
| 80 | + |
| 81 | +## Contributing |
| 82 | + |
| 83 | +This repository is generated from the OpenAPI specs in [`two-inc/docs`](https://github.com/two-inc/docs). |
| 84 | +Bug reports and PRs for the CLI itself (flags, output formatting, ergonomics) are welcome here. |
| 85 | +For API behaviour or schema changes, please open an issue against `two-inc/docs`. |
| 86 | + |
| 87 | +## Licence |
| 88 | + |
| 89 | +MIT - see [LICENSE](LICENSE). |
0 commit comments