@wix/himalaya-cli 0.1523.0 → 0.1525.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/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/apple-iap-contract.d.ts +5 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/cashier-charges.d.ts +3 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/iap-checkout.mjs +35 -9
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/iap.mjs +14 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/screens.mjs +34 -8
- package/package.json +2 -2
- package/templates/beauty-salon/tier5-src/himi-branded-lite-cart/index.ts +4 -63
- package/templates/beauty-salon/tier5-src/himi-store-product/index.ts +153 -132
- package/templates/branded-lite/tier5-src/himi-branded-lite-cart/index.ts +4 -63
- package/templates/branded-lite/tier5-src/himi-store-product/index.ts +153 -132
- package/templates/gym-fitness/tier5-src/himi-branded-lite-cart/index.ts +4 -63
- package/templates/gym-fitness/tier5-src/himi-store-product/index.ts +153 -132
- package/templates/portfolio-creative/tier5-src/himi-branded-lite-cart/index.ts +4 -63
- package/templates/portfolio-creative/tier5-src/himi-store-product/index.ts +153 -132
- package/templates/retail-store/tier5-src/himi-branded-lite-cart/index.ts +4 -63
- package/templates/retail-store/tier5-src/himi-store-product/index.ts +153 -132
|
@@ -76,10 +76,14 @@ export type IapEligibility = {
|
|
|
76
76
|
};
|
|
77
77
|
/** `open`: a pending order the cashier can charge. `granted`: the vertical already gives the
|
|
78
78
|
* member access, so nothing is sold. */
|
|
79
|
-
export type OrderAttempt = (
|
|
79
|
+
export type OrderAttempt = (
|
|
80
|
+
/** `placed`: the order was created by this call, so it cannot have a charge yet. Only an adapter
|
|
81
|
+
* that never returns an existing order may say so; an order it reuses must be listed first. */
|
|
82
|
+
{
|
|
80
83
|
status: "open";
|
|
81
84
|
cashierOrderId: string;
|
|
82
85
|
verticalRef: VerticalRef;
|
|
86
|
+
placed?: boolean;
|
|
83
87
|
} | {
|
|
84
88
|
status: "granted";
|
|
85
89
|
} | {
|
|
@@ -15,6 +15,9 @@ export type AppleIapChargeResult = {
|
|
|
15
15
|
status: "closed" | "inOtherPayment" | "refused" | "notConfigured" | "invalidResponse" | "unavailable" | "notEnabled" | "sessionChanged";
|
|
16
16
|
};
|
|
17
17
|
export declare function ensureAppleIapCharge(bridge: SessionBoundBridge, route: CashierRoute, orderId: string): Promise<AppleIapChargeResult>;
|
|
18
|
+
/** An order created in this same call has no charges, so List would only cost a round trip. A
|
|
19
|
+
* lost answer is still reconciled through List. */
|
|
20
|
+
export declare function chargePlacedOrder(bridge: SessionBoundBridge, route: CashierRoute, orderId: string): Promise<AppleIapChargeResult>;
|
|
18
21
|
export declare function listOrderCharges(bridge: SessionBoundBridge, route: CashierRoute, orderId: string): Promise<{
|
|
19
22
|
status: "ok";
|
|
20
23
|
charges: CashierCharge[];
|
|
@@ -810,10 +810,23 @@ function enabledPricing(source, deps) {
|
|
|
810
810
|
let selling = "active";
|
|
811
811
|
let lookupRevision = 0;
|
|
812
812
|
let answeredRoutes;
|
|
813
|
+
let inFlight;
|
|
814
|
+
const sharedAnswer = (request) => {
|
|
815
|
+
const key = JSON.stringify(request);
|
|
816
|
+
if (inFlight?.key === key) return inFlight.answer;
|
|
817
|
+
const answer = Promise.resolve(source.mapping.resolve(request));
|
|
818
|
+
const asked = { key, answer };
|
|
819
|
+
inFlight = asked;
|
|
820
|
+
const settle = () => {
|
|
821
|
+
if (inFlight === asked) inFlight = void 0;
|
|
822
|
+
};
|
|
823
|
+
answer.then(settle, settle);
|
|
824
|
+
return answer;
|
|
825
|
+
};
|
|
813
826
|
const mapping = {
|
|
814
827
|
resolve: async (request) => {
|
|
815
828
|
const asked = lookupRevision;
|
|
816
|
-
const answer = await
|
|
829
|
+
const answer = await sharedAnswer(request);
|
|
817
830
|
if (asked === lookupRevision) answeredRoutes = routesAnswered(answer);
|
|
818
831
|
return answer;
|
|
819
832
|
}
|
|
@@ -1570,12 +1583,19 @@ function storesAppleSalesEnabled() {
|
|
|
1570
1583
|
|
|
1571
1584
|
// ../../stdlib/flows/iap-checkout/src/cashier-charges.ts
|
|
1572
1585
|
async function ensureAppleIapCharge(bridge, route, orderId) {
|
|
1573
|
-
|
|
1574
|
-
if (
|
|
1586
|
+
const invalid = invalidRequest(route, orderId);
|
|
1587
|
+
if (invalid) return invalid;
|
|
1575
1588
|
const listed = await listOrderCharges(bridge, route, orderId);
|
|
1576
1589
|
if (listed.status !== "ok") return listed;
|
|
1577
1590
|
return decideFromCharges(listed.charges) ?? chargeThenReconcile(bridge, route, orderId);
|
|
1578
1591
|
}
|
|
1592
|
+
async function chargePlacedOrder(bridge, route, orderId) {
|
|
1593
|
+
return invalidRequest(route, orderId) ?? chargeThenReconcile(bridge, route, orderId);
|
|
1594
|
+
}
|
|
1595
|
+
function invalidRequest(route, orderId) {
|
|
1596
|
+
if (!isRoutePrefix2(route.prefix)) return { status: "notConfigured" };
|
|
1597
|
+
return orderId ? null : { status: "invalidResponse" };
|
|
1598
|
+
}
|
|
1579
1599
|
async function listOrderCharges(bridge, route, orderId) {
|
|
1580
1600
|
const answer = await bridge.call("GET", chargesPath(route, orderId));
|
|
1581
1601
|
if (answer.status !== "ok") return failureOf(answer);
|
|
@@ -1892,7 +1912,7 @@ function createWixOrderBackend(deps) {
|
|
|
1892
1912
|
async function startOrderFor(sale) {
|
|
1893
1913
|
const ordered = await orderFor(sale);
|
|
1894
1914
|
if (isStop(ordered)) return contextResult(sale.catalogRef, ordered);
|
|
1895
|
-
const charged = await chargeFor(sale, ordered, { reordered: false });
|
|
1915
|
+
const charged = await chargeFor(sale, ordered.ref, { reordered: false, placed: ordered.placed });
|
|
1896
1916
|
if (isStop(charged)) return contextResult(sale.catalogRef, charged);
|
|
1897
1917
|
return startFor(sale, charged);
|
|
1898
1918
|
}
|
|
@@ -1952,7 +1972,9 @@ function createWixOrderBackend(deps) {
|
|
|
1952
1972
|
return true;
|
|
1953
1973
|
};
|
|
1954
1974
|
const attempt3 = existing?.cashierOrderId && existing.verticalRef ? await reopenOrOpen(sale, { cashierOrderId: existing.cashierOrderId, verticalRef: existing.verticalRef }) : await sale.adapter.openOrder(sale.item, sale.bridge, beforeCreate);
|
|
1955
|
-
|
|
1975
|
+
if (prevented) return prevented;
|
|
1976
|
+
const ref = recordOrder(sale, existing, attempt3);
|
|
1977
|
+
return isStop(ref) ? ref : { ref, placed: isPlaced(attempt3) };
|
|
1956
1978
|
}
|
|
1957
1979
|
async function reopenOrOpen(sale, order) {
|
|
1958
1980
|
const reopened = await sale.adapter.reopenOrder(order, sale.bridge);
|
|
@@ -1978,7 +2000,7 @@ function createWixOrderBackend(deps) {
|
|
|
1978
2000
|
});
|
|
1979
2001
|
}
|
|
1980
2002
|
async function chargeFor(sale, ref, options) {
|
|
1981
|
-
const charge = await ensureAppleIapCharge(sale.bridge, deps.cashier, ref.cashierOrderId ?? "");
|
|
2003
|
+
const charge = await (options.placed ? chargePlacedOrder : ensureAppleIapCharge)(sale.bridge, deps.cashier, ref.cashierOrderId ?? "");
|
|
1982
2004
|
switch (charge.status) {
|
|
1983
2005
|
case "pending":
|
|
1984
2006
|
return persist(sale, { ...ref, stage: "charged", wixTransactionId: charge.transactionId, updatedAt: now() });
|
|
@@ -2002,8 +2024,9 @@ function createWixOrderBackend(deps) {
|
|
|
2002
2024
|
async function reorder(sale) {
|
|
2003
2025
|
if (sale.adapter.repeatable) return stopWith("rejected", "orderClosed");
|
|
2004
2026
|
if (!forget(sale, sale.catalogRef)) return stopWith("rejected", "storageUnavailable");
|
|
2005
|
-
const
|
|
2006
|
-
|
|
2027
|
+
const attempt3 = await sale.adapter.openOrder(sale.item, sale.bridge);
|
|
2028
|
+
const recorded = recordOrder(sale, void 0, attempt3);
|
|
2029
|
+
return isStop(recorded) ? recorded : chargeFor(sale, recorded, { reordered: true, placed: isPlaced(attempt3) });
|
|
2007
2030
|
}
|
|
2008
2031
|
async function alreadyPaid(sale, ref) {
|
|
2009
2032
|
const access = await sale.adapter.readAccess(ref.verticalRef ?? {}, sale.bridge);
|
|
@@ -2237,6 +2260,9 @@ function unassociatedHold(transaction, updatedAt) {
|
|
|
2237
2260
|
function acknowledgementOf(transaction, scopeKey) {
|
|
2238
2261
|
return { transactionId: transaction.transactionId, productId: transaction.productId, environment: transaction.environment, scopeKey };
|
|
2239
2262
|
}
|
|
2263
|
+
function isPlaced(attempt3) {
|
|
2264
|
+
return attempt3.status === "open" && attempt3.placed === true;
|
|
2265
|
+
}
|
|
2240
2266
|
function refAt(partition, key) {
|
|
2241
2267
|
return partition.refs().find((ref) => ref.key === key);
|
|
2242
2268
|
}
|
|
@@ -3267,7 +3293,7 @@ async function readAccess3(verticalRef, bridge) {
|
|
|
3267
3293
|
async function placedOrder(body, bridge) {
|
|
3268
3294
|
if (!isObject7(body) || !isNonEmpty3(body.orderId)) return ORDER_REFUSED;
|
|
3269
3295
|
const verticalRef = { orderId: body.orderId };
|
|
3270
|
-
if (isNonEmpty3(body.paymentGatewayOrderId)) return { status: "open", cashierOrderId: body.paymentGatewayOrderId, verticalRef };
|
|
3296
|
+
if (isNonEmpty3(body.paymentGatewayOrderId)) return { status: "open", cashierOrderId: body.paymentGatewayOrderId, verticalRef, placed: true };
|
|
3271
3297
|
const access = await readAccess3(verticalRef, bridge);
|
|
3272
3298
|
if (access === "granted") return GRANTED;
|
|
3273
3299
|
return access === "sessionChanged" || access === "unavailable" ? { status: access } : ORDER_REFUSED;
|
|
@@ -787,10 +787,23 @@ function enabledPricing(source, deps) {
|
|
|
787
787
|
let selling = "active";
|
|
788
788
|
let lookupRevision = 0;
|
|
789
789
|
let answeredRoutes;
|
|
790
|
+
let inFlight;
|
|
791
|
+
const sharedAnswer = (request) => {
|
|
792
|
+
const key = JSON.stringify(request);
|
|
793
|
+
if (inFlight?.key === key) return inFlight.answer;
|
|
794
|
+
const answer = Promise.resolve(source.mapping.resolve(request));
|
|
795
|
+
const asked = { key, answer };
|
|
796
|
+
inFlight = asked;
|
|
797
|
+
const settle = () => {
|
|
798
|
+
if (inFlight === asked) inFlight = void 0;
|
|
799
|
+
};
|
|
800
|
+
answer.then(settle, settle);
|
|
801
|
+
return answer;
|
|
802
|
+
};
|
|
790
803
|
const mapping = {
|
|
791
804
|
resolve: async (request) => {
|
|
792
805
|
const asked = lookupRevision;
|
|
793
|
-
const answer = await
|
|
806
|
+
const answer = await sharedAnswer(request);
|
|
794
807
|
if (asked === lookupRevision) answeredRoutes = routesAnswered(answer);
|
|
795
808
|
return answer;
|
|
796
809
|
}
|
|
@@ -1352,10 +1352,23 @@ function enabledPricing(source, deps) {
|
|
|
1352
1352
|
let selling = "active";
|
|
1353
1353
|
let lookupRevision = 0;
|
|
1354
1354
|
let answeredRoutes;
|
|
1355
|
+
let inFlight;
|
|
1356
|
+
const sharedAnswer = (request) => {
|
|
1357
|
+
const key = JSON.stringify(request);
|
|
1358
|
+
if (inFlight?.key === key) return inFlight.answer;
|
|
1359
|
+
const answer = Promise.resolve(source.mapping.resolve(request));
|
|
1360
|
+
const asked = { key, answer };
|
|
1361
|
+
inFlight = asked;
|
|
1362
|
+
const settle = () => {
|
|
1363
|
+
if (inFlight === asked) inFlight = void 0;
|
|
1364
|
+
};
|
|
1365
|
+
answer.then(settle, settle);
|
|
1366
|
+
return answer;
|
|
1367
|
+
};
|
|
1355
1368
|
const mapping = {
|
|
1356
1369
|
resolve: async (request) => {
|
|
1357
1370
|
const asked = lookupRevision;
|
|
1358
|
-
const answer = await
|
|
1371
|
+
const answer = await sharedAnswer(request);
|
|
1359
1372
|
if (asked === lookupRevision) answeredRoutes = routesAnswered(answer);
|
|
1360
1373
|
return answer;
|
|
1361
1374
|
}
|
|
@@ -2130,12 +2143,19 @@ function itemPaymentEnabled() {
|
|
|
2130
2143
|
|
|
2131
2144
|
// ../../stdlib/flows/iap-checkout/src/cashier-charges.ts
|
|
2132
2145
|
async function ensureAppleIapCharge(bridge, route, orderId) {
|
|
2133
|
-
|
|
2134
|
-
if (
|
|
2146
|
+
const invalid = invalidRequest(route, orderId);
|
|
2147
|
+
if (invalid) return invalid;
|
|
2135
2148
|
const listed = await listOrderCharges(bridge, route, orderId);
|
|
2136
2149
|
if (listed.status !== "ok") return listed;
|
|
2137
2150
|
return decideFromCharges(listed.charges) ?? chargeThenReconcile(bridge, route, orderId);
|
|
2138
2151
|
}
|
|
2152
|
+
async function chargePlacedOrder(bridge, route, orderId) {
|
|
2153
|
+
return invalidRequest(route, orderId) ?? chargeThenReconcile(bridge, route, orderId);
|
|
2154
|
+
}
|
|
2155
|
+
function invalidRequest(route, orderId) {
|
|
2156
|
+
if (!isRoutePrefix2(route.prefix)) return { status: "notConfigured" };
|
|
2157
|
+
return orderId ? null : { status: "invalidResponse" };
|
|
2158
|
+
}
|
|
2139
2159
|
async function listOrderCharges(bridge, route, orderId) {
|
|
2140
2160
|
const answer = await bridge.call("GET", chargesPath(route, orderId));
|
|
2141
2161
|
if (answer.status !== "ok") return failureOf(answer);
|
|
@@ -2452,7 +2472,7 @@ function createWixOrderBackend(deps) {
|
|
|
2452
2472
|
async function startOrderFor(sale) {
|
|
2453
2473
|
const ordered = await orderFor(sale);
|
|
2454
2474
|
if (isStop(ordered)) return contextResult(sale.catalogRef, ordered);
|
|
2455
|
-
const charged = await chargeFor(sale, ordered, { reordered: false });
|
|
2475
|
+
const charged = await chargeFor(sale, ordered.ref, { reordered: false, placed: ordered.placed });
|
|
2456
2476
|
if (isStop(charged)) return contextResult(sale.catalogRef, charged);
|
|
2457
2477
|
return startFor(sale, charged);
|
|
2458
2478
|
}
|
|
@@ -2512,7 +2532,9 @@ function createWixOrderBackend(deps) {
|
|
|
2512
2532
|
return true;
|
|
2513
2533
|
};
|
|
2514
2534
|
const attempt4 = existing?.cashierOrderId && existing.verticalRef ? await reopenOrOpen(sale, { cashierOrderId: existing.cashierOrderId, verticalRef: existing.verticalRef }) : await sale.adapter.openOrder(sale.item, sale.bridge, beforeCreate);
|
|
2515
|
-
|
|
2535
|
+
if (prevented) return prevented;
|
|
2536
|
+
const ref = recordOrder(sale, existing, attempt4);
|
|
2537
|
+
return isStop(ref) ? ref : { ref, placed: isPlaced(attempt4) };
|
|
2516
2538
|
}
|
|
2517
2539
|
async function reopenOrOpen(sale, order) {
|
|
2518
2540
|
const reopened = await sale.adapter.reopenOrder(order, sale.bridge);
|
|
@@ -2538,7 +2560,7 @@ function createWixOrderBackend(deps) {
|
|
|
2538
2560
|
});
|
|
2539
2561
|
}
|
|
2540
2562
|
async function chargeFor(sale, ref, options) {
|
|
2541
|
-
const charge = await ensureAppleIapCharge(sale.bridge, deps.cashier, ref.cashierOrderId ?? "");
|
|
2563
|
+
const charge = await (options.placed ? chargePlacedOrder : ensureAppleIapCharge)(sale.bridge, deps.cashier, ref.cashierOrderId ?? "");
|
|
2542
2564
|
switch (charge.status) {
|
|
2543
2565
|
case "pending":
|
|
2544
2566
|
return persist(sale, { ...ref, stage: "charged", wixTransactionId: charge.transactionId, updatedAt: now() });
|
|
@@ -2562,8 +2584,9 @@ function createWixOrderBackend(deps) {
|
|
|
2562
2584
|
async function reorder(sale) {
|
|
2563
2585
|
if (sale.adapter.repeatable) return stopWith("rejected", "orderClosed");
|
|
2564
2586
|
if (!forget(sale, sale.catalogRef)) return stopWith("rejected", "storageUnavailable");
|
|
2565
|
-
const
|
|
2566
|
-
|
|
2587
|
+
const attempt4 = await sale.adapter.openOrder(sale.item, sale.bridge);
|
|
2588
|
+
const recorded = recordOrder(sale, void 0, attempt4);
|
|
2589
|
+
return isStop(recorded) ? recorded : chargeFor(sale, recorded, { reordered: true, placed: isPlaced(attempt4) });
|
|
2567
2590
|
}
|
|
2568
2591
|
async function alreadyPaid(sale, ref) {
|
|
2569
2592
|
const access = await sale.adapter.readAccess(ref.verticalRef ?? {}, sale.bridge);
|
|
@@ -2797,6 +2820,9 @@ function unassociatedHold(transaction, updatedAt) {
|
|
|
2797
2820
|
function acknowledgementOf(transaction, scopeKey) {
|
|
2798
2821
|
return { transactionId: transaction.transactionId, productId: transaction.productId, environment: transaction.environment, scopeKey };
|
|
2799
2822
|
}
|
|
2823
|
+
function isPlaced(attempt4) {
|
|
2824
|
+
return attempt4.status === "open" && attempt4.placed === true;
|
|
2825
|
+
}
|
|
2800
2826
|
function refAt(partition, key) {
|
|
2801
2827
|
return partition.refs().find((ref) => ref.key === key);
|
|
2802
2828
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/himalaya-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1525.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "himi — the Himalaya authoring CLI. Build a Tier-5 content package on your own machine, push it to the production serve as a draft, preview it on web + Himi Player, and read worker logs back — the remote dev loop. Wraps @himalaya/serve-cli for transport.",
|
|
6
6
|
"keywords": [
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"artifactId": "himalaya-cli"
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
|
-
"falconPackageHash": "
|
|
74
|
+
"falconPackageHash": "4d57d913fdf7e7ed0944f6605a9a5093b4fe45fb1efa09885218796d"
|
|
75
75
|
}
|
|
@@ -2,9 +2,8 @@ import { getStoreProduct } from "../_shared/himi-store.js";
|
|
|
2
2
|
import { iapPriceCopy } from "../_shared/iap-worker.js";
|
|
3
3
|
import { withIapPresentation } from "../_shared/iap-presentation.js";
|
|
4
4
|
import { type IapCommerce, classifyCart } from "@himalaya/iap-checkout";
|
|
5
|
-
import { addCouponToCurrentCart, calculateCurrentCart, createCheckoutFromCurrentCart,
|
|
5
|
+
import { addCouponToCurrentCart, calculateCurrentCart, createCheckoutFromCurrentCart, getCurrentCart, removeCouponFromCurrentCart, removeLineItemsFromCurrentCart, updateLineItemsQuantity, type WixCartDetail, type WixCartLineItemDetail } from "@himalaya/wix-ecom";
|
|
6
6
|
import { createRedirectSession } from "@himalaya/wix-redirects";
|
|
7
|
-
import { session as wixPlatformSession } from "@himalaya/wix-platform";
|
|
8
7
|
import { payCashierOrder } from "@himalaya/checkout";
|
|
9
8
|
import { hostedCheckoutOpener, isHostedWorker } from "../_shared/hosted-checkout.js";
|
|
10
9
|
import { formatCurrency } from "../_shared/engine-intl.js";
|
|
@@ -14,16 +13,6 @@ import { formatCurrency } from "../_shared/engine-intl.js";
|
|
|
14
13
|
const WIX_STORES_CATALOG_ID = "215238eb-22a5-4c36-9e7b-e7c08025e04e";
|
|
15
14
|
const WIX_STORES_APP_ID = "1380b703-ce81-ff05-f115-39571d94dfcd";
|
|
16
15
|
|
|
17
|
-
/** The site's metaSiteId for the cashier payment config. Best-effort — the native
|
|
18
|
-
* cashier can also resolve it from the app's signed Wix session, so "" is tolerated. */
|
|
19
|
-
async function resolveMsid(): Promise<string> {
|
|
20
|
-
try {
|
|
21
|
-
const st = await wixPlatformSession.signedInstanceStatus();
|
|
22
|
-
return st.msid ?? "";
|
|
23
|
-
} catch {
|
|
24
|
-
return "";
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
16
|
import { copyParam, copyTemplate, stashCopy } from "../_shared/himi-copy.js";
|
|
28
17
|
import { getAll, upsert, remove as dbRemove, type DbEntity } from "@himalaya/local-db";
|
|
29
18
|
import { isOfflineFailure, writeMayHaveLanded } from "../_shared/owner-load-error.js";
|
|
@@ -387,30 +376,6 @@ function couponDetails(result: unknown): { id: string; code: string } {
|
|
|
387
376
|
return { id: coupon?.coupon?.id ?? coupon?.id ?? "", code: coupon?.coupon?.code ?? coupon?.code ?? "" };
|
|
388
377
|
}
|
|
389
378
|
|
|
390
|
-
/** The state slice a SETTLED order leaves behind: the order consumed the cart, so the
|
|
391
|
-
* lines AND the subtotal go with it (`refresh` and the error path both clear the pair —
|
|
392
|
-
* leaving a stale subtotal in state is the class of defect #864 fixed on the render side).
|
|
393
|
-
*
|
|
394
|
-
* `emptyText` is cleared deliberately: the empty card would otherwise nudge "Your cart is
|
|
395
|
-
* empty." underneath the confirmation, which is noise at the moment of a successful
|
|
396
|
-
* payment. The next `load` restores it.
|
|
397
|
-
*
|
|
398
|
-
* This used to be written inline as `{ items: [], itemCount: 0, checkoutHint: ... }`.
|
|
399
|
-
* `itemCount` is not a field of `State` and never was — a write to nowhere, which is why
|
|
400
|
-
* the subtotal and emptyText resets were missing. It survived because nothing typechecks
|
|
401
|
-
* Tier-5 workers: esbuild erases types, and no tsconfig includes tier5-bundles-src.
|
|
402
|
-
*/
|
|
403
|
-
function cartConsumedByOrder(): Pick<State, "items" | "subtotal" | "emptyText" | "checkoutHint" | "showPaidToast" | "promoCode" | "appliedCode" | "couponId" | "discount"> {
|
|
404
|
-
return {
|
|
405
|
-
items: [],
|
|
406
|
-
subtotal: "",
|
|
407
|
-
emptyText: "",
|
|
408
|
-
checkoutHint: copyParam("cart.checkoutPaidMessage", "Order placed. Thanks!"),
|
|
409
|
-
showPaidToast: true,
|
|
410
|
-
promoCode: "", appliedCode: "", couponId: "", discount: "",
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
|
|
414
379
|
let cartPricing: IapCommerce;
|
|
415
380
|
const defineService = withIapPresentation<State>({
|
|
416
381
|
onCreate: commerce => { cartPricing = commerce; },
|
|
@@ -544,13 +509,7 @@ const svc = defineService<State, {
|
|
|
544
509
|
return derive({ ...state, checkoutHint: copyParam("cart.quantityFailedMessage", "Could not update the quantity.") });
|
|
545
510
|
}
|
|
546
511
|
},
|
|
547
|
-
//
|
|
548
|
-
// (@wix/himalaya/checkout) instead of always bouncing to the hosted checkout:
|
|
549
|
-
// createCheckoutFromCurrentCart → ecom.createOrder → payCashierOrder
|
|
550
|
-
// A wallet-equipped app settles with NO navigation at all; every other app hands
|
|
551
|
-
// off to the in-app Wix cashier (the previous behaviour), so nothing regresses.
|
|
552
|
-
// `createOrder` returning no paymentGatewayOrderId means there is nothing to
|
|
553
|
-
// charge (fully covered / zero total) — the order already stands.
|
|
512
|
+
// Physical checkout collects shipping before the site's checkout creates the order.
|
|
554
513
|
checkout: async (state) => {
|
|
555
514
|
let validatedLines: WixCartLineItemDetail[] = [];
|
|
556
515
|
const signature = (lines: WixCartLineItemDetail[]) => JSON.stringify(lines.map(line => [line.id, line.quantity, (line as WixCartLineItemDetail & { catalogReference?: Row["catalogReference"] }).catalogReference]));
|
|
@@ -577,21 +536,11 @@ const svc = defineService<State, {
|
|
|
577
536
|
if (!checkout.checkoutId) return derive({ ...state, checkoutHint: copyParam("cart.checkoutIdMissingMessage", "Wix did not return a checkout id.") });
|
|
578
537
|
const checkoutId = checkout.checkoutId;
|
|
579
538
|
|
|
580
|
-
// Hosted (Spaces): the site's own checkout page creates the order (RN's
|
|
581
|
-
// route) — creating it here first fails on a site with no payment method set up, before the
|
|
582
|
-
// member ever reaches the checkout. The host opens the checkout as the lent member.
|
|
583
539
|
const hosted = isHostedWorker();
|
|
584
|
-
const order = hosted ? { paymentGatewayOrderId: "" } : await createOrder(checkoutId);
|
|
585
|
-
const snapshotId = order.paymentGatewayOrderId ?? "";
|
|
586
|
-
if (!snapshotId && !hosted) {
|
|
587
|
-
await writeCachedItems([]);
|
|
588
|
-
return derive({ ...state, ...cartConsumedByOrder() });
|
|
589
|
-
}
|
|
590
|
-
|
|
591
540
|
const pay = await payCashierOrder({
|
|
592
541
|
appId: WIX_STORES_APP_ID,
|
|
593
|
-
snapshotId,
|
|
594
|
-
msid:
|
|
542
|
+
snapshotId: "",
|
|
543
|
+
msid: "",
|
|
595
544
|
mayCharge: async () => {
|
|
596
545
|
const latest = await getCurrentCart();
|
|
597
546
|
if (signature(latest.lineItems ?? []) !== signature(validatedLines)) return false;
|
|
@@ -611,19 +560,11 @@ const svc = defineService<State, {
|
|
|
611
560
|
return redirect.redirectSession?.fullUrl;
|
|
612
561
|
},
|
|
613
562
|
});
|
|
614
|
-
if (pay.kind === "paid") {
|
|
615
|
-
// Settled in place — the cart is consumed by the order.
|
|
616
|
-
await writeCachedItems([]);
|
|
617
|
-
return derive({ ...state, ...cartConsumedByOrder() });
|
|
618
|
-
}
|
|
619
563
|
if (pay.kind === "handoff") {
|
|
620
564
|
// Do NOT clear the cart: payment completes in the cashier and the order is
|
|
621
565
|
// only confirmed once it lands, so the cart must survive a bail-out.
|
|
622
566
|
return derive({ ...state, checkoutHint: copyParam("cart.checkoutOpenedMessage", "Checkout opened.") });
|
|
623
567
|
}
|
|
624
|
-
if (pay.kind === "cancelled") {
|
|
625
|
-
return derive({ ...state, checkoutHint: copyParam("cart.checkoutCancelledMessage", "Payment cancelled — your cart is still here.") });
|
|
626
|
-
}
|
|
627
568
|
return derive({ ...state, checkoutHint: copyParam("cart.checkoutFailedMessage", "Checkout could not start.") });
|
|
628
569
|
} catch {
|
|
629
570
|
return derive({ ...state, checkoutHint: copyParam("cart.checkoutFailedMessage", "Checkout could not start.") });
|