DEV Community

Cover image for Testing Payments with Stripe’s New Postman Collections
Charles Watkins for Stripe

Posted on • Edited on • Originally published at blog.postman.com

Testing Payments with Stripe’s New Postman Collections

Stripe 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 on the Postman Public API Network to help anyone explore our payment, billing, and identity APIs.

The Stripe public workspace and collections 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 API.

Getting started with the Stripe API collection

To start, go to the Stripe public workspace 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. Once you’ve registered for an account, navigate to the Stripe dashboard, switch your account to test mode, and copy your secret key.

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, 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

Creating a prebuilt checkout form

You can use the Stripe Checkout API 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

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 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 with any expiration date and CVC code:

Stripe Checkout form for $20.00 T-shirt being completed.

Try combining the Stripe Checkout and Customers APIs to test more advanced payment scenarios like associating the payment with an existing customer, saving a card for future usage, or creating a recurring payment.

We look forward to seeing what you create. Please share your customized workspace with us at @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 or on YouTube.

Top comments (0)