# 设置您的开发环境
熟悉 Stripe CLI 和我们的服务器端 SDK。
查看我们的[无代码文档](https://docs.stripe.com/no-code.md),使用我们合作伙伴目录中的[预构建解决方案](https://stripe.com/partners/directory),或聘请 [Stripe 认证专家](https://stripe.com/partners/directory?t=Consulting)。
您可以通过 Stripe 的服务器端 SDK 和命令行接口 (CLI) 与 Stripe 的 REST API 进行交互。从 Stripe CLI 开始,简化您的开发环境并进行 API 调用。
使用 SDK 可以避免编写样板代码。要开始从您的环境发送请求,请选择一种语言,按照其快速入门指南进行。
> #### Chrome 扩展程序
>
> 建议您在自己的网站上构建与 Stripe 的支付集成(例如 [Elements](https://docs.stripe.com/payments/elements.md) 或 [Checkout](https://docs.stripe.com/payments/checkout.md))。然后,设置您的 Chrome 扩展程序,在用户准备好完成购买时使他们转至此支付页面。
>
> 这种方法比尝试直接在扩展中处理付款更安全、更易于维护。
# Ruby
> This is a Ruby for when lang is ruby. View the full page at https://docs.stripe.com/get-started/development-environment?lang=ruby.
在本快速入门中,您将安装 [Stripe CLI](https://docs.stripe.com/stripe-cli.md)。它是一个必不可少的工具,让您可以通过命令行访问 Stripe 集成。您还将安装 [Stripe Ruby 服务器端 SDK](https://github.com/stripe/stripe-ruby),以便从 Ruby 编写的应用程序访问 Stripe API。
## 所学内容
本快速指南中,您将学会如何:
- 如何在不编写代码的情况下调用 Stripe API
- 如何用 RubyGems 的 Bundler 管理第三方依赖
- 如何安装最新的 Stripe Ruby SDK v18.4.0
- 如何发送第一个 SDK 请求
## 初始设置
首先,[创建 Stripe 账户](https://dashboard.stripe.com/register)或[登录](https://dashboard.stripe.com/login)。
## 设置 Stripe CLI
首先,[创建 Stripe 账户](https://dashboard.stripe.com/register)或[登录](https://dashboard.stripe.com/login)。
### 安装
在命令行中,使用一个安装脚本或为您的操作系统下载并提取一个有版本号的归档文件,完成 CLI 的安装。
#### homebrew
要用 [homebrew](https://brew.sh/) 安装 Stripe CLI,请运行:
```bash
brew install stripe/stripe-cli/stripe
```
如果您在 Linux 版本的 homebrew 上运行该命令,则此命令将失败,但您可以使用此替代方法或按照 Linux 选项卡上的说明进行操作。
```bash
brew install stripe-cli
```
#### apt
> 用于 CLI 的 Debian 构建版本可在 JFrog 的https://packages.stripe.dev,获取,该域名并非 Stripe 所有。当您访问此 URL 时,它将会重定向至 Jfrog 工件列表。
要在基于 Debian 和 Ubuntu 的发行版本上安装 Stripe CLI:
1. Add Stripe CLI’s GPG key to the apt sources keyring:
```bash
curl -s https://packages.stripe.dev/api/security/keypair/stripe-cli-gpg/public | gpg --dearmor | sudo tee /usr/share/keyrings/stripe.gpg
```
1. 将 CLI 的 APT Repository 添加到 apt sources list:
```bash
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
```
1. 更新软件包列表:
```bash
sudo apt update
```
1. 安装 CLI:
```bash
sudo apt install stripe
```
#### yum
> 用于 CLI 的 RPM 构建版本可在 JFrog 的https://packages.stripe.dev,获取,该域名并非 Stripe 所有。当您访问此 URL 时,它将会重定向至 Jfrog 工件列表。
要在基于 RPM 的发行版本上安装 Stripe CLI:
1. 将 CLI 的 yum repository 添加到 yum 源列表:
```bash
echo -e "[Stripe]\nname=stripe\nbaseurl=https://packages.stripe.dev/stripe-cli-rpm-local/\nenabled=1\ngpgcheck=0" >> /etc/yum.repos.d/stripe.repo
```
1. 安装 CLI:
```bash
sudo yum install stripe
```
#### Scoop
要用 [Scoop](https://scoop.sh/) 安装 Stripe CLI,请运行:
```bash
scoop bucket add stripe https://github.com/stripe/scoop-stripe-cli.git
```
```bash
scoop install stripe
```
#### macOS
要在没有 homebrew 的 macOS 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载您的 CPU 结构类型的最新的 `mac-os` tar.gz 文件。
1. 解压文件:`tar -xvf stripe_[X.X.X]_mac-os_[ARCH_TYPE].tar.gz`。
或者,将二进制文件安装在可以全局执行的位置(例如,`/usr/local/bin`)。
#### Linux
要在没有软件包管理器的 Linux 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载最新的 `linux` tar.gz 文件。
1. 解压文件:`tar -xvf stripe_X.X.X_linux_x86_64.tar.gz`.
1. 将 `./stripe` 移到您的执行路径。
#### Windows
要在没有 Scoop 的 Windows 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载最新的 `windows` zip 文件
1. 解压 `stripe_X.X.X_windows_x86_64.zip` 文件。
1. 将解压缩后的 `stripe.exe` 文件的路径添加到 `Path` 环境变量中。若要了解如何更新环境变量,请参阅 [Microsoft PowerShell 文档](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.3#saving-changes-to-environment-variables)。
> Windows 防病毒扫描程序偶尔会将 Stripe CLI 标记为不安全。这称为误报。有关详细信息,请参阅 GitHub 存储库中的[问题 #692](https://github.com/stripe/stripe-cli/issues/692)。
1. 运行解压的 `.exe` 文件。
#### Docker
Stripe CLI 也可以作为 [Docker 镜像](https://hub.docker.com/r/stripe/stripe-cli)提供。要安装最新版本,请运行:
```bash
docker run --rm -it stripe/stripe-cli:latest
```
### 验证身份
登录并验证您的 Stripe 用户[账户](https://docs.stripe.com/get-started/account/activate.md),以生成一组受限密钥。如需了解更多信息,请参阅 [Stripe CLI 密钥和权限 ](https://docs.stripe.com/stripe-cli/keys.md)。
```bash
stripe login
```
在浏览器中按键盘上的**回车键**以完成认证流程。
```bash
Your pairing code is: enjoy-enough-outwit-win
This pairing code verifies your authentication with Stripe.
Press Enter to open the browser or visit https://dashboard.stripe.com/stripecli/confirm_auth?t=THQdJfL3x12udFkNorJL8OF1iFlN8Az1 (^C to quit)
```
### 确认设置
现在,CLI 已安装完毕,您可以向 [Create a product](https://docs.stripe.com/api/products/create.md) 发出一个 API 请求。
#### bash
```bash
stripe products create \
--name="My First Product" \
--description="Created with the Stripe CLI"
```
在响应对象中查找产品标识符( `id` 中)。保存它以备下一步使用。
如果一切正常,命令行将显示以下响应。
#### bash
```json
{
"id": "prod_LTenIrmp8Q67sa", // 标识符如下所示。
"object": "product",
"active": true,
"attributes": [],
"created": 1668198126,
"default_price": null,
"description": "Created with the Stripe CLI",
"identifiers": {},
"images": [],
"livemode": false,
"metadata": {},
"name": "My First Product",
"package_dimensions": null,
"price": null,
"product_class": null,
"shippable": null,
"sku": "my-first-product-10",
"statement_descriptor": null,
"tax_code": null,
"type": "service",
"unit_label": null,
"updated": 1668198126,
"url": null
}
```
接下来,调用 [Create a price](https://docs.stripe.com/api/prices/create.md),附加一个 30 美元的价格。将 `product` 中的占位符替换为您的产品标识符(例如,`prod_LTenIrmp8Q67sa`)。
#### bash
```bash
stripe prices create \
--unit-amount=3000 \
--currency=usd \
--product="{{PRODUCT_ID}}"
```
如果一切正常,命令行将显示以下响应。
#### bash
```json
{
"id": "price_1KzlAMJJDeE9fu01WMJJr79o", // 标识符如下所示。
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1652636348,
"currency": "usd",
"livemode": false,
"lookup_key": null,
"metadata": {},
"nickname": null,
"product": "prod_Lh9iTGZhb2mcBy",
"recurring": null,
"tax_behavior": "unspecified",
"tiers_mode": null,
"transform_quantity": null,
"type": "one_time",
"unit_amount": 3000,
"unit_amount_decimal": "3000"
}
```
## 管理第三方依赖
建议用 [RubyGems](http://rubygems.org/) 命令行工具管理第三方依赖项,该工具允许您添加新的库并将其包含在您的 Ruby 项目中。检查是否已安装 RubyGems:
### 安装 RubyGems
#### 安装 RubyGems
```bash
gem --version
```
如果您收到 `gem: command not found`,请从他们的下载页面[下载 RubyGems](http://rubygems.org/pages/download)。
## 安装 Ruby 服务器端 SDK
Stripe Ruby 服务器端 SDK 的最新版本是 v18.4.0。它支持 2.3+ 版 Ruby。
检查您的 Ruby 版本:
```bash
ruby -v
```
### 安装库
[创建 gem 文件](https://guides.rubygems.org/make-your-own-gem/),然后用 [RubyGems](https://rubygems.org/) 安装生成的 gem。
将最新版 [Stripe gem](https://rubygems.org/gems/stripe) 添加到项目:
```bash
bundle add stripe
```
从您指定的来源安装所需的 gem:
```bash
bundle install
```
### 备选安装方式
**添加依赖**——添加最新版本的库作为 gem 依赖项:
```ruby
source 'https://rubygems.org'
gem 'rails'
gem 'stripe'
```
**全局安装**——用 [RubyGems](https://rubygems.org/) 对该库进行全局安装:
```bash
gem install stripe
```
**手动安装**——[从源代码创建 gem](https://github.com/stripe/stripe-ruby),然后运行以下命令安装该库:
```bash
gem build stripe.gemspec
```
## 运行您的第一个 SDK 请求
您现在已安装 Ruby SDK,可以通过几个 API 请求创建订阅[产品](https://docs.stripe.com/api/products/create.md)并附加[价格](https://docs.stripe.com/api/prices/create.md)。在此示例中,我们使用响应中返回的产品标识符来创建价格。
> 该示例为您的*沙盒* (A sandbox is an isolated test environment that allows you to test Stripe functionality in your account without affecting your live integration. Use sandboxes to safely experiment with new features and changes)环境使用的是您的 Stripe 用户[账户](https://docs.stripe.com/get-started/account/activate.md)的默认密钥。只有您可以看到这些值。
#### 创建产品和价格
```ruby
require 'rubygems'
require 'stripe'
Stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"
starter_subscription = Stripe::Product.create(
name: 'Starter Subscription',
description: '$12/Month subscription',
)
starter_subscription_price = Stripe::Price.create(
currency: 'usd',
unit_amount: 1200,
recurring: {interval: 'month'},
product: starter_subscription['id'],
)
puts "Success! Here is your starter subscription product id: #{starter_subscription.id}"
puts "Success! Here is your starter subscription price id: #{starter_subscription_price.id}"
```
将文件另存为 `create_price.rb`。从命令行,`cd` 到包含您刚刚保存的文件的目录,然后运行:
#### create_price.rb
```bash
ruby create_price.rb
```
如果一切正常,命令行将显示以下响应。保存这些标识符,以便在构建集成时使用。
#### bash
```bash
Success! Here is your starter subscription product id: prod_0KxBDl589O8KAxCG1alJgiA6
Success! Here is your starter subscription price id: price_0KxBDm589O8KAxCGMgG7scjb
```
## See also
快速入门到此结束。有关处理您刚创建的产品的付款的几种不同方式,请参阅下面的链接。
- [创建支付链接](https://docs.stripe.com/payment-links.md)
- [Stripe 托管页面](https://docs.stripe.com/checkout/quickstart.md)
- [高级集成](https://docs.stripe.com/payments/quickstart-checkout-sessions.md)
# Python
> This is a Python for when lang is python. View the full page at https://docs.stripe.com/get-started/development-environment?lang=python.
在本快速入门中,您将安装 [Stripe CLI](https://docs.stripe.com/stripe-cli.md)。它是一个必不可少的工具,让您可以通过命令行访问 Stripe 集成。您还将安装 [Stripe Python 服务器端 SDK](https://github.com/stripe/stripe-python),以便从 Python 编写的应用程序访问 Stripe API。
## 所学内容
本快速指南中,您将学会如何:
- 如何在不编写代码的情况下调用 Stripe API
- 如何用虚拟环境或 pip 包管理工具管理第三方依赖
- 如何安装最新的 Stripe Python SDK v14.4.0
- 如何发送第一个 SDK 请求
## 初始设置
首先,[创建 Stripe 账户](https://dashboard.stripe.com/register)或[登录](https://dashboard.stripe.com/login)。
## 设置 Stripe CLI
### 安装
在命令行中,使用一个安装脚本或为您的操作系统下载并提取一个有版本号的归档文件,完成 CLI 的安装。
#### homebrew
要用 [homebrew](https://brew.sh/) 安装 Stripe CLI,请运行:
```bash
brew install stripe/stripe-cli/stripe
```
如果您在 Linux 版本的 homebrew 上运行该命令,则此命令将失败,但您可以使用此替代方法或按照 Linux 选项卡上的说明进行操作。
```bash
brew install stripe-cli
```
#### apt
> 用于 CLI 的 Debian 构建版本可在 JFrog 的https://packages.stripe.dev,获取,该域名并非 Stripe 所有。当您访问此 URL 时,它将会重定向至 Jfrog 工件列表。
要在基于 Debian 和 Ubuntu 的发行版本上安装 Stripe CLI:
1. Add Stripe CLI’s GPG key to the apt sources keyring:
```bash
curl -s https://packages.stripe.dev/api/security/keypair/stripe-cli-gpg/public | gpg --dearmor | sudo tee /usr/share/keyrings/stripe.gpg
```
1. 将 CLI 的 APT Repository 添加到 apt sources list:
```bash
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
```
1. 更新软件包列表:
```bash
sudo apt update
```
1. 安装 CLI:
```bash
sudo apt install stripe
```
#### yum
> 用于 CLI 的 RPM 构建版本可在 JFrog 的https://packages.stripe.dev,获取,该域名并非 Stripe 所有。当您访问此 URL 时,它将会重定向至 Jfrog 工件列表。
要在基于 RPM 的发行版本上安装 Stripe CLI:
1. 将 CLI 的 yum repository 添加到 yum 源列表:
```bash
echo -e "[Stripe]\nname=stripe\nbaseurl=https://packages.stripe.dev/stripe-cli-rpm-local/\nenabled=1\ngpgcheck=0" >> /etc/yum.repos.d/stripe.repo
```
1. 安装 CLI:
```bash
sudo yum install stripe
```
#### Scoop
要用 [Scoop](https://scoop.sh/) 安装 Stripe CLI,请运行:
```bash
scoop bucket add stripe https://github.com/stripe/scoop-stripe-cli.git
```
```bash
scoop install stripe
```
#### macOS
要在没有 homebrew 的 macOS 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载您的 CPU 结构类型的最新的 `mac-os` tar.gz 文件。
1. 解压文件:`tar -xvf stripe_[X.X.X]_mac-os_[ARCH_TYPE].tar.gz`。
或者,将二进制文件安装在可以全局执行的位置(例如,`/usr/local/bin`)。
#### Linux
要在没有软件包管理器的 Linux 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载最新的 `linux` tar.gz 文件。
1. 解压文件:`tar -xvf stripe_X.X.X_linux_x86_64.tar.gz`.
1. 将 `./stripe` 移到您的执行路径。
#### Windows
要在没有 Scoop 的 Windows 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载最新的 `windows` zip 文件
1. 解压 `stripe_X.X.X_windows_x86_64.zip` 文件。
1. 将解压缩后的 `stripe.exe` 文件的路径添加到 `Path` 环境变量中。若要了解如何更新环境变量,请参阅 [Microsoft PowerShell 文档](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.3#saving-changes-to-environment-variables)。
> Windows 防病毒扫描程序偶尔会将 Stripe CLI 标记为不安全。这称为误报。有关详细信息,请参阅 GitHub 存储库中的[问题 #692](https://github.com/stripe/stripe-cli/issues/692)。
1. 运行解压的 `.exe` 文件。
#### Docker
Stripe CLI 也可以作为 [Docker 镜像](https://hub.docker.com/r/stripe/stripe-cli)提供。要安装最新版本,请运行:
```bash
docker run --rm -it stripe/stripe-cli:latest
```
### 验证身份
登录并验证您的 Stripe 用户[账户](https://docs.stripe.com/get-started/account/activate.md),以生成一组受限密钥。如需了解更多信息,请参阅 [Stripe CLI 密钥和权限 ](https://docs.stripe.com/stripe-cli/keys.md)。
```bash
stripe login
```
在浏览器中按键盘上的**回车键**以完成认证流程。
```bash
Your pairing code is: enjoy-enough-outwit-win
This pairing code verifies your authentication with Stripe.
Press Enter to open the browser or visit https://dashboard.stripe.com/stripecli/confirm_auth?t=THQdJfL3x12udFkNorJL8OF1iFlN8Az1 (^C to quit)
```
### 确认设置
现在,CLI 已安装完毕,您可以向 [Create a product](https://docs.stripe.com/api/products/create.md) 发出一个 API 请求。
#### bash
```bash
stripe products create \
--name="My First Product" \
--description="Created with the Stripe CLI"
```
在响应对象中查找产品标识符( `id` 中)。保存它以备下一步使用。
如果一切正常,命令行将显示以下响应。
#### bash
```json
{
"id": "prod_LTenIrmp8Q67sa", // 标识符如下所示。
"object": "product",
"active": true,
"attributes": [],
"created": 1668198126,
"default_price": null,
"description": "Created with the Stripe CLI",
"identifiers": {},
"images": [],
"livemode": false,
"metadata": {},
"name": "My First Product",
"package_dimensions": null,
"price": null,
"product_class": null,
"shippable": null,
"sku": "my-first-product-10",
"statement_descriptor": null,
"tax_code": null,
"type": "service",
"unit_label": null,
"updated": 1668198126,
"url": null
}
```
接下来,调用 [Create a price](https://docs.stripe.com/api/prices/create.md),附加一个 30 美元的价格。将 `product` 中的占位符替换为您的产品标识符(例如,`prod_LTenIrmp8Q67sa`)。
#### bash
```bash
stripe prices create \
--unit-amount=3000 \
--currency=usd \
--product="{{PRODUCT_ID}}"
```
如果一切正常,命令行将显示以下响应。
#### bash
```json
{
"id": "price_1KzlAMJJDeE9fu01WMJJr79o", // 标识符如下所示。
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1652636348,
"currency": "usd",
"livemode": false,
"lookup_key": null,
"metadata": {},
"nickname": null,
"product": "prod_Lh9iTGZhb2mcBy",
"recurring": null,
"tax_behavior": "unspecified",
"tiers_mode": null,
"transform_quantity": null,
"type": "one_time",
"unit_amount": 3000,
"unit_amount_decimal": "3000"
}
```
## 管理第三方依赖
建议用 [venv](https://docs.python.org/3/tutorial/venv.html) 模块管理第三方依赖项,该工具允许您添加新的库并将其包含在您的 Python 3 项目中。
### 在 Windows 上 (cmd.exe):
#### 在 Windows 上 (cmd.exe)
```bash
python3 -m venv env
.\env\Scripts\activate.bat
```
### 在 GNU Linux 或 MacOS (bash) 上:
#### 在 GNU/Linux 或 MacOS 上 (bash)
```bash
python3 -m venv env
source env/bin/activate
```
## 安装 Python 服务器端 SDK
Stripe Python 服务器端 SDK 的最新版本是 v14.4.0。它支持 3.6+ 版 Python。
检查您的 Python 版本:
```bash
python3 --version
```
### 安装库
从 [PyPi](http://pypi.python.org/pypi/stripe/) 安装库,这是一个 Python 包管理工具:
```bash
pip3 install --upgrade stripe
```
接下来,在您的 requirements.txt 文件中指定以下版本:
```txt
stripe>=14.4.0
```
### 备选安装方式
**手动安装**——为 SDK [下载源代码](https://github.com/stripe/stripe-python),然后运行以下命令安装该库:
```bash
python3 setup.py install
```
## 运行您的第一个 SDK 请求
您现在已安装 Python SDK,可以通过几个 API 请求创建订阅[产品](https://docs.stripe.com/api/products/create.md)并附加[价格](https://docs.stripe.com/api/prices/create.md)。在此示例中,我们使用响应中返回的产品标识符来创建价格。
> 该示例为您的*沙盒* (A sandbox is an isolated test environment that allows you to test Stripe functionality in your account without affecting your live integration. Use sandboxes to safely experiment with new features and changes)环境使用的是您的 Stripe 用户[账户](https://docs.stripe.com/get-started/account/activate.md)的默认密钥。只有您可以看到这些值。
#### 创建产品和价格
```python
import stripe
stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"
starter_subscription = stripe.Product.create(
name="Starter Subscription",
description="$12/Month subscription",
)
starter_subscription_price = stripe.Price.create(
unit_amount=1200,
currency="usd",
recurring={"interval": "month"},
product=starter_subscription['id'],
)
# Save these identifiers
print(f"Success! Here is your starter subscription product id: {starter_subscription.id}")
print(f"Success! Here is your starter subscription price id: {starter_subscription_price.id}")
```
将文件另存为 `create_price.py`。从命令行,`cd` 到包含您刚刚保存的文件的目录,然后运行:
#### create_price.py
```bash
python3 create_price.py
```
如果一切正常,命令行将显示以下响应。保存这些标识符,以便在构建集成时使用。
#### bash
```bash
Success! Here is your starter subscription product id: prod_0KxBDl589O8KAxCG1alJgiA6
Success! Here is your starter subscription price id: price_0KxBDm589O8KAxCGMgG7scjb
```
## See also
快速入门到此结束。有关处理您刚创建的产品的付款的几种不同方式,请参阅下面的链接。
- [创建支付链接](https://docs.stripe.com/payment-links.md)
- [Stripe 托管页面](https://docs.stripe.com/checkout/quickstart.md)
- [高级集成](https://docs.stripe.com/payments/quickstart-checkout-sessions.md)
# Go
> This is a Go for when lang is go. View the full page at https://docs.stripe.com/get-started/development-environment?lang=go.
在本快速入门中,您将安装 [Stripe CLI](https://docs.stripe.com/stripe-cli.md)。它是一个必不可少的工具,让您可以通过命令行访问 Stripe 集成。您还将安装 [Stripe Go 服务器端 SDK](https://github.com/stripe/stripe-go),以便从 Go 编写的应用程序访问 Stripe API。
## 所学内容
本快速指南中,您将学会如何:
- 如何在不编写代码的情况下调用 Stripe API
- 如何用 Go 模块管理第三方依赖
- 如何安装最新的 Stripe Go SDK v84.4.0
- 如何发送第一个 SDK 请求
## 初始设置
首先,[创建 Stripe 账户](https://dashboard.stripe.com/register)或[登录](https://dashboard.stripe.com/login)。
## 设置 Stripe CLI
### 安装
在命令行中,使用一个安装脚本或为您的操作系统下载并提取一个有版本号的归档文件,完成 CLI 的安装。
#### homebrew
要用 [homebrew](https://brew.sh/) 安装 Stripe CLI,请运行:
```bash
brew install stripe/stripe-cli/stripe
```
如果您在 Linux 版本的 homebrew 上运行该命令,则此命令将失败,但您可以使用此替代方法或按照 Linux 选项卡上的说明进行操作。
```bash
brew install stripe-cli
```
#### apt
> 用于 CLI 的 Debian 构建版本可在 JFrog 的https://packages.stripe.dev,获取,该域名并非 Stripe 所有。当您访问此 URL 时,它将会重定向至 Jfrog 工件列表。
要在基于 Debian 和 Ubuntu 的发行版本上安装 Stripe CLI:
1. Add Stripe CLI’s GPG key to the apt sources keyring:
```bash
curl -s https://packages.stripe.dev/api/security/keypair/stripe-cli-gpg/public | gpg --dearmor | sudo tee /usr/share/keyrings/stripe.gpg
```
1. 将 CLI 的 APT Repository 添加到 apt sources list:
```bash
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
```
1. 更新软件包列表:
```bash
sudo apt update
```
1. 安装 CLI:
```bash
sudo apt install stripe
```
#### yum
> 用于 CLI 的 RPM 构建版本可在 JFrog 的https://packages.stripe.dev,获取,该域名并非 Stripe 所有。当您访问此 URL 时,它将会重定向至 Jfrog 工件列表。
要在基于 RPM 的发行版本上安装 Stripe CLI:
1. 将 CLI 的 yum repository 添加到 yum 源列表:
```bash
echo -e "[Stripe]\nname=stripe\nbaseurl=https://packages.stripe.dev/stripe-cli-rpm-local/\nenabled=1\ngpgcheck=0" >> /etc/yum.repos.d/stripe.repo
```
1. 安装 CLI:
```bash
sudo yum install stripe
```
#### Scoop
要用 [Scoop](https://scoop.sh/) 安装 Stripe CLI,请运行:
```bash
scoop bucket add stripe https://github.com/stripe/scoop-stripe-cli.git
```
```bash
scoop install stripe
```
#### macOS
要在没有 homebrew 的 macOS 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载您的 CPU 结构类型的最新的 `mac-os` tar.gz 文件。
1. 解压文件:`tar -xvf stripe_[X.X.X]_mac-os_[ARCH_TYPE].tar.gz`。
或者,将二进制文件安装在可以全局执行的位置(例如,`/usr/local/bin`)。
#### Linux
要在没有软件包管理器的 Linux 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载最新的 `linux` tar.gz 文件。
1. 解压文件:`tar -xvf stripe_X.X.X_linux_x86_64.tar.gz`.
1. 将 `./stripe` 移到您的执行路径。
#### Windows
要在没有 Scoop 的 Windows 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载最新的 `windows` zip 文件
1. 解压 `stripe_X.X.X_windows_x86_64.zip` 文件。
1. 将解压缩后的 `stripe.exe` 文件的路径添加到 `Path` 环境变量中。若要了解如何更新环境变量,请参阅 [Microsoft PowerShell 文档](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.3#saving-changes-to-environment-variables)。
> Windows 防病毒扫描程序偶尔会将 Stripe CLI 标记为不安全。这称为误报。有关详细信息,请参阅 GitHub 存储库中的[问题 #692](https://github.com/stripe/stripe-cli/issues/692)。
1. 运行解压的 `.exe` 文件。
#### Docker
Stripe CLI 也可以作为 [Docker 镜像](https://hub.docker.com/r/stripe/stripe-cli)提供。要安装最新版本,请运行:
```bash
docker run --rm -it stripe/stripe-cli:latest
```
### 验证身份
登录并验证您的 Stripe 用户[账户](https://docs.stripe.com/get-started/account/activate.md),以生成一组受限密钥。如需了解更多信息,请参阅 [Stripe CLI 密钥和权限 ](https://docs.stripe.com/stripe-cli/keys.md)。
```bash
stripe login
```
在浏览器中按键盘上的**回车键**以完成认证流程。
```bash
Your pairing code is: enjoy-enough-outwit-win
This pairing code verifies your authentication with Stripe.
Press Enter to open the browser or visit https://dashboard.stripe.com/stripecli/confirm_auth?t=THQdJfL3x12udFkNorJL8OF1iFlN8Az1 (^C to quit)
```
### 确认设置
现在,CLI 已安装完毕,您可以向 [Create a product](https://docs.stripe.com/api/products/create.md) 发出一个 API 请求。
#### bash
```bash
stripe products create \
--name="My First Product" \
--description="Created with the Stripe CLI"
```
在响应对象中查找产品标识符( `id` 中)。保存它以备下一步使用。
如果一切正常,命令行将显示以下响应。
#### bash
```json
{
"id": "prod_LTenIrmp8Q67sa", // 标识符如下所示。
"object": "product",
"active": true,
"attributes": [],
"created": 1668198126,
"default_price": null,
"description": "Created with the Stripe CLI",
"identifiers": {},
"images": [],
"livemode": false,
"metadata": {},
"name": "My First Product",
"package_dimensions": null,
"price": null,
"product_class": null,
"shippable": null,
"sku": "my-first-product-10",
"statement_descriptor": null,
"tax_code": null,
"type": "service",
"unit_label": null,
"updated": 1668198126,
"url": null
}
```
接下来,调用 [Create a price](https://docs.stripe.com/api/prices/create.md),附加一个 30 美元的价格。将 `product` 中的占位符替换为您的产品标识符(例如,`prod_LTenIrmp8Q67sa`)。
#### bash
```bash
stripe prices create \
--unit-amount=3000 \
--currency=usd \
--product="{{PRODUCT_ID}}"
```
如果一切正常,命令行将显示以下响应。
#### bash
```json
{
"id": "price_1KzlAMJJDeE9fu01WMJJr79o", // 标识符如下所示。
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1652636348,
"currency": "usd",
"livemode": false,
"lookup_key": null,
"metadata": {},
"nickname": null,
"product": "prod_Lh9iTGZhb2mcBy",
"recurring": null,
"tax_behavior": "unspecified",
"tiers_mode": null,
"transform_quantity": null,
"type": "one_time",
"unit_amount": 3000,
"unit_amount_decimal": "3000"
}
```
## 管理第三方依赖
建议用 [Go 模块](https://go.dev/blog/using-go-modules)管理第三方依赖项,这使您可以添加新库并将其包含在 Go 项目中。
### 初始化 Go
如果您是在一个新目录中从头开始,那么首先需要创建一个 `go.mod` 文件来跟踪依赖项。例如:
#### 初始化 Go
```bash
go mod init stripe-example
```
## 安装 Go 服务器端 SDK
Stripe Go 服务器端 SDK 的最新版本是 v84.4.0。它支持 1.15+ 版 Go。
### 安装库
从 [Go 模块](https://go.dev/blog/using-go-modules)安装库,这是一个 Go 包管理工具:
```bash
go get github.com/stripe/stripe-go/v84
```
用 Go 模块向一个_新_项目安装库后,该库将作为依赖项自动添加到您的项目的 go.mod 文件中。例如:
```go.mod
module stripe-example
go 1.18
require github.com/stripe/stripe-go/v84 84.4.0 // indirect
```
### 同步依赖
要使_已有_项目的托管依赖项集保持整洁,请运行以下命令[同步代码的依赖项](https://go.dev/doc/modules/managing-dependencies)。
```bash
go mod tidy
```
## 运行您的第一个 SDK 请求
现在您已安装 Go SDK,可以通过几个 API 请求创建订阅[产品](https://docs.stripe.com/api/products/create.md)并附加[价格](https://docs.stripe.com/api/prices/create.md)。在此示例中,我们使用响应中返回的产品标识符来创建价格。
> 该示例为您的*沙盒* (A sandbox is an isolated test environment that allows you to test Stripe functionality in your account without affecting your live integration. Use sandboxes to safely experiment with new features and changes)环境使用的是您的 Stripe 用户[账户](https://docs.stripe.com/get-started/account/activate.md)的默认密钥。只有您可以看到这些值。
#### 创建产品和价格
```go
package main
import (
"fmt"
"github.com/stripe/stripe-go/v84"
"github.com/stripe/stripe-go/v84/product"
"github.com/stripe/stripe-go/v84/price"
)
func main() {
stripe.Key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"
product_params := &stripe.ProductParams{
Name: stripe.String("Starter Subscription"),
Description: stripe.String("$12/Month subscription"),
}
starter_product, _ := product.New(product_params)
price_params := &stripe.PriceParams{
Currency: stripe.String(string(stripe.CurrencyUSD)),
Product: stripe.String(starter_product.ID),
Recurring: &stripe.PriceRecurringParams{
Interval: stripe.String(string(stripe.PriceRecurringIntervalMonth)),
},
UnitAmount: stripe.Int64(1200),
}
starter_price, _ := price.New(price_params)
fmt.Println("Success! Here is your starter subscription product id: " + starter_product.ID)
fmt.Println("Success! Here is your starter subscription price id: " + starter_price.ID)
}
```
将文件另存为 `create_price.go`。从命令行,`cd` 到包含您刚刚保存的文件的目录,然后运行:
#### create_price.rb
```bash
go run create_price.go
```
如果一切正常,命令行将显示以下响应。保存这些标识符,以便在构建集成时使用。
#### bash
```bash
Success! Here is your starter subscription product id: prod_0KxBDl589O8KAxCG1alJgiA6
Success! Here is your starter subscription price id: price_0KxBDm589O8KAxCGMgG7scjb
```
## See also
快速入门到此结束。有关处理您刚创建的产品的付款的几种不同方式,请参阅下面的链接。
- [创建支付链接](https://docs.stripe.com/payment-links.md)
- [Stripe 托管页面](https://docs.stripe.com/checkout/quickstart.md)
- [高级集成](https://docs.stripe.com/payments/quickstart-checkout-sessions.md)
# Java
> This is a Java for when lang is java. View the full page at https://docs.stripe.com/get-started/development-environment?lang=java.
在本快速入门中,您将安装 [Stripe CLI](https://docs.stripe.com/stripe-cli.md)。它是一个必不可少的工具,让您可以通过命令行访问 Stripe 集成。您还将安装 [Stripe Java 服务器端 SDK](https://github.com/stripe/stripe-java),以便从 Java 编写的应用程序访问 Stripe API。
## 所学内容
本快速指南中,您将学会如何:
- 如何在不编写代码的情况下调用 Stripe API
- 如何用 Maven 或 Gradle 管理第三方依赖
- 如何安装最新的 Stripe Java SDK v31.4.0
- 如何发送第一个 SDK 请求
## 初始设置
首先,[创建 Stripe 账户](https://dashboard.stripe.com/register)或[登录](https://dashboard.stripe.com/login)。
## 设置 Stripe CLI
### 安装
在命令行中,使用一个安装脚本或为您的操作系统下载并提取一个有版本号的归档文件,完成 CLI 的安装。
#### homebrew
要用 [homebrew](https://brew.sh/) 安装 Stripe CLI,请运行:
```bash
brew install stripe/stripe-cli/stripe
```
如果您在 Linux 版本的 homebrew 上运行该命令,则此命令将失败,但您可以使用此替代方法或按照 Linux 选项卡上的说明进行操作。
```bash
brew install stripe-cli
```
#### apt
> 用于 CLI 的 Debian 构建版本可在 JFrog 的https://packages.stripe.dev,获取,该域名并非 Stripe 所有。当您访问此 URL 时,它将会重定向至 Jfrog 工件列表。
要在基于 Debian 和 Ubuntu 的发行版本上安装 Stripe CLI:
1. Add Stripe CLI’s GPG key to the apt sources keyring:
```bash
curl -s https://packages.stripe.dev/api/security/keypair/stripe-cli-gpg/public | gpg --dearmor | sudo tee /usr/share/keyrings/stripe.gpg
```
1. 将 CLI 的 APT Repository 添加到 apt sources list:
```bash
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
```
1. 更新软件包列表:
```bash
sudo apt update
```
1. 安装 CLI:
```bash
sudo apt install stripe
```
#### yum
> 用于 CLI 的 RPM 构建版本可在 JFrog 的https://packages.stripe.dev,获取,该域名并非 Stripe 所有。当您访问此 URL 时,它将会重定向至 Jfrog 工件列表。
要在基于 RPM 的发行版本上安装 Stripe CLI:
1. 将 CLI 的 yum repository 添加到 yum 源列表:
```bash
echo -e "[Stripe]\nname=stripe\nbaseurl=https://packages.stripe.dev/stripe-cli-rpm-local/\nenabled=1\ngpgcheck=0" >> /etc/yum.repos.d/stripe.repo
```
1. 安装 CLI:
```bash
sudo yum install stripe
```
#### Scoop
要用 [Scoop](https://scoop.sh/) 安装 Stripe CLI,请运行:
```bash
scoop bucket add stripe https://github.com/stripe/scoop-stripe-cli.git
```
```bash
scoop install stripe
```
#### macOS
要在没有 homebrew 的 macOS 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载您的 CPU 结构类型的最新的 `mac-os` tar.gz 文件。
1. 解压文件:`tar -xvf stripe_[X.X.X]_mac-os_[ARCH_TYPE].tar.gz`。
或者,将二进制文件安装在可以全局执行的位置(例如,`/usr/local/bin`)。
#### Linux
要在没有软件包管理器的 Linux 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载最新的 `linux` tar.gz 文件。
1. 解压文件:`tar -xvf stripe_X.X.X_linux_x86_64.tar.gz`.
1. 将 `./stripe` 移到您的执行路径。
#### Windows
要在没有 Scoop 的 Windows 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载最新的 `windows` zip 文件
1. 解压 `stripe_X.X.X_windows_x86_64.zip` 文件。
1. 将解压缩后的 `stripe.exe` 文件的路径添加到 `Path` 环境变量中。若要了解如何更新环境变量,请参阅 [Microsoft PowerShell 文档](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.3#saving-changes-to-environment-variables)。
> Windows 防病毒扫描程序偶尔会将 Stripe CLI 标记为不安全。这称为误报。有关详细信息,请参阅 GitHub 存储库中的[问题 #692](https://github.com/stripe/stripe-cli/issues/692)。
1. 运行解压的 `.exe` 文件。
#### Docker
Stripe CLI 也可以作为 [Docker 镜像](https://hub.docker.com/r/stripe/stripe-cli)提供。要安装最新版本,请运行:
```bash
docker run --rm -it stripe/stripe-cli:latest
```
### 验证身份
登录并验证您的 Stripe 用户[账户](https://docs.stripe.com/get-started/account/activate.md),以生成一组受限密钥。如需了解更多信息,请参阅 [Stripe CLI 密钥和权限 ](https://docs.stripe.com/stripe-cli/keys.md)。
```bash
stripe login
```
在浏览器中按键盘上的**回车键**以完成认证流程。
```bash
Your pairing code is: enjoy-enough-outwit-win
This pairing code verifies your authentication with Stripe.
Press Enter to open the browser or visit https://dashboard.stripe.com/stripecli/confirm_auth?t=THQdJfL3x12udFkNorJL8OF1iFlN8Az1 (^C to quit)
```
### 确认设置
现在,CLI 已安装完毕,您可以向 [Create a product](https://docs.stripe.com/api/products/create.md) 发出一个 API 请求。
#### bash
```bash
stripe products create \
--name="My First Product" \
--description="Created with the Stripe CLI"
```
在响应对象中查找产品标识符( `id` 中)。保存它以备下一步使用。
如果一切正常,命令行将显示以下响应。
#### bash
```json
{
"id": "prod_LTenIrmp8Q67sa", // 标识符如下所示。
"object": "product",
"active": true,
"attributes": [],
"created": 1668198126,
"default_price": null,
"description": "Created with the Stripe CLI",
"identifiers": {},
"images": [],
"livemode": false,
"metadata": {},
"name": "My First Product",
"package_dimensions": null,
"price": null,
"product_class": null,
"shippable": null,
"sku": "my-first-product-10",
"statement_descriptor": null,
"tax_code": null,
"type": "service",
"unit_label": null,
"updated": 1668198126,
"url": null
}
```
接下来,调用 [Create a price](https://docs.stripe.com/api/prices/create.md),附加一个 30 美元的价格。将 `product` 中的占位符替换为您的产品标识符(例如,`prod_LTenIrmp8Q67sa`)。
#### bash
```bash
stripe prices create \
--unit-amount=3000 \
--currency=usd \
--product="{{PRODUCT_ID}}"
```
如果一切正常,命令行将显示以下响应。
#### bash
```json
{
"id": "price_1KzlAMJJDeE9fu01WMJJr79o", // 标识符如下所示。
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1652636348,
"currency": "usd",
"livemode": false,
"lookup_key": null,
"metadata": {},
"nickname": null,
"product": "prod_Lh9iTGZhb2mcBy",
"recurring": null,
"tax_behavior": "unspecified",
"tiers_mode": null,
"transform_quantity": null,
"type": "one_time",
"unit_amount": 3000,
"unit_amount_decimal": "3000"
}
```
## 管理第三方依赖
建议用 [Maven](https://maven.apache.org/guides/getting-started/index.html) 或 [Gradle](https://docs.gradle.org) 管理第三方依赖项,该工具可帮助您添加新的库并将其包含在您的 Java 项目中。
### 初始化项目
- 要用 **Maven** 创建项目,请参阅[如何制作我的第一个 Maven 项目?](https://maven.apache.org/guides/getting-started/index.html#How_do_I_make_my_first_Maven_project)。
- 要使用 **Gradle** 创建项目,请参阅 [Java 应用程序构建示例](https://docs.gradle.org/current/samples/sample_building_java_applications.html)。
## 安装 Java 服务器端 SDK
Stripe Java 服务器端 SDK 的最新版本是 v31.4.0。它支持 1.8+ 版 Java。
检查您的 Java 版本:
```bash
java -version
```
### 安装库
- 要使用 **Maven**,请将以下内容放入项目的 pom.xml 文件中:
```xml
com.stripe
stripe-java
31.4.0
```
- 要使用 **Gradle** ,请将下一行粘贴到 build.gradle 文件的依赖块中:
```groovy
implementation 'com.stripe:stripe-java:31.4.0'
```
### 备选安装方式
**手动安装**——您可以使用以下 JAR 手动安装 stripe-java:[下载 Stripe JAR (.jar)](https://search.maven.org/remote_content?g=com.stripe&a=stripe-java&v=LATEST)。
为 [Google Gson](https://github.com/google/gson) [下载 Gson JAR (.jar)](https://repo1.maven.org/maven2/com/google/code/gson/gson/2.8.9/gson-2.8.9.jar)。
**Proguard**——如果您使用的是 ProGuard,请务必将以下内容添加到您的 `proguard.cfg` 文件中:
```proguard
-keep class com.stripe.** { *; }
```
## 运行您的第一个 SDK 请求
现在您已安装 Java SDK,可以通过几个 API 请求创建订阅[产品](https://docs.stripe.com/api/products/create.md)并附加[价格](https://docs.stripe.com/api/prices/create.md)。在此示例中,我们使用响应中返回的产品标识符来创建价格。
> 该示例为您的*沙盒* (A sandbox is an isolated test environment that allows you to test Stripe functionality in your account without affecting your live integration. Use sandboxes to safely experiment with new features and changes)环境使用的是您的 Stripe 用户[账户](https://docs.stripe.com/get-started/account/activate.md)的默认密钥。只有您可以看到这些值。
#### 创建产品和价格
```java
package com.stripe.sample;
import com.stripe.Stripe;
import com.stripe.exception.StripeException;
import com.stripe.model.Product;
import com.stripe.param.ProductCreateParams;
import com.stripe.param.PriceCreateParams;
import com.stripe.model.Price;
public class Server {
public static void main(String[] args) throws StripeException {
Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4olfQ2";
ProductCreateParams productParams =
ProductCreateParams.builder()
.setName("Starter Subscription")
.setDescription("$12/Month subscription")
.build();
Product product = Product.create(productParams);
System.out.println("Success! Here is your starter subscription product id: " + product.getId());
PriceCreateParams params =
PriceCreateParams
.builder()
.setProduct(product.getId())
.setCurrency("usd")
.setUnitAmount(1200L)
.setRecurring(
PriceCreateParams.Recurring
.builder()
.setInterval(PriceCreateParams.Recurring.Interval.MONTH)
.build())
.build();
Price price = Price.create(params);
System.out.println("Success! Here is your starter subscription price id: " + price.getId());
}
}
```
将文件另存为 `CreatePrice.java`。从您的 Maven 或 Gradle 的 IDE 中,运行示例。例如:`Run 'CreatePrice.main()'`。
如果一切正常,命令行将显示以下响应。保存这些标识符,以便在构建集成时使用。
#### bash
```bash
Success! Here is your starter subscription product id: prod_0KxBDl589O8KAxCG1alJgiA6
Success! Here is your starter subscription price id: price_0KxBDm589O8KAxCGMgG7scjb
```
## See also
快速入门到此结束。有关处理您刚创建的产品的付款的几种不同方式,请参阅下面的链接。
- [创建支付链接](https://docs.stripe.com/payment-links.md)
- [Stripe 托管页面](https://docs.stripe.com/checkout/quickstart.md)
- [高级集成](https://docs.stripe.com/payments/quickstart-checkout-sessions.md)
# Node.js
> This is a Node.js for when lang is node. View the full page at https://docs.stripe.com/get-started/development-environment?lang=node.
在本快速入门中,您将安装 [Stripe CLI](https://docs.stripe.com/stripe-cli.md)。它是一个必不可少的工具,让您可以通过命令行访问 Stripe 集成。您还将安装 [Stripe Node.js 服务器端 SDK](https://github.com/stripe/stripe-node),以便从 Node.js 编写的应用程序访问 Stripe API。
## 所学内容
本快速指南中,您将学会如何:
- 如何在不编写代码的情况下调用 Stripe API
- 如何用 npm 或 yarn 包管理工具管理第三方依赖
- 如何安装最新的 Stripe Node SDK v20.4.0
- 如何发送第一个 SDK 请求
## 初始设置
首先,[创建 Stripe 账户](https://dashboard.stripe.com/register)或[登录](https://dashboard.stripe.com/login)。
## 设置 Stripe CLI
### 安装
在命令行中,使用一个安装脚本或为您的操作系统下载并提取一个有版本号的归档文件,完成 CLI 的安装。
#### homebrew
要用 [homebrew](https://brew.sh/) 安装 Stripe CLI,请运行:
```bash
brew install stripe/stripe-cli/stripe
```
如果您在 Linux 版本的 homebrew 上运行该命令,则此命令将失败,但您可以使用此替代方法或按照 Linux 选项卡上的说明进行操作。
```bash
brew install stripe-cli
```
#### apt
> 用于 CLI 的 Debian 构建版本可在 JFrog 的https://packages.stripe.dev,获取,该域名并非 Stripe 所有。当您访问此 URL 时,它将会重定向至 Jfrog 工件列表。
要在基于 Debian 和 Ubuntu 的发行版本上安装 Stripe CLI:
1. Add Stripe CLI’s GPG key to the apt sources keyring:
```bash
curl -s https://packages.stripe.dev/api/security/keypair/stripe-cli-gpg/public | gpg --dearmor | sudo tee /usr/share/keyrings/stripe.gpg
```
1. 将 CLI 的 APT Repository 添加到 apt sources list:
```bash
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
```
1. 更新软件包列表:
```bash
sudo apt update
```
1. 安装 CLI:
```bash
sudo apt install stripe
```
#### yum
> 用于 CLI 的 RPM 构建版本可在 JFrog 的https://packages.stripe.dev,获取,该域名并非 Stripe 所有。当您访问此 URL 时,它将会重定向至 Jfrog 工件列表。
要在基于 RPM 的发行版本上安装 Stripe CLI:
1. 将 CLI 的 yum repository 添加到 yum 源列表:
```bash
echo -e "[Stripe]\nname=stripe\nbaseurl=https://packages.stripe.dev/stripe-cli-rpm-local/\nenabled=1\ngpgcheck=0" >> /etc/yum.repos.d/stripe.repo
```
1. 安装 CLI:
```bash
sudo yum install stripe
```
#### Scoop
要用 [Scoop](https://scoop.sh/) 安装 Stripe CLI,请运行:
```bash
scoop bucket add stripe https://github.com/stripe/scoop-stripe-cli.git
```
```bash
scoop install stripe
```
#### macOS
要在没有 homebrew 的 macOS 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载您的 CPU 结构类型的最新的 `mac-os` tar.gz 文件。
1. 解压文件:`tar -xvf stripe_[X.X.X]_mac-os_[ARCH_TYPE].tar.gz`。
或者,将二进制文件安装在可以全局执行的位置(例如,`/usr/local/bin`)。
#### Linux
要在没有软件包管理器的 Linux 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载最新的 `linux` tar.gz 文件。
1. 解压文件:`tar -xvf stripe_X.X.X_linux_x86_64.tar.gz`.
1. 将 `./stripe` 移到您的执行路径。
#### Windows
要在没有 Scoop 的 Windows 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载最新的 `windows` zip 文件
1. 解压 `stripe_X.X.X_windows_x86_64.zip` 文件。
1. 将解压缩后的 `stripe.exe` 文件的路径添加到 `Path` 环境变量中。若要了解如何更新环境变量,请参阅 [Microsoft PowerShell 文档](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.3#saving-changes-to-environment-variables)。
> Windows 防病毒扫描程序偶尔会将 Stripe CLI 标记为不安全。这称为误报。有关详细信息,请参阅 GitHub 存储库中的[问题 #692](https://github.com/stripe/stripe-cli/issues/692)。
1. 运行解压的 `.exe` 文件。
#### Docker
Stripe CLI 也可以作为 [Docker 镜像](https://hub.docker.com/r/stripe/stripe-cli)提供。要安装最新版本,请运行:
```bash
docker run --rm -it stripe/stripe-cli:latest
```
### 验证身份
登录并验证您的 Stripe 用户[账户](https://docs.stripe.com/get-started/account/activate.md),以生成一组受限密钥。如需了解更多信息,请参阅 [Stripe CLI 密钥和权限 ](https://docs.stripe.com/stripe-cli/keys.md)。
```bash
stripe login
```
在浏览器中按键盘上的**回车键**以完成认证流程。
```bash
Your pairing code is: enjoy-enough-outwit-win
This pairing code verifies your authentication with Stripe.
Press Enter to open the browser or visit https://dashboard.stripe.com/stripecli/confirm_auth?t=THQdJfL3x12udFkNorJL8OF1iFlN8Az1 (^C to quit)
```
### 确认设置
现在,CLI 已安装完毕,您可以向 [Create a product](https://docs.stripe.com/api/products/create.md) 发出一个 API 请求。
#### bash
```bash
stripe products create \
--name="My First Product" \
--description="Created with the Stripe CLI"
```
在响应对象中查找产品标识符( `id` 中)。保存它以备下一步使用。
如果一切正常,命令行将显示以下响应。
#### bash
```json
{
"id": "prod_LTenIrmp8Q67sa", // 标识符如下所示。
"object": "product",
"active": true,
"attributes": [],
"created": 1668198126,
"default_price": null,
"description": "Created with the Stripe CLI",
"identifiers": {},
"images": [],
"livemode": false,
"metadata": {},
"name": "My First Product",
"package_dimensions": null,
"price": null,
"product_class": null,
"shippable": null,
"sku": "my-first-product-10",
"statement_descriptor": null,
"tax_code": null,
"type": "service",
"unit_label": null,
"updated": 1668198126,
"url": null
}
```
接下来,调用 [Create a price](https://docs.stripe.com/api/prices/create.md),附加一个 30 美元的价格。将 `product` 中的占位符替换为您的产品标识符(例如,`prod_LTenIrmp8Q67sa`)。
#### bash
```bash
stripe prices create \
--unit-amount=3000 \
--currency=usd \
--product="{{PRODUCT_ID}}"
```
如果一切正常,命令行将显示以下响应。
#### bash
```json
{
"id": "price_1KzlAMJJDeE9fu01WMJJr79o", // 标识符如下所示。
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1652636348,
"currency": "usd",
"livemode": false,
"lookup_key": null,
"metadata": {},
"nickname": null,
"product": "prod_Lh9iTGZhb2mcBy",
"recurring": null,
"tax_behavior": "unspecified",
"tiers_mode": null,
"transform_quantity": null,
"type": "one_time",
"unit_amount": 3000,
"unit_amount_decimal": "3000"
}
```
## 安装 Node.js 服务器端 SDK
Stripe Node.js 服务器端 SDK 的最新版本是 v20.4.0。它支持 12+ 版 Node.js。
检查您的 Node 版本:
```bash
node --version
```
### 初始化 Node
#### 初始化 Node
```bash
npm init
```
### 安装库
从 [npm](https://www.npmjs.com/package/node) 安装库,这是一个 Node 软件包管理工具:
```bash
npm install stripe --save
```
用 npm 安装库后,该库将作为依赖项自动添加到您的项目的 package.json 文件中。例如:
```json
{
"name": "stripe-node-example",
"version": "1.0.0",
"description": "A Stripe demo",
"main": "index.js",
"scripts": {
"node ": "node create_price.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"stripe": "^20.4.0"
}
}
```
### 备选安装方式
**Yarn**——您可以使用 Node 的另一个软件包管理工具 [yarn](https://yarnpkg.com/) 来安装该库:
```bash
yarn add stripe
```
## 运行您的第一个 SDK 请求
现在您已安装 Node.js SDK,可以通过几个 API 请求创建订阅[产品](https://docs.stripe.com/api/products/create.md)并附加[价格](https://docs.stripe.com/api/prices/create.md)。Node.js SDK 返回[承诺](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise),可以用作可链式回调。为了演示,在此示例中我们传递产品响应中返回的产品标识符来创建价格。
> 该示例为您的*沙盒* (A sandbox is an isolated test environment that allows you to test Stripe functionality in your account without affecting your live integration. Use sandboxes to safely experiment with new features and changes)环境使用的是您的 Stripe 用户[账户](https://docs.stripe.com/get-started/account/activate.md)的默认密钥。只有您可以看到这些值。
#### 创建产品和价格
```node
const stripe = require('stripe')('sk_test_BQokikJOvBiI2HlWgH4olfQ2');
stripe.products.create({
name: 'Starter Subscription',
description: '$12/Month subscription',
}).then(product => {
stripe.prices.create({
unit_amount: 1200,
currency: 'usd',
recurring: {
interval: 'month',
},
product: product.id,
}).then(price => {
console.log('Success! Here is your starter subscription product id: ' + product.id);
console.log('Success! Here is your starter subscription price id: ' + price.id);
});
});
```
将文件另存为 `create_price.js`。从命令行,`cd` 到包含您刚刚保存的文件的目录,然后运行:
#### create_price.js
```bash
node create_price.js
```
如果一切正常,命令行将显示以下响应。保存这些标识符,以便在构建集成时使用。
#### bash
```bash
Success! Here is your starter subscription product id: prod_0KxBDl589O8KAxCG1alJgiA6
Success! Here is your starter subscription price id: price_0KxBDm589O8KAxCGMgG7scjb
```
## See also
快速入门到此结束。有关处理您刚创建的产品的付款的几种不同方式,请参阅下面的链接。
- [创建支付链接](https://docs.stripe.com/payment-links.md)
- [Stripe 托管页面](https://docs.stripe.com/checkout/quickstart.md)
- [高级集成](https://docs.stripe.com/payments/quickstart-checkout-sessions.md)
# PHP
> This is a PHP for when lang is php. View the full page at https://docs.stripe.com/get-started/development-environment?lang=php.
在本快速入门中,您将安装 [Stripe CLI](https://docs.stripe.com/stripe-cli.md)。它是一个必不可少的工具,让您可以通过命令行访问 Stripe 集成。您还将安装 [Stripe PHP 服务器端 SDK](https://github.com/stripe/stripe-php),以便从 PHP 编写的应用程序访问 Stripe API。
## 所学内容
本快速指南中,您将学会如何:
- 如何在不编写代码的情况下调用 Stripe API
- 如何用 Composer 管理第三方依赖
- 如何安装最新的 Stripe PHP SDK v19.4.0
- 如何发送第一个 SDK 请求
## 初始设置
首先,[创建 Stripe 账户](https://dashboard.stripe.com/register)或[登录](https://dashboard.stripe.com/login)。
## 设置 Stripe CLI
### 安装
在命令行中,使用一个安装脚本或为您的操作系统下载并提取一个有版本号的归档文件,完成 CLI 的安装。
#### homebrew
要用 [homebrew](https://brew.sh/) 安装 Stripe CLI,请运行:
```bash
brew install stripe/stripe-cli/stripe
```
如果您在 Linux 版本的 homebrew 上运行该命令,则此命令将失败,但您可以使用此替代方法或按照 Linux 选项卡上的说明进行操作。
```bash
brew install stripe-cli
```
#### apt
> 用于 CLI 的 Debian 构建版本可在 JFrog 的https://packages.stripe.dev,获取,该域名并非 Stripe 所有。当您访问此 URL 时,它将会重定向至 Jfrog 工件列表。
要在基于 Debian 和 Ubuntu 的发行版本上安装 Stripe CLI:
1. Add Stripe CLI’s GPG key to the apt sources keyring:
```bash
curl -s https://packages.stripe.dev/api/security/keypair/stripe-cli-gpg/public | gpg --dearmor | sudo tee /usr/share/keyrings/stripe.gpg
```
1. 将 CLI 的 APT Repository 添加到 apt sources list:
```bash
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
```
1. 更新软件包列表:
```bash
sudo apt update
```
1. 安装 CLI:
```bash
sudo apt install stripe
```
#### yum
> 用于 CLI 的 RPM 构建版本可在 JFrog 的https://packages.stripe.dev,获取,该域名并非 Stripe 所有。当您访问此 URL 时,它将会重定向至 Jfrog 工件列表。
要在基于 RPM 的发行版本上安装 Stripe CLI:
1. 将 CLI 的 yum repository 添加到 yum 源列表:
```bash
echo -e "[Stripe]\nname=stripe\nbaseurl=https://packages.stripe.dev/stripe-cli-rpm-local/\nenabled=1\ngpgcheck=0" >> /etc/yum.repos.d/stripe.repo
```
1. 安装 CLI:
```bash
sudo yum install stripe
```
#### Scoop
要用 [Scoop](https://scoop.sh/) 安装 Stripe CLI,请运行:
```bash
scoop bucket add stripe https://github.com/stripe/scoop-stripe-cli.git
```
```bash
scoop install stripe
```
#### macOS
要在没有 homebrew 的 macOS 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载您的 CPU 结构类型的最新的 `mac-os` tar.gz 文件。
1. 解压文件:`tar -xvf stripe_[X.X.X]_mac-os_[ARCH_TYPE].tar.gz`。
或者,将二进制文件安装在可以全局执行的位置(例如,`/usr/local/bin`)。
#### Linux
要在没有软件包管理器的 Linux 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载最新的 `linux` tar.gz 文件。
1. 解压文件:`tar -xvf stripe_X.X.X_linux_x86_64.tar.gz`.
1. 将 `./stripe` 移到您的执行路径。
#### Windows
要在没有 Scoop 的 Windows 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载最新的 `windows` zip 文件
1. 解压 `stripe_X.X.X_windows_x86_64.zip` 文件。
1. 将解压缩后的 `stripe.exe` 文件的路径添加到 `Path` 环境变量中。若要了解如何更新环境变量,请参阅 [Microsoft PowerShell 文档](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.3#saving-changes-to-environment-variables)。
> Windows 防病毒扫描程序偶尔会将 Stripe CLI 标记为不安全。这称为误报。有关详细信息,请参阅 GitHub 存储库中的[问题 #692](https://github.com/stripe/stripe-cli/issues/692)。
1. 运行解压的 `.exe` 文件。
#### Docker
Stripe CLI 也可以作为 [Docker 镜像](https://hub.docker.com/r/stripe/stripe-cli)提供。要安装最新版本,请运行:
```bash
docker run --rm -it stripe/stripe-cli:latest
```
### 验证身份
登录并验证您的 Stripe 用户[账户](https://docs.stripe.com/get-started/account/activate.md),以生成一组受限密钥。如需了解更多信息,请参阅 [Stripe CLI 密钥和权限 ](https://docs.stripe.com/stripe-cli/keys.md)。
```bash
stripe login
```
在浏览器中按键盘上的**回车键**以完成认证流程。
```bash
Your pairing code is: enjoy-enough-outwit-win
This pairing code verifies your authentication with Stripe.
Press Enter to open the browser or visit https://dashboard.stripe.com/stripecli/confirm_auth?t=THQdJfL3x12udFkNorJL8OF1iFlN8Az1 (^C to quit)
```
### 确认设置
现在,CLI 已安装完毕,您可以向 [Create a product](https://docs.stripe.com/api/products/create.md) 发出一个 API 请求。
#### bash
```bash
stripe products create \
--name="My First Product" \
--description="Created with the Stripe CLI"
```
在响应对象中查找产品标识符( `id` 中)。保存它以备下一步使用。
如果一切正常,命令行将显示以下响应。
#### bash
```json
{
"id": "prod_LTenIrmp8Q67sa", // 标识符如下所示。
"object": "product",
"active": true,
"attributes": [],
"created": 1668198126,
"default_price": null,
"description": "Created with the Stripe CLI",
"identifiers": {},
"images": [],
"livemode": false,
"metadata": {},
"name": "My First Product",
"package_dimensions": null,
"price": null,
"product_class": null,
"shippable": null,
"sku": "my-first-product-10",
"statement_descriptor": null,
"tax_code": null,
"type": "service",
"unit_label": null,
"updated": 1668198126,
"url": null
}
```
接下来,调用 [Create a price](https://docs.stripe.com/api/prices/create.md),附加一个 30 美元的价格。将 `product` 中的占位符替换为您的产品标识符(例如,`prod_LTenIrmp8Q67sa`)。
#### bash
```bash
stripe prices create \
--unit-amount=3000 \
--currency=usd \
--product="{{PRODUCT_ID}}"
```
如果一切正常,命令行将显示以下响应。
#### bash
```json
{
"id": "price_1KzlAMJJDeE9fu01WMJJr79o", // 标识符如下所示。
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1652636348,
"currency": "usd",
"livemode": false,
"lookup_key": null,
"metadata": {},
"nickname": null,
"product": "prod_Lh9iTGZhb2mcBy",
"recurring": null,
"tax_behavior": "unspecified",
"tiers_mode": null,
"transform_quantity": null,
"type": "one_time",
"unit_amount": 3000,
"unit_amount_decimal": "3000"
}
```
## 管理第三方依赖
建议用 [Composer](https://getcomposer.org/download/) 从 [Packagist](https://packagist.org/) 管理第三方依赖项,该工具允许您添加新的库并将其包含在您的 PHP 项目中。
### 安装 Composer
从命令行,根据说明[下载 Composer](https://getcomposer.org/download/)。
## 安装 PHP 服务器端 SDK
Stripe PHP 服务器端 SDK 的最新版本是 v19.4.0。它支持 5.6.0+ 版 PHP。
检查您的 PHP 版本:
```bash
php --version
```
### 安装库
从 [Composer](http://getcomposer.org/) 安装库,这是一个 PHP 包管理工具:
```bash
composer require stripe/stripe-php
```
用 Composer 安装库后,该库将作为依赖项自动添加到您的项目的 composer.json 文件中。例如:
```json
{
"require": {
"stripe/stripe-php": "^19.4.0"
}
}
```
要使用绑定,请使用 Composer 的 [autoload](https://getcomposer.org/doc/01-basic-usage.md#autoloading)。例如:
```php
require_once('vendor/autoload.php');
```
### 备选安装方式
**手动安装**
您可以[下载最新版本](https://github.com/stripe/stripe-php/releases)来使用绑定,然后包含 init.php 文件:
```php
require_once('/path/to/stripe-php/init.php');
```
然后添加以下扩展:[cURL](https://secure.php.net/manual/en/book.curl.php)(也可以用您自己的非 curl 客户端)[json](https://secure.php.net/manual/en/book.json.php) [mbstring](https://secure.php.net/manual/en/book.mbstring.php)
## 运行您的第一个 SDK 请求
您现在已安装 PHP SDK,可以通过几个 API 请求创建订阅[产品](https://docs.stripe.com/api/products/create.md)并附加[价格](https://docs.stripe.com/api/prices/create.md)。在此示例中,我们使用响应中返回的产品标识符来创建价格。
> 该示例为您的*沙盒* (A sandbox is an isolated test environment that allows you to test Stripe functionality in your account without affecting your live integration. Use sandboxes to safely experiment with new features and changes)环境使用的是您的 Stripe 用户[账户](https://docs.stripe.com/get-started/account/activate.md)的默认密钥。只有您可以看到这些值。
#### 创建产品和价格
```php
products->create([
'name' => 'Starter Subscription',
'description' => '$12/Month subscription',
]);
echo "Success! Here is your starter subscription product id: " . $product->id . "\n";
$price = $stripe->prices->create([
'unit_amount' => 1200,
'currency' => 'usd',
'recurring' => ['interval' => 'month'],
'product' => $product['id'],
]);
echo "Success! Here is your starter subscription price id: " . $price->id . "\n";
?>
```
将文件另存为 `create_price.php`。从命令行,`cd` 到包含您刚刚保存的文件的目录,然后运行:
#### create_price.php
```bash
php create_price.php
```
如果一切正常,命令行将显示以下响应。保存这些标识符,以便在构建集成时使用。
#### bash
```bash
Success! Here is your starter subscription product id: price_0KxBDl589O8KAxCG1alJgiA6
Success! Here is your starter subscription price id: price_0KxBDm589O8KAxCGMgG7scjb
```
## See also
快速入门到此结束。有关处理您刚创建的产品的付款的几种不同方式,请参阅下面的链接。
- [创建支付链接](https://docs.stripe.com/payment-links.md)
- [Stripe 托管页面](https://docs.stripe.com/checkout/quickstart.md)
- [高级集成](https://docs.stripe.com/payments/quickstart-checkout-sessions.md)
# .NET
> This is a .NET for when lang is dotnet. View the full page at https://docs.stripe.com/get-started/development-environment?lang=dotnet.
在本快速入门中,您将安装 [Stripe CLI](https://docs.stripe.com/stripe-cli.md)。它是一个必不可少的工具,让您可以通过命令行访问 Stripe 集成。您还将安装 [Stripe .NET 服务器端 SDK](https://github.com/stripe/stripe-dotnet),以便从 C\# 编写的应用程序访问 Stripe API。
## 所学内容
本快速指南中,您将学会如何:
- 如何在不编写代码的情况下调用 Stripe API
- 如何用 .NET Core CLI、NuGet CLI 或包管理控制台管理第三方依赖
- 如何安装最新的 Stripe .NET SDK v50.4.0
- 如何发送第一个 SDK 请求
## 初始设置
首先,[创建 Stripe 账户](https://dashboard.stripe.com/register)或[登录](https://dashboard.stripe.com/login)。
## 设置 Stripe CLI
### 安装
在命令行中,使用一个安装脚本或为您的操作系统下载并提取一个有版本号的归档文件,完成 CLI 的安装。
#### homebrew
要用 [homebrew](https://brew.sh/) 安装 Stripe CLI,请运行:
```bash
brew install stripe/stripe-cli/stripe
```
如果您在 Linux 版本的 homebrew 上运行该命令,则此命令将失败,但您可以使用此替代方法或按照 Linux 选项卡上的说明进行操作。
```bash
brew install stripe-cli
```
#### apt
> 用于 CLI 的 Debian 构建版本可在 JFrog 的https://packages.stripe.dev,获取,该域名并非 Stripe 所有。当您访问此 URL 时,它将会重定向至 Jfrog 工件列表。
要在基于 Debian 和 Ubuntu 的发行版本上安装 Stripe CLI:
1. Add Stripe CLI’s GPG key to the apt sources keyring:
```bash
curl -s https://packages.stripe.dev/api/security/keypair/stripe-cli-gpg/public | gpg --dearmor | sudo tee /usr/share/keyrings/stripe.gpg
```
1. 将 CLI 的 APT Repository 添加到 apt sources list:
```bash
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
```
1. 更新软件包列表:
```bash
sudo apt update
```
1. 安装 CLI:
```bash
sudo apt install stripe
```
#### yum
> 用于 CLI 的 RPM 构建版本可在 JFrog 的https://packages.stripe.dev,获取,该域名并非 Stripe 所有。当您访问此 URL 时,它将会重定向至 Jfrog 工件列表。
要在基于 RPM 的发行版本上安装 Stripe CLI:
1. 将 CLI 的 yum repository 添加到 yum 源列表:
```bash
echo -e "[Stripe]\nname=stripe\nbaseurl=https://packages.stripe.dev/stripe-cli-rpm-local/\nenabled=1\ngpgcheck=0" >> /etc/yum.repos.d/stripe.repo
```
1. 安装 CLI:
```bash
sudo yum install stripe
```
#### Scoop
要用 [Scoop](https://scoop.sh/) 安装 Stripe CLI,请运行:
```bash
scoop bucket add stripe https://github.com/stripe/scoop-stripe-cli.git
```
```bash
scoop install stripe
```
#### macOS
要在没有 homebrew 的 macOS 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载您的 CPU 结构类型的最新的 `mac-os` tar.gz 文件。
1. 解压文件:`tar -xvf stripe_[X.X.X]_mac-os_[ARCH_TYPE].tar.gz`。
或者,将二进制文件安装在可以全局执行的位置(例如,`/usr/local/bin`)。
#### Linux
要在没有软件包管理器的 Linux 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载最新的 `linux` tar.gz 文件。
1. 解压文件:`tar -xvf stripe_X.X.X_linux_x86_64.tar.gz`.
1. 将 `./stripe` 移到您的执行路径。
#### Windows
要在没有 Scoop 的 Windows 上安装 Stripe CLI:
1. 从 [GitHub](https://github.com/stripe/stripe-cli/releases/latest) 下载最新的 `windows` zip 文件
1. 解压 `stripe_X.X.X_windows_x86_64.zip` 文件。
1. 将解压缩后的 `stripe.exe` 文件的路径添加到 `Path` 环境变量中。若要了解如何更新环境变量,请参阅 [Microsoft PowerShell 文档](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.3#saving-changes-to-environment-variables)。
> Windows 防病毒扫描程序偶尔会将 Stripe CLI 标记为不安全。这称为误报。有关详细信息,请参阅 GitHub 存储库中的[问题 #692](https://github.com/stripe/stripe-cli/issues/692)。
1. 运行解压的 `.exe` 文件。
#### Docker
Stripe CLI 也可以作为 [Docker 镜像](https://hub.docker.com/r/stripe/stripe-cli)提供。要安装最新版本,请运行:
```bash
docker run --rm -it stripe/stripe-cli:latest
```
### 验证身份
登录并验证您的 Stripe 用户[账户](https://docs.stripe.com/get-started/account/activate.md),以生成一组受限密钥。如需了解更多信息,请参阅 [Stripe CLI 密钥和权限 ](https://docs.stripe.com/stripe-cli/keys.md)。
```bash
stripe login
```
在浏览器中按键盘上的**回车键**以完成认证流程。
```bash
Your pairing code is: enjoy-enough-outwit-win
This pairing code verifies your authentication with Stripe.
Press Enter to open the browser or visit https://dashboard.stripe.com/stripecli/confirm_auth?t=THQdJfL3x12udFkNorJL8OF1iFlN8Az1 (^C to quit)
```
### 确认设置
现在,CLI 已安装完毕,您可以向 [Create a product](https://docs.stripe.com/api/products/create.md) 发出一个 API 请求。
#### bash
```bash
stripe products create \
--name="My First Product" \
--description="Created with the Stripe CLI"
```
在响应对象中查找产品标识符( `id` 中)。保存它以备下一步使用。
如果一切正常,命令行将显示以下响应。
#### bash
```json
{
"id": "prod_LTenIrmp8Q67sa", // 标识符如下所示。
"object": "product",
"active": true,
"attributes": [],
"created": 1668198126,
"default_price": null,
"description": "Created with the Stripe CLI",
"identifiers": {},
"images": [],
"livemode": false,
"metadata": {},
"name": "My First Product",
"package_dimensions": null,
"price": null,
"product_class": null,
"shippable": null,
"sku": "my-first-product-10",
"statement_descriptor": null,
"tax_code": null,
"type": "service",
"unit_label": null,
"updated": 1668198126,
"url": null
}
```
接下来,调用 [Create a price](https://docs.stripe.com/api/prices/create.md),附加一个 30 美元的价格。将 `product` 中的占位符替换为您的产品标识符(例如,`prod_LTenIrmp8Q67sa`)。
#### bash
```bash
stripe prices create \
--unit-amount=3000 \
--currency=usd \
--product="{{PRODUCT_ID}}"
```
如果一切正常,命令行将显示以下响应。
#### bash
```json
{
"id": "price_1KzlAMJJDeE9fu01WMJJr79o", // 标识符如下所示。
"object": "price",
"active": true,
"billing_scheme": "per_unit",
"created": 1652636348,
"currency": "usd",
"livemode": false,
"lookup_key": null,
"metadata": {},
"nickname": null,
"product": "prod_Lh9iTGZhb2mcBy",
"recurring": null,
"tax_behavior": "unspecified",
"tiers_mode": null,
"transform_quantity": null,
"type": "one_time",
"unit_amount": 3000,
"unit_amount_decimal": "3000"
}
```
## 安装 .NET 服务器端 SDK
Stripe .NET 服务器端 SDK 的最新版本是 v50.4.0。它支持 .NET Standard 2.0+、.NET Core 2.0+ 和 .NET Framework 4.6.1+。
检查您的 [.NET SDK](https://docs.microsoft.com/en-us/dotnet/core/install/how-to-detect-installed-versions) 的版本:
```bash
dotnet --list-sdks
```
### 安装库
使用 [.NET Core 命令行界面 (CLI)](https://docs.microsoft.com/en-us/dotnet/core/tools/) 从命令行新建项目:
```bash
dotnet new console
```
要安装库,运行以下命令,将包引用添加到您的项目文件 (`.csproj`) 中:
```bash
dotnet add package Stripe.net
```
用 CLI 安装库后,该库将作为依赖项自动添加到您的项目文件 (`.csproj`) 中。例如:
```xml
Exe
net6.0
enable
enable
```
### 备选安装方式
**NuGet 命令行接口 (CLI)**——您可以用 [NuGet CLI](https://docs.microsoft.com/en-us/nuget/tools/nuget-exe-cli-reference) 安装库:
```bash
nuget install Stripe.net
```
**软件包管理控制台 (PowerShell)**——如果您使用的是[软件包管理控制台 (Package Manager Console) (PowerShell)](https://docs.microsoft.com/en-us/nuget/tools/package-manager-console),请运行以下命令来安装库:
```PowerShell
Install-Package Stripe.net
```
**VisualStudio**——将 Stripe.net 包添加到 Visual Studio:打开 Solution Explorer。右键点击您的项目。点击**管理 NuGet 包**。点击**浏览**选项卡并搜索 **Stripe.net**。点击 **Stripe.net** 包,在选项卡中选择适当的版本,然后点击**安装**。
## 运行您的第一个 SDK 请求
您现在已安装 .NET SDK,可以通过几个 API 请求创建订阅[产品](https://docs.stripe.com/api/products/create.md)并附加[价格](https://docs.stripe.com/api/prices/create.md)。在此示例中,我们使用响应中返回的产品标识符来创建价格。
> 该示例为您的*沙盒* (A sandbox is an isolated test environment that allows you to test Stripe functionality in your account without affecting your live integration. Use sandboxes to safely experiment with new features and changes)环境使用的是您的 Stripe 用户[账户](https://docs.stripe.com/get-started/account/activate.md)的默认密钥。只有您可以看到这些值。
#### 创建产品和价格
```dotnet
using System;
using Stripe;
class Program
{
static void Main(string[] args)
{
var client = new StripeClient("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
var optionsProduct = new ProductCreateOptions
{
Name = "Starter Subscription",
Description = "$12/Month subscription",
};
Product product = client.V1.Products.Create(optionsProduct);
Console.Write("Success! Here is your starter subscription product id: {0}\n", product.Id);
var optionsPrice = new PriceCreateOptions
{
UnitAmount = 1200,
Currency = "usd",
Recurring = new PriceRecurringOptions
{
Interval = "month",
},
Product = product.Id
};
Price price = client.V1.Prices.Create(optionsPrice);
Console.Write("Success! Here is your starter subscription price id: {0}\n", price.Id);
}
}
```
将代码保存到项目中的 `Program.cs` 文件中。从命令行,`cd` 到包含您刚刚保存的文件的目录,然后运行:
#### Program.cs
```bash
dotnet run
```
如果一切正常,命令行将显示以下响应。保存这些标识符,以便在构建集成时使用。
#### bash
```bash
Success! Here is your starter subscription product id: prod_0KxBDl589O8KAxCG1alJgiA6
Success! Here is your starter subscription price id: price_0KxBDm589O8KAxCGMgG7scjb
```
## See also
快速入门到此结束。有关处理您刚创建的产品的付款的几种不同方式,请参阅下面的链接。
- [创建支付链接](https://docs.stripe.com/payment-links.md)
- [Stripe 托管页面](https://docs.stripe.com/checkout/quickstart.md)
- [高级集成](https://docs.stripe.com/payments/quickstart-checkout-sessions.md)