使用 Stripe CLI 在 Windows 开发机上测试 Webhooks

6

我想在本地Windows开发机上测试stripe Webhooks,stripe文档提到stripe CLI是测试Webhooks端点和发送虚假事件的最佳/更容易的方法,我按照文档将stripe CLI下载到我的Windows机器中,我将可执行文件提取到我的桌面,但现在我不知道如何在cmd中正确执行命令。

我的桌面上有stripe.exe,我首先尝试简单地点击它,命令提示符打开并显示以下消息,在几秒钟后命令提示符关闭。

This is a command line tool.

You need to open cmd.exe and run it from there.

之后我尝试打开一个CMD窗口,将stripe.exe拖放到选项卡中,我得到了以下命令列表:

C:\Users\GABRIEL>C:\Users\GABRIEL\Desktop\stripe.exe
The official command-line tool to interact with Stripe.

Before using the CLI, you'll need to login:

  $ stripe login

If you're working on multiple projects, you can run the login command with the
--project-name flag:

  $ stripe login --project-name rocket-rides

Usage:
  stripe [command]

Webhook commands:
  listen                        Listen for webhook events
  trigger                       Trigger test webhook events

Stripe commands:
  logs                          Interact with Stripe API request logs
  status                        Check the status of the Stripe API

Resource commands:
  get                           Quickly retrieve resources from Stripe
  charges                       Make requests (capture, create, list, etc) on charges
  customers                     Make requests (create, delete, list, etc) on customers
  payment_intents               Make requests (cancel, capture, confirm, etc) on payment intents
  ...                           To see more resource commands, run `stripe resources help`

Other commands:
  completion                    Generate bash and zsh completion scripts
  config                        Manually change the config values for the CLI
  feedback                      Provide us with feedback on the CLI
  fixtures                      Run fixtures to populate your account with data
  help                          Help about any command
  login                         Login to your Stripe account
  logout                        Logout of your Stripe account
  open                          Quickly open Stripe pages
  samples                       Sample integrations built by Stripe
  serve                         Serve static files locally
  version                       Get the version of the Stripe CLI

Flags:
      --api-key string        Your API key to use for the command
      --color string          turn on/off color output (on, off, auto)
      --config string         config file (default is
                              $HOME/.config/stripe/config.toml)
      --device-name string    device name
  -h, --help                  help for stripe
      --log-level string      log level (debug, info, warn, error)
                              (default "info")
  -p, --project-name string   the project name to read from for config
                              (default "default")
  -v, --version               Get the version of the Stripe CLI

Use "stripe [command] --help" for more information about a command.

C:\Users\GABRIEL>

正如您所见,我无法输入任何命令,例如

stripe login

我在命令行中无法使用Stripe CLI执行任何操作。

6个回答

4
你需要进入存储 stripe.exe 的文件夹。在你的情况下,应该是这样的: cd 到那个文件夹中。
C:\Users\GABRIEL> cd Desktop

然后你只需从那里运行条纹命令,它就会起作用。例如:

C:\Users\GABRIEL\Desktop> stripe --help

或者

C:\Users\GABRIEL\Desktop> stripe login

1
它现在无法正常工作。抛出错误:“stripe”不被识别为内部或外部命令, - Surjith S M
你需要使用命令提示符,而不是PowerShell。 - undefined

3
要将stripe.exe文件的路径添加到Windows的PATH环境变量中,请按照以下步骤操作:
按下Windows键+R打开运行对话框。
在运行对话框中输入"sysdm.cpl"并按Enter键。这将打开系统属性窗口。
在系统属性窗口中,点击"高级"选项卡。
点击"环境变量"按钮。这将打开环境变量窗口。
在环境���量窗口中,在"系统变量"部分,向下滚动并找到"Path"变量。选择它,然后点击"编辑"按钮。
在编辑环境变量窗口中,点击"新建"按钮添加一个新条目。
输入stripe.exe文件所在目录的完整路径。例如,如果stripe.exe文件位于C:\Users\YourUsername\Desktop\thefolderwherestripe.exeislocated文件夹中,你需要将'C:\Users\YourUsername\Desktop\thefolderwherestripe.exeislocated'作为一个新条目添加进去。
点击"确定"关闭所有窗口。
可能不是必需的,但最好重新启动计算机。
重新启动后,您应该能够全局访问stripe cli,在命令提示符中尝试stripe -v命令。
请注意:很多人都在这样添加路径

这是错误的方式: C:\Users\YourUsername\Desktop\foldername\stripe.exe

这是正确的方式: C:\Users\YourUsername\Desktop\stripefolder


1
这个问题的唯一正确答案。谢谢! - Prakhar Rathi
1
非常欢迎,我自己也曾经困惑过,当我跟随随机的教程和视频时...为什么每个人都做错了... - Adam.M

0

在Windows中,".\stripe login"有效,但其他命令无效。我使用stripe login时遇到了很多问题,尝试了100次后它仍然不起作用。最终我使用了.\stripe login命令,成功解决了问题。


1
请点击以下链接学习如何在stackoverflow上撰写优秀的答案:https://stackoverflow.com/help/how-to-answer - DaniyalAhmadSE

0

下载zip文件

提取获取其中的.exe文件

打开命令提示符(cmd)

定位到文件路径

并运行 "stripe.exe"

C:MyFolder> stripe.exe


0
我们可以直接使用文件来运行Stripe登录,就像这样。
请转到存储了stripe.exe文件的文件夹, 然后在那里打开终端,只需输入 .\stripe.exe login

-1

使用系统变量

我知道这是一个老问题,但我想发布这个相当简单的答案,它在以后遇到这类问题时也很有用。

我认为其他答案在使用一次时也是不错的选择,但当您在此处持续使用条纹命令时,这是我的解决方案:

  1. 在您可以轻松访问的地方创建一个新文件夹,例如在文档文件夹中。我称之为custom-commands,您可以随意命名。

  2. 在文件夹内创建一个新的记事本文件,并将以下代码粘贴到其中:

@echo off

set cwd=%cd%
set stripePath=C:\Path\To\Stripe\Location
cd /d %stripePath% && stripe %*
cd /d %cwd%

set cwd=
set stripePath=

注意stripePath需要设置为stripe.exe所在的位置。

该脚本告诉您的cmd stripe位于哪里。

  1. 在Windows搜索功能中搜索系统变量,打开应用程序,会提示出现以下屏幕: System variables prompt

  2. 点击系统变量,然后编辑用户路径User path

  3. 添加新路径: enter image description here

  • 路径需要指向你新建的文件夹,我的文件夹名为: custom-commands。

  • 你可能需要重启电脑,然后只需在 cmd 中输入 stripe 进行测试。

  • 就是这样!这也有一个主要的好处,因为无论何时你需要类似的东西,你只需要创建 .bat 文件并添加自己的脚本!


    网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,
    原文链接