{
  "openapi": "3.1.0",
  "info": {
    "title": "Kash.click API partenaire v1 - Fidélité",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "/api/partner/v1"
    }
  ],
  "security": [
    {
      "ManagedBearer": []
    }
  ],
  "paths": {
    "/loyalty/program": {
      "get": {
        "operationId": "getPartnerLoyaltyProgram",
        "security": [
          {
            "ManagedBearer": []
          }
        ],
        "x-required-scopes": [
          "customers.read"
        ],
        "summary": "Consulter le programme de fidélité",
        "description": "Droit customers.read. Le programme indique les règles de points, les modes de conversion et les modèles de cartes à tampons actifs avec la licence de l’établissement.",
        "parameters": [
          {
            "$ref": "#/components/parameters/shop_id"
          }
        ],
        "responses": {
          "200": {
            "description": "Consulter le programme de fidélité.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProgramResponse"
                }
              }
            }
          },
          "400": {
            "description": "Paramètre, corps JSON ou curseur invalide.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentification invalide.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Droit insuffisant ou établissement non autorisé.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "Méthode HTTP non autorisée.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service temporairement indisponible.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/loyalty/customers/{customer_id}": {
      "get": {
        "operationId": "getPartnerLoyaltyAccount",
        "security": [
          {
            "ManagedBearer": []
          }
        ],
        "x-required-scopes": [
          "customers.read"
        ],
        "summary": "Consulter le compte de fidélité",
        "description": "Droit customers.read. Le compte présente le solde de points acquis et la progression enregistrée sur les cartes à tampons actives. Les avantages au seuil sont soumis aux conditions de caisse.",
        "parameters": [
          {
            "$ref": "#/components/parameters/shop_id"
          },
          {
            "$ref": "#/components/parameters/customer_id"
          }
        ],
        "responses": {
          "200": {
            "description": "Consulter le compte de fidélité.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountResponse"
                }
              }
            }
          },
          "400": {
            "description": "Paramètre, corps JSON ou curseur invalide.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentification invalide.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Droit insuffisant ou établissement non autorisé.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Compte client introuvable dans cet établissement.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "Méthode HTTP non autorisée.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service temporairement indisponible.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/loyalty/customers/{customer_id}/movements": {
      "get": {
        "operationId": "listPartnerLoyaltyMovements",
        "security": [
          {
            "ManagedBearer": []
          }
        ],
        "x-required-scopes": [
          "customers.read"
        ],
        "summary": "Lister les mouvements connus",
        "description": "Droit customers.read. Les tickets actifs et les archives disponibles sont triés par identifiant décroissant, avec priorité au ticket actif. Les inscriptions initiales, fusions, annulations avant numérotation et tampons ne sont pas garantis dans cet historique. Le solde se lit sur le compte.",
        "parameters": [
          {
            "$ref": "#/components/parameters/shop_id"
          },
          {
            "$ref": "#/components/parameters/customer_id"
          },
          {
            "$ref": "#/components/parameters/limit"
          },
          {
            "$ref": "#/components/parameters/cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "Lister les mouvements connus.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MovementPage"
                },
                "example": {
                  "data": [
                    {
                      "order_id": 435,
                      "recorded_at": "2026-11-12T16:50:00+01:00",
                      "is_return": true,
                      "source_order_id": 428,
                      "recorded_points": -4,
                      "points_on_reward_lines": 2
                    }
                  ],
                  "pagination": {
                    "next_cursor": null
                  }
                }
              }
            }
          },
          "400": {
            "description": "Paramètre, corps JSON ou curseur invalide.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentification invalide.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Droit insuffisant ou établissement non autorisé.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Compte client introuvable dans cet établissement.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "Méthode HTTP non autorisée.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service temporairement indisponible.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/loyalty/quotes": {
      "post": {
        "operationId": "quotePartnerLoyalty",
        "security": [
          {
            "ManagedBearer": []
          }
        ],
        "x-required-scopes": [
          "customers.read",
          "catalog.read"
        ],
        "summary": "Estimer la fidélité sur un panier",
        "description": "Droits customers.read et catalog.read. Le prix provient du calcul de panier partenaire. Les points estimés sont ceux d’une vente ordinaire éligible avant application des récompenses. Les suggestions de conversion se basent sur les points acquis au moment de la lecture. Les estimations de tampons s’entendent par modèle pour les lignes du panier. La caisse contrôle l’éligibilité et écrit les mouvements lors de l’opération métier.",
        "parameters": [
          {
            "$ref": "#/components/parameters/shop_id"
          }
        ],
        "responses": {
          "200": {
            "description": "Estimer la fidélité sur un panier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/QuoteResponse"
                }
              }
            }
          },
          "400": {
            "description": "Paramètre, corps JSON ou curseur invalide.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentification invalide.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Droit insuffisant ou établissement non autorisé.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Compte client, article ou variante indisponible dans l’établissement.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "405": {
            "description": "Méthode HTTP non autorisée.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Corps dépassant 65 536 octets.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Content-Type différent de application/json.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Combinaison ou configuration de prix non prise en charge par le panier.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Service temporairement indisponible.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "description": "Un objet JSON de 65 536 octets au maximum.",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/QuoteInput"
              },
              "example": {
                "customer_id": 58,
                "cart": {
                  "context": "takeaway",
                  "lines": [
                    {
                      "item_id": 120,
                      "quantity": 2
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ManagedBearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "parameters": {
      "shop_id": {
        "in": "query",
        "name": "shop_id",
        "required": true,
        "schema": {
          "type": "integer",
          "format": "int64",
          "minimum": 1
        }
      },
      "customer_id": {
        "in": "path",
        "name": "customer_id",
        "required": true,
        "schema": {
          "type": "integer",
          "format": "int64",
          "minimum": 1
        }
      },
      "limit": {
        "in": "query",
        "name": "limit",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 200,
          "default": 50
        }
      },
      "cursor": {
        "in": "query",
        "name": "cursor",
        "description": "Curseur opaque lié à l’établissement et au client de la requête précédente.",
        "schema": {
          "type": "string"
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "PointsMode": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "minimum_amount",
          "maximum_amount"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "minimum_amount": {
            "type": "string",
            "pattern": "^-?[0-9]+\\.[0-9]{2,}$"
          },
          "maximum_amount": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^-?[0-9]+\\.[0-9]{2,}$"
          }
        }
      },
      "StampTemplate": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "name",
          "stamps_required",
          "earning_basis",
          "earning_department_id",
          "reward_scope",
          "reward_department_id",
          "reward_discount"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "name": {
            "type": "string"
          },
          "stamps_required": {
            "type": "number",
            "exclusiveMinimum": 0
          },
          "earning_basis": {
            "type": "string",
            "enum": [
              "sale",
              "item_quantity"
            ]
          },
          "earning_department_id": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64",
            "minimum": 1
          },
          "reward_scope": {
            "type": "string",
            "enum": [
              "order",
              "any_item",
              "department"
            ]
          },
          "reward_department_id": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64",
            "minimum": 1
          },
          "reward_discount": {
            "type": [
              "object",
              "null"
            ],
            "additionalProperties": false,
            "required": [
              "id",
              "percentage_delta",
              "amount_delta",
              "fixed_price"
            ],
            "properties": {
              "id": {
                "type": "integer",
                "format": "int64",
                "minimum": 1
              },
              "percentage_delta": {
                "type": "number"
              },
              "amount_delta": {
                "type": "string",
                "pattern": "^-?[0-9]+\\.[0-9]{2,}$"
              },
              "fixed_price": {
                "type": [
                  "string",
                  "null"
                ],
                "pattern": "^-?[0-9]+\\.[0-9]{2,}$"
              }
            }
          }
        }
      },
      "ProgramResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "data"
        ],
        "properties": {
          "data": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "currency",
              "points",
              "stamp_cards"
            ],
            "properties": {
              "currency": {
                "type": "string",
                "description": "Code de devise de l’établissement."
              },
              "points": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "enabled",
                  "earning_basis",
                  "earning_rate",
                  "uses_department_rates",
              "department_rates",
                  "welcome_points",
                  "currency_value_per_point",
                  "minimum_redeemable_balance",
                  "minimum_redemption_amount",
                  "redemption_requires_customer_password",
                  "earns_with_store_credit",
                  "customer_group_exclusion_enabled",
                  "payment_modes"
                ],
                "properties": {
                  "enabled": {
                    "type": "boolean"
                  },
                  "earning_basis": {
                    "type": "string",
                    "enum": [
                      "sale",
                      "item_quantity",
                      "gross_amount"
                    ]
                  },
                  "earning_rate": {
                    "type": "number"
                  },
                  "uses_department_rates": {
                    "type": "boolean"
                  },
                "department_rates": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "additionalProperties": false,
                    "required": [
                      "department_id",
                      "earning_rate"
                    ],
                    "properties": {
                      "department_id": {
                        "type": "integer",
                        "format": "int64",
                        "minimum": 1
                      },
                      "earning_rate": {
                        "type": [
                          "number",
                          "null"
                        ],
                        "description": "La valeur null indique que le rayon hérite du taux de l’établissement."
                      }
                    }
                  }
                },
                  "welcome_points": {
                    "type": "number"
                  },
                  "currency_value_per_point": {
                    "type": "string",
                    "pattern": "^-?[0-9]+\\.[0-9]{2,}$"
                  },
                  "minimum_redeemable_balance": {
                    "type": "number"
                  },
                  "minimum_redemption_amount": {
                    "type": "string",
                    "pattern": "^-?[0-9]+\\.[0-9]{2,}$"
                  },
                  "redemption_requires_customer_password": {
                    "type": "boolean"
                  },
                  "earns_with_store_credit": {
                    "type": "boolean"
                  },
                  "customer_group_exclusion_enabled": {
                    "type": "boolean"
                  },
                  "payment_modes": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/PointsMode"
                    }
                  }
                }
              },
              "stamp_cards": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "enabled",
                  "templates"
                ],
                "properties": {
                  "enabled": {
                    "type": "boolean"
                  },
                  "templates": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/StampTemplate"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "AccountResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "data"
        ],
        "properties": {
          "data": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "customer_id",
              "currency",
              "points",
              "stamp_cards"
            ],
            "properties": {
              "customer_id": {
                "type": "integer",
                "format": "int64",
                "minimum": 1
              },
              "currency": {
                "type": "string",
                "description": "Code de devise de l’établissement."
              },
              "points": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "balance",
                  "redemption_status",
                  "requires_customer_password",
                  "balance_value"
                ],
                "properties": {
                  "balance": {
                    "type": "number"
                  },
                  "redemption_status": {
                    "type": "string",
                    "enum": [
                      "disabled",
                      "customer_group_excluded",
                      "customer_blocked",
                      "redemption_unavailable",
                      "insufficient_points",
                      "eligible",
                      "customer_required",
                      "cart_minimum_not_met"
                    ]
                  },
                  "requires_customer_password": {
                    "type": "boolean"
                  },
                  "balance_value": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "pattern": "^-?[0-9]+\\.[0-9]{2,}$"
                  }
                }
              },
              "stamp_cards": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "template_id",
                    "stamps",
                    "rewards_at_threshold"
                  ],
                  "properties": {
                    "template_id": {
                      "type": "integer",
                      "format": "int64",
                      "minimum": 1
                    },
                    "stamps": {
                      "type": "number"
                    },
                    "rewards_at_threshold": {
                      "type": "integer",
                      "minimum": 0
                    }
                  }
                }
              }
            }
          }
        }
      },
      "Movement": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "order_id",
          "recorded_at",
          "is_return",
          "source_order_id",
          "recorded_points",
          "points_on_reward_lines"
        ],
        "properties": {
          "order_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "recorded_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "is_return": {
            "type": "boolean"
          },
          "source_order_id": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64",
            "minimum": 1,
            "description": "Vente source reliée au retour et disponible dans le même établissement et pour le même client."
          },
          "recorded_points": {
            "type": "number",
            "description": "Points signés inscrits sur le ticket."
          },
          "points_on_reward_lines": {
            "type": [
              "number",
              "null"
            ],
            "description": "Quantité absolue portée par les lignes fidélité connues du ticket. Null si la table des lignes d’archives est indisponible."
          }
        }
      },
      "MovementPage": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "data",
          "pagination"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Movement"
            }
          },
          "pagination": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "next_cursor"
            ],
            "properties": {
              "next_cursor": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        }
      },
      "QuoteInput": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "cart"
        ],
        "properties": {
          "customer_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "maximum": 2147483647
          },
          "cart": {
            "$ref": "./openapi-partner-v1-cart-quotes.json#/components/schemas/CartQuoteInput"
          }
        }
      },
      "QuoteResponse": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "data"
        ],
        "properties": {
          "data": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "customer_id",
              "currency",
              "cart",
              "points",
              "stamp_cards"
            ],
            "properties": {
              "customer_id": {
                "type": [
                  "integer",
                  "null"
                ],
                "format": "int64",
                "minimum": 1
              },
              "currency": {
                "type": "string",
                "description": "Code de devise de l’établissement."
              },
              "cart": {
                "$ref": "./openapi-partner-v1-cart-quotes.json#/components/schemas/CartQuote"
              },
              "points": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "balance",
                  "redemption_status",
                  "requires_customer_password",
                  "estimated_earned_before_rewards",
                  "earning_conditional_on_customer",
                  "earning_conditional_on_payment_mode",
                  "redemptions"
                ],
                "properties": {
                  "balance": {
                    "type": [
                      "number",
                      "null"
                    ]
                  },
                  "redemption_status": {
                    "type": "string",
                    "enum": [
                      "disabled",
                      "customer_group_excluded",
                      "customer_blocked",
                      "redemption_unavailable",
                      "insufficient_points",
                      "eligible",
                      "customer_required",
                      "cart_minimum_not_met"
                    ]
                  },
                  "requires_customer_password": {
                    "type": "boolean"
                  },
                  "estimated_earned_before_rewards": {
                    "type": "number"
                  },
                  "earning_conditional_on_customer": {
                    "type": "boolean"
                  },
                  "earning_conditional_on_payment_mode": {
                    "type": "boolean"
                  },
                  "redemptions": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "required": [
                        "payment_mode_id",
                        "points",
                        "amount"
                      ],
                      "properties": {
                        "payment_mode_id": {
                          "type": "integer",
                          "format": "int64",
                          "minimum": 1
                        },
                        "points": {
                          "type": "number"
                        },
                        "amount": {
                          "type": "string",
                          "pattern": "^-?[0-9]+\\.[0-9]{2,}$"
                        }
                      }
                    }
                  }
                }
              },
              "stamp_cards": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "template_id",
                    "stamps",
                    "estimated_stamps_earned",
                    "potential_rewards"
                  ],
                  "properties": {
                    "template_id": {
                      "type": "integer",
                      "format": "int64",
                      "minimum": 1
                    },
                    "stamps": {
                      "type": "number"
                    },
                    "estimated_stamps_earned": {
                      "type": "number"
                    },
                    "potential_rewards": {
                      "type": "integer",
                      "minimum": 0
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
