All Cents apps use Stripe to manage payments.
We do not store card data in our system, as it is managed by Stripe.
This guide will walk you through the process of securely collecting
a customer’s card details and adding them as a new payment method using Dispatch API and Stripe.js.
Overview of the Flow
Example with React application
Frontend (React): On form submission, use Stripe’s createPaymentMethod method to convert the card details into a secure token (pm_…).
Backend (Dispatch API): We receive the token, use it with our Stripe backend SDK to verify a Payment Method and attach it to the customer in our system.
Prerequisites
You have Publishable Key for Stripe library provided by Cents
Step 1. Install Stripe.js
You need to install the @stripe/stripe-js and @stripe/react-stripe-js libraries, which provide React-friendly hooks and components for Stripe Elements.
Step 2. Create the Stripe Instance and Context Provider
In your form component or a top-level component, create a Stripe promise and provide it to your application using the Elements provider.
Put to the function loadStripe the KEY publishable-key-here that was provided by CENTS
What Dispatch API Expects
Your frontend code is now correctly configured to send a request to Dispatch API endpoint:
Endpoint: POST /customers/payment-methods
Request Body (JSON):
On success, the API returns the saved payment method record:
Save the returned paymentMethodToken. You will need it to specify a payment method when creating or updating a service order.
By following this guide, you have implemented a secure, PCI-compliant way to add new payment methods without sensitive card data ever touching servers.