Compare commits
13 Commits
test/stres
...
e63a03601a
| Author | SHA1 | Date | |
|---|---|---|---|
| e63a03601a | |||
| 389373ad8c | |||
| ace02a3133 | |||
| d69a6210f6 | |||
| 3c0b43fea3 | |||
| 9b0008626b | |||
| 61861e331a | |||
| 2cc9d7dd97 | |||
| f982bcead1 | |||
| 7a85e1731d | |||
| 6db99e775a | |||
| e5f7ba3615 | |||
| 24bfef431b |
@@ -8,7 +8,6 @@ PURCHASE_CHECKOUT_EXPIRATION_MINUTES=30
|
|||||||
PURCHASE_QR_EXPIRATION_MINUTES=15
|
PURCHASE_QR_EXPIRATION_MINUTES=15
|
||||||
PURCHASE_TELEPAGOS_EXPIRATION_MINUTES=30
|
PURCHASE_TELEPAGOS_EXPIRATION_MINUTES=30
|
||||||
PURCHASE_TRANSFER_EXPIRATION_MINUTES=1440
|
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
|
||||||
|
|
||||||
@@ -32,7 +31,6 @@ AUTH_LOGIN_ATTEMPT_WINDOW_MINUTES=30
|
|||||||
AUTH_LOGIN_LOCK_MINUTES=15
|
AUTH_LOGIN_LOCK_MINUTES=15
|
||||||
AUTH_LOGIN_RATE_LIMIT_PER_MINUTE=10
|
AUTH_LOGIN_RATE_LIMIT_PER_MINUTE=10
|
||||||
AUTH_LOGIN_IP_RATE_LIMIT_PER_MINUTE=30
|
AUTH_LOGIN_IP_RATE_LIMIT_PER_MINUTE=30
|
||||||
AUTH_PASSWORD_RESET_EXPIRATION_MINUTES=60
|
|
||||||
|
|
||||||
LOG_CHANNEL=daily
|
LOG_CHANNEL=daily
|
||||||
LOG_STACK=single
|
LOG_STACK=single
|
||||||
@@ -43,8 +41,6 @@ TELEPAGOS_LOG_LEVEL=info
|
|||||||
TELEPAGOS_LOG_DAYS=30
|
TELEPAGOS_LOG_DAYS=30
|
||||||
COMMANDS_LOG_LEVEL=info
|
COMMANDS_LOG_LEVEL=info
|
||||||
COMMANDS_LOG_DAYS=30
|
COMMANDS_LOG_DAYS=30
|
||||||
EMAILS_LOG_LEVEL=info
|
|
||||||
EMAILS_LOG_DAYS=30
|
|
||||||
|
|
||||||
DB_CONNECTION=mysql
|
DB_CONNECTION=mysql
|
||||||
DB_HOST=127.0.0.1
|
DB_HOST=127.0.0.1
|
||||||
|
|||||||
@@ -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,18 +22,10 @@ class ValidateResetPasswordAttemptController extends Controller
|
|||||||
{
|
{
|
||||||
$data = $request->validated();
|
$data = $request->validated();
|
||||||
|
|
||||||
$result = $this->resetPasswordAttemptService->validateCode(
|
if (! $this->resetPasswordAttemptService->validateCode(
|
||||||
$data['email'],
|
$data['email'],
|
||||||
$data['codigo'],
|
$data['codigo'],
|
||||||
);
|
)) {
|
||||||
|
|
||||||
if ($result === ResetPasswordAttemptService::CODE_EXPIRED) {
|
|
||||||
throw ValidationException::withMessages([
|
|
||||||
'codigo' => __('api.auth.reset_code_expired'),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($result !== ResetPasswordAttemptService::CODE_VALID) {
|
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
'codigo' => __('api.auth.reset_code_invalid'),
|
'codigo' => __('api.auth.reset_code_invalid'),
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Attributes\Hidden;
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
#[Fillable(['user_id', 'codigo', 'reason', 'status', 'expires_at'])]
|
#[Fillable(['user_id', 'codigo', 'reason', 'status'])]
|
||||||
#[Hidden(['codigo'])]
|
#[Hidden(['codigo'])]
|
||||||
class ResetPasswordAttempt extends Model
|
class ResetPasswordAttempt extends Model
|
||||||
{
|
{
|
||||||
@@ -31,7 +31,6 @@ class ResetPasswordAttempt extends Model
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'user_id' => 'integer',
|
'user_id' => 'integer',
|
||||||
'expires_at' => 'datetime',
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,12 +12,6 @@ use Throwable;
|
|||||||
|
|
||||||
class ResetPasswordAttemptService
|
class ResetPasswordAttemptService
|
||||||
{
|
{
|
||||||
public const CODE_VALID = 'valid';
|
|
||||||
|
|
||||||
public const CODE_INVALID = 'invalid';
|
|
||||||
|
|
||||||
public const CODE_EXPIRED = 'expired';
|
|
||||||
|
|
||||||
public function createForEmail(
|
public function createForEmail(
|
||||||
string $email,
|
string $email,
|
||||||
string $tenantCode,
|
string $tenantCode,
|
||||||
@@ -152,12 +146,12 @@ class ResetPasswordAttemptService
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function validateCode(string $email, string $code): string
|
public function validateCode(string $email, string $code): bool
|
||||||
{
|
{
|
||||||
$emailFingerprint = $this->emailFingerprint($email);
|
$emailFingerprint = $this->emailFingerprint($email);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return DB::transaction(function () use ($email, $code, $emailFingerprint): string {
|
return DB::transaction(function () use ($email, $code, $emailFingerprint): bool {
|
||||||
$user = User::query()
|
$user = User::query()
|
||||||
->where('email', $email)
|
->where('email', $email)
|
||||||
->lockForUpdate()
|
->lockForUpdate()
|
||||||
@@ -175,27 +169,14 @@ class ResetPasswordAttemptService
|
|||||||
'email_fingerprint' => $emailFingerprint,
|
'email_fingerprint' => $emailFingerprint,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return self::CODE_INVALID;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if ($attempt->expires_at?->isPast()) {
|
|
||||||
$attempt->update([
|
|
||||||
'status' => ResetPasswordAttempt::STATUS_EXPIRED,
|
|
||||||
]);
|
|
||||||
|
|
||||||
Log::info('Password reset code validation failed: attempt expired.', [
|
|
||||||
'email_fingerprint' => $emailFingerprint,
|
|
||||||
'attempt_id' => $attempt->getKey(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return self::CODE_EXPIRED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$attempt->update([
|
$attempt->update([
|
||||||
'status' => ResetPasswordAttempt::STATUS_VALIDATED,
|
'status' => ResetPasswordAttempt::STATUS_VALIDATED,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return self::CODE_VALID;
|
return true;
|
||||||
});
|
});
|
||||||
} catch (Throwable $exception) {
|
} catch (Throwable $exception) {
|
||||||
Log::error('Failed to validate password reset code.', [
|
Log::error('Failed to validate password reset code.', [
|
||||||
@@ -233,19 +214,6 @@ class ResetPasswordAttemptService
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($attempt->expires_at?->isPast()) {
|
|
||||||
$attempt->update([
|
|
||||||
'status' => ResetPasswordAttempt::STATUS_EXPIRED,
|
|
||||||
]);
|
|
||||||
|
|
||||||
Log::info('Password reset failed: attempt expired.', [
|
|
||||||
'email_fingerprint' => $emailFingerprint,
|
|
||||||
'attempt_id' => $attempt->getKey(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$user->password = $password;
|
$user->password = $password;
|
||||||
$user->failed_login_attempts = 0;
|
$user->failed_login_attempts = 0;
|
||||||
$user->last_failed_login_at = null;
|
$user->last_failed_login_at = null;
|
||||||
@@ -302,7 +270,6 @@ class ResetPasswordAttemptService
|
|||||||
'codigo' => $this->generateCode(),
|
'codigo' => $this->generateCode(),
|
||||||
'reason' => $reason,
|
'reason' => $reason,
|
||||||
'status' => ResetPasswordAttempt::STATUS_PENDING,
|
'status' => ResetPasswordAttempt::STATUS_PENDING,
|
||||||
'expires_at' => now()->addMinutes((int) config('auth.passwords.users.expire')),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $attempt->getKey();
|
return $attempt->getKey();
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ class AdminAppBootstrapResource extends JsonResource
|
|||||||
'login_header_footer_color' => $websiteType->login_header_footer_color,
|
'login_header_footer_color' => $websiteType->login_header_footer_color,
|
||||||
'site_logo' => $websiteType->siteLogo?->getTemporaryUrl(1440),
|
'site_logo' => $websiteType->siteLogo?->getTemporaryUrl(1440),
|
||||||
'footer_logo' => $websiteType->footerLogo?->getTemporaryUrl(1440),
|
'footer_logo' => $websiteType->footerLogo?->getTemporaryUrl(1440),
|
||||||
'favicon' => $websiteType->favicon?->getTemporaryUrl(1440),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class AdminAppBootstrapService
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'website_type' => WebsiteType::query()
|
'website_type' => WebsiteType::query()
|
||||||
->with(['siteLogo', 'footerLogo', 'favicon'])
|
->with(['siteLogo', 'footerLogo'])
|
||||||
->where('dominio', $domain)
|
->where('dominio', $domain)
|
||||||
->firstOrFail(),
|
->firstOrFail(),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class ScannerBootstrapService
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'website_type' => WebsiteType::query()
|
'website_type' => WebsiteType::query()
|
||||||
->with(['siteLogo', 'footerLogo', 'favicon'])
|
->with(['siteLogo', 'footerLogo'])
|
||||||
->where('scanner_domain', $domain)
|
->where('scanner_domain', $domain)
|
||||||
->firstOrFail(),
|
->firstOrFail(),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -343,9 +343,9 @@ class StockReservationService
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clearExpirationForReview(Purchase $purchase): void
|
public function refreshForPurchase(Purchase $purchase, ?Carbon $expiresAt): void
|
||||||
{
|
{
|
||||||
DB::transaction(function () use ($purchase): void {
|
DB::transaction(function () use ($purchase, $expiresAt): void {
|
||||||
/** @var Purchase $purchase */
|
/** @var Purchase $purchase */
|
||||||
$purchase = Purchase::query()->lockForUpdate()->findOrFail($purchase->getKey());
|
$purchase = Purchase::query()->lockForUpdate()->findOrFail($purchase->getKey());
|
||||||
if ($purchase->stock_reservation_id === null) {
|
if ($purchase->stock_reservation_id === null) {
|
||||||
@@ -363,7 +363,7 @@ class StockReservationService
|
|||||||
throw new StockReservationExpiredException;
|
throw new StockReservationExpiredException;
|
||||||
}
|
}
|
||||||
|
|
||||||
$reservation->update(['expires_at' => null]);
|
$reservation->update(['expires_at' => $expiresAt]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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'],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
namespace App\Domains\Integration\Services;
|
namespace App\Domains\Integration\Services;
|
||||||
|
|
||||||
use App\Domains\Client\Models\Client;
|
use App\Domains\Client\Models\Client;
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
|
||||||
use App\Domains\Tenant\Models\WebsiteType;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Contracts\Mail\Factory as MailFactory;
|
use Illuminate\Contracts\Mail\Factory as MailFactory;
|
||||||
use Illuminate\Contracts\Mail\Mailer;
|
use Illuminate\Contracts\Mail\Mailer;
|
||||||
@@ -72,35 +70,24 @@ class MailService extends BaseIntegrationService
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function send(string|array $recipient, string $subject, string $content): void
|
||||||
* @param array<int, array{data: string, name: string, mime: string}> $attachments
|
{
|
||||||
*/
|
|
||||||
public function send(
|
|
||||||
string|array $recipient,
|
|
||||||
string $subject,
|
|
||||||
string $content,
|
|
||||||
Tenant|WebsiteType|null $brand = null,
|
|
||||||
array $attachments = [],
|
|
||||||
): void {
|
|
||||||
if (! $this->mailer || ! $this->tenant) {
|
if (! $this->mailer || ! $this->tenant) {
|
||||||
throw new Exception('MailService no está configurado. Llamá a forTenant() o forClient() primero.');
|
throw new Exception('MailService no está configurado. Llamá a forTenant() o forClient() primero.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$brand ??= $this->tenant;
|
$this->tenant->loadMissing(['headerLogo', 'footerLogo']);
|
||||||
$branding = $this->brandingFor($brand);
|
|
||||||
|
|
||||||
$html = Blade::render(
|
$html = Blade::render(
|
||||||
<<<'BLADE'
|
<<<'BLADE'
|
||||||
<x-mail.branded-layout :branding="$branding" :header-logo-url="$headerLogoUrl" :footer-logo-url="$footerLogoUrl">
|
<x-mail.branded-layout :tenant="$tenant" :header-logo-url="$headerLogoUrl" :footer-logo-url="$footerLogoUrl">
|
||||||
{!! $content !!}
|
{!! $content !!}
|
||||||
</x-mail.branded-layout>
|
</x-mail.branded-layout>
|
||||||
BLADE,
|
BLADE,
|
||||||
[
|
[
|
||||||
'branding' => $branding,
|
'tenant' => $this->tenant,
|
||||||
'headerLogoUrl' => $brand instanceof WebsiteType
|
'headerLogoUrl' => $this->tenant->headerLogo?->getTemporaryUrl(1440),
|
||||||
? $brand->siteLogo?->getTemporaryUrl(1440)
|
'footerLogoUrl' => $this->tenant->footerLogo?->getTemporaryUrl(1440),
|
||||||
: $brand->headerLogo?->getTemporaryUrl(1440),
|
|
||||||
'footerLogoUrl' => $brand->footerLogo?->getTemporaryUrl(1440),
|
|
||||||
'content' => $content,
|
'content' => $content,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@@ -109,14 +96,6 @@ class MailService extends BaseIntegrationService
|
|||||||
->subject($subject)
|
->subject($subject)
|
||||||
->html($html);
|
->html($html);
|
||||||
|
|
||||||
foreach ($attachments as $attachment) {
|
|
||||||
$mail->attachData(
|
|
||||||
$attachment['data'],
|
|
||||||
$attachment['name'],
|
|
||||||
['mime' => $attachment['mime']],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->mailer->to($recipient)->send($mail);
|
$this->mailer->to($recipient)->send($mail);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,36 +106,6 @@ class MailService extends BaseIntegrationService
|
|||||||
: (string) config('mail.default');
|
: (string) config('mail.default');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return array{name: string, primary_color: string, body_color: string, background_color: string, surface_color: string, header_bg_color: string, footer_bg_color: string} */
|
|
||||||
private function brandingFor(Tenant|WebsiteType $brand): array
|
|
||||||
{
|
|
||||||
if ($brand instanceof WebsiteType) {
|
|
||||||
$brand->loadMissing(['siteLogo', 'footerLogo']);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'name' => $brand->nombre,
|
|
||||||
'primary_color' => $brand->primary_color ?? '#FF7006',
|
|
||||||
'body_color' => $brand->body_color ?? '#666666',
|
|
||||||
'background_color' => $brand->background_color ?? '#f8f8f8',
|
|
||||||
'surface_color' => $brand->surface_color ?? '#ffffff',
|
|
||||||
'header_bg_color' => $brand->surface_color ?? '#ffffff',
|
|
||||||
'footer_bg_color' => $brand->login_header_footer_color ?? '#838383',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$brand->loadMissing(['headerLogo', 'footerLogo']);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'name' => $brand->nombre,
|
|
||||||
'primary_color' => $brand->primary_color ?? '#6376f3',
|
|
||||||
'body_color' => '#334155',
|
|
||||||
'background_color' => '#f1f5f9',
|
|
||||||
'surface_color' => '#ffffff',
|
|
||||||
'header_bg_color' => $brand->header_bg_color ?? '#ffffff',
|
|
||||||
'footer_bg_color' => $brand->footer_bg_color ?? '#334155',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onSetup(): void
|
public function onSetup(): void
|
||||||
{
|
{
|
||||||
if (! $this->mailer || ! $this->clientContext) {
|
if (! $this->mailer || ! $this->clientContext) {
|
||||||
|
|||||||
@@ -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');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,21 +28,10 @@ class TestMail extends Mailable
|
|||||||
{
|
{
|
||||||
$this->tenant->loadMissing(['headerLogo', 'footerLogo']);
|
$this->tenant->loadMissing(['headerLogo', 'footerLogo']);
|
||||||
|
|
||||||
$branding = [
|
|
||||||
'name' => $this->tenant->nombre,
|
|
||||||
'primary_color' => $this->tenant->primary_color ?? '#6376f3',
|
|
||||||
'body_color' => '#334155',
|
|
||||||
'background_color' => '#f1f5f9',
|
|
||||||
'surface_color' => '#ffffff',
|
|
||||||
'header_bg_color' => $this->tenant->header_bg_color ?? '#ffffff',
|
|
||||||
'footer_bg_color' => $this->tenant->footer_bg_color ?? '#334155',
|
|
||||||
];
|
|
||||||
|
|
||||||
return new Content(
|
return new Content(
|
||||||
view: 'mail.test',
|
view: 'mail.test',
|
||||||
with: [
|
with: [
|
||||||
'tenant' => $this->tenant,
|
'tenant' => $this->tenant,
|
||||||
'branding' => $branding,
|
|
||||||
'headerLogoUrl' => $this->tenant->headerLogo?->getTemporaryUrl(1440),
|
'headerLogoUrl' => $this->tenant->headerLogo?->getTemporaryUrl(1440),
|
||||||
'footerLogoUrl' => $this->tenant->footerLogo?->getTemporaryUrl(1440),
|
'footerLogoUrl' => $this->tenant->footerLogo?->getTemporaryUrl(1440),
|
||||||
],
|
],
|
||||||
|
|||||||
20
app/Domains/Notification/Events/TicketsAvailable.php
Normal file
20
app/Domains/Notification/Events/TicketsAvailable.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Notification\Events;
|
||||||
|
|
||||||
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
|
use Illuminate\Foundation\Events\Dispatchable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class TicketsAvailable
|
||||||
|
{
|
||||||
|
use Dispatchable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, int> $ticketIds
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
public readonly Purchase $purchase,
|
||||||
|
public readonly array $ticketIds,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
@@ -6,6 +6,8 @@ use App\Domains\Notification\Events\PasswordResetRequested;
|
|||||||
use App\Domains\Notification\Services\NotificationMailService;
|
use App\Domains\Notification\Services\NotificationMailService;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueueAfterCommit;
|
use Illuminate\Contracts\Queue\ShouldQueueAfterCommit;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
class SendPasswordResetEmail implements ShouldQueueAfterCommit
|
class SendPasswordResetEmail implements ShouldQueueAfterCommit
|
||||||
{
|
{
|
||||||
@@ -20,10 +22,21 @@ class SendPasswordResetEmail implements ShouldQueueAfterCommit
|
|||||||
|
|
||||||
public function handle(PasswordResetRequested $event): void
|
public function handle(PasswordResetRequested $event): void
|
||||||
{
|
{
|
||||||
app(NotificationMailService::class)->sendPasswordResetCode(
|
try {
|
||||||
$event->attemptId,
|
app(NotificationMailService::class)->sendPasswordResetCode(
|
||||||
$event->tenantCode,
|
$event->attemptId,
|
||||||
$event->channel,
|
$event->tenantCode,
|
||||||
);
|
$event->channel,
|
||||||
|
);
|
||||||
|
} catch (Throwable $exception) {
|
||||||
|
Log::error('Failed to send password reset email.', [
|
||||||
|
'attempt_id' => $event->attemptId,
|
||||||
|
'tenant_code' => $event->tenantCode,
|
||||||
|
'channel' => $event->channel,
|
||||||
|
'exception' => $exception,
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw $exception;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use App\Domains\Purchase\Events\PurchasePaid;
|
|||||||
use Illuminate\Contracts\Queue\ShouldQueueAfterCommit;
|
use Illuminate\Contracts\Queue\ShouldQueueAfterCommit;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
|
||||||
class SendPurchaseConfirmedEmail implements ShouldQueueAfterCommit
|
class SendPurchasePaidEmail implements ShouldQueueAfterCommit
|
||||||
{
|
{
|
||||||
use InteractsWithQueue;
|
use InteractsWithQueue;
|
||||||
|
|
||||||
@@ -20,6 +20,6 @@ class SendPurchaseConfirmedEmail implements ShouldQueueAfterCommit
|
|||||||
|
|
||||||
public function handle(PurchasePaid $event): void
|
public function handle(PurchasePaid $event): void
|
||||||
{
|
{
|
||||||
app(NotificationMailService::class)->sendPurchaseConfirmed($event->purchaseId);
|
app(NotificationMailService::class)->sendPurchasePaid($event->purchase->getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Notification\Listeners;
|
||||||
|
|
||||||
|
use App\Domains\Notification\Events\TicketsAvailable;
|
||||||
|
use App\Domains\Notification\Services\NotificationMailService;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueueAfterCommit;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
|
||||||
|
class SendTicketsAvailableEmail implements ShouldQueueAfterCommit
|
||||||
|
{
|
||||||
|
use InteractsWithQueue;
|
||||||
|
|
||||||
|
public string $queue = 'emails';
|
||||||
|
|
||||||
|
public int $tries = 3;
|
||||||
|
|
||||||
|
/** @var array<int, int> */
|
||||||
|
public array $backoff = [30, 120, 300];
|
||||||
|
|
||||||
|
public function handle(TicketsAvailable $event): void
|
||||||
|
{
|
||||||
|
app(NotificationMailService::class)->sendTicketsAvailable($event->purchase->getKey(), $event->ticketIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,43 +9,28 @@ use App\Domains\Notification\Events\PasswordResetRequested;
|
|||||||
use App\Domains\Purchase\Models\Purchase;
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
use App\Domains\Ticket\Models\Ticket;
|
use App\Domains\Ticket\Models\Ticket;
|
||||||
use App\Domains\Ticket\Services\TicketPdfService;
|
|
||||||
use App\Domains\Ticket\Services\TicketPresentationResolver;
|
use App\Domains\Ticket\Services\TicketPresentationResolver;
|
||||||
use Closure;
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Throwable;
|
|
||||||
|
|
||||||
class NotificationMailService
|
class NotificationMailService
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly MailService $mailService,
|
private readonly MailService $mailService,
|
||||||
private readonly TicketPdfService $ticketPdfService,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function sendWelcome(int $userId, string $tenantCode): void
|
public function sendWelcome(int $userId, string $tenantCode): void
|
||||||
{
|
{
|
||||||
$this->sendLogged('welcome', [
|
$tenant = Tenant::query()->where('codigo', $tenantCode)->firstOrFail();
|
||||||
'user_id' => $userId,
|
$user = User::query()->findOrFail($userId);
|
||||||
'tenant_code' => $tenantCode,
|
|
||||||
], function () use ($userId, $tenantCode): array {
|
|
||||||
$tenant = Tenant::query()->with('websiteType')->where('codigo', $tenantCode)->firstOrFail();
|
|
||||||
$user = User::query()->findOrFail($userId);
|
|
||||||
$brand = $tenant->websiteType ?? $tenant;
|
|
||||||
|
|
||||||
$this->mailService
|
$this->mailService
|
||||||
->forTenant($tenantCode)
|
->forTenant($tenantCode)
|
||||||
->send(
|
->send(
|
||||||
$user->email,
|
$user->email,
|
||||||
"Bienvenido a {$brand->nombre}",
|
"Bienvenido a {$tenant->nombre}",
|
||||||
view('mail.notifications.welcome', compact('brand', 'user'))->render(),
|
view('mail.notifications.welcome', compact('tenant', 'user'))->render(),
|
||||||
$brand,
|
);
|
||||||
);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'brand_type' => $tenant->websiteType === null ? 'tenant' : 'website_type',
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sendPasswordResetCode(
|
public function sendPasswordResetCode(
|
||||||
@@ -53,161 +38,95 @@ class NotificationMailService
|
|||||||
string $tenantCode,
|
string $tenantCode,
|
||||||
string $channel = PasswordResetRequested::CHANNEL_STOREFRONT,
|
string $channel = PasswordResetRequested::CHANNEL_STOREFRONT,
|
||||||
): void {
|
): void {
|
||||||
$context = [
|
$tenant = Tenant::query()
|
||||||
'attempt_id' => $attemptId,
|
->with('websiteType')
|
||||||
'tenant_code' => $tenantCode,
|
->where('codigo', $tenantCode)
|
||||||
'channel' => $channel,
|
->firstOrFail();
|
||||||
];
|
$attempt = ResetPasswordAttempt::query()
|
||||||
|
->with('user')
|
||||||
|
->findOrFail($attemptId);
|
||||||
|
|
||||||
$this->sendLogged('password_reset', $context, function () use ($attemptId, $tenantCode, $channel, $context): ?array {
|
if ($attempt->status !== ResetPasswordAttempt::STATUS_PENDING) {
|
||||||
$tenant = Tenant::query()
|
Log::warning('Password reset email was skipped because the attempt is no longer pending.', [
|
||||||
->with('websiteType')
|
'attempt_id' => $attemptId,
|
||||||
->where('codigo', $tenantCode)
|
'tenant_code' => $tenantCode,
|
||||||
->firstOrFail();
|
'attempt_status' => $attempt->status,
|
||||||
$attempt = ResetPasswordAttempt::query()
|
]);
|
||||||
->with('user')
|
|
||||||
->findOrFail($attemptId);
|
|
||||||
|
|
||||||
if ($attempt->status !== ResetPasswordAttempt::STATUS_PENDING) {
|
return;
|
||||||
$this->logSkipped('password_reset', array_merge($context, [
|
}
|
||||||
'reason' => 'attempt_not_pending',
|
|
||||||
'attempt_status' => $attempt->status,
|
|
||||||
'user_id' => $attempt->user_id,
|
|
||||||
]));
|
|
||||||
|
|
||||||
return null;
|
$recoveryDomain = match ($channel) {
|
||||||
}
|
PasswordResetRequested::CHANNEL_ADMINAPP => $tenant->websiteType?->dominio,
|
||||||
|
PasswordResetRequested::CHANNEL_SCANNER => $tenant->websiteType?->scanner_domain,
|
||||||
|
default => $tenant->dominio,
|
||||||
|
};
|
||||||
|
$recoveryBasePath = $channel === PasswordResetRequested::CHANNEL_STOREFRONT
|
||||||
|
&& $tenant->base_path !== '/'
|
||||||
|
? $tenant->base_path
|
||||||
|
: '';
|
||||||
|
$recoveryQuery = ['email' => $attempt->user->email];
|
||||||
|
if (
|
||||||
|
$channel === PasswordResetRequested::CHANNEL_SCANNER
|
||||||
|
&& $attempt->reason === ResetPasswordAttempt::REASON_STAFF_CREATED
|
||||||
|
) {
|
||||||
|
$recoveryQuery['code'] = $attempt->codigo;
|
||||||
|
}
|
||||||
|
$recoveryUrl = $recoveryDomain === null
|
||||||
|
? null
|
||||||
|
: 'https://'.$recoveryDomain.$recoveryBasePath.'/recuperar-contrasena/codigo?'.http_build_query($recoveryQuery);
|
||||||
|
|
||||||
$recoveryDomain = match ($channel) {
|
$this->mailService
|
||||||
PasswordResetRequested::CHANNEL_ADMINAPP => $tenant->websiteType?->dominio,
|
->forTenant($tenantCode)
|
||||||
PasswordResetRequested::CHANNEL_SCANNER => $tenant->websiteType?->scanner_domain,
|
->send(
|
||||||
default => $tenant->dominio,
|
$attempt->user->email,
|
||||||
};
|
"Código para recuperar tu contraseña - {$tenant->nombre}",
|
||||||
$recoveryBasePath = $channel === PasswordResetRequested::CHANNEL_STOREFRONT
|
view('mail.notifications.password-reset', compact('tenant', 'attempt', 'recoveryUrl'))->render(),
|
||||||
&& $tenant->base_path !== '/'
|
);
|
||||||
? $tenant->base_path
|
|
||||||
: '';
|
|
||||||
$recoveryQuery = ['email' => $attempt->user->email];
|
|
||||||
if (
|
|
||||||
$channel === PasswordResetRequested::CHANNEL_SCANNER
|
|
||||||
&& $attempt->reason === ResetPasswordAttempt::REASON_STAFF_CREATED
|
|
||||||
) {
|
|
||||||
$recoveryQuery['code'] = $attempt->codigo;
|
|
||||||
}
|
|
||||||
$recoveryUrl = $recoveryDomain === null
|
|
||||||
? null
|
|
||||||
: 'https://'.$recoveryDomain.$recoveryBasePath.'/recuperar-contrasena/codigo?'.http_build_query($recoveryQuery);
|
|
||||||
$brand = $tenant->websiteType ?? $tenant;
|
|
||||||
|
|
||||||
$this->mailService
|
|
||||||
->forTenant($tenantCode)
|
|
||||||
->send(
|
|
||||||
$attempt->user->email,
|
|
||||||
"Código para recuperar tu contraseña - {$brand->nombre}",
|
|
||||||
view('mail.notifications.password-reset', [
|
|
||||||
'attempt' => $attempt,
|
|
||||||
'recoveryUrl' => $recoveryUrl,
|
|
||||||
'brand' => $brand,
|
|
||||||
])->render(),
|
|
||||||
$brand,
|
|
||||||
);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'user_id' => $attempt->user_id,
|
|
||||||
'recovery_domain_available' => $recoveryDomain !== null,
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sendPurchaseConfirmed(int $purchaseId): void
|
public function sendPurchasePaid(int $purchaseId): void
|
||||||
{
|
{
|
||||||
$context = ['purchase_id' => $purchaseId];
|
$purchase = Purchase::query()
|
||||||
|
->with(['tenant', 'user', 'items'])
|
||||||
|
->findOrFail($purchaseId);
|
||||||
|
|
||||||
$this->sendLogged('purchase_confirmed', $context, function () use ($purchaseId, $context): ?array {
|
$this->mailService
|
||||||
$purchase = Purchase::query()
|
->forTenant($purchase->tenant_codigo)
|
||||||
->with(['tenant', 'user', 'items'])
|
->send(
|
||||||
->find($purchaseId);
|
$this->recipientFor($purchase),
|
||||||
|
"Pago confirmado - Compra #{$purchase->getKey()}",
|
||||||
|
view('mail.notifications.purchase-paid', compact('purchase'))->render(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if ($purchase === null) {
|
/** @param array<int, int> $ticketIds */
|
||||||
$this->logSkipped('purchase_confirmed', array_merge($context, [
|
public function sendTicketsAvailable(int $purchaseId, array $ticketIds): void
|
||||||
'reason' => 'purchase_not_found',
|
{
|
||||||
'missing_model' => Purchase::class,
|
$purchase = Purchase::query()->with(['tenant', 'user'])->findOrFail($purchaseId);
|
||||||
]));
|
/** @var Collection<int, Ticket> $tickets */
|
||||||
|
$tickets = Ticket::query()
|
||||||
|
->where('tenant_code', $purchase->tenant_codigo)
|
||||||
|
->where('user_id', $purchase->user_id)
|
||||||
|
->whereKey($ticketIds)
|
||||||
|
->with(TicketPresentationResolver::RELATIONS)
|
||||||
|
->get();
|
||||||
|
|
||||||
return null;
|
if ($tickets->isEmpty()) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/** @var Collection<int, Ticket> $tickets */
|
$this->mailService
|
||||||
$tickets = Ticket::query()
|
->forTenant($purchase->tenant_codigo)
|
||||||
->where('source_purchase_id', $purchase->getKey())
|
->send(
|
||||||
->where('tenant_code', $purchase->tenant_codigo)
|
$this->recipientFor($purchase),
|
||||||
->with(TicketPresentationResolver::RELATIONS)
|
'Tus tickets ya están disponibles',
|
||||||
->get();
|
view('mail.notifications.tickets-available', compact('purchase', 'tickets'))->render(),
|
||||||
$attachments = $tickets->isEmpty()
|
);
|
||||||
? []
|
|
||||||
: [[
|
|
||||||
'data' => $this->ticketPdfService->contents($purchase->tenant, $tickets),
|
|
||||||
'name' => $this->ticketPdfService->filename($tickets),
|
|
||||||
'mime' => 'application/pdf',
|
|
||||||
]];
|
|
||||||
|
|
||||||
$this->mailService
|
|
||||||
->forTenant($purchase->tenant_codigo)
|
|
||||||
->send(
|
|
||||||
$this->recipientFor($purchase),
|
|
||||||
"Compra confirmada - Compra #{$purchase->getKey()}",
|
|
||||||
view('mail.notifications.purchase-confirmed', compact('purchase', 'tickets'))->render(),
|
|
||||||
attachments: $attachments,
|
|
||||||
);
|
|
||||||
|
|
||||||
return [
|
|
||||||
'tenant_code' => $purchase->tenant_codigo,
|
|
||||||
'user_id' => $purchase->user_id,
|
|
||||||
'purchase_status' => $purchase->status,
|
|
||||||
'purchase_item_count' => $purchase->items->count(),
|
|
||||||
'ticket_count' => $tickets->count(),
|
|
||||||
'ticket_ids' => $tickets->modelKeys(),
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function recipientFor(Purchase $purchase): string
|
private function recipientFor(Purchase $purchase): string
|
||||||
{
|
{
|
||||||
return (string) ($purchase->email ?: $purchase->user?->email);
|
return (string) ($purchase->email ?: $purchase->user?->email);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array<string, mixed> $context
|
|
||||||
* @param Closure(): (array<string, mixed>|null) $send
|
|
||||||
*/
|
|
||||||
private function sendLogged(string $emailType, array $context, Closure $send): void
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$resultContext = $send();
|
|
||||||
|
|
||||||
if ($resultContext === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log::channel('emails')->info('Notification email sent.', array_merge($context, $resultContext, [
|
|
||||||
'email_type' => $emailType,
|
|
||||||
'mailer' => $this->mailService->mailerName(),
|
|
||||||
]));
|
|
||||||
} catch (Throwable $exception) {
|
|
||||||
Log::channel('emails')->error('Notification email delivery failed.', array_merge($context, [
|
|
||||||
'email_type' => $emailType,
|
|
||||||
'exception' => $exception,
|
|
||||||
]));
|
|
||||||
|
|
||||||
throw $exception;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param array<string, mixed> $context */
|
|
||||||
private function logSkipped(string $emailType, array $context): void
|
|
||||||
{
|
|
||||||
Log::channel('emails')->warning('Notification email skipped.', array_merge($context, [
|
|
||||||
'email_type' => $emailType,
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,12 @@ Orquesta notificaciones de negocio por correo a partir de eventos de otros domin
|
|||||||
|
|
||||||
- `UserRegistered`: dispara el correo de bienvenida.
|
- `UserRegistered`: dispara el correo de bienvenida.
|
||||||
- `PasswordResetRequested`: envía el código de recuperación si el intento sigue pendiente.
|
- `PasswordResetRequested`: envía el código de recuperación si el intento sigue pendiente.
|
||||||
- `PurchasePaid`: envía la confirmación de compra y adjunta los tickets generados, cuando corresponde.
|
- `PurchasePaid`: envía la confirmación de pago.
|
||||||
|
- `TicketsAvailable`: informa y entrega la disponibilidad de tickets.
|
||||||
|
|
||||||
## Componentes
|
## Componentes
|
||||||
|
|
||||||
Los listeners `SendWelcomeEmail`, `SendPasswordResetEmail` y `SendPurchaseConfirmedEmail` delegan en `NotificationMailService`. Este servicio carga el contexto necesario, renderiza las vistas y envía mediante `Integration/MailService`.
|
Los listeners `SendWelcomeEmail`, `SendPasswordResetEmail`, `SendPurchasePaidEmail` y `SendTicketsAvailableEmail` delegan en `NotificationMailService`. Este servicio carga el contexto necesario, renderiza las vistas y envía mediante `Integration/MailService`.
|
||||||
|
|
||||||
## API y dependencias
|
## API y dependencias
|
||||||
|
|
||||||
@@ -22,6 +23,4 @@ No expone rutas HTTP. Consume datos de `Auth`, `Tenant`, `Purchase` y `Ticket`,
|
|||||||
|
|
||||||
- Los listeners reciben identificadores y vuelven a cargar los modelos, evitando transportar entidades obsoletas.
|
- Los listeners reciben identificadores y vuelven a cargar los modelos, evitando transportar entidades obsoletas.
|
||||||
- La recuperación no se envía si el intento dejó de estar pendiente.
|
- La recuperación no se envía si el intento dejó de estar pendiente.
|
||||||
- Los correos de cuenta (bienvenida y recuperación de contraseña) usan la identidad visual del `WebsiteType` asociado al tenant, con fallback al tenant si no tiene uno configurado.
|
|
||||||
- El correo transaccional de compra confirmada usa la identidad visual del tenant y adjunta un único PDF cuando la compra generó tickets.
|
|
||||||
- Los handlers deben permanecer idempotentes o tolerantes a reintentos de cola.
|
- Los handlers deben permanecer idempotentes o tolerantes a reintentos de cola.
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ class PurchaseController extends Controller
|
|||||||
PaymentIntentRequest $request,
|
PaymentIntentRequest $request,
|
||||||
Tenant $tenant,
|
Tenant $tenant,
|
||||||
Purchase $compra,
|
Purchase $compra,
|
||||||
|
CheckoutService $checkoutService,
|
||||||
PurchaseStateGuard $purchaseState,
|
PurchaseStateGuard $purchaseState,
|
||||||
): JsonResponse {
|
): JsonResponse {
|
||||||
$compra = $this->resolveScopedPurchase($tenant, $request->user()->id, $compra);
|
$compra = $this->resolveScopedPurchase($tenant, $request->user()->id, $compra);
|
||||||
@@ -102,6 +103,7 @@ class PurchaseController extends Controller
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
$updated = DB::transaction(function () use (
|
$updated = DB::transaction(function () use (
|
||||||
|
$checkoutService,
|
||||||
$compra,
|
$compra,
|
||||||
$method,
|
$method,
|
||||||
$purchaseState,
|
$purchaseState,
|
||||||
@@ -140,6 +142,12 @@ class PurchaseController extends Controller
|
|||||||
$purchaseUpdate['transfer_payer_dni'] = $transferPayerDni;
|
$purchaseUpdate['transfer_payer_dni'] = $transferPayerDni;
|
||||||
}
|
}
|
||||||
$purchase->update($purchaseUpdate);
|
$purchase->update($purchaseUpdate);
|
||||||
|
$checkoutService->refreshReservationExpiration(
|
||||||
|
$purchase,
|
||||||
|
now()->addMinutes(
|
||||||
|
max(1, (int) config("purchase.payment_expiration_minutes.{$method}", 30)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Domains\Purchase\Events;
|
namespace App\Domains\Purchase\Events;
|
||||||
|
|
||||||
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
use Illuminate\Foundation\Events\Dispatchable;
|
use Illuminate\Foundation\Events\Dispatchable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
@@ -9,5 +10,5 @@ class PurchasePaid
|
|||||||
{
|
{
|
||||||
use Dispatchable, SerializesModels;
|
use Dispatchable, SerializesModels;
|
||||||
|
|
||||||
public function __construct(public readonly int $purchaseId) {}
|
public function __construct(public readonly Purchase $purchase) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
||||||
@@ -199,7 +193,7 @@ class Purchase extends Model
|
|||||||
'status' => self::STATUS_PAID,
|
'status' => self::STATUS_PAID,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
PurchasePaid::dispatch($this->getKey());
|
PurchasePaid::dispatch($this);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
@@ -18,15 +17,12 @@ class PurchaseResource extends JsonResource
|
|||||||
*/
|
*/
|
||||||
public function toArray(Request $request): array
|
public function toArray(Request $request): array
|
||||||
{
|
{
|
||||||
$serverTime = now();
|
|
||||||
$expiresAt = $this->stockReservation?->expires_at;
|
|
||||||
$items = $this->resource->relationLoaded('items')
|
$items = $this->resource->relationLoaded('items')
|
||||||
? $this->resource->getRelation('items')
|
? $this->resource->getRelation('items')
|
||||||
: collect();
|
: collect();
|
||||||
$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(
|
||||||
@@ -52,11 +48,7 @@ class PurchaseResource extends JsonResource
|
|||||||
'created_at' => $this->created_at,
|
'created_at' => $this->created_at,
|
||||||
'status' => $this->status,
|
'status' => $this->status,
|
||||||
'payment_method' => $this->payment_method,
|
'payment_method' => $this->payment_method,
|
||||||
'expires_at' => $expiresAt,
|
'expires_at' => $this->stockReservation?->expires_at,
|
||||||
'expires_in_seconds' => $expiresAt === null
|
|
||||||
? null
|
|
||||||
: max(0, $expiresAt->getTimestamp() - $serverTime->getTimestamp()),
|
|
||||||
'server_time' => $serverTime,
|
|
||||||
'dni' => $this->dni,
|
'dni' => $this->dni,
|
||||||
'transfer_payer_dni' => $this->transfer_payer_dni,
|
'transfer_payer_dni' => $this->transfer_payer_dni,
|
||||||
'telefono' => $this->telefono,
|
'telefono' => $this->telefono,
|
||||||
@@ -66,7 +58,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 +77,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,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ class CompleteCheckoutService
|
|||||||
$purchase->update([
|
$purchase->update([
|
||||||
'status' => Purchase::STATUS_IN_REVIEW,
|
'status' => Purchase::STATUS_IN_REVIEW,
|
||||||
]);
|
]);
|
||||||
$this->reservations->clearExpirationForReview($purchase);
|
$this->reservations->refreshForPurchase($purchase, null);
|
||||||
|
|
||||||
return $this->loadPurchase($purchase);
|
return $this->loadPurchase($purchase);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Domains\Purchase\Services;
|
namespace App\Domains\Purchase\Services;
|
||||||
|
|
||||||
|
use App\Domains\Catalog\Services\StockReservationService;
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
use App\Domains\Purchase\Services\Checkout\CompleteCheckoutService;
|
use App\Domains\Purchase\Services\Checkout\CompleteCheckoutService;
|
||||||
use App\Domains\Purchase\Services\Checkout\EditCheckoutService;
|
use App\Domains\Purchase\Services\Checkout\EditCheckoutService;
|
||||||
use App\Domains\Purchase\Services\Checkout\ReleaseCheckoutService;
|
use App\Domains\Purchase\Services\Checkout\ReleaseCheckoutService;
|
||||||
use App\Domains\Purchase\Services\Checkout\StartCheckoutService;
|
use App\Domains\Purchase\Services\Checkout\StartCheckoutService;
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,6 +24,7 @@ class CheckoutService
|
|||||||
private readonly EditCheckoutService $editor,
|
private readonly EditCheckoutService $editor,
|
||||||
private readonly CompleteCheckoutService $completer,
|
private readonly CompleteCheckoutService $completer,
|
||||||
private readonly ReleaseCheckoutService $releaser,
|
private readonly ReleaseCheckoutService $releaser,
|
||||||
|
private readonly StockReservationService $reservations,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/** @param array<string, mixed> $purchaseData */
|
/** @param array<string, mixed> $purchaseData */
|
||||||
@@ -75,4 +78,9 @@ class CheckoutService
|
|||||||
{
|
{
|
||||||
return $this->releaser->expire($purchase);
|
return $this->releaser->expire($purchase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function refreshReservationExpiration(Purchase $purchase, ?Carbon $expiresAt): void
|
||||||
|
{
|
||||||
|
$this->reservations->refreshForPurchase($purchase, $expiresAt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,21 +9,18 @@ use App\Domains\Sale\Resources\AdminApp\SaleDetailResource;
|
|||||||
use App\Domains\Sale\Resources\AdminApp\SaleModificationResource;
|
use App\Domains\Sale\Resources\AdminApp\SaleModificationResource;
|
||||||
use App\Domains\Sale\Resources\AdminApp\SaleResource;
|
use App\Domains\Sale\Resources\AdminApp\SaleResource;
|
||||||
use App\Domains\Sale\Resources\AdminApp\SaleTicketResource;
|
use App\Domains\Sale\Resources\AdminApp\SaleTicketResource;
|
||||||
use App\Domains\Sale\Services\AdminAppSaleExcelService;
|
|
||||||
use App\Domains\Sale\Services\AdminAppSalePdfService;
|
use App\Domains\Sale\Services\AdminAppSalePdfService;
|
||||||
use App\Domains\Sale\Services\AdminAppSaleService;
|
use App\Domains\Sale\Services\AdminAppSaleService;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
||||||
|
|
||||||
class SaleController extends Controller
|
class SaleController extends Controller
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected AdminAppSaleService $saleService,
|
protected AdminAppSaleService $saleService,
|
||||||
protected AdminAppSalePdfService $salePdfService,
|
protected AdminAppSalePdfService $salePdfService,
|
||||||
protected AdminAppSaleExcelService $saleExcelService,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function index(AdminAppSaleIndexRequest $request): AnonymousResourceCollection
|
public function index(AdminAppSaleIndexRequest $request): AnonymousResourceCollection
|
||||||
@@ -97,27 +94,4 @@ class SaleController extends Controller
|
|||||||
$request->validated('timezone'),
|
$request->validated('timezone'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function downloadExcel(AdminAppSalePdfRequest $request): StreamedResponse
|
|
||||||
{
|
|
||||||
$tenant = $request->user()->tenant()->firstOrFail();
|
|
||||||
|
|
||||||
return $this->saleExcelService->downloadSales(
|
|
||||||
$tenant,
|
|
||||||
$this->saleService->salesForExport($tenant, $request->validated()),
|
|
||||||
$request->validated('timezone'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function downloadModificationsExcel(
|
|
||||||
AdminAppSaleModificationPdfRequest $request,
|
|
||||||
): StreamedResponse {
|
|
||||||
$tenant = $request->user()->tenant()->firstOrFail();
|
|
||||||
|
|
||||||
return $this->saleExcelService->downloadModifications(
|
|
||||||
$tenant,
|
|
||||||
$this->saleService->modificationsForExport($tenant),
|
|
||||||
$request->validated('timezone'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,211 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Domains\Sale\Services;
|
|
||||||
|
|
||||||
use App\Domains\Logging\Models\ValueChange;
|
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Cell\DataType;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
||||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
||||||
|
|
||||||
class AdminAppSaleExcelService
|
|
||||||
{
|
|
||||||
/** @param Collection<int, Purchase> $sales */
|
|
||||||
public function downloadSales(Tenant $tenant, Collection $sales, string $timeZone): StreamedResponse
|
|
||||||
{
|
|
||||||
$generatedAt = now();
|
|
||||||
$spreadsheet = $this->spreadsheet($tenant, 'Historial de ventas');
|
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
|
||||||
$sheet->setTitle('Ventas');
|
|
||||||
$sheet->fromArray([
|
|
||||||
'ID',
|
|
||||||
'Fecha',
|
|
||||||
'Cliente',
|
|
||||||
'Cantidad',
|
|
||||||
'Estado',
|
|
||||||
'Importe',
|
|
||||||
'Tickets',
|
|
||||||
], null, 'A1');
|
|
||||||
|
|
||||||
foreach ($sales->values() as $index => $sale) {
|
|
||||||
$row = $index + 2;
|
|
||||||
$sheet->setCellValueExplicit("A{$row}", '#'.$sale->id, DataType::TYPE_STRING);
|
|
||||||
if ($sale->created_at) {
|
|
||||||
$sheet->setCellValue(
|
|
||||||
"B{$row}",
|
|
||||||
Date::dateTimeToExcel($sale->created_at->copy()->timezone($timeZone)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
$sheet->setCellValueExplicit(
|
|
||||||
"C{$row}",
|
|
||||||
$sale->nombre_apellido ?: 'Sin nombre',
|
|
||||||
DataType::TYPE_STRING,
|
|
||||||
);
|
|
||||||
$sheet->setCellValue("D{$row}", (int) ($sale->quantity ?? 0));
|
|
||||||
$sheet->setCellValue("E{$row}", $this->saleStatus($sale->status));
|
|
||||||
$sheet->setCellValue("F{$row}", (float) $sale->total);
|
|
||||||
$sheet->setCellValue("G{$row}", (int) ($sale->tickets_count ?? 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
$lastRow = max(2, $sales->count() + 1);
|
|
||||||
$sheet->getStyle("B2:B{$lastRow}")->getNumberFormat()->setFormatCode('dd/mm/yyyy hh:mm');
|
|
||||||
$sheet->getStyle("F2:F{$lastRow}")->getNumberFormat()->setFormatCode('$ #,##0.00');
|
|
||||||
$this->formatSheet($spreadsheet, 'A1:G1', "A1:G{$lastRow}", [
|
|
||||||
'A' => 13,
|
|
||||||
'B' => 20,
|
|
||||||
'C' => 32,
|
|
||||||
'D' => 12,
|
|
||||||
'E' => 22,
|
|
||||||
'F' => 16,
|
|
||||||
'G' => 12,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $this->download(
|
|
||||||
$spreadsheet,
|
|
||||||
'ventas_'.$tenant->codigo.'_'
|
|
||||||
.$generatedAt->copy()->timezone($timeZone)->format('Ymd_His').'.xlsx',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param Collection<int, ValueChange> $modifications */
|
|
||||||
public function downloadModifications(
|
|
||||||
Tenant $tenant,
|
|
||||||
Collection $modifications,
|
|
||||||
string $timeZone,
|
|
||||||
): StreamedResponse {
|
|
||||||
$generatedAt = now();
|
|
||||||
$spreadsheet = $this->spreadsheet($tenant, 'Historial de modificaciones de ventas');
|
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
|
||||||
$sheet->setTitle('Modificaciones');
|
|
||||||
$sheet->fromArray([
|
|
||||||
'Fecha',
|
|
||||||
'Hora',
|
|
||||||
'Venta',
|
|
||||||
'Cliente',
|
|
||||||
'Campo',
|
|
||||||
'Valor anterior',
|
|
||||||
'Valor nuevo',
|
|
||||||
'Modificado por',
|
|
||||||
], null, 'A1');
|
|
||||||
|
|
||||||
foreach ($modifications->values() as $index => $modification) {
|
|
||||||
$row = $index + 2;
|
|
||||||
$changedAt = $modification->changed_at->copy()->timezone($timeZone);
|
|
||||||
$sale = $modification->trackable;
|
|
||||||
$sheet->setCellValue("A{$row}", Date::dateTimeToExcel($changedAt));
|
|
||||||
$sheet->setCellValue("B{$row}", Date::dateTimeToExcel($changedAt));
|
|
||||||
$sheet->setCellValueExplicit(
|
|
||||||
"C{$row}",
|
|
||||||
'#'.$modification->trackable_id,
|
|
||||||
DataType::TYPE_STRING,
|
|
||||||
);
|
|
||||||
$sheet->setCellValueExplicit(
|
|
||||||
"D{$row}",
|
|
||||||
$sale?->nombre_apellido ?: 'Sin nombre',
|
|
||||||
DataType::TYPE_STRING,
|
|
||||||
);
|
|
||||||
$sheet->setCellValueExplicit(
|
|
||||||
"E{$row}",
|
|
||||||
$modification->attribute,
|
|
||||||
DataType::TYPE_STRING,
|
|
||||||
);
|
|
||||||
$sheet->setCellValueExplicit(
|
|
||||||
"F{$row}",
|
|
||||||
$modification->old_value ?? '-',
|
|
||||||
DataType::TYPE_STRING,
|
|
||||||
);
|
|
||||||
$sheet->setCellValueExplicit(
|
|
||||||
"G{$row}",
|
|
||||||
$modification->new_value ?? '-',
|
|
||||||
DataType::TYPE_STRING,
|
|
||||||
);
|
|
||||||
$sheet->setCellValueExplicit(
|
|
||||||
"H{$row}",
|
|
||||||
$modification->user?->nombre_apellido ?? 'Sistema',
|
|
||||||
DataType::TYPE_STRING,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$lastRow = max(2, $modifications->count() + 1);
|
|
||||||
$sheet->getStyle("A2:A{$lastRow}")->getNumberFormat()->setFormatCode('dd/mm/yyyy');
|
|
||||||
$sheet->getStyle("B2:B{$lastRow}")->getNumberFormat()->setFormatCode('hh:mm:ss');
|
|
||||||
$this->formatSheet($spreadsheet, 'A1:H1', "A1:H{$lastRow}", [
|
|
||||||
'A' => 14,
|
|
||||||
'B' => 12,
|
|
||||||
'C' => 13,
|
|
||||||
'D' => 32,
|
|
||||||
'E' => 20,
|
|
||||||
'F' => 24,
|
|
||||||
'G' => 24,
|
|
||||||
'H' => 28,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $this->download(
|
|
||||||
$spreadsheet,
|
|
||||||
'historial_modificaciones_'.$tenant->codigo.'_'
|
|
||||||
.$generatedAt->copy()->timezone($timeZone)->format('Ymd_His').'.xlsx',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function spreadsheet(Tenant $tenant, string $title): Spreadsheet
|
|
||||||
{
|
|
||||||
$spreadsheet = new Spreadsheet;
|
|
||||||
$spreadsheet->getProperties()
|
|
||||||
->setCreator('Shopit')
|
|
||||||
->setTitle($title)
|
|
||||||
->setSubject($tenant->nombre);
|
|
||||||
|
|
||||||
return $spreadsheet;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param array<string, int> $widths */
|
|
||||||
private function formatSheet(
|
|
||||||
Spreadsheet $spreadsheet,
|
|
||||||
string $headerRange,
|
|
||||||
string $filterRange,
|
|
||||||
array $widths,
|
|
||||||
): void {
|
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
|
||||||
$sheet->getStyle($headerRange)->applyFromArray([
|
|
||||||
'font' => ['bold' => true, 'color' => ['rgb' => 'FFFFFF']],
|
|
||||||
'fill' => [
|
|
||||||
'fillType' => Fill::FILL_SOLID,
|
|
||||||
'startColor' => ['rgb' => '26382E'],
|
|
||||||
],
|
|
||||||
'alignment' => ['vertical' => Alignment::VERTICAL_CENTER],
|
|
||||||
]);
|
|
||||||
$sheet->getRowDimension(1)->setRowHeight(24);
|
|
||||||
$sheet->freezePane('A2');
|
|
||||||
$sheet->setAutoFilter($filterRange);
|
|
||||||
|
|
||||||
foreach ($widths as $column => $width) {
|
|
||||||
$sheet->getColumnDimension($column)->setWidth($width);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function download(Spreadsheet $spreadsheet, string $filename): StreamedResponse
|
|
||||||
{
|
|
||||||
return response()->streamDownload(function () use ($spreadsheet): void {
|
|
||||||
(new Xlsx($spreadsheet))->save('php://output');
|
|
||||||
$spreadsheet->disconnectWorksheets();
|
|
||||||
}, $filename, [
|
|
||||||
'Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function saleStatus(string $status): string
|
|
||||||
{
|
|
||||||
return match ($status) {
|
|
||||||
Purchase::STATUS_PAID => 'Confirmado',
|
|
||||||
Purchase::STATUS_CREATED => 'Por completar datos',
|
|
||||||
Purchase::STATUS_PENDING_PAYMENT, Purchase::STATUS_IN_REVIEW => 'Esperando pago',
|
|
||||||
default => 'Anulado',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,6 @@ Provee consultas administrativas y exportaciones de ventas confirmadas, además
|
|||||||
|
|
||||||
- `AdminAppSaleService`: pagina ventas, calcula totales y obtiene colecciones para exportación; también consulta modificaciones.
|
- `AdminAppSaleService`: pagina ventas, calcula totales y obtiene colecciones para exportación; también consulta modificaciones.
|
||||||
- `AdminAppSalePdfService`: genera descargas PDF de ventas y de cambios.
|
- `AdminAppSalePdfService`: genera descargas PDF de ventas y de cambios.
|
||||||
- `AdminAppSaleExcelService`: genera descargas Excel de ventas y de cambios.
|
|
||||||
- `AdminAppSaleIndexRequest`: valida filtros del listado y la exportación.
|
- `AdminAppSaleIndexRequest`: valida filtros del listado y la exportación.
|
||||||
- `SaleResource` y `SaleModificationResource`: representan ventas e historial para AdminApp.
|
- `SaleResource` y `SaleModificationResource`: representan ventas e historial para AdminApp.
|
||||||
- `SaleController`: entrada HTTP del panel.
|
- `SaleController`: entrada HTTP del panel.
|
||||||
@@ -17,8 +16,8 @@ Provee consultas administrativas y exportaciones de ventas confirmadas, además
|
|||||||
|
|
||||||
Bajo `/v1/adminapp/tenant`, protegidos por `auth:sanctum` y `adminapp.tenant`:
|
Bajo `/v1/adminapp/tenant`, protegidos por `auth:sanctum` y `adminapp.tenant`:
|
||||||
|
|
||||||
- `GET /sales`, `GET /sales/pdf` y `GET /sales/excel`.
|
- `GET /sales` y `GET /sales/pdf`.
|
||||||
- `GET /sales/modifications`, `GET /sales/modifications/pdf` y `GET /sales/modifications/excel`.
|
- `GET /sales/modifications` y `GET /sales/modifications/pdf`.
|
||||||
|
|
||||||
## Dependencias
|
## Dependencias
|
||||||
|
|
||||||
@@ -26,4 +25,4 @@ Consume compras de `Purchase`, datos del tenant y entradas de `Logging`. No es d
|
|||||||
|
|
||||||
## Consideraciones
|
## Consideraciones
|
||||||
|
|
||||||
La consulta paginada y la colección de exportación deben aplicar los mismos filtros para evitar diferencias entre pantalla, PDF y Excel.
|
La consulta paginada y la colección de exportación deben aplicar los mismos filtros para evitar diferencias entre pantalla y PDF.
|
||||||
|
|||||||
@@ -8,10 +8,8 @@ Route::prefix('v1/adminapp/tenant')
|
|||||||
->group(function (): void {
|
->group(function (): void {
|
||||||
Route::get('sales', [SaleController::class, 'index']);
|
Route::get('sales', [SaleController::class, 'index']);
|
||||||
Route::get('sales/pdf', [SaleController::class, 'downloadPdf']);
|
Route::get('sales/pdf', [SaleController::class, 'downloadPdf']);
|
||||||
Route::get('sales/excel', [SaleController::class, 'downloadExcel']);
|
|
||||||
Route::get('sales/modifications', [SaleController::class, 'modifications']);
|
Route::get('sales/modifications', [SaleController::class, 'modifications']);
|
||||||
Route::get('sales/modifications/pdf', [SaleController::class, 'downloadModificationsPdf']);
|
Route::get('sales/modifications/pdf', [SaleController::class, 'downloadModificationsPdf']);
|
||||||
Route::get('sales/modifications/excel', [SaleController::class, 'downloadModificationsExcel']);
|
|
||||||
Route::post('sales/{sale}/confirm', [SaleController::class, 'confirm'])->whereNumber('sale');
|
Route::post('sales/{sale}/confirm', [SaleController::class, 'confirm'])->whereNumber('sale');
|
||||||
Route::post('sales/{sale}/cancel', [SaleController::class, 'cancel'])->whereNumber('sale');
|
Route::post('sales/{sale}/cancel', [SaleController::class, 'cancel'])->whereNumber('sale');
|
||||||
Route::get('sales/{sale}/tickets', [SaleController::class, 'tickets'])->whereNumber('sale');
|
Route::get('sales/{sale}/tickets', [SaleController::class, 'tickets'])->whereNumber('sale');
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ class WebsiteTypeService
|
|||||||
&& $previousLogo->id !== $websiteType->site_logo
|
&& $previousLogo->id !== $websiteType->site_logo
|
||||||
&& $previousLogo->id !== $websiteType->footer_logo
|
&& $previousLogo->id !== $websiteType->footer_logo
|
||||||
&& $previousLogo->id !== $websiteType->favicon_id
|
&& $previousLogo->id !== $websiteType->favicon_id
|
||||||
&& ! $this->isReferencedByWebsiteType($previousLogo)
|
|
||||||
) {
|
) {
|
||||||
$this->attachmentService->delete($previousLogo);
|
$this->attachmentService->delete($previousLogo);
|
||||||
}
|
}
|
||||||
@@ -91,16 +90,4 @@ class WebsiteTypeService
|
|||||||
return $websiteType;
|
return $websiteType;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private function isReferencedByWebsiteType(Attachment $attachment): bool
|
|
||||||
{
|
|
||||||
return WebsiteType::query()
|
|
||||||
->where(function ($query) use ($attachment): void {
|
|
||||||
$query
|
|
||||||
->where('site_logo', $attachment->id)
|
|
||||||
->orWhere('footer_logo', $attachment->id)
|
|
||||||
->orWhere('favicon_id', $attachment->id);
|
|
||||||
})
|
|
||||||
->exists();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
namespace App\Domains\Ticket\Listeners;
|
namespace App\Domains\Ticket\Listeners;
|
||||||
|
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
|
use App\Domains\Notification\Events\TicketsAvailable;
|
||||||
use App\Domains\Purchase\Events\PurchasePaid;
|
use App\Domains\Purchase\Events\PurchasePaid;
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
|
||||||
use App\Domains\Ticket\Exceptions\TicketGenerationException;
|
use App\Domains\Ticket\Exceptions\TicketGenerationException;
|
||||||
use App\Domains\Ticket\Services\TicketGeneratorService;
|
use App\Domains\Ticket\Services\TicketGeneratorService;
|
||||||
|
|
||||||
@@ -16,10 +16,13 @@ class GenerateTicketsForPaidPurchase
|
|||||||
|
|
||||||
public function handle(PurchasePaid $event): void
|
public function handle(PurchasePaid $event): void
|
||||||
{
|
{
|
||||||
$purchase = Purchase::query()
|
$purchase = $event->purchase
|
||||||
|
->newQuery()
|
||||||
->with(['user', 'items'])
|
->with(['user', 'items'])
|
||||||
->findOrFail($event->purchaseId);
|
->findOrFail($event->purchase->getKey());
|
||||||
$user = $purchase->user;
|
$user = $purchase->user;
|
||||||
|
$ticketIds = [];
|
||||||
|
|
||||||
foreach ($purchase->items as $purchaseItem) {
|
foreach ($purchase->items as $purchaseItem) {
|
||||||
$catalogItem = CatalogItem::query()
|
$catalogItem = CatalogItem::query()
|
||||||
->where('tenant_code', $purchase->tenant_codigo)
|
->where('tenant_code', $purchase->tenant_codigo)
|
||||||
@@ -37,13 +40,19 @@ class GenerateTicketsForPaidPurchase
|
|||||||
throw TicketGenerationException::purchaseWithoutUser($purchase);
|
throw TicketGenerationException::purchaseWithoutUser($purchase);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->ticketGenerator->generate(
|
$generatedTickets = $this->ticketGenerator->generate(
|
||||||
$catalogItem,
|
$catalogItem,
|
||||||
$user,
|
$user,
|
||||||
$purchaseItem->cantidad,
|
$purchaseItem->cantidad,
|
||||||
$purchaseItem->source_variant_id,
|
$purchaseItem->source_variant_id,
|
||||||
$purchase->getKey(),
|
$purchase->getKey(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
array_push($ticketIds, ...$generatedTickets->pluck('id')->all());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ticketIds !== []) {
|
||||||
|
TicketsAvailable::dispatch($purchase, $ticketIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,6 @@ namespace App\Domains\Ticket\Services;
|
|||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
use App\Domains\Ticket\Models\Ticket;
|
use App\Domains\Ticket\Models\Ticket;
|
||||||
use Barryvdh\DomPDF\Facade\Pdf;
|
use Barryvdh\DomPDF\Facade\Pdf;
|
||||||
use Barryvdh\DomPDF\PDF as DomPdf;
|
|
||||||
use Endroid\QrCode\ErrorCorrectionLevel;
|
use Endroid\QrCode\ErrorCorrectionLevel;
|
||||||
use Endroid\QrCode\QrCode;
|
use Endroid\QrCode\QrCode;
|
||||||
use Endroid\QrCode\Writer\PngWriter;
|
use Endroid\QrCode\Writer\PngWriter;
|
||||||
@@ -20,36 +19,12 @@ class TicketPdfService
|
|||||||
* @param Collection<int, Ticket> $tickets
|
* @param Collection<int, Ticket> $tickets
|
||||||
*/
|
*/
|
||||||
public function download(Tenant $tenant, Collection $tickets): Response
|
public function download(Tenant $tenant, Collection $tickets): Response
|
||||||
{
|
|
||||||
return $this->pdf($tenant, $tickets)->download($this->filename($tickets));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Collection<int, Ticket> $tickets
|
|
||||||
*/
|
|
||||||
public function contents(Tenant $tenant, Collection $tickets): string
|
|
||||||
{
|
|
||||||
return $this->pdf($tenant, $tickets)->output();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Collection<int, Ticket> $tickets
|
|
||||||
*/
|
|
||||||
public function filename(Collection $tickets): string
|
|
||||||
{
|
|
||||||
return 'tickets_'.$tickets->pluck('id')->implode('_').'.pdf';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Collection<int, Ticket> $tickets
|
|
||||||
*/
|
|
||||||
private function pdf(Tenant $tenant, Collection $tickets): DomPdf
|
|
||||||
{
|
{
|
||||||
$tenant->loadMissing('headerLogo');
|
$tenant->loadMissing('headerLogo');
|
||||||
$primaryColor = $this->color($tenant->primary_color, '#009933');
|
$primaryColor = $this->color($tenant->primary_color, '#009933');
|
||||||
$headerBackgroundColor = $this->color($tenant->header_bg_color, $primaryColor);
|
$headerBackgroundColor = $this->color($tenant->header_bg_color, $primaryColor);
|
||||||
|
|
||||||
return Pdf::loadView('pdf.tickets', [
|
$pdf = Pdf::loadView('pdf.tickets', [
|
||||||
'tenant' => $tenant,
|
'tenant' => $tenant,
|
||||||
'tickets' => $tickets,
|
'tickets' => $tickets,
|
||||||
'logoDataUri' => $this->logoDataUri($tenant),
|
'logoDataUri' => $this->logoDataUri($tenant),
|
||||||
@@ -60,6 +35,10 @@ class TicketPdfService
|
|||||||
fn (Ticket $ticket): array => [$ticket->id => $this->qrCodeDataUri($ticket->ticket)]
|
fn (Ticket $ticket): array => [$ticket->id => $this->qrCodeDataUri($ticket->ticket)]
|
||||||
),
|
),
|
||||||
])->setPaper('a4');
|
])->setPaper('a4');
|
||||||
|
|
||||||
|
$ticketIds = $tickets->pluck('id')->implode('_');
|
||||||
|
|
||||||
|
return $pdf->download("tickets_{$ticketIds}.pdf");
|
||||||
}
|
}
|
||||||
|
|
||||||
private function qrCodeDataUri(string $value): string
|
private function qrCodeDataUri(string $value): string
|
||||||
|
|||||||
@@ -21,34 +21,7 @@ vigente, vencido o usado, y resuelve sus fechas efectivas de inicio y fin sin pe
|
|||||||
1. `Purchase` emite `PurchasePaid` al confirmarse el pago.
|
1. `Purchase` emite `PurchasePaid` al confirmarse el pago.
|
||||||
2. `GenerateTicketsForPaidPurchase` atiende el evento.
|
2. `GenerateTicketsForPaidPurchase` atiende el evento.
|
||||||
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. El flujo puede emitir disponibilidad para que `Notification` informe al comprador.
|
||||||
|
|
||||||
## 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
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,11 @@
|
|||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use App\Domains\Notification\Events\PasswordResetRequested;
|
use App\Domains\Notification\Events\PasswordResetRequested;
|
||||||
|
use App\Domains\Notification\Events\TicketsAvailable;
|
||||||
use App\Domains\Notification\Events\UserRegistered;
|
use App\Domains\Notification\Events\UserRegistered;
|
||||||
use App\Domains\Notification\Listeners\SendPasswordResetEmail;
|
use App\Domains\Notification\Listeners\SendPasswordResetEmail;
|
||||||
use App\Domains\Notification\Listeners\SendPurchaseConfirmedEmail;
|
use App\Domains\Notification\Listeners\SendPurchasePaidEmail;
|
||||||
|
use App\Domains\Notification\Listeners\SendTicketsAvailableEmail;
|
||||||
use App\Domains\Notification\Listeners\SendWelcomeEmail;
|
use App\Domains\Notification\Listeners\SendWelcomeEmail;
|
||||||
use App\Domains\Purchase\Events\PurchasePaid;
|
use App\Domains\Purchase\Events\PurchasePaid;
|
||||||
use App\Domains\Ticket\Listeners\GenerateTicketsForPaidPurchase;
|
use App\Domains\Ticket\Listeners\GenerateTicketsForPaidPurchase;
|
||||||
@@ -31,8 +33,9 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot(): void
|
public function boot(): void
|
||||||
{
|
{
|
||||||
|
Event::listen(PurchasePaid::class, SendPurchasePaidEmail::class);
|
||||||
Event::listen(PurchasePaid::class, GenerateTicketsForPaidPurchase::class);
|
Event::listen(PurchasePaid::class, GenerateTicketsForPaidPurchase::class);
|
||||||
Event::listen(PurchasePaid::class, SendPurchaseConfirmedEmail::class);
|
Event::listen(TicketsAvailable::class, SendTicketsAvailableEmail::class);
|
||||||
Event::listen(UserRegistered::class, SendWelcomeEmail::class);
|
Event::listen(UserRegistered::class, SendWelcomeEmail::class);
|
||||||
Event::listen(PasswordResetRequested::class, SendPasswordResetEmail::class);
|
Event::listen(PasswordResetRequested::class, SendPasswordResetEmail::class);
|
||||||
|
|
||||||
|
|||||||
@@ -6,16 +6,15 @@
|
|||||||
"keywords": ["laravel", "framework"],
|
"keywords": ["laravel", "framework"],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.3",
|
|
||||||
"ext-gd": "*",
|
"ext-gd": "*",
|
||||||
|
"php": "^8.3",
|
||||||
"barryvdh/laravel-dompdf": "^3.1",
|
"barryvdh/laravel-dompdf": "^3.1",
|
||||||
"endroid/qr-code": "^6.1",
|
"endroid/qr-code": "^6.1",
|
||||||
"laravel/framework": "^13.8",
|
"laravel/framework": "^13.8",
|
||||||
"laravel/sanctum": "^4.3",
|
"laravel/sanctum": "^4.3",
|
||||||
"laravel/socialite": "^5.29",
|
"laravel/socialite": "^5.29",
|
||||||
"laravel/tinker": "^3.0",
|
"laravel/tinker": "^3.0",
|
||||||
"league/flysystem-aws-s3-v3": "^3.0",
|
"league/flysystem-aws-s3-v3": "^3.0"
|
||||||
"phpoffice/phpspreadsheet": "^5.9"
|
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fakerphp/faker": "^1.23",
|
"fakerphp/faker": "^1.23",
|
||||||
|
|||||||
376
composer.lock
generated
376
composer.lock
generated
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "a593ab47d99b233f75851dbb7ea50479",
|
"content-hash": "ce185c60c617846be30ae694f0cf6e9c",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "aws/aws-crt-php",
|
"name": "aws/aws-crt-php",
|
||||||
@@ -417,82 +417,6 @@
|
|||||||
],
|
],
|
||||||
"time": "2024-02-09T16:56:22+00:00"
|
"time": "2024-02-09T16:56:22+00:00"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "composer/pcre",
|
|
||||||
"version": "3.4.0",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/composer/pcre.git",
|
|
||||||
"reference": "d5a341b3fb61f3001970940afb1d332968a183ed"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/composer/pcre/zipball/d5a341b3fb61f3001970940afb1d332968a183ed",
|
|
||||||
"reference": "d5a341b3fb61f3001970940afb1d332968a183ed",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"php": "^7.4 || ^8.0"
|
|
||||||
},
|
|
||||||
"conflict": {
|
|
||||||
"phpstan/phpstan": "<2.2.2"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"phpstan/phpstan": "^2",
|
|
||||||
"phpstan/phpstan-deprecation-rules": "^2",
|
|
||||||
"phpstan/phpstan-strict-rules": "^2",
|
|
||||||
"phpunit/phpunit": "^9"
|
|
||||||
},
|
|
||||||
"type": "library",
|
|
||||||
"extra": {
|
|
||||||
"phpstan": {
|
|
||||||
"includes": [
|
|
||||||
"extension.neon"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"branch-alias": {
|
|
||||||
"dev-main": "3.x-dev"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"Composer\\Pcre\\": "src"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"MIT"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Jordi Boggiano",
|
|
||||||
"email": "j.boggiano@seld.be",
|
|
||||||
"homepage": "http://seld.be"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "PCRE wrapping library that offers type-safe preg_* replacements.",
|
|
||||||
"keywords": [
|
|
||||||
"PCRE",
|
|
||||||
"preg",
|
|
||||||
"regex",
|
|
||||||
"regular expression"
|
|
||||||
],
|
|
||||||
"support": {
|
|
||||||
"issues": "https://github.com/composer/pcre/issues",
|
|
||||||
"source": "https://github.com/composer/pcre/tree/3.4.0"
|
|
||||||
},
|
|
||||||
"funding": [
|
|
||||||
{
|
|
||||||
"url": "https://packagist.com",
|
|
||||||
"type": "custom"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "https://github.com/composer",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"time": "2026-06-07T11:47:49+00:00"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "dasprid/enum",
|
"name": "dasprid/enum",
|
||||||
"version": "1.0.7",
|
"version": "1.0.7",
|
||||||
@@ -3000,191 +2924,6 @@
|
|||||||
],
|
],
|
||||||
"time": "2026-03-08T20:05:35+00:00"
|
"time": "2026-03-08T20:05:35+00:00"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "maennchen/zipstream-php",
|
|
||||||
"version": "3.2.2",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/maennchen/ZipStream-PHP.git",
|
|
||||||
"reference": "77bebeb4c6c340bb3c11c843b2cffd8bbfde4d5e"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/maennchen/ZipStream-PHP/zipball/77bebeb4c6c340bb3c11c843b2cffd8bbfde4d5e",
|
|
||||||
"reference": "77bebeb4c6c340bb3c11c843b2cffd8bbfde4d5e",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"ext-mbstring": "*",
|
|
||||||
"ext-zlib": "*",
|
|
||||||
"php-64bit": "^8.3"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"brianium/paratest": "^7.7",
|
|
||||||
"ext-zip": "*",
|
|
||||||
"friendsofphp/php-cs-fixer": "^3.86",
|
|
||||||
"guzzlehttp/guzzle": "^7.5",
|
|
||||||
"mikey179/vfsstream": "^1.6",
|
|
||||||
"php-coveralls/php-coveralls": "^2.5",
|
|
||||||
"phpunit/phpunit": "^12.0",
|
|
||||||
"vimeo/psalm": "^6.0"
|
|
||||||
},
|
|
||||||
"suggest": {
|
|
||||||
"guzzlehttp/psr7": "^2.4",
|
|
||||||
"psr/http-message": "^2.0"
|
|
||||||
},
|
|
||||||
"type": "library",
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"ZipStream\\": "src/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"MIT"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Paul Duncan",
|
|
||||||
"email": "pabs@pablotron.org"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Jonatan Männchen",
|
|
||||||
"email": "jonatan@maennchen.ch"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Jesse Donat",
|
|
||||||
"email": "donatj@gmail.com"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "András Kolesár",
|
|
||||||
"email": "kolesar@kolesar.hu"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "ZipStream is a library for dynamically streaming dynamic zip files from PHP without writing to the disk at all on the server.",
|
|
||||||
"keywords": [
|
|
||||||
"stream",
|
|
||||||
"zip"
|
|
||||||
],
|
|
||||||
"support": {
|
|
||||||
"issues": "https://github.com/maennchen/ZipStream-PHP/issues",
|
|
||||||
"source": "https://github.com/maennchen/ZipStream-PHP/tree/3.2.2"
|
|
||||||
},
|
|
||||||
"funding": [
|
|
||||||
{
|
|
||||||
"url": "https://github.com/maennchen",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"time": "2026-04-11T18:38:28+00:00"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "markbaker/complex",
|
|
||||||
"version": "3.0.2",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/MarkBaker/PHPComplex.git",
|
|
||||||
"reference": "95c56caa1cf5c766ad6d65b6344b807c1e8405b9"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/MarkBaker/PHPComplex/zipball/95c56caa1cf5c766ad6d65b6344b807c1e8405b9",
|
|
||||||
"reference": "95c56caa1cf5c766ad6d65b6344b807c1e8405b9",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"php": "^7.2 || ^8.0"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"dealerdirect/phpcodesniffer-composer-installer": "dev-master",
|
|
||||||
"phpcompatibility/php-compatibility": "^9.3",
|
|
||||||
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
|
|
||||||
"squizlabs/php_codesniffer": "^3.7"
|
|
||||||
},
|
|
||||||
"type": "library",
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"Complex\\": "classes/src/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"MIT"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Mark Baker",
|
|
||||||
"email": "mark@lange.demon.co.uk"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "PHP Class for working with complex numbers",
|
|
||||||
"homepage": "https://github.com/MarkBaker/PHPComplex",
|
|
||||||
"keywords": [
|
|
||||||
"complex",
|
|
||||||
"mathematics"
|
|
||||||
],
|
|
||||||
"support": {
|
|
||||||
"issues": "https://github.com/MarkBaker/PHPComplex/issues",
|
|
||||||
"source": "https://github.com/MarkBaker/PHPComplex/tree/3.0.2"
|
|
||||||
},
|
|
||||||
"time": "2022-12-06T16:21:08+00:00"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "markbaker/matrix",
|
|
||||||
"version": "3.0.1",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/MarkBaker/PHPMatrix.git",
|
|
||||||
"reference": "728434227fe21be27ff6d86621a1b13107a2562c"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/MarkBaker/PHPMatrix/zipball/728434227fe21be27ff6d86621a1b13107a2562c",
|
|
||||||
"reference": "728434227fe21be27ff6d86621a1b13107a2562c",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"php": "^7.1 || ^8.0"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"dealerdirect/phpcodesniffer-composer-installer": "dev-master",
|
|
||||||
"phpcompatibility/php-compatibility": "^9.3",
|
|
||||||
"phpdocumentor/phpdocumentor": "2.*",
|
|
||||||
"phploc/phploc": "^4.0",
|
|
||||||
"phpmd/phpmd": "2.*",
|
|
||||||
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
|
|
||||||
"sebastian/phpcpd": "^4.0",
|
|
||||||
"squizlabs/php_codesniffer": "^3.7"
|
|
||||||
},
|
|
||||||
"type": "library",
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"Matrix\\": "classes/src/"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"MIT"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Mark Baker",
|
|
||||||
"email": "mark@demon-angel.eu"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "PHP Class for working with matrices",
|
|
||||||
"homepage": "https://github.com/MarkBaker/PHPMatrix",
|
|
||||||
"keywords": [
|
|
||||||
"mathematics",
|
|
||||||
"matrix",
|
|
||||||
"vector"
|
|
||||||
],
|
|
||||||
"support": {
|
|
||||||
"issues": "https://github.com/MarkBaker/PHPMatrix/issues",
|
|
||||||
"source": "https://github.com/MarkBaker/PHPMatrix/tree/3.0.1"
|
|
||||||
},
|
|
||||||
"time": "2022-12-02T22:17:43+00:00"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "masterminds/html5",
|
"name": "masterminds/html5",
|
||||||
"version": "2.10.1",
|
"version": "2.10.1",
|
||||||
@@ -3947,115 +3686,6 @@
|
|||||||
},
|
},
|
||||||
"time": "2020-10-15T08:29:30+00:00"
|
"time": "2020-10-15T08:29:30+00:00"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "phpoffice/phpspreadsheet",
|
|
||||||
"version": "5.9.0",
|
|
||||||
"source": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/PHPOffice/PhpSpreadsheet.git",
|
|
||||||
"reference": "05e99ebf61238a70227b4d9cc02d0030d34f6339"
|
|
||||||
},
|
|
||||||
"dist": {
|
|
||||||
"type": "zip",
|
|
||||||
"url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/05e99ebf61238a70227b4d9cc02d0030d34f6339",
|
|
||||||
"reference": "05e99ebf61238a70227b4d9cc02d0030d34f6339",
|
|
||||||
"shasum": ""
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"composer/pcre": "^1||^2||^3",
|
|
||||||
"ext-ctype": "*",
|
|
||||||
"ext-dom": "*",
|
|
||||||
"ext-fileinfo": "*",
|
|
||||||
"ext-filter": "*",
|
|
||||||
"ext-gd": "*",
|
|
||||||
"ext-iconv": "*",
|
|
||||||
"ext-libxml": "*",
|
|
||||||
"ext-mbstring": "*",
|
|
||||||
"ext-simplexml": "*",
|
|
||||||
"ext-xml": "*",
|
|
||||||
"ext-xmlreader": "*",
|
|
||||||
"ext-xmlwriter": "*",
|
|
||||||
"ext-zip": "*",
|
|
||||||
"ext-zlib": "*",
|
|
||||||
"maennchen/zipstream-php": "^2.1 || ^3.0",
|
|
||||||
"markbaker/complex": "^3.0",
|
|
||||||
"markbaker/matrix": "^3.0",
|
|
||||||
"php": "^8.2",
|
|
||||||
"psr/simple-cache": "^1.0 || ^2.0 || ^3.0"
|
|
||||||
},
|
|
||||||
"require-dev": {
|
|
||||||
"dealerdirect/phpcodesniffer-composer-installer": "dev-main",
|
|
||||||
"dompdf/dompdf": "^2.0 || ^3.0",
|
|
||||||
"ext-intl": "*",
|
|
||||||
"friendsofphp/php-cs-fixer": "^3.2",
|
|
||||||
"mitoteam/jpgraph": "^10.5",
|
|
||||||
"mpdf/mpdf": "^8.1.1",
|
|
||||||
"phpcompatibility/php-compatibility": "^9.3",
|
|
||||||
"phpstan/phpstan": "^1.1 || ^2.0",
|
|
||||||
"phpstan/phpstan-deprecation-rules": "^1.0 || ^2.0",
|
|
||||||
"phpstan/phpstan-phpunit": "^1.0 || ^2.0",
|
|
||||||
"phpunit/phpunit": "^10.5 || ^11.0",
|
|
||||||
"squizlabs/php_codesniffer": "^3.7",
|
|
||||||
"tecnickcom/tcpdf": "^6.5"
|
|
||||||
},
|
|
||||||
"suggest": {
|
|
||||||
"dompdf/dompdf": "Option for rendering PDF with PDF Writer",
|
|
||||||
"ext-intl": "PHP Internationalization Functions, required for NumberFormat Wizard and StringHelper::setLocale()",
|
|
||||||
"mitoteam/jpgraph": "Option for rendering charts, or including charts with PDF or HTML Writers",
|
|
||||||
"mpdf/mpdf": "Option for rendering PDF with PDF Writer",
|
|
||||||
"tecnickcom/tcpdf": "Option for rendering PDF with PDF Writer"
|
|
||||||
},
|
|
||||||
"type": "library",
|
|
||||||
"autoload": {
|
|
||||||
"psr-4": {
|
|
||||||
"PhpOffice\\PhpSpreadsheet\\": "src/PhpSpreadsheet"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
|
||||||
"license": [
|
|
||||||
"MIT"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
{
|
|
||||||
"name": "Maarten Balliauw",
|
|
||||||
"homepage": "https://blog.maartenballiauw.be"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Mark Baker",
|
|
||||||
"homepage": "https://markbakeruk.net"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Franck Lefevre",
|
|
||||||
"homepage": "https://rootslabs.net"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Erik Tilt"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Adrien Crivelli"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Owen Leibman"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine",
|
|
||||||
"homepage": "https://github.com/PHPOffice/PhpSpreadsheet",
|
|
||||||
"keywords": [
|
|
||||||
"OpenXML",
|
|
||||||
"excel",
|
|
||||||
"gnumeric",
|
|
||||||
"ods",
|
|
||||||
"php",
|
|
||||||
"spreadsheet",
|
|
||||||
"xls",
|
|
||||||
"xlsx"
|
|
||||||
],
|
|
||||||
"support": {
|
|
||||||
"issues": "https://github.com/PHPOffice/PhpSpreadsheet/issues",
|
|
||||||
"source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/5.9.0"
|
|
||||||
},
|
|
||||||
"time": "2026-07-12T19:17:39+00:00"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "phpoption/phpoption",
|
"name": "phpoption/phpoption",
|
||||||
"version": "1.9.5",
|
"version": "1.9.5",
|
||||||
@@ -10208,8 +9838,8 @@
|
|||||||
"prefer-stable": true,
|
"prefer-stable": true,
|
||||||
"prefer-lowest": false,
|
"prefer-lowest": false,
|
||||||
"platform": {
|
"platform": {
|
||||||
"php": "^8.3",
|
"ext-gd": "*",
|
||||||
"ext-gd": "*"
|
"php": "^8.3"
|
||||||
},
|
},
|
||||||
"platform-dev": {},
|
"platform-dev": {},
|
||||||
"plugin-api-version": "2.9.0"
|
"plugin-api-version": "2.9.0"
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ return [
|
|||||||
'users' => [
|
'users' => [
|
||||||
'provider' => 'users',
|
'provider' => 'users',
|
||||||
'table' => env('AUTH_PASSWORD_RESET_TOKEN_TABLE', 'password_reset_tokens'),
|
'table' => env('AUTH_PASSWORD_RESET_TOKEN_TABLE', 'password_reset_tokens'),
|
||||||
'expire' => (int) env('AUTH_PASSWORD_RESET_EXPIRATION_MINUTES', 60),
|
'expire' => 60,
|
||||||
'throttle' => 60,
|
'throttle' => 60,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -89,14 +89,6 @@ return [
|
|||||||
'replace_placeholders' => true,
|
'replace_placeholders' => true,
|
||||||
],
|
],
|
||||||
|
|
||||||
'emails' => [
|
|
||||||
'driver' => 'daily',
|
|
||||||
'path' => storage_path('logs/emails/emails.log'),
|
|
||||||
'level' => env('EMAILS_LOG_LEVEL', 'info'),
|
|
||||||
'days' => env('EMAILS_LOG_DAYS', 30),
|
|
||||||
'replace_placeholders' => true,
|
|
||||||
],
|
|
||||||
|
|
||||||
'slack' => [
|
'slack' => [
|
||||||
'driver' => 'slack',
|
'driver' => 'slack',
|
||||||
'url' => env('LOG_SLACK_WEBHOOK_URL'),
|
'url' => env('LOG_SLACK_WEBHOOK_URL'),
|
||||||
|
|||||||
@@ -8,9 +8,4 @@ return [
|
|||||||
'telepagos' => (int) env('PURCHASE_TELEPAGOS_EXPIRATION_MINUTES', 30),
|
'telepagos' => (int) env('PURCHASE_TELEPAGOS_EXPIRATION_MINUTES', 30),
|
||||||
'transfer' => (int) env('PURCHASE_TRANSFER_EXPIRATION_MINUTES', 1440),
|
'transfer' => (int) env('PURCHASE_TRANSFER_EXPIRATION_MINUTES', 1440),
|
||||||
],
|
],
|
||||||
|
|
||||||
'transfer_candidate_amount_tolerance_percentage' => (float) env(
|
|
||||||
'PURCHASE_TRANSFER_CANDIDATE_AMOUNT_TOLERANCE_PERCENTAGE',
|
|
||||||
5,
|
|
||||||
),
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use App\Domains\Auth\Models\ResetPasswordAttempt;
|
|
||||||
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('reset_password_attempts', function (Blueprint $table): void {
|
|
||||||
$table->timestamp('expires_at')->nullable()->after('status');
|
|
||||||
});
|
|
||||||
|
|
||||||
// Attempts created before this migration did not have an expiration instant.
|
|
||||||
DB::table('reset_password_attempts')
|
|
||||||
->whereIn('status', [
|
|
||||||
ResetPasswordAttempt::STATUS_PENDING,
|
|
||||||
ResetPasswordAttempt::STATUS_VALIDATED,
|
|
||||||
])
|
|
||||||
->update(['status' => ResetPasswordAttempt::STATUS_EXPIRED]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('reset_password_attempts', function (Blueprint $table): void {
|
|
||||||
$table->dropColumn('expires_at');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
private const FILENAME = 'onticket_favicon.svg';
|
|
||||||
|
|
||||||
/** @var list<string> */
|
|
||||||
private const WEBSITE_TYPE_CODES = ['shopit', 'onticket'];
|
|
||||||
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
$websiteTypes = DB::table('website_type')
|
|
||||||
->whereIn('codigo', self::WEBSITE_TYPE_CODES)
|
|
||||||
->get(['codigo', 'favicon_id']);
|
|
||||||
|
|
||||||
if ($websiteTypes->isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$faviconIds = $websiteTypes
|
|
||||||
->pluck('favicon_id')
|
|
||||||
->filter()
|
|
||||||
->unique()
|
|
||||||
->values();
|
|
||||||
|
|
||||||
if (
|
|
||||||
$faviconIds->count() === 1
|
|
||||||
&& DB::table('attachments')
|
|
||||||
->where('id', $faviconIds->first())
|
|
||||||
->where('filename', self::FILENAME)
|
|
||||||
->exists()
|
|
||||||
&& $websiteTypes->every(
|
|
||||||
fn (object $websiteType): bool => $websiteType->favicon_id === $faviconIds->first()
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sourcePath = public_path('images/website_types/'.self::FILENAME);
|
|
||||||
|
|
||||||
if (! is_file($sourcePath)) {
|
|
||||||
throw new RuntimeException("Favicon not found at path: {$sourcePath}");
|
|
||||||
}
|
|
||||||
|
|
||||||
$contents = file_get_contents($sourcePath);
|
|
||||||
|
|
||||||
if ($contents === false) {
|
|
||||||
throw new RuntimeException("Could not read favicon at path: {$sourcePath}");
|
|
||||||
}
|
|
||||||
|
|
||||||
$key = (string) Str::uuid();
|
|
||||||
$storedPath = "website-types/{$key}.svg";
|
|
||||||
|
|
||||||
if (! Storage::disk('s3')->put($storedPath, $contents)) {
|
|
||||||
throw new RuntimeException("Could not store favicon at path: {$storedPath}");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
DB::transaction(function () use ($contents, $key, $storedPath): void {
|
|
||||||
$attachmentId = DB::table('attachments')->insertGetId([
|
|
||||||
'key' => $key,
|
|
||||||
'path' => $storedPath,
|
|
||||||
'filename' => self::FILENAME,
|
|
||||||
'type' => 'image',
|
|
||||||
'mime_type' => 'image/svg+xml',
|
|
||||||
'extension' => 'svg',
|
|
||||||
'size' => strlen($contents),
|
|
||||||
'created_at' => now(),
|
|
||||||
'updated_at' => now(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
DB::table('website_type')
|
|
||||||
->whereIn('codigo', self::WEBSITE_TYPE_CODES)
|
|
||||||
->update([
|
|
||||||
'favicon_id' => $attachmentId,
|
|
||||||
'updated_at' => now(),
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
} catch (Throwable $throwable) {
|
|
||||||
Storage::disk('s3')->delete($storedPath);
|
|
||||||
|
|
||||||
throw $throwable;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
// The shared attachment may be in use outside these website types.
|
|
||||||
// Keep this data migration irreversible to avoid deleting an active asset.
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -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']);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -191,7 +191,6 @@ class DesfilePuraTendenciaSeeder extends Seeder
|
|||||||
|
|
||||||
FeaturedGroup::query()->create([
|
FeaturedGroup::query()->create([
|
||||||
'tenant_code' => self::TENANT_CODE,
|
'tenant_code' => self::TENANT_CODE,
|
||||||
'code' => 'entradas',
|
|
||||||
'source_type' => FeaturedGroupSource::All,
|
'source_type' => FeaturedGroupSource::All,
|
||||||
'category_id' => null,
|
'category_id' => null,
|
||||||
'product_layout' => ProductLayout::TicketSelector,
|
'product_layout' => ProductLayout::TicketSelector,
|
||||||
|
|||||||
@@ -144,7 +144,6 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
|||||||
|
|
||||||
FeaturedGroup::query()->create([
|
FeaturedGroup::query()->create([
|
||||||
'tenant_code' => $tenant->codigo,
|
'tenant_code' => $tenant->codigo,
|
||||||
'code' => 'productos',
|
|
||||||
'source_type' => FeaturedGroupSource::All,
|
'source_type' => FeaturedGroupSource::All,
|
||||||
'category_id' => null,
|
'category_id' => null,
|
||||||
'product_layout' => ProductLayout::Row,
|
'product_layout' => ProductLayout::Row,
|
||||||
|
|||||||
@@ -171,7 +171,6 @@ class ProductCatalogFromImagesSeeder extends Seeder
|
|||||||
|
|
||||||
FeaturedGroup::query()->create([
|
FeaturedGroup::query()->create([
|
||||||
'tenant_code' => $tenant->codigo,
|
'tenant_code' => $tenant->codigo,
|
||||||
'code' => 'productos',
|
|
||||||
'source_type' => FeaturedGroupSource::All,
|
'source_type' => FeaturedGroupSource::All,
|
||||||
'product_layout' => ProductLayout::ColumnWithImage,
|
'product_layout' => ProductLayout::ColumnWithImage,
|
||||||
'group_layout' => GroupLayout::Paginated,
|
'group_layout' => GroupLayout::Paginated,
|
||||||
@@ -181,7 +180,6 @@ class ProductCatalogFromImagesSeeder extends Seeder
|
|||||||
|
|
||||||
$carouselGroup = FeaturedGroup::query()->create([
|
$carouselGroup = FeaturedGroup::query()->create([
|
||||||
'tenant_code' => $tenant->codigo,
|
'tenant_code' => $tenant->codigo,
|
||||||
'code' => 'productos-destacados',
|
|
||||||
'source_type' => FeaturedGroupSource::Manual,
|
'source_type' => FeaturedGroupSource::Manual,
|
||||||
'product_layout' => ProductLayout::ColumnWithImage,
|
'product_layout' => ProductLayout::ColumnWithImage,
|
||||||
'group_layout' => GroupLayout::Carousel,
|
'group_layout' => GroupLayout::Carousel,
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ class WebsiteTypeSeeder extends Seeder
|
|||||||
...self::PRESENTATION,
|
...self::PRESENTATION,
|
||||||
'site_logo' => $this->onTicketLogo(),
|
'site_logo' => $this->onTicketLogo(),
|
||||||
'footer_logo' => $this->onTicketFooterLogo(),
|
'footer_logo' => $this->onTicketFooterLogo(),
|
||||||
'favicon' => $this->onTicketFavicon(),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -71,7 +70,6 @@ class WebsiteTypeSeeder extends Seeder
|
|||||||
...self::PRESENTATION,
|
...self::PRESENTATION,
|
||||||
'site_logo' => $this->onTicketLogo(),
|
'site_logo' => $this->onTicketLogo(),
|
||||||
'footer_logo' => $this->onTicketFooterLogo(),
|
'footer_logo' => $this->onTicketFooterLogo(),
|
||||||
'favicon' => $shopIt->favicon()->firstOrFail()->key,
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -177,21 +175,4 @@ class WebsiteTypeSeeder extends Seeder
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function onTicketFavicon(): UploadedFile
|
|
||||||
{
|
|
||||||
$path = public_path('images/website_types/onticket_favicon.svg');
|
|
||||||
|
|
||||||
if (! file_exists($path)) {
|
|
||||||
throw new RuntimeException("OnTicket favicon not found at path: {$path}");
|
|
||||||
}
|
|
||||||
|
|
||||||
return new UploadedFile(
|
|
||||||
$path,
|
|
||||||
'onticket_favicon.svg',
|
|
||||||
'image/svg+xml',
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ return [
|
|||||||
'password_reset_invalid' => 'The password recovery request is invalid or has already been used.',
|
'password_reset_invalid' => 'The password recovery request is invalid or has already been used.',
|
||||||
'password_updated' => 'Password updated successfully.',
|
'password_updated' => 'Password updated successfully.',
|
||||||
'reset_code_invalid' => 'The code you entered is invalid.',
|
'reset_code_invalid' => 'The code you entered is invalid.',
|
||||||
'reset_code_expired' => 'The password recovery code expired. Request a new one.',
|
|
||||||
'reset_code_valid' => 'Code validated successfully.',
|
'reset_code_valid' => 'Code validated successfully.',
|
||||||
'invalid_tenant_or_return_url' => 'The tenant or return URL is invalid.',
|
'invalid_tenant_or_return_url' => 'The tenant or return URL is invalid.',
|
||||||
'request_expired' => 'The authentication request expired. Please try again.',
|
'request_expired' => 'The authentication request expired. Please try again.',
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ return [
|
|||||||
'password_reset_invalid' => 'La solicitud de recuperación es inválida o ya fue utilizada.',
|
'password_reset_invalid' => 'La solicitud de recuperación es inválida o ya fue utilizada.',
|
||||||
'password_updated' => 'Contraseña modificada correctamente.',
|
'password_updated' => 'Contraseña modificada correctamente.',
|
||||||
'reset_code_invalid' => 'El código ingresado es inválido.',
|
'reset_code_invalid' => 'El código ingresado es inválido.',
|
||||||
'reset_code_expired' => 'El código de recuperación expiró. Solicitá uno nuevo.',
|
|
||||||
'reset_code_valid' => 'Código validado correctamente.',
|
'reset_code_valid' => 'Código validado correctamente.',
|
||||||
'invalid_tenant_or_return_url' => 'El tenant o la URL de retorno no son válidos.',
|
'invalid_tenant_or_return_url' => 'El tenant o la URL de retorno no son válidos.',
|
||||||
'request_expired' => 'La solicitud de autenticación expiró. Intenta nuevamente.',
|
'request_expired' => 'La solicitud de autenticación expiró. Intenta nuevamente.',
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
</source>
|
</source>
|
||||||
<php>
|
<php>
|
||||||
<env name="APP_ENV" value="testing"/>
|
<env name="APP_ENV" value="testing"/>
|
||||||
<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"/>
|
||||||
<env name="APP_EVENTS_CACHE" value="bootstrap/cache/phpunit-events.php"/>
|
<env name="APP_EVENTS_CACHE" value="bootstrap/cache/phpunit-events.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',
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
<svg width="63" height="36" viewBox="0 0 63 36" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
||||||
<path d="M44.64 0H17.94C8.05 0 0 8.05 0 17.94C0 27.83 8.05 35.88 17.94 35.88H44.64C54.53 35.88 62.58 27.83 62.58 17.94C62.58 8.05 54.53 0 44.64 0ZM44.62 31.78C36.98 31.78 30.79 25.59 30.79 17.95C30.79 10.31 36.98 4.12 44.62 4.12C52.26 4.12 58.45 10.31 58.45 17.95C58.45 25.59 52.26 31.78 44.62 31.78Z" fill="#FF7006"/>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 422 B |
@@ -1,4 +1,4 @@
|
|||||||
@props(['branding', 'headerLogoUrl' => null, 'footerLogoUrl' => null])
|
@props(['tenant', 'headerLogoUrl' => null, 'footerLogoUrl' => null])
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="es">
|
<html lang="es">
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta name="color-scheme" content="light">
|
<meta name="color-scheme" content="light">
|
||||||
<title>{{ $branding['name'] }}</title>
|
<title>{{ $tenant->nombre }}</title>
|
||||||
<style>
|
<style>
|
||||||
@media only screen and (max-width: 620px) {
|
@media only screen and (max-width: 620px) {
|
||||||
.mail-container { width: 100% !important; }
|
.mail-container { width: 100% !important; }
|
||||||
@@ -14,17 +14,17 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body style="margin: 0; padding: 0; background-color: {{ $branding['background_color'] }}; color: {{ $branding['body_color'] }}; font-family: Arial, Helvetica, sans-serif;">
|
<body style="margin: 0; padding: 0; background-color: #f1f5f9; color: #334155; font-family: Arial, Helvetica, sans-serif;">
|
||||||
<table role="presentation" width="100%" cellspacing="0" cellpadding="0" border="0" style="background-color: {{ $branding['background_color'] }};">
|
<table role="presentation" width="100%" cellspacing="0" cellpadding="0" border="0" style="background-color: #f1f5f9;">
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center" style="padding: 32px 12px;">
|
<td align="center" style="padding: 32px 12px;">
|
||||||
<table role="presentation" width="600" cellspacing="0" cellpadding="0" border="0" class="mail-container" style="width: 600px; max-width: 600px; background-color: {{ $branding['surface_color'] }}; border-top: 4px solid {{ $branding['primary_color'] }}; border-radius: 8px; overflow: hidden; box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);">
|
<table role="presentation" width="600" cellspacing="0" cellpadding="0" border="0" class="mail-container" style="width: 600px; max-width: 600px; background-color: #ffffff; border-top: 4px solid {{ $tenant->primary_color }}; border-radius: 8px; overflow: hidden; box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);">
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center" bgcolor="{{ $branding['header_bg_color'] }}" style="padding: 24px 32px; background-color: {{ $branding['header_bg_color'] }};">
|
<td align="center" bgcolor="{{ $tenant->header_bg_color }}" style="padding: 24px 32px; background-color: {{ $tenant->header_bg_color }};">
|
||||||
@if ($headerLogoUrl)
|
@if ($headerLogoUrl)
|
||||||
<img src="{{ $headerLogoUrl }}" alt="{{ $branding['name'] }}" width="180" style="display: block; width: auto; max-width: 180px; max-height: 64px; border: 0;">
|
<img src="{{ $headerLogoUrl }}" alt="{{ $tenant->nombre }}" width="180" style="display: block; width: auto; max-width: 180px; max-height: 64px; border: 0;">
|
||||||
@else
|
@else
|
||||||
<span style="color: {{ $branding['primary_color'] }}; font-size: 24px; font-weight: 700; line-height: 1.2;">{{ $branding['name'] }}</span>
|
<span style="color: {{ $tenant->primary_color }}; font-size: 24px; font-weight: 700; line-height: 1.2;">{{ $tenant->nombre }}</span>
|
||||||
@endif
|
@endif
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -34,11 +34,11 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center" bgcolor="{{ $branding['footer_bg_color'] }}" style="padding: 24px 32px; background-color: {{ $branding['footer_bg_color'] }}; color: #ffffff; font-size: 12px; line-height: 1.5;">
|
<td align="center" bgcolor="{{ $tenant->footer_bg_color }}" style="padding: 24px 32px; background-color: {{ $tenant->footer_bg_color }}; color: #ffffff; font-size: 12px; line-height: 1.5;">
|
||||||
@if ($footerLogoUrl)
|
@if ($footerLogoUrl)
|
||||||
<img src="{{ $footerLogoUrl }}" alt="{{ $branding['name'] }}" width="140" style="display: block; width: auto; max-width: 140px; max-height: 48px; margin: 0 auto 16px; border: 0;">
|
<img src="{{ $footerLogoUrl }}" alt="{{ $tenant->nombre }}" width="140" style="display: block; width: auto; max-width: 140px; max-height: 48px; margin: 0 auto 16px; border: 0;">
|
||||||
@endif
|
@endif
|
||||||
{{ $footer ?? 'Este correo fue enviado por '.$branding['name'].'.' }}
|
{{ $footer ?? 'Este correo fue enviado por '.$tenant->nombre.'.' }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<h1 style="margin: 0 0 20px; color: {{ $brand->primary_color }};">
|
<h1 style="margin: 0 0 20px; color: {{ $tenant->primary_color }};">
|
||||||
Recuperá tu contraseña
|
Recuperá tu contraseña
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
@if($attempt->reason === \App\Domains\Auth\Models\ResetPasswordAttempt::REASON_STAFF_CREATED)
|
@if($attempt->reason === \App\Domains\Auth\Models\ResetPasswordAttempt::REASON_STAFF_CREATED)
|
||||||
<p>
|
<p>
|
||||||
Hola {{ $attempt->user->nombre_apellido }}, creamos tu cuenta de scanner en {{ $brand->nombre }}. Utilizá este código para crear tu contraseña y comenzar a usarla.
|
Hola {{ $attempt->user->nombre_apellido }}, creamos tu cuenta de scanner en {{ $tenant->nombre }}. Utilizá este código para crear tu contraseña y comenzar a usarla.
|
||||||
</p>
|
</p>
|
||||||
@elseif($attempt->reason === \App\Domains\Auth\Models\ResetPasswordAttempt::REASON_ACCOUNT_LOCKED)
|
@elseif($attempt->reason === \App\Domains\Auth\Models\ResetPasswordAttempt::REASON_ACCOUNT_LOCKED)
|
||||||
<p>
|
<p>
|
||||||
@@ -17,10 +17,10 @@
|
|||||||
</p>
|
</p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
<p>Ingresá este código en {{ $brand->nombre }}:</p>
|
<p>Ingresá este código en {{ $tenant->nombre }}:</p>
|
||||||
|
|
||||||
<div style="margin: 28px 0; padding: 20px; border: 2px solid {{ $brand->primary_color }}; border-radius: 8px; text-align: center;">
|
<div style="margin: 28px 0; padding: 20px; border: 2px solid {{ $tenant->primary_color }}; border-radius: 8px; text-align: center;">
|
||||||
<span style="color: {{ $brand->primary_color }}; font-size: 36px; font-weight: 700; letter-spacing: 12px;">
|
<span style="color: {{ $tenant->primary_color }}; font-size: 36px; font-weight: 700; letter-spacing: 12px;">
|
||||||
{{ $attempt->codigo }}
|
{{ $attempt->codigo }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
@if($recoveryUrl)
|
@if($recoveryUrl)
|
||||||
<div style="text-align: center; margin-bottom: 28px;">
|
<div style="text-align: center; margin-bottom: 28px;">
|
||||||
<a href="{{ $recoveryUrl }}"
|
<a href="{{ $recoveryUrl }}"
|
||||||
style="display: inline-block; padding: 12px 24px; background-color: {{ $brand->primary_color }}; color: #ffffff; text-decoration: none; border-radius: 6px; font-weight: bold;">
|
style="display: inline-block; padding: 12px 24px; background-color: {{ $tenant->primary_color }}; color: #ffffff; text-decoration: none; border-radius: 6px; font-weight: bold;">
|
||||||
{{ $attempt->reason === \App\Domains\Auth\Models\ResetPasswordAttempt::REASON_STAFF_CREATED ? 'Crear mi contraseña' : 'Ingresar código ahora' }}
|
{{ $attempt->reason === \App\Domains\Auth\Models\ResetPasswordAttempt::REASON_STAFF_CREATED ? 'Crear mi contraseña' : 'Ingresar código ahora' }}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<h1 style="margin: 0 0 20px;">¡Compra realizada con éxito!</h1>
|
<h1 style="margin: 0 0 20px;">¡Recibimos tu pago!</h1>
|
||||||
<p>La compra <strong>#{{ $purchase->id }}</strong> fue confirmada correctamente.</p>
|
<p>La compra <strong>#{{ $purchase->id }}</strong> fue confirmada correctamente.</p>
|
||||||
<table role="presentation" style="width: 100%; border-collapse: collapse; margin: 20px 0;">
|
<table role="presentation" style="width: 100%; border-collapse: collapse; margin: 20px 0;">
|
||||||
@foreach ($purchase->items as $item)
|
@foreach ($purchase->items as $item)
|
||||||
@@ -10,6 +10,3 @@
|
|||||||
@endforeach
|
@endforeach
|
||||||
</table>
|
</table>
|
||||||
<p style="font-size: 18px;"><strong>Total pagado: ${{ number_format((float) $purchase->total, 2, ',', '.') }}</strong></p>
|
<p style="font-size: 18px;"><strong>Total pagado: ${{ number_format((float) $purchase->total, 2, ',', '.') }}</strong></p>
|
||||||
@if ($tickets->isNotEmpty())
|
|
||||||
<p><strong>Tus tickets ya están disponibles</strong></p>
|
|
||||||
@endif
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<h1 style="margin: 0 0 20px;">Tus tickets ya están disponibles</h1>
|
||||||
|
<p>Generamos {{ $tickets->count() }} {{ $tickets->count() === 1 ? 'ticket' : 'tickets' }} para la compra <strong>#{{ $purchase->id }}</strong>.</p>
|
||||||
|
<ul style="padding-left: 20px;">
|
||||||
|
@foreach ($tickets as $ticket)
|
||||||
|
<li style="margin-bottom: 8px;">{{ $ticket->name }}</li>
|
||||||
|
@endforeach
|
||||||
|
</ul>
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
<h1 style="margin: 0 0 20px;">¡Bienvenido a {{ $brand->nombre }}!</h1>
|
<h1 style="margin: 0 0 20px;">¡Bienvenido a {{ $tenant->nombre }}!</h1>
|
||||||
<p>Hola {{ $user->nombre_apellido }}, tu cuenta fue creada correctamente.</p>
|
<p>Hola {{ $user->nombre_apellido }}, tu cuenta fue creada correctamente.</p>
|
||||||
<p>Ya podés ingresar y comenzar a comprar.</p>
|
<p>Ya podés ingresar y comenzar a comprar.</p>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<x-mail.branded-layout :branding="$branding" :header-logo-url="$headerLogoUrl" :footer-logo-url="$footerLogoUrl">
|
<x-mail.branded-layout :tenant="$tenant" :header-logo-url="$headerLogoUrl" :footer-logo-url="$footerLogoUrl">
|
||||||
<h1 style="margin: 0 0 20px; color: {{ $tenant->primary_color }}; font-size: 26px; line-height: 1.3;">
|
<h1 style="margin: 0 0 20px; color: {{ $tenant->primary_color }}; font-size: 26px; line-height: 1.3;">
|
||||||
Prueba de correo de Shopit
|
Prueba de correo de Shopit
|
||||||
</h1>
|
</h1>
|
||||||
|
|||||||
@@ -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á}
|
||||||
|
|||||||
@@ -69,10 +69,6 @@ class CreateResetPasswordAttemptControllerTest extends TestCase
|
|||||||
$this->assertTrue($attempt->user->is($user));
|
$this->assertTrue($attempt->user->is($user));
|
||||||
$this->assertMatchesRegularExpression('/^\d{4}$/', $attempt->codigo);
|
$this->assertMatchesRegularExpression('/^\d{4}$/', $attempt->codigo);
|
||||||
$this->assertSame(ResetPasswordAttempt::STATUS_PENDING, $attempt->status);
|
$this->assertSame(ResetPasswordAttempt::STATUS_PENDING, $attempt->status);
|
||||||
$this->assertTrue($attempt->expires_at->between(
|
|
||||||
now()->addMinutes(59),
|
|
||||||
now()->addMinutes(60),
|
|
||||||
));
|
|
||||||
Event::assertDispatched(
|
Event::assertDispatched(
|
||||||
PasswordResetRequested::class,
|
PasswordResetRequested::class,
|
||||||
fn (PasswordResetRequested $event): bool => $event->attemptId === $attempt->id
|
fn (PasswordResetRequested $event): bool => $event->attemptId === $attempt->id
|
||||||
|
|||||||
@@ -18,9 +18,7 @@ class ResetPasswordAttemptTest extends TestCase
|
|||||||
'id',
|
'id',
|
||||||
'user_id',
|
'user_id',
|
||||||
'codigo',
|
'codigo',
|
||||||
'reason',
|
|
||||||
'status',
|
'status',
|
||||||
'expires_at',
|
|
||||||
], Schema::getColumnListing('reset_password_attempts'));
|
], Schema::getColumnListing('reset_password_attempts'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,14 +28,12 @@ class ResetPasswordAttemptTest extends TestCase
|
|||||||
|
|
||||||
$attempt = $user->resetPasswordAttempts()->create([
|
$attempt = $user->resetPasswordAttempts()->create([
|
||||||
'codigo' => '123456',
|
'codigo' => '123456',
|
||||||
'expires_at' => now()->addHour(),
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame(ResetPasswordAttempt::STATUS_PENDING, $attempt->status);
|
$this->assertSame(ResetPasswordAttempt::STATUS_PENDING, $attempt->status);
|
||||||
$this->assertTrue($attempt->user->is($user));
|
$this->assertTrue($attempt->user->is($user));
|
||||||
$this->assertTrue($user->resetPasswordAttempts->contains($attempt));
|
$this->assertTrue($user->resetPasswordAttempts->contains($attempt));
|
||||||
$this->assertFalse($attempt->usesTimestamps());
|
$this->assertFalse($attempt->usesTimestamps());
|
||||||
$this->assertTrue($attempt->expires_at->isFuture());
|
|
||||||
$this->assertArrayNotHasKey('codigo', $attempt->toArray());
|
$this->assertArrayNotHasKey('codigo', $attempt->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,30 +99,6 @@ class ResetPasswordControllerTest extends TestCase
|
|||||||
$this->assertSame(ResetPasswordAttempt::STATUS_USED, $attempt->fresh()->status);
|
$this->assertSame(ResetPasswordAttempt::STATUS_USED, $attempt->fresh()->status);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_an_expired_validated_attempt_cannot_reset_the_password(): void
|
|
||||||
{
|
|
||||||
$user = User::factory()->create([
|
|
||||||
'email' => 'ada@example.com',
|
|
||||||
'password' => 'OldSecret!123',
|
|
||||||
]);
|
|
||||||
$attempt = $user->resetPasswordAttempts()->create([
|
|
||||||
'codigo' => '1234',
|
|
||||||
'status' => ResetPasswordAttempt::STATUS_VALIDATED,
|
|
||||||
'expires_at' => now()->subSecond(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->postJson('/api/password/reset', [
|
|
||||||
'email' => 'ada@example.com',
|
|
||||||
'codigo' => '1234',
|
|
||||||
'password' => 'NewSecret!456',
|
|
||||||
'password_confirmation' => 'NewSecret!456',
|
|
||||||
])->assertUnprocessable()
|
|
||||||
->assertJsonValidationErrors('codigo');
|
|
||||||
|
|
||||||
$this->assertTrue(Hash::check('OldSecret!123', $user->fresh()->password));
|
|
||||||
$this->assertSame(ResetPasswordAttempt::STATUS_EXPIRED, $attempt->fresh()->status);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_validates_password_confirmation_and_strength(): void
|
public function test_it_validates_password_confirmation_and_strength(): void
|
||||||
{
|
{
|
||||||
$this->postJson('/api/password/reset', [
|
$this->postJson('/api/password/reset', [
|
||||||
|
|||||||
@@ -49,27 +49,6 @@ class ValidateResetPasswordAttemptControllerTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_it_expires_an_attempt_and_returns_the_expired_code_message(): void
|
|
||||||
{
|
|
||||||
$user = User::factory()->create(['email' => 'ada@example.com']);
|
|
||||||
$attempt = $user->resetPasswordAttempts()->create([
|
|
||||||
'codigo' => '1234',
|
|
||||||
'expires_at' => now()->subSecond(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->postJson('/api/password/reset-attempts/validate', [
|
|
||||||
'email' => 'ada@example.com',
|
|
||||||
'codigo' => '1234',
|
|
||||||
])->assertUnprocessable()
|
|
||||||
->assertJsonValidationErrors('codigo')
|
|
||||||
->assertJsonPath('errors.codigo.0', __('api.auth.reset_code_expired'));
|
|
||||||
|
|
||||||
$this->assertSame(
|
|
||||||
ResetPasswordAttempt::STATUS_EXPIRED,
|
|
||||||
$attempt->fresh()->status,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_rejects_an_expired_or_already_validated_attempt(): void
|
public function test_it_rejects_an_expired_or_already_validated_attempt(): void
|
||||||
{
|
{
|
||||||
$user = User::factory()->create(['email' => 'ada@example.com']);
|
$user = User::factory()->create(['email' => 'ada@example.com']);
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ class CatalogSchemaTest extends TestCase
|
|||||||
$this->assertEqualsCanonicalizing([
|
$this->assertEqualsCanonicalizing([
|
||||||
'id',
|
'id',
|
||||||
'tenant_code',
|
'tenant_code',
|
||||||
'code',
|
|
||||||
'source_type',
|
'source_type',
|
||||||
'category_id',
|
'category_id',
|
||||||
'product_layout',
|
'product_layout',
|
||||||
|
|||||||
@@ -60,9 +60,9 @@ class TelepagosWebhookTest extends TestCase
|
|||||||
->assertJsonValidationErrors(['transfer_payer_dni']);
|
->assertJsonValidationErrors(['transfer_payer_dni']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_transfer_payment_intent_persists_data_without_extending_checkout_expiration(): void
|
public function test_transfer_payment_intent_persists_transfer_payer_dni_without_replacing_customer_dni(): void
|
||||||
{
|
{
|
||||||
config()->set('purchase.checkout_expiration_minutes', 30);
|
config()->set('purchase.payment_expiration_minutes.transfer', 60);
|
||||||
$now = now()->startOfSecond();
|
$now = now()->startOfSecond();
|
||||||
$this->travelTo($now);
|
$this->travelTo($now);
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ class TelepagosWebhookTest extends TestCase
|
|||||||
$this->assertDatabaseHas('stock_reservations', [
|
$this->assertDatabaseHas('stock_reservations', [
|
||||||
'id' => $purchase->stock_reservation_id,
|
'id' => $purchase->stock_reservation_id,
|
||||||
'status' => 'active',
|
'status' => 'active',
|
||||||
'expires_at' => $now->copy()->addMinutes(30)->toDateTimeString(),
|
'expires_at' => $now->copy()->addMinutes(60)->toDateTimeString(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->travelBack();
|
$this->travelBack();
|
||||||
@@ -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');
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature\Migrations;
|
|
||||||
|
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class SetWebsiteTypeFaviconTest extends TestCase
|
|
||||||
{
|
|
||||||
use RefreshDatabase;
|
|
||||||
|
|
||||||
public function test_it_uploads_one_favicon_and_shares_the_attachment_between_website_types(): void
|
|
||||||
{
|
|
||||||
Storage::fake('s3');
|
|
||||||
|
|
||||||
DB::table('website_type')->insert([
|
|
||||||
[
|
|
||||||
'codigo' => 'shopit',
|
|
||||||
'nombre' => 'ShopIt',
|
|
||||||
'created_at' => now(),
|
|
||||||
'updated_at' => now(),
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'codigo' => 'onticket',
|
|
||||||
'nombre' => 'OnTicket',
|
|
||||||
'created_at' => now(),
|
|
||||||
'updated_at' => now(),
|
|
||||||
],
|
|
||||||
]);
|
|
||||||
|
|
||||||
$migration = require database_path(
|
|
||||||
'migrations/2026_08_26_000000_set_website_type_favicon.php'
|
|
||||||
);
|
|
||||||
|
|
||||||
$migration->up();
|
|
||||||
$migration->up();
|
|
||||||
|
|
||||||
$faviconIds = DB::table('website_type')
|
|
||||||
->whereIn('codigo', ['shopit', 'onticket'])
|
|
||||||
->pluck('favicon_id');
|
|
||||||
|
|
||||||
$this->assertCount(2, $faviconIds);
|
|
||||||
$this->assertNotNull($faviconIds->first());
|
|
||||||
$this->assertSame(1, $faviconIds->unique()->count());
|
|
||||||
|
|
||||||
$attachment = DB::table('attachments')->where('id', $faviconIds->first())->first();
|
|
||||||
|
|
||||||
$this->assertNotNull($attachment);
|
|
||||||
$this->assertSame('onticket_favicon.svg', $attachment->filename);
|
|
||||||
$this->assertSame('image/svg+xml', $attachment->mime_type);
|
|
||||||
$this->assertSame('svg', $attachment->extension);
|
|
||||||
$this->assertSame(1, DB::table('attachments')->where('filename', 'onticket_favicon.svg')->count());
|
|
||||||
Storage::disk('s3')->assertExists($attachment->path);
|
|
||||||
$this->assertSame(
|
|
||||||
file_get_contents(public_path('images/website_types/onticket_favicon.svg')),
|
|
||||||
Storage::disk('s3')->get($attachment->path),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -71,24 +71,19 @@ class NotificationMailServiceTest extends TestCase
|
|||||||
|
|
||||||
public function test_it_sends_a_branded_welcome_email(): void
|
public function test_it_sends_a_branded_welcome_email(): void
|
||||||
{
|
{
|
||||||
$this->useWebsiteTypeBranding();
|
|
||||||
|
|
||||||
app(NotificationMailService::class)->sendWelcome($this->user->id, $this->tenant->codigo);
|
app(NotificationMailService::class)->sendWelcome($this->user->id, $this->tenant->codigo);
|
||||||
|
|
||||||
Mail::assertSent(Mailable::class, function (Mailable $mail): bool {
|
Mail::assertSent(Mailable::class, function (Mailable $mail): bool {
|
||||||
$mail->assertTo('ada@example.com');
|
$mail->assertTo('ada@example.com');
|
||||||
$mail->assertHasSubject('Bienvenido a OnTicket');
|
$mail->assertHasSubject('Bienvenido a Mail Tenant');
|
||||||
|
|
||||||
return str_contains($mail->render(), 'Ada Lovelace')
|
return str_contains($mail->render(), 'Ada Lovelace')
|
||||||
&& str_contains($mail->render(), 'OnTicket')
|
&& str_contains($mail->render(), 'Mail Tenant');
|
||||||
&& ! str_contains($mail->render(), 'Mail Tenant')
|
|
||||||
&& str_contains($mail->render(), 'border-top: 4px solid #ff7006');
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_it_sends_a_branded_password_reset_email(): void
|
public function test_it_sends_a_branded_password_reset_email(): void
|
||||||
{
|
{
|
||||||
$this->useWebsiteTypeBranding();
|
|
||||||
$attempt = $this->user->resetPasswordAttempts()->create([
|
$attempt = $this->user->resetPasswordAttempts()->create([
|
||||||
'codigo' => '0123',
|
'codigo' => '0123',
|
||||||
]);
|
]);
|
||||||
@@ -100,15 +95,13 @@ class NotificationMailServiceTest extends TestCase
|
|||||||
|
|
||||||
Mail::assertSent(Mailable::class, function (Mailable $mail): bool {
|
Mail::assertSent(Mailable::class, function (Mailable $mail): bool {
|
||||||
$mail->assertTo('ada@example.com');
|
$mail->assertTo('ada@example.com');
|
||||||
$mail->assertHasSubject('Código para recuperar tu contraseña - OnTicket');
|
$mail->assertHasSubject('Código para recuperar tu contraseña - Mail Tenant');
|
||||||
$rendered = $mail->render();
|
$rendered = $mail->render();
|
||||||
|
|
||||||
return str_contains($rendered, '0123')
|
return str_contains($rendered, '0123')
|
||||||
&& str_contains($rendered, 'Ada Lovelace')
|
&& str_contains($rendered, 'Ada Lovelace')
|
||||||
&& str_contains($rendered, 'OnTicket')
|
&& str_contains($rendered, 'Mail Tenant')
|
||||||
&& ! str_contains($rendered, 'Mail Tenant')
|
&& str_contains($rendered, '#112233');
|
||||||
&& str_contains($rendered, '#ff7006')
|
|
||||||
&& ! str_contains($rendered, 'border: 2px solid #112233');
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,9 +135,8 @@ class NotificationMailServiceTest extends TestCase
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_it_sends_one_purchase_confirmation_with_generated_tickets_attached(): void
|
public function test_it_sends_purchase_and_ticket_emails_to_the_purchase_recipient(): void
|
||||||
{
|
{
|
||||||
$this->useWebsiteTypeBranding();
|
|
||||||
$purchase = Purchase::query()->create([
|
$purchase = Purchase::query()->create([
|
||||||
'tenant_codigo' => $this->tenant->codigo,
|
'tenant_codigo' => $this->tenant->codigo,
|
||||||
'user_id' => $this->user->id,
|
'user_id' => $this->user->id,
|
||||||
@@ -175,65 +167,26 @@ class NotificationMailServiceTest extends TestCase
|
|||||||
$ticket = Ticket::query()->create([
|
$ticket = Ticket::query()->create([
|
||||||
'tenant_code' => $this->tenant->codigo,
|
'tenant_code' => $this->tenant->codigo,
|
||||||
'ticket' => fake()->uuid(),
|
'ticket' => fake()->uuid(),
|
||||||
'source_purchase_id' => $purchase->id,
|
|
||||||
'source_catalog_item_id' => $catalogItem->id,
|
'source_catalog_item_id' => $catalogItem->id,
|
||||||
'user_id' => $this->user->id,
|
'user_id' => $this->user->id,
|
||||||
]);
|
]);
|
||||||
$service = app(NotificationMailService::class);
|
$service = app(NotificationMailService::class);
|
||||||
|
|
||||||
$service->sendPurchaseConfirmed($purchase->id);
|
$service->sendPurchasePaid($purchase->id);
|
||||||
|
$service->sendTicketsAvailable($purchase->id, [$ticket->id]);
|
||||||
Mail::assertSent(Mailable::class, 1);
|
|
||||||
Mail::assertSent(Mailable::class, function (Mailable $mail) use ($purchase, $ticket): bool {
|
|
||||||
$mail->assertTo('checkout@example.com');
|
|
||||||
$attachment = collect($mail->rawAttachments)->firstWhere('name', "tickets_{$ticket->id}.pdf");
|
|
||||||
|
|
||||||
return $mail->subject === "Compra confirmada - Compra #{$purchase->id}"
|
|
||||||
&& str_contains($mail->render(), '¡Compra realizada con éxito!')
|
|
||||||
&& str_contains($mail->render(), 'Total pagado')
|
|
||||||
&& str_contains($mail->render(), 'Tus tickets ya están disponibles')
|
|
||||||
&& $attachment !== null
|
|
||||||
&& $attachment['options'] === ['mime' => 'application/pdf']
|
|
||||||
&& str_starts_with($attachment['data'], '%PDF-')
|
|
||||||
&& str_contains($mail->render(), 'border-top: 4px solid #112233')
|
|
||||||
&& ! str_contains($mail->render(), 'border-top: 4px solid #ff7006');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_purchase_confirmation_omits_ticket_content_and_attachment_without_tickets(): void
|
|
||||||
{
|
|
||||||
$purchase = Purchase::query()->create([
|
|
||||||
'tenant_codigo' => $this->tenant->codigo,
|
|
||||||
'user_id' => $this->user->id,
|
|
||||||
'status' => Purchase::STATUS_PAID,
|
|
||||||
'payment_method' => 'transfer',
|
|
||||||
'total' => 25,
|
|
||||||
]);
|
|
||||||
|
|
||||||
app(NotificationMailService::class)->sendPurchaseConfirmed($purchase->id);
|
|
||||||
|
|
||||||
|
Mail::assertSent(Mailable::class, 2);
|
||||||
Mail::assertSent(Mailable::class, function (Mailable $mail) use ($purchase): bool {
|
Mail::assertSent(Mailable::class, function (Mailable $mail) use ($purchase): bool {
|
||||||
return $mail->subject === "Compra confirmada - Compra #{$purchase->id}"
|
$mail->assertTo('checkout@example.com');
|
||||||
&& str_contains($mail->render(), '¡Compra realizada con éxito!')
|
|
||||||
&& ! str_contains($mail->render(), 'Tus tickets ya están disponibles')
|
return $mail->subject === "Pago confirmado - Compra #{$purchase->id}"
|
||||||
&& $mail->rawAttachments === [];
|
&& str_contains($mail->render(), 'Total pagado');
|
||||||
});
|
});
|
||||||
}
|
Mail::assertSent(Mailable::class, function (Mailable $mail): bool {
|
||||||
|
$mail->assertTo('checkout@example.com');
|
||||||
|
|
||||||
private function useWebsiteTypeBranding(): void
|
return $mail->subject === 'Tus tickets ya están disponibles'
|
||||||
{
|
&& str_contains($mail->render(), 'Entrada general');
|
||||||
$websiteType = WebsiteType::query()->create([
|
});
|
||||||
'codigo' => 'onticket',
|
|
||||||
'nombre' => 'OnTicket',
|
|
||||||
'dominio' => 'onticket.local',
|
|
||||||
'primary_color' => '#ff7006',
|
|
||||||
'body_color' => '#666666',
|
|
||||||
'background_color' => '#f8f8f8',
|
|
||||||
'surface_color' => '#ffffff',
|
|
||||||
'login_header_footer_color' => '#838383',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->tenant->update(['website_type_code' => $websiteType->codigo]);
|
|
||||||
$this->tenant->unsetRelation('websiteType');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature\Notification;
|
|
||||||
|
|
||||||
use App\Domains\Notification\Listeners\SendPurchaseConfirmedEmail;
|
|
||||||
use App\Domains\Notification\Services\NotificationMailService;
|
|
||||||
use App\Domains\Purchase\Events\PurchasePaid;
|
|
||||||
use Mockery;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class QueuedNotificationListenerTest extends TestCase
|
|
||||||
{
|
|
||||||
public function test_purchase_confirmed_email_delegates_with_the_purchase_id(): void
|
|
||||||
{
|
|
||||||
$mailService = Mockery::mock(NotificationMailService::class);
|
|
||||||
$mailService->shouldReceive('sendPurchaseConfirmed')
|
|
||||||
->once()
|
|
||||||
->with(123);
|
|
||||||
$this->app->instance(NotificationMailService::class, $mailService);
|
|
||||||
|
|
||||||
(new SendPurchaseConfirmedEmail)->handle(new PurchasePaid(123));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_purchase_paid_event_only_serializes_the_purchase_id(): void
|
|
||||||
{
|
|
||||||
$purchasePaid = unserialize(serialize(new PurchasePaid(123)));
|
|
||||||
|
|
||||||
$this->assertSame(123, $purchasePaid->purchaseId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -796,18 +796,12 @@ class StorePurchaseTest extends TestCase
|
|||||||
|
|
||||||
public function test_it_updates_customer_data_for_a_pending_payment_purchase(): void
|
public function test_it_updates_customer_data_for_a_pending_payment_purchase(): void
|
||||||
{
|
{
|
||||||
config()->set('purchase.checkout_expiration_minutes', 30);
|
|
||||||
$now = now()->startOfSecond();
|
|
||||||
$this->travelTo($now);
|
|
||||||
|
|
||||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
$variant = $this->createVariantForTenant('sonder', 10, '50.00');
|
$variant = $this->createVariantForTenant('sonder', 10, '50.00');
|
||||||
$purchase = $this->createCheckoutPurchase($user, 'sonder', $variant, 1);
|
$purchase = $this->createCheckoutPurchase($user, 'sonder', $variant, 1);
|
||||||
$purchase->update(['status' => Purchase::STATUS_PENDING_PAYMENT]);
|
$purchase->update(['status' => Purchase::STATUS_PENDING_PAYMENT]);
|
||||||
|
|
||||||
$this->travel(10)->minutes();
|
|
||||||
|
|
||||||
$this->actingAs($user, 'sanctum')
|
$this->actingAs($user, 'sanctum')
|
||||||
->patchJson("/api/tenants/sonder/compras/{$purchase->id}/customer-data", [
|
->patchJson("/api/tenants/sonder/compras/{$purchase->id}/customer-data", [
|
||||||
'dni' => '987654321',
|
'dni' => '987654321',
|
||||||
@@ -824,12 +818,6 @@ class StorePurchaseTest extends TestCase
|
|||||||
'status' => Purchase::STATUS_PENDING_PAYMENT,
|
'status' => Purchase::STATUS_PENDING_PAYMENT,
|
||||||
'dni' => '987654321',
|
'dni' => '987654321',
|
||||||
]);
|
]);
|
||||||
$this->assertDatabaseHas('stock_reservations', [
|
|
||||||
'id' => $purchase->stock_reservation_id,
|
|
||||||
'expires_at' => $now->copy()->addMinutes(30)->toDateTimeString(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->travelBack();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_checkout_items_are_immutable_and_editing_routes_are_unavailable(): void
|
public function test_checkout_items_are_immutable_and_editing_routes_are_unavailable(): void
|
||||||
|
|||||||
@@ -161,7 +161,6 @@ class DesfilePuraTendenciaSeederTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
$this->assertDatabaseHas('featured_groups', [
|
$this->assertDatabaseHas('featured_groups', [
|
||||||
'tenant_code' => 'desfile_pura_tendencia',
|
'tenant_code' => 'desfile_pura_tendencia',
|
||||||
'code' => 'entradas',
|
|
||||||
'source_type' => 'all',
|
'source_type' => 'all',
|
||||||
'product_layout' => 'ticket_selector',
|
'product_layout' => 'ticket_selector',
|
||||||
'group_layout' => 'single',
|
'group_layout' => 'single',
|
||||||
@@ -218,13 +217,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 +288,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 +311,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')
|
||||||
|
|||||||
@@ -151,7 +151,6 @@ class FiestaFutbolInfantilProductSeederTest extends TestCase
|
|||||||
));
|
));
|
||||||
|
|
||||||
$featuredGroup = FeaturedGroup::query()->where('tenant_code', $tenant->codigo)->sole();
|
$featuredGroup = FeaturedGroup::query()->where('tenant_code', $tenant->codigo)->sole();
|
||||||
$this->assertSame('productos', $featuredGroup->code);
|
|
||||||
$this->assertSame(FeaturedGroupSource::All, $featuredGroup->source_type);
|
$this->assertSame(FeaturedGroupSource::All, $featuredGroup->source_type);
|
||||||
$this->assertSame(ProductLayout::Row, $featuredGroup->product_layout);
|
$this->assertSame(ProductLayout::Row, $featuredGroup->product_layout);
|
||||||
$this->assertSame(GroupLayout::SimpleVertical, $featuredGroup->group_layout);
|
$this->assertSame(GroupLayout::SimpleVertical, $featuredGroup->group_layout);
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ class ProductCatalogFromImagesSeederTest extends TestCase
|
|||||||
->pluck('id');
|
->pluck('id');
|
||||||
|
|
||||||
$this->assertNotNull($paginatedGroup);
|
$this->assertNotNull($paginatedGroup);
|
||||||
$this->assertSame('productos', $paginatedGroup->code);
|
|
||||||
$this->assertSame(ProductLayout::ColumnWithImage, $paginatedGroup->product_layout);
|
$this->assertSame(ProductLayout::ColumnWithImage, $paginatedGroup->product_layout);
|
||||||
$this->assertSame(GroupLayout::Paginated, $paginatedGroup->group_layout);
|
$this->assertSame(GroupLayout::Paginated, $paginatedGroup->group_layout);
|
||||||
$this->assertSame(FeaturedGroupSource::All, $paginatedGroup->source_type);
|
$this->assertSame(FeaturedGroupSource::All, $paginatedGroup->source_type);
|
||||||
@@ -77,7 +76,6 @@ class ProductCatalogFromImagesSeederTest extends TestCase
|
|||||||
$this->assertCount(0, $paginatedGroup->featuredItems);
|
$this->assertCount(0, $paginatedGroup->featuredItems);
|
||||||
|
|
||||||
$this->assertNotNull($carouselGroup);
|
$this->assertNotNull($carouselGroup);
|
||||||
$this->assertSame('productos-destacados', $carouselGroup->code);
|
|
||||||
$this->assertSame(ProductLayout::ColumnWithImage, $carouselGroup->product_layout);
|
$this->assertSame(ProductLayout::ColumnWithImage, $carouselGroup->product_layout);
|
||||||
$this->assertSame(GroupLayout::Carousel, $carouselGroup->group_layout);
|
$this->assertSame(GroupLayout::Carousel, $carouselGroup->group_layout);
|
||||||
$this->assertSame(FeaturedGroupSource::Manual, $carouselGroup->source_type);
|
$this->assertSame(FeaturedGroupSource::Manual, $carouselGroup->source_type);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class WebsiteTypeSeederTest extends TestCase
|
|||||||
$this->seed(WebsiteTypeSeeder::class);
|
$this->seed(WebsiteTypeSeeder::class);
|
||||||
|
|
||||||
$this->assertSame(2, WebsiteType::query()->count());
|
$this->assertSame(2, WebsiteType::query()->count());
|
||||||
$this->assertSame(5, Attachment::query()->count());
|
$this->assertSame(4, Attachment::query()->count());
|
||||||
|
|
||||||
$expectedPresentation = [
|
$expectedPresentation = [
|
||||||
'primary_color' => '#FF7006',
|
'primary_color' => '#FF7006',
|
||||||
@@ -49,8 +49,6 @@ class WebsiteTypeSeederTest extends TestCase
|
|||||||
Storage::disk('s3')->assertExists($shopIt->siteLogo->path);
|
Storage::disk('s3')->assertExists($shopIt->siteLogo->path);
|
||||||
$this->assertSame('onticket_footer_logo.png', $shopIt->footerLogo->filename);
|
$this->assertSame('onticket_footer_logo.png', $shopIt->footerLogo->filename);
|
||||||
Storage::disk('s3')->assertExists($shopIt->footerLogo->path);
|
Storage::disk('s3')->assertExists($shopIt->footerLogo->path);
|
||||||
$this->assertSame('onticket_favicon.svg', $shopIt->favicon->filename);
|
|
||||||
Storage::disk('s3')->assertExists($shopIt->favicon->path);
|
|
||||||
$this->assertSame(['carousel'], $shopIt->extras->pluck('codigo')->all());
|
$this->assertSame(['carousel'], $shopIt->extras->pluck('codigo')->all());
|
||||||
$this->assertSame('Carrusel principal', $shopIt->extras->sole()->nombre);
|
$this->assertSame('Carrusel principal', $shopIt->extras->sole()->nombre);
|
||||||
$this->assertSame([
|
$this->assertSame([
|
||||||
@@ -81,8 +79,6 @@ class WebsiteTypeSeederTest extends TestCase
|
|||||||
Storage::disk('s3')->assertExists($onTicket->footerLogo->path);
|
Storage::disk('s3')->assertExists($onTicket->footerLogo->path);
|
||||||
$this->assertNotSame($shopIt->site_logo, $onTicket->site_logo);
|
$this->assertNotSame($shopIt->site_logo, $onTicket->site_logo);
|
||||||
$this->assertNotSame($shopIt->footer_logo, $onTicket->footer_logo);
|
$this->assertNotSame($shopIt->footer_logo, $onTicket->footer_logo);
|
||||||
$this->assertSame($shopIt->favicon_id, $onTicket->favicon_id);
|
|
||||||
$this->assertSame('onticket_favicon.svg', $onTicket->favicon->filename);
|
|
||||||
$this->assertEqualsCanonicalizing(
|
$this->assertEqualsCanonicalizing(
|
||||||
['heroConfig', 'eventConfig', 'additionalInfoConfig'],
|
['heroConfig', 'eventConfig', 'additionalInfoConfig'],
|
||||||
$onTicket->extras->pluck('codigo')->all(),
|
$onTicket->extras->pluck('codigo')->all(),
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ class BootstrapAdminAppControllerTest extends TestCase
|
|||||||
public function test_it_publicly_bootstraps_the_admin_app_by_domain(): void
|
public function test_it_publicly_bootstraps_the_admin_app_by_domain(): void
|
||||||
{
|
{
|
||||||
$footerLogo = Attachment::factory()->create();
|
$footerLogo = Attachment::factory()->create();
|
||||||
$favicon = Attachment::factory()->create();
|
|
||||||
|
|
||||||
WebsiteType::query()->create([
|
WebsiteType::query()->create([
|
||||||
'codigo' => 'shopit',
|
'codigo' => 'shopit',
|
||||||
@@ -32,7 +31,6 @@ class BootstrapAdminAppControllerTest extends TestCase
|
|||||||
'border_color' => '#eaeaea',
|
'border_color' => '#eaeaea',
|
||||||
'login_header_footer_color' => '#313131',
|
'login_header_footer_color' => '#313131',
|
||||||
'footer_logo' => $footerLogo->id,
|
'footer_logo' => $footerLogo->id,
|
||||||
'favicon_id' => $favicon->id,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->getJson('/api/v1/adminapp/bootstrap/ADMIN.SHOPIT.TEST')
|
$this->getJson('/api/v1/adminapp/bootstrap/ADMIN.SHOPIT.TEST')
|
||||||
@@ -43,7 +41,6 @@ class BootstrapAdminAppControllerTest extends TestCase
|
|||||||
->assertJsonPath('data.login_header_footer_color', '#313131')
|
->assertJsonPath('data.login_header_footer_color', '#313131')
|
||||||
->assertJsonPath('data.site_logo', null)
|
->assertJsonPath('data.site_logo', null)
|
||||||
->assertJsonPath('data.footer_logo', $footerLogo->getTemporaryUrl(1440))
|
->assertJsonPath('data.footer_logo', $footerLogo->getTemporaryUrl(1440))
|
||||||
->assertJsonPath('data.favicon', $favicon->getTemporaryUrl(1440))
|
|
||||||
->assertJsonMissingPath('data.forms')
|
->assertJsonMissingPath('data.forms')
|
||||||
->assertJsonMissingPath('data.codigo')
|
->assertJsonMissingPath('data.codigo')
|
||||||
->assertJsonMissingPath('data.nombre')
|
->assertJsonMissingPath('data.nombre')
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ class BootstrapScannerControllerTest extends TestCase
|
|||||||
public function test_it_publicly_bootstraps_the_scanner_by_scanner_domain(): void
|
public function test_it_publicly_bootstraps_the_scanner_by_scanner_domain(): void
|
||||||
{
|
{
|
||||||
$siteLogo = Attachment::factory()->create();
|
$siteLogo = Attachment::factory()->create();
|
||||||
$favicon = Attachment::factory()->create();
|
|
||||||
|
|
||||||
WebsiteType::query()->create([
|
WebsiteType::query()->create([
|
||||||
'codigo' => 'shopit',
|
'codigo' => 'shopit',
|
||||||
@@ -33,7 +32,6 @@ class BootstrapScannerControllerTest extends TestCase
|
|||||||
'border_color' => '#eaeaea',
|
'border_color' => '#eaeaea',
|
||||||
'login_header_footer_color' => '#313131',
|
'login_header_footer_color' => '#313131',
|
||||||
'site_logo' => $siteLogo->id,
|
'site_logo' => $siteLogo->id,
|
||||||
'favicon_id' => $favicon->id,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->getJson('/api/v1/scanner/bootstrap/SCANNER.SHOPIT.TEST')
|
$this->getJson('/api/v1/scanner/bootstrap/SCANNER.SHOPIT.TEST')
|
||||||
@@ -42,7 +40,6 @@ class BootstrapScannerControllerTest extends TestCase
|
|||||||
->assertJsonPath('data.primary_color', '#112233')
|
->assertJsonPath('data.primary_color', '#112233')
|
||||||
->assertJsonPath('data.site_logo', $siteLogo->getTemporaryUrl(1440))
|
->assertJsonPath('data.site_logo', $siteLogo->getTemporaryUrl(1440))
|
||||||
->assertJsonPath('data.footer_logo', null)
|
->assertJsonPath('data.footer_logo', null)
|
||||||
->assertJsonPath('data.favicon', $favicon->getTemporaryUrl(1440))
|
|
||||||
->assertJsonMissingPath('data.codigo')
|
->assertJsonMissingPath('data.codigo')
|
||||||
->assertJsonMissingPath('data.nombre')
|
->assertJsonMissingPath('data.nombre')
|
||||||
->assertJsonMissingPath('data.dominio')
|
->assertJsonMissingPath('data.dominio')
|
||||||
|
|||||||
@@ -69,31 +69,4 @@ class WebsiteTypeServiceTest extends TestCase
|
|||||||
'favicon_id' => $favicon->id,
|
'favicon_id' => $favicon->id,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_it_keeps_a_shared_favicon_when_one_website_type_replaces_it(): void
|
|
||||||
{
|
|
||||||
Storage::fake('s3');
|
|
||||||
|
|
||||||
$service = app(WebsiteTypeService::class);
|
|
||||||
$shopIt = $service->create([
|
|
||||||
'codigo' => 'shopit',
|
|
||||||
'nombre' => 'ShopIt',
|
|
||||||
'favicon' => UploadedFile::fake()->image('shared-favicon.png', 32, 32),
|
|
||||||
]);
|
|
||||||
$sharedFavicon = $shopIt->favicon()->firstOrFail();
|
|
||||||
$onTicket = $service->create([
|
|
||||||
'codigo' => 'onticket',
|
|
||||||
'nombre' => 'OnTicket',
|
|
||||||
'favicon' => $sharedFavicon->key,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$service->updateOrCreate(
|
|
||||||
['codigo' => 'shopit'],
|
|
||||||
['favicon' => UploadedFile::fake()->image('shopit-favicon.png', 32, 32)],
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertSame($sharedFavicon->id, $onTicket->fresh()->favicon_id);
|
|
||||||
$this->assertDatabaseHas('attachments', ['id' => $sharedFavicon->id]);
|
|
||||||
Storage::disk('s3')->assertExists($sharedFavicon->path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,6 +11,7 @@ use App\Domains\Catalog\Models\CatalogItem;
|
|||||||
use App\Domains\Catalog\Models\Inventory;
|
use App\Domains\Catalog\Models\Inventory;
|
||||||
use App\Domains\Catalog\Services\CatalogService;
|
use App\Domains\Catalog\Services\CatalogService;
|
||||||
use App\Domains\Event\Models\EventDate;
|
use App\Domains\Event\Models\EventDate;
|
||||||
|
use App\Domains\Notification\Events\TicketsAvailable;
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
use App\Domains\Shared\Enums\FieldType;
|
use App\Domains\Shared\Enums\FieldType;
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
@@ -21,6 +22,7 @@ use App\Domains\Ticket\Services\TicketGeneratorService;
|
|||||||
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
use Illuminate\Support\Facades\Queue;
|
use Illuminate\Support\Facades\Queue;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
@@ -218,6 +220,7 @@ class TicketGeneratorServiceTest extends TestCase
|
|||||||
|
|
||||||
public function test_marking_a_purchase_as_paid_generates_its_tickets_once(): void
|
public function test_marking_a_purchase_as_paid_generates_its_tickets_once(): void
|
||||||
{
|
{
|
||||||
|
Event::fake([TicketsAvailable::class]);
|
||||||
$item = $this->createTicketableItem('paid-ticket');
|
$item = $this->createTicketableItem('paid-ticket');
|
||||||
$purchase = $this->createPurchase($item, 2);
|
$purchase = $this->createPurchase($item, 2);
|
||||||
$purchase->setRelation('items', new EloquentCollection);
|
$purchase->setRelation('items', new EloquentCollection);
|
||||||
@@ -226,6 +229,7 @@ class TicketGeneratorServiceTest extends TestCase
|
|||||||
|
|
||||||
$this->assertSame(Purchase::STATUS_PAID, $purchase->status);
|
$this->assertSame(Purchase::STATUS_PAID, $purchase->status);
|
||||||
$this->assertDatabaseCount('tickets', 2);
|
$this->assertDatabaseCount('tickets', 2);
|
||||||
|
Event::assertDispatchedTimes(TicketsAvailable::class, 1);
|
||||||
|
|
||||||
$this->actingAs($this->user, 'sanctum')
|
$this->actingAs($this->user, 'sanctum')
|
||||||
->getJson("/api/tenants/{$this->tenant->codigo}/compras/{$purchase->id}")
|
->getJson("/api/tenants/{$this->tenant->codigo}/compras/{$purchase->id}")
|
||||||
@@ -236,6 +240,7 @@ class TicketGeneratorServiceTest extends TestCase
|
|||||||
$purchase->markAsPaid();
|
$purchase->markAsPaid();
|
||||||
|
|
||||||
$this->assertDatabaseCount('tickets', 2);
|
$this->assertDatabaseCount('tickets', 2);
|
||||||
|
Event::assertDispatchedTimes(TicketsAvailable::class, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_a_ticket_generated_from_a_purchase_keeps_its_source_ids(): void
|
public function test_a_ticket_generated_from_a_purchase_keeps_its_source_ids(): void
|
||||||
@@ -448,6 +453,7 @@ class TicketGeneratorServiceTest extends TestCase
|
|||||||
|
|
||||||
public function test_marking_a_purchase_as_paid_ignores_items_without_tickets(): void
|
public function test_marking_a_purchase_as_paid_ignores_items_without_tickets(): void
|
||||||
{
|
{
|
||||||
|
Event::fake([TicketsAvailable::class]);
|
||||||
$item = $this->createTicketableItem('regular-product');
|
$item = $this->createTicketableItem('regular-product');
|
||||||
$item->update(['has_tickets' => false]);
|
$item->update(['has_tickets' => false]);
|
||||||
$purchase = $this->createPurchase($item->fresh(), 1);
|
$purchase = $this->createPurchase($item->fresh(), 1);
|
||||||
@@ -456,6 +462,7 @@ class TicketGeneratorServiceTest extends TestCase
|
|||||||
|
|
||||||
$this->assertSame(Purchase::STATUS_PAID, $purchase->status);
|
$this->assertSame(Purchase::STATUS_PAID, $purchase->status);
|
||||||
$this->assertDatabaseCount('tickets', 0);
|
$this->assertDatabaseCount('tickets', 0);
|
||||||
|
Event::assertNotDispatched(TicketsAvailable::class);
|
||||||
|
|
||||||
$this->actingAs($this->user, 'sanctum')
|
$this->actingAs($this->user, 'sanctum')
|
||||||
->getJson("/api/tenants/{$this->tenant->codigo}/compras/{$purchase->id}")
|
->getJson("/api/tenants/{$this->tenant->codigo}/compras/{$purchase->id}")
|
||||||
|
|||||||
@@ -2,25 +2,9 @@
|
|||||||
|
|
||||||
namespace Tests;
|
namespace Tests;
|
||||||
|
|
||||||
use Illuminate\Foundation\Application;
|
|
||||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||||
use RuntimeException;
|
|
||||||
|
|
||||||
abstract class TestCase extends BaseTestCase
|
abstract class TestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
public function createApplication(): Application
|
//
|
||||||
{
|
|
||||||
$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')) {
|
|
||||||
throw new RuntimeException(
|
|
||||||
"Unsafe test database [{$database}]. Tests may only use an in-memory SQLite database or a database ending in _test.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $app;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,13 +17,11 @@ class AdminAppBootstrapResourceTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
$websiteType->setRelation('siteLogo', null);
|
$websiteType->setRelation('siteLogo', null);
|
||||||
$websiteType->setRelation('footerLogo', null);
|
$websiteType->setRelation('footerLogo', null);
|
||||||
$websiteType->setRelation('favicon', null);
|
|
||||||
$data = AdminAppBootstrapResource::make([
|
$data = AdminAppBootstrapResource::make([
|
||||||
'website_type' => $websiteType,
|
'website_type' => $websiteType,
|
||||||
])->resolve(request());
|
])->resolve(request());
|
||||||
|
|
||||||
$this->assertSame('shopit', $data['website_type_code']);
|
$this->assertSame('shopit', $data['website_type_code']);
|
||||||
$this->assertNull($data['favicon']);
|
|
||||||
$this->assertArrayNotHasKey('forms', $data);
|
$this->assertArrayNotHasKey('forms', $data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,112 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Unit\Notification;
|
|
||||||
|
|
||||||
use App\Domains\Integration\Services\MailService;
|
|
||||||
use App\Domains\Notification\Services\NotificationMailService;
|
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
|
||||||
use App\Domains\Ticket\Services\TicketPdfService;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
use Mockery;
|
|
||||||
use ReflectionMethod;
|
|
||||||
use RuntimeException;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class NotificationMailServiceLoggingTest extends TestCase
|
|
||||||
{
|
|
||||||
private NotificationMailService $service;
|
|
||||||
|
|
||||||
private MailService $mailService;
|
|
||||||
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
$this->mailService = Mockery::mock(MailService::class);
|
|
||||||
$this->service = new NotificationMailService(
|
|
||||||
$this->mailService,
|
|
||||||
Mockery::mock(TicketPdfService::class),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_logs_and_swallows_a_missing_purchase(): void
|
|
||||||
{
|
|
||||||
$this->createEmptyPurchasesTable();
|
|
||||||
|
|
||||||
Log::shouldReceive('channel')->once()->with('emails')->andReturnSelf();
|
|
||||||
Log::shouldReceive('warning')->once()->with(
|
|
||||||
'Notification email skipped.',
|
|
||||||
[
|
|
||||||
'purchase_id' => 123,
|
|
||||||
'reason' => 'purchase_not_found',
|
|
||||||
'missing_model' => Purchase::class,
|
|
||||||
'email_type' => 'purchase_confirmed',
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->service->sendPurchaseConfirmed(123);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_logs_successful_delivery_with_the_mailer(): void
|
|
||||||
{
|
|
||||||
$this->mailService->shouldReceive('mailerName')->once()->andReturn('smtp');
|
|
||||||
Log::shouldReceive('channel')->once()->with('emails')->andReturnSelf();
|
|
||||||
Log::shouldReceive('info')->once()->with(
|
|
||||||
'Notification email sent.',
|
|
||||||
[
|
|
||||||
'user_id' => 10,
|
|
||||||
'tenant_code' => 'tenant-test',
|
|
||||||
'email_type' => 'welcome',
|
|
||||||
'mailer' => 'smtp',
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->sendLogged(
|
|
||||||
'welcome',
|
|
||||||
['user_id' => 10],
|
|
||||||
fn (): array => ['tenant_code' => 'tenant-test'],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_logs_and_rethrows_delivery_failures(): void
|
|
||||||
{
|
|
||||||
$exception = new RuntimeException('SMTP unavailable.');
|
|
||||||
Log::shouldReceive('channel')->once()->with('emails')->andReturnSelf();
|
|
||||||
Log::shouldReceive('error')->once()->with(
|
|
||||||
'Notification email delivery failed.',
|
|
||||||
Mockery::on(fn (array $context): bool => $context['purchase_id'] === 123
|
|
||||||
&& $context['email_type'] === 'purchase_confirmed'
|
|
||||||
&& $context['exception'] === $exception),
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->expectExceptionObject($exception);
|
|
||||||
|
|
||||||
$this->sendLogged('purchase_confirmed', ['purchase_id' => 123], function () use ($exception): array {
|
|
||||||
throw $exception;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param array<string, mixed> $context */
|
|
||||||
private function sendLogged(string $emailType, array $context, callable $send): void
|
|
||||||
{
|
|
||||||
(new ReflectionMethod($this->service, 'sendLogged'))->invoke(
|
|
||||||
$this->service,
|
|
||||||
$emailType,
|
|
||||||
$context,
|
|
||||||
$send,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createEmptyPurchasesTable(): void
|
|
||||||
{
|
|
||||||
config([
|
|
||||||
'database.default' => 'sqlite',
|
|
||||||
'database.connections.sqlite.database' => ':memory:',
|
|
||||||
]);
|
|
||||||
Schema::connection('sqlite')->create('compras', function (Blueprint $table): void {
|
|
||||||
$table->id();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,12 +5,13 @@ namespace Tests\Unit\Notification;
|
|||||||
use App\Domains\Notification\Events\PasswordResetRequested;
|
use App\Domains\Notification\Events\PasswordResetRequested;
|
||||||
use App\Domains\Notification\Listeners\SendPasswordResetEmail;
|
use App\Domains\Notification\Listeners\SendPasswordResetEmail;
|
||||||
use App\Domains\Notification\Services\NotificationMailService;
|
use App\Domains\Notification\Services\NotificationMailService;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class SendPasswordResetEmailTest extends TestCase
|
class SendPasswordResetEmailTest extends TestCase
|
||||||
{
|
{
|
||||||
public function test_it_delegates_mail_failures_to_the_notification_service(): void
|
public function test_it_logs_and_rethrows_mail_failures(): void
|
||||||
{
|
{
|
||||||
$exception = new RuntimeException('SMTP unavailable.');
|
$exception = new RuntimeException('SMTP unavailable.');
|
||||||
$mailService = \Mockery::mock(NotificationMailService::class);
|
$mailService = \Mockery::mock(NotificationMailService::class);
|
||||||
@@ -20,6 +21,16 @@ class SendPasswordResetEmailTest extends TestCase
|
|||||||
->andThrow($exception);
|
->andThrow($exception);
|
||||||
$this->app->instance(NotificationMailService::class, $mailService);
|
$this->app->instance(NotificationMailService::class, $mailService);
|
||||||
|
|
||||||
|
Log::shouldReceive('error')
|
||||||
|
->once()
|
||||||
|
->with(
|
||||||
|
'Failed to send password reset email.',
|
||||||
|
\Mockery::on(fn (array $context): bool => $context['attempt_id'] === 10
|
||||||
|
&& $context['tenant_code'] === 'tenant-test'
|
||||||
|
&& $context['channel'] === PasswordResetRequested::CHANNEL_STOREFRONT
|
||||||
|
&& $context['exception'] === $exception),
|
||||||
|
);
|
||||||
|
|
||||||
$this->expectExceptionObject($exception);
|
$this->expectExceptionObject($exception);
|
||||||
|
|
||||||
(new SendPasswordResetEmail)->handle(
|
(new SendPasswordResetEmail)->handle(
|
||||||
|
|||||||
@@ -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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Unit\Purchase;
|
|
||||||
|
|
||||||
use App\Domains\Catalog\Models\StockReservation;
|
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
|
||||||
use App\Domains\Purchase\Resources\PurchaseResource;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Carbon;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class PurchaseResourceTest extends TestCase
|
|
||||||
{
|
|
||||||
public function test_it_exposes_the_remaining_checkout_time_using_the_server_clock(): void
|
|
||||||
{
|
|
||||||
$now = now()->startOfSecond();
|
|
||||||
$this->travelTo($now);
|
|
||||||
$expiresAt = $now->copy()->addMinutes(12);
|
|
||||||
|
|
||||||
$resource = $this->resourceFor(Purchase::STATUS_PENDING_PAYMENT, $expiresAt);
|
|
||||||
|
|
||||||
$this->assertTrue($expiresAt->equalTo($resource['expires_at']));
|
|
||||||
$this->assertSame(720, $resource['expires_in_seconds']);
|
|
||||||
$this->assertTrue($now->equalTo($resource['server_time']));
|
|
||||||
|
|
||||||
$this->travelBack();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_clamps_an_overdue_checkout_to_zero_seconds(): void
|
|
||||||
{
|
|
||||||
$now = now()->startOfSecond();
|
|
||||||
$this->travelTo($now);
|
|
||||||
|
|
||||||
$resource = $this->resourceFor(
|
|
||||||
Purchase::STATUS_CREATED,
|
|
||||||
$now->copy()->subSecond(),
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertSame(0, $resource['expires_in_seconds']);
|
|
||||||
|
|
||||||
$this->travelBack();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_exposes_null_expiration_after_the_purchase_enters_review(): void
|
|
||||||
{
|
|
||||||
$resource = $this->resourceFor(
|
|
||||||
Purchase::STATUS_IN_REVIEW,
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertNull($resource['expires_at']);
|
|
||||||
$this->assertNull($resource['expires_in_seconds']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @return array<string, mixed> */
|
|
||||||
private function resourceFor(string $status, ?Carbon $expiresAt): array
|
|
||||||
{
|
|
||||||
$purchase = (new Purchase)->forceFill([
|
|
||||||
'status' => $status,
|
|
||||||
'total' => '0.00',
|
|
||||||
]);
|
|
||||||
$purchase->setRelation('stockReservation', (new StockReservation)->forceFill([
|
|
||||||
'status' => StockReservation::STATUS_ACTIVE,
|
|
||||||
'expires_at' => $expiresAt,
|
|
||||||
]));
|
|
||||||
|
|
||||||
return (new PurchaseResource($purchase))->toArray(Request::create('/'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,146 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Unit\Sale;
|
|
||||||
|
|
||||||
use App\Domains\Auth\Models\User;
|
|
||||||
use App\Domains\Logging\Models\ValueChange;
|
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
|
||||||
use App\Domains\Sale\Services\AdminAppSaleExcelService;
|
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
|
||||||
use Illuminate\Support\Carbon;
|
|
||||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
||||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class AdminAppSaleExcelServiceTest extends TestCase
|
|
||||||
{
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
Carbon::setTestNow(Carbon::parse('2026-08-24 17:53:00', 'UTC'));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function tearDown(): void
|
|
||||||
{
|
|
||||||
Carbon::setTestNow();
|
|
||||||
|
|
||||||
parent::tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_downloads_filtered_sales_as_an_excel_file(): void
|
|
||||||
{
|
|
||||||
$response = app(AdminAppSaleExcelService::class)->downloadSales(
|
|
||||||
$this->tenant(),
|
|
||||||
collect([$this->sale()]),
|
|
||||||
'America/La_Paz',
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertExcelResponse(
|
|
||||||
$response,
|
|
||||||
'ventas_acme_20260824_135300.xlsx',
|
|
||||||
function (string $path): void {
|
|
||||||
$sheet = IOFactory::load($path)->getActiveSheet();
|
|
||||||
|
|
||||||
$this->assertSame('Ventas', $sheet->getTitle());
|
|
||||||
$this->assertSame('Cliente Test', $sheet->getCell('C2')->getValue());
|
|
||||||
$this->assertSame('Confirmado', $sheet->getCell('E2')->getValue());
|
|
||||||
$this->assertSame(25000.0, $sheet->getCell('F2')->getValue());
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_it_downloads_the_modification_history_as_an_excel_file(): void
|
|
||||||
{
|
|
||||||
$sale = $this->sale();
|
|
||||||
$admin = (new User)->forceFill([
|
|
||||||
'id' => 10,
|
|
||||||
'nombre_apellido' => 'Admin Test',
|
|
||||||
'email' => 'admin@example.test',
|
|
||||||
]);
|
|
||||||
$modification = (new ValueChange)->forceFill([
|
|
||||||
'id' => 1,
|
|
||||||
'trackable_id' => $sale->id,
|
|
||||||
'attribute' => 'status',
|
|
||||||
'old_value' => Purchase::STATUS_PENDING_PAYMENT,
|
|
||||||
'new_value' => Purchase::STATUS_PAID,
|
|
||||||
'changed_at' => now(),
|
|
||||||
'actor_type' => 'user',
|
|
||||||
]);
|
|
||||||
$modification->setRelation('trackable', $sale);
|
|
||||||
$modification->setRelation('user', $admin);
|
|
||||||
|
|
||||||
$response = app(AdminAppSaleExcelService::class)->downloadModifications(
|
|
||||||
$this->tenant(),
|
|
||||||
collect([$modification]),
|
|
||||||
'America/La_Paz',
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertExcelResponse(
|
|
||||||
$response,
|
|
||||||
'historial_modificaciones_acme_20260824_135300.xlsx',
|
|
||||||
function (string $path): void {
|
|
||||||
$sheet = IOFactory::load($path)->getActiveSheet();
|
|
||||||
|
|
||||||
$this->assertSame('Modificaciones', $sheet->getTitle());
|
|
||||||
$this->assertSame('#15', $sheet->getCell('C2')->getValue());
|
|
||||||
$this->assertSame('pending_payment', $sheet->getCell('F2')->getValue());
|
|
||||||
$this->assertSame('paid', $sheet->getCell('G2')->getValue());
|
|
||||||
$this->assertSame('Admin Test', $sheet->getCell('H2')->getValue());
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @param callable(string): void $assertSpreadsheet */
|
|
||||||
private function assertExcelResponse(
|
|
||||||
StreamedResponse $response,
|
|
||||||
string $filename,
|
|
||||||
callable $assertSpreadsheet,
|
|
||||||
): void {
|
|
||||||
$this->assertSame(
|
|
||||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
||||||
$response->headers->get('content-type'),
|
|
||||||
);
|
|
||||||
$this->assertStringContainsString(
|
|
||||||
"attachment; filename={$filename}",
|
|
||||||
(string) $response->headers->get('content-disposition'),
|
|
||||||
);
|
|
||||||
|
|
||||||
ob_start();
|
|
||||||
($response->getCallback())();
|
|
||||||
$contents = ob_get_clean();
|
|
||||||
$this->assertIsString($contents);
|
|
||||||
$this->assertStringStartsWith('PK', $contents);
|
|
||||||
|
|
||||||
$path = tempnam(sys_get_temp_dir(), 'shopit_excel_');
|
|
||||||
$this->assertNotFalse($path);
|
|
||||||
|
|
||||||
try {
|
|
||||||
file_put_contents($path, $contents);
|
|
||||||
$assertSpreadsheet($path);
|
|
||||||
} finally {
|
|
||||||
@unlink($path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function tenant(): Tenant
|
|
||||||
{
|
|
||||||
return (new Tenant)->forceFill([
|
|
||||||
'codigo' => 'acme',
|
|
||||||
'nombre' => 'Acme Eventos',
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function sale(): Purchase
|
|
||||||
{
|
|
||||||
return (new Purchase)->forceFill([
|
|
||||||
'id' => 15,
|
|
||||||
'created_at' => now(),
|
|
||||||
'nombre_apellido' => 'Cliente Test',
|
|
||||||
'quantity' => 2,
|
|
||||||
'status' => Purchase::STATUS_PAID,
|
|
||||||
'total' => '25000.00',
|
|
||||||
'tickets_count' => 2,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user