@final-commerce/command-frame 0.3.2-preprod.1 → 0.4.1-preprod.1
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/README.md +47 -50
- package/dist/actions/apply-transition/mock.d.ts +1 -1
- package/dist/actions/apply-transition/mock.js +8 -18
- package/dist/actions/apply-transition/types.d.ts +6 -4
- package/dist/actions/extension-payment/types.d.ts +2 -2
- package/dist/actions/get-available-transitions/mock.d.ts +5 -3
- package/dist/actions/get-available-transitions/mock.js +24 -12
- package/dist/actions/get-refund-plan/action.d.ts +6 -0
- package/dist/actions/get-refund-plan/action.js +8 -0
- package/dist/actions/get-refund-plan/mock.d.ts +14 -0
- package/dist/actions/get-refund-plan/mock.js +59 -0
- package/dist/actions/get-refund-plan/types.d.ts +32 -0
- package/dist/actions/get-refund-plan/types.js +7 -0
- package/dist/actions/integration-payment/types.d.ts +2 -0
- package/dist/actions/partial-payment/types.d.ts +2 -2
- package/dist/actions/process-partial-refund/mock.js +9 -1
- package/dist/actions/process-partial-refund/types.d.ts +99 -1
- package/dist/actions/redeem-payment/types.d.ts +2 -0
- package/dist/actions/redeem-refund/action.d.ts +6 -0
- package/dist/actions/redeem-refund/action.js +8 -0
- package/dist/actions/redeem-refund/mock.d.ts +2 -0
- package/dist/actions/redeem-refund/mock.js +59 -0
- package/dist/actions/redeem-refund/types.d.ts +39 -0
- package/dist/actions/redeem-refund/types.js +2 -0
- package/dist/actions/terminal-payment/types.d.ts +3 -3
- package/dist/demo/database.d.ts +2 -2
- package/dist/demo/database.js +271 -264
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/projects/render/mocks.js +6 -0
- package/dist/projects/render/types.d.ts +4 -1
- package/dist/pubsub/topics/orders/index.d.ts +2 -2
- package/dist/pubsub/topics/orders/index.js +27 -27
- package/dist/pubsub/topics/orders/types.d.ts +15 -15
- package/dist/pubsub/topics/orders/types.js +7 -7
- package/package.json +1 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { MOCK_ORDERS, mockPublishEvent } from '../../demo/database';
|
|
2
|
+
// Payment states in which an order is refundable
|
|
3
|
+
const REFUNDABLE_PAYMENT_STATES = ['paid', 'partially_refunded'];
|
|
4
|
+
// Track refunded amounts per order to enforce remaining capacity gate
|
|
5
|
+
const mockRefundedAmounts = {};
|
|
6
|
+
export const mockRedeemRefund = async (params) => {
|
|
7
|
+
console.log('[Mock] redeemRefund called', params);
|
|
8
|
+
// Validate required params
|
|
9
|
+
if (!params.amount || params.amount <= 0) {
|
|
10
|
+
throw new Error('Amount must be greater than 0');
|
|
11
|
+
}
|
|
12
|
+
if (!params.referenceId) {
|
|
13
|
+
throw new Error('referenceId is required');
|
|
14
|
+
}
|
|
15
|
+
// Find order
|
|
16
|
+
const order = params.orderId ? MOCK_ORDERS.find((o) => o._id === params.orderId) : MOCK_ORDERS[0];
|
|
17
|
+
if (!order) {
|
|
18
|
+
throw new Error(`Order with ID ${params.orderId} not found`);
|
|
19
|
+
}
|
|
20
|
+
const orderId = order._id;
|
|
21
|
+
// Check if order is in a refundable state
|
|
22
|
+
if (!REFUNDABLE_PAYMENT_STATES.includes(order.paymentState)) {
|
|
23
|
+
throw new Error(`ORDER_NOT_REFUNDABLE: order ${orderId} is '${order.paymentState}' — only 'paid' or 'partially_refunded' orders can be refunded`);
|
|
24
|
+
}
|
|
25
|
+
// Track refunded amounts and check remaining capacity
|
|
26
|
+
const refundedSoFar = mockRefundedAmounts[orderId] || 0;
|
|
27
|
+
const remainingCapacity = order.summary.total - refundedSoFar;
|
|
28
|
+
if (params.amount > remainingCapacity) {
|
|
29
|
+
throw new Error(`REFUND_AMOUNT_EXCEEDS_CAPACITY: Refund amount ${params.amount} exceeds remaining refundable capacity ${remainingCapacity}`);
|
|
30
|
+
}
|
|
31
|
+
// Update refunded amount tracking
|
|
32
|
+
const refundedAfter = refundedSoFar + params.amount;
|
|
33
|
+
mockRefundedAmounts[orderId] = refundedAfter;
|
|
34
|
+
// Update order state based on remaining capacity after this refund
|
|
35
|
+
const remainingAfterRefund = order.summary.total - refundedAfter;
|
|
36
|
+
if (remainingAfterRefund > 0) {
|
|
37
|
+
order.paymentState = 'partially_refunded';
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
order.paymentState = 'refunded';
|
|
41
|
+
}
|
|
42
|
+
// Publish refund event
|
|
43
|
+
mockPublishEvent('refunds', 'refund-created', {
|
|
44
|
+
orderId,
|
|
45
|
+
amount: params.amount,
|
|
46
|
+
referenceId: params.referenceId,
|
|
47
|
+
processor: params.processor || 'giftCard',
|
|
48
|
+
label: params.label,
|
|
49
|
+
reason: params.reason,
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
success: true,
|
|
53
|
+
orderId,
|
|
54
|
+
amount: params.amount,
|
|
55
|
+
referenceId: params.referenceId,
|
|
56
|
+
legCount: 1,
|
|
57
|
+
timestamp: new Date().toISOString(),
|
|
58
|
+
};
|
|
59
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface RedeemRefundParams {
|
|
2
|
+
/** Order to refund; defaults to the active order. */
|
|
3
|
+
orderId?: string;
|
|
4
|
+
/**
|
|
5
|
+
* Amount to refund onto the redeem tender, integer MINOR currency units
|
|
6
|
+
* (1575 = $15.75). Required; must be > 0 and within the order's remaining
|
|
7
|
+
* refundable capacity (tip-inclusive, across all source payments).
|
|
8
|
+
*/
|
|
9
|
+
amount: number;
|
|
10
|
+
/**
|
|
11
|
+
* Destination card/account identifier the funds were credited to
|
|
12
|
+
* (e.g. the gift-card number). Recorded in the emv block (`'Card Number'`)
|
|
13
|
+
* of every refund payment entry on the order, and in paymentData on the
|
|
14
|
+
* local transaction rows, for the audit trail. Required.
|
|
15
|
+
*/
|
|
16
|
+
referenceId: string;
|
|
17
|
+
/** Destination provider label; defaults to "giftCard" (matches redeemPayment). */
|
|
18
|
+
processor?: string;
|
|
19
|
+
/** Human-readable label for receipts/reporting. */
|
|
20
|
+
label?: string;
|
|
21
|
+
/** Extension identity, recorded on the legs when provided. */
|
|
22
|
+
extensionId?: string;
|
|
23
|
+
/** Opaque extension payload, recorded on the legs when provided. */
|
|
24
|
+
metadata?: Record<string, unknown>;
|
|
25
|
+
/** Cashier-facing reason, recorded on the refund + state-event audit rows. */
|
|
26
|
+
reason?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface RedeemRefundResponse {
|
|
29
|
+
success: boolean;
|
|
30
|
+
orderId: string;
|
|
31
|
+
/** Total refunded onto the redeem tender (minor units). */
|
|
32
|
+
amount: number;
|
|
33
|
+
/** Echo of the destination identifier the legs were recorded against. */
|
|
34
|
+
referenceId: string;
|
|
35
|
+
/** Number of source payments the amount was drawn from. */
|
|
36
|
+
legCount: number;
|
|
37
|
+
timestamp: string;
|
|
38
|
+
}
|
|
39
|
+
export type RedeemRefund = (params: RedeemRefundParams) => Promise<RedeemRefundResponse>;
|
|
@@ -12,9 +12,9 @@ export interface TerminalPaymentParams {
|
|
|
12
12
|
*/
|
|
13
13
|
amount: number;
|
|
14
14
|
/** "Bluetooth" or "Cloud". Defaults to "Cloud". */
|
|
15
|
-
paymentType?:
|
|
16
|
-
/** Override the fulfillment
|
|
17
|
-
|
|
15
|
+
paymentType?: "Bluetooth" | "Cloud";
|
|
16
|
+
/** Override the fulfillment landing on full payment. Omitted: preserve advanced fulfillment, auto-fulfill from draft/pending/on_hold. */
|
|
17
|
+
targetFulfillmentState?: string;
|
|
18
18
|
}
|
|
19
19
|
export interface TerminalPaymentResponse {
|
|
20
20
|
success: boolean;
|
package/dist/demo/database.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Mock Database for Standalone/Demo Mode
|
|
3
3
|
* Stores mock data that mimics the Render environment
|
|
4
4
|
*/
|
|
5
|
-
import { CFActiveCompany, CFActiveUser, CFActiveStation, CFActiveOutlet, CFActiveOrder, CFCustomer, CFProduct, CFActiveCart, CFCategory, CFActiveProduct, CFSession, CFActiveRefundDetails, CFSmartGridLayout } from
|
|
6
|
-
export * from
|
|
5
|
+
import { CFActiveCompany, CFActiveUser, CFActiveStation, CFActiveOutlet, CFActiveOrder, CFCustomer, CFProduct, CFActiveCart, CFCategory, CFActiveProduct, CFSession, CFActiveRefundDetails, CFSmartGridLayout } from '../CommonTypes';
|
|
6
|
+
export * from './mocks';
|
|
7
7
|
/** Replace mock catalog / context data in place (same array references mock handlers use). */
|
|
8
8
|
export interface MockDatabaseConfig {
|
|
9
9
|
company?: Partial<CFActiveCompany>;
|