@easy-cms/plugin-ecommerce 0.63.0 → 0.65.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.
@@ -554,6 +554,13 @@ function shopCollections(o) {
554
554
  access: bySystem,
555
555
  label: { en: "Paid", th: "\u0E0A\u0E33\u0E23\u0E30\u0E40\u0E21\u0E37\u0E48\u0E2D" }
556
556
  },
557
+ {
558
+ // Unpaid manual orders are cancelled after this (the payment method's `expiresIn`).
559
+ name: "expiresAt",
560
+ type: "date",
561
+ access: bySystem,
562
+ label: { en: "Unpaid until", th: "\u0E23\u0E2D\u0E0A\u0E33\u0E23\u0E30\u0E16\u0E36\u0E07" }
563
+ },
557
564
  {
558
565
  name: "note",
559
566
  type: "textarea",
@@ -776,7 +783,7 @@ var INFO = {
776
783
  name: "@easy-cms/plugin-ecommerce",
777
784
  // The plugin API it is written for (`PLUGIN_API_VERSION` of @easy-cms/core).
778
785
  apiVersion: 1,
779
- ...true ? { version: "0.63.0" } : {}
786
+ ...true ? { version: "0.65.0" } : {}
780
787
  };
781
788
 
782
789
  // src/shop.ts
@@ -1362,7 +1369,8 @@ var Orders = class {
1362
1369
  paymentMethod: String(tx.method),
1363
1370
  stockShort: short,
1364
1371
  locale: snapshot.locale,
1365
- ...status === "paid" ? { paidAt: (/* @__PURE__ */ new Date()).toISOString() } : {}
1372
+ ...status === "paid" ? { paidAt: (/* @__PURE__ */ new Date()).toISOString() } : {},
1373
+ ...status === "pending" && typeof adapter?.expiresIn === "number" ? { expiresAt: new Date(Date.now() + adapter.expiresIn * 1e3).toISOString() } : {}
1366
1374
  },
1367
1375
  { context, depth: 0 }
1368
1376
  );
@@ -1491,6 +1499,33 @@ var Orders = class {
1491
1499
  * Upkeep: transactions left `processing` by a stopped process go back to `pending`, so the
1492
1500
  * next confirmation or webhook makes the order.
1493
1501
  */
1502
+ /** Cancels unpaid orders past their `expiresAt`, putting their stock back. */
1503
+ async expire(now) {
1504
+ const due = await this.cms.find(ORDERS, {
1505
+ where: {
1506
+ and: [{ status: { equals: "pending" } }, { expiresAt: { lt: now.toISOString() } }]
1507
+ },
1508
+ limit: 100,
1509
+ depth: 0
1510
+ });
1511
+ let cancelled = 0;
1512
+ for (const found of due.docs) {
1513
+ const order = await this.cms.update(
1514
+ ORDERS,
1515
+ found.id,
1516
+ { status: "cancelled" },
1517
+ { where: { status: { equals: "pending" } }, depth: 0 }
1518
+ );
1519
+ if (!order) continue;
1520
+ await this.restock(order);
1521
+ const transaction = await this.transactionOf(order);
1522
+ if (transaction)
1523
+ await this.setTransaction(transaction, { status: "failed", error: "expired" });
1524
+ await this.shop.onOrder("cancelled", order, this.cms);
1525
+ cancelled++;
1526
+ }
1527
+ return cancelled;
1528
+ }
1494
1529
  async release(now) {
1495
1530
  const stale = new Date(now.getTime() - 10 * 6e4).toISOString();
1496
1531
  const stuck = await this.cms.find(TRANSACTIONS, {
@@ -1852,7 +1887,10 @@ function ecommercePlugin(options) {
1852
1887
  {
1853
1888
  name: "shop:payments",
1854
1889
  every: 300,
1855
- run: ({ cms, now }) => runtime(cms).orders.release(now)
1890
+ run: async ({ cms, now }) => {
1891
+ await runtime(cms).orders.release(now);
1892
+ await runtime(cms).orders.expire(now);
1893
+ }
1856
1894
  },
1857
1895
  {
1858
1896
  name: "shop:carts",
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Label, Field, FieldTypeDefinition, ID, AuthUser, RequestContext, EasyCMS, MembersSignup, MembersConfig, CollectionConfig, TypedPlugin } from '@easy-cms/core';
2
- import { O as ORDER_STATUSES, C as CartView, a as Currency, A as Address, b as Adjustment, c as OrderStatus, P as PaymentAdapter } from './payments-tPD3bTTW.js';
3
- export { d as CURRENCIES, e as CartLine, f as CheckoutResult, g as ConfirmResult, I as InitiateResult, M as ManualAdapterOptions, h as PaymentTransaction, S as ShopSettings, T as TRANSACTION_STATUSES, i as TransactionStatus, j as definePaymentAdapter, k as formatPrice, m as manualAdapter, p as priceField } from './payments-tPD3bTTW.js';
2
+ import { O as ORDER_STATUSES, C as CartView, a as Currency, A as Address, b as Adjustment, c as OrderStatus, P as PaymentAdapter } from './payments-DZKeAbza.js';
3
+ export { d as CURRENCIES, e as CartLine, f as CheckoutResult, g as ConfirmResult, I as InitiateResult, M as ManualAdapterOptions, h as PaymentTransaction, S as ShopSettings, T as TRANSACTION_STATUSES, i as TransactionStatus, j as definePaymentAdapter, k as formatPrice, m as manualAdapter, p as priceField } from './payments-DZKeAbza.js';
4
4
 
5
5
  declare module '@easy-cms/core' {
6
6
  interface CustomFieldTypes {
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  paymentSucceeded,
13
13
  price,
14
14
  priceField
15
- } from "./chunk-2W6YWHFN.js";
15
+ } from "./chunk-XMAH3NBH.js";
16
16
 
17
17
  // src/payments.ts
18
18
  var definePaymentAdapter = (adapter) => adapter;
@@ -21,6 +21,7 @@ function manualAdapter(options = {}) {
21
21
  name: options.name ?? "bank-transfer",
22
22
  label: options.label ?? { en: "Bank transfer", th: "\u0E42\u0E2D\u0E19\u0E40\u0E07\u0E34\u0E19" },
23
23
  manual: true,
24
+ expiresIn: options.expiresIn ?? 3 * 86400,
24
25
  ...options.instructions ? { instructions: options.instructions } : {},
25
26
  initiate: () => ({})
26
27
  };
@@ -165,6 +165,11 @@ interface PaymentAdapter {
165
165
  readonly manual?: boolean;
166
166
  /** For `manual` ones: what to tell the customer, e.g. the bank account (page and email). */
167
167
  readonly instructions?: Label;
168
+ /**
169
+ * For `manual` ones: seconds an order may wait for its payment; then it is cancelled and its
170
+ * stock put back. `false`: it waits until staff act on it.
171
+ */
172
+ readonly expiresIn?: number | false;
168
173
  /** Starts the payment of a new transaction. */
169
174
  readonly initiate: (args: {
170
175
  readonly cms: EasyCMS;
@@ -203,6 +208,12 @@ interface ManualAdapterOptions {
203
208
  * order email.
204
209
  */
205
210
  readonly instructions?: Label;
211
+ /**
212
+ * Seconds an order waits for the money before it is cancelled and its stock put back, so
213
+ * unpaid orders don't hold stock. Default 3 days; `false` to keep them until staff act (e.g.
214
+ * cash on delivery).
215
+ */
216
+ readonly expiresIn?: number | false;
206
217
  }
207
218
  /**
208
219
  * Payment by bank transfer, cash on delivery or any other way outside the site: the order is
package/dist/stripe.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Label } from '@easy-cms/core';
2
- import { P as PaymentAdapter } from './payments-tPD3bTTW.js';
2
+ import { P as PaymentAdapter } from './payments-DZKeAbza.js';
3
3
 
4
4
  /** The parts of the `stripe` package's client the adapter uses. */
5
5
  interface StripeClient {
package/dist/stripe.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  paymentFailed,
3
3
  paymentSucceeded
4
- } from "./chunk-2W6YWHFN.js";
4
+ } from "./chunk-XMAH3NBH.js";
5
5
 
6
6
  // src/stripe.ts
7
7
  function stripeAdapter(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-cms/plugin-ecommerce",
3
- "version": "0.63.0",
3
+ "version": "0.65.0",
4
4
  "description": "A shop for Easy CMS: products and variants, prices in several currencies, carts (guests too), checkout with Stripe or bank transfer, orders, stock, customer accounts, and React and Vue hooks (experimental)",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -36,7 +36,7 @@
36
36
  "react": ">=18.0.0",
37
37
  "stripe": ">=17.0.0",
38
38
  "vue": "^3.4.0",
39
- "@easy-cms/core": "^0.63.0"
39
+ "@easy-cms/core": "^0.65.0"
40
40
  },
41
41
  "peerDependenciesMeta": {
42
42
  "react": {
@@ -54,9 +54,9 @@
54
54
  "happy-dom": "^20.14.5",
55
55
  "react": "^19.2.0",
56
56
  "vue": "^3.5.43",
57
- "@easy-cms/core": "^0.63.0",
58
- "@easy-cms/db-sqlite": "^0.63.0",
59
- "@easy-cms/plugin-multi-tenant": "^0.63.0"
57
+ "@easy-cms/core": "^0.65.0",
58
+ "@easy-cms/db-sqlite": "^0.65.0",
59
+ "@easy-cms/plugin-multi-tenant": "^0.65.0"
60
60
  },
61
61
  "engines": {
62
62
  "node": ">=22.12"