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.
- package/package.json +3 -4
- package/src/Cart.tsx +0 -100
- package/src/CartAlert.tsx +0 -34
- package/src/CartHeader.tsx +0 -27
- package/src/CartProvider.tsx +0 -386
- package/src/CartTotals.tsx +0 -106
- package/src/assets/merchi-monster-loader.gif +0 -0
- package/src/assets/merchi-swipe-outline.png +0 -0
- package/src/assets/product-not-found.png +0 -0
- package/src/buttons/Button.tsx +0 -35
- package/src/buttons/ButtonBack.tsx +0 -37
- package/src/buttons/ButtonClearCart.tsx +0 -18
- package/src/buttons/ButtonInvoiceDownload.tsx +0 -63
- package/src/buttons/ButtonNext.tsx +0 -38
- package/src/buttons/ButtonNextDynamic.tsx +0 -31
- package/src/buttons/ButtonPay.tsx +0 -32
- package/src/buttons/ButtonShipmentTabNext.tsx +0 -25
- package/src/buttons/index.ts +0 -15
- package/src/components/Alert.tsx +0 -31
- package/src/components/CartBody.tsx +0 -16
- package/src/components/CartClient.tsx +0 -48
- package/src/components/CartFooter.tsx +0 -15
- package/src/components/CartItemRow.tsx +0 -145
- package/src/components/CartPaymentSettingsInvalid.tsx +0 -12
- package/src/components/CartShipment.tsx +0 -55
- package/src/components/CartTabContent.tsx +0 -15
- package/src/components/CartTabPanel.tsx +0 -25
- package/src/components/CartTableContainer.tsx +0 -15
- package/src/components/Collapse.tsx +0 -23
- package/src/components/LoadingTemplate.tsx +0 -22
- package/src/components/NoCartItems.tsx +0 -15
- package/src/components/ShipmentGroupCard.tsx +0 -156
- package/src/components/Table.tsx +0 -14
- package/src/components/Title.tsx +0 -22
- package/src/components/containers.tsx +0 -40
- package/src/components/index.ts +0 -30
- package/src/forms/FormNewCustomer.tsx +0 -119
- package/src/forms/FormReturningCustomer.tsx +0 -70
- package/src/forms/FormShipmentAddressAndNotes.tsx +0 -142
- package/src/forms/FormSquarePayment.tsx +0 -14
- package/src/forms/FormStripePayment.tsx +0 -14
- package/src/forms/InputAcceptUserTermsAndConditions.tsx +0 -43
- package/src/forms/InputError.tsx +0 -23
- package/src/forms/InputSelect.tsx +0 -58
- package/src/forms/InputText.tsx +0 -56
- package/src/forms/InputsAddress.tsx +0 -205
- package/src/index.tsx +0 -13
- package/src/panels/PanelCartItems.tsx +0 -61
- package/src/panels/PanelCartShipment.tsx +0 -89
- package/src/panels/PanelClearCart.tsx +0 -47
- package/src/panels/PanelClientCheckout.tsx +0 -92
- package/src/panels/PanelEditCartItem.tsx +0 -58
- package/src/panels/PanelPaymentSuccess.tsx +0 -69
- package/src/panels/index.ts +0 -15
- package/src/slices/sliceCart.ts +0 -159
- package/src/slices/sliceCartAlert.ts +0 -39
- package/src/slices/sliceCartItem.ts +0 -29
- package/src/slices/sliceCartPayment.ts +0 -45
- package/src/slices/sliceCartShipment.ts +0 -67
- package/src/slices/sliceFormReturningCustomer.ts +0 -25
- package/src/slices/sliceNewCustomerForm.ts +0 -24
- package/src/square/SquareCard.tsx +0 -58
- package/src/square/actions.ts +0 -40
- package/src/square/slices/reducersSquare.ts +0 -9
- package/src/square/slices/sliceSquareAlerts.ts +0 -29
- package/src/square/slices/sliceSquareForm.ts +0 -29
- package/src/store.ts +0 -499
- package/src/stripe/StripeCardFields.tsx +0 -164
- package/src/stripe/StripeCardForm.tsx +0 -86
- package/src/stripe/StripePaymentButtons.tsx +0 -117
- package/src/stripe/actions.ts +0 -94
- package/src/stripe/slices/sliceStripeAlerts.ts +0 -29
- package/src/stripe/slices/sliceStripeCardForm.ts +0 -9
- package/src/stripe/slices/sliceStripeForm.ts +0 -56
- package/src/stripe/utils.ts +0 -21
- package/src/styles/globals.css +0 -191
- package/src/styles/globals.css.map +0 -1
- package/src/styles/globals.scss +0 -197
- package/src/tabs/CartNav.tsx +0 -20
- package/src/tabs/NavTab.tsx +0 -38
- package/src/utilities/address.ts +0 -351
- package/src/utilities/cart.ts +0 -73
- package/src/utilities/company.ts +0 -8
- package/src/utilities/cookie.ts +0 -54
- package/src/utilities/currency.ts +0 -216
- package/src/utilities/helpers.ts +0 -209
- package/src/utilities/invoice.ts +0 -60
- package/src/utilities/product.ts +0 -7
- package/src/utilities/user.ts +0 -38
- package/src/utilities/variations.ts +0 -56
package/src/utilities/cookie.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { isUndefined } from 'lodash';
|
|
2
|
-
import { isBrowser } from "browser-or-node";
|
|
3
|
-
|
|
4
|
-
export async function getCookie(name: string, defaultValue: any) {
|
|
5
|
-
if (!isBrowser) {
|
|
6
|
-
return '';
|
|
7
|
-
}
|
|
8
|
-
const searchPrefix = name + '=';
|
|
9
|
-
const cookies = document.cookie.split(';');
|
|
10
|
-
let i;
|
|
11
|
-
let cookie;
|
|
12
|
-
for (i = 0; i < cookies.length; ++i) {
|
|
13
|
-
cookie = cookies[i];
|
|
14
|
-
cookie = cookie.replace(/^\s*/, '');
|
|
15
|
-
if (cookie.indexOf(searchPrefix) === 0) {
|
|
16
|
-
return cookie.substring(searchPrefix.length, cookie.length);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
if (isUndefined(defaultValue)) {
|
|
20
|
-
throw 'no such cookie present';
|
|
21
|
-
} else {
|
|
22
|
-
return defaultValue;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export async function getCartCookie(domainId: number) {
|
|
27
|
-
const idAndToken: string = await getCookie(`cart-${domainId}`, null);
|
|
28
|
-
return idAndToken ? idAndToken.split(',') : null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function setSessionCookie(name: string, value: any, domain?: any) {
|
|
32
|
-
if (!isBrowser) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
let cookie = name + '=' + value;
|
|
36
|
-
if (!!domain) {
|
|
37
|
-
// remove port, if it exists
|
|
38
|
-
let n = domain.indexOf(':');
|
|
39
|
-
domain = domain.substring(0, n != -1 ? n : domain.length);
|
|
40
|
-
// remove trailing slash and path, if they exists
|
|
41
|
-
n = domain.indexOf('/');
|
|
42
|
-
domain = domain.substring(0, n != -1 ? n : domain.length);
|
|
43
|
-
cookie += '; Domain=' + domain;
|
|
44
|
-
} else {
|
|
45
|
-
cookie += '; Domain=' + '.' + (location as any).hostname;
|
|
46
|
-
}
|
|
47
|
-
cookie += '; path=/';
|
|
48
|
-
document.cookie = cookie;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export const setCartCookie = async (storeId: number, cart: any, domain?: any) => {
|
|
52
|
-
const cookieValue = cart ? cart.id + ',' + cart.token : '';
|
|
53
|
-
await setSessionCookie('cart-' + String(storeId), cookieValue, domain);
|
|
54
|
-
};
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
export const currencyMap: any =
|
|
2
|
-
{ALL: 'L',
|
|
3
|
-
AFN: '؋',
|
|
4
|
-
ARS: '$',
|
|
5
|
-
AWG: 'ƒ',
|
|
6
|
-
AUD: '$',
|
|
7
|
-
AZN: '₼',
|
|
8
|
-
BSD: '$',
|
|
9
|
-
BBD: '$',
|
|
10
|
-
BYR: 'p.',
|
|
11
|
-
BZD: 'BZ$',
|
|
12
|
-
BMD: '$',
|
|
13
|
-
BOB: 'Bs.',
|
|
14
|
-
BAM: 'KM',
|
|
15
|
-
BWP: 'P',
|
|
16
|
-
BGN: 'лв',
|
|
17
|
-
BRL: 'R$',
|
|
18
|
-
BND: '$',
|
|
19
|
-
KHR: '៛',
|
|
20
|
-
CAD: '$',
|
|
21
|
-
KYD: '$',
|
|
22
|
-
CLP: '$',
|
|
23
|
-
CNY: '¥',
|
|
24
|
-
COP: '$',
|
|
25
|
-
CRC: '₡',
|
|
26
|
-
HRK: 'kn',
|
|
27
|
-
CUP: '₱',
|
|
28
|
-
CZK: 'Kč',
|
|
29
|
-
DKK: 'kr',
|
|
30
|
-
DOP: 'RD$',
|
|
31
|
-
XCD: '$',
|
|
32
|
-
EGP: '£',
|
|
33
|
-
SVC: '$',
|
|
34
|
-
EEK: 'kr',
|
|
35
|
-
EUR: '€',
|
|
36
|
-
FKP: '£',
|
|
37
|
-
FJD: '$',
|
|
38
|
-
GHC: '₵',
|
|
39
|
-
GIP: '£',
|
|
40
|
-
GTQ: 'Q',
|
|
41
|
-
GGP: '£',
|
|
42
|
-
GYD: '$',
|
|
43
|
-
HNL: 'L',
|
|
44
|
-
HKD: '$',
|
|
45
|
-
HUF: 'Ft',
|
|
46
|
-
ISK: 'kr',
|
|
47
|
-
INR: '₹',
|
|
48
|
-
IDR: 'Rp',
|
|
49
|
-
IRR: '﷼',
|
|
50
|
-
IMP: '£',
|
|
51
|
-
ILS: '₪',
|
|
52
|
-
JMD: '`J$',
|
|
53
|
-
JPY: '¥',
|
|
54
|
-
JEP: '£',
|
|
55
|
-
KES: 'KSh',
|
|
56
|
-
KZT: 'лв',
|
|
57
|
-
KPW: '₩',
|
|
58
|
-
KRW: '₩',
|
|
59
|
-
KGS: 'лв',
|
|
60
|
-
LAK: '₭',
|
|
61
|
-
LVL: 'Ls',
|
|
62
|
-
LBP: '£',
|
|
63
|
-
LRD: '$',
|
|
64
|
-
LTL: 'Lt',
|
|
65
|
-
MKD: 'ден',
|
|
66
|
-
MYR: 'RM',
|
|
67
|
-
MUR: '₨',
|
|
68
|
-
MXN: '$',
|
|
69
|
-
MNT: '₮',
|
|
70
|
-
MZN: 'MT',
|
|
71
|
-
NAD: '$',
|
|
72
|
-
NPR: '₨',
|
|
73
|
-
ANG: 'ƒ',
|
|
74
|
-
NZD: '$',
|
|
75
|
-
NIO: 'C$',
|
|
76
|
-
NGN: '₦',
|
|
77
|
-
NOK: 'kr',
|
|
78
|
-
OMR: '﷼',
|
|
79
|
-
PKR: '₨',
|
|
80
|
-
PAB: 'B/.',
|
|
81
|
-
PYG: 'Gs',
|
|
82
|
-
PEN: 'S/.',
|
|
83
|
-
PHP: '₱',
|
|
84
|
-
PLN: 'zł',
|
|
85
|
-
QAR: '﷼',
|
|
86
|
-
RON: 'lei',
|
|
87
|
-
RUB: '₽',
|
|
88
|
-
RMB: '¥',
|
|
89
|
-
SHP: '£',
|
|
90
|
-
SAR: '﷼',
|
|
91
|
-
RSD: 'Дин.',
|
|
92
|
-
SCR: '₨',
|
|
93
|
-
SGD: '$',
|
|
94
|
-
SBD: '$',
|
|
95
|
-
SOS: 'S',
|
|
96
|
-
ZAR: 'R',
|
|
97
|
-
LKR: '₨',
|
|
98
|
-
SEK: 'kr',
|
|
99
|
-
CHF: 'CHF',
|
|
100
|
-
SRD: '$',
|
|
101
|
-
SYP: '£',
|
|
102
|
-
TZS: 'TSh',
|
|
103
|
-
TWD: 'NT$',
|
|
104
|
-
THB: '฿',
|
|
105
|
-
TTD: 'TT$',
|
|
106
|
-
TRY: '₺',
|
|
107
|
-
TRL: '₤',
|
|
108
|
-
TVD: '$',
|
|
109
|
-
UGX: 'USh',
|
|
110
|
-
UAH: '₴',
|
|
111
|
-
GBP: '£',
|
|
112
|
-
USD: '$',
|
|
113
|
-
UYU: '$U',
|
|
114
|
-
UZS: 'лв',
|
|
115
|
-
VEF: 'Bs',
|
|
116
|
-
VND: '₫',
|
|
117
|
-
YER: '﷼',
|
|
118
|
-
ZWD: 'Z$'};
|
|
119
|
-
|
|
120
|
-
export function formatCurrency(amount: any, options: any) {
|
|
121
|
-
/*
|
|
122
|
-
* Example usage:
|
|
123
|
-
|
|
124
|
-
formatCurrency(-222.123456, {currency: 'EGP',
|
|
125
|
-
showCodeIfNoSymbol: true,
|
|
126
|
-
financialNegative: true,
|
|
127
|
-
decimalPlaces: 3})
|
|
128
|
-
|
|
129
|
-
--> '(£222.123)'
|
|
130
|
-
*/
|
|
131
|
-
|
|
132
|
-
let symbol;
|
|
133
|
-
let negative = false;
|
|
134
|
-
let result;
|
|
135
|
-
options = options || {};
|
|
136
|
-
options.currency = options.currency || 'AUD';
|
|
137
|
-
options.showCodeIfNoSymbol = options.showCodeIfNoSymbol || true;
|
|
138
|
-
options.symbolAfterAmount = options.symbolAfterAmount || false;
|
|
139
|
-
options.financialNegative = options.financialNegative || false;
|
|
140
|
-
options.codeAfterSymbol = options.codeAfterSymbol || false;
|
|
141
|
-
options.codeBeforeSymbol = options.codeBeforeSymbol || false;
|
|
142
|
-
options.spaceBetweenSymbol = options.spaceBetweenSymbol || false;
|
|
143
|
-
options.decimalPlaces = options.decimalPlaces || 2;
|
|
144
|
-
options.decimalSeperator = options.decimalSeperator || '.';
|
|
145
|
-
options.codeAfterAmount = options.codeAfterAmount || false;
|
|
146
|
-
if (amount < 0.0) {
|
|
147
|
-
negative = true;
|
|
148
|
-
amount *= -1.0; // eslint-disable-line
|
|
149
|
-
}
|
|
150
|
-
if (Object.prototype.hasOwnProperty.call(currencyMap, options.currency)) {
|
|
151
|
-
symbol = currencyMap[options.currency];
|
|
152
|
-
if (options.codeAfterSymbol) {
|
|
153
|
-
symbol += '(' + options.currency + ') ';
|
|
154
|
-
}
|
|
155
|
-
if (options.codeBeforeSymbol) {
|
|
156
|
-
symbol = `(${options.currency}) ${symbol}`;
|
|
157
|
-
}
|
|
158
|
-
} else if (options.showCodeIfNoSymbol) {
|
|
159
|
-
symbol = options.currency;
|
|
160
|
-
} else {
|
|
161
|
-
symbol = '';
|
|
162
|
-
}
|
|
163
|
-
amount = amount.toFixed(options.decimalPlaces);
|
|
164
|
-
amount = amount.replace('.', options.decimalSeperator);
|
|
165
|
-
if (options.symbolAfterAmount) {
|
|
166
|
-
result = amount;
|
|
167
|
-
if (options.spaceBetweenSymbol) {
|
|
168
|
-
result += ' ';
|
|
169
|
-
}
|
|
170
|
-
result += symbol;
|
|
171
|
-
} else {
|
|
172
|
-
result = symbol;
|
|
173
|
-
if (options.spaceBetweenSymbol) {
|
|
174
|
-
result += ' ';
|
|
175
|
-
}
|
|
176
|
-
result += amount;
|
|
177
|
-
}
|
|
178
|
-
if (negative) {
|
|
179
|
-
if (options.financialNegative) {
|
|
180
|
-
result = `(${result})`;
|
|
181
|
-
} else {
|
|
182
|
-
result = `-${result}`;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
if (options.codeAfterAmount === true) {
|
|
186
|
-
result += ` (${options.currency})`;
|
|
187
|
-
}
|
|
188
|
-
return result;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function formatCountryTax(countryTax: any) {
|
|
192
|
-
const { taxName, taxPercent } = countryTax;
|
|
193
|
-
return taxPercent > 0 ? ` inc ${taxName} (${taxPercent}%)` : '';
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export function calculateTotalWithTax(total: number, tax: any) {
|
|
197
|
-
let taxMultiplier = 1.0;
|
|
198
|
-
if (tax && tax.taxPercent() > 0) {
|
|
199
|
-
taxMultiplier += tax.taxPercent() / 100;
|
|
200
|
-
taxMultiplier = parseFloat(taxMultiplier.toFixed(2));
|
|
201
|
-
}
|
|
202
|
-
let grandTotal = total * taxMultiplier;
|
|
203
|
-
return parseFloat(grandTotal.toFixed(2));
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export function cartItemCurrencyAndCost(cartItem: any) {
|
|
207
|
-
const { currency, subtotalCost, taxType } = cartItem;
|
|
208
|
-
const tax = taxType ? formatCountryTax(taxType) : '';
|
|
209
|
-
return`${currency} ${formatCurrency(subtotalCost, { currency, showCodeIfNoSymbol: false })} ${tax}`;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export function currencyTaxAndCost(currency: string, tax: any, theCost: number) {
|
|
213
|
-
const totalCost = calculateTotalWithTax(theCost, tax);
|
|
214
|
-
const _tax = tax ? formatCountryTax(tax) : '';
|
|
215
|
-
return `${currency} ${formatCurrency(totalCost, {currency, showCodeIfNoSymbol: false})} ${_tax}`;
|
|
216
|
-
}
|
package/src/utilities/helpers.ts
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import camelCase from 'lodash/camelCase';
|
|
2
|
-
import snakeCase from 'lodash/snakeCase';
|
|
3
|
-
|
|
4
|
-
interface JsonObject {
|
|
5
|
-
[key: string]: any;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
enum TransformationType {
|
|
9
|
-
CAMEL = "camel",
|
|
10
|
-
UNDERSCORE = "underscore"
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const functionDict: { [key in TransformationType]: (word: string) => string } = {
|
|
14
|
-
[TransformationType.CAMEL]: camelCase,
|
|
15
|
-
[TransformationType.UNDERSCORE]: snakeCase
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
function parseJsonKeyNames(jsonObject: any, standard: keyof typeof functionDict): any {
|
|
19
|
-
if (typeof jsonObject === 'object' && jsonObject !== null) {
|
|
20
|
-
if (Array.isArray(jsonObject)) {
|
|
21
|
-
for (let item of jsonObject) {
|
|
22
|
-
parseJsonKeyNames(item, standard);
|
|
23
|
-
}
|
|
24
|
-
} else {
|
|
25
|
-
const oldKeys = Object.keys(jsonObject);
|
|
26
|
-
for (let old of oldKeys) {
|
|
27
|
-
const newKey = functionDict[standard](old);
|
|
28
|
-
if (newKey !== old) {
|
|
29
|
-
jsonObject[newKey] = jsonObject[old];
|
|
30
|
-
delete jsonObject[old];
|
|
31
|
-
parseJsonKeyNames(jsonObject[newKey], standard);
|
|
32
|
-
} else {
|
|
33
|
-
parseJsonKeyNames(jsonObject[old], standard);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return jsonObject;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function parseJsonKeyCamel(jsonObject: any) {
|
|
42
|
-
return parseJsonKeyNames(jsonObject, TransformationType.CAMEL);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
interface Counter {
|
|
46
|
-
value: number;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
interface SerialiseOptions {
|
|
50
|
-
existing?: FormData;
|
|
51
|
-
excludeOld?: boolean;
|
|
52
|
-
_prefix?: string;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function unpackRecursiveJsonIter(jsonObject: JsonObject, options?: SerialiseOptions, fileIndex?: Counter): FormData {
|
|
56
|
-
if (!options) options = {};
|
|
57
|
-
const result = options.existing || new FormData();
|
|
58
|
-
const prefix = options._prefix || '';
|
|
59
|
-
|
|
60
|
-
if (!fileIndex) fileIndex = { value: 0 };
|
|
61
|
-
|
|
62
|
-
const appendData = (name: string, value: any) => {
|
|
63
|
-
if (prefix) {
|
|
64
|
-
name = prefix + '-' + name;
|
|
65
|
-
}
|
|
66
|
-
if (value !== undefined && value !== null) {
|
|
67
|
-
result.set(name, value.toString()); // Convert to string since FormData accepts only strings or Blobs.
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const processSingleEntityProperty = (key: string, value: any) => {
|
|
72
|
-
let innerPrefix = key + '-0';
|
|
73
|
-
if (prefix) {
|
|
74
|
-
innerPrefix = prefix + '-' + innerPrefix;
|
|
75
|
-
}
|
|
76
|
-
unpackRecursiveJsonIter(value, { existing: result, _prefix: innerPrefix }, fileIndex);
|
|
77
|
-
appendData(key + '-count', '1');
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
for (const key in jsonObject) {
|
|
81
|
-
if ([undefined, '', null].includes(jsonObject[key]) || key === 'rights') {
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (Array.isArray(jsonObject[key])) {
|
|
86
|
-
jsonObject[key].forEach((item: any, index: number) => {
|
|
87
|
-
if ((typeof item === "object" || Array.isArray(item)) && item !== null) {
|
|
88
|
-
const arrayPrefix = prefix ? `${prefix}-${key}-${index}` : `${key}-${index}`;
|
|
89
|
-
unpackRecursiveJsonIter(item, { existing: result, _prefix: arrayPrefix }, fileIndex);
|
|
90
|
-
} else {
|
|
91
|
-
appendData(`${key}-${index}`, item);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
appendData(key + '-count', jsonObject[key].length.toString());
|
|
95
|
-
} else if (typeof jsonObject[key] === "object" && jsonObject[key] !== null) {
|
|
96
|
-
processSingleEntityProperty(key, jsonObject[key]);
|
|
97
|
-
} else {
|
|
98
|
-
appendData(key, jsonObject[key]);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return result;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function encodeMerchiApiData(dataDict: { [key: string]: any }): { [key: string]: any } {
|
|
106
|
-
const dataJson = parseJsonKeyCamel(dataDict);
|
|
107
|
-
return unpackRecursiveJsonIter(dataJson);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const supportedNumbers: any = {
|
|
111
|
-
AU: 'Australia (+61)',
|
|
112
|
-
AE: 'United Arab Emirates (+971)',
|
|
113
|
-
BH: 'Bahrain (+973)',
|
|
114
|
-
CN: 'China (+86)',
|
|
115
|
-
DK: 'Denmark (+45)',
|
|
116
|
-
ES: 'Spain (+34)',
|
|
117
|
-
FR: 'France (+33)',
|
|
118
|
-
GB: 'United Kingdom (+44)',
|
|
119
|
-
HK: 'Hong Kong (+852)',
|
|
120
|
-
ID: 'Indonesia (+62)',
|
|
121
|
-
IN: 'India (+91)',
|
|
122
|
-
IT: 'Italy (+39)',
|
|
123
|
-
KR: 'South Korea (+82)',
|
|
124
|
-
NC: 'New Caledonia (+687)',
|
|
125
|
-
NZ: 'New Zealand (+64)',
|
|
126
|
-
OM: 'Oman (+968)',
|
|
127
|
-
PH: 'Philippines (+63)',
|
|
128
|
-
PT: 'Portugal (+351)',
|
|
129
|
-
QA: 'Qatar (+974)',
|
|
130
|
-
SE: 'Sweden (+46)',
|
|
131
|
-
SG: 'Singapore (+65)',
|
|
132
|
-
TH: 'Thailand (+66)',
|
|
133
|
-
US: 'United States (+1)',
|
|
134
|
-
ZA: 'South Africa (+27)',
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
export const phoneOptions = Object.keys(supportedNumbers).map((key) => ({
|
|
138
|
-
value: key,
|
|
139
|
-
label: supportedNumbers[key],
|
|
140
|
-
}));
|
|
141
|
-
|
|
142
|
-
export function appendStyleSheetText(css: string, callback?: () => void) {
|
|
143
|
-
if (document && document !== undefined) {
|
|
144
|
-
const newStyleSheet = document.createElement('style');
|
|
145
|
-
newStyleSheet.textContent = css;
|
|
146
|
-
if (callback) {
|
|
147
|
-
newStyleSheet.onload = callback;
|
|
148
|
-
}
|
|
149
|
-
document.head.appendChild(newStyleSheet);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const optionsEmbed: any = {
|
|
154
|
-
options: {
|
|
155
|
-
linkedFile: {},
|
|
156
|
-
variationCostDiscountGroup: {},
|
|
157
|
-
variationUnitCostDiscountGroup: {}},
|
|
158
|
-
variationCostDiscountGroup: {},
|
|
159
|
-
variationUnitCostDiscountGroup: {},
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
const variationsEmbed: any = {
|
|
163
|
-
selectedOptions: {},
|
|
164
|
-
variationField: optionsEmbed,
|
|
165
|
-
variationFiles: {}
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
const variationsGroupsEmbed: any = {variations: variationsEmbed};
|
|
169
|
-
|
|
170
|
-
const productWithImagesEmbed: any = {
|
|
171
|
-
domain: {company: {defaultTaxType: {}, taxTypes: {}}},
|
|
172
|
-
featureImage: {},
|
|
173
|
-
groupVariationFields: {options: {linkedFile: {}}},
|
|
174
|
-
images: {},
|
|
175
|
-
independentVariationFields: {options: {linkedFile: {}}},
|
|
176
|
-
taxType: {},
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
const cartShipmentQuote: any = {
|
|
180
|
-
shipmentMethod: {originAddress: {}, taxType: {}},
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
export const cartEmbed: any = {
|
|
184
|
-
cartItems: {
|
|
185
|
-
product: productWithImagesEmbed,
|
|
186
|
-
taxType: {},
|
|
187
|
-
variations: variationsEmbed,
|
|
188
|
-
variationsGroups: variationsGroupsEmbed,
|
|
189
|
-
},
|
|
190
|
-
client: {
|
|
191
|
-
emailAddresses: {}, profilePicture: {},
|
|
192
|
-
},
|
|
193
|
-
clientCompany: {},
|
|
194
|
-
domain: {
|
|
195
|
-
company: {
|
|
196
|
-
defaultTaxType: {},
|
|
197
|
-
isStripeAccountEnabled: {},
|
|
198
|
-
taxTypes: {},
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
invoice: {},
|
|
202
|
-
receiverAddress: {},
|
|
203
|
-
shipmentGroups: {
|
|
204
|
-
cartItems: {product: {}},
|
|
205
|
-
quotes: cartShipmentQuote,
|
|
206
|
-
selectedQuote: cartShipmentQuote,
|
|
207
|
-
},
|
|
208
|
-
};
|
|
209
|
-
|
package/src/utilities/invoice.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
const urlToFile = async (url: string, filename: string, type: string) => {
|
|
2
|
-
const res = await fetch(url);
|
|
3
|
-
const buf = await res.arrayBuffer();
|
|
4
|
-
return new File([buf], filename, { type });
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
const urlToFilePdf = async (url: string, filename: string) => {
|
|
8
|
-
const file = await urlToFile(url, filename, 'application/pdf');
|
|
9
|
-
return file;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export async function generatePublicInvoicePdf(urlApi: string, invoice: any, receipt?: boolean) {
|
|
13
|
-
const id = invoice.id;
|
|
14
|
-
const domain = invoice.domain.emailDomain;
|
|
15
|
-
|
|
16
|
-
const queryString = new URLSearchParams({
|
|
17
|
-
invoice_token: invoice.invoiceToken
|
|
18
|
-
}).toString();
|
|
19
|
-
|
|
20
|
-
const fetchOptions: any = {
|
|
21
|
-
method: 'GET',
|
|
22
|
-
mode: 'cors'
|
|
23
|
-
};
|
|
24
|
-
const uri = receipt ? '/generate/receipt/pdf/' : '/generate/pdf/';
|
|
25
|
-
try {
|
|
26
|
-
const response = await fetch(
|
|
27
|
-
`${urlApi}invoices/${id}${uri}?${queryString}`,
|
|
28
|
-
fetchOptions
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
if (!response.ok) {
|
|
32
|
-
throw new Error("Error fetching PDF.");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const r = await response.json();
|
|
36
|
-
const pdf = await urlToFilePdf(
|
|
37
|
-
`data:application/pdf;base64,${r.pdf}`,
|
|
38
|
-
`${domain}-invoice-${id}.pdf`
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
const url = URL.createObjectURL(pdf);
|
|
42
|
-
const doc = (document as any);
|
|
43
|
-
const anchor = doc.createElement('a');
|
|
44
|
-
anchor.href = url;
|
|
45
|
-
anchor.download = pdf.name;
|
|
46
|
-
|
|
47
|
-
// Append to the DOM
|
|
48
|
-
doc.body.appendChild(anchor);
|
|
49
|
-
|
|
50
|
-
// Trigger `click` event
|
|
51
|
-
anchor.click();
|
|
52
|
-
|
|
53
|
-
// Remove element from DOM
|
|
54
|
-
doc.body.removeChild(anchor);
|
|
55
|
-
|
|
56
|
-
return { success: true };
|
|
57
|
-
} catch (e: any) {
|
|
58
|
-
throw e;
|
|
59
|
-
}
|
|
60
|
-
}
|
package/src/utilities/product.ts
DELETED
package/src/utilities/user.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Merchi } from 'merchi_sdk_ts';
|
|
2
|
-
import { encodeMerchiApiData } from './helpers';
|
|
3
|
-
|
|
4
|
-
const merchi = new Merchi()
|
|
5
|
-
|
|
6
|
-
export function makeUser(userJson: any, makeDirty?: boolean) {
|
|
7
|
-
const user = new merchi.User();
|
|
8
|
-
return user.fromJson(userJson, { makeDirty });
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function primaryEmail(user: any) {
|
|
12
|
-
const { emailAddresses = [] } = user;
|
|
13
|
-
return emailAddresses[0] ? emailAddresses[0].emailAddress : '';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function primaryPhone(user: any) {
|
|
17
|
-
const { phoneNumbers = [] } = user;
|
|
18
|
-
return phoneNumbers[0] ? phoneNumbers[0].internationalFormatNumber : '';
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export async function tryReturningCustomerEmail(urlApi: string, emailAddress: string) {
|
|
22
|
-
const queryString = new URLSearchParams({email_address: emailAddress}).toString();
|
|
23
|
-
const fetchOptions: any = {method: 'POST'};
|
|
24
|
-
|
|
25
|
-
return await fetch(
|
|
26
|
-
`${urlApi}user-check-email/?${queryString}`,
|
|
27
|
-
fetchOptions,
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export async function createNewCustomer(urlApi: string, customerJson: any) {
|
|
32
|
-
const formData = encodeMerchiApiData(customerJson);
|
|
33
|
-
const fetchOptions: any = {method: 'POST', body: formData}
|
|
34
|
-
return await fetch(
|
|
35
|
-
`${urlApi}public_user_create/`,
|
|
36
|
-
fetchOptions,
|
|
37
|
-
);
|
|
38
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
export enum FieldType {
|
|
2
|
-
TEXT_INPUT = 1,
|
|
3
|
-
SELECT = 2,
|
|
4
|
-
FILE_UPLOAD = 3,
|
|
5
|
-
TEXT_AREA = 4,
|
|
6
|
-
NUMBER_INPUT = 5,
|
|
7
|
-
CHECKBOX = 6,
|
|
8
|
-
RADIO = 7,
|
|
9
|
-
FIELD_INSTRUCTIONS = 8,
|
|
10
|
-
IMAGE_SELECT = 9,
|
|
11
|
-
COLOUR_PICKER = 10,
|
|
12
|
-
COLOUR_SELECT = 11,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export function isSelectable(fieldType: number) {
|
|
17
|
-
return [
|
|
18
|
-
FieldType.SELECT,
|
|
19
|
-
FieldType.CHECKBOX,
|
|
20
|
-
FieldType.RADIO,
|
|
21
|
-
FieldType.IMAGE_SELECT,
|
|
22
|
-
FieldType.COLOUR_SELECT
|
|
23
|
-
].includes(fieldType);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function concatinatedSelectedOptionValues(variation: any) {
|
|
27
|
-
const { selectableOptions, value } = variation;
|
|
28
|
-
const optionIds = value ? value.split(',') : [];
|
|
29
|
-
const optionIdsLength = optionIds.length - 1;
|
|
30
|
-
let option
|
|
31
|
-
let i = 0;
|
|
32
|
-
let val = '';
|
|
33
|
-
for (i; i < optionIds.length; i++) {
|
|
34
|
-
option = selectableOptions.find(
|
|
35
|
-
(o: any) => String(o.optionId) === String(optionIds[i]));
|
|
36
|
-
val += option ? option.value : '';
|
|
37
|
-
if (optionIdsLength > i) {
|
|
38
|
-
val += ', ';
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return val;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function valueString(variation: any) {
|
|
45
|
-
const {
|
|
46
|
-
variationField: field,
|
|
47
|
-
variationFiles,
|
|
48
|
-
value,
|
|
49
|
-
} = variation;
|
|
50
|
-
if (isSelectable(field.fieldType)) {
|
|
51
|
-
return concatinatedSelectedOptionValues(variation);
|
|
52
|
-
} else if (field.fieldType === FieldType.FILE_UPLOAD && variationFiles) {
|
|
53
|
-
return variationFiles.length > 1 ? 'uploaded files' : 'uploaded file';
|
|
54
|
-
}
|
|
55
|
-
return value;
|
|
56
|
-
}
|