Set up your development environment
Get familiar with the Stripe CLI and our server-side SDKs.
Stripe’s server-side SDKs and command-line interface (CLI) allow you to interact with Stripe’s REST APIs. Start with the Stripe CLI to streamline your development environment and make API calls.
Use the SDKs to avoid writing boilerplate code. To start sending requests from your environment, choose a language to follow a quickstart guide.
Chrome extensions
We recommend you build your payment integration with Stripe (such as Elements or Checkout) on your own website. Then, set up your Chrome extension to send users to this payment page when they’re ready to complete a purchase.
This method is more secure and easier to maintain than trying to handle payments directly within the extension.
In this quickstart, you install the Stripe CLI—an essential tool that gets you command line access to your Stripe integration. You also install the Stripe Go server-side SDK to get access to Stripe APIs from applications written in Go.
What you learn
In this quickstart, you’ll learn:
- How to call Stripe APIs without writing a line of code
- How to manage third-party dependencies using Go modules
- How to install the latest Stripe Go SDK v82.0.0
- How to send your first SDK request
Initial setup
First, create a Stripe account or sign in.
Set up the Stripe CLI
Install
From the command-line, use an install script or download and extract a versioned archive file for your operating system to install the CLI.
Authenticate
Log in and authenticate your Stripe user Account to generate a set of restricted keys. To learn more, see Stripe CLI keys and permissions.
stripe login
Press the Enter key on your keyboard to complete the authentication process in your browser.
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)
Confirm setup
Now that you’ve installed the CLI, you can make a single API request to Create a product.
stripe products create \ --name="My First Product" \ --description="Created with the Stripe CLI"
Look for the product identifier (in id
) in the response object. Save it for the next step.
If everything worked, the command-line displays the following response.
{ "id":
, "object": "product","prod_LTenIrmp8Q67sa"
Next, call Create a price to attach a price of 30 USD. Swap the placeholder in product
with your product identifier (for example, prod_
).
stripe prices create \ --unit-amount=3000 \ --currency=usd \ --product=
{{PRODUCT_ID}}
If everything worked, the command-line displays the following response.
{ "id":
, "object": "price","price_1KzlAMJJDeE9fu01WMJJr79o"
Manage third-party dependencies
We recommend managing third-party dependencies using Go modules, which allows you to add new libraries and include them in your Go projects.
Initialize Go
If you’re starting from scratch in a new directory, you first need to create a go.
file for tracking dependencies. For example:
go mod init stripe-example
Install the Go server-side SDK
The latest version of the Stripe Go server-side SDK is v82.0.0. It supports Go versions 1.15+.
Install the library
Install the library with Go modules, a package manager for Go:
go get github.com/stripe/stripe-go/v82
After you install the library with Go modules to a new project, the library is automatically added as a dependency in your project’s go.mod file. For example:
module stripe-example go 1.18 require github.com/stripe/stripe-go/v82 82.0.0 // indirect
Synchronize dependencies
To keep your managed dependency set tidy for an existing project, run the following command to sync your code’s dependencies.
go mod tidy
Run your first SDK request
Now that you have the Go SDK installed, you can create a subscription Product and attach a Price with a couple API requests. We’re using the product identifier returned in the response to create the price in this example.
Note
package main import ( "fmt" "github.com/stripe/stripe-go/v82" "github.com/stripe/stripe-go/v82/product" "github.com/stripe/stripe-go/v82/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) }
Save the file as create_
. From the command line, cd
to the directory containing the file you just saved and run:
go run create_price.go
If everything worked, the command line shows the following response. Save these identifiers so you can use them while building your integration.
Success! Here is your starter subscription product id: prod_0KxBDl589O8KAxCG1alJgiA6 Success! Here is your starter subscription price id: price_0KxBDm589O8KAxCGMgG7scjb
See also
This wraps up the quickstart. See the links below for a few different ways to process a payment for the product you just created.