Skip to content
Open
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-method.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/ui-extensions': minor
---

Add `paymentmethodselected` intercept types for POS payment blocking workflows.
41 changes: 41 additions & 0 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 @@ -25,6 +26,7 @@ export const POS_EVENT_NAMES = {
*/
export const POS_INTERCEPT_NAMES = {
BEFORE_CHECKOUT: 'beforecheckout',
PAYMENT_METHOD_SELECTED: 'paymentmethodselected',
} as const;

/**
Expand Down Expand Up @@ -56,6 +58,7 @@ export interface ShopifyEventMap {
*/
export interface ShopifyInterceptMap {
[POS_INTERCEPT_NAMES.BEFORE_CHECKOUT]: BeforeCheckoutEvent;
[POS_INTERCEPT_NAMES.PAYMENT_METHOD_SELECTED]: PaymentMethodSelectedEvent;
}

/**
Expand All @@ -69,6 +72,44 @@ export interface BeforeCheckoutEvent extends Event {
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 PaymentMethodSelectedEvent extends Event {
readonly type: typeof POS_INTERCEPT_NAMES.PAYMENT_METHOD_SELECTED;

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

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

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