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:
- Verify user authentication
- Get the company associated with the user
- Verify that the payment method limit is not exceeded (max. 10)
- Create a session in the Stripe portal to add payment methods
- 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
- 200
- 400
- 401
URL of the Stripe portal to set up payment method
Incorrect request. Possible causes:
- Missing returnUrl parameter
- Payment methods limit reached (10)
Unauthorized. Possible causes:
- Invalid JWT token
- User has no associated company
- No Stripe account configured