@open-mercato/core 0.4.7-develop-0a657b411f → 0.4.7-develop-e249d3e7d0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (278) hide show
  1. package/dist/generated/entities/carrier_shipment/index.js +37 -0
  2. package/dist/generated/entities/carrier_shipment/index.js.map +7 -0
  3. package/dist/generated/entities/gateway_transaction/index.js +47 -0
  4. package/dist/generated/entities/gateway_transaction/index.js.map +7 -0
  5. package/dist/generated/entities/webhook_processed_event/index.js +17 -0
  6. package/dist/generated/entities/webhook_processed_event/index.js.map +7 -0
  7. package/dist/generated/entities.ids.generated.js +10 -1
  8. package/dist/generated/entities.ids.generated.js.map +2 -2
  9. package/dist/generated/entity-fields-registry.js +6 -0
  10. package/dist/generated/entity-fields-registry.js.map +2 -2
  11. package/dist/modules/data_sync/api/runs/[id]/cancel.js +14 -5
  12. package/dist/modules/data_sync/api/runs/[id]/cancel.js.map +2 -2
  13. package/dist/modules/data_sync/backend/data-sync/page.meta.js +2 -2
  14. package/dist/modules/data_sync/backend/data-sync/page.meta.js.map +1 -1
  15. package/dist/modules/data_sync/backend/data-sync/runs/[id]/page.js +37 -12
  16. package/dist/modules/data_sync/backend/data-sync/runs/[id]/page.js.map +2 -2
  17. package/dist/modules/directory/api/get/tenants/lookup.js +1 -0
  18. package/dist/modules/directory/api/get/tenants/lookup.js.map +2 -2
  19. package/dist/modules/integrations/api/[id]/route.js +38 -11
  20. package/dist/modules/integrations/api/[id]/route.js.map +2 -2
  21. package/dist/modules/integrations/api/logs/route.js +52 -26
  22. package/dist/modules/integrations/api/logs/route.js.map +2 -2
  23. package/dist/modules/integrations/api/route.js +37 -7
  24. package/dist/modules/integrations/api/route.js.map +2 -2
  25. package/dist/modules/integrations/api/umes-read.js +121 -0
  26. package/dist/modules/integrations/api/umes-read.js.map +7 -0
  27. package/dist/modules/integrations/backend/integrations/[id]/page.js +715 -183
  28. package/dist/modules/integrations/backend/integrations/[id]/page.js.map +2 -2
  29. package/dist/modules/integrations/backend/integrations/bundle/[id]/page.js +30 -9
  30. package/dist/modules/integrations/backend/integrations/bundle/[id]/page.js.map +2 -2
  31. package/dist/modules/integrations/backend/integrations/detail-page-widgets.js +46 -0
  32. package/dist/modules/integrations/backend/integrations/detail-page-widgets.js.map +7 -0
  33. package/dist/modules/integrations/backend/integrations/page.js +78 -62
  34. package/dist/modules/integrations/backend/integrations/page.js.map +2 -2
  35. package/dist/modules/integrations/backend/integrations/page.meta.js +2 -2
  36. package/dist/modules/integrations/backend/integrations/page.meta.js.map +1 -1
  37. package/dist/modules/integrations/setup.js +2 -2
  38. package/dist/modules/integrations/setup.js.map +2 -2
  39. package/dist/modules/payment_gateways/acl.js +12 -0
  40. package/dist/modules/payment_gateways/acl.js.map +7 -0
  41. package/dist/modules/payment_gateways/api/cancel/route.js +55 -0
  42. package/dist/modules/payment_gateways/api/cancel/route.js.map +7 -0
  43. package/dist/modules/payment_gateways/api/capture/route.js +55 -0
  44. package/dist/modules/payment_gateways/api/capture/route.js.map +7 -0
  45. package/dist/modules/payment_gateways/api/interceptors.js +24 -0
  46. package/dist/modules/payment_gateways/api/interceptors.js.map +7 -0
  47. package/dist/modules/payment_gateways/api/openapi.js +5 -0
  48. package/dist/modules/payment_gateways/api/openapi.js.map +7 -0
  49. package/dist/modules/payment_gateways/api/refund/route.js +56 -0
  50. package/dist/modules/payment_gateways/api/refund/route.js.map +7 -0
  51. package/dist/modules/payment_gateways/api/sessions/route.js +74 -0
  52. package/dist/modules/payment_gateways/api/sessions/route.js.map +7 -0
  53. package/dist/modules/payment_gateways/api/status/route.js +66 -0
  54. package/dist/modules/payment_gateways/api/status/route.js.map +7 -0
  55. package/dist/modules/payment_gateways/api/transactions/[id]/route.js +118 -0
  56. package/dist/modules/payment_gateways/api/transactions/[id]/route.js.map +7 -0
  57. package/dist/modules/payment_gateways/api/transactions/route.js +113 -0
  58. package/dist/modules/payment_gateways/api/transactions/route.js.map +7 -0
  59. package/dist/modules/payment_gateways/api/webhook/[provider]/route.js +136 -0
  60. package/dist/modules/payment_gateways/api/webhook/[provider]/route.js.map +7 -0
  61. package/dist/modules/payment_gateways/backend/payment-gateways/page.js +496 -0
  62. package/dist/modules/payment_gateways/backend/payment-gateways/page.js.map +7 -0
  63. package/dist/modules/payment_gateways/backend/payment-gateways/page.meta.js +23 -0
  64. package/dist/modules/payment_gateways/backend/payment-gateways/page.meta.js.map +7 -0
  65. package/dist/modules/payment_gateways/data/enrichers.js +5 -0
  66. package/dist/modules/payment_gateways/data/enrichers.js.map +7 -0
  67. package/dist/modules/payment_gateways/data/entities.js +131 -0
  68. package/dist/modules/payment_gateways/data/entities.js.map +7 -0
  69. package/dist/modules/payment_gateways/data/validators.js +57 -0
  70. package/dist/modules/payment_gateways/data/validators.js.map +7 -0
  71. package/dist/modules/payment_gateways/di.js +16 -0
  72. package/dist/modules/payment_gateways/di.js.map +7 -0
  73. package/dist/modules/payment_gateways/events.js +21 -0
  74. package/dist/modules/payment_gateways/events.js.map +7 -0
  75. package/dist/modules/payment_gateways/i18n/en.js +6 -0
  76. package/dist/modules/payment_gateways/i18n/en.js.map +7 -0
  77. package/dist/modules/payment_gateways/i18n/pl.js +6 -0
  78. package/dist/modules/payment_gateways/i18n/pl.js.map +7 -0
  79. package/dist/modules/payment_gateways/index.js +9 -0
  80. package/dist/modules/payment_gateways/index.js.map +7 -0
  81. package/dist/modules/payment_gateways/lib/gateway-service.js +378 -0
  82. package/dist/modules/payment_gateways/lib/gateway-service.js.map +7 -0
  83. package/dist/modules/payment_gateways/lib/queue.js +17 -0
  84. package/dist/modules/payment_gateways/lib/queue.js.map +7 -0
  85. package/dist/modules/payment_gateways/lib/status-machine.js +29 -0
  86. package/dist/modules/payment_gateways/lib/status-machine.js.map +7 -0
  87. package/dist/modules/payment_gateways/lib/webhook-processor.js +88 -0
  88. package/dist/modules/payment_gateways/lib/webhook-processor.js.map +7 -0
  89. package/dist/modules/payment_gateways/lib/webhook-utils.js +42 -0
  90. package/dist/modules/payment_gateways/lib/webhook-utils.js.map +7 -0
  91. package/dist/modules/payment_gateways/migrations/Migration20260305122155.js +19 -0
  92. package/dist/modules/payment_gateways/migrations/Migration20260305122155.js.map +7 -0
  93. package/dist/modules/payment_gateways/setup.js +13 -0
  94. package/dist/modules/payment_gateways/setup.js.map +7 -0
  95. package/dist/modules/payment_gateways/widgets/injection-table.js +7 -0
  96. package/dist/modules/payment_gateways/widgets/injection-table.js.map +7 -0
  97. package/dist/modules/payment_gateways/workers/status-poller.js +44 -0
  98. package/dist/modules/payment_gateways/workers/status-poller.js.map +7 -0
  99. package/dist/modules/payment_gateways/workers/webhook-processor.js +20 -0
  100. package/dist/modules/payment_gateways/workers/webhook-processor.js.map +7 -0
  101. package/dist/modules/sales/data/enrichers.js +72 -0
  102. package/dist/modules/sales/data/enrichers.js.map +7 -0
  103. package/dist/modules/sales/lib/makeSalesLineRoute.js +3 -0
  104. package/dist/modules/sales/lib/makeSalesLineRoute.js.map +2 -2
  105. package/dist/modules/sales/widgets/injection/payment-gateway-config-field/widget.js +29 -0
  106. package/dist/modules/sales/widgets/injection/payment-gateway-config-field/widget.js.map +7 -0
  107. package/dist/modules/sales/widgets/injection/payment-gateway-status-column/widget.js +23 -0
  108. package/dist/modules/sales/widgets/injection/payment-gateway-status-column/widget.js.map +7 -0
  109. package/dist/modules/sales/widgets/injection-table.js +13 -1
  110. package/dist/modules/sales/widgets/injection-table.js.map +2 -2
  111. package/dist/modules/shipping_carriers/acl.js +10 -0
  112. package/dist/modules/shipping_carriers/acl.js.map +7 -0
  113. package/dist/modules/shipping_carriers/api/cancel/route.js +55 -0
  114. package/dist/modules/shipping_carriers/api/cancel/route.js.map +7 -0
  115. package/dist/modules/shipping_carriers/api/interceptors.js +21 -0
  116. package/dist/modules/shipping_carriers/api/interceptors.js.map +7 -0
  117. package/dist/modules/shipping_carriers/api/openapi.js +5 -0
  118. package/dist/modules/shipping_carriers/api/openapi.js.map +7 -0
  119. package/dist/modules/shipping_carriers/api/rates/route.js +55 -0
  120. package/dist/modules/shipping_carriers/api/rates/route.js.map +7 -0
  121. package/dist/modules/shipping_carriers/api/shipments/route.js +61 -0
  122. package/dist/modules/shipping_carriers/api/shipments/route.js.map +7 -0
  123. package/dist/modules/shipping_carriers/api/tracking/route.js +58 -0
  124. package/dist/modules/shipping_carriers/api/tracking/route.js.map +7 -0
  125. package/dist/modules/shipping_carriers/api/webhook/[provider]/route.js +119 -0
  126. package/dist/modules/shipping_carriers/api/webhook/[provider]/route.js.map +7 -0
  127. package/dist/modules/shipping_carriers/data/enrichers.js +82 -0
  128. package/dist/modules/shipping_carriers/data/enrichers.js.map +7 -0
  129. package/dist/modules/shipping_carriers/data/entities.js +80 -0
  130. package/dist/modules/shipping_carriers/data/entities.js.map +7 -0
  131. package/dist/modules/shipping_carriers/data/validators.js +49 -0
  132. package/dist/modules/shipping_carriers/data/validators.js.map +7 -0
  133. package/dist/modules/shipping_carriers/di.js +15 -0
  134. package/dist/modules/shipping_carriers/di.js.map +7 -0
  135. package/dist/modules/shipping_carriers/events.js +19 -0
  136. package/dist/modules/shipping_carriers/events.js.map +7 -0
  137. package/dist/modules/shipping_carriers/i18n/en.js +11 -0
  138. package/dist/modules/shipping_carriers/i18n/en.js.map +7 -0
  139. package/dist/modules/shipping_carriers/i18n/pl.js +11 -0
  140. package/dist/modules/shipping_carriers/i18n/pl.js.map +7 -0
  141. package/dist/modules/shipping_carriers/index.js +9 -0
  142. package/dist/modules/shipping_carriers/index.js.map +7 -0
  143. package/dist/modules/shipping_carriers/lib/adapter-registry.js +29 -0
  144. package/dist/modules/shipping_carriers/lib/adapter-registry.js.map +7 -0
  145. package/dist/modules/shipping_carriers/lib/adapter.js +1 -0
  146. package/dist/modules/shipping_carriers/lib/adapter.js.map +7 -0
  147. package/dist/modules/shipping_carriers/lib/queue.js +17 -0
  148. package/dist/modules/shipping_carriers/lib/queue.js.map +7 -0
  149. package/dist/modules/shipping_carriers/lib/shipping-service.js +155 -0
  150. package/dist/modules/shipping_carriers/lib/shipping-service.js.map +7 -0
  151. package/dist/modules/shipping_carriers/lib/status-sync.js +37 -0
  152. package/dist/modules/shipping_carriers/lib/status-sync.js.map +7 -0
  153. package/dist/modules/shipping_carriers/migrations/Migration20260305170000.js +16 -0
  154. package/dist/modules/shipping_carriers/migrations/Migration20260305170000.js.map +7 -0
  155. package/dist/modules/shipping_carriers/setup.js +13 -0
  156. package/dist/modules/shipping_carriers/setup.js.map +7 -0
  157. package/dist/modules/shipping_carriers/widgets/injection/create-shipment-button/widget.js +25 -0
  158. package/dist/modules/shipping_carriers/widgets/injection/create-shipment-button/widget.js.map +7 -0
  159. package/dist/modules/shipping_carriers/widgets/injection/tracking-column/widget.js +23 -0
  160. package/dist/modules/shipping_carriers/widgets/injection/tracking-column/widget.js.map +7 -0
  161. package/dist/modules/shipping_carriers/widgets/injection/tracking-status-badge/widget.js +40 -0
  162. package/dist/modules/shipping_carriers/widgets/injection/tracking-status-badge/widget.js.map +7 -0
  163. package/dist/modules/shipping_carriers/widgets/injection-table.js +24 -0
  164. package/dist/modules/shipping_carriers/widgets/injection-table.js.map +7 -0
  165. package/dist/modules/shipping_carriers/workers/status-poller.js +21 -0
  166. package/dist/modules/shipping_carriers/workers/status-poller.js.map +7 -0
  167. package/dist/modules/shipping_carriers/workers/webhook-processor.js +54 -0
  168. package/dist/modules/shipping_carriers/workers/webhook-processor.js.map +7 -0
  169. package/dist/modules/translations/api/get/locales.js +1 -0
  170. package/dist/modules/translations/api/get/locales.js.map +2 -2
  171. package/dist/modules/translations/api/put/locales.js +1 -0
  172. package/dist/modules/translations/api/put/locales.js.map +2 -2
  173. package/generated/entities/carrier_shipment/index.ts +17 -0
  174. package/generated/entities/gateway_transaction/index.ts +22 -0
  175. package/generated/entities/webhook_processed_event/index.ts +7 -0
  176. package/generated/entities.ids.generated.ts +10 -1
  177. package/generated/entity-fields-registry.ts +6 -0
  178. package/jest.config.cjs +1 -0
  179. package/package.json +5 -2
  180. package/src/modules/auth/i18n/de.json +1 -0
  181. package/src/modules/auth/i18n/en.json +1 -0
  182. package/src/modules/auth/i18n/es.json +1 -0
  183. package/src/modules/auth/i18n/pl.json +1 -0
  184. package/src/modules/data_sync/api/runs/[id]/cancel.ts +18 -5
  185. package/src/modules/data_sync/backend/data-sync/page.meta.ts +2 -2
  186. package/src/modules/data_sync/backend/data-sync/runs/[id]/page.tsx +50 -12
  187. package/src/modules/directory/api/get/tenants/lookup.ts +1 -0
  188. package/src/modules/integrations/AGENTS.md +31 -0
  189. package/src/modules/integrations/api/[id]/route.ts +38 -11
  190. package/src/modules/integrations/api/logs/route.ts +53 -27
  191. package/src/modules/integrations/api/route.ts +31 -1
  192. package/src/modules/integrations/api/umes-read.ts +177 -0
  193. package/src/modules/integrations/backend/integrations/[id]/page.tsx +902 -202
  194. package/src/modules/integrations/backend/integrations/bundle/[id]/page.tsx +43 -9
  195. package/src/modules/integrations/backend/integrations/detail-page-widgets.ts +74 -0
  196. package/src/modules/integrations/backend/integrations/page.meta.ts +2 -2
  197. package/src/modules/integrations/backend/integrations/page.tsx +65 -54
  198. package/src/modules/integrations/i18n/de.json +15 -0
  199. package/src/modules/integrations/i18n/en.json +15 -0
  200. package/src/modules/integrations/i18n/es.json +15 -0
  201. package/src/modules/integrations/i18n/pl.json +15 -0
  202. package/src/modules/integrations/setup.ts +2 -2
  203. package/src/modules/payment_gateways/acl.ts +8 -0
  204. package/src/modules/payment_gateways/api/cancel/route.ts +56 -0
  205. package/src/modules/payment_gateways/api/capture/route.ts +56 -0
  206. package/src/modules/payment_gateways/api/interceptors.ts +22 -0
  207. package/src/modules/payment_gateways/api/openapi.ts +1 -0
  208. package/src/modules/payment_gateways/api/refund/route.ts +57 -0
  209. package/src/modules/payment_gateways/api/sessions/route.ts +76 -0
  210. package/src/modules/payment_gateways/api/status/route.ts +69 -0
  211. package/src/modules/payment_gateways/api/transactions/[id]/route.ts +123 -0
  212. package/src/modules/payment_gateways/api/transactions/route.ts +120 -0
  213. package/src/modules/payment_gateways/api/webhook/[provider]/route.ts +161 -0
  214. package/src/modules/payment_gateways/backend/payment-gateways/page.meta.ts +19 -0
  215. package/src/modules/payment_gateways/backend/payment-gateways/page.tsx +660 -0
  216. package/src/modules/payment_gateways/data/enrichers.ts +8 -0
  217. package/src/modules/payment_gateways/data/entities.ts +106 -0
  218. package/src/modules/payment_gateways/data/validators.ts +67 -0
  219. package/src/modules/payment_gateways/di.ts +26 -0
  220. package/src/modules/payment_gateways/events.ts +17 -0
  221. package/src/modules/payment_gateways/i18n/de.json +77 -0
  222. package/src/modules/payment_gateways/i18n/en.json +77 -0
  223. package/src/modules/payment_gateways/i18n/en.ts +4 -0
  224. package/src/modules/payment_gateways/i18n/es.json +77 -0
  225. package/src/modules/payment_gateways/i18n/pl.json +77 -0
  226. package/src/modules/payment_gateways/i18n/pl.ts +4 -0
  227. package/src/modules/payment_gateways/index.ts +5 -0
  228. package/src/modules/payment_gateways/lib/gateway-service.ts +486 -0
  229. package/src/modules/payment_gateways/lib/queue.ts +19 -0
  230. package/src/modules/payment_gateways/lib/status-machine.ts +28 -0
  231. package/src/modules/payment_gateways/lib/webhook-processor.ts +133 -0
  232. package/src/modules/payment_gateways/lib/webhook-utils.ts +52 -0
  233. package/src/modules/payment_gateways/migrations/.snapshot-open-mercato.json +373 -0
  234. package/src/modules/payment_gateways/migrations/Migration20260305122155.ts +20 -0
  235. package/src/modules/payment_gateways/setup.ts +11 -0
  236. package/src/modules/payment_gateways/widgets/injection-table.ts +9 -0
  237. package/src/modules/payment_gateways/workers/status-poller.ts +58 -0
  238. package/src/modules/payment_gateways/workers/webhook-processor.ts +30 -0
  239. package/src/modules/sales/data/enrichers.ts +120 -0
  240. package/src/modules/sales/lib/makeSalesLineRoute.ts +3 -0
  241. package/src/modules/sales/widgets/injection/payment-gateway-config-field/widget.ts +28 -0
  242. package/src/modules/sales/widgets/injection/payment-gateway-status-column/widget.ts +22 -0
  243. package/src/modules/sales/widgets/injection-table.ts +12 -0
  244. package/src/modules/shipping_carriers/acl.ts +6 -0
  245. package/src/modules/shipping_carriers/api/cancel/route.ts +53 -0
  246. package/src/modules/shipping_carriers/api/interceptors.ts +19 -0
  247. package/src/modules/shipping_carriers/api/openapi.ts +1 -0
  248. package/src/modules/shipping_carriers/api/rates/route.ts +53 -0
  249. package/src/modules/shipping_carriers/api/shipments/route.ts +59 -0
  250. package/src/modules/shipping_carriers/api/tracking/route.ts +56 -0
  251. package/src/modules/shipping_carriers/api/webhook/[provider]/route.ts +134 -0
  252. package/src/modules/shipping_carriers/data/enrichers.ts +89 -0
  253. package/src/modules/shipping_carriers/data/entities.ts +60 -0
  254. package/src/modules/shipping_carriers/data/validators.ts +48 -0
  255. package/src/modules/shipping_carriers/di.ts +20 -0
  256. package/src/modules/shipping_carriers/events.ts +16 -0
  257. package/src/modules/shipping_carriers/i18n/de.json +7 -0
  258. package/src/modules/shipping_carriers/i18n/en.json +7 -0
  259. package/src/modules/shipping_carriers/i18n/en.ts +7 -0
  260. package/src/modules/shipping_carriers/i18n/es.json +7 -0
  261. package/src/modules/shipping_carriers/i18n/pl.json +7 -0
  262. package/src/modules/shipping_carriers/i18n/pl.ts +7 -0
  263. package/src/modules/shipping_carriers/index.ts +5 -0
  264. package/src/modules/shipping_carriers/lib/adapter-registry.ts +33 -0
  265. package/src/modules/shipping_carriers/lib/adapter.ts +93 -0
  266. package/src/modules/shipping_carriers/lib/queue.ts +19 -0
  267. package/src/modules/shipping_carriers/lib/shipping-service.ts +204 -0
  268. package/src/modules/shipping_carriers/lib/status-sync.ts +38 -0
  269. package/src/modules/shipping_carriers/migrations/Migration20260305170000.ts +14 -0
  270. package/src/modules/shipping_carriers/setup.ts +11 -0
  271. package/src/modules/shipping_carriers/widgets/injection/create-shipment-button/widget.ts +24 -0
  272. package/src/modules/shipping_carriers/widgets/injection/tracking-column/widget.ts +22 -0
  273. package/src/modules/shipping_carriers/widgets/injection/tracking-status-badge/widget.tsx +44 -0
  274. package/src/modules/shipping_carriers/widgets/injection-table.ts +22 -0
  275. package/src/modules/shipping_carriers/workers/status-poller.ts +33 -0
  276. package/src/modules/shipping_carriers/workers/webhook-processor.ts +79 -0
  277. package/src/modules/translations/api/get/locales.ts +1 -0
  278. package/src/modules/translations/api/put/locales.ts +1 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../src/modules/payment_gateways/api/webhook/%5Bprovider%5D/route.ts"],
4
+ "sourcesContent": ["import { NextResponse } from 'next/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport { readJsonSafe } from '@open-mercato/shared/lib/http/readJsonSafe'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { getWebhookHandler } from '@open-mercato/shared/modules/payment_gateways/types'\nimport type { IntegrationLogService } from '../../../../integrations/lib/log-service'\nimport type { PaymentGatewayService } from '../../../lib/gateway-service'\nimport type { CredentialsService } from '../../../../integrations/lib/credentials-service'\nimport { GatewayTransaction } from '../../../data/entities'\nimport { getPaymentGatewayQueue } from '../../../lib/queue'\nimport { processPaymentGatewayWebhookJob } from '../../../lib/webhook-processor'\nimport { paymentGatewaysTag } from '../../openapi'\n\nexport const metadata = {\n path: '/payment_gateways/webhook/[provider]',\n POST: { requireAuth: false },\n}\n\nfunction readScopeFromEventData(data: Record<string, unknown>): { organizationId: string; tenantId: string } | null {\n const metadata = data.metadata\n if (!metadata || typeof metadata !== 'object') return null\n\n const metadataRecord = metadata as Record<string, unknown>\n const organizationId = typeof metadataRecord.organizationId === 'string'\n ? metadataRecord.organizationId.trim()\n : ''\n const tenantId = typeof metadataRecord.tenantId === 'string'\n ? metadataRecord.tenantId.trim()\n : ''\n\n if (!organizationId || !tenantId) return null\n return { organizationId, tenantId }\n}\n\nexport async function POST(req: Request, { params }: { params: Promise<{ provider: string }> | { provider: string } }) {\n const resolvedParams = await params\n const providerKey = resolvedParams.provider\n const container = await createRequestContainer()\n const registration = getWebhookHandler(providerKey)\n if (!registration) {\n return NextResponse.json({ error: `No webhook handler for provider: ${providerKey}` }, { status: 404 })\n }\n\n const rawBody = await req.text()\n const headers: Record<string, string> = {}\n req.headers.forEach((value, key) => {\n headers[key] = value\n })\n\n const service = container.resolve('paymentGatewayService') as PaymentGatewayService\n const em = container.resolve('em') as EntityManager\n const integrationCredentialsService = container.resolve('integrationCredentialsService') as CredentialsService\n const queue = getPaymentGatewayQueue(registration.queue ?? 'payment-gateways-webhook')\n const payload = await readJsonSafe<Record<string, unknown>>(rawBody)\n const sessionIdHint = registration.readSessionIdHint?.(payload) ?? null\n\n try {\n const candidates = sessionIdHint\n ? await findWithDecryption(\n em,\n GatewayTransaction,\n {\n providerKey,\n providerSessionId: sessionIdHint,\n deletedAt: null,\n },\n { limit: 10, orderBy: { createdAt: 'desc' } },\n )\n : []\n\n let transaction = null as GatewayTransaction | null\n let matchedScope = null as { organizationId: string; tenantId: string } | null\n let event = null as Awaited<ReturnType<typeof registration.handler>> | null\n let lastVerificationError: unknown = null\n\n for (const candidate of candidates) {\n const candidateScope = { organizationId: candidate.organizationId, tenantId: candidate.tenantId }\n const credentials = await integrationCredentialsService.resolve(`gateway_${providerKey}`, candidateScope) ?? {}\n try {\n event = await registration.handler({ rawBody, headers, credentials })\n transaction = candidate\n matchedScope = candidateScope\n break\n } catch (error: unknown) {\n lastVerificationError = error\n }\n }\n\n if (!event) {\n try {\n event = await registration.handler({ rawBody, headers, credentials: {} })\n } catch (error: unknown) {\n throw lastVerificationError ?? error\n }\n }\n if (!event) {\n throw new Error('Webhook verification failed')\n }\n\n if (!transaction && sessionIdHint) {\n const derivedScope = readScopeFromEventData(event.data)\n if (derivedScope) {\n transaction = await service.findTransactionBySessionId(sessionIdHint, derivedScope, providerKey)\n matchedScope = transaction\n ? { organizationId: transaction.organizationId, tenantId: transaction.tenantId }\n : derivedScope\n }\n }\n\n const scope = transaction\n ? { organizationId: transaction.organizationId, tenantId: transaction.tenantId }\n : matchedScope ?? readScopeFromEventData(event.data)\n\n const jobPayload = {\n providerKey,\n event,\n transactionId: transaction?.id ?? null,\n scope,\n }\n\n if (process.env.QUEUE_STRATEGY === 'async') {\n await queue.enqueue({\n name: 'payment-gateway-webhook',\n payload: jobPayload,\n })\n } else {\n await processPaymentGatewayWebhookJob(\n {\n em: container.resolve('em') as EntityManager,\n paymentGatewayService: service,\n integrationLogService: container.resolve('integrationLogService') as IntegrationLogService,\n },\n jobPayload,\n )\n }\n\n return NextResponse.json({ received: true, queued: true }, { status: 202 })\n } catch (err: unknown) {\n const message = err instanceof Error ? err.message : 'Webhook verification failed'\n return NextResponse.json({ error: message }, { status: 401 })\n }\n}\n\nexport const openApi = {\n tags: [paymentGatewaysTag],\n summary: 'Receive payment gateway webhook',\n methods: {\n POST: {\n summary: 'Process inbound webhook from payment provider',\n tags: [paymentGatewaysTag],\n responses: [\n { status: 202, description: 'Webhook accepted for async processing' },\n { status: 401, description: 'Signature verification failed' },\n { status: 404, description: 'Unknown provider' },\n ],\n },\n },\n}\n\nexport default POST\n"],
5
+ "mappings": "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",
6
+ "names": ["metadata"]
7
+ }
@@ -0,0 +1,496 @@
1
+ "use client";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { Page, PageHeader, PageBody } from "@open-mercato/ui/backend/Page";
5
+ import { DataTable } from "@open-mercato/ui/backend/DataTable";
6
+ import { JsonDisplay } from "@open-mercato/ui/backend/JsonDisplay";
7
+ import { LoadingMessage, ErrorMessage } from "@open-mercato/ui/backend/detail";
8
+ import { RowActions } from "@open-mercato/ui/backend/RowActions";
9
+ import { apiCall } from "@open-mercato/ui/backend/utils/apiCall";
10
+ import { flash } from "@open-mercato/ui/backend/FlashMessages";
11
+ import { useOrganizationScopeVersion } from "@open-mercato/shared/lib/frontend/useOrganizationScope";
12
+ import { useT } from "@open-mercato/shared/lib/i18n/context";
13
+ import { Badge } from "@open-mercato/ui/primitives/badge";
14
+ import { Button } from "@open-mercato/ui/primitives/button";
15
+ import { Card, CardContent, CardHeader, CardTitle } from "@open-mercato/ui/primitives/card";
16
+ import { Spinner } from "@open-mercato/ui/primitives/spinner";
17
+ import { ChevronDown, ChevronRight, CreditCard, RefreshCw, Webhook } from "lucide-react";
18
+ const STATUS_STYLES = {
19
+ pending: "bg-slate-100 text-slate-800",
20
+ authorized: "bg-blue-100 text-blue-800",
21
+ captured: "bg-green-100 text-green-800",
22
+ partially_captured: "bg-emerald-100 text-emerald-800",
23
+ refunded: "bg-amber-100 text-amber-800",
24
+ partially_refunded: "bg-orange-100 text-orange-800",
25
+ cancelled: "bg-zinc-200 text-zinc-900",
26
+ failed: "bg-red-100 text-red-800",
27
+ expired: "bg-neutral-200 text-neutral-900",
28
+ unknown: "bg-purple-100 text-purple-800"
29
+ };
30
+ const LOG_LEVEL_STYLES = {
31
+ info: "bg-blue-100 text-blue-800",
32
+ warn: "bg-yellow-100 text-yellow-800",
33
+ error: "bg-red-100 text-red-800"
34
+ };
35
+ function formatDateTime(value) {
36
+ if (!value) return "\u2014";
37
+ const parsed = new Date(value);
38
+ if (Number.isNaN(parsed.getTime())) return value;
39
+ return parsed.toLocaleString();
40
+ }
41
+ function formatAmount(value, currencyCode) {
42
+ const amount = Number(value);
43
+ if (Number.isNaN(amount)) return `${value} ${currencyCode}`;
44
+ try {
45
+ return new Intl.NumberFormat(void 0, {
46
+ style: "currency",
47
+ currency: currencyCode
48
+ }).format(amount);
49
+ } catch {
50
+ return `${amount.toFixed(2)} ${currencyCode}`;
51
+ }
52
+ }
53
+ function formatTypeLabel(value) {
54
+ return value.split("_").filter(Boolean).map((part) => part[0]?.toUpperCase() + part.slice(1)).join(" ");
55
+ }
56
+ function formatLogDetailLabel(key) {
57
+ return key.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").split(" ").filter(Boolean).map((part) => part[0]?.toUpperCase() + part.slice(1)).join(" ");
58
+ }
59
+ function isPrimitiveLogValue(value) {
60
+ return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
61
+ }
62
+ function splitLogPayload(payload) {
63
+ if (!payload) {
64
+ return {
65
+ inlineEntries: [],
66
+ nestedEntries: []
67
+ };
68
+ }
69
+ const inlineEntries = [];
70
+ const nestedEntries = [];
71
+ Object.entries(payload).forEach(([key, value]) => {
72
+ if (isPrimitiveLogValue(value)) {
73
+ inlineEntries.push([key, value]);
74
+ return;
75
+ }
76
+ nestedEntries.push([key, value]);
77
+ });
78
+ return { inlineEntries, nestedEntries };
79
+ }
80
+ function DetailStat({ label, value }) {
81
+ return /* @__PURE__ */ jsxs("div", { className: "rounded-lg border bg-muted/20 px-4 py-3", children: [
82
+ /* @__PURE__ */ jsx("div", { className: "text-[11px] font-medium uppercase tracking-wide text-muted-foreground", children: label }),
83
+ /* @__PURE__ */ jsx("div", { className: "mt-1 text-sm font-medium", children: value })
84
+ ] });
85
+ }
86
+ function PaymentTransactionsPage() {
87
+ const t = useT();
88
+ const scopeVersion = useOrganizationScopeVersion();
89
+ const [rows, setRows] = React.useState([]);
90
+ const [page, setPage] = React.useState(1);
91
+ const [total, setTotal] = React.useState(0);
92
+ const [totalPages, setTotalPages] = React.useState(1);
93
+ const [search, setSearch] = React.useState("");
94
+ const [filterValues, setFilterValues] = React.useState({});
95
+ const [isLoading, setIsLoading] = React.useState(true);
96
+ const [selectedId, setSelectedId] = React.useState(null);
97
+ const [detail, setDetail] = React.useState(null);
98
+ const [isLoadingDetail, setIsLoadingDetail] = React.useState(false);
99
+ const [detailError, setDetailError] = React.useState(null);
100
+ const [expandedLogId, setExpandedLogId] = React.useState(null);
101
+ const [isRefreshingStatus, setIsRefreshingStatus] = React.useState(false);
102
+ const noneLabel = t("common.none", "None");
103
+ const formatLogPrimitiveValue = React.useCallback((value) => {
104
+ if (value === null) return noneLabel;
105
+ if (typeof value === "boolean") return value ? t("common.yes", "Yes") : t("common.no", "No");
106
+ return String(value);
107
+ }, [noneLabel, t]);
108
+ const loadRows = React.useCallback(async () => {
109
+ setIsLoading(true);
110
+ const params = new URLSearchParams({
111
+ page: String(page),
112
+ pageSize: "20"
113
+ });
114
+ if (search.trim()) params.set("search", search.trim());
115
+ if (typeof filterValues.providerKey === "string" && filterValues.providerKey) {
116
+ params.set("providerKey", filterValues.providerKey);
117
+ }
118
+ if (typeof filterValues.status === "string" && filterValues.status) {
119
+ params.set("status", filterValues.status);
120
+ }
121
+ const fallback = { items: [], total: 0, page, pageSize: 20, totalPages: 1 };
122
+ const call = await apiCall(`/api/payment_gateways/transactions?${params.toString()}`, void 0, { fallback });
123
+ if (call.ok && call.result) {
124
+ setRows(Array.isArray(call.result.items) ? call.result.items : []);
125
+ setTotal(call.result.total ?? 0);
126
+ setTotalPages(call.result.totalPages ?? 1);
127
+ } else {
128
+ flash(t("payment_gateways.transactions.error.load", "Failed to load payment transactions"), "error");
129
+ setRows([]);
130
+ setTotal(0);
131
+ setTotalPages(1);
132
+ }
133
+ setIsLoading(false);
134
+ }, [filterValues.providerKey, filterValues.status, page, search, t]);
135
+ const loadDetail = React.useCallback(async (transactionId) => {
136
+ setIsLoadingDetail(true);
137
+ setDetailError(null);
138
+ const call = await apiCall(`/api/payment_gateways/transactions/${encodeURIComponent(transactionId)}`, void 0, { fallback: null });
139
+ if (call.ok && call.result) {
140
+ setDetail(call.result);
141
+ setExpandedLogId((current) => current && call.result?.logs.some((log) => log.id === current) ? current : null);
142
+ } else {
143
+ setDetail(null);
144
+ setDetailError(t("payment_gateways.transactions.error.loadDetail", "Failed to load transaction details"));
145
+ }
146
+ setIsLoadingDetail(false);
147
+ }, [t]);
148
+ React.useEffect(() => {
149
+ void loadRows();
150
+ }, [loadRows, scopeVersion]);
151
+ React.useEffect(() => {
152
+ if (!selectedId) {
153
+ setDetail(null);
154
+ setDetailError(null);
155
+ return;
156
+ }
157
+ void loadDetail(selectedId);
158
+ }, [loadDetail, selectedId]);
159
+ React.useEffect(() => {
160
+ setSelectedId((current) => current && rows.some((row) => row.id === current) ? current : null);
161
+ }, [rows]);
162
+ const handleFiltersApply = React.useCallback((values) => {
163
+ const next = {};
164
+ Object.entries(values).forEach(([key, value]) => {
165
+ if (typeof value === "string" && value.trim()) next[key] = value;
166
+ });
167
+ setFilterValues(next);
168
+ setPage(1);
169
+ }, []);
170
+ const handleFiltersClear = React.useCallback(() => {
171
+ setFilterValues({});
172
+ setPage(1);
173
+ }, []);
174
+ const handleRefreshStatus = React.useCallback(async () => {
175
+ if (!selectedId) return;
176
+ setIsRefreshingStatus(true);
177
+ const call = await apiCall(`/api/payment_gateways/status?transactionId=${encodeURIComponent(selectedId)}`, void 0, { fallback: null });
178
+ if (!call.ok) {
179
+ flash(t("payment_gateways.transactions.error.refreshStatus", "Failed to refresh transaction status"), "error");
180
+ setIsRefreshingStatus(false);
181
+ return;
182
+ }
183
+ await Promise.all([
184
+ loadRows(),
185
+ loadDetail(selectedId)
186
+ ]);
187
+ flash(t("payment_gateways.transactions.success.refreshStatus", "Transaction status refreshed"), "success");
188
+ setIsRefreshingStatus(false);
189
+ }, [loadDetail, loadRows, selectedId, t]);
190
+ const providerOptions = React.useMemo(() => {
191
+ const values = Array.from(new Set(rows.map((row) => row.providerKey).filter(Boolean))).sort();
192
+ return values.map((value) => ({
193
+ label: formatTypeLabel(value),
194
+ value
195
+ }));
196
+ }, [rows]);
197
+ const filters = React.useMemo(() => [
198
+ {
199
+ id: "providerKey",
200
+ type: "select",
201
+ label: t("payment_gateways.transactions.filters.provider", "Provider"),
202
+ options: [
203
+ { label: t("payment_gateways.transactions.filters.allProviders", "All providers"), value: "" },
204
+ ...providerOptions
205
+ ]
206
+ },
207
+ {
208
+ id: "status",
209
+ type: "select",
210
+ label: t("payment_gateways.transactions.filters.status", "Status"),
211
+ options: [
212
+ { label: t("payment_gateways.transactions.filters.allStatuses", "All statuses"), value: "" },
213
+ { label: t("payment_gateways.status.pending", "Pending"), value: "pending" },
214
+ { label: t("payment_gateways.status.authorized", "Authorized"), value: "authorized" },
215
+ { label: t("payment_gateways.status.captured", "Captured"), value: "captured" },
216
+ { label: t("payment_gateways.status.partially_captured", "Partially Captured"), value: "partially_captured" },
217
+ { label: t("payment_gateways.status.refunded", "Refunded"), value: "refunded" },
218
+ { label: t("payment_gateways.status.partially_refunded", "Partially Refunded"), value: "partially_refunded" },
219
+ { label: t("payment_gateways.status.cancelled", "Cancelled"), value: "cancelled" },
220
+ { label: t("payment_gateways.status.failed", "Failed"), value: "failed" },
221
+ { label: t("payment_gateways.status.expired", "Expired"), value: "expired" },
222
+ { label: t("payment_gateways.status.unknown", "Unknown"), value: "unknown" }
223
+ ]
224
+ }
225
+ ], [providerOptions, t]);
226
+ const columns = React.useMemo(() => [
227
+ {
228
+ accessorKey: "paymentId",
229
+ header: t("payment_gateways.transactions.columns.paymentId", "Payment"),
230
+ cell: ({ row }) => /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
231
+ /* @__PURE__ */ jsx("div", { className: "font-medium", children: row.original.paymentId }),
232
+ /* @__PURE__ */ jsx("div", { className: "text-xs text-muted-foreground", children: row.original.id })
233
+ ] }),
234
+ meta: { maxWidth: "20rem" }
235
+ },
236
+ {
237
+ accessorKey: "providerKey",
238
+ header: t("payment_gateways.transactions.columns.provider", "Provider"),
239
+ cell: ({ row }) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
240
+ /* @__PURE__ */ jsx(CreditCard, { className: "h-4 w-4 text-muted-foreground" }),
241
+ /* @__PURE__ */ jsx("span", { children: formatTypeLabel(row.original.providerKey) })
242
+ ] })
243
+ },
244
+ {
245
+ accessorKey: "unifiedStatus",
246
+ header: t("payment_gateways.transactions.columns.status", "Status"),
247
+ cell: ({ row }) => /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: STATUS_STYLES[row.original.unifiedStatus] ?? "", children: t(`payment_gateways.status.${row.original.unifiedStatus}`, formatTypeLabel(row.original.unifiedStatus)) })
248
+ },
249
+ {
250
+ accessorKey: "amount",
251
+ header: t("payment_gateways.transactions.columns.amount", "Amount"),
252
+ cell: ({ row }) => formatAmount(row.original.amount, row.original.currencyCode)
253
+ },
254
+ {
255
+ accessorKey: "providerSessionId",
256
+ header: t("payment_gateways.transactions.columns.session", "Session"),
257
+ cell: ({ row }) => /* @__PURE__ */ jsx("span", { className: "font-mono text-xs text-muted-foreground", children: row.original.providerSessionId ?? "\u2014" }),
258
+ meta: { maxWidth: "18rem", truncate: true }
259
+ },
260
+ {
261
+ accessorKey: "updatedAt",
262
+ header: t("payment_gateways.transactions.columns.updatedAt", "Updated"),
263
+ cell: ({ row }) => formatDateTime(row.original.updatedAt)
264
+ }
265
+ ], [t]);
266
+ const selectedSummary = React.useMemo(
267
+ () => rows.find((row) => row.id === selectedId) ?? null,
268
+ [rows, selectedId]
269
+ );
270
+ return /* @__PURE__ */ jsxs(Page, { children: [
271
+ /* @__PURE__ */ jsx(
272
+ PageHeader,
273
+ {
274
+ title: t("payment_gateways.transactions.title", "Payment Transactions"),
275
+ description: t("payment_gateways.transactions.description", "Track all payment-gateway transactions, inspect webhook activity, and review provider logs from one place.")
276
+ }
277
+ ),
278
+ /* @__PURE__ */ jsxs(PageBody, { className: "space-y-6", children: [
279
+ /* @__PURE__ */ jsx(
280
+ DataTable,
281
+ {
282
+ title: t("payment_gateways.transactions.tableTitle", "Transactions"),
283
+ columns,
284
+ data: rows,
285
+ filters,
286
+ filterValues,
287
+ onFiltersApply: handleFiltersApply,
288
+ onFiltersClear: handleFiltersClear,
289
+ searchValue: search,
290
+ onSearchChange: (value) => {
291
+ setSearch(value);
292
+ setPage(1);
293
+ },
294
+ searchPlaceholder: t("payment_gateways.transactions.searchPlaceholder", "Search by payment, transaction, session, or gateway id"),
295
+ perspective: { tableId: "payment_gateways.transactions.list" },
296
+ pagination: { page, pageSize: 20, total, totalPages, onPageChange: setPage },
297
+ isLoading,
298
+ onRowClick: (row) => setSelectedId((current) => current === row.id ? null : row.id),
299
+ rowActions: (row) => /* @__PURE__ */ jsx(RowActions, { items: [
300
+ {
301
+ id: "details",
302
+ label: selectedId === row.id ? t("payment_gateways.transactions.actions.hideDetails", "Hide details") : t("payment_gateways.transactions.actions.showDetails", "Show details"),
303
+ onSelect: () => setSelectedId((current) => current === row.id ? null : row.id)
304
+ }
305
+ ] })
306
+ }
307
+ ),
308
+ selectedId ? /* @__PURE__ */ jsxs(Card, { children: [
309
+ /* @__PURE__ */ jsxs(CardHeader, { className: "gap-4 sm:flex-row sm:items-start sm:justify-between", children: [
310
+ /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
311
+ /* @__PURE__ */ jsx(CardTitle, { children: t("payment_gateways.transactions.detail.title", "Transaction details") }),
312
+ selectedSummary ? /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-2 text-sm text-muted-foreground", children: [
313
+ /* @__PURE__ */ jsx("span", { children: selectedSummary.paymentId }),
314
+ /* @__PURE__ */ jsx("span", { children: "\u2022" }),
315
+ /* @__PURE__ */ jsx("span", { children: formatTypeLabel(selectedSummary.providerKey) }),
316
+ /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: STATUS_STYLES[selectedSummary.unifiedStatus] ?? "", children: t(`payment_gateways.status.${selectedSummary.unifiedStatus}`, formatTypeLabel(selectedSummary.unifiedStatus)) })
317
+ ] }) : null
318
+ ] }),
319
+ /* @__PURE__ */ jsxs(
320
+ Button,
321
+ {
322
+ type: "button",
323
+ variant: "outline",
324
+ size: "sm",
325
+ onClick: () => void handleRefreshStatus(),
326
+ disabled: isRefreshingStatus || isLoadingDetail,
327
+ children: [
328
+ isRefreshingStatus ? /* @__PURE__ */ jsx(Spinner, { className: "mr-2 h-4 w-4" }) : /* @__PURE__ */ jsx(RefreshCw, { className: "mr-2 h-4 w-4" }),
329
+ t("payment_gateways.transactions.actions.refreshStatus", "Refresh status")
330
+ ]
331
+ }
332
+ )
333
+ ] }),
334
+ /* @__PURE__ */ jsxs(CardContent, { className: "space-y-6", children: [
335
+ isLoadingDetail ? /* @__PURE__ */ jsx(LoadingMessage, { label: t("payment_gateways.transactions.detail.loading", "Loading transaction details") }) : null,
336
+ !isLoadingDetail && detailError ? /* @__PURE__ */ jsx(ErrorMessage, { label: detailError }) : null,
337
+ !isLoadingDetail && !detailError && detail ? /* @__PURE__ */ jsxs(Fragment, { children: [
338
+ /* @__PURE__ */ jsxs("div", { className: "grid gap-4 lg:grid-cols-4", children: [
339
+ /* @__PURE__ */ jsx(
340
+ DetailStat,
341
+ {
342
+ label: t("payment_gateways.transactions.detail.summary.status", "Status"),
343
+ value: /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: STATUS_STYLES[detail.transaction.unifiedStatus] ?? "", children: t(`payment_gateways.status.${detail.transaction.unifiedStatus}`, formatTypeLabel(detail.transaction.unifiedStatus)) })
344
+ }
345
+ ),
346
+ /* @__PURE__ */ jsx(
347
+ DetailStat,
348
+ {
349
+ label: t("payment_gateways.transactions.detail.summary.gatewayStatus", "Gateway status"),
350
+ value: detail.transaction.gatewayStatus ?? noneLabel
351
+ }
352
+ ),
353
+ /* @__PURE__ */ jsx(
354
+ DetailStat,
355
+ {
356
+ label: t("payment_gateways.transactions.detail.summary.amount", "Amount"),
357
+ value: formatAmount(detail.transaction.amount, detail.transaction.currencyCode)
358
+ }
359
+ ),
360
+ /* @__PURE__ */ jsx(
361
+ DetailStat,
362
+ {
363
+ label: t("payment_gateways.transactions.detail.summary.provider", "Provider"),
364
+ value: formatTypeLabel(detail.transaction.providerKey)
365
+ }
366
+ )
367
+ ] }),
368
+ /* @__PURE__ */ jsxs("div", { className: "grid gap-6 xl:grid-cols-[minmax(0,1.2fr)_minmax(0,0.8fr)]", children: [
369
+ /* @__PURE__ */ jsxs("div", { className: "space-y-6", children: [
370
+ /* @__PURE__ */ jsxs("section", { className: "space-y-3", children: [
371
+ /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold", children: t("payment_gateways.transactions.detail.identifiers", "Identifiers") }),
372
+ /* @__PURE__ */ jsx("dl", { className: "grid gap-3 md:grid-cols-2", children: [
373
+ [t("payment_gateways.transactions.columns.transactionId", "Transaction ID"), detail.transaction.id],
374
+ [t("payment_gateways.transactions.columns.paymentId", "Payment ID"), detail.transaction.paymentId],
375
+ [t("payment_gateways.transactions.columns.session", "Session ID"), detail.transaction.providerSessionId ?? "\u2014"],
376
+ [t("payment_gateways.transactions.columns.gatewayPaymentId", "Gateway payment ID"), detail.transaction.gatewayPaymentId ?? "\u2014"],
377
+ [t("payment_gateways.transactions.columns.gatewayRefundId", "Gateway refund ID"), detail.transaction.gatewayRefundId ?? "\u2014"],
378
+ [t("payment_gateways.transactions.columns.redirectUrl", "Redirect URL"), detail.transaction.redirectUrl ?? "\u2014"],
379
+ [t("payment_gateways.transactions.columns.createdAt", "Created at"), formatDateTime(detail.transaction.createdAt)],
380
+ [t("payment_gateways.transactions.columns.updatedAt", "Updated at"), formatDateTime(detail.transaction.updatedAt)],
381
+ [t("payment_gateways.transactions.columns.lastWebhookAt", "Last webhook"), formatDateTime(detail.transaction.lastWebhookAt)],
382
+ [t("payment_gateways.transactions.columns.lastPolledAt", "Last poll"), formatDateTime(detail.transaction.lastPolledAt)]
383
+ ].map(([label, value]) => /* @__PURE__ */ jsxs("div", { className: "rounded-lg border bg-muted/20 px-4 py-3", children: [
384
+ /* @__PURE__ */ jsx("dt", { className: "text-[11px] font-medium uppercase tracking-wide text-muted-foreground", children: label }),
385
+ /* @__PURE__ */ jsx("dd", { className: "mt-1 break-all text-sm", children: value })
386
+ ] }, label)) })
387
+ ] }),
388
+ /* @__PURE__ */ jsxs("section", { className: "space-y-3", children: [
389
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
390
+ /* @__PURE__ */ jsx(Webhook, { className: "h-4 w-4 text-muted-foreground" }),
391
+ /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold", children: t("payment_gateways.transactions.detail.webhooks", "Webhook activity") })
392
+ ] }),
393
+ detail.transaction.webhookLog && detail.transaction.webhookLog.length > 0 ? /* @__PURE__ */ jsx("div", { className: "overflow-hidden rounded-lg border", children: /* @__PURE__ */ jsxs("table", { className: "w-full text-sm", children: [
394
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { className: "border-b bg-muted/40", children: [
395
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-2 text-left font-medium", children: t("payment_gateways.transactions.columns.eventType", "Event") }),
396
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-2 text-left font-medium", children: t("payment_gateways.transactions.columns.status", "Status") }),
397
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-2 text-left font-medium", children: t("payment_gateways.transactions.columns.processed", "Processed") }),
398
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-2 text-left font-medium", children: t("payment_gateways.transactions.columns.receivedAt", "Received") })
399
+ ] }) }),
400
+ /* @__PURE__ */ jsx("tbody", { children: detail.transaction.webhookLog.map((entry) => /* @__PURE__ */ jsxs("tr", { className: "border-b last:border-0", children: [
401
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-2 font-medium", children: entry.eventType }),
402
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-2", children: /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: STATUS_STYLES[entry.unifiedStatus] ?? "", children: t(`payment_gateways.status.${entry.unifiedStatus}`, formatTypeLabel(entry.unifiedStatus)) }) }),
403
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-2", children: entry.processed ? t("common.yes", "Yes") : t("common.no", "No") }),
404
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-2 text-muted-foreground", children: formatDateTime(entry.receivedAt) })
405
+ ] }, `${entry.idempotencyKey}:${entry.receivedAt}`)) })
406
+ ] }) }) : /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("payment_gateways.transactions.detail.webhooksEmpty", "No webhook events have been recorded for this transaction yet.") })
407
+ ] }),
408
+ /* @__PURE__ */ jsxs("section", { className: "space-y-3", children: [
409
+ /* @__PURE__ */ jsx("h3", { className: "text-sm font-semibold", children: t("payment_gateways.transactions.detail.logs", "Gateway logs") }),
410
+ detail.logs.length === 0 ? /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: t("payment_gateways.transactions.detail.logsEmpty", "No transaction-scoped logs are available yet.") }) : /* @__PURE__ */ jsx("div", { className: "overflow-hidden rounded-lg border", children: /* @__PURE__ */ jsxs("table", { className: "w-full text-sm", children: [
411
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { className: "border-b bg-muted/40", children: [
412
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-2 text-left font-medium", children: t("payment_gateways.transactions.columns.time", "Time") }),
413
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-2 text-left font-medium", children: t("payment_gateways.transactions.columns.level", "Level") }),
414
+ /* @__PURE__ */ jsx("th", { className: "px-4 py-2 text-left font-medium", children: t("payment_gateways.transactions.columns.message", "Message") })
415
+ ] }) }),
416
+ /* @__PURE__ */ jsx("tbody", { children: detail.logs.map((log) => {
417
+ const isExpanded = expandedLogId === log.id;
418
+ const metadataEntries = [
419
+ [t("payment_gateways.transactions.log.time", "Time"), formatDateTime(log.createdAt)],
420
+ [t("payment_gateways.transactions.log.level", "Level"), t(`payment_gateways.transactions.level.${log.level}`, log.level)],
421
+ [t("payment_gateways.transactions.log.code", "Code"), log.code ?? null],
422
+ [t("payment_gateways.transactions.log.runId", "Run ID"), log.runId ?? null],
423
+ [t("payment_gateways.transactions.log.entityType", "Entity Type"), log.scopeEntityType ?? null],
424
+ [t("payment_gateways.transactions.log.entityId", "Entity ID"), log.scopeEntityId ?? null]
425
+ ].filter((entry) => typeof entry[1] === "string" && entry[1].trim().length > 0);
426
+ const { inlineEntries, nestedEntries } = splitLogPayload(log.payload);
427
+ return /* @__PURE__ */ jsxs(React.Fragment, { children: [
428
+ /* @__PURE__ */ jsxs("tr", { className: "border-b last:border-0", children: [
429
+ /* @__PURE__ */ jsx("td", { className: "whitespace-nowrap px-4 py-2 text-muted-foreground", children: formatDateTime(log.createdAt) }),
430
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-2", children: /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: LOG_LEVEL_STYLES[log.level] ?? "", children: t(`payment_gateways.transactions.level.${log.level}`, log.level) }) }),
431
+ /* @__PURE__ */ jsx("td", { className: "px-4 py-2", children: /* @__PURE__ */ jsxs(
432
+ Button,
433
+ {
434
+ type: "button",
435
+ variant: "ghost",
436
+ size: "sm",
437
+ className: "h-auto w-full justify-start gap-2 px-0 py-0 text-left hover:bg-transparent",
438
+ onClick: () => setExpandedLogId((current) => current === log.id ? null : log.id),
439
+ children: [
440
+ isExpanded ? /* @__PURE__ */ jsx(ChevronDown, { className: "h-4 w-4 shrink-0" }) : /* @__PURE__ */ jsx(ChevronRight, { className: "h-4 w-4 shrink-0" }),
441
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: log.message })
442
+ ]
443
+ }
444
+ ) })
445
+ ] }),
446
+ isExpanded ? /* @__PURE__ */ jsx("tr", { className: "border-b bg-muted/15 last:border-0", children: /* @__PURE__ */ jsx("td", { colSpan: 3, className: "px-4 py-4", children: /* @__PURE__ */ jsxs("div", { className: "space-y-4 rounded-lg border bg-card p-4", children: [
447
+ metadataEntries.length > 0 ? /* @__PURE__ */ jsx("dl", { className: "grid gap-3 sm:grid-cols-2 xl:grid-cols-3", children: metadataEntries.map(([label, value]) => /* @__PURE__ */ jsxs("div", { className: "rounded-md border bg-muted/20 px-3 py-2", children: [
448
+ /* @__PURE__ */ jsx("dt", { className: "text-[11px] font-medium uppercase tracking-wide text-muted-foreground", children: label }),
449
+ /* @__PURE__ */ jsx("dd", { className: "mt-1 break-all text-sm", children: value })
450
+ ] }, label)) }) : null,
451
+ inlineEntries.length > 0 ? /* @__PURE__ */ jsx("dl", { className: "grid gap-3 sm:grid-cols-2 xl:grid-cols-3", children: inlineEntries.map(([key, value]) => /* @__PURE__ */ jsxs("div", { className: "rounded-md border bg-muted/20 px-3 py-2", children: [
452
+ /* @__PURE__ */ jsx("dt", { className: "text-[11px] font-medium uppercase tracking-wide text-muted-foreground", children: formatLogDetailLabel(key) }),
453
+ /* @__PURE__ */ jsx("dd", { className: "mt-1 break-words text-sm", children: formatLogPrimitiveValue(value) })
454
+ ] }, key)) }) : null,
455
+ nestedEntries.map(([key, value]) => /* @__PURE__ */ jsx(
456
+ JsonDisplay,
457
+ {
458
+ data: value,
459
+ title: formatLogDetailLabel(key),
460
+ defaultExpanded: true,
461
+ maxInitialDepth: 1,
462
+ theme: "dark",
463
+ maxHeight: "16rem",
464
+ className: "p-4"
465
+ },
466
+ key
467
+ ))
468
+ ] }) }) }) : null
469
+ ] }, log.id);
470
+ }) })
471
+ ] }) })
472
+ ] })
473
+ ] }),
474
+ /* @__PURE__ */ jsx("div", { className: "space-y-4", children: /* @__PURE__ */ jsx(
475
+ JsonDisplay,
476
+ {
477
+ data: detail.transaction.gatewayMetadata ?? {},
478
+ title: t("payment_gateways.transactions.detail.gatewayMetadata", "Gateway metadata"),
479
+ defaultExpanded: true,
480
+ maxInitialDepth: 1,
481
+ theme: "dark",
482
+ maxHeight: "24rem",
483
+ className: "p-4"
484
+ }
485
+ ) })
486
+ ] })
487
+ ] }) : null
488
+ ] })
489
+ ] }) : null
490
+ ] })
491
+ ] });
492
+ }
493
+ export {
494
+ PaymentTransactionsPage as default
495
+ };
496
+ //# sourceMappingURL=page.js.map