@tonder.io/ionic-full-sdk 0.0.48-beta.DEV-1610.1 → 0.0.48-beta.DEV-1610.2

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.
@@ -16,7 +16,9 @@ export type CollectorIds = {
16
16
  msgNotification: string,
17
17
  cardsListContainer: string,
18
18
  apmsListContainer?: string,
19
+ msgErrorText?: string,
19
20
  tdsIframe?: string
21
+ msgNotificationText?: string;
20
22
  }
21
23
 
22
24
  export type Card = {
@@ -30,6 +32,7 @@ export type Card = {
30
32
 
31
33
  export const cardTemplate = (data: {
32
34
  renderPaymentButton?: boolean;
35
+ renderSaveCardButton?: boolean;
33
36
  customization?: IInlineCustomizationOptions;
34
37
  collectorIds: CollectorIds;
35
38
  isEnrollmentCard?: boolean;
@@ -66,17 +69,22 @@ export const cardTemplate = (data: {
66
69
  </label>
67
70
  </div>
68
71
  `:``}
69
- <div id="${data.collectorIds.msgError}"></div>
70
- <div id="${data.collectorIds.msgNotification}"></div>
72
+ ${buttonAndMessagesTemplate({
73
+ showButton: !data.isEnrollmentCard ? data.renderPaymentButton || false:data.renderSaveCardButton || false,
74
+ classContainerButton: "container-pay-button",
75
+ tonderButtonId: !data.isEnrollmentCard ? data.collectorIds.tonderPayButton:data.collectorIds.tonderSaveCardButton!,
76
+ classButton: !data.isEnrollmentCard ? "tndr-button pay-button hidden":"tndr-button save-card-button",
77
+ msgErrorId: data.collectorIds.msgError,
78
+ msgErrorTextId: data.collectorIds.msgErrorText!,
79
+ msgNotificationId: data.collectorIds.msgNotification,
80
+ msgNotificationTextId: data.collectorIds.msgNotificationText!,
81
+ buttonText: !data.isEnrollmentCard ? data.customization?.paymentButton?.text!: "Guardar",
82
+ })}
71
83
  </div>
72
84
  ${!data.isEnrollmentCard ? `
73
85
  <div id="apmsListContainer" class="apms-list-container"></div>
74
86
  `:``}
75
- <div class="container-pay-button">
76
- <button id="${data.collectorIds.tonderPayButton}" class="pay-button hidden">${data.customization?.paymentButton?.text}</button>
77
- ${data.isEnrollmentCard ? `
78
- <button id="${data.collectorIds.tonderSaveCardButton ? data.collectorIds.tonderSaveCardButton:''}" class="save-card-button">Guardar</button>
79
- `:``} </div>
87
+
80
88
  <iframe class="tds-iframe" allowtransparency="true" id="${data.collectorIds.tdsIframe}"></iframe>
81
89
  </div>
82
90
 
@@ -137,7 +145,8 @@ export const cardTemplate = (data: {
137
145
  }
138
146
 
139
147
  .container-pay-button{
140
- padding: ${!!data['renderPaymentButton'] ? '30px 30px':''};
148
+ padding-top: ${!!data['renderPaymentButton'] ? '10px':''};
149
+ padding-bottom: ${!!data['renderPaymentButton'] ? '10px':''};
141
150
  }
142
151
 
143
152
  .collect-row {
@@ -165,25 +174,36 @@ export const cardTemplate = (data: {
165
174
  height: 80px !important;
166
175
  }
167
176
  .error-container{
168
- color: red !important;
169
- background-color: #FFDBDB !important;
170
- margin-bottom: 13px !important;
171
- font-size: 80% !important;
172
- padding: 8px 10px !important;
173
- border-radius: 10px !important;
174
- text-align: left !important;
177
+ display: none;
178
+ color: #832828 !important;
179
+ background-color: #FDE7E7 !important;
180
+ margin-bottom: 13px !important;
181
+ font-size: 14px !important;
182
+ padding: 10px 10px !important;
183
+ border-radius: 5px !important;
184
+ text-align: left !important;
185
+ align-items: center;
186
+ gap: 8px;
187
+ margin-top: 5px;
175
188
  }
176
189
 
177
190
  .message-container{
178
- color: #3bc635 !important;
179
- background-color: #DAFCE4 !important;
180
- margin-bottom: 13px !important;
181
- font-size: 80% !important;
182
- padding: 8px 10px !important;
183
- border-radius: 10px !important;
184
- text-align: left !important;
191
+ display: none;
192
+ color: #28832C !important;
193
+ background-color: #ECFDE7 !important;
194
+ margin-bottom: 13px !important;
195
+ font-size: 14px !important;
196
+ padding: 10px 10px !important;
197
+ border-radius: 5px !important;
198
+ text-align: left !important;
199
+ align-items: center;
200
+ gap: 8px;
201
+ margin-top: ${data.renderPaymentButton || data.renderSaveCardButton ? "0px" : "5px"};
202
+ }
203
+ .error-container p,
204
+ .message-container p {
205
+ margin: 0;
185
206
  }
186
-
187
207
  .pay-button {
188
208
  font-size: 16px;
189
209
  font-weight: bold;
@@ -458,7 +478,6 @@ export const cardItemsTemplate = (data: {
458
478
  cards: Card[];
459
479
  collectorIds:CollectorIds;
460
480
  renderPaymentButton: boolean;
461
- acId: string;
462
481
  customStyles: any;
463
482
  customization?: IInlineCustomizationOptions;
464
483
  }) => {
@@ -467,9 +486,9 @@ export const cardItemsTemplate = (data: {
467
486
  const { cvvLabel } = getCardFormLabels(data.customStyles).labels;
468
487
 
469
488
  return `${total}
470
- <div class="ac" id="card_container-${card.skyflow_id}">
489
+ <div class="ac" id="option_container-${card.skyflow_id}">
471
490
  <div class="card-item">
472
- <input id="${card.skyflow_id}" class="card_selected" name="card_selected" type="radio"/>
491
+ <input id="${card.skyflow_id}" class="cards card_selected" name="card_selected" type="radio"/>
473
492
  <label class="card-item-label" for="${card.skyflow_id}">
474
493
  <img class="card-image" src="${getCardType(card.card_scheme)}" />
475
494
  <div class="card-number">${card.card_number}</div>
@@ -484,7 +503,7 @@ export const cardItemsTemplate = (data: {
484
503
  </label>
485
504
  </div>
486
505
  <div class="ac-panel">
487
- <div class="ac-card-panel-container" id="acContainer${card.skyflow_id}">
506
+ <div class="ac-option-panel-container" id="acContainer${card.skyflow_id}">
488
507
 
489
508
  <div class="cvvContainer" id="cvvContainer${card.skyflow_id}">
490
509
  <label class="tndr-form-label label-cvv-cards">${cvvLabel}</label>
@@ -521,12 +540,17 @@ export const cardItemsTemplate = (data: {
521
540
 
522
541
  </div>
523
542
  </div>
524
- ${ data?.renderPaymentButton ?
525
- `<div class="container-card-pay-button">
526
- <button id="${data.collectorIds.tonderPayButton ? data.collectorIds.tonderPayButton:''}${card.skyflow_id}" class="card-pay-button pay-button">${data.customization?.paymentButton?.text}</button>
527
- </div> `
528
- :``
529
- }
543
+ ${buttonAndMessagesTemplate({
544
+ showButton: data.renderPaymentButton || false,
545
+ classContainerButton: "container-pay-button",
546
+ tonderButtonId: `${data.collectorIds.tonderPayButton}${card.skyflow_id}`,
547
+ classButton: "tndr-button card-pay-button pay-button",
548
+ msgErrorId: `${data.collectorIds.msgError}${card.skyflow_id}`,
549
+ msgErrorTextId: `${data.collectorIds.msgErrorText}${card.skyflow_id}`,
550
+ msgNotificationId: `${data.collectorIds.msgNotification}${card.skyflow_id}`,
551
+ msgNotificationTextId: `${data.collectorIds.msgNotificationText}${card.skyflow_id}`,
552
+ buttonText: data.customization?.paymentButton?.text!
553
+ })}
530
554
  </div>
531
555
  </div>
532
556
  </div>`
@@ -542,7 +566,7 @@ export const cardItemsTemplate = (data: {
542
566
  margin-bottom: 0;
543
567
  border-bottom: 1px solid #e2e8f0;
544
568
  }
545
- .ac-card-panel-container{
569
+ .ac-option-panel-container{
546
570
  padding: ${data?.renderPaymentButton ? '20px 32px 0px 32px':'20px 32px 20px 32px'};
547
571
  }
548
572
  .cvvContainer{
@@ -566,7 +590,7 @@ export const cardItemsTemplate = (data: {
566
590
  transition-delay: 0.3s;
567
591
  }
568
592
  .cvvContainer.show .cvvIcon,
569
- .ac-card-panel-container.show .card-pay-button {
593
+ .ac-option-panel-container.show .card-pay-button {
570
594
  opacity: 1;
571
595
  transform: translateY(0);
572
596
  transition-delay: 0.3s;
@@ -787,7 +811,7 @@ export const cardItemsTemplate = (data: {
787
811
  </style>
788
812
  `
789
813
  const cardItem = `
790
- <div class="accordion-container${data.acId}">
814
+ <div class="accordion-container">
791
815
  ${cardItemsHTML}
792
816
  </div>
793
817
  ${cardItemStyle}
@@ -795,21 +819,39 @@ export const cardItemsTemplate = (data: {
795
819
  return cardItem;
796
820
  }
797
821
 
798
- export const apmItemsTemplate = (external: boolean, apms: ITonderPaymentMethod[]) => {
799
- const apmItemsHTML = apms.reduce((total, apm) => {
822
+ export const apmItemsTemplate = (data:{apms: ITonderPaymentMethod[]; collectorIds:CollectorIds; renderPaymentButton?: boolean; customization?: IInlineCustomizationOptions;} ) => {
823
+ const apmItemsHTML = data.apms.reduce((total, apm) => {
800
824
  const apm_data = getPaymentMethodDetails(apm.payment_method);
801
825
  return `
802
826
  ${total}
803
- <div class="apm-item" id="card_container-${apm.pk}">
804
- <input id="${apm.pk}" class="card_selected" name="card_selected" type="radio"/>
805
- <label class="apm-item-label" for="${apm.pk}">
806
- <div class="apm-image">
807
- <div class="apm-image-border"></div>
808
- <img src="${apm_data.icon}" />
809
- </div>
810
- <div class="apm-name">${apm_data.label}</div>
811
- </label>
812
- </div>`
827
+ <div class="ac ac-paymentMethods" id="option_container-${apm.pk}">
828
+ <div class="apm-item">
829
+ <input id="${apm.pk}" class="paymentMethods card_selected" name="card_selected" type="radio"/>
830
+ <label class="apm-item-label" for="${apm.pk}">
831
+ <div class="apm-image">
832
+ <div class="apm-image-border"></div>
833
+ <img src="${apm_data.icon}" />
834
+ </div>
835
+ <div class="apm-name">${apm_data.label}</div>
836
+ </label>
837
+ </div>
838
+ <div class="ac-panel">
839
+ <div class="ac-option-panel-container tndr-pm-item-container" id="acContainer${apm.pk}">
840
+ ${buttonAndMessagesTemplate({
841
+ showButton: data.renderPaymentButton || false,
842
+ classContainerButton: "container-pay-button",
843
+ tonderButtonId: `${data.collectorIds.tonderPayButton}${apm.pk}`,
844
+ classButton: "tndr-button card-pay-button pay-button",
845
+ msgErrorId: `${data.collectorIds.msgError}${apm.pk}`,
846
+ msgErrorTextId: `${data.collectorIds.msgErrorText}${apm.pk}`,
847
+ msgNotificationId: `${data.collectorIds.msgNotification}${apm.pk}`,
848
+ msgNotificationTextId: `${data.collectorIds.msgNotificationText}${apm.pk}`,
849
+ buttonText: data.customization?.paymentButton?.text!
850
+ })}
851
+ </div>
852
+ </div>
853
+ </div>
854
+ `
813
855
  }, ``);
814
856
 
815
857
  const apmItemStyle = `
@@ -824,14 +866,15 @@ export const apmItemsTemplate = (external: boolean, apms: ITonderPaymentMethod[]
824
866
  margin-bottom: 15px;
825
867
  width: 100%;
826
868
  }
827
-
869
+ .ac-option-panel-container.tndr-pm-item-container{
870
+ padding-top: 0;
871
+ }
828
872
  .apm-item {
829
873
  position: relative;
830
874
  display: flex;
831
875
  justify-content: start;
832
876
  align-items: center;
833
877
  gap: 33% 15px;
834
- border-bottom: 1px solid #e2e8f0;
835
878
  padding: 0px 30px;
836
879
  }
837
880
 
@@ -949,8 +992,46 @@ export const apmItemsTemplate = (external: boolean, apms: ITonderPaymentMethod[]
949
992
  </style>
950
993
  `
951
994
  const apmItem = `
952
- ${apmItemsHTML}
995
+ <div class="accordion-container-apm">
996
+ ${apmItemsHTML}
997
+ </div>
953
998
  ${apmItemStyle}
954
999
  `
955
1000
  return apmItem;
956
- }
1001
+ }
1002
+
1003
+ const buttonAndMessagesTemplate = (data: {
1004
+ showButton: boolean;
1005
+ classContainerButton: string;
1006
+ tonderButtonId: string;
1007
+ classButton: string;
1008
+ msgErrorId: string;
1009
+ msgNotificationId: string;
1010
+ msgNotificationTextId: string;
1011
+ msgErrorTextId: string;
1012
+ buttonText: string;
1013
+ }) => {
1014
+ return `
1015
+ ${
1016
+ data.showButton
1017
+ ? `
1018
+ <div class="${data.classContainerButton}">
1019
+ <button id="${data.tonderButtonId}" class="${data.classButton}">${data.buttonText}</button>
1020
+ </div>
1021
+ `
1022
+ : ``
1023
+ }
1024
+ <div id="${data.msgErrorId}" class="error-container">
1025
+ <svg xmlns="http://www.w3.org/2000/svg" width="18" height="17" viewBox="0 0 28.25 27.828">
1026
+ <path id="Cancel_Icon" data-name="Cancel Icon" d="M89.04-859.129l5.085-5.009,5.085,5.009,1.978-1.948L96.1-866.086l5.085-5.009-1.978-1.948-5.085,5.009-5.085-5.009L87.063-871.1l5.085,5.009-5.085,5.009Zm5.085,6.957a13.935,13.935,0,0,1-5.509-1.1,14.276,14.276,0,0,1-4.485-2.974,14.04,14.04,0,0,1-3.019-4.418A13.375,13.375,0,0,1,80-866.086a13.374,13.374,0,0,1,1.112-5.426,14.041,14.041,0,0,1,3.019-4.418,14.277,14.277,0,0,1,4.485-2.974,13.932,13.932,0,0,1,5.509-1.1,13.933,13.933,0,0,1,5.509,1.1,14.278,14.278,0,0,1,4.485,2.974,14.041,14.041,0,0,1,3.019,4.418,13.374,13.374,0,0,1,1.112,5.426,13.375,13.375,0,0,1-1.112,5.426,14.04,14.04,0,0,1-3.019,4.418,14.276,14.276,0,0,1-4.485,2.974A13.935,13.935,0,0,1,94.125-852.172Z" transform="translate(-80 880)" fill="#832828"/>
1027
+ </svg>
1028
+ <p id="${data.msgErrorTextId}"></p>
1029
+ </div>
1030
+ <div id="${data.msgNotificationId}" class="message-container">
1031
+ <svg xmlns="http://www.w3.org/2000/svg" width="18" height="17" viewBox="0 0 28.25 27.828">
1032
+ <path id="Check_Circle_Icon" data-name="Check Circle Icon" d="M92.147-859.686l9.958-9.809-1.977-1.948-7.981,7.861-4.026-3.965L86.144-865.6Zm1.978,7.513a13.935,13.935,0,0,1-5.509-1.1,14.278,14.278,0,0,1-4.485-2.974,14.041,14.041,0,0,1-3.019-4.418A13.374,13.374,0,0,1,80-866.086a13.374,13.374,0,0,1,1.112-5.426,14.041,14.041,0,0,1,3.019-4.418,14.278,14.278,0,0,1,4.485-2.974,13.935,13.935,0,0,1,5.509-1.1,13.935,13.935,0,0,1,5.509,1.1,14.278,14.278,0,0,1,4.485,2.974,14.041,14.041,0,0,1,3.019,4.418,13.374,13.374,0,0,1,1.112,5.426,13.374,13.374,0,0,1-1.112,5.426,14.041,14.041,0,0,1-3.019,4.418,14.278,14.278,0,0,1-4.485,2.974A13.935,13.935,0,0,1,94.125-852.172Z" transform="translate(-80 880)" fill="#28832c"/>
1033
+ </svg>
1034
+ <p id="${data.msgNotificationTextId}"></p>
1035
+ </div>
1036
+ `;
1037
+ };
@@ -46,31 +46,55 @@ export function toCurrency(value: string | number) {
46
46
  return typeof value === "number" && formatter.format(value);
47
47
  }
48
48
 
49
- export function showError(message: string, containerId: string, payButtonId: string) {
50
- const msgErrorDiv: any = document.getElementById(`${containerId}`);
51
- if(msgErrorDiv) {
52
- msgErrorDiv.classList.add("error-container");
53
- msgErrorDiv.innerHTML = message;
49
+ export function showError(
50
+ message: string,
51
+ selectedId:string | null=null,
52
+ containerId: string = "msgError",
53
+ containerTextId: string = "msgErrorText",
54
+ ) {
55
+ try{
56
+ const existSelectedId = selectedId && selectedId !== "new";
57
+ let msgErrorDiv = document.getElementById(`${containerId}${existSelectedId ? selectedId : ""}`);
58
+ let msgErrorText = document.getElementById(
59
+ `${containerTextId}${existSelectedId ? selectedId : ""}`,
60
+ );
61
+ msgErrorText!.innerHTML = "";
62
+ msgErrorText!.innerHTML = message;
63
+ msgErrorDiv!.style.display = "flex";
64
+ console.log("msgErrorDiv", msgErrorDiv)
54
65
  setTimeout(function () {
55
- try {
56
- const selector: any = document.querySelector(`#${payButtonId}`)
57
- selector.disabled = false;
58
- } catch (error) {}
59
- msgErrorDiv.classList.remove("error-container");
60
- msgErrorDiv.innerHTML = "";
61
- }, 3000);
66
+ msgErrorDiv!.style.display = "none";
67
+ msgErrorText!.innerHTML = "";
68
+ }, 30000);
69
+ }catch (error) {
70
+ console.warn("Error showing message error", error);
62
71
  }
72
+
63
73
  }
64
74
 
65
- export function showMessage(message: string, containerId: string) {
66
- const msgDiv: any = document.getElementById(`${containerId}`);
67
- if(msgDiv) {
68
- msgDiv.classList.add("message-container");
69
- msgDiv.innerHTML = message;
70
- setTimeout(function () {
71
- msgDiv.classList.remove("message-container");
72
- msgDiv.innerHTML = "";
73
- }, 3000);
75
+ export function showMessage(
76
+ message: string,
77
+ selectedId: string | null = null,
78
+ containerId = "msgNotification",
79
+ containerTextId = "msgNotificationText",
80
+ ) {
81
+ try {
82
+ const existSelectedId = selectedId && selectedId !== "new";
83
+ const msgDiv = document.getElementById(`${containerId}${existSelectedId ? selectedId : ""}`);
84
+ if (msgDiv) {
85
+ let msgText = document.getElementById(
86
+ `${containerTextId}${existSelectedId ? selectedId : ""}`,
87
+ );
88
+ msgDiv.style.display = "flex";
89
+ msgText!.innerHTML = "";
90
+ msgText!.innerHTML = message;
91
+ setTimeout(function () {
92
+ msgDiv.style.display = "none";
93
+ msgText!.innerHTML = "";
94
+ }, 30000);
95
+ }
96
+ } catch (error) {
97
+ console.error("Error showing message", error);
74
98
  }
75
99
  }
76
100
 
@@ -213,6 +237,14 @@ export const getPaymentMethodDetails = (scheme_data: string): {icon: string; lab
213
237
  label: "Círculo K",
214
238
  icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/circulo_k.png",
215
239
  },
240
+ [PAYMENT_METHOD.MERCADOPAGO]: {
241
+ label: "Mercado Pago",
242
+ icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/mercadopago.png",
243
+ },
244
+ [PAYMENT_METHOD.OXXOPAY]: {
245
+ label: "Oxxo Pay",
246
+ icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/oxxopay.png",
247
+ },
216
248
  [PAYMENT_METHOD.SEVEN11]: {
217
249
  label: "7 Eleven",
218
250
  icon: "https://d35a75syrgujp0.cloudfront.net/payment_methods/7_eleven.png",
package/src/index.ts CHANGED
@@ -1,7 +1,5 @@
1
- import { Checkout } from './classes/checkout'
2
1
  import { InlineCheckout } from './classes/inlineCheckout'
3
2
 
4
3
  export {
5
- Checkout,
6
4
  InlineCheckout
7
5
  }
@@ -0,0 +1 @@
1
+ type AccordionType = "cards" | "paymentMethods";
@@ -1,31 +0,0 @@
1
- import { CheckoutType } from "../types/commons";
2
- export declare class Checkout {
3
- url: string;
4
- apiKey?: string;
5
- type: string;
6
- backgroundColor: string;
7
- color: string;
8
- params: string;
9
- order: any;
10
- buttonText: string;
11
- cb: (params: any) => void;
12
- tonderButton: any;
13
- constructor({ apiKey, type, backgroundColor, color, cb, url }: CheckoutType);
14
- generateButton: (buttonText: string) => void;
15
- getButton: ({ buttonText }: {
16
- buttonText: string;
17
- }) => any;
18
- mountButton: ({ buttonText }: {
19
- buttonText: string;
20
- }) => void;
21
- stylishButton: (element: HTMLElement) => void;
22
- setOrder: ({ products, email, shippingCost }: {
23
- products: any;
24
- email: string;
25
- shippingCost: string;
26
- }) => any;
27
- openTabListener: (tab: any, button: HTMLButtonElement) => void;
28
- openCheckout: () => void;
29
- getUrlParams: () => string;
30
- receiveMessage(event: any): void;
31
- }
@@ -1,139 +0,0 @@
1
- import { AES } from "crypto-js";
2
- import {CheckoutType} from "../types/commons";
3
-
4
- export class Checkout {
5
- url: string;
6
- apiKey?: string;
7
- type: string;
8
- backgroundColor: string;
9
- color: string;
10
- params: string;
11
- order: any;
12
- buttonText: string;
13
- cb: (params: any) => void;
14
- tonderButton: any;
15
-
16
- constructor({
17
- apiKey,
18
- type = "payment",
19
- backgroundColor="#141414",
20
- color="#EBEBEB",
21
- cb=()=>{},
22
- url="http://checkout.tonder.io/#/"
23
- }: CheckoutType) {
24
- this.url = url
25
- this.apiKey = apiKey
26
- this.type = type
27
- this.backgroundColor = backgroundColor
28
- this.color = color
29
- this.params = ""
30
- this.order = {}
31
- this.buttonText = "Proceder al pago"
32
- this.cb = cb
33
-
34
- window.addEventListener("message", this.receiveMessage.bind(this), false);
35
- }
36
- generateButton = (buttonText: string) => {
37
- this.buttonText = buttonText ? buttonText : this.buttonText
38
- this.tonderButton = document.createElement('button');
39
- this.tonderButton.innerHTML = this.buttonText;
40
- this.stylishButton(this.tonderButton)
41
- this.tonderButton.onclick = this.openCheckout
42
- }
43
- getButton = ({ buttonText }: { buttonText: string }) => {
44
- this.generateButton(buttonText)
45
- return this.tonderButton
46
- }
47
- mountButton = ({ buttonText }: { buttonText: string }) => {
48
- this.generateButton(buttonText)
49
- const entryPoint: HTMLElement | null = document.getElementById("tonder-checkout")
50
- try {
51
- if(entryPoint) {
52
- entryPoint.innerHTML = ""
53
- entryPoint.append(this.tonderButton)
54
- }
55
- } catch(error) {
56
- console.error(error)
57
- }
58
- }
59
- stylishButton = (element: HTMLElement) => {
60
- element.style.backgroundColor = this.backgroundColor
61
- element.style.color = this.color
62
- element.style.display = 'flex'
63
- element.style.justifyContent = 'center'
64
- element.style.border = 'none'
65
- element.style.padding = '1rem'
66
- element.style.borderRadius = '10px'
67
- element.style.fontSize = '1rem'
68
- element.style.width = '100%'
69
- element.style.boxShadow = '0 3px 6px 0 rgba(0,0,0,0.16)'
70
- }
71
- setOrder = ({ products, email, shippingCost }: { products: any, email: string, shippingCost: string }) => {
72
- let _order: any = {}
73
- if (products) _order.products = products
74
- if (email) _order.email = email
75
- if (shippingCost) _order.shippingCost = shippingCost
76
- this.order = {...this.order, ..._order}
77
- return this.order
78
- }
79
- openTabListener = (tab: any, button: HTMLButtonElement) => {
80
- const tabInterval = setInterval(() => {
81
- if (tab.closed) {
82
- clearInterval(tabInterval);
83
- button.disabled = false
84
- button.innerHTML = this.buttonText
85
- }
86
- }, 500)
87
- }
88
- openCheckout = () => {
89
- const queryString = this.getUrlParams()
90
- const encrypted = AES.encrypt(queryString, 'url-params-encrypt').toString()
91
- const encodedURL = encodeURIComponent(encrypted);
92
- this.params = "?" + encodedURL;
93
- const newWindow = window.open(this.url + this.params, '_blank', `width=1200,height=$800,left=0,top=0`);
94
- this.tonderButton.disabled = true
95
- this.tonderButton.innerHTML = `
96
- <div class="loader"></div>
97
- <style>
98
- .loader {
99
- border: 4px solid ${this.color};
100
- border-radius: 50%;
101
- border-top: 4px solid ${this.backgroundColor};
102
- width: 0.625rem;
103
- height: 0.625rem;
104
- -webkit-animation: spin 2s linear infinite; /* Safari */
105
- animation: spin 2s linear infinite;
106
- }
107
-
108
- /* Safari */
109
- @-webkit-keyframes spin {
110
- 0% { -webkit-transform: rotate(0deg); }
111
- 100% { -webkit-transform: rotate(360deg); }
112
- }
113
-
114
- @keyframes spin {
115
- 0% { transform: rotate(0deg); }
116
- 100% { transform: rotate(360deg); }
117
- }
118
- </style>
119
- `
120
- this.openTabListener(newWindow, this.tonderButton)
121
- }
122
- getUrlParams = () => {
123
- const params = { apiKey: this.apiKey, ...this.order, type: this.type}
124
- if (params.products) {
125
- params.products = JSON.stringify(params.products)
126
- }
127
- const queryString = new URLSearchParams(params).toString();
128
- return queryString
129
- }
130
- receiveMessage(event: any) {
131
- // Parse data if it is possible, in case of error it will return the raw data.
132
- try {
133
- const data = JSON.parse(event.data)
134
- this.cb(data)
135
- } catch(error) {
136
- this.cb(event.data)
137
- }
138
- }
139
- }