@everymatrix/cashier-method-details 1.27.10 → 1.28.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cashier-method-details.js +295 -234
- package/dist/cashier-method-details.js.map +1 -1
- package/package.json +2 -2
- package/rollup.config.js +4 -0
- package/src/CashierMethodDetails.svelte +138 -13
- package/src/translations.js +2 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@everymatrix/cashier-method-details",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.28.0",
|
4
4
|
"main": "index.js",
|
5
5
|
"svelte": "src/index.ts",
|
6
6
|
"scripts": {
|
@@ -35,5 +35,5 @@
|
|
35
35
|
"publishConfig": {
|
36
36
|
"access": "public"
|
37
37
|
},
|
38
|
-
"gitHead": "
|
38
|
+
"gitHead": "d291acb27fcd4cf8217ec1c98666c02bfb1aea9f"
|
39
39
|
}
|
package/rollup.config.js
CHANGED
@@ -6,6 +6,7 @@ import livereload from 'rollup-plugin-livereload';
|
|
6
6
|
import { terser } from 'rollup-plugin-terser';
|
7
7
|
import sveltePreprocess from 'svelte-preprocess';
|
8
8
|
import typescript from '@rollup/plugin-typescript';
|
9
|
+
import postcss from 'rollup-plugin-postcss';
|
9
10
|
const production = process.env.NODE_ENV === 'production';
|
10
11
|
const dev = process.env.NODE_ENV === 'development';
|
11
12
|
|
@@ -18,6 +19,9 @@ export default {
|
|
18
19
|
file: 'dist/cashier-method-details.js'
|
19
20
|
},
|
20
21
|
plugins: [
|
22
|
+
postcss({
|
23
|
+
extensions:['.css']
|
24
|
+
}),
|
21
25
|
svelte({
|
22
26
|
preprocess: sveltePreprocess(),
|
23
27
|
compilerOptions: {
|
@@ -8,8 +8,13 @@
|
|
8
8
|
|
9
9
|
import '@everymatrix/cashier-iframe-redirect';
|
10
10
|
import '@everymatrix/cashier-receipt-page';
|
11
|
-
import '@everymatrix/cashier-confirm-modal'
|
12
|
-
import '@everymatrix/cashier-notifications'
|
11
|
+
import '@everymatrix/cashier-confirm-modal';
|
12
|
+
import '@everymatrix/cashier-notifications';
|
13
|
+
import '@everymatrix/cashier-error';
|
14
|
+
import '@everymatrix/cashier-modal';
|
15
|
+
import flatpickr from "flatpickr";
|
16
|
+
import "flatpickr/dist/flatpickr.min.css";
|
17
|
+
import FlatpickrLanguages from "flatpickr/dist/l10n";
|
13
18
|
|
14
19
|
import type {PaymentMethod} from "./CashierMethodDetails.types";
|
15
20
|
export class PaymentMethodDetails {
|
@@ -120,6 +125,9 @@
|
|
120
125
|
export let session: string;
|
121
126
|
export let lang: string = 'en';
|
122
127
|
export let local: string = 'en-US';
|
128
|
+
export let dateformat: string = "d/m/Y";
|
129
|
+
export let timeformat: string = "H:i";
|
130
|
+
export let dateandtimeformat: string = 'd/m/Y H:i';
|
123
131
|
export let translationurl: string;
|
124
132
|
export let customerid: string;
|
125
133
|
export let currency: string;
|
@@ -151,6 +159,7 @@
|
|
151
159
|
let openedLookup: string | null;
|
152
160
|
let clickedElem: HTMLElement;
|
153
161
|
let qrCodeContainer: HTMLElement[] = [];
|
162
|
+
let flatpickrEl: HTMLElement[] = [];
|
154
163
|
let qrCodeScriptSrc: string = 'https://cdn.rawgit.com/davidshimjs/qrcodejs/gh-pages/qrcode.min.js';
|
155
164
|
let blankPageTarget: string = '_blank';
|
156
165
|
let externalLink: string = '';
|
@@ -165,16 +174,39 @@
|
|
165
174
|
let openLookupTop = false;
|
166
175
|
let maxLookupHeight: number;
|
167
176
|
let editedAmount: number;
|
177
|
+
let errorResponseCode: string;
|
168
178
|
|
169
|
-
$: endpoint && session && selectedpaymentmethodname && currency &&
|
179
|
+
$: endpoint && session && selectedpaymentmethodname && currency && reinitMethod();
|
170
180
|
$: clientstyling && customStylingContainer && setClientStyling();
|
171
181
|
$: clientstylingurl && customStylingContainer && setClientStylingURL();
|
172
182
|
$: lang && setActiveLanguage();
|
173
183
|
$: lang && translationurl && setTranslationUrl();
|
174
|
-
$:
|
184
|
+
$: fields.length && qrCodeContainer.length && generateQr();
|
185
|
+
$: fields.length && flatpickrEl.length && createDatePicker();
|
175
186
|
$: innerWidth && onWindowResize();
|
176
187
|
$: mobileView.toString() && hideMethodsList();
|
177
188
|
|
189
|
+
|
190
|
+
const reinitMethod = () => {
|
191
|
+
if (flatpickrEl.length) {
|
192
|
+
flatpickrEl.forEach(el => {
|
193
|
+
if (!el) {
|
194
|
+
return;
|
195
|
+
}
|
196
|
+
flatpickr(el, {dateFormat: dateformat}).destroy();
|
197
|
+
})
|
198
|
+
}
|
199
|
+
flatpickrEl = [];
|
200
|
+
fields = [];
|
201
|
+
prepareFields = {};
|
202
|
+
showError = {};
|
203
|
+
fieldValidation = {};
|
204
|
+
qrCodeContainer = [];
|
205
|
+
selectedPaymentMethod = null;
|
206
|
+
errorResponseCode = ''
|
207
|
+
getPaymentDetails();
|
208
|
+
}
|
209
|
+
|
178
210
|
const generateQr = () => {
|
179
211
|
qrCodeContainer.forEach(elem => {
|
180
212
|
if (elem && elem.innerText) {
|
@@ -188,6 +220,35 @@
|
|
188
220
|
}
|
189
221
|
})
|
190
222
|
}
|
223
|
+
const createDatePicker = () => {
|
224
|
+
const dateOptions = {
|
225
|
+
[FieldTypes.Time]: {
|
226
|
+
noCalendar: true,
|
227
|
+
enableTime: true,
|
228
|
+
dateFormat: timeformat,
|
229
|
+
time_24hr: timeformat === 'H:i',
|
230
|
+
allowInput: true
|
231
|
+
},
|
232
|
+
[FieldTypes.Date]: {
|
233
|
+
dateFormat: dateformat,
|
234
|
+
allowInput: true,
|
235
|
+
locale: {...FlatpickrLanguages[lang]}
|
236
|
+
},
|
237
|
+
[FieldTypes.DateTime]: {
|
238
|
+
dateFormat: dateandtimeformat,
|
239
|
+
allowInput: true,
|
240
|
+
enableTime: true,
|
241
|
+
time_24hr: timeformat === 'H:i',
|
242
|
+
locale: {...FlatpickrLanguages[lang]}
|
243
|
+
}
|
244
|
+
}
|
245
|
+
flatpickrEl.forEach((el) => {
|
246
|
+
if(!el) {
|
247
|
+
return;
|
248
|
+
}
|
249
|
+
flatpickr(flatpickrEl, dateOptions[el.dataset.type])
|
250
|
+
});
|
251
|
+
}
|
191
252
|
const setActiveLanguage = ():void => {
|
192
253
|
setLocale(lang);
|
193
254
|
}
|
@@ -226,17 +287,27 @@
|
|
226
287
|
})
|
227
288
|
}
|
228
289
|
fetch(url, requestParams).then(res => res.json()).then(data => {
|
290
|
+
if (data.error) {
|
291
|
+
window.postMessage({type: 'ShowSessionError', error: data.error}, window.location.href)
|
292
|
+
return;
|
293
|
+
}
|
294
|
+
if (data.ResponseCode !== 'Success') {
|
295
|
+
errorResponseCode = data.ResponseCode;
|
296
|
+
return;
|
297
|
+
}
|
229
298
|
xPaymentSessionToken = data.XPaymentSessionToken;
|
230
299
|
selectedPaymentMethod = data.PaymentMethod;
|
231
|
-
showError = {};
|
232
|
-
prepareFields = {};
|
233
|
-
fieldValidation = {};
|
234
300
|
editedAmount = amount;
|
235
301
|
if (!selectedPaymentMethod.HideAmountField) {
|
236
302
|
validateAmount();
|
237
303
|
}
|
238
304
|
fields = selectedPaymentMethod.Fields && selectedPaymentMethod.Fields.map(field => new PaymentMethodDetails(field));
|
239
|
-
fields.forEach(field => {
|
305
|
+
fields.forEach(field => {
|
306
|
+
if (field?.defaultValue) {
|
307
|
+
prepareFields[field.name] = field.defaultValue;
|
308
|
+
}
|
309
|
+
validateField(field);
|
310
|
+
})
|
240
311
|
hideMethodsList();
|
241
312
|
})
|
242
313
|
}
|
@@ -333,12 +404,30 @@
|
|
333
404
|
})
|
334
405
|
}
|
335
406
|
fetch(url, requestParams).then((res) => res.json()).then(data => {
|
407
|
+
if (data.error) {
|
408
|
+
postMessage({type: 'ShowSessionError', error: data.error}, window.location.href)
|
409
|
+
return;
|
410
|
+
}
|
411
|
+
if (data.ResponseCode !== 'Success') {
|
412
|
+
errorResponseCode = data.ResponseCode
|
413
|
+
isProcessingTxn = false;
|
414
|
+
showModal()
|
415
|
+
return;
|
416
|
+
}
|
336
417
|
xPaymentSessionToken = data.XPaymentSessionToken;
|
337
418
|
isProcessingTxn = false;
|
338
419
|
showConfirmModal = true;
|
339
420
|
})
|
340
421
|
}
|
341
422
|
|
423
|
+
const showModal = () => {
|
424
|
+
window.postMessage({ type: 'ShowCashierModal' }, window.location.href)
|
425
|
+
}
|
426
|
+
|
427
|
+
const hideModal = () => {
|
428
|
+
window.postMessage({ type: 'HideCashierModal' }, window.location.href)
|
429
|
+
}
|
430
|
+
|
342
431
|
const backToMethodList = () => {
|
343
432
|
dispatchEvent(new CustomEvent('backToMethodList', {
|
344
433
|
bubbles: true,
|
@@ -387,6 +476,12 @@
|
|
387
476
|
})
|
388
477
|
}
|
389
478
|
fetch(url, requestParams).then((res) => res.json()).then(data => {
|
479
|
+
if (data.ResponseCode !== 'Success') {
|
480
|
+
errorResponseCode = data.ResponseCode;
|
481
|
+
isProcessingTxn = false;
|
482
|
+
showModal();
|
483
|
+
return;
|
484
|
+
}
|
390
485
|
xPaymentSessionToken = data.XPaymentSessionToken;
|
391
486
|
redirectUrl = data.RedirectUrl;
|
392
487
|
redirectMode = data.RedirectionMode;
|
@@ -478,7 +573,7 @@
|
|
478
573
|
}
|
479
574
|
|
480
575
|
const amountIntError = ():string => {
|
481
|
-
if (selectedPaymentMethod.IsIntegerAmount && !Number.isInteger(
|
576
|
+
if (selectedPaymentMethod.IsIntegerAmount && !Number.isInteger(editedAmount)) {
|
482
577
|
return $_('amountIntError')
|
483
578
|
}
|
484
579
|
return ''
|
@@ -492,7 +587,7 @@
|
|
492
587
|
}
|
493
588
|
|
494
589
|
const patternMatchesError = (field, value):string => {
|
495
|
-
if (field.format && !value.toString().match(field.format)) {
|
590
|
+
if (field.format && value && !value.toString().match(field.format)) {
|
496
591
|
return $_('invalidFieldError',{ values: { field: field.label }})
|
497
592
|
}
|
498
593
|
return ''
|
@@ -593,7 +688,14 @@
|
|
593
688
|
placeholder="{field.placeholder}"
|
594
689
|
on:input="{() => { validateField(field) }}"
|
595
690
|
on:blur="{() => { showError[field.name] = true; validateField(field) }}">
|
596
|
-
|
691
|
+
{:else if field.type === FieldTypes.Time || field.type === FieldTypes.Date || field.type === FieldTypes.DateTime}
|
692
|
+
<input type="text" bind:value={ prepareFields[field.name] } pattern={field.format}
|
693
|
+
data-type={field.type}
|
694
|
+
placeholder={field.placeholder}
|
695
|
+
on:input={() => { validateField(field) }}
|
696
|
+
on:blur={() => { showError[field.name] = true; validateField(field) }}
|
697
|
+
bind:this={flatpickrEl[flatpickrEl.length]}
|
698
|
+
>
|
597
699
|
{:else if field.type === FieldTypes.Number || field.type === FieldTypes.Money}
|
598
700
|
<input type="number" placeholder="{field.placeholder}" bind:value={prepareFields[field.name]}
|
599
701
|
on:input="{() => { validateField(field) }}"
|
@@ -696,7 +798,18 @@
|
|
696
798
|
</div>
|
697
799
|
{/if}
|
698
800
|
</div>
|
699
|
-
|
801
|
+
{:else if errorResponseCode}
|
802
|
+
<cashier-error
|
803
|
+
{assetsurl}
|
804
|
+
{translationurl}
|
805
|
+
{clientstylingurl}
|
806
|
+
{clientstyling}
|
807
|
+
hidebuttons="{!mobileView || ''}"
|
808
|
+
errorcode={errorResponseCode}
|
809
|
+
>
|
810
|
+
<div slot="button" class="ModalButton" on:click={backToMethodList}>{$_('backToMethodList')}</div>
|
811
|
+
</cashier-error>
|
812
|
+
{/if}
|
700
813
|
{#if redirectUrl && redirectMode === RedirectionModeStringEnum.Default}
|
701
814
|
<div class="IframeRedirect">
|
702
815
|
<cashier-iframe-redirect
|
@@ -713,6 +826,17 @@
|
|
713
826
|
<div slot="confirm">{$_(`${type.toLowerCase()}.confirmButton`)}</div>
|
714
827
|
</cashier-confirm-modal>
|
715
828
|
{/if}
|
829
|
+
<cashier-modal>
|
830
|
+
<cashier-error
|
831
|
+
{assetsurl}
|
832
|
+
{translationurl}
|
833
|
+
{clientstylingurl}
|
834
|
+
{clientstyling}
|
835
|
+
errorcode={errorResponseCode}
|
836
|
+
>
|
837
|
+
<div slot="button" class="ModalButton" on:click={hideModal}>{$_('closeModal')}</div>
|
838
|
+
</cashier-error>
|
839
|
+
</cashier-modal>
|
716
840
|
</div>
|
717
841
|
|
718
842
|
|
@@ -750,7 +874,6 @@
|
|
750
874
|
input[type=number] {
|
751
875
|
-moz-appearance: textfield;
|
752
876
|
}
|
753
|
-
|
754
877
|
.MethodsDetails {
|
755
878
|
position: relative;
|
756
879
|
display: flex;
|
@@ -915,6 +1038,8 @@
|
|
915
1038
|
line-height: var(--emw--size-small, 14px);
|
916
1039
|
color: var(--emw--color-black, #111);
|
917
1040
|
padding: 0 15px;
|
1041
|
+
font-style: inherit;
|
1042
|
+
font-family: inherit;
|
918
1043
|
&:focus {
|
919
1044
|
outline: none;
|
920
1045
|
}
|
package/src/translations.js
CHANGED
@@ -19,6 +19,8 @@ export const TRANSLATIONS = {
|
|
19
19
|
"amountIntError": "Amount should be integer value",
|
20
20
|
"amountDecimalError": "Amount should have 2 or less digits after decimal point",
|
21
21
|
"invalidFieldError": "{field} is invalid",
|
22
|
+
"closeModal": "CLOSE",
|
23
|
+
"backToMethodList": "BACK TO PAYMENT METHODS",
|
22
24
|
"deposit": {
|
23
25
|
"makeTxnButton": "DEPOSIT",
|
24
26
|
"confirmText": "You\'re going to deposit {amount} {currency} to your account",
|