• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
vawogbemi

vawogbemi

StripeClientDemo

Public
Like
StripeClientDemo
Home
Code
3
README.md
index.html
H
index.ts
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
README.md
Code
/
README.md
Search
5/14/2025
Viewing readonly version of main branch: v9
View latest version
README.md

Stripe Checkout with Direct Price Implementation

This is a Stripe Checkout implementation that uses the actual price displayed on the page instead of a predefined price ID. It combines client-side and server-side approaches to create a seamless checkout experience.

How It Works

  1. The page loads with a product display and checkout button
  2. When the user clicks "Proceed to Checkout":
    • The code extracts the price directly from the page ($19.99)
    • It sends this price to a server-side endpoint (/create-checkout-session)
    • The server creates a Stripe Checkout Session with this exact amount
    • The client redirects to Stripe's hosted checkout page
  3. After payment, the user is redirected back to the success or cancel URL
  4. The page displays a success or cancellation message based on the URL parameters

Important Setup

  1. Environment Variables:

    • Set your STRIPE_SECRET_KEY in Val Town environment variables
    • Replace the placeholder publishable key (pk_test_TYooMQauvdEDq54NiTphI7jx) with your actual Stripe publishable key in the HTML
  2. Advantages of This Approach:

    • Uses the displayed price directly from the UI
    • No need to create and manage price IDs in Stripe dashboard
    • Prices can be changed in the UI without updating Stripe
    • More secure than client-side only approaches
  3. Security Considerations:

    • Never include your Stripe secret key in client-side code
    • The publishable key is safe to include in client-side code
    • Server-side validation ensures price integrity

Customization

To customize this implementation:

  1. Update the product details and pricing in the HTML
  2. The checkout will automatically use whatever price is displayed on the page
  3. Customize the success and cancel messages
  4. Adjust the styling as needed using Tailwind classes

Technical Details

  • Uses Stripe's Checkout Sessions API on the server
  • Extracts the price directly from the UI
  • Converts the price to cents (Stripe's required format)
  • Creates a dynamic product with the specified price
  • Handles errors gracefully with user feedback
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.