Skip to content

Payment Model

The Payment model represents a payment transaction that can contain multiple orders.

Structure

{
  "id": 1,
  "user_id": 5,
  "user": {
    "id": 5,
    "first_name": "John",
    "last_name": "Doe",
    "email": "john.doe@example.com",
    ...
  },
  "order_id": "ORDER123456",
  "amount": 150.00,
  "currency_name": "AZN",
  "transaction_id": "TRANS123456789",
  "status": "2",
  "card_number": "4111******1111",
  "json_request": "{...}",
  "json_response": "{...}",
  "created": "2025-01-15T10:30:00Z"
}

Fields

Field Type Description Notes
id integer Unique identifier Auto-increment, primary key
user_id integer Customer who made the payment Required, foreign key to UserModel
order_id string Unique order identifier Required, generated by system
amount float Total payment amount Sum of all orders in this payment
currency_name string Currency code e.g., "AZN", "USD"
transaction_id string Payment gateway transaction ID Provided by payment gateway
status string Payment status See Payment Status Values below
card_number string Masked card number e.g., "4111**1111"
json_request string Payment request JSON Sent to payment gateway
json_response string Payment response JSON Received from payment gateway
created datetime Payment creation timestamp Auto-generated
updated datetime Last update timestamp Auto-updated

Payment Status Values

  • "1" - Not completed (pending)
  • "2" - Success (payment successful)
  • "3" - Failed (payment failed)

Relationships

  • UserModel: Many-to-one relationship with customer
  • PaymentOrderModel: One-to-many relationship with order links

Payment Flow

  1. Create Payment Request: User initiates payment, status: "1", transaction_id generated
  2. Payment Gateway: User redirected to payment gateway
  3. Payment Callback: Gateway sends callback with result
  4. Success: status: "2", orders updated, stock decremented, basket cleared
  5. Failed: status: "3", orders marked as failed

Notes

  • One payment can contain multiple orders (grouped by transaction)
  • order_id is a unique string identifier generated by the system
  • transaction_id is provided by the external payment gateway (epoint.az)
  • Card number is masked for security (only last 4 digits visible)
  • Payment callback verifies signature before processing
  • On successful payment, all associated orders are updated and basket is cleared
  • On failed payment, orders remain with payment_status: "2" (failed)