{
  "openapi": "3.0.3",
  "info": {
    "title": "Loyvo Loyalty API",
    "version": "1.0.0",
    "description": "Run your loyalty programme from your point-of-sale or backend: enrol customers by phone number, award points on every purchase, and redeem them with a 4-digit PIN that Loyvo sends to the customer by SMS.\n\nAuthenticate every request with a live Loyvo API key (`lvo_live_…`, app.loyvo.lk → Settings → API keys) with `loyalty:pos`, or `loyalty:read` for reads, as a bearer token. Never put it in a mobile app or a web page.\n\nA typical checkout:\n\n- **Find the customer** with `GET /v1/loyalty/pos/customers/lookup`, or enrol them with `POST /v1/loyalty/pos/customers/quick-enroll`.\n- **Record the purchase** with `POST /v1/loyalty/pos/transactions` to award points.\n- **Redeem points** with `POST /v1/loyalty/pos/redemptions/initiate`, then `POST /v1/loyalty/pos/redemptions/confirm` with the PIN the customer received.\n\nAll endpoints are under `https://api.loyvo.lk/v1/loyalty` and return JSON."
  },
  "paths": {
    "/v1/loyalty/companies/verify-token": {
      "get": {
        "operationId": "api_v1_companies_verify_token_retrieve",
        "description": "Protected endpoint to verify company authorization with header: `Authorization: Bearer lvo_live_...`.",
        "summary": "Verify Company Secret API Key",
        "tags": [
          "Authentication"
        ],
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VerifyTokenResponse"
                }
              }
            },
            "description": ""
          }
        }
      }
    },
    "/v1/loyalty/companies/loyalty-config": {
      "get": {
        "operationId": "api_v1_companies_loyalty_config_retrieve",
        "description": "Retrieves points_earned and spend_amount for the authenticated company.",
        "summary": "Get Company Loyalty Configuration",
        "tags": [
          "Loyalty Configuration"
        ],
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MerchantLoyaltyConfigGetResponse"
                }
              }
            },
            "description": ""
          }
        }
      },
      "patch": {
        "operationId": "api_v1_companies_loyalty_config_partial_update",
        "description": "Allows a merchant to update their points_earned and spend_amount using their Company Secret Key ",
        "summary": "Update Company Loyalty Configuration",
        "tags": [
          "Loyalty Configuration"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PatchedMerchantLoyaltyConfigRequest"
              }
            }
          }
        },
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MerchantLoyaltyConfigUpdateResponse"
                }
              }
            },
            "description": ""
          }
        }
      }
    },
    "/v1/loyalty/branches": {
      "get": {
        "operationId": "api_v1_branches_list",
        "description": "Retrieves all branches belonging to the company identified by the Bearer secret key in the `Authorization` header.",
        "summary": "List all branches for authenticated company",
        "tags": [
          "Branches"
        ],
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Branch"
                  }
                }
              }
            },
            "description": ""
          }
        }
      },
      "post": {
        "operationId": "api_v1_branches_create",
        "description": "Creates a new branch directly under the company identified by the Bearer secret key.",
        "summary": "Create branch under authenticated company",
        "tags": [
          "Branches"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BranchCreateRequest"
              }
            }
          },
          "required": true
        },
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Branch"
                }
              }
            },
            "description": ""
          }
        }
      }
    },
    "/v1/loyalty/branches/{id}": {
      "get": {
        "operationId": "api_v1_branches_retrieve",
        "description": "Retrieves branch details. The branch must belong to the authenticated company.",
        "summary": "Get branch details",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "schema": {
              "type": "integer"
            },
            "required": true
          }
        ],
        "tags": [
          "Branches"
        ],
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Branch"
                }
              }
            },
            "description": ""
          }
        }
      },
      "put": {
        "operationId": "api_v1_branches_update",
        "summary": "Update branch",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "schema": {
              "type": "integer"
            },
            "required": true
          }
        ],
        "tags": [
          "Branches"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BranchUpdateRequest"
              }
            }
          },
          "required": true
        },
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Branch"
                }
              }
            },
            "description": ""
          }
        }
      },
      "patch": {
        "operationId": "api_v1_branches_partial_update",
        "summary": "Partially update branch",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "schema": {
              "type": "integer"
            },
            "required": true
          }
        ],
        "tags": [
          "Branches"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PatchedBranchUpdateRequest"
              }
            }
          }
        },
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Branch"
                }
              }
            },
            "description": ""
          }
        }
      },
      "delete": {
        "operationId": "api_v1_branches_destroy",
        "description": "Sets is_active=False. Branch must belong to the authenticated company.",
        "summary": "Deactivate branch (Soft-delete)",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "schema": {
              "type": "integer"
            },
            "required": true
          }
        ],
        "tags": [
          "Branches"
        ],
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BranchDeleteResponse"
                }
              }
            },
            "description": ""
          }
        }
      }
    },
    "/v1/loyalty/pos/customers/lookup": {
      "get": {
        "operationId": "api_v1_pos_customers_lookup_retrieve",
        "description": "Cashier enters mobile number. Returns customer profile and points balance if found, or prompts for enrollment if not found.",
        "summary": "POS Customer Lookup by Phone",
        "parameters": [
          {
            "in": "query",
            "name": "phone",
            "schema": {
              "type": "string"
            },
            "description": "Customer mobile number (e.g. 0771234567 or +94771234567)",
            "required": true
          }
        ],
        "tags": [
          "POS Operations"
        ],
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CustomerLookupResponse"
                }
              }
            },
            "description": ""
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CustomerLookupBadRequest"
                }
              }
            },
            "description": ""
          }
        }
      }
    },
    "/v1/loyalty/pos/customers/quick-enroll": {
      "post": {
        "operationId": "api_v1_pos_customers_quick_enroll_create",
        "description": "Fast customer enrollment at till (< 200ms). Dispatches onboarding SMS with OTP and verification link in the background.",
        "summary": "POS Quick Customer Enrollment (Triggers Background OTP SMS)",
        "tags": [
          "POS Operations"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CustomerQuickEnrollRequest"
              }
            }
          },
          "required": true
        },
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CustomerEnrollResponse"
                }
              }
            },
            "description": ""
          }
        }
      }
    },
    "/v1/loyalty/pos/transactions": {
      "post": {
        "operationId": "api_v1_pos_transactions_create",
        "description": "Ingests purchase amount, calculates loyalty points based on merchant ratio, and updates customer balance atomically.",
        "summary": "Record POS Checkout Transaction & Award Points",
        "tags": [
          "POS Operations"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RecordTransactionRequest"
              },
              "examples": {
                "RecordTransactionExample": {
                  "value": {
                    "phone": "+94771234567",
                    "branch_id": 1,
                    "amount": 1000,
                    "invoice_id": "INV-2026-001",
                    "get_offer": false
                  },
                  "summary": "Record Transaction Example"
                },
                "RecordTransactionWithOfferRedemption": {
                  "value": {
                    "phone": "+94771234567",
                    "branch_id": 1,
                    "amount": 2500,
                    "invoice_id": "INV-2026-002",
                    "get_offer": true
                  },
                  "summary": "Record Transaction with Offer Redemption"
                }
              }
            }
          },
          "required": true
        },
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RecordTransactionResponse"
                }
              }
            },
            "description": ""
          }
        }
      }
    },
    "/v1/loyalty/pos/transactions/details": {
      "get": {
        "operationId": "api_v1_pos_transactions_details_retrieve",
        "description": "Fetches the complete details of a transaction using its transaction_uuid query parameter (e.g. ?transaction_uuid=tx_...) under the authenticated merchant company.",
        "summary": "Get Transaction Details by UUID",
        "parameters": [
          {
            "in": "query",
            "name": "transaction_uuid",
            "schema": {
              "type": "string"
            },
            "description": "Unique transaction identifier (e.g., tx_9df3dceb...)",
            "required": true
          }
        ],
        "tags": [
          "POS Operations"
        ],
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PosTransactionDetailResponse"
                }
              }
            },
            "description": ""
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PosTransactionMissingUuid"
                }
              }
            },
            "description": ""
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PosTransactionNotFound"
                }
              }
            },
            "description": ""
          }
        }
      },
      "patch": {
        "operationId": "api_v1_pos_transactions_details_partial_update",
        "description": "Updates a transaction by its transaction_uuid query parameter (?transaction_uuid=...). The request body ONLY requires `amount`. Loyalty points are automatically recalculated based on the merchant company spend rules, customer balance is atomically updated, and ledger & wallet passes are synchronized.",
        "summary": "Update Transaction Details & Auto Recalculate Points by UUID",
        "parameters": [
          {
            "in": "query",
            "name": "transaction_uuid",
            "schema": {
              "type": "string"
            },
            "description": "Unique transaction identifier as a query parameter (e.g. ?transaction_uuid=tx_9df3dceb...)",
            "required": true
          }
        ],
        "tags": [
          "POS Operations"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PatchedPosUpdateTransactionRequest"
              },
              "examples": {
                "AmountUpdateBody": {
                  "value": {
                    "amount": 2500
                  },
                  "summary": "Amount Update Body"
                }
              }
            }
          }
        },
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PosTransactionUpdateResponse"
                }
              }
            },
            "description": ""
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PosTransactionUpdateBadRequest"
                }
              }
            },
            "description": ""
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PosTransactionUpdateNotFound"
                }
              }
            },
            "description": ""
          },
          "422": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PosTransactionUpdateUnprocessable"
                }
              }
            },
            "description": ""
          }
        }
      }
    },
    "/v1/loyalty/pos/customers/delete": {
      "delete": {
        "operationId": "api_v1_pos_customers_delete_destroy",
        "description": "Permanently deletes an enrolled customer profile under this merchant company. Provide either customer mobile number or customer_id.",
        "summary": "Delete Customer Profile by Phone or Customer ID",
        "parameters": [
          {
            "in": "query",
            "name": "customer_id",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Optional customer UUID"
          },
          {
            "in": "query",
            "name": "phone",
            "schema": {
              "type": "string"
            },
            "description": "Customer mobile number (e.g. 0771234567 or +94771234567)"
          }
        ],
        "tags": [
          "POS Operations"
        ],
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CustomerDeleteResponse"
                }
              }
            },
            "description": ""
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CustomerDeleteBadRequest"
                }
              }
            },
            "description": ""
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CustomerDeleteNotFound"
                }
              }
            },
            "description": ""
          }
        }
      }
    },
    "/v1/loyalty/pos/customers/resend-pass": {
      "post": {
        "operationId": "api_v1_pos_customers_resend_pass_create",
        "description": "Dispatches an onboarding SMS containing the direct Apple / Google Wallet pass link to the customer.",
        "summary": "Resend Digital Wallet Pass Link SMS",
        "tags": [
          "POS Operations"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ResendPassRequestRequest"
              }
            }
          },
          "required": true
        },
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResendPassResponse"
                }
              }
            },
            "description": ""
          }
        }
      }
    },
    "/v1/loyalty/pos/redemptions/initiate": {
      "post": {
        "operationId": "api_v1_pos_redemptions_initiate_create",
        "description": "Initiates a points redemption at the POS till. Validates requested points against customer balance, calculates currency equivalent, generates a cryptographically secure 4-digit PIN with a 3-minute TTL, and sends it via SMS to the customer. No points are deducted until confirm succeeds.",
        "summary": "Points Redemption (4-Digit SMS PIN)",
        "tags": [
          "POS Operations - Redemption"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PosRedemptionInitiateRequestRequest"
              }
            }
          },
          "required": true
        },
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RedemptionInitiateResponse"
                }
              }
            },
            "description": ""
          },
          "404": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RedemptionNotFound"
                }
              }
            },
            "description": ""
          },
          "422": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RedemptionInsufficientBalance"
                }
              }
            },
            "description": ""
          }
        }
      }
    },
    "/v1/loyalty/pos/redemptions/confirm": {
      "post": {
        "operationId": "api_v1_pos_redemptions_confirm_create",
        "description": "Customer verbally reads the 4-digit PIN to cashier. On matching PIN, atomically debits points from balance, records an immutable negative delta in LoyaltyLedger, and marks redemption CONFIRMED.",
        "summary": "Confirm Points Redemption ",
        "tags": [
          "POS Operations - Redemption"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PosRedemptionConfirmRequestRequest"
              }
            }
          },
          "required": true
        },
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RedemptionConfirmResponse"
                }
              }
            },
            "description": ""
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RedemptionInvalidPin"
                }
              }
            },
            "description": ""
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RedemptionMaxAttempts"
                }
              }
            },
            "description": ""
          },
          "409": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RedemptionAlreadyConfirmed"
                }
              }
            },
            "description": ""
          },
          "410": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RedemptionExpired"
                }
              }
            },
            "description": ""
          }
        }
      }
    },
    "/v1/loyalty/pos/redemptions/resend-pin": {
      "post": {
        "operationId": "api_v1_pos_redemptions_resend_pin_create",
        "description": "Dispatches a fresh 4-digit PIN via SMS, resets attempt count, and renews the 3-minute timer.",
        "summary": "Resend Redemption PIN",
        "tags": [
          "POS Operations - Redemption"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PosRedemptionResendPinRequestRequest"
              }
            }
          },
          "required": true
        },
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RedemptionResendResponse"
                }
              }
            },
            "description": ""
          }
        }
      }
    },
    "/v1/loyalty/pos/redemptions/cancel": {
      "post": {
        "operationId": "api_v1_pos_redemptions_cancel_create",
        "description": "Handles cancellation of pending redemptions (customer abandoned till) and reversals of confirmed redemptions (POS sale voided/refunded). Points are restored automatically if already debited.",
        "summary": "Cancel or Reverse Points Redemption (Unified)",
        "tags": [
          "POS Operations - Redemption"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PosRedemptionCancelRequestRequest"
              }
            }
          },
          "required": true
        },
        "security": [
          {
            "CompanyApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RedemptionCancelResponse"
                }
              }
            },
            "description": ""
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Branch": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "readOnly": true
          },
          "company_id": {
            "type": "integer",
            "readOnly": true
          },
          "company_name": {
            "type": "string",
            "readOnly": true
          },
          "branch_code": {
            "type": "string",
            "maxLength": 50
          },
          "branch_name": {
            "type": "string",
            "nullable": true,
            "maxLength": 255
          },
          "phone": {
            "type": "string",
            "nullable": true,
            "maxLength": 20
          },
          "email": {
            "nullable": true,
            "oneOf": [
              {
                "type": "string",
                "format": "email",
                "maxLength": 255
              },
              {
                "type": "string",
                "maxLength": 0
              }
            ]
          },
          "is_active": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "required": [
          "branch_code",
          "company_id",
          "company_name",
          "created_at",
          "id",
          "updated_at"
        ]
      },
      "BranchCreateRequest": {
        "type": "object",
        "properties": {
          "branch_code": {
            "type": "string",
            "minLength": 1,
            "maxLength": 50
          },
          "branch_name": {
            "type": "string",
            "nullable": true,
            "maxLength": 255
          },
          "phone": {
            "type": "string",
            "nullable": true,
            "maxLength": 20
          },
          "email": {
            "nullable": true,
            "oneOf": [
              {
                "type": "string",
                "format": "email",
                "maxLength": 255
              },
              {
                "type": "string",
                "maxLength": 0
              }
            ]
          }
        },
        "required": [
          "branch_code"
        ]
      },
      "BranchDeleteResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "message",
          "status"
        ]
      },
      "BranchUpdateRequest": {
        "type": "object",
        "properties": {
          "branch_code": {
            "type": "string",
            "minLength": 1,
            "maxLength": 50
          },
          "branch_name": {
            "type": "string",
            "nullable": true,
            "maxLength": 255
          },
          "phone": {
            "type": "string",
            "nullable": true,
            "maxLength": 20
          },
          "email": {
            "nullable": true,
            "oneOf": [
              {
                "type": "string",
                "format": "email",
                "maxLength": 255
              },
              {
                "type": "string",
                "maxLength": 0
              }
            ]
          },
          "is_active": {
            "type": "boolean"
          }
        },
        "required": [
          "branch_code"
        ]
      },
      "Customer": {
        "type": "object",
        "description": "Full serialization of an enrolled customer.",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "readOnly": true
          },
          "phone": {
            "type": "string",
            "maxLength": 20
          },
          "first_name": {
            "type": "string",
            "maxLength": 100
          },
          "last_name": {
            "type": "string",
            "nullable": true,
            "maxLength": 100
          },
          "email": {
            "nullable": true,
            "oneOf": [
              {
                "type": "string",
                "format": "email",
                "maxLength": 255
              },
              {
                "type": "string",
                "maxLength": 0
              }
            ]
          },
          "is_email_verified": {
            "type": "boolean",
            "readOnly": true
          },
          "nic": {
            "type": "string",
            "nullable": true,
            "maxLength": 20
          },
          "points_balance": {
            "type": "integer",
            "readOnly": true,
            "description": "Current available loyalty points balance"
          },
          "points_value_equivalent": {
            "type": "number",
            "format": "double",
            "readOnly": true,
            "description": "Currency value of points in LKR based on merchant ratio"
          },
          "registration_status": {
            "$ref": "#/components/schemas/RegistrationStatusEnum"
          },
          "created_by_branch": {
            "type": "integer",
            "nullable": true
          },
          "enrolled_date": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "required": [
          "enrolled_date",
          "first_name",
          "id",
          "is_email_verified",
          "phone",
          "points_balance",
          "points_value_equivalent"
        ]
      },
      "CustomerDeleteBadRequest": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "errors": {
            "type": "object",
            "additionalProperties": {}
          }
        },
        "required": [
          "errors",
          "status"
        ]
      },
      "CustomerDeleteData": {
        "type": "object",
        "properties": {
          "customer_id": {
            "type": "string"
          },
          "phone": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "points_deleted": {
            "type": "integer"
          },
          "deleted_at": {
            "type": "string"
          }
        },
        "required": [
          "customer_id",
          "deleted_at",
          "name",
          "phone",
          "points_deleted"
        ]
      },
      "CustomerDeleteNotFound": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "error_code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "error_code",
          "message",
          "status"
        ]
      },
      "CustomerDeleteResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "data": {
            "$ref": "#/components/schemas/CustomerDeleteData"
          }
        },
        "required": [
          "data",
          "message",
          "status"
        ]
      },
      "CustomerEnrollResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "data": {
            "$ref": "#/components/schemas/Customer"
          }
        },
        "required": [
          "data",
          "message",
          "status"
        ]
      },
      "CustomerLookupBadRequest": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "errors": {
            "type": "object",
            "additionalProperties": {}
          }
        },
        "required": [
          "errors",
          "status"
        ]
      },
      "CustomerLookupResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "exists": {
            "type": "boolean"
          },
          "data": {
            "$ref": "#/components/schemas/Customer"
          },
          "has_offer": {
            "type": "boolean"
          },
          "offer_details": {
            "type": "object",
            "additionalProperties": {},
            "nullable": true
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "exists",
          "has_offer",
          "offer_details",
          "status"
        ]
      },
      "CustomerQuickEnrollRequest": {
        "type": "object",
        "description": "POS Quick Enrollment payload.\nTakes only phone and first_name (+ optional branch_id) for instant zero-friction checkout.",
        "properties": {
          "phone": {
            "type": "string",
            "minLength": 1,
            "description": "Customer mobile number (e.g. 0771234567)",
            "maxLength": 20
          },
          "first_name": {
            "type": "string",
            "minLength": 1,
            "description": "Customer first name",
            "maxLength": 100
          },
          "branch_id": {
            "type": "integer",
            "nullable": true,
            "description": "Optional Branch ID where customer is enrolling"
          },
          "notify": {
            "type": "boolean",
            "default": true,
            "description": "Send the welcome SMS with the digital card link (default true). False: enrol quietly, e.g. when a business imports its existing customers."
          }
        },
        "required": [
          "first_name",
          "phone"
        ]
      },
      "LoyaltyConfigData": {
        "type": "object",
        "properties": {
          "points_earned": {
            "type": "integer"
          },
          "spend_amount": {
            "type": "integer"
          }
        },
        "required": [
          "points_earned",
          "spend_amount"
        ]
      },
      "MerchantLoyaltyConfigData": {
        "type": "object",
        "properties": {
          "company_id": {
            "type": "integer"
          },
          "company_name": {
            "type": "string"
          },
          "points_earned": {
            "type": "integer"
          },
          "spend_amount": {
            "type": "integer"
          }
        },
        "required": [
          "company_id",
          "company_name",
          "points_earned",
          "spend_amount"
        ]
      },
      "MerchantLoyaltyConfigGetResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "data": {
            "$ref": "#/components/schemas/MerchantLoyaltyConfigData"
          }
        },
        "required": [
          "data",
          "status"
        ]
      },
      "MerchantLoyaltyConfigUpdateResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "data": {
            "$ref": "#/components/schemas/MerchantLoyaltyConfigUpdatedData"
          }
        },
        "required": [
          "data",
          "message",
          "status"
        ]
      },
      "MerchantLoyaltyConfigUpdatedData": {
        "type": "object",
        "properties": {
          "company_id": {
            "type": "integer"
          },
          "company_name": {
            "type": "string"
          },
          "points_earned": {
            "type": "integer"
          },
          "spend_amount": {
            "type": "integer"
          }
        },
        "required": [
          "company_id",
          "company_name",
          "points_earned",
          "spend_amount"
        ]
      },
      "PatchedBranchUpdateRequest": {
        "type": "object",
        "properties": {
          "branch_code": {
            "type": "string",
            "minLength": 1,
            "maxLength": 50
          },
          "branch_name": {
            "type": "string",
            "nullable": true,
            "maxLength": 255
          },
          "phone": {
            "type": "string",
            "nullable": true,
            "maxLength": 20
          },
          "email": {
            "nullable": true,
            "oneOf": [
              {
                "type": "string",
                "format": "email",
                "maxLength": 255
              },
              {
                "type": "string",
                "maxLength": 0
              }
            ]
          },
          "is_active": {
            "type": "boolean"
          }
        }
      },
      "PatchedMerchantLoyaltyConfigRequest": {
        "type": "object",
        "description": "Serializer for merchants to view and update their own loyalty point ratio\nusing their company secret API key.",
        "properties": {
          "points_earned": {
            "type": "integer",
            "minimum": 1,
            "description": "Points awarded per qualifying spend amount (integer, >= 1)"
          },
          "spend_amount": {
            "type": "integer",
            "minimum": 1,
            "description": "Qualifying spending amount required to earn points (integer, >= 1)"
          }
        }
      },
      "PatchedPosUpdateTransactionRequest": {
        "type": "object",
        "description": "Payload for updating transaction amount and automatically recalculating points.\nOnly `amount` is in the body.",
        "properties": {
          "amount": {
            "type": "number",
            "format": "double",
            "minimum": 0.01,
            "description": "Updated transaction purchase amount in LKR"
          }
        }
      },
      "PosRedemptionCancelRequestRequest": {
        "type": "object",
        "description": "Step 5.6 & Reversal: POS Redemption Cancel / Void payload.\nHandles both cancelling pending requests and reversing confirmed redemptions.",
        "properties": {
          "redemption_id": {
            "type": "string",
            "minLength": 1,
            "description": "Redemption ID to cancel or reverse",
            "maxLength": 64
          },
          "reason": {
            "type": "string",
            "default": "Cancelled / voided at POS till",
            "description": "Optional cancellation or void reason",
            "maxLength": 255
          }
        },
        "required": [
          "redemption_id"
        ]
      },
      "PosRedemptionConfirmRequestRequest": {
        "type": "object",
        "description": "Step 5.3: POS Redemption Confirm payload.\nTakes redemption_id and the 4-digit PIN provided by the customer.",
        "properties": {
          "redemption_id": {
            "type": "string",
            "minLength": 1,
            "description": "Unique redemption ID issued at initiate step",
            "maxLength": 64
          },
          "pin": {
            "type": "string",
            "minLength": 4,
            "description": "4-digit numeric PIN read by customer",
            "maxLength": 4
          }
        },
        "required": [
          "pin",
          "redemption_id"
        ]
      },
      "PosRedemptionInitiateRequestRequest": {
        "type": "object",
        "description": "Step 5.2: POS Redemption Initiate payload.\nAccepts customer phone, branch, and points_to_redeem.",
        "properties": {
          "phone": {
            "type": "string",
            "minLength": 1,
            "description": "Customer mobile number (e.g. 0771234567)",
            "maxLength": 20
          },
          "points_to_redeem": {
            "type": "integer",
            "minimum": 1,
            "description": "Loyalty points to redeem"
          },
          "branch_id": {
            "type": "integer",
            "nullable": true,
            "description": "Till branch location ID"
          },
          "invoice_id": {
            "type": "string",
            "nullable": true,
            "description": "Optional POS invoice / receipt reference",
            "maxLength": 100
          }
        },
        "required": [
          "phone",
          "points_to_redeem"
        ]
      },
      "PosRedemptionResendPinRequestRequest": {
        "type": "object",
        "description": "Step 5.6: POS Redemption Resend PIN payload.",
        "properties": {
          "redemption_id": {
            "type": "string",
            "minLength": 1,
            "description": "Active redemption ID",
            "maxLength": 64
          }
        },
        "required": [
          "redemption_id"
        ]
      },
      "PosTransactionDetailResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "data": {
            "$ref": "#/components/schemas/TransactionResponse"
          }
        },
        "required": [
          "data",
          "status"
        ]
      },
      "PosTransactionMissingUuid": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "message",
          "status"
        ]
      },
      "PosTransactionNotFound": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "error_code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "error_code",
          "message",
          "status"
        ]
      },
      "PosTransactionUpdateBadRequest": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "errors": {
            "type": "object",
            "additionalProperties": {}
          }
        },
        "required": [
          "errors",
          "status"
        ]
      },
      "PosTransactionUpdateNotFound": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "error_code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "error_code",
          "message",
          "status"
        ]
      },
      "PosTransactionUpdateResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "data": {
            "$ref": "#/components/schemas/PosTransactionUpdateResultData"
          }
        },
        "required": [
          "data",
          "message",
          "status"
        ]
      },
      "PosTransactionUpdateResultData": {
        "type": "object",
        "properties": {
          "transaction_uuid": {
            "type": "string"
          },
          "invoice_id": {
            "type": "string",
            "nullable": true
          },
          "amount": {
            "type": "number",
            "format": "double"
          },
          "points_earned": {
            "type": "integer"
          },
          "points_delta": {
            "type": "integer"
          },
          "previous_points_balance": {
            "type": "integer"
          },
          "new_points_balance": {
            "type": "integer"
          },
          "customer_phone": {
            "type": "string"
          },
          "customer_name": {
            "type": "string"
          },
          "updated_at": {
            "type": "string"
          }
        },
        "required": [
          "amount",
          "customer_name",
          "customer_phone",
          "invoice_id",
          "new_points_balance",
          "points_delta",
          "points_earned",
          "previous_points_balance",
          "transaction_uuid",
          "updated_at"
        ]
      },
      "PosTransactionUpdateUnprocessable": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "error_code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "error_code",
          "message",
          "status"
        ]
      },
      "RecordTransactionRequest": {
        "type": "object",
        "description": "POS Checkout spend ingestion.",
        "properties": {
          "phone": {
            "type": "string",
            "minLength": 1,
            "maxLength": 20
          },
          "branch_id": {
            "type": "integer",
            "nullable": true
          },
          "amount": {
            "type": "number",
            "format": "double",
            "minimum": 0.01,
            "default": 1000,
            "description": "Transaction purchase amount in LKR (default: 1000.0)"
          },
          "invoice_id": {
            "type": "string",
            "nullable": true,
            "description": "Optional merchant invoice/receipt number",
            "maxLength": 100
          },
          "get_offer": {
            "type": "boolean",
            "default": false,
            "description": "If true, redeems the active campaign offer for this customer at checkout"
          }
        },
        "required": [
          "phone"
        ]
      },
      "RecordTransactionResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "data": {
            "$ref": "#/components/schemas/TransactionResultData"
          }
        },
        "required": [
          "data",
          "message",
          "status"
        ]
      },
      "RedemptionAlreadyConfirmed": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "error_code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "error_code",
          "message",
          "status"
        ]
      },
      "RedemptionCancelData": {
        "type": "object",
        "properties": {
          "redemption_id": {
            "type": "string"
          },
          "points_restored": {
            "type": "integer"
          },
          "previous_balance": {
            "type": "integer"
          },
          "new_points_balance": {
            "type": "integer"
          },
          "reversal_ledger_reference": {
            "type": "string"
          },
          "status": {
            "type": "string"
          }
        },
        "required": [
          "points_restored",
          "redemption_id",
          "status"
        ]
      },
      "RedemptionCancelResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "action": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "data": {
            "$ref": "#/components/schemas/RedemptionCancelData"
          }
        },
        "required": [
          "action",
          "data",
          "message",
          "status"
        ]
      },
      "RedemptionConfirmData": {
        "type": "object",
        "properties": {
          "redemption_id": {
            "type": "string"
          },
          "customer_name": {
            "type": "string"
          },
          "points_redeemed": {
            "type": "integer"
          },
          "discount_applied_amount": {
            "type": "number",
            "format": "double"
          },
          "previous_balance": {
            "type": "integer"
          },
          "new_points_balance": {
            "type": "integer"
          },
          "ledger_reference": {
            "type": "string"
          },
          "confirmed_at": {
            "type": "string"
          }
        },
        "required": [
          "confirmed_at",
          "customer_name",
          "discount_applied_amount",
          "ledger_reference",
          "new_points_balance",
          "points_redeemed",
          "previous_balance",
          "redemption_id"
        ]
      },
      "RedemptionConfirmResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "data": {
            "$ref": "#/components/schemas/RedemptionConfirmData"
          }
        },
        "required": [
          "data",
          "message",
          "status"
        ]
      },
      "RedemptionExpired": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "error_code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "error_code",
          "message",
          "status"
        ]
      },
      "RedemptionInitiateData": {
        "type": "object",
        "properties": {
          "redemption_id": {
            "type": "string"
          },
          "customer_name": {
            "type": "string"
          },
          "phone": {
            "type": "string"
          },
          "current_balance": {
            "type": "integer"
          },
          "points_to_redeem": {
            "type": "integer"
          },
          "value_equivalent": {
            "type": "number",
            "format": "double"
          },
          "projected_remaining_balance": {
            "type": "integer"
          },
          "expires_in_seconds": {
            "type": "integer"
          },
          "expires_at": {
            "type": "string"
          }
        },
        "required": [
          "current_balance",
          "customer_name",
          "expires_at",
          "expires_in_seconds",
          "phone",
          "points_to_redeem",
          "projected_remaining_balance",
          "redemption_id",
          "value_equivalent"
        ]
      },
      "RedemptionInitiateResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "data": {
            "$ref": "#/components/schemas/RedemptionInitiateData"
          }
        },
        "required": [
          "data",
          "message",
          "status"
        ]
      },
      "RedemptionInsufficientBalance": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "error_code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "current_balance": {
            "type": "integer"
          },
          "max_redeemable_value": {
            "type": "number",
            "format": "double"
          }
        },
        "required": [
          "current_balance",
          "error_code",
          "max_redeemable_value",
          "message",
          "status"
        ]
      },
      "RedemptionInvalidPin": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "error_code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "attempts_remaining": {
            "type": "integer"
          }
        },
        "required": [
          "error_code",
          "message",
          "status"
        ]
      },
      "RedemptionMaxAttempts": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "error_code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "error_code",
          "message",
          "status"
        ]
      },
      "RedemptionNotFound": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "error_code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        },
        "required": [
          "error_code",
          "message",
          "status"
        ]
      },
      "RedemptionResendData": {
        "type": "object",
        "properties": {
          "redemption_id": {
            "type": "string"
          },
          "expires_in_seconds": {
            "type": "integer"
          },
          "expires_at": {
            "type": "string"
          }
        },
        "required": [
          "expires_at",
          "expires_in_seconds",
          "redemption_id"
        ]
      },
      "RedemptionResendResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "data": {
            "$ref": "#/components/schemas/RedemptionResendData"
          }
        },
        "required": [
          "data",
          "message",
          "status"
        ]
      },
      "RegistrationStatusEnum": {
        "enum": [
          "basic",
          "pending_verification",
          "profile_partial",
          "profile_complete"
        ],
        "type": "string",
        "description": "* `basic` - Basic (Phone + First Name at POS)\n* `pending_verification` - Pending Verification (Link clicked, OTP sent)\n* `profile_partial` - Profile Partial (OTP verified, some fields skipped)\n* `profile_complete` - Profile Complete (All fields provided & email verified)"
      },
      "ResendPassRequestRequest": {
        "type": "object",
        "properties": {
          "phone": {
            "type": "string",
            "minLength": 1,
            "description": "Customer phone number"
          }
        },
        "required": [
          "phone"
        ]
      },
      "ResendPassResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "wallet_pass_url": {
            "type": "string"
          }
        },
        "required": [
          "message",
          "status"
        ]
      },
      "TransactionResponse": {
        "type": "object",
        "description": "Transaction receipt representation.",
        "properties": {
          "transaction_uuid": {
            "type": "string",
            "maxLength": 64
          },
          "amount": {
            "type": "string",
            "format": "decimal",
            "pattern": "^-?\\d{0,10}(?:\\.\\d{0,2})?$"
          },
          "points_earned": {
            "type": "integer",
            "maximum": 4294967295,
            "minimum": 0,
            "format": "int64"
          },
          "invoice_id": {
            "type": "string",
            "nullable": true,
            "description": "Optional merchant invoice/receipt ID",
            "maxLength": 100
          },
          "branch": {
            "type": "integer",
            "nullable": true
          },
          "branch_name": {
            "type": "string",
            "readOnly": true
          },
          "branch_code": {
            "type": "string",
            "readOnly": true
          },
          "customer": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Customer"
              }
            ],
            "readOnly": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "readOnly": true
          }
        },
        "required": [
          "amount",
          "branch_code",
          "branch_name",
          "created_at",
          "customer",
          "points_earned",
          "transaction_uuid"
        ]
      },
      "TransactionResultData": {
        "type": "object",
        "properties": {
          "transaction_uuid": {
            "type": "string"
          },
          "invoice_id": {
            "type": "string",
            "nullable": true
          },
          "amount": {
            "type": "number",
            "format": "double"
          },
          "net_amount": {
            "type": "number",
            "format": "double"
          },
          "points_awarded": {
            "type": "integer"
          },
          "previous_balance": {
            "type": "integer"
          },
          "new_points_balance": {
            "type": "integer"
          },
          "customer_name": {
            "type": "string"
          },
          "offer_redeemed": {
            "type": "boolean"
          },
          "offer_details": {
            "type": "object",
            "additionalProperties": {},
            "nullable": true
          }
        },
        "required": [
          "amount",
          "customer_name",
          "invoice_id",
          "new_points_balance",
          "offer_details",
          "offer_redeemed",
          "points_awarded",
          "previous_balance",
          "transaction_uuid"
        ]
      },
      "VerifyTokenData": {
        "type": "object",
        "properties": {
          "company_id": {
            "type": "integer"
          },
          "company_name": {
            "type": "string"
          },
          "company_email": {
            "type": "string"
          },
          "sms_id": {
            "type": "integer"
          },
          "branches_count": {
            "type": "integer"
          },
          "loyalty_config": {
            "$ref": "#/components/schemas/LoyaltyConfigData"
          }
        },
        "required": [
          "branches_count",
          "company_email",
          "company_id",
          "company_name",
          "loyalty_config",
          "sms_id"
        ]
      },
      "VerifyTokenResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "data": {
            "$ref": "#/components/schemas/VerifyTokenData"
          }
        },
        "required": [
          "data",
          "message",
          "status"
        ]
      }
    },
    "securitySchemes": {
      "CompanyApiKeyAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "lvo_live_*",
        "description": "A live Loyvo API key (lvo_live_…) with loyalty:pos or loyalty:read."
      }
    }
  },
  "servers": [
    {
      "url": "https://api.loyvo.lk",
      "description": "Production"
    }
  ]
}
