Skip to main content

Payment Service โ€“ API Reference ๐Ÿ’ณ

This document describes the payment-related APIs exposed by the Payment Service in ShopVerse.

Payments are handled securely using Razorpay and all APIs are accessed via the API Gateway.


๐ŸŒ Base URLโ€‹


/api/payments


๐Ÿ” Authentication & Authorizationโ€‹

  • JWT is validated at the API Gateway
  • Gateway injects:
    • X-User-Email
    • X-User-Role
  • Only authenticated users can initiate payments
  • Admin access is restricted to reporting APIs

๐Ÿ’ฐ Create Payment Orderโ€‹

Initiate a payment for an existing order.

โžค Endpointโ€‹


POST /api/payments/create

โžค Request Bodyโ€‹

{
"orderId": "ORD789",
"amount": 5497
}

โžค Success Response (200 OK)โ€‹

{
"razorpayOrderId": "order_JH23KLM",
"amount": 5497,
"currency": "INR"
}

๐Ÿ“„ Get My Paymentsโ€‹

Fetch payment history of the authenticated user.

โžค Endpointโ€‹

GET /api/payments/my

โžค Success Response (200 OK)โ€‹

[
{
"paymentId": "PAY123",
"orderId": "ORD789",
"amount": 5497,
"status": "SUCCESS",
"createdAt": "2026-01-21T12:45:00"
}
]

๐Ÿ”” Payment Callback (Webhook)โ€‹

Handle Razorpay payment callbacks.

This endpoint is internal and not exposed to clients.

โžค Endpointโ€‹

POST /api/payments/callback

โžค Headersโ€‹

X-Razorpay-Signature

โžค Callback Payload (Example)โ€‹

{
"razorpay_payment_id": "pay_JH23XYZ",
"razorpay_order_id": "order_JH23KLM",
"razorpay_signature": "abc123signature"
}

โžค Success Response (200 OK)โ€‹

{
"message": "Payment processed successfully"
}

๐Ÿ”„ Payment Lifecycleโ€‹


๐Ÿ“ก Events Publishedโ€‹

EventTopicDescription
PAYMENT_CREATEDpayment-eventsPayment initiated
PAYMENT_SUCCESSpayment-eventsPayment successful
PAYMENT_FAILEDpayment-eventsPayment failed

Consumed by:

  • Order Service
  • Notification Service
  • Analytics Service

๐Ÿ”„ Request Flowโ€‹


โš ๏ธ Common Errorsโ€‹

StatusMeaning
400Invalid payment request
401Unauthorized
403Forbidden
404Order not found
500Payment gateway failure

๐Ÿ›ก๏ธ Security Notesโ€‹

  • Razorpay signatures are verified
  • Payment secrets stored in environment variables
  • Callbacks are idempotent
  • Duplicate callbacks are safely ignored

๐Ÿ“Œ Summaryโ€‹

The Payment API provides:

  • Secure payment initiation
  • Reliable callback handling
  • Event-driven post-payment workflows
  • Clean integration with Razorpay

It ensures safe and consistent payment processing in ShopVerse.