| [ Web Proxy ] |
| Viewing: https://stripe.com/docs/development/quickstart#api-keys | [Back] [Original] |
Check out our no-code docs, use a prebuilt solution from our partner directory, or hire a Stripe-certified expert.
Stripes server-side SDKs and command-line interface (CLI) allow you to interact with Stripes 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.
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 theyre 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 CLIan essential tool that gets you command line access to your Stripe integration. You also install the Stripe Ruby server-side SDK to get access to Stripe APIs from applications written in Ruby.
In this quickstart, youll learn:
Install the Stripe CLI with npm:
npm install --global @stripe/cli
For more installation options for Windows, macOS, Linux, and Docker, check the Stripe CLI readme on GitHub.
After installation, connect the CLI to your Stripe account by logging in:
stripe login
The CLI displays a pairing code and opens the Stripe Dashboard, where you approve access to accounts, sandboxes, and live mode. The CLI stores your credentials in your operating systems secure credential store (when available) and refreshes the session automatically. To authenticate with an API key instead, run stripe login --interactive, use stripe config, pass --api-key, or set the STRIPE_API_KEY environment variable.
Now that youve 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_LTenIrmp8Q67sa).
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"
We recommend managing third-party dependencies using the RubyGems command-line tool, which allows you to add new libraries and include them in your Ruby projects. Check whether RubyGems is installed:
gem --version
If you get gem: command not found, download RubyGems from their downloads page.
The latest version of the Stripe Ruby server-side SDK is v19.4.0. It supports Ruby versions 2.3+.
Check your Ruby version:
ruby -v
Create a gem file and install the generated gem using a bundler with RubyGems.
Add the latest version of the Stripe gem to a project:
bundle add stripe
Install the required gems from your specified sources:
bundle install
Now that you have the Ruby SDK installed, you can create a subscription Product and attach a Price with a couple API requests. Were using the product identifier returned in the response to create the price in this example.
This sample uses the default keys of your Stripe user account for your sandbox environment. Only you can see these values. Follow best practices to manage your keys safely.
require 'rubygems' require 'stripe' # Don't embed any keys in production code. This is an example. # See https://docs.stripe.com/keys-best-practices. client = Stripe::StripeClient.new("sk_test_wU7nrJCZspk1NPDxiQgAF05q") starter_subscription = client.v1.products.create( name: 'Starter Subscription', description: '$12/Month subscription', ) starter_subscription_price = client.v1.prices.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}"
Save the file as create_price.rb. From the command line, cd to the directory containing the file you just saved and run:
ruby create_price.rb
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
This wraps up the quickstart. See the links below for a few different ways to process a payment for the product you just created.
| Web Proxy Viewer | New URL | Original Page |