@cogenta/commerce 0.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 (98) hide show
  1. package/LICENSE +373 -0
  2. package/dist/admin/permissions.d.ts +57 -0
  3. package/dist/admin/permissions.d.ts.map +1 -0
  4. package/dist/admin/permissions.js +87 -0
  5. package/dist/admin/permissions.js.map +1 -0
  6. package/dist/admin/router.d.ts +53 -0
  7. package/dist/admin/router.d.ts.map +1 -0
  8. package/dist/admin/router.js +476 -0
  9. package/dist/admin/router.js.map +1 -0
  10. package/dist/cart/store.d.ts +91 -0
  11. package/dist/cart/store.d.ts.map +1 -0
  12. package/dist/cart/store.js +342 -0
  13. package/dist/cart/store.js.map +1 -0
  14. package/dist/cart/totals.d.ts +73 -0
  15. package/dist/cart/totals.d.ts.map +1 -0
  16. package/dist/cart/totals.js +65 -0
  17. package/dist/cart/totals.js.map +1 -0
  18. package/dist/catalog/store.d.ts +53 -0
  19. package/dist/catalog/store.d.ts.map +1 -0
  20. package/dist/catalog/store.js +358 -0
  21. package/dist/catalog/store.js.map +1 -0
  22. package/dist/catalog/types.d.ts +95 -0
  23. package/dist/catalog/types.d.ts.map +1 -0
  24. package/dist/catalog/types.js +5 -0
  25. package/dist/catalog/types.js.map +1 -0
  26. package/dist/coupon/store.d.ts +103 -0
  27. package/dist/coupon/store.d.ts.map +1 -0
  28. package/dist/coupon/store.js +181 -0
  29. package/dist/coupon/store.js.map +1 -0
  30. package/dist/customer/store.d.ts +41 -0
  31. package/dist/customer/store.d.ts.map +1 -0
  32. package/dist/customer/store.js +103 -0
  33. package/dist/customer/store.js.map +1 -0
  34. package/dist/index.d.ts +42 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +23 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/invoice/pdf.d.ts +67 -0
  39. package/dist/invoice/pdf.d.ts.map +1 -0
  40. package/dist/invoice/pdf.js +449 -0
  41. package/dist/invoice/pdf.js.map +1 -0
  42. package/dist/invoice/store.d.ts +96 -0
  43. package/dist/invoice/store.d.ts.map +1 -0
  44. package/dist/invoice/store.js +221 -0
  45. package/dist/invoice/store.js.map +1 -0
  46. package/dist/money.d.ts +55 -0
  47. package/dist/money.d.ts.map +1 -0
  48. package/dist/money.js +146 -0
  49. package/dist/money.js.map +1 -0
  50. package/dist/order/store.d.ts +75 -0
  51. package/dist/order/store.d.ts.map +1 -0
  52. package/dist/order/store.js +301 -0
  53. package/dist/order/store.js.map +1 -0
  54. package/dist/order/types.d.ts +67 -0
  55. package/dist/order/types.d.ts.map +1 -0
  56. package/dist/order/types.js +71 -0
  57. package/dist/order/types.js.map +1 -0
  58. package/dist/payment/manual.d.ts +27 -0
  59. package/dist/payment/manual.d.ts.map +1 -0
  60. package/dist/payment/manual.js +105 -0
  61. package/dist/payment/manual.js.map +1 -0
  62. package/dist/payment/registry.d.ts +23 -0
  63. package/dist/payment/registry.d.ts.map +1 -0
  64. package/dist/payment/registry.js +30 -0
  65. package/dist/payment/registry.js.map +1 -0
  66. package/dist/payment/store.d.ts +38 -0
  67. package/dist/payment/store.d.ts.map +1 -0
  68. package/dist/payment/store.js +253 -0
  69. package/dist/payment/store.js.map +1 -0
  70. package/dist/payment/stripe.d.ts +10 -0
  71. package/dist/payment/stripe.d.ts.map +1 -0
  72. package/dist/payment/stripe.js +419 -0
  73. package/dist/payment/stripe.js.map +1 -0
  74. package/dist/payment/types.d.ts +124 -0
  75. package/dist/payment/types.d.ts.map +1 -0
  76. package/dist/payment/types.js +18 -0
  77. package/dist/payment/types.js.map +1 -0
  78. package/dist/rows.d.ts +26 -0
  79. package/dist/rows.d.ts.map +1 -0
  80. package/dist/rows.js +87 -0
  81. package/dist/rows.js.map +1 -0
  82. package/dist/shipping/store.d.ts +88 -0
  83. package/dist/shipping/store.d.ts.map +1 -0
  84. package/dist/shipping/store.js +165 -0
  85. package/dist/shipping/store.js.map +1 -0
  86. package/dist/subscription/store.d.ts +106 -0
  87. package/dist/subscription/store.d.ts.map +1 -0
  88. package/dist/subscription/store.js +310 -0
  89. package/dist/subscription/store.js.map +1 -0
  90. package/dist/tables.d.ts +41 -0
  91. package/dist/tables.d.ts.map +1 -0
  92. package/dist/tables.js +383 -0
  93. package/dist/tables.js.map +1 -0
  94. package/dist/tax/store.d.ts +68 -0
  95. package/dist/tax/store.d.ts.map +1 -0
  96. package/dist/tax/store.js +126 -0
  97. package/dist/tax/store.js.map +1 -0
  98. package/package.json +42 -0
@@ -0,0 +1,30 @@
1
+ import { createDriverRegistry } from '@cogenta/core';
2
+ import { manualPaymentDriver } from './manual.js';
3
+ import { stripePaymentDriver } from './stripe.js';
4
+ /**
5
+ * The payment gateways Cogenta ships.
6
+ *
7
+ * Registered in tier order, exactly like cache, queue, storage and database:
8
+ * Stripe is `optimal` and answers only when a key is configured and the API
9
+ * responds; bank transfer is `degraded` and always answers. So a site with no
10
+ * Stripe account does not fail to start and does not fall over at checkout —
11
+ * it takes bank transfers, which is a real way to be paid, not a placeholder.
12
+ *
13
+ * The registry's two rules apply here with more force than anywhere else in
14
+ * the project. If the configuration **names** Stripe, a Stripe outage is fatal
15
+ * rather than a silent downgrade: quietly switching a shop that expects card
16
+ * payments over to "please make a transfer" would change what customers are
17
+ * asked to do without anybody deciding to. If the configuration names nothing,
18
+ * the fall-through is the point.
19
+ */
20
+ export function createPaymentRegistry(options = {}) {
21
+ const { logger } = options;
22
+ const registry = createDriverRegistry({
23
+ need: 'payment',
24
+ ...(logger === undefined ? {} : { logger }),
25
+ });
26
+ registry.register(stripePaymentDriver());
27
+ registry.register(manualPaymentDriver());
28
+ return registry;
29
+ }
30
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/payment/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAoC,MAAM,eAAe,CAAA;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAOjD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAO,GAA2B,EAAE;IAEpC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;IAC1B,MAAM,QAAQ,GAAG,oBAAoB,CAAgC;QACnE,IAAI,EAAE,SAAS;QACf,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC;KAC5C,CAAC,CAAA;IAEF,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,EAAE,CAAC,CAAA;IACxC,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,EAAE,CAAC,CAAA;IAExC,OAAO,QAAQ,CAAA;AACjB,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { type DatabaseHandle } from '@cogenta/core';
2
+ import type { OrderStore } from '../order/store.js';
3
+ import type { PaymentGateway, PaymentRecord, RefundRecord } from './types.js';
4
+ export interface PaymentStoreDependencies {
5
+ readonly gateway: PaymentGateway;
6
+ readonly orders: OrderStore;
7
+ }
8
+ export interface PaymentStore {
9
+ /** Starts a payment for an order and records it. Idempotent per order. */
10
+ start(orderId: string, options?: {
11
+ readonly returnUrl?: string;
12
+ }): Promise<PaymentRecord>;
13
+ read(id: string): Promise<PaymentRecord | null>;
14
+ listForOrder(orderId: string): Promise<readonly PaymentRecord[]>;
15
+ /**
16
+ * Records that money arrived, and moves the order to `paid`.
17
+ *
18
+ * The one entry point for "we have been paid", whatever told us: a verified
19
+ * webhook, a poll of the gateway, or a person ticking off a bank statement.
20
+ * One path means the order can never be paid by one route and not the other.
21
+ */
22
+ settle(paymentId: string, options?: {
23
+ readonly actorId?: string | null;
24
+ readonly note?: string;
25
+ }): Promise<PaymentRecord>;
26
+ fail(paymentId: string, reason: string): Promise<PaymentRecord>;
27
+ /** Re-reads from the gateway and settles if it now says paid. */
28
+ poll(paymentId: string): Promise<PaymentRecord>;
29
+ refund(paymentId: string, amountMinor: number, options?: {
30
+ readonly reason?: string;
31
+ readonly actorId?: string | null;
32
+ }): Promise<RefundRecord>;
33
+ listRefunds(paymentId: string): Promise<readonly RefundRecord[]>;
34
+ /** Verifies an inbound notification and applies it. Never trusts it unverified. */
35
+ handleWebhook(payload: string, headers: Readonly<Record<string, string>>): Promise<PaymentRecord | null>;
36
+ }
37
+ export declare function createPaymentStore(db: DatabaseHandle, dependencies: PaymentStoreDependencies, now?: () => number): PaymentStore;
38
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/payment/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,cAAc,EAKpB,MAAM,eAAe,CAAA;AAEtB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAGnD,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAiB,YAAY,EAAE,MAAM,YAAY,CAAA;AAE5F,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAA;IAChC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;CAC5B;AAED,MAAM,WAAW,YAAY;IAC3B,0EAA0E;IAC1E,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;IACzF,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAA;IAC/C,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,aAAa,EAAE,CAAC,CAAA;IAChE;;;;;;OAMG;IACH,MAAM,CACJ,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GACrE,OAAO,CAAC,aAAa,CAAC,CAAA;IACzB,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;IAC/D,iEAAiE;IACjE,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;IAC/C,MAAM,CACJ,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GACvE,OAAO,CAAC,YAAY,CAAC,CAAA;IACxB,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,YAAY,EAAE,CAAC,CAAA;IAChE,mFAAmF;IACnF,aAAa,CACX,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACxC,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAA;CACjC;AAwDD,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,cAAc,EAClB,YAAY,EAAE,wBAAwB,EACtC,GAAG,GAAE,MAAM,MAAiB,GAC3B,YAAY,CA8Qd"}
@@ -0,0 +1,253 @@
1
+ import { CogentaError, identifier, newId, sql, } from '@cogenta/core';
2
+ import { assertSameCurrency } from '../money.js';
3
+ import { toInt, toNullableText, toText } from '../rows.js';
4
+ import { TABLES } from '../tables.js';
5
+ function decode(row) {
6
+ return {
7
+ id: toText(row.id, 'payment.id'),
8
+ orderId: toText(row.order_id, 'payment.order_id'),
9
+ driver: toText(row.driver, 'payment.driver'),
10
+ externalId: toNullableText(row.external_id),
11
+ status: toText(row.status, 'payment.status'),
12
+ amountMinor: toInt(row.amount_minor, 'payment.amount_minor'),
13
+ currency: toText(row.currency, 'payment.currency'),
14
+ instructions: toNullableText(row.instructions),
15
+ createdAt: toText(row.created_at, 'payment.created_at'),
16
+ updatedAt: toText(row.updated_at, 'payment.updated_at'),
17
+ };
18
+ }
19
+ function decodeRefund(row) {
20
+ return {
21
+ id: toText(row.id, 'refund.id'),
22
+ paymentId: toText(row.payment_id, 'refund.payment_id'),
23
+ orderId: toText(row.order_id, 'refund.order_id'),
24
+ externalId: toNullableText(row.external_id),
25
+ status: toText(row.status, 'refund.status'),
26
+ amountMinor: toInt(row.amount_minor, 'refund.amount_minor'),
27
+ currency: toText(row.currency, 'refund.currency'),
28
+ reason: toNullableText(row.reason),
29
+ createdAt: toText(row.created_at, 'refund.created_at'),
30
+ };
31
+ }
32
+ export function createPaymentStore(db, dependencies, now = Date.now) {
33
+ const d = db.dialect;
34
+ const payments = identifier(TABLES.payments, d);
35
+ const refunds = identifier(TABLES.refunds, d);
36
+ const stamp = () => new Date(now()).toISOString();
37
+ async function read(id, executor = db) {
38
+ const result = await executor.query(sql `select * from ${payments} where id = ${id}`);
39
+ const row = result.rows[0];
40
+ return row === undefined ? null : decode(row);
41
+ }
42
+ async function load(id) {
43
+ const found = await read(id);
44
+ if (found === null) {
45
+ throw new CogentaError({
46
+ code: 'COMMERCE_PAYMENT_NOT_FOUND',
47
+ message: 'This payment does not exist.',
48
+ hint: 'It may belong to another order. Check the order first.',
49
+ });
50
+ }
51
+ return found;
52
+ }
53
+ async function setStatus(id, status) {
54
+ await db.query(sql `update ${payments} set status = ${status}, updated_at = ${stamp()} where id = ${id}`);
55
+ return load(id);
56
+ }
57
+ /**
58
+ * Marks paid and moves the order, in one transaction, exactly once.
59
+ *
60
+ * `status <> 'paid'` in the UPDATE is what makes it exactly once: a gateway
61
+ * that delivers the same webhook twice — which every gateway does — finds
62
+ * zero rows affected the second time and stops there, rather than
63
+ * transitioning an already-shipped order back to `paid`.
64
+ */
65
+ async function settleOnce(paymentId, actorId, note) {
66
+ return db.transaction(async (tx) => {
67
+ const claimed = await tx.query(sql `
68
+ update ${payments} set status = ${'paid'}, updated_at = ${stamp()}
69
+ where id = ${paymentId} and status <> ${'paid'}`);
70
+ const payment = await read(paymentId, tx);
71
+ if (payment === null) {
72
+ throw new CogentaError({
73
+ code: 'COMMERCE_PAYMENT_NOT_FOUND',
74
+ message: 'This payment does not exist.',
75
+ hint: 'It may belong to another order.',
76
+ });
77
+ }
78
+ if (claimed.rowsAffected === 0)
79
+ return payment;
80
+ // The payment event is recorded before the status change it causes, so
81
+ // the history reads in the order the events happened rather than in
82
+ // the order the code happened to call things.
83
+ await dependencies.orders.record(payment.orderId, 'payment_settled', { actorId, note: note ?? `Payment settled via ${payment.driver}.` }, tx);
84
+ const order = await dependencies.orders.read(payment.orderId);
85
+ if (order !== null && order.status === 'pending') {
86
+ await dependencies.orders.transition(payment.orderId, 'paid', {
87
+ actorId,
88
+ note: note ?? `Payment settled via ${payment.driver}.`,
89
+ });
90
+ }
91
+ return payment;
92
+ }, { immediate: true });
93
+ }
94
+ return {
95
+ start: async (orderId, options) => {
96
+ const order = await dependencies.orders.read(orderId);
97
+ if (order === null) {
98
+ throw new CogentaError({
99
+ code: 'COMMERCE_ORDER_NOT_FOUND',
100
+ message: 'This order does not exist.',
101
+ hint: 'Check the order reference.',
102
+ });
103
+ }
104
+ // One live payment per order. Asking to pay twice — a shopper who
105
+ // refreshed, a retry after a timeout — must return the payment already
106
+ // started, not open a second one the gateway will settle separately.
107
+ const existing = await db.query(sql `
108
+ select * from ${payments}
109
+ where order_id = ${orderId} and status in (${'pending'}, ${'authorised'}, ${'paid'})
110
+ order by created_at asc`);
111
+ const live = existing.rows[0];
112
+ if (live !== undefined)
113
+ return decode(live);
114
+ const started = await dependencies.gateway.start({
115
+ orderId: order.id,
116
+ orderReference: order.reference,
117
+ amountMinor: order.totalMinor,
118
+ currency: order.currency,
119
+ customerEmail: order.email,
120
+ ...(options?.returnUrl === undefined ? {} : { returnUrl: options.returnUrl }),
121
+ description: `Order ${order.reference}`,
122
+ });
123
+ const id = newId(now);
124
+ const at = stamp();
125
+ await db.query(sql `
126
+ insert into ${payments} (id, order_id, driver, external_id, status, amount_minor,
127
+ currency, instructions, created_at, updated_at)
128
+ values (${id}, ${orderId}, ${dependencies.gateway.name}, ${started.externalId},
129
+ ${started.status}, ${order.totalMinor}, ${order.currency},
130
+ ${started.instructions}, ${at}, ${at})`);
131
+ await dependencies.orders.record(orderId, 'payment_started', {
132
+ note: `Payment started via ${dependencies.gateway.name}.`,
133
+ });
134
+ // A gateway that settles instantly (a zero-total order, a saved card)
135
+ // must not leave the order pending just because the record was written
136
+ // a moment after the fact.
137
+ if (started.status === 'paid')
138
+ return settleOnce(id, null, null);
139
+ return load(id);
140
+ },
141
+ read,
142
+ listForOrder: async (orderId) => {
143
+ const result = await db.query(sql `select * from ${payments} where order_id = ${orderId} order by created_at asc`);
144
+ return result.rows.map(decode);
145
+ },
146
+ settle: async (paymentId, options) => settleOnce(paymentId, options?.actorId ?? null, options?.note ?? null),
147
+ fail: async (paymentId, reason) => {
148
+ const payment = await load(paymentId);
149
+ await dependencies.orders.record(payment.orderId, 'payment_failed', { note: reason });
150
+ return setStatus(paymentId, 'failed');
151
+ },
152
+ poll: async (paymentId) => {
153
+ const payment = await load(paymentId);
154
+ if (payment.externalId === null)
155
+ return payment;
156
+ const fresh = await dependencies.gateway.fetch(payment.externalId);
157
+ if (fresh.status === 'paid')
158
+ return settleOnce(paymentId, null, null);
159
+ if (fresh.status === payment.status)
160
+ return payment;
161
+ return setStatus(paymentId, fresh.status);
162
+ },
163
+ refund: async (paymentId, amountMinor, options) => {
164
+ const payment = await load(paymentId);
165
+ if (payment.status !== 'paid' && payment.status !== 'refunded') {
166
+ throw new CogentaError({
167
+ code: 'COMMERCE_PAYMENT_FAILED',
168
+ message: 'Only a settled payment can be refunded.',
169
+ hint: 'Cancel the order instead — nothing has been taken yet.',
170
+ details: { paymentId, status: payment.status },
171
+ });
172
+ }
173
+ const already = await db.query(sql `select * from ${refunds} where payment_id = ${paymentId}`);
174
+ const refundedSoFar = already.rows
175
+ .map(decodeRefund)
176
+ .filter((refund) => refund.status !== 'failed')
177
+ .reduce((sum, refund) => sum + refund.amountMinor, 0);
178
+ // Checked before the gateway is asked, not after. A gateway that
179
+ // accepted an over-refund would have moved real money by the time we
180
+ // noticed, and there is no undo for that.
181
+ if (refundedSoFar + amountMinor > payment.amountMinor) {
182
+ throw new CogentaError({
183
+ code: 'COMMERCE_REFUND_EXCEEDS_PAYMENT',
184
+ message: `Refunding ${String(amountMinor)} would take the total refunded past what was paid.`,
185
+ hint: `Paid: ${String(payment.amountMinor)}. Already refunded: ${String(refundedSoFar)}.`,
186
+ details: { paymentId, amountMinor, refundedSoFar, paid: payment.amountMinor },
187
+ });
188
+ }
189
+ const result = payment.externalId === null
190
+ ? { externalId: null, status: 'pending' }
191
+ : await dependencies.gateway.refund({
192
+ externalId: payment.externalId,
193
+ amountMinor,
194
+ currency: assertSameCurrency(payment.currency, payment.currency),
195
+ ...(options?.reason === undefined ? {} : { reason: options.reason }),
196
+ });
197
+ const id = newId(now);
198
+ await db.query(sql `
199
+ insert into ${refunds} (id, payment_id, order_id, external_id, status, amount_minor,
200
+ currency, reason, created_at)
201
+ values (${id}, ${paymentId}, ${payment.orderId}, ${result.externalId}, ${result.status},
202
+ ${amountMinor}, ${payment.currency}, ${options?.reason ?? null}, ${stamp()})`);
203
+ await dependencies.orders.record(payment.orderId, 'refunded', {
204
+ note: options?.reason ?? `Refunded ${String(amountMinor)} ${payment.currency}.`,
205
+ actorId: options?.actorId ?? null,
206
+ });
207
+ // Fully refunded, so the order says so too. A partial refund leaves the
208
+ // order where it is: a customer who got half their money back still has
209
+ // the other half of the goods.
210
+ if (refundedSoFar + amountMinor >= payment.amountMinor) {
211
+ await db.query(sql `update ${payments} set status = ${'refunded'}, updated_at = ${stamp()} where id = ${paymentId}`);
212
+ const order = await dependencies.orders.read(payment.orderId);
213
+ if (order !== null && order.status !== 'refunded' && order.status !== 'cancelled') {
214
+ await dependencies.orders.transition(payment.orderId, 'refunded', {
215
+ actorId: options?.actorId ?? null,
216
+ note: 'Fully refunded.',
217
+ });
218
+ }
219
+ }
220
+ const stored = await db.query(sql `select * from ${refunds} where id = ${id}`);
221
+ const row = stored.rows[0];
222
+ if (row === undefined) {
223
+ throw new CogentaError({
224
+ code: 'INTERNAL',
225
+ message: 'The refund was not stored.',
226
+ hint: 'Check that the commerce tables exist (ensureCommerceTables).',
227
+ });
228
+ }
229
+ return decodeRefund(row);
230
+ },
231
+ listRefunds: async (paymentId) => {
232
+ const result = await db.query(sql `select * from ${refunds} where payment_id = ${paymentId} order by created_at asc`);
233
+ return result.rows.map(decodeRefund);
234
+ },
235
+ handleWebhook: async (payload, headers) => {
236
+ // Verification first, and there is no path around it. An unauthenticated
237
+ // "paid" notification is a way to take goods for free, so a driver that
238
+ // has no inbound channel throws rather than returning something usable.
239
+ const event = await dependencies.gateway.verifyEvent(payload, headers);
240
+ const found = await db.query(sql `select * from ${payments} where external_id = ${event.externalId}`);
241
+ const row = found.rows[0];
242
+ if (row === undefined)
243
+ return null;
244
+ const payment = decode(row);
245
+ if (event.status === 'paid')
246
+ return settleOnce(payment.id, null, 'Confirmed by the gateway.');
247
+ if (event.status === payment.status)
248
+ return payment;
249
+ return setStatus(payment.id, event.status);
250
+ },
251
+ };
252
+ }
253
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/payment/store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAEZ,UAAU,EACV,KAAK,EAEL,GAAG,GACJ,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAEhD,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAC1D,OAAO,EA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EAAE,OAAO,CAAC,CAAA;YAEtE,MAAM,KAAK,GAAG,MAAM,EAAE,CAAC,KAAK,CAC1B,GAAG,CAAA,iBAAiB,QAAQ,wBAAwB,KAAK,CAAC,UAAU,EAAE,CACvE,CAAA;YACD,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YACzB,IAAI,GAAG,KAAK,SAAS;gBAAE,OAAO,IAAI,CAAA;YAElC,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;YAC3B,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM;gBAAE,OAAO,UAAU,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,2BAA2B,CAAC,CAAA;YAC7F,IAAI,KAAK,CAAC,MAAM,KAAK,OAAO,CAAC,MAAM;gBAAE,OAAO,OAAO,CAAA;YACnD,OAAO,SAAS,CAAC,OAAO,CAAC,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAC5C,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { type Logger } from '@cogenta/core';
2
+ import type { PaymentDriver } from './types.js';
3
+ export interface StripeDriverOptions {
4
+ /** Optional: without one, an unknown Stripe status is mapped to `failed` silently. */
5
+ readonly logger?: Logger;
6
+ /** Injected so a freshness window can be tested without waiting five minutes. */
7
+ readonly now?: () => number;
8
+ }
9
+ export declare function stripePaymentDriver(options?: StripeDriverOptions): PaymentDriver;
10
+ //# sourceMappingURL=stripe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripe.d.ts","sourceRoot":"","sources":["../../src/payment/stripe.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,KAAK,MAAM,EAAE,MAAM,eAAe,CAAA;AAC5E,OAAO,KAAK,EAIV,aAAa,EAMd,MAAM,YAAY,CAAA;AAiEnB,MAAM,WAAW,mBAAmB;IAClC,sFAAsF;IACtF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,iFAAiF;IACjF,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;CAC5B;AAiWD,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,mBAAwB,GAAG,aAAa,CAgGpF"}