PaymentService is a Laravel-based application that provides a comprehensive API for managing payments, refunds, and payment gateways. This document outlines the API structure, model structure, and provides examples of API requests.
-
Create a new payment
POST /api/payments- Request Body:
{ "email": "user@example.com", "amount": 100.00, "currency": "USD", "status": "pending", "gateway": "Stripe", "transaction_id": "txn_12345" }
-
Update an existing payment
PUT /api/payments/{id}- Request Body:
{ "status": "completed" }
-
Delete a payment
DELETE /api/payments/{id}
-
Get all payments
GET /api/payments
-
Get a specific payment by ID
GET /api/payments/{id}
-
Get payments by email
GET /api/payments/email/{email}
-
Get payments by status
GET /api/payments/status/{status}
-
Create a new refund for a payment
POST /api/payments/{id}/refund- Request Body:
{ "amount": 50.00, "reason": "Product returned", "status": "pending" }
-
Update an existing refund
PUT /api/refunds/{id}- Request Body:
{ "status": "completed" }
-
Delete a refund
DELETE /api/refunds/{id}
-
Get all gateways
GET /api/gateways
-
Get a specific gateway by ID
GET /api/gateways/{id}
-
Create a new gateway
POST /api/gateways- Request Body:
{ "gateway": "Stripe", "api_key": "...", "secret_key": "...", "other_configuration": "..." }
-
Update an existing gateway
PUT /api/gateways/{id}- Request Body:
{ "api_key": "new_api_key" }
-
Delete a gateway
DELETE /api/gateways/{id}
- Fields:
id: Primary keyemail: Email of the payeramount: Payment amountcurrency: Currency code (e.g., USD)status: Payment status (pending, completed, failed)gateway: Payment gateway used (e.g., Stripe, PayPal)transaction_id: Unique transaction ID from the payment gatewaycreated_at: Timestamp when the payment was createdupdated_at: Timestamp when the payment was last updated
- Fields:
id: Primary keypayment_id: Foreign key referencing the paymentamount: Refund amountreason: Reason for the refundstatus: Refund status (pending, completed, failed)created_at: Timestamp when the refund was createdupdated_at: Timestamp when the refund was last updated
- Fields:
id: Primary keygateway: Name of the payment gateway (e.g., Stripe, PayPal)api_key: API key for the gatewaysecret_key: Secret key for the gatewayother_configuration: Additional configuration for the gatewaycreated_at: Timestamp when the gateway was createdupdated_at: Timestamp when the gateway was last updated
curl -X POST http://localhost:8000/api/payments \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"amount": 100.00,
"currency": "USD",
"status": "pending",
"gateway": "Stripe",
"transaction_id": "txn_12345"
}'curl -X PUT http://localhost:8000/api/payments/1 \
-H "Content-Type: application/json" \
-d '{
"status": "completed"
}'curl http://localhost:8000/api/payments/email/user@example.comcurl -X POST http://localhost:8000/api/payments/1/refund \
-H "Content-Type: application/json" \
-d '{
"amount": 50.00,
"reason": "Product returned",
"status": "pending"
}'curl -X POST http://localhost:8000/api/gateways \
-H "Content-Type: application/json" \
-d '{
"gateway": "Stripe",
"api_key": "...",
"secret_key": "...",
"other_configuration": "..."
}'- Database Migrations: The database migrations for creating the
payments,refunds, andgatewaystables are located in thedatabase/migrationsdirectory. - Controllers: The business logic for handling API requests is implemented in the
PaymentController,RefundController, andGatewayControllerlocated in theapp/Http/Controllersdirectory. - Models: The Eloquent models representing the
Payment,Refund, andGatewayentities are located in theapp/Modelsdirectory.