/routes/payment.js
Purpose
Defines the route for initiating a Stripe checkout session, allowing clients to make payments using a Stripe-hosted checkout page.
Prerequisites
This route requires the following environment variables:
TEST_PRODUCT_PRICE_ID
: The Price ID for the product in Stripe (available in the Stripe Dashboard).TEST_COUPON_ID
: The Coupon ID for discounts in Stripe.
Route: /create-checkout-session
Method:
POST
Description: Creates a Stripe checkout session for processing payments.
Request Body: No specific body fields are required.
Response:
On success, returns the
id
of the created session.On failure, returns a 500 status with an error message.
Stripe Checkout Session Configuration
payment_method_types
: Accepts card payments.line_items
: Contains the product’s price ID and quantity.mode
: Set to"payment"
for a one-time payment.discounts
: Applies a coupon based on the providedTEST_COUPON_ID
.success_url
: Redirects to the success page upon payment completion.cancel_url
: Redirects to the cancellation page if payment is canceled.
Notes
Dependencies: Uses
stripeTest
(a Stripe instance) from the/config/stripe
file.Environment Setup: Ensure
.env
has the correct Stripe credentials and product IDs.
This route enables streamlined payment handling using Stripe’s checkout, making it a plug-and-play payment solution.
This documentation provides a focused overview of the payment route’s purpose, configuration, and usage.
Last updated