@storepecker/storefront-core 2.9.0 → 2.10.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-BdIB6IuI.d.cts +42 -0
- package/dist/address-BdIB6IuI.d.ts +42 -0
- package/dist/api/index.cjs +38 -30
- package/dist/api/index.d.cts +27 -9
- package/dist/api/index.d.ts +27 -9
- package/dist/api/index.js +3 -3
- package/dist/{buy-now-B1dkx82V.d.cts → buy-now-B_15RUVT.d.cts} +2 -2
- package/dist/{buy-now-BgKd5p4J.d.ts → buy-now-kII0KrhP.d.ts} +2 -2
- package/dist/{cart-BGIsIZdM.d.ts → cart-DZq1ZEnE.d.ts} +1 -1
- package/dist/{cart-CyN2JQTw.d.cts → cart-DwMFBmpC.d.cts} +1 -1
- package/dist/checkout/index.cjs +115 -22
- package/dist/checkout/index.d.cts +28 -4
- package/dist/checkout/index.d.ts +28 -4
- package/dist/checkout/index.js +4 -3
- package/dist/{chunk-IG4BW3ZB.cjs → chunk-32X4SWN4.cjs} +3 -3
- package/dist/{chunk-RDUT4W3B.cjs → chunk-6APRQ2ED.cjs} +4 -1
- package/dist/{chunk-ICKTXS6B.js → chunk-6IXTFZFS.js} +3 -3
- package/dist/{chunk-7M5CVYZJ.js → chunk-A7EI7XLU.js} +8 -1
- package/dist/{chunk-CBKJ3Y2I.js → chunk-EWZ7TGI7.js} +11 -1
- package/dist/{chunk-5XVHYPOC.js → chunk-FF5N7PTB.js} +1 -1
- package/dist/{chunk-XFOUNOKO.cjs → chunk-KNG4OMS5.cjs} +8 -0
- package/dist/{chunk-CIBMO44U.cjs → chunk-NOT6VKXA.cjs} +18 -15
- package/dist/{chunk-ETXIP5XE.cjs → chunk-NRPK5GCJ.cjs} +8 -0
- package/dist/{chunk-K44JZ5NL.cjs → chunk-NSAHGMS7.cjs} +6 -1
- package/dist/chunk-QED6QJZC.cjs +603 -0
- package/dist/{chunk-SU5LVRZD.js → chunk-QQHQTBAM.js} +12 -9
- package/dist/{chunk-W6BDMNSU.js → chunk-QVO56X4E.js} +1 -1
- package/dist/{chunk-6LS5F4R3.cjs → chunk-SGJUMI3M.cjs} +11 -0
- package/dist/{chunk-YLLAP3H2.cjs → chunk-SGKLMS7W.cjs} +2 -2
- package/dist/{chunk-WFDKKOO7.js → chunk-VAU5OL72.js} +6 -1
- package/dist/{chunk-ZGMLOLTC.js → chunk-VRZRV2BR.js} +4 -1
- package/dist/{chunk-IVKJJLG7.cjs → chunk-WWJAPKRQ.cjs} +8 -8
- package/dist/chunk-Y4RNRPBC.js +545 -0
- package/dist/{chunk-YMZZCVZ2.js → chunk-ZAWZ3RB6.js} +8 -1
- package/dist/{collections-ycrA2cPL.d.ts → collections-CNh2OGbl.d.ts} +1 -1
- package/dist/{collections-8YdINtUf.d.cts → collections-CXgOv5_G.d.cts} +1 -1
- package/dist/components/address-form.cjs +6 -6
- package/dist/components/address-form.d.cts +10 -6
- package/dist/components/address-form.d.ts +10 -6
- package/dist/components/address-form.js +5 -5
- package/dist/components/digital-product-download-modal.d.cts +2 -2
- package/dist/components/digital-product-download-modal.d.ts +2 -2
- package/dist/components/index.cjs +8 -8
- package/dist/components/index.d.cts +7 -7
- package/dist/components/index.d.ts +7 -7
- package/dist/components/index.js +6 -6
- package/dist/components/search-dropdown.d.cts +4 -4
- package/dist/components/search-dropdown.d.ts +4 -4
- package/dist/components/share-button.cjs +3 -3
- package/dist/components/share-button.d.cts +1 -1
- package/dist/components/share-button.d.ts +1 -1
- package/dist/components/share-button.js +2 -2
- package/dist/components/theme-data-initializer.d.cts +5 -5
- package/dist/components/theme-data-initializer.d.ts +5 -5
- package/dist/hooks/index.cjs +685 -34
- package/dist/hooks/index.d.cts +238 -13
- package/dist/hooks/index.d.ts +238 -13
- package/dist/hooks/index.js +655 -12
- package/dist/{instagram-CqJBZ-0X.d.ts → instagram-BADLnNQ3.d.ts} +1 -1
- package/dist/{instagram-D4JUT4ZU.d.cts → instagram-DalreBu6.d.cts} +1 -1
- package/dist/models/index.d.cts +9 -8
- package/dist/models/index.d.ts +9 -8
- package/dist/{orders-COKWr7K7.d.cts → orders-B3G4CyhH.d.cts} +1 -1
- package/dist/{orders-Cp8qNCrl.d.ts → orders-Bl-Slh72.d.ts} +1 -1
- package/dist/pincode-8u7yWLpQ.d.cts +29 -0
- package/dist/pincode-8u7yWLpQ.d.ts +29 -0
- package/dist/pincode-CHM-ZD3H.d.ts +179 -0
- package/dist/pincode-Ch3bZSJz.d.cts +179 -0
- package/dist/{pixelEvents-BJNH06rS.d.cts → pixelEvents-COqZIgTu.d.cts} +5 -4
- package/dist/{pixelEvents-2Tb-_fRP.d.ts → pixelEvents-Ds6fwS9t.d.ts} +5 -4
- package/dist/{product-CZtFWhxO.d.ts → product-D9liEtl4.d.cts} +1 -0
- package/dist/{product-CZtFWhxO.d.cts → product-D9liEtl4.d.ts} +1 -0
- package/dist/store/index.cjs +7 -7
- package/dist/store/index.d.cts +6 -6
- package/dist/store/index.d.ts +6 -6
- package/dist/store/index.js +2 -2
- package/dist/{useAddressForm-DGbEn91-.d.cts → useAddressForm-fMOb5Z-a.d.ts} +6 -1
- package/dist/{useAddressForm-cO3Au33k.d.ts → useAddressForm-wleIo78M.d.cts} +6 -1
- package/dist/utils/index.cjs +60 -56
- package/dist/utils/index.d.cts +17 -8
- package/dist/utils/index.d.ts +17 -8
- package/dist/utils/index.js +4 -4
- package/dist/{wishlist-Cx9Vrszq.d.cts → wishlist-BakHvIFN.d.cts} +1 -1
- package/dist/{wishlist-CRNbfFIx.d.ts → wishlist-Cj0sQxiY.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/address-DwBZHzbI.d.cts +0 -19
- package/dist/address-DwBZHzbI.d.ts +0 -19
- package/dist/chunk-TFWTQTWE.cjs +0 -246
- package/dist/chunk-UWW5YIHL.js +0 -232
package/dist/chunk-TFWTQTWE.cjs
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunkXFOUNOKO_cjs = require('./chunk-XFOUNOKO.cjs');
|
|
4
|
-
var chunkK44JZ5NL_cjs = require('./chunk-K44JZ5NL.cjs');
|
|
5
|
-
var chunkH6FJYRO3_cjs = require('./chunk-H6FJYRO3.cjs');
|
|
6
|
-
var chunkN3CTXRFT_cjs = require('./chunk-N3CTXRFT.cjs');
|
|
7
|
-
var axios = require('axios');
|
|
8
|
-
|
|
9
|
-
// src/checkout/payment.ts
|
|
10
|
-
function openRazorpayCheckout(order, callbacks, paymentOptions) {
|
|
11
|
-
if (!order) return;
|
|
12
|
-
chunkK44JZ5NL_cjs.pixelEvents.initiateCheckout(order, "razorpay");
|
|
13
|
-
const {
|
|
14
|
-
razorpay_order_id,
|
|
15
|
-
razorpay_public_token,
|
|
16
|
-
total_amount,
|
|
17
|
-
razorpay_order_currency,
|
|
18
|
-
store_color_scheme,
|
|
19
|
-
store_logo,
|
|
20
|
-
store_name,
|
|
21
|
-
customer_name,
|
|
22
|
-
customer_phone,
|
|
23
|
-
customer_email
|
|
24
|
-
} = order;
|
|
25
|
-
const cloudFront = chunkN3CTXRFT_cjs.getCloudFront();
|
|
26
|
-
const options = {
|
|
27
|
-
key: razorpay_public_token,
|
|
28
|
-
amount: Number(total_amount) * 100,
|
|
29
|
-
currency: razorpay_order_currency,
|
|
30
|
-
name: store_name,
|
|
31
|
-
image: cloudFront ? `${cloudFront}${store_logo}` : store_logo,
|
|
32
|
-
order_id: razorpay_order_id,
|
|
33
|
-
handler: async (response) => {
|
|
34
|
-
handleRazorpaySuccess(
|
|
35
|
-
{
|
|
36
|
-
razorpay_payment_id: response.razorpay_payment_id,
|
|
37
|
-
razorpay_subscription_id: response.razorpay_subscription_id,
|
|
38
|
-
razorpay_signature: response.razorpay_signature,
|
|
39
|
-
order_id: order.id,
|
|
40
|
-
razorpay_order_id,
|
|
41
|
-
payment_id: response.razorpay_payment_id
|
|
42
|
-
},
|
|
43
|
-
order,
|
|
44
|
-
callbacks,
|
|
45
|
-
paymentOptions
|
|
46
|
-
);
|
|
47
|
-
},
|
|
48
|
-
theme: {
|
|
49
|
-
color: store_color_scheme?.primary,
|
|
50
|
-
accent: store_color_scheme?.secondary
|
|
51
|
-
},
|
|
52
|
-
prefill: {
|
|
53
|
-
name: customer_name,
|
|
54
|
-
email: customer_email?.endsWith("@test.com") ? void 0 : customer_email,
|
|
55
|
-
phone: customer_phone
|
|
56
|
-
},
|
|
57
|
-
modal: {
|
|
58
|
-
ondismiss: () => handleRazorpayFail(
|
|
59
|
-
order,
|
|
60
|
-
callbacks,
|
|
61
|
-
{
|
|
62
|
-
description: "User cancelled the payment manually",
|
|
63
|
-
reason: "user_cancelled_payment_manually"
|
|
64
|
-
},
|
|
65
|
-
{ isPublic: paymentOptions?.isPublic }
|
|
66
|
-
)
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
const paymentObject = new window.Razorpay(options);
|
|
70
|
-
paymentObject.on("payment.failed", (response) => {
|
|
71
|
-
handleRazorpayFail(order, callbacks, response?.error, {
|
|
72
|
-
isPublic: paymentOptions?.isPublic
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
paymentObject.open();
|
|
76
|
-
}
|
|
77
|
-
async function handleRazorpaySuccess(data, order, callbacks, options) {
|
|
78
|
-
try {
|
|
79
|
-
callbacks.onPaymentStart?.();
|
|
80
|
-
if (options?.isPublic) {
|
|
81
|
-
await chunkH6FJYRO3_cjs.razorpayPublicOrderSuccess(data);
|
|
82
|
-
} else {
|
|
83
|
-
await chunkH6FJYRO3_cjs.razorpayOrderSuccess(data);
|
|
84
|
-
}
|
|
85
|
-
chunkK44JZ5NL_cjs.pixelEvents.purchase(order);
|
|
86
|
-
chunkK44JZ5NL_cjs.pixelEvents.checkoutCompleted(order);
|
|
87
|
-
callbacks.onCartReset();
|
|
88
|
-
callbacks.onSuccess(order);
|
|
89
|
-
} catch {
|
|
90
|
-
callbacks.onFailure(order);
|
|
91
|
-
} finally {
|
|
92
|
-
callbacks.onPaymentEnd?.();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
async function handleRazorpayFail(order, callbacks, error, options) {
|
|
96
|
-
try {
|
|
97
|
-
const payload = {
|
|
98
|
-
order_id: order.id,
|
|
99
|
-
razorpay_order_id: order.razorpay_order_id,
|
|
100
|
-
error
|
|
101
|
-
};
|
|
102
|
-
options?.isPublic ? await chunkH6FJYRO3_cjs.publicRazorpayOrderFailure(payload) : await chunkH6FJYRO3_cjs.razorpayOrderFail(payload);
|
|
103
|
-
} catch {
|
|
104
|
-
}
|
|
105
|
-
callbacks.onFailure(order);
|
|
106
|
-
}
|
|
107
|
-
function handlePhonepePayment(order, callbacks) {
|
|
108
|
-
if (!order) return;
|
|
109
|
-
chunkK44JZ5NL_cjs.pixelEvents.initiateCheckout(order, "phonepe");
|
|
110
|
-
if (!order.phonepe_redirect_url) {
|
|
111
|
-
callbacks.onFailure(order);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
callbacks.onRedirect(order.phonepe_redirect_url);
|
|
115
|
-
}
|
|
116
|
-
function handleTabbyPayment(order, callbacks) {
|
|
117
|
-
if (!order) return;
|
|
118
|
-
chunkK44JZ5NL_cjs.pixelEvents.initiateCheckout(order, "tabby");
|
|
119
|
-
if (!order.tabby_redirect_url) {
|
|
120
|
-
callbacks.onFailure(order);
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
callbacks.onRedirect(order.tabby_redirect_url);
|
|
124
|
-
}
|
|
125
|
-
async function handleCODPayment(order, callbacks, options) {
|
|
126
|
-
if (!order) return;
|
|
127
|
-
try {
|
|
128
|
-
callbacks.onPaymentStart?.();
|
|
129
|
-
chunkK44JZ5NL_cjs.pixelEvents.initiateCheckout(order, "cod");
|
|
130
|
-
if (options?.isPublic) {
|
|
131
|
-
await chunkH6FJYRO3_cjs.publicMakeCODOrder(order.order_number, {
|
|
132
|
-
customer_phone: order.customer_phone,
|
|
133
|
-
customer_email: order.customer_email
|
|
134
|
-
});
|
|
135
|
-
} else {
|
|
136
|
-
await chunkH6FJYRO3_cjs.makeCODOrder(order.id);
|
|
137
|
-
}
|
|
138
|
-
chunkK44JZ5NL_cjs.pixelEvents.purchase(order);
|
|
139
|
-
chunkK44JZ5NL_cjs.pixelEvents.checkoutCompleted(order);
|
|
140
|
-
callbacks.onCartReset();
|
|
141
|
-
callbacks.onSuccess(order);
|
|
142
|
-
} catch {
|
|
143
|
-
callbacks.onFailure(order);
|
|
144
|
-
} finally {
|
|
145
|
-
callbacks.onPaymentEnd?.();
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
function handleStripePayment(order, callbacks) {
|
|
149
|
-
if (!order) return;
|
|
150
|
-
chunkK44JZ5NL_cjs.pixelEvents.initiateCheckout(order, "stripe");
|
|
151
|
-
if (order.stripe_payment_link_url) {
|
|
152
|
-
callbacks.onRedirect(order.stripe_payment_link_url);
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
if (order.stripe_client_secret) {
|
|
156
|
-
callbacks.onStripeModalOpen?.(order);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
callbacks.onFailure(order);
|
|
160
|
-
}
|
|
161
|
-
async function handleStripeSuccess(order, paymentIntentId, callbacks, options) {
|
|
162
|
-
try {
|
|
163
|
-
callbacks.onPaymentStart?.();
|
|
164
|
-
const stripeSuccessPayload = {
|
|
165
|
-
order_id: order.id,
|
|
166
|
-
payment_intent_id: paymentIntentId
|
|
167
|
-
};
|
|
168
|
-
if (options?.isPublic) {
|
|
169
|
-
await chunkH6FJYRO3_cjs.stripePublicOrderSuccess(stripeSuccessPayload);
|
|
170
|
-
} else {
|
|
171
|
-
await chunkH6FJYRO3_cjs.stripeOrderSuccess(stripeSuccessPayload);
|
|
172
|
-
}
|
|
173
|
-
chunkK44JZ5NL_cjs.pixelEvents.purchase(order);
|
|
174
|
-
chunkK44JZ5NL_cjs.pixelEvents.checkoutCompleted(order);
|
|
175
|
-
callbacks.onCartReset();
|
|
176
|
-
callbacks.onSuccess(order);
|
|
177
|
-
} catch {
|
|
178
|
-
callbacks.onFailure(order);
|
|
179
|
-
} finally {
|
|
180
|
-
callbacks.onPaymentEnd?.();
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
function processPayment(order, paymentMethod, callbacks, options) {
|
|
184
|
-
if (paymentMethod === "cod") {
|
|
185
|
-
handleCODPayment(order, callbacks, options);
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
if (order.tabby_redirect_url) {
|
|
189
|
-
handleTabbyPayment(order, callbacks);
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
if (order.stripe_client_secret || order.stripe_payment_link_url) {
|
|
193
|
-
handleStripePayment(order, callbacks);
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
if (order.razorpay_public_token) {
|
|
197
|
-
openRazorpayCheckout(order, callbacks, options);
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
handlePhonepePayment(order, callbacks);
|
|
201
|
-
}
|
|
202
|
-
async function fetchAvailableCoupons() {
|
|
203
|
-
const response = await chunkXFOUNOKO_cjs.getCoupons();
|
|
204
|
-
return response.data;
|
|
205
|
-
}
|
|
206
|
-
async function fetchAppliedCoupon() {
|
|
207
|
-
try {
|
|
208
|
-
const response = await chunkXFOUNOKO_cjs.getAppliedCoupon();
|
|
209
|
-
return response.data || null;
|
|
210
|
-
} catch {
|
|
211
|
-
return null;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
async function applyCheckoutCoupon(code, callbacks) {
|
|
215
|
-
try {
|
|
216
|
-
const response = await chunkXFOUNOKO_cjs.applyCoupon(code);
|
|
217
|
-
if (response.data?.coupon) {
|
|
218
|
-
await callbacks.onCartRefresh();
|
|
219
|
-
return response.data.coupon;
|
|
220
|
-
}
|
|
221
|
-
throw new Error("Failed to apply coupon");
|
|
222
|
-
} catch (error) {
|
|
223
|
-
if (error instanceof axios.AxiosError) {
|
|
224
|
-
throw new Error(error.response?.data?.detail || "Failed to apply coupon");
|
|
225
|
-
}
|
|
226
|
-
throw error;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
async function removeCheckoutCoupon(couponCode, callbacks) {
|
|
230
|
-
await chunkXFOUNOKO_cjs.removeCoupon(couponCode);
|
|
231
|
-
await callbacks.onCartRefresh();
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
exports.applyCheckoutCoupon = applyCheckoutCoupon;
|
|
235
|
-
exports.fetchAppliedCoupon = fetchAppliedCoupon;
|
|
236
|
-
exports.fetchAvailableCoupons = fetchAvailableCoupons;
|
|
237
|
-
exports.handleCODPayment = handleCODPayment;
|
|
238
|
-
exports.handlePhonepePayment = handlePhonepePayment;
|
|
239
|
-
exports.handleRazorpayFail = handleRazorpayFail;
|
|
240
|
-
exports.handleRazorpaySuccess = handleRazorpaySuccess;
|
|
241
|
-
exports.handleStripePayment = handleStripePayment;
|
|
242
|
-
exports.handleStripeSuccess = handleStripeSuccess;
|
|
243
|
-
exports.handleTabbyPayment = handleTabbyPayment;
|
|
244
|
-
exports.openRazorpayCheckout = openRazorpayCheckout;
|
|
245
|
-
exports.processPayment = processPayment;
|
|
246
|
-
exports.removeCheckoutCoupon = removeCheckoutCoupon;
|
package/dist/chunk-UWW5YIHL.js
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { getCoupons, getAppliedCoupon, applyCoupon, removeCoupon } from './chunk-7M5CVYZJ.js';
|
|
2
|
-
import { pixelEvents } from './chunk-WFDKKOO7.js';
|
|
3
|
-
import { razorpayPublicOrderSuccess, razorpayOrderSuccess, publicRazorpayOrderFailure, razorpayOrderFail, publicMakeCODOrder, makeCODOrder, stripePublicOrderSuccess, stripeOrderSuccess } from './chunk-KCLVR6G5.js';
|
|
4
|
-
import { getCloudFront } from './chunk-JQMLHRWL.js';
|
|
5
|
-
import { AxiosError } from 'axios';
|
|
6
|
-
|
|
7
|
-
// src/checkout/payment.ts
|
|
8
|
-
function openRazorpayCheckout(order, callbacks, paymentOptions) {
|
|
9
|
-
if (!order) return;
|
|
10
|
-
pixelEvents.initiateCheckout(order, "razorpay");
|
|
11
|
-
const {
|
|
12
|
-
razorpay_order_id,
|
|
13
|
-
razorpay_public_token,
|
|
14
|
-
total_amount,
|
|
15
|
-
razorpay_order_currency,
|
|
16
|
-
store_color_scheme,
|
|
17
|
-
store_logo,
|
|
18
|
-
store_name,
|
|
19
|
-
customer_name,
|
|
20
|
-
customer_phone,
|
|
21
|
-
customer_email
|
|
22
|
-
} = order;
|
|
23
|
-
const cloudFront = getCloudFront();
|
|
24
|
-
const options = {
|
|
25
|
-
key: razorpay_public_token,
|
|
26
|
-
amount: Number(total_amount) * 100,
|
|
27
|
-
currency: razorpay_order_currency,
|
|
28
|
-
name: store_name,
|
|
29
|
-
image: cloudFront ? `${cloudFront}${store_logo}` : store_logo,
|
|
30
|
-
order_id: razorpay_order_id,
|
|
31
|
-
handler: async (response) => {
|
|
32
|
-
handleRazorpaySuccess(
|
|
33
|
-
{
|
|
34
|
-
razorpay_payment_id: response.razorpay_payment_id,
|
|
35
|
-
razorpay_subscription_id: response.razorpay_subscription_id,
|
|
36
|
-
razorpay_signature: response.razorpay_signature,
|
|
37
|
-
order_id: order.id,
|
|
38
|
-
razorpay_order_id,
|
|
39
|
-
payment_id: response.razorpay_payment_id
|
|
40
|
-
},
|
|
41
|
-
order,
|
|
42
|
-
callbacks,
|
|
43
|
-
paymentOptions
|
|
44
|
-
);
|
|
45
|
-
},
|
|
46
|
-
theme: {
|
|
47
|
-
color: store_color_scheme?.primary,
|
|
48
|
-
accent: store_color_scheme?.secondary
|
|
49
|
-
},
|
|
50
|
-
prefill: {
|
|
51
|
-
name: customer_name,
|
|
52
|
-
email: customer_email?.endsWith("@test.com") ? void 0 : customer_email,
|
|
53
|
-
phone: customer_phone
|
|
54
|
-
},
|
|
55
|
-
modal: {
|
|
56
|
-
ondismiss: () => handleRazorpayFail(
|
|
57
|
-
order,
|
|
58
|
-
callbacks,
|
|
59
|
-
{
|
|
60
|
-
description: "User cancelled the payment manually",
|
|
61
|
-
reason: "user_cancelled_payment_manually"
|
|
62
|
-
},
|
|
63
|
-
{ isPublic: paymentOptions?.isPublic }
|
|
64
|
-
)
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
const paymentObject = new window.Razorpay(options);
|
|
68
|
-
paymentObject.on("payment.failed", (response) => {
|
|
69
|
-
handleRazorpayFail(order, callbacks, response?.error, {
|
|
70
|
-
isPublic: paymentOptions?.isPublic
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
paymentObject.open();
|
|
74
|
-
}
|
|
75
|
-
async function handleRazorpaySuccess(data, order, callbacks, options) {
|
|
76
|
-
try {
|
|
77
|
-
callbacks.onPaymentStart?.();
|
|
78
|
-
if (options?.isPublic) {
|
|
79
|
-
await razorpayPublicOrderSuccess(data);
|
|
80
|
-
} else {
|
|
81
|
-
await razorpayOrderSuccess(data);
|
|
82
|
-
}
|
|
83
|
-
pixelEvents.purchase(order);
|
|
84
|
-
pixelEvents.checkoutCompleted(order);
|
|
85
|
-
callbacks.onCartReset();
|
|
86
|
-
callbacks.onSuccess(order);
|
|
87
|
-
} catch {
|
|
88
|
-
callbacks.onFailure(order);
|
|
89
|
-
} finally {
|
|
90
|
-
callbacks.onPaymentEnd?.();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
async function handleRazorpayFail(order, callbacks, error, options) {
|
|
94
|
-
try {
|
|
95
|
-
const payload = {
|
|
96
|
-
order_id: order.id,
|
|
97
|
-
razorpay_order_id: order.razorpay_order_id,
|
|
98
|
-
error
|
|
99
|
-
};
|
|
100
|
-
options?.isPublic ? await publicRazorpayOrderFailure(payload) : await razorpayOrderFail(payload);
|
|
101
|
-
} catch {
|
|
102
|
-
}
|
|
103
|
-
callbacks.onFailure(order);
|
|
104
|
-
}
|
|
105
|
-
function handlePhonepePayment(order, callbacks) {
|
|
106
|
-
if (!order) return;
|
|
107
|
-
pixelEvents.initiateCheckout(order, "phonepe");
|
|
108
|
-
if (!order.phonepe_redirect_url) {
|
|
109
|
-
callbacks.onFailure(order);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
callbacks.onRedirect(order.phonepe_redirect_url);
|
|
113
|
-
}
|
|
114
|
-
function handleTabbyPayment(order, callbacks) {
|
|
115
|
-
if (!order) return;
|
|
116
|
-
pixelEvents.initiateCheckout(order, "tabby");
|
|
117
|
-
if (!order.tabby_redirect_url) {
|
|
118
|
-
callbacks.onFailure(order);
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
callbacks.onRedirect(order.tabby_redirect_url);
|
|
122
|
-
}
|
|
123
|
-
async function handleCODPayment(order, callbacks, options) {
|
|
124
|
-
if (!order) return;
|
|
125
|
-
try {
|
|
126
|
-
callbacks.onPaymentStart?.();
|
|
127
|
-
pixelEvents.initiateCheckout(order, "cod");
|
|
128
|
-
if (options?.isPublic) {
|
|
129
|
-
await publicMakeCODOrder(order.order_number, {
|
|
130
|
-
customer_phone: order.customer_phone,
|
|
131
|
-
customer_email: order.customer_email
|
|
132
|
-
});
|
|
133
|
-
} else {
|
|
134
|
-
await makeCODOrder(order.id);
|
|
135
|
-
}
|
|
136
|
-
pixelEvents.purchase(order);
|
|
137
|
-
pixelEvents.checkoutCompleted(order);
|
|
138
|
-
callbacks.onCartReset();
|
|
139
|
-
callbacks.onSuccess(order);
|
|
140
|
-
} catch {
|
|
141
|
-
callbacks.onFailure(order);
|
|
142
|
-
} finally {
|
|
143
|
-
callbacks.onPaymentEnd?.();
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
function handleStripePayment(order, callbacks) {
|
|
147
|
-
if (!order) return;
|
|
148
|
-
pixelEvents.initiateCheckout(order, "stripe");
|
|
149
|
-
if (order.stripe_payment_link_url) {
|
|
150
|
-
callbacks.onRedirect(order.stripe_payment_link_url);
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
if (order.stripe_client_secret) {
|
|
154
|
-
callbacks.onStripeModalOpen?.(order);
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
callbacks.onFailure(order);
|
|
158
|
-
}
|
|
159
|
-
async function handleStripeSuccess(order, paymentIntentId, callbacks, options) {
|
|
160
|
-
try {
|
|
161
|
-
callbacks.onPaymentStart?.();
|
|
162
|
-
const stripeSuccessPayload = {
|
|
163
|
-
order_id: order.id,
|
|
164
|
-
payment_intent_id: paymentIntentId
|
|
165
|
-
};
|
|
166
|
-
if (options?.isPublic) {
|
|
167
|
-
await stripePublicOrderSuccess(stripeSuccessPayload);
|
|
168
|
-
} else {
|
|
169
|
-
await stripeOrderSuccess(stripeSuccessPayload);
|
|
170
|
-
}
|
|
171
|
-
pixelEvents.purchase(order);
|
|
172
|
-
pixelEvents.checkoutCompleted(order);
|
|
173
|
-
callbacks.onCartReset();
|
|
174
|
-
callbacks.onSuccess(order);
|
|
175
|
-
} catch {
|
|
176
|
-
callbacks.onFailure(order);
|
|
177
|
-
} finally {
|
|
178
|
-
callbacks.onPaymentEnd?.();
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
function processPayment(order, paymentMethod, callbacks, options) {
|
|
182
|
-
if (paymentMethod === "cod") {
|
|
183
|
-
handleCODPayment(order, callbacks, options);
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
if (order.tabby_redirect_url) {
|
|
187
|
-
handleTabbyPayment(order, callbacks);
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
if (order.stripe_client_secret || order.stripe_payment_link_url) {
|
|
191
|
-
handleStripePayment(order, callbacks);
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
if (order.razorpay_public_token) {
|
|
195
|
-
openRazorpayCheckout(order, callbacks, options);
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
handlePhonepePayment(order, callbacks);
|
|
199
|
-
}
|
|
200
|
-
async function fetchAvailableCoupons() {
|
|
201
|
-
const response = await getCoupons();
|
|
202
|
-
return response.data;
|
|
203
|
-
}
|
|
204
|
-
async function fetchAppliedCoupon() {
|
|
205
|
-
try {
|
|
206
|
-
const response = await getAppliedCoupon();
|
|
207
|
-
return response.data || null;
|
|
208
|
-
} catch {
|
|
209
|
-
return null;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
async function applyCheckoutCoupon(code, callbacks) {
|
|
213
|
-
try {
|
|
214
|
-
const response = await applyCoupon(code);
|
|
215
|
-
if (response.data?.coupon) {
|
|
216
|
-
await callbacks.onCartRefresh();
|
|
217
|
-
return response.data.coupon;
|
|
218
|
-
}
|
|
219
|
-
throw new Error("Failed to apply coupon");
|
|
220
|
-
} catch (error) {
|
|
221
|
-
if (error instanceof AxiosError) {
|
|
222
|
-
throw new Error(error.response?.data?.detail || "Failed to apply coupon");
|
|
223
|
-
}
|
|
224
|
-
throw error;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
async function removeCheckoutCoupon(couponCode, callbacks) {
|
|
228
|
-
await removeCoupon(couponCode);
|
|
229
|
-
await callbacks.onCartRefresh();
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export { applyCheckoutCoupon, fetchAppliedCoupon, fetchAvailableCoupons, handleCODPayment, handlePhonepePayment, handleRazorpayFail, handleRazorpaySuccess, handleStripePayment, handleStripeSuccess, handleTabbyPayment, openRazorpayCheckout, processPayment, removeCheckoutCoupon };
|