Skip to main content

Set up new payment method

POST 

/truckers/payment/setup_payment_method

Generate a URL to set up a new payment method in Stripe.

Technical Flow:

  1. Verify user authentication
  2. Get the company associated with the user
  3. Verify that the payment method limit is not exceeded (max. 10)
  4. Create a session in the Stripe portal to add payment methods
  5. Return the URL to redirect the user

Validations:

  • User must be authenticated (valid JWT)
  • User must belong to a valid company
  • The company must have an associated Stripe account
  • Must not exceed the payment method limit (10)

Required Parameters:

  • returnUrl: URL to which Stripe will redirect after setting up the payment method

Example Request:

{
returnUrl: https://app.cargoffer.com/payment/success
}

Example Success Response:

{
url: https://checkout.stripe.com/setup/cs_test_abc123
}

Error Cases:

  • 400 Bad Request:
    • Missing returnUrl parameter
    • Payment method limit reached (10)
  • 401 Unauthorized:
    • Invalid JWT token
    • User has no associated company
    • No Stripe account configured
  • 500 Internal Server Error: Error connecting to Stripe

Frontend Usage Example:

// Frontend: Set up a new payment method
const setupPaymentMethod = async (returnUrl) => {
try {
const response = await axios.post(
'/truckers/payment/setup_payment_method',
{ returnUrl },
{ headers: { Authorization: `Bearer ${token}` } }
);

if (response.data.url) {
window.location.href = response.data.url; // Redirect to Stripe
}
} catch (error) {
handleError(error);
}
};

Request

Responses

URL of the Stripe portal to set up payment method