Skip to main content
Create a Stripe checkout session to subscribe to a paid plan (BASIC or PRO). Returns a URL where the user can complete the payment.

Authentication

Requires a valid JWT token in the Authorization header.
Authorization: Bearer YOUR_JWT_TOKEN

Request Body

plan
string
required
The plan to subscribe to. Must be “BASIC” or “PRO”. The FREE plan doesn’t require a checkout session.
billing
string
default:"monthly"
Billing frequency: “monthly” or “annual”. Annual billing provides a discount.
promotionCode
string
Optional promotion/discount code to apply to the subscription. Must be 3-50 characters.

Response

sessionId
string
The Stripe checkout session ID.
url
string
The URL to redirect the user to complete the checkout. This URL expires after 24 hours.
message
string
Success message.

Trial Period

New users are eligible for a 30-day free trial on BASIC and PRO plans. The trial period can also be extended through promotion codes.

Example Request (Monthly)

cURL
curl -X POST https://api.tresacontafy.com/api/subscription/create-checkout \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "plan": "PRO",
    "billing": "monthly"
  }'

Example Request (Annual with Promo Code)

cURL
curl -X POST https://api.tresacontafy.com/api/subscription/create-checkout \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "plan": "PRO",
    "billing": "annual",
    "promotionCode": "SAVE20"
  }'

Example Response

{
  "sessionId": "cs_test_a1b2c3d4e5f6g7h8i9j0",
  "url": "https://checkout.stripe.com/c/pay/cs_test_a1b2c3d4e5f6g7h8i9j0",
  "message": "Checkout session creada exitosamente"
}

Error Responses

401
error
Unauthorized - Invalid or missing JWT token.
400
error
Bad request - Invalid plan, already subscribed to this plan, or invalid promotion code.Possible error messages:
  • “Plan inválido” - Plan must be BASIC or PRO
  • “El plan FREE no requiere suscripción”
  • “Ya tienes este plan activo”
  • “Código de descuento inválido” - Promotion code is invalid or expired
500
error
Internal server error or Stripe API error.
After successful payment, the user will be redirected to the success URL with the session ID. The webhook will handle updating the subscription in the database.

Build docs developers (and LLMs) love