Optional Lab - Complete Checkout Flow with Payment
Optional Lab - Complete Checkout Flow with Payment
Optional Lab - Complete Checkout Flow with Payment
Our previous workflow simulated a checkout workflow, using the GraphQL Storefront API to create a cart, add a product, add shipping and billing information, and “complete” the checkout by creating an incomplete order.
Completing this workflow to “place” an order in your BigCommerce store requires processing payment via the REST Payments API. Follow these exercise steps if you want to complete your Postman checkout workflow with this step, or feel free to skip it, since this step doesn’t pertain to the GraphQL API.
Our general prerequisites remain the same, but we must add to those a required configuration for payments.
Your store must have the following payment configuration:
A gateway in sandbox mode is important for the successful use of a dummy credit card number, and the enabled payment method must be compatible with the Payments API. The following shows an example of enabling Test Mode with the Stripe payment gateway:

Consider setting up a sandbox account for one of the following payment gateways:
For more about configuring payments, see the article below:
An Important Note About Payments
Our example requests will involve directly supplying a credit card number. For real-world implementations directly handling credit card numbers, you must consider the implications for PCI DSS compliance. If an application passes credit card information to BigCommerce, that application’s PCI compliance and Cardholder Data Environment (CDE) are not managed by BigCommerce.
You can minimize your PCI compliance burden by using the Stored Credit Cards feature provided by BigCommerce. Assuming a cart has a customer ID associated with it, and the customer has previously stored a credit card with BigCommerce, the application can use the customer’s stored payment method to make a payment instead of directly entering a credit card number.
Redirecting to or embedding the BigCommerce checkout means sensitive payment data is never directly entered or transmitted by your frontend application, leaving the burden of PCI compliance to BigCommerce. This is an advantage of this approach. Carefully consider PCI compliance when planning your headless implementation.
The previous exercise added to your existing Postman configuration with:
order_id variable added to the collectionMake sure you have run through your checkout workflow requests and have an order_id value stored before proceeding.
Now that we have an incomplete order, we need to find out how we can process payment to complete that order. From this step through the rest of the purchasing workflow, we must use the REST Payments API.
Remember that, to be compatible with our workflow, your store must have at least one payment provider in test mode. We will retrieve the list of accepted payment methods, then store the ID of the first payment method with “test_mode” equal to TRUE.
{{v3_token}}.)You should see a response body with a collection of payment methods, and the payment provider for which you enabled test mode should clearly indicate "test_mode": true.
If you intend to use a stored payment instrument (e.g., credit card) to complete payment rather than passing credit card data to the Payments API, you will need to retrieve the customer’s stored payment instrument ID at this point. For the response to include a stored payment instrument, several conditions must be met:
customer_id associated with it (this would have required using the GraphQL assignCartToCustomer mutation).Observe the stored_instruments array in the response body to find stored payment instrument IDs.
Let’s proceed to test the response and store the values we need, which in this case includes only the ID of the appropriate payment method.
payment_method_id variable is populated on the collection.Before we can process a payment, we must generate a payment access token that will then be used to authenticate with payments.bigcommerce.com.
Let’s verify the response contains a token and store it.
pat variable is populated on the collection.All right, it’s time to do the thing you came here to do: complete a checkout with a payment. This example will pass a test credit card to the BigCommerce Payments API on the assumption that your store is configured to use a payment gateway like Stripe (not the Test Payment Gateway) in test mode and that the payment gateway will accept certain test credit card numbers, such as 4111111111111111. See the Stripe Testing documentation for more ways to use test mode.
It’s worth noting again that you must consider the PCI compliance implications for your application and organization if you are building an application that passes credit card numbers to the BigCommerce API. We’ve discussed some alternative ways to process payment, including embedding a BigCommerce-hosted checkout page in your web app and using Stored Credit Cards with the Payments API.
Note that the Authorization header contains the actual string “PAT” followed by the value of the collection variable we stored in the last request.
You should also now be able to identify a new order in your BigCommerce control panel. (Orders > View Orders)