@final-commerce/command-frame 0.11.1-preprod.1 → 0.11.1-preprod.3

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.
@@ -1,5 +1,7 @@
1
1
  /** The shopper-facing vocabulary: never the platform's payment / fulfilment states. */
2
2
  export type CheckoutOrderStatus = 'awaiting_payment' | 'confirming' | 'payment_failed' | 'paid' | 'fulfilled' | 'partially_refunded' | 'refunded' | 'cancelled';
3
+ /** Why the server cancelled an order the shopper paid for. */
4
+ export type CheckoutCancelReason = 'sold_out';
3
5
  export interface GetCheckoutStatusParams {
4
6
  /**
5
7
  * The receipt `startCheckout` returned, to name which order. Omitted: the checkout in flight,
@@ -13,6 +15,11 @@ export interface GetCheckoutStatusResponse {
13
15
  status: CheckoutOrderStatus | null;
14
16
  /** True once the money is in: `paid`, `fulfilled`, or refunded since. */
15
17
  paid: boolean;
18
+ /**
19
+ * Why a `cancelled` order was cancelled, when the server cancelled it. `sold_out`: the stock ran out
20
+ * before the payment was captured, so the payment was released and nothing was charged.
21
+ */
22
+ cancelReason?: CheckoutCancelReason;
16
23
  receiptId: string | null;
17
24
  timestamp: string;
18
25
  }
@@ -19,11 +19,16 @@ export const mockRecordExternalPayment = async (params) => {
19
19
  if (amount > balanceDue) {
20
20
  throw new Error(`recordExternalPayment: amount ${amount} exceeds the balance due ${balanceDue}`);
21
21
  }
22
+ const tip = params.tip?.amount ?? 0;
23
+ if (params.tip !== undefined && (!Number.isInteger(tip) || tip <= 0)) {
24
+ throw new Error('recordExternalPayment: tip.amount must be a positive integer (minor units)');
25
+ }
22
26
  const order = applyMockPayment(amount, 'external', label);
23
27
  const remainingBalance = MOCK_CART.remainingBalance ?? 0;
24
28
  return {
25
29
  success: true,
26
30
  amount,
31
+ tip,
27
32
  label,
28
33
  paymentType: 'external',
29
34
  change: 0,
@@ -1,4 +1,11 @@
1
1
  import { CFOrder } from '../../CommonTypes';
2
+ /** A tip the customer already paid wherever the money was taken (the website, a delivery app). */
3
+ export interface RecordExternalPaymentTip {
4
+ /** Tip in integer MINOR currency units. Must be positive. */
5
+ amount: number;
6
+ /** User id the tip belongs to. Defaults to the cashier recording the payment. */
7
+ tipTo?: string;
8
+ }
2
9
  export interface RecordExternalPaymentParams {
3
10
  /**
4
11
  * What the payment was — shown on the order and in reports, e.g. 'Paid online',
@@ -12,13 +19,21 @@ export interface RecordExternalPaymentParams {
12
19
  * the rest can be taken with any other tender. Above the balance due is an error.
13
20
  */
14
21
  amount?: number;
22
+ /**
23
+ * Tip paid along with it. Recorded ON TOP of `amount` — it never counts toward the
24
+ * balance due — and stored on the payment like a card tip, so reports and tip-outs
25
+ * see it. Omit for no tip.
26
+ */
27
+ tip?: RecordExternalPaymentTip;
15
28
  /** Fulfillment state to land on after full payment, e.g. 'pending' to keep the order going to the kitchen. */
16
29
  checkoutFulfillmentTarget?: string;
17
30
  }
18
31
  export interface RecordExternalPaymentResponse {
19
32
  success: boolean;
20
- /** The amount recorded, in integer MINOR currency units. */
33
+ /** The amount recorded against the balance, in integer MINOR currency units. Excludes the tip. */
21
34
  amount: number;
35
+ /** The tip recorded on top of `amount`, in integer MINOR currency units; 0 when none. */
36
+ tip: number;
22
37
  /** The label, as recorded. */
23
38
  label: string;
24
39
  paymentType: 'external';
package/dist/index.d.ts CHANGED
@@ -223,7 +223,7 @@ export type { GetOrderStatuses, GetOrderStatusesResponse } from './actions/get-o
223
223
  export type { DeleteParkedOrder, DeleteParkedOrderParams, DeleteParkedOrderResponse, } from './actions/delete-parked-order/types';
224
224
  export type { VoidOrder, VoidOrderParams, VoidOrderResponse, VoidOrderOutcome } from './actions/void-order/types';
225
225
  export type { CashPayment, CashPaymentParams, CashPaymentResponse } from './actions/cash-payment/types';
226
- export type { RecordExternalPayment, RecordExternalPaymentParams, RecordExternalPaymentResponse, } from './actions/record-external-payment/types';
226
+ export type { RecordExternalPayment, RecordExternalPaymentParams, RecordExternalPaymentResponse, RecordExternalPaymentTip, } from './actions/record-external-payment/types';
227
227
  export type { GetCashRoundingAmount, GetCashRoundingAmountParams, GetCashRoundingAmountResponse, } from './actions/get-cash-rounding-amount/types';
228
228
  export type { TapToPayPayment, TapToPayPaymentParams, TapToPayPaymentResponse, } from './actions/tap-to-pay-payment/types';
229
229
  export type { TerminalPayment, TerminalPaymentParams, TerminalPaymentResponse } from './actions/terminal-payment/types';
@@ -240,7 +240,7 @@ export type { GetShippingOptions, GetShippingOptionsResponse, ShippingOptionView
240
240
  export type { SelectShippingOption, SelectShippingOptionParams, SelectShippingOptionResponse, } from './actions/select-shipping-option/types';
241
241
  export type { SetOutlet, SetOutletParams, SetOutletResponse } from './actions/set-outlet/types';
242
242
  export type { ResumeCheckout, ResumeCheckoutParams, ResumeCheckoutResponse, ResumeCheckoutResult, } from './actions/resume-checkout/types';
243
- export type { GetCheckoutStatus, GetCheckoutStatusParams, GetCheckoutStatusResponse, CheckoutOrderStatus, } from './actions/get-checkout-status/types';
243
+ export type { GetCheckoutStatus, GetCheckoutStatusParams, GetCheckoutStatusResponse, CheckoutOrderStatus, CheckoutCancelReason, } from './actions/get-checkout-status/types';
244
244
  export type { GetMotoConfig, GetMotoConfigResponse, MotoUnavailableReason } from './actions/get-moto-config/types';
245
245
  export type { AddCustomerNote, AddCustomerNoteParams, AddCustomerNoteResponse, } from './actions/add-customer-note/types';
246
246
  export type { RemoveCustomerNote, RemoveCustomerNoteParams, RemoveCustomerNoteResponse, } from './actions/remove-customer-note/types';
@@ -1,4 +1,4 @@
1
- import type { TopicEvent } from "../../../types";
1
+ import type { TopicEvent } from '../../../types';
2
2
  /**
3
3
  * Payload for payment-failed event
4
4
  *
@@ -9,7 +9,10 @@ import type { TopicEvent } from "../../../types";
9
9
  export interface PaymentFailedPayload {
10
10
  orderId: string;
11
11
  receiptId: string;
12
- /** The provider's result code, e.g. `Refused`, or an error name. */
12
+ /**
13
+ * The provider's result code, e.g. `Refused`, or an error name. `SoldOut`: the shopper pressed Pay
14
+ * and something in the cart can no longer be sold, so the card was never sent.
15
+ */
13
16
  resultCode: string;
14
17
  /** Present when the failure carried a message worth showing. */
15
18
  message?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@final-commerce/command-frame",
3
- "version": "0.11.1-preprod.1",
3
+ "version": "0.11.1-preprod.3",
4
4
  "description": "Commands Frame library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",