ts-glitter 21.0.4 → 21.0.6
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.
- package/lowcode/Entry.js +1 -1
- package/lowcode/Entry.ts +1 -1
- package/lowcode/backend-manager/bg-blog.js +22 -37
- package/lowcode/backend-manager/bg-blog.ts +45 -34
- package/lowcode/backend-manager/bg-list-component.js +2 -2
- package/lowcode/backend-manager/bg-list-component.ts +2 -2
- package/lowcode/backend-manager/bg-widget.js +21 -0
- package/lowcode/backend-manager/bg-widget.ts +21 -0
- package/lowcode/cms-plugin/filter-options.js +3 -3
- package/lowcode/cms-plugin/filter-options.ts +1 -1
- package/lowcode/cms-plugin/pos-pages/models.ts +1 -0
- package/lowcode/cms-plugin/pos-pages/payment-page.js +74 -8
- package/lowcode/cms-plugin/pos-pages/payment-page.ts +98 -19
- package/lowcode/cms-plugin/product-service.js +2 -1
- package/lowcode/cms-plugin/product-service.ts +3 -2
- package/lowcode/cms-plugin/shopping-finance-setting.js +251 -6
- package/lowcode/cms-plugin/shopping-finance-setting.ts +291 -6
- package/lowcode/cms-plugin/shopping-order-manager.js +56 -46
- package/lowcode/cms-plugin/shopping-order-manager.ts +59 -47
- package/lowcode/cms-plugin/shopping-product-setting.js +10 -5
- package/lowcode/cms-plugin/shopping-product-setting.ts +14 -6
- package/lowcode/cms-plugin/shopping-setting-advance.js +21 -72
- package/lowcode/cms-plugin/shopping-setting-advance.ts +31 -98
- package/lowcode/css/editor.css +48 -16
- package/lowcode/css/front-end.css +16 -17
- package/lowcode/glitter-base/global/language.js +2 -0
- package/lowcode/glitter-base/global/language.ts +3 -0
- package/lowcode/glitter-base/global/shipment-config.js +4 -4
- package/lowcode/glitter-base/global/shipment-config.ts +1 -1
- package/lowcode/glitter-base/route/shopping.js +11 -0
- package/lowcode/glitter-base/route/shopping.ts +12 -0
- package/lowcode/official_view_component/form-widget/input-custom.js +0 -1
- package/lowcode/official_view_component/form-widget/input-custom.ts +0 -1
- package/lowcode/public-components/checkout/index.js +578 -780
- package/lowcode/public-components/checkout/index.ts +2457 -2652
- package/lowcode/public-components/headers/header-class.js +252 -324
- package/lowcode/public-components/headers/header-class.ts +389 -480
- package/lowcode/public-components/modules/cart-module.js +433 -0
- package/lowcode/public-components/modules/cart-module.ts +491 -0
- package/lowcode/public-components/modules/product-module.js +45 -0
- package/lowcode/public-components/modules/product-module.ts +58 -0
- package/lowcode/public-components/product/product-detail.js +178 -184
- package/lowcode/public-components/product/product-detail.ts +564 -579
- package/lowcode/public-components/user-manager/um-order.js +162 -32
- package/lowcode/public-components/user-manager/um-order.ts +181 -46
- package/lowcode/public-models/product.ts +1 -0
- package/package.json +1 -1
- package/src/Language.js +1 -0
- package/src/Language.js.map +1 -1
- package/src/Language.ts +3 -0
- package/src/api-public/controllers/article.js +33 -29
- package/src/api-public/controllers/article.js.map +1 -1
- package/src/api-public/controllers/article.ts +152 -146
- package/src/api-public/controllers/index.js +2 -0
- package/src/api-public/controllers/index.js.map +1 -1
- package/src/api-public/controllers/index.ts +2 -0
- package/src/api-public/controllers/shop.js +125 -47
- package/src/api-public/controllers/shop.js.map +1 -1
- package/src/api-public/controllers/shop.ts +148 -61
- package/src/api-public/controllers/user.js +51 -52
- package/src/api-public/controllers/user.js.map +1 -1
- package/src/api-public/controllers/user.ts +63 -52
- package/src/api-public/models/glitter-finance.js +2 -1
- package/src/api-public/models/glitter-finance.js.map +5 -1
- package/src/api-public/services/checkout-event.d.ts +1 -0
- package/src/api-public/services/checkout-event.js +38 -13
- package/src/api-public/services/checkout-event.js.map +1 -1
- package/src/api-public/services/checkout-event.ts +38 -10
- package/src/api-public/services/factories/payment-strategy-factory.d.ts +6 -0
- package/src/api-public/services/factories/payment-strategy-factory.js +49 -0
- package/src/api-public/services/factories/payment-strategy-factory.js.map +1 -0
- package/src/api-public/services/factories/payment-strategy-factory.ts +71 -0
- package/src/api-public/services/fb-service.js +4 -4
- package/src/api-public/services/fb-service.js.map +1 -1
- package/src/api-public/services/financial-service.d.ts +2 -1
- package/src/api-public/services/financial-service.js +48 -53
- package/src/api-public/services/financial-service.js.map +1 -1
- package/src/api-public/services/financial-service.ts +29 -38
- package/src/api-public/services/financial-serviceV2.d.ts +298 -0
- package/src/api-public/services/financial-serviceV2.js +1158 -0
- package/src/api-public/services/financial-serviceV2.js.map +1 -0
- package/src/api-public/services/financial-serviceV2.ts +1518 -0
- package/src/api-public/services/interface/payment-keys-interface.d.ts +37 -0
- package/src/api-public/services/interface/payment-keys-interface.js +3 -0
- package/src/api-public/services/interface/payment-keys-interface.js.map +1 -0
- package/src/api-public/services/interface/payment-keys-interface.ts +46 -0
- package/src/api-public/services/interface/payment-strategy-interface.d.ts +17 -0
- package/src/api-public/services/interface/payment-strategy-interface.js +3 -0
- package/src/api-public/services/interface/payment-strategy-interface.js.map +1 -0
- package/src/api-public/services/interface/payment-strategy-interface.ts +48 -0
- package/src/api-public/services/migrate-event/public-user-config.d.ts +5 -0
- package/src/api-public/services/migrate-event/public-user-config.js +81 -0
- package/src/api-public/services/migrate-event/public-user-config.js.map +1 -0
- package/src/api-public/services/migrate-event/public-user-config.ts +106 -0
- package/src/api-public/services/model/handlePaymentTransaction.js +0 -68
- package/src/api-public/services/model/handlePaymentTransaction.js.map +1 -1
- package/src/api-public/services/model/handlePaymentTransaction.ts +62 -54
- package/src/api-public/services/monitor.d.ts +1 -0
- package/src/api-public/services/payment-service.d.ts +12 -0
- package/src/api-public/services/payment-service.js +83 -0
- package/src/api-public/services/payment-service.js.map +1 -0
- package/src/api-public/services/payment-service.ts +112 -0
- package/src/api-public/services/shopping.d.ts +2 -1
- package/src/api-public/services/shopping.js +60 -23
- package/src/api-public/services/shopping.js.map +1 -1
- package/src/api-public/services/shopping.ts +88 -16
- package/src/api-public/services/strategies/ecpay-strategy.d.ts +8 -0
- package/src/api-public/services/strategies/ecpay-strategy.js +26 -0
- package/src/api-public/services/strategies/ecpay-strategy.js.map +1 -0
- package/src/api-public/services/strategies/ecpay-strategy.ts +30 -0
- package/src/api-public/services/strategies/ezpay-strategy.d.ts +8 -0
- package/src/api-public/services/strategies/ezpay-strategy.js +26 -0
- package/src/api-public/services/strategies/ezpay-strategy.js.map +1 -0
- package/src/api-public/services/strategies/ezpay-strategy.ts +31 -0
- package/src/api-public/services/strategies/jkopay-strategy.d.ts +8 -0
- package/src/api-public/services/strategies/jkopay-strategy.js +32 -0
- package/src/api-public/services/strategies/jkopay-strategy.js.map +1 -0
- package/src/api-public/services/strategies/jkopay-strategy.ts +36 -0
- package/src/api-public/services/strategies/linepay-strategy.d.ts +8 -0
- package/src/api-public/services/strategies/linepay-strategy.js +32 -0
- package/src/api-public/services/strategies/linepay-strategy.js.map +1 -0
- package/src/api-public/services/strategies/linepay-strategy.ts +35 -0
- package/src/api-public/services/strategies/paynow-strategy.d.ts +8 -0
- package/src/api-public/services/strategies/paynow-strategy.js +26 -0
- package/src/api-public/services/strategies/paynow-strategy.js.map +1 -0
- package/src/api-public/services/strategies/paynow-strategy.ts +29 -0
- package/src/api-public/services/strategies/paypal-strategy.d.ts +8 -0
- package/src/api-public/services/strategies/paypal-strategy.js +28 -0
- package/src/api-public/services/strategies/paypal-strategy.js.map +1 -0
- package/src/api-public/services/strategies/paypal-strategy.ts +31 -0
- package/src/api-public/services/updated-table-checked.d.ts +1 -0
- package/src/api-public/services/updated-table-checked.js +37 -15
- package/src/api-public/services/updated-table-checked.js.map +1 -1
- package/src/api-public/services/updated-table-checked.ts +56 -36
- package/src/api-public/utils/ut-permission.d.ts +1 -0
- package/src/app-project/serverless/src/index.js +17 -7
- package/src/app-project/serverless/src/index.js.map +1 -1
- package/src/app-project/serverless/src/modules/CryptoJS.js +17 -7
- package/src/app-project/serverless/src/modules/CryptoJS.js.map +1 -1
- package/src/app-project/serverless/src/modules/ssh.js +17 -7
- package/src/app-project/serverless/src/modules/ssh.js.map +1 -1
- package/src/config.d.ts +1 -1
- package/src/modules/AWSLib.js +3 -2
- package/src/modules/AWSLib.js.map +1 -1
- package/src/modules/CryptoJS.js +17 -7
- package/src/modules/CryptoJS.js.map +1 -1
- package/src/modules/database.d.ts +1 -1
- package/src/modules/redis.d.ts +1 -1
- package/src/modules/ssh.js +17 -7
- package/src/modules/ssh.js.map +1 -1
- package/src/modules/tool.d.ts +4 -4
- package/src/modules/tool.js +2 -1
- package/src/modules/tool.js.map +1 -1
- package/src/run.js +2 -1
- package/src/run.js.map +1 -1
- package/src/services/create-instance.js +4 -3
- package/src/services/create-instance.js.map +1 -1
- package/src/services/saas-table-check.js +2 -2
- package/src/services/saas-table-check.js.map +5 -1
- package/src/services/tool.js +3 -2
- package/src/services/tool.js.map +1 -1
- package/vp00rqhw1r.json +1 -0
- package/src/api-public/services/product-migrate.d.ts +0 -8
- package/src/api-public/services/product-migrate.js.map +0 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PaymentService = void 0;
|
|
7
|
+
const redis_js_1 = __importDefault(require("../../modules/redis.js"));
|
|
8
|
+
const tool_js_1 = __importDefault(require("../../modules/tool.js"));
|
|
9
|
+
const private_config_1 = require("../../services/private_config");
|
|
10
|
+
class PaymentService {
|
|
11
|
+
constructor(paymentStrategies, appName, payment_select) {
|
|
12
|
+
this.paymentStrategies = paymentStrategies;
|
|
13
|
+
this.paymentStrategies = paymentStrategies;
|
|
14
|
+
this.app = appName;
|
|
15
|
+
this.domain = process.env.DOMAIN || '';
|
|
16
|
+
this.payment_select = payment_select;
|
|
17
|
+
if (!process.env.DOMAIN)
|
|
18
|
+
console.warn('DOMAIN environment variable is not set! Using default.');
|
|
19
|
+
}
|
|
20
|
+
async createInstance() {
|
|
21
|
+
var _a;
|
|
22
|
+
console.info('執行 createInstance 載入金流資料...');
|
|
23
|
+
const keyData = (await private_config_1.Private_config.getConfig({
|
|
24
|
+
appName: this.app,
|
|
25
|
+
key: 'glitter_finance',
|
|
26
|
+
}))[0].value;
|
|
27
|
+
if (keyData) {
|
|
28
|
+
this.kd = (_a = keyData[this.payment_select]) !== null && _a !== void 0 ? _a : {
|
|
29
|
+
ReturnURL: '',
|
|
30
|
+
NotifyURL: '',
|
|
31
|
+
};
|
|
32
|
+
console.log('金流資料載入完成 。');
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
console.log('金流資料載入錯誤 。');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async processPayment(carData, return_url, payment_select) {
|
|
39
|
+
if (!this.kd) {
|
|
40
|
+
await this.createInstance();
|
|
41
|
+
}
|
|
42
|
+
if (!this.kd) {
|
|
43
|
+
console.error('無法載入支付金鑰資料 (keyData)。');
|
|
44
|
+
return { error: '無法載入支付金鑰資料,請聯繫管理員。' };
|
|
45
|
+
}
|
|
46
|
+
const id = 'redirect_' + tool_js_1.default.randomString(6);
|
|
47
|
+
const redirect_url = new URL(return_url);
|
|
48
|
+
redirect_url.searchParams.set('cart_token', carData.orderID);
|
|
49
|
+
await redis_js_1.default.setValue(id, redirect_url.href);
|
|
50
|
+
const strategy = this.paymentStrategies.get(payment_select);
|
|
51
|
+
if (!strategy) {
|
|
52
|
+
console.warn(`找不到支付方式 "${payment_select}" 的處理策略,將使用預設線下處理。`);
|
|
53
|
+
const offlineStrategy = this.paymentStrategies.get('off_line');
|
|
54
|
+
if (offlineStrategy) {
|
|
55
|
+
const offlineConfig = {
|
|
56
|
+
app: this.app,
|
|
57
|
+
id: id,
|
|
58
|
+
domain: this.domain,
|
|
59
|
+
};
|
|
60
|
+
return await offlineStrategy.initiatePayment(carData, offlineConfig);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.error(`不支援的支付方式: ${payment_select},且找不到預設處理方式。`);
|
|
64
|
+
return { error: `不支援的支付方式: ${payment_select}` };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const config = {
|
|
68
|
+
app: this.app,
|
|
69
|
+
id: id,
|
|
70
|
+
domain: this.domain,
|
|
71
|
+
};
|
|
72
|
+
try {
|
|
73
|
+
return await strategy.initiatePayment(carData, config);
|
|
74
|
+
}
|
|
75
|
+
catch (paymentError) {
|
|
76
|
+
console.error(`支付方式 "${payment_select}" 處理失敗:`, paymentError);
|
|
77
|
+
const errorMessage = paymentError instanceof Error ? paymentError.message : String(paymentError);
|
|
78
|
+
return { error: `支付處理失敗: ${errorMessage}` };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.PaymentService = PaymentService;
|
|
83
|
+
//# sourceMappingURL=payment-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-service.js","sourceRoot":"","sources":["payment-service.ts"],"names":[],"mappings":";;;;;;AAGA,sEAA2C;AAC3C,oEAAyC;AACzC,kEAA+D;AAG/D,MAAa,cAAc;IAMzB,YACU,iBAAgD,EACxD,OAAe,EACf,cAAsB;QAFd,sBAAiB,GAAjB,iBAAiB,CAA+B;QAIxD,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC;QAEnB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC;QACvC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM;YAAE,OAAO,CAAC,IAAI,CAAC,wDAAwD,CAAC,CAAC;IAClG,CAAC;IAGO,KAAK,CAAC,cAAc;;QAC1B,OAAO,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;QAC5C,MAAM,OAAO,GAAG,CACd,MAAM,+BAAc,CAAC,SAAS,CAAC;YAC7B,OAAO,EAAE,IAAI,CAAC,GAAG;YACjB,GAAG,EAAE,iBAAiB;SACvB,CAAC,CACH,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACX,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,EAAE,GAAG,MAAA,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,mCAAI;gBACxC,SAAS,EAAE,EAAE;gBACb,SAAS,EAAE,EAAE;aACd,CAAC;YACF,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAC5B,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IASD,KAAK,CAAC,cAAc,CAAC,OAAa,EAAE,UAAkB,EAAE,cAAsB;QAE5E,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;QAC9B,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;YACvC,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAE,CAAC;QACzC,CAAC;QAID,MAAM,EAAE,GAAG,WAAW,GAAG,iBAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QAE9C,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;QACzC,YAAY,CAAC,YAAY,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAC7D,MAAM,kBAAK,CAAC,QAAQ,CAAC,EAAE,EAAE,YAAY,CAAC,IAAI,CAAC,CAAC;QAG5C,MAAM,QAAQ,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAG5D,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,CAAC,IAAI,CAAC,YAAY,cAAc,oBAAoB,CAAC,CAAC;YAC7D,MAAM,eAAe,GAAG,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC/D,IAAI,eAAe,EAAE,CAAC;gBACpB,MAAM,aAAa,GAAkB;oBACnC,GAAG,EAAE,IAAI,CAAC,GAAG;oBACb,EAAE,EAAE,EAAE;oBACN,MAAM,EAAE,IAAI,CAAC,MAAM;iBACpB,CAAC;gBAEF,OAAO,MAAM,eAAe,CAAC,eAAe,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;YACvE,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,aAAa,cAAc,cAAc,CAAC,CAAC;gBACzD,OAAO,EAAE,KAAK,EAAE,aAAa,cAAc,EAAE,EAAE,CAAC;YAClD,CAAC;QACH,CAAC;QAGD,MAAM,MAAM,GAAkB;YAC5B,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,EAAE,EAAE,EAAE;YACN,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC;QAKF,IAAI,CAAC;YACH,OAAO,MAAM,QAAQ,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACzD,CAAC;QAAC,OAAO,YAAY,EAAE,CAAC;YACtB,OAAO,CAAC,KAAK,CAAC,SAAS,cAAc,SAAS,EAAE,YAAY,CAAC,CAAC;YAC9D,MAAM,YAAY,GAAG,YAAY,YAAY,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YACjG,OAAO,EAAE,KAAK,EAAE,WAAW,YAAY,EAAE,EAAE,CAAC;QAC9C,CAAC;IACH,CAAC;CACF;AAvGD,wCAuGC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { IPaymentStrategy, PaymentConfig, PaymentResult } from './interface/payment-strategy-interface.js';
|
|
2
|
+
import { KeyData } from './financial-serviceV2.js';
|
|
3
|
+
import { Cart } from './shopping.js';
|
|
4
|
+
import redis from '../../modules/redis.js';
|
|
5
|
+
import Tool from '../../modules/tool.js';
|
|
6
|
+
import { Private_config } from '../../services/private_config';
|
|
7
|
+
import { OrderEvent } from './order-event';
|
|
8
|
+
|
|
9
|
+
export class PaymentService {
|
|
10
|
+
private kd: KeyData | undefined; // KeyData 型別來自 interface 檔案
|
|
11
|
+
private app: string;
|
|
12
|
+
private domain: string;
|
|
13
|
+
private payment_select: string;
|
|
14
|
+
// **** 依賴注入:透過建構子傳入所有可用的策略 Map ****
|
|
15
|
+
constructor(
|
|
16
|
+
private paymentStrategies: Map<string, IPaymentStrategy>,
|
|
17
|
+
appName: string,
|
|
18
|
+
payment_select: string
|
|
19
|
+
) {
|
|
20
|
+
this.paymentStrategies = paymentStrategies;
|
|
21
|
+
this.app = appName;
|
|
22
|
+
// 實際應用中 DOMAIN 應來自環境變數
|
|
23
|
+
this.domain = process.env.DOMAIN || ''; //
|
|
24
|
+
this.payment_select = payment_select;
|
|
25
|
+
if (!process.env.DOMAIN) console.warn('DOMAIN environment variable is not set! Using default.');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 載入 keyData 的方法
|
|
29
|
+
private async createInstance() {
|
|
30
|
+
console.info('執行 createInstance 載入金流資料...');
|
|
31
|
+
const keyData = (
|
|
32
|
+
await Private_config.getConfig({
|
|
33
|
+
appName: this.app,
|
|
34
|
+
key: 'glitter_finance',
|
|
35
|
+
})
|
|
36
|
+
)[0].value;
|
|
37
|
+
if (keyData) {
|
|
38
|
+
this.kd = keyData[this.payment_select] ?? {
|
|
39
|
+
ReturnURL: '',
|
|
40
|
+
NotifyURL: '',
|
|
41
|
+
};
|
|
42
|
+
console.log('金流資料載入完成 。');
|
|
43
|
+
} else {
|
|
44
|
+
console.log('金流資料載入錯誤 。');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 處理支付流程(重構後)
|
|
50
|
+
* @param carData 訂單/購物車資料
|
|
51
|
+
* @param return_url
|
|
52
|
+
* @param payment_select 使用者選擇的支付方式 key (例如 'ecPay', 'line_pay')
|
|
53
|
+
* @returns 標準化的支付結果 PaymentResult
|
|
54
|
+
*/
|
|
55
|
+
async processPayment(carData: Cart, return_url: string, payment_select: string): Promise<PaymentResult> {
|
|
56
|
+
// 1. 確保 keyData 已載入
|
|
57
|
+
if (!this.kd) {
|
|
58
|
+
await this.createInstance();
|
|
59
|
+
}
|
|
60
|
+
if (!this.kd) {
|
|
61
|
+
console.error('無法載入支付金鑰資料 (keyData)。');
|
|
62
|
+
return { error: '無法載入支付金鑰資料,請聯繫管理員。' }; // 回傳錯誤結果
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 2. 產生並儲存 Redis ID 並且把前端指定的return_url塞進去
|
|
66
|
+
// Generate notify redirect id
|
|
67
|
+
const id = 'redirect_' + Tool.randomString(6);
|
|
68
|
+
//前端希望跳轉的頁面
|
|
69
|
+
const redirect_url = new URL(return_url);
|
|
70
|
+
redirect_url.searchParams.set('cart_token', carData.orderID);
|
|
71
|
+
await redis.setValue(id, redirect_url.href);
|
|
72
|
+
|
|
73
|
+
// 3. 從注入的 Map 中查找對應的策略物件
|
|
74
|
+
const strategy = this.paymentStrategies.get(payment_select);
|
|
75
|
+
|
|
76
|
+
// 4. 如果找不到策略,處理預設情況或錯誤
|
|
77
|
+
if (!strategy) {
|
|
78
|
+
console.warn(`找不到支付方式 "${payment_select}" 的處理策略,將使用預設線下處理。`);
|
|
79
|
+
const offlineStrategy = this.paymentStrategies.get('off_line');
|
|
80
|
+
if (offlineStrategy) {
|
|
81
|
+
const offlineConfig: PaymentConfig = {
|
|
82
|
+
app: this.app,
|
|
83
|
+
id: id,
|
|
84
|
+
domain: this.domain,
|
|
85
|
+
};
|
|
86
|
+
// 委派給線下策略
|
|
87
|
+
return await offlineStrategy.initiatePayment(carData, offlineConfig);
|
|
88
|
+
} else {
|
|
89
|
+
console.error(`不支援的支付方式: ${payment_select},且找不到預設處理方式。`);
|
|
90
|
+
return { error: `不支援的支付方式: ${payment_select}` };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 5. 準備通用的設定物件傳給策略
|
|
95
|
+
const config: PaymentConfig = {
|
|
96
|
+
app: this.app,
|
|
97
|
+
id: id,
|
|
98
|
+
domain: this.domain,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
// 6. 呼叫選中策略的 initiatePayment 方法,並回傳結果
|
|
104
|
+
try {
|
|
105
|
+
return await strategy.initiatePayment(carData, config);
|
|
106
|
+
} catch (paymentError) {
|
|
107
|
+
console.error(`支付方式 "${payment_select}" 處理失敗:`, paymentError);
|
|
108
|
+
const errorMessage = paymentError instanceof Error ? paymentError.message : String(paymentError);
|
|
109
|
+
return { error: `支付處理失敗: ${errorMessage}` };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -374,7 +374,7 @@ export declare class Shopping {
|
|
|
374
374
|
value: string;
|
|
375
375
|
}[], value: number | string): number;
|
|
376
376
|
getShipmentFee(user_info: any, lineItems: CartItem[], shipment: any): number;
|
|
377
|
-
repayOrder(orderID: string, return_url: string): Promise<
|
|
377
|
+
repayOrder(orderID: string, return_url: string): Promise<import("./interface/payment-strategy-interface.js").PaymentResult | undefined>;
|
|
378
378
|
getReturnOrder(query: {
|
|
379
379
|
page: number;
|
|
380
380
|
limit: number;
|
|
@@ -522,6 +522,7 @@ export declare class Shopping {
|
|
|
522
522
|
sortCollection(data: Collection[]): Promise<boolean>;
|
|
523
523
|
checkVariantDataType(variants: any[]): void;
|
|
524
524
|
postProduct(content: any): Promise<any>;
|
|
525
|
+
removeLogisticGroup(group_key: string): Promise<boolean>;
|
|
525
526
|
updateCollectionFromUpdateProduct(collection: string[]): Promise<void>;
|
|
526
527
|
postMulProduct(content: any): Promise<any>;
|
|
527
528
|
promisesProducts(productArray: any, insertIDStart: any): Promise<void>;
|
|
@@ -10,6 +10,7 @@ const express_1 = __importDefault(require("express"));
|
|
|
10
10
|
const moment_1 = __importDefault(require("moment"));
|
|
11
11
|
const axios_1 = __importDefault(require("axios"));
|
|
12
12
|
const app_1 = __importDefault(require("../../app"));
|
|
13
|
+
const redis_js_1 = __importDefault(require("../../modules/redis.js"));
|
|
13
14
|
const tool_js_1 = __importDefault(require("../../modules/tool.js"));
|
|
14
15
|
const financial_service_js_1 = require("./financial-service.js");
|
|
15
16
|
const private_config_js_1 = require("../../services/private_config.js");
|
|
@@ -34,8 +35,9 @@ const checkout_js_1 = require("./checkout.js");
|
|
|
34
35
|
const product_initial_js_1 = require("./product-initial.js");
|
|
35
36
|
const ut_timer_js_1 = require("../utils/ut-timer.js");
|
|
36
37
|
const auto_fcm_js_1 = require("../../public-config-initial/auto-fcm.js");
|
|
37
|
-
const handlePaymentTransaction_js_1 = __importDefault(require("./model/handlePaymentTransaction.js"));
|
|
38
38
|
const Language_js_1 = require("../../Language.js");
|
|
39
|
+
const payment_strategy_factory_js_1 = require("./factories/payment-strategy-factory.js");
|
|
40
|
+
const payment_service_js_1 = require("./payment-service.js");
|
|
39
41
|
const checkout_event_js_1 = require("./checkout-event.js");
|
|
40
42
|
class OrderDetail {
|
|
41
43
|
constructor(subtotal, shipment) {
|
|
@@ -1355,7 +1357,7 @@ class Shopping {
|
|
|
1355
1357
|
return (this.calculateShipment(shipment.volume, total_volume) + this.calculateShipment(shipment.weight, total_weight));
|
|
1356
1358
|
}
|
|
1357
1359
|
async repayOrder(orderID, return_url) {
|
|
1358
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o
|
|
1360
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
1359
1361
|
const app = this.app;
|
|
1360
1362
|
async function getOrder(orderID) {
|
|
1361
1363
|
try {
|
|
@@ -1398,21 +1400,17 @@ class Shopping {
|
|
|
1398
1400
|
return [];
|
|
1399
1401
|
}
|
|
1400
1402
|
})();
|
|
1401
|
-
|
|
1402
|
-
ReturnURL: '',
|
|
1403
|
-
NotifyURL: '',
|
|
1404
|
-
};
|
|
1405
|
-
const newOrderID = Date.now();
|
|
1403
|
+
const newOrderID = 'repay' + Date.now();
|
|
1406
1404
|
const carData = {
|
|
1407
1405
|
orderID: `${newOrderID}`,
|
|
1408
|
-
discount: (
|
|
1406
|
+
discount: (_a = orderData.discount) !== null && _a !== void 0 ? _a : 0,
|
|
1409
1407
|
customer_info: orderData.customer_info || {},
|
|
1410
|
-
lineItems: (
|
|
1411
|
-
total: (
|
|
1412
|
-
email: (
|
|
1408
|
+
lineItems: (_b = orderData.lineItems) !== null && _b !== void 0 ? _b : [],
|
|
1409
|
+
total: (_c = orderData.total) !== null && _c !== void 0 ? _c : 0,
|
|
1410
|
+
email: (_f = (_d = sqlData.email) !== null && _d !== void 0 ? _d : (_e = orderData.user_info) === null || _e === void 0 ? void 0 : _e.email) !== null && _f !== void 0 ? _f : '',
|
|
1413
1411
|
user_info: orderData.user_info,
|
|
1414
|
-
shipment_fee: (
|
|
1415
|
-
rebate: (
|
|
1412
|
+
shipment_fee: (_g = orderData.shipment_fee) !== null && _g !== void 0 ? _g : 0,
|
|
1413
|
+
rebate: (_h = orderData.rebate) !== null && _h !== void 0 ? _h : 0,
|
|
1416
1414
|
goodsWeight: 0,
|
|
1417
1415
|
use_rebate: orderData.use_rebate || 0,
|
|
1418
1416
|
shipment_support: shipment_setting.support,
|
|
@@ -1422,7 +1420,7 @@ class Shopping {
|
|
|
1422
1420
|
name: dd.title,
|
|
1423
1421
|
value: dd.value,
|
|
1424
1422
|
})),
|
|
1425
|
-
...((
|
|
1423
|
+
...((_j = shipment_setting.custom_delivery) !== null && _j !== void 0 ? _j : []).map((dd) => ({
|
|
1426
1424
|
form: dd.form,
|
|
1427
1425
|
name: dd.name,
|
|
1428
1426
|
value: dd.id,
|
|
@@ -1430,8 +1428,8 @@ class Shopping {
|
|
|
1430
1428
|
})),
|
|
1431
1429
|
].filter(option => shipment_setting.support.includes(option.value)),
|
|
1432
1430
|
use_wallet: 0,
|
|
1433
|
-
method: (
|
|
1434
|
-
user_email: (
|
|
1431
|
+
method: (_k = sqlData.user_info) === null || _k === void 0 ? void 0 : _k.method,
|
|
1432
|
+
user_email: (_o = (_l = sqlData.email) !== null && _l !== void 0 ? _l : (_m = orderData.user_info) === null || _m === void 0 ? void 0 : _m.email) !== null && _o !== void 0 ? _o : '',
|
|
1435
1433
|
useRebateInfo: sqlData.useRebateInfo,
|
|
1436
1434
|
custom_form_format: sqlData.custom_form_format,
|
|
1437
1435
|
custom_form_data: sqlData.custom_form_data,
|
|
@@ -1447,13 +1445,19 @@ class Shopping {
|
|
|
1447
1445
|
fbp: sqlData.fbp,
|
|
1448
1446
|
editRecord: [],
|
|
1449
1447
|
};
|
|
1450
|
-
await
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1448
|
+
await redis_js_1.default.setValue(newOrderID, `${orderData.orderID}`);
|
|
1449
|
+
const strategyFactory = new payment_strategy_factory_js_1.PaymentStrategyFactory(keyData);
|
|
1450
|
+
const allPaymentStrategies = strategyFactory.createStrategyRegistry();
|
|
1451
|
+
const appName = this.app;
|
|
1452
|
+
const paymentService = new payment_service_js_1.PaymentService(allPaymentStrategies, appName, carData.customer_info.payment_select);
|
|
1453
|
+
try {
|
|
1454
|
+
const paymentResult = await paymentService.processPayment(carData, return_url, carData.customer_info.payment_select);
|
|
1455
|
+
console.log("Controller 收到 Payment Result:", paymentResult);
|
|
1456
|
+
return paymentResult;
|
|
1457
|
+
}
|
|
1458
|
+
catch (error) {
|
|
1459
|
+
console.error("Controller 捕獲到錯誤:", error);
|
|
1460
|
+
}
|
|
1457
1461
|
}
|
|
1458
1462
|
}
|
|
1459
1463
|
async getReturnOrder(query) {
|
|
@@ -3650,6 +3654,39 @@ class Shopping {
|
|
|
3650
3654
|
throw exception_js_1.default.BadRequestError('BAD_REQUEST', 'postProduct Error:' + e, null);
|
|
3651
3655
|
}
|
|
3652
3656
|
}
|
|
3657
|
+
async removeLogisticGroup(group_key) {
|
|
3658
|
+
try {
|
|
3659
|
+
const getProducts = await database_js_1.default.query(`SELECT * FROM \`${this.app}\`.t_manager_post
|
|
3660
|
+
WHERE JSON_CONTAINS(JSON_EXTRACT(content, '$.designated_logistics.group'), JSON_QUOTE(?))`, [group_key]);
|
|
3661
|
+
const chunk = 10;
|
|
3662
|
+
const chunkLength = Math.ceil(getProducts.length / chunk);
|
|
3663
|
+
for (let i = 0; i < chunkLength; i++) {
|
|
3664
|
+
const promisesArray = getProducts.slice(i * chunk, (i + 1) * chunk);
|
|
3665
|
+
setTimeout(async () => {
|
|
3666
|
+
await Promise.all(promisesArray.map(async (product) => {
|
|
3667
|
+
product.content.designated_logistics.group = product.content.designated_logistics.group.filter((item) => {
|
|
3668
|
+
return item !== group_key;
|
|
3669
|
+
});
|
|
3670
|
+
if (product.content.designated_logistics.group.length === 0) {
|
|
3671
|
+
delete product.content.designated_logistics.group;
|
|
3672
|
+
product.content.designated_logistics.type = 'all';
|
|
3673
|
+
}
|
|
3674
|
+
await database_js_1.default.query(`UPDATE \`${this.app}\`.\`t_manager_post\` SET ? WHERE id = ?`, [
|
|
3675
|
+
{
|
|
3676
|
+
content: JSON.stringify(product.content),
|
|
3677
|
+
},
|
|
3678
|
+
product.id,
|
|
3679
|
+
]);
|
|
3680
|
+
}));
|
|
3681
|
+
}, 200);
|
|
3682
|
+
}
|
|
3683
|
+
return true;
|
|
3684
|
+
}
|
|
3685
|
+
catch (e) {
|
|
3686
|
+
console.error(e);
|
|
3687
|
+
throw exception_js_1.default.BadRequestError('BAD_REQUEST', 'removeLogisticGroup Error:' + e, null);
|
|
3688
|
+
}
|
|
3689
|
+
}
|
|
3653
3690
|
async updateCollectionFromUpdateProduct(collection) {
|
|
3654
3691
|
var _a;
|
|
3655
3692
|
collection = Array.from(new Set(collection.map(dd => {
|