@sixtyninecommerce/admin 0.10.0 → 0.12.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 (302) hide show
  1. package/README.md +5772 -118
  2. package/dist/auth/index.d.ts +7 -1
  3. package/dist/auth/index.js +8 -1
  4. package/dist/catalog/assets.d.ts +120 -8
  5. package/dist/catalog/assets.js +98 -12
  6. package/dist/catalog/collections.d.ts +279 -14
  7. package/dist/catalog/collections.js +246 -15
  8. package/dist/catalog/documents.d.ts +142 -0
  9. package/dist/catalog/documents.js +114 -0
  10. package/dist/catalog/index.d.ts +54 -6
  11. package/dist/catalog/index.js +10 -1
  12. package/dist/catalog/metadata.d.ts +244 -0
  13. package/dist/catalog/metadata.js +220 -0
  14. package/dist/catalog/products.d.ts +159 -19
  15. package/dist/catalog/products.js +88 -13
  16. package/dist/catalog/properties.d.ts +140 -14
  17. package/dist/catalog/properties.js +65 -1
  18. package/dist/catalog/recommendations.d.ts +288 -0
  19. package/dist/catalog/recommendations.js +237 -0
  20. package/dist/catalog/reviews.d.ts +381 -0
  21. package/dist/catalog/reviews.js +325 -0
  22. package/dist/catalog/types.d.ts +17 -1
  23. package/dist/catalog/types.js +10 -0
  24. package/dist/catalog/variant-find.d.ts +136 -0
  25. package/dist/catalog/variant-find.js +239 -0
  26. package/dist/catalog/variants.d.ts +293 -26
  27. package/dist/catalog/variants.js +164 -7
  28. package/dist/catalog/visibility.d.ts +38 -7
  29. package/dist/catalog/visibility.js +19 -1
  30. package/dist/client.d.ts +121 -9
  31. package/dist/client.js +53 -14
  32. package/dist/content/assets.d.ts +285 -0
  33. package/dist/content/assets.js +181 -0
  34. package/dist/content/forms.d.ts +332 -1
  35. package/dist/content/forms.js +140 -4
  36. package/dist/content/items.d.ts +292 -0
  37. package/dist/content/items.js +170 -0
  38. package/dist/content/menus.d.ts +254 -0
  39. package/dist/content/menus.js +70 -0
  40. package/dist/content/strings.d.ts +137 -0
  41. package/dist/content/strings.js +82 -0
  42. package/dist/content/types.d.ts +282 -0
  43. package/dist/content/types.js +100 -0
  44. package/dist/customers/age-verification.d.ts +66 -0
  45. package/dist/customers/age-verification.js +79 -0
  46. package/dist/customers/credit.d.ts +263 -0
  47. package/dist/customers/credit.js +244 -0
  48. package/dist/customers/delivery-preferences.d.ts +120 -0
  49. package/dist/customers/delivery-preferences.js +97 -0
  50. package/dist/customers/delivery-terms.d.ts +44 -0
  51. package/dist/customers/delivery-terms.js +32 -0
  52. package/dist/customers/groups.d.ts +207 -0
  53. package/dist/customers/groups.js +438 -0
  54. package/dist/customers/index.d.ts +462 -37
  55. package/dist/customers/index.js +317 -40
  56. package/dist/customers/invitation-status.d.ts +57 -0
  57. package/dist/customers/invitation-status.js +21 -0
  58. package/dist/customers/notes.d.ts +67 -0
  59. package/dist/customers/notes.js +51 -0
  60. package/dist/customers/notification-recipients.d.ts +97 -0
  61. package/dist/customers/notification-recipients.js +84 -0
  62. package/dist/customers/saved-lists.d.ts +42 -0
  63. package/dist/customers/saved-lists.js +61 -0
  64. package/dist/customers/vat.d.ts +83 -0
  65. package/dist/customers/vat.js +46 -0
  66. package/dist/customers/wire.d.ts +20 -0
  67. package/dist/customers/wire.js +35 -0
  68. package/dist/documents/ar.d.ts +307 -0
  69. package/dist/documents/ar.js +254 -0
  70. package/dist/documents/emails.d.ts +150 -0
  71. package/dist/documents/emails.js +220 -0
  72. package/dist/documents/index.d.ts +744 -21
  73. package/dist/documents/index.js +438 -24
  74. package/dist/documents/pdf.d.ts +2 -0
  75. package/dist/documents/pdf.js +11 -0
  76. package/dist/fulfillments/create.d.ts +167 -0
  77. package/dist/fulfillments/create.js +216 -0
  78. package/dist/fulfillments/index.d.ts +163 -11
  79. package/dist/fulfillments/index.js +135 -6
  80. package/dist/fulfillments/payment-policy.d.ts +64 -0
  81. package/dist/fulfillments/payment-policy.js +140 -0
  82. package/dist/fulfillments/warehouse.d.ts +724 -0
  83. package/dist/fulfillments/warehouse.js +914 -0
  84. package/dist/geo/index.d.ts +119 -0
  85. package/dist/geo/index.js +107 -0
  86. package/dist/index.d.ts +147 -39
  87. package/dist/index.js +51 -12
  88. package/dist/integrations/afas-actions.d.ts +234 -0
  89. package/dist/integrations/afas-actions.js +310 -0
  90. package/dist/integrations/afas-types.d.ts +483 -0
  91. package/dist/integrations/afas-types.js +5 -0
  92. package/dist/integrations/afas.d.ts +234 -0
  93. package/dist/integrations/afas.js +290 -0
  94. package/dist/integrations/connections.d.ts +103 -0
  95. package/dist/integrations/connections.js +55 -0
  96. package/dist/integrations/esp.d.ts +313 -0
  97. package/dist/integrations/esp.js +169 -0
  98. package/dist/integrations/exact-online-types.d.ts +965 -0
  99. package/dist/integrations/exact-online-types.js +6 -0
  100. package/dist/integrations/exact-online.d.ts +784 -0
  101. package/dist/integrations/exact-online.js +1089 -0
  102. package/dist/integrations/index.d.ts +44 -3
  103. package/dist/integrations/index.js +23 -3
  104. package/dist/integrations/pipeline-discoveries.d.ts +65 -0
  105. package/dist/integrations/pipeline-discoveries.js +65 -0
  106. package/dist/integrations/pipeline-keys.d.ts +13 -0
  107. package/dist/integrations/pipeline-keys.js +22 -0
  108. package/dist/integrations/pipeline-runs.d.ts +119 -0
  109. package/dist/integrations/pipeline-runs.js +87 -0
  110. package/dist/integrations/pipelines.d.ts +87 -15
  111. package/dist/integrations/pipelines.js +41 -22
  112. package/dist/integrations/price-import.d.ts +223 -0
  113. package/dist/integrations/price-import.js +124 -0
  114. package/dist/integrations/types.d.ts +367 -3
  115. package/dist/integrations/types.js +4 -3
  116. package/dist/locations/index.d.ts +66 -0
  117. package/dist/locations/index.js +31 -0
  118. package/dist/meta/index.d.ts +172 -0
  119. package/dist/metafields/index.d.ts +8 -1
  120. package/dist/metafields/index.js +10 -0
  121. package/dist/orders/cancel-with-money.d.ts +237 -0
  122. package/dist/orders/cancel-with-money.js +155 -0
  123. package/dist/orders/commit-edit.d.ts +23 -1
  124. package/dist/orders/commit-edit.js +19 -2
  125. package/dist/orders/deposit-policy.d.ts +3 -1
  126. package/dist/orders/drafts.d.ts +800 -0
  127. package/dist/orders/drafts.js +771 -0
  128. package/dist/orders/fields.d.ts +245 -0
  129. package/dist/orders/fields.js +188 -0
  130. package/dist/orders/get.d.ts +29 -19
  131. package/dist/orders/get.js +17 -8
  132. package/dist/orders/index.d.ts +66 -15
  133. package/dist/orders/index.js +25 -2
  134. package/dist/orders/lifecycle.d.ts +128 -0
  135. package/dist/orders/lifecycle.js +158 -0
  136. package/dist/orders/line-price-preview.d.ts +7 -2
  137. package/dist/orders/list.d.ts +243 -0
  138. package/dist/orders/list.js +487 -0
  139. package/dist/orders/manual-discounts.d.ts +13 -5
  140. package/dist/orders/manual-pricing.d.ts +5 -0
  141. package/dist/orders/money-view.d.ts +149 -0
  142. package/dist/orders/money-view.js +99 -0
  143. package/dist/orders/order-entry.d.ts +20 -7
  144. package/dist/orders/plan-edit.d.ts +34 -2
  145. package/dist/orders/plan-edit.js +112 -11
  146. package/dist/orders/settings.d.ts +201 -0
  147. package/dist/orders/settings.js +325 -0
  148. package/dist/orders/status.d.ts +159 -13
  149. package/dist/orders/status.js +21 -0
  150. package/dist/orders/surcharges.d.ts +20 -1
  151. package/dist/orders/surcharges.js +37 -11
  152. package/dist/payments/account-credit.d.ts +46 -0
  153. package/dist/payments/account-credit.js +42 -0
  154. package/dist/payments/ar.d.ts +292 -0
  155. package/dist/payments/ar.js +223 -0
  156. package/dist/payments/connected-account.d.ts +47 -0
  157. package/dist/payments/connected-account.js +61 -0
  158. package/dist/payments/credit-noted-fields.d.ts +19 -0
  159. package/dist/payments/credit-noted-fields.js +69 -0
  160. package/dist/payments/customer-consent.d.ts +30 -0
  161. package/dist/payments/customer-consent.js +49 -0
  162. package/dist/payments/index.d.ts +340 -19
  163. package/dist/payments/index.js +151 -1
  164. package/dist/payments/methods.d.ts +303 -8
  165. package/dist/payments/methods.js +337 -7
  166. package/dist/payments/mollie-methods.d.ts +159 -0
  167. package/dist/payments/mollie-methods.js +141 -0
  168. package/dist/payments/payment-links.d.ts +180 -0
  169. package/dist/payments/payment-links.js +97 -0
  170. package/dist/payments/provider-keys.d.ts +150 -0
  171. package/dist/payments/provider-keys.js +118 -0
  172. package/dist/payments/providers.d.ts +86 -11
  173. package/dist/payments/providers.js +29 -0
  174. package/dist/payments/requests.d.ts +147 -0
  175. package/dist/payments/requests.js +93 -0
  176. package/dist/payments/store-credit-fields.d.ts +15 -0
  177. package/dist/payments/store-credit-fields.js +51 -0
  178. package/dist/pickups/index.d.ts +106 -0
  179. package/dist/pickups/index.js +108 -0
  180. package/dist/platform/channels.d.ts +132 -0
  181. package/dist/platform/channels.js +128 -0
  182. package/dist/platform/email-gateways.d.ts +165 -0
  183. package/dist/platform/email-gateways.js +78 -0
  184. package/dist/platform/geo.d.ts +123 -0
  185. package/dist/platform/geo.js +144 -0
  186. package/dist/platform/tax.d.ts +162 -0
  187. package/dist/platform/tax.js +169 -0
  188. package/dist/pos/anomalies.d.ts +158 -0
  189. package/dist/pos/anomalies.js +64 -0
  190. package/dist/pos/assisted-selling.d.ts +79 -0
  191. package/dist/pos/assisted-selling.js +38 -0
  192. package/dist/pos/exchanges.d.ts +108 -0
  193. package/dist/pos/exchanges.js +22 -0
  194. package/dist/pos/gift-cards.d.ts +135 -0
  195. package/dist/pos/gift-cards.js +47 -0
  196. package/dist/pos/index.d.ts +2370 -58
  197. package/dist/pos/index.js +854 -7
  198. package/dist/pos/no-receipt.d.ts +94 -0
  199. package/dist/pos/no-receipt.js +25 -0
  200. package/dist/pos/offline-sales.d.ts +228 -0
  201. package/dist/pos/offline-sales.js +170 -0
  202. package/dist/pos/pay-by-link.d.ts +143 -0
  203. package/dist/pos/pay-by-link.js +57 -0
  204. package/dist/pos/quick-keys.d.ts +103 -0
  205. package/dist/pos/quick-keys.js +45 -0
  206. package/dist/pos/reports.d.ts +360 -0
  207. package/dist/pos/reports.js +62 -0
  208. package/dist/pos/returns.d.ts +244 -0
  209. package/dist/pos/returns.js +83 -0
  210. package/dist/pricing/bulk-coupons.d.ts +139 -0
  211. package/dist/pricing/bulk-coupons.js +112 -0
  212. package/dist/pricing/index.d.ts +174 -4
  213. package/dist/pricing/index.js +174 -1
  214. package/dist/pricing/price-lists.d.ts +606 -0
  215. package/dist/pricing/price-lists.js +600 -0
  216. package/dist/purchasing/alerts.d.ts +104 -0
  217. package/dist/purchasing/alerts.js +88 -0
  218. package/dist/purchasing/backorders.d.ts +61 -0
  219. package/dist/purchasing/backorders.js +92 -0
  220. package/dist/purchasing/cost.d.ts +110 -0
  221. package/dist/purchasing/cost.js +86 -0
  222. package/dist/purchasing/index.d.ts +54 -0
  223. package/dist/purchasing/index.js +24 -0
  224. package/dist/purchasing/links.d.ts +263 -0
  225. package/dist/purchasing/links.js +192 -0
  226. package/dist/purchasing/purchase-orders.d.ts +551 -0
  227. package/dist/purchasing/purchase-orders.js +491 -0
  228. package/dist/purchasing/receipts.d.ts +396 -0
  229. package/dist/purchasing/receipts.js +287 -0
  230. package/dist/purchasing/replenishment.d.ts +281 -0
  231. package/dist/purchasing/replenishment.js +240 -0
  232. package/dist/purchasing/returns.d.ts +273 -0
  233. package/dist/purchasing/returns.js +229 -0
  234. package/dist/purchasing/settings.d.ts +152 -0
  235. package/dist/purchasing/settings.js +181 -0
  236. package/dist/purchasing/suppliers.d.ts +476 -0
  237. package/dist/purchasing/suppliers.js +438 -0
  238. package/dist/quotes/index.d.ts +518 -0
  239. package/dist/quotes/index.js +439 -0
  240. package/dist/reports/index.d.ts +71 -8
  241. package/dist/reports/index.js +74 -11
  242. package/dist/returns/index.d.ts +675 -21
  243. package/dist/returns/index.js +756 -11
  244. package/dist/search/index.d.ts +76 -1
  245. package/dist/search/index.js +63 -0
  246. package/dist/seo/config.d.ts +128 -0
  247. package/dist/seo/config.js +95 -0
  248. package/dist/seo/redirects.d.ts +125 -0
  249. package/dist/seo/redirects.js +60 -1
  250. package/dist/seo/settings.d.ts +147 -0
  251. package/dist/seo/settings.js +209 -0
  252. package/dist/shipping/definitions.d.ts +29 -0
  253. package/dist/shipping/definitions.js +47 -0
  254. package/dist/shipping/fulfillment-profiles.d.ts +174 -0
  255. package/dist/shipping/fulfillment-profiles.js +104 -0
  256. package/dist/shipping/hendriks.d.ts +97 -0
  257. package/dist/shipping/hendriks.js +50 -0
  258. package/dist/shipping/index.d.ts +54 -0
  259. package/dist/shipping/index.js +27 -0
  260. package/dist/shipping/methods.d.ts +205 -0
  261. package/dist/shipping/methods.js +240 -0
  262. package/dist/shipping/myparcel.d.ts +668 -0
  263. package/dist/shipping/myparcel.js +466 -0
  264. package/dist/shipping/parcel-count-suggestion.d.ts +2 -0
  265. package/dist/shipping/parcel-rule.d.ts +6 -5
  266. package/dist/shipping/parcel-rule.js +21 -23
  267. package/dist/shipping/rate-tables.d.ts +324 -0
  268. package/dist/shipping/rate-tables.js +390 -0
  269. package/dist/shipping/ship-to-countries.d.ts +75 -0
  270. package/dist/shipping/ship-to-countries.js +47 -0
  271. package/dist/stock/by-location.d.ts +86 -0
  272. package/dist/stock/by-location.js +94 -0
  273. package/dist/stock/index.d.ts +18 -4
  274. package/dist/stock/index.js +7 -0
  275. package/dist/stock/locations.d.ts +144 -0
  276. package/dist/stock/locations.js +168 -0
  277. package/dist/stock/settings.d.ts +106 -0
  278. package/dist/stock/settings.js +103 -0
  279. package/dist/stock/transfers.d.ts +386 -52
  280. package/dist/stock/transfers.js +222 -17
  281. package/dist/stored-value/index.d.ts +312 -11
  282. package/dist/stored-value/index.js +223 -4
  283. package/dist/subscriptions/index.d.ts +682 -0
  284. package/dist/subscriptions/index.js +815 -0
  285. package/dist/tax/display-policy.d.ts +105 -0
  286. package/dist/tax/display-policy.js +84 -0
  287. package/dist/tax/index.d.ts +79 -1
  288. package/dist/tax/index.js +52 -0
  289. package/dist/tenant/email-style.d.ts +102 -0
  290. package/dist/tenant/email-style.js +72 -0
  291. package/dist/tenant/email-templates.d.ts +287 -0
  292. package/dist/tenant/email-templates.js +271 -0
  293. package/dist/tenant/notifications.d.ts +23 -17
  294. package/dist/tenant/settings-sources.d.ts +1 -1
  295. package/dist/tenant/time-zone.d.ts +17 -0
  296. package/dist/tenant/time-zone.js +11 -0
  297. package/dist/types.d.ts +50 -3
  298. package/dist/users/index.d.ts +3 -0
  299. package/dist/users/index.js +2 -0
  300. package/dist/users/warehouses.d.ts +50 -0
  301. package/dist/users/warehouses.js +51 -0
  302. package/package.json +2 -2
@@ -53,6 +53,15 @@ export interface SurchargeRemoveCall extends Call {
53
53
  * either (`ORDER_OVERPAYMENT_REFUND_UNRECONCILED`) until it is reconciled.
54
54
  */
55
55
  overpayment?: OrderOverpaymentChoice;
56
+ /**
57
+ * With `ACCOUNT_CREDIT` in a store whose book is store credit (`preview`'s
58
+ * `accountCredit.book` `STORE_CREDIT`): whether the customer expressly agreed to store credit
59
+ * instead of a refund to their payment (EU consumer law, CRD art. 13(1)), as staff recorded it.
60
+ * The move records it on its ledger entries (`StoredValueEntry.customerAgreed`); never a
61
+ * condition, nothing is refused for it, and it is recorded nowhere else. Sent only when given;
62
+ * an engine before the field (incentives sprint 8 PR 6a) refuses a call that gives it.
63
+ */
64
+ customerAgreed?: boolean;
56
65
  }
57
66
  /** Options for a surcharge write. */
58
67
  export interface SurchargeCall extends SurchargeRemoveCall {
@@ -133,6 +142,13 @@ export interface OverpaymentOption {
133
142
  available: boolean;
134
143
  code: string | null;
135
144
  message: string | null;
145
+ /**
146
+ * On an `accountCredit` option: where "credit the customer" lands in this store, its ONE
147
+ * customer-credit book. `AR` (unapplied cash on the AR ledger), `STORE_CREDIT` (the customer's
148
+ * store-credit wallet) or `NONE` (neither: the option is closed). Null on the other options and
149
+ * from an engine before it.
150
+ */
151
+ book?: string | null;
136
152
  }
137
153
  /** What a surcharge change would do to an order's money. Nothing was saved. */
138
154
  export interface SurchargeChangePreview {
@@ -190,5 +206,8 @@ export declare const UPDATE_ORDER_SURCHARGE_MUTATION = "\n mutation UpdateOrder
190
206
  export declare const UPDATE_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION = "\n mutation UpdateOrderSurchargeWithOverpayment(\n $orderId: ID!\n $surchargeId: ID!\n $input: SurchargeInput!\n $taxClass: String\n $idempotencyKey: String\n $overpayment: OrderOverpaymentChoice\n ) {\n updateOrderSurcharge(\n orderId: $orderId\n surchargeId: $surchargeId\n input: $input\n taxClass: $taxClass\n idempotencyKey: $idempotencyKey\n overpayment: $overpayment\n ) {\n \n id\n code\n currencyCode\n total\n totalWithTax\n surcharges {\n id\n description\n sku\n price\n priceWithTax\n taxRate\n }\n\n }\n }\n";
191
207
  export declare const REMOVE_ORDER_SURCHARGE_MUTATION = "\n mutation RemoveOrderSurcharge($orderId: ID!, $surchargeId: ID!, $idempotencyKey: String) {\n removeOrderSurcharge(\n orderId: $orderId\n surchargeId: $surchargeId\n idempotencyKey: $idempotencyKey\n ) {\n \n id\n code\n currencyCode\n total\n totalWithTax\n surcharges {\n id\n description\n sku\n price\n priceWithTax\n taxRate\n }\n\n }\n }\n";
192
208
  export declare const REMOVE_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION = "\n mutation RemoveOrderSurchargeWithOverpayment(\n $orderId: ID!\n $surchargeId: ID!\n $idempotencyKey: String\n $overpayment: OrderOverpaymentChoice\n ) {\n removeOrderSurcharge(\n orderId: $orderId\n surchargeId: $surchargeId\n idempotencyKey: $idempotencyKey\n overpayment: $overpayment\n ) {\n \n id\n code\n currencyCode\n total\n totalWithTax\n surcharges {\n id\n description\n sku\n price\n priceWithTax\n taxRate\n }\n\n }\n }\n";
193
- export declare const PREVIEW_ORDER_SURCHARGE_CHANGE_QUERY = "\n query PreviewOrderSurchargeChange($orderId: ID!, $change: OrderSurchargeChangeInput!) {\n previewOrderSurchargeChange(orderId: $orderId, change: $change) {\n currencyCode\n totalBefore\n totalAfter\n overpayment {\n amount\n currencyCode\n refund { available code message }\n accountCredit { available code message }\n }\n }\n }\n";
209
+ export declare const ADD_ORDER_SURCHARGE_WITH_CONSENT_MUTATION: string;
210
+ export declare const UPDATE_ORDER_SURCHARGE_WITH_CONSENT_MUTATION: string;
211
+ export declare const REMOVE_ORDER_SURCHARGE_WITH_CONSENT_MUTATION: string;
212
+ export declare const PREVIEW_ORDER_SURCHARGE_CHANGE_QUERY = "\n query PreviewOrderSurchargeChange($orderId: ID!, $change: OrderSurchargeChangeInput!) {\n previewOrderSurchargeChange(orderId: $orderId, change: $change) {\n currencyCode\n totalBefore\n totalAfter\n overpayment {\n amount\n currencyCode\n refund { available code message book }\n accountCredit { available code message book }\n }\n }\n }\n";
194
213
  export declare function createSurchargesModule(transport: Transport): SurchargesModule;
@@ -1,3 +1,5 @@
1
+ import { customerAgreedVariable, withCustomerAgreed } from '../payments/customer-consent.js';
2
+ import { storeCreditAware } from '../payments/store-credit-fields.js';
1
3
  const SURCHARGED_ORDER_FIELDS = /* GraphQL */ `
2
4
  id
3
5
  code
@@ -120,7 +122,16 @@ export const REMOVE_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION = /* GraphQL */ `
120
122
  }
121
123
  }
122
124
  `;
123
- const OVERPAYMENT_OPTION_FIELDS = 'available code message';
125
+ // A third document per write, used only on a call that states the customer's answer to store
126
+ // credit: an engine before the argument still takes every call that does not.
127
+ const CONSENT_ANCHOR = {
128
+ declaration: '$overpayment: OrderOverpaymentChoice',
129
+ argument: 'overpayment: $overpayment',
130
+ };
131
+ export const ADD_ORDER_SURCHARGE_WITH_CONSENT_MUTATION = withCustomerAgreed(ADD_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION, CONSENT_ANCHOR);
132
+ export const UPDATE_ORDER_SURCHARGE_WITH_CONSENT_MUTATION = withCustomerAgreed(UPDATE_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION, CONSENT_ANCHOR);
133
+ export const REMOVE_ORDER_SURCHARGE_WITH_CONSENT_MUTATION = withCustomerAgreed(REMOVE_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION, CONSENT_ANCHOR);
134
+ const OVERPAYMENT_OPTION_FIELDS = 'available code message book';
124
135
  export const PREVIEW_ORDER_SURCHARGE_CHANGE_QUERY = /* GraphQL */ `
125
136
  query PreviewOrderSurchargeChange($orderId: ID!, $change: OrderSurchargeChangeInput!) {
126
137
  previewOrderSurchargeChange(orderId: $orderId, change: $change) {
@@ -141,6 +152,12 @@ function overpaymentVariable(options) {
141
152
  const value = options?.overpayment;
142
153
  return value === 'REFUND' || value === 'ACCOUNT_CREDIT' ? value : undefined;
143
154
  }
155
+ /** The document a write sends: the plainest one that declares every argument the call states. */
156
+ function surchargeDocument(options, documents) {
157
+ if (customerAgreedVariable(options?.customerAgreed) !== undefined)
158
+ return documents.consent;
159
+ return overpaymentVariable(options) === undefined ? documents.plain : documents.overpayment;
160
+ }
144
161
  /**
145
162
  * `undefined` rather than `null` for an absent tax class: a variable explicitly
146
163
  * set to null is still a value the engine reads, and this argument's whole
@@ -155,15 +172,18 @@ export function createSurchargesModule(transport) {
155
172
  async add(orderId, input, options) {
156
173
  const data = await transport.graphql({
157
174
  api: 'admin',
158
- query: overpaymentVariable(options) === undefined
159
- ? ADD_ORDER_SURCHARGE_MUTATION
160
- : ADD_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION,
175
+ query: surchargeDocument(options, {
176
+ plain: ADD_ORDER_SURCHARGE_MUTATION,
177
+ overpayment: ADD_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION,
178
+ consent: ADD_ORDER_SURCHARGE_WITH_CONSENT_MUTATION,
179
+ }),
161
180
  variables: {
162
181
  orderId,
163
182
  input,
164
183
  taxClass: taxClassVariable(options),
165
184
  idempotencyKey: options?.idempotencyKey,
166
185
  overpayment: overpaymentVariable(options),
186
+ customerAgreed: customerAgreedVariable(options?.customerAgreed),
167
187
  },
168
188
  }, options);
169
189
  return data.addOrderSurcharge;
@@ -171,9 +191,11 @@ export function createSurchargesModule(transport) {
171
191
  async update(orderId, surchargeId, input, options) {
172
192
  const data = await transport.graphql({
173
193
  api: 'admin',
174
- query: overpaymentVariable(options) === undefined
175
- ? UPDATE_ORDER_SURCHARGE_MUTATION
176
- : UPDATE_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION,
194
+ query: surchargeDocument(options, {
195
+ plain: UPDATE_ORDER_SURCHARGE_MUTATION,
196
+ overpayment: UPDATE_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION,
197
+ consent: UPDATE_ORDER_SURCHARGE_WITH_CONSENT_MUTATION,
198
+ }),
177
199
  variables: {
178
200
  orderId,
179
201
  surchargeId,
@@ -181,6 +203,7 @@ export function createSurchargesModule(transport) {
181
203
  taxClass: taxClassVariable(options),
182
204
  idempotencyKey: options?.idempotencyKey,
183
205
  overpayment: overpaymentVariable(options),
206
+ customerAgreed: customerAgreedVariable(options?.customerAgreed),
184
207
  },
185
208
  }, options);
186
209
  return data.updateOrderSurcharge;
@@ -188,21 +211,24 @@ export function createSurchargesModule(transport) {
188
211
  async remove(orderId, surchargeId, options) {
189
212
  const data = await transport.graphql({
190
213
  api: 'admin',
191
- query: overpaymentVariable(options) === undefined
192
- ? REMOVE_ORDER_SURCHARGE_MUTATION
193
- : REMOVE_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION,
214
+ query: surchargeDocument(options, {
215
+ plain: REMOVE_ORDER_SURCHARGE_MUTATION,
216
+ overpayment: REMOVE_ORDER_SURCHARGE_WITH_OVERPAYMENT_MUTATION,
217
+ consent: REMOVE_ORDER_SURCHARGE_WITH_CONSENT_MUTATION,
218
+ }),
194
219
  variables: {
195
220
  orderId,
196
221
  surchargeId,
197
222
  idempotencyKey: options?.idempotencyKey,
198
223
  overpayment: overpaymentVariable(options),
224
+ customerAgreed: customerAgreedVariable(options?.customerAgreed),
199
225
  },
200
226
  }, options);
201
227
  return data.removeOrderSurcharge;
202
228
  },
203
229
  async preview(orderId, change, options) {
204
230
  const taxClass = taxClassVariable(options);
205
- const data = await transport.graphql({
231
+ const data = await storeCreditAware(transport).graphql({
206
232
  api: 'admin',
207
233
  query: PREVIEW_ORDER_SURCHARGE_CHANGE_QUERY,
208
234
  variables: {
@@ -33,6 +33,19 @@ export interface UnappliedCash {
33
33
  /** ISO-8601 with offset. */
34
34
  createdAt: string;
35
35
  }
36
+ /**
37
+ * Money of an order's settled payments moved to the customer's store-credit wallet instead of a
38
+ * refund: one never-expiring ledger entry per payment it came from. Minor units of
39
+ * `currencyCode`, the order's own currency.
40
+ */
41
+ export interface StoreCreditMove {
42
+ /** The customer's store-credit wallet (a stored-value account of kind `store_credit`). */
43
+ accountId: string;
44
+ amount: number;
45
+ currencyCode: string;
46
+ /** The ledger entries, one per payment the money came from. */
47
+ entryIds: string[];
48
+ }
36
49
  export interface CreditOverpaymentInput {
37
50
  orderId: string;
38
51
  /**
@@ -43,6 +56,17 @@ export interface CreditOverpaymentInput {
43
56
  /** Why, in your own words: shown on the receipt and in the order's history. */
44
57
  reason?: string;
45
58
  }
59
+ /** Options of {@link AccountCreditModule.creditOverpaymentToStoreCredit}. */
60
+ export interface CreditOverpaymentToStoreCreditCall extends Call {
61
+ /**
62
+ * Whether the customer expressly agreed to store credit instead of a refund to their payment
63
+ * (EU consumer law, CRD art. 13(1)), as staff recorded it: the move records it on its ledger
64
+ * entries (`StoredValueEntry.customerAgreed`). Never a condition, nothing is refused for it.
65
+ * Part of the request: a repeat under the same key sends the same answer. Sent only when given;
66
+ * an engine before the argument (incentives sprint 8 PR 6a) refuses a call that gives it.
67
+ */
68
+ customerAgreed?: boolean;
69
+ }
46
70
  export interface ApplyUnappliedCashInput {
47
71
  unappliedCashId: string;
48
72
  /** The AR invoice to pay. Give exactly one of `invoiceId` and `orderId`. */
@@ -123,6 +147,22 @@ export interface AccountCreditModule {
123
147
  * account refusals above.
124
148
  */
125
149
  creditOverpayment(input: CreditOverpaymentInput, options?: Call): Promise<UnappliedCash[]>;
150
+ /**
151
+ * The store-credit sibling of {@link creditOverpayment}, for a store whose customer-credit book
152
+ * is store credit (`storedValue.storeCreditSettings`): what the order holds over its bill moves
153
+ * to the customer's store-credit wallet, in the order's currency, one ledger entry per payment
154
+ * it came from. Same bounds and `ACCOUNT_CREDIT_*` refusals; an AR store is refused
155
+ * `STORE_CREDIT_STORE_KEEPS_ACCOUNTS` (use {@link creditOverpayment} there), a store without
156
+ * store credit `STORE_CREDIT_NOT_ENABLED` / `_NOT_GRANTED` / `_METHOD_REQUIRED`. A gift card's or
157
+ * store credit's payment is never moved (`STORE_CREDIT_STORED_VALUE_REFUND_INSTEAD`: refund it),
158
+ * and the customer must be reachable (`STORE_CREDIT_CUSTOMER_ANONYMOUS`,
159
+ * `STORED_VALUE_ACCOUNT_BLOCKED`). The overpayment is what the order's payments hold over what
160
+ * it BILLS, the larger of its total and its live invoices', as a plain refund of an invoiced order
161
+ * measures it. From then on that money is no longer the order's: `payments.refundPosition` takes
162
+ * it off `refundable` and `payments.position` no longer reports it as `overpaid`. Needs an
163
+ * engine with incentives sprint 8 PR 3.
164
+ */
165
+ creditOverpaymentToStoreCredit(input: CreditOverpaymentInput, options?: CreditOverpaymentToStoreCreditCall): Promise<StoreCreditMove>;
126
166
  /** A customer's unapplied cash in this store, oldest first. */
127
167
  list(customerId: string, options?: Call): Promise<UnappliedCash[]>;
128
168
  /**
@@ -159,6 +199,12 @@ export interface AccountCreditModule {
159
199
  onOrder(orderId: string, options?: Call): Promise<OrderMoneyOnAccount>;
160
200
  }
161
201
  export declare const CREDIT_ORDER_OVERPAYMENT_MUTATION = "\n mutation CreditOrderOverpaymentToAccount(\n $input: CreditOrderOverpaymentInput!\n $idempotencyKey: String\n ) {\n creditOrderOverpaymentToAccount(input: $input, idempotencyKey: $idempotencyKey) {\n \n id\n customerId\n currencyCode\n amount\n applied\n refunded\n remaining\n orderId\n paymentId\n receivedOn\n reference\n notes\n createdAt\n\n }\n }\n";
202
+ export declare const CREDIT_ORDER_OVERPAYMENT_TO_STORE_CREDIT_MUTATION = "\n mutation CreditOrderOverpaymentToStoreCredit(\n $input: CreditOrderOverpaymentInput!\n $idempotencyKey: String\n ) {\n creditOrderOverpaymentToStoreCredit(input: $input, idempotencyKey: $idempotencyKey) {\n accountId amount currencyCode entryIds\n }\n }\n";
203
+ /**
204
+ * The same, declaring the customer's answer to store credit: sent only by a call that states it,
205
+ * so an engine before the argument still takes every call that does not.
206
+ */
207
+ export declare const CREDIT_ORDER_OVERPAYMENT_TO_STORE_CREDIT_WITH_CONSENT_MUTATION = "\n mutation CreditOrderOverpaymentToStoreCredit(\n $input: CreditOrderOverpaymentInput!\n $idempotencyKey: String\n $customerAgreed: Boolean\n ) {\n creditOrderOverpaymentToStoreCredit(\n input: $input\n idempotencyKey: $idempotencyKey\n customerAgreed: $customerAgreed\n ) {\n accountId amount currencyCode entryIds\n }\n }\n";
162
208
  export declare const UNAPPLIED_CASH_QUERY = "\n query ArUnappliedCash($customerId: ID!) {\n arUnappliedCash(customerId: $customerId) {\n \n id\n customerId\n currencyCode\n amount\n applied\n refunded\n remaining\n orderId\n paymentId\n receivedOn\n reference\n notes\n createdAt\n\n }\n }\n";
163
209
  export declare const APPLY_UNAPPLIED_CASH_MUTATION = "\n mutation ApplyArUnappliedCash($input: ApplyArUnappliedCashInput!, $idempotencyKey: String) {\n applyArUnappliedCash(input: $input, idempotencyKey: $idempotencyKey) {\n \n id\n customerId\n currencyCode\n amount\n applied\n refunded\n remaining\n orderId\n paymentId\n receivedOn\n reference\n notes\n createdAt\n\n }\n }\n";
164
210
  export declare const REFUND_UNAPPLIED_CASH_MUTATION = "\n mutation RefundArUnappliedCash($input: RefundArUnappliedCashInput!, $idempotencyKey: String) {\n refundArUnappliedCash(input: $input, idempotencyKey: $idempotencyKey) {\n id\n total\n state\n method\n transactionId\n reason\n }\n }\n";
@@ -1,3 +1,5 @@
1
+ import { customerAgreedVariable } from './customer-consent.js';
2
+ import { STORE_CREDIT_MOVE_FIELDS } from './store-credit-fields.js';
1
3
  const UNAPPLIED_CASH_FIELDS = /* GraphQL */ `
2
4
  id
3
5
  customerId
@@ -23,6 +25,35 @@ export const CREDIT_ORDER_OVERPAYMENT_MUTATION = /* GraphQL */ `
23
25
  }
24
26
  }
25
27
  `;
28
+ export const CREDIT_ORDER_OVERPAYMENT_TO_STORE_CREDIT_MUTATION = /* GraphQL */ `
29
+ mutation CreditOrderOverpaymentToStoreCredit(
30
+ $input: CreditOrderOverpaymentInput!
31
+ $idempotencyKey: String
32
+ ) {
33
+ creditOrderOverpaymentToStoreCredit(input: $input, idempotencyKey: $idempotencyKey) {
34
+ ${STORE_CREDIT_MOVE_FIELDS}
35
+ }
36
+ }
37
+ `;
38
+ /**
39
+ * The same, declaring the customer's answer to store credit: sent only by a call that states it,
40
+ * so an engine before the argument still takes every call that does not.
41
+ */
42
+ export const CREDIT_ORDER_OVERPAYMENT_TO_STORE_CREDIT_WITH_CONSENT_MUTATION = /* GraphQL */ `
43
+ mutation CreditOrderOverpaymentToStoreCredit(
44
+ $input: CreditOrderOverpaymentInput!
45
+ $idempotencyKey: String
46
+ $customerAgreed: Boolean
47
+ ) {
48
+ creditOrderOverpaymentToStoreCredit(
49
+ input: $input
50
+ idempotencyKey: $idempotencyKey
51
+ customerAgreed: $customerAgreed
52
+ ) {
53
+ ${STORE_CREDIT_MOVE_FIELDS}
54
+ }
55
+ }
56
+ `;
26
57
  export const UNAPPLIED_CASH_QUERY = /* GraphQL */ `
27
58
  query ArUnappliedCash($customerId: ID!) {
28
59
  arUnappliedCash(customerId: $customerId) {
@@ -79,6 +110,17 @@ export function createAccountCreditModule(transport) {
79
110
  }, options);
80
111
  return data.creditOrderOverpaymentToAccount;
81
112
  },
113
+ async creditOverpaymentToStoreCredit(input, options) {
114
+ const customerAgreed = customerAgreedVariable(options?.customerAgreed);
115
+ const data = await transport.graphql({
116
+ api: 'admin',
117
+ query: customerAgreed === undefined
118
+ ? CREDIT_ORDER_OVERPAYMENT_TO_STORE_CREDIT_MUTATION
119
+ : CREDIT_ORDER_OVERPAYMENT_TO_STORE_CREDIT_WITH_CONSENT_MUTATION,
120
+ variables: { input, idempotencyKey: options?.idempotencyKey, customerAgreed },
121
+ }, options);
122
+ return data.creditOrderOverpaymentToStoreCredit;
123
+ },
82
124
  async list(customerId, options) {
83
125
  const data = await transport.graphql({ api: 'admin', query: UNAPPLIED_CASH_QUERY, variables: { customerId } }, options);
84
126
  return data.arUnappliedCash;
@@ -0,0 +1,292 @@
1
+ import { type Page, type Transport } from '@sixtyninecommerce/core';
2
+ import type { Call, ListOptions } from '../types.js';
3
+ /**
4
+ * Money on the store's accounts-receivable ledger (`admin.payments.ar`, headless W10-30): the
5
+ * payments customers make against their AR invoices, the ledger itself, prepaid drawdowns, and
6
+ * collecting an invoice by SEPA direct debit. Unapplied cash (an order's overpayment kept on the
7
+ * account) is `payments.accountCredit`.
8
+ *
9
+ * Every write needs `UpdateOrder` and a store that keeps its AR ledger (else
10
+ * `AR_LEDGER_NOT_ENABLED`, → `BusinessRuleError`, 422); every read `ReadOrder`. A customer the
11
+ * store does not hold is `CUSTOMER_NOT_FOUND` (→ `NotFoundError`). Money is in integer minor units
12
+ * of the currency named beside it.
13
+ *
14
+ * **Keys.** `recordPayment`, `recordPrepaidDrawdown` and `directDebit.collectNow` take
15
+ * `options.idempotencyKey`: a repeat under the same key answers the first call's outcome instead
16
+ * of moving the money again; another request under the key is `IDEMPOTENCY_CONFLICT`
17
+ * (→ `ConflictError`, 409), one that arrives while the first still runs
18
+ * `IDEMPOTENCY_IN_PROGRESS`. **Without a key `recordPayment` is NOT de-duplicated**: a double
19
+ * submit records two payments. Use a fresh key per intended payment and reuse it only to retry
20
+ * that payment.
21
+ */
22
+ /** A customer payment received on the AR ledger, with what it settled. */
23
+ export interface ArPayment {
24
+ id: string;
25
+ customerId: string;
26
+ amount: number;
27
+ currencyCode: string;
28
+ /** `bank_transfer`, `cash`, `card`, `direct_debit` or `other`. */
29
+ method: string;
30
+ receivedOn: string;
31
+ reference: string | null;
32
+ notes: string | null;
33
+ allocations: Array<{
34
+ id: string;
35
+ invoiceId: string;
36
+ amount: number;
37
+ }>;
38
+ createdAt: string;
39
+ }
40
+ export type ArPaymentMethod = 'bank_transfer' | 'cash' | 'card' | 'direct_debit' | 'other';
41
+ export interface RecordArPaymentInput {
42
+ customerId: string;
43
+ /** Minor units of `currencyCode`, above zero. */
44
+ amount: number;
45
+ method: ArPaymentMethod;
46
+ /** `YYYY-MM-DD`; defaults to today in the store's zone. */
47
+ receivedOn?: string;
48
+ reference?: string;
49
+ notes?: string;
50
+ /** One the store sells in; defaults to the account's currency. It settles only invoices in it. */
51
+ currencyCode?: string;
52
+ /**
53
+ * Where the money goes, each at most what the invoice still owes. Omitted, it is allocated
54
+ * oldest invoice first and the rest stays on the account.
55
+ */
56
+ allocations?: Array<{
57
+ invoiceId: string;
58
+ amount: number;
59
+ }>;
60
+ }
61
+ /** One ledger posting. */
62
+ export interface ArLedgerEntry {
63
+ id: string;
64
+ /** `invoice_debit`, `payment_credit`, `credit_note_credit`, `prepaid_drawdown`, … */
65
+ entryType: string;
66
+ /** Signed minor units of `currencyCode`. */
67
+ amount: number;
68
+ currencyCode: string;
69
+ sourceType: string;
70
+ sourceId: string | null;
71
+ occurredOn: string;
72
+ metadata: Record<string, unknown> | null;
73
+ createdAt: string;
74
+ }
75
+ /** The drawdown already posted for an order. */
76
+ export interface ArOrderPrepaidDrawdown {
77
+ entryId: string;
78
+ orderId: string;
79
+ amount: number;
80
+ currencyCode: string;
81
+ occurredOn: string;
82
+ }
83
+ export interface ArPrepaidDrawdownResult {
84
+ entryId: string;
85
+ customerId: string;
86
+ amount: number;
87
+ currencyCode: string;
88
+ occurredOn: string;
89
+ /** The customer's signed balance after it, in `currencyCode` only. */
90
+ balanceAfter: number;
91
+ /** True when the order had been drawn down already: nothing new was posted. */
92
+ alreadyRecorded: boolean;
93
+ }
94
+ export interface RecordArPrepaidDrawdownInput {
95
+ orderId: string;
96
+ /** `YYYY-MM-DD`; defaults to today in the store's zone. */
97
+ occurredOn?: string;
98
+ }
99
+ /** A customer's SEPA direct debit set-up. */
100
+ export interface ArDirectDebitSettings {
101
+ customerId: string;
102
+ enabled: boolean;
103
+ /** Set: every collection is blocked until a person clears it. */
104
+ suspendedReason: string | null;
105
+ hasValidMandate: boolean;
106
+ mandateId: string | null;
107
+ providerMandateId: string | null;
108
+ /** False when the platform has no mandate provider at all. */
109
+ available: boolean;
110
+ }
111
+ export interface UpdateArDirectDebitSettingsInput {
112
+ enabled?: boolean;
113
+ /** Null lifts a suspension. */
114
+ suspendedReason?: string | null;
115
+ }
116
+ /** One attempt to collect an invoice by direct debit. */
117
+ export interface ArCollectionAttempt {
118
+ id: string;
119
+ invoiceId: string;
120
+ customerId: string;
121
+ attemptNumber: number;
122
+ amount: number;
123
+ currencyCode: string;
124
+ /** `pending`, `paid`, `failed`, `reversed` or `cancelled`. */
125
+ status: string;
126
+ provider: string;
127
+ providerPaymentId: string | null;
128
+ /** The SEPA R-code when the provider gave one (`AM04`, `MD06`, …). */
129
+ failureCode: string | null;
130
+ failureReason: string | null;
131
+ settledAt: string | null;
132
+ reversedAt: string | null;
133
+ orderSettlementState: string;
134
+ lastCheckedAt: string | null;
135
+ createdAt: string;
136
+ }
137
+ /** The recorded pre-notification and the wording the merchant must send the debtor. */
138
+ export interface ArPreNotification {
139
+ invoiceId: string;
140
+ /** The first day the collection may be taken. */
141
+ collectOn: string;
142
+ amount: number;
143
+ noticeTitle: string;
144
+ noticeBody: string;
145
+ }
146
+ /**
147
+ * What asking to collect an invoice now answered. A refusal is an ANSWER, not an error:
148
+ * `{ result: 'refused', refusal, message }` says why the invoice cannot be collected now (not
149
+ * pre-notified, no mandate, suspended, nothing outstanding, …), and nothing was asked of the
150
+ * bank. `declined`: the provider refused the charge at once. `already-in-flight`: a collection
151
+ * of the invoice is running; `attempt` is it.
152
+ */
153
+ export type ArCollectResult = {
154
+ result: 'charged' | 'declined' | 'already-in-flight';
155
+ refusal: null;
156
+ message: null;
157
+ attempt: ArCollectionAttempt;
158
+ } | {
159
+ result: 'refused';
160
+ refusal: string;
161
+ message: string;
162
+ attempt: null;
163
+ };
164
+ export interface ArDirectDebitModule {
165
+ /**
166
+ * A customer's direct debit settings and mandate state.
167
+ *
168
+ * @effect read
169
+ * @permission ReadOrder
170
+ */
171
+ settings(customerId: string, options?: Call): Promise<ArDirectDebitSettings>;
172
+ /**
173
+ * Turn direct debit on or off for a customer, or lift a suspension. Turning it on needs a valid
174
+ * SEPA mandate (`AR_DIRECT_DEBIT_MANDATE_REQUIRED`; an older engine answered
175
+ * `USER_INPUT_ERROR`). Moves no money.
176
+ *
177
+ * @effect write
178
+ * @permission UpdateOrder
179
+ */
180
+ update(customerId: string, input: UpdateArDirectDebitSettingsInput, options?: Call): Promise<ArDirectDebitSettings>;
181
+ /**
182
+ * Every collection attempt of one invoice, newest first (the last 50).
183
+ *
184
+ * @effect read
185
+ * @permission ReadOrder
186
+ */
187
+ attempts(invoiceId: string, options?: Call): Promise<ArCollectionAttempt[]>;
188
+ /**
189
+ * The newest attempt of each invoice named, in one call.
190
+ *
191
+ * @effect read
192
+ * @permission ReadOrder
193
+ */
194
+ latestAttempts(invoiceIds: string[], options?: Call): Promise<ArCollectionAttempt[]>;
195
+ /**
196
+ * Record that the debtor has been told the invoice will be collected, and get the exact
197
+ * wording to send them. It sends nothing itself: sending the notice is the merchant's legal
198
+ * duty, and recording it is what allows the collection. Run it again when the outstanding
199
+ * amount changes.
200
+ *
201
+ * Refused, coded (an older engine answered each `USER_INPUT_ERROR` with the same sentence):
202
+ * `AR_INVOICE_NOT_FOUND`, `AR_INVOICE_NOT_OPEN` (voided, or nothing outstanding),
203
+ * `AR_DIRECT_DEBIT_NOT_ENABLED`, `AR_DIRECT_DEBIT_SUSPENDED`, `AR_ACCOUNT_IN_ERP`,
204
+ * `AR_INVOICE_DIRECT_DEBIT_IN_FLIGHT`.
205
+ *
206
+ * @effect money
207
+ * @permission UpdateOrder
208
+ */
209
+ sendPreNotification(invoiceId: string, options?: Call): Promise<ArPreNotification>;
210
+ /**
211
+ * Collect a pre-notified invoice now, from the customer's SEPA mandate. A refusal is answered
212
+ * as `{ result: 'refused', refusal }`, NOT thrown (see {@link ArCollectResult}). Thrown:
213
+ * `AR_INVOICE_NOT_FOUND`, and `AR_DIRECT_DEBIT_UNAVAILABLE` (a platform fault, 500: the
214
+ * platform has no webhook address or charge provider for the collection; nothing is reserved).
215
+ *
216
+ * Pass `options.idempotencyKey`: a repeat under it answers the first outcome (the attempt as it
217
+ * is now). Once the provider was asked, a failure spends the key: a repeat answers
218
+ * `IDEMPOTENCY_OUTCOME_UNKNOWN` (`error.outcomeUnknown`) and asks the bank nothing; read
219
+ * {@link attempts} for what happened. The engine also keeps one live attempt per invoice
220
+ * whatever the key does.
221
+ *
222
+ * @effect money
223
+ * @permission UpdateOrder
224
+ */
225
+ collectNow(invoiceId: string, options?: Call): Promise<ArCollectResult>;
226
+ }
227
+ export interface ArPaymentsModule {
228
+ /**
229
+ * AR payments, newest first, one customer's or the store's, paged (`limit` up to 100).
230
+ *
231
+ * @effect read
232
+ * @permission ReadOrder
233
+ */
234
+ payments(options?: ListOptions & {
235
+ customerId?: string;
236
+ }): Promise<Page<ArPayment>>;
237
+ /**
238
+ * A customer's ledger postings, newest first, paged (`limit` up to 100).
239
+ *
240
+ * @effect read
241
+ * @permission ReadOrder
242
+ */
243
+ ledger(customerId: string, options?: ListOptions): Promise<Page<ArLedgerEntry>>;
244
+ /**
245
+ * Record a payment a customer made against their AR invoices: the receipt, its allocations and
246
+ * the ledger credit, in one transaction. **Pass `options.idempotencyKey`**: without one a
247
+ * repeat (a double click, a retry after a timeout) records a second payment. With one, the
248
+ * repeat answers the first payment as it is now.
249
+ *
250
+ * Refusals: `AR_LEDGER_NOT_ENABLED`, `CUSTOMER_NOT_FOUND`, `CURRENCY_NOT_AVAILABLE` (a currency
251
+ * the store does not sell in), `AR_CURRENCY_MISMATCH` (an allocation to an invoice in another
252
+ * currency), `AR_INVOICE_NOT_FOUND` (an allocation to an invoice not this customer's),
253
+ * `AR_INVOICE_NOT_OPEN` (to a voided one), `AR_ALLOCATION_EXCEEDS_OUTSTANDING` (more than the
254
+ * invoice still owes) and `AR_ALLOCATION_EXCEEDS_PAYMENT` (more than the payment), each a
255
+ * `USER_INPUT_ERROR` on an older engine; and a field refusal (`USER_INPUT_ERROR`) for an amount,
256
+ * a method or an allocation that is not one (a duplicate).
257
+ *
258
+ * @effect money
259
+ * @permission UpdateOrder
260
+ */
261
+ recordPayment(input: RecordArPaymentInput, options?: Call): Promise<ArPayment>;
262
+ /**
263
+ * The prepaid drawdown already posted for an order, or null.
264
+ *
265
+ * @effect read
266
+ * @permission ReadOrder
267
+ */
268
+ prepaidDrawdown(orderId: string, options?: Call): Promise<ArOrderPrepaidDrawdown | null>;
269
+ /**
270
+ * Draw a delivered order's gross total off the customer's prepaid credit. Once per order
271
+ * whatever happens (`alreadyRecorded` on a repeat without a key); with a key, a repeat answers
272
+ * the first result. Refused `ORDER_NOT_FOUND`, `AR_ORDER_HAS_NO_CUSTOMER` and
273
+ * `AR_ORDER_STATE_BLOCKS_DRAWDOWN` (each `USER_INPUT_ERROR` on an older engine).
274
+ *
275
+ * @effect money
276
+ * @permission UpdateOrder
277
+ */
278
+ recordPrepaidDrawdown(input: RecordArPrepaidDrawdownInput, options?: Call): Promise<ArPrepaidDrawdownResult>;
279
+ directDebit: ArDirectDebitModule;
280
+ }
281
+ export declare const AR_PAYMENTS_QUERY = "\n query ArPayments($options: ArListOptions) {\n arPayments(options: $options) {\n items { \n id\n customerId\n amount\n currencyCode\n method\n receivedOn\n reference\n notes\n allocations {\n id\n invoiceId\n amount\n }\n createdAt\n }\n totalItems\n }\n }\n";
282
+ export declare const AR_LEDGER_QUERY = "\n query ArLedgerEntries($customerId: ID!, $options: ArListOptions) {\n arLedgerEntries(customerId: $customerId, options: $options) {\n items {\n id\n entryType\n amount\n currencyCode\n sourceType\n sourceId\n occurredOn\n metadata\n createdAt\n }\n totalItems\n }\n }\n";
283
+ export declare const RECORD_AR_PAYMENT_MUTATION = "\n mutation RecordArPayment($input: RecordArPaymentInput!, $idempotencyKey: String) {\n recordArPayment(input: $input, idempotencyKey: $idempotencyKey) { \n id\n customerId\n amount\n currencyCode\n method\n receivedOn\n reference\n notes\n allocations {\n id\n invoiceId\n amount\n }\n createdAt\n }\n }\n";
284
+ export declare const AR_ORDER_PREPAID_DRAWDOWN_QUERY = "\n query ArOrderPrepaidDrawdown($orderId: ID!) {\n arOrderPrepaidDrawdown(orderId: $orderId) {\n entryId\n orderId\n amount\n currencyCode\n occurredOn\n }\n }\n";
285
+ export declare const RECORD_AR_PREPAID_DRAWDOWN_MUTATION = "\n mutation RecordArPrepaidDrawdown($input: RecordArPrepaidDrawdownInput!, $idempotencyKey: String) {\n recordArPrepaidDrawdown(input: $input, idempotencyKey: $idempotencyKey) {\n entryId\n customerId\n amount\n currencyCode\n occurredOn\n balanceAfter\n alreadyRecorded\n }\n }\n";
286
+ export declare const AR_DIRECT_DEBIT_SETTINGS_QUERY = "\n query ArDirectDebitSettings($customerId: ID!) {\n arDirectDebitSettings(customerId: $customerId) { \n customerId\n enabled\n suspendedReason\n hasValidMandate\n mandateId\n providerMandateId\n available\n }\n }\n";
287
+ export declare const UPDATE_AR_DIRECT_DEBIT_SETTINGS_MUTATION = "\n mutation UpdateArDirectDebitSettings($customerId: ID!, $input: UpdateArDirectDebitSettingsInput!) {\n updateArDirectDebitSettings(customerId: $customerId, input: $input) {\n \n customerId\n enabled\n suspendedReason\n hasValidMandate\n mandateId\n providerMandateId\n available\n\n }\n }\n";
288
+ export declare const AR_COLLECTION_ATTEMPTS_QUERY = "\n query ArCollectionAttempts($invoiceId: ID!) {\n arCollectionAttempts(invoiceId: $invoiceId) { \n id\n invoiceId\n customerId\n attemptNumber\n amount\n currencyCode\n status\n provider\n providerPaymentId\n failureCode\n failureReason\n settledAt\n reversedAt\n orderSettlementState\n lastCheckedAt\n createdAt\n }\n }\n";
289
+ export declare const AR_LATEST_COLLECTION_ATTEMPTS_QUERY = "\n query ArLatestCollectionAttempts($invoiceIds: [ID!]!) {\n arLatestCollectionAttempts(invoiceIds: $invoiceIds) { \n id\n invoiceId\n customerId\n attemptNumber\n amount\n currencyCode\n status\n provider\n providerPaymentId\n failureCode\n failureReason\n settledAt\n reversedAt\n orderSettlementState\n lastCheckedAt\n createdAt\n }\n }\n";
290
+ export declare const SEND_AR_PRE_NOTIFICATION_MUTATION = "\n mutation SendArDirectDebitPreNotification($invoiceId: ID!) {\n sendArDirectDebitPreNotification(invoiceId: $invoiceId) {\n invoiceId\n collectOn\n amount\n noticeTitle\n noticeBody\n }\n }\n";
291
+ export declare const COLLECT_AR_INVOICE_NOW_MUTATION = "\n mutation CollectArInvoiceNow($invoiceId: ID!, $idempotencyKey: String) {\n collectArInvoiceNow(invoiceId: $invoiceId, idempotencyKey: $idempotencyKey) {\n result\n refusal\n message\n attempt { \n id\n invoiceId\n customerId\n attemptNumber\n amount\n currencyCode\n status\n provider\n providerPaymentId\n failureCode\n failureReason\n settledAt\n reversedAt\n orderSettlementState\n lastCheckedAt\n createdAt\n }\n }\n }\n";
292
+ export declare function createArPaymentsModule(transport: Transport): ArPaymentsModule;