Skip to main content

Delete payment method

DELETE 

/truckers/payment/payment_method

Remove a payment method associated with the carrier in Stripe.

Technical Flow:

  1. Verify user authentication
  2. Retrieve the company associated with the user
  3. Validate that the payment method belongs to the company's Stripe customer
  4. Verify that the method is not the default
  5. Check that it is not in use in active transactions
  6. Delete the method using toolsStripe.deletePaymentMethod

Validations:

  • User must be authenticated (valid JWT)
  • User must belong to a valid company
  • The payment method must belong to the company's Stripe customer
  • The payment method must not be in use in active transactions
  • The payment method must not be the default

Request Example:

// Frontend: Delete payment method
const deletePaymentMethod = async (paymentMethodId) => {
try {
const response = await axios.delete(
`/truckers/payment/payment_method/${paymentMethodId}`,
{ headers: { Authorization: `Bearer ${token}` } }
);

if (response.data.success) {
refreshPaymentMethods(); // Refresh payment methods list
}
} catch (error) {
handleError(error);
}
};

Error Cases:

  • 400 Bad Request: Payment method ID not provided
  • 401 Unauthorized:
    • Invalid JWT token
    • Payment method does not belong to the user
    • Payment method is the default
    • Payment method is in use in active transactions
  • 500 Internal Server Error: Error deleting from Stripe

Request

Responses

Method successfully removed