Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pos-intercept-payment-validations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/ui-extensions': minor
---

Add `paymentvalidations` intercept types for POS payment blocking workflows, and rename the `beforecheckout` intercept to `cartvalidations` so both interceptable workflows follow one naming scheme.
49 changes: 45 additions & 4 deletions packages/ui-extensions/src/surfaces/point-of-sale/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
CashTrackingSessionCompleteEvent,
} from './events/cash-tracking-session-events';
import type {Cart} from './types/cart';
import type {MoneyV2} from './types/money';

/**
* Canonical event-name constants for POS host events. Prefer these over string
Expand All @@ -24,7 +25,8 @@ export const POS_EVENT_NAMES = {
* @private
*/
export const POS_INTERCEPT_NAMES = {
BEFORE_CHECKOUT: 'beforecheckout',
CART_VALIDATIONS: 'cartvalidations',
PAYMENT_VALIDATIONS: 'paymentvalidations',
} as const;

/**
Expand Down Expand Up @@ -55,20 +57,59 @@ export interface ShopifyEventMap {
* @private
*/
export interface ShopifyInterceptMap {
[POS_INTERCEPT_NAMES.BEFORE_CHECKOUT]: BeforeCheckoutEvent;
[POS_INTERCEPT_NAMES.CART_VALIDATIONS]: CartValidationsEvent;
[POS_INTERCEPT_NAMES.PAYMENT_VALIDATIONS]: PaymentValidationsEvent;
}

/**
* Dispatched when staff attempts to leave the active cart for checkout.
*
* @private
*/
export interface BeforeCheckoutEvent extends Event {
readonly type: typeof POS_INTERCEPT_NAMES.BEFORE_CHECKOUT;
export interface CartValidationsEvent extends Event {
readonly type: typeof POS_INTERCEPT_NAMES.CART_VALIDATIONS;
/** The POS cart at the point checkout was requested. */
readonly cart: Cart;
}

/**
* The kind of payment method being attempted.
*
* @private
*/
export type InterceptedPaymentMethodType = 'cash';

/**
* Identifies the payment method being attempted.
*
* `type` alone identifies singleton methods (for example `cash`). `identifier`
* disambiguates method types a shop can have several of (for example custom
* payment methods) as they become interceptable.
*
* @private
*/
export interface InterceptedPaymentMethod {
readonly type: InterceptedPaymentMethodType;

/** Present when `type` alone is ambiguous. Matching is exact on the pair. */
readonly identifier?: string;
}

/**
* Dispatched when staff selects a payment method on the payments screen.
*
* @private
*/
export interface PaymentValidationsEvent extends Event {
readonly type: typeof POS_INTERCEPT_NAMES.PAYMENT_VALIDATIONS;

/** The payment method staff selected. */
readonly paymentMethod: InterceptedPaymentMethod;

/** The amount this tender would charge, in presentment currency. */
readonly amount: MoneyV2;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add transactionId

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reversed after discussion — dropping transactionId from v1. The host cannot guarantee an id at selection time (Transaction.id?), so the field would be unreliable at exactly the moment it dispatches; payload stays paymentMethod + amount. Can revisit if a concrete correlation need lands.

}

/** @private */
export type ShopifyInterceptor<TEvent extends Event> = (
event: TEvent,
Expand Down
Loading