Skip to main content

Process service payment

POST 

/truckers/payment/pay

Process the payment for a service using the default payment method in Stripe.

Technical Flow:

  1. Verify user authentication
  2. Retrieve the company associated with the user
  3. Validate that Stripe is enabled for the company
  4. Verify that a default payment method exists
  5. Find the delivery associated with the serviceCode
  6. Calculate the amount and commission
  7. Create a PaymentIntent in Stripe
  8. Save the reference in the delivery
  9. Send a confirmation email

Validations:

  • User must be authenticated (valid JWT)
  • User must belong to a valid company
  • Stripe must be enabled for the company
  • A default payment method must exist
  • serviceCode must correspond to an existing delivery

Required Parameters:

  • serviceCode: Unique code of the service to be paid

Example Request:

{
serviceCode: DEL123456
}

Example Successful Response:

{
success: true
}

Error Cases:

  • 400 Bad Request:
    • serviceCode not provided
    • serviceCode not valid
  • 401 Unauthorized:
    • Invalid JWT token
    • User has no associated company
    • Stripe not enabled for the company
    • No default payment method
  • 500 Internal Server Error: Error processing payment in Stripe

Frontend Usage Example:

// Frontend: Process service payment
const processPayment = async (serviceCode) => {
try {
const response = await axios.post(
'/truckers/payment/pay',
{ serviceCode },
{ headers: { Authorization: `Bearer ${token}` } }
);

if (response.data.success) {
showPaymentSuccess(); // Show confirmation
}
} catch (error) {
handleError(error);
}
};

Important Notes:

  • Uses the configured default payment method
  • The amount is automatically calculated based on the auction
  • A 6% commission is applied by default
  • Generates a PaymentIntent record in Stripe
  • Sends confirmation email to both parties

Request

Responses

Payment successfully processed.