Booking API course · updated 2026-10-05
Lesson 7: take the card with Stripe.js on your page
The card is entered inside Stripe's Payment Element on your page, so card data never touches your server or ours. You initialize Stripe.js with the publishable key from the /intents response, mount the element with the client_secret, and confirm. This lesson is the exact code.
Before you start
- Lesson 6: a client_secret and the stripe object from the response
- Stripe.js loaded on your page: https://js.stripe.com/v3/
- ## Load Stripe.js and initialize
```
<script src="https://js.stripe.com/v3/"></script>
```
const intent = /* data from POST /intents */;
const stripe = Stripe(intent.stripe.publishable_key, intent.stripe.account ? { stripeAccount: intent.stripe.account } : {});
const elements = stripe.elements({ clientSecret: intent.client_secret, appearance: { theme: "stripe" } });
const paymentElement = elements.create("payment");
paymentElement.mount("#payment-element");
```
For Canadian companies stripe.account is set and the stripeAccount option is mandatory: the PaymentIntent lives on the company's connected Stripe account. For US companies it is null and the intent lives on the platform account. - ## Confirm the card
```
const { error, paymentIntent } = await stripe.confirmPayment({
elements,
confirmParams: { return_url: window.location.href },
redirect: "if_required",
});
if (error) { showMessage(error.message); return; }
// paymentIntent.status is "succeeded" or "requires_capture" (review hold): both mean authorized.
await confirmOrder(intent.session_id, intent.payment_intent_id); // lesson 8
```
redirect: "if_required" keeps the customer on your page for cards; wallets or bank redirects return to return_url with the PaymentIntent id in the query string, so your return page must call POST /confirm as well. - ## What the customer should see
The amount on the pay button must be gross_total from /intents (what the card is charged), with processing_fee shown as its own line when card_fee_handling is customer_pays or split_50_50. Show the company's rental agreement (GET /company booking.rental_agreement: use_standard or custom_content) and a checkbox the customer ticks before paying; that is the terms_accepted you already sent as true. - ## Testing without a real card
There is no sandbox: the engine runs on live Stripe accounts. For a true end-to-end test, book a 10 dollar order on your own company with a real card, then refund it from Order History. Quotes, checks and intents cost nothing; an intent that is never confirmed expires on its own.
What happens next
- Right after confirmPayment resolves without error, call POST /confirm (lesson 8). Do not wait for a webhook to show the order number.
Troubleshooting
Stripe.js says the client_secret does not belong to this account.
A Canadian company: you initialized Stripe without stripeAccount. Pass { stripeAccount: intent.stripe.account }.
The card was declined.
Show error.message from confirmPayment and let the customer try another card. The same session_id and client_secret stay valid; no new /intents call is needed.
Related guides
© 2026 Dumpster Controls. All rights reserved. Made in the USA.