@cartbase/storefront 0.2.0 → 0.4.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/package.json +1 -1
- package/src/api/carts.ts +5 -3
- package/src/api/checkout.ts +93 -43
- package/src/api/integrations.ts +4 -17
- package/src/cart-drawer/labels-bg.ts +1 -1
- package/src/cart-drawer/labels.ts +119 -119
- package/src/cart-drawer/summary-breakdown.tsx +197 -196
- package/src/checkout/checkout-client.tsx +13 -10
- package/src/checkout/index.ts +0 -1
- package/src/checkout/labels-bg.ts +1 -1
- package/src/checkout/labels.ts +263 -263
- package/src/checkout/order-summary.tsx +45 -45
- package/src/checkout/payment-method-list.tsx +92 -32
- package/src/checkout/use-checkout-orchestration.ts +100 -92
- package/src/lib/payment-constants.ts +53 -66
- package/src/order/labels-bg.ts +39 -39
- package/src/order/labels.ts +79 -79
- package/src/order/order-completed-template.tsx +17 -9
- package/src/order/order-payment-card.tsx +26 -35
- package/src/order/order-totals.tsx +250 -245
package/src/order/labels.ts
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Order family label pack. Ported from `@1click/ui/src/order/labels.ts`
|
|
3
|
-
* (v2.3.1) unchanged, plus `tracking` — new in the Cartbase port because the
|
|
4
|
-
* Cartbase order surface exposes fulfillment tracking labels
|
|
5
|
-
* (`StoreOrderDetail.fulfillments[].fulfillment.labels`) that
|
|
6
|
-
* `OrderDeliveryCard` now renders.
|
|
7
|
-
*/
|
|
8
|
-
export type OrderLabels = {
|
|
9
|
-
orderConfirmed: string
|
|
10
|
-
confirmationSent: string
|
|
11
|
-
orderNumber: string
|
|
12
|
-
orderDate: string
|
|
13
|
-
summary: string
|
|
14
|
-
subtotal: string
|
|
15
|
-
shipping: string
|
|
16
|
-
discount: string
|
|
17
|
-
tax: string
|
|
18
|
-
total: string
|
|
19
|
-
/** Default label for the cash-on-delivery fee row. Used as the third-
|
|
20
|
-
* level fallback when neither a per-store override nor the server's
|
|
21
|
-
* `
|
|
22
|
-
|
|
23
|
-
contactInfo: string
|
|
24
|
-
delivery: string
|
|
25
|
-
paymentMethod: string
|
|
26
|
-
paymentMethodTitles: {
|
|
27
|
-
card: string
|
|
28
|
-
cod: string
|
|
29
|
-
/** Offline manual payments (pp_manual) — NOT cash on delivery. */
|
|
30
|
-
manual: string
|
|
31
|
-
paypal: string
|
|
32
|
-
}
|
|
33
|
-
needHelp: string
|
|
34
|
-
contactUs: string
|
|
35
|
-
returnsExchanges: string
|
|
36
|
-
orderPlaced: string
|
|
37
|
-
processing: string
|
|
38
|
-
shipped: string
|
|
39
|
-
delivered: string
|
|
40
|
-
free: string
|
|
41
|
-
continueShopping: string
|
|
42
|
-
qty: string
|
|
43
|
-
/** Heading for the fulfillment tracking-numbers block (Cartbase addition). */
|
|
44
|
-
tracking: string
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const defaultOrderLabels: OrderLabels = {
|
|
48
|
-
orderConfirmed: "Order confirmed",
|
|
49
|
-
confirmationSent: "We sent a confirmation to",
|
|
50
|
-
orderNumber: "Order",
|
|
51
|
-
orderDate: "Date",
|
|
52
|
-
summary: "Order summary",
|
|
53
|
-
subtotal: "Subtotal",
|
|
54
|
-
shipping: "Shipping",
|
|
55
|
-
discount: "Discount",
|
|
56
|
-
tax: "Tax",
|
|
57
|
-
total: "Total",
|
|
58
|
-
|
|
59
|
-
contactInfo: "Contact info",
|
|
60
|
-
delivery: "Delivery",
|
|
61
|
-
paymentMethod: "Payment method",
|
|
62
|
-
paymentMethodTitles: {
|
|
63
|
-
card: "Credit / debit card",
|
|
64
|
-
cod: "Cash on delivery",
|
|
65
|
-
manual: "Manual payment",
|
|
66
|
-
paypal: "PayPal",
|
|
67
|
-
},
|
|
68
|
-
needHelp: "Need help?",
|
|
69
|
-
contactUs: "Contact us",
|
|
70
|
-
returnsExchanges: "Returns & exchanges",
|
|
71
|
-
orderPlaced: "Placed",
|
|
72
|
-
processing: "Processing",
|
|
73
|
-
shipped: "Shipped",
|
|
74
|
-
delivered: "Delivered",
|
|
75
|
-
free: "FREE",
|
|
76
|
-
continueShopping: "Continue shopping",
|
|
77
|
-
qty: "qty.",
|
|
78
|
-
tracking: "Tracking",
|
|
79
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Order family label pack. Ported from `@1click/ui/src/order/labels.ts`
|
|
3
|
+
* (v2.3.1) unchanged, plus `tracking` — new in the Cartbase port because the
|
|
4
|
+
* Cartbase order surface exposes fulfillment tracking labels
|
|
5
|
+
* (`StoreOrderDetail.fulfillments[].fulfillment.labels`) that
|
|
6
|
+
* `OrderDeliveryCard` now renders.
|
|
7
|
+
*/
|
|
8
|
+
export type OrderLabels = {
|
|
9
|
+
orderConfirmed: string
|
|
10
|
+
confirmationSent: string
|
|
11
|
+
orderNumber: string
|
|
12
|
+
orderDate: string
|
|
13
|
+
summary: string
|
|
14
|
+
subtotal: string
|
|
15
|
+
shipping: string
|
|
16
|
+
discount: string
|
|
17
|
+
tax: string
|
|
18
|
+
total: string
|
|
19
|
+
/** Default label for the cash-on-delivery fee row. Used as the third-
|
|
20
|
+
* level fallback when neither a per-store override nor the server's
|
|
21
|
+
* `payment_method_fee_label` / fee line title is available. */
|
|
22
|
+
paymentMethodFee: string
|
|
23
|
+
contactInfo: string
|
|
24
|
+
delivery: string
|
|
25
|
+
paymentMethod: string
|
|
26
|
+
paymentMethodTitles: {
|
|
27
|
+
card: string
|
|
28
|
+
cod: string
|
|
29
|
+
/** Offline manual payments (pp_manual) — NOT cash on delivery. */
|
|
30
|
+
manual: string
|
|
31
|
+
paypal: string
|
|
32
|
+
}
|
|
33
|
+
needHelp: string
|
|
34
|
+
contactUs: string
|
|
35
|
+
returnsExchanges: string
|
|
36
|
+
orderPlaced: string
|
|
37
|
+
processing: string
|
|
38
|
+
shipped: string
|
|
39
|
+
delivered: string
|
|
40
|
+
free: string
|
|
41
|
+
continueShopping: string
|
|
42
|
+
qty: string
|
|
43
|
+
/** Heading for the fulfillment tracking-numbers block (Cartbase addition). */
|
|
44
|
+
tracking: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const defaultOrderLabels: OrderLabels = {
|
|
48
|
+
orderConfirmed: "Order confirmed",
|
|
49
|
+
confirmationSent: "We sent a confirmation to",
|
|
50
|
+
orderNumber: "Order",
|
|
51
|
+
orderDate: "Date",
|
|
52
|
+
summary: "Order summary",
|
|
53
|
+
subtotal: "Subtotal",
|
|
54
|
+
shipping: "Shipping",
|
|
55
|
+
discount: "Discount",
|
|
56
|
+
tax: "Tax",
|
|
57
|
+
total: "Total",
|
|
58
|
+
paymentMethodFee: "Payment method fee",
|
|
59
|
+
contactInfo: "Contact info",
|
|
60
|
+
delivery: "Delivery",
|
|
61
|
+
paymentMethod: "Payment method",
|
|
62
|
+
paymentMethodTitles: {
|
|
63
|
+
card: "Credit / debit card",
|
|
64
|
+
cod: "Cash on delivery",
|
|
65
|
+
manual: "Manual payment",
|
|
66
|
+
paypal: "PayPal",
|
|
67
|
+
},
|
|
68
|
+
needHelp: "Need help?",
|
|
69
|
+
contactUs: "Contact us",
|
|
70
|
+
returnsExchanges: "Returns & exchanges",
|
|
71
|
+
orderPlaced: "Placed",
|
|
72
|
+
processing: "Processing",
|
|
73
|
+
shipped: "Shipped",
|
|
74
|
+
delivered: "Delivered",
|
|
75
|
+
free: "FREE",
|
|
76
|
+
continueShopping: "Continue shopping",
|
|
77
|
+
qty: "qty.",
|
|
78
|
+
tracking: "Tracking",
|
|
79
|
+
}
|
|
@@ -40,9 +40,12 @@ import { OrderHelpSection } from "./order-help-section"
|
|
|
40
40
|
* `order.items` via `displayItemFromOrderItem` (prefer passing
|
|
41
41
|
* cart-derived lines via `displayItemFromCartLine` right after checkout
|
|
42
42
|
* to keep server-computed per-line discounts).
|
|
43
|
-
* - `shippingMethod` / `paymentProviderId` / `
|
|
44
|
-
* checkout state (decorated cart /
|
|
45
|
-
* delivery and payment cards render
|
|
43
|
+
* - `shippingMethod` / `paymentProviderId` / `paymentMethodName` /
|
|
44
|
+
* `cardLast4` — from the checkout state (decorated cart /
|
|
45
|
+
* prepare-checkout response); the delivery and payment cards render
|
|
46
|
+
* only what they are given. A merchant-method order passes
|
|
47
|
+
* `paymentMethodName` (its merchant name — the display everywhere
|
|
48
|
+
* since the pp_* kill) and no provider id.
|
|
46
49
|
*
|
|
47
50
|
* The Purchase tracking trio (fbq/gtag/rybbit, deduped by
|
|
48
51
|
* `order.display_id`) stays APP-OWNED: fire it from the confirmation
|
|
@@ -61,6 +64,8 @@ type OrderCompletedTemplateProps = {
|
|
|
61
64
|
items?: OrderDisplayItem[]
|
|
62
65
|
shippingMethod?: ShippingMethodDisplay | null
|
|
63
66
|
paymentProviderId?: string | null
|
|
67
|
+
/** The merchant method's name — wins over any provider bucket. */
|
|
68
|
+
paymentMethodName?: string | null
|
|
64
69
|
cardLast4?: string | null
|
|
65
70
|
labels?: OrderLabels
|
|
66
71
|
locale?: string
|
|
@@ -69,11 +74,12 @@ type OrderCompletedTemplateProps = {
|
|
|
69
74
|
/** Href for the bottom "continue shopping" CTA (source hardcoded /store). */
|
|
70
75
|
storeHref?: string
|
|
71
76
|
/**
|
|
72
|
-
* Per-store override for the
|
|
73
|
-
*
|
|
74
|
-
* then the fee line's title, then the translated
|
|
77
|
+
* Per-store override for the method-fee row in the totals breakdown.
|
|
78
|
+
* Optional — falls back to the server's `payment_method_fee_label`,
|
|
79
|
+
* then the fee line's title, then the translated
|
|
80
|
+
* `labels.paymentMethodFee`.
|
|
75
81
|
*/
|
|
76
|
-
|
|
82
|
+
methodFeeLabel?: string
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
export function OrderCompletedTemplate({
|
|
@@ -82,13 +88,14 @@ export function OrderCompletedTemplate({
|
|
|
82
88
|
items,
|
|
83
89
|
shippingMethod,
|
|
84
90
|
paymentProviderId,
|
|
91
|
+
paymentMethodName,
|
|
85
92
|
cardLast4,
|
|
86
93
|
labels,
|
|
87
94
|
locale,
|
|
88
95
|
contactHref,
|
|
89
96
|
returnsHref,
|
|
90
97
|
storeHref = "/store",
|
|
91
|
-
|
|
98
|
+
methodFeeLabel,
|
|
92
99
|
}: OrderCompletedTemplateProps) {
|
|
93
100
|
const l = { ...defaultOrderLabels, ...labels }
|
|
94
101
|
const displayItems =
|
|
@@ -119,7 +126,7 @@ export function OrderCompletedTemplate({
|
|
|
119
126
|
currencyCode={order.currency_code}
|
|
120
127
|
items={displayItems}
|
|
121
128
|
labels={l}
|
|
122
|
-
|
|
129
|
+
methodFeeLabel={methodFeeLabel}
|
|
123
130
|
/>
|
|
124
131
|
</div>
|
|
125
132
|
</div>
|
|
@@ -134,6 +141,7 @@ export function OrderCompletedTemplate({
|
|
|
134
141
|
/>
|
|
135
142
|
<OrderPaymentCard
|
|
136
143
|
providerId={paymentProviderId}
|
|
144
|
+
methodName={paymentMethodName}
|
|
137
145
|
cardLast4={cardLast4}
|
|
138
146
|
labels={l}
|
|
139
147
|
/>
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { CreditCard } from "lucide-react"
|
|
2
|
-
import {
|
|
3
|
-
isManual,
|
|
4
|
-
isPaypal,
|
|
5
|
-
isStripeLike,
|
|
6
|
-
paymentInfoMap,
|
|
7
|
-
} from "../lib/payment-constants"
|
|
2
|
+
import { isPaypal, isStripeLike, paymentInfoMap } from "../lib/payment-constants"
|
|
8
3
|
import { defaultOrderLabels, type OrderLabels } from "./labels"
|
|
9
4
|
|
|
10
5
|
/**
|
|
@@ -12,47 +7,42 @@ import { defaultOrderLabels, type OrderLabels } from "./labels"
|
|
|
12
7
|
* `@1click/ui/src/order/order-payment-card.tsx` (v2.3.1); data seam:
|
|
13
8
|
* Medusa's `order.payment_collections[0].payments[0]` embed does not exist
|
|
14
9
|
* on Cartbase's `StoreOrderDetail` (payment internals never cross the store
|
|
15
|
-
* surface) — the
|
|
16
|
-
* `prepareCheckout()
|
|
17
|
-
*
|
|
10
|
+
* surface) — the tender arrives via props instead: from
|
|
11
|
+
* `prepareCheckout()`, the decorated cart's `payment_collection` sessions,
|
|
12
|
+
* or the app's checkout state.
|
|
18
13
|
*/
|
|
19
14
|
|
|
20
15
|
/**
|
|
21
|
-
* Resolve a human-readable, locale-correct title for a payment
|
|
22
|
-
*
|
|
16
|
+
* Resolve a human-readable, locale-correct title for a payment tender.
|
|
17
|
+
* Since the pp_* kill (20260811250000) a merchant METHOD carries its own
|
|
18
|
+
* merchant-written name — that name IS the display (Bank transfer, the
|
|
19
|
+
* merchant's COD name); locale buckets apply to processor ids only:
|
|
23
20
|
*
|
|
24
|
-
* 1.
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* adopted the labels pack yet.
|
|
31
|
-
* 3. The raw provider id as a last resort, so the card never renders
|
|
32
|
-
* empty if a brand-new provider lands.
|
|
33
|
-
*
|
|
34
|
-
* The bucket is determined by the same `isStripeLike` / `isManual` /
|
|
35
|
-
* `isPaypal` predicates used everywhere else in the library (translated to
|
|
36
|
-
* Cartbase ids in `lib/payment-constants`), so a single change to those
|
|
37
|
-
* propagates here automatically.
|
|
21
|
+
* 1. `methodName` (the method's merchant name), verbatim.
|
|
22
|
+
* 2. Bucketed lookup against `labels.paymentMethodTitles` for processor
|
|
23
|
+
* ids (Stripe → the locale's "card" title, PayPal likewise).
|
|
24
|
+
* 3. Hardcoded `paymentInfoMap` fallback for known processor ids.
|
|
25
|
+
* 4. The raw provider id as a last resort, so the card never renders
|
|
26
|
+
* empty if a brand-new processor lands.
|
|
38
27
|
*/
|
|
39
28
|
export function resolvePaymentTitle(
|
|
40
|
-
providerId: string | undefined,
|
|
41
|
-
paymentMethodTitles: OrderLabels["paymentMethodTitles"]
|
|
29
|
+
providerId: string | null | undefined,
|
|
30
|
+
paymentMethodTitles: OrderLabels["paymentMethodTitles"],
|
|
31
|
+
methodName?: string | null
|
|
42
32
|
): string {
|
|
33
|
+
if (methodName) return methodName
|
|
43
34
|
if (!providerId) return ""
|
|
44
35
|
if (isStripeLike(providerId)) return paymentMethodTitles.card
|
|
45
|
-
// COD before manual: pp_cod is its own bucket (payments-registry card) —
|
|
46
|
-
// an offline manual payment must never render as "Cash on delivery".
|
|
47
|
-
if (providerId === "pp_cod") return paymentMethodTitles.cod
|
|
48
|
-
if (isManual(providerId)) return paymentMethodTitles.manual
|
|
49
36
|
if (isPaypal(providerId)) return paymentMethodTitles.paypal
|
|
50
37
|
return paymentInfoMap[providerId]?.title ?? providerId
|
|
51
38
|
}
|
|
52
39
|
|
|
53
40
|
type OrderPaymentCardProps = {
|
|
54
|
-
/**
|
|
41
|
+
/** Processor id (e.g. `pp_stripe`), or null for a merchant method. */
|
|
55
42
|
providerId?: string | null
|
|
43
|
+
/** The merchant method's name (Bank transfer, the merchant's COD name) —
|
|
44
|
+
* wins over any provider bucket when present. */
|
|
45
|
+
methodName?: string | null
|
|
56
46
|
/** Last 4 card digits when known (Stripe checkout state). */
|
|
57
47
|
cardLast4?: string | null
|
|
58
48
|
labels?: Pick<OrderLabels, "paymentMethod" | "paymentMethodTitles">
|
|
@@ -60,15 +50,16 @@ type OrderPaymentCardProps = {
|
|
|
60
50
|
|
|
61
51
|
export function OrderPaymentCard({
|
|
62
52
|
providerId,
|
|
53
|
+
methodName,
|
|
63
54
|
cardLast4,
|
|
64
55
|
labels,
|
|
65
56
|
}: OrderPaymentCardProps) {
|
|
66
57
|
const l = { ...defaultOrderLabels, ...labels }
|
|
67
58
|
|
|
68
|
-
if (!providerId) return null
|
|
59
|
+
if (!providerId && !methodName) return null
|
|
69
60
|
|
|
70
|
-
const title = resolvePaymentTitle(providerId, l.paymentMethodTitles)
|
|
71
|
-
const icon = paymentInfoMap[providerId]?.icon
|
|
61
|
+
const title = resolvePaymentTitle(providerId, l.paymentMethodTitles, methodName)
|
|
62
|
+
const icon = (providerId && paymentInfoMap[providerId]?.icon) || null
|
|
72
63
|
|
|
73
64
|
return (
|
|
74
65
|
<div className="bg-card rounded-xl p-5 shadow-sm">
|