@storepecker/storefront-core 2.6.3 → 2.9.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/api/index.cjs +90 -46
- package/dist/api/index.d.cts +99 -7
- package/dist/api/index.d.ts +99 -7
- package/dist/api/index.js +3 -3
- package/dist/buy-now-B1dkx82V.d.cts +197 -0
- package/dist/buy-now-BgKd5p4J.d.ts +197 -0
- package/dist/checkout/index.cjs +78 -31
- package/dist/checkout/index.d.cts +47 -9
- package/dist/checkout/index.d.ts +47 -9
- package/dist/checkout/index.js +64 -18
- package/dist/{chunk-GTV42PDK.cjs → chunk-57UU7IJ2.cjs} +1 -0
- package/dist/{chunk-ZQOESVVE.cjs → chunk-CIBMO44U.cjs} +26 -31
- package/dist/{chunk-5BT3MH4A.cjs → chunk-ETXIP5XE.cjs} +3 -3
- package/dist/{chunk-LZADKC4Y.cjs → chunk-H6FJYRO3.cjs} +55 -3
- package/dist/{chunk-ME6Z7TZW.js → chunk-KCLVR6G5.js} +45 -4
- package/dist/{chunk-LCMJYFHC.cjs → chunk-NQZ5GUOG.cjs} +0 -1
- package/dist/{chunk-4C4NTH6O.js → chunk-OOFYY6GR.js} +1 -0
- package/dist/{chunk-PGBYYKFQ.js → chunk-SU5LVRZD.js} +9 -14
- package/dist/{chunk-QSHOJ3NJ.cjs → chunk-TFWTQTWE.cjs} +40 -19
- package/dist/{chunk-H32TICAM.js → chunk-TH7OAMGC.js} +0 -1
- package/dist/{chunk-VYHAWRJR.js → chunk-UWW5YIHL.js} +39 -18
- package/dist/{chunk-TY5NK7NW.js → chunk-YMZZCVZ2.js} +1 -1
- package/dist/components/digital-product-download-modal.d.cts +1 -1
- package/dist/components/digital-product-download-modal.d.ts +1 -1
- package/dist/components/index.d.cts +2 -2
- package/dist/components/index.d.ts +2 -2
- package/dist/components/theme-data-initializer.d.cts +2 -2
- package/dist/components/theme-data-initializer.d.ts +2 -2
- package/dist/hooks/index.cjs +564 -29
- package/dist/hooks/index.d.cts +179 -2
- package/dist/hooks/index.d.ts +179 -2
- package/dist/hooks/index.js +541 -10
- package/dist/middleware/index.cjs +3 -3
- package/dist/middleware/index.js +1 -1
- package/dist/models/index.d.cts +2 -1
- package/dist/models/index.d.ts +2 -1
- package/dist/{orders-9_scVq_M.d.cts → orders-COKWr7K7.d.cts} +1 -0
- package/dist/{orders-C1XZr8tx.d.ts → orders-Cp8qNCrl.d.ts} +1 -0
- package/dist/{pixelEvents-D0sH22Er.d.ts → pixelEvents-2Tb-_fRP.d.ts} +2 -1
- package/dist/{pixelEvents-uiPHbiAQ.d.cts → pixelEvents-BJNH06rS.d.cts} +2 -1
- package/dist/store/index.cjs +9 -9
- package/dist/store/index.d.cts +9 -4
- package/dist/store/index.d.ts +9 -4
- package/dist/store/index.js +4 -4
- package/dist/utils/index.cjs +7 -7
- package/dist/utils/index.d.cts +4 -3
- package/dist/utils/index.d.ts +4 -3
- package/dist/utils/index.js +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { A as Address } from './address-DwBZHzbI.cjs';
|
|
2
|
+
import { C as Cart, c as Coupon } from './cart-CyN2JQTw.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Types shared by the two checkout surfaces that price an *inline* selection
|
|
6
|
+
* rather than the persisted server cart:
|
|
7
|
+
*
|
|
8
|
+
* - **Buy Now** (`BuyNow` namespace, `useBuyNow`) — one variant, guest or
|
|
9
|
+
* logged-in.
|
|
10
|
+
* - **Public checkout** (`PublicCheckout` namespace, `usePublicCheckout`) —
|
|
11
|
+
* the guest's whole local cart.
|
|
12
|
+
*
|
|
13
|
+
* Customized products are **login-only by design**: every guest payload omits
|
|
14
|
+
* customization fields, and the themes gate the customization form behind
|
|
15
|
+
* login for both add-to-cart and Buy Now.
|
|
16
|
+
*
|
|
17
|
+
* Both flows preview against cart-shaped responses and, for guests, place
|
|
18
|
+
* through the same `POST /customer/public_order/` endpoint — so the
|
|
19
|
+
* address/contact/placement shapes here are common; only the item selection
|
|
20
|
+
* (and each namespace's own PreviewPayload) differs.
|
|
21
|
+
*/
|
|
22
|
+
declare namespace Checkout {
|
|
23
|
+
/**
|
|
24
|
+
* One personalization answer.
|
|
25
|
+
*
|
|
26
|
+
* Login-only: used by `BuyNow.PreviewPayload` and `BuyNow.PlaceOrderPayload`
|
|
27
|
+
* (the authenticated placement). No guest payload carries it — guests must
|
|
28
|
+
* log in to buy customized products. `variant_id` is part of the API contract
|
|
29
|
+
* even though Buy Now sends a single line. The server recomputes
|
|
30
|
+
* customization prices — any client-sent price is ignored.
|
|
31
|
+
*/
|
|
32
|
+
interface CustomizationInput {
|
|
33
|
+
variant_id: number;
|
|
34
|
+
customization_option: number;
|
|
35
|
+
customer_input: string;
|
|
36
|
+
live_option_id?: string;
|
|
37
|
+
live_customization_option_id?: number;
|
|
38
|
+
}
|
|
39
|
+
interface GuestAddress {
|
|
40
|
+
country_obj: number | string;
|
|
41
|
+
state_obj: number | string;
|
|
42
|
+
pincode: string;
|
|
43
|
+
country?: string;
|
|
44
|
+
state?: string;
|
|
45
|
+
}
|
|
46
|
+
type GuestAddressForm = Omit<Address, "id" | "customer" | "latitude" | "longitude"> & {
|
|
47
|
+
country_obj: number | string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Full shipping/display address carried on a guest order — the `address`
|
|
51
|
+
* nested inside `GuestContact`. Display only; account linking reads the
|
|
52
|
+
* top-level contact fields, not these.
|
|
53
|
+
*/
|
|
54
|
+
interface GuestOrderAddress {
|
|
55
|
+
customer_name: string;
|
|
56
|
+
customer_phone: string;
|
|
57
|
+
customer_country_code: string;
|
|
58
|
+
address: string;
|
|
59
|
+
city: string;
|
|
60
|
+
state: string;
|
|
61
|
+
country: string;
|
|
62
|
+
pincode: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Top-level `email` / `phone` / `country_code` drive account linking on the
|
|
66
|
+
* backend (email+phone match → link to that account; else phone-OTP match →
|
|
67
|
+
* link; else create silently, so checkout never fails on a taken email).
|
|
68
|
+
* `address.customer_phone` is display/shipping only and does not link.
|
|
69
|
+
*/
|
|
70
|
+
interface GuestContact {
|
|
71
|
+
email: string;
|
|
72
|
+
phone: string;
|
|
73
|
+
country_code: string;
|
|
74
|
+
address: GuestOrderAddress;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Cart-shaped pricing result returned by BOTH preview endpoints
|
|
78
|
+
* (`buyNowPreview`, `publicCheckoutPreview`), deliberately key-compatible
|
|
79
|
+
* with `GET /customer/cart/` so one set of theme checkout components renders
|
|
80
|
+
* the real cart and either preview alike.
|
|
81
|
+
*
|
|
82
|
+
* `id` is always null — nothing was persisted. `missing_items` is advisory
|
|
83
|
+
* here but fatal at placement, so surface it as a warning rather than an
|
|
84
|
+
* error. `is_cod_enabled` / `cod_amount` are populated only by the public
|
|
85
|
+
* preview, and `cod_amount` is already inside `total_amount` when the request
|
|
86
|
+
* set `is_cod` — never add it locally as well.
|
|
87
|
+
*/
|
|
88
|
+
type PreviewResponse = Cart.Root & {
|
|
89
|
+
id?: null;
|
|
90
|
+
applied_coupons?: Coupon | Record<string, never>;
|
|
91
|
+
total_coupon_discount?: number;
|
|
92
|
+
selected_shipping_option_name?: string;
|
|
93
|
+
shipping_option_unavailable?: boolean;
|
|
94
|
+
shipping_option_unavailable_reason?: string;
|
|
95
|
+
missing_items: {
|
|
96
|
+
[variantId: number]: number;
|
|
97
|
+
};
|
|
98
|
+
is_cod_enabled?: boolean;
|
|
99
|
+
cod_amount?: number | string;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Body for `POST /customer/public_order/` — the guest placement endpoint,
|
|
103
|
+
* multi-item by nature. Two callers:
|
|
104
|
+
*
|
|
105
|
+
* - `placeGuestBuyNowOrder` (guest Buy Now): single-entry `cart_items`,
|
|
106
|
+
* `is_buy_now: true`.
|
|
107
|
+
* - `placePublicOrder` (public checkout): the whole local cart, flag omitted.
|
|
108
|
+
*
|
|
109
|
+
* No customization fields — customized products are login-only, so guests
|
|
110
|
+
* can never place one.
|
|
111
|
+
*/
|
|
112
|
+
interface GuestPlaceOrderPayload extends GuestContact {
|
|
113
|
+
/** `{ [variant_id]: quantity }`. */
|
|
114
|
+
cart_items: Record<number, number>;
|
|
115
|
+
is_buy_now?: boolean;
|
|
116
|
+
coupon_codes?: string[];
|
|
117
|
+
shipping_option_id?: number;
|
|
118
|
+
is_cod?: boolean;
|
|
119
|
+
phonepe_redirect_url?: string;
|
|
120
|
+
stripe_redirect_url?: string;
|
|
121
|
+
tabby_redirect_url?: string;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Public checkout — a guest buys a multi-item cart held entirely in frontend
|
|
127
|
+
* state (see `LocalCart`), with no server cart and no customer record. Gated by
|
|
128
|
+
* the store's `public_checkout_enabled` flag; unlike Buy Now there is no plan
|
|
129
|
+
* gate, so the preview never returns FEATURE_NOT_AVAILABLE.
|
|
130
|
+
*
|
|
131
|
+
* Shared address/contact/placement shapes come from the `Checkout` namespace —
|
|
132
|
+
* placement is the same `POST /customer/public_order/` call Buy Now uses,
|
|
133
|
+
* minus the `is_buy_now` flag.
|
|
134
|
+
*/
|
|
135
|
+
declare namespace PublicCheckout {
|
|
136
|
+
interface PreviewPayload {
|
|
137
|
+
/** `{ [variant_id]: quantity }` — the local cart. Quantities must be >= 1. */
|
|
138
|
+
cart_items: Record<number, number>;
|
|
139
|
+
coupon_codes?: string[];
|
|
140
|
+
/** Guest: inline destination. Safe to pass the placement address unchanged. */
|
|
141
|
+
address?: Checkout.GuestAddress;
|
|
142
|
+
/** Logged-in only: a saved address id, takes precedence over `address`. */
|
|
143
|
+
address_id?: number;
|
|
144
|
+
shipping_option_id?: number;
|
|
145
|
+
/** Drives whether the COD charge is inside the returned total. */
|
|
146
|
+
is_cod?: boolean;
|
|
147
|
+
}
|
|
148
|
+
type PreviewResponse = Checkout.PreviewResponse;
|
|
149
|
+
type PlaceOrderPayload = Checkout.GuestPlaceOrderPayload;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Buy Now — one product, one quantity, straight to checkout, bypassing the cart.
|
|
154
|
+
* The selection lives only in frontend state; the customer's persistent cart is
|
|
155
|
+
* never read or modified, so a customer with items in their cart still has them
|
|
156
|
+
* after buying this way.
|
|
157
|
+
*
|
|
158
|
+
* Only the single-item shapes live here. Address, contact, placement and the
|
|
159
|
+
* preview response are shared with public checkout — see the `Checkout`
|
|
160
|
+
* namespace. The aliases below keep older `BuyNow.*` imports working.
|
|
161
|
+
*/
|
|
162
|
+
declare namespace BuyNow {
|
|
163
|
+
type CustomizationInput = Checkout.CustomizationInput;
|
|
164
|
+
type GuestAddress = Checkout.GuestAddress;
|
|
165
|
+
type GuestAddressForm = Checkout.GuestAddressForm;
|
|
166
|
+
type GuestOrderAddress = Checkout.GuestOrderAddress;
|
|
167
|
+
type GuestContact = Checkout.GuestContact;
|
|
168
|
+
type PreviewResponse = Checkout.PreviewResponse;
|
|
169
|
+
type GuestPlaceOrderPayload = Checkout.GuestPlaceOrderPayload;
|
|
170
|
+
/** Body for `POST /customer/buy_now/preview/`. Never persists — safe to re-call. */
|
|
171
|
+
interface PreviewPayload {
|
|
172
|
+
variant_id: number;
|
|
173
|
+
quantity: number;
|
|
174
|
+
coupon_codes?: string[];
|
|
175
|
+
/** Logged-in customer: a saved address id. */
|
|
176
|
+
address_id?: number;
|
|
177
|
+
/** Guest: inline destination for tax/shipping. */
|
|
178
|
+
address?: Checkout.GuestAddress;
|
|
179
|
+
shipping_option_id?: number;
|
|
180
|
+
customization_inputs?: Checkout.CustomizationInput[];
|
|
181
|
+
}
|
|
182
|
+
/** Body for `POST /customer/buy_now/` (logged-in placement). */
|
|
183
|
+
interface PlaceOrderPayload {
|
|
184
|
+
variant_id: number;
|
|
185
|
+
quantity: number;
|
|
186
|
+
address_id: number;
|
|
187
|
+
coupon_codes?: string[];
|
|
188
|
+
shipping_option_id?: number;
|
|
189
|
+
customization_inputs?: Checkout.CustomizationInput[];
|
|
190
|
+
is_cod?: boolean;
|
|
191
|
+
phonepe_redirect_url?: string;
|
|
192
|
+
stripe_redirect_url?: string;
|
|
193
|
+
tabby_redirect_url?: string;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export { BuyNow as B, Checkout as C, PublicCheckout as P };
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { A as Address } from './address-DwBZHzbI.js';
|
|
2
|
+
import { C as Cart, c as Coupon } from './cart-BGIsIZdM.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Types shared by the two checkout surfaces that price an *inline* selection
|
|
6
|
+
* rather than the persisted server cart:
|
|
7
|
+
*
|
|
8
|
+
* - **Buy Now** (`BuyNow` namespace, `useBuyNow`) — one variant, guest or
|
|
9
|
+
* logged-in.
|
|
10
|
+
* - **Public checkout** (`PublicCheckout` namespace, `usePublicCheckout`) —
|
|
11
|
+
* the guest's whole local cart.
|
|
12
|
+
*
|
|
13
|
+
* Customized products are **login-only by design**: every guest payload omits
|
|
14
|
+
* customization fields, and the themes gate the customization form behind
|
|
15
|
+
* login for both add-to-cart and Buy Now.
|
|
16
|
+
*
|
|
17
|
+
* Both flows preview against cart-shaped responses and, for guests, place
|
|
18
|
+
* through the same `POST /customer/public_order/` endpoint — so the
|
|
19
|
+
* address/contact/placement shapes here are common; only the item selection
|
|
20
|
+
* (and each namespace's own PreviewPayload) differs.
|
|
21
|
+
*/
|
|
22
|
+
declare namespace Checkout {
|
|
23
|
+
/**
|
|
24
|
+
* One personalization answer.
|
|
25
|
+
*
|
|
26
|
+
* Login-only: used by `BuyNow.PreviewPayload` and `BuyNow.PlaceOrderPayload`
|
|
27
|
+
* (the authenticated placement). No guest payload carries it — guests must
|
|
28
|
+
* log in to buy customized products. `variant_id` is part of the API contract
|
|
29
|
+
* even though Buy Now sends a single line. The server recomputes
|
|
30
|
+
* customization prices — any client-sent price is ignored.
|
|
31
|
+
*/
|
|
32
|
+
interface CustomizationInput {
|
|
33
|
+
variant_id: number;
|
|
34
|
+
customization_option: number;
|
|
35
|
+
customer_input: string;
|
|
36
|
+
live_option_id?: string;
|
|
37
|
+
live_customization_option_id?: number;
|
|
38
|
+
}
|
|
39
|
+
interface GuestAddress {
|
|
40
|
+
country_obj: number | string;
|
|
41
|
+
state_obj: number | string;
|
|
42
|
+
pincode: string;
|
|
43
|
+
country?: string;
|
|
44
|
+
state?: string;
|
|
45
|
+
}
|
|
46
|
+
type GuestAddressForm = Omit<Address, "id" | "customer" | "latitude" | "longitude"> & {
|
|
47
|
+
country_obj: number | string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Full shipping/display address carried on a guest order — the `address`
|
|
51
|
+
* nested inside `GuestContact`. Display only; account linking reads the
|
|
52
|
+
* top-level contact fields, not these.
|
|
53
|
+
*/
|
|
54
|
+
interface GuestOrderAddress {
|
|
55
|
+
customer_name: string;
|
|
56
|
+
customer_phone: string;
|
|
57
|
+
customer_country_code: string;
|
|
58
|
+
address: string;
|
|
59
|
+
city: string;
|
|
60
|
+
state: string;
|
|
61
|
+
country: string;
|
|
62
|
+
pincode: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Top-level `email` / `phone` / `country_code` drive account linking on the
|
|
66
|
+
* backend (email+phone match → link to that account; else phone-OTP match →
|
|
67
|
+
* link; else create silently, so checkout never fails on a taken email).
|
|
68
|
+
* `address.customer_phone` is display/shipping only and does not link.
|
|
69
|
+
*/
|
|
70
|
+
interface GuestContact {
|
|
71
|
+
email: string;
|
|
72
|
+
phone: string;
|
|
73
|
+
country_code: string;
|
|
74
|
+
address: GuestOrderAddress;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Cart-shaped pricing result returned by BOTH preview endpoints
|
|
78
|
+
* (`buyNowPreview`, `publicCheckoutPreview`), deliberately key-compatible
|
|
79
|
+
* with `GET /customer/cart/` so one set of theme checkout components renders
|
|
80
|
+
* the real cart and either preview alike.
|
|
81
|
+
*
|
|
82
|
+
* `id` is always null — nothing was persisted. `missing_items` is advisory
|
|
83
|
+
* here but fatal at placement, so surface it as a warning rather than an
|
|
84
|
+
* error. `is_cod_enabled` / `cod_amount` are populated only by the public
|
|
85
|
+
* preview, and `cod_amount` is already inside `total_amount` when the request
|
|
86
|
+
* set `is_cod` — never add it locally as well.
|
|
87
|
+
*/
|
|
88
|
+
type PreviewResponse = Cart.Root & {
|
|
89
|
+
id?: null;
|
|
90
|
+
applied_coupons?: Coupon | Record<string, never>;
|
|
91
|
+
total_coupon_discount?: number;
|
|
92
|
+
selected_shipping_option_name?: string;
|
|
93
|
+
shipping_option_unavailable?: boolean;
|
|
94
|
+
shipping_option_unavailable_reason?: string;
|
|
95
|
+
missing_items: {
|
|
96
|
+
[variantId: number]: number;
|
|
97
|
+
};
|
|
98
|
+
is_cod_enabled?: boolean;
|
|
99
|
+
cod_amount?: number | string;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Body for `POST /customer/public_order/` — the guest placement endpoint,
|
|
103
|
+
* multi-item by nature. Two callers:
|
|
104
|
+
*
|
|
105
|
+
* - `placeGuestBuyNowOrder` (guest Buy Now): single-entry `cart_items`,
|
|
106
|
+
* `is_buy_now: true`.
|
|
107
|
+
* - `placePublicOrder` (public checkout): the whole local cart, flag omitted.
|
|
108
|
+
*
|
|
109
|
+
* No customization fields — customized products are login-only, so guests
|
|
110
|
+
* can never place one.
|
|
111
|
+
*/
|
|
112
|
+
interface GuestPlaceOrderPayload extends GuestContact {
|
|
113
|
+
/** `{ [variant_id]: quantity }`. */
|
|
114
|
+
cart_items: Record<number, number>;
|
|
115
|
+
is_buy_now?: boolean;
|
|
116
|
+
coupon_codes?: string[];
|
|
117
|
+
shipping_option_id?: number;
|
|
118
|
+
is_cod?: boolean;
|
|
119
|
+
phonepe_redirect_url?: string;
|
|
120
|
+
stripe_redirect_url?: string;
|
|
121
|
+
tabby_redirect_url?: string;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Public checkout — a guest buys a multi-item cart held entirely in frontend
|
|
127
|
+
* state (see `LocalCart`), with no server cart and no customer record. Gated by
|
|
128
|
+
* the store's `public_checkout_enabled` flag; unlike Buy Now there is no plan
|
|
129
|
+
* gate, so the preview never returns FEATURE_NOT_AVAILABLE.
|
|
130
|
+
*
|
|
131
|
+
* Shared address/contact/placement shapes come from the `Checkout` namespace —
|
|
132
|
+
* placement is the same `POST /customer/public_order/` call Buy Now uses,
|
|
133
|
+
* minus the `is_buy_now` flag.
|
|
134
|
+
*/
|
|
135
|
+
declare namespace PublicCheckout {
|
|
136
|
+
interface PreviewPayload {
|
|
137
|
+
/** `{ [variant_id]: quantity }` — the local cart. Quantities must be >= 1. */
|
|
138
|
+
cart_items: Record<number, number>;
|
|
139
|
+
coupon_codes?: string[];
|
|
140
|
+
/** Guest: inline destination. Safe to pass the placement address unchanged. */
|
|
141
|
+
address?: Checkout.GuestAddress;
|
|
142
|
+
/** Logged-in only: a saved address id, takes precedence over `address`. */
|
|
143
|
+
address_id?: number;
|
|
144
|
+
shipping_option_id?: number;
|
|
145
|
+
/** Drives whether the COD charge is inside the returned total. */
|
|
146
|
+
is_cod?: boolean;
|
|
147
|
+
}
|
|
148
|
+
type PreviewResponse = Checkout.PreviewResponse;
|
|
149
|
+
type PlaceOrderPayload = Checkout.GuestPlaceOrderPayload;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Buy Now — one product, one quantity, straight to checkout, bypassing the cart.
|
|
154
|
+
* The selection lives only in frontend state; the customer's persistent cart is
|
|
155
|
+
* never read or modified, so a customer with items in their cart still has them
|
|
156
|
+
* after buying this way.
|
|
157
|
+
*
|
|
158
|
+
* Only the single-item shapes live here. Address, contact, placement and the
|
|
159
|
+
* preview response are shared with public checkout — see the `Checkout`
|
|
160
|
+
* namespace. The aliases below keep older `BuyNow.*` imports working.
|
|
161
|
+
*/
|
|
162
|
+
declare namespace BuyNow {
|
|
163
|
+
type CustomizationInput = Checkout.CustomizationInput;
|
|
164
|
+
type GuestAddress = Checkout.GuestAddress;
|
|
165
|
+
type GuestAddressForm = Checkout.GuestAddressForm;
|
|
166
|
+
type GuestOrderAddress = Checkout.GuestOrderAddress;
|
|
167
|
+
type GuestContact = Checkout.GuestContact;
|
|
168
|
+
type PreviewResponse = Checkout.PreviewResponse;
|
|
169
|
+
type GuestPlaceOrderPayload = Checkout.GuestPlaceOrderPayload;
|
|
170
|
+
/** Body for `POST /customer/buy_now/preview/`. Never persists — safe to re-call. */
|
|
171
|
+
interface PreviewPayload {
|
|
172
|
+
variant_id: number;
|
|
173
|
+
quantity: number;
|
|
174
|
+
coupon_codes?: string[];
|
|
175
|
+
/** Logged-in customer: a saved address id. */
|
|
176
|
+
address_id?: number;
|
|
177
|
+
/** Guest: inline destination for tax/shipping. */
|
|
178
|
+
address?: Checkout.GuestAddress;
|
|
179
|
+
shipping_option_id?: number;
|
|
180
|
+
customization_inputs?: Checkout.CustomizationInput[];
|
|
181
|
+
}
|
|
182
|
+
/** Body for `POST /customer/buy_now/` (logged-in placement). */
|
|
183
|
+
interface PlaceOrderPayload {
|
|
184
|
+
variant_id: number;
|
|
185
|
+
quantity: number;
|
|
186
|
+
address_id: number;
|
|
187
|
+
coupon_codes?: string[];
|
|
188
|
+
shipping_option_id?: number;
|
|
189
|
+
customization_inputs?: Checkout.CustomizationInput[];
|
|
190
|
+
is_cod?: boolean;
|
|
191
|
+
phonepe_redirect_url?: string;
|
|
192
|
+
stripe_redirect_url?: string;
|
|
193
|
+
tabby_redirect_url?: string;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export { BuyNow as B, Checkout as C, PublicCheckout as P };
|
package/dist/checkout/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkTFWTQTWE_cjs = require('../chunk-TFWTQTWE.cjs');
|
|
4
4
|
require('../chunk-XFOUNOKO.cjs');
|
|
5
5
|
var chunkK44JZ5NL_cjs = require('../chunk-K44JZ5NL.cjs');
|
|
6
|
-
var
|
|
6
|
+
var chunkH6FJYRO3_cjs = require('../chunk-H6FJYRO3.cjs');
|
|
7
7
|
var chunkTB72NPRM_cjs = require('../chunk-TB72NPRM.cjs');
|
|
8
8
|
require('../chunk-ECHV2JSY.cjs');
|
|
9
9
|
require('../chunk-BBRXE57K.cjs');
|
|
@@ -46,10 +46,52 @@ function calculateCartTotals(cart) {
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
// src/checkout/placement-error.ts
|
|
50
|
+
function describePlacementError(error) {
|
|
51
|
+
const code = error?.response?.data?.error_code || error?.response?.data?.code;
|
|
52
|
+
if (["INVALID_SHIPPING_OPTION", "SHIPPING_OPTION_UNAVAILABLE", "SHIPPING_OPTION_REQUIRED"].includes(code)) {
|
|
53
|
+
return {
|
|
54
|
+
code,
|
|
55
|
+
action: "reset-shipping",
|
|
56
|
+
message: "That shipping option is no longer available. Please choose another."
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (code === "SHIPPING_OPTION_NOT_AVAILABLE_FOR_LOCATION") {
|
|
60
|
+
return {
|
|
61
|
+
code,
|
|
62
|
+
action: "reset-shipping",
|
|
63
|
+
message: "The selected shipping option isn't available for your delivery address."
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (code === "CART_EMPTY") {
|
|
67
|
+
return { code, action: "none", message: "Your cart is no longer available." };
|
|
68
|
+
}
|
|
69
|
+
if (code === "PREORDER_DIRECT_ONLY") {
|
|
70
|
+
return {
|
|
71
|
+
code,
|
|
72
|
+
action: "none",
|
|
73
|
+
message: "A pre-order product is in your cart. Please remove it and purchase it directly with Pre Order."
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (["ITEM_UNAVAILABLE", "CHECKOUT_STOCK_ERROR"].includes(code)) {
|
|
77
|
+
return {
|
|
78
|
+
code,
|
|
79
|
+
action: "refresh-preview",
|
|
80
|
+
message: "Some items are no longer available in the requested quantity."
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
code,
|
|
85
|
+
action: "none",
|
|
86
|
+
message: error?.response?.data?.error || "Unable to place your order. Please try again."
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
49
90
|
// src/checkout/payment-status.ts
|
|
50
|
-
async function checkPhonepeReturnStatus(transactionId, callbacks) {
|
|
91
|
+
async function checkPhonepeReturnStatus(transactionId, callbacks, options) {
|
|
51
92
|
try {
|
|
52
|
-
const
|
|
93
|
+
const checkStatus = options?.isPublic ? chunkH6FJYRO3_cjs.checkPhonepePaymentStatusPublic : chunkH6FJYRO3_cjs.checkPhonepePaymentStatus;
|
|
94
|
+
const response = await checkStatus(transactionId);
|
|
53
95
|
if (response.data.success) {
|
|
54
96
|
callbacks.onSuccess(void 0);
|
|
55
97
|
} else {
|
|
@@ -59,11 +101,13 @@ async function checkPhonepeReturnStatus(transactionId, callbacks) {
|
|
|
59
101
|
callbacks.onFailure();
|
|
60
102
|
}
|
|
61
103
|
}
|
|
62
|
-
async function checkPhonepeReturnStatusWithOrder(transactionId, orderNumber, callbacks) {
|
|
104
|
+
async function checkPhonepeReturnStatusWithOrder(transactionId, orderNumber, callbacks, options) {
|
|
63
105
|
try {
|
|
106
|
+
const checkStatus = options?.isPublic ? chunkH6FJYRO3_cjs.checkPhonepePaymentStatusPublic : chunkH6FJYRO3_cjs.checkPhonepePaymentStatus;
|
|
107
|
+
const getOrder = options?.isPublic ? chunkH6FJYRO3_cjs.getPublicOrderDetailsByNumber : chunkH6FJYRO3_cjs.getOrderDetailsByNumber;
|
|
64
108
|
const [paymentResponse, orderResponse] = await Promise.all([
|
|
65
|
-
|
|
66
|
-
|
|
109
|
+
checkStatus(transactionId),
|
|
110
|
+
getOrder(orderNumber)
|
|
67
111
|
]);
|
|
68
112
|
const order = orderResponse.data;
|
|
69
113
|
callbacks.onOrderLoaded?.(order);
|
|
@@ -80,12 +124,13 @@ async function checkPhonepeReturnStatusWithOrder(transactionId, orderNumber, cal
|
|
|
80
124
|
}
|
|
81
125
|
async function checkStripeReturnStatus(sessionId, orderNumber, paymentLinkUrl, callbacks, options) {
|
|
82
126
|
try {
|
|
83
|
-
const getStatus = options?.isPublic ?
|
|
127
|
+
const getStatus = options?.isPublic ? chunkH6FJYRO3_cjs.getStripePaymentStatusPublic : chunkH6FJYRO3_cjs.getStripePaymentStatus;
|
|
84
128
|
const response = await getStatus(sessionId, orderNumber, paymentLinkUrl);
|
|
85
129
|
const data = response.data;
|
|
86
130
|
if (data.payment_status === "paid" || data.status === "complete") {
|
|
87
131
|
try {
|
|
88
|
-
const
|
|
132
|
+
const getOrder = options?.isPublic ? chunkH6FJYRO3_cjs.getPublicOrderDetailsByNumber : chunkH6FJYRO3_cjs.getOrderDetailsByNumber;
|
|
133
|
+
const orderResponse = await getOrder(orderNumber);
|
|
89
134
|
const order = orderResponse.data;
|
|
90
135
|
callbacks.onOrderLoaded?.(order);
|
|
91
136
|
chunkK44JZ5NL_cjs.pixelEvents.purchase(order);
|
|
@@ -101,20 +146,21 @@ async function checkStripeReturnStatus(sessionId, orderNumber, paymentLinkUrl, c
|
|
|
101
146
|
callbacks.onFailure();
|
|
102
147
|
}
|
|
103
148
|
}
|
|
104
|
-
async function checkTabbyReturnStatus(orderNumber, callbacks) {
|
|
149
|
+
async function checkTabbyReturnStatus(orderNumber, callbacks, options) {
|
|
105
150
|
try {
|
|
106
|
-
const
|
|
151
|
+
const getOrder = options?.isPublic ? chunkH6FJYRO3_cjs.getPublicOrderDetailsByNumber : chunkH6FJYRO3_cjs.getOrderDetailsByNumber;
|
|
152
|
+
const [response, orderResponse] = await Promise.all([
|
|
153
|
+
chunkH6FJYRO3_cjs.verifyTabbyPayment(orderNumber),
|
|
154
|
+
getOrder(orderNumber).catch(() => null)
|
|
155
|
+
]);
|
|
156
|
+
const order = orderResponse?.data;
|
|
157
|
+
if (order) callbacks.onOrderLoaded?.(order);
|
|
107
158
|
if (response.data.order_status === "paid" || response.data.order_status === "confirmed" || response.data.status === "paid") {
|
|
108
|
-
|
|
109
|
-
const orderResponse = await chunkLZADKC4Y_cjs.getOrderDetailsByNumber(orderNumber);
|
|
110
|
-
const order = orderResponse.data;
|
|
111
|
-
callbacks.onOrderLoaded?.(order);
|
|
159
|
+
if (order) {
|
|
112
160
|
chunkK44JZ5NL_cjs.pixelEvents.purchase(order);
|
|
113
161
|
chunkK44JZ5NL_cjs.pixelEvents.checkoutCompleted(order);
|
|
114
|
-
callbacks.onSuccess(order);
|
|
115
|
-
} catch {
|
|
116
|
-
callbacks.onSuccess(void 0);
|
|
117
162
|
}
|
|
163
|
+
callbacks.onSuccess(order ?? void 0);
|
|
118
164
|
} else {
|
|
119
165
|
callbacks.onFailure();
|
|
120
166
|
}
|
|
@@ -125,55 +171,55 @@ async function checkTabbyReturnStatus(orderNumber, callbacks) {
|
|
|
125
171
|
|
|
126
172
|
Object.defineProperty(exports, "applyCheckoutCoupon", {
|
|
127
173
|
enumerable: true,
|
|
128
|
-
get: function () { return
|
|
174
|
+
get: function () { return chunkTFWTQTWE_cjs.applyCheckoutCoupon; }
|
|
129
175
|
});
|
|
130
176
|
Object.defineProperty(exports, "fetchAppliedCoupon", {
|
|
131
177
|
enumerable: true,
|
|
132
|
-
get: function () { return
|
|
178
|
+
get: function () { return chunkTFWTQTWE_cjs.fetchAppliedCoupon; }
|
|
133
179
|
});
|
|
134
180
|
Object.defineProperty(exports, "fetchAvailableCoupons", {
|
|
135
181
|
enumerable: true,
|
|
136
|
-
get: function () { return
|
|
182
|
+
get: function () { return chunkTFWTQTWE_cjs.fetchAvailableCoupons; }
|
|
137
183
|
});
|
|
138
184
|
Object.defineProperty(exports, "handleCODPayment", {
|
|
139
185
|
enumerable: true,
|
|
140
|
-
get: function () { return
|
|
186
|
+
get: function () { return chunkTFWTQTWE_cjs.handleCODPayment; }
|
|
141
187
|
});
|
|
142
188
|
Object.defineProperty(exports, "handlePhonepePayment", {
|
|
143
189
|
enumerable: true,
|
|
144
|
-
get: function () { return
|
|
190
|
+
get: function () { return chunkTFWTQTWE_cjs.handlePhonepePayment; }
|
|
145
191
|
});
|
|
146
192
|
Object.defineProperty(exports, "handleRazorpayFail", {
|
|
147
193
|
enumerable: true,
|
|
148
|
-
get: function () { return
|
|
194
|
+
get: function () { return chunkTFWTQTWE_cjs.handleRazorpayFail; }
|
|
149
195
|
});
|
|
150
196
|
Object.defineProperty(exports, "handleRazorpaySuccess", {
|
|
151
197
|
enumerable: true,
|
|
152
|
-
get: function () { return
|
|
198
|
+
get: function () { return chunkTFWTQTWE_cjs.handleRazorpaySuccess; }
|
|
153
199
|
});
|
|
154
200
|
Object.defineProperty(exports, "handleStripePayment", {
|
|
155
201
|
enumerable: true,
|
|
156
|
-
get: function () { return
|
|
202
|
+
get: function () { return chunkTFWTQTWE_cjs.handleStripePayment; }
|
|
157
203
|
});
|
|
158
204
|
Object.defineProperty(exports, "handleStripeSuccess", {
|
|
159
205
|
enumerable: true,
|
|
160
|
-
get: function () { return
|
|
206
|
+
get: function () { return chunkTFWTQTWE_cjs.handleStripeSuccess; }
|
|
161
207
|
});
|
|
162
208
|
Object.defineProperty(exports, "handleTabbyPayment", {
|
|
163
209
|
enumerable: true,
|
|
164
|
-
get: function () { return
|
|
210
|
+
get: function () { return chunkTFWTQTWE_cjs.handleTabbyPayment; }
|
|
165
211
|
});
|
|
166
212
|
Object.defineProperty(exports, "openRazorpayCheckout", {
|
|
167
213
|
enumerable: true,
|
|
168
|
-
get: function () { return
|
|
214
|
+
get: function () { return chunkTFWTQTWE_cjs.openRazorpayCheckout; }
|
|
169
215
|
});
|
|
170
216
|
Object.defineProperty(exports, "processPayment", {
|
|
171
217
|
enumerable: true,
|
|
172
|
-
get: function () { return
|
|
218
|
+
get: function () { return chunkTFWTQTWE_cjs.processPayment; }
|
|
173
219
|
});
|
|
174
220
|
Object.defineProperty(exports, "removeCheckoutCoupon", {
|
|
175
221
|
enumerable: true,
|
|
176
|
-
get: function () { return
|
|
222
|
+
get: function () { return chunkTFWTQTWE_cjs.removeCheckoutCoupon; }
|
|
177
223
|
});
|
|
178
224
|
Object.defineProperty(exports, "IP_API_CACHE_KEY", {
|
|
179
225
|
enumerable: true,
|
|
@@ -232,3 +278,4 @@ exports.checkPhonepeReturnStatus = checkPhonepeReturnStatus;
|
|
|
232
278
|
exports.checkPhonepeReturnStatusWithOrder = checkPhonepeReturnStatusWithOrder;
|
|
233
279
|
exports.checkStripeReturnStatus = checkStripeReturnStatus;
|
|
234
280
|
exports.checkTabbyReturnStatus = checkTabbyReturnStatus;
|
|
281
|
+
exports.describePlacementError = describePlacementError;
|