@mj-biz-apps/orders-core-entities-server 0.0.1 → 5.2.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 (267) hide show
  1. package/LICENSE +183 -0
  2. package/README.md +141 -2
  3. package/dist/AccountingBridge.d.ts +65 -0
  4. package/dist/AccountingBridge.d.ts.map +1 -0
  5. package/dist/AccountingBridge.js +102 -0
  6. package/dist/AccountingBridge.js.map +1 -0
  7. package/dist/AdvanceOrderStateOperation.d.ts +80 -0
  8. package/dist/AdvanceOrderStateOperation.d.ts.map +1 -0
  9. package/dist/AdvanceOrderStateOperation.js +267 -0
  10. package/dist/AdvanceOrderStateOperation.js.map +1 -0
  11. package/dist/ApplyAccountCreditOperation.d.ts +97 -0
  12. package/dist/ApplyAccountCreditOperation.d.ts.map +1 -0
  13. package/dist/ApplyAccountCreditOperation.js +275 -0
  14. package/dist/ApplyAccountCreditOperation.js.map +1 -0
  15. package/dist/BaseDeliveryChannel.d.ts +106 -0
  16. package/dist/BaseDeliveryChannel.d.ts.map +1 -0
  17. package/dist/BaseDeliveryChannel.js +36 -0
  18. package/dist/BaseDeliveryChannel.js.map +1 -0
  19. package/dist/BasePaymentProvider.d.ts +239 -0
  20. package/dist/BasePaymentProvider.d.ts.map +1 -0
  21. package/dist/BasePaymentProvider.js +91 -0
  22. package/dist/BasePaymentProvider.js.map +1 -0
  23. package/dist/BundleBehavior.d.ts +139 -0
  24. package/dist/BundleBehavior.d.ts.map +1 -0
  25. package/dist/BundleBehavior.js +173 -0
  26. package/dist/BundleBehavior.js.map +1 -0
  27. package/dist/BundleEngine.d.ts +60 -0
  28. package/dist/BundleEngine.d.ts.map +1 -0
  29. package/dist/BundleEngine.js +197 -0
  30. package/dist/BundleEngine.js.map +1 -0
  31. package/dist/CancelSubscriptionOperation.d.ts +98 -0
  32. package/dist/CancelSubscriptionOperation.d.ts.map +1 -0
  33. package/dist/CancelSubscriptionOperation.js +317 -0
  34. package/dist/CancelSubscriptionOperation.js.map +1 -0
  35. package/dist/CapturePaymentOperation.d.ts +62 -0
  36. package/dist/CapturePaymentOperation.d.ts.map +1 -0
  37. package/dist/CapturePaymentOperation.js +463 -0
  38. package/dist/CapturePaymentOperation.js.map +1 -0
  39. package/dist/CheckEntitlementOperation.d.ts +27 -0
  40. package/dist/CheckEntitlementOperation.d.ts.map +1 -0
  41. package/dist/CheckEntitlementOperation.js +45 -0
  42. package/dist/CheckEntitlementOperation.js.map +1 -0
  43. package/dist/CheckoutSessionService.d.ts +258 -0
  44. package/dist/CheckoutSessionService.d.ts.map +1 -0
  45. package/dist/CheckoutSessionService.js +1557 -0
  46. package/dist/CheckoutSessionService.js.map +1 -0
  47. package/dist/DeliveryBehavior.d.ts +121 -0
  48. package/dist/DeliveryBehavior.d.ts.map +1 -0
  49. package/dist/DeliveryBehavior.js +145 -0
  50. package/dist/DeliveryBehavior.js.map +1 -0
  51. package/dist/DeliveryRecipientResolver.d.ts +38 -0
  52. package/dist/DeliveryRecipientResolver.d.ts.map +1 -0
  53. package/dist/DeliveryRecipientResolver.js +93 -0
  54. package/dist/DeliveryRecipientResolver.js.map +1 -0
  55. package/dist/DeliveryResolver.d.ts +14 -0
  56. package/dist/DeliveryResolver.d.ts.map +1 -0
  57. package/dist/DeliveryResolver.js +45 -0
  58. package/dist/DeliveryResolver.js.map +1 -0
  59. package/dist/EmailDeliveryChannel.d.ts +31 -0
  60. package/dist/EmailDeliveryChannel.d.ts.map +1 -0
  61. package/dist/EmailDeliveryChannel.js +158 -0
  62. package/dist/EmailDeliveryChannel.js.map +1 -0
  63. package/dist/EntitlementBehavior.d.ts +235 -0
  64. package/dist/EntitlementBehavior.d.ts.map +1 -0
  65. package/dist/EntitlementBehavior.js +330 -0
  66. package/dist/EntitlementBehavior.js.map +1 -0
  67. package/dist/EntitlementEngine.d.ts +97 -0
  68. package/dist/EntitlementEngine.d.ts.map +1 -0
  69. package/dist/EntitlementEngine.js +338 -0
  70. package/dist/EntitlementEngine.js.map +1 -0
  71. package/dist/EntitlementGrantClaimDriver.d.ts +42 -0
  72. package/dist/EntitlementGrantClaimDriver.d.ts.map +1 -0
  73. package/dist/EntitlementGrantClaimDriver.js +158 -0
  74. package/dist/EntitlementGrantClaimDriver.js.map +1 -0
  75. package/dist/EntitlementRead.d.ts +82 -0
  76. package/dist/EntitlementRead.d.ts.map +1 -0
  77. package/dist/EntitlementRead.js +368 -0
  78. package/dist/EntitlementRead.js.map +1 -0
  79. package/dist/FulfillOrderLinesOperation.d.ts +34 -0
  80. package/dist/FulfillOrderLinesOperation.d.ts.map +1 -0
  81. package/dist/FulfillOrderLinesOperation.js +208 -0
  82. package/dist/FulfillOrderLinesOperation.js.map +1 -0
  83. package/dist/FulfillmentBehavior.d.ts +101 -0
  84. package/dist/FulfillmentBehavior.d.ts.map +1 -0
  85. package/dist/FulfillmentBehavior.js +145 -0
  86. package/dist/FulfillmentBehavior.js.map +1 -0
  87. package/dist/GLAccountResolver.d.ts +123 -0
  88. package/dist/GLAccountResolver.d.ts.map +1 -0
  89. package/dist/GLAccountResolver.js +175 -0
  90. package/dist/GLAccountResolver.js.map +1 -0
  91. package/dist/GetFulfillmentQueueOperation.d.ts +35 -0
  92. package/dist/GetFulfillmentQueueOperation.d.ts.map +1 -0
  93. package/dist/GetFulfillmentQueueOperation.js +221 -0
  94. package/dist/GetFulfillmentQueueOperation.js.map +1 -0
  95. package/dist/GetOverdueWorklistOperation.d.ts +41 -0
  96. package/dist/GetOverdueWorklistOperation.d.ts.map +1 -0
  97. package/dist/GetOverdueWorklistOperation.js +210 -0
  98. package/dist/GetOverdueWorklistOperation.js.map +1 -0
  99. package/dist/GiftCardBehavior.d.ts +97 -0
  100. package/dist/GiftCardBehavior.d.ts.map +1 -0
  101. package/dist/GiftCardBehavior.js +121 -0
  102. package/dist/GiftCardBehavior.js.map +1 -0
  103. package/dist/GiftCardEngine.d.ts +59 -0
  104. package/dist/GiftCardEngine.d.ts.map +1 -0
  105. package/dist/GiftCardEngine.js +197 -0
  106. package/dist/GiftCardEngine.js.map +1 -0
  107. package/dist/GuestOrderClaimDriver.d.ts +36 -0
  108. package/dist/GuestOrderClaimDriver.d.ts.map +1 -0
  109. package/dist/GuestOrderClaimDriver.js +161 -0
  110. package/dist/GuestOrderClaimDriver.js.map +1 -0
  111. package/dist/InvoiceBehavior.d.ts +394 -0
  112. package/dist/InvoiceBehavior.d.ts.map +1 -0
  113. package/dist/InvoiceBehavior.js +496 -0
  114. package/dist/InvoiceBehavior.js.map +1 -0
  115. package/dist/InvoiceBuilder.d.ts +48 -0
  116. package/dist/InvoiceBuilder.d.ts.map +1 -0
  117. package/dist/InvoiceBuilder.js +352 -0
  118. package/dist/InvoiceBuilder.js.map +1 -0
  119. package/dist/InvoiceDisplay.d.ts +96 -0
  120. package/dist/InvoiceDisplay.d.ts.map +1 -0
  121. package/dist/InvoiceDisplay.js +121 -0
  122. package/dist/InvoiceDisplay.js.map +1 -0
  123. package/dist/ListEntitlementsOperation.d.ts +21 -0
  124. package/dist/ListEntitlementsOperation.d.ts.map +1 -0
  125. package/dist/ListEntitlementsOperation.js +39 -0
  126. package/dist/ListEntitlementsOperation.js.map +1 -0
  127. package/dist/ManualPaymentProvider.d.ts +19 -0
  128. package/dist/ManualPaymentProvider.d.ts.map +1 -0
  129. package/dist/ManualPaymentProvider.js +92 -0
  130. package/dist/ManualPaymentProvider.js.map +1 -0
  131. package/dist/OrderEntityServer.d.ts +542 -0
  132. package/dist/OrderEntityServer.d.ts.map +1 -0
  133. package/dist/OrderEntityServer.js +2100 -0
  134. package/dist/OrderEntityServer.js.map +1 -0
  135. package/dist/OrderJournalEntryFactory.d.ts +140 -0
  136. package/dist/OrderJournalEntryFactory.d.ts.map +1 -0
  137. package/dist/OrderJournalEntryFactory.js +466 -0
  138. package/dist/OrderJournalEntryFactory.js.map +1 -0
  139. package/dist/OrderLineEntityServer.d.ts +90 -0
  140. package/dist/OrderLineEntityServer.d.ts.map +1 -0
  141. package/dist/OrderLineEntityServer.js +260 -0
  142. package/dist/OrderLineEntityServer.js.map +1 -0
  143. package/dist/OrdersSettings.d.ts +36 -0
  144. package/dist/OrdersSettings.d.ts.map +1 -0
  145. package/dist/OrdersSettings.js +147 -0
  146. package/dist/OrdersSettings.js.map +1 -0
  147. package/dist/PaymentAllocationFactory.d.ts +128 -0
  148. package/dist/PaymentAllocationFactory.d.ts.map +1 -0
  149. package/dist/PaymentAllocationFactory.js +235 -0
  150. package/dist/PaymentAllocationFactory.js.map +1 -0
  151. package/dist/PaymentHeaderEntityServer.d.ts +180 -0
  152. package/dist/PaymentHeaderEntityServer.d.ts.map +1 -0
  153. package/dist/PaymentHeaderEntityServer.js +656 -0
  154. package/dist/PaymentHeaderEntityServer.js.map +1 -0
  155. package/dist/PaymentIntentService.d.ts +101 -0
  156. package/dist/PaymentIntentService.d.ts.map +1 -0
  157. package/dist/PaymentIntentService.js +150 -0
  158. package/dist/PaymentIntentService.js.map +1 -0
  159. package/dist/PaymentJournalEntryFactory.d.ts +99 -0
  160. package/dist/PaymentJournalEntryFactory.d.ts.map +1 -0
  161. package/dist/PaymentJournalEntryFactory.js +127 -0
  162. package/dist/PaymentJournalEntryFactory.js.map +1 -0
  163. package/dist/PaymentLineEntityServer.d.ts +73 -0
  164. package/dist/PaymentLineEntityServer.d.ts.map +1 -0
  165. package/dist/PaymentLineEntityServer.js +303 -0
  166. package/dist/PaymentLineEntityServer.js.map +1 -0
  167. package/dist/PaymentProviderBehavior.d.ts +222 -0
  168. package/dist/PaymentProviderBehavior.d.ts.map +1 -0
  169. package/dist/PaymentProviderBehavior.js +368 -0
  170. package/dist/PaymentProviderBehavior.js.map +1 -0
  171. package/dist/PaymentProviderResolver.d.ts +84 -0
  172. package/dist/PaymentProviderResolver.d.ts.map +1 -0
  173. package/dist/PaymentProviderResolver.js +220 -0
  174. package/dist/PaymentProviderResolver.js.map +1 -0
  175. package/dist/PaymentReversalFactory.d.ts +107 -0
  176. package/dist/PaymentReversalFactory.d.ts.map +1 -0
  177. package/dist/PaymentReversalFactory.js +174 -0
  178. package/dist/PaymentReversalFactory.js.map +1 -0
  179. package/dist/PaymentSettlement.d.ts +56 -0
  180. package/dist/PaymentSettlement.d.ts.map +1 -0
  181. package/dist/PaymentSettlement.js +243 -0
  182. package/dist/PaymentSettlement.js.map +1 -0
  183. package/dist/PaymentTermsBehavior.d.ts +109 -0
  184. package/dist/PaymentTermsBehavior.d.ts.map +1 -0
  185. package/dist/PaymentTermsBehavior.js +172 -0
  186. package/dist/PaymentTermsBehavior.js.map +1 -0
  187. package/dist/PaymentWebhookHandler.d.ts +103 -0
  188. package/dist/PaymentWebhookHandler.d.ts.map +1 -0
  189. package/dist/PaymentWebhookHandler.js +246 -0
  190. package/dist/PaymentWebhookHandler.js.map +1 -0
  191. package/dist/PreviewPriceOperation.d.ts +62 -0
  192. package/dist/PreviewPriceOperation.d.ts.map +1 -0
  193. package/dist/PreviewPriceOperation.js +161 -0
  194. package/dist/PreviewPriceOperation.js.map +1 -0
  195. package/dist/PriceOrderOperation.d.ts +93 -0
  196. package/dist/PriceOrderOperation.d.ts.map +1 -0
  197. package/dist/PriceOrderOperation.js +146 -0
  198. package/dist/PriceOrderOperation.js.map +1 -0
  199. package/dist/ProductPriceEntityServer.d.ts +34 -0
  200. package/dist/ProductPriceEntityServer.d.ts.map +1 -0
  201. package/dist/ProductPriceEntityServer.js +97 -0
  202. package/dist/ProductPriceEntityServer.js.map +1 -0
  203. package/dist/RefundPaymentOperation.d.ts +61 -0
  204. package/dist/RefundPaymentOperation.d.ts.map +1 -0
  205. package/dist/RefundPaymentOperation.js +177 -0
  206. package/dist/RefundPaymentOperation.js.map +1 -0
  207. package/dist/RevenueRecognition.d.ts +76 -0
  208. package/dist/RevenueRecognition.d.ts.map +1 -0
  209. package/dist/RevenueRecognition.js +133 -0
  210. package/dist/RevenueRecognition.js.map +1 -0
  211. package/dist/ReversalBehavior.d.ts +82 -0
  212. package/dist/ReversalBehavior.d.ts.map +1 -0
  213. package/dist/ReversalBehavior.js +100 -0
  214. package/dist/ReversalBehavior.js.map +1 -0
  215. package/dist/ReversalResolver.d.ts +37 -0
  216. package/dist/ReversalResolver.d.ts.map +1 -0
  217. package/dist/ReversalResolver.js +96 -0
  218. package/dist/ReversalResolver.js.map +1 -0
  219. package/dist/SpawnRenewalsOperation.d.ts +109 -0
  220. package/dist/SpawnRenewalsOperation.d.ts.map +1 -0
  221. package/dist/SpawnRenewalsOperation.js +295 -0
  222. package/dist/SpawnRenewalsOperation.js.map +1 -0
  223. package/dist/StoredValuePaymentProvider.d.ts +52 -0
  224. package/dist/StoredValuePaymentProvider.d.ts.map +1 -0
  225. package/dist/StoredValuePaymentProvider.js +205 -0
  226. package/dist/StoredValuePaymentProvider.js.map +1 -0
  227. package/dist/StripeACHPaymentProvider.d.ts +50 -0
  228. package/dist/StripeACHPaymentProvider.d.ts.map +1 -0
  229. package/dist/StripeACHPaymentProvider.js +211 -0
  230. package/dist/StripeACHPaymentProvider.js.map +1 -0
  231. package/dist/StripePaymentProvider.d.ts +83 -0
  232. package/dist/StripePaymentProvider.d.ts.map +1 -0
  233. package/dist/StripePaymentProvider.js +442 -0
  234. package/dist/StripePaymentProvider.js.map +1 -0
  235. package/dist/SubscriptionBehavior.d.ts +197 -0
  236. package/dist/SubscriptionBehavior.d.ts.map +1 -0
  237. package/dist/SubscriptionBehavior.js +415 -0
  238. package/dist/SubscriptionBehavior.js.map +1 -0
  239. package/dist/checkoutCaptureAlert.d.ts +16 -0
  240. package/dist/checkoutCaptureAlert.d.ts.map +1 -0
  241. package/dist/checkoutCaptureAlert.js +55 -0
  242. package/dist/checkoutCaptureAlert.js.map +1 -0
  243. package/dist/checkoutCaptureRetry.d.ts +27 -0
  244. package/dist/checkoutCaptureRetry.d.ts.map +1 -0
  245. package/dist/checkoutCaptureRetry.js +50 -0
  246. package/dist/checkoutCaptureRetry.js.map +1 -0
  247. package/dist/claimDriverHelpers.d.ts +15 -0
  248. package/dist/claimDriverHelpers.d.ts.map +1 -0
  249. package/dist/claimDriverHelpers.js +34 -0
  250. package/dist/claimDriverHelpers.js.map +1 -0
  251. package/dist/entity-names.d.ts +15 -0
  252. package/dist/entity-names.d.ts.map +1 -0
  253. package/dist/entity-names.js +15 -0
  254. package/dist/entity-names.js.map +1 -0
  255. package/dist/identityClaimContracts.d.ts +118 -0
  256. package/dist/identityClaimContracts.d.ts.map +1 -0
  257. package/dist/identityClaimContracts.js +58 -0
  258. package/dist/identityClaimContracts.js.map +1 -0
  259. package/dist/index.d.ts +126 -0
  260. package/dist/index.d.ts.map +1 -0
  261. package/dist/index.js +115 -0
  262. package/dist/index.js.map +1 -0
  263. package/dist/sql-guards.d.ts +78 -0
  264. package/dist/sql-guards.d.ts.map +1 -0
  265. package/dist/sql-guards.js +115 -0
  266. package/dist/sql-guards.js.map +1 -0
  267. package/package.json +50 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PaymentHeaderEntityServer.js","sourceRoot":"","sources":["../src/PaymentHeaderEntityServer.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,OAAO,EACH,UAAU,EACV,gBAAgB,EAChB,sBAAsB,EAEtB,iBAAiB,EAGjB,QAAQ,EACR,SAAS,EACT,OAAO,EAEP,mBAAmB,EACnB,mBAAmB,GAEtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAoC,MAAM,8BAA8B,CAAC;AACrG,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,2BAA2B,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CA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
+ * WHY THIS EXISTS. Every driver has implemented `CreateIntent` since the payment seam landed, and
5
+ * until now NOTHING CALLED IT except unit tests. `PaymentHeaderEntityServer.settleWithProvider`
6
+ * refuses a provider-backed capture without one — *"names a payment provider but no provider intent,
7
+ * so there is nothing for the gateway to capture. Open an intent first"* — and there was no way to
8
+ * open one. The gateway path was complete at both ends and had no beginning. This is the beginning.
9
+ *
10
+ * ═══ WHY AN INTENT IS ITS OWN ROW AND NOT A STATUS ON `PaymentHeader` ═══
11
+ *
12
+ * Three reasons, and all three are ordinary for a bank debit rather than edge cases:
13
+ *
14
+ * RETRIES ARE 1:N. Insufficient funds is the commonest ACH failure, so a second attempt is the
15
+ * normal path. Each attempt is its own intent at the gateway with its own id. As a column you would
16
+ * either lose the first attempt's id on overwrite, or mint a `PaymentHeader` per attempt — putting
17
+ * rows for money that never moved into the payment series and into AR.
18
+ *
19
+ * AN INTENT CAN EXIST WITH NO PAYMENT. A customer opens a hosted checkout and walks away. There is
20
+ * no cash, no allocation, nothing to record as a payment — and `DecideSettlement` already answers
21
+ * for exactly that case ("the intent has no payment to settle"). A status column cannot represent a
22
+ * payment that does not exist.
23
+ *
24
+ * `ProviderEventID` IS THE WEBHOOK IDEMPOTENCY KEY AND IT LIVES HERE. Events can arrive before a
25
+ * header exists, or for an intent that never produces one. On the header, the key would not exist
26
+ * until the header did.
27
+ *
28
+ * There is also a lifecycle mismatch: a `Captured` header is frozen, while an intent churns through
29
+ * `Processing → Succeeded`. And the two vocabularies are genuinely different — ours is cash-shaped
30
+ * (`Pending|Captured|Failed|…`), the gateway's is attempt-shaped.
31
+ *
32
+ * THE CLIENT SECRET IS RETURNED AND NEVER STORED. It authorises the browser to confirm this intent;
33
+ * persisting it would put a bearer credential in a table that reporting reads. `BasePaymentProvider`
34
+ * says "Never logged" for the same reason, and the row below deliberately has no column for it.
35
+ *
36
+ * THIS DOES NOT CREATE A PAYMENT. Opening an intent is asking the gateway to stand ready; no money
37
+ * has moved and nothing is owed differently because of it. `Orders.CapturePayment` writes the
38
+ * `PaymentHeader` and links it to the intent by id.
39
+ *
40
+ * CONNECTS TO:
41
+ * DRIVER: ./BasePaymentProvider.ts → CreateIntent
42
+ * LOOKUP: ./PaymentProviderResolver.ts
43
+ * CAPTURE: ./CapturePaymentOperation.ts — takes the returned PaymentIntentID
44
+ * SETTLE: ./PaymentSettlement.ts — moves the payment when the gateway answers
45
+ * DOC: plans/archive/bizapps-orders-master.md D19, D37, D80
46
+ */
47
+ import { type IMetadataProvider, type UserInfo } from '@memberjunction/core';
48
+ import type { IntentStatus } from './PaymentProviderBehavior.js';
49
+ /** What to ask the gateway to stand ready for. */
50
+ export interface OpenIntentRequest {
51
+ /** Which configured `PaymentProvider` account. Decides the driver and the credentials. */
52
+ PaymentProviderID: string;
53
+ /** Major units, as we store money. */
54
+ Amount: number;
55
+ CurrencyCode: string;
56
+ /** The order this intent is collecting for. Null for a payment on account. */
57
+ OrderHeaderID?: string | null;
58
+ /** Who we are collecting from (D65) — the gateway's record should match ours. */
59
+ BillToPersonID?: string | null;
60
+ BillToOrganizationID?: string | null;
61
+ /** A saved instrument to charge — the recurring-renewal path, where the mandate already exists. */
62
+ ProviderCustomerRef?: string | null;
63
+ ProviderInstrumentRef?: string | null;
64
+ /** Echoed back on webhooks. Useful for reconciliation, never load-bearing. */
65
+ Metadata?: Record<string, string>;
66
+ /**
67
+ * Sent to the gateway so a retried call does not open a SECOND intent — which, on a saved
68
+ * instrument, would charge the customer twice. See the dedup note in {@link OpenPaymentIntent}.
69
+ */
70
+ IdempotencyKey?: string | null;
71
+ }
72
+ export interface OpenIntentResult {
73
+ Success: boolean;
74
+ /** Why not, when not — in the gateway's own words where it has any. */
75
+ Reason?: string;
76
+ /** OUR row's id. This is what `Orders.CapturePayment` takes. */
77
+ PaymentIntentID?: string;
78
+ /** The GATEWAY's id for the same thing. */
79
+ ProviderIntentID?: string;
80
+ Status?: IntentStatus;
81
+ /** For a browser-side confirmation flow. RETURNED, NEVER STORED — see the header. */
82
+ ClientSecret?: string;
83
+ /** For a hosted-checkout flow — where to send the customer. */
84
+ HostedUrl?: string;
85
+ /** True when this call found an intent we had already opened rather than opening a new one. */
86
+ WasExisting?: boolean;
87
+ }
88
+ /**
89
+ * Ask the gateway to stand ready, and record that we did.
90
+ *
91
+ * REFUSALS COME BACK IN THE RESULT; only faults throw. A gateway declining to open an intent is a
92
+ * normal outcome of asking — the same contract every driver follows — while an unresolvable provider
93
+ * or a database that will not accept the row is a fault the caller cannot act on.
94
+ *
95
+ * THE DEDUP IS NOT BELT-AND-BRACES. `ProviderIntentID` is UNIQUE, and a gateway given a repeated
96
+ * idempotency key returns the SAME intent rather than a new one. So a retried call reaches us with an
97
+ * id we already hold, and inserting would violate the constraint. Finding and returning the existing
98
+ * row makes the retry a no-op instead of an error — which is the whole point of sending the key.
99
+ */
100
+ export declare function OpenPaymentIntent(request: OpenIntentRequest, provider: IMetadataProvider, user: UserInfo): Promise<OpenIntentResult>;
101
+ //# sourceMappingURL=PaymentIntentService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PaymentIntentService.d.ts","sourceRoot":"","sources":["../src/PaymentIntentService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,OAAO,EAKH,KAAK,iBAAiB,EAEtB,KAAK,QAAQ,EAChB,MAAM,sBAAsB,CAAC;AAK9B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAIjE,kDAAkD;AAClD,MAAM,WAAW,iBAAiB;IAC9B,0FAA0F;IAC1F,iBAAiB,EAAE,MAAM,CAAC;IAC1B,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,8EAA8E;IAC9E,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,iFAAiF;IACjF,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,mGAAmG;IACnG,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,qBAAqB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,gBAAgB;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,2CAA2C;IAC3C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,qFAAqF;IACrF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+FAA+F;IAC/F,WAAW,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,iBAAiB,CACnC,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,EAAE,iBAAiB,EAC3B,IAAI,EAAE,QAAQ,GACf,OAAO,CAAC,gBAAgB,CAAC,CA4E3B"}
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Opening a payment intent — the front half of a gateway-collected payment.
3
+ *
4
+ * WHY THIS EXISTS. Every driver has implemented `CreateIntent` since the payment seam landed, and
5
+ * until now NOTHING CALLED IT except unit tests. `PaymentHeaderEntityServer.settleWithProvider`
6
+ * refuses a provider-backed capture without one — *"names a payment provider but no provider intent,
7
+ * so there is nothing for the gateway to capture. Open an intent first"* — and there was no way to
8
+ * open one. The gateway path was complete at both ends and had no beginning. This is the beginning.
9
+ *
10
+ * ═══ WHY AN INTENT IS ITS OWN ROW AND NOT A STATUS ON `PaymentHeader` ═══
11
+ *
12
+ * Three reasons, and all three are ordinary for a bank debit rather than edge cases:
13
+ *
14
+ * RETRIES ARE 1:N. Insufficient funds is the commonest ACH failure, so a second attempt is the
15
+ * normal path. Each attempt is its own intent at the gateway with its own id. As a column you would
16
+ * either lose the first attempt's id on overwrite, or mint a `PaymentHeader` per attempt — putting
17
+ * rows for money that never moved into the payment series and into AR.
18
+ *
19
+ * AN INTENT CAN EXIST WITH NO PAYMENT. A customer opens a hosted checkout and walks away. There is
20
+ * no cash, no allocation, nothing to record as a payment — and `DecideSettlement` already answers
21
+ * for exactly that case ("the intent has no payment to settle"). A status column cannot represent a
22
+ * payment that does not exist.
23
+ *
24
+ * `ProviderEventID` IS THE WEBHOOK IDEMPOTENCY KEY AND IT LIVES HERE. Events can arrive before a
25
+ * header exists, or for an intent that never produces one. On the header, the key would not exist
26
+ * until the header did.
27
+ *
28
+ * There is also a lifecycle mismatch: a `Captured` header is frozen, while an intent churns through
29
+ * `Processing → Succeeded`. And the two vocabularies are genuinely different — ours is cash-shaped
30
+ * (`Pending|Captured|Failed|…`), the gateway's is attempt-shaped.
31
+ *
32
+ * THE CLIENT SECRET IS RETURNED AND NEVER STORED. It authorises the browser to confirm this intent;
33
+ * persisting it would put a bearer credential in a table that reporting reads. `BasePaymentProvider`
34
+ * says "Never logged" for the same reason, and the row below deliberately has no column for it.
35
+ *
36
+ * THIS DOES NOT CREATE A PAYMENT. Opening an intent is asking the gateway to stand ready; no money
37
+ * has moved and nothing is owed differently because of it. `Orders.CapturePayment` writes the
38
+ * `PaymentHeader` and links it to the intent by id.
39
+ *
40
+ * CONNECTS TO:
41
+ * DRIVER: ./BasePaymentProvider.ts → CreateIntent
42
+ * LOOKUP: ./PaymentProviderResolver.ts
43
+ * CAPTURE: ./CapturePaymentOperation.ts — takes the returned PaymentIntentID
44
+ * SETTLE: ./PaymentSettlement.ts — moves the payment when the gateway answers
45
+ * DOC: plans/archive/bizapps-orders-master.md D19, D37, D80
46
+ */
47
+ import { LogError, LogStatus, RunView, } from '@memberjunction/core';
48
+ import { ResolvePaymentProvider } from './PaymentProviderResolver.js';
49
+ const PAYMENT_INTENT_ENTITY = 'MJ_BizApps_Orders: Payment Intents';
50
+ /**
51
+ * Ask the gateway to stand ready, and record that we did.
52
+ *
53
+ * REFUSALS COME BACK IN THE RESULT; only faults throw. A gateway declining to open an intent is a
54
+ * normal outcome of asking — the same contract every driver follows — while an unresolvable provider
55
+ * or a database that will not accept the row is a fault the caller cannot act on.
56
+ *
57
+ * THE DEDUP IS NOT BELT-AND-BRACES. `ProviderIntentID` is UNIQUE, and a gateway given a repeated
58
+ * idempotency key returns the SAME intent rather than a new one. So a retried call reaches us with an
59
+ * id we already hold, and inserting would violate the constraint. Finding and returning the existing
60
+ * row makes the retry a no-op instead of an error — which is the whole point of sending the key.
61
+ */
62
+ export async function OpenPaymentIntent(request, provider, user) {
63
+ if (!Number.isFinite(request?.Amount) || request.Amount <= 0) {
64
+ return { Success: false, Reason: `Cannot open a payment intent for ${request?.Amount}.` };
65
+ }
66
+ if (!request?.PaymentProviderID) {
67
+ return { Success: false, Reason: 'A payment intent needs a PaymentProviderID — it decides which gateway to ask.' };
68
+ }
69
+ const driver = await ResolvePaymentProvider(request.PaymentProviderID, provider, user);
70
+ const opened = await driver.CreateIntent({
71
+ Amount: request.Amount,
72
+ CurrencyCode: request.CurrencyCode,
73
+ OrderHeaderID: request.OrderHeaderID ?? null,
74
+ BillToPersonID: request.BillToPersonID ?? null,
75
+ BillToOrganizationID: request.BillToOrganizationID ?? null,
76
+ ProviderCustomerRef: request.ProviderCustomerRef ?? null,
77
+ ProviderInstrumentRef: request.ProviderInstrumentRef ?? null,
78
+ Metadata: request.Metadata,
79
+ IdempotencyKey: request.IdempotencyKey ?? undefined,
80
+ });
81
+ if (!opened.Success || !opened.ProviderIntentID) {
82
+ return { Success: false, Reason: opened.Reason ?? 'The gateway did not open a payment intent.' };
83
+ }
84
+ const existing = await findByProviderIntentID(opened.ProviderIntentID, provider, user);
85
+ if (existing) {
86
+ LogStatus(`Payment intent ${opened.ProviderIntentID} was already open; reusing row ${existing}.`);
87
+ return {
88
+ Success: true,
89
+ WasExisting: true,
90
+ PaymentIntentID: existing,
91
+ ProviderIntentID: opened.ProviderIntentID,
92
+ Status: opened.Status,
93
+ // Still returned: a caller retrying a checkout needs the secret to confirm the intent, and
94
+ // it is not ours to withhold merely because the row predates this call.
95
+ ClientSecret: opened.ClientSecret,
96
+ HostedUrl: opened.HostedUrl,
97
+ };
98
+ }
99
+ const row = await provider.GetEntityObject(PAYMENT_INTENT_ENTITY, user);
100
+ row.NewRecord();
101
+ row.PaymentProviderID = request.PaymentProviderID;
102
+ row.ProviderIntentID = opened.ProviderIntentID;
103
+ // The gateway's reading, already mapped to our CHECK vocabulary by the driver. Defaulted to
104
+ // Processing rather than to a confident value — the same rule `MapStripeIntentStatus` follows.
105
+ row.Status = opened.Status ?? 'Processing';
106
+ row.Amount = Math.round(request.Amount * 100) / 100;
107
+ if (request.OrderHeaderID)
108
+ row.OrderHeaderID = request.OrderHeaderID;
109
+ if (request.BillToPersonID)
110
+ row.BillToPersonID = request.BillToPersonID;
111
+ if (request.BillToOrganizationID)
112
+ row.BillToOrganizationID = request.BillToOrganizationID;
113
+ if (!(await row.Save())) {
114
+ // A FAULT. The gateway has an open intent and we failed to record it, which means a webhook
115
+ // about real money will arrive for an intent this application cannot recognise. Throwing puts
116
+ // that in front of somebody rather than returning a refusal the caller might retry — and a
117
+ // retry would open a second intent unless an idempotency key was supplied.
118
+ const reason = row.LatestResult?.CompleteMessage ?? 'unknown error';
119
+ LogError(`Opened gateway intent ${opened.ProviderIntentID} but could not record it: ${reason}. ` +
120
+ `A webhook for this intent will not match any payment.`);
121
+ throw new Error(`Could not record payment intent ${opened.ProviderIntentID}: ${reason}`);
122
+ }
123
+ return {
124
+ Success: true,
125
+ WasExisting: false,
126
+ PaymentIntentID: row.ID,
127
+ ProviderIntentID: opened.ProviderIntentID,
128
+ Status: opened.Status,
129
+ ClientSecret: opened.ClientSecret,
130
+ HostedUrl: opened.HostedUrl,
131
+ };
132
+ }
133
+ /** Our row for a gateway intent id, if we already hold one. */
134
+ async function findByProviderIntentID(providerIntentID, provider, user) {
135
+ const rv = new RunView(provider);
136
+ // Escaped rather than interpolated raw. The value came from our own driver rather than from a
137
+ // caller, so it is not attacker-controlled — but "ours" and "safe to concatenate into SQL" are
138
+ // different claims, and only one of them is being made here.
139
+ const safe = providerIntentID.replace(/'/g, "''");
140
+ const result = await rv.RunView({
141
+ EntityName: PAYMENT_INTENT_ENTITY,
142
+ ExtraFilter: `ProviderIntentID = '${safe}'`,
143
+ Fields: ['ID'],
144
+ ResultType: 'simple',
145
+ // The row may have been written moments ago by the call this one is retrying.
146
+ BypassCache: true,
147
+ }, user);
148
+ return result?.Results?.[0]?.ID ?? null;
149
+ }
150
+ //# sourceMappingURL=PaymentIntentService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PaymentIntentService.js","sourceRoot":"","sources":["../src/PaymentIntentService.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,OAAO,EAEH,QAAQ,EACR,SAAS,EACT,OAAO,GAIV,MAAM,sBAAsB,CAAC;AAI9B,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAGtE,MAAM,qBAAqB,GAAG,oCAAoC,CAAC;AA2CnE;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACnC,OAA0B,EAC1B,QAA2B,EAC3B,IAAc;IAEd,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;QAC3D,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,oCAAoC,OAAO,EAAE,MAAM,GAAG,EAA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,MAAM,IAAI,KAAK,CAAC,mCAAmC,MAAM,CAAC,gBAAgB,KAAK,MAAM,EAAE,CAAC,CAAC;IAC7F,CAAC;IAED,OAAO;QACH,OAAO,EAAE,IAAI;QACb,WAAW,EAAE,KAAK;QAClB,eAAe,EAAE,GAAG,CAAC,EAAE;QACvB,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;QACzC,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,SAAS,EAAE,MAAM,CAAC,SAAS;KAC9B,CAAC;AACN,CAAC;AAED,+DAA+D;AAC/D,KAAK,UAAU,sBAAsB,CACjC,gBAAwB,EACxB,QAA2B,EAC3B,IAAc;IAEd,MAAM,EAAE,GAAG,IAAI,OAAO,CAAC,QAAuC,CAAC,CAAC;IAChE,8FAA8F;IAC9F,+FAA+F;IAC/F,6DAA6D;IAC7D,MAAM,IAAI,GAAG,gBAAgB,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,OAAO,CAC3B;QACI,UAAU,EAAE,qBAAqB;QACjC,WAAW,EAAE,uBAAuB,IAAI,GAAG;QAC3C,MAAM,EAAE,CAAC,IAAI,CAAC;QACd,UAAU,EAAE,QAAQ;QACpB,8EAA8E;QAC9E,WAAW,EAAE,IAAI;KACpB,EACD,IAAI,CACP,CAAC;IACF,OAAO,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,IAAI,IAAI,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Payment-side journal entries — the PROCESSING FEE at capture (plan D18).
3
+ *
4
+ * WHAT THIS BOOKS, AND WHAT IT NO LONGER BOOKS
5
+ * This class used to book the whole cash leg at capture: `Dr Cash / Dr Fee / Cr AR`. That was
6
+ * wrong the moment an order carried a second company's product, because it credited the RECEIVING
7
+ * company's receivable for money that company was never owed (D13, intercompany-balancing.md §1).
8
+ *
9
+ * The AR/Cash side moved to `PaymentAllocationFactory`, driven by `PaymentLine`, because
10
+ * ALLOCATION is the earliest point at which the owning companies are known at all. A capture says
11
+ * how much cash arrived; only an allocation says whose revenue it settles.
12
+ *
13
+ * What remains here is the part that genuinely IS a header fact:
14
+ *
15
+ * Dr Processing Fee the provider's cut
16
+ * Cr Cash the provider never deposited it
17
+ *
18
+ * The fee is incurred when the processor takes it, against the payment as a whole — it does not
19
+ * belong to any one order, and pro-rating it across allocations would invent a precision that the
20
+ * underlying fact does not have. Booking it separately also keeps the customer's debt clearing for
21
+ * the FULL amount they paid: a fee netted against AR would leave a permanent residue on their
22
+ * balance that no payment could ever clear.
23
+ *
24
+ * FEES ARE OPTIONAL BY DESIGN. There is no seeded `Processing Fee` GL role — accounting ships
25
+ * eight roles and that is not one of them. When it does not resolve, NOTHING is booked here and
26
+ * the shortfall is reported, rather than being folded into a line that would misstate the bank
27
+ * position.
28
+ *
29
+ * REVERSALS mirror — same accounts, debit and credit swapped, positive amounts (D53). Refunds and
30
+ * chargebacks are the same entry read backwards, never a negative-amount entry.
31
+ *
32
+ * CONNECTS TO:
33
+ * ALLOCATION: PaymentAllocationFactory (./PaymentAllocationFactory.ts) — the AR/Cash side
34
+ * RESOLVER: GLAccountResolver (./GLAccountResolver.ts)
35
+ * CALLER: PaymentHeaderEntityServer (./PaymentHeaderEntityServer.ts)
36
+ * OP: 'Accounting.CreateJournalEntries' — the same op order booking uses
37
+ */
38
+ import { type GLAccountResolver } from './GLAccountResolver.js';
39
+ /** One ledger line of the capture entry. */
40
+ export interface PaymentJELine {
41
+ GLAccountID: string;
42
+ DebitAmount?: number;
43
+ CreditAmount?: number;
44
+ Description: string;
45
+ }
46
+ export interface PaymentJEDraft {
47
+ EffectiveDate: string;
48
+ EntryType: string;
49
+ Description: string;
50
+ LinkedEntityID: string;
51
+ LinkedRecordID: string;
52
+ Lines: PaymentJELine[];
53
+ }
54
+ export interface PaymentCaptureContext {
55
+ PaymentID: string;
56
+ PaymentNumber: string;
57
+ /** Where the cash lands — the receivable being cleared belongs to this company. */
58
+ CompanyID: string;
59
+ /** Gross: what the customer paid. */
60
+ Amount: number;
61
+ /** The provider's cut, if any. Booked separately when a Processing Fee account resolves. */
62
+ ProcessingFeeAmount: number;
63
+ PaymentDate: Date;
64
+ /** True when this reverses an earlier capture — the same entry, mirrored. */
65
+ IsReversal: boolean;
66
+ }
67
+ export interface PaymentCaptureResult {
68
+ /**
69
+ * The fee entry, or null when there is no fee — or when there IS one but no Processing Fee
70
+ * account resolves. Null means "book nothing", never "book something approximate".
71
+ */
72
+ Draft: PaymentJEDraft | null;
73
+ /**
74
+ * Set when a fee was present but no Processing Fee account could be resolved. Surfaced rather
75
+ * than swallowed: the cash line elsewhere is then gross, so the bank position is overstated by
76
+ * this much and someone needs to know.
77
+ */
78
+ UnbookedFeeAmount?: number;
79
+ }
80
+ export declare class PaymentJournalEntryFactory {
81
+ private readonly _resolver;
82
+ private readonly _paymentEntityID;
83
+ constructor(_resolver: GLAccountResolver, _paymentEntityID: string);
84
+ /**
85
+ * Build the fee entry for a payment, or null when there is nothing to book.
86
+ *
87
+ * Amounts are always positive; `IsReversal` decides the direction. The caller owns the
88
+ * transaction and the write — this computes only.
89
+ */
90
+ BuildCaptureDraft(ctx: PaymentCaptureContext): Promise<PaymentCaptureResult>;
91
+ /**
92
+ * A local balance check before the draft leaves this class.
93
+ *
94
+ * Accounting validates too, but its rejection arrives as a batch of `MALFORMED_DRAFT` strings
95
+ * from inside a remote operation. Failing here names the payment and the amounts.
96
+ */
97
+ private assertBalanced;
98
+ }
99
+ //# sourceMappingURL=PaymentJournalEntryFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PaymentJournalEntryFactory.d.ts","sourceRoot":"","sources":["../src/PaymentJournalEntryFactory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,EAAW,KAAK,iB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E at capture (plan D18).
3
+ *
4
+ * WHAT THIS BOOKS, AND WHAT IT NO LONGER BOOKS
5
+ * This class used to book the whole cash leg at capture: `Dr Cash / Dr Fee / Cr AR`. That was
6
+ * wrong the moment an order carried a second company's product, because it credited the RECEIVING
7
+ * company's receivable for money that company was never owed (D13, intercompany-balancing.md §1).
8
+ *
9
+ * The AR/Cash side moved to `PaymentAllocationFactory`, driven by `PaymentLine`, because
10
+ * ALLOCATION is the earliest point at which the owning companies are known at all. A capture says
11
+ * how much cash arrived; only an allocation says whose revenue it settles.
12
+ *
13
+ * What remains here is the part that genuinely IS a header fact:
14
+ *
15
+ * Dr Processing Fee the provider's cut
16
+ * Cr Cash the provider never deposited it
17
+ *
18
+ * The fee is incurred when the processor takes it, against the payment as a whole — it does not
19
+ * belong to any one order, and pro-rating it across allocations would invent a precision that the
20
+ * underlying fact does not have. Booking it separately also keeps the customer's debt clearing for
21
+ * the FULL amount they paid: a fee netted against AR would leave a permanent residue on their
22
+ * balance that no payment could ever clear.
23
+ *
24
+ * FEES ARE OPTIONAL BY DESIGN. There is no seeded `Processing Fee` GL role — accounting ships
25
+ * eight roles and that is not one of them. When it does not resolve, NOTHING is booked here and
26
+ * the shortfall is reported, rather than being folded into a line that would misstate the bank
27
+ * position.
28
+ *
29
+ * REVERSALS mirror — same accounts, debit and credit swapped, positive amounts (D53). Refunds and
30
+ * chargebacks are the same entry read backwards, never a negative-amount entry.
31
+ *
32
+ * CONNECTS TO:
33
+ * ALLOCATION: PaymentAllocationFactory (./PaymentAllocationFactory.ts) — the AR/Cash side
34
+ * RESOLVER: GLAccountResolver (./GLAccountResolver.ts)
35
+ * CALLER: PaymentHeaderEntityServer (./PaymentHeaderEntityServer.ts)
36
+ * OP: 'Accounting.CreateJournalEntries' — the same op order booking uses
37
+ */
38
+ import { GL_ROLE } from './GLAccountResolver.js';
39
+ function money(v) {
40
+ return Math.round((v + Number.EPSILON) * 100) / 100;
41
+ }
42
+ const isoDate = (d) => new Date(d).toISOString().slice(0, 10);
43
+ /** Swap debit and credit — see D53; reversal is mirroring, never negation. */
44
+ function mirrorIf(reverse, lines) {
45
+ if (!reverse)
46
+ return lines;
47
+ return lines.map((l) => ({ ...l, DebitAmount: l.CreditAmount, CreditAmount: l.DebitAmount }));
48
+ }
49
+ export class PaymentJournalEntryFactory {
50
+ constructor(_resolver, _paymentEntityID) {
51
+ this._resolver = _resolver;
52
+ this._paymentEntityID = _paymentEntityID;
53
+ }
54
+ /**
55
+ * Build the fee entry for a payment, or null when there is nothing to book.
56
+ *
57
+ * Amounts are always positive; `IsReversal` decides the direction. The caller owns the
58
+ * transaction and the write — this computes only.
59
+ */
60
+ async BuildCaptureDraft(ctx) {
61
+ const gross = money(Math.abs(ctx.Amount));
62
+ if (gross <= 0) {
63
+ throw new Error(`Payment ${ctx.PaymentNumber} has an amount of ${ctx.Amount}, so there is nothing to book. ` +
64
+ `A zero-amount payment should not reach capture.`);
65
+ }
66
+ const fee = money(Math.abs(ctx.ProcessingFeeAmount ?? 0));
67
+ if (fee <= 0)
68
+ return { Draft: null };
69
+ const asOf = new Date(ctx.PaymentDate);
70
+ let feeAccount;
71
+ try {
72
+ feeAccount = await this._resolver.Resolve(GL_ROLE.ProcessingFee, null, null, ctx.CompanyID, asOf);
73
+ }
74
+ catch {
75
+ // No Processing Fee role/account configured — see the header. Book nothing and report.
76
+ return { Draft: null, UnbookedFeeAmount: fee };
77
+ }
78
+ // Payments are company-level: there is no product to walk from, so the company default is
79
+ // both the start and the end of the resolution (D12).
80
+ const cashAccount = await this._resolver.Resolve(GL_ROLE.Cash, null, null, ctx.CompanyID, asOf);
81
+ const label = ctx.IsReversal ? 'Refund' : 'Payment';
82
+ const lines = [
83
+ {
84
+ GLAccountID: feeAccount,
85
+ DebitAmount: fee,
86
+ Description: `${label} ${ctx.PaymentNumber} — processing fee`,
87
+ },
88
+ {
89
+ // The processor kept this; it never reached the bank.
90
+ GLAccountID: cashAccount,
91
+ CreditAmount: fee,
92
+ Description: `${label} ${ctx.PaymentNumber} — fee withheld from deposit`,
93
+ },
94
+ ];
95
+ const finalLines = mirrorIf(ctx.IsReversal, lines);
96
+ this.assertBalanced(finalLines, ctx);
97
+ return {
98
+ Draft: {
99
+ EffectiveDate: isoDate(ctx.PaymentDate),
100
+ // Accounting's own vocabulary — 'PaymentReceipt' and 'Refund' are two of the
101
+ // seventeen values its CHECK constraint allows. Inventing 'PaymentCapture' was
102
+ // rejected at the draft gate, correctly: the entry type is accounting's taxonomy to
103
+ // define, not ours to extend from the orders side.
104
+ EntryType: ctx.IsReversal ? 'Refund' : 'PaymentReceipt',
105
+ Description: `${label} ${ctx.PaymentNumber} — processing fee`,
106
+ LinkedEntityID: this._paymentEntityID,
107
+ LinkedRecordID: ctx.PaymentID,
108
+ Lines: finalLines,
109
+ },
110
+ };
111
+ }
112
+ /**
113
+ * A local balance check before the draft leaves this class.
114
+ *
115
+ * Accounting validates too, but its rejection arrives as a batch of `MALFORMED_DRAFT` strings
116
+ * from inside a remote operation. Failing here names the payment and the amounts.
117
+ */
118
+ assertBalanced(lines, ctx) {
119
+ const debits = money(lines.reduce((s, l) => s + (l.DebitAmount ?? 0), 0));
120
+ const credits = money(lines.reduce((s, l) => s + (l.CreditAmount ?? 0), 0));
121
+ if (debits !== credits) {
122
+ throw new Error(`The capture entry for payment ${ctx.PaymentNumber} does not balance: ` +
123
+ `debits ${debits} vs credits ${credits}. Gross ${ctx.Amount}, fee ${ctx.ProcessingFeeAmount}.`);
124
+ }
125
+ }
126
+ }
127
+ //# sourceMappingURL=PaymentJournalEntryFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PaymentJournalEntryFactory.js","sourceRoot":"","sources":["../src/PaymentJournalEntryFactory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,EAAE,OAAO,EAA0B,MAAM,wBAAwB,CAAC;AA+CzE,SAAS,KAAK,CAAC,CAAS;IACpB,OAAO,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;gBAC/E,oFAAoF;gBACpF,mDAAmD;gBACnD,SAAS,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,gBAAgB;gBACvD,WAAW,EAAE,GAAG,KAAK,IAAI,GAAG,CAAC,aAAa,mBAAmB;gBAC7D,cAAc,EAAE,IAAI,CAAC,gBAAgB;gBACrC,cAAc,EAAE,GAAG,CAAC,SAAS;gBAC7B,KAAK,EAAE,UAAU;aACpB;SACJ,CAAC;IACN,CAAC;IAED;;;;;OAKG;IACK,cAAc,CAAC,KAAsB,EAAE,GAA0B;QACrE,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC1E,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC5E,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CACX,iCAAiC,GAAG,CAAC,aAAa,qBAAqB;gBACnE,UAAU,MAAM,eAAe,OAAO,WAAW,GAAG,CAAC,MAAM,SAAS,GAAG,CAAC,mBAAmB,GAAG,CACrG,CAAC;QACN,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * PaymentLine server subclass — the cash-application guard (plan D18/D41) AND the cash leg (D13).
3
+ *
4
+ * `PaymentLine` is the junction that says "this much of that payment settles this order". The only
5
+ * protection it had was `CHECK (Amount <> 0)`, so nothing stopped applying $500 against a $100
6
+ * order. The rollup triggers would dutifully compute `Balance = -400` and `PaymentStatus = 'Paid'`,
7
+ * and the customer would appear to be owed money the ledger has no record of.
8
+ *
9
+ * ONE RULE HERE (D68 revised the other away)
10
+ * A negative application (un-apply, or spending a credit) may not push the order's applied total
11
+ * BELOW zero. Un-applying more than was ever applied is always a mistake.
12
+ *
13
+ * THERE IS DELIBERATELY NO CEILING. An earlier version refused any application that pushed the
14
+ * order's applied total above its gross, on the reasoning that an over-payment should be recorded
15
+ * "deliberately" as a credit memo. That was wrong, and it made the honest case unrecordable: a
16
+ * customer who sends 1000 for a 900 order has done nothing unusual, and the money is in the bank
17
+ * whether or not the schema likes it. Over-applying now simply drives the order's balance negative,
18
+ * and a negative balance IS the credit — spendable on another order via the Account Credit tender.
19
+ *
20
+ * WHAT GUARDS THE PAYMENT INSTEAD: `PaymentHeaderEntityServer` requires a captured payment's Amount
21
+ * to equal the sum of its lines (D68). That is a payment-side sum, so it belongs on the payment —
22
+ * and being an equality rather than a ceiling, it makes over-allocating a payment impossible by
23
+ * construction rather than by a second check.
24
+ *
25
+ * ── THE CASH LEG MOVED HERE (2026-07-26, D13 payment half) ──────────────────────────────────
26
+ * It used to live on `PaymentHeader` capture, which booked `Dr Cash / Cr AR` against the RECEIVING
27
+ * company and nothing else. That was wrong the moment an order carried another company's product:
28
+ * the collector's receivable was credited for money it was never owed, and the owner's receivable
29
+ * stayed open forever — balanced, posted, and invisible.
30
+ *
31
+ * ALLOCATION is the earliest point the companies are even KNOWN. A capture says how much cash
32
+ * arrived; only the allocation says whose revenue it settles. So the entries belong here, one per
33
+ * company owning a line on the order (plans/archive/intercompany-balancing.md §2).
34
+ *
35
+ * `BookedAt` is the idempotency key rather than a `JournalEntryID`, because one allocation produces
36
+ * N entries. They are found the other way round, through accounting's D25 provenance pair.
37
+ *
38
+ * CONNECTS TO:
39
+ * FACTORY: PaymentAllocationFactory (./PaymentAllocationFactory.ts)
40
+ * LOOKUP: AccountingEngineBase.ResolveIntercompanyAccounts (BA-D26)
41
+ * TRIGGERS: trg_PaymentLine_RollupTotals → spRecalcOrderHeaderTotals (D41)
42
+ * TABLE: __mj_BizAppsOrders.PaymentLine
43
+ */
44
+ import { EntitySaveOptions, ValidationResult } from '@memberjunction/core';
45
+ import { mjBizAppsOrdersPaymentLineEntity } from '@mj-biz-apps/orders-entities';
46
+ export declare class PaymentLineEntityServer extends mjBizAppsOrdersPaymentLineEntity {
47
+ /**
48
+ * The applied-total check runs in `Save`, not `Validate`, because it needs to read sibling rows
49
+ * — `Validate()` is synchronous by contract, and a guard that cannot see the other applications
50
+ * is not a guard.
51
+ */
52
+ Save(options?: EntitySaveOptions): Promise<boolean>;
53
+ /**
54
+ * Book one journal entry per company owning a line on the order this allocation settles.
55
+ *
56
+ * Single-company orders produce exactly one entry — the shape the ledger had before — so this
57
+ * is a generalisation of the old behaviour rather than a parallel path.
58
+ */
59
+ private bookAllocation;
60
+ /** The payment this allocation belongs to, or null when it cannot be read. */
61
+ private loadPayment;
62
+ /** Every line of the order, with the company that owns it — the pro-rating basis. */
63
+ private loadOrderLines;
64
+ private loadOrderNumber;
65
+ private createJournalEntries;
66
+ Validate(): ValidationResult;
67
+ /** Returns a message when this application would take the order out of range, else null. */
68
+ private checkApplicationTotal;
69
+ private buildRejection;
70
+ }
71
+ /** Tree-shaking anchor — the guard lives in Save, reachable only via the registration. */
72
+ export declare function LoadPaymentLineEntityServer(): void;
73
+ //# sourceMappingURL=PaymentLineEntityServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PaymentLineEntityServer.d.ts","sourceRoot":"","sources":["../src/PaymentLineEntityServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,OAAO,EAKH,iBAAiB,EAQjB,gBAAgB,EACnB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,gCAAgC,EAAE,MAAM,8BAA8B,CAAC;AA6BhF,qBACa,uBAAwB,SAAQ,gCAAgC;IACzE;;;;OAIG;IACmB,IAAI,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC;IAiDzE;;;;;OAKG;YACW,cAAc;IAsD5B,8EAA8E;YAChE,WAAW;IA4BzB,qFAAqF;YACvE,cAAc;YAyBd,eAAe;YAef,oBAAoB;IA+BlB,QAAQ,IAAI,gBAAgB;IAgB5C,4FAA4F;YAC9E,qBAAqB;IAuDnC,OAAO,CAAC,cAAc;CAWzB;AAED,0FAA0F;AAC1F,wBAAgB,2BAA2B,IAAI,IAAI,CAElD"}