@vectoriox/iox-ui 5.119.0 → 5.120.0
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.
- package/commerce-core/index.d.ts +169 -5
- package/fesm2022/vectoriox-iox-ui-commerce-core.mjs +214 -5
- package/fesm2022/vectoriox-iox-ui-commerce-core.mjs.map +1 -1
- package/package.json +1 -1
- package/src/commerce-core/payment-sessions.ts +213 -0
- package/src/commerce-core/payments.ts +21 -4
- package/src/commerce-core/public-api.ts +1 -0
- package/src/commerce-core/site-checkout.ts +61 -1
package/package.json
CHANGED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { CommerceLabel } from './labels';
|
|
2
|
+
import { isMoney, Money } from './money';
|
|
3
|
+
import { OrderState, STOCK_RESERVATION_MINUTES } from './orders';
|
|
4
|
+
import { PaymentChannel } from './payments';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Card payments (commerce E2, C-D2, trap T2): what a payment provider's answer MEANS for an order. The provider's
|
|
8
|
+
* adapter (iox-cms) asks the provider itself — never the buyer's browser, never a webhook's body — and normalises its
|
|
9
|
+
* answer to a `PaymentResult`; `paymentVerdict` decides. Pure: no clock (the caller passes `now`), no provider names.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export enum PaymentResultStatus {
|
|
13
|
+
/** The provider took the money: a transaction exists. */
|
|
14
|
+
Paid = 'paid',
|
|
15
|
+
/** The page is open (the buyer has not paid yet, or a card was declined and the page still waits). */
|
|
16
|
+
Pending = 'pending',
|
|
17
|
+
/** The provider closed the session without a payment. */
|
|
18
|
+
Failed = 'failed',
|
|
19
|
+
/** The provider does not know the session (or did not answer): nothing is decided. */
|
|
20
|
+
Unknown = 'unknown',
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** One provider answer about one session, as its adapter read it. */
|
|
24
|
+
export interface PaymentResult {
|
|
25
|
+
status: PaymentResultStatus;
|
|
26
|
+
/** The provider's session id, as the provider said it. */
|
|
27
|
+
sessionId: string | null;
|
|
28
|
+
/** Our reference, echoed back by the provider (what we sent when the session was made). */
|
|
29
|
+
reference: string | null;
|
|
30
|
+
/** The provider's transaction id — what a refund names. */
|
|
31
|
+
transactionId: string | null;
|
|
32
|
+
/** What was charged, in minor units of the charged currency. */
|
|
33
|
+
amount: Money | null;
|
|
34
|
+
/** The provider's words for the last declined try while the page still waits — shown to the buyer. */
|
|
35
|
+
declined?: string | null;
|
|
36
|
+
/** What the owner may read of the card that paid (never more than a brand and the last four digits). */
|
|
37
|
+
card?: PaidCard | null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface PaidCard {
|
|
41
|
+
brand: string | null;
|
|
42
|
+
last4: string | null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** One time the buyer was sent to the provider's page for an order. */
|
|
46
|
+
export enum PaymentAttemptStatus {
|
|
47
|
+
Open = 'open',
|
|
48
|
+
Paid = 'paid',
|
|
49
|
+
Failed = 'failed',
|
|
50
|
+
/** The order expired or was cancelled while this page was open. */
|
|
51
|
+
Closed = 'closed',
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface PaymentAttempt {
|
|
55
|
+
/** Our reference: the provider echoes it, so a result for another order is refused. */
|
|
56
|
+
reference: string;
|
|
57
|
+
provider: string;
|
|
58
|
+
sessionId: string;
|
|
59
|
+
/** Where the buyer pays (the provider's hosted page). */
|
|
60
|
+
url: string;
|
|
61
|
+
status: PaymentAttemptStatus;
|
|
62
|
+
createdAt: Date | string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export enum PaymentVerdictKind {
|
|
66
|
+
/** Paid and every fact matches: the order moves to paid (the machine's `confirmPayment`). */
|
|
67
|
+
Confirm = 'confirm',
|
|
68
|
+
/** The provider closed the session unpaid: `failPayment`, the reservation released. */
|
|
69
|
+
Fail = 'fail',
|
|
70
|
+
/** Still open: show "Confirming…" and ask again. */
|
|
71
|
+
Wait = 'wait',
|
|
72
|
+
/** Nothing to do (an unknown session, a pending page of an order that moved on). */
|
|
73
|
+
Ignore = 'ignore',
|
|
74
|
+
/** The answer does not belong to this order or does not match it: nothing changes, the owner is told. */
|
|
75
|
+
Refuse = 'refuse',
|
|
76
|
+
/** The same transaction was already recorded: a replayed answer, a second webhook, the return racing the webhook. */
|
|
77
|
+
AlreadyPaid = 'alreadyPaid',
|
|
78
|
+
/** A SECOND transaction paid an order already paid (two tabs): kept for the owner to refund. */
|
|
79
|
+
PaidTwice = 'paidTwice',
|
|
80
|
+
/** Paid after the order was cancelled (the reservation ran out): kept for the owner to refund. */
|
|
81
|
+
PaidAfterClose = 'paidAfterClose',
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export enum PaymentMismatch {
|
|
85
|
+
Session = 'session-mismatch',
|
|
86
|
+
Reference = 'reference-mismatch',
|
|
87
|
+
Currency = 'currency-mismatch',
|
|
88
|
+
Amount = 'amount-mismatch',
|
|
89
|
+
NoTransaction = 'no-transaction',
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface PaymentVerdict {
|
|
93
|
+
kind: PaymentVerdictKind;
|
|
94
|
+
mismatches: PaymentMismatch[];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface PaymentVerdictInput {
|
|
98
|
+
state: OrderState;
|
|
99
|
+
/** The order's total — what must have been charged. */
|
|
100
|
+
total: Money;
|
|
101
|
+
/** The attempt this answer is about (found by OUR records, never by the answer). */
|
|
102
|
+
attempt: Pick<PaymentAttempt, 'reference' | 'sessionId'>;
|
|
103
|
+
/** The transaction already recorded as paying this order, if any. */
|
|
104
|
+
paidTransactionId: string | null;
|
|
105
|
+
result: PaymentResult;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const PAID_STATES: readonly OrderState[] = Object.freeze([
|
|
109
|
+
OrderState.Paid, OrderState.Fulfilled, OrderState.Delivered, OrderState.PartiallyRefunded, OrderState.Refunded,
|
|
110
|
+
]);
|
|
111
|
+
|
|
112
|
+
const OPEN_STATES: readonly OrderState[] = Object.freeze([OrderState.PendingPayment, OrderState.PaymentFailed]);
|
|
113
|
+
|
|
114
|
+
const verdict = (kind: PaymentVerdictKind, mismatches: PaymentMismatch[] = []): PaymentVerdict => ({ kind, mismatches });
|
|
115
|
+
|
|
116
|
+
/** The mismatches that make an answer not this order's: another session, another reference. */
|
|
117
|
+
function identityMismatches(input: PaymentVerdictInput): PaymentMismatch[] {
|
|
118
|
+
const { result, attempt } = input;
|
|
119
|
+
const found: PaymentMismatch[] = [];
|
|
120
|
+
if (result.sessionId !== null && result.sessionId !== attempt.sessionId) found.push(PaymentMismatch.Session);
|
|
121
|
+
if (result.reference !== attempt.reference) found.push(PaymentMismatch.Reference);
|
|
122
|
+
return found;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** A paid answer must name a transaction and have charged exactly the order's total, in its currency. */
|
|
126
|
+
function moneyMismatches(input: PaymentVerdictInput): PaymentMismatch[] {
|
|
127
|
+
const { result, total } = input;
|
|
128
|
+
if (!result.transactionId) return [PaymentMismatch.NoTransaction];
|
|
129
|
+
if (!isMoney(result.amount) || result.amount.currency !== total.currency) return [PaymentMismatch.Currency];
|
|
130
|
+
return result.amount.amount === total.amount ? [] : [PaymentMismatch.Amount];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** THE decision on a provider's answer (T2): only a paid answer for THIS attempt, of exactly this total, pays — once. */
|
|
134
|
+
export function paymentVerdict(input: PaymentVerdictInput): PaymentVerdict {
|
|
135
|
+
const { result, state } = input;
|
|
136
|
+
if (result.status === PaymentResultStatus.Unknown) return verdict(PaymentVerdictKind.Ignore);
|
|
137
|
+
const identity = identityMismatches(input);
|
|
138
|
+
if (identity.length) return verdict(PaymentVerdictKind.Refuse, identity);
|
|
139
|
+
if (result.status === PaymentResultStatus.Paid) {
|
|
140
|
+
const money = moneyMismatches(input);
|
|
141
|
+
if (money.length) return verdict(PaymentVerdictKind.Refuse, money);
|
|
142
|
+
if (input.paidTransactionId && input.paidTransactionId === result.transactionId) return verdict(PaymentVerdictKind.AlreadyPaid);
|
|
143
|
+
if (OPEN_STATES.includes(state)) return verdict(PaymentVerdictKind.Confirm);
|
|
144
|
+
if (PAID_STATES.includes(state)) return verdict(PaymentVerdictKind.PaidTwice);
|
|
145
|
+
if (state === OrderState.Cancelled) return verdict(PaymentVerdictKind.PaidAfterClose);
|
|
146
|
+
return verdict(PaymentVerdictKind.Ignore);
|
|
147
|
+
}
|
|
148
|
+
if (state !== OrderState.PendingPayment) return verdict(PaymentVerdictKind.Ignore);
|
|
149
|
+
return verdict(result.status === PaymentResultStatus.Failed ? PaymentVerdictKind.Fail : PaymentVerdictKind.Wait);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** A page made this recently is sent again instead of a new one (a double click, a second tab) — while the stock is held. */
|
|
153
|
+
export function reusableAttempt(attempts: readonly PaymentAttempt[] | null | undefined, now: number): PaymentAttempt | null {
|
|
154
|
+
const open = (attempts ?? []).filter(attempt => attempt.status === PaymentAttemptStatus.Open);
|
|
155
|
+
const last = open[open.length - 1];
|
|
156
|
+
if (!last) return null;
|
|
157
|
+
return now - new Date(last.createdAt).getTime() < STOCK_RESERVATION_MINUTES * 60000 ? last : null;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The reservation ran out: the payment sweep asks the provider one last time, then expires the order (C-D10). */
|
|
161
|
+
export function reservationDue(reservedUntil: Date | string | null | undefined, now: number): boolean {
|
|
162
|
+
if (!reservedUntil) return false;
|
|
163
|
+
const until = new Date(reservedUntil).getTime();
|
|
164
|
+
return Number.isFinite(until) && until <= now;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** What the buyer's order page shows about paying (the engine's "Confirming your payment…"). */
|
|
168
|
+
export enum BuyerPaymentStage {
|
|
169
|
+
/** A manual method: how to pay. */
|
|
170
|
+
Instructions = 'instructions',
|
|
171
|
+
/** A card payment is open: confirming with the provider. */
|
|
172
|
+
Confirming = 'confirming',
|
|
173
|
+
Paid = 'paid',
|
|
174
|
+
/** The card payment did not go through: the buyer may try again. */
|
|
175
|
+
Failed = 'failed',
|
|
176
|
+
/** Cancelled (by the owner, or not paid in time). */
|
|
177
|
+
Closed = 'closed',
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const ONLINE_STAGES: Readonly<Record<OrderState, BuyerPaymentStage>> = Object.freeze({
|
|
181
|
+
[OrderState.AwaitingPayment]: BuyerPaymentStage.Instructions,
|
|
182
|
+
[OrderState.PendingPayment]: BuyerPaymentStage.Confirming,
|
|
183
|
+
[OrderState.PaymentFailed]: BuyerPaymentStage.Failed,
|
|
184
|
+
[OrderState.Paid]: BuyerPaymentStage.Paid,
|
|
185
|
+
[OrderState.Fulfilled]: BuyerPaymentStage.Paid,
|
|
186
|
+
[OrderState.Delivered]: BuyerPaymentStage.Paid,
|
|
187
|
+
[OrderState.Refunded]: BuyerPaymentStage.Paid,
|
|
188
|
+
[OrderState.PartiallyRefunded]: BuyerPaymentStage.Paid,
|
|
189
|
+
[OrderState.Cancelled]: BuyerPaymentStage.Closed,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
export function buyerPaymentStage(state: OrderState, channel: PaymentChannel): BuyerPaymentStage {
|
|
193
|
+
const stage = ONLINE_STAGES[state] ?? BuyerPaymentStage.Closed;
|
|
194
|
+
if (channel === PaymentChannel.Manual && (stage === BuyerPaymentStage.Confirming || stage === BuyerPaymentStage.Failed)) return BuyerPaymentStage.Instructions;
|
|
195
|
+
return stage;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** The buyer may (re)open the payment page: still within the open states of a card order. */
|
|
199
|
+
export function buyerMayPay(state: OrderState, channel: PaymentChannel): boolean {
|
|
200
|
+
return channel === PaymentChannel.Online && OPEN_STATES.includes(state);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** What happened to a card payment, as the order's history and the admin say it. */
|
|
204
|
+
export const PAYMENT_VERDICT_LABELS: Readonly<Record<PaymentVerdictKind, CommerceLabel>> = Object.freeze({
|
|
205
|
+
[PaymentVerdictKind.Confirm]: { en: 'Paid by card', he: 'שולם בכרטיס אשראי' },
|
|
206
|
+
[PaymentVerdictKind.Fail]: { en: 'The card payment did not go through', he: 'התשלום בכרטיס לא עבר' },
|
|
207
|
+
[PaymentVerdictKind.Wait]: { en: 'Waiting for the payment', he: 'ממתינים לתשלום' },
|
|
208
|
+
[PaymentVerdictKind.Ignore]: { en: 'Nothing changed', he: 'לא השתנה דבר' },
|
|
209
|
+
[PaymentVerdictKind.Refuse]: { en: 'A payment answer that does not match this order was refused', he: 'תשובת תשלום שלא תואמת להזמנה נדחתה' },
|
|
210
|
+
[PaymentVerdictKind.AlreadyPaid]: { en: 'Already recorded', he: 'כבר נרשם' },
|
|
211
|
+
[PaymentVerdictKind.PaidTwice]: { en: 'Paid a second time — refund the extra payment', he: 'שולם פעמיים — יש לזכות את התשלום הנוסף' },
|
|
212
|
+
[PaymentVerdictKind.PaidAfterClose]: { en: 'Paid after the order was cancelled — refund it', he: 'שולם אחרי שההזמנה בוטלה — יש לזכות' },
|
|
213
|
+
});
|
|
@@ -15,7 +15,7 @@ export enum PaymentMethodKind {
|
|
|
15
15
|
PayOnPickup = 'payOnPickup',
|
|
16
16
|
CashOnDelivery = 'cashOnDelivery',
|
|
17
17
|
Bit = 'bit',
|
|
18
|
-
/** A PSP's hosted page (E2, Cardcom first)
|
|
18
|
+
/** A PSP's hosted page (E2, Cardcom first): the buyer pays there, never on a card field of ours. */
|
|
19
19
|
Online = 'online',
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -46,6 +46,8 @@ interface PaymentMethodRule {
|
|
|
46
46
|
readonly channel: PaymentChannel;
|
|
47
47
|
/** false = typed for a later phase, never shown to a buyer. */
|
|
48
48
|
readonly offered: boolean;
|
|
49
|
+
/** Ready only while the studio's payment connector answers (E2): the server says so in `connected`. */
|
|
50
|
+
readonly needsConnection: boolean;
|
|
49
51
|
readonly fields: readonly PaymentField[];
|
|
50
52
|
readonly fit: DeliveryFit;
|
|
51
53
|
readonly label: CommerceLabel;
|
|
@@ -57,6 +59,7 @@ export const PAYMENT_METHODS: Readonly<Record<PaymentMethodKind, PaymentMethodRu
|
|
|
57
59
|
[PaymentMethodKind.BankTransfer]: {
|
|
58
60
|
channel: PaymentChannel.Manual,
|
|
59
61
|
offered: true,
|
|
62
|
+
needsConnection: false,
|
|
60
63
|
fields: [PaymentField.AccountName, PaymentField.Bank, PaymentField.Branch, PaymentField.AccountNumber],
|
|
61
64
|
fit: DeliveryFit.Any,
|
|
62
65
|
label: { en: 'Bank transfer', he: 'העברה בנקאית' },
|
|
@@ -68,6 +71,7 @@ export const PAYMENT_METHODS: Readonly<Record<PaymentMethodKind, PaymentMethodRu
|
|
|
68
71
|
[PaymentMethodKind.PayOnPickup]: {
|
|
69
72
|
channel: PaymentChannel.Manual,
|
|
70
73
|
offered: true,
|
|
74
|
+
needsConnection: false,
|
|
71
75
|
fields: [],
|
|
72
76
|
fit: DeliveryFit.PickupOnly,
|
|
73
77
|
label: { en: 'Pay on pickup', he: 'תשלום באיסוף' },
|
|
@@ -79,6 +83,7 @@ export const PAYMENT_METHODS: Readonly<Record<PaymentMethodKind, PaymentMethodRu
|
|
|
79
83
|
[PaymentMethodKind.CashOnDelivery]: {
|
|
80
84
|
channel: PaymentChannel.Manual,
|
|
81
85
|
offered: true,
|
|
86
|
+
needsConnection: false,
|
|
82
87
|
fields: [],
|
|
83
88
|
fit: DeliveryFit.AddressOnly,
|
|
84
89
|
label: { en: 'Cash on delivery', he: 'מזומן במסירה' },
|
|
@@ -90,6 +95,7 @@ export const PAYMENT_METHODS: Readonly<Record<PaymentMethodKind, PaymentMethodRu
|
|
|
90
95
|
[PaymentMethodKind.Bit]: {
|
|
91
96
|
channel: PaymentChannel.Manual,
|
|
92
97
|
offered: true,
|
|
98
|
+
needsConnection: false,
|
|
93
99
|
fields: [PaymentField.BitPhone],
|
|
94
100
|
fit: DeliveryFit.Any,
|
|
95
101
|
label: { en: 'Bit', he: 'ביט' },
|
|
@@ -100,7 +106,8 @@ export const PAYMENT_METHODS: Readonly<Record<PaymentMethodKind, PaymentMethodRu
|
|
|
100
106
|
},
|
|
101
107
|
[PaymentMethodKind.Online]: {
|
|
102
108
|
channel: PaymentChannel.Online,
|
|
103
|
-
offered:
|
|
109
|
+
offered: true,
|
|
110
|
+
needsConnection: true,
|
|
104
111
|
fields: [PaymentField.Provider],
|
|
105
112
|
fit: DeliveryFit.Any,
|
|
106
113
|
label: { en: 'Card', he: 'כרטיס אשראי' },
|
|
@@ -144,6 +151,11 @@ export interface PaymentMethodConfig {
|
|
|
144
151
|
details?: Partial<Record<PaymentField, string>> | null;
|
|
145
152
|
/** The owner's own words, shown after the instructions. */
|
|
146
153
|
note?: string | null;
|
|
154
|
+
/**
|
|
155
|
+
* A FACT the server adds, never stored: the studio's payment connector answered its last check (E2). Only a method
|
|
156
|
+
* that `needsConnection` reads it — a card method whose terminal does not answer is not a way to get paid.
|
|
157
|
+
*/
|
|
158
|
+
connected?: boolean | null;
|
|
147
159
|
}
|
|
148
160
|
|
|
149
161
|
export const isPaymentMethodKind = (value: unknown): value is PaymentMethodKind =>
|
|
@@ -160,10 +172,15 @@ export function paymentMethodProblems(config: PaymentMethodConfig): PaymentField
|
|
|
160
172
|
return PAYMENT_METHODS[config.kind].fields.filter(field => !PAYMENT_FIELD_CHECKS[field](details[field]));
|
|
161
173
|
}
|
|
162
174
|
|
|
163
|
-
/**
|
|
175
|
+
/** A method that needs no connection, or whose connection answered (E2). */
|
|
176
|
+
export function paymentMethodConnected(config: PaymentMethodConfig): boolean {
|
|
177
|
+
return !!config && isPaymentMethodKind(config.kind) && (!PAYMENT_METHODS[config.kind].needsConnection || config.connected === true);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Enabled, offered in this phase, complete and — for a card method — connected: the ONE rule the checkout and its gate read. */
|
|
164
181
|
export function paymentMethodReady(config: PaymentMethodConfig): boolean {
|
|
165
182
|
return !!config && isPaymentMethodKind(config.kind) && config.enabled === true
|
|
166
|
-
&& PAYMENT_METHODS[config.kind].offered && paymentMethodProblems(config).length === 0;
|
|
183
|
+
&& PAYMENT_METHODS[config.kind].offered && paymentMethodProblems(config).length === 0 && paymentMethodConnected(config);
|
|
167
184
|
}
|
|
168
185
|
|
|
169
186
|
/** The methods a buyer may pick with this delivery (null = nothing ships). */
|
|
@@ -6,7 +6,8 @@ import { CommerceLabel, labelIn } from './labels';
|
|
|
6
6
|
import { isMoney, Money } from './money';
|
|
7
7
|
import { OrderSnapshot, PostalAddress } from './order-snapshot';
|
|
8
8
|
import { OrderState } from './orders';
|
|
9
|
-
import {
|
|
9
|
+
import { BuyerPaymentStage } from './payment-sessions';
|
|
10
|
+
import { DeliveryFit, PaymentChannel, PaymentMethodKind } from './payments';
|
|
10
11
|
import { ShippingMethodKind, ShippingQuote } from './shipping';
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -30,6 +31,16 @@ export enum SiteCommerceRoute {
|
|
|
30
31
|
Order = 'order',
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
/** What the buyer does to a card order through its link (E2): `pay` opens (or re-opens) the provider's page. */
|
|
35
|
+
export enum SiteOrderAction {
|
|
36
|
+
Pay = 'pay',
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** `POST /api/site/<org>/order/<token>/pay` — root-relative, like every site route. */
|
|
40
|
+
export function siteOrderActionPath(orgId: string, token: string, action: SiteOrderAction): string {
|
|
41
|
+
return `${siteCommercePath(orgId, SiteCommerceRoute.Order, token)}/${action}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
33
44
|
/** A public commerce route of one org, ROOT-relative (the same rule as `cartEndpointPath`). */
|
|
34
45
|
export function siteCommercePath(orgId: string, route: SiteCommerceRoute, id?: string | null): string {
|
|
35
46
|
const base = `/api/site/${encodeURIComponent(orgId)}/${route}`;
|
|
@@ -149,12 +160,33 @@ export interface SiteBuyerOrder {
|
|
|
149
160
|
snapshot: OrderSnapshot;
|
|
150
161
|
paymentLabel: string;
|
|
151
162
|
instructions: string | null;
|
|
163
|
+
/** How paying stands (E2): the stage the page shows, whether the buyer may open the payment page, a declined card's words. */
|
|
164
|
+
payment: SiteOrderPayment;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface SiteOrderPayment {
|
|
168
|
+
channel: PaymentChannel;
|
|
169
|
+
stage: BuyerPaymentStage;
|
|
170
|
+
canPay: boolean;
|
|
171
|
+
declined: string | null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Where to send the buyer to pay — a card order only (E2); `null` when the page could not be made (they try again from the order page). */
|
|
175
|
+
export interface SitePaymentRedirect {
|
|
176
|
+
redirectUrl: string;
|
|
152
177
|
}
|
|
153
178
|
|
|
154
179
|
/** `POST checkout/place` — 201. */
|
|
155
180
|
export interface SitePlacedOrder {
|
|
156
181
|
order: SiteBuyerOrder;
|
|
157
182
|
viewToken: string;
|
|
183
|
+
payment?: SitePaymentRedirect | null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** `POST order/:token/pay` — the order as it stands and where to pay. */
|
|
187
|
+
export interface SitePayAnswer {
|
|
188
|
+
order: SiteBuyerOrder;
|
|
189
|
+
payment: SitePaymentRedirect | null;
|
|
158
190
|
}
|
|
159
191
|
|
|
160
192
|
// ── the step a visitor is on ──────────────────────────────────────────────────────────────────
|
|
@@ -235,6 +267,17 @@ export enum CheckoutWord {
|
|
|
235
267
|
ApplyCoupon = 'applyCoupon',
|
|
236
268
|
RemoveCoupon = 'removeCoupon',
|
|
237
269
|
Discount = 'discount',
|
|
270
|
+
PayOrder = 'payOrder',
|
|
271
|
+
PayNote = 'payNote',
|
|
272
|
+
ToPaymentPage = 'toPaymentPage',
|
|
273
|
+
ConfirmingPayment = 'confirmingPayment',
|
|
274
|
+
ConfirmingSlow = 'confirmingSlow',
|
|
275
|
+
PaymentConfirmed = 'paymentConfirmed',
|
|
276
|
+
PaymentFailed = 'paymentFailed',
|
|
277
|
+
PaymentDeclined = 'paymentDeclined',
|
|
278
|
+
TryAgain = 'tryAgain',
|
|
279
|
+
PayNow = 'payNow',
|
|
280
|
+
OrderClosed = 'orderClosed',
|
|
238
281
|
}
|
|
239
282
|
|
|
240
283
|
/** `{name}`, `{n}`, `{of}`, `{amount}`, `{percent}`, `{number}`, `{email}`, `{total}`, `{place}` are filled by `checkoutWord`. */
|
|
@@ -284,6 +327,17 @@ export const CHECKOUT_WORDS: Readonly<Record<CheckoutWord, CommerceLabel>> = Obj
|
|
|
284
327
|
[CheckoutWord.ApplyCoupon]: { en: 'Apply', he: 'החלה' },
|
|
285
328
|
[CheckoutWord.RemoveCoupon]: { en: 'Remove', he: 'הסרה' },
|
|
286
329
|
[CheckoutWord.Discount]: { en: 'Discount · {code}', he: 'הנחה · {code}' },
|
|
330
|
+
[CheckoutWord.PayOrder]: { en: 'Pay · {total}', he: 'לתשלום · {total}' },
|
|
331
|
+
[CheckoutWord.PayNote]: { en: 'You pay on a secure payment page. We never see your card.', he: 'התשלום מתבצע בעמוד תשלום מאובטח. איננו רואים את פרטי הכרטיס.' },
|
|
332
|
+
[CheckoutWord.ToPaymentPage]: { en: 'Taking you to the payment page…', he: 'מעבירים אותך לעמוד התשלום…' },
|
|
333
|
+
[CheckoutWord.ConfirmingPayment]: { en: 'Confirming your payment…', he: 'מאשרים את התשלום…' },
|
|
334
|
+
[CheckoutWord.ConfirmingSlow]: { en: 'This is taking longer than usual. You can close this page — we will email you once the payment is confirmed.', he: 'זה לוקח יותר זמן מהרגיל. אפשר לסגור את העמוד — נשלח אימייל כשהתשלום יאושר.' },
|
|
335
|
+
[CheckoutWord.PaymentConfirmed]: { en: 'Payment confirmed', he: 'התשלום אושר' },
|
|
336
|
+
[CheckoutWord.PaymentFailed]: { en: 'The payment did not go through. Nothing was charged.', he: 'התשלום לא עבר. לא חויבתם.' },
|
|
337
|
+
[CheckoutWord.PaymentDeclined]: { en: 'The card was declined: {reason}', he: 'הכרטיס נדחה: {reason}' },
|
|
338
|
+
[CheckoutWord.TryAgain]: { en: 'Try again', he: 'נסו שוב' },
|
|
339
|
+
[CheckoutWord.PayNow]: { en: 'Pay now · {total}', he: 'לתשלום עכשיו · {total}' },
|
|
340
|
+
[CheckoutWord.OrderClosed]: { en: 'This order was cancelled.', he: 'ההזמנה הזו בוטלה.' },
|
|
287
341
|
});
|
|
288
342
|
|
|
289
343
|
export function checkoutWord(word: CheckoutWord, lang: string | null | undefined, fill: Readonly<Record<string, string | number>> = {}): string {
|
|
@@ -356,6 +410,10 @@ export enum SiteRefusalCode {
|
|
|
356
410
|
RecoveryDone = 'recovery-done',
|
|
357
411
|
/** A reminder's link whose bag is gone, or a link that is not one. */
|
|
358
412
|
RecoveryExpired = 'recovery-expired',
|
|
413
|
+
/** The payment page could not be made right now (the provider did not answer) — the order stands; try again (E2). */
|
|
414
|
+
PaymentUnavailable = 'payment-unavailable',
|
|
415
|
+
/** This order cannot be paid any more (paid, or cancelled). */
|
|
416
|
+
PaymentClosed = 'payment-closed',
|
|
359
417
|
Network = 'network',
|
|
360
418
|
}
|
|
361
419
|
|
|
@@ -411,6 +469,8 @@ export const SITE_REFUSALS: Readonly<Record<SiteRefusalCode, RefusalRule>> = Obj
|
|
|
411
469
|
[SiteRefusalCode.CouponNotUsable]: { slot: CheckoutSlot.Coupon, label: COUPON_REFUSAL_LABELS[CouponRefusal.NotUsable] },
|
|
412
470
|
[SiteRefusalCode.RecoveryDone]: { slot: CheckoutSlot.Page, label: { en: 'This purchase was already completed.', he: 'הרכישה הזו כבר הושלמה.' } },
|
|
413
471
|
[SiteRefusalCode.RecoveryExpired]: { slot: CheckoutSlot.Page, label: { en: 'This bag is no longer kept. You are welcome to shop again.', he: 'הסל הזה כבר לא שמור. אפשר לקנות שוב.' } },
|
|
472
|
+
[SiteRefusalCode.PaymentUnavailable]: { slot: CheckoutSlot.Page, label: { en: 'The payment page is not available right now. Your order is saved — try again in a moment.', he: 'עמוד התשלום לא זמין כרגע. ההזמנה נשמרה — נסו שוב בעוד רגע.' } },
|
|
473
|
+
[SiteRefusalCode.PaymentClosed]: { slot: CheckoutSlot.Page, label: { en: 'This order cannot be paid any more.', he: 'כבר אי אפשר לשלם על ההזמנה הזו.' } },
|
|
414
474
|
[SiteRefusalCode.Network]: { slot: CheckoutSlot.Page, label: { en: 'We could not reach the shop. Try again.', he: 'לא הצלחנו להגיע לחנות. נסו שוב.' } },
|
|
415
475
|
});
|
|
416
476
|
|