Compare commits
6 Commits
test/stres
...
b1f42775d6
| Author | SHA1 | Date | |
|---|---|---|---|
| b1f42775d6 | |||
| 0f6f39cce7 | |||
| 1ec7ab3e35 | |||
| ba0e2dd00c | |||
| c792e7d306 | |||
| 6ee3f22e41 |
@@ -5,10 +5,6 @@ APP_DEBUG=false
|
|||||||
APP_URL=http://localhost
|
APP_URL=http://localhost
|
||||||
|
|
||||||
PURCHASE_CHECKOUT_EXPIRATION_MINUTES=30
|
PURCHASE_CHECKOUT_EXPIRATION_MINUTES=30
|
||||||
PURCHASE_QR_EXPIRATION_MINUTES=15
|
|
||||||
PURCHASE_TELEPAGOS_EXPIRATION_MINUTES=30
|
|
||||||
PURCHASE_TRANSFER_EXPIRATION_MINUTES=1440
|
|
||||||
PURCHASE_TRANSFER_CANDIDATE_AMOUNT_TOLERANCE_PERCENTAGE=5
|
|
||||||
STOCK_RESERVATION_EXPIRATION_MINUTES=30
|
STOCK_RESERVATION_EXPIRATION_MINUTES=30
|
||||||
FRONTEND_URLS=http://localhost:4200
|
FRONTEND_URLS=http://localhost:4200
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"info": {
|
"info": {
|
||||||
"_postman_id": "76fd6fd2-53b9-4d92-8e02-1ddcc6207fa2",
|
"_postman_id": "76fd6fd2-53b9-4d92-8e02-1ddcc6207fa2",
|
||||||
"name": "ShopIt API — Complete",
|
"name": "ShopIt API — Complete",
|
||||||
"description": "Colección canónica generada desde las rutas reales de Laravel. Incluye 137 operaciones HTTP, ejemplos de payload, filtros, archivos y tokens separados para Storefront, Admin App y Scanner.\n\nUso rápido:\n1. Ajustá `base_url` y las credenciales.\n2. Ejecutá el Login de la aplicación correspondiente; el token se guarda automáticamente.\n3. Ajustá los IDs y códigos de las variables de colección.\n\nRegeneración: `php postman/generate-shopit-collection.php`.",
|
"description": "Colección canónica generada desde las rutas reales de Laravel. Incluye 122 operaciones HTTP, ejemplos de payload, filtros, archivos y tokens separados para Storefront, Admin App y Scanner.\n\nUso rápido:\n1. Ajustá `base_url` y las credenciales.\n2. Ejecutá el Login de la aplicación correspondiente; el token se guarda automáticamente.\n3. Ajustá los IDs y códigos de las variables de colección.\n\nRegeneración: `php postman/generate-shopit-collection.php`.",
|
||||||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
||||||
},
|
},
|
||||||
"item": [
|
"item": [
|
||||||
@@ -385,42 +385,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "redirect Google Auth",
|
|
||||||
"request": {
|
|
||||||
"method": "GET",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Accept",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Ruta Laravel: `GET /auth/google/redirect`\n\nControlador: `App\\Domains\\Auth\\Controllers\\GoogleAuthController@redirect`",
|
|
||||||
"url": {
|
|
||||||
"raw": "{{base_url}}/auth/google/redirect?tenant={{tenant_code}}&return_url={{storefront_url}}",
|
|
||||||
"host": [
|
|
||||||
"{{base_url}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"auth",
|
|
||||||
"google",
|
|
||||||
"redirect"
|
|
||||||
],
|
|
||||||
"query": [
|
|
||||||
{
|
|
||||||
"key": "tenant",
|
|
||||||
"value": "{{tenant_code}}"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "return_url",
|
|
||||||
"value": "{{storefront_url}}"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -608,6 +572,60 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Update Checkout Cart Item Cart",
|
||||||
|
"request": {
|
||||||
|
"method": "PATCH",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "Content-Type",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Ruta Laravel: `PATCH /api/tenants/{tenant:codigo}/checkout-carts/{cart}/items/{cartItem}`\n\nControlador: `App\\Domains\\Cart\\Controllers\\CartController@updateCheckoutItem`\n\nRequiere autenticación Sanctum.",
|
||||||
|
"url": {
|
||||||
|
"raw": "{{base_url}}/api/tenants/{{tenant_code}}/checkout-carts/{{cart}}/items/{{cart_item_id}}",
|
||||||
|
"host": [
|
||||||
|
"{{base_url}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"api",
|
||||||
|
"tenants",
|
||||||
|
"{{tenant_code}}",
|
||||||
|
"checkout-carts",
|
||||||
|
"{{cart}}",
|
||||||
|
"items",
|
||||||
|
"{{cart_item_id}}"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": "{\n \"cantidad\": 2\n}",
|
||||||
|
"options": {
|
||||||
|
"raw": {
|
||||||
|
"language": "json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": "bearer",
|
||||||
|
"bearer": [
|
||||||
|
{
|
||||||
|
"key": "token",
|
||||||
|
"value": "{{token}}",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -1151,6 +1169,99 @@
|
|||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Prepare Item Editing Purchase",
|
||||||
|
"request": {
|
||||||
|
"method": "POST",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Ruta Laravel: `POST /api/tenants/{tenant:codigo}/compras/{compra}/edit-items`\n\nControlador: `App\\Domains\\Purchase\\Controllers\\PurchaseController@prepareItemEditing`\n\nRequiere autenticación Sanctum.",
|
||||||
|
"url": {
|
||||||
|
"raw": "{{base_url}}/api/tenants/{{tenant_code}}/compras/{{purchase_id}}/edit-items",
|
||||||
|
"host": [
|
||||||
|
"{{base_url}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"api",
|
||||||
|
"tenants",
|
||||||
|
"{{tenant_code}}",
|
||||||
|
"compras",
|
||||||
|
"{{purchase_id}}",
|
||||||
|
"edit-items"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": "bearer",
|
||||||
|
"bearer": [
|
||||||
|
{
|
||||||
|
"key": "token",
|
||||||
|
"value": "{{token}}",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Update Item Purchase",
|
||||||
|
"request": {
|
||||||
|
"method": "PATCH",
|
||||||
|
"header": [
|
||||||
|
{
|
||||||
|
"key": "Accept",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "Content-Type",
|
||||||
|
"value": "application/json",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Ruta Laravel: `PATCH /api/tenants/{tenant:codigo}/compras/{compra}/items/{item}`\n\nControlador: `App\\Domains\\Purchase\\Controllers\\PurchaseController@updateItem`\n\nRequiere autenticación Sanctum.",
|
||||||
|
"url": {
|
||||||
|
"raw": "{{base_url}}/api/tenants/{{tenant_code}}/compras/{{purchase_id}}/items/{{purchase_item_id}}",
|
||||||
|
"host": [
|
||||||
|
"{{base_url}}"
|
||||||
|
],
|
||||||
|
"path": [
|
||||||
|
"api",
|
||||||
|
"tenants",
|
||||||
|
"{{tenant_code}}",
|
||||||
|
"compras",
|
||||||
|
"{{purchase_id}}",
|
||||||
|
"items",
|
||||||
|
"{{purchase_item_id}}"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": "{\n \"quantity\": 2,\n \"variant_id\": {{variant_id}}\n}",
|
||||||
|
"options": {
|
||||||
|
"raw": {
|
||||||
|
"language": "json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"auth": {
|
||||||
|
"type": "bearer",
|
||||||
|
"bearer": [
|
||||||
|
{
|
||||||
|
"key": "token",
|
||||||
|
"value": "{{token}}",
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Create Payment Intent Purchase",
|
"name": "Create Payment Intent Purchase",
|
||||||
"request": {
|
"request": {
|
||||||
@@ -2103,7 +2214,7 @@
|
|||||||
},
|
},
|
||||||
"body": {
|
"body": {
|
||||||
"mode": "raw",
|
"mode": "raw",
|
||||||
"raw": "{\n \"client_id\": {{client_id}},\n \"codigo\": \"{{tenant_code}}\",\n \"nombre\": \"Tenant Demo\",\n \"dominio\": \"{{tenant_domain}}\",\n \"site_title\": \"ShopIt Demo\",\n \"primary_color\": \"#111827\",\n \"secondary_color\": \"#2563EB\",\n \"danger_color\": \"#DC2626\",\n \"success_color\": \"#16A34A\",\n \"header_bg_color\": \"#FFFFFF\",\n \"footer_bg_color\": \"#111827\",\n \"header_logo\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==\",\n \"footer_logo\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==\",\n \"search_product_layout\": \"column_with_image\",\n \"search_group_layout\": \"paginated\",\n \"search_items_per_page\": 12,\n \"display_categories\": true,\n \"display_seach_bar\": true,\n \"display_cart\": true,\n \"cart_editing_policy\": \"full\",\n \"website_type_code\": \"shopit\"\n}",
|
"raw": "{\n \"client_id\": {{client_id}},\n \"codigo\": \"{{tenant_code}}\",\n \"nombre\": \"Tenant Demo\",\n \"dominio\": \"{{tenant_domain}}\",\n \"site_title\": \"ShopIt Demo\",\n \"primary_color\": \"#111827\",\n \"secondary_color\": \"#2563EB\",\n \"danger_color\": \"#DC2626\",\n \"success_color\": \"#16A34A\",\n \"header_bg_color\": \"#FFFFFF\",\n \"footer_bg_color\": \"#111827\",\n \"header_logo\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==\",\n \"footer_logo\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==\",\n \"search_product_layout\": \"column_with_image\",\n \"search_group_layout\": \"paginated\",\n \"search_items_per_page\": 12,\n \"display_categories\": true,\n \"display_seach_bar\": true,\n \"display_cart\": true,\n \"cart_editing_policy\": \"full\",\n \"checkout_editing_policy\": \"full\",\n \"website_type_code\": \"shopit\"\n}",
|
||||||
"options": {
|
"options": {
|
||||||
"raw": {
|
"raw": {
|
||||||
"language": "json"
|
"language": "json"
|
||||||
@@ -2169,7 +2280,7 @@
|
|||||||
},
|
},
|
||||||
"body": {
|
"body": {
|
||||||
"mode": "raw",
|
"mode": "raw",
|
||||||
"raw": "{\n \"nombre\": \"Tenant Demo Actualizado\",\n \"site_title\": \"ShopIt Demo\",\n \"primary_color\": \"#111827\",\n \"cart_editing_policy\": \"full\"\n}",
|
"raw": "{\n \"nombre\": \"Tenant Demo Actualizado\",\n \"site_title\": \"ShopIt Demo\",\n \"primary_color\": \"#111827\",\n \"cart_editing_policy\": \"full\",\n \"checkout_editing_policy\": \"full\"\n}",
|
||||||
"options": {
|
"options": {
|
||||||
"raw": {
|
"raw": {
|
||||||
"language": "json"
|
"language": "json"
|
||||||
@@ -2209,7 +2320,7 @@
|
|||||||
},
|
},
|
||||||
"body": {
|
"body": {
|
||||||
"mode": "raw",
|
"mode": "raw",
|
||||||
"raw": "{\n \"nombre\": \"Tenant Demo Actualizado\",\n \"site_title\": \"ShopIt Demo\",\n \"primary_color\": \"#111827\",\n \"cart_editing_policy\": \"full\"\n}",
|
"raw": "{\n \"nombre\": \"Tenant Demo Actualizado\",\n \"site_title\": \"ShopIt Demo\",\n \"primary_color\": \"#111827\",\n \"cart_editing_policy\": \"full\",\n \"checkout_editing_policy\": \"full\"\n}",
|
||||||
"options": {
|
"options": {
|
||||||
"raw": {
|
"raw": {
|
||||||
"language": "json"
|
"language": "json"
|
||||||
@@ -2552,45 +2663,6 @@
|
|||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "Ticket Form",
|
|
||||||
"request": {
|
|
||||||
"method": "GET",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Accept",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Ruta Laravel: `GET /api/v1/adminapp/forms/fiesta-futbol-infantil/ticket`\n\nControlador: `App\\Domains\\Forms\\Controllers\\AdminApp\\TicketFormController`\n\nRequiere autenticación Sanctum.",
|
|
||||||
"url": {
|
|
||||||
"raw": "{{base_url}}/api/v1/adminapp/forms/fiesta-futbol-infantil/ticket",
|
|
||||||
"host": [
|
|
||||||
"{{base_url}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"v1",
|
|
||||||
"adminapp",
|
|
||||||
"forms",
|
|
||||||
"fiesta-futbol-infantil",
|
|
||||||
"ticket"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "bearer",
|
|
||||||
"bearer": [
|
|
||||||
{
|
|
||||||
"key": "token",
|
|
||||||
"value": "{{admin_token}}",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "Sale Form",
|
"name": "Sale Form",
|
||||||
"request": {
|
"request": {
|
||||||
@@ -2666,44 +2738,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Ticket Filter Form",
|
|
||||||
"request": {
|
|
||||||
"method": "GET",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Accept",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Ruta Laravel: `GET /api/v1/adminapp/forms/tickets-filter`\n\nControlador: `App\\Domains\\Forms\\Controllers\\AdminApp\\TicketFilterFormController`\n\nRequiere autenticación Sanctum.",
|
|
||||||
"url": {
|
|
||||||
"raw": "{{base_url}}/api/v1/adminapp/forms/tickets-filter",
|
|
||||||
"host": [
|
|
||||||
"{{base_url}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"v1",
|
|
||||||
"adminapp",
|
|
||||||
"forms",
|
|
||||||
"tickets-filter"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "bearer",
|
|
||||||
"bearer": [
|
|
||||||
{
|
|
||||||
"key": "token",
|
|
||||||
"value": "{{admin_token}}",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -3024,84 +3058,6 @@
|
|||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "Get Category Visibility",
|
|
||||||
"request": {
|
|
||||||
"method": "GET",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Accept",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Ruta Laravel: `GET /api/v1/adminapp/tenant/accommodations/visibility`\n\nControlador: `App\\Domains\\FiestaFutbolInfantil\\Controllers\\CategoryVisibilityController@show`\n\nRequiere autenticación Sanctum.",
|
|
||||||
"url": {
|
|
||||||
"raw": "{{base_url}}/api/v1/adminapp/tenant/accommodations/visibility",
|
|
||||||
"host": [
|
|
||||||
"{{base_url}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"v1",
|
|
||||||
"adminapp",
|
|
||||||
"tenant",
|
|
||||||
"accommodations",
|
|
||||||
"visibility"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "bearer",
|
|
||||||
"bearer": [
|
|
||||||
{
|
|
||||||
"key": "token",
|
|
||||||
"value": "{{admin_token}}",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Update Category Visibility",
|
|
||||||
"request": {
|
|
||||||
"method": "PATCH",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Accept",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Ruta Laravel: `PATCH /api/v1/adminapp/tenant/accommodations/visibility`\n\nControlador: `App\\Domains\\FiestaFutbolInfantil\\Controllers\\CategoryVisibilityController@update`\n\nRequiere autenticación Sanctum.",
|
|
||||||
"url": {
|
|
||||||
"raw": "{{base_url}}/api/v1/adminapp/tenant/accommodations/visibility",
|
|
||||||
"host": [
|
|
||||||
"{{base_url}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"v1",
|
|
||||||
"adminapp",
|
|
||||||
"tenant",
|
|
||||||
"accommodations",
|
|
||||||
"visibility"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "bearer",
|
|
||||||
"bearer": [
|
|
||||||
{
|
|
||||||
"key": "token",
|
|
||||||
"value": "{{admin_token}}",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "Delete Accommodation",
|
"name": "Delete Accommodation",
|
||||||
"request": {
|
"request": {
|
||||||
@@ -3231,84 +3187,6 @@
|
|||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "Get Category Visibility",
|
|
||||||
"request": {
|
|
||||||
"method": "GET",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Accept",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Ruta Laravel: `GET /api/v1/adminapp/tenant/entries/visibility`\n\nControlador: `App\\Domains\\FiestaFutbolInfantil\\Controllers\\CategoryVisibilityController@show`\n\nRequiere autenticación Sanctum.",
|
|
||||||
"url": {
|
|
||||||
"raw": "{{base_url}}/api/v1/adminapp/tenant/entries/visibility",
|
|
||||||
"host": [
|
|
||||||
"{{base_url}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"v1",
|
|
||||||
"adminapp",
|
|
||||||
"tenant",
|
|
||||||
"entries",
|
|
||||||
"visibility"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "bearer",
|
|
||||||
"bearer": [
|
|
||||||
{
|
|
||||||
"key": "token",
|
|
||||||
"value": "{{admin_token}}",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Update Category Visibility",
|
|
||||||
"request": {
|
|
||||||
"method": "PATCH",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Accept",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Ruta Laravel: `PATCH /api/v1/adminapp/tenant/entries/visibility`\n\nControlador: `App\\Domains\\FiestaFutbolInfantil\\Controllers\\CategoryVisibilityController@update`\n\nRequiere autenticación Sanctum.",
|
|
||||||
"url": {
|
|
||||||
"raw": "{{base_url}}/api/v1/adminapp/tenant/entries/visibility",
|
|
||||||
"host": [
|
|
||||||
"{{base_url}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"v1",
|
|
||||||
"adminapp",
|
|
||||||
"tenant",
|
|
||||||
"entries",
|
|
||||||
"visibility"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "bearer",
|
|
||||||
"bearer": [
|
|
||||||
{
|
|
||||||
"key": "token",
|
|
||||||
"value": "{{admin_token}}",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "Delete Entry",
|
"name": "Delete Entry",
|
||||||
"request": {
|
"request": {
|
||||||
@@ -3438,84 +3316,6 @@
|
|||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "Get Category Visibility",
|
|
||||||
"request": {
|
|
||||||
"method": "GET",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Accept",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Ruta Laravel: `GET /api/v1/adminapp/tenant/foods/visibility`\n\nControlador: `App\\Domains\\FiestaFutbolInfantil\\Controllers\\CategoryVisibilityController@show`\n\nRequiere autenticación Sanctum.",
|
|
||||||
"url": {
|
|
||||||
"raw": "{{base_url}}/api/v1/adminapp/tenant/foods/visibility",
|
|
||||||
"host": [
|
|
||||||
"{{base_url}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"v1",
|
|
||||||
"adminapp",
|
|
||||||
"tenant",
|
|
||||||
"foods",
|
|
||||||
"visibility"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "bearer",
|
|
||||||
"bearer": [
|
|
||||||
{
|
|
||||||
"key": "token",
|
|
||||||
"value": "{{admin_token}}",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Update Category Visibility",
|
|
||||||
"request": {
|
|
||||||
"method": "PATCH",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Accept",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Ruta Laravel: `PATCH /api/v1/adminapp/tenant/foods/visibility`\n\nControlador: `App\\Domains\\FiestaFutbolInfantil\\Controllers\\CategoryVisibilityController@update`\n\nRequiere autenticación Sanctum.",
|
|
||||||
"url": {
|
|
||||||
"raw": "{{base_url}}/api/v1/adminapp/tenant/foods/visibility",
|
|
||||||
"host": [
|
|
||||||
"{{base_url}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"v1",
|
|
||||||
"adminapp",
|
|
||||||
"tenant",
|
|
||||||
"foods",
|
|
||||||
"visibility"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "bearer",
|
|
||||||
"bearer": [
|
|
||||||
{
|
|
||||||
"key": "token",
|
|
||||||
"value": "{{admin_token}}",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "Delete Food",
|
"name": "Delete Food",
|
||||||
"request": {
|
"request": {
|
||||||
@@ -3645,84 +3445,6 @@
|
|||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "Get Category Visibility",
|
|
||||||
"request": {
|
|
||||||
"method": "GET",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Accept",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Ruta Laravel: `GET /api/v1/adminapp/tenant/merchandise/visibility`\n\nControlador: `App\\Domains\\FiestaFutbolInfantil\\Controllers\\CategoryVisibilityController@show`\n\nRequiere autenticación Sanctum.",
|
|
||||||
"url": {
|
|
||||||
"raw": "{{base_url}}/api/v1/adminapp/tenant/merchandise/visibility",
|
|
||||||
"host": [
|
|
||||||
"{{base_url}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"v1",
|
|
||||||
"adminapp",
|
|
||||||
"tenant",
|
|
||||||
"merchandise",
|
|
||||||
"visibility"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "bearer",
|
|
||||||
"bearer": [
|
|
||||||
{
|
|
||||||
"key": "token",
|
|
||||||
"value": "{{admin_token}}",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Update Category Visibility",
|
|
||||||
"request": {
|
|
||||||
"method": "PATCH",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Accept",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Ruta Laravel: `PATCH /api/v1/adminapp/tenant/merchandise/visibility`\n\nControlador: `App\\Domains\\FiestaFutbolInfantil\\Controllers\\CategoryVisibilityController@update`\n\nRequiere autenticación Sanctum.",
|
|
||||||
"url": {
|
|
||||||
"raw": "{{base_url}}/api/v1/adminapp/tenant/merchandise/visibility",
|
|
||||||
"host": [
|
|
||||||
"{{base_url}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"v1",
|
|
||||||
"adminapp",
|
|
||||||
"tenant",
|
|
||||||
"merchandise",
|
|
||||||
"visibility"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "bearer",
|
|
||||||
"bearer": [
|
|
||||||
{
|
|
||||||
"key": "token",
|
|
||||||
"value": "{{admin_token}}",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "Delete Merchandise",
|
"name": "Delete Merchandise",
|
||||||
"request": {
|
"request": {
|
||||||
@@ -4327,45 +4049,6 @@
|
|||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "download Excel Sale",
|
|
||||||
"request": {
|
|
||||||
"method": "GET",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Accept",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Ruta Laravel: `GET /api/v1/adminapp/tenant/sales/excel`\n\nControlador: `App\\Domains\\Sale\\Controllers\\AdminApp\\SaleController@downloadExcel`\n\nRequiere autenticación Sanctum.",
|
|
||||||
"url": {
|
|
||||||
"raw": "{{base_url}}/api/v1/adminapp/tenant/sales/excel",
|
|
||||||
"host": [
|
|
||||||
"{{base_url}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"v1",
|
|
||||||
"adminapp",
|
|
||||||
"tenant",
|
|
||||||
"sales",
|
|
||||||
"excel"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "bearer",
|
|
||||||
"bearer": [
|
|
||||||
{
|
|
||||||
"key": "token",
|
|
||||||
"value": "{{admin_token}}",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "List Modifications Sale",
|
"name": "List Modifications Sale",
|
||||||
"request": {
|
"request": {
|
||||||
@@ -4405,46 +4088,6 @@
|
|||||||
},
|
},
|
||||||
"response": []
|
"response": []
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "download Modifications Excel Sale",
|
|
||||||
"request": {
|
|
||||||
"method": "GET",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Accept",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Ruta Laravel: `GET /api/v1/adminapp/tenant/sales/modifications/excel`\n\nControlador: `App\\Domains\\Sale\\Controllers\\AdminApp\\SaleController@downloadModificationsExcel`\n\nRequiere autenticación Sanctum.",
|
|
||||||
"url": {
|
|
||||||
"raw": "{{base_url}}/api/v1/adminapp/tenant/sales/modifications/excel",
|
|
||||||
"host": [
|
|
||||||
"{{base_url}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"v1",
|
|
||||||
"adminapp",
|
|
||||||
"tenant",
|
|
||||||
"sales",
|
|
||||||
"modifications",
|
|
||||||
"excel"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "bearer",
|
|
||||||
"bearer": [
|
|
||||||
{
|
|
||||||
"key": "token",
|
|
||||||
"value": "{{admin_token}}",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "Download Modifications PDF Sale",
|
"name": "Download Modifications PDF Sale",
|
||||||
"request": {
|
"request": {
|
||||||
@@ -4958,127 +4601,6 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "Ticket",
|
|
||||||
"item": [
|
|
||||||
{
|
|
||||||
"name": "List Ticket",
|
|
||||||
"request": {
|
|
||||||
"method": "GET",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Accept",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Ruta Laravel: `GET /api/v1/adminapp/tenant/tickets`\n\nControlador: `App\\Domains\\Ticket\\Controllers\\AdminApp\\TicketController@index`\n\nRequiere autenticación Sanctum.",
|
|
||||||
"url": {
|
|
||||||
"raw": "{{base_url}}/api/v1/adminapp/tenant/tickets",
|
|
||||||
"host": [
|
|
||||||
"{{base_url}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"v1",
|
|
||||||
"adminapp",
|
|
||||||
"tenant",
|
|
||||||
"tickets"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "bearer",
|
|
||||||
"bearer": [
|
|
||||||
{
|
|
||||||
"key": "token",
|
|
||||||
"value": "{{admin_token}}",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "download Excel Ticket",
|
|
||||||
"request": {
|
|
||||||
"method": "GET",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Accept",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Ruta Laravel: `GET /api/v1/adminapp/tenant/tickets/excel`\n\nControlador: `App\\Domains\\Ticket\\Controllers\\AdminApp\\TicketController@downloadExcel`\n\nRequiere autenticación Sanctum.",
|
|
||||||
"url": {
|
|
||||||
"raw": "{{base_url}}/api/v1/adminapp/tenant/tickets/excel",
|
|
||||||
"host": [
|
|
||||||
"{{base_url}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"v1",
|
|
||||||
"adminapp",
|
|
||||||
"tenant",
|
|
||||||
"tickets",
|
|
||||||
"excel"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "bearer",
|
|
||||||
"bearer": [
|
|
||||||
{
|
|
||||||
"key": "token",
|
|
||||||
"value": "{{admin_token}}",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Download PDF Ticket",
|
|
||||||
"request": {
|
|
||||||
"method": "GET",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Accept",
|
|
||||||
"value": "application/json",
|
|
||||||
"type": "text"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Ruta Laravel: `GET /api/v1/adminapp/tenant/tickets/pdf`\n\nControlador: `App\\Domains\\Ticket\\Controllers\\AdminApp\\TicketController@downloadPdf`\n\nRequiere autenticación Sanctum.",
|
|
||||||
"url": {
|
|
||||||
"raw": "{{base_url}}/api/v1/adminapp/tenant/tickets/pdf",
|
|
||||||
"host": [
|
|
||||||
"{{base_url}}"
|
|
||||||
],
|
|
||||||
"path": [
|
|
||||||
"api",
|
|
||||||
"v1",
|
|
||||||
"adminapp",
|
|
||||||
"tenant",
|
|
||||||
"tickets",
|
|
||||||
"pdf"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"auth": {
|
|
||||||
"type": "bearer",
|
|
||||||
"bearer": [
|
|
||||||
{
|
|
||||||
"key": "token",
|
|
||||||
"value": "{{admin_token}}",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "Tenant",
|
"name": "Tenant",
|
||||||
"item": [
|
"item": [
|
||||||
@@ -5732,11 +5254,6 @@
|
|||||||
"value": "http://localhost:8000",
|
"value": "http://localhost:8000",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"key": "storefront_url",
|
|
||||||
"value": "http://localhost:4200",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"key": "token",
|
"key": "token",
|
||||||
"value": "",
|
"value": "",
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class InvitationPurchaseProvisioner
|
|||||||
private const ALLOCATIONS = [
|
private const ALLOCATIONS = [
|
||||||
['sector' => 'A', 'row' => 1, 'first_seat' => 1, 'last_seat' => 16, 'type' => 'NORMAL'],
|
['sector' => 'A', 'row' => 1, 'first_seat' => 1, 'last_seat' => 16, 'type' => 'NORMAL'],
|
||||||
['sector' => 'A', 'row' => 3, 'first_seat' => 1, 'last_seat' => 14, 'type' => 'NORMAL'],
|
['sector' => 'A', 'row' => 3, 'first_seat' => 1, 'last_seat' => 14, 'type' => 'NORMAL'],
|
||||||
['sector' => 'C', 'row' => 1, 'first_seat' => 1, 'last_seat' => 17, 'type' => 'VIP + LUNCH'],
|
['sector' => 'C', 'row' => 1, 'first_seat' => 1, 'last_seat' => 16, 'type' => 'VIP + LUNCH'],
|
||||||
['sector' => 'C', 'row' => 3, 'first_seat' => 6, 'last_seat' => 7, 'type' => 'NORMAL'],
|
['sector' => 'C', 'row' => 3, 'first_seat' => 6, 'last_seat' => 7, 'type' => 'NORMAL'],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Forms\Controllers\AdminApp;
|
||||||
|
|
||||||
|
use App\Domains\Forms\Resources\TicketFormResource;
|
||||||
|
use App\Domains\Forms\Services\TicketFormService;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class TicketFormController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(protected TicketFormService $ticketFormService) {}
|
||||||
|
|
||||||
|
public function __invoke(Request $request): TicketFormResource
|
||||||
|
{
|
||||||
|
return TicketFormResource::make(
|
||||||
|
$this->ticketFormService->get(
|
||||||
|
$request->user('sanctum')->tenant()->firstOrFail()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
18
app/Domains/Forms/Resources/TicketFormResource.php
Normal file
18
app/Domains/Forms/Resources/TicketFormResource.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Forms\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class TicketFormResource extends JsonResource
|
||||||
|
{
|
||||||
|
/** @return array<string, mixed> */
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'statuses' => $this->resource['statuses'],
|
||||||
|
'categories' => $this->resource['categories'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
234
app/Domains/Forms/Services/TicketFormService.php
Normal file
234
app/Domains/Forms/Services/TicketFormService.php
Normal file
@@ -0,0 +1,234 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Forms\Services;
|
||||||
|
|
||||||
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
|
use App\Domains\Catalog\Models\Variant;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use App\Domains\Ticket\Models\Ticket;
|
||||||
|
|
||||||
|
class TicketFormService
|
||||||
|
{
|
||||||
|
private const PRODUCT = 'product';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array<string, array{label: string|null, product: string, type: string|null, order: int}>
|
||||||
|
*/
|
||||||
|
private const CATEGORY_PRESENTATIONS = [
|
||||||
|
'entradas' => [
|
||||||
|
'label' => null,
|
||||||
|
'product' => self::PRODUCT,
|
||||||
|
'type' => null,
|
||||||
|
'order' => 1,
|
||||||
|
],
|
||||||
|
'alojamientos' => [
|
||||||
|
'label' => 'Camping',
|
||||||
|
'product' => 'tipo_alojamiento',
|
||||||
|
'type' => null,
|
||||||
|
'order' => 2,
|
||||||
|
],
|
||||||
|
'camping' => [
|
||||||
|
'label' => null,
|
||||||
|
'product' => 'tipo_alojamiento',
|
||||||
|
'type' => null,
|
||||||
|
'order' => 2,
|
||||||
|
],
|
||||||
|
'comidas' => [
|
||||||
|
'label' => 'Comida',
|
||||||
|
'product' => 'event_date',
|
||||||
|
'type' => 'horario',
|
||||||
|
'order' => 3,
|
||||||
|
],
|
||||||
|
'comida' => [
|
||||||
|
'label' => null,
|
||||||
|
'product' => 'event_date',
|
||||||
|
'type' => 'horario',
|
||||||
|
'order' => 3,
|
||||||
|
],
|
||||||
|
'merchandising' => [
|
||||||
|
'label' => null,
|
||||||
|
'product' => self::PRODUCT,
|
||||||
|
'type' => 'color',
|
||||||
|
'order' => 4,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{
|
||||||
|
* statuses: list<array{value: string, label: string}>,
|
||||||
|
* categories: list<array{
|
||||||
|
* value: string,
|
||||||
|
* label: string,
|
||||||
|
* products: list<array{
|
||||||
|
* value: string,
|
||||||
|
* label: string,
|
||||||
|
* types: list<array{value: string, label: string}>
|
||||||
|
* }>
|
||||||
|
* }>
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
public function get(Tenant $tenant): array
|
||||||
|
{
|
||||||
|
$categories = [];
|
||||||
|
|
||||||
|
$items = CatalogItem::query()
|
||||||
|
->where('tenant_code', $tenant->codigo)
|
||||||
|
->where('has_tickets', true)
|
||||||
|
->whereHas('category')
|
||||||
|
->with([
|
||||||
|
'category',
|
||||||
|
'itemAttributes.attribute.options',
|
||||||
|
'variants.definitions.itemAttribute.attribute.options',
|
||||||
|
'variants.eventDates',
|
||||||
|
'variants.eventDate',
|
||||||
|
])
|
||||||
|
->orderBy('group_order')
|
||||||
|
->orderBy('nombre')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
foreach ($items as $item) {
|
||||||
|
$sourceCategory = trim((string) $item->category?->nombre);
|
||||||
|
$categoryValue = mb_strtolower($sourceCategory);
|
||||||
|
$presentation = self::CATEGORY_PRESENTATIONS[$categoryValue] ?? [
|
||||||
|
'label' => null,
|
||||||
|
'product' => self::PRODUCT,
|
||||||
|
'type' => null,
|
||||||
|
'order' => PHP_INT_MAX,
|
||||||
|
];
|
||||||
|
|
||||||
|
$categories[$categoryValue] ??= [
|
||||||
|
'value' => $categoryValue,
|
||||||
|
'label' => $presentation['label'] ?? $sourceCategory,
|
||||||
|
'order' => $presentation['order'],
|
||||||
|
'products' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($this->products($item, $presentation['product'], $presentation['type']) as $product) {
|
||||||
|
$productValue = $product['value'];
|
||||||
|
$existingProduct = $categories[$categoryValue]['products'][$productValue] ?? [
|
||||||
|
'value' => $productValue,
|
||||||
|
'label' => $product['label'],
|
||||||
|
'types' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($product['types'] as $type) {
|
||||||
|
$existingProduct['types'][$type['value']] = $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
$categories[$categoryValue]['products'][$productValue] = $existingProduct;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uasort($categories, fn (array $left, array $right): int => $left['order'] <=> $right['order']
|
||||||
|
?: $left['label'] <=> $right['label']);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'statuses' => [
|
||||||
|
['value' => Ticket::STATUS_ACTIVE, 'label' => 'Activo'],
|
||||||
|
['value' => Ticket::STATUS_USED, 'label' => 'Usado'],
|
||||||
|
['value' => Ticket::STATUS_EXPIRED, 'label' => 'Vencido'],
|
||||||
|
],
|
||||||
|
'categories' => array_values(array_map(
|
||||||
|
fn (array $category): array => [
|
||||||
|
'value' => $category['value'],
|
||||||
|
'label' => $category['label'],
|
||||||
|
'products' => array_values(array_map(
|
||||||
|
fn (array $product): array => [
|
||||||
|
'value' => $product['value'],
|
||||||
|
'label' => $product['label'],
|
||||||
|
'types' => array_values($product['types']),
|
||||||
|
],
|
||||||
|
$category['products'],
|
||||||
|
)),
|
||||||
|
],
|
||||||
|
$categories,
|
||||||
|
)),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array{
|
||||||
|
* value: string,
|
||||||
|
* label: string,
|
||||||
|
* types: list<array{value: string, label: string}>
|
||||||
|
* }>
|
||||||
|
*/
|
||||||
|
private function products(CatalogItem $item, string $productCode, ?string $typeCode): array
|
||||||
|
{
|
||||||
|
if ($productCode === self::PRODUCT) {
|
||||||
|
return [[
|
||||||
|
'value' => $item->slug,
|
||||||
|
'label' => $item->nombre,
|
||||||
|
'types' => $this->types($item, $typeCode),
|
||||||
|
]];
|
||||||
|
}
|
||||||
|
|
||||||
|
$products = [];
|
||||||
|
|
||||||
|
foreach ($item->variants as $variant) {
|
||||||
|
foreach ($this->variantOptions($variant, $productCode) as $productOption) {
|
||||||
|
$productValue = $productOption['value'];
|
||||||
|
$products[$productValue] ??= [
|
||||||
|
'value' => $productValue,
|
||||||
|
'label' => $this->optionLabel($productOption['label'], $productCode),
|
||||||
|
'types' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($this->variantOptions($variant, $typeCode) as $typeOption) {
|
||||||
|
$products[$productValue]['types'][$typeOption['value']] = $typeOption;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_values(array_map(
|
||||||
|
fn (array $product): array => [
|
||||||
|
'value' => $product['value'],
|
||||||
|
'label' => $product['label'],
|
||||||
|
'types' => array_values($product['types']),
|
||||||
|
],
|
||||||
|
$products,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return list<array{value: string, label: string}> */
|
||||||
|
private function types(CatalogItem $item, ?string $typeCode): array
|
||||||
|
{
|
||||||
|
$types = [];
|
||||||
|
|
||||||
|
foreach ($item->variants as $variant) {
|
||||||
|
foreach ($this->variantOptions($variant, $typeCode) as $typeOption) {
|
||||||
|
$types[$typeOption['value']] = $typeOption;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_values($types);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return list<array{value: string, label: string}> */
|
||||||
|
private function variantOptions(Variant $variant, ?string $attributeCode): array
|
||||||
|
{
|
||||||
|
if ($attributeCode === null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$selection = $variant->selectionOptions($variant->catalogItem->itemAttributes)
|
||||||
|
->get($attributeCode);
|
||||||
|
|
||||||
|
if ($selection === null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_is_list($selection) ? $selection : [$selection];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function optionLabel(string $label, string $attributeCode): string
|
||||||
|
{
|
||||||
|
if ($attributeCode !== 'event_date') {
|
||||||
|
return $label;
|
||||||
|
}
|
||||||
|
|
||||||
|
[$day, $month] = array_pad(explode('/', $label), 2, null);
|
||||||
|
|
||||||
|
return $day !== null && $month !== null ? "{$day}/{$month}" : $label;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ Provee catálogos y opciones auxiliares para construir formularios del panel adm
|
|||||||
- `EventFormService`: devuelve redes sociales disponibles y las URL configuradas para el tenant.
|
- `EventFormService`: devuelve redes sociales disponibles y las URL configuradas para el tenant.
|
||||||
- `SaleFormService`: expone los estados admitidos para compras con sus etiquetas de presentación.
|
- `SaleFormService`: expone los estados admitidos para compras con sus etiquetas de presentación.
|
||||||
- `StaffFormService`: lista categorías raíz que pueden asignarse al personal del tenant.
|
- `StaffFormService`: lista categorías raíz que pueden asignarse al personal del tenant.
|
||||||
|
- `TicketFormService`: expone estados y opciones anidadas de categoría, producto y tipo para los tickets de Fiesta Fútbol Infantil.
|
||||||
|
|
||||||
Cada servicio tiene un controlador invocable y un `JsonResource` específico. `SocialMediaOptionResource` representa las opciones de redes sociales.
|
Cada servicio tiene un controlador invocable y un `JsonResource` específico. `SocialMediaOptionResource` representa las opciones de redes sociales.
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ Bajo `/v1/adminapp/forms`, con `auth:sanctum` y `adminapp.tenant`:
|
|||||||
- `GET /event`.
|
- `GET /event`.
|
||||||
- `GET /sale`.
|
- `GET /sale`.
|
||||||
- `GET /staff`.
|
- `GET /staff`.
|
||||||
|
- `GET /fiesta-futbol-infantil/ticket`: estados y jerarquía categoría → producto → tipo para filtros de tickets.
|
||||||
- `GET /fiesta-futbol-infantil/merchandise`: opciones de color y talle del tenant para merchandising.
|
- `GET /fiesta-futbol-infantil/merchandise`: opciones de color y talle del tenant para merchandising.
|
||||||
|
|
||||||
## Dependencias
|
## Dependencias
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use App\Domains\Forms\Controllers\AdminApp\FoodFormController;
|
|||||||
use App\Domains\Forms\Controllers\AdminApp\MerchandiseFormController;
|
use App\Domains\Forms\Controllers\AdminApp\MerchandiseFormController;
|
||||||
use App\Domains\Forms\Controllers\AdminApp\SaleFormController;
|
use App\Domains\Forms\Controllers\AdminApp\SaleFormController;
|
||||||
use App\Domains\Forms\Controllers\AdminApp\StaffFormController;
|
use App\Domains\Forms\Controllers\AdminApp\StaffFormController;
|
||||||
|
use App\Domains\Forms\Controllers\AdminApp\TicketFormController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
Route::prefix('v1/adminapp/forms')
|
Route::prefix('v1/adminapp/forms')
|
||||||
@@ -13,6 +14,10 @@ Route::prefix('v1/adminapp/forms')
|
|||||||
Route::get('event', EventFormController::class);
|
Route::get('event', EventFormController::class);
|
||||||
Route::get('sale', SaleFormController::class);
|
Route::get('sale', SaleFormController::class);
|
||||||
Route::get('staff', StaffFormController::class);
|
Route::get('staff', StaffFormController::class);
|
||||||
|
Route::get(
|
||||||
|
'fiesta-futbol-infantil/ticket',
|
||||||
|
TicketFormController::class
|
||||||
|
);
|
||||||
Route::get(
|
Route::get(
|
||||||
'fiesta-futbol-infantil/merchandise',
|
'fiesta-futbol-infantil/merchandise',
|
||||||
MerchandiseFormController::class
|
MerchandiseFormController::class
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ use App\Domains\Purchase\Models\Purchase;
|
|||||||
use App\Domains\Purchase\Models\TelepagosPayment;
|
use App\Domains\Purchase\Models\TelepagosPayment;
|
||||||
use App\Domains\Purchase\Models\TelepagosQr;
|
use App\Domains\Purchase\Models\TelepagosQr;
|
||||||
use App\Domains\Purchase\Services\CheckoutService;
|
use App\Domains\Purchase\Services\CheckoutService;
|
||||||
use App\Domains\Purchase\Services\DniDistanceService;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
@@ -18,7 +15,6 @@ class TelepagosWebhookService
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly CheckoutService $checkoutService,
|
private readonly CheckoutService $checkoutService,
|
||||||
private readonly DniDistanceService $dniDistance,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,6 +41,7 @@ class TelepagosWebhookService
|
|||||||
|
|
||||||
$paymentData = [
|
$paymentData = [
|
||||||
'compra_id' => null,
|
'compra_id' => null,
|
||||||
|
'matched_purchase_ids' => null,
|
||||||
'cuit_buyer' => $details['data']['buyer']['cuit'] ?? $details['buyer']['cuit'] ?? null,
|
'cuit_buyer' => $details['data']['buyer']['cuit'] ?? $details['buyer']['cuit'] ?? null,
|
||||||
'cvu_buyer' => $details['data']['buyer']['cvu'] ?? $details['buyer']['cvu'] ?? null,
|
'cvu_buyer' => $details['data']['buyer']['cvu'] ?? $details['buyer']['cvu'] ?? null,
|
||||||
'amount' => $amount,
|
'amount' => $amount,
|
||||||
@@ -76,55 +73,24 @@ class TelepagosWebhookService
|
|||||||
$dni = substr($cuit, 2, -1);
|
$dni = substr($cuit, 2, -1);
|
||||||
|
|
||||||
$tenantCodes = $client->tenants()->pluck('codigo');
|
$tenantCodes = $client->tenants()->pluck('codigo');
|
||||||
$eligiblePurchases = Purchase::query()
|
$purchases = Purchase::whereIn('tenant_codigo', $tenantCodes)
|
||||||
->whereIn('tenant_codigo', $tenantCodes)
|
->where('transfer_payer_dni', $dni)
|
||||||
->whereIn('status', [
|
->whereIn('status', [
|
||||||
Purchase::STATUS_CREATED,
|
Purchase::STATUS_CREATED,
|
||||||
Purchase::STATUS_PENDING_PAYMENT,
|
Purchase::STATUS_PENDING_PAYMENT,
|
||||||
Purchase::STATUS_IN_REVIEW,
|
Purchase::STATUS_IN_REVIEW,
|
||||||
])
|
])
|
||||||
->where('payment_method', 'transfer');
|
->where('payment_method', 'transfer')
|
||||||
|
|
||||||
$purchases = (clone $eligiblePurchases)
|
|
||||||
->where('total', $amount)
|
->where('total', $amount)
|
||||||
->latest()
|
->latest()
|
||||||
->get()
|
->get();
|
||||||
->filter(fn (Purchase $purchase): bool => $purchase->transfer_payer_dni !== null
|
|
||||||
&& $this->dniDistance->distance($dni, $purchase->transfer_payer_dni) === 0)
|
|
||||||
->values();
|
|
||||||
|
|
||||||
|
$paymentData['matched_purchase_ids'] = $purchases->pluck('id')->all();
|
||||||
$compra = $purchases->count() === 1 ? $purchases->first() : null;
|
$compra = $purchases->count() === 1 ? $purchases->first() : null;
|
||||||
|
|
||||||
if (! $compra) {
|
if (! $compra) {
|
||||||
$candidatePurchases = $this->findTransferCandidates(
|
if ($purchases->count() > 1) {
|
||||||
$eligiblePurchases,
|
TelepagosPayment::create($paymentData);
|
||||||
$dni,
|
|
||||||
$amount,
|
|
||||||
);
|
|
||||||
if ($candidatePurchases->isNotEmpty()) {
|
|
||||||
$payment = $this->storeTransferCandidates(
|
|
||||||
$paymentData,
|
|
||||||
$candidatePurchases,
|
|
||||||
$dni,
|
|
||||||
$amount,
|
|
||||||
);
|
|
||||||
|
|
||||||
Log::channel('telepagos')->info('Telepagos webhook: Transfer payment candidates found.', [
|
|
||||||
'client_code' => $client->code,
|
|
||||||
'cashin_id' => $cashinId,
|
|
||||||
'telepagos_payment_id' => $payment->id,
|
|
||||||
'amount' => $amount,
|
|
||||||
'candidate_count' => $payment->candidates->count(),
|
|
||||||
'candidates' => $payment->candidates
|
|
||||||
->map(fn ($candidate): array => [
|
|
||||||
'purchase_id' => $candidate->compra_id,
|
|
||||||
'match_reason' => $candidate->match_reason,
|
|
||||||
'dni_distance' => $candidate->dni_distance,
|
|
||||||
'amount_difference' => $candidate->amount_difference,
|
|
||||||
'confidence' => $candidate->confidence,
|
|
||||||
])
|
|
||||||
->all(),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::channel('telepagos')->warning('Telepagos webhook: Expected exactly one matching purchase.', [
|
Log::channel('telepagos')->warning('Telepagos webhook: Expected exactly one matching purchase.', [
|
||||||
@@ -243,91 +209,4 @@ class TelepagosWebhookService
|
|||||||
{
|
{
|
||||||
return number_format((float) $amount, 2, '.', '');
|
return number_format((float) $amount, 2, '.', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Builder<Purchase> $eligiblePurchases
|
|
||||||
* @return Collection<int, Purchase>
|
|
||||||
*/
|
|
||||||
private function findTransferCandidates(Builder $eligiblePurchases, string $dni, string $amount): Collection
|
|
||||||
{
|
|
||||||
$tolerancePercentage = max(
|
|
||||||
0,
|
|
||||||
(float) config('purchase.transfer_candidate_amount_tolerance_percentage', 5),
|
|
||||||
);
|
|
||||||
$numericAmount = (float) $amount;
|
|
||||||
$tolerance = $numericAmount * ($tolerancePercentage / 100);
|
|
||||||
$minimumAmount = $this->normalizeAmount(max(0, $numericAmount - $tolerance));
|
|
||||||
$maximumAmount = $this->normalizeAmount($numericAmount + $tolerance);
|
|
||||||
|
|
||||||
return (clone $eligiblePurchases)
|
|
||||||
->whereBetween('total', [$minimumAmount, $maximumAmount])
|
|
||||||
->latest()
|
|
||||||
->get()
|
|
||||||
->filter(function (Purchase $purchase) use ($dni, $amount): bool {
|
|
||||||
if ($purchase->transfer_payer_dni === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$purchaseAmount = $this->normalizeAmount($purchase->total);
|
|
||||||
$distance = $this->dniDistance->distance(
|
|
||||||
$dni,
|
|
||||||
(string) $purchase->transfer_payer_dni,
|
|
||||||
);
|
|
||||||
|
|
||||||
return $distance === 0
|
|
||||||
|| ($purchaseAmount === $amount && $distance <= 2);
|
|
||||||
})
|
|
||||||
->values();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array<string, mixed> $paymentData
|
|
||||||
* @param Collection<int, Purchase> $candidatePurchases
|
|
||||||
*/
|
|
||||||
private function storeTransferCandidates(
|
|
||||||
array $paymentData,
|
|
||||||
Collection $candidatePurchases,
|
|
||||||
string $dni,
|
|
||||||
string $amount,
|
|
||||||
): TelepagosPayment {
|
|
||||||
return DB::transaction(function () use ($paymentData, $candidatePurchases, $dni, $amount): TelepagosPayment {
|
|
||||||
$payment = TelepagosPayment::create($paymentData);
|
|
||||||
|
|
||||||
$payment->candidates()->createMany(
|
|
||||||
$candidatePurchases
|
|
||||||
->map(function (Purchase $purchase) use ($dni, $amount): array {
|
|
||||||
$purchaseAmount = $this->normalizeAmount($purchase->total);
|
|
||||||
$dniDistance = $this->dniDistance->distance(
|
|
||||||
$dni,
|
|
||||||
(string) $purchase->transfer_payer_dni,
|
|
||||||
);
|
|
||||||
$dniMatches = $dniDistance === 0;
|
|
||||||
$amountMatches = $purchaseAmount === $amount;
|
|
||||||
|
|
||||||
return [
|
|
||||||
'compra_id' => $purchase->id,
|
|
||||||
'dni_matches' => $dniMatches,
|
|
||||||
'dni_distance' => $dniDistance,
|
|
||||||
'payment_dni' => $dni,
|
|
||||||
'purchase_dni' => $purchase->transfer_payer_dni,
|
|
||||||
'amount_matches' => $amountMatches,
|
|
||||||
'payment_amount' => $amount,
|
|
||||||
'purchase_amount' => $purchaseAmount,
|
|
||||||
'amount_difference' => $this->normalizeAmount(
|
|
||||||
abs((float) $purchaseAmount - (float) $amount),
|
|
||||||
),
|
|
||||||
'match_reason' => $amountMatches
|
|
||||||
? ($dniMatches ? 'ambiguous_exact_match' : 'exact_amount_near_dni')
|
|
||||||
: 'exact_dni_near_amount',
|
|
||||||
'confidence' => $amountMatches
|
|
||||||
? ($dniMatches ? 'exact' : 'medium')
|
|
||||||
: 'high',
|
|
||||||
];
|
|
||||||
})
|
|
||||||
->all(),
|
|
||||||
);
|
|
||||||
|
|
||||||
return $payment->load('candidates');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,12 +145,6 @@ class Purchase extends Model
|
|||||||
return $this->hasMany(TelepagosPayment::class, 'compra_id');
|
return $this->hasMany(TelepagosPayment::class, 'compra_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return HasMany<TelepagosPaymentCandidate, $this> */
|
|
||||||
public function telepagosPaymentCandidates(): HasMany
|
|
||||||
{
|
|
||||||
return $this->hasMany(TelepagosPaymentCandidate::class, 'compra_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTotalAmount(): float
|
public function getTotalAmount(): float
|
||||||
{
|
{
|
||||||
if ($this->total !== null) {
|
if ($this->total !== null) {
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
||||||
|
|
||||||
#[Fillable([
|
#[Fillable([
|
||||||
'compra_id',
|
'compra_id',
|
||||||
|
'matched_purchase_ids',
|
||||||
'cuit_buyer',
|
'cuit_buyer',
|
||||||
'cvu_buyer',
|
'cvu_buyer',
|
||||||
'amount',
|
'amount',
|
||||||
@@ -30,6 +30,7 @@ class TelepagosPayment extends Model
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'compra_id' => 'integer',
|
'compra_id' => 'integer',
|
||||||
|
'matched_purchase_ids' => 'array',
|
||||||
'amount' => 'decimal:2',
|
'amount' => 'decimal:2',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -41,10 +42,4 @@ class TelepagosPayment extends Model
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(Purchase::class, 'compra_id');
|
return $this->belongsTo(Purchase::class, 'compra_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return HasMany<TelepagosPaymentCandidate, $this> */
|
|
||||||
public function candidates(): HasMany
|
|
||||||
{
|
|
||||||
return $this->hasMany(TelepagosPaymentCandidate::class, 'telepagos_payment_id');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Purchase\Models;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
||||||
|
|
||||||
#[Fillable([
|
|
||||||
'telepagos_payment_id',
|
|
||||||
'compra_id',
|
|
||||||
'dni_matches',
|
|
||||||
'dni_distance',
|
|
||||||
'payment_dni',
|
|
||||||
'purchase_dni',
|
|
||||||
'amount_matches',
|
|
||||||
'payment_amount',
|
|
||||||
'purchase_amount',
|
|
||||||
'amount_difference',
|
|
||||||
'match_reason',
|
|
||||||
'confidence',
|
|
||||||
])]
|
|
||||||
class TelepagosPaymentCandidate extends Model
|
|
||||||
{
|
|
||||||
protected $table = 'telepagos_payment_candidates';
|
|
||||||
|
|
||||||
protected function casts(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'telepagos_payment_id' => 'integer',
|
|
||||||
'compra_id' => 'integer',
|
|
||||||
'dni_matches' => 'boolean',
|
|
||||||
'dni_distance' => 'integer',
|
|
||||||
'amount_matches' => 'boolean',
|
|
||||||
'payment_amount' => 'decimal:2',
|
|
||||||
'purchase_amount' => 'decimal:2',
|
|
||||||
'amount_difference' => 'decimal:2',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function payment(): BelongsTo
|
|
||||||
{
|
|
||||||
return $this->belongsTo(TelepagosPayment::class, 'telepagos_payment_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function purchase(): BelongsTo
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Purchase::class, 'compra_id');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,6 @@ namespace App\Domains\Purchase\Resources;
|
|||||||
|
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
use App\Domains\Purchase\Models\PurchaseItem;
|
use App\Domains\Purchase\Models\PurchaseItem;
|
||||||
use App\Domains\Purchase\Models\TelepagosPaymentCandidate;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
@@ -26,7 +25,6 @@ class PurchaseResource extends JsonResource
|
|||||||
$ticketsCount = array_key_exists('tickets_count', $this->resource->getAttributes())
|
$ticketsCount = array_key_exists('tickets_count', $this->resource->getAttributes())
|
||||||
? (int) $this->resource->getAttribute('tickets_count')
|
? (int) $this->resource->getAttribute('tickets_count')
|
||||||
: null;
|
: null;
|
||||||
$paymentVerification = $this->resolvePaymentVerification();
|
|
||||||
|
|
||||||
$subtotal = $items->isNotEmpty()
|
$subtotal = $items->isNotEmpty()
|
||||||
? $items->reduce(
|
? $items->reduce(
|
||||||
@@ -66,7 +64,6 @@ class PurchaseResource extends JsonResource
|
|||||||
'items' => PurchaseItemResource::collection($items),
|
'items' => PurchaseItemResource::collection($items),
|
||||||
'tickets_count' => $this->when($ticketsCount !== null, $ticketsCount),
|
'tickets_count' => $this->when($ticketsCount !== null, $ticketsCount),
|
||||||
'has_generated_tickets' => $this->when($ticketsCount !== null, $ticketsCount > 0),
|
'has_generated_tickets' => $this->when($ticketsCount !== null, $ticketsCount > 0),
|
||||||
'payment_verification' => $this->when($paymentVerification !== null, $paymentVerification),
|
|
||||||
'subtotal' => $this->formatMoney($subtotal),
|
'subtotal' => $this->formatMoney($subtotal),
|
||||||
'total' => $this->formatMoney($total),
|
'total' => $this->formatMoney($total),
|
||||||
];
|
];
|
||||||
@@ -86,75 +83,4 @@ class PurchaseResource extends JsonResource
|
|||||||
{
|
{
|
||||||
return number_format((float) ($amount ?? 0), 2, '.', '');
|
return number_format((float) ($amount ?? 0), 2, '.', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return array<string, mixed>|null */
|
|
||||||
private function resolvePaymentVerification(): ?array
|
|
||||||
{
|
|
||||||
if (
|
|
||||||
$this->status !== Purchase::STATUS_IN_REVIEW
|
|
||||||
|| $this->payment_method !== 'transfer'
|
|
||||||
|| ! $this->resource->relationLoaded('telepagosPaymentCandidates')
|
|
||||||
) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$candidates = $this->resource
|
|
||||||
->getRelation('telepagosPaymentCandidates')
|
|
||||||
->sort(fn (TelepagosPaymentCandidate $left, TelepagosPaymentCandidate $right): int => $this->comparePaymentCandidates($left, $right))
|
|
||||||
->values();
|
|
||||||
/** @var TelepagosPaymentCandidate|null $primary */
|
|
||||||
$primary = $candidates->first();
|
|
||||||
|
|
||||||
return [
|
|
||||||
'status' => $primary === null ? 'pending' : 'candidate',
|
|
||||||
'candidate_count' => $candidates->count(),
|
|
||||||
'primary' => $primary === null ? null : [
|
|
||||||
'reason' => $primary->match_reason,
|
|
||||||
'dni_distance' => $primary->dni_distance,
|
|
||||||
'payment_amount' => $this->formatMoney($primary->payment_amount),
|
|
||||||
'purchase_amount' => $this->formatMoney($primary->purchase_amount),
|
|
||||||
'amount_difference' => $this->formatMoney($primary->amount_difference),
|
|
||||||
'confidence' => $primary->confidence,
|
|
||||||
'detected_at' => $primary->payment?->created_at?->toIso8601String(),
|
|
||||||
],
|
|
||||||
'reasons' => $candidates
|
|
||||||
->pluck('match_reason')
|
|
||||||
->unique()
|
|
||||||
->values()
|
|
||||||
->all(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
private function comparePaymentCandidates(
|
|
||||||
TelepagosPaymentCandidate $left,
|
|
||||||
TelepagosPaymentCandidate $right,
|
|
||||||
): int {
|
|
||||||
$reasonComparison = $this->paymentCandidateRank($left->match_reason)
|
|
||||||
<=> $this->paymentCandidateRank($right->match_reason);
|
|
||||||
|
|
||||||
if ($reasonComparison !== 0) {
|
|
||||||
return $reasonComparison;
|
|
||||||
}
|
|
||||||
|
|
||||||
$differenceComparison = (float) $left->amount_difference <=> (float) $right->amount_difference;
|
|
||||||
|
|
||||||
if ($differenceComparison !== 0) {
|
|
||||||
return $differenceComparison;
|
|
||||||
}
|
|
||||||
|
|
||||||
$leftTimestamp = $left->payment?->created_at?->getTimestamp() ?? 0;
|
|
||||||
$rightTimestamp = $right->payment?->created_at?->getTimestamp() ?? 0;
|
|
||||||
|
|
||||||
return ($rightTimestamp <=> $leftTimestamp) ?: ($right->id <=> $left->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function paymentCandidateRank(string $reason): int
|
|
||||||
{
|
|
||||||
return match ($reason) {
|
|
||||||
'ambiguous_exact_match' => 0,
|
|
||||||
'exact_dni_near_amount' => 1,
|
|
||||||
'exact_amount_near_dni' => 2,
|
|
||||||
default => 3,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,15 +8,6 @@ class PurchaseResponseLoader
|
|||||||
{
|
{
|
||||||
public function load(Purchase $purchase): Purchase
|
public function load(Purchase $purchase): Purchase
|
||||||
{
|
{
|
||||||
$relations = ['tenant', 'items.imageAttachment', 'stockReservation'];
|
return $purchase->load(['tenant', 'items.imageAttachment', 'stockReservation']);
|
||||||
|
|
||||||
if (
|
|
||||||
$purchase->status === Purchase::STATUS_IN_REVIEW
|
|
||||||
&& $purchase->payment_method === 'transfer'
|
|
||||||
) {
|
|
||||||
$relations[] = 'telepagosPaymentCandidates.payment';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $purchase->load($relations);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Purchase\Services;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Measures likely DNI typing errors using the optimal-string-alignment
|
|
||||||
* variant of the Damerau-Levenshtein distance.
|
|
||||||
*
|
|
||||||
* The returned value is the minimum number of single-character edits needed
|
|
||||||
* to transform one DNI into the other. Supported edits are insertion,
|
|
||||||
* deletion, substitution and transposition of two adjacent digits.
|
|
||||||
*/
|
|
||||||
class DniDistanceService
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Calculate the edit distance between two normalized DNI strings.
|
|
||||||
*
|
|
||||||
* Each matrix cell [row][column] stores the minimum edits required to
|
|
||||||
* transform the first $row digits of $left into the first $column digits
|
|
||||||
* of $right. The bottom-right cell therefore contains the final distance.
|
|
||||||
*/
|
|
||||||
public function distance(string $left, string $right): int
|
|
||||||
{
|
|
||||||
$left = $this->normalize($left);
|
|
||||||
$right = $this->normalize($right);
|
|
||||||
$leftLength = strlen($left);
|
|
||||||
$rightLength = strlen($right);
|
|
||||||
$matrix = [];
|
|
||||||
|
|
||||||
// Transforming a prefix into an empty string requires deleting every digit.
|
|
||||||
for ($row = 0; $row <= $leftLength; $row++) {
|
|
||||||
$matrix[$row] = [$row];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Transforming an empty string into a prefix requires inserting every digit.
|
|
||||||
for ($column = 0; $column <= $rightLength; $column++) {
|
|
||||||
$matrix[0][$column] = $column;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ($row = 1; $row <= $leftLength; $row++) {
|
|
||||||
for ($column = 1; $column <= $rightLength; $column++) {
|
|
||||||
$substitutionCost = $left[$row - 1] === $right[$column - 1] ? 0 : 1;
|
|
||||||
$deletionDistance = $matrix[$row - 1][$column] + 1;
|
|
||||||
$insertionDistance = $matrix[$row][$column - 1] + 1;
|
|
||||||
$substitutionDistance = $matrix[$row - 1][$column - 1] + $substitutionCost;
|
|
||||||
|
|
||||||
// Keep the cheapest way to align the two prefixes at this position.
|
|
||||||
$matrix[$row][$column] = min(
|
|
||||||
$deletionDistance,
|
|
||||||
$insertionDistance,
|
|
||||||
$substitutionDistance,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Count two adjacent inverted digits as one edit instead of two substitutions.
|
|
||||||
if (
|
|
||||||
$row > 1
|
|
||||||
&& $column > 1
|
|
||||||
&& $left[$row - 1] === $right[$column - 2]
|
|
||||||
&& $left[$row - 2] === $right[$column - 1]
|
|
||||||
) {
|
|
||||||
$matrix[$row][$column] = min(
|
|
||||||
$matrix[$row][$column],
|
|
||||||
$matrix[$row - 2][$column - 2] + 1,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $matrix[$leftLength][$rightLength];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Keep only digits and left-pad seven-digit DNIs so comparisons preserve
|
|
||||||
* the leading zero that is present when the DNI is extracted from a CUIT.
|
|
||||||
*/
|
|
||||||
public function normalize(string $dni): string
|
|
||||||
{
|
|
||||||
$digits = preg_replace('/\D+/', '', $dni) ?? '';
|
|
||||||
|
|
||||||
return str_pad($digits, 8, '0', STR_PAD_LEFT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
22
app/Domains/Ticket/Controllers/AdminApp/TicketController.php
Normal file
22
app/Domains/Ticket/Controllers/AdminApp/TicketController.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Ticket\Controllers\AdminApp;
|
||||||
|
|
||||||
|
use App\Domains\Ticket\Requests\AdminAppTicketIndexRequest;
|
||||||
|
use App\Domains\Ticket\Resources\AdminApp\AdminAppTicketCollection;
|
||||||
|
use App\Domains\Ticket\Services\AdminAppTicketService;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
|
||||||
|
class TicketController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(private readonly AdminAppTicketService $ticketService) {}
|
||||||
|
|
||||||
|
public function index(AdminAppTicketIndexRequest $request): AdminAppTicketCollection
|
||||||
|
{
|
||||||
|
$tenant = $request->user()->tenant()->firstOrFail();
|
||||||
|
|
||||||
|
return new AdminAppTicketCollection(
|
||||||
|
$this->ticketService->search($tenant, $request->validated())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
23
app/Domains/Ticket/Requests/AdminAppTicketIndexRequest.php
Normal file
23
app/Domains/Ticket/Requests/AdminAppTicketIndexRequest.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Ticket\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class AdminAppTicketIndexRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array<string, list<string>> */
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'q' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||||
|
'page' => ['sometimes', 'integer', 'min:1'],
|
||||||
|
'per_page' => ['sometimes', 'integer', 'min:1', 'max:100'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Ticket\Resources\AdminApp;
|
||||||
|
|
||||||
|
use App\Domains\Ticket\Services\AdminAppTicketResult;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||||
|
|
||||||
|
class AdminAppTicketCollection extends ResourceCollection
|
||||||
|
{
|
||||||
|
/** @var class-string<AdminAppTicketResource> */
|
||||||
|
public $collects = AdminAppTicketResource::class;
|
||||||
|
|
||||||
|
private readonly int $scannedTickets;
|
||||||
|
|
||||||
|
private readonly int $totalTickets;
|
||||||
|
|
||||||
|
public function __construct(AdminAppTicketResult $result)
|
||||||
|
{
|
||||||
|
parent::__construct($result->tickets);
|
||||||
|
|
||||||
|
$this->scannedTickets = $result->scannedTickets;
|
||||||
|
$this->totalTickets = $result->totalTickets;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array{scanned_tickets: int, total_tickets: int} */
|
||||||
|
public function with(Request $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'scanned_tickets' => $this->scannedTickets,
|
||||||
|
'total_tickets' => $this->totalTickets,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Ticket\Resources\AdminApp;
|
||||||
|
|
||||||
|
use App\Domains\Catalog\Models\ItemAttribute;
|
||||||
|
use App\Domains\Purchase\Models\PurchaseItem;
|
||||||
|
use App\Domains\Ticket\Models\Ticket;
|
||||||
|
use App\Domains\Ticket\Resources\TicketResource;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
/** @mixin Ticket */
|
||||||
|
class AdminAppTicketResource extends TicketResource
|
||||||
|
{
|
||||||
|
/** @return array<string, mixed> */
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
$purchaseItem = $this->sourcePurchaseItem();
|
||||||
|
|
||||||
|
return [
|
||||||
|
...parent::toArray($request),
|
||||||
|
'source_purchase_id' => $this->source_purchase_id,
|
||||||
|
'order_number' => $this->source_purchase_id,
|
||||||
|
'product' => $purchaseItem?->item_nombre
|
||||||
|
?? $this->sourceCatalogItem?->nombre
|
||||||
|
?? $this->name,
|
||||||
|
'amount' => $purchaseItem?->precio_unitario,
|
||||||
|
'client' => $this->sourcePurchase?->nombre_apellido ?? $this->user?->nombre_apellido,
|
||||||
|
'date' => $this->sourcePurchase?->created_at,
|
||||||
|
'status' => $this->status,
|
||||||
|
'scanned_by' => $this->scannerUser?->nombre_apellido,
|
||||||
|
'variant_properties' => $this->variantProperties(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sourcePurchaseItem(): ?PurchaseItem
|
||||||
|
{
|
||||||
|
return $this->sourcePurchase?->items->first(function (PurchaseItem $item): bool {
|
||||||
|
if ($this->source_variant_id !== null) {
|
||||||
|
return $item->source_variant_id === $this->source_variant_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $item->source_catalog_item_id === $this->source_catalog_item_id
|
||||||
|
&& $item->source_variant_id === null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array{
|
||||||
|
* code: string,
|
||||||
|
* label: string,
|
||||||
|
* values: list<array{value: string, label: string}>
|
||||||
|
* }>
|
||||||
|
*/
|
||||||
|
private function variantProperties(): array
|
||||||
|
{
|
||||||
|
$variant = $this->sourceVariant;
|
||||||
|
|
||||||
|
if ($variant === null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemAttributes = $variant->definitions
|
||||||
|
->map(fn ($definition) => $definition->itemAttribute)
|
||||||
|
->filter()
|
||||||
|
->merge($variant->catalogItem?->itemAttributes ?? collect())
|
||||||
|
->unique('id')
|
||||||
|
->values();
|
||||||
|
|
||||||
|
return $variant->selectionOptions($itemAttributes)
|
||||||
|
->map(function (array $selection, string $attributeCode) use ($itemAttributes): array {
|
||||||
|
$itemAttribute = $itemAttributes->first(
|
||||||
|
fn (ItemAttribute $itemAttribute): bool => $itemAttribute->attribute?->codigo
|
||||||
|
=== $attributeCode,
|
||||||
|
);
|
||||||
|
$values = array_is_list($selection) ? $selection : [$selection];
|
||||||
|
|
||||||
|
return [
|
||||||
|
'code' => $attributeCode,
|
||||||
|
'label' => $itemAttribute?->attribute?->nombre
|
||||||
|
?? ($attributeCode === 'event_date' ? 'Fecha' : $attributeCode),
|
||||||
|
'values' => array_values($values),
|
||||||
|
];
|
||||||
|
})
|
||||||
|
->values()
|
||||||
|
->all();
|
||||||
|
}
|
||||||
|
}
|
||||||
16
app/Domains/Ticket/Services/AdminAppTicketResult.php
Normal file
16
app/Domains/Ticket/Services/AdminAppTicketResult.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Ticket\Services;
|
||||||
|
|
||||||
|
use App\Domains\Ticket\Models\Ticket;
|
||||||
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
|
|
||||||
|
final readonly class AdminAppTicketResult
|
||||||
|
{
|
||||||
|
/** @param LengthAwarePaginator<Ticket> $tickets */
|
||||||
|
public function __construct(
|
||||||
|
public LengthAwarePaginator $tickets,
|
||||||
|
public int $scannedTickets,
|
||||||
|
public int $totalTickets,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
58
app/Domains/Ticket/Services/AdminAppTicketService.php
Normal file
58
app/Domains/Ticket/Services/AdminAppTicketService.php
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Ticket\Services;
|
||||||
|
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use App\Domains\Ticket\Models\Ticket;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
|
class AdminAppTicketService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param array{q?: string|null, page?: int, per_page?: int} $filters
|
||||||
|
*/
|
||||||
|
public function search(Tenant $tenant, array $filters = []): AdminAppTicketResult
|
||||||
|
{
|
||||||
|
$query = $this->baseQuery($tenant, $filters);
|
||||||
|
|
||||||
|
$tickets = (clone $query)
|
||||||
|
->with([
|
||||||
|
...TicketValidityResolver::RELATIONS,
|
||||||
|
...TicketPresentationResolver::RELATIONS,
|
||||||
|
'user',
|
||||||
|
'scannerUser',
|
||||||
|
'sourceCatalogItem.category',
|
||||||
|
'sourcePurchase.items',
|
||||||
|
])
|
||||||
|
->orderByDesc('id')
|
||||||
|
->paginateFromRequest()
|
||||||
|
->withQueryString();
|
||||||
|
|
||||||
|
return new AdminAppTicketResult(
|
||||||
|
tickets: $tickets,
|
||||||
|
scannedTickets: (clone $query)->whereNotNull('used_at')->count(),
|
||||||
|
totalTickets: $tickets->total(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array{q?: string|null, page?: int, per_page?: int} $filters
|
||||||
|
* @return Builder<Ticket>
|
||||||
|
*/
|
||||||
|
private function baseQuery(Tenant $tenant, array $filters): Builder
|
||||||
|
{
|
||||||
|
$search = trim((string) ($filters['q'] ?? ''));
|
||||||
|
|
||||||
|
return Ticket::query()
|
||||||
|
->where('tenant_code', $tenant->codigo)
|
||||||
|
->when($search !== '', function (Builder $query) use ($search): void {
|
||||||
|
$query->when(
|
||||||
|
ctype_digit($search),
|
||||||
|
fn (Builder $searchQuery): Builder => $searchQuery
|
||||||
|
->where('tickets.id', (int) $search),
|
||||||
|
fn (Builder $searchQuery): Builder => $searchQuery
|
||||||
|
->where('ticket', 'like', "%{$search}%"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,229 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Ticket\Services;
|
|
||||||
|
|
||||||
use App\Domains\Auth\Models\User;
|
|
||||||
use App\Domains\Authorization\Enums\RoleCode;
|
|
||||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
|
||||||
use App\Domains\Catalog\Models\Variant;
|
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use InvalidArgumentException;
|
|
||||||
|
|
||||||
class LoadTestTicketDatasetService
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private readonly TicketGeneratorService $ticketGenerator,
|
|
||||||
private readonly TicketValidityResolver $validityResolver,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array{
|
|
||||||
* run_id: string,
|
|
||||||
* tenant_code: string,
|
|
||||||
* catalog_item_id: int,
|
|
||||||
* variant_id: int|null,
|
|
||||||
* tickets: int,
|
|
||||||
* scanners: int,
|
|
||||||
* owners: int,
|
|
||||||
* rows: array<int, array{scanner_token: string, ticket_uuid: string, expected_status: int}>
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
public function prepare(
|
|
||||||
string $tenantCode,
|
|
||||||
int $ticketCount,
|
|
||||||
int $scannerCount,
|
|
||||||
int $ownerCount,
|
|
||||||
?int $catalogItemId = null,
|
|
||||||
?int $variantId = null,
|
|
||||||
?string $runId = null,
|
|
||||||
): array {
|
|
||||||
$this->validateInput($tenantCode, $ticketCount, $scannerCount, $ownerCount);
|
|
||||||
|
|
||||||
$tenant = Tenant::query()->where('codigo', $tenantCode)->firstOrFail();
|
|
||||||
$catalogItem = $this->resolveCatalogItem($tenant, $catalogItemId);
|
|
||||||
$variant = $this->resolveVariant($catalogItem, $variantId);
|
|
||||||
$runId ??= now()->format('Ymd-His').'-'.Str::lower(Str::random(6));
|
|
||||||
|
|
||||||
if (preg_match('/\A[a-zA-Z0-9][a-zA-Z0-9._-]{0,63}\z/', $runId) !== 1) {
|
|
||||||
throw new InvalidArgumentException('run_id contiene caracteres inválidos o es demasiado largo.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($variant !== null && ! $this->validityResolver->resolveVariant($variant)->isValid()) {
|
|
||||||
throw new InvalidArgumentException(
|
|
||||||
'La variante seleccionada no tiene una vigencia activa y resoluble.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$scanners = $this->scanners($tenant, $catalogItem, $scannerCount);
|
|
||||||
$owners = $this->owners($tenant, $ownerCount);
|
|
||||||
$tokens = $scanners->map(function (User $scanner): string {
|
|
||||||
$scanner->tokens()->where('name', 'load-test-scanner')->delete();
|
|
||||||
|
|
||||||
return $scanner->createToken(
|
|
||||||
'load-test-scanner',
|
|
||||||
['scanner'],
|
|
||||||
now()->addMinutes((int) config('sanctum.expiration', 720)),
|
|
||||||
)->plainTextToken;
|
|
||||||
})->values();
|
|
||||||
|
|
||||||
$rows = [];
|
|
||||||
$remaining = $ticketCount;
|
|
||||||
$ownerIndex = 0;
|
|
||||||
$scannerIndex = 0;
|
|
||||||
$batchSize = min(500, max(1, (int) ceil($ticketCount / $ownerCount)));
|
|
||||||
|
|
||||||
while ($remaining > 0) {
|
|
||||||
$quantity = min($batchSize, $remaining);
|
|
||||||
$owner = $owners[$ownerIndex % $owners->count()];
|
|
||||||
$tickets = $this->ticketGenerator->generate(
|
|
||||||
$catalogItem,
|
|
||||||
$owner,
|
|
||||||
$quantity,
|
|
||||||
$variant?->getKey(),
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($tickets as $ticket) {
|
|
||||||
if (! $ticket->is_valid) {
|
|
||||||
throw new InvalidArgumentException(
|
|
||||||
'La configuración seleccionada genera tickets que no están vigentes.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$rows[] = [
|
|
||||||
'scanner_token' => $tokens[$scannerIndex % $tokens->count()],
|
|
||||||
'ticket_uuid' => $ticket->ticket,
|
|
||||||
'expected_status' => 200,
|
|
||||||
];
|
|
||||||
$scannerIndex++;
|
|
||||||
}
|
|
||||||
|
|
||||||
$remaining -= $quantity;
|
|
||||||
$ownerIndex++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'run_id' => $runId,
|
|
||||||
'tenant_code' => $tenant->codigo,
|
|
||||||
'catalog_item_id' => $catalogItem->getKey(),
|
|
||||||
'variant_id' => $variant?->getKey(),
|
|
||||||
'tickets' => count($rows),
|
|
||||||
'scanners' => $scanners->count(),
|
|
||||||
'owners' => $owners->count(),
|
|
||||||
'rows' => $rows,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
private function validateInput(
|
|
||||||
string $tenantCode,
|
|
||||||
int $ticketCount,
|
|
||||||
int $scannerCount,
|
|
||||||
int $ownerCount,
|
|
||||||
): void {
|
|
||||||
foreach ([
|
|
||||||
'tickets' => [$ticketCount, 100_000],
|
|
||||||
'scanners' => [$scannerCount, 10_000],
|
|
||||||
'owners' => [$ownerCount, 100_000],
|
|
||||||
] as $name => [$value, $maximum]) {
|
|
||||||
if ($value < 1 || $value > $maximum) {
|
|
||||||
throw new InvalidArgumentException("{$name} debe estar entre 1 y {$maximum}.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($scannerCount > $ticketCount || $ownerCount > $ticketCount) {
|
|
||||||
throw new InvalidArgumentException(
|
|
||||||
'La cantidad de scanners y propietarios no puede superar la cantidad de tickets.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function resolveCatalogItem(Tenant $tenant, ?int $catalogItemId): CatalogItem
|
|
||||||
{
|
|
||||||
$query = $tenant->catalogItems()
|
|
||||||
->where('has_tickets', true)
|
|
||||||
->where('type', CatalogItemType::Standard->value);
|
|
||||||
|
|
||||||
if ($catalogItemId !== null) {
|
|
||||||
$query->whereKey($catalogItemId);
|
|
||||||
}
|
|
||||||
|
|
||||||
$catalogItem = $query->first();
|
|
||||||
|
|
||||||
if ($catalogItem === null) {
|
|
||||||
throw new InvalidArgumentException(
|
|
||||||
'No se encontró un producto estándar con tickets habilitados para el tenant.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($tenant->requiresScannerCategoryValidation() && $catalogItem->category_id === null) {
|
|
||||||
throw new InvalidArgumentException(
|
|
||||||
'El producto debe tener una categoría para autorizar a los scanners.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $catalogItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function resolveVariant(CatalogItem $catalogItem, ?int $variantId): ?Variant
|
|
||||||
{
|
|
||||||
if ($variantId === null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$variant = $catalogItem->variants()->whereKey($variantId)->first();
|
|
||||||
|
|
||||||
if ($variant === null) {
|
|
||||||
throw new InvalidArgumentException('La variante no pertenece al producto seleccionado.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $variant;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return Collection<int, User> */
|
|
||||||
private function scanners(Tenant $tenant, CatalogItem $catalogItem, int $count): Collection
|
|
||||||
{
|
|
||||||
return Collection::times($count, function (int $number) use ($tenant, $catalogItem): User {
|
|
||||||
$scanner = User::query()->updateOrCreate(
|
|
||||||
['email' => $this->email($tenant, 'scanner', $number)],
|
|
||||||
[
|
|
||||||
'nombre_apellido' => "Load test scanner {$number}",
|
|
||||||
'password' => Str::password(32),
|
|
||||||
'rol_codigo' => RoleCode::Scanner->value,
|
|
||||||
'tenant_codigo' => $tenant->codigo,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
if ($tenant->requiresScannerCategoryValidation()) {
|
|
||||||
$scanner->scanCategories()->syncWithoutDetaching([$catalogItem->category_id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $scanner;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return Collection<int, User> */
|
|
||||||
private function owners(Tenant $tenant, int $count): Collection
|
|
||||||
{
|
|
||||||
return Collection::times($count, function (int $number) use ($tenant): User {
|
|
||||||
$owner = User::query()->updateOrCreate(
|
|
||||||
['email' => $this->email($tenant, 'owner', $number)],
|
|
||||||
[
|
|
||||||
'nombre_apellido' => "Load test owner {$number}",
|
|
||||||
'password' => Str::password(32),
|
|
||||||
'rol_codigo' => RoleCode::User->value,
|
|
||||||
'tenant_codigo' => $tenant->codigo,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
return $owner;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private function email(Tenant $tenant, string $kind, int $number): string
|
|
||||||
{
|
|
||||||
$tenantSlug = Str::lower(preg_replace('/[^a-z0-9]+/i', '-', $tenant->codigo));
|
|
||||||
|
|
||||||
return "loadtest+{$tenantSlug}.{$kind}.{$number}@shopit.test";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -23,33 +23,6 @@ vigente, vencido o usado, y resuelve sus fechas efectivas de inicio y fin sin pe
|
|||||||
3. `TicketGeneratorService` crea los tickets requeridos según ítems, cantidades y vigencia.
|
3. `TicketGeneratorService` crea los tickets requeridos según ítems, cantidades y vigencia.
|
||||||
4. `Notification` envía la confirmación de compra después de la generación y adjunta los tickets cuando existen.
|
4. `Notification` envía la confirmación de compra después de la generación y adjunta los tickets cuando existen.
|
||||||
|
|
||||||
## Datos descartables para pruebas de carga
|
|
||||||
|
|
||||||
En ambientes `local`, `testing`, `staging`, `homo` u `homologation`, el comando siguiente crea tickets
|
|
||||||
válidos, identidades scanner con tokens Sanctum y un dataset JSON importable por Postman:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
php artisan load-test:tickets:prepare loadtest-evento \
|
|
||||||
--tickets=40000 \
|
|
||||||
--scanners=100 \
|
|
||||||
--owners=1000 \
|
|
||||||
--catalog-item=123 \
|
|
||||||
--run=evento-001
|
|
||||||
```
|
|
||||||
|
|
||||||
El tenant debe existir y se recomienda que sea exclusivo para carga. Si no se indica `--catalog-item`,
|
|
||||||
se usa el primer producto estándar del tenant con tickets habilitados. `--variant`
|
|
||||||
es opcional; al indicarlo, su configuración de vigencia debe estar activa y ser resoluble. Sin variante,
|
|
||||||
los tickets tienen vigencia irrestricta.
|
|
||||||
|
|
||||||
El archivo se escribe por defecto en `storage/app/private/load-tests/` y contiene tokens secretos, por
|
|
||||||
lo que no debe versionarse. Para limpiar el tenant después de la ejecución:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
php artisan tenants:reset-transactions loadtest-evento --dry-run
|
|
||||||
php artisan tenants:reset-transactions loadtest-evento
|
|
||||||
```
|
|
||||||
|
|
||||||
## Endpoints
|
## Endpoints
|
||||||
|
|
||||||
Bajo `/tenants/{tenant:codigo}`, protegidos por `auth:sanctum`:
|
Bajo `/tenants/{tenant:codigo}`, protegidos por `auth:sanctum`:
|
||||||
@@ -57,6 +30,12 @@ Bajo `/tenants/{tenant:codigo}`, protegidos por `auth:sanctum`:
|
|||||||
- `GET /tickets`.
|
- `GET /tickets`.
|
||||||
- `POST /tickets/pdf`.
|
- `POST /tickets/pdf`.
|
||||||
|
|
||||||
|
Bajo `/v1/adminapp/tenant`, protegido por `auth:sanctum`, `adminapp.tenant` y el menú
|
||||||
|
`adminapp.tickets`:
|
||||||
|
|
||||||
|
- `GET /tickets`, paginado y con búsqueda opcional mediante `q`. La respuesta incluye
|
||||||
|
`scanned_tickets` y `total_tickets` para el tenant autenticado.
|
||||||
|
|
||||||
`TicketPdfService` genera la descarga y `TicketResource`/`ValidityTimeResource` definen las respuestas.
|
`TicketPdfService` genera la descarga y `TicketResource`/`ValidityTimeResource` definen las respuestas.
|
||||||
|
|
||||||
## Dependencias y reglas
|
## Dependencias y reglas
|
||||||
|
|||||||
12
app/Domains/Ticket/routes/adminapp.php
Normal file
12
app/Domains/Ticket/routes/adminapp.php
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Domains\Ticket\Controllers\AdminApp\TicketController;
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
|
Route::prefix('v1/adminapp/tenant')
|
||||||
|
->middleware(['auth:sanctum', 'adminapp.tenant'])
|
||||||
|
->group(function (): void {
|
||||||
|
Route::get('tickets', [TicketController::class, 'index'])
|
||||||
|
->middleware('tenant.menu:adminapp.tickets')
|
||||||
|
->name('adminapp.tickets.index');
|
||||||
|
});
|
||||||
@@ -11,3 +11,4 @@ Route::prefix('tenants/{tenant:codigo}')
|
|||||||
});
|
});
|
||||||
|
|
||||||
require __DIR__.'/scanner.php';
|
require __DIR__.'/scanner.php';
|
||||||
|
require __DIR__.'/adminapp.php';
|
||||||
|
|||||||
@@ -2,15 +2,4 @@
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'checkout_expiration_minutes' => (int) env('PURCHASE_CHECKOUT_EXPIRATION_MINUTES', 30),
|
'checkout_expiration_minutes' => (int) env('PURCHASE_CHECKOUT_EXPIRATION_MINUTES', 30),
|
||||||
|
|
||||||
'payment_expiration_minutes' => [
|
|
||||||
'qr' => (int) env('PURCHASE_QR_EXPIRATION_MINUTES', 15),
|
|
||||||
'telepagos' => (int) env('PURCHASE_TELEPAGOS_EXPIRATION_MINUTES', 30),
|
|
||||||
'transfer' => (int) env('PURCHASE_TRANSFER_EXPIRATION_MINUTES', 1440),
|
|
||||||
],
|
|
||||||
|
|
||||||
'transfer_candidate_amount_tolerance_percentage' => (float) env(
|
|
||||||
'PURCHASE_TRANSFER_CANDIDATE_AMOUNT_TOLERANCE_PERCENTAGE',
|
|
||||||
5,
|
|
||||||
),
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,141 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
Schema::create('telepagos_payment_candidates', function (Blueprint $table) {
|
|
||||||
$table->id();
|
|
||||||
$table->foreignId('telepagos_payment_id')
|
|
||||||
->constrained('telepagos_payments')
|
|
||||||
->cascadeOnDelete();
|
|
||||||
$table->foreignId('compra_id')->constrained('compras')->cascadeOnDelete();
|
|
||||||
$table->boolean('dni_matches');
|
|
||||||
$table->boolean('amount_matches');
|
|
||||||
$table->decimal('payment_amount', 10, 2);
|
|
||||||
$table->decimal('purchase_amount', 10, 2);
|
|
||||||
$table->decimal('amount_difference', 10, 2);
|
|
||||||
$table->string('match_reason');
|
|
||||||
$table->string('confidence');
|
|
||||||
$table->timestamps();
|
|
||||||
|
|
||||||
$table->unique(
|
|
||||||
['telepagos_payment_id', 'compra_id'],
|
|
||||||
'telepagos_payment_candidate_unique',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->migrateExistingCandidates();
|
|
||||||
|
|
||||||
Schema::table('telepagos_payments', function (Blueprint $table) {
|
|
||||||
$table->dropColumn('matched_purchase_ids');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('telepagos_payments', function (Blueprint $table) {
|
|
||||||
$table->json('matched_purchase_ids')->nullable()->after('compra_id');
|
|
||||||
});
|
|
||||||
|
|
||||||
DB::table('telepagos_payments')
|
|
||||||
->whereNull('compra_id')
|
|
||||||
->orderBy('id')
|
|
||||||
->each(function (object $payment): void {
|
|
||||||
$candidateIds = DB::table('telepagos_payment_candidates')
|
|
||||||
->where('telepagos_payment_id', $payment->id)
|
|
||||||
->pluck('compra_id')
|
|
||||||
->all();
|
|
||||||
|
|
||||||
if ($candidateIds !== []) {
|
|
||||||
DB::table('telepagos_payments')
|
|
||||||
->where('id', $payment->id)
|
|
||||||
->update(['matched_purchase_ids' => json_encode($candidateIds)]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Schema::dropIfExists('telepagos_payment_candidates');
|
|
||||||
}
|
|
||||||
|
|
||||||
private function migrateExistingCandidates(): void
|
|
||||||
{
|
|
||||||
DB::table('telepagos_payments')
|
|
||||||
->whereNull('compra_id')
|
|
||||||
->whereNotNull('matched_purchase_ids')
|
|
||||||
->orderBy('id')
|
|
||||||
->each(function (object $payment): void {
|
|
||||||
$candidateIds = json_decode((string) $payment->matched_purchase_ids, true);
|
|
||||||
|
|
||||||
if (! is_array($candidateIds)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$paymentAmount = number_format((float) $payment->amount, 2, '.', '');
|
|
||||||
$payerDni = $payment->cuit_buyer
|
|
||||||
? substr((string) $payment->cuit_buyer, 2, -1)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
foreach ($candidateIds as $candidateId) {
|
|
||||||
$purchase = DB::table('compras')->find($candidateId);
|
|
||||||
|
|
||||||
if ($purchase === null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$purchaseAmount = number_format((float) $purchase->total, 2, '.', '');
|
|
||||||
$dniMatches = $payerDni !== null && $purchase->transfer_payer_dni === $payerDni;
|
|
||||||
$amountMatches = $purchaseAmount === $paymentAmount;
|
|
||||||
|
|
||||||
DB::table('telepagos_payment_candidates')->insertOrIgnore([
|
|
||||||
'telepagos_payment_id' => $payment->id,
|
|
||||||
'compra_id' => $purchase->id,
|
|
||||||
'dni_matches' => $dniMatches,
|
|
||||||
'amount_matches' => $amountMatches,
|
|
||||||
'payment_amount' => $paymentAmount,
|
|
||||||
'purchase_amount' => $purchaseAmount,
|
|
||||||
'amount_difference' => number_format(
|
|
||||||
abs((float) $purchaseAmount - (float) $paymentAmount),
|
|
||||||
2,
|
|
||||||
'.',
|
|
||||||
'',
|
|
||||||
),
|
|
||||||
'match_reason' => $this->matchReason($dniMatches, $amountMatches),
|
|
||||||
'confidence' => $this->confidence($dniMatches, $amountMatches),
|
|
||||||
'created_at' => $payment->created_at,
|
|
||||||
'updated_at' => $payment->updated_at,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private function matchReason(bool $dniMatches, bool $amountMatches): string
|
|
||||||
{
|
|
||||||
if ($dniMatches && $amountMatches) {
|
|
||||||
return 'ambiguous_exact_match';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($dniMatches) {
|
|
||||||
return 'exact_dni_near_amount';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($amountMatches) {
|
|
||||||
return 'exact_amount_different_dni';
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'legacy_candidate';
|
|
||||||
}
|
|
||||||
|
|
||||||
private function confidence(bool $dniMatches, bool $amountMatches): string
|
|
||||||
{
|
|
||||||
if ($dniMatches && $amountMatches) {
|
|
||||||
return 'exact';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $dniMatches ? 'high' : 'medium';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use App\Domains\Purchase\Services\DniDistanceService;
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
Schema::table('telepagos_payment_candidates', function (Blueprint $table) {
|
|
||||||
$table->unsignedTinyInteger('dni_distance')->nullable()->after('dni_matches');
|
|
||||||
$table->string('payment_dni', 8)->nullable()->after('dni_distance');
|
|
||||||
$table->string('purchase_dni', 8)->nullable()->after('payment_dni');
|
|
||||||
});
|
|
||||||
|
|
||||||
$dniDistance = new DniDistanceService;
|
|
||||||
|
|
||||||
DB::table('telepagos_payment_candidates as candidate')
|
|
||||||
->join('telepagos_payments as payment', 'payment.id', '=', 'candidate.telepagos_payment_id')
|
|
||||||
->join('compras as purchase', 'purchase.id', '=', 'candidate.compra_id')
|
|
||||||
->select([
|
|
||||||
'candidate.id',
|
|
||||||
'candidate.match_reason',
|
|
||||||
'payment.cuit_buyer',
|
|
||||||
'purchase.transfer_payer_dni',
|
|
||||||
])
|
|
||||||
->orderBy('candidate.id')
|
|
||||||
->each(function (object $candidate) use ($dniDistance): void {
|
|
||||||
if ($candidate->cuit_buyer === null || $candidate->transfer_payer_dni === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$payerDni = substr((string) $candidate->cuit_buyer, 2, -1);
|
|
||||||
$distance = $dniDistance->distance($payerDni, (string) $candidate->transfer_payer_dni);
|
|
||||||
|
|
||||||
if ($candidate->match_reason === 'exact_amount_different_dni' && $distance > 2) {
|
|
||||||
DB::table('telepagos_payment_candidates')->where('id', $candidate->id)->delete();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DB::table('telepagos_payment_candidates')
|
|
||||||
->where('id', $candidate->id)
|
|
||||||
->update([
|
|
||||||
'dni_distance' => $distance,
|
|
||||||
'payment_dni' => $payerDni,
|
|
||||||
'purchase_dni' => $candidate->transfer_payer_dni,
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('telepagos_payment_candidates', function (Blueprint $table) {
|
|
||||||
$table->dropColumn(['dni_distance', 'payment_dni', 'purchase_dni']);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
DB::table('telepagos_payment_candidates')
|
|
||||||
->where('match_reason', 'exact_amount_different_dni')
|
|
||||||
->update(['match_reason' => 'exact_amount_near_dni']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
DB::table('telepagos_payment_candidates')
|
|
||||||
->where('match_reason', 'exact_amount_near_dni')
|
|
||||||
->update(['match_reason' => 'exact_amount_different_dni']);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
private const MENU_CODE = 'adminapp.tickets';
|
||||||
|
|
||||||
|
private const TENANT_CODE = 'fiesta_futbol_infantil';
|
||||||
|
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
if (! DB::table('menues')->where('code', 'main.adminapp')->exists()) {
|
||||||
|
// Reference data is added by seeders on fresh installations.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$now = now();
|
||||||
|
|
||||||
|
DB::transaction(function () use ($now): void {
|
||||||
|
DB::table('menues')->updateOrInsert(
|
||||||
|
['code' => self::MENU_CODE],
|
||||||
|
[
|
||||||
|
'label' => 'Tickets',
|
||||||
|
'parent_menu_code' => 'main.adminapp',
|
||||||
|
'content_type' => 'dynamic',
|
||||||
|
'static_content_schema' => null,
|
||||||
|
'route' => '/admin/tickets',
|
||||||
|
'created_at' => $now,
|
||||||
|
'updated_at' => $now,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
DB::table('tenants_menues')
|
||||||
|
->where('menu_code', self::MENU_CODE)
|
||||||
|
->where('tenant_code', '!=', self::TENANT_CODE)
|
||||||
|
->delete();
|
||||||
|
|
||||||
|
if (DB::table('tenants')->where('codigo', self::TENANT_CODE)->exists()) {
|
||||||
|
DB::table('tenants_menues')->updateOrInsert(
|
||||||
|
[
|
||||||
|
'tenant_code' => self::TENANT_CODE,
|
||||||
|
'menu_code' => self::MENU_CODE,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'static_content' => null,
|
||||||
|
'created_at' => $now,
|
||||||
|
'updated_at' => $now,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::table('roles')
|
||||||
|
->whereIn('codigo', ['admin', 'adminapp'])
|
||||||
|
->pluck('codigo')
|
||||||
|
->each(function (string $roleCode): void {
|
||||||
|
DB::table('roles_menues')->updateOrInsert([
|
||||||
|
'rol_codigo' => $roleCode,
|
||||||
|
'menu_codigo' => self::MENU_CODE,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
DB::transaction(function (): void {
|
||||||
|
DB::table('tenants_menues')
|
||||||
|
->where('menu_code', self::MENU_CODE)
|
||||||
|
->delete();
|
||||||
|
|
||||||
|
DB::table('roles_menues')
|
||||||
|
->where('menu_codigo', self::MENU_CODE)
|
||||||
|
->delete();
|
||||||
|
|
||||||
|
DB::table('menues')
|
||||||
|
->where('code', self::MENU_CODE)
|
||||||
|
->delete();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -78,6 +78,12 @@ class MenuSeeder extends Seeder
|
|||||||
'parent_menu_code' => 'main.adminapp',
|
'parent_menu_code' => 'main.adminapp',
|
||||||
'route' => '/admin/staff',
|
'route' => '/admin/staff',
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'code' => 'adminapp.tickets',
|
||||||
|
'label' => 'Tickets',
|
||||||
|
'parent_menu_code' => 'main.adminapp',
|
||||||
|
'route' => '/admin/tickets',
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'code' => 'adminapp.fiesta-futbol-infantil.entradas',
|
'code' => 'adminapp.fiesta-futbol-infantil.entradas',
|
||||||
'label' => 'Entradas',
|
'label' => 'Entradas',
|
||||||
@@ -270,6 +276,7 @@ class MenuSeeder extends Seeder
|
|||||||
'fiesta_futbol_infantil',
|
'fiesta_futbol_infantil',
|
||||||
];
|
];
|
||||||
$fiestaCategoryMenuCodes = [
|
$fiestaCategoryMenuCodes = [
|
||||||
|
'adminapp.tickets',
|
||||||
'adminapp.fiesta-futbol-infantil.entradas',
|
'adminapp.fiesta-futbol-infantil.entradas',
|
||||||
'adminapp.fiesta-futbol-infantil.alojamientos',
|
'adminapp.fiesta-futbol-infantil.alojamientos',
|
||||||
'adminapp.fiesta-futbol-infantil.merchandising',
|
'adminapp.fiesta-futbol-infantil.merchandising',
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
</include>
|
</include>
|
||||||
</source>
|
</source>
|
||||||
<php>
|
<php>
|
||||||
<env name="APP_ENV" value="testing"/>
|
<env name="APP_ENV" value="testing" force="true"/>
|
||||||
<env name="DB_DATABASE" value="shopit_test" force="true"/>
|
<env name="DB_DATABASE" value="shopit_test" force="true"/>
|
||||||
<env name="APP_MAINTENANCE_DRIVER" value="file"/>
|
<env name="APP_MAINTENANCE_DRIVER" value="file"/>
|
||||||
<env name="APP_CONFIG_CACHE" value="bootstrap/cache/phpunit-config.php"/>
|
<env name="APP_CONFIG_CACHE" value="bootstrap/cache/phpunit-config.php"/>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ declare(strict_types=1);
|
|||||||
$root = dirname(__DIR__);
|
$root = dirname(__DIR__);
|
||||||
chdir($root);
|
chdir($root);
|
||||||
|
|
||||||
$command = escapeshellarg(PHP_BINARY).' artisan route:list --json';
|
$command = escapeshellarg(PHP_BINARY).' artisan route:list --path=api --json';
|
||||||
$routeJson = shell_exec($command);
|
$routeJson = shell_exec($command);
|
||||||
|
|
||||||
if (! is_string($routeJson) || trim($routeJson) === '') {
|
if (! is_string($routeJson) || trim($routeJson) === '') {
|
||||||
@@ -20,11 +20,6 @@ if (! is_string($routeJson) || trim($routeJson) === '') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$routes = json_decode($routeJson, true, flags: JSON_THROW_ON_ERROR);
|
$routes = json_decode($routeJson, true, flags: JSON_THROW_ON_ERROR);
|
||||||
$routes = array_values(array_filter(
|
|
||||||
$routes,
|
|
||||||
fn (array $route): bool => str_starts_with($route['uri'], 'api/')
|
|
||||||
|| $route['uri'] === 'auth/google/redirect',
|
|
||||||
));
|
|
||||||
|
|
||||||
const TINY_PNG = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
|
const TINY_PNG = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
|
||||||
|
|
||||||
@@ -182,10 +177,6 @@ function bodyFor(string $method, string $uri): ?array
|
|||||||
function queryFor(string $uri): array
|
function queryFor(string $uri): array
|
||||||
{
|
{
|
||||||
return match ($uri) {
|
return match ($uri) {
|
||||||
'auth/google/redirect' => [
|
|
||||||
['key' => 'tenant', 'value' => '{{tenant_code}}'],
|
|
||||||
['key' => 'return_url', 'value' => '{{storefront_url}}'],
|
|
||||||
],
|
|
||||||
'api/tenants/bootstrap' => [['key' => 'dominio', 'value' => '{{tenant_domain}}'], ['key' => 'path', 'value' => '/']],
|
'api/tenants/bootstrap' => [['key' => 'dominio', 'value' => '{{tenant_domain}}'], ['key' => 'path', 'value' => '/']],
|
||||||
'api/v1/adminapp/bootstrap/{dominio}', 'api/v1/scanner/bootstrap/{dominio}' => [['key' => 'path', 'value' => '/']],
|
'api/v1/adminapp/bootstrap/{dominio}', 'api/v1/scanner/bootstrap/{dominio}' => [['key' => 'path', 'value' => '/']],
|
||||||
'api/tenants/{tenant:codigo}/catalog-items' => [['key' => 'q', 'value' => 'demo'], ['key' => 'page', 'value' => '1']],
|
'api/tenants/{tenant:codigo}/catalog-items' => [['key' => 'q', 'value' => 'demo'], ['key' => 'page', 'value' => '1']],
|
||||||
@@ -424,7 +415,6 @@ foreach ($tree as $section => $folders) {
|
|||||||
|
|
||||||
$variables = [
|
$variables = [
|
||||||
'base_url' => 'http://localhost:8000',
|
'base_url' => 'http://localhost:8000',
|
||||||
'storefront_url' => 'http://localhost:4200',
|
|
||||||
'token' => '', 'admin_token' => '', 'scanner_token' => '',
|
'token' => '', 'admin_token' => '', 'scanner_token' => '',
|
||||||
'user_email' => 'usuario@example.com', 'user_password' => 'Password!123',
|
'user_email' => 'usuario@example.com', 'user_password' => 'Password!123',
|
||||||
'admin_email' => 'admin@example.com', 'admin_password' => 'Password!123',
|
'admin_email' => 'admin@example.com', 'admin_password' => 'Password!123',
|
||||||
|
|||||||
@@ -3,11 +3,9 @@
|
|||||||
use App\Domains\Auth\Services\AdminCredentialVerifier;
|
use App\Domains\Auth\Services\AdminCredentialVerifier;
|
||||||
use App\Domains\Catalog\Services\ExpireStockReservationsService;
|
use App\Domains\Catalog\Services\ExpireStockReservationsService;
|
||||||
use App\Domains\Purchase\Services\TenantTransactionResetService;
|
use App\Domains\Purchase\Services\TenantTransactionResetService;
|
||||||
use App\Domains\Ticket\Services\LoadTestTicketDatasetService;
|
|
||||||
use Illuminate\Foundation\Inspiring;
|
use Illuminate\Foundation\Inspiring;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
use Illuminate\Support\Facades\Schedule;
|
use Illuminate\Support\Facades\Schedule;
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
|
|
||||||
Artisan::command('inspire', function () {
|
Artisan::command('inspire', function () {
|
||||||
$this->comment(Inspiring::quote());
|
$this->comment(Inspiring::quote());
|
||||||
@@ -26,79 +24,6 @@ Schedule::command('reservations:expire')
|
|||||||
->everyMinute()
|
->everyMinute()
|
||||||
->withoutOverlapping();
|
->withoutOverlapping();
|
||||||
|
|
||||||
Artisan::command(
|
|
||||||
'load-test:tickets:prepare
|
|
||||||
{tenant : Código del tenant que recibirá los datos de carga}
|
|
||||||
{--tickets=1000 : Cantidad de tickets válidos}
|
|
||||||
{--scanners=10 : Cantidad de identidades scanner}
|
|
||||||
{--owners=100 : Cantidad de propietarios de tickets}
|
|
||||||
{--catalog-item= : Producto estándar con tickets habilitados}
|
|
||||||
{--variant= : Variante opcional que define la vigencia}
|
|
||||||
{--run= : Identificador opcional de la ejecución}
|
|
||||||
{--output= : Ruta relativa dentro del disco local}',
|
|
||||||
function (LoadTestTicketDatasetService $datasetService): int {
|
|
||||||
if (! app()->environment(['local', 'testing', 'staging', 'homo', 'homologation'])) {
|
|
||||||
$this->error('Este comando sólo puede ejecutarse en local u homologación.');
|
|
||||||
|
|
||||||
return self::FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
$requestedOutput = filled($this->option('output'))
|
|
||||||
? ltrim((string) $this->option('output'), '/\\')
|
|
||||||
: null;
|
|
||||||
|
|
||||||
if ($requestedOutput !== null
|
|
||||||
&& ($requestedOutput === '' || str_contains(str_replace('\\', '/', $requestedOutput), '../'))) {
|
|
||||||
$this->error('La ruta de salida debe permanecer dentro del disco local.');
|
|
||||||
|
|
||||||
return self::FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$dataset = $datasetService->prepare(
|
|
||||||
(string) $this->argument('tenant'),
|
|
||||||
(int) $this->option('tickets'),
|
|
||||||
(int) $this->option('scanners'),
|
|
||||||
(int) $this->option('owners'),
|
|
||||||
filled($this->option('catalog-item')) ? (int) $this->option('catalog-item') : null,
|
|
||||||
filled($this->option('variant')) ? (int) $this->option('variant') : null,
|
|
||||||
filled($this->option('run')) ? (string) $this->option('run') : null,
|
|
||||||
);
|
|
||||||
} catch (Throwable $exception) {
|
|
||||||
$this->error($exception->getMessage());
|
|
||||||
|
|
||||||
return self::FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
$relativePath = $requestedOutput !== null
|
|
||||||
? $requestedOutput
|
|
||||||
: "load-tests/{$dataset['run_id']}.postman.json";
|
|
||||||
$payload = json_encode($dataset['rows'], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
|
||||||
|
|
||||||
if (! is_string($payload) || ! Storage::disk('local')->put($relativePath, $payload.PHP_EOL)) {
|
|
||||||
$this->error('No se pudo escribir el dataset.');
|
|
||||||
|
|
||||||
return self::FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->info('Dataset de carga generado.');
|
|
||||||
$this->table(['Dato', 'Valor'], [
|
|
||||||
['run_id', $dataset['run_id']],
|
|
||||||
['tenant', $dataset['tenant_code']],
|
|
||||||
['catalog_item_id', $dataset['catalog_item_id']],
|
|
||||||
['variant_id', $dataset['variant_id'] ?? 'sin variante (vigencia irrestricta)'],
|
|
||||||
['tickets', $dataset['tickets']],
|
|
||||||
['scanners', $dataset['scanners']],
|
|
||||||
['owners', $dataset['owners']],
|
|
||||||
['archivo', Storage::disk('local')->path($relativePath)],
|
|
||||||
]);
|
|
||||||
$this->warn('El archivo contiene tokens secretos. No lo subas al repositorio.');
|
|
||||||
$this->comment("Limpieza: php artisan tenants:reset-transactions {$dataset['tenant_code']}");
|
|
||||||
|
|
||||||
return self::SUCCESS;
|
|
||||||
},
|
|
||||||
)->purpose('Prepare disposable scanner tickets and a Postman performance dataset');
|
|
||||||
|
|
||||||
Artisan::command(
|
Artisan::command(
|
||||||
'tenants:reset-transactions
|
'tenants:reset-transactions
|
||||||
{tenant : Código del tenant que se limpiará}
|
{tenant : Código del tenant que se limpiará}
|
||||||
|
|||||||
155
tests/Feature/Forms/AdminAppTicketFormControllerTest.php
Normal file
155
tests/Feature/Forms/AdminAppTicketFormControllerTest.php
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Forms;
|
||||||
|
|
||||||
|
use App\Domains\Attachable\Enums\AttachmentType;
|
||||||
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
|
use App\Domains\Auth\Models\User;
|
||||||
|
use App\Domains\Authorization\Enums\RoleCode;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use Database\Seeders\AttributeSeeder;
|
||||||
|
use Database\Seeders\AuthorizationSeeder;
|
||||||
|
use Database\Seeders\FiestaFutbolInfantilProductSeeder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Laravel\Sanctum\Sanctum;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AdminAppTicketFormControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->seed(AuthorizationSeeder::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_authentication_is_required(): void
|
||||||
|
{
|
||||||
|
$this->getJson('/api/v1/adminapp/forms/fiesta-futbol-infantil/ticket')
|
||||||
|
->assertUnauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_returns_nested_ticket_options_using_the_frontend_presentation_mapping(): void
|
||||||
|
{
|
||||||
|
$headerLogo = $this->createAttachment('header.png');
|
||||||
|
$footerLogo = $this->createAttachment('footer.png');
|
||||||
|
$tenant = Tenant::query()->create([
|
||||||
|
'codigo' => 'fiesta_futbol_infantil',
|
||||||
|
'nombre' => 'Fiesta Fútbol Infantil',
|
||||||
|
'dominio' => 'fiesta-futbol-infantil.test',
|
||||||
|
'primary_color' => '#00973F',
|
||||||
|
'secondary_color' => '#A0A0A0',
|
||||||
|
'danger_color' => '#FF8888',
|
||||||
|
'success_color' => '#198754',
|
||||||
|
'header_bg_color' => '#ffffff',
|
||||||
|
'footer_bg_color' => '#015327',
|
||||||
|
'header_logo_id' => $headerLogo->id,
|
||||||
|
'footer_logo_id' => $footerLogo->id,
|
||||||
|
]);
|
||||||
|
$this->seed([AttributeSeeder::class, FiestaFutbolInfantilProductSeeder::class]);
|
||||||
|
|
||||||
|
Sanctum::actingAs(User::factory()->create([
|
||||||
|
'rol_codigo' => RoleCode::AdminApp->value,
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
]));
|
||||||
|
|
||||||
|
$response = $this->getJson('/api/v1/adminapp/forms/fiesta-futbol-infantil/ticket')
|
||||||
|
->assertOk()
|
||||||
|
->assertExactJson([
|
||||||
|
'data' => [
|
||||||
|
'statuses' => [
|
||||||
|
['value' => 'active', 'label' => 'Activo'],
|
||||||
|
['value' => 'used', 'label' => 'Usado'],
|
||||||
|
['value' => 'expired', 'label' => 'Vencido'],
|
||||||
|
],
|
||||||
|
'categories' => [
|
||||||
|
[
|
||||||
|
'value' => 'entradas',
|
||||||
|
'label' => 'Entradas',
|
||||||
|
'products' => [[
|
||||||
|
'value' => 'abono',
|
||||||
|
'label' => 'Abono',
|
||||||
|
'types' => [],
|
||||||
|
]],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'value' => 'alojamientos',
|
||||||
|
'label' => 'Camping',
|
||||||
|
'products' => [
|
||||||
|
['value' => 'Carpa', 'label' => 'Carpa', 'types' => []],
|
||||||
|
['value' => 'Motorhome', 'label' => 'Motorhome', 'types' => []],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'value' => 'comidas',
|
||||||
|
'label' => 'Comida',
|
||||||
|
'products' => [
|
||||||
|
[
|
||||||
|
'value' => (string) $tenant->eventDates[0]->id,
|
||||||
|
'label' => '09/10',
|
||||||
|
'types' => [
|
||||||
|
['value' => 'Desayuno', 'label' => 'Desayuno'],
|
||||||
|
['value' => 'Almuerzo', 'label' => 'Almuerzo'],
|
||||||
|
['value' => 'Cena', 'label' => 'Cena'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'value' => (string) $tenant->eventDates[1]->id,
|
||||||
|
'label' => '10/10',
|
||||||
|
'types' => [
|
||||||
|
['value' => 'Desayuno', 'label' => 'Desayuno'],
|
||||||
|
['value' => 'Almuerzo', 'label' => 'Almuerzo'],
|
||||||
|
['value' => 'Cena', 'label' => 'Cena'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'value' => (string) $tenant->eventDates[2]->id,
|
||||||
|
'label' => '11/10',
|
||||||
|
'types' => [
|
||||||
|
['value' => 'Desayuno', 'label' => 'Desayuno'],
|
||||||
|
['value' => 'Almuerzo', 'label' => 'Almuerzo'],
|
||||||
|
['value' => 'Cena', 'label' => 'Cena'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'value' => (string) $tenant->eventDates[3]->id,
|
||||||
|
'label' => '12/10',
|
||||||
|
'types' => [
|
||||||
|
['value' => 'Desayuno', 'label' => 'Desayuno'],
|
||||||
|
['value' => 'Almuerzo', 'label' => 'Almuerzo'],
|
||||||
|
['value' => 'Cena', 'label' => 'Cena'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'value' => 'merchandising',
|
||||||
|
'label' => 'Merchandising',
|
||||||
|
'products' => [[
|
||||||
|
'value' => 'camiseta',
|
||||||
|
'label' => 'Camiseta',
|
||||||
|
'types' => [
|
||||||
|
['value' => 'Verde', 'label' => 'Verde'],
|
||||||
|
['value' => 'Blanco', 'label' => 'Blanco'],
|
||||||
|
],
|
||||||
|
]],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertJsonMissingPath('data.categories.0.products.0.category');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createAttachment(string $filename): Attachment
|
||||||
|
{
|
||||||
|
return Attachment::query()->create([
|
||||||
|
'path' => "tests/{$filename}",
|
||||||
|
'filename' => $filename,
|
||||||
|
'type' => AttachmentType::Image,
|
||||||
|
'mime_type' => 'image/png',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -341,9 +341,8 @@ class TelepagosWebhookTest extends TestCase
|
|||||||
->firstOrFail();
|
->firstOrFail();
|
||||||
$this->assertEqualsCanonicalizing(
|
$this->assertEqualsCanonicalizing(
|
||||||
[$firstPurchase->id, $secondPurchase->id, $thirdPurchase->id],
|
[$firstPurchase->id, $secondPurchase->id, $thirdPurchase->id],
|
||||||
$payment->candidates()->pluck('compra_id')->all(),
|
$payment->matched_purchase_ids,
|
||||||
);
|
);
|
||||||
$this->assertSame(3, $payment->candidates()->where('match_reason', 'ambiguous_exact_match')->count());
|
|
||||||
$this->assertDatabaseHas('compras', [
|
$this->assertDatabaseHas('compras', [
|
||||||
'id' => $firstPurchase->id,
|
'id' => $firstPurchase->id,
|
||||||
'status' => Purchase::STATUS_PENDING_PAYMENT,
|
'status' => Purchase::STATUS_PENDING_PAYMENT,
|
||||||
@@ -358,183 +357,6 @@ class TelepagosWebhookTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_transfer_webhook_records_near_amount_only_with_exact_dni_or_exact_amount_with_different_dni(): void
|
|
||||||
{
|
|
||||||
config(['purchase.transfer_candidate_amount_tolerance_percentage' => 5]);
|
|
||||||
|
|
||||||
$tenant = $this->createTenant('candidates', 'Candidates', 'candidates.com.ar');
|
|
||||||
$this->configureTelepagosIntegration($tenant);
|
|
||||||
|
|
||||||
$nearAmountVariant = $this->createVariantForTenant('candidates', 10, '52.00', 'near');
|
|
||||||
$exactAmountVariant = $this->createVariantForTenant('candidates', 10, '50.00', 'exact');
|
|
||||||
$distanceTwoExactAmountVariant = $this->createVariantForTenant('candidates', 10, '50.00', 'distance-two');
|
|
||||||
$farExactAmountVariant = $this->createVariantForTenant('candidates', 10, '50.00', 'far-exact');
|
|
||||||
$nearAmountDifferentDniVariant = $this->createVariantForTenant('candidates', 10, '51.00', 'near-other-dni');
|
|
||||||
$outsideRangeVariant = $this->createVariantForTenant('candidates', 10, '100.00', 'outside');
|
|
||||||
|
|
||||||
$nearAmountPurchase = $this->createPendingTransferPurchase(
|
|
||||||
$tenant,
|
|
||||||
User::factory()->create()->id,
|
|
||||||
$nearAmountVariant->id,
|
|
||||||
1,
|
|
||||||
'12345678',
|
|
||||||
);
|
|
||||||
$exactAmountDifferentDniPurchase = $this->createPendingTransferPurchase(
|
|
||||||
$tenant,
|
|
||||||
User::factory()->create()->id,
|
|
||||||
$exactAmountVariant->id,
|
|
||||||
1,
|
|
||||||
'12345687',
|
|
||||||
);
|
|
||||||
$farExactAmountDifferentDniPurchase = $this->createPendingTransferPurchase(
|
|
||||||
$tenant,
|
|
||||||
User::factory()->create()->id,
|
|
||||||
$farExactAmountVariant->id,
|
|
||||||
1,
|
|
||||||
'87654321',
|
|
||||||
);
|
|
||||||
$distanceTwoExactAmountPurchase = $this->createPendingTransferPurchase(
|
|
||||||
$tenant,
|
|
||||||
User::factory()->create()->id,
|
|
||||||
$distanceTwoExactAmountVariant->id,
|
|
||||||
1,
|
|
||||||
'12345087',
|
|
||||||
);
|
|
||||||
$nearAmountDifferentDniPurchase = $this->createPendingTransferPurchase(
|
|
||||||
$tenant,
|
|
||||||
User::factory()->create()->id,
|
|
||||||
$nearAmountDifferentDniVariant->id,
|
|
||||||
1,
|
|
||||||
'87654321',
|
|
||||||
);
|
|
||||||
$outsideRangePurchase = $this->createPendingTransferPurchase(
|
|
||||||
$tenant,
|
|
||||||
User::factory()->create()->id,
|
|
||||||
$outsideRangeVariant->id,
|
|
||||||
1,
|
|
||||||
'12345678',
|
|
||||||
);
|
|
||||||
|
|
||||||
Http::fake([
|
|
||||||
'https://api.telepagos.com.ar/v2/auth/token' => Http::response([
|
|
||||||
'status' => 'ok',
|
|
||||||
'token' => 'test-token',
|
|
||||||
'expires_at' => now()->addHour()->toIso8601String(),
|
|
||||||
]),
|
|
||||||
'https://api.telepagos.com.ar/v2/payment/cashin/candidates' => Http::response([
|
|
||||||
'status' => 'ok',
|
|
||||||
'data' => [
|
|
||||||
'amount' => 50,
|
|
||||||
'operation_id' => 1,
|
|
||||||
'transaction_id' => 'tx-candidates',
|
|
||||||
'buyer' => ['cuit' => '20123456789'],
|
|
||||||
],
|
|
||||||
]),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->postJson('/api/webhooks/telepagos/candidates', ['id' => 'candidates'])
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonPath('status', 'success');
|
|
||||||
|
|
||||||
$payment = TelepagosPayment::query()
|
|
||||||
->where('transaction_id', 'tx-candidates')
|
|
||||||
->firstOrFail();
|
|
||||||
|
|
||||||
$this->assertNull($payment->compra_id);
|
|
||||||
$this->assertEqualsCanonicalizing([
|
|
||||||
$nearAmountPurchase->id,
|
|
||||||
$exactAmountDifferentDniPurchase->id,
|
|
||||||
$distanceTwoExactAmountPurchase->id,
|
|
||||||
], $payment->candidates()->pluck('compra_id')->all());
|
|
||||||
$this->assertDatabaseHas('telepagos_payment_candidates', [
|
|
||||||
'telepagos_payment_id' => $payment->id,
|
|
||||||
'compra_id' => $nearAmountPurchase->id,
|
|
||||||
'dni_matches' => true,
|
|
||||||
'dni_distance' => 0,
|
|
||||||
'payment_dni' => '12345678',
|
|
||||||
'purchase_dni' => '12345678',
|
|
||||||
'amount_matches' => false,
|
|
||||||
'payment_amount' => 50,
|
|
||||||
'purchase_amount' => 52,
|
|
||||||
'amount_difference' => 2,
|
|
||||||
'match_reason' => 'exact_dni_near_amount',
|
|
||||||
'confidence' => 'high',
|
|
||||||
]);
|
|
||||||
$this->assertDatabaseHas('telepagos_payment_candidates', [
|
|
||||||
'telepagos_payment_id' => $payment->id,
|
|
||||||
'compra_id' => $exactAmountDifferentDniPurchase->id,
|
|
||||||
'dni_matches' => false,
|
|
||||||
'dni_distance' => 1,
|
|
||||||
'payment_dni' => '12345678',
|
|
||||||
'purchase_dni' => '12345687',
|
|
||||||
'amount_matches' => true,
|
|
||||||
'payment_amount' => 50,
|
|
||||||
'purchase_amount' => 50,
|
|
||||||
'amount_difference' => 0,
|
|
||||||
'match_reason' => 'exact_amount_near_dni',
|
|
||||||
'confidence' => 'medium',
|
|
||||||
]);
|
|
||||||
$this->assertDatabaseHas('telepagos_payment_candidates', [
|
|
||||||
'telepagos_payment_id' => $payment->id,
|
|
||||||
'compra_id' => $distanceTwoExactAmountPurchase->id,
|
|
||||||
'dni_matches' => false,
|
|
||||||
'dni_distance' => 2,
|
|
||||||
'payment_dni' => '12345678',
|
|
||||||
'purchase_dni' => '12345087',
|
|
||||||
'amount_matches' => true,
|
|
||||||
'match_reason' => 'exact_amount_near_dni',
|
|
||||||
]);
|
|
||||||
$this->assertDatabaseMissing('telepagos_payment_candidates', [
|
|
||||||
'telepagos_payment_id' => $payment->id,
|
|
||||||
'compra_id' => $farExactAmountDifferentDniPurchase->id,
|
|
||||||
]);
|
|
||||||
$this->assertDatabaseMissing('telepagos_payment_candidates', [
|
|
||||||
'telepagos_payment_id' => $payment->id,
|
|
||||||
'compra_id' => $nearAmountDifferentDniPurchase->id,
|
|
||||||
]);
|
|
||||||
$this->assertDatabaseMissing('telepagos_payment_candidates', [
|
|
||||||
'telepagos_payment_id' => $payment->id,
|
|
||||||
'compra_id' => $outsideRangePurchase->id,
|
|
||||||
]);
|
|
||||||
$this->assertSame(Purchase::STATUS_PENDING_PAYMENT, $nearAmountPurchase->fresh()->status);
|
|
||||||
$this->assertSame(Purchase::STATUS_PENDING_PAYMENT, $exactAmountDifferentDniPurchase->fresh()->status);
|
|
||||||
|
|
||||||
$higherPriorityPayment = TelepagosPayment::query()->create([
|
|
||||||
'cuit_buyer' => '20123456789',
|
|
||||||
'amount' => 52,
|
|
||||||
'operation_id' => 1,
|
|
||||||
'transaction_id' => 'tx-primary-candidate',
|
|
||||||
]);
|
|
||||||
$higherPriorityPayment->candidates()->create([
|
|
||||||
'compra_id' => $nearAmountPurchase->id,
|
|
||||||
'dni_matches' => true,
|
|
||||||
'dni_distance' => 0,
|
|
||||||
'payment_dni' => '12345678',
|
|
||||||
'purchase_dni' => '12345678',
|
|
||||||
'amount_matches' => true,
|
|
||||||
'payment_amount' => 52,
|
|
||||||
'purchase_amount' => 52,
|
|
||||||
'amount_difference' => 0,
|
|
||||||
'match_reason' => 'ambiguous_exact_match',
|
|
||||||
'confidence' => 'exact',
|
|
||||||
]);
|
|
||||||
|
|
||||||
app(CheckoutService::class)->submitForReview($nearAmountPurchase->fresh());
|
|
||||||
$buyer = User::query()->findOrFail($nearAmountPurchase->user_id);
|
|
||||||
|
|
||||||
$this->actingAs($buyer, 'sanctum')
|
|
||||||
->getJson("/api/tenants/candidates/compras/{$nearAmountPurchase->id}")
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonPath('data.status', Purchase::STATUS_IN_REVIEW)
|
|
||||||
->assertJsonPath('data.payment_verification.status', 'candidate')
|
|
||||||
->assertJsonPath('data.payment_verification.candidate_count', 2)
|
|
||||||
->assertJsonPath('data.payment_verification.primary.reason', 'ambiguous_exact_match')
|
|
||||||
->assertJsonPath('data.payment_verification.primary.amount_difference', '0.00')
|
|
||||||
->assertJsonPath('data.payment_verification.primary.confidence', 'exact')
|
|
||||||
->assertJsonPath('data.payment_verification.reasons.0', 'ambiguous_exact_match')
|
|
||||||
->assertJsonPath('data.payment_verification.reasons.1', 'exact_dni_near_amount');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_webhook_confirms_a_purchase_with_tickets_enabled(): void
|
public function test_webhook_confirms_a_purchase_with_tickets_enabled(): void
|
||||||
{
|
{
|
||||||
$tenant = $this->createTenant('expired-ticket', 'Expired Ticket', 'expired-ticket.com.ar');
|
$tenant = $this->createTenant('expired-ticket', 'Expired Ticket', 'expired-ticket.com.ar');
|
||||||
|
|||||||
@@ -218,13 +218,13 @@ class DesfilePuraTendenciaSeederTest extends TestCase
|
|||||||
->whereIn('variant_id', (clone $variants)->pluck('id'))
|
->whereIn('variant_id', (clone $variants)->pluck('id'))
|
||||||
->count());
|
->count());
|
||||||
$this->assertSame(330, (clone $variants)->whereNull('event_date_id')->count());
|
$this->assertSame(330, (clone $variants)->whereNull('event_date_id')->count());
|
||||||
$this->assertSame(283, DB::table('inventories')
|
$this->assertSame(284, DB::table('inventories')
|
||||||
->whereIn('id', (clone $variants)->pluck('inventory_id'))
|
->whereIn('id', (clone $variants)->pluck('inventory_id'))
|
||||||
->where('real_stock', 1)
|
->where('real_stock', 1)
|
||||||
->where('reserved_stock', 0)
|
->where('reserved_stock', 0)
|
||||||
->where('sold_units', 0)
|
->where('sold_units', 0)
|
||||||
->count());
|
->count());
|
||||||
$this->assertSame(47, DB::table('inventories')
|
$this->assertSame(46, DB::table('inventories')
|
||||||
->whereIn('id', (clone $variants)->pluck('inventory_id'))
|
->whereIn('id', (clone $variants)->pluck('inventory_id'))
|
||||||
->where('real_stock', 0)
|
->where('real_stock', 0)
|
||||||
->where('reserved_stock', 0)
|
->where('reserved_stock', 0)
|
||||||
@@ -289,14 +289,14 @@ class DesfilePuraTendenciaSeederTest extends TestCase
|
|||||||
|
|
||||||
$items = DB::table('compra_items')->where('compra_id', $purchase->id);
|
$items = DB::table('compra_items')->where('compra_id', $purchase->id);
|
||||||
|
|
||||||
$this->assertSame(49, (clone $items)->count());
|
$this->assertSame(48, (clone $items)->count());
|
||||||
$this->assertSame(49, (clone $items)
|
$this->assertSame(48, (clone $items)
|
||||||
->where('precio_unitario', 0)
|
->where('precio_unitario', 0)
|
||||||
->where('discount_total', 0)
|
->where('discount_total', 0)
|
||||||
->where('tax_total', 0)
|
->where('tax_total', 0)
|
||||||
->where('total', 0)
|
->where('total', 0)
|
||||||
->count());
|
->count());
|
||||||
$this->assertSame(49, DB::table('tickets')
|
$this->assertSame(48, DB::table('tickets')
|
||||||
->where('source_purchase_id', $purchase->id)
|
->where('source_purchase_id', $purchase->id)
|
||||||
->where('user_id', $user->id)
|
->where('user_id', $user->id)
|
||||||
->where('source_catalog_item_id', $catalogItemId)
|
->where('source_catalog_item_id', $catalogItemId)
|
||||||
@@ -312,13 +312,7 @@ class DesfilePuraTendenciaSeederTest extends TestCase
|
|||||||
foreach ([
|
foreach ([
|
||||||
['sector' => 'A', 'fila' => '1', 'tipo' => 'NORMAL', 'count' => 16],
|
['sector' => 'A', 'fila' => '1', 'tipo' => 'NORMAL', 'count' => 16],
|
||||||
['sector' => 'A', 'fila' => '3', 'tipo' => 'NORMAL', 'count' => 14],
|
['sector' => 'A', 'fila' => '3', 'tipo' => 'NORMAL', 'count' => 14],
|
||||||
[
|
['sector' => 'C', 'fila' => '1', 'tipo' => 'VIP + LUNCH', 'count' => 16],
|
||||||
'sector' => 'C',
|
|
||||||
'fila' => '1',
|
|
||||||
'tipo' => 'VIP + LUNCH',
|
|
||||||
'count' => 17,
|
|
||||||
'seats' => array_map('strval', range(1, 17)),
|
|
||||||
],
|
|
||||||
['sector' => 'C', 'fila' => '3', 'tipo' => 'NORMAL', 'count' => 2, 'seats' => ['6', '7']],
|
['sector' => 'C', 'fila' => '3', 'tipo' => 'NORMAL', 'count' => 2, 'seats' => ['6', '7']],
|
||||||
] as $allocation) {
|
] as $allocation) {
|
||||||
$allocatedVariants = DB::table('variantes')
|
$allocatedVariants = DB::table('variantes')
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class MenuSeederTest extends TestCase
|
|||||||
'adminapp.ventas' => ['Ventas', '/admin/ventas'],
|
'adminapp.ventas' => ['Ventas', '/admin/ventas'],
|
||||||
];
|
];
|
||||||
$fiestaCategoryMenus = [
|
$fiestaCategoryMenus = [
|
||||||
|
'adminapp.tickets' => ['Tickets', '/admin/tickets'],
|
||||||
'adminapp.fiesta-futbol-infantil.entradas' => ['Entradas', '/admin/entradas'],
|
'adminapp.fiesta-futbol-infantil.entradas' => ['Entradas', '/admin/entradas'],
|
||||||
'adminapp.fiesta-futbol-infantil.alojamientos' => ['Alojamientos', '/admin/alojamientos'],
|
'adminapp.fiesta-futbol-infantil.alojamientos' => ['Alojamientos', '/admin/alojamientos'],
|
||||||
'adminapp.fiesta-futbol-infantil.merchandising' => ['Merchandising', '/admin/merchandising'],
|
'adminapp.fiesta-futbol-infantil.merchandising' => ['Merchandising', '/admin/merchandising'],
|
||||||
@@ -49,7 +50,11 @@ class MenuSeederTest extends TestCase
|
|||||||
$this->assertSame(Menu::CONTENT_TYPE_DYNAMIC, $adminApp->content_type);
|
$this->assertSame(Menu::CONTENT_TYPE_DYNAMIC, $adminApp->content_type);
|
||||||
$this->assertSame('/', $adminApp->route);
|
$this->assertSame('/', $adminApp->route);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
array_keys([...$expectedMenus, ...$fiestaCategoryMenus]),
|
collect(array_keys([
|
||||||
|
...$expectedMenus,
|
||||||
|
...$fiestaCategoryMenus,
|
||||||
|
'adminapp.desfile.entradas' => ['Entradas', '/admin/desfile/entradas'],
|
||||||
|
]))->sort()->values()->all(),
|
||||||
$adminApp->children->pluck('code')->sort()->values()->all()
|
$adminApp->children->pluck('code')->sort()->values()->all()
|
||||||
);
|
);
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
|
|||||||
250
tests/Feature/Ticket/AdminAppTicketControllerTest.php
Normal file
250
tests/Feature/Ticket/AdminAppTicketControllerTest.php
Normal file
@@ -0,0 +1,250 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Ticket;
|
||||||
|
|
||||||
|
use App\Domains\Attachable\Enums\AttachmentType;
|
||||||
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
|
use App\Domains\Auth\Models\User;
|
||||||
|
use App\Domains\Authorization\Enums\RoleCode;
|
||||||
|
use App\Domains\Catalog\Models\Attribute;
|
||||||
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
|
use App\Domains\Catalog\Models\Inventory;
|
||||||
|
use App\Domains\Catalog\Models\Variant;
|
||||||
|
use App\Domains\Menu\Models\Menu;
|
||||||
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
|
use App\Domains\Purchase\Models\PurchaseItem;
|
||||||
|
use App\Domains\Shared\Enums\FieldType;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use App\Domains\Tenant\Models\WebsiteType;
|
||||||
|
use App\Domains\Ticket\Models\Ticket;
|
||||||
|
use Database\Seeders\AuthorizationSeeder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Laravel\Sanctum\Sanctum;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AdminAppTicketControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->seed(AuthorizationSeeder::class);
|
||||||
|
WebsiteType::query()->create(['codigo' => 'onticket', 'nombre' => 'OnTicket']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_authentication_is_required(): void
|
||||||
|
{
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/tickets')->assertUnauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_tenant_must_have_the_tickets_menu(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||||
|
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/tickets')->assertNotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_lists_only_tickets_from_the_authenticated_tenant(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||||
|
$otherTenant = $this->createTenant('other');
|
||||||
|
$admin = $this->createAdminAppUser($tenant);
|
||||||
|
$otherUser = $this->createAdminAppUser($otherTenant);
|
||||||
|
$this->grantTicketsMenu($tenant);
|
||||||
|
Sanctum::actingAs($admin);
|
||||||
|
|
||||||
|
$ticket = $this->createTicket($tenant, $admin);
|
||||||
|
$this->createTicket($otherTenant, $otherUser);
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(1, 'data')
|
||||||
|
->assertJsonPath('data.0.id', $ticket->id)
|
||||||
|
->assertJsonPath('data.0.tenant_code', $tenant->codigo)
|
||||||
|
->assertJsonPath('meta.total', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_supports_id_and_uuid_search(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||||
|
$admin = $this->createAdminAppUser($tenant);
|
||||||
|
$this->grantTicketsMenu($tenant);
|
||||||
|
Sanctum::actingAs($admin);
|
||||||
|
|
||||||
|
$matching = $this->createTicket($tenant, $admin);
|
||||||
|
$this->createTicket($tenant, $admin);
|
||||||
|
|
||||||
|
$this->getJson("/api/v1/adminapp/tenant/tickets?q={$matching->id}")
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(1, 'data')
|
||||||
|
->assertJsonPath('data.0.id', $matching->id);
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/tickets?q='.substr($matching->ticket, 0, 8))
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(1, 'data')
|
||||||
|
->assertJsonPath('data.0.ticket', $matching->ticket);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_includes_tenant_scanned_and_total_ticket_counts(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||||
|
$otherTenant = $this->createTenant('other');
|
||||||
|
$admin = $this->createAdminAppUser($tenant);
|
||||||
|
$otherUser = $this->createAdminAppUser($otherTenant);
|
||||||
|
$this->grantTicketsMenu($tenant);
|
||||||
|
Sanctum::actingAs($admin);
|
||||||
|
|
||||||
|
$this->createTicket($tenant, $admin)->update(['used_at' => now()]);
|
||||||
|
$this->createTicket($tenant, $admin);
|
||||||
|
$this->createTicket($otherTenant, $otherUser)->update(['used_at' => now()]);
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/tickets?q=does-not-match')
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(0, 'data')
|
||||||
|
->assertJsonPath('scanned_tickets', 0)
|
||||||
|
->assertJsonPath('total_tickets', 0);
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonPath('scanned_tickets', 1)
|
||||||
|
->assertJsonPath('total_tickets', 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_returns_structured_variant_properties(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||||
|
$admin = $this->createAdminAppUser($tenant);
|
||||||
|
$this->grantTicketsMenu($tenant);
|
||||||
|
Sanctum::actingAs($admin);
|
||||||
|
|
||||||
|
$item = CatalogItem::query()->create([
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'slug' => 'remera',
|
||||||
|
'nombre' => 'Remera',
|
||||||
|
'precio' => '8000.00',
|
||||||
|
'has_tickets' => true,
|
||||||
|
]);
|
||||||
|
$attribute = Attribute::query()->create([
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
'codigo' => 'size',
|
||||||
|
'nombre' => 'Talle',
|
||||||
|
'type' => FieldType::Select,
|
||||||
|
]);
|
||||||
|
$attribute->options()->create(['value' => 'xl', 'label' => 'XL']);
|
||||||
|
$itemAttribute = $item->itemAttributes()->create([
|
||||||
|
'attribute_id' => $attribute->id,
|
||||||
|
'sort_order' => 1,
|
||||||
|
]);
|
||||||
|
$variant = Variant::query()->create([
|
||||||
|
'catalog_item_id' => $item->id,
|
||||||
|
'inventory_id' => Inventory::query()->create()->id,
|
||||||
|
]);
|
||||||
|
$variant->definitions()->create([
|
||||||
|
'item_attribute_id' => $itemAttribute->id,
|
||||||
|
'value' => 'xl',
|
||||||
|
]);
|
||||||
|
$purchase = Purchase::query()->create([
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
'user_id' => $admin->id,
|
||||||
|
'status' => Purchase::STATUS_PAID,
|
||||||
|
'nombre_apellido' => 'Nombre Apellido',
|
||||||
|
'total' => '8000.00',
|
||||||
|
]);
|
||||||
|
PurchaseItem::query()->create([
|
||||||
|
'compra_id' => $purchase->id,
|
||||||
|
'source_catalog_item_id' => $item->id,
|
||||||
|
'source_variant_id' => $variant->id,
|
||||||
|
'nombre' => 'Remera',
|
||||||
|
'descripcion' => '',
|
||||||
|
'slug' => 'remera',
|
||||||
|
'item_nombre' => 'Remera',
|
||||||
|
'cantidad' => 1,
|
||||||
|
'precio_unitario' => '8000.00',
|
||||||
|
'total' => '8000.00',
|
||||||
|
]);
|
||||||
|
$ticket = $this->createTicket($tenant, $admin, [
|
||||||
|
'source_purchase_id' => $purchase->id,
|
||||||
|
'source_catalog_item_id' => $item->id,
|
||||||
|
'source_variant_id' => $variant->id,
|
||||||
|
'scanner_user_id' => $admin->id,
|
||||||
|
'used_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonPath('data.0.id', $ticket->id)
|
||||||
|
->assertJsonPath('data.0.order_number', $purchase->id)
|
||||||
|
->assertJsonPath('data.0.product', 'Remera')
|
||||||
|
->assertJsonPath('data.0.amount', '8000.00')
|
||||||
|
->assertJsonPath('data.0.status', Ticket::STATUS_USED)
|
||||||
|
->assertJsonPath('data.0.scanned_by', $admin->nombre_apellido)
|
||||||
|
->assertJsonPath('data.0.variant_properties.0.code', 'size')
|
||||||
|
->assertJsonPath('data.0.variant_properties.0.label', 'Talle')
|
||||||
|
->assertJsonPath('data.0.variant_properties.0.values.0.value', 'xl')
|
||||||
|
->assertJsonPath('data.0.variant_properties.0.values.0.label', 'XL');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createTenant(string $code): Tenant
|
||||||
|
{
|
||||||
|
$headerLogo = $this->createAttachment("{$code}-header.png");
|
||||||
|
$footerLogo = $this->createAttachment("{$code}-footer.png");
|
||||||
|
|
||||||
|
return Tenant::query()->create([
|
||||||
|
'codigo' => $code,
|
||||||
|
'nombre' => ucfirst($code),
|
||||||
|
'dominio' => "{$code}.test",
|
||||||
|
'website_type_code' => 'onticket',
|
||||||
|
'primary_color' => '#111111',
|
||||||
|
'secondary_color' => '#222222',
|
||||||
|
'danger_color' => '#333333',
|
||||||
|
'success_color' => '#444444',
|
||||||
|
'header_bg_color' => '#ffffff',
|
||||||
|
'footer_bg_color' => '#ffffff',
|
||||||
|
'header_logo_id' => $headerLogo->id,
|
||||||
|
'footer_logo_id' => $footerLogo->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createAttachment(string $filename): Attachment
|
||||||
|
{
|
||||||
|
return Attachment::query()->create([
|
||||||
|
'path' => "test/{$filename}",
|
||||||
|
'filename' => $filename,
|
||||||
|
'type' => AttachmentType::Image,
|
||||||
|
'mime_type' => 'image/png',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createAdminAppUser(Tenant $tenant): User
|
||||||
|
{
|
||||||
|
return User::factory()->create([
|
||||||
|
'rol_codigo' => RoleCode::AdminApp->value,
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function grantTicketsMenu(Tenant $tenant): void
|
||||||
|
{
|
||||||
|
$menu = Menu::query()->create([
|
||||||
|
'code' => 'adminapp.tickets',
|
||||||
|
'label' => 'Tickets',
|
||||||
|
'route' => '/admin/tickets',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$tenant->menues()->attach($menu->code);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param array<string, mixed> $attributes */
|
||||||
|
private function createTicket(Tenant $tenant, User $user, array $attributes = []): Ticket
|
||||||
|
{
|
||||||
|
return Ticket::query()->create(array_merge([
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'ticket' => (string) Str::uuid(),
|
||||||
|
'user_id' => $user->id,
|
||||||
|
], $attributes));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature\Ticket;
|
|
||||||
|
|
||||||
use App\Domains\Attachable\Models\Attachment;
|
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
|
||||||
use App\Domains\Catalog\Models\Category;
|
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
|
||||||
use App\Domains\Tenant\Models\WebsiteType;
|
|
||||||
use App\Domains\Ticket\Models\Ticket;
|
|
||||||
use Database\Seeders\AuthorizationSeeder;
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Illuminate\Support\Facades\Artisan;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class PrepareLoadTestTicketsCommandTest extends TestCase
|
|
||||||
{
|
|
||||||
use RefreshDatabase;
|
|
||||||
|
|
||||||
public function test_it_generates_a_postman_dataset_that_can_scan_the_tickets(): void
|
|
||||||
{
|
|
||||||
Storage::fake('local');
|
|
||||||
$this->seed(AuthorizationSeeder::class);
|
|
||||||
WebsiteType::query()->create(['codigo' => 'onticket', 'nombre' => 'OnTicket']);
|
|
||||||
$tenant = $this->createTenant('acme');
|
|
||||||
$category = Category::query()->create([
|
|
||||||
'tenant_code' => $tenant->codigo,
|
|
||||||
'nombre' => 'Entradas de carga',
|
|
||||||
]);
|
|
||||||
$catalogItem = CatalogItem::query()->create([
|
|
||||||
'tenant_code' => $tenant->codigo,
|
|
||||||
'category_id' => $category->id,
|
|
||||||
'slug' => 'entrada-load-test',
|
|
||||||
'nombre' => 'Entrada load test',
|
|
||||||
'descripcion' => 'Ticket descartable',
|
|
||||||
'precio' => 100,
|
|
||||||
'has_tickets' => true,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$exitCode = Artisan::call('load-test:tickets:prepare', [
|
|
||||||
'tenant' => $tenant->codigo,
|
|
||||||
'--tickets' => 4,
|
|
||||||
'--scanners' => 2,
|
|
||||||
'--owners' => 2,
|
|
||||||
'--catalog-item' => $catalogItem->id,
|
|
||||||
'--run' => 'test-run',
|
|
||||||
'--output' => 'load-tests/test-run.postman.json',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->assertSame(0, $exitCode, Artisan::output());
|
|
||||||
|
|
||||||
Storage::disk('local')->assertExists('load-tests/test-run.postman.json');
|
|
||||||
$rows = json_decode(
|
|
||||||
Storage::disk('local')->get('load-tests/test-run.postman.json'),
|
|
||||||
true,
|
|
||||||
flags: JSON_THROW_ON_ERROR,
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertCount(4, $rows);
|
|
||||||
$this->assertCount(4, collect($rows)->pluck('ticket_uuid')->unique());
|
|
||||||
$this->assertCount(2, collect($rows)->pluck('scanner_token')->unique());
|
|
||||||
$this->assertSame([200], collect($rows)->pluck('expected_status')->unique()->values()->all());
|
|
||||||
$this->assertDatabaseCount('tickets', 4);
|
|
||||||
$this->assertCount(2, Ticket::query()->distinct()->pluck('user_id'));
|
|
||||||
$this->assertDatabaseCount('category_scanners', 2);
|
|
||||||
|
|
||||||
$first = $rows[0];
|
|
||||||
$this->withToken($first['scanner_token'])
|
|
||||||
->postJson("/api/v1/scanner/tickets/{$first['ticket_uuid']}/scan")
|
|
||||||
->assertOk()
|
|
||||||
->assertJsonPath('data.ticket', $first['ticket_uuid']);
|
|
||||||
|
|
||||||
$this->assertNotNull(
|
|
||||||
Ticket::query()->where('ticket', $first['ticket_uuid'])->firstOrFail()->used_at
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createTenant(string $code): Tenant
|
|
||||||
{
|
|
||||||
$logo = Attachment::query()->create([
|
|
||||||
'key' => (string) Str::uuid(),
|
|
||||||
'path' => "tests/{$code}-logo.png",
|
|
||||||
'filename' => "{$code}-logo.png",
|
|
||||||
'type' => 'image',
|
|
||||||
'mime_type' => 'image/png',
|
|
||||||
'extension' => 'png',
|
|
||||||
'size' => 1,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return Tenant::query()->create([
|
|
||||||
'codigo' => $code,
|
|
||||||
'nombre' => ucfirst($code),
|
|
||||||
'dominio' => "{$code}.test",
|
|
||||||
'primary_color' => '#ff7006',
|
|
||||||
'secondary_color' => '#777777',
|
|
||||||
'danger_color' => '#e04a4a',
|
|
||||||
'success_color' => '#81bc73',
|
|
||||||
'header_bg_color' => '#313131',
|
|
||||||
'footer_bg_color' => '#313131',
|
|
||||||
'header_logo_id' => $logo->id,
|
|
||||||
'footer_logo_id' => $logo->id,
|
|
||||||
'website_type_code' => 'onticket',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,17 +8,22 @@ use RuntimeException;
|
|||||||
|
|
||||||
abstract class TestCase extends BaseTestCase
|
abstract class TestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Boot the application only when the test database is explicitly isolated.
|
||||||
|
*/
|
||||||
public function createApplication(): Application
|
public function createApplication(): Application
|
||||||
{
|
{
|
||||||
$app = parent::createApplication();
|
$app = parent::createApplication();
|
||||||
$connection = (string) $app['config']->get('database.default');
|
|
||||||
$database = (string) $app['config']->get("database.connections.{$connection}.database");
|
|
||||||
$usesInMemorySqlite = $connection === 'sqlite' && $database === ':memory:';
|
|
||||||
|
|
||||||
if (! $usesInMemorySqlite && ! str_ends_with(strtolower($database), '_test')) {
|
$database = (string) $app['config']->get(
|
||||||
throw new RuntimeException(
|
'database.connections.'.$app['config']->get('database.default').'.database'
|
||||||
"Unsafe test database [{$database}]. Tests may only use an in-memory SQLite database or a database ending in _test.",
|
);
|
||||||
);
|
|
||||||
|
if (! preg_match('/^shopit_(?:test|testing)(?:_\d+)?$/', $database)) {
|
||||||
|
throw new RuntimeException(sprintf(
|
||||||
|
'Refusing to run tests against database [%s]. Use [shopit_test] or [shopit_testing].',
|
||||||
|
$database !== '' ? $database : '(empty)'
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $app;
|
return $app;
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Unit\Purchase;
|
|
||||||
|
|
||||||
use App\Domains\Purchase\Services\DniDistanceService;
|
|
||||||
use PHPUnit\Framework\Attributes\DataProvider;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class DniDistanceServiceTest extends TestCase
|
|
||||||
{
|
|
||||||
/** @return iterable<string, array{string, string, int}> */
|
|
||||||
public static function distances(): iterable
|
|
||||||
{
|
|
||||||
yield 'exact' => ['40123456', '40123456', 0];
|
|
||||||
yield 'leading transposition' => ['40123456', '04123456', 1];
|
|
||||||
yield 'trailing transposition' => ['40123456', '40123465', 1];
|
|
||||||
yield 'single substitution' => ['40123456', '40123856', 1];
|
|
||||||
yield 'substitution and transposition' => ['12345678', '12345087', 2];
|
|
||||||
yield 'seven digits normalized with leading zero' => ['04123456', '4123456', 0];
|
|
||||||
yield 'more than two edits' => ['40123456', '87654321', 7];
|
|
||||||
}
|
|
||||||
|
|
||||||
#[DataProvider('distances')]
|
|
||||||
public function test_it_calculates_damerau_levenshtein_distance(
|
|
||||||
string $left,
|
|
||||||
string $right,
|
|
||||||
int $expected,
|
|
||||||
): void {
|
|
||||||
$this->assertSame($expected, (new DniDistanceService)->distance($left, $right));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user