checkout-stripe
v1.0.1
Published
Stripe Checkout Extension
Maintainers
Readme
Stripe Checkout Extension
This extension provides a simple integration with Stripe Checkout for processing payments.
Setup
- Install dependencies:
npm install- Create a
.envfile in the root directory with the following variables:
STRIPE_SECRET_KEY=your_stripe_secret_key
PUBLIC_URL=your_frontend_url # e.g., http://your-domain.comhttp://3.107.204.138:5003/stripe-checkout1/create-checkout-session
API Endpoint
Create Checkout Session
Endpoint: POST /create-checkout-session
Creates a Stripe checkout session for processing payments.
Request Body:
{
"amount": 9.99, // Required: Price in USD
"orderNumber": "123456789", // Required: Unique order identifier
"customerEmail": "[email protected]", // Optional: Customer's email
"productDetails": { // Required: Product information
"name": "Product Name", // Required: Name of the product
"quantity": 1, // Required: Quantity to purchase
"description": "Description", // Optional: Product description
"images": [ // Optional: Product images
"https://example.com/image1.jpg"
]
}
}Success Response:
{
"checkout_url": "https://checkout.stripe.com/...",
"session_id": "cs_test_..."
}Error Response:
{
"error": "Error message here"
}Success and Cancel URLs
The extension will redirect to:
- Success:
${PUBLIC_URL}/payment-success?session_id={CHECKOUT_SESSION_ID} - Cancel:
${PUBLIC_URL}/payment-cancel
Make sure these routes are handled in your frontend application.
Error Handling
The extension includes validation for:
- Required environment variables
- Required request body fields
- Product details validation
- Stripe API errors
Example Usage
// Example using fetch
const response = await fetch('/create-checkout-session', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
amount: 29.99,
orderNumber: "ORD123456",
customerEmail: "[email protected]",
productDetails: {
name: "Premium Package",
quantity: 1,
description: "Complete premium package with all features",
images: ["https://example.com/product.jpg"]
}
})
});
const { checkout_url } = await response.json();
window.location.href = checkout_url;Security Notes
- Always use HTTPS in production
- Never expose your STRIPE_SECRET_KEY
- Validate order numbers and amounts on your server
- Consider implementing webhook handling for payment confirmation
