@storepecker/storefront-core 1.0.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/address-DQEZzyUG.d.cts +19 -0
- package/dist/address-DQEZzyUG.d.ts +19 -0
- package/dist/api/index.cjs +367 -0
- package/dist/api/index.d.cts +127 -0
- package/dist/api/index.d.ts +127 -0
- package/dist/api/index.js +131 -0
- package/dist/booking-ClX-dhX7.d.ts +131 -0
- package/dist/booking-Drl7-IL7.d.cts +131 -0
- package/dist/cart-DVrn8hD0.d.cts +367 -0
- package/dist/cart-DVrn8hD0.d.ts +367 -0
- package/dist/checkout/index.cjs +228 -0
- package/dist/checkout/index.d.cts +251 -0
- package/dist/checkout/index.d.ts +251 -0
- package/dist/checkout/index.js +122 -0
- package/dist/chunk-4CVKE6CC.cjs +312 -0
- package/dist/chunk-4MJMNIAB.js +123 -0
- package/dist/chunk-57ZBPAXU.js +114 -0
- package/dist/chunk-7MQOVWLW.js +40 -0
- package/dist/chunk-7UH6REGV.js +12 -0
- package/dist/chunk-A6IO3HIN.cjs +151 -0
- package/dist/chunk-CFF632IQ.cjs +100 -0
- package/dist/chunk-CSISWBZZ.js +121 -0
- package/dist/chunk-E7WPE3PV.js +98 -0
- package/dist/chunk-FLBJKM6G.js +83 -0
- package/dist/chunk-GB3HW6DM.js +61 -0
- package/dist/chunk-GH75WUO2.cjs +42 -0
- package/dist/chunk-GQTO5ZE2.cjs +96 -0
- package/dist/chunk-JHGXIIBZ.cjs +37 -0
- package/dist/chunk-JQMLHRWL.js +21 -0
- package/dist/chunk-K44JZ5NL.cjs +212 -0
- package/dist/chunk-K5B62JZO.cjs +154 -0
- package/dist/chunk-KWKHHRRJ.cjs +15 -0
- package/dist/chunk-LBGIUNM6.js +30 -0
- package/dist/chunk-LC5ZAUKL.cjs +220 -0
- package/dist/chunk-N3CTXRFT.cjs +30 -0
- package/dist/chunk-QCQCFYYR.js +206 -0
- package/dist/chunk-QM73PI5L.cjs +218 -0
- package/dist/chunk-RCXQJ6XC.cjs +131 -0
- package/dist/chunk-UM24VDYB.js +216 -0
- package/dist/chunk-UXLUE3HW.cjs +69 -0
- package/dist/chunk-WFDKKOO7.js +210 -0
- package/dist/chunk-YUPBTD4M.js +289 -0
- package/dist/components/index.cjs +576 -0
- package/dist/components/index.css +329 -0
- package/dist/components/index.d.cts +58 -0
- package/dist/components/index.d.ts +58 -0
- package/dist/components/index.js +569 -0
- package/dist/coupons-C7iJ-1cy.d.cts +37 -0
- package/dist/coupons-CnfTKL1i.d.ts +37 -0
- package/dist/hooks/index.cjs +381 -0
- package/dist/hooks/index.d.cts +123 -0
- package/dist/hooks/index.d.ts +123 -0
- package/dist/hooks/index.js +364 -0
- package/dist/index-DTyIuLuI.d.cts +18 -0
- package/dist/index-DTyIuLuI.d.ts +18 -0
- package/dist/index.cjs +14 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/models/index.cjs +2 -0
- package/dist/models/index.d.cts +53 -0
- package/dist/models/index.d.ts +53 -0
- package/dist/models/index.js +1 -0
- package/dist/orders-CkUzv5Xh.d.ts +159 -0
- package/dist/orders-D0oC9ugD.d.cts +159 -0
- package/dist/phonepe-D7vn-9SR.d.cts +27 -0
- package/dist/phonepe-D7vn-9SR.d.ts +27 -0
- package/dist/store/index.cjs +149 -0
- package/dist/store/index.d.cts +46 -0
- package/dist/store/index.d.ts +46 -0
- package/dist/store/index.js +141 -0
- package/dist/useAddressForm-C-Uzug4d.d.ts +42 -0
- package/dist/useAddressForm-DgkCP1nG.d.cts +42 -0
- package/dist/utils/index.cjs +535 -0
- package/dist/utils/index.d.cts +507 -0
- package/dist/utils/index.d.ts +507 -0
- package/dist/utils/index.js +342 -0
- package/dist/wishlist-BzhnCAQD.d.ts +41 -0
- package/dist/wishlist-CBCZD66Y.d.cts +41 -0
- package/package.json +134 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import * as Yup from 'yup';
|
|
2
|
+
import { C as Cart } from '../cart-DVrn8hD0.cjs';
|
|
3
|
+
import { C as Coupon } from '../coupons-C7iJ-1cy.cjs';
|
|
4
|
+
import { O as Order } from '../orders-D0oC9ugD.cjs';
|
|
5
|
+
import 'react-toastify';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Cache key for IP geolocation data (used by analytics collector and address form prefill).
|
|
9
|
+
*/
|
|
10
|
+
declare const IP_API_CACHE_KEY = "ip_geolocation_data";
|
|
11
|
+
interface AddressFormValues {
|
|
12
|
+
customer_phone: string;
|
|
13
|
+
customer_country_code: string;
|
|
14
|
+
customer_name: string;
|
|
15
|
+
pincode: string;
|
|
16
|
+
state_obj: string;
|
|
17
|
+
address: string;
|
|
18
|
+
street_name: string;
|
|
19
|
+
area: string;
|
|
20
|
+
city: string;
|
|
21
|
+
customer_email: string;
|
|
22
|
+
}
|
|
23
|
+
declare const addressFormInitialValues: AddressFormValues;
|
|
24
|
+
/**
|
|
25
|
+
* Validates a phone number using libphonenumber-js
|
|
26
|
+
*/
|
|
27
|
+
declare function isValidPhoneNumber(input: string, countryCode: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Yup validation schema for the address form.
|
|
30
|
+
* Uses libphonenumber-js for phone validation.
|
|
31
|
+
* Pincode is optional for UAE (AE) addresses.
|
|
32
|
+
*/
|
|
33
|
+
declare const addressValidationSchema: Yup.ObjectSchema<{
|
|
34
|
+
customer_phone: string;
|
|
35
|
+
customer_name: string;
|
|
36
|
+
pincode: string | undefined;
|
|
37
|
+
state_obj: string;
|
|
38
|
+
address: string;
|
|
39
|
+
street_name: string | undefined;
|
|
40
|
+
area: string | undefined;
|
|
41
|
+
city: string;
|
|
42
|
+
customer_email: string;
|
|
43
|
+
}, Yup.AnyObject, {
|
|
44
|
+
customer_phone: undefined;
|
|
45
|
+
customer_name: undefined;
|
|
46
|
+
pincode: undefined;
|
|
47
|
+
state_obj: undefined;
|
|
48
|
+
address: undefined;
|
|
49
|
+
street_name: undefined;
|
|
50
|
+
area: undefined;
|
|
51
|
+
city: undefined;
|
|
52
|
+
customer_email: undefined;
|
|
53
|
+
}, "">;
|
|
54
|
+
/**
|
|
55
|
+
* Encode an address ID and city into a URL-safe base64 string.
|
|
56
|
+
*/
|
|
57
|
+
declare function encodeAddress(id: number, city: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Decode a previously encoded address string back to id and city.
|
|
60
|
+
*/
|
|
61
|
+
declare function decodeAddress(encoded: string): {
|
|
62
|
+
id: number;
|
|
63
|
+
city: string;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Save address form values to sessionStorage for persistence across page navigations.
|
|
67
|
+
*/
|
|
68
|
+
declare function saveAddressFormToSession(values: AddressFormValues): void;
|
|
69
|
+
/**
|
|
70
|
+
* Load address form values from sessionStorage.
|
|
71
|
+
*/
|
|
72
|
+
declare function loadAddressFormFromSession(): AddressFormValues | null;
|
|
73
|
+
/**
|
|
74
|
+
* Clear address form values from sessionStorage.
|
|
75
|
+
*/
|
|
76
|
+
declare function clearAddressFormSession(): void;
|
|
77
|
+
/**
|
|
78
|
+
* Build the address payload for API submission from form values + selected country/state data.
|
|
79
|
+
*/
|
|
80
|
+
declare function buildAddressPayload(formValues: AddressFormValues, selectedCountry: {
|
|
81
|
+
short_code: string;
|
|
82
|
+
name: string;
|
|
83
|
+
}, states: Array<{
|
|
84
|
+
name: string;
|
|
85
|
+
state_code: string;
|
|
86
|
+
}>): {
|
|
87
|
+
customer_name: string;
|
|
88
|
+
customer_phone: string;
|
|
89
|
+
customer_country_code: string;
|
|
90
|
+
customer_email: string;
|
|
91
|
+
address: string;
|
|
92
|
+
street_name: string;
|
|
93
|
+
area: string;
|
|
94
|
+
city: string;
|
|
95
|
+
state: string;
|
|
96
|
+
state_obj: string;
|
|
97
|
+
country: string;
|
|
98
|
+
pincode: string;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Parse a comma-separated address string (from the API) into its components.
|
|
102
|
+
* The API stores address as "address, street_name, area" concatenated with commas.
|
|
103
|
+
*/
|
|
104
|
+
declare function parseEditAddress(fullAddress: string): {
|
|
105
|
+
address: string;
|
|
106
|
+
street_name: string;
|
|
107
|
+
area: string;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Build the submit payload from form values, selected country, and states list.
|
|
111
|
+
* Converts TLD-based country code (e.g. "IN") to calling code format ("+91"),
|
|
112
|
+
* resolves state name from state ID, and includes country name/id.
|
|
113
|
+
*/
|
|
114
|
+
declare function buildSubmitPayload(values: AddressFormValues & {
|
|
115
|
+
is_default?: boolean;
|
|
116
|
+
}, country: {
|
|
117
|
+
id: number;
|
|
118
|
+
name: string;
|
|
119
|
+
tld_code: string;
|
|
120
|
+
} | null, states: Array<{
|
|
121
|
+
id: number;
|
|
122
|
+
name: string;
|
|
123
|
+
}>): any;
|
|
124
|
+
|
|
125
|
+
interface CartTotals {
|
|
126
|
+
totalSellingAmount: number;
|
|
127
|
+
discountAmount: number;
|
|
128
|
+
isCartEmpty: boolean;
|
|
129
|
+
allInclusiveTax: boolean;
|
|
130
|
+
exclusiveTaxAmount: number;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Calculate cart totals from the cart data.
|
|
134
|
+
* Computes subtotal (based on actual_price or selling_price), discount amount,
|
|
135
|
+
* and tax breakdown (inclusive vs exclusive).
|
|
136
|
+
*/
|
|
137
|
+
declare function calculateCartTotals(cart: Cart.Root | null): CartTotals;
|
|
138
|
+
|
|
139
|
+
interface CouponCallbacks {
|
|
140
|
+
onCartRefresh: () => void | Promise<void>;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Fetch all available coupons for the current store.
|
|
144
|
+
*/
|
|
145
|
+
declare function fetchAvailableCoupons(): Promise<Coupon[]>;
|
|
146
|
+
/**
|
|
147
|
+
* Fetch the currently applied coupon, if any.
|
|
148
|
+
*/
|
|
149
|
+
declare function fetchAppliedCoupon(): Promise<Coupon | null>;
|
|
150
|
+
/**
|
|
151
|
+
* Apply a coupon code. On success, triggers cart refresh via callback.
|
|
152
|
+
* Returns the applied coupon or throws with the error message.
|
|
153
|
+
*/
|
|
154
|
+
declare function applyCheckoutCoupon(code: string, callbacks: CouponCallbacks): Promise<Coupon>;
|
|
155
|
+
/**
|
|
156
|
+
* Remove an applied coupon. On success, triggers cart refresh via callback.
|
|
157
|
+
*/
|
|
158
|
+
declare function removeCheckoutCoupon(couponCode: string, callbacks: CouponCallbacks): Promise<void>;
|
|
159
|
+
|
|
160
|
+
declare global {
|
|
161
|
+
interface Window {
|
|
162
|
+
Razorpay: any;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
interface PaymentCallbacks {
|
|
166
|
+
onSuccess: (order: Order.OrderSummary) => void;
|
|
167
|
+
onFailure: (order: Order.OrderSummary) => void;
|
|
168
|
+
onRedirect: (url: string) => void;
|
|
169
|
+
onStripeModalOpen?: (order: Order.OrderSummary) => void;
|
|
170
|
+
onCartReset: () => void;
|
|
171
|
+
onPaymentStart?: () => void;
|
|
172
|
+
onPaymentEnd?: () => void;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Open the Razorpay checkout widget with the order details.
|
|
176
|
+
*/
|
|
177
|
+
declare function openRazorpayCheckout(order: Order.OrderSummary, callbacks: PaymentCallbacks): void;
|
|
178
|
+
/**
|
|
179
|
+
* Handle Razorpay payment success — call the backend API and fire pixel events.
|
|
180
|
+
*/
|
|
181
|
+
declare function handleRazorpaySuccess(data: {
|
|
182
|
+
razorpay_payment_id: string;
|
|
183
|
+
razorpay_subscription_id?: string;
|
|
184
|
+
razorpay_signature: string;
|
|
185
|
+
order_id: number;
|
|
186
|
+
razorpay_order_id: string;
|
|
187
|
+
payment_id: string;
|
|
188
|
+
}, order: Order.OrderSummary, callbacks: PaymentCallbacks): Promise<void>;
|
|
189
|
+
/**
|
|
190
|
+
* Handle Razorpay payment failure — notify the backend.
|
|
191
|
+
*/
|
|
192
|
+
declare function handleRazorpayFail(order: Order.OrderSummary, callbacks: PaymentCallbacks): Promise<void>;
|
|
193
|
+
/**
|
|
194
|
+
* Handle PhonePe payment — redirect to the PhonePe URL.
|
|
195
|
+
*/
|
|
196
|
+
declare function handlePhonepePayment(order: Order.OrderSummary, callbacks: PaymentCallbacks): void;
|
|
197
|
+
/**
|
|
198
|
+
* Handle Tabby payment — redirect to the Tabby URL.
|
|
199
|
+
*/
|
|
200
|
+
declare function handleTabbyPayment(order: Order.OrderSummary, callbacks: PaymentCallbacks): void;
|
|
201
|
+
/**
|
|
202
|
+
* Handle COD (Cash on Delivery) payment.
|
|
203
|
+
*/
|
|
204
|
+
declare function handleCODPayment(order: Order.OrderSummary, callbacks: PaymentCallbacks, options?: {
|
|
205
|
+
isPublic?: boolean;
|
|
206
|
+
}): Promise<void>;
|
|
207
|
+
/**
|
|
208
|
+
* Handle Stripe payment — open the Stripe modal or redirect.
|
|
209
|
+
*/
|
|
210
|
+
declare function handleStripePayment(order: Order.OrderSummary, callbacks: PaymentCallbacks): void;
|
|
211
|
+
/**
|
|
212
|
+
* Handle Stripe order success after payment intent confirmation.
|
|
213
|
+
*/
|
|
214
|
+
declare function handleStripeSuccess(order: Order.OrderSummary, paymentIntentId: string, callbacks: PaymentCallbacks): Promise<void>;
|
|
215
|
+
/**
|
|
216
|
+
* Route payment to the appropriate gateway based on payment method and order data.
|
|
217
|
+
*
|
|
218
|
+
* For "cod": calls handleCODPayment
|
|
219
|
+
* For "online"/"tabby": checks tabby_redirect_url → Tabby
|
|
220
|
+
* For "online"/"stripe": checks stripe fields → Stripe
|
|
221
|
+
* Otherwise: checks razorpay_public_token → Razorpay, else → PhonePe
|
|
222
|
+
*/
|
|
223
|
+
declare function processPayment(order: Order.OrderSummary, paymentMethod: string, callbacks: PaymentCallbacks, options?: {
|
|
224
|
+
isPublic?: boolean;
|
|
225
|
+
}): void;
|
|
226
|
+
|
|
227
|
+
interface PaymentStatusCallbacks {
|
|
228
|
+
onSuccess: (order: Order.OrderSummary) => void;
|
|
229
|
+
onFailure: () => void;
|
|
230
|
+
onOrderLoaded?: (order: Order.OrderSummary) => void;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Check PhonePe payment status after redirect back from PhonePe.
|
|
234
|
+
*/
|
|
235
|
+
declare function checkPhonepeReturnStatus(transactionId: string, callbacks: PaymentStatusCallbacks): Promise<void>;
|
|
236
|
+
/**
|
|
237
|
+
* Check PhonePe payment status with order details for pixel events.
|
|
238
|
+
*/
|
|
239
|
+
declare function checkPhonepeReturnStatusWithOrder(transactionId: string, orderNumber: number, callbacks: PaymentStatusCallbacks): Promise<void>;
|
|
240
|
+
/**
|
|
241
|
+
* Check Stripe payment status after redirect back from Stripe checkout.
|
|
242
|
+
*/
|
|
243
|
+
declare function checkStripeReturnStatus(sessionId: string, orderNumber: number, paymentLinkUrl: string, callbacks: PaymentStatusCallbacks, options?: {
|
|
244
|
+
isPublic?: boolean;
|
|
245
|
+
}): Promise<void>;
|
|
246
|
+
/**
|
|
247
|
+
* Check Tabby payment status after redirect back from Tabby.
|
|
248
|
+
*/
|
|
249
|
+
declare function checkTabbyReturnStatus(orderNumber: number, callbacks: PaymentStatusCallbacks): Promise<void>;
|
|
250
|
+
|
|
251
|
+
export { type AddressFormValues, type CartTotals, type CouponCallbacks, IP_API_CACHE_KEY, type PaymentCallbacks, type PaymentStatusCallbacks, addressFormInitialValues, addressValidationSchema, applyCheckoutCoupon, buildAddressPayload, buildSubmitPayload, calculateCartTotals, checkPhonepeReturnStatus, checkPhonepeReturnStatusWithOrder, checkStripeReturnStatus, checkTabbyReturnStatus, clearAddressFormSession, decodeAddress, encodeAddress, fetchAppliedCoupon, fetchAvailableCoupons, handleCODPayment, handlePhonepePayment, handleRazorpayFail, handleRazorpaySuccess, handleStripePayment, handleStripeSuccess, handleTabbyPayment, isValidPhoneNumber, loadAddressFormFromSession, openRazorpayCheckout, parseEditAddress, processPayment, removeCheckoutCoupon, saveAddressFormToSession };
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import * as Yup from 'yup';
|
|
2
|
+
import { C as Cart } from '../cart-DVrn8hD0.js';
|
|
3
|
+
import { C as Coupon } from '../coupons-CnfTKL1i.js';
|
|
4
|
+
import { O as Order } from '../orders-CkUzv5Xh.js';
|
|
5
|
+
import 'react-toastify';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Cache key for IP geolocation data (used by analytics collector and address form prefill).
|
|
9
|
+
*/
|
|
10
|
+
declare const IP_API_CACHE_KEY = "ip_geolocation_data";
|
|
11
|
+
interface AddressFormValues {
|
|
12
|
+
customer_phone: string;
|
|
13
|
+
customer_country_code: string;
|
|
14
|
+
customer_name: string;
|
|
15
|
+
pincode: string;
|
|
16
|
+
state_obj: string;
|
|
17
|
+
address: string;
|
|
18
|
+
street_name: string;
|
|
19
|
+
area: string;
|
|
20
|
+
city: string;
|
|
21
|
+
customer_email: string;
|
|
22
|
+
}
|
|
23
|
+
declare const addressFormInitialValues: AddressFormValues;
|
|
24
|
+
/**
|
|
25
|
+
* Validates a phone number using libphonenumber-js
|
|
26
|
+
*/
|
|
27
|
+
declare function isValidPhoneNumber(input: string, countryCode: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Yup validation schema for the address form.
|
|
30
|
+
* Uses libphonenumber-js for phone validation.
|
|
31
|
+
* Pincode is optional for UAE (AE) addresses.
|
|
32
|
+
*/
|
|
33
|
+
declare const addressValidationSchema: Yup.ObjectSchema<{
|
|
34
|
+
customer_phone: string;
|
|
35
|
+
customer_name: string;
|
|
36
|
+
pincode: string | undefined;
|
|
37
|
+
state_obj: string;
|
|
38
|
+
address: string;
|
|
39
|
+
street_name: string | undefined;
|
|
40
|
+
area: string | undefined;
|
|
41
|
+
city: string;
|
|
42
|
+
customer_email: string;
|
|
43
|
+
}, Yup.AnyObject, {
|
|
44
|
+
customer_phone: undefined;
|
|
45
|
+
customer_name: undefined;
|
|
46
|
+
pincode: undefined;
|
|
47
|
+
state_obj: undefined;
|
|
48
|
+
address: undefined;
|
|
49
|
+
street_name: undefined;
|
|
50
|
+
area: undefined;
|
|
51
|
+
city: undefined;
|
|
52
|
+
customer_email: undefined;
|
|
53
|
+
}, "">;
|
|
54
|
+
/**
|
|
55
|
+
* Encode an address ID and city into a URL-safe base64 string.
|
|
56
|
+
*/
|
|
57
|
+
declare function encodeAddress(id: number, city: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* Decode a previously encoded address string back to id and city.
|
|
60
|
+
*/
|
|
61
|
+
declare function decodeAddress(encoded: string): {
|
|
62
|
+
id: number;
|
|
63
|
+
city: string;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Save address form values to sessionStorage for persistence across page navigations.
|
|
67
|
+
*/
|
|
68
|
+
declare function saveAddressFormToSession(values: AddressFormValues): void;
|
|
69
|
+
/**
|
|
70
|
+
* Load address form values from sessionStorage.
|
|
71
|
+
*/
|
|
72
|
+
declare function loadAddressFormFromSession(): AddressFormValues | null;
|
|
73
|
+
/**
|
|
74
|
+
* Clear address form values from sessionStorage.
|
|
75
|
+
*/
|
|
76
|
+
declare function clearAddressFormSession(): void;
|
|
77
|
+
/**
|
|
78
|
+
* Build the address payload for API submission from form values + selected country/state data.
|
|
79
|
+
*/
|
|
80
|
+
declare function buildAddressPayload(formValues: AddressFormValues, selectedCountry: {
|
|
81
|
+
short_code: string;
|
|
82
|
+
name: string;
|
|
83
|
+
}, states: Array<{
|
|
84
|
+
name: string;
|
|
85
|
+
state_code: string;
|
|
86
|
+
}>): {
|
|
87
|
+
customer_name: string;
|
|
88
|
+
customer_phone: string;
|
|
89
|
+
customer_country_code: string;
|
|
90
|
+
customer_email: string;
|
|
91
|
+
address: string;
|
|
92
|
+
street_name: string;
|
|
93
|
+
area: string;
|
|
94
|
+
city: string;
|
|
95
|
+
state: string;
|
|
96
|
+
state_obj: string;
|
|
97
|
+
country: string;
|
|
98
|
+
pincode: string;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Parse a comma-separated address string (from the API) into its components.
|
|
102
|
+
* The API stores address as "address, street_name, area" concatenated with commas.
|
|
103
|
+
*/
|
|
104
|
+
declare function parseEditAddress(fullAddress: string): {
|
|
105
|
+
address: string;
|
|
106
|
+
street_name: string;
|
|
107
|
+
area: string;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Build the submit payload from form values, selected country, and states list.
|
|
111
|
+
* Converts TLD-based country code (e.g. "IN") to calling code format ("+91"),
|
|
112
|
+
* resolves state name from state ID, and includes country name/id.
|
|
113
|
+
*/
|
|
114
|
+
declare function buildSubmitPayload(values: AddressFormValues & {
|
|
115
|
+
is_default?: boolean;
|
|
116
|
+
}, country: {
|
|
117
|
+
id: number;
|
|
118
|
+
name: string;
|
|
119
|
+
tld_code: string;
|
|
120
|
+
} | null, states: Array<{
|
|
121
|
+
id: number;
|
|
122
|
+
name: string;
|
|
123
|
+
}>): any;
|
|
124
|
+
|
|
125
|
+
interface CartTotals {
|
|
126
|
+
totalSellingAmount: number;
|
|
127
|
+
discountAmount: number;
|
|
128
|
+
isCartEmpty: boolean;
|
|
129
|
+
allInclusiveTax: boolean;
|
|
130
|
+
exclusiveTaxAmount: number;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Calculate cart totals from the cart data.
|
|
134
|
+
* Computes subtotal (based on actual_price or selling_price), discount amount,
|
|
135
|
+
* and tax breakdown (inclusive vs exclusive).
|
|
136
|
+
*/
|
|
137
|
+
declare function calculateCartTotals(cart: Cart.Root | null): CartTotals;
|
|
138
|
+
|
|
139
|
+
interface CouponCallbacks {
|
|
140
|
+
onCartRefresh: () => void | Promise<void>;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Fetch all available coupons for the current store.
|
|
144
|
+
*/
|
|
145
|
+
declare function fetchAvailableCoupons(): Promise<Coupon[]>;
|
|
146
|
+
/**
|
|
147
|
+
* Fetch the currently applied coupon, if any.
|
|
148
|
+
*/
|
|
149
|
+
declare function fetchAppliedCoupon(): Promise<Coupon | null>;
|
|
150
|
+
/**
|
|
151
|
+
* Apply a coupon code. On success, triggers cart refresh via callback.
|
|
152
|
+
* Returns the applied coupon or throws with the error message.
|
|
153
|
+
*/
|
|
154
|
+
declare function applyCheckoutCoupon(code: string, callbacks: CouponCallbacks): Promise<Coupon>;
|
|
155
|
+
/**
|
|
156
|
+
* Remove an applied coupon. On success, triggers cart refresh via callback.
|
|
157
|
+
*/
|
|
158
|
+
declare function removeCheckoutCoupon(couponCode: string, callbacks: CouponCallbacks): Promise<void>;
|
|
159
|
+
|
|
160
|
+
declare global {
|
|
161
|
+
interface Window {
|
|
162
|
+
Razorpay: any;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
interface PaymentCallbacks {
|
|
166
|
+
onSuccess: (order: Order.OrderSummary) => void;
|
|
167
|
+
onFailure: (order: Order.OrderSummary) => void;
|
|
168
|
+
onRedirect: (url: string) => void;
|
|
169
|
+
onStripeModalOpen?: (order: Order.OrderSummary) => void;
|
|
170
|
+
onCartReset: () => void;
|
|
171
|
+
onPaymentStart?: () => void;
|
|
172
|
+
onPaymentEnd?: () => void;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Open the Razorpay checkout widget with the order details.
|
|
176
|
+
*/
|
|
177
|
+
declare function openRazorpayCheckout(order: Order.OrderSummary, callbacks: PaymentCallbacks): void;
|
|
178
|
+
/**
|
|
179
|
+
* Handle Razorpay payment success — call the backend API and fire pixel events.
|
|
180
|
+
*/
|
|
181
|
+
declare function handleRazorpaySuccess(data: {
|
|
182
|
+
razorpay_payment_id: string;
|
|
183
|
+
razorpay_subscription_id?: string;
|
|
184
|
+
razorpay_signature: string;
|
|
185
|
+
order_id: number;
|
|
186
|
+
razorpay_order_id: string;
|
|
187
|
+
payment_id: string;
|
|
188
|
+
}, order: Order.OrderSummary, callbacks: PaymentCallbacks): Promise<void>;
|
|
189
|
+
/**
|
|
190
|
+
* Handle Razorpay payment failure — notify the backend.
|
|
191
|
+
*/
|
|
192
|
+
declare function handleRazorpayFail(order: Order.OrderSummary, callbacks: PaymentCallbacks): Promise<void>;
|
|
193
|
+
/**
|
|
194
|
+
* Handle PhonePe payment — redirect to the PhonePe URL.
|
|
195
|
+
*/
|
|
196
|
+
declare function handlePhonepePayment(order: Order.OrderSummary, callbacks: PaymentCallbacks): void;
|
|
197
|
+
/**
|
|
198
|
+
* Handle Tabby payment — redirect to the Tabby URL.
|
|
199
|
+
*/
|
|
200
|
+
declare function handleTabbyPayment(order: Order.OrderSummary, callbacks: PaymentCallbacks): void;
|
|
201
|
+
/**
|
|
202
|
+
* Handle COD (Cash on Delivery) payment.
|
|
203
|
+
*/
|
|
204
|
+
declare function handleCODPayment(order: Order.OrderSummary, callbacks: PaymentCallbacks, options?: {
|
|
205
|
+
isPublic?: boolean;
|
|
206
|
+
}): Promise<void>;
|
|
207
|
+
/**
|
|
208
|
+
* Handle Stripe payment — open the Stripe modal or redirect.
|
|
209
|
+
*/
|
|
210
|
+
declare function handleStripePayment(order: Order.OrderSummary, callbacks: PaymentCallbacks): void;
|
|
211
|
+
/**
|
|
212
|
+
* Handle Stripe order success after payment intent confirmation.
|
|
213
|
+
*/
|
|
214
|
+
declare function handleStripeSuccess(order: Order.OrderSummary, paymentIntentId: string, callbacks: PaymentCallbacks): Promise<void>;
|
|
215
|
+
/**
|
|
216
|
+
* Route payment to the appropriate gateway based on payment method and order data.
|
|
217
|
+
*
|
|
218
|
+
* For "cod": calls handleCODPayment
|
|
219
|
+
* For "online"/"tabby": checks tabby_redirect_url → Tabby
|
|
220
|
+
* For "online"/"stripe": checks stripe fields → Stripe
|
|
221
|
+
* Otherwise: checks razorpay_public_token → Razorpay, else → PhonePe
|
|
222
|
+
*/
|
|
223
|
+
declare function processPayment(order: Order.OrderSummary, paymentMethod: string, callbacks: PaymentCallbacks, options?: {
|
|
224
|
+
isPublic?: boolean;
|
|
225
|
+
}): void;
|
|
226
|
+
|
|
227
|
+
interface PaymentStatusCallbacks {
|
|
228
|
+
onSuccess: (order: Order.OrderSummary) => void;
|
|
229
|
+
onFailure: () => void;
|
|
230
|
+
onOrderLoaded?: (order: Order.OrderSummary) => void;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Check PhonePe payment status after redirect back from PhonePe.
|
|
234
|
+
*/
|
|
235
|
+
declare function checkPhonepeReturnStatus(transactionId: string, callbacks: PaymentStatusCallbacks): Promise<void>;
|
|
236
|
+
/**
|
|
237
|
+
* Check PhonePe payment status with order details for pixel events.
|
|
238
|
+
*/
|
|
239
|
+
declare function checkPhonepeReturnStatusWithOrder(transactionId: string, orderNumber: number, callbacks: PaymentStatusCallbacks): Promise<void>;
|
|
240
|
+
/**
|
|
241
|
+
* Check Stripe payment status after redirect back from Stripe checkout.
|
|
242
|
+
*/
|
|
243
|
+
declare function checkStripeReturnStatus(sessionId: string, orderNumber: number, paymentLinkUrl: string, callbacks: PaymentStatusCallbacks, options?: {
|
|
244
|
+
isPublic?: boolean;
|
|
245
|
+
}): Promise<void>;
|
|
246
|
+
/**
|
|
247
|
+
* Check Tabby payment status after redirect back from Tabby.
|
|
248
|
+
*/
|
|
249
|
+
declare function checkTabbyReturnStatus(orderNumber: number, callbacks: PaymentStatusCallbacks): Promise<void>;
|
|
250
|
+
|
|
251
|
+
export { type AddressFormValues, type CartTotals, type CouponCallbacks, IP_API_CACHE_KEY, type PaymentCallbacks, type PaymentStatusCallbacks, addressFormInitialValues, addressValidationSchema, applyCheckoutCoupon, buildAddressPayload, buildSubmitPayload, calculateCartTotals, checkPhonepeReturnStatus, checkPhonepeReturnStatusWithOrder, checkStripeReturnStatus, checkTabbyReturnStatus, clearAddressFormSession, decodeAddress, encodeAddress, fetchAppliedCoupon, fetchAvailableCoupons, handleCODPayment, handlePhonepePayment, handleRazorpayFail, handleRazorpaySuccess, handleStripePayment, handleStripeSuccess, handleTabbyPayment, isValidPhoneNumber, loadAddressFormFromSession, openRazorpayCheckout, parseEditAddress, processPayment, removeCheckoutCoupon, saveAddressFormToSession };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
export { applyCheckoutCoupon, fetchAppliedCoupon, fetchAvailableCoupons, handleCODPayment, handlePhonepePayment, handleRazorpayFail, handleRazorpaySuccess, handleStripePayment, handleStripeSuccess, handleTabbyPayment, openRazorpayCheckout, processPayment, removeCheckoutCoupon } from '../chunk-QCQCFYYR.js';
|
|
2
|
+
import { checkPhonepePaymentStatus, getOrderDetailsByNumber, getStripePaymentStatusPublic, getStripePaymentStatus, verifyTabbyPayment } from '../chunk-4MJMNIAB.js';
|
|
3
|
+
import { pixelEvents } from '../chunk-WFDKKOO7.js';
|
|
4
|
+
export { IP_API_CACHE_KEY, addressFormInitialValues, addressValidationSchema, buildAddressPayload, buildSubmitPayload, clearAddressFormSession, decodeAddress, encodeAddress, isValidPhoneNumber, loadAddressFormFromSession, parseEditAddress, saveAddressFormToSession } from '../chunk-CSISWBZZ.js';
|
|
5
|
+
import '../chunk-GB3HW6DM.js';
|
|
6
|
+
import '../chunk-FLBJKM6G.js';
|
|
7
|
+
import '../chunk-JQMLHRWL.js';
|
|
8
|
+
|
|
9
|
+
// src/checkout/cart-calculations.ts
|
|
10
|
+
function calculateCartTotals(cart) {
|
|
11
|
+
if (!cart) {
|
|
12
|
+
return {
|
|
13
|
+
totalSellingAmount: 0,
|
|
14
|
+
discountAmount: 0,
|
|
15
|
+
isCartEmpty: true,
|
|
16
|
+
allInclusiveTax: true,
|
|
17
|
+
exclusiveTaxAmount: 0
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
let totalSellingAmount = 0;
|
|
21
|
+
let discountAmount = 0;
|
|
22
|
+
let exclusiveTaxAmount = 0;
|
|
23
|
+
let allInclusiveTax = true;
|
|
24
|
+
cart.product_variants?.forEach((item) => {
|
|
25
|
+
const quantity = cart.products_quantity[item.id] || 0;
|
|
26
|
+
const actualPrice = Number(item.actual_price);
|
|
27
|
+
const sellingPrice = Number(item.selling_price);
|
|
28
|
+
const variant = item;
|
|
29
|
+
totalSellingAmount += actualPrice ? actualPrice * quantity : sellingPrice * quantity;
|
|
30
|
+
discountAmount += actualPrice ? (actualPrice - sellingPrice) * quantity : 0;
|
|
31
|
+
if (!variant.is_tax_inclusive_price) {
|
|
32
|
+
allInclusiveTax = false;
|
|
33
|
+
exclusiveTaxAmount += Number(variant.total_tax_price || 0) * quantity;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
totalSellingAmount,
|
|
38
|
+
discountAmount,
|
|
39
|
+
isCartEmpty: !cart.product_variants?.length,
|
|
40
|
+
allInclusiveTax,
|
|
41
|
+
exclusiveTaxAmount
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/checkout/payment-status.ts
|
|
46
|
+
async function checkPhonepeReturnStatus(transactionId, callbacks) {
|
|
47
|
+
try {
|
|
48
|
+
const response = await checkPhonepePaymentStatus(transactionId);
|
|
49
|
+
if (response.data.success) {
|
|
50
|
+
callbacks.onSuccess(void 0);
|
|
51
|
+
} else {
|
|
52
|
+
callbacks.onFailure();
|
|
53
|
+
}
|
|
54
|
+
} catch {
|
|
55
|
+
callbacks.onFailure();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function checkPhonepeReturnStatusWithOrder(transactionId, orderNumber, callbacks) {
|
|
59
|
+
try {
|
|
60
|
+
const [paymentResponse, orderResponse] = await Promise.all([
|
|
61
|
+
checkPhonepePaymentStatus(transactionId),
|
|
62
|
+
getOrderDetailsByNumber(orderNumber)
|
|
63
|
+
]);
|
|
64
|
+
const order = orderResponse.data;
|
|
65
|
+
callbacks.onOrderLoaded?.(order);
|
|
66
|
+
if (paymentResponse.data.success) {
|
|
67
|
+
pixelEvents.purchase(order);
|
|
68
|
+
pixelEvents.checkoutCompleted(order);
|
|
69
|
+
callbacks.onSuccess(order);
|
|
70
|
+
} else {
|
|
71
|
+
callbacks.onFailure();
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
callbacks.onFailure();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async function checkStripeReturnStatus(sessionId, orderNumber, paymentLinkUrl, callbacks, options) {
|
|
78
|
+
try {
|
|
79
|
+
const getStatus = options?.isPublic ? getStripePaymentStatusPublic : getStripePaymentStatus;
|
|
80
|
+
const response = await getStatus(sessionId, orderNumber, paymentLinkUrl);
|
|
81
|
+
const data = response.data;
|
|
82
|
+
if (data.payment_status === "paid" || data.status === "complete") {
|
|
83
|
+
try {
|
|
84
|
+
const orderResponse = await getOrderDetailsByNumber(orderNumber);
|
|
85
|
+
const order = orderResponse.data;
|
|
86
|
+
callbacks.onOrderLoaded?.(order);
|
|
87
|
+
pixelEvents.purchase(order);
|
|
88
|
+
pixelEvents.checkoutCompleted(order);
|
|
89
|
+
callbacks.onSuccess(order);
|
|
90
|
+
} catch {
|
|
91
|
+
callbacks.onSuccess(void 0);
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
callbacks.onFailure();
|
|
95
|
+
}
|
|
96
|
+
} catch {
|
|
97
|
+
callbacks.onFailure();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async function checkTabbyReturnStatus(orderNumber, callbacks) {
|
|
101
|
+
try {
|
|
102
|
+
const response = await verifyTabbyPayment(orderNumber);
|
|
103
|
+
if (response.data.order_status === "paid" || response.data.order_status === "confirmed") {
|
|
104
|
+
try {
|
|
105
|
+
const orderResponse = await getOrderDetailsByNumber(orderNumber);
|
|
106
|
+
const order = orderResponse.data;
|
|
107
|
+
callbacks.onOrderLoaded?.(order);
|
|
108
|
+
pixelEvents.purchase(order);
|
|
109
|
+
pixelEvents.checkoutCompleted(order);
|
|
110
|
+
callbacks.onSuccess(order);
|
|
111
|
+
} catch {
|
|
112
|
+
callbacks.onSuccess(void 0);
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
callbacks.onFailure();
|
|
116
|
+
}
|
|
117
|
+
} catch {
|
|
118
|
+
callbacks.onFailure();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export { calculateCartTotals, checkPhonepeReturnStatus, checkPhonepeReturnStatusWithOrder, checkStripeReturnStatus, checkTabbyReturnStatus };
|