Skip to content

Commit 91a9728

Browse files
committed
Fix: Upgrade stripe packages and refactor the order status for stripe payment
1 parent e358861 commit 91a9728

19 files changed

Lines changed: 369 additions & 68 deletions

File tree

configExample.text

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
{
2+
"shop": {
3+
"language": "en",
4+
"timezone": "America/New_York",
5+
"currency": "USD",
6+
"weightUnit": "kg",
7+
"homeUrl": "http://localhost:3000"
8+
},
9+
"system": {
10+
"file_storage": "local",
11+
"admin_collection_size": 20,
12+
"upload_allowed_mime_types": [
13+
"image/jpeg",
14+
"image/png",
15+
"image/gif",
16+
"image/webp",
17+
"image/avif"
18+
],
19+
"theme": "mytheme",
20+
"extensions": [
21+
{
22+
"name": "my-custom-extension",
23+
"resolve": "extensions/my-custom-extension",
24+
"enabled": true
25+
}
26+
],
27+
"session": {
28+
"maxAge": 86400000,
29+
"resave": false,
30+
"saveUninitialized": false,
31+
"cookieSecret": "keyboard cat",
32+
"cookieName": "sid",
33+
"adminCookieName": "admin-sid"
34+
},
35+
"notification_emails": {
36+
"from": "noreply@example.com",
37+
"order_confirmation": {
38+
"enabled": true,
39+
"templatePath": null
40+
},
41+
"customer_welcome": {
42+
"enabled": true,
43+
"templatePath": null
44+
},
45+
"reset_password": {
46+
"enabled": true,
47+
"templatePath": null
48+
}
49+
}
50+
},
51+
catalog: {
52+
collectionPageSize: 3,
53+
product: { image: { width: 1200, height: 1200 } },
54+
showOutOfStockProduct: false
55+
},
56+
"checkout": {
57+
"showShippingNote": true
58+
},
59+
"pricing": {
60+
"rounding": "round",
61+
"precision": 2,
62+
"tax": {
63+
"rounding": "round",
64+
"precision": 2,
65+
"round_level": "total",
66+
"price_including_tax": true
67+
}
68+
},
69+
"themeConfig": {
70+
"logo": {
71+
"alt": "My Shop Logo",
72+
"src": "/logo.png",
73+
"width": 200,
74+
"height": 50
75+
},
76+
"headTags": {
77+
"links": [
78+
{ "rel": "icon", "href": "/favicon.ico", "type": "image/x-icon" }
79+
],
80+
"metas": [
81+
{ "name": "viewport", "content": "width=device-width, initial-scale=1" }
82+
],
83+
"scripts": [
84+
{ "src": "/custom.js", "async": true }
85+
],
86+
"bases": [
87+
{ "href": "/" }
88+
]
89+
},
90+
"copyRight": "© 2025 My Shop. All Rights Reserved."
91+
},
92+
"oms": {
93+
"order": {
94+
"paymentStatus": {
95+
"pending": {
96+
"name": "Pending",
97+
"badge": "default",
98+
"isDefault": true
99+
},
100+
"paid": {
101+
"name": "Paid",
102+
"badge": "success",
103+
},
104+
"failed": {
105+
"name": "Failed",
106+
"badge": "critical",
107+
}
108+
},
109+
"shipmentStatus": {
110+
"pending": {
111+
"name": "Pending",
112+
"badge": "default",
113+
"isDefault": true
114+
},
115+
"shipped": {
116+
"name": "Shipped",
117+
"badge": "attention",
118+
},
119+
"delivered": {
120+
"name": "Delivered",
121+
"badge": "success",
122+
}
123+
},
124+
"status": {
125+
"new": {
126+
"name": "New",
127+
"badge": "default",
128+
"isDefault": true,
129+
"next": ["processing", "canceled"]
130+
},
131+
"processing": {
132+
"name": "Processing",
133+
"badge": "default",
134+
"next": ["completed", "canceled"]
135+
},
136+
"completed": {
137+
"name": "Completed",
138+
"badge": "success",
139+
"next": ["closed"]
140+
},
141+
"canceled": {
142+
"name": "Canceled",
143+
"badge": "critical",
144+
"next": []
145+
},
146+
"closed": {
147+
"name": "Closed",
148+
"badge": "default",
149+
"next": []
150+
}
151+
},
152+
"psoMapping": {
153+
"pending:pending": "new",
154+
"pending:*": "processing",
155+
"paid:*": "processing",
156+
"paid:delivered": "completed",
157+
"canceled:*": "processing",
158+
"canceled:canceled": "canceled"
159+
},
160+
"reStockAfterCancellation": true
161+
},
162+
"carriers": {
163+
"default": {
164+
"name": "Default"
165+
},
166+
"fedex": {
167+
"name": "FedEx",
168+
"trackingUrl": "https://www.fedex.com/fedextrack/?trknbr={trackingNumber}"
169+
},
170+
"usps": {
171+
"name": "USPS",
172+
"trackingUrl": "https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1={trackingNumber}"
173+
},
174+
"ups": {
175+
"name": "UPS",
176+
"trackingUrl": "https://www.ups.com/track?loc=en_US&tracknum={trackingNumber}"
177+
}
178+
}
179+
}
180+
}

package-lock.json

Lines changed: 28 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/evershop/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@
153153
"@graphql-tools/schema": "^9.0.19",
154154
"@hapi/topo": "^5.0.0",
155155
"@pmmmwh/react-refresh-webpack-plugin": "^0.6.0",
156-
"@stripe/react-stripe-js": "^1.5.0",
157-
"@stripe/stripe-js": "^1.18.0",
156+
"@stripe/react-stripe-js": "^3.10.0",
157+
"@stripe/stripe-js": "^5.10.0",
158158
"@swc/cli": "^0.7.7",
159159
"@swc/core": "^1.11.29",
160160
"@tailwindcss/postcss": "^4.1.18",
@@ -225,7 +225,7 @@
225225
"session-file-store": "^1.5.0",
226226
"sharp": "^0.33.5",
227227
"slick-carousel": "^1.8.1",
228-
"stripe": "^8.176.0",
228+
"stripe": "^21.0.1",
229229
"style-loader": "^3.3.1",
230230
"swc-minify-webpack-plugin": "^2.1.3",
231231
"tailwind-merge": "^3.4.0",

packages/evershop/src/modules/oms/services/statusManager.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import config from 'config';
22
import { getConfig } from '../../../lib/util/getConfig.js';
3+
import { addProcessor } from '../../../lib/util/registry.js';
34
import {
45
OrderStatus,
56
PaymentStatus,
@@ -131,11 +132,28 @@ function registerOrderStatus(id: string, detail: OrderStatus) {
131132
config.util.setModuleDefaults('oms', statusConfig);
132133
}
133134

135+
/** Registers a mapping of payment status and shipment status to order status. This function must be called during the application initialization phase (e.g., in a module's `bootstrap` function).
136+
* @param paymentStatus Payment status ID or "*" to match any payment status
137+
* @param shipmentStatus Shipment status ID or "*" to match any shipment status
138+
* @param orderStatus Order status ID to map to when the payment status and shipment status match the provided values
139+
*/
140+
function registerPSOStatusMapping(
141+
paymentStatus: string | '*',
142+
shipmentStatus: string | '*',
143+
orderStatus: string
144+
) {
145+
addProcessor('psoMapping', async (mapping: Record<string, string>) => {
146+
mapping[`${paymentStatus}:${shipmentStatus}`] = orderStatus;
147+
return mapping;
148+
});
149+
}
150+
134151
export {
135152
getOrderStatusList,
136153
getShipmentStatusList,
137154
getPaymentStatusList,
138155
registerPaymentStatus,
139156
registerShipmentStatus,
140-
registerOrderStatus
157+
registerOrderStatus,
158+
registerPSOStatusMapping
141159
};

packages/evershop/src/modules/oms/services/updateOrderStatus.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { error } from '../../../lib/log/logger.js';
1616
import { pool } from '../../../lib/postgres/connection.js';
1717
import { getConfig } from '../../../lib/util/getConfig.js';
1818
import { hookable, hookAfter, hookBefore } from '../../../lib/util/hookable.js';
19+
import { getValueSync } from '../../../lib/util/registry.js';
1920
import { OrderRow } from '../../../types/db/index.js';
2021
import { PaymentStatus, ShipmentStatus } from '../../../types/order.js';
2122

@@ -59,12 +60,13 @@ export function resolveOrderStatus(
5960
'Either shipment status or payment status is invalid. Can not update order status'
6061
);
6162
}
63+
const finalPsoMapping = getValueSync('psoMapping', psoMapping, {});
6264
// Reverse the order status list to get the highest priority status first
6365
const nextStatus =
64-
psoMapping[`${paymentStatus}:${shipmentStatus}`] ||
65-
psoMapping[`*:${shipmentStatus}`] ||
66-
psoMapping[`${paymentStatus}:*`] ||
67-
psoMapping['*:*'];
66+
finalPsoMapping[`${paymentStatus}:${shipmentStatus}`] ||
67+
finalPsoMapping[`*:${shipmentStatus}`] ||
68+
finalPsoMapping[`${paymentStatus}:*`] ||
69+
finalPsoMapping['*:*'];
6870
if (!nextStatus || !orderStatusList[nextStatus]) {
6971
throw new Error(
7072
'Can not found a valid order status from the current shipment and payment status'

packages/evershop/src/modules/stripe/api/capturePaymentIntent/[context]bodyParser[auth].js renamed to packages/evershop/src/modules/stripe/api/capturePaymentIntent/[context]bodyParser[auth].ts

File renamed without changes.

0 commit comments

Comments
 (0)