Skip to main content

Overview

The Checkout API enables you to create secure payment sessions for FitAiid products using Stripe. This endpoint handles product purchases, subscription plans, and digital fitness content.
All payment processing is handled securely through Stripe. FitAiid never stores sensitive payment information.

Create Checkout Session

Headers

Authorization
string
required
Bearer token: Bearer YOUR_JWT_TOKEN

Body Parameters

items
array
required
Array of products to purchase
successUrl
string
required
URL to redirect after successful payment
cancelUrl
string
required
URL to redirect if payment is cancelled
shippingAddress
object
required
Shipping address information
shippingMethod
string
default:"standard"
Shipping method selection
couponCode
string
Discount coupon code
customerNotes
string
Special delivery instructions (max 500 characters)

Response

curl -X POST https://api.fitaiid.com/api/checkout/create-session \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "items": [
      {
        "productId": "507f1f77bcf86cd799439011",
        "quantity": 2
      },
      {
        "productId": "507f1f77bcf86cd799439012",
        "quantity": 1
      }
    ],
    "shippingAddress": {
      "firstName": "Carlos",
      "lastName": "Rodriguez",
      "street": "Calle 123 #45-67",
      "city": "Bogotá",
      "state": "Cundinamarca",
      "zipCode": "110111",
      "country": "Colombia",
      "phone": "+573001234567"
    },
    "shippingMethod": "express",
    "successUrl": "https://fitaiid.com/checkout/success",
    "cancelUrl": "https://fitaiid.com/checkout/cancel",
    "customerNotes": "Please deliver in the afternoon"
  }'
After receiving the response, redirect the user to the checkoutUrl to complete payment on Stripe’s secure checkout page.

Verify Payment Status

Path Parameters

sessionId
string
required
Stripe checkout session ID returned from create-session

Response

curl -X GET https://api.fitaiid.com/api/checkout/verify/cs_test_a1b2c3d4e5f6... \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Apply Coupon Code

Body Parameters

couponCode
string
required
Coupon code to validate
items
array
required
Array of cart items to calculate discount

Response

curl -X POST https://api.fitaiid.com/api/checkout/apply-coupon \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "couponCode": "FITAIID20",
    "items": [
      {"productId": "507f1f77bcf86cd799439011", "quantity": 2}
    ]
  }'

Stripe Webhook Handler

This endpoint is called directly by Stripe and should not be called by clients. It requires Stripe signature verification.

Webhook Events Handled

checkout.session.completed
Triggered when a customer completes the checkout session
  • Creates order record in database
  • Updates product inventory
  • Sends confirmation email
  • Updates payment status to paid
checkout.session.expired
Triggered when a checkout session expires
  • Updates order status to cancelled
  • Releases reserved inventory
payment_intent.succeeded
Triggered when payment is successfully processed
  • Confirms order status
  • Triggers fulfillment workflow
payment_intent.payment_failed
Triggered when payment fails
  • Updates payment status to failed
  • Sends payment failure notification
charge.refunded
Triggered when a charge is refunded
  • Updates order status to refunded
  • Restores product inventory
  • Sends refund confirmation

Configuration

To set up the webhook in your Stripe dashboard:
  1. Go to DevelopersWebhooks in Stripe Dashboard
  2. Click Add endpoint
  3. Enter URL: https://api.fitaiid.com/api/checkout/webhook
  4. Select events to listen for:
    • checkout.session.completed
    • checkout.session.expired
    • payment_intent.succeeded
    • payment_intent.payment_failed
    • charge.refunded
  5. Copy the Signing secret and add to your environment variables as STRIPE_WEBHOOK_SECRET

Security

Webhook Signature Verification

All webhook requests are verified using Stripe’s signature in the stripe-signature header. Requests without valid signatures are rejected.

Calculate Shipping Cost

Body Parameters

items
array
required
Array of cart items
shippingMethod
string
required
Desired shipping method: standard, express, overnight, or pickup
city
string
required
Delivery city for location-based calculations

Response

{
  "success": true,
  "shippingMethod": "express",
  "shippingCost": 45000,
  "formattedCost": "$45,000",
  "estimatedDays": 3,
  "carrier": "Servientrega",
  "freeShippingThreshold": 200000,
  "amountToFreeShipping": 0,
  "isFreeShipping": false
}
Orders over $200,000 COP qualify for free standard shipping. Express and overnight shipping incur additional charges.

Error Responses

400 Bad Request
Invalid request parameters
401 Unauthorized
Missing or invalid authentication token
404 Not Found
Product or checkout session not found
500 Internal Server Error
Stripe API error or server issue

Testing

Test Cards

Use these test card numbers in Stripe test mode:

Successful Payment

Card Number: 4242 4242 4242 4242Expiry: Any future dateCVC: Any 3 digits

Payment Declined

Card Number: 4000 0000 0000 0002Use this to test declined payments

3D Secure Required

Card Number: 4000 0027 6000 3184Use this to test Strong Customer Authentication
See Stripe Testing Documentation for more test scenarios.

Build docs developers (and LLMs) love