Payment - Smart-Cart-System/backend-fastapi GitHub Wiki

Payment Module Documentation for Frontend

Endpoints

1. Create Payment

  • URL: /payment/create-payment/{session_id}
  • Method: POST
  • Description: Creates an online payment for a specific session.
  • Path Parameters:
    • session_id (int): The ID of the session for which the payment is being created.
  • Response:
    • 201 Created: Payment created successfully.
    • 500 Internal Server Error: Failed to create the payment.

2. Get Payment

  • URL: /payment/get-payment/{session_id}
  • Method: GET
  • Description: Retrieves the payment URL for a specific session.
  • Path Parameters:
    • session_id (int): The ID of the session.
  • Response:
    • 200 OK: Returns the payment URL.
    • 404 Not Found: Payment not found.

Schemas

1. PaymentRequest

  • Fields:
    • name (str): The name of the payment.
    • customer_name (str): The customer's name.
    • customer_email (str): The customer's email.
    • customer_mobile (str): The customer's mobile number.
    • amount (float): The payment amount.
    • currency (str): The currency of the payment.
    • redirect_url (str): The URL to redirect after payment.
    • callback_url (str): The webhook URL for payment notifications.

** WebSocket Notification in Payment Webhook**

Scenarios When WebSocket Messages Are Sent

  1. Payment Successful:

    • When the transaction is marked as successful, a WebSocket message is sent to notify the client.
    • Message: "Payment successful"
    • Example:
      await notify_clients(payment.session_id, "Payment successful", 0)
      
  2. Payment Failed (Retrying):

    • If the transaction fails but the system allows retry attempts (less than 3), a WebSocket message is sent to inform the client that the system will retry.
    • Message: "Payment failed, retrying"
    • Example:
      await notify_clients(payment.session_id, "Payment failed, retrying", 0)
      
  3. Payment Failed (Final Failure):

    • If the transaction fails and no retry attempts remain, a WebSocket message is sent to notify the client of the final failure.
    • Message: "Payment failed"
    • Example:
      await notify_clients(payment.session_id, "Payment failed", 0)