Skip to content

Commit

Permalink
Separate payment interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
vctrchu committed Jan 22, 2025
1 parent 7c09700 commit 1d5f224
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 78 deletions.
3 changes: 2 additions & 1 deletion packages/ui-extensions/src/surfaces/point-of-sale/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ export type {
LineItemDiscount,
CustomSale,
Address,
PaymentMethod,
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import {
} from '../../api';
import {BaseInput} from './BaseInput';

export interface PurchaseCompleteInput extends BaseInput {
purchaseComplete: {
export interface TransactionCompleteInput extends BaseInput {
transactionComplete: {
discounts: Discount[];
draftCheckoutId: string;
draftCheckoutId: number;
lineItems: LineItem[];
orderId: string;
orderId: number;
paymentMethods: PaymentMethod[];
shippingLines: ShippingLine;
taxLines: TaxLine[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {BaseIntent} from '../intent';
import {PurchaseCompleteInput} from './input/PurchaseCompleteInput';
import {TransactionCompleteInput} from './input/TransactionCompleteInput';

export interface EventExtensionTargets {
'pos.transaction-completed.observe': (
input: PurchaseCompleteInput,
input: TransactionCompleteInput,
) => BaseIntent;
}

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';
85 changes: 15 additions & 70 deletions packages/ui-extensions/src/surfaces/point-of-sale/types/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,83 +109,28 @@ export interface Address {
countryCode?: CountryCode;
}

export type ShippingLine =
| {
handle: string;
price: string;
title: string;
methodType: ShippingMethodType;
type: 'Calculated';
}
| {
handle: string;
price: string;
title: string;
type: 'Custom';
};
export type ShippingLine = CalculatedShippingLine | CustomShippingLine;

export enum ShippingMethodType {
Shipping = 'SHIPPING',
Retail = 'RETAIL',
}

export interface TaxLine {
export interface CalculatedShippingLine {
uuid: string;
price: string;
rate: number;
// For bundles we need to show the range of the tax rate.
// This is the minimum and maximum tax rate of the tax lines of the components.
rateRange?: [number, number];
title: string;
enabled: boolean;
}

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';
lastDigits: string;
brand: string;
tipAmount: string;
cardSource?: CardSource;
hasPendingOfflineTransactions: boolean;
}

interface CashPayment extends BasePayment {
type: 'Cash';
changeAmount: string;
roundedAmount?: string;
methodType: 'SHIPPING' | 'RETAIL';
type: 'Calculated';
}

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

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

interface CustomPayment extends BasePayment {
export interface CustomShippingLine {
uuid: string;
price: string;
title: string;
type: 'Custom';
name: string;
}

interface UnknownPayment extends BasePayment {
type: 'Unknown';
export interface TaxLine {
uuid: string;
price: string;
rate: number;
rateRange?: {min: number; max: number};
title: string;
enabled: boolean;
}
49 changes: 49 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,49 @@
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';
lastDigits: string;
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 1d5f224

Please sign in to comment.