Skip to main content

Get payment URLs for subscription plans

GET 

/truckers/payment/urls

Returns Stripe checkout URLs for the different available subscription plans.

Technical Flow:

  1. Verifies user authentication
  2. Gets the company associated with the user
  3. Queries available plans in the database
  4. Gets Stripe prices using toolsStripe.getPricesList()
  5. Creates a checkout session for each plan
  6. Associates the Stripe customer if it exists
  7. Returns URLs ready to redirect the user

Important Details:

  • Uses subscription mode for recurring payments
  • Automatically associates the Stripe customer if it exists
  • Uses the company's billing email if no Stripe customer exists
  • Generates a unique client_reference_id for each company

Information included per plan:

  • id_plan: Unique plan identifier
  • name: Plan name
  • description: Plan description
  • price: Plan price
  • url: Stripe checkout URL

Validations:

  • User must be authenticated (valid JWT)
  • User must belong to a valid company
  • The company must have a configured billing email

Response Example:

[
{
id_plan: plan_basic,
name: Basic Plan,
description: Access to basic features,
price: 9.99,
url: https://checkout.stripe.com/pay/cs_test_abc123
},
{
id_plan: plan_premium,
name: Premium Plan,
description: Full access to all features,
price: 19.99,
url: https://checkout.stripe.com/pay/cs_test_xyz456
}
]

Frontend Usage Example:

// Frontend: Get payment URLs
const getPaymentUrls = async () => {
try {
const response = await axios.get('/truckers/payment/urls', {
headers: { Authorization: `Bearer ${token}` }
});

if (response.data.length > 0) {
displayPlans(response.data); // Display available plans
}
} catch (error) {
handleError(error);
}
};

Error Cases:

  • 401 Unauthorized:
    • Invalid JWT token

Responses

List of payment URLs with details of each plan.