Skip to content

Commit

Permalink
Merge pull request #2577 from Shopify/vic/transaction-complete-types
Browse files Browse the repository at this point in the history
Add transaction complete event types
  • Loading branch information
vctrchu authored Jan 22, 2025
2 parents 9a3debd + 5074ca0 commit a3a9109
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .changeset/large-laws-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@shopify/ui-extensions': minor
'@shopify/ui-extensions-react': minor
---

Adds POS UI Extension: TransactionCompleteInput property typing and payment interfaces
4 changes: 4 additions & 0 deletions packages/ui-extensions/src/surfaces/point-of-sale/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ export type {
LineItemDiscount,
CustomSale,
Address,
ShippingLine,
TaxLine,
} from './types/cart';

export type {PaymentMethod} from './types/payment';

export type {MultipleResourceResult} from './types/multiple-resource-result';

export type {PaginatedResult} from './types/paginated-result';
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
Discount,
LineItem,
PaymentMethod,
ShippingLine,
TaxLine,
} from '../../api';
import {BaseInput} from './BaseInput';

export interface TransactionCompleteInput extends BaseInput {
transactionComplete: {
discounts: Discount[];
draftCheckoutId: number;
lineItems: LineItem[];
orderId?: number;
paymentMethods: PaymentMethod[];
shippingLines?: ShippingLine;
taxLines?: TaxLine[];
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
CashTrackingSessionCompleteInput,
CashTrackingSessionCancelInput,
} from './input/CashTrackingSessionInput';
import {PurchaseCompleteInput} from './input/PurchaseCompleteInput';
import {TransactionCompleteInput} from './input/TransactionCompleteInput';

export interface EventExtensionTargets {
'pos.transaction-complete.event.observe': (
input: PurchaseCompleteInput,
input: TransactionCompleteInput,
) => BaseIntent;
'pos.cash-tracking-session-start.event.observe': (
input: CashTrackingSessionStartInput,
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-extensions/src/surfaces/point-of-sale/input.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type {BaseInput} from './event/input/BaseInput';
export type {PurchaseCompleteInput} from './event/input/PurchaseCompleteInput';
export type {TransactionCompleteInput} from './event/input/TransactionCompleteInput';

export type {Device} from './types/device';
27 changes: 27 additions & 0 deletions packages/ui-extensions/src/surfaces/point-of-sale/types/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface LineItem {
vendor?: string;
properties: {[key: string]: string};
isGiftCard: boolean;
attributedUserId?: number;
}

export interface Discount {
Expand Down Expand Up @@ -107,3 +108,29 @@ export interface Address {
provinceCode?: string;
countryCode?: CountryCode;
}

export type ShippingLine = CalculatedShippingLine | CustomShippingLine;

export interface CalculatedShippingLine {
uuid: string;
price: string;
title: string;
methodType: 'SHIPPING' | 'RETAIL';
type: 'Calculated';
}

export interface CustomShippingLine {
uuid: string;
price: string;
title: string;
type: 'Custom';
}

export interface TaxLine {
uuid: string;
price: string;
rate: number;
rateRange?: {min: number; max: number};
title: string;
enabled: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ export interface Device {
*/
name: string;
/**
* The string ID of the device
* The ID of the device
*/
deviceId: string;
deviceId: number;
/**
* Whether the device is a tablet
*/
Expand Down
48 changes: 48 additions & 0 deletions packages/ui-extensions/src/surfaces/point-of-sale/types/payment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export type PaymentMethod =
| CashPayment
| CreditPayment
| GiftCardPayment
| ShopPayPayment
| CustomPayment
| UnknownPayment;

export type CardSource = 'manual' | 'swiped' | 'emv';

interface BasePayment {
amount: string;
}

interface CreditPayment extends BasePayment {
type: 'CreditCard';
brand: string;
tipAmount: string;
cardSource?: CardSource;
hasPendingOfflineTransactions: boolean;
}

interface CashPayment extends BasePayment {
type: 'Cash';
changeAmount: string;
roundedAmount?: string;
}

interface GiftCardPayment extends BasePayment {
type: 'GiftCard';
lastCharacters: string;
balance?: string;
}

interface ShopPayPayment extends BasePayment {
type: 'ShopPay';
isInstallmentsPayment: boolean;
orderTransactionId?: string;
}

interface CustomPayment extends BasePayment {
type: 'Custom';
name: string;
}

interface UnknownPayment extends BasePayment {
type: 'Unknown';
}

0 comments on commit a3a9109

Please sign in to comment.