@adonis-agora/payments 0.2.0 → 0.3.0

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 (319) hide show
  1. package/CHANGELOG.md +2347 -0
  2. package/dist/assets/spa/assets/index-CT5Zon6P.css +1 -0
  3. package/dist/assets/spa/assets/index-CvEbJEnq.js +41 -0
  4. package/dist/assets/spa/assets/index-CvEbJEnq.js.map +1 -0
  5. package/dist/assets/spa/index.html +20 -0
  6. package/dist/commands/main.d.ts +4 -3
  7. package/dist/commands/main.d.ts.map +1 -1
  8. package/dist/commands/main.js +9 -2
  9. package/dist/commands/main.js.map +1 -1
  10. package/dist/commands/payments_health.d.ts +31 -0
  11. package/dist/commands/payments_health.d.ts.map +1 -0
  12. package/dist/commands/payments_health.js +113 -0
  13. package/dist/commands/payments_health.js.map +1 -0
  14. package/dist/commands/payments_sync.d.ts +18 -4
  15. package/dist/commands/payments_sync.d.ts.map +1 -1
  16. package/dist/commands/payments_sync.js +136 -40
  17. package/dist/commands/payments_sync.js.map +1 -1
  18. package/dist/configure.d.ts +12 -5
  19. package/dist/configure.d.ts.map +1 -1
  20. package/dist/configure.js +18 -5
  21. package/dist/configure.js.map +1 -1
  22. package/dist/providers/dashboard_provider.d.ts +97 -0
  23. package/dist/providers/dashboard_provider.d.ts.map +1 -0
  24. package/dist/providers/dashboard_provider.js +430 -0
  25. package/dist/providers/dashboard_provider.js.map +1 -0
  26. package/dist/providers/payments_client_provider.d.ts +41 -0
  27. package/dist/providers/payments_client_provider.d.ts.map +1 -0
  28. package/dist/providers/payments_client_provider.js +95 -0
  29. package/dist/providers/payments_client_provider.js.map +1 -0
  30. package/dist/providers/payments_provider.d.ts +35 -0
  31. package/dist/providers/payments_provider.d.ts.map +1 -1
  32. package/dist/providers/payments_provider.js +250 -36
  33. package/dist/providers/payments_provider.js.map +1 -1
  34. package/dist/src/billing/billing_health.d.ts +85 -0
  35. package/dist/src/billing/billing_health.d.ts.map +1 -0
  36. package/dist/src/billing/billing_health.js +155 -0
  37. package/dist/src/billing/billing_health.js.map +1 -0
  38. package/dist/src/billing/billing_overview.d.ts +4 -3
  39. package/dist/src/billing/billing_overview.d.ts.map +1 -1
  40. package/dist/src/billing/billing_overview.js +14 -5
  41. package/dist/src/billing/billing_overview.js.map +1 -1
  42. package/dist/src/billing/billing_store.d.ts +634 -5
  43. package/dist/src/billing/billing_store.d.ts.map +1 -1
  44. package/dist/src/billing/billing_store.js +18 -1
  45. package/dist/src/billing/billing_store.js.map +1 -1
  46. package/dist/src/billing/index.d.ts +2 -1
  47. package/dist/src/billing/index.d.ts.map +1 -1
  48. package/dist/src/billing/index.js +1 -0
  49. package/dist/src/billing/index.js.map +1 -1
  50. package/dist/src/billing/list_query.d.ts +16 -0
  51. package/dist/src/billing/list_query.d.ts.map +1 -0
  52. package/dist/src/billing/list_query.js +28 -0
  53. package/dist/src/billing/list_query.js.map +1 -0
  54. package/dist/src/billing/lucid_billing_store.d.ts +122 -4
  55. package/dist/src/billing/lucid_billing_store.d.ts.map +1 -1
  56. package/dist/src/billing/lucid_billing_store.js +811 -13
  57. package/dist/src/billing/lucid_billing_store.js.map +1 -1
  58. package/dist/src/billing/mixins/index.d.ts +3 -0
  59. package/dist/src/billing/mixins/index.d.ts.map +1 -1
  60. package/dist/src/billing/mixins/index.js +3 -0
  61. package/dist/src/billing/mixins/index.js.map +1 -1
  62. package/dist/src/billing/mixins/with_audit_event.d.ts +48 -0
  63. package/dist/src/billing/mixins/with_audit_event.d.ts.map +1 -0
  64. package/dist/src/billing/mixins/with_audit_event.js +77 -0
  65. package/dist/src/billing/mixins/with_audit_event.js.map +1 -0
  66. package/dist/src/billing/mixins/with_customer.d.ts +39 -0
  67. package/dist/src/billing/mixins/with_customer.d.ts.map +1 -0
  68. package/dist/src/billing/mixins/with_customer.js +68 -0
  69. package/dist/src/billing/mixins/with_customer.js.map +1 -0
  70. package/dist/src/billing/mixins/with_dispute.d.ts +68 -0
  71. package/dist/src/billing/mixins/with_dispute.d.ts.map +1 -0
  72. package/dist/src/billing/mixins/with_dispute.js +83 -0
  73. package/dist/src/billing/mixins/with_dispute.js.map +1 -0
  74. package/dist/src/billing/mixins/with_payment.d.ts +42 -0
  75. package/dist/src/billing/mixins/with_payment.d.ts.map +1 -1
  76. package/dist/src/billing/mixins/with_payment.js +29 -3
  77. package/dist/src/billing/mixins/with_payment.js.map +1 -1
  78. package/dist/src/billing/mixins/with_subscription.d.ts +7 -0
  79. package/dist/src/billing/mixins/with_subscription.d.ts.map +1 -1
  80. package/dist/src/billing/mixins/with_subscription.js +15 -1
  81. package/dist/src/billing/mixins/with_subscription.js.map +1 -1
  82. package/dist/src/billing/mixins/with_usage_event.d.ts +7 -0
  83. package/dist/src/billing/mixins/with_usage_event.d.ts.map +1 -1
  84. package/dist/src/billing/mixins/with_usage_event.js +15 -1
  85. package/dist/src/billing/mixins/with_usage_event.js.map +1 -1
  86. package/dist/src/billing/mixins/with_webhook_event.d.ts +18 -0
  87. package/dist/src/billing/mixins/with_webhook_event.d.ts.map +1 -1
  88. package/dist/src/billing/mixins/with_webhook_event.js +18 -1
  89. package/dist/src/billing/mixins/with_webhook_event.js.map +1 -1
  90. package/dist/src/billing/resolve_dispatch.d.ts +22 -0
  91. package/dist/src/billing/resolve_dispatch.d.ts.map +1 -0
  92. package/dist/src/billing/resolve_dispatch.js +44 -0
  93. package/dist/src/billing/resolve_dispatch.js.map +1 -0
  94. package/dist/src/billing/resolve_store.d.ts +18 -0
  95. package/dist/src/billing/resolve_store.d.ts.map +1 -0
  96. package/dist/src/billing/resolve_store.js +35 -0
  97. package/dist/src/billing/resolve_store.js.map +1 -0
  98. package/dist/src/billing/schema.d.ts +108 -0
  99. package/dist/src/billing/schema.d.ts.map +1 -0
  100. package/dist/src/billing/schema.js +350 -0
  101. package/dist/src/billing/schema.js.map +1 -0
  102. package/dist/src/billing/webhook_dispatcher.d.ts +95 -16
  103. package/dist/src/billing/webhook_dispatcher.d.ts.map +1 -1
  104. package/dist/src/billing/webhook_dispatcher.js +186 -33
  105. package/dist/src/billing/webhook_dispatcher.js.map +1 -1
  106. package/dist/src/billing/webhook_events.d.ts +67 -1
  107. package/dist/src/billing/webhook_events.d.ts.map +1 -1
  108. package/dist/src/billing/webhook_events.js +15 -0
  109. package/dist/src/billing/webhook_events.js.map +1 -1
  110. package/dist/src/billing/webhook_processor.d.ts.map +1 -1
  111. package/dist/src/billing/webhook_processor.js +325 -5
  112. package/dist/src/billing/webhook_processor.js.map +1 -1
  113. package/dist/src/client/define_config.d.ts +150 -0
  114. package/dist/src/client/define_config.d.ts.map +1 -0
  115. package/dist/src/client/define_config.js +98 -0
  116. package/dist/src/client/define_config.js.map +1 -0
  117. package/dist/src/client/handlers.d.ts +71 -0
  118. package/dist/src/client/handlers.d.ts.map +1 -0
  119. package/dist/src/client/handlers.js +119 -0
  120. package/dist/src/client/handlers.js.map +1 -0
  121. package/dist/src/client/index.d.ts +16 -0
  122. package/dist/src/client/index.d.ts.map +1 -0
  123. package/dist/src/client/index.js +13 -0
  124. package/dist/src/client/index.js.map +1 -0
  125. package/dist/src/client/statuses.d.ts +38 -0
  126. package/dist/src/client/statuses.d.ts.map +1 -0
  127. package/dist/src/client/statuses.js +42 -0
  128. package/dist/src/client/statuses.js.map +1 -0
  129. package/dist/src/dashboard/actions.d.ts +143 -0
  130. package/dist/src/dashboard/actions.d.ts.map +1 -0
  131. package/dist/src/dashboard/actions.js +112 -0
  132. package/dist/src/dashboard/actions.js.map +1 -0
  133. package/dist/src/dashboard/auth.d.ts +136 -0
  134. package/dist/src/dashboard/auth.d.ts.map +1 -0
  135. package/dist/src/dashboard/auth.js +152 -0
  136. package/dist/src/dashboard/auth.js.map +1 -0
  137. package/dist/src/dashboard/define_config.d.ts +80 -0
  138. package/dist/src/dashboard/define_config.d.ts.map +1 -0
  139. package/dist/src/dashboard/define_config.js +83 -0
  140. package/dist/src/dashboard/define_config.js.map +1 -0
  141. package/dist/src/dashboard/handlers.d.ts +281 -0
  142. package/dist/src/dashboard/handlers.d.ts.map +1 -0
  143. package/dist/src/dashboard/handlers.js +960 -0
  144. package/dist/src/dashboard/handlers.js.map +1 -0
  145. package/dist/src/dashboard/index.d.ts +18 -0
  146. package/dist/src/dashboard/index.d.ts.map +1 -0
  147. package/dist/src/dashboard/index.js +14 -0
  148. package/dist/src/dashboard/index.js.map +1 -0
  149. package/dist/src/dashboard/login_page.d.ts +23 -0
  150. package/dist/src/dashboard/login_page.d.ts.map +1 -0
  151. package/dist/src/dashboard/login_page.js +170 -0
  152. package/dist/src/dashboard/login_page.js.map +1 -0
  153. package/dist/src/dashboard/period.d.ts +31 -0
  154. package/dist/src/dashboard/period.d.ts.map +1 -0
  155. package/dist/src/dashboard/period.js +44 -0
  156. package/dist/src/dashboard/period.js.map +1 -0
  157. package/dist/src/dashboard/session_cookie.d.ts +42 -0
  158. package/dist/src/dashboard/session_cookie.d.ts.map +1 -0
  159. package/dist/src/dashboard/session_cookie.js +97 -0
  160. package/dist/src/dashboard/session_cookie.js.map +1 -0
  161. package/dist/src/dashboard/spa.d.ts +24 -0
  162. package/dist/src/dashboard/spa.d.ts.map +1 -0
  163. package/dist/src/dashboard/spa.js +52 -0
  164. package/dist/src/dashboard/spa.js.map +1 -0
  165. package/dist/src/define_config.d.ts +244 -9
  166. package/dist/src/define_config.d.ts.map +1 -1
  167. package/dist/src/define_config.js +97 -1
  168. package/dist/src/define_config.js.map +1 -1
  169. package/dist/src/diagnostics.d.ts +287 -7
  170. package/dist/src/diagnostics.d.ts.map +1 -1
  171. package/dist/src/diagnostics.js +317 -1
  172. package/dist/src/diagnostics.js.map +1 -1
  173. package/dist/src/driver.d.ts +139 -5
  174. package/dist/src/driver.d.ts.map +1 -1
  175. package/dist/src/drivers/abacate.d.ts +12 -2
  176. package/dist/src/drivers/abacate.d.ts.map +1 -1
  177. package/dist/src/drivers/abacate.js +112 -19
  178. package/dist/src/drivers/abacate.js.map +1 -1
  179. package/dist/src/drivers/adyen.d.ts +164 -0
  180. package/dist/src/drivers/adyen.d.ts.map +1 -0
  181. package/dist/src/drivers/adyen.js +678 -0
  182. package/dist/src/drivers/adyen.js.map +1 -0
  183. package/dist/src/drivers/asaas.d.ts +52 -2
  184. package/dist/src/drivers/asaas.d.ts.map +1 -1
  185. package/dist/src/drivers/asaas.js +364 -29
  186. package/dist/src/drivers/asaas.js.map +1 -1
  187. package/dist/src/drivers/dodo.d.ts +135 -0
  188. package/dist/src/drivers/dodo.d.ts.map +1 -0
  189. package/dist/src/drivers/dodo.js +864 -0
  190. package/dist/src/drivers/dodo.js.map +1 -0
  191. package/dist/src/drivers/efi.d.ts +98 -0
  192. package/dist/src/drivers/efi.d.ts.map +1 -0
  193. package/dist/src/drivers/efi.js +628 -0
  194. package/dist/src/drivers/efi.js.map +1 -0
  195. package/dist/src/drivers/infinitepay.d.ts +156 -0
  196. package/dist/src/drivers/infinitepay.d.ts.map +1 -0
  197. package/dist/src/drivers/infinitepay.js +321 -0
  198. package/dist/src/drivers/infinitepay.js.map +1 -0
  199. package/dist/src/drivers/lemonsqueezy.d.ts +125 -0
  200. package/dist/src/drivers/lemonsqueezy.d.ts.map +1 -0
  201. package/dist/src/drivers/lemonsqueezy.js +632 -0
  202. package/dist/src/drivers/lemonsqueezy.js.map +1 -0
  203. package/dist/src/drivers/mercadopago.d.ts +97 -0
  204. package/dist/src/drivers/mercadopago.d.ts.map +1 -0
  205. package/dist/src/drivers/mercadopago.js +844 -0
  206. package/dist/src/drivers/mercadopago.js.map +1 -0
  207. package/dist/src/drivers/mollie.d.ts +125 -0
  208. package/dist/src/drivers/mollie.d.ts.map +1 -0
  209. package/dist/src/drivers/mollie.js +812 -0
  210. package/dist/src/drivers/mollie.js.map +1 -0
  211. package/dist/src/drivers/paddle.d.ts +148 -0
  212. package/dist/src/drivers/paddle.d.ts.map +1 -0
  213. package/dist/src/drivers/paddle.js +738 -0
  214. package/dist/src/drivers/paddle.js.map +1 -0
  215. package/dist/src/drivers/pagarme.d.ts +97 -0
  216. package/dist/src/drivers/pagarme.d.ts.map +1 -0
  217. package/dist/src/drivers/pagarme.js +829 -0
  218. package/dist/src/drivers/pagarme.js.map +1 -0
  219. package/dist/src/drivers/pagbank.d.ts +57 -0
  220. package/dist/src/drivers/pagbank.d.ts.map +1 -0
  221. package/dist/src/drivers/pagbank.js +499 -0
  222. package/dist/src/drivers/pagbank.js.map +1 -0
  223. package/dist/src/drivers/paypal.d.ts +120 -0
  224. package/dist/src/drivers/paypal.d.ts.map +1 -0
  225. package/dist/src/drivers/paypal.js +891 -0
  226. package/dist/src/drivers/paypal.js.map +1 -0
  227. package/dist/src/drivers/polar.d.ts +118 -0
  228. package/dist/src/drivers/polar.d.ts.map +1 -0
  229. package/dist/src/drivers/polar.js +604 -0
  230. package/dist/src/drivers/polar.js.map +1 -0
  231. package/dist/src/drivers/razorpay.d.ts +103 -0
  232. package/dist/src/drivers/razorpay.d.ts.map +1 -0
  233. package/dist/src/drivers/razorpay.js +867 -0
  234. package/dist/src/drivers/razorpay.js.map +1 -0
  235. package/dist/src/drivers/shared.d.ts +33 -0
  236. package/dist/src/drivers/shared.d.ts.map +1 -0
  237. package/dist/src/drivers/shared.js +37 -0
  238. package/dist/src/drivers/shared.js.map +1 -0
  239. package/dist/src/drivers/square.d.ts +133 -0
  240. package/dist/src/drivers/square.d.ts.map +1 -0
  241. package/dist/src/drivers/square.js +905 -0
  242. package/dist/src/drivers/square.js.map +1 -0
  243. package/dist/src/drivers/stripe.d.ts +40 -3
  244. package/dist/src/drivers/stripe.d.ts.map +1 -1
  245. package/dist/src/drivers/stripe.js +806 -25
  246. package/dist/src/drivers/stripe.js.map +1 -1
  247. package/dist/src/drivers/woovi.d.ts +10 -3
  248. package/dist/src/drivers/woovi.d.ts.map +1 -1
  249. package/dist/src/drivers/woovi.js +162 -29
  250. package/dist/src/drivers/woovi.js.map +1 -1
  251. package/dist/src/ensure_customer.d.ts +34 -1
  252. package/dist/src/ensure_customer.d.ts.map +1 -1
  253. package/dist/src/ensure_customer.js +29 -4
  254. package/dist/src/ensure_customer.js.map +1 -1
  255. package/dist/src/http.d.ts +37 -3
  256. package/dist/src/http.d.ts.map +1 -1
  257. package/dist/src/http.js +69 -5
  258. package/dist/src/http.js.map +1 -1
  259. package/dist/src/index.d.ts +40 -10
  260. package/dist/src/index.d.ts.map +1 -1
  261. package/dist/src/index.js +22 -4
  262. package/dist/src/index.js.map +1 -1
  263. package/dist/src/invoice/emit_invoice.d.ts.map +1 -1
  264. package/dist/src/invoice/emit_invoice.js +31 -11
  265. package/dist/src/invoice/emit_invoice.js.map +1 -1
  266. package/dist/src/money.d.ts +23 -5
  267. package/dist/src/money.d.ts.map +1 -1
  268. package/dist/src/money.js +72 -7
  269. package/dist/src/money.js.map +1 -1
  270. package/dist/src/payments_manager.d.ts +8 -1
  271. package/dist/src/payments_manager.d.ts.map +1 -1
  272. package/dist/src/payments_manager.js +168 -6
  273. package/dist/src/payments_manager.js.map +1 -1
  274. package/dist/src/services/main.d.ts +38 -0
  275. package/dist/src/services/main.d.ts.map +1 -1
  276. package/dist/src/services/main.js +130 -0
  277. package/dist/src/services/main.js.map +1 -1
  278. package/dist/src/telescope/index.d.ts +2 -0
  279. package/dist/src/telescope/index.d.ts.map +1 -1
  280. package/dist/src/telescope/index.js +1 -0
  281. package/dist/src/telescope/index.js.map +1 -1
  282. package/dist/src/telescope/payments_watcher.d.ts +10 -4
  283. package/dist/src/telescope/payments_watcher.d.ts.map +1 -1
  284. package/dist/src/telescope/payments_watcher.js +65 -13
  285. package/dist/src/telescope/payments_watcher.js.map +1 -1
  286. package/dist/src/telescope/register.d.ts +62 -0
  287. package/dist/src/telescope/register.d.ts.map +1 -0
  288. package/dist/src/telescope/register.js +48 -0
  289. package/dist/src/telescope/register.js.map +1 -0
  290. package/dist/src/testing/fake_payments.d.ts +62 -0
  291. package/dist/src/testing/fake_payments.d.ts.map +1 -0
  292. package/dist/src/testing/fake_payments.js +82 -0
  293. package/dist/src/testing/fake_payments.js.map +1 -0
  294. package/dist/src/testing/in_memory_billing_store.d.ts +151 -2
  295. package/dist/src/testing/in_memory_billing_store.d.ts.map +1 -1
  296. package/dist/src/testing/in_memory_billing_store.js +517 -4
  297. package/dist/src/testing/in_memory_billing_store.js.map +1 -1
  298. package/dist/src/testing/index.d.ts +2 -1
  299. package/dist/src/testing/index.d.ts.map +1 -1
  300. package/dist/src/testing/index.js +1 -0
  301. package/dist/src/testing/index.js.map +1 -1
  302. package/dist/src/types.d.ts +161 -5
  303. package/dist/src/types.d.ts.map +1 -1
  304. package/dist/src/types.js +30 -1
  305. package/dist/src/types.js.map +1 -1
  306. package/dist/src/webhook_handlers.d.ts +96 -2
  307. package/dist/src/webhook_handlers.d.ts.map +1 -1
  308. package/dist/src/webhook_handlers.js +91 -10
  309. package/dist/src/webhook_handlers.js.map +1 -1
  310. package/dist/src/webhook_security.d.ts +94 -3
  311. package/dist/src/webhook_security.d.ts.map +1 -1
  312. package/dist/src/webhook_security.js +173 -9
  313. package/dist/src/webhook_security.js.map +1 -1
  314. package/dist/stubs/config/payments.stub +13 -0
  315. package/dist/stubs/config/payments_client.stub +42 -0
  316. package/dist/stubs/config/payments_dashboard.stub +38 -0
  317. package/dist/stubs/database/migrations/create_billing_tables.stub +35 -77
  318. package/dist/stubs/make/webhook_handler/main.stub +29 -11
  319. package/package.json +60 -25
@@ -0,0 +1,20 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <meta name="robots" content="noindex, nofollow" />
7
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
8
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
9
+ <link
10
+ href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&family=Space+Grotesk:wght@400;500;600;700&display=swap"
11
+ rel="stylesheet"
12
+ />
13
+ <title>payments · billing console</title>
14
+ <script type="module" crossorigin src="/__PAYMENTS_DASHBOARD__/assets/index-CvEbJEnq.js"></script>
15
+ <link rel="stylesheet" crossorigin href="/__PAYMENTS_DASHBOARD__/assets/index-CT5Zon6P.css">
16
+ </head>
17
+ <body>
18
+ <div id="root"></div>
19
+ </body>
20
+ </html>
@@ -1,5 +1,6 @@
1
1
  import { ListLoader } from '@adonisjs/core/ace';
2
2
  import MakeBillable from './make_billable.js';
3
+ import PaymentsHealth from './payments_health.js';
3
4
  import PaymentsSync from './payments_sync.js';
4
5
  import PaymentsWebhook from './payments_webhook.js';
5
6
  /**
@@ -7,10 +8,10 @@ import PaymentsWebhook from './payments_webhook.js';
7
8
  * `rcFile.addCommand('@adonis-agora/payments/commands')` (done by this package's
8
9
  * `configure`). The ace kernel imports this module and treats it as a commands loader: a
9
10
  * {@link ListLoader} over the payments commands (`make:billable`, `make:webhook-handler`,
10
- * `payments:webhook`, `payments:sync`) provides their metadata and constructors.
11
+ * `payments:webhook`, `payments:sync`, `payments:health`) provides their metadata and constructors.
11
12
  */
12
- declare const loader: ListLoader<typeof MakeBillable | typeof PaymentsSync | typeof PaymentsWebhook>;
13
+ declare const loader: ListLoader<typeof MakeBillable | typeof PaymentsHealth | typeof PaymentsSync | typeof PaymentsWebhook>;
13
14
  export declare const getMetaData: () => Promise<import("@adonisjs/core/types/ace").CommandMetaData[]>;
14
- export declare const getCommand: (metaData: import("@adonisjs/core/types/ace").CommandMetaData) => Promise<typeof MakeBillable | typeof PaymentsSync | typeof PaymentsWebhook | null>;
15
+ export declare const getCommand: (metaData: import("@adonisjs/core/types/ace").CommandMetaData) => Promise<typeof MakeBillable | typeof PaymentsHealth | typeof PaymentsSync | typeof PaymentsWebhook | null>;
15
16
  export default loader;
16
17
  //# sourceMappingURL=main.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../commands/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAE9C,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAEpD;;;;;;GAMG;AACH,QAAA,MAAM,MAAM,gFAAoF,CAAC;AAEjG,eAAO,MAAM,WAAW,qEAAkC,CAAC;AAC3D,eAAO,MAAM,UAAU,sJAAiC,CAAC;AAEzD,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../commands/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAE9C,OAAO,cAAc,MAAM,sBAAsB,CAAC;AAClD,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAEpD;;;;;;GAMG;AACH,QAAA,MAAM,MAAM,wGAMV,CAAC;AAEH,eAAO,MAAM,WAAW,qEAAkC,CAAC;AAC3D,eAAO,MAAM,UAAU,8KAAiC,CAAC;AAEzD,eAAe,MAAM,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { ListLoader } from '@adonisjs/core/ace';
2
2
  import MakeBillable from './make_billable.js';
3
3
  import MakeWebhookHandler from './make_webhook_handler.js';
4
+ import PaymentsHealth from './payments_health.js';
4
5
  import PaymentsSync from './payments_sync.js';
5
6
  import PaymentsWebhook from './payments_webhook.js';
6
7
  /**
@@ -8,9 +9,15 @@ import PaymentsWebhook from './payments_webhook.js';
8
9
  * `rcFile.addCommand('@adonis-agora/payments/commands')` (done by this package's
9
10
  * `configure`). The ace kernel imports this module and treats it as a commands loader: a
10
11
  * {@link ListLoader} over the payments commands (`make:billable`, `make:webhook-handler`,
11
- * `payments:webhook`, `payments:sync`) provides their metadata and constructors.
12
+ * `payments:webhook`, `payments:sync`, `payments:health`) provides their metadata and constructors.
12
13
  */
13
- const loader = new ListLoader([MakeBillable, MakeWebhookHandler, PaymentsWebhook, PaymentsSync]);
14
+ const loader = new ListLoader([
15
+ MakeBillable,
16
+ MakeWebhookHandler,
17
+ PaymentsWebhook,
18
+ PaymentsSync,
19
+ PaymentsHealth,
20
+ ]);
14
21
  export const getMetaData = loader.getMetaData.bind(loader);
15
22
  export const getCommand = loader.getCommand.bind(loader);
16
23
  export default loader;
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["../../commands/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,kBAAkB,MAAM,2BAA2B,CAAC;AAC3D,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,CAAC,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,YAAY,CAAC,CAAC,CAAC;AAEjG,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC3D,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAEzD,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../commands/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,kBAAkB,MAAM,2BAA2B,CAAC;AAC3D,OAAO,cAAc,MAAM,sBAAsB,CAAC;AAClD,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC;IAC5B,YAAY;IACZ,kBAAkB;IAClB,eAAe;IACf,YAAY;IACZ,cAAc;CACf,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC3D,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAEzD,eAAe,MAAM,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { BaseCommand } from '@adonisjs/core/ace';
2
+ import type { CommandOptions } from '@adonisjs/core/types/ace';
3
+ /**
4
+ * `node ace payments:health` — the scheduled check for the six silent failures of a billing
5
+ * install: events claimed and never finished, events the dispatcher gave up on, charges
6
+ * created that never confirmed, a chargeback whose evidence window is about to close, a
7
+ * chargeback that is simply open, and deliveries the endpoint refused.
8
+ *
9
+ * Two of those are the reason to run this on a cron rather than when something looks wrong.
10
+ * A closing evidence window is not a failure at all — nothing is broken, and the money goes
11
+ * anyway if nobody answers in time. A refused delivery leaves no ledger row (it is rejected
12
+ * before an event exists), so a rotated webhook credential looks exactly like a quiet
13
+ * gateway from the inside: no events, no failures, and revenue that simply stops.
14
+ *
15
+ * Exits non-zero when anything is wrong, so a cron entry or a container healthcheck can
16
+ * page on it without parsing the output. `--json` prints the machine-readable form for a
17
+ * metrics shipper.
18
+ */
19
+ export default class PaymentsHealth extends BaseCommand {
20
+ static commandName: string;
21
+ static description: string;
22
+ static options: CommandOptions;
23
+ stuckAfter?: number;
24
+ unconfirmedAfter?: number;
25
+ window?: number;
26
+ disputeWindow?: number;
27
+ rejectedWindow?: number;
28
+ json?: boolean;
29
+ run(): Promise<void>;
30
+ }
31
+ //# sourceMappingURL=payments_health.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payments_health.d.ts","sourceRoot":"","sources":["../../commands/payments_health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAS,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAK/D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,WAAW;IACrD,OAAgB,WAAW,SAAqB;IAChD,OAAgB,WAAW,SACkF;IAC7G,OAAgB,OAAO,EAAE,cAAc,CAAsB;IAKrD,UAAU,CAAC,EAAE,MAAM,CAAC;IAKpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAG1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAMhB,aAAa,CAAC,EAAE,MAAM,CAAC;IAKvB,cAAc,CAAC,EAAE,MAAM,CAAC;IAGxB,IAAI,CAAC,EAAE,OAAO,CAAC;IAER,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CA4DpC"}
@@ -0,0 +1,113 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { BaseCommand, flags } from '@adonisjs/core/ace';
8
+ import { billingHealth } from '../src/billing/billing_health.js';
9
+ import { resolveBillingStore } from '../src/billing/resolve_store.js';
10
+ /**
11
+ * `node ace payments:health` — the scheduled check for the six silent failures of a billing
12
+ * install: events claimed and never finished, events the dispatcher gave up on, charges
13
+ * created that never confirmed, a chargeback whose evidence window is about to close, a
14
+ * chargeback that is simply open, and deliveries the endpoint refused.
15
+ *
16
+ * Two of those are the reason to run this on a cron rather than when something looks wrong.
17
+ * A closing evidence window is not a failure at all — nothing is broken, and the money goes
18
+ * anyway if nobody answers in time. A refused delivery leaves no ledger row (it is rejected
19
+ * before an event exists), so a rotated webhook credential looks exactly like a quiet
20
+ * gateway from the inside: no events, no failures, and revenue that simply stops.
21
+ *
22
+ * Exits non-zero when anything is wrong, so a cron entry or a container healthcheck can
23
+ * page on it without parsing the output. `--json` prints the machine-readable form for a
24
+ * metrics shipper.
25
+ */
26
+ export default class PaymentsHealth extends BaseCommand {
27
+ static commandName = 'payments:health';
28
+ static description = 'Report stuck and failed webhooks, unconfirmed charges, open and closing disputes, and refused deliveries';
29
+ static options = { startApp: true };
30
+ async run() {
31
+ const config = this.app.config.get('payments', {});
32
+ if (config.billing?.enabled === false) {
33
+ this.logger.error('The billing layer is disabled (billing.enabled = false). Nothing to check.');
34
+ this.exitCode = 1;
35
+ return;
36
+ }
37
+ const store = await resolveBillingStore(config);
38
+ const report = await billingHealth(store, {
39
+ ...(this.stuckAfter !== undefined ? { stuckAfter: this.stuckAfter * 60_000 } : {}),
40
+ ...(this.unconfirmedAfter !== undefined
41
+ ? { unconfirmedAfter: this.unconfirmedAfter * 60_000 }
42
+ : {}),
43
+ ...(this.window !== undefined ? { failedWithin: this.window * 3_600_000 } : {}),
44
+ ...(this.disputeWindow !== undefined
45
+ ? { disputeDueWithin: this.disputeWindow * 3_600_000 }
46
+ : {}),
47
+ ...(this.rejectedWindow !== undefined
48
+ ? { rejectedWithin: this.rejectedWindow * 3_600_000 }
49
+ : {}),
50
+ });
51
+ if (this.json) {
52
+ this.logger.log(JSON.stringify(report, null, 2));
53
+ }
54
+ else {
55
+ for (const check of report.checks) {
56
+ const line = `${check.count} ${check.label}`;
57
+ if (check.healthy)
58
+ this.logger.success(line);
59
+ else
60
+ this.logger.error(`${line}\n ${check.hint}`);
61
+ }
62
+ for (const failure of report.failures) {
63
+ this.logger.info(` ${failure.provider} ${failure.type}: ${failure.count} failed`);
64
+ }
65
+ // WHICH windows are closing, soonest first — a count names nobody to email and no
66
+ // gateway dashboard to open. The list is capped; the check's count is not, so a
67
+ // report can name twenty of fifty without pretending it named all of them.
68
+ for (const dispute of report.deadlines) {
69
+ const due = dispute.evidenceDueBy?.toISOString() ?? 'unknown';
70
+ this.logger.info(` ${dispute.provider} ${dispute.gatewayId} (payment ${dispute.paymentGatewayId}): evidence due ${due}`);
71
+ }
72
+ // The open-dispute check exists BECAUSE a deadline is usually absent — Asaas' own
73
+ // webhook examples never carry one — so printing only `deadlines` would fire a count
74
+ // that names nobody, on precisely the installs the check was added for.
75
+ const named = new Set(report.deadlines.map((dispute) => dispute.gatewayId));
76
+ for (const dispute of report.openDisputes) {
77
+ if (named.has(dispute.gatewayId))
78
+ continue;
79
+ this.logger.info(` ${dispute.provider} ${dispute.gatewayId} (payment ${dispute.paymentGatewayId}): open, no deadline given`);
80
+ }
81
+ }
82
+ // Non-zero so a scheduler notices without reading the output.
83
+ if (!report.healthy)
84
+ this.exitCode = 1;
85
+ }
86
+ }
87
+ __decorate([
88
+ flags.number({
89
+ description: 'Minutes an event may sit unfinished before it counts as stuck (default 15)',
90
+ })
91
+ ], PaymentsHealth.prototype, "stuckAfter", void 0);
92
+ __decorate([
93
+ flags.number({
94
+ description: 'Minutes a charge may stay pending before it counts as unconfirmed (default 120)',
95
+ })
96
+ ], PaymentsHealth.prototype, "unconfirmedAfter", void 0);
97
+ __decorate([
98
+ flags.number({ description: 'Window in hours that failures are counted over (default 24)' })
99
+ ], PaymentsHealth.prototype, "window", void 0);
100
+ __decorate([
101
+ flags.number({
102
+ description: 'Hours ahead to look for a dispute whose evidence window closes (default 72). Windows already past are always counted',
103
+ })
104
+ ], PaymentsHealth.prototype, "disputeWindow", void 0);
105
+ __decorate([
106
+ flags.number({
107
+ description: 'Window in hours that refused deliveries are counted over (default 24)',
108
+ })
109
+ ], PaymentsHealth.prototype, "rejectedWindow", void 0);
110
+ __decorate([
111
+ flags.boolean({ description: 'Print the report as JSON' })
112
+ ], PaymentsHealth.prototype, "json", void 0);
113
+ //# sourceMappingURL=payments_health.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payments_health.js","sourceRoot":"","sources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AAC,MAAM,CAAC;QACZ,WAAW,EAAE,uEAAuE;KACrF,CAAC;sDAC8B;AAGxB;IADP,KAAK,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,0BAA0B,EAAE,CAAC;4CACpC"}
@@ -2,10 +2,24 @@ import { BaseCommand } from '@adonisjs/core/ace';
2
2
  import type { CommandOptions } from '@adonisjs/core/types/ace';
3
3
  /**
4
4
  * `node ace payments:sync [--provider=stripe] [--customer=cus_123 | --all]` — reconcile
5
- * local billing records with the gateway. Useful after missed webhooks or manual
6
- * dashboard changes: pulls recent invoices for a customer (or every customer in
7
- * `billing_customers` with `--all`) and upserts the paid ones into the local store, so
8
- * the billing tables converge with the gateway.
5
+ * local billing records with the gateway. Useful after missed webhooks or manual dashboard
6
+ * changes: pages through every invoice for a customer (or for every recorded customer with
7
+ * `--all`), asks the gateway what each charge's payment actually says, and writes that into
8
+ * the local store — so the billing tables converge with the gateway.
9
+ *
10
+ * Three properties this command has to have, and did not:
11
+ *
12
+ * 1. **Every invoice, not the first page.** It read one unpaginated listing and reported the
13
+ * total as if it were the whole customer.
14
+ * 2. **Both directions.** It wrote `status: 'paid'` and nothing else, counting everything
15
+ * that was not paid as "skipped (non-paid)" — so a local row saying `paid` while the
16
+ * gateway said refunded or charged back could never be corrected, which is precisely the
17
+ * drift a gateway-is-truth reconcile exists for.
18
+ * 3. **The gateway's settlement date, or none.** It stamped `paidAt: new Date()`, which moved
19
+ * historic revenue into the month the reconcile ran.
20
+ *
21
+ * One local state is deliberately NOT reconcilable from the gateway: `disputed`. See the
22
+ * comment on it below.
9
23
  */
10
24
  export default class PaymentsSync extends BaseCommand {
11
25
  #private;
@@ -1 +1 @@
1
- {"version":3,"file":"payments_sync.d.ts","sourceRoot":"","sources":["../../commands/payments_sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAS,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAM/D;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,WAAW;;IACnD,OAAgB,WAAW,SAAmB;IAC9C,OAAgB,WAAW,SAA6D;IACxF,OAAgB,OAAO,EAAE,cAAc,CAA+B;IAG9D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAKlB,GAAG,CAAC,EAAE,OAAO,CAAC;IAEP,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAqEpC"}
1
+ {"version":3,"file":"payments_sync.d.ts","sourceRoot":"","sources":["../../commands/payments_sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAS,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAsB/D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,WAAW;;IACnD,OAAgB,WAAW,SAAmB;IAC9C,OAAgB,WAAW,SAA6D;IACxF,OAAgB,OAAO,EAAE,cAAc,CAA+B;IAG9D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAKlB,GAAG,CAAC,EAAE,OAAO,CAAC;IAEP,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CA2JpC"}
@@ -5,15 +5,43 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { BaseCommand, flags } from '@adonisjs/core/ace';
8
- import db from '@adonisjs/lucid/services/db';
9
- import { LucidBillingStore } from '../src/billing/lucid_billing_store.js';
8
+ import { resolveBillingStore } from '../src/billing/resolve_store.js';
10
9
  import { PaymentsManager } from '../src/payments_manager.js';
10
+ /** Customers pulled per page while iterating `--all`. */
11
+ const PAGE = 100;
12
+ /**
13
+ * A gateway-sent settlement date as a `Date`, or `undefined` when there is nothing usable.
14
+ *
15
+ * Never a fallback to "now". `revenue()` windows on `paid_at`, so a manufactured date files
16
+ * money in the month the reconcile ran rather than the month it was earned — and running the
17
+ * reconcile twice, in two months, counted the same charge in both.
18
+ */
19
+ function parseInstant(value) {
20
+ if (value === undefined)
21
+ return undefined;
22
+ const parsed = new Date(value);
23
+ return Number.isNaN(parsed.getTime()) ? undefined : parsed;
24
+ }
11
25
  /**
12
26
  * `node ace payments:sync [--provider=stripe] [--customer=cus_123 | --all]` — reconcile
13
- * local billing records with the gateway. Useful after missed webhooks or manual
14
- * dashboard changes: pulls recent invoices for a customer (or every customer in
15
- * `billing_customers` with `--all`) and upserts the paid ones into the local store, so
16
- * the billing tables converge with the gateway.
27
+ * local billing records with the gateway. Useful after missed webhooks or manual dashboard
28
+ * changes: pages through every invoice for a customer (or for every recorded customer with
29
+ * `--all`), asks the gateway what each charge's payment actually says, and writes that into
30
+ * the local store — so the billing tables converge with the gateway.
31
+ *
32
+ * Three properties this command has to have, and did not:
33
+ *
34
+ * 1. **Every invoice, not the first page.** It read one unpaginated listing and reported the
35
+ * total as if it were the whole customer.
36
+ * 2. **Both directions.** It wrote `status: 'paid'` and nothing else, counting everything
37
+ * that was not paid as "skipped (non-paid)" — so a local row saying `paid` while the
38
+ * gateway said refunded or charged back could never be corrected, which is precisely the
39
+ * drift a gateway-is-truth reconcile exists for.
40
+ * 3. **The gateway's settlement date, or none.** It stamped `paidAt: new Date()`, which moved
41
+ * historic revenue into the month the reconcile ran.
42
+ *
43
+ * One local state is deliberately NOT reconcilable from the gateway: `disputed`. See the
44
+ * comment on it below.
17
45
  */
18
46
  export default class PaymentsSync extends BaseCommand {
19
47
  static commandName = 'payments:sync';
@@ -26,7 +54,7 @@ export default class PaymentsSync extends BaseCommand {
26
54
  return;
27
55
  }
28
56
  if (!this.customer && !this.all) {
29
- this.logger.error('Pass --customer=<gateway customer id> to sync one customer, or --all to sync every customer in billing_customers.');
57
+ this.logger.error('Pass --customer=<gateway customer id> to sync one customer, or --all to sync every recorded gateway customer.');
30
58
  return;
31
59
  }
32
60
  const manager = await this.app.container.make(PaymentsManager);
@@ -34,50 +62,118 @@ export default class PaymentsSync extends BaseCommand {
34
62
  // Some gateways (Woovi/OpenPix) have no invoice concept — fail early with a clear
35
63
  // message instead of listing nothing.
36
64
  manager.assertCapability(driver, 'invoices');
37
- const store = new LucidBillingStore();
38
- const customers = this.customer ? [this.customer] : await this.#listCustomers();
65
+ // The CONFIGURED store, not a fresh Lucid one: an app that pointed `billing.store`
66
+ // somewhere else would otherwise have its reconcile write to a database the rest of
67
+ // the billing layer never reads.
68
+ const store = await resolveBillingStore(config);
69
+ const customers = this.customer
70
+ ? [this.customer]
71
+ : await this.#listCustomers(store, this.provider);
39
72
  if (customers.length === 0) {
40
- this.logger.info('No customers to sync (billing_customers is empty).');
73
+ this.logger.info('No customers recorded to sync. `--all` iterates the mappings written by ensureCustomer({ store }) / store.saveCustomer() — see the billing docs.');
41
74
  return;
42
75
  }
43
76
  let synced = 0;
77
+ let protectedRows = 0;
44
78
  for (const customerId of customers) {
45
79
  const invoices = await driver.listInvoices(customerId);
46
- let skipped = 0;
80
+ let changed = 0;
81
+ let unchanged = 0;
82
+ let undecided = 0;
47
83
  for (const invoice of invoices) {
48
- // Only sync invoices that represent a settled/paid billing event.
49
- if (invoice.status === 'paid') {
50
- await store.savePayment({
51
- gatewayId: invoice.gatewayId,
52
- provider: invoice.provider,
53
- status: 'paid',
54
- amount: invoice.amount.amount,
55
- currency: invoice.amount.currency,
56
- ...(invoice.customerId !== undefined ? { customerId: invoice.customerId } : {}),
57
- ...(invoice.subscriptionId !== undefined
58
- ? { subscriptionId: invoice.subscriptionId }
59
- : {}),
60
- paidAt: new Date(),
61
- payload: invoice.payload,
62
- });
63
- synced += 1;
84
+ const local = await store.findPaymentByGatewayId(invoice.gatewayId);
85
+ // The converged case, and the reason a second run of this command is cheap: the
86
+ // gateway says paid, the local row says paid, and it already carries a settlement
87
+ // date. There is nothing a `findPayment` could tell us, so it is not asked.
88
+ if (local !== null &&
89
+ local.status === 'paid' &&
90
+ local.paidAt &&
91
+ invoice.status === 'paid') {
92
+ unchanged += 1;
93
+ continue;
64
94
  }
65
- else {
66
- skipped += 1;
95
+ // `Invoice.status` cannot say `refunded` or `disputed` — its vocabulary has no
96
+ // members for them, so a reversed charge arrives here as `draft`. That is the exact
97
+ // drift a gateway-is-truth reconcile exists to correct, so the authority is the
98
+ // PAYMENT resource, which speaks `BillingStatus`: the listing enumerates, the payment
99
+ // decides.
100
+ const remote = await driver.findPayment(invoice.gatewayId);
101
+ if (remote === null) {
102
+ undecided += 1;
103
+ continue;
67
104
  }
105
+ // The one local state the gateway does not get to overwrite. A chargeback is money
106
+ // the bank has pulled back, it lives in `billing_disputes` with a deadline, and the
107
+ // gateway's payment resource frequently goes on reporting the charge as received
108
+ // while the dispute is open — so reconciling `disputed` back to `paid` here would
109
+ // re-count money that is gone and silence the dispute at the same time. Only
110
+ // `payment.dispute_closed`, which carries an outcome, resolves one.
111
+ if (local !== null && local.status === 'disputed' && remote.status !== 'disputed') {
112
+ protectedRows += 1;
113
+ this.logger.warning(` ${invoice.gatewayId}: local row is disputed, gateway says ${remote.status} — left alone. A dispute is resolved by its close event, not by a reconcile.`);
114
+ continue;
115
+ }
116
+ // Already agreed, with nothing left to add: same status, and either the settlement
117
+ // date is recorded or the gateway has none to give. Skipped so a reconcile over a
118
+ // stable install writes nothing at all rather than churning every row's `updated_at`.
119
+ if (local !== null &&
120
+ local.status === remote.status &&
121
+ (local.paidAt || remote.paidAt === undefined)) {
122
+ unchanged += 1;
123
+ continue;
124
+ }
125
+ // The gateway's OWN settlement date, and never a substitute for it. Stamping
126
+ // `new Date()` here — which is what this did — relocated historic revenue into the
127
+ // month the reconcile ran, so running it twice in different months counted the same
128
+ // charge in both. An already-recorded `paid_at` is never overwritten, and an invoice
129
+ // that carries none records none: absent means "not stated" to `savePayment`, which
130
+ // leaves whatever is there alone.
131
+ const settledAt = local?.paidAt ? undefined : parseInstant(remote.paidAt);
132
+ await store.savePayment({
133
+ gatewayId: invoice.gatewayId,
134
+ provider: invoice.provider,
135
+ // Both directions. Writing only `paid` meant a local row saying `paid` while the
136
+ // gateway said refunded or charged back could never be corrected — and every such
137
+ // row was counted as "skipped (non-paid)", which read like nothing was wrong.
138
+ status: remote.status,
139
+ amount: remote.amount.amount,
140
+ currency: remote.amount.currency,
141
+ ...(invoice.customerId !== undefined ? { customerId: invoice.customerId } : {}),
142
+ ...(invoice.subscriptionId !== undefined
143
+ ? { subscriptionId: invoice.subscriptionId }
144
+ : {}),
145
+ ...(settledAt !== undefined ? { paidAt: settledAt } : {}),
146
+ payload: invoice.payload,
147
+ });
148
+ changed += 1;
149
+ synced += 1;
68
150
  }
69
- this.logger.info(` ${customerId}: ${invoices.length} invoice(s), ${invoices.length - skipped} synced, ${skipped} skipped (non-paid)`);
151
+ this.logger.info(` ${customerId}: ${invoices.length} invoice(s), ${changed} reconciled, ${unchanged} already current, ${undecided} undecidable (gateway had no payment)`);
70
152
  }
71
- this.logger.success(`Synced ${synced} paid invoice(s) across ${customers.length} customer(s).`);
153
+ this.logger.success(`Reconciled ${synced} payment(s) across ${customers.length} customer(s)${protectedRows > 0 ? `; ${protectedRows} disputed row(s) left alone` : ''}.`);
72
154
  }
73
- /** Gateway customer ids from the `billing_customers` table (best-effort). */
74
- async #listCustomers() {
75
- try {
76
- const rows = await db.from('billing_customers').select('gateway_id');
77
- return rows.map((row) => row.gateway_id);
78
- }
79
- catch {
80
- return [];
155
+ /**
156
+ * Gateway customer ids from the recorded customer mappings.
157
+ *
158
+ * Read through the STORE rather than the table: `billing.store` is a configured seam, and
159
+ * a reconcile that queried `billing_customers` directly would iterate a table the rest of
160
+ * the billing layer no longer uses the moment an app points that seam elsewhere.
161
+ *
162
+ * Paged, because `--all` on a large install would otherwise select the whole table into
163
+ * memory before the first invoice is fetched.
164
+ */
165
+ async #listCustomers(store, provider) {
166
+ const ids = [];
167
+ for (let offset = 0;; offset += PAGE) {
168
+ const page = await store.listCustomers({
169
+ limit: PAGE,
170
+ offset,
171
+ ...(provider !== undefined ? { provider } : {}),
172
+ });
173
+ for (const row of page)
174
+ ids.push(row.gatewayId);
175
+ if (page.length < PAGE)
176
+ return ids;
81
177
  }
82
178
  }
83
179
  }
@@ -89,7 +185,7 @@ __decorate([
89
185
  ], PaymentsSync.prototype, "customer", void 0);
90
186
  __decorate([
91
187
  flags.boolean({
92
- description: 'Sync invoices for every customer in the billing_customers table',
188
+ description: 'Sync invoices for every recorded gateway customer',
93
189
  })
94
190
  ], PaymentsSync.prototype, "all", void 0);
95
191
  //# sourceMappingURL=payments_sync.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"payments_sync.js","sourceRoot":"","sources":["../../commands/payments_sync.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,WAAW;IACnD,MAAM,CAAU,WAAW,GAAG,eAAe,CAAC;IAC9C,MAAM,CAAU,WAAW,GAAG,yDAAyD,CAAC;IACxF,MAAM,CAAU,OAAO,GAAmB,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC;IAa7D,KAAK,CAAC,GAAG;QAChB,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAiB,UAAU,EAAE,EAAE,CAAC,CAAC;QACnE,IAAI,MAAM,CAAC,OAAO,EAAE,OAAO,KAAK,KAAK,EAAE,CAAC;YACtC,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,2EAA2E,CAC5E,CAAC;YACF,OAAO;QACT,CAAC;QACD,IAAI,CAAC,IAAI,CAAC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C,CACzJ,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,OAAO,CACjB,cAAc,MAAM,sBAAsB,SAAS,CAAC,MAAM,eACxD,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,aAAa,6BAA6B,CAAC,CAAC,CAAC,EACxE,GAAG,CACJ,CAAC;IACJ,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,cAAc,CAAC,KAAmB,EAAE,QAAiB;QACzD,MAAM,GAAG,GAAa,EAAE,CAAC;QACzB,KAAK,IAAI,MAAM,GAAG,CAAC,GAAI,MAAM,IAAI,IAAI,EAAE,CAAC;YACtC,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,aAAa,CAAC;gBACrC,KAAK,EAAE,IAAI;gBACX,MAAM;gBACN,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAChD,CAAC,CAAC;YACH,KAAK,MAAM,GAAG,IAAI,IAAI;gBAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YAChD,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI;gBAAE,OAAO,GAAG,CAAC;QACrC,CAAC;IACH,CAAC;;AApKO;IADP,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,8CAA8C,EAAE,CAAC;8CACpD;AAGlB;IADP,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,0CAA0C,EAAE,CAAC;8CAChD;AAKlB;IAHP,KAAK,CAAC,OAAO,CAAC;QACb,WAAW,EAAE,mDAAmD;KACjE,CAAC;yCACoB"}
@@ -2,11 +2,18 @@ import type Configure from '@adonisjs/core/commands/configure';
2
2
  /**
3
3
  * `node ace configure @adonis-agora/payments` — auto-wires the package:
4
4
  *
5
- * 1. registers the payments service provider in `adonisrc.ts`;
6
- * 2. publishes `config/payments.ts`;
7
- * 3. publishes the Lucid migrations for the billing tables (run `node ace migration:run`;
8
- * delete the file if you only use payments without the billing layer);
9
- * 4. registers the env validations for the payment providers.
5
+ * 1. registers the payments service provider in `adonisrc.ts`, plus the optional
6
+ * dashboard provider;
7
+ * 2. registers the Assembler `init` hook that generates the `app/payment_handlers/`
8
+ * barrel (discovery works without it — the provider falls back to a runtime scan —
9
+ * but the barrel removes that scan from boot);
10
+ * 3. publishes `config/payments.ts`, `config/payments_dashboard.ts` and
11
+ * `config/payments_client.ts` (the browser status endpoint — off unless enabled);
12
+ * 4. publishes ONE Lucid migration for the billing tables, which most apps can delete: the
13
+ * library creates its own schema on first use (`billing.autoCreateSchema`, on by
14
+ * default), so the file is there for apps that would rather run the DDL explicitly. Both
15
+ * paths call the same `createBillingTables`;
16
+ * 5. registers the env validations for the payment providers.
10
17
  */
11
18
  export declare function configure(command: Configure): Promise<void>;
12
19
  //# sourceMappingURL=configure.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../configure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,mCAAmC,CAAC;AAG/D;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,SAAS,iBAyBjD"}
1
+ {"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../configure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,mCAAmC,CAAC;AAG/D;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,SAAS,iBA+BjD"}
package/dist/configure.js CHANGED
@@ -2,21 +2,33 @@ import { stubsRoot } from './stubs/main.js';
2
2
  /**
3
3
  * `node ace configure @adonis-agora/payments` — auto-wires the package:
4
4
  *
5
- * 1. registers the payments service provider in `adonisrc.ts`;
6
- * 2. publishes `config/payments.ts`;
7
- * 3. publishes the Lucid migrations for the billing tables (run `node ace migration:run`;
8
- * delete the file if you only use payments without the billing layer);
9
- * 4. registers the env validations for the payment providers.
5
+ * 1. registers the payments service provider in `adonisrc.ts`, plus the optional
6
+ * dashboard provider;
7
+ * 2. registers the Assembler `init` hook that generates the `app/payment_handlers/`
8
+ * barrel (discovery works without it — the provider falls back to a runtime scan —
9
+ * but the barrel removes that scan from boot);
10
+ * 3. publishes `config/payments.ts`, `config/payments_dashboard.ts` and
11
+ * `config/payments_client.ts` (the browser status endpoint — off unless enabled);
12
+ * 4. publishes ONE Lucid migration for the billing tables, which most apps can delete: the
13
+ * library creates its own schema on first use (`billing.autoCreateSchema`, on by
14
+ * default), so the file is there for apps that would rather run the DDL explicitly. Both
15
+ * paths call the same `createBillingTables`;
16
+ * 5. registers the env validations for the payment providers.
10
17
  */
11
18
  export async function configure(command) {
12
19
  const codemods = await command.createCodemods();
13
20
  // biome-ignore lint/suspicious/noExplicitAny: `createCodemods` types the callback; matching media.
14
21
  await codemods.updateRcFile((rcFile) => {
15
22
  rcFile.addProvider('@adonis-agora/payments/payments_provider');
23
+ rcFile.addProvider('@adonis-agora/payments/dashboard_provider');
24
+ rcFile.addProvider('@adonis-agora/payments/payments_client_provider');
16
25
  rcFile.addCommand('@adonis-agora/payments/commands');
26
+ rcFile.addAssemblerHook('init', '@adonis-agora/payments/hooks/webhook_handlers');
17
27
  });
18
28
  const stubs = stubsRoot();
19
29
  await codemods.makeUsingStub(stubs, 'config/payments.stub', {});
30
+ await codemods.makeUsingStub(stubs, 'config/payments_dashboard.stub', {});
31
+ await codemods.makeUsingStub(stubs, 'config/payments_client.stub', {});
20
32
  await codemods.makeUsingStub(stubs, 'database/migrations/create_billing_tables.stub', {});
21
33
  await codemods.defineEnvValidations({
22
34
  leadingComment: 'PAYMENTS_',
@@ -28,6 +40,7 @@ export async function configure(command) {
28
40
  ASAAS_API_KEY: 'Env.schema.string.optional()',
29
41
  WOOVI_APP_ID: 'Env.schema.string.optional()',
30
42
  FOCUS_NFE_TOKEN: 'Env.schema.string.optional()',
43
+ PAYMENTS_DASHBOARD_TOKEN: 'Env.schema.string.optional()',
31
44
  },
32
45
  });
33
46
  }
@@ -1 +1 @@
1
- {"version":3,"file":"configure.js","sourceRoot":"","sources":["../configure.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,OAAkB;IAChD,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC;IAEhD,mGAAmG;IACnG,MAAM,QAAQ,CAAC,YAAY,CAAC,CAAC,MAAW,EAAE,EAAE;QAC1C,MAAM,CAAC,WAAW,CAAC,0CAA0C,CAAC,CAAC;QAC/D,MAAM,CAAC,UAAU,CAAC,iCAAiC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG,SAAS,EAAE,CAAC;IAC1B,MAAM,QAAQ,CAAC,aAAa,CAAC,KAAK,EAAE,sBAAsB,EAAE,EAAE,CAAC,CAAC;IAChE,MAAM,QAAQ,CAAC,aAAa,CAAC,KAAK,EAAE,gDAAgD,EAAE,EAAE,CAAC,CAAC;IAE1F,MAAM,QAAQ,CAAC,oBAAoB,CAAC;QAClC,cAAc,EAAE,WAAW;QAC3B,SAAS,EAAE;YACT,UAAU,EAAE,8BAA8B;YAC1C,qBAAqB,EAAE,8BAA8B;YACrD,eAAe,EAAE,8BAA8B;YAC/C,kBAAkB,EAAE,8BAA8B;YAClD,aAAa,EAAE,8BAA8B;YAC7C,YAAY,EAAE,8BAA8B;YAC5C,eAAe,EAAE,8BAA8B;SAChD;KACF,CAAC,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"configure.js","sourceRoot":"","sources":["../configure.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,OAAkB;IAChD,MAAM,QAAQ,GAAG,MAAM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