Testing Payments with Stripe’s New Postman Collections
Tags: testing, payments, postman, stripe
Published: 2021-08-24 15:05:22

[Stripe](https://stripe.com/) builds payments infrastructure for the internet and exposes APIs for a variety of use cases. To improve the overall developer experience, we recently launched our own [team profile](https://www.postman.com/stripedev/) on the [Postman Public API Network](https://www.postman.com/explore) to help anyone explore our [payment](https://stripe.com/payments), [billing](https://stripe.com/billing), and [identity APIs](https://stripe.com/identity). 

The [Stripe public workspace and collections](https://www.postman.com/stripedev/workspace/stripe-developers/overview) in Postman include request templates for all of our API resources, lists all available parameters, and offers configurable variables for authenticating API requests against your account.

In this guide, we'll cover the steps to getting started along with a use case for the [Stripe Checkout](https://stripe.com/payments/checkout) API.

## Getting started with the Stripe API collection

To start, go to the [Stripe public workspace](https://www.postman.com/stripedev/workspace/stripe-developers/overview) and fork the Stripe API collection. Next, fork the Stripe environment template.

In order to make test API calls, you’ll need a test Stripe secret key. You can get a secret key by [registering for a Stripe account](https://dashboard.stripe.com/register). Once you’ve registered for an account, navigate to the [Stripe dashboard](https://dashboard.stripe.com/dashboard), switch your account to test mode, and [copy your secret key](https://stripe.com/docs/keys#obtain-api-keys). 

Next, navigate to your forked Stripe environment and set the `secret_key` variable’s initial value to your secret key, which should be in your clipboard, and save. Select your new Postman environment as the active environment.

Finally, go to the top-level folder of the Stripe API collection. Under the **Authorization** tab, set the token to the `{{secret_key}}` variable and save. This will ensure that all API calls in the collection are using your test account API credentials. Now you’re ready to explore the Stripe APIs by making test API calls to your account using Postman.

## Exploring the API

The Stripe API collection includes all of Stripe’s APIs organized by resource. Each resource contains all possible request shapes, and each request shape includes all possible fields. The required fields are enabled by default to make building your requests easier. All fields, required or not, include a description that specifies how and when they can be used. Before making a request, it’s good practice to review the fields to see which ones are required and what they do.

Below is an example of creating a [customer](https://stripe.com/docs/api/customers), which is a Stripe object that lets you associate payments, payment methods, and subscriptions with an individual customer: 

[![Postman request that generates a Customer object with an email](https://lh6.googleusercontent.com/Bl6PkgErgxJp59NMiwl2UmBLIhPjwjPMany5GlF4ihe693Ti7nBpfLE0L2b7EQ3dtV8CHLY7PeuOWIm4HqNgxDdtT-iCtQR_MnNROm-gObx6nOjpxp51ZfF1qyotCvv_xw7dInCZ)](https://blog.postman.com/wp-content/uploads/2021/08/image4-1.png)

## Creating a prebuilt checkout form

You can use the [Stripe Checkout API](https://stripe.com/docs/payments/checkout) to generate prebuilt, conversion-optimized checkout forms that are hosted on Stripe. Stripe Checkout can be used to accept single payments, set up recurring payments, and save cards for future usage. 

To try it out, let’s generate a checkout form for a $20 T-shirt. First, navigate to the **Checkout** folder and select the **Create a Session** request. Update the request to include values for the `cancel_url`, `success_url`, and the `line_items` keys. You can see an example of a minimum viable API call to create a Checkout session below:

[![Postman request that generates a Stripe Checkout Session for one-time payment](https://lh5.googleusercontent.com/FiDlezmS5UrDi94GtFvH7ocM557xgETj3ulG4hfcBdd4BA_hMpmWyB1Kg3yS2qItZZtEp-Q5lRVs5HTTQIjSi1ShFebk8nbnHaUgE1VKlEL55YtFRr0oISfRzz3kic9O67_sXW3I)]
(https://blog.postman.com/wp-content/uploads/2021/08/image1-2.png)


The API call creates a test checkout form for a single T-shirt for $20.00. The form can accept cards and digital wallets. When the customer completes the checkout form, they’re redirected to our [https://example.com/success](https://example.com/success) URL. 

You can test the checkout form on your own by clicking on the URL in the response body. You can make a test payment by completing the payment form using the [4242 4242 4242 4242 test card](https://stripe.com/docs/testing#cards) with any expiration date and CVC code: 

[![Stripe Checkout form for $20.00 T-shirt being completed.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2zkxvfftb4gw3wp9g1go.gif)]
(https://blog.postman.com/wp-content/uploads/2021/08/image3.gif)

Try combining the Stripe Checkout and Customers APIs to test more advanced payment scenarios like [associating the payment with an existing customer](https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=checkout#handling-existing-customers), [saving a card for future usage](https://stripe.com/docs/payments/save-and-reuse?platform=checkout), or [creating a recurring payment](https://stripe.com/docs/billing/subscriptions/checkout).

We look forward to seeing what you create. Please share your customized workspace with us at [@StripeDev](https://twitter.com/StripeDev). We’d love to highlight what you’re building in the future.

Charles Watkins is a developer advocate at Stripe and lives in Seattle. You can find him on Twitter at [@charlesw_dev](https://twitter.com/charlesw_dev) or on YouTube.