merchi_cart 0.0.7-e → 0.0.7

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.
Files changed (90) hide show
  1. package/package.json +3 -4
  2. package/src/Cart.tsx +0 -100
  3. package/src/CartAlert.tsx +0 -34
  4. package/src/CartHeader.tsx +0 -27
  5. package/src/CartProvider.tsx +0 -386
  6. package/src/CartTotals.tsx +0 -106
  7. package/src/assets/merchi-monster-loader.gif +0 -0
  8. package/src/assets/merchi-swipe-outline.png +0 -0
  9. package/src/assets/product-not-found.png +0 -0
  10. package/src/buttons/Button.tsx +0 -35
  11. package/src/buttons/ButtonBack.tsx +0 -37
  12. package/src/buttons/ButtonClearCart.tsx +0 -18
  13. package/src/buttons/ButtonInvoiceDownload.tsx +0 -63
  14. package/src/buttons/ButtonNext.tsx +0 -38
  15. package/src/buttons/ButtonNextDynamic.tsx +0 -31
  16. package/src/buttons/ButtonPay.tsx +0 -32
  17. package/src/buttons/ButtonShipmentTabNext.tsx +0 -25
  18. package/src/buttons/index.ts +0 -15
  19. package/src/components/Alert.tsx +0 -31
  20. package/src/components/CartBody.tsx +0 -16
  21. package/src/components/CartClient.tsx +0 -48
  22. package/src/components/CartFooter.tsx +0 -15
  23. package/src/components/CartItemRow.tsx +0 -145
  24. package/src/components/CartPaymentSettingsInvalid.tsx +0 -12
  25. package/src/components/CartShipment.tsx +0 -55
  26. package/src/components/CartTabContent.tsx +0 -15
  27. package/src/components/CartTabPanel.tsx +0 -25
  28. package/src/components/CartTableContainer.tsx +0 -15
  29. package/src/components/Collapse.tsx +0 -23
  30. package/src/components/LoadingTemplate.tsx +0 -22
  31. package/src/components/NoCartItems.tsx +0 -15
  32. package/src/components/ShipmentGroupCard.tsx +0 -156
  33. package/src/components/Table.tsx +0 -14
  34. package/src/components/Title.tsx +0 -22
  35. package/src/components/containers.tsx +0 -40
  36. package/src/components/index.ts +0 -30
  37. package/src/forms/FormNewCustomer.tsx +0 -119
  38. package/src/forms/FormReturningCustomer.tsx +0 -70
  39. package/src/forms/FormShipmentAddressAndNotes.tsx +0 -142
  40. package/src/forms/FormSquarePayment.tsx +0 -14
  41. package/src/forms/FormStripePayment.tsx +0 -14
  42. package/src/forms/InputAcceptUserTermsAndConditions.tsx +0 -43
  43. package/src/forms/InputError.tsx +0 -23
  44. package/src/forms/InputSelect.tsx +0 -58
  45. package/src/forms/InputText.tsx +0 -56
  46. package/src/forms/InputsAddress.tsx +0 -205
  47. package/src/index.tsx +0 -13
  48. package/src/panels/PanelCartItems.tsx +0 -61
  49. package/src/panels/PanelCartShipment.tsx +0 -89
  50. package/src/panels/PanelClearCart.tsx +0 -47
  51. package/src/panels/PanelClientCheckout.tsx +0 -92
  52. package/src/panels/PanelEditCartItem.tsx +0 -58
  53. package/src/panels/PanelPaymentSuccess.tsx +0 -69
  54. package/src/panels/index.ts +0 -15
  55. package/src/slices/sliceCart.ts +0 -159
  56. package/src/slices/sliceCartAlert.ts +0 -39
  57. package/src/slices/sliceCartItem.ts +0 -29
  58. package/src/slices/sliceCartPayment.ts +0 -45
  59. package/src/slices/sliceCartShipment.ts +0 -67
  60. package/src/slices/sliceFormReturningCustomer.ts +0 -25
  61. package/src/slices/sliceNewCustomerForm.ts +0 -24
  62. package/src/square/SquareCard.tsx +0 -58
  63. package/src/square/actions.ts +0 -40
  64. package/src/square/slices/reducersSquare.ts +0 -9
  65. package/src/square/slices/sliceSquareAlerts.ts +0 -29
  66. package/src/square/slices/sliceSquareForm.ts +0 -29
  67. package/src/store.ts +0 -499
  68. package/src/stripe/StripeCardFields.tsx +0 -164
  69. package/src/stripe/StripeCardForm.tsx +0 -86
  70. package/src/stripe/StripePaymentButtons.tsx +0 -117
  71. package/src/stripe/actions.ts +0 -94
  72. package/src/stripe/slices/sliceStripeAlerts.ts +0 -29
  73. package/src/stripe/slices/sliceStripeCardForm.ts +0 -9
  74. package/src/stripe/slices/sliceStripeForm.ts +0 -56
  75. package/src/stripe/utils.ts +0 -21
  76. package/src/styles/globals.css +0 -191
  77. package/src/styles/globals.css.map +0 -1
  78. package/src/styles/globals.scss +0 -197
  79. package/src/tabs/CartNav.tsx +0 -20
  80. package/src/tabs/NavTab.tsx +0 -38
  81. package/src/utilities/address.ts +0 -351
  82. package/src/utilities/cart.ts +0 -73
  83. package/src/utilities/company.ts +0 -8
  84. package/src/utilities/cookie.ts +0 -54
  85. package/src/utilities/currency.ts +0 -216
  86. package/src/utilities/helpers.ts +0 -209
  87. package/src/utilities/invoice.ts +0 -60
  88. package/src/utilities/product.ts +0 -7
  89. package/src/utilities/user.ts +0 -38
  90. package/src/utilities/variations.ts +0 -56
@@ -1,29 +0,0 @@
1
- import { createSlice, PayloadAction } from '@reduxjs/toolkit';
2
-
3
- const sliceSquareForm = createSlice({
4
- initialState: {
5
- invoice: {},
6
- isCart: false,
7
- loading: false,
8
- loadingAcceptedPaymentMethods: false,
9
- loadingPaymentRequestButton: false,
10
- },
11
- name: 'stateSquareForm',
12
- reducers: {
13
- actionSquarePaymentEnd: (state: any) => {
14
- state.loading = false;
15
- },
16
- actionSquarePaymentStart: (state: any) => {
17
- state.loading = true;
18
- },
19
- setInvoiceOrCart: (state: any, action: PayloadAction<any>) => {
20
- const { invoice, isCart } = action.payload;
21
- state.invoice = invoice;
22
- if (isCart) {
23
- state.isCart = isCart;
24
- }
25
- },
26
- },
27
- });
28
-
29
- export default sliceSquareForm;
package/src/store.ts DELETED
@@ -1,499 +0,0 @@
1
- import { batch } from 'react-redux';
2
- import { configureStore } from '@reduxjs/toolkit';
3
- import {
4
- sliceCart,
5
- tabIdCheckout,
6
- tabIdItem,
7
- tabIdItems,
8
- tabIdPaymentSuccess,
9
- } from './slices/sliceCart';
10
- import { sliceCartAlert } from './slices/sliceCartAlert';
11
- import sliceCartItem from './slices/sliceCartItem';
12
- import { sliceCartPayment } from './slices/sliceCartPayment';
13
- import { sliceCartShipment } from './slices/sliceCartShipment';
14
- import sliceNewCustomerForm from './slices/sliceNewCustomerForm';
15
- import sliceFormReturningCustomer from './slices/sliceFormReturningCustomer';
16
- import reducersSquare from './square/slices/reducersSquare';
17
- import sliceStripeCardForm from './stripe/slices/sliceStripeCardForm';
18
- import { Merchi } from 'merchi_sdk_ts';
19
- import { cartEmbed } from './utilities/helpers';
20
- import { makeAddress } from './utilities/address';
21
- import {
22
- getCartCookie as getMerchiCartCookie,
23
- setCartCookie,
24
- } from './utilities/cookie';
25
- import {
26
- getCartShipmentGroupsAndQuotes,
27
- makeCart,
28
- makeCartItem,
29
- makeCartShipmentQuote,
30
- stripeIsValidAndActive,
31
- } from './utilities/cart';
32
- import {
33
- makeUser,
34
- createNewCustomer,
35
- tryReturningCustomerEmail,
36
- } from './utilities/user';
37
- import { appendStyleSheetText } from './utilities/helpers';
38
-
39
- const merchi = new Merchi();
40
-
41
- const merchiCartReducer = {
42
- stateCartAlert: sliceCartAlert.reducer,
43
- stateCartItem: sliceCartItem.reducer,
44
- stateCartPayment: sliceCartPayment.reducer,
45
- stateCartShipment: sliceCartShipment.reducer,
46
- stateCart: sliceCart.reducer,
47
- stateNewCustomerForm: sliceNewCustomerForm.reducer,
48
- stateFormReturningCustomer: sliceFormReturningCustomer.reducer,
49
-
50
- // Square slices
51
- ...reducersSquare,
52
-
53
- // Stripe slices
54
- ...sliceStripeCardForm,
55
- };
56
-
57
- export const store = configureStore({
58
- middleware: (getDefaultMiddleware) => getDefaultMiddleware({ serializableCheck: false }),
59
- reducer: merchiCartReducer,
60
- });
61
-
62
- function getStore() {
63
- return store.getState();
64
- }
65
-
66
- const {
67
- deleteCartItem,
68
- deleteCartItemError,
69
- deleteCartItemSuccess,
70
- fetchCart,
71
- fetchCartError,
72
- fetchCartSuccess,
73
- fetchTheme,
74
- fetchThemeError,
75
- fetchThemeSuccess,
76
- setCart,
77
- setCartClient,
78
- setDomainId,
79
- setCartShipmentGroups,
80
- } = sliceCart.actions;
81
-
82
- async function getCartToken() {
83
- const { domainId } = getStore().stateCart;
84
- const cartIdAndToken = domainId ? await getMerchiCartCookie(Number(domainId)) : undefined;
85
- return cartIdAndToken && cartIdAndToken[1] ? cartIdAndToken[1] : undefined;
86
- }
87
-
88
- function dispatch(method: any) {
89
- store.dispatch(method);
90
- }
91
-
92
- export function axtionSetCartClient(client: any) {
93
- dispatch(setCartClient(client));
94
- }
95
-
96
- export function setCartItem(cartItem: any, index: number) {
97
- batch(() => {
98
- if (cartItem && cartItem.id) {
99
- setActiveTab(tabIdItem);
100
- } else {
101
- setActiveTab(tabIdItems);
102
- }
103
- dispatch(sliceCartItem.actions.setCartItem({ cartItem, index }));
104
- });
105
- }
106
-
107
- export function setActiveTab(tabId: number) {
108
- dispatch(sliceCart.actions.setActiveTab(tabId));
109
- }
110
-
111
- interface setActiveTabAndEditDisabledProps {
112
- tabId: number;
113
- tabIndexToSet: number;
114
- disabled: boolean;
115
- }
116
-
117
- export function setActiveTabAndEditDisabled(settings: setActiveTabAndEditDisabledProps) {
118
- dispatch(sliceCart.actions.setActiveTabAndEditDisabled(settings));
119
- }
120
-
121
- export function closeAlert() {
122
- dispatch(sliceCartAlert.actions.closeAlert());
123
- }
124
-
125
- export function closeClearCart() {
126
- dispatch(sliceCart.actions.setActiveTab(tabIdItems));
127
- }
128
-
129
- export function alertError(message: string) {
130
- dispatch(sliceCartAlert.actions.showAlertDanger(
131
- { message, title: 'Error!' }));
132
- }
133
-
134
- function alertSuccess(message: string) {
135
- dispatch(sliceCartAlert.actions.showAlertSuccess(
136
- { message, title: 'Success!' }));
137
- }
138
-
139
- export function actionFetchTheme(id: number) {
140
- dispatch(fetchTheme())
141
- merchi.Domain.get(id, {embed: {activeTheme: {mainCss: {}}}})
142
- .then((domain: any) => {
143
- return domain.activeTheme;
144
- })
145
- .then((theme: any) => {
146
- appendStyleSheetText(theme.mainCss, () => dispatch(fetchThemeSuccess()));
147
- })
148
- .catch((e: any) => {
149
- alertError(e.errorMessage);
150
- dispatch(fetchThemeError());
151
- });
152
- }
153
-
154
- async function cartAndCookie(domainId: number) {
155
- const cart = makeCart({domain: {id: domainId}}, true);
156
- return cart.create({embed: cartEmbed})
157
- .then((c: any) => {
158
- if (domainId) {
159
- setCartCookie(Number(domainId), c.toJson(), undefined);
160
- }
161
- return c.toJson();
162
- })
163
- .then((cJson: any) => {
164
- dispatch(fetchCartSuccess(cJson));
165
- })
166
- .catch((e: any) => {
167
- batch(() => {
168
- alertError(e.errorMessage || 'Unable to fetch cart.');
169
- dispatch(fetchCartError());
170
- });
171
- });
172
- }
173
-
174
- export async function createAndSetNewCartCookie(domainId: number) {
175
- dispatch(fetchCart());
176
- await cartAndCookie(domainId);
177
- }
178
-
179
- export async function doClearCart() {
180
- const { domainId } = getStore().stateCart;
181
- dispatch(setCart({}));
182
- closeClearCart();
183
- await createAndSetNewCartCookie((domainId as any));
184
- }
185
-
186
- export async function patchCartItem(cartItem: any) {
187
- const data = getStore();
188
- const {
189
- patchCartItem: doPatch,
190
- patchCartItemError: doPatchError,
191
- patchCartItemSuccess: doPatchSuccess,
192
- } = sliceCartItem.actions;
193
- const cartToken = await getCartToken();
194
- const {
195
- stateCart: { cart },
196
- stateCartItem: { cartItem: stateCartItem, index }
197
- } = data;
198
- const cartEnt = makeCart(cart, false, cartToken);
199
- const cartItemEnt = makeCartItem(cartItem, true);
200
- cartItemEnt.id = (stateCartItem as any).id;
201
- (cartEnt as any).cartItems[index] = cartItemEnt;
202
- dispatch(doPatch());
203
- cartEnt.save({embed: cartEmbed}).
204
- then(
205
- (c: any) => {
206
- batch(() => {
207
- alertSuccess('Item updated.');
208
- dispatch(setCart(c.toJson()));
209
- dispatch(doPatchSuccess());
210
- setActiveTab(tabIdItems);
211
- });
212
- }
213
- ).
214
- then(() => {
215
- setCartItem({}, 0);
216
- }).
217
- catch(
218
- (e: any) => {
219
- batch(() => {
220
- alertError(e.errorMessage);
221
- dispatch(doPatchError());
222
- });
223
- }
224
- );
225
- }
226
-
227
- export async function actionDeleteCartItem(index: number) {
228
- const data = getStore();
229
- const cartToken = await getCartToken();
230
- const { stateCart: { cart } } = data;
231
- const cartEnt = makeCart(cart, false, cartToken);
232
- const cartItems = (cartEnt as any).cartItems;
233
- cartItems.splice(index, 1);
234
- (cartEnt as any).cartItems = cartItems;
235
- dispatch(deleteCartItem(index));
236
- cartEnt.save({embed: cartEmbed}).
237
- then(
238
- (c: any) => {
239
- dispatch(deleteCartItemSuccess(c.toJson()));
240
- }
241
- ).
242
- catch(
243
- (e: any) => {
244
- batch(() => {
245
- alertError(e.errorMessage);
246
- dispatch(deleteCartItemError());
247
- });
248
- }
249
- );
250
- }
251
-
252
- export async function updateCartShipmentAddress() {
253
- const {
254
- updateShipmentAddressError,
255
- updateShipmentAddressSuccess,
256
- } = sliceCartShipment.actions;
257
- const cartToken = await getCartToken();
258
- const {
259
- stateCart: { cart },
260
- stateCartShipment: { receiverAddress: address },
261
- } = getStore();
262
- const receiverAddress = makeAddress(address, true);
263
- const cartEnt = makeCart(cart, false, cartToken);
264
- cartEnt.receiverAddress = receiverAddress;
265
- cartEnt.save({embed: cartEmbed}).
266
- then((c: any) => {
267
- dispatch(setCart(c.toJson()));
268
- getCartShipmentGroupsAndQuotes(c.toJson()).
269
- then((cartWithShipmentGroups: any) => {
270
- const cartJson = cartWithShipmentGroups;
271
- batch(() => {
272
- dispatch(setCartShipmentGroups(cartJson.shipmentGroups));
273
- dispatch(updateShipmentAddressSuccess(cartJson.shipmentGroups));
274
- });
275
- });
276
- }).
277
- catch((e: any) => {
278
- batch(() => {
279
- alertError(e.errorMessage);
280
- dispatch(updateShipmentAddressError());
281
- });
282
- });
283
- }
284
-
285
- export async function saveCartShipmentAddressAndGoToNextTab(values: any) {
286
- const { receiverAddress: address, receiverNotes } = values;
287
- const {
288
- saveShipmentAddress,
289
- saveShipmentAddressError,
290
- saveShipmentAddressSuccess,
291
- } = sliceCartShipment.actions;
292
- const cartToken = await getCartToken();
293
- const { stateCart: { cart } } = getStore();
294
- dispatch(saveShipmentAddress());
295
- const receiverAddress = makeAddress(address, true);
296
- const cartEnt = makeCart(cart, false, cartToken);
297
- cartEnt.receiverAddress = receiverAddress;
298
- cartEnt.receiverNotes = receiverNotes;
299
- cartEnt.save({embed: cartEmbed}).
300
- then((c: any) => {
301
- batch(() => {
302
- dispatch(setCart(c.toJson()));
303
- dispatch(saveShipmentAddressSuccess());
304
- setActiveTabAndEditDisabled(
305
- {tabId: tabIdCheckout, tabIndexToSet: 2, disabled: false});
306
- });
307
- }).
308
- catch((e: any) => {
309
- batch(() => {
310
- alertError(e.errorMessage);
311
- dispatch(saveShipmentAddressError());
312
- });
313
- });
314
- }
315
-
316
- async function attachClientToCart(clientJson: any) {
317
- const {
318
- createNewCustomerSuccess: createNewSuccess,
319
- } = sliceNewCustomerForm.actions;
320
- const cartToken = await getCartToken();
321
- const { stateCart: { cart } } = getStore();
322
- const clientEnt = makeUser({id: clientJson.id});
323
- const cartEnt = makeCart(cart, false, cartToken);
324
- cartEnt.client = clientEnt;
325
- return cartEnt.save({embed: cartEmbed}).
326
- then((c: any) => {
327
- dispatch(setCart(c.toJson()));
328
- dispatch(createNewSuccess());
329
- });
330
- }
331
-
332
- export async function setSelectedShipmentQuote(groupIndex: number, quote: any) {
333
- const cartToken = await getCartToken();
334
- const { stateCart: { cart } } = getStore();
335
- const {
336
- setSelectedShipmentQuote: setSelected,
337
- setSelectedShipmentQuoteError,
338
- setSelectedShipmentQuoteSuccess,
339
- } = sliceCartShipment.actions;
340
- const cartEnt = makeCart(cart, false, cartToken);
341
- const cartShipmentQuote = makeCartShipmentQuote(quote);
342
- (cartEnt as any).shipmentGroups[groupIndex].selectedQuote = cartShipmentQuote;
343
- dispatch(setSelected({ groupIndex, quote }));
344
- cartEnt.save({embed: cartEmbed}).
345
- then((c: any) => {
346
- dispatch(setCart(c.toJson()));
347
- dispatch(setSelectedShipmentQuoteSuccess());
348
- }).
349
- catch((e: any) => {
350
- batch(() => {
351
- alertError(e.errorMessage);
352
- dispatch(setSelectedShipmentQuoteError());
353
- });
354
- });
355
- }
356
-
357
- const {
358
- setReturningCustomerError,
359
- tryReturningCustomer: tryReturning,
360
- tryReturningCustomerError,
361
- tryReturningCustomerSuccess,
362
- } = sliceFormReturningCustomer.actions;
363
-
364
- export function tryReturningCustomer(urlApi: string, data: any) {
365
- const { emailAddress } = data;
366
- dispatch(tryReturning());
367
- tryReturningCustomerEmail(urlApi, emailAddress)
368
- .then((r: any) => attachClientToCart({
369
- emailAddresses: [{emailAddress}],
370
- id: r.user_id,
371
- }))
372
- .then(() => dispatch(tryReturningCustomerSuccess()))
373
- .catch((e: any) =>
374
- batch(() => {
375
- alertError(e.errorMessage);
376
- dispatch(tryReturningCustomerError());
377
- dispatch(setReturningCustomerError(true));
378
- }));
379
- }
380
-
381
- const {
382
- createNewCustomer: createNew,
383
- createNewCustomerError: createNewError,
384
- createNewCustomerSuccess: createNewSuccess,
385
- } = sliceNewCustomerForm.actions;
386
-
387
- export function actionCreateNewCustomer(urlApi: string, customerJson: any) {
388
- const { cart } = getStore().stateCart;
389
- const domainId = cart && (cart as any).domain && (cart as any).domain.id;
390
- dispatch(createNew());
391
- const user = makeUser(
392
- {...customerJson,
393
- registeredUnderDomains: [{id: domainId}]},
394
- true
395
- );
396
- const error = (e: any) => batch(
397
- () => {
398
- alertError(e.errorMessage);
399
- dispatch(createNewError(e.errorMessage));
400
- });
401
- createNewCustomer(urlApi, {...customerJson, registeredUnderDomains: [{id: domainId}]})
402
- .then((r: any) => {
403
- const { user: userJson } = r;
404
- attachClientToCart(userJson);
405
- })
406
- .then(() => dispatch(createNewSuccess()))
407
- .catch(error);
408
- }
409
-
410
- const { creditCardPaySuccess } = sliceCartPayment.actions;
411
-
412
- export function callbackCreditCardPaymentSuccess(invoiceJson: any) {
413
- batch(() => {
414
- dispatch(creditCardPaySuccess(invoiceJson));
415
- setActiveTab(tabIdPaymentSuccess);
416
- });
417
- }
418
-
419
- async function convertToJson(ent: any) {
420
- const json = await ent.toJson();
421
- return json;
422
- }
423
-
424
- function updateCartValues(cartJson: any) {
425
- const { initCartShipmentSlice } = sliceCartShipment.actions;
426
- dispatch(sliceCart.actions.fetchCartSuccess(cartJson));
427
- dispatch(initCartShipmentSlice(cartJson));
428
- }
429
-
430
- function getCart(domainId: number, cartIdAndToken: Array<string>) {
431
- const {
432
- cartSettingsInvalid,
433
- } = sliceCart.actions;
434
- const id = Number(cartIdAndToken[0]);
435
- if (cartIdAndToken[1]) {
436
- merchi.cartToken = cartIdAndToken[1];
437
- }
438
- dispatch(fetchCart());
439
- merchi.Cart.get(id, {embed: cartEmbed})
440
- .then(convertToJson)
441
- .then((cart: any) => {
442
- if (stripeIsValidAndActive(cart)) {
443
- updateCartValues(cart);
444
- } else {
445
- console.error(
446
- `MErhci cart error: Stripe payment ` +
447
- `options have not been correctly set up. ` +
448
- `Check the company profile payment options tab ` +
449
- `to set and edit stripe payment options.`);
450
- dispatch(cartSettingsInvalid());
451
- }
452
- })
453
- .catch((e: any) => {
454
- createAndSetNewCartCookie(domainId);
455
- });
456
- }
457
-
458
- export async function actionGetMerchiCart(domainId: number) {
459
- const cartIdAndToken = await getMerchiCartCookie(domainId);
460
- if (cartIdAndToken) {
461
- getCart(domainId, cartIdAndToken);
462
- } else {
463
- createAndSetNewCartCookie(domainId);
464
- }
465
- }
466
-
467
- export async function isMerchiCartFetching() {
468
- return getStore().stateCart.fetchingCart;
469
- }
470
-
471
- export async function getMerchiCartValues() {
472
- const { cart } = getStore().stateCart;
473
- const { cartItems, currency, subtotalCost, taxAmount, totalCost } = (cart as any);
474
- const cartItemsCount = cartItems ? cartItems.length : 0;
475
- return {
476
- cart,
477
- cartItemsCount,
478
- currency: currency || '',
479
- subtotalCost: subtotalCost || 0,
480
- taxAmount: taxAmount || 0,
481
- totalCost: totalCost || 0,
482
- };
483
- }
484
-
485
- export async function doCartComplete() {
486
- const domainId: any = getStore().stateCart.domainId;
487
- dispatch(sliceCartPayment.actions.doCardComplete());
488
- await cartAndCookie(domainId).then(() => location.reload());
489
- }
490
-
491
- export function initMerchiCart(domainId: number) {
492
- dispatch(setDomainId(domainId));
493
- actionGetMerchiCart(domainId);
494
- if ((window as any) && (window as any) !== undefined) {
495
- (window as any).getCart = () => actionGetMerchiCart(domainId);
496
- (window as any).isMerchiCartFetching = isMerchiCartFetching;
497
- (window as any).getMerchiCartValues = getMerchiCartValues;
498
- }
499
- }
@@ -1,164 +0,0 @@
1
- import * as React from 'react';
2
- import StripePaymentButtons from './StripePaymentButtons';
3
- import {
4
- CardCvcElement,
5
- CardExpiryElement,
6
- CardNumberElement,
7
- Elements,
8
- useStripe,
9
- useElements,
10
- } from '@stripe/react-stripe-js';
11
- import {
12
- loadStripe,
13
- PaymentRequestPaymentMethodEvent,
14
- } from '@stripe/stripe-js';
15
- import { CARD_ELEMENT_OPTIONS } from './utils';
16
-
17
- type DoStripePaymentRequestForButton = (
18
- stripe: any,
19
- event: PaymentRequestPaymentMethodEvent
20
- ) => void;
21
-
22
- interface FormProps {
23
- doStripePayment: (values: any) => void;
24
- doStripePaymentRequestForButton?: DoStripePaymentRequestForButton;
25
- cart: any;
26
- loadingStripePayment: boolean;
27
- loadingStripePaymentButtons: boolean;
28
- PaymentButton?: any;
29
- setLoadingStripePayment: (loading: boolean) => void;
30
- }
31
-
32
- function InnerForm({
33
- doStripePayment,
34
- doStripePaymentRequestForButton,
35
- cart,
36
- loadingStripePayment,
37
- loadingStripePaymentButtons,
38
- PaymentButton,
39
- setLoadingStripePayment,
40
- }: FormProps) {
41
- const inputClass = 'form-control p-t-8 stripe-form-control';
42
- const stripe = useStripe();
43
- const elements = useElements();
44
- function paymentStart(e: any) {
45
- const card = (elements as any).getElement(CardNumberElement) as any;
46
- setLoadingStripePayment(true);
47
- e.preventDefault();
48
- if (!stripe || !elements) {
49
- setLoadingStripePayment(false);
50
- return;
51
- }
52
- doStripePayment({ card, cart, stripe });
53
- }
54
- return (
55
- <>
56
- {loadingStripePaymentButtons ? (
57
- <div style={{ alignItems: 'center' }}>
58
- <div
59
- style={{
60
- alignItems: 'center',
61
- display: 'flex',
62
- justifyContent: 'center',
63
- marginBottom: '1rem',
64
- textAlign: 'center',
65
- }}
66
- >
67
- <div className='spinner-merchi-small' />
68
- </div>
69
- <p style={{ fontSize: '14px', fontWeight: 600, textAlign: 'center' }}>
70
- Processing payment
71
- </p>
72
- </div>
73
- ) : (
74
- <>
75
- {!!(cart && doStripePaymentRequestForButton) && (
76
- <StripePaymentButtons
77
- doPaymentRequest={(event: PaymentRequestPaymentMethodEvent) =>
78
- (
79
- doStripePaymentRequestForButton as DoStripePaymentRequestForButton
80
- )(stripe, event)
81
- }
82
- cart={cart}
83
- />
84
- )}
85
- <form onSubmit={paymentStart}>
86
- <label>
87
- <strong>Card details</strong>
88
- </label>
89
- <div className='d-flex flex-column gap-1'>
90
- <CardNumberElement
91
- className={inputClass}
92
- {...CARD_ELEMENT_OPTIONS}
93
- />
94
- <CardExpiryElement
95
- className={inputClass}
96
- {...CARD_ELEMENT_OPTIONS}
97
- />
98
- <CardCvcElement
99
- className={inputClass}
100
- {...CARD_ELEMENT_OPTIONS}
101
- />
102
- <PaymentButton loading={loadingStripePayment} />
103
- </div>
104
- </form>
105
- </>
106
- )}
107
- </>
108
- );
109
- }
110
-
111
- interface Props {
112
- doStripePayment: (values: any) => void;
113
- doStripePaymentRequestForButton?: (
114
- stripe: any,
115
- event: PaymentRequestPaymentMethodEvent
116
- ) => void;
117
- cart: any;
118
- loadingStripePayment: boolean;
119
- loadingStripePaymentButtons: boolean;
120
- PaymentButton?: any;
121
- setLoadingStripePayment: (loading: boolean) => void;
122
- stripePubKey: string;
123
- }
124
-
125
- function FormStripeCardFields({
126
- doStripePayment,
127
- doStripePaymentRequestForButton,
128
- cart,
129
- loadingStripePayment,
130
- loadingStripePaymentButtons,
131
- PaymentButton,
132
- setLoadingStripePayment,
133
- stripePubKey,
134
- }: Props) {
135
- return stripePubKey ? (
136
- <Elements stripe={loadStripe(stripePubKey)}>
137
- <InnerForm
138
- doStripePayment={doStripePayment}
139
- doStripePaymentRequestForButton={doStripePaymentRequestForButton}
140
- cart={cart}
141
- loadingStripePayment={loadingStripePayment}
142
- loadingStripePaymentButtons={loadingStripePaymentButtons}
143
- setLoadingStripePayment={setLoadingStripePayment}
144
- PaymentButton={PaymentButton}
145
- />
146
- </Elements>
147
- ) : (
148
- <div style={{ alignItems: 'center' }}>
149
- <div
150
- style={{
151
- alignItems: 'center',
152
- display: 'flex',
153
- justifyContent: 'center',
154
- marginBottom: '1rem',
155
- textAlign: 'center',
156
- }}
157
- >
158
- <div className='spinner-merchi-small' />
159
- </div>
160
- </div>
161
- );
162
- }
163
-
164
- export default FormStripeCardFields;