@healnow/payments-ui 1.0.0 → 1.1.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/lib/payments/card.js +49 -120
- package/lib/payments/checkout.js +110 -0
- package/lib/payments.js +13 -14
- package/package.json +11 -10
- package/src/payments/checkout.js +96 -0
- package/src/payments.js +2 -0
- package/dist/payments-ui.js +0 -1
package/lib/payments/card.js
CHANGED
|
@@ -1,177 +1,106 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports["default"] = void 0;
|
|
7
|
-
|
|
8
8
|
var _channelMessenger = _interopRequireDefault(require("@mladenilic/channel-messenger"));
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
25
|
-
|
|
26
|
-
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
|
|
27
|
-
|
|
28
|
-
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
|
29
|
-
|
|
30
|
-
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
|
31
|
-
|
|
32
|
-
function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
|
|
33
|
-
|
|
34
|
-
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
35
|
-
|
|
36
|
-
function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
|
|
37
|
-
|
|
38
|
-
var Card = (_mounted = /*#__PURE__*/new WeakMap(), _messenger = /*#__PURE__*/new WeakMap(), _baseUrl = /*#__PURE__*/new WeakMap(), _clientKey = /*#__PURE__*/new WeakMap(), _tokenResolve = /*#__PURE__*/new WeakMap(), _tokenReject = /*#__PURE__*/new WeakMap(), _errorHandler = /*#__PURE__*/new WeakMap(), _buildIframe = /*#__PURE__*/new WeakSet(), _onMessage = /*#__PURE__*/new WeakSet(), /*#__PURE__*/function () {
|
|
9
|
+
var _mounted, _messenger, _baseUrl, _clientKey, _tokenResolve, _tokenReject, _errorHandler, _Class_brand;
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
11
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
12
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
13
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
14
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
15
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
16
|
+
function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
|
|
17
|
+
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
18
|
+
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
19
|
+
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
20
|
+
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
21
|
+
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
22
|
+
var Card = (_mounted = /*#__PURE__*/new WeakMap(), _messenger = /*#__PURE__*/new WeakMap(), _baseUrl = /*#__PURE__*/new WeakMap(), _clientKey = /*#__PURE__*/new WeakMap(), _tokenResolve = /*#__PURE__*/new WeakMap(), _tokenReject = /*#__PURE__*/new WeakMap(), _errorHandler = /*#__PURE__*/new WeakMap(), _Class_brand = /*#__PURE__*/new WeakSet(), /*#__PURE__*/function () {
|
|
39
23
|
function Card() {
|
|
40
24
|
var baseUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
41
25
|
var clientKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
42
|
-
|
|
43
26
|
_classCallCheck(this, Card);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
_classPrivateFieldInitSpec(this,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
value: null
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
_classPrivateFieldInitSpec(this, _baseUrl, {
|
|
60
|
-
writable: true,
|
|
61
|
-
value: null
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
_classPrivateFieldInitSpec(this, _clientKey, {
|
|
65
|
-
writable: true,
|
|
66
|
-
value: null
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
_classPrivateFieldInitSpec(this, _tokenResolve, {
|
|
70
|
-
writable: true,
|
|
71
|
-
value: null
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
_classPrivateFieldInitSpec(this, _tokenReject, {
|
|
75
|
-
writable: true,
|
|
76
|
-
value: null
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
_classPrivateFieldInitSpec(this, _errorHandler, {
|
|
80
|
-
writable: true,
|
|
81
|
-
value: null
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
_classPrivateFieldSet(this, _messenger, new _channelMessenger["default"]());
|
|
85
|
-
|
|
86
|
-
_classPrivateFieldSet(this, _baseUrl, baseUrl);
|
|
87
|
-
|
|
88
|
-
_classPrivateFieldSet(this, _clientKey, clientKey);
|
|
89
|
-
|
|
90
|
-
_classPrivateFieldGet(this, _messenger).onMessage(_classPrivateMethodGet(this, _onMessage, _onMessage2).bind(this));
|
|
27
|
+
_classPrivateMethodInitSpec(this, _Class_brand);
|
|
28
|
+
_classPrivateFieldInitSpec(this, _mounted, false);
|
|
29
|
+
_classPrivateFieldInitSpec(this, _messenger, null);
|
|
30
|
+
_classPrivateFieldInitSpec(this, _baseUrl, null);
|
|
31
|
+
_classPrivateFieldInitSpec(this, _clientKey, null);
|
|
32
|
+
_classPrivateFieldInitSpec(this, _tokenResolve, null);
|
|
33
|
+
_classPrivateFieldInitSpec(this, _tokenReject, null);
|
|
34
|
+
_classPrivateFieldInitSpec(this, _errorHandler, null);
|
|
35
|
+
_classPrivateFieldSet(_messenger, this, new _channelMessenger["default"]());
|
|
36
|
+
_classPrivateFieldSet(_baseUrl, this, baseUrl);
|
|
37
|
+
_classPrivateFieldSet(_clientKey, this, clientKey);
|
|
38
|
+
_classPrivateFieldGet(_messenger, this).onMessage(_assertClassBrand(_Class_brand, this, _onMessage).bind(this));
|
|
91
39
|
}
|
|
92
|
-
|
|
93
|
-
_createClass(Card, [{
|
|
40
|
+
return _createClass(Card, [{
|
|
94
41
|
key: "onError",
|
|
95
42
|
value: function onError(cb) {
|
|
96
|
-
_classPrivateFieldSet(
|
|
43
|
+
_classPrivateFieldSet(_errorHandler, this, cb);
|
|
97
44
|
}
|
|
98
45
|
}, {
|
|
99
46
|
key: "tokenize",
|
|
100
47
|
value: function tokenize() {
|
|
101
48
|
var _this = this;
|
|
102
|
-
|
|
103
|
-
if (_classPrivateFieldGet(this, _tokenResolve)) return new Error('Card is already being tokenized');
|
|
49
|
+
if (_classPrivateFieldGet(_tokenResolve, this)) return new Error('Card is already being tokenized');
|
|
104
50
|
return new Promise(function (resolve, reject) {
|
|
105
|
-
_classPrivateFieldGet(
|
|
51
|
+
_classPrivateFieldGet(_messenger, _this).send({
|
|
106
52
|
type: 'tokenize'
|
|
107
53
|
})["catch"](reject);
|
|
108
|
-
|
|
109
|
-
_classPrivateFieldSet(
|
|
110
|
-
|
|
111
|
-
_classPrivateFieldSet(_this, _tokenReject, reject);
|
|
54
|
+
_classPrivateFieldSet(_tokenResolve, _this, resolve);
|
|
55
|
+
_classPrivateFieldSet(_tokenReject, _this, reject);
|
|
112
56
|
});
|
|
113
57
|
}
|
|
114
58
|
}, {
|
|
115
59
|
key: "mount",
|
|
116
60
|
value: function mount(target) {
|
|
117
61
|
var _this2 = this;
|
|
118
|
-
|
|
119
62
|
if (typeof target === 'string') {
|
|
120
63
|
target = document.querySelector(target);
|
|
121
64
|
}
|
|
122
|
-
|
|
123
65
|
if (!target || !target instanceof HTMLElement) throw new Error('Invalid mount target');
|
|
124
66
|
return new Promise(function (resolve, reject) {
|
|
125
|
-
var iframe =
|
|
126
|
-
|
|
67
|
+
var iframe = _assertClassBrand(_Class_brand, _this2, _buildIframe).call(_this2);
|
|
127
68
|
target.appendChild(iframe);
|
|
128
|
-
|
|
129
|
-
_classPrivateFieldSet(_this2, _mounted, true);
|
|
130
|
-
|
|
69
|
+
_classPrivateFieldSet(_mounted, _this2, true);
|
|
131
70
|
iframe.addEventListener('load', function () {
|
|
132
71
|
setTimeout(function () {
|
|
133
|
-
_classPrivateFieldGet(
|
|
72
|
+
_classPrivateFieldGet(_messenger, _this2).connect(iframe).then(_classPrivateFieldGet(_messenger, _this2).send({
|
|
134
73
|
type: 'init',
|
|
135
|
-
key: _classPrivateFieldGet(
|
|
74
|
+
key: _classPrivateFieldGet(_clientKey, _this2)
|
|
136
75
|
}).then(resolve)["catch"](reject))["catch"](reject);
|
|
137
76
|
}, 300);
|
|
138
77
|
});
|
|
139
78
|
});
|
|
140
79
|
}
|
|
141
80
|
}]);
|
|
142
|
-
|
|
143
|
-
return Card;
|
|
144
81
|
}());
|
|
145
|
-
|
|
146
|
-
function _buildIframe2() {
|
|
82
|
+
function _buildIframe() {
|
|
147
83
|
var iframe = document.createElement('iframe');
|
|
148
84
|
iframe.hidden = false;
|
|
149
85
|
iframe.style.border = 'none';
|
|
150
86
|
iframe.height = '250px';
|
|
151
|
-
iframe.src = "".concat(_classPrivateFieldGet(
|
|
87
|
+
iframe.src = "".concat(_classPrivateFieldGet(_baseUrl, this), "/payments/ui");
|
|
152
88
|
iframe.width = '100%';
|
|
153
89
|
return iframe;
|
|
154
90
|
}
|
|
155
|
-
|
|
156
|
-
function _onMessage2(message) {
|
|
91
|
+
function _onMessage(message) {
|
|
157
92
|
if (message.payload.type === 'error') {
|
|
158
|
-
if (typeof _classPrivateFieldGet(
|
|
159
|
-
_classPrivateFieldGet(
|
|
93
|
+
if (typeof _classPrivateFieldGet(_errorHandler, this) === 'function') {
|
|
94
|
+
_classPrivateFieldGet(_errorHandler, this).call(this, message.payload);
|
|
160
95
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
_classPrivateFieldGet(this, _tokenReject).call(this, message.payload);
|
|
96
|
+
if (typeof _classPrivateFieldGet(_tokenReject, this) === 'function') {
|
|
97
|
+
_classPrivateFieldGet(_tokenReject, this).call(this, message.payload);
|
|
164
98
|
}
|
|
165
99
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
_classPrivateFieldGet(this, _tokenResolve).call(this, message.payload.value);
|
|
100
|
+
if (message.payload.type === 'token' && typeof _classPrivateFieldGet(_tokenResolve, this) === 'function') {
|
|
101
|
+
_classPrivateFieldGet(_tokenResolve, this).call(this, message.payload.value);
|
|
169
102
|
}
|
|
170
|
-
|
|
171
|
-
_classPrivateFieldSet(
|
|
172
|
-
|
|
173
|
-
_classPrivateFieldSet(this, _tokenReject, null);
|
|
103
|
+
_classPrivateFieldSet(_tokenResolve, this, null);
|
|
104
|
+
_classPrivateFieldSet(_tokenReject, this, null);
|
|
174
105
|
}
|
|
175
|
-
|
|
176
|
-
var _default = Card;
|
|
177
|
-
exports["default"] = _default;
|
|
106
|
+
var _default = exports["default"] = Card;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _channelMessenger = _interopRequireDefault(require("@mladenilic/channel-messenger"));
|
|
9
|
+
var _lodash = _interopRequireDefault(require("lodash.merge"));
|
|
10
|
+
var _mounted, _connected, _messenger, _checkoutUrl, _errorHandler, _paymentHandler, _options, _Class_brand;
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
12
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
13
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
14
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
15
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
16
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
17
|
+
function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
|
|
18
|
+
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
19
|
+
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
20
|
+
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
21
|
+
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
22
|
+
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
23
|
+
var Checkout = (_mounted = /*#__PURE__*/new WeakMap(), _connected = /*#__PURE__*/new WeakMap(), _messenger = /*#__PURE__*/new WeakMap(), _checkoutUrl = /*#__PURE__*/new WeakMap(), _errorHandler = /*#__PURE__*/new WeakMap(), _paymentHandler = /*#__PURE__*/new WeakMap(), _options = /*#__PURE__*/new WeakMap(), _Class_brand = /*#__PURE__*/new WeakSet(), /*#__PURE__*/function () {
|
|
24
|
+
function Checkout() {
|
|
25
|
+
var checkoutUrl = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
26
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
27
|
+
_classCallCheck(this, Checkout);
|
|
28
|
+
_classPrivateMethodInitSpec(this, _Class_brand);
|
|
29
|
+
_classPrivateFieldInitSpec(this, _mounted, false);
|
|
30
|
+
_classPrivateFieldInitSpec(this, _connected, false);
|
|
31
|
+
_classPrivateFieldInitSpec(this, _messenger, null);
|
|
32
|
+
_classPrivateFieldInitSpec(this, _checkoutUrl, null);
|
|
33
|
+
_classPrivateFieldInitSpec(this, _errorHandler, null);
|
|
34
|
+
_classPrivateFieldInitSpec(this, _paymentHandler, null);
|
|
35
|
+
_classPrivateFieldInitSpec(this, _options, {
|
|
36
|
+
applePay: {
|
|
37
|
+
domainName: document.location.hostname
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
_classPrivateFieldSet(_messenger, this, new _channelMessenger["default"]());
|
|
41
|
+
_classPrivateFieldSet(_checkoutUrl, this, checkoutUrl);
|
|
42
|
+
(0, _lodash["default"])(_classPrivateFieldGet(_options, this), options);
|
|
43
|
+
_classPrivateFieldGet(_messenger, this).onMessage(_assertClassBrand(_Class_brand, this, _onMessage).bind(this));
|
|
44
|
+
}
|
|
45
|
+
return _createClass(Checkout, [{
|
|
46
|
+
key: "onError",
|
|
47
|
+
value: function onError(cb) {
|
|
48
|
+
_classPrivateFieldSet(_errorHandler, this, cb);
|
|
49
|
+
}
|
|
50
|
+
}, {
|
|
51
|
+
key: "onPayment",
|
|
52
|
+
value: function onPayment(cb) {
|
|
53
|
+
_classPrivateFieldSet(_paymentHandler, this, cb);
|
|
54
|
+
}
|
|
55
|
+
}, {
|
|
56
|
+
key: "mount",
|
|
57
|
+
value: function mount(target) {
|
|
58
|
+
var _this = this;
|
|
59
|
+
if (typeof target === 'string') {
|
|
60
|
+
target = document.querySelector(target);
|
|
61
|
+
}
|
|
62
|
+
if (!target || !(target instanceof HTMLElement)) throw new Error('Invalid mount target');
|
|
63
|
+
return new Promise(function (resolve, reject) {
|
|
64
|
+
var iframe = _assertClassBrand(_Class_brand, _this, _buildIframe).call(_this);
|
|
65
|
+
target.appendChild(iframe);
|
|
66
|
+
_classPrivateFieldSet(_mounted, _this, true);
|
|
67
|
+
iframe.addEventListener('load', function () {
|
|
68
|
+
var _connect = function connect() {
|
|
69
|
+
return setTimeout(function () {
|
|
70
|
+
if (_classPrivateFieldGet(_connected, _this)) return resolve();
|
|
71
|
+
_classPrivateFieldGet(_messenger, _this).connect(iframe).then(_connect)["catch"](reject);
|
|
72
|
+
}, 1000);
|
|
73
|
+
};
|
|
74
|
+
_connect();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}]);
|
|
79
|
+
}());
|
|
80
|
+
function _buildIframe() {
|
|
81
|
+
var iframe = document.createElement('iframe');
|
|
82
|
+
iframe.hidden = false;
|
|
83
|
+
iframe.style.border = 'none';
|
|
84
|
+
iframe.style.overflow = 'hidden';
|
|
85
|
+
iframe.height = '600px';
|
|
86
|
+
iframe.src = "".concat(_classPrivateFieldGet(_checkoutUrl, this), "/embedded");
|
|
87
|
+
iframe.width = '100%';
|
|
88
|
+
iframe.allow = 'payment';
|
|
89
|
+
iframe.scrolling = 'no';
|
|
90
|
+
return iframe;
|
|
91
|
+
}
|
|
92
|
+
function _initCheckout() {
|
|
93
|
+
_classPrivateFieldGet(_messenger, this).send({
|
|
94
|
+
type: 'init',
|
|
95
|
+
options: _classPrivateFieldGet(_options, this)
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function _onMessage(message) {
|
|
99
|
+
if (message.payload.type === 'payment' && typeof _classPrivateFieldGet(_paymentHandler, this) === 'function') {
|
|
100
|
+
_classPrivateFieldGet(_paymentHandler, this).call(this, message.payload.value);
|
|
101
|
+
}
|
|
102
|
+
if (message.payload.type === 'error' && typeof _classPrivateFieldGet(_errorHandler, this) === 'function') {
|
|
103
|
+
_classPrivateFieldGet(_errorHandler, this).call(this, message.payload.value);
|
|
104
|
+
}
|
|
105
|
+
if (message.payload.type === 'connected') {
|
|
106
|
+
_classPrivateFieldSet(_connected, this, true);
|
|
107
|
+
_assertClassBrand(_Class_brand, this, _initCheckout).call(this);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
var _default = exports["default"] = Checkout;
|
package/lib/payments.js
CHANGED
|
@@ -4,24 +4,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
|
|
8
7
|
var _card = _interopRequireDefault(require("./payments/card"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
17
|
-
|
|
18
|
-
var _default = {
|
|
8
|
+
var _checkout = _interopRequireDefault(require("./payments/checkout"));
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
10
|
+
function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
|
|
11
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
12
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
13
|
+
var _default = exports["default"] = {
|
|
19
14
|
card: function card() {
|
|
20
15
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
21
16
|
args[_key] = arguments[_key];
|
|
22
17
|
}
|
|
23
|
-
|
|
24
18
|
return _construct(_card["default"], args);
|
|
19
|
+
},
|
|
20
|
+
checkout: function checkout() {
|
|
21
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
22
|
+
args[_key2] = arguments[_key2];
|
|
23
|
+
}
|
|
24
|
+
return _construct(_checkout["default"], args);
|
|
25
25
|
}
|
|
26
|
-
};
|
|
27
|
-
exports["default"] = _default;
|
|
26
|
+
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@healnow/payments-ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "lib/payments.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"start": "webpack serve --mode development",
|
|
8
8
|
"build:dist": "webpack",
|
|
@@ -16,15 +16,16 @@
|
|
|
16
16
|
"author": "Mladen Ilic <mladen@healnow.io>",
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@mladenilic/channel-messenger": "^1.0.1"
|
|
19
|
+
"@mladenilic/channel-messenger": "^1.0.1",
|
|
20
|
+
"lodash.merge": "^4.6.2"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
|
-
"@babel/cli": "^7.
|
|
23
|
-
"@babel/core": "^7.
|
|
24
|
-
"@babel/preset-env": "^7.
|
|
25
|
-
"babel-loader": "^
|
|
26
|
-
"webpack": "^5.
|
|
27
|
-
"webpack-cli": "^
|
|
28
|
-
"webpack-dev-server": "^
|
|
23
|
+
"@babel/cli": "^7.28.0",
|
|
24
|
+
"@babel/core": "^7.28.0",
|
|
25
|
+
"@babel/preset-env": "^7.28.0",
|
|
26
|
+
"babel-loader": "^10.0.0",
|
|
27
|
+
"webpack": "^5.100.2",
|
|
28
|
+
"webpack-cli": "^6.0.1",
|
|
29
|
+
"webpack-dev-server": "^5.2.2"
|
|
29
30
|
}
|
|
30
31
|
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import ChannelMessenger from '@mladenilic/channel-messenger';
|
|
2
|
+
import merge from 'lodash.merge'
|
|
3
|
+
|
|
4
|
+
const Checkout = class {
|
|
5
|
+
#mounted = false;
|
|
6
|
+
#connected = false;
|
|
7
|
+
#messenger = null;
|
|
8
|
+
#checkoutUrl = null;
|
|
9
|
+
#errorHandler = null;
|
|
10
|
+
#paymentHandler = null;
|
|
11
|
+
#options = {
|
|
12
|
+
applePay: {
|
|
13
|
+
domainName: document.location.hostname
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
constructor(checkoutUrl = '', options = {}) {
|
|
18
|
+
this.#messenger = new ChannelMessenger();
|
|
19
|
+
this.#checkoutUrl = checkoutUrl;
|
|
20
|
+
|
|
21
|
+
merge(this.#options, options);
|
|
22
|
+
|
|
23
|
+
this.#messenger.onMessage(this.#onMessage.bind(this));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
onError(cb) {
|
|
27
|
+
this.#errorHandler = cb;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
onPayment(cb) {
|
|
31
|
+
this.#paymentHandler = cb;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
mount(target) {
|
|
35
|
+
if (typeof target === 'string') {
|
|
36
|
+
target = document.querySelector(target);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!target || !(target instanceof HTMLElement)) throw new Error('Invalid mount target');
|
|
40
|
+
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
const iframe = this.#buildIframe();
|
|
43
|
+
target.appendChild(iframe);
|
|
44
|
+
this.#mounted = true;
|
|
45
|
+
|
|
46
|
+
iframe.addEventListener('load', () => {
|
|
47
|
+
const connect = () => setTimeout(() => {
|
|
48
|
+
if (this.#connected) return resolve();
|
|
49
|
+
|
|
50
|
+
this.#messenger.connect(iframe)
|
|
51
|
+
.then(connect)
|
|
52
|
+
.catch(reject);
|
|
53
|
+
}, 1000)
|
|
54
|
+
|
|
55
|
+
connect()
|
|
56
|
+
});
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
#buildIframe() {
|
|
61
|
+
const iframe = document.createElement('iframe');
|
|
62
|
+
|
|
63
|
+
iframe.hidden = false;
|
|
64
|
+
iframe.style.border = 'none';
|
|
65
|
+
iframe.style.overflow = 'hidden';
|
|
66
|
+
iframe.height = '600px';
|
|
67
|
+
iframe.src = `${this.#checkoutUrl}/embedded`;
|
|
68
|
+
iframe.width = '100%';
|
|
69
|
+
iframe.allow = 'payment';
|
|
70
|
+
iframe.scrolling = 'no';
|
|
71
|
+
|
|
72
|
+
return iframe;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
#initCheckout() {
|
|
76
|
+
this.#messenger.send({ type: 'init', options: this.#options })
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
#onMessage(message) {
|
|
80
|
+
if (message.payload.type === 'payment' && typeof this.#paymentHandler === 'function') {
|
|
81
|
+
this.#paymentHandler(message.payload.value);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (message.payload.type === 'error' && typeof this.#errorHandler === 'function') {
|
|
85
|
+
this.#errorHandler(message.payload.value);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (message.payload.type === 'connected') {
|
|
89
|
+
this.#connected = true;
|
|
90
|
+
|
|
91
|
+
this.#initCheckout();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export default Checkout;
|
package/src/payments.js
CHANGED
package/dist/payments-ui.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.PaymentsUI=t():e.PaymentsUI=t()}(self,(()=>(()=>{"use strict";var e={625:(e,t,n)=>{t.Z=void 0;var r,i,o,a,s,c,l,u,f,h,p,d,y,v=(r=n(100))&&r.__esModule?r:{default:r};function w(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function b(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?w(Object(n),!0).forEach((function(t){j(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):w(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function m(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function g(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function k(e,t){E(e,t),t.add(e)}function O(e,t,n){E(e,t),t.set(e,n)}function E(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}function j(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function P(e,t){return function(e,t){return t.get?t.get.call(e):t.value}(e,C(e,t,"get"))}function C(e,t,n){if(!t.has(e))throw new TypeError("attempted to "+n+" private field on non-instance");return t.get(e)}function S(e,t,n){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return n}var W=(o=new WeakMap,a=new WeakSet,s=new WeakSet,c=new WeakSet,l=new WeakSet,u=new WeakSet,f=new WeakSet,h=new WeakSet,p=new WeakSet,d=new WeakSet,y=new WeakSet,i=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};m(this,e),k(this,y),k(this,d),k(this,p),k(this,h),k(this,f),k(this,u),k(this,l),k(this,c),k(this,s),k(this,a),O(this,o,{writable:!0,value:null}),this.options=b({timeout:5e3,ack:!1},t),this.messageBuffer=[],this.listeners={global:[],ack:{}},this.connected=!1}var t,n;return t=e,n=[{key:"connect",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"*",r=new MessageChannel,i=S(this,y,z).call(this,null,e.opcodes.CONNECT);return t.contentWindow.postMessage(i,n,[r.port2]),S(this,l,A).call(this,r.port1),S(this,c,x).call(this,i)}},{key:"close",value:function(){var t=this;if(!this.connected)throw new Error("Cannot close connection. Not connected.");return this.send(null,e.opcodes.CLOSE).then((function(e){return S(t,u,_).call(t),e}))}},{key:"send",value:function(e,t){var n=S(this,y,z).call(this,e,t);return S(this,a,M).call(this,n)}},{key:"waitForConnection",value:function(e){var t=this;return new Promise((function(n){e.addEventListener("message",(function(e){t.connected||(S(t,f,N).call(t,e),t.connected&&n())}))}))}},{key:"onMessage",value:function(e){this.listeners.global.push(e)}},{key:"onError",value:function(e){var t,n;n=e,function(e,t,n){if(t.set)t.set.call(e,n);else{if(!t.writable)throw new TypeError("attempted to set read only private field");t.value=n}}(t=this,C(t,o,"set"),n)}}],n&&g(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}(),j(i,"opcodes",{CONNECT:"messenger::connect",CLOSE:"messenger::close",ACK:"messenger::ack",MESSAGE:"messenger::message"}),i);function M(e){return this.connected?this.port.postMessage(e):this.messageBuffer.push(e),S(this,c,x).call(this,e)}function T(e){this.options.ack&&this.send(e,W.opcodes.ACK)}function x(e){var t=this;return new Promise((function(n,r){if(!t.options.ack||e.opcode===W.opcodes.ACK)return n(e);var i=setTimeout((function(){delete t.listeners.ack[e.id],r("ACK not received")}),t.options.timeout);t.listeners.ack[e.id]=function(){clearTimeout(i),delete t.listeners.ack[e.id],n(e)}}))}function A(e){for(this.port=e,this.port.onmessage=S(this,f,N).bind(this),this.port.onmessageerror=S(this,h,B).bind(this),this.connected=!0;this.messageBuffer.length>0;)S(this,a,M).call(this,this.messageBuffer.shift()).catch(S(this,h,B))}function _(){this.port.close(),this.connected=!1}function N(e){var t=e.data;switch(t.opcode){case W.opcodes.CONNECT:S(this,l,A).call(this,e.ports[0]),S(this,s,T).call(this,t.id);break;case W.opcodes.CLOSE:S(this,s,T).call(this,t.id),S(this,u,_).call(this);break;case W.opcodes.ACK:S(this,p,L).call(this,t.payload);break;default:S(this,s,T).call(this,t.id),S(this,d,R).call(this,t)}}function B(e){if(P(this,o)){var t=e.data;P(this,o).call(this,t)}}function L(e){this.listeners.ack[e]&&this.listeners.ack[e](e)}function R(e){this.listeners.global.forEach((function(t){return t(e)}))}function z(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:W.opcodes.MESSAGE;return{id:(0,v.default)(),opcode:t,payload:e}}var K=W;t.Z=K},100:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;t.default=function(){var e=new Uint32Array(4);return crypto.getRandomValues(e),Array.from(e).concat([performance.now()]).map((function(e){return e.toString(36)})).join("")}}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var r={};return(()=>{n.d(r,{default:()=>S});var e,t,i,o,a,s,c,l,u,f=n(625);function h(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function p(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function d(e,t){v(e,t),t.add(e)}function y(e,t,n){v(e,t),t.set(e,n)}function v(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}function w(e,t,n){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return n}function b(e,t){return function(e,t){return t.get?t.get.call(e):t.value}(e,g(e,t,"get"))}function m(e,t,n){return function(e,t,n){if(t.set)t.set.call(e,n);else{if(!t.writable)throw new TypeError("attempted to set read only private field");t.value=n}}(e,g(e,t,"set"),n),n}function g(e,t,n){if(!t.has(e))throw new TypeError("attempted to "+n+" private field on non-instance");return t.get(e)}function k(){var e=document.createElement("iframe");return e.hidden=!1,e.style.border="none",e.height="250px",e.src="".concat(b(this,i),"/payments/ui"),e.width="100%",e}function O(e){"error"===e.payload.type&&("function"==typeof b(this,c)&&b(this,c).call(this,e.payload),"function"==typeof b(this,s)&&b(this,s).call(this,e.payload)),"token"===e.payload.type&&"function"==typeof b(this,a)&&b(this,a).call(this,e.payload.value),m(this,a,null),m(this,s,null)}const E=(e=new WeakMap,t=new WeakMap,i=new WeakMap,o=new WeakMap,a=new WeakMap,s=new WeakMap,c=new WeakMap,l=new WeakSet,u=new WeakSet,function(){function n(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",p=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";h(this,n),d(this,u),d(this,l),y(this,e,{writable:!0,value:!1}),y(this,t,{writable:!0,value:null}),y(this,i,{writable:!0,value:null}),y(this,o,{writable:!0,value:null}),y(this,a,{writable:!0,value:null}),y(this,s,{writable:!0,value:null}),y(this,c,{writable:!0,value:null}),m(this,t,new f.Z),m(this,i,r),m(this,o,p),b(this,t).onMessage(w(this,u,O).bind(this))}var r,v;return r=n,(v=[{key:"onError",value:function(e){m(this,c,e)}},{key:"tokenize",value:function(){var e=this;return b(this,a)?new Error("Card is already being tokenized"):new Promise((function(n,r){b(e,t).send({type:"tokenize"}).catch(r),m(e,a,n),m(e,s,r)}))}},{key:"mount",value:function(n){var r=this;if("string"==typeof n&&(n=document.querySelector(n)),!n||!n instanceof HTMLElement)throw new Error("Invalid mount target");return new Promise((function(i,a){var s=w(r,l,k).call(r);n.appendChild(s),m(r,e,!0),s.addEventListener("load",(function(){setTimeout((function(){b(r,t).connect(s).then(b(r,t).send({type:"init",key:b(r,o)}).then(i).catch(a)).catch(a)}),300)}))}))}}])&&p(r.prototype,v),Object.defineProperty(r,"prototype",{writable:!1}),n}());function j(e,t,n){return j=P()?Reflect.construct.bind():function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&C(i,n.prototype),i},j.apply(null,arguments)}function P(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function C(e,t){return C=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},C(e,t)}const S={card:function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return j(E,t)}}})(),r.default})()));
|