pay-sdk-web10 1.0.1

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.
@@ -0,0 +1,331 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) :
3
+ typeof define === 'function' && define.amd ? define(['react'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.WalletPaymentForm = factory(global.React));
5
+ })(this, (function (React) { 'use strict';
6
+
7
+ var DefaultContext = {
8
+ color: undefined,
9
+ size: undefined,
10
+ className: undefined,
11
+ style: undefined,
12
+ attr: undefined
13
+ };
14
+ var IconContext = React.createContext && /*#__PURE__*/React.createContext(DefaultContext);
15
+
16
+ var _excluded = ["attr", "size", "title"];
17
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
18
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } } return target; }
19
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
20
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
21
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
22
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
23
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
24
+ 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); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
25
+ function Tree2Element(tree) {
26
+ return tree && tree.map((node, i) => /*#__PURE__*/React.createElement(node.tag, _objectSpread({
27
+ key: i
28
+ }, node.attr), Tree2Element(node.child)));
29
+ }
30
+ function GenIcon(data) {
31
+ return props => /*#__PURE__*/React.createElement(IconBase, _extends({
32
+ attr: _objectSpread({}, data.attr)
33
+ }, props), Tree2Element(data.child));
34
+ }
35
+ function IconBase(props) {
36
+ var elem = conf => {
37
+ var {
38
+ attr,
39
+ size,
40
+ title
41
+ } = props,
42
+ svgProps = _objectWithoutProperties(props, _excluded);
43
+ var computedSize = size || conf.size || "1em";
44
+ var className;
45
+ if (conf.className) className = conf.className;
46
+ if (props.className) className = (className ? className + " " : "") + props.className;
47
+ return /*#__PURE__*/React.createElement("svg", _extends({
48
+ stroke: "currentColor",
49
+ fill: "currentColor",
50
+ strokeWidth: "0"
51
+ }, conf.attr, attr, svgProps, {
52
+ className: className,
53
+ style: _objectSpread(_objectSpread({
54
+ color: props.color || conf.color
55
+ }, conf.style), props.style),
56
+ height: computedSize,
57
+ width: computedSize,
58
+ xmlns: "http://www.w3.org/2000/svg"
59
+ }), title && /*#__PURE__*/React.createElement("title", null, title), props.children);
60
+ };
61
+ return IconContext !== undefined ? /*#__PURE__*/React.createElement(IconContext.Consumer, null, conf => elem(conf)) : elem(DefaultContext);
62
+ }
63
+
64
+ // THIS FILE IS AUTO GENERATED
65
+ function FaCheckCircle (props) {
66
+ return GenIcon({"attr":{"viewBox":"0 0 512 512"},"child":[{"tag":"path","attr":{"d":"M504 256c0 136.967-111.033 248-248 248S8 392.967 8 256 119.033 8 256 8s248 111.033 248 248zM227.314 387.314l184-184c6.248-6.248 6.248-16.379 0-22.627l-22.627-22.627c-6.248-6.249-16.379-6.249-22.628 0L216 308.118l-70.059-70.059c-6.248-6.248-16.379-6.248-22.628 0l-22.627 22.627c-6.248 6.248-6.248 16.379 0 22.627l104 104c6.249 6.249 16.379 6.249 22.628.001z"},"child":[]}]})(props);
67
+ }function FaExclamationCircle (props) {
68
+ return GenIcon({"attr":{"viewBox":"0 0 512 512"},"child":[{"tag":"path","attr":{"d":"M504 256c0 136.997-111.043 248-248 248S8 392.997 8 256C8 119.083 119.043 8 256 8s248 111.083 248 248zm-248 50c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z"},"child":[]}]})(props);
69
+ }function FaTimesCircle (props) {
70
+ return GenIcon({"attr":{"viewBox":"0 0 512 512"},"child":[{"tag":"path","attr":{"d":"M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm121.6 313.1c4.7 4.7 4.7 12.3 0 17L338 377.6c-4.7 4.7-12.3 4.7-17 0L256 312l-65.1 65.6c-4.7 4.7-12.3 4.7-17 0L134.4 338c-4.7-4.7-4.7-12.3 0-17l65.6-65-65.6-65.1c-4.7-4.7-4.7-12.3 0-17l39.6-39.6c4.7-4.7 12.3-4.7 17 0l65 65.7 65.1-65.6c4.7-4.7 12.3-4.7 17 0l39.6 39.6c4.7 4.7 4.7 12.3 0 17L312 256l65.6 65.1z"},"child":[]}]})(props);
71
+ }
72
+
73
+ // THIS FILE IS AUTO GENERATED
74
+ function IoEyeOff (props) {
75
+ return GenIcon({"attr":{"viewBox":"0 0 512 512"},"child":[{"tag":"path","attr":{"d":"M432 448a15.92 15.92 0 0 1-11.31-4.69l-352-352a16 16 0 0 1 22.62-22.62l352 352A16 16 0 0 1 432 448zM248 315.85l-51.79-51.79a2 2 0 0 0-3.39 1.69 64.11 64.11 0 0 0 53.49 53.49 2 2 0 0 0 1.69-3.39zm16-119.7L315.87 248a2 2 0 0 0 3.4-1.69 64.13 64.13 0 0 0-53.55-53.55 2 2 0 0 0-1.72 3.39z"},"child":[]},{"tag":"path","attr":{"d":"M491 273.36a32.2 32.2 0 0 0-.1-34.76c-26.46-40.92-60.79-75.68-99.27-100.53C349 110.55 302 96 255.68 96a226.54 226.54 0 0 0-71.82 11.79 4 4 0 0 0-1.56 6.63l47.24 47.24a4 4 0 0 0 3.82 1.05 96 96 0 0 1 116 116 4 4 0 0 0 1.05 3.81l67.95 68a4 4 0 0 0 5.4.24 343.81 343.81 0 0 0 67.24-77.4zM256 352a96 96 0 0 1-93.3-118.63 4 4 0 0 0-1.05-3.81l-66.84-66.87a4 4 0 0 0-5.41-.23c-24.39 20.81-47 46.13-67.67 75.72a31.92 31.92 0 0 0-.64 35.54c26.41 41.33 60.39 76.14 98.28 100.65C162.06 402 207.92 416 255.68 416a238.22 238.22 0 0 0 72.64-11.55 4 4 0 0 0 1.61-6.64l-47.47-47.46a4 4 0 0 0-3.81-1.05A96 96 0 0 1 256 352z"},"child":[]}]})(props);
76
+ }function IoEye (props) {
77
+ return GenIcon({"attr":{"viewBox":"0 0 512 512"},"child":[{"tag":"circle","attr":{"cx":"256","cy":"256","r":"64"},"child":[]},{"tag":"path","attr":{"d":"M490.84 238.6c-26.46-40.92-60.79-75.68-99.27-100.53C349 110.55 302 96 255.66 96c-42.52 0-84.33 12.15-124.27 36.11-40.73 24.43-77.63 60.12-109.68 106.07a31.92 31.92 0 0 0-.64 35.54c26.41 41.33 60.4 76.14 98.28 100.65C162 402 207.9 416 255.66 416c46.71 0 93.81-14.43 136.2-41.72 38.46-24.77 72.72-59.66 99.08-100.92a32.2 32.2 0 0 0-.1-34.76zM256 352a96 96 0 1 1 96-96 96.11 96.11 0 0 1-96 96z"},"child":[]}]})(props);
78
+ }
79
+
80
+ const SAMPLE_CUSTOMERS = {
81
+ "customer123": {
82
+ name: "John Doe",
83
+ balance: 1000,
84
+ passcode: "1234"
85
+ },
86
+ "customer456": {
87
+ name: "Jane Smith",
88
+ balance: 500,
89
+ passcode: "5678"
90
+ },
91
+ "customer789": {
92
+ name: "Alice Brown",
93
+ balance: 50,
94
+ passcode: "9012"
95
+ }
96
+ };
97
+ const generateTransactionDetails = (amount, transactionId) => ({
98
+ type: "Booking",
99
+ id: transactionId,
100
+ particulars: "Hotel Booking",
101
+ billedCurrency: "UGX",
102
+ billedAmount: amount,
103
+ totalBilling: amount
104
+ });
105
+ const checkAccountExists = customerId => Promise.resolve(!!SAMPLE_CUSTOMERS[customerId]);
106
+ const checkFunds = (customerId, amount) => {
107
+ const customer = SAMPLE_CUSTOMERS[customerId];
108
+ return Promise.resolve(customer && customer.balance >= amount);
109
+ };
110
+ const validatePasscode = (customerId, passcode, amount) => {
111
+ const customer = SAMPLE_CUSTOMERS[customerId];
112
+ if (customer && customer.passcode === passcode && customer.balance >= amount) {
113
+ SAMPLE_CUSTOMERS[customerId].balance -= amount;
114
+ return Promise.resolve(true);
115
+ }
116
+ return Promise.resolve(false);
117
+ };
118
+ const WalletPaymentForm = ({
119
+ customerId,
120
+ amount,
121
+ onClose,
122
+ onSuccess
123
+ }) => {
124
+ const [popup, setPopup] = React.useState('transactionSummary');
125
+ const [passcode, setPasscode] = React.useState('');
126
+ const [hasAccount, setHasAccount] = React.useState(null);
127
+ const [hasFunds, setHasFunds] = React.useState(null);
128
+ const [paymentStatus, setPaymentStatus] = React.useState('idle');
129
+ const [showPasscode, setShowPasscode] = React.useState(false);
130
+ const [transactionId] = React.useState(`W-${Math.floor(Math.random() * 1000000000)}`);
131
+ const [loading, setLoading] = React.useState(true); // New loading state
132
+
133
+ React.useEffect(() => {
134
+ // Show loading animation for 5 seconds
135
+ const timer = setTimeout(() => {
136
+ setLoading(false);
137
+ }, 5000);
138
+ const checkConditions = async () => {
139
+ if (!customerId) {
140
+ setHasAccount(false);
141
+ return;
142
+ }
143
+ const accountExists = await checkAccountExists(customerId);
144
+ setHasAccount(accountExists);
145
+ if (!accountExists) return;
146
+ const fundsOk = await checkFunds(customerId, amount);
147
+ setHasFunds(fundsOk);
148
+ };
149
+ checkConditions();
150
+
151
+ // Cleanup timer on unmount
152
+ return () => clearTimeout(timer);
153
+ }, [customerId, amount]);
154
+ const handleConfirm = () => {
155
+ if (hasAccount && hasFunds) {
156
+ setPopup('enterPasscode');
157
+ }
158
+ };
159
+ const handleSubmit = async e => {
160
+ e.preventDefault();
161
+ setPaymentStatus('pending');
162
+ const success = await validatePasscode(customerId, passcode, amount);
163
+ setPaymentStatus(success ? 'success' : 'failed');
164
+ setPopup(success ? 'paymentSuccess' : 'paymentFailed');
165
+ if (success && onSuccess) onSuccess();
166
+ setTimeout(() => {
167
+ setPopup('transactionSummary');
168
+ setPasscode('');
169
+ setPaymentStatus('idle');
170
+ onClose();
171
+ }, 5000);
172
+ };
173
+ const transactionDetails = generateTransactionDetails(amount, transactionId);
174
+ const renderHeader = () => /*#__PURE__*/React.createElement("div", {
175
+ className: "popup-header"
176
+ }, /*#__PURE__*/React.createElement("div", {
177
+ className: "logo"
178
+ }, /*#__PURE__*/React.createElement("img", {
179
+ src: "https://github.com/Bravothe/payment-library/blob/main/src/assets/logo.jpg?raw=true",
180
+ alt: "EvZone Logo",
181
+ className: "header-icon"
182
+ })), /*#__PURE__*/React.createElement("h2", null, /*#__PURE__*/React.createElement("span", {
183
+ className: "evzone"
184
+ }, "EvZone"), /*#__PURE__*/React.createElement("span", {
185
+ className: "pay"
186
+ }, " Pay")));
187
+ const renderPopup = () => {
188
+ switch (popup) {
189
+ case 'transactionSummary':
190
+ if (!hasAccount) {
191
+ return /*#__PURE__*/React.createElement("div", {
192
+ className: "popup-content"
193
+ }, renderHeader(), /*#__PURE__*/React.createElement("div", {
194
+ className: "error-content"
195
+ }, /*#__PURE__*/React.createElement(FaExclamationCircle, {
196
+ className: "icon"
197
+ }), /*#__PURE__*/React.createElement("h3", null, "Account Not Found"), /*#__PURE__*/React.createElement("p", null, "No wallet account matches the provided credentials."), /*#__PURE__*/React.createElement("button", {
198
+ onClick: onClose,
199
+ className: "close-button"
200
+ }, "Close")));
201
+ }
202
+ if (!hasFunds) {
203
+ return /*#__PURE__*/React.createElement("div", {
204
+ className: "popup-content"
205
+ }, renderHeader(), /*#__PURE__*/React.createElement("div", {
206
+ className: "error-content"
207
+ }, /*#__PURE__*/React.createElement(FaExclamationCircle, {
208
+ className: "icon"
209
+ }), /*#__PURE__*/React.createElement("h3", null, "Insufficient Funds"), /*#__PURE__*/React.createElement("p", null, "The account did not have sufficient funds to cover the transaction amount."), /*#__PURE__*/React.createElement("button", {
210
+ onClick: onClose,
211
+ className: "close-button"
212
+ }, "Add Amount")));
213
+ }
214
+ return /*#__PURE__*/React.createElement("div", {
215
+ className: "popup-content"
216
+ }, renderHeader(), /*#__PURE__*/React.createElement("div", {
217
+ className: "transaction-summary"
218
+ }, /*#__PURE__*/React.createElement("div", {
219
+ className: "merchant-info"
220
+ }, "Airbnb"), /*#__PURE__*/React.createElement("div", {
221
+ className: "total-billing"
222
+ }, "UGX ", transactionDetails.totalBilling.toFixed(2)), /*#__PURE__*/React.createElement("div", {
223
+ className: "transaction-details"
224
+ }, /*#__PURE__*/React.createElement("div", {
225
+ className: "detail"
226
+ }, /*#__PURE__*/React.createElement("span", null, "Transaction Type:"), /*#__PURE__*/React.createElement("strong", null, transactionDetails.type)), /*#__PURE__*/React.createElement("div", {
227
+ className: "detail"
228
+ }, /*#__PURE__*/React.createElement("span", null, "Transaction ID:"), /*#__PURE__*/React.createElement("strong", null, transactionDetails.id)), /*#__PURE__*/React.createElement("div", {
229
+ className: "detail"
230
+ }, /*#__PURE__*/React.createElement("span", null, "Particulars:"), /*#__PURE__*/React.createElement("strong", null, transactionDetails.particulars)), /*#__PURE__*/React.createElement("div", {
231
+ className: "detail"
232
+ }, /*#__PURE__*/React.createElement("span", null, "Billed Currency:"), /*#__PURE__*/React.createElement("strong", null, transactionDetails.billedCurrency)), /*#__PURE__*/React.createElement("div", {
233
+ className: "detail"
234
+ }, /*#__PURE__*/React.createElement("span", null, "Billed Amount:"), /*#__PURE__*/React.createElement("strong", null, "UGX ", transactionDetails.billedAmount.toFixed(2)))), /*#__PURE__*/React.createElement("button", {
235
+ onClick: handleConfirm,
236
+ className: "confirm-button"
237
+ }, "Confirm")));
238
+ case 'enterPasscode':
239
+ return /*#__PURE__*/React.createElement("div", {
240
+ className: "passcode-popup"
241
+ }, renderHeader(), /*#__PURE__*/React.createElement("div", {
242
+ className: "merchant-header"
243
+ }, "Merchant Info :"), /*#__PURE__*/React.createElement("div", {
244
+ className: "merchant-details"
245
+ }, /*#__PURE__*/React.createElement("div", {
246
+ className: "merchant-left"
247
+ }, /*#__PURE__*/React.createElement("div", {
248
+ className: "merchant-info"
249
+ }, /*#__PURE__*/React.createElement("div", {
250
+ className: "merchant-name"
251
+ }, "Airbnb"), /*#__PURE__*/React.createElement("div", {
252
+ className: "merchant-id"
253
+ }, "W-123456789"))), /*#__PURE__*/React.createElement("div", {
254
+ className: "merchant-amount"
255
+ }, /*#__PURE__*/React.createElement("strong", null, "UGX ", transactionDetails.totalBilling.toFixed(2)))), /*#__PURE__*/React.createElement("div", {
256
+ className: "passcode-section"
257
+ }, /*#__PURE__*/React.createElement("label", {
258
+ htmlFor: "passcode"
259
+ }, "Enter Passcode"), /*#__PURE__*/React.createElement("div", {
260
+ className: "passcode-input"
261
+ }, /*#__PURE__*/React.createElement("input", {
262
+ type: showPasscode ? "text" : "password",
263
+ id: "passcode",
264
+ value: passcode,
265
+ onChange: e => setPasscode(e.target.value),
266
+ placeholder: "\u2022\u2022\u2022\u2022\u2022\u2022",
267
+ maxLength: "6"
268
+ }), /*#__PURE__*/React.createElement("span", {
269
+ className: "toggle-visibility",
270
+ onClick: () => setShowPasscode(!showPasscode)
271
+ }, showPasscode ? /*#__PURE__*/React.createElement(IoEye, null) : /*#__PURE__*/React.createElement(IoEyeOff, null)))), /*#__PURE__*/React.createElement("div", {
272
+ className: "transaction-details"
273
+ }, /*#__PURE__*/React.createElement("p", null, "You are making a payment to ", /*#__PURE__*/React.createElement("strong", null, "Acorn International School"), " and an amount of", /*#__PURE__*/React.createElement("strong", null, " UGX ", transactionDetails.totalBilling.toFixed(2)), " will be deducted off your wallet, including:", /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("strong", null, "0.5% Tax:"), " UGX ", (transactionDetails.totalBilling * 0.005).toFixed(2), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("strong", null, "0.5% Wallet Fee:"), " UGX ", (transactionDetails.totalBilling * 0.005).toFixed(2))), /*#__PURE__*/React.createElement("div", {
274
+ className: "buttons-container"
275
+ }, /*#__PURE__*/React.createElement("button", {
276
+ onClick: handleSubmit,
277
+ className: "confirm-button",
278
+ disabled: !passcode
279
+ }, "Confirm Payment"), /*#__PURE__*/React.createElement("button", {
280
+ onClick: () => setPopup('transactionSummary'),
281
+ className: "back-button",
282
+ style: {
283
+ marginTop: '15px'
284
+ } // Adds space above the Back button
285
+ }, "Back")));
286
+ case 'paymentSuccess':
287
+ return /*#__PURE__*/React.createElement("div", {
288
+ className: "popup-content"
289
+ }, renderHeader(), /*#__PURE__*/React.createElement("div", {
290
+ className: "success-content"
291
+ }, /*#__PURE__*/React.createElement(FaCheckCircle, {
292
+ className: "icon"
293
+ }), /*#__PURE__*/React.createElement("h3", null, "Payment Successful"), /*#__PURE__*/React.createElement("p", null, "Your payment of UGX ", amount.toFixed(2), " was processed successfully!")));
294
+ case 'paymentFailed':
295
+ return /*#__PURE__*/React.createElement("div", {
296
+ className: "popup-content"
297
+ }, renderHeader(), /*#__PURE__*/React.createElement("div", {
298
+ className: "error-content"
299
+ }, /*#__PURE__*/React.createElement(FaTimesCircle, {
300
+ className: "icon"
301
+ }), /*#__PURE__*/React.createElement("h3", null, "Payment Failed"), /*#__PURE__*/React.createElement("p", null, "Please check your wallet for details."), /*#__PURE__*/React.createElement("button", {
302
+ onClick: onClose,
303
+ className: "close-button"
304
+ }, "Details")));
305
+ default:
306
+ return null;
307
+ }
308
+ };
309
+ return /*#__PURE__*/React.createElement("div", {
310
+ className: "wallet-payment-form"
311
+ }, loading ? /*#__PURE__*/React.createElement("div", {
312
+ class: "loading-overlay"
313
+ }, /*#__PURE__*/React.createElement("div", {
314
+ class: "loading-content"
315
+ }, /*#__PURE__*/React.createElement("img", {
316
+ src: "https://github.com/Bravothe/payment-library/blob/main/src/assets/logo.jpg?raw=true",
317
+ alt: "EvZone Logo",
318
+ class: "logo"
319
+ }), /*#__PURE__*/React.createElement("p", {
320
+ class: "loading-text"
321
+ }, "Evzone Wallet Pay"))) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
322
+ className: "overlay",
323
+ onClick: onClose
324
+ }), /*#__PURE__*/React.createElement("div", {
325
+ className: "content"
326
+ }, renderPopup())));
327
+ };
328
+
329
+ return WalletPaymentForm;
330
+
331
+ }));