@tonder.io/ionic-full-sdk 0.0.30-beta → 0.0.32-beta
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/.gitlab-ci.yml +18 -18
- package/README.md +448 -448
- package/cypress.config.js +9 -9
- package/dist/classes/inlineCheckout.d.ts +6 -1
- package/dist/helpers/template.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/types/commons.d.ts +0 -1
- package/index.js.example +49 -49
- package/package.json +27 -27
- package/rollup.config.js +14 -14
- package/src/classes/3dsHandler.ts +237 -237
- package/src/classes/checkout.ts +147 -147
- package/src/classes/inlineCheckout.ts +734 -622
- package/src/helpers/skyflow.ts +358 -358
- package/src/helpers/styles.ts +60 -60
- package/src/helpers/template.ts +520 -492
- package/src/helpers/utils.ts +148 -148
- package/src/index-dev.js +120 -120
- package/src/index.html +57 -57
- package/src/index.ts +6 -6
- package/src/types/commons.ts +42 -43
- package/src/types/skyflow.ts +40 -40
- package/tsconfig.json +22 -22
- package/dist/data/api.d.ts +0 -18
- package/dist/types/commons-ds.d.ts +0 -40
- package/dist/types/skyflow.ds.d.ts +0 -39
package/src/classes/checkout.ts
CHANGED
|
@@ -1,148 +1,148 @@
|
|
|
1
|
-
import { AES } from "crypto-js";
|
|
2
|
-
|
|
3
|
-
type CheckoutType = {
|
|
4
|
-
apiKey?: string,
|
|
5
|
-
type: string,
|
|
6
|
-
backgroundColor: string,
|
|
7
|
-
color: string,
|
|
8
|
-
cb: (params?: any)=> void,
|
|
9
|
-
url: string,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class Checkout {
|
|
13
|
-
|
|
14
|
-
url: string
|
|
15
|
-
apiKey?: string
|
|
16
|
-
type: string
|
|
17
|
-
backgroundColor: string
|
|
18
|
-
color: string
|
|
19
|
-
params: string
|
|
20
|
-
order: any
|
|
21
|
-
buttonText: string
|
|
22
|
-
cb: (params: any) => void
|
|
23
|
-
tonderButton: any
|
|
24
|
-
|
|
25
|
-
constructor({
|
|
26
|
-
apiKey,
|
|
27
|
-
type = "payment",
|
|
28
|
-
backgroundColor="#141414",
|
|
29
|
-
color="#EBEBEB",
|
|
30
|
-
cb=()=>{},
|
|
31
|
-
url="http://checkout.tonder.io/#/"
|
|
32
|
-
}: CheckoutType) {
|
|
33
|
-
this.url = url
|
|
34
|
-
this.apiKey = apiKey
|
|
35
|
-
this.type = type
|
|
36
|
-
this.backgroundColor = backgroundColor
|
|
37
|
-
this.color = color
|
|
38
|
-
this.params = ""
|
|
39
|
-
this.order = {}
|
|
40
|
-
this.buttonText = "Proceder al pago"
|
|
41
|
-
this.cb = cb
|
|
42
|
-
|
|
43
|
-
window.addEventListener("message", this.receiveMessage.bind(this), false);
|
|
44
|
-
}
|
|
45
|
-
generateButton = (buttonText: string) => {
|
|
46
|
-
this.buttonText = buttonText ? buttonText : this.buttonText
|
|
47
|
-
this.tonderButton = document.createElement('button');
|
|
48
|
-
this.tonderButton.innerHTML = this.buttonText;
|
|
49
|
-
this.stylishButton(this.tonderButton)
|
|
50
|
-
this.tonderButton.onclick = this.openCheckout
|
|
51
|
-
}
|
|
52
|
-
getButton = ({ buttonText }: { buttonText: string }) => {
|
|
53
|
-
this.generateButton(buttonText)
|
|
54
|
-
return this.tonderButton
|
|
55
|
-
}
|
|
56
|
-
mountButton = ({ buttonText }: { buttonText: string }) => {
|
|
57
|
-
this.generateButton(buttonText)
|
|
58
|
-
const entryPoint: HTMLElement | null = document.getElementById("tonder-checkout")
|
|
59
|
-
try {
|
|
60
|
-
if(entryPoint) {
|
|
61
|
-
entryPoint.innerHTML = ""
|
|
62
|
-
entryPoint.append(this.tonderButton)
|
|
63
|
-
}
|
|
64
|
-
} catch(error) {
|
|
65
|
-
console.error(error)
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
stylishButton = (element: HTMLElement) => {
|
|
69
|
-
element.style.backgroundColor = this.backgroundColor
|
|
70
|
-
element.style.color = this.color
|
|
71
|
-
element.style.display = 'flex'
|
|
72
|
-
element.style.justifyContent = 'center'
|
|
73
|
-
element.style.border = 'none'
|
|
74
|
-
element.style.padding = '1rem'
|
|
75
|
-
element.style.borderRadius = '10px'
|
|
76
|
-
element.style.fontSize = '1rem'
|
|
77
|
-
element.style.width = '100%'
|
|
78
|
-
element.style.boxShadow = '0 3px 6px 0 rgba(0,0,0,0.16)'
|
|
79
|
-
}
|
|
80
|
-
setOrder = ({ products, email, shippingCost }: { products: any, email: string, shippingCost: string }) => {
|
|
81
|
-
let _order: any = {}
|
|
82
|
-
if (products) _order.products = products
|
|
83
|
-
if (email) _order.email = email
|
|
84
|
-
if (shippingCost) _order.shippingCost = shippingCost
|
|
85
|
-
this.order = {...this.order, ..._order}
|
|
86
|
-
return this.order
|
|
87
|
-
}
|
|
88
|
-
openTabListener = (tab: any, button: HTMLButtonElement) => {
|
|
89
|
-
const tabInterval = setInterval(() => {
|
|
90
|
-
if (tab.closed) {
|
|
91
|
-
clearInterval(tabInterval);
|
|
92
|
-
button.disabled = false
|
|
93
|
-
button.innerHTML = this.buttonText
|
|
94
|
-
}
|
|
95
|
-
}, 500)
|
|
96
|
-
}
|
|
97
|
-
openCheckout = () => {
|
|
98
|
-
const queryString = this.getUrlParams()
|
|
99
|
-
const encrypted = AES.encrypt(queryString, 'url-params-encrypt').toString()
|
|
100
|
-
const encodedURL = encodeURIComponent(encrypted);
|
|
101
|
-
this.params = "?" + encodedURL;
|
|
102
|
-
const newWindow = window.open(this.url + this.params, '_blank', `width=1200,height=$800,left=0,top=0`);
|
|
103
|
-
this.tonderButton.disabled = true
|
|
104
|
-
this.tonderButton.innerHTML = `
|
|
105
|
-
<div class="loader"></div>
|
|
106
|
-
<style>
|
|
107
|
-
.loader {
|
|
108
|
-
border: 4px solid ${this.color};
|
|
109
|
-
border-radius: 50%;
|
|
110
|
-
border-top: 4px solid ${this.backgroundColor};
|
|
111
|
-
width: 0.625rem;
|
|
112
|
-
height: 0.625rem;
|
|
113
|
-
-webkit-animation: spin 2s linear infinite; /* Safari */
|
|
114
|
-
animation: spin 2s linear infinite;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/* Safari */
|
|
118
|
-
@-webkit-keyframes spin {
|
|
119
|
-
0% { -webkit-transform: rotate(0deg); }
|
|
120
|
-
100% { -webkit-transform: rotate(360deg); }
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
@keyframes spin {
|
|
124
|
-
0% { transform: rotate(0deg); }
|
|
125
|
-
100% { transform: rotate(360deg); }
|
|
126
|
-
}
|
|
127
|
-
</style>
|
|
128
|
-
`
|
|
129
|
-
this.openTabListener(newWindow, this.tonderButton)
|
|
130
|
-
}
|
|
131
|
-
getUrlParams = () => {
|
|
132
|
-
const params = { apiKey: this.apiKey, ...this.order, type: this.type}
|
|
133
|
-
if (params.products) {
|
|
134
|
-
params.products = JSON.stringify(params.products)
|
|
135
|
-
}
|
|
136
|
-
const queryString = new URLSearchParams(params).toString();
|
|
137
|
-
return queryString
|
|
138
|
-
}
|
|
139
|
-
receiveMessage(event: any) {
|
|
140
|
-
// Parse data if it is possible, in case of error it will return the raw data.
|
|
141
|
-
try {
|
|
142
|
-
const data = JSON.parse(event.data)
|
|
143
|
-
this.cb(data)
|
|
144
|
-
} catch(error) {
|
|
145
|
-
this.cb(event.data)
|
|
146
|
-
}
|
|
147
|
-
}
|
|
1
|
+
import { AES } from "crypto-js";
|
|
2
|
+
|
|
3
|
+
type CheckoutType = {
|
|
4
|
+
apiKey?: string,
|
|
5
|
+
type: string,
|
|
6
|
+
backgroundColor: string,
|
|
7
|
+
color: string,
|
|
8
|
+
cb: (params?: any)=> void,
|
|
9
|
+
url: string,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class Checkout {
|
|
13
|
+
|
|
14
|
+
url: string
|
|
15
|
+
apiKey?: string
|
|
16
|
+
type: string
|
|
17
|
+
backgroundColor: string
|
|
18
|
+
color: string
|
|
19
|
+
params: string
|
|
20
|
+
order: any
|
|
21
|
+
buttonText: string
|
|
22
|
+
cb: (params: any) => void
|
|
23
|
+
tonderButton: any
|
|
24
|
+
|
|
25
|
+
constructor({
|
|
26
|
+
apiKey,
|
|
27
|
+
type = "payment",
|
|
28
|
+
backgroundColor="#141414",
|
|
29
|
+
color="#EBEBEB",
|
|
30
|
+
cb=()=>{},
|
|
31
|
+
url="http://checkout.tonder.io/#/"
|
|
32
|
+
}: CheckoutType) {
|
|
33
|
+
this.url = url
|
|
34
|
+
this.apiKey = apiKey
|
|
35
|
+
this.type = type
|
|
36
|
+
this.backgroundColor = backgroundColor
|
|
37
|
+
this.color = color
|
|
38
|
+
this.params = ""
|
|
39
|
+
this.order = {}
|
|
40
|
+
this.buttonText = "Proceder al pago"
|
|
41
|
+
this.cb = cb
|
|
42
|
+
|
|
43
|
+
window.addEventListener("message", this.receiveMessage.bind(this), false);
|
|
44
|
+
}
|
|
45
|
+
generateButton = (buttonText: string) => {
|
|
46
|
+
this.buttonText = buttonText ? buttonText : this.buttonText
|
|
47
|
+
this.tonderButton = document.createElement('button');
|
|
48
|
+
this.tonderButton.innerHTML = this.buttonText;
|
|
49
|
+
this.stylishButton(this.tonderButton)
|
|
50
|
+
this.tonderButton.onclick = this.openCheckout
|
|
51
|
+
}
|
|
52
|
+
getButton = ({ buttonText }: { buttonText: string }) => {
|
|
53
|
+
this.generateButton(buttonText)
|
|
54
|
+
return this.tonderButton
|
|
55
|
+
}
|
|
56
|
+
mountButton = ({ buttonText }: { buttonText: string }) => {
|
|
57
|
+
this.generateButton(buttonText)
|
|
58
|
+
const entryPoint: HTMLElement | null = document.getElementById("tonder-checkout")
|
|
59
|
+
try {
|
|
60
|
+
if(entryPoint) {
|
|
61
|
+
entryPoint.innerHTML = ""
|
|
62
|
+
entryPoint.append(this.tonderButton)
|
|
63
|
+
}
|
|
64
|
+
} catch(error) {
|
|
65
|
+
console.error(error)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
stylishButton = (element: HTMLElement) => {
|
|
69
|
+
element.style.backgroundColor = this.backgroundColor
|
|
70
|
+
element.style.color = this.color
|
|
71
|
+
element.style.display = 'flex'
|
|
72
|
+
element.style.justifyContent = 'center'
|
|
73
|
+
element.style.border = 'none'
|
|
74
|
+
element.style.padding = '1rem'
|
|
75
|
+
element.style.borderRadius = '10px'
|
|
76
|
+
element.style.fontSize = '1rem'
|
|
77
|
+
element.style.width = '100%'
|
|
78
|
+
element.style.boxShadow = '0 3px 6px 0 rgba(0,0,0,0.16)'
|
|
79
|
+
}
|
|
80
|
+
setOrder = ({ products, email, shippingCost }: { products: any, email: string, shippingCost: string }) => {
|
|
81
|
+
let _order: any = {}
|
|
82
|
+
if (products) _order.products = products
|
|
83
|
+
if (email) _order.email = email
|
|
84
|
+
if (shippingCost) _order.shippingCost = shippingCost
|
|
85
|
+
this.order = {...this.order, ..._order}
|
|
86
|
+
return this.order
|
|
87
|
+
}
|
|
88
|
+
openTabListener = (tab: any, button: HTMLButtonElement) => {
|
|
89
|
+
const tabInterval = setInterval(() => {
|
|
90
|
+
if (tab.closed) {
|
|
91
|
+
clearInterval(tabInterval);
|
|
92
|
+
button.disabled = false
|
|
93
|
+
button.innerHTML = this.buttonText
|
|
94
|
+
}
|
|
95
|
+
}, 500)
|
|
96
|
+
}
|
|
97
|
+
openCheckout = () => {
|
|
98
|
+
const queryString = this.getUrlParams()
|
|
99
|
+
const encrypted = AES.encrypt(queryString, 'url-params-encrypt').toString()
|
|
100
|
+
const encodedURL = encodeURIComponent(encrypted);
|
|
101
|
+
this.params = "?" + encodedURL;
|
|
102
|
+
const newWindow = window.open(this.url + this.params, '_blank', `width=1200,height=$800,left=0,top=0`);
|
|
103
|
+
this.tonderButton.disabled = true
|
|
104
|
+
this.tonderButton.innerHTML = `
|
|
105
|
+
<div class="loader"></div>
|
|
106
|
+
<style>
|
|
107
|
+
.loader {
|
|
108
|
+
border: 4px solid ${this.color};
|
|
109
|
+
border-radius: 50%;
|
|
110
|
+
border-top: 4px solid ${this.backgroundColor};
|
|
111
|
+
width: 0.625rem;
|
|
112
|
+
height: 0.625rem;
|
|
113
|
+
-webkit-animation: spin 2s linear infinite; /* Safari */
|
|
114
|
+
animation: spin 2s linear infinite;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/* Safari */
|
|
118
|
+
@-webkit-keyframes spin {
|
|
119
|
+
0% { -webkit-transform: rotate(0deg); }
|
|
120
|
+
100% { -webkit-transform: rotate(360deg); }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@keyframes spin {
|
|
124
|
+
0% { transform: rotate(0deg); }
|
|
125
|
+
100% { transform: rotate(360deg); }
|
|
126
|
+
}
|
|
127
|
+
</style>
|
|
128
|
+
`
|
|
129
|
+
this.openTabListener(newWindow, this.tonderButton)
|
|
130
|
+
}
|
|
131
|
+
getUrlParams = () => {
|
|
132
|
+
const params = { apiKey: this.apiKey, ...this.order, type: this.type}
|
|
133
|
+
if (params.products) {
|
|
134
|
+
params.products = JSON.stringify(params.products)
|
|
135
|
+
}
|
|
136
|
+
const queryString = new URLSearchParams(params).toString();
|
|
137
|
+
return queryString
|
|
138
|
+
}
|
|
139
|
+
receiveMessage(event: any) {
|
|
140
|
+
// Parse data if it is possible, in case of error it will return the raw data.
|
|
141
|
+
try {
|
|
142
|
+
const data = JSON.parse(event.data)
|
|
143
|
+
this.cb(data)
|
|
144
|
+
} catch(error) {
|
|
145
|
+
this.cb(event.data)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
148
|
}
|