@foxy.io/sdk 1.11.3 → 1.12.0
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/dist/cdn/FoxySDKCustomer.js +2 -2
- package/dist/cjs/customer/PaymentCardEmbed.js +170 -0
- package/dist/cjs/customer/index.js +3 -1
- package/dist/esm/customer/PaymentCardEmbed.js +166 -0
- package/dist/esm/customer/index.js +1 -0
- package/dist/types/backend/Graph/default_payment_method.d.ts +2 -0
- package/dist/types/customer/Graph/default_payment_method.d.ts +2 -2
- package/dist/types/customer/PaymentCardEmbed.d.ts +69 -0
- package/dist/types/customer/index.d.ts +1 -0
- package/dist/types/customer/types.d.ts +84 -0
- package/package.json +1 -1
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.PaymentCardEmbed = void 0;
|
|
15
|
+
/**
|
|
16
|
+
* A convenience wrapper for the payment card embed iframe. You don't have to use
|
|
17
|
+
* this class to embed the payment card iframe, but it provides a more convenient
|
|
18
|
+
* way to interact with the iframe and listen to its events.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const embed = new PaymentCardEmbed({
|
|
22
|
+
* url: 'https://embed.foxy.io/v1.html?template_set_id=123'
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* await embed.mount(document.body);
|
|
26
|
+
* console.log('Token:', await embed.tokenize());
|
|
27
|
+
*/
|
|
28
|
+
class PaymentCardEmbed {
|
|
29
|
+
constructor(_a) {
|
|
30
|
+
var { url } = _a, config = __rest(_a, ["url"]);
|
|
31
|
+
/**
|
|
32
|
+
* An event handler that is triggered when Enter is pressed in the card form.
|
|
33
|
+
* This feature is not available for template sets configured with the `stripe_connect`
|
|
34
|
+
* hosted payment gateway due to the limitations of Stripe.js.
|
|
35
|
+
*/
|
|
36
|
+
this.onsubmit = null;
|
|
37
|
+
this.__tokenizationRequests = [];
|
|
38
|
+
this.__iframeMessageHandler = (evt) => {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
const data = JSON.parse(evt.data);
|
|
41
|
+
switch (data.type) {
|
|
42
|
+
case 'tokenization_response': {
|
|
43
|
+
const request = this.__tokenizationRequests.find(r => r.id === data.id);
|
|
44
|
+
data.token ? request === null || request === void 0 ? void 0 : request.resolve(data.token) : request === null || request === void 0 ? void 0 : request.reject();
|
|
45
|
+
this.__tokenizationRequests = this.__tokenizationRequests.filter(r => r.id !== data.id);
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case 'submit': {
|
|
49
|
+
(_a = this.onsubmit) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case 'resize': {
|
|
53
|
+
if (this.__iframe)
|
|
54
|
+
this.__iframe.style.height = data.height;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
case 'ready': {
|
|
58
|
+
this.configure(this.__config);
|
|
59
|
+
(_b = this.__mountingTask) === null || _b === void 0 ? void 0 : _b.resolve();
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
this.__iframeLoadHandler = (evt) => {
|
|
65
|
+
if (this.__channel) {
|
|
66
|
+
const contentWindow = evt.currentTarget.contentWindow;
|
|
67
|
+
if (!contentWindow)
|
|
68
|
+
throw new Error('Content window is not available.');
|
|
69
|
+
contentWindow.postMessage('connect', '*', [this.__channel.port2]);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
this.__mountingTask = null;
|
|
73
|
+
this.__channel = null;
|
|
74
|
+
this.__iframe = null;
|
|
75
|
+
this.__config = config;
|
|
76
|
+
this.__url = url;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Updates the configuration of the payment card embed.
|
|
80
|
+
* You can change style, translations, language and interactivity settings.
|
|
81
|
+
* To change the URL of the payment card embed, you need to create a new instance.
|
|
82
|
+
* You are not required to provide the full configuration object, only the properties you want to change.
|
|
83
|
+
*
|
|
84
|
+
* @param config - The new configuration.
|
|
85
|
+
*/
|
|
86
|
+
configure(config) {
|
|
87
|
+
var _a;
|
|
88
|
+
this.__config = config;
|
|
89
|
+
const message = Object.assign({ type: 'config' }, config);
|
|
90
|
+
(_a = this.__channel) === null || _a === void 0 ? void 0 : _a.port1.postMessage(JSON.stringify(message));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Requests the tokenization of the card data.
|
|
94
|
+
*
|
|
95
|
+
* @returns A promise that resolves with the tokenized card data.
|
|
96
|
+
*/
|
|
97
|
+
tokenize() {
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
if (this.__channel) {
|
|
100
|
+
const id = this._createId();
|
|
101
|
+
this.__tokenizationRequests.push({ id, reject, resolve });
|
|
102
|
+
this.__channel.port1.postMessage(JSON.stringify({ id, type: 'tokenization_request' }));
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
reject();
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Safely removes the embed iframe from the parent node,
|
|
111
|
+
* closing the message channel and cleaning up event listeners.
|
|
112
|
+
*/
|
|
113
|
+
unmount() {
|
|
114
|
+
var _a, _b, _c, _d, _e, _f;
|
|
115
|
+
(_a = this.__channel) === null || _a === void 0 ? void 0 : _a.port1.removeEventListener('message', this.__iframeMessageHandler);
|
|
116
|
+
(_b = this.__channel) === null || _b === void 0 ? void 0 : _b.port1.close();
|
|
117
|
+
(_c = this.__channel) === null || _c === void 0 ? void 0 : _c.port2.close();
|
|
118
|
+
this.__channel = null;
|
|
119
|
+
(_d = this.__iframe) === null || _d === void 0 ? void 0 : _d.removeEventListener('load', this.__iframeLoadHandler);
|
|
120
|
+
(_e = this.__iframe) === null || _e === void 0 ? void 0 : _e.remove();
|
|
121
|
+
this.__iframe = null;
|
|
122
|
+
(_f = this.__mountingTask) === null || _f === void 0 ? void 0 : _f.reject();
|
|
123
|
+
this.__mountingTask = null;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Mounts the payment card embed in the given root element. If the embed is already mounted,
|
|
127
|
+
* it will be unmounted first.
|
|
128
|
+
*
|
|
129
|
+
* @param root - The root element to mount the embed in.
|
|
130
|
+
* @returns A promise that resolves when the embed is mounted.
|
|
131
|
+
*/
|
|
132
|
+
mount(root) {
|
|
133
|
+
this.unmount();
|
|
134
|
+
this.__channel = this._createMessageChannel();
|
|
135
|
+
this.__channel.port1.addEventListener('message', this.__iframeMessageHandler);
|
|
136
|
+
this.__channel.port1.start();
|
|
137
|
+
this.__iframe = this._createIframe(root);
|
|
138
|
+
this.__iframe.addEventListener('load', this.__iframeLoadHandler);
|
|
139
|
+
this.__iframe.style.transition = 'height 0.15s ease';
|
|
140
|
+
this.__iframe.style.margin = '-2px';
|
|
141
|
+
this.__iframe.style.height = '100px';
|
|
142
|
+
this.__iframe.style.width = 'calc(100% + 4px)';
|
|
143
|
+
this.__iframe.src = this.__url;
|
|
144
|
+
root.append(this.__iframe);
|
|
145
|
+
return new Promise((resolve, reject) => {
|
|
146
|
+
this.__mountingTask = { reject, resolve };
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Clears the card data from the embed.
|
|
151
|
+
* No-op if the embed is not mounted.
|
|
152
|
+
*/
|
|
153
|
+
clear() {
|
|
154
|
+
var _a;
|
|
155
|
+
(_a = this.__channel) === null || _a === void 0 ? void 0 : _a.port1.postMessage(JSON.stringify({ type: 'clear' }));
|
|
156
|
+
}
|
|
157
|
+
/* v8 ignore next */
|
|
158
|
+
_createMessageChannel() {
|
|
159
|
+
return new MessageChannel();
|
|
160
|
+
}
|
|
161
|
+
/* v8 ignore next */
|
|
162
|
+
_createIframe(root) {
|
|
163
|
+
return root.ownerDocument.createElement('iframe');
|
|
164
|
+
}
|
|
165
|
+
/* v8 ignore next */
|
|
166
|
+
_createId() {
|
|
167
|
+
return `${Date.now()}${Math.random().toFixed(6).slice(2)}`;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
exports.PaymentCardEmbed = PaymentCardEmbed;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNextTransactionDate = exports.getTimeFromFrequency = exports.getNextTransactionDateConstraints = exports.getAllowedFrequencies = exports.API = void 0;
|
|
3
|
+
exports.PaymentCardEmbed = exports.isNextTransactionDate = exports.getTimeFromFrequency = exports.getNextTransactionDateConstraints = exports.getAllowedFrequencies = exports.API = void 0;
|
|
4
4
|
var API_js_1 = require("./API.js");
|
|
5
5
|
Object.defineProperty(exports, "API", { enumerable: true, get: function () { return API_js_1.API; } });
|
|
6
6
|
var getAllowedFrequencies_js_1 = require("./getAllowedFrequencies.js");
|
|
@@ -11,3 +11,5 @@ var getTimeFromFrequency_js_1 = require("../backend/getTimeFromFrequency.js");
|
|
|
11
11
|
Object.defineProperty(exports, "getTimeFromFrequency", { enumerable: true, get: function () { return getTimeFromFrequency_js_1.getTimeFromFrequency; } });
|
|
12
12
|
var isNextTransactionDate_js_1 = require("./isNextTransactionDate.js");
|
|
13
13
|
Object.defineProperty(exports, "isNextTransactionDate", { enumerable: true, get: function () { return isNextTransactionDate_js_1.isNextTransactionDate; } });
|
|
14
|
+
var PaymentCardEmbed_js_1 = require("./PaymentCardEmbed.js");
|
|
15
|
+
Object.defineProperty(exports, "PaymentCardEmbed", { enumerable: true, get: function () { return PaymentCardEmbed_js_1.PaymentCardEmbed; } });
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A convenience wrapper for the payment card embed iframe. You don't have to use
|
|
14
|
+
* this class to embed the payment card iframe, but it provides a more convenient
|
|
15
|
+
* way to interact with the iframe and listen to its events.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const embed = new PaymentCardEmbed({
|
|
19
|
+
* url: 'https://embed.foxy.io/v1.html?template_set_id=123'
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* await embed.mount(document.body);
|
|
23
|
+
* console.log('Token:', await embed.tokenize());
|
|
24
|
+
*/
|
|
25
|
+
export class PaymentCardEmbed {
|
|
26
|
+
constructor(_a) {
|
|
27
|
+
var { url } = _a, config = __rest(_a, ["url"]);
|
|
28
|
+
/**
|
|
29
|
+
* An event handler that is triggered when Enter is pressed in the card form.
|
|
30
|
+
* This feature is not available for template sets configured with the `stripe_connect`
|
|
31
|
+
* hosted payment gateway due to the limitations of Stripe.js.
|
|
32
|
+
*/
|
|
33
|
+
this.onsubmit = null;
|
|
34
|
+
this.__tokenizationRequests = [];
|
|
35
|
+
this.__iframeMessageHandler = (evt) => {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
const data = JSON.parse(evt.data);
|
|
38
|
+
switch (data.type) {
|
|
39
|
+
case 'tokenization_response': {
|
|
40
|
+
const request = this.__tokenizationRequests.find(r => r.id === data.id);
|
|
41
|
+
data.token ? request === null || request === void 0 ? void 0 : request.resolve(data.token) : request === null || request === void 0 ? void 0 : request.reject();
|
|
42
|
+
this.__tokenizationRequests = this.__tokenizationRequests.filter(r => r.id !== data.id);
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
case 'submit': {
|
|
46
|
+
(_a = this.onsubmit) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case 'resize': {
|
|
50
|
+
if (this.__iframe)
|
|
51
|
+
this.__iframe.style.height = data.height;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case 'ready': {
|
|
55
|
+
this.configure(this.__config);
|
|
56
|
+
(_b = this.__mountingTask) === null || _b === void 0 ? void 0 : _b.resolve();
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
this.__iframeLoadHandler = (evt) => {
|
|
62
|
+
if (this.__channel) {
|
|
63
|
+
const contentWindow = evt.currentTarget.contentWindow;
|
|
64
|
+
if (!contentWindow)
|
|
65
|
+
throw new Error('Content window is not available.');
|
|
66
|
+
contentWindow.postMessage('connect', '*', [this.__channel.port2]);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
this.__mountingTask = null;
|
|
70
|
+
this.__channel = null;
|
|
71
|
+
this.__iframe = null;
|
|
72
|
+
this.__config = config;
|
|
73
|
+
this.__url = url;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Updates the configuration of the payment card embed.
|
|
77
|
+
* You can change style, translations, language and interactivity settings.
|
|
78
|
+
* To change the URL of the payment card embed, you need to create a new instance.
|
|
79
|
+
* You are not required to provide the full configuration object, only the properties you want to change.
|
|
80
|
+
*
|
|
81
|
+
* @param config - The new configuration.
|
|
82
|
+
*/
|
|
83
|
+
configure(config) {
|
|
84
|
+
var _a;
|
|
85
|
+
this.__config = config;
|
|
86
|
+
const message = Object.assign({ type: 'config' }, config);
|
|
87
|
+
(_a = this.__channel) === null || _a === void 0 ? void 0 : _a.port1.postMessage(JSON.stringify(message));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Requests the tokenization of the card data.
|
|
91
|
+
*
|
|
92
|
+
* @returns A promise that resolves with the tokenized card data.
|
|
93
|
+
*/
|
|
94
|
+
tokenize() {
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
if (this.__channel) {
|
|
97
|
+
const id = this._createId();
|
|
98
|
+
this.__tokenizationRequests.push({ id, reject, resolve });
|
|
99
|
+
this.__channel.port1.postMessage(JSON.stringify({ id, type: 'tokenization_request' }));
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
reject();
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Safely removes the embed iframe from the parent node,
|
|
108
|
+
* closing the message channel and cleaning up event listeners.
|
|
109
|
+
*/
|
|
110
|
+
unmount() {
|
|
111
|
+
var _a, _b, _c, _d, _e, _f;
|
|
112
|
+
(_a = this.__channel) === null || _a === void 0 ? void 0 : _a.port1.removeEventListener('message', this.__iframeMessageHandler);
|
|
113
|
+
(_b = this.__channel) === null || _b === void 0 ? void 0 : _b.port1.close();
|
|
114
|
+
(_c = this.__channel) === null || _c === void 0 ? void 0 : _c.port2.close();
|
|
115
|
+
this.__channel = null;
|
|
116
|
+
(_d = this.__iframe) === null || _d === void 0 ? void 0 : _d.removeEventListener('load', this.__iframeLoadHandler);
|
|
117
|
+
(_e = this.__iframe) === null || _e === void 0 ? void 0 : _e.remove();
|
|
118
|
+
this.__iframe = null;
|
|
119
|
+
(_f = this.__mountingTask) === null || _f === void 0 ? void 0 : _f.reject();
|
|
120
|
+
this.__mountingTask = null;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Mounts the payment card embed in the given root element. If the embed is already mounted,
|
|
124
|
+
* it will be unmounted first.
|
|
125
|
+
*
|
|
126
|
+
* @param root - The root element to mount the embed in.
|
|
127
|
+
* @returns A promise that resolves when the embed is mounted.
|
|
128
|
+
*/
|
|
129
|
+
mount(root) {
|
|
130
|
+
this.unmount();
|
|
131
|
+
this.__channel = this._createMessageChannel();
|
|
132
|
+
this.__channel.port1.addEventListener('message', this.__iframeMessageHandler);
|
|
133
|
+
this.__channel.port1.start();
|
|
134
|
+
this.__iframe = this._createIframe(root);
|
|
135
|
+
this.__iframe.addEventListener('load', this.__iframeLoadHandler);
|
|
136
|
+
this.__iframe.style.transition = 'height 0.15s ease';
|
|
137
|
+
this.__iframe.style.margin = '-2px';
|
|
138
|
+
this.__iframe.style.height = '100px';
|
|
139
|
+
this.__iframe.style.width = 'calc(100% + 4px)';
|
|
140
|
+
this.__iframe.src = this.__url;
|
|
141
|
+
root.append(this.__iframe);
|
|
142
|
+
return new Promise((resolve, reject) => {
|
|
143
|
+
this.__mountingTask = { reject, resolve };
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Clears the card data from the embed.
|
|
148
|
+
* No-op if the embed is not mounted.
|
|
149
|
+
*/
|
|
150
|
+
clear() {
|
|
151
|
+
var _a;
|
|
152
|
+
(_a = this.__channel) === null || _a === void 0 ? void 0 : _a.port1.postMessage(JSON.stringify({ type: 'clear' }));
|
|
153
|
+
}
|
|
154
|
+
/* v8 ignore next */
|
|
155
|
+
_createMessageChannel() {
|
|
156
|
+
return new MessageChannel();
|
|
157
|
+
}
|
|
158
|
+
/* v8 ignore next */
|
|
159
|
+
_createIframe(root) {
|
|
160
|
+
return root.ownerDocument.createElement('iframe');
|
|
161
|
+
}
|
|
162
|
+
/* v8 ignore next */
|
|
163
|
+
_createId() {
|
|
164
|
+
return `${Date.now()}${Math.random().toFixed(6).slice(2)}`;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -3,3 +3,4 @@ export { getAllowedFrequencies } from './getAllowedFrequencies.js';
|
|
|
3
3
|
export { getNextTransactionDateConstraints } from './getNextTransactionDateConstraints.js';
|
|
4
4
|
export { getTimeFromFrequency } from '../backend/getTimeFromFrequency.js';
|
|
5
5
|
export { isNextTransactionDate } from './isNextTransactionDate.js';
|
|
6
|
+
export { PaymentCardEmbed } from './PaymentCardEmbed.js';
|
|
@@ -19,6 +19,8 @@ export interface DefaultPaymentMethod extends Graph {
|
|
|
19
19
|
save_cc: boolean;
|
|
20
20
|
/** The credit card or debit card type. This will be determined automatically once the payment card is saved. */
|
|
21
21
|
cc_type: string | null;
|
|
22
|
+
/** Token returned by our Tokenization Embed. Send this field with PATCH to update customer's payment method. */
|
|
23
|
+
cc_token?: string;
|
|
22
24
|
/** The payment card number. This property will not be displayed as part of this resource, but can be used to modify this payment method. */
|
|
23
25
|
cc_number?: number;
|
|
24
26
|
/** A masked version of this payment card showing only the last 4 digits. */
|
|
@@ -15,8 +15,8 @@ export interface DefaultPaymentMethod extends Graph {
|
|
|
15
15
|
save_cc: boolean;
|
|
16
16
|
/** The credit card or debit card type. This will be determined automatically once the payment card is saved. */
|
|
17
17
|
cc_type: string | null;
|
|
18
|
-
/**
|
|
19
|
-
|
|
18
|
+
/** Token returned by our Tokenization Embed. Send this field with PATCH to update customer's payment method. */
|
|
19
|
+
cc_token?: string;
|
|
20
20
|
/** A masked version of this payment card showing only the last 4 digits. */
|
|
21
21
|
cc_number_masked: string | null;
|
|
22
22
|
/** The payment card expiration month in the MM format. */
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { PaymentCardEmbedConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* A convenience wrapper for the payment card embed iframe. You don't have to use
|
|
4
|
+
* this class to embed the payment card iframe, but it provides a more convenient
|
|
5
|
+
* way to interact with the iframe and listen to its events.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const embed = new PaymentCardEmbed({
|
|
9
|
+
* url: 'https://embed.foxy.io/v1.html?template_set_id=123'
|
|
10
|
+
* });
|
|
11
|
+
*
|
|
12
|
+
* await embed.mount(document.body);
|
|
13
|
+
* console.log('Token:', await embed.tokenize());
|
|
14
|
+
*/
|
|
15
|
+
export declare class PaymentCardEmbed {
|
|
16
|
+
/**
|
|
17
|
+
* An event handler that is triggered when Enter is pressed in the card form.
|
|
18
|
+
* This feature is not available for template sets configured with the `stripe_connect`
|
|
19
|
+
* hosted payment gateway due to the limitations of Stripe.js.
|
|
20
|
+
*/
|
|
21
|
+
onsubmit: (() => void) | null;
|
|
22
|
+
private __tokenizationRequests;
|
|
23
|
+
private __iframeMessageHandler;
|
|
24
|
+
private __iframeLoadHandler;
|
|
25
|
+
private __mountingTask;
|
|
26
|
+
private __channel;
|
|
27
|
+
private __iframe;
|
|
28
|
+
private __config;
|
|
29
|
+
private __url;
|
|
30
|
+
constructor({ url, ...config }: {
|
|
31
|
+
url: string;
|
|
32
|
+
} & PaymentCardEmbedConfig);
|
|
33
|
+
/**
|
|
34
|
+
* Updates the configuration of the payment card embed.
|
|
35
|
+
* You can change style, translations, language and interactivity settings.
|
|
36
|
+
* To change the URL of the payment card embed, you need to create a new instance.
|
|
37
|
+
* You are not required to provide the full configuration object, only the properties you want to change.
|
|
38
|
+
*
|
|
39
|
+
* @param config - The new configuration.
|
|
40
|
+
*/
|
|
41
|
+
configure(config: PaymentCardEmbedConfig): void;
|
|
42
|
+
/**
|
|
43
|
+
* Requests the tokenization of the card data.
|
|
44
|
+
*
|
|
45
|
+
* @returns A promise that resolves with the tokenized card data.
|
|
46
|
+
*/
|
|
47
|
+
tokenize(): Promise<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Safely removes the embed iframe from the parent node,
|
|
50
|
+
* closing the message channel and cleaning up event listeners.
|
|
51
|
+
*/
|
|
52
|
+
unmount(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Mounts the payment card embed in the given root element. If the embed is already mounted,
|
|
55
|
+
* it will be unmounted first.
|
|
56
|
+
*
|
|
57
|
+
* @param root - The root element to mount the embed in.
|
|
58
|
+
* @returns A promise that resolves when the embed is mounted.
|
|
59
|
+
*/
|
|
60
|
+
mount(root: Element): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Clears the card data from the embed.
|
|
63
|
+
* No-op if the embed is not mounted.
|
|
64
|
+
*/
|
|
65
|
+
clear(): void;
|
|
66
|
+
protected _createMessageChannel(): MessageChannel;
|
|
67
|
+
protected _createIframe(root: Element): HTMLIFrameElement;
|
|
68
|
+
protected _createId(): string;
|
|
69
|
+
}
|
|
@@ -3,6 +3,7 @@ export { getAllowedFrequencies } from './getAllowedFrequencies.js';
|
|
|
3
3
|
export { getNextTransactionDateConstraints } from './getNextTransactionDateConstraints.js';
|
|
4
4
|
export { getTimeFromFrequency } from '../backend/getTimeFromFrequency.js';
|
|
5
5
|
export { isNextTransactionDate } from './isNextTransactionDate.js';
|
|
6
|
+
export { PaymentCardEmbed } from './PaymentCardEmbed.js';
|
|
6
7
|
import type * as Rels from './Rels';
|
|
7
8
|
export type { Graph } from './Graph';
|
|
8
9
|
export type { Rels };
|
|
@@ -1,3 +1,87 @@
|
|
|
1
|
+
/** Tokenization embed configuration that can be updated any time after mount. */
|
|
2
|
+
export type PaymentCardEmbedConfig = Partial<{
|
|
3
|
+
/** Translations. Note that Stripe and Square provide their own translations that can't be customized. */
|
|
4
|
+
translations: {
|
|
5
|
+
stripe?: {
|
|
6
|
+
label?: string;
|
|
7
|
+
status?: {
|
|
8
|
+
idle?: string;
|
|
9
|
+
busy?: string;
|
|
10
|
+
fail?: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
square?: {
|
|
14
|
+
label?: string;
|
|
15
|
+
status?: {
|
|
16
|
+
idle?: string;
|
|
17
|
+
busy?: string;
|
|
18
|
+
fail?: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
default?: {
|
|
22
|
+
'cc-number'?: {
|
|
23
|
+
label?: string;
|
|
24
|
+
placeholder?: string;
|
|
25
|
+
v8n_required?: string;
|
|
26
|
+
v8n_invalid?: string;
|
|
27
|
+
v8n_unsupported?: string;
|
|
28
|
+
};
|
|
29
|
+
'cc-exp'?: {
|
|
30
|
+
label?: string;
|
|
31
|
+
placeholder?: string;
|
|
32
|
+
v8n_required?: string;
|
|
33
|
+
v8n_invalid?: string;
|
|
34
|
+
v8n_expired?: string;
|
|
35
|
+
};
|
|
36
|
+
'cc-csc'?: {
|
|
37
|
+
label?: string;
|
|
38
|
+
placeholder?: string;
|
|
39
|
+
v8n_required?: string;
|
|
40
|
+
v8n_invalid?: string;
|
|
41
|
+
};
|
|
42
|
+
'status'?: {
|
|
43
|
+
idle?: string;
|
|
44
|
+
busy?: string;
|
|
45
|
+
fail?: string;
|
|
46
|
+
misconfigured?: string;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
/** If true, all fields inside the embed will be disabled. */
|
|
51
|
+
disabled: boolean;
|
|
52
|
+
/** If true, all fields inside the embed will be set to be read-only. For Stripe and Square the fields will be disabled and styled as readonly. */
|
|
53
|
+
readonly: boolean;
|
|
54
|
+
/** Appearance settings. */
|
|
55
|
+
style: Partial<{
|
|
56
|
+
'--lumo-space-m': string;
|
|
57
|
+
'--lumo-space-s': string;
|
|
58
|
+
'--lumo-contrast-5pct': string;
|
|
59
|
+
'--lumo-contrast-10pct': string;
|
|
60
|
+
'--lumo-contrast-50pct': string;
|
|
61
|
+
'--lumo-size-m': string;
|
|
62
|
+
'--lumo-size-xs': string;
|
|
63
|
+
'--lumo-border-radius-m': string;
|
|
64
|
+
'--lumo-border-radius-s': string;
|
|
65
|
+
'--lumo-font-family': string;
|
|
66
|
+
'--lumo-font-size-m': string;
|
|
67
|
+
'--lumo-font-size-s': string;
|
|
68
|
+
'--lumo-font-size-xs': string;
|
|
69
|
+
'--lumo-primary-color': string;
|
|
70
|
+
'--lumo-primary-text-color': string;
|
|
71
|
+
'--lumo-primary-color-50pct': string;
|
|
72
|
+
'--lumo-secondary-text-color': string;
|
|
73
|
+
'--lumo-disabled-text-color': string;
|
|
74
|
+
'--lumo-body-text-color': string;
|
|
75
|
+
'--lumo-error-text-color': string;
|
|
76
|
+
'--lumo-error-color-10pct': string;
|
|
77
|
+
'--lumo-error-color-50pct': string;
|
|
78
|
+
'--lumo-line-height-xs': string;
|
|
79
|
+
'--lumo-base-color': string;
|
|
80
|
+
}>;
|
|
81
|
+
/** Locale to use with Stripe or Square. Has no effect on the default UI. */
|
|
82
|
+
lang: string;
|
|
83
|
+
}>;
|
|
84
|
+
|
|
1
85
|
/** User credentials for authentication. */
|
|
2
86
|
export interface Credentials {
|
|
3
87
|
/** Email address associated with an account. */
|
package/package.json
CHANGED