关于 Stripe CLI
Stripe CLI 让开发者在本地环境中转发 webhook、触发测试事件和调用 Stripe API。通过 stripe login 认证后,可以快速验证支付流程、订阅和其他金融事务的实现。
主要功能
- 01将线上 webhook 转发到本地开发环境
- 02触发支付、订阅等测试事件进行验证
- 03直接调用 Stripe API 进行集成测试
适用场景
- 01在本地验证支付流程和 webhook 处理逻辑
- 02测试订阅、发票等金融工作流
- 03快速迭代 Stripe 集成而无需部署到生产环境
安装
选择你的系统或包管理器,复制命令到终端运行。
安装完成后运行stripe --version确认安装成功。
命令示例
常用命令按使用顺序排列。
详细介绍
Stripe CLI
Stripe CLI 可帮助你直接在终端中构建、测试和管理 Stripe 集成。
使用 CLI,你可以:
- 安全地测试 Webhook,无需依赖第三方软件
- 触发 Webhook 事件,或重新发送事件以便轻松测试
- 实时查看 API 请求日志
- 创建、检索、更新或删除 API 对象。

安装
Stripe CLI 支持 macOS、Windows 和 Linux,适用于 Ubuntu、Debian、RedHat 和 CentOS 等发行版。
npm(macOS、Linux、Windows)
如果已安装 Node.js >= 18,可以通过 npm 安装:
npm install -g @stripe/cli
你也可以通过 npx 直接执行命令,但这不会将 stripe 添加到你的 PATH:
npx @stripe/cli login
macOS
Homebrew:
brew install stripe
Linux
apt(Debian、Ubuntu):
curl -s https://packages.stripe.dev/api/security/keypair/stripe-cli-gpg/public | gpg --dearmor | sudo tee /usr/share/keyrings/stripe.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/stripe.gpg] https://packages.stripe.dev/stripe-cli-debian-local stable main" | sudo tee -a /etc/apt/sources.list.d/stripe.list
sudo apt update
sudo apt install stripe
yum/dnf(RedHat、Fedora、CentOS):
echo -e "[Stripe]\nname=stripe\nbaseurl=https://packages.stripe.dev/stripe-cli-rpm-local/\nenabled=1\ngpgcheck=0" | sudo tee -a /etc/yum.repos.d/stripe.repo
sudo yum install stripe
Windows
WinGet:
winget install Stripe.StripeCLI
Scoop:
scoop bucket add stripe https://github.com/stripe/scoop-stripe-cli.git
scoop install stripe
Docker
CLI 也提供 Docker 镜像:stripe/stripe-cli。
docker run --rm -it stripe/stripe-cli version
stripe version x.y.z (beta)
使用 Docker 设置密码存储
测试模式无需密码存储,但如果你希望执行实时模式请求,则需要进行设置。
你也可以按命令添加
--api-key标志,以执行实时模式请求。
- 创建
entrypoint.sh
#!/bin/sh
if ! [ -f ~/.gnupg/trustdb.gpg ] ; then
chmod 700 ~/.gnupg/
gpg --quick-generate-key stripe-live # This will generate a gpg key called "stripe-live"
fi
if ! [ -f ~/.password-store/.gpg-id ] ; then
pass init stripe-live # This will initialize a password store record named "stripe-live", using the gpg key above
pass insert stripe-live # This will insert value for the password store "stripe-live", which we will put Stripe Live Secret Key in
fi
string="$@"
liveflag="--live"
if [ -z "${string##*$liveflag*}" ] ;then
OPTS="--api-key $(pass show stripe-live)" # This will use the content of the password store "stripe-live" which was inserted in line 8
fi
#pass insert stripe-live
/bin/stripe $@ $OPTS
- 创建 Docker 文件
Dockerfile-cli
FROM stripe/stripe-cli:vx.x.x
RUN apk add pass gpg-agent
COPY ./entrypoint.sh /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]
- 构建 Docker 镜像
docker build -t stripe-cli -f Dockerfile-cli .
- 使用密码卷运行 Docker 镜像,并将
$command替换为相应的 Stripe CLI 命令(例如customers list)
docker run --rm -it -v stripe-config://root/.config/stripe/ -v stripe-gpg://root/.gnupg/ -v stripe-pass://root/.password-store/ stripe-cli $command
如需执行实时模式请求,请在
$command后添加--live。
不使用包管理器
从 GitHub Releases 页面下载适用于你平台的最新版本。
macOS:
tar -xvf stripe_X.X.X_mac-os_ARCH.tar.gz
你也可以将 stripe 二进制文件移到 /usr/local/bin,以便全局访问。
Linux:
tar -xvf stripe_X.X.X_linux_x86_64.tar.gz
将 stripe 二进制文件移到 PATH 中的某个目录。
Windows:
解压 stripe_X.X.X_windows_x86_64.zip,并将包含 stripe.exe 的路径添加到 Path 环境变量。
注意: 防病毒软件可能会将此二进制文件标记为不安全。这是误报;详情请参阅 issue #692。
升级
npm(macOS、Linux、Windows)
npm install -g @stripe/cli
macOS
Homebrew:
brew upgrade stripe
Linux
apt(Debian、Ubuntu):
sudo apt update && sudo apt upgrade stripe
yum/dnf(RedHat、Fedora、CentOS):
yum update stripe
Windows
WinGet:
winget upgrade Stripe.StripeCLI
Scoop:
scoop update stripe
Docker
docker pull stripe/stripe-cli:latest
由于 Docker 容器是临时的,因此不支持 stripe login 命令。请改用 --api-key 标志。
不使用包管理器
从 GitHub Releases 页面下载适用于你平台的最新版本,并替换现有二进制文件。
卸载
1. 移除插件
包管理器只会移除 stripe 二进制文件,不会移除已安装的插件。请先在 stripe 二进制文件仍可用时移除插件:
stripe plugin uninstall --all
2. 移除 CLI
npm(macOS、Linux、Windows):
npm uninstall -g @stripe/cli
Homebrew(macOS):
brew uninstall stripe
apt(Debian、Ubuntu):
sudo apt remove stripe
yum/dnf(RedHat、Fedora、CentOS):
sudo yum remove stripe
WinGet(Windows):
winget uninstall Stripe.StripeCLI
Scoop(Windows):
scoop uninstall stripe
Docker:
docker rmi stripe/stripe-cli
不使用包管理器:
删除你下载的 stripe 二进制文件。
3. 可选:移除配置和凭据
卸载 CLI 时会保留你的配置,以便重新安装后保留项目和设置。只有你自行移除时,配置才会被删除:
# Clear stored credentials for every project you are logged into
stripe logout --all
# Remove all remaining CLI configuration
rm -rf "${XDG_CONFIG_HOME:-$HOME/.config}/stripe"
使用方法
安装 CLI 后,即可使用 stripe 命令。
stripe [command]
# Run `--help` for detailed information about CLI commands
stripe [command] help
命令
Stripe CLI 支持多种命令。以下是一些最常用的命令:
文档
完整参考请参阅 CLI 参考网站
遥测
Stripe CLI 包含遥测功能,可收集部分使用数据。详情请参阅遥测参考。
反馈
有任何反馈想告诉我们吗?欢迎随时通过反馈告诉我们。
贡献
有关开发 Stripe CLI 的详情,请参阅 CONTRIBUTING.md。所有贡献均受行为准则约束。
许可证
版权所有 (c) Stripe。保留所有权利。
根据 Apache License 2.0 license 授权。