@tonder.io/ionic-full-sdk 0.0.9 → 0.0.11-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.
@@ -1,172 +1,172 @@
1
- import CollectElement from "skyflow-js/types/core/external/collect/collect-element";
2
- import { defaultStyles } from "./styles";
3
- import Skyflow from 'skyflow-js'
4
- import { CollectorIds } from "./template";
5
- import CollectorContainer from "skyflow-js/types/core/external/collect/collect-container"
6
- import ComposableContainer from "skyflow-js/types/core/external/collect/compose-collect-container"
7
- import RevealContainer from "skyflow-js/types/core/external/reveal/reveal-container"
8
- import RevealElement from "skyflow-js/types/core/external/reveal/reveal-element";
9
- import ComposableElement from "skyflow-js/types/core/external/collect/compose-collect-element";
10
-
11
- export type InCollectorContainer = {
12
- container: CollectorContainer | ComposableContainer | RevealContainer,
13
- elements: { [ index: string ]: CollectElement | ComposableElement | RevealElement }
14
- }
15
-
16
- export async function initSkyflow(
17
- vaultId: string,
18
- vaultUrl: string,
19
- baseUrl: string,
20
- signal: AbortSignal,
21
- customStyles: any = {},
22
- collectorIds: CollectorIds,
23
- apiKey: string
24
- ): Promise <InCollectorContainer> {
25
- const skyflow = await Skyflow.init({
26
- vaultID: vaultId,
27
- vaultURL: vaultUrl,
28
- getBearerToken: async () => {
29
- // Pass the signal to the fetch call
30
- const response = await fetch(`${baseUrl}/api/v1/vault-token/`, {
31
- method: 'GET',
32
- headers: {
33
- 'Authorization': `Token ${apiKey}`,
34
- },
35
- signal: signal,
36
- });
37
-
38
- if (response.ok) {
39
- const responseBody = await response.json();
40
- return responseBody.token;
41
- } else {
42
- throw new Error('Failed to retrieve bearer token');
43
- }
44
- },
45
- options: {
46
- logLevel: Skyflow.LogLevel.ERROR,
47
- env: Skyflow.Env.DEV,
48
- },
49
- });
50
-
51
- // Create collect Container.
52
- const collectContainer = await skyflow.container(
53
- Skyflow.ContainerType.COLLECT
54
- );
55
-
56
- // Custom styles for collect elements.
57
- var collectStylesOptions: any = Object.keys(customStyles).length === 0 ? defaultStyles : customStyles
58
-
59
- const stylesForCardNumber = { ...collectStylesOptions.inputStyles.base };
60
- stylesForCardNumber.textIndent = '44px';
61
-
62
- const lengthMatchRule = {
63
- type: Skyflow.ValidationRuleType.LENGTH_MATCH_RULE,
64
- params: {
65
- max: 70,
66
- },
67
- };
68
-
69
- const cardHolderNameElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
70
- table: "cards",
71
- column: "cardholder_name",
72
- ...collectStylesOptions,
73
- label: "Titular de la tarjeta",
74
- placeholder: "Nombre como aparece en la tarjeta",
75
- type: Skyflow.ElementType.CARDHOLDER_NAME,
76
- validations: [lengthMatchRule],
77
- });
78
-
79
- if("setError" in cardHolderNameElement) {
80
- cardHolderNameElement.setError('Inválido')
81
- }
82
-
83
- // Create collect elements.
84
- const cardNumberElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
85
- table: "cards",
86
- column: "card_number",
87
- ...collectStylesOptions,
88
- inputStyles: {
89
- ...collectStylesOptions.inputStyles,
90
- base: stylesForCardNumber
91
- },
92
- label: "Número de tarjeta",
93
- placeholder: "1234 1234 1234 1234",
94
- type: Skyflow.ElementType.CARD_NUMBER,
95
- });
96
-
97
- if("setError" in cardNumberElement) {
98
- cardNumberElement.setError('Inválido')
99
- }
100
-
101
- const cvvElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
102
- table: "cards",
103
- column: "cvv",
104
- ...collectStylesOptions,
105
- label: "CVC/CVV",
106
- placeholder: "3-4 dígitos",
107
- type: Skyflow.ElementType.CVV,
108
- });
109
-
110
- if("setError" in cvvElement) {
111
- cvvElement.setError('Inválido')
112
- }
113
-
114
- const expiryMonthElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
115
- table: "cards",
116
- column: "expiration_month",
117
- ...collectStylesOptions,
118
- label: "Fecha de expiración",
119
- placeholder: "MM",
120
- type: Skyflow.ElementType.EXPIRATION_MONTH,
121
- });
122
-
123
- if("setError" in expiryMonthElement) {
124
- expiryMonthElement.setError('Inválido')
125
- }
126
-
127
- const expiryYearElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
128
- table: "cards",
129
- column: "expiration_year",
130
- ...collectStylesOptions,
131
- label: "",
132
- placeholder: "AA",
133
- type: Skyflow.ElementType.EXPIRATION_YEAR,
134
- });
135
-
136
- if("setError" in expiryYearElement) {
137
- expiryYearElement.setError('Inválido')
138
- }
139
-
140
- await mountElements(
141
- { id: collectorIds.cardNumber, element: cardNumberElement },
142
- { id: collectorIds.cvv, element: cvvElement },
143
- { id: collectorIds.expirationMonth, element: expiryMonthElement },
144
- { id: collectorIds.expirationYear, element: expiryYearElement },
145
- { id: collectorIds.holderName, element: cardHolderNameElement }
146
- )
147
-
148
- return {
149
- container: collectContainer,
150
- elements: {
151
- cardHolderNameElement,
152
- cardNumberElement,
153
- cvvElement,
154
- expiryMonthElement,
155
- expiryYearElement
156
- }
157
- }
158
- }
159
-
160
- async function mountElements(
161
- cardNumberElement: any,
162
- cvvElement: any,
163
- expiryMonthElement: any,
164
- expiryYearElement: any,
165
- cardHolderNameElement: any,
166
- ) {
167
- cardNumberElement.element.mount(`#${cardNumberElement.id}`);
168
- cvvElement.element.mount(`#${cvvElement.id}`);
169
- expiryMonthElement.element.mount(`#${expiryMonthElement.id}`);
170
- expiryYearElement.element.mount(`#${expiryYearElement.id}`);
171
- cardHolderNameElement.element.mount(`#${cardHolderNameElement.id}`);
172
- }
1
+ import CollectElement from "skyflow-js/types/core/external/collect/collect-element";
2
+ import { defaultStyles } from "./styles";
3
+ import Skyflow from 'skyflow-js'
4
+ import { CollectorIds } from "./template";
5
+ import CollectorContainer from "skyflow-js/types/core/external/collect/collect-container"
6
+ import ComposableContainer from "skyflow-js/types/core/external/collect/compose-collect-container"
7
+ import RevealContainer from "skyflow-js/types/core/external/reveal/reveal-container"
8
+ import RevealElement from "skyflow-js/types/core/external/reveal/reveal-element";
9
+ import ComposableElement from "skyflow-js/types/core/external/collect/compose-collect-element";
10
+
11
+ export type InCollectorContainer = {
12
+ container: CollectorContainer | ComposableContainer | RevealContainer,
13
+ elements: { [ index: string ]: CollectElement | ComposableElement | RevealElement }
14
+ }
15
+
16
+ export async function initSkyflow(
17
+ vaultId: string,
18
+ vaultUrl: string,
19
+ baseUrl: string,
20
+ signal: AbortSignal,
21
+ customStyles: any = {},
22
+ collectorIds: CollectorIds,
23
+ apiKey: string
24
+ ): Promise <InCollectorContainer> {
25
+ const skyflow = await Skyflow.init({
26
+ vaultID: vaultId,
27
+ vaultURL: vaultUrl,
28
+ getBearerToken: async () => {
29
+ // Pass the signal to the fetch call
30
+ const response = await fetch(`${baseUrl}/api/v1/vault-token/`, {
31
+ method: 'GET',
32
+ headers: {
33
+ 'Authorization': `Token ${apiKey}`,
34
+ },
35
+ signal: signal,
36
+ });
37
+
38
+ if (response.ok) {
39
+ const responseBody = await response.json();
40
+ return responseBody.token;
41
+ } else {
42
+ throw new Error('Failed to retrieve bearer token');
43
+ }
44
+ },
45
+ options: {
46
+ logLevel: Skyflow.LogLevel.ERROR,
47
+ env: Skyflow.Env.DEV,
48
+ },
49
+ });
50
+
51
+ // Create collect Container.
52
+ const collectContainer = await skyflow.container(
53
+ Skyflow.ContainerType.COLLECT
54
+ );
55
+
56
+ // Custom styles for collect elements.
57
+ var collectStylesOptions: any = Object.keys(customStyles).length === 0 ? defaultStyles : customStyles
58
+
59
+ const stylesForCardNumber = { ...collectStylesOptions.inputStyles.base };
60
+ stylesForCardNumber.textIndent = '44px';
61
+
62
+ const lengthMatchRule = {
63
+ type: Skyflow.ValidationRuleType.LENGTH_MATCH_RULE,
64
+ params: {
65
+ max: 70,
66
+ },
67
+ };
68
+
69
+ const cardHolderNameElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
70
+ table: "cards",
71
+ column: "cardholder_name",
72
+ ...collectStylesOptions,
73
+ label: "Titular de la tarjeta",
74
+ placeholder: "Nombre como aparece en la tarjeta",
75
+ type: Skyflow.ElementType.CARDHOLDER_NAME,
76
+ validations: [lengthMatchRule],
77
+ });
78
+
79
+ if("setError" in cardHolderNameElement) {
80
+ cardHolderNameElement.setError('Inválido')
81
+ }
82
+
83
+ // Create collect elements.
84
+ const cardNumberElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
85
+ table: "cards",
86
+ column: "card_number",
87
+ ...collectStylesOptions,
88
+ inputStyles: {
89
+ ...collectStylesOptions.inputStyles,
90
+ base: stylesForCardNumber
91
+ },
92
+ label: "Número de tarjeta",
93
+ placeholder: "1234 1234 1234 1234",
94
+ type: Skyflow.ElementType.CARD_NUMBER,
95
+ });
96
+
97
+ if("setError" in cardNumberElement) {
98
+ cardNumberElement.setError('Inválido')
99
+ }
100
+
101
+ const cvvElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
102
+ table: "cards",
103
+ column: "cvv",
104
+ ...collectStylesOptions,
105
+ label: "CVC/CVV",
106
+ placeholder: "3-4 dígitos",
107
+ type: Skyflow.ElementType.CVV,
108
+ });
109
+
110
+ if("setError" in cvvElement) {
111
+ cvvElement.setError('Inválido')
112
+ }
113
+
114
+ const expiryMonthElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
115
+ table: "cards",
116
+ column: "expiration_month",
117
+ ...collectStylesOptions,
118
+ label: "Fecha de expiración",
119
+ placeholder: "MM",
120
+ type: Skyflow.ElementType.EXPIRATION_MONTH,
121
+ });
122
+
123
+ if("setError" in expiryMonthElement) {
124
+ expiryMonthElement.setError('Inválido')
125
+ }
126
+
127
+ const expiryYearElement: CollectElement | RevealElement | ComposableElement = await collectContainer.create({
128
+ table: "cards",
129
+ column: "expiration_year",
130
+ ...collectStylesOptions,
131
+ label: "",
132
+ placeholder: "AA",
133
+ type: Skyflow.ElementType.EXPIRATION_YEAR,
134
+ });
135
+
136
+ if("setError" in expiryYearElement) {
137
+ expiryYearElement.setError('Inválido')
138
+ }
139
+
140
+ await mountElements(
141
+ { id: collectorIds.cardNumber, element: cardNumberElement },
142
+ { id: collectorIds.cvv, element: cvvElement },
143
+ { id: collectorIds.expirationMonth, element: expiryMonthElement },
144
+ { id: collectorIds.expirationYear, element: expiryYearElement },
145
+ { id: collectorIds.holderName, element: cardHolderNameElement }
146
+ )
147
+
148
+ return {
149
+ container: collectContainer,
150
+ elements: {
151
+ cardHolderNameElement,
152
+ cardNumberElement,
153
+ cvvElement,
154
+ expiryMonthElement,
155
+ expiryYearElement
156
+ }
157
+ }
158
+ }
159
+
160
+ async function mountElements(
161
+ cardNumberElement: any,
162
+ cvvElement: any,
163
+ expiryMonthElement: any,
164
+ expiryYearElement: any,
165
+ cardHolderNameElement: any,
166
+ ) {
167
+ cardNumberElement.element.mount(`#${cardNumberElement.id}`);
168
+ cvvElement.element.mount(`#${cvvElement.id}`);
169
+ expiryMonthElement.element.mount(`#${expiryMonthElement.id}`);
170
+ expiryYearElement.element.mount(`#${expiryYearElement.id}`);
171
+ cardHolderNameElement.element.mount(`#${cardHolderNameElement.id}`);
172
+ }
@@ -1,60 +1,60 @@
1
- export const defaultStyles: any = {
2
- inputStyles: {
3
- base: {
4
- border: "1px solid #e0e0e0",
5
- padding: "10px 7px",
6
- borderRadius: "5px",
7
- color: "#1d1d1d",
8
- marginTop: "2px",
9
- backgroundColor: "white",
10
- fontFamily: '"Inter", sans-serif',
11
- fontSize: '16px',
12
- '&::placeholder': {
13
- color: "#ccc",
14
- },
15
- },
16
- cardIcon: {
17
- position: 'absolute',
18
- left: '6px',
19
- bottom: 'calc(50% - 12px)',
20
- },
21
- complete: {
22
- color: "#4caf50",
23
- },
24
- empty: {},
25
- focus: {},
26
- invalid: {
27
- border: "1px solid #f44336",
28
- },
29
- global: {
30
- '@import': 'url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;700&display=swap")',
31
- }
32
- },
33
- labelStyles: {
34
- base: {
35
- fontSize: '12px',
36
- fontWeight: '500',
37
- fontFamily: '"Inter", sans-serif'
38
- },
39
- },
40
- errorTextStyles: {
41
- base: {
42
- fontSize: '12px',
43
- fontWeight: '500',
44
- color: "#f44336",
45
- fontFamily: '"Inter", sans-serif'
46
- },
47
- },
48
- labels: {
49
- cardLabel: '',
50
- cvvLabel: '',
51
- expiryMonthLabel: '',
52
- expiryYearLabel: ''
53
- },
54
- placeholders: {
55
- cardPlaceholder: '',
56
- cvvPlaceholder: '',
57
- expiryMonthPlaceholder: '',
58
- expiryYearPlaceholder: ''
59
- }
60
- }
1
+ export const defaultStyles: any = {
2
+ inputStyles: {
3
+ base: {
4
+ border: "1px solid #e0e0e0",
5
+ padding: "10px 7px",
6
+ borderRadius: "5px",
7
+ color: "#1d1d1d",
8
+ marginTop: "2px",
9
+ backgroundColor: "white",
10
+ fontFamily: '"Inter", sans-serif',
11
+ fontSize: '16px',
12
+ '&::placeholder': {
13
+ color: "#ccc",
14
+ },
15
+ },
16
+ cardIcon: {
17
+ position: 'absolute',
18
+ left: '6px',
19
+ bottom: 'calc(50% - 12px)',
20
+ },
21
+ complete: {
22
+ color: "#4caf50",
23
+ },
24
+ empty: {},
25
+ focus: {},
26
+ invalid: {
27
+ border: "1px solid #f44336",
28
+ },
29
+ global: {
30
+ '@import': 'url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;700&display=swap")',
31
+ }
32
+ },
33
+ labelStyles: {
34
+ base: {
35
+ fontSize: '12px',
36
+ fontWeight: '500',
37
+ fontFamily: '"Inter", sans-serif'
38
+ },
39
+ },
40
+ errorTextStyles: {
41
+ base: {
42
+ fontSize: '12px',
43
+ fontWeight: '500',
44
+ color: "#f44336",
45
+ fontFamily: '"Inter", sans-serif'
46
+ },
47
+ },
48
+ labels: {
49
+ cardLabel: '',
50
+ cvvLabel: '',
51
+ expiryMonthLabel: '',
52
+ expiryYearLabel: ''
53
+ },
54
+ placeholders: {
55
+ cardPlaceholder: '',
56
+ cvvPlaceholder: '',
57
+ expiryMonthPlaceholder: '',
58
+ expiryYearPlaceholder: ''
59
+ }
60
+ }