Skip to content

Commit

Permalink
A few fixes to README.md (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe committed Jul 15, 2019
1 parent 1d7307f commit 5244cae
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 53 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ trim_trailing_whitespace = true
[*.go]
indent_style = tab
indent_size = 4

[*.md]
indent_style = space
indent_size = 2
132 changes: 79 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@ The main focus for this initial release is to improve the developer while integr

## Table of Contents

* [Stripe CLI](#stripe-cli)
* [Installation](#installation)
* [Download the CLI](#download-the-cli)
* [Commands](#commands)
* [login](#login)
* [listen](#listen)
* [get, post, and delete](#get-post-and-delete)
* [trigger](#trigger)
* [Development](#development)
* [Installing](#installing)
* [Deploying](#deploying)
* [Development](#development-1)
* [Tests](#tests)
* [Stripe CLI](#stripe-cli)
* [Installation](#installation)
* [Download the CLI](#download-the-cli)
* [Commands](#commands)
* [login](#login)
* [listen](#listen)
* [get, post, and delete](#get-post-and-delete)
* [trigger](#trigger)
* [Developing the Stripe CLI](#developing-the-stripe-cli)
* [Installation](#installation-1)
* [Tests](#tests)

## Installation

Expand All @@ -34,11 +32,15 @@ The main focus for this initial release is to improve the developer while integr
> **Note:** For Homebrew, you’ll need to create a personal access token because this repository is still private. Make sure to save your access token since GitHub won’t show it to you again.
1. Create a [personal access token](https://github.com/settings/tokens) on github.com. Provide a name like “Stripe CLI: Homebrew download” and enable repository access.

2. Copy the token github.com provides and add a line to your terminal configuration, e.g. `~/.bash_profile` or `~/.zshrc`:
```
export HOMEBREW_GITHUB_API_TOKEN=foobar
```

```sh
export HOMEBREW_GITHUB_API_TOKEN=foobar
```

3. Run `brew tap stripe/stripe-cli`

4. Run `brew install stripe`

🎉 The `stripe` command should now work!
Expand All @@ -49,25 +51,31 @@ export HOMEBREW_GITHUB_API_TOKEN=foobar

The Stripe CLI runs commands using a global configuration or project-specific configuration. To configure the CLI globally, run:

$ stripe login
```sh
$ stripe login
```

You'll be redirected to the Stripe dashboard to confirm that you want to give access to your account to the CLI. After confirming, a new API key will be created and returned to the CLI.

You can create project-specific configurations with the `--project-name` flag, which can be used in any context. To create an initial configuration:

$ stripe login --project-name=rocket-rides
```sh
$ stripe login --project-name=rocket-rides
```

If you do not provide the `--project-name` flag for a command, it will default to the global configuration.

All configurations are stored in `~/.config/stripe/config.toml` but you can use the [`XDG_CONFIG_HOME`](https://wiki.archlinux.org/index.php/XDG_Base_Directory) environment variable to override this location.

You can also provide an API key manually by passing the `--interactive` flag:

$ stripe login --interactive
Enter your API key: sk_test_foobar
Your API key is: sk_test_**obar
How would you like to identify this device in the Stripe Dashboard? [default: st-tomer1]
You're configured and all set to get started
```sh
$ stripe login --interactive
Enter your API key: sk_test_foobar
Your API key is: sk_test_**obar
How would you like to identify this device in the Stripe Dashboard? [default: st-tomer1]
You're configured and all set to get started
```
### `listen`
Expand All @@ -76,23 +84,30 @@ The `listen` command establishes a direct connection with Stripe, delivering web
> **Note:** You do not need to configure any webhook endpoints in your Dashboard to receive webhooks with the CLI.
By default, `listen` accepts all webhook events displays them in your terminal. To forward events to your local app, use the `--forward-to` flag with the location:
- `--forward-to localhost:9000`
- `--forward-to https://example.com/hooks`
* `--forward-to localhost:9000`
* `--forward-to https://example.com/hooks`
Using `--forward-to` will return a [webhook signing secret](https://stripe.com/docs/webhooks/signatures), which you can add to your application's configuration:

$ stripe listen --forward-to https://example.com/hooks
> Ready! Your webhook signing secret is whsec_oZ8nus9PHnoltEtWZ3pGITZdeHWHoqnL (^C to quit)
```sh
$ stripe listen --forward-to https://example.com/hooks
> Ready! Your webhook signing secret is whsec_oZ8nus9PHnoltEtWZ3pGITZdeHWHoqnL (^C to quit)
```

The webhook signing secret provided will not change between restarts to the `listen` command.

You can specify which events you want to listen to using `--events` with a comma-separated [list of Stripe events](https://stripe.com/docs/api/events/list).

$ stripe listen --events=payment_intents.created,payment_intents.updated
```sh
$ stripe listen --events=payment_intents.created,payment_intents.updated
```

You may have webhook endpoints you've already configured with specific Stripe events in your Dashboard. The Stripe CLI can automatically listen to those events with the `--load-from-webhooks-api` flag, used alongside the `--forward-to` flag. This will read any endpoints configured in test mode for your account and forward associated events to the provided URL:
$ stripe listen --load-from-webhooks-api --forward-to https://example.com/hooks
```sh
$ stripe listen --load-from-webhooks-api --forward-to https://example.com/hooks
```
> **Note:** You will receive events for all interactions on your Stripe account. There is currently no way to limit events to only those that a specific user created.
Expand All @@ -102,11 +117,15 @@ The CLI has three commands that let you interact with the Stripe API in test mod
For example, you can retrieve a specific charge:
$ stripe get /charges/ch_1EGYgUByst5pquEtjb0EkYha
```sh
$ stripe get /charges/ch_1EGYgUByst5pquEtjb0EkYha
```
You can also pass data in using the `-d` flag:
$ stripe post /charges -d amount=100 -d source=tok_visa -d currency=usd
```
$ stripe post /charges -d amount=100 -d source=tok_visa -d currency=usd
```
These commands support many of the features on the Stripe API (e.g. selecting a version, pagination, and expansion) through command-line flags, so you won't need to provide specific headers.

Expand All @@ -123,50 +142,57 @@ These commands support many of the features on the Stripe API (e.g. selecting a
| get | `-a`, `--starting-after` | Retrieve the next page in the list. This is a cursor for pagination and should be an object ID | `--starting-after cust_1234abc` |
| get | `-b`, `--ending-before` | Retrieve the previous page in the list. This is a cursor for pagination and should be an object ID | `--ending-before cust_1234abc` |


You can pipe the output of these commands to other tools. For example, you could use `[jq](https://stedolan.github.io/jq/)` to extract information from JSON the API returns, and then use that information to trigger other API requests.
You can pipe the output of these commands to other tools. For example, you could use [jq](https://stedolan.github.io/jq/) to extract information from JSON the API returns, and then use that information to trigger other API requests.

Here’s a simple example that lists `past_due` subscriptions, extracts the IDs, and cancels those subscriptions:

$ stripe get /subscriptions -d status=past_due | jq ".data[].id" | xargs -I % -p stripe delete /subscriptions/%
```sh
$ stripe get /subscriptions -d status=past_due | jq ".data[].id" | xargs -I % -p stripe delete /subscriptions/%
```

### `trigger`

The CLI will allow you to trigger a few test webhook events to conduct local testing. These test webhook events are real objects on the API and may trigger other webhook events as part of the test (e.g. triggering `payment_intent.succeeded` will also trigger `payment_intent.created`).

The webhook events we currently support are:

- `charge.captured`
- `charge.failed`
- `charge.succeeded`
- `customer.created`
- `customer.updated`
- `customer.source.created`
- `customer.source.updated`
- `customer.subscription.updated`
- `invoice.created`
- `invoice.finalized`
- `invoice.payment_succeeded`
- `invoice.updated`
- `payment_intent.created`
- `payment_intent.payment_failed`
- `payment_intent.succeeded`
- `payment_method.attached`
* `charge.captured`
* `charge.failed`
* `charge.succeeded`
* `customer.created`
* `customer.updated`
* `customer.source.created`
* `customer.source.updated`
* `customer.subscription.updated`
* `invoice.created`
* `invoice.finalized`
* `invoice.payment_succeeded`
* `invoice.updated`
* `payment_intent.created`
* `payment_intent.payment_failed`
* `payment_intent.succeeded`
* `payment_method.attached`

To trigger an event, run:

$ stripe trigger <event>
```sh
$ stripe trigger <event>
```

## Developing the Stripe CLI

### Installation

The Stripe CLI is built using Go. To download and compile the source code, run:

$ go get -u github.com/stripe/stripe-cli/...
```sh
$ go get -u github.com/stripe/stripe-cli/...
```

### Tests

You can run tests with:

$ go test ./...
```sh
$ make test
```

0 comments on commit 5244cae

Please sign in to comment.