@pinerohit11/testwidget 0.1.40 → 0.1.41

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.cjs CHANGED
@@ -47,7 +47,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
47
47
  // src/app/index.ts
48
48
  var app_exports = {};
49
49
  __export(app_exports, {
50
- RequestPayment: () => RequestPayment
50
+ RequestPayment: () => RequestPayment,
51
+ RequestPaymentAllInput: () => RequestPaymentAllInput,
52
+ RequestPaymentDynamic: () => RequestPaymentDynamic,
53
+ RequestPaymentonClick: () => RequestPaymentonClick
51
54
  });
52
55
  module.exports = __toCommonJS(app_exports);
53
56
 
@@ -1318,15 +1321,381 @@ var import_react5 = __toESM(require("react"), 1);
1318
1321
  var import_react_bootstrap2 = require("react-bootstrap");
1319
1322
  var import_react_toastify = require("react-toastify");
1320
1323
  var import_ReactToastify = require("react-toastify/dist/ReactToastify.css");
1324
+ function RequestPaymentAllInput({ fractalpayClientKey }) {
1325
+ const [isLoading, setIsLoading] = (0, import_react5.useState)(false);
1326
+ const [show, setShow] = (0, import_react5.useState)(false);
1327
+ const [phoneNumber, setPhoneNumber] = (0, import_react5.useState)("");
1328
+ const [amount, setAmount] = (0, import_react5.useState)("");
1329
+ const [orderId, setOrderId] = (0, import_react5.useState)("");
1330
+ const [isValidNumber, setIsValidNumber] = (0, import_react5.useState)(true);
1331
+ const [isValidAmount, setIsValidAmount] = (0, import_react5.useState)(true);
1332
+ const [isValidOrderId, setIsValidOrderId] = (0, import_react5.useState)(true);
1333
+ const [errorMessagephone, setErrorMessagephone] = (0, import_react5.useState)("");
1334
+ const [errorMessageamount, setErrorMessageamount] = (0, import_react5.useState)("");
1335
+ const [errorMessageorderid, setErrorMessageorderid] = (0, import_react5.useState)("");
1336
+ const [submitClicked, setSubmitClicked] = (0, import_react5.useState)(false);
1337
+ const handleClose = () => setShow(false);
1338
+ const handleShow = () => setShow(true);
1339
+ const sendRequestPayment = () => {
1340
+ if (!phoneNumber) {
1341
+ setErrorMessagephone(ErrorText.phonenumberrequired);
1342
+ setSubmitClicked(true);
1343
+ return;
1344
+ }
1345
+ if (!/^\d{10}$/.test(phoneNumber)) {
1346
+ setErrorMessagephone(ErrorText.phonenumbervalid);
1347
+ setSubmitClicked(true);
1348
+ return;
1349
+ }
1350
+ if (!amount) {
1351
+ setErrorMessageamount(ErrorText.amountenter);
1352
+ setSubmitClicked(true);
1353
+ return;
1354
+ }
1355
+ if (isNaN(Number(amount))) {
1356
+ setErrorMessageamount(ErrorText.amountvalid);
1357
+ setSubmitClicked(true);
1358
+ return;
1359
+ }
1360
+ if (!orderId) {
1361
+ setErrorMessageorderid(ErrorText.orderidenter);
1362
+ setSubmitClicked(true);
1363
+ return;
1364
+ }
1365
+ setErrorMessagephone("");
1366
+ setErrorMessageamount("");
1367
+ setErrorMessageorderid("");
1368
+ setSubmitClicked(true);
1369
+ setIsLoading(true);
1370
+ let formData = {
1371
+ fractalpayPublicKey: fractalpayClientKey,
1372
+ amount,
1373
+ phone_number: phoneNumber,
1374
+ orderId,
1375
+ action: "request"
1376
+ };
1377
+ const jsonData = JSON.stringify(formData);
1378
+ fetch(`${baseUrl}create-widget-order`, {
1379
+ method: "POST",
1380
+ headers: {
1381
+ "Content-Type": "application/json"
1382
+ },
1383
+ body: jsonData
1384
+ }).then((response) => {
1385
+ setIsLoading(false);
1386
+ if (!response.ok) {
1387
+ throw new Error(ErrorText.networkresponseerror);
1388
+ }
1389
+ return response.json();
1390
+ }).then((data) => {
1391
+ if (data.result === true) {
1392
+ setShow(true);
1393
+ }
1394
+ console.log(data);
1395
+ }).catch((error) => {
1396
+ setIsLoading(false);
1397
+ console.error("Error:", error);
1398
+ import_react_toastify.toast.error(ErrorText.anerroroccured);
1399
+ });
1400
+ };
1401
+ const handlePhoneNumberChange = (e) => {
1402
+ const number = e.target.value;
1403
+ const isValid = /^\d*$/.test(number);
1404
+ if (isValid) {
1405
+ setPhoneNumber(number);
1406
+ setIsValidNumber(number.length <= 10);
1407
+ if (number.length > 10) {
1408
+ setErrorMessagephone(ErrorText.phonenumberlength);
1409
+ } else {
1410
+ setErrorMessagephone("");
1411
+ }
1412
+ } else {
1413
+ setErrorMessagephone(ErrorText.phonenumbervalid);
1414
+ }
1415
+ };
1416
+ const handleAmountChange = (e) => {
1417
+ const amountValue = e.target.value;
1418
+ if (!isNaN(Number(amountValue))) {
1419
+ setAmount(amountValue);
1420
+ setIsValidAmount(true);
1421
+ setErrorMessageamount("");
1422
+ } else {
1423
+ setAmount("");
1424
+ setIsValidAmount(false);
1425
+ }
1426
+ };
1427
+ const handleOrderIdChange = (e) => {
1428
+ const orderIdValue = e.target.value;
1429
+ if (orderIdValue) {
1430
+ setOrderId(orderIdValue);
1431
+ setIsValidOrderId(true);
1432
+ setErrorMessageorderid("");
1433
+ } else {
1434
+ setOrderId("");
1435
+ setIsValidOrderId(false);
1436
+ }
1437
+ };
1438
+ return /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null, /* @__PURE__ */ import_react5.default.createElement(RequestPaymentstyles_default, null), /* @__PURE__ */ import_react5.default.createElement("div", { className: " border-container" }, /* @__PURE__ */ import_react5.default.createElement("div", { className: "payment-column" }, /* @__PURE__ */ import_react5.default.createElement("label", null, "Enter Phone Number:"), /* @__PURE__ */ import_react5.default.createElement("div", { className: "input-container" }, /* @__PURE__ */ import_react5.default.createElement(
1439
+ "input",
1440
+ {
1441
+ type: "text",
1442
+ value: phoneNumber,
1443
+ onChange: handlePhoneNumberChange,
1444
+ placeholder: "Enter phone number",
1445
+ maxLength: 10,
1446
+ className: submitClicked && (!phoneNumber || !isValidNumber) ? "error" : ""
1447
+ }
1448
+ ), errorMessagephone && /* @__PURE__ */ import_react5.default.createElement("div", { className: "error-message text-danger" }, errorMessagephone))), /* @__PURE__ */ import_react5.default.createElement("div", { className: "payment-column" }, /* @__PURE__ */ import_react5.default.createElement("label", null, "Enter Amount:"), /* @__PURE__ */ import_react5.default.createElement("div", { className: "input-container" }, /* @__PURE__ */ import_react5.default.createElement(
1449
+ "input",
1450
+ {
1451
+ type: "text",
1452
+ value: amount,
1453
+ onChange: handleAmountChange,
1454
+ placeholder: "Enter amount",
1455
+ className: submitClicked && (!amount || !isValidAmount) ? "error" : ""
1456
+ }
1457
+ ), errorMessageamount && /* @__PURE__ */ import_react5.default.createElement("div", { className: "error-message text-danger" }, errorMessageamount))), /* @__PURE__ */ import_react5.default.createElement("div", { className: "payment-column" }, /* @__PURE__ */ import_react5.default.createElement("label", null, "Enter Order ID:"), /* @__PURE__ */ import_react5.default.createElement("div", { className: "input-container" }, /* @__PURE__ */ import_react5.default.createElement(
1458
+ "input",
1459
+ {
1460
+ type: "text",
1461
+ value: orderId,
1462
+ onChange: handleOrderIdChange,
1463
+ placeholder: "Enter order ID",
1464
+ className: submitClicked && (!orderId || !isValidOrderId) ? "error" : ""
1465
+ }
1466
+ ), errorMessageorderid && /* @__PURE__ */ import_react5.default.createElement("div", { className: "error-message text-danger" }, errorMessageorderid))), /* @__PURE__ */ import_react5.default.createElement(
1467
+ "button",
1468
+ {
1469
+ onClick: sendRequestPayment,
1470
+ disabled: isLoading || !isValidNumber || !isValidAmount || !isValidOrderId,
1471
+ className: "paymentBtn"
1472
+ },
1473
+ isLoading ? "Loading..." : "Request Payment"
1474
+ )), /* @__PURE__ */ import_react5.default.createElement(import_react_bootstrap2.Modal, { className: "payment-suc", show, onHide: handleClose }, /* @__PURE__ */ import_react5.default.createElement(import_react_bootstrap2.Modal.Header, { closeButton: true }), /* @__PURE__ */ import_react5.default.createElement(import_react_bootstrap2.Modal.Body, null, /* @__PURE__ */ import_react5.default.createElement(
1475
+ "svg",
1476
+ {
1477
+ width: "60",
1478
+ height: "60",
1479
+ viewBox: "0 0 60 60",
1480
+ fill: "none",
1481
+ xmlns: "http://www.w3.org/2000/svg"
1482
+ },
1483
+ /* @__PURE__ */ import_react5.default.createElement(
1484
+ "rect",
1485
+ {
1486
+ x: "0.5",
1487
+ y: "0.5",
1488
+ width: "59",
1489
+ height: "59",
1490
+ rx: "29.5",
1491
+ stroke: "#31B379"
1492
+ }
1493
+ ),
1494
+ /* @__PURE__ */ import_react5.default.createElement("g", { clipPath: "url(#clip0_2659_5018)" }, /* @__PURE__ */ import_react5.default.createElement(
1495
+ "path",
1496
+ {
1497
+ d: "M41.1778 22.248C40.7483 21.8184 40.0518 21.8184 39.6222 22.248L26.4435 35.4268L21.3778 30.3611C20.9483 29.9315 20.2518 29.9316 19.8222 30.3611C19.3926 30.7907 19.3926 31.4871 19.8222 31.9167L25.6657 37.7601C26.0951 38.1897 26.7921 38.1894 27.2213 37.7601L41.1778 23.8036C41.6074 23.3741 41.6074 22.6776 41.1778 22.248Z",
1498
+ fill: "#31B379"
1499
+ }
1500
+ )),
1501
+ /* @__PURE__ */ import_react5.default.createElement("defs", null, /* @__PURE__ */ import_react5.default.createElement("clipPath", { id: "clip0_2659_5018" }, /* @__PURE__ */ import_react5.default.createElement(
1502
+ "rect",
1503
+ {
1504
+ width: "22",
1505
+ height: "22",
1506
+ fill: "white",
1507
+ transform: "translate(19.5 19.0039)"
1508
+ }
1509
+ )))
1510
+ ), /* @__PURE__ */ import_react5.default.createElement("h1", null, "Success!"), /* @__PURE__ */ import_react5.default.createElement("h4", null, "Payment link created successfully.")), /* @__PURE__ */ import_react5.default.createElement(import_react_bootstrap2.Modal.Footer, null, /* @__PURE__ */ import_react5.default.createElement("button", { className: "paymentBtn", onClick: handleClose }, "Ok"))), /* @__PURE__ */ import_react5.default.createElement(import_react_toastify.ToastContainer, null));
1511
+ }
1321
1512
 
1322
1513
  // src/app/components/RequestPayment/RequestPaymentDynamic.tsx
1323
1514
  var import_react6 = __toESM(require("react"), 1);
1324
1515
  var import_react_bootstrap3 = require("react-bootstrap");
1325
1516
 
1517
+ // src/app/components/Api/createWidgetOrder.ts
1518
+ var createWidgetOrder = (formData) => {
1519
+ const jsonData = JSON.stringify(formData);
1520
+ return fetch(`${baseUrl}create-widget-order`, {
1521
+ method: "POST",
1522
+ headers: {
1523
+ "Content-Type": "application/json"
1524
+ },
1525
+ body: jsonData
1526
+ }).then((response) => {
1527
+ if (!response.ok) {
1528
+ throw new Error(ErrorText.networkresponseerror);
1529
+ }
1530
+ return response.json();
1531
+ }).then((data) => {
1532
+ return data;
1533
+ });
1534
+ };
1535
+
1536
+ // src/app/components/RequestPayment/RequestPaymentDynamic.tsx
1537
+ function RequestPaymentDynamic({ fractalpayClientKey, amount, phone_number, orderID }) {
1538
+ console.log("props", { fractalpayClientKey, amount, phone_number, orderID });
1539
+ const [isLoading, setIsLoading] = (0, import_react6.useState)(false);
1540
+ const [show, setShow] = (0, import_react6.useState)(false);
1541
+ const handleClose = () => setShow(false);
1542
+ const handleShow = () => setShow(true);
1543
+ const sendRequestPayment = () => {
1544
+ setIsLoading(true);
1545
+ const formData = {
1546
+ fractalpayPublicKey: fractalpayClientKey,
1547
+ amount,
1548
+ phone_number,
1549
+ orderId: orderID,
1550
+ action: "request"
1551
+ };
1552
+ createWidgetOrder(formData).then((data) => {
1553
+ setIsLoading(false);
1554
+ if (data.result === true) {
1555
+ setShow(true);
1556
+ }
1557
+ console.log(data);
1558
+ }).catch((error) => {
1559
+ setIsLoading(false);
1560
+ console.error("Error:", error);
1561
+ });
1562
+ };
1563
+ return /* @__PURE__ */ import_react6.default.createElement(import_react6.default.Fragment, null, /* @__PURE__ */ import_react6.default.createElement("br", null), /* @__PURE__ */ import_react6.default.createElement(
1564
+ "button",
1565
+ {
1566
+ onClick: sendRequestPayment,
1567
+ disabled: isLoading,
1568
+ className: "paymentBtn"
1569
+ },
1570
+ isLoading ? "Loading..." : "Request Payment"
1571
+ ), /* @__PURE__ */ import_react6.default.createElement(import_react_bootstrap3.Modal, { className: "payment-suc", show, onHide: handleClose }, /* @__PURE__ */ import_react6.default.createElement(import_react_bootstrap3.Modal.Header, { closeButton: true }), /* @__PURE__ */ import_react6.default.createElement(import_react_bootstrap3.Modal.Body, null, /* @__PURE__ */ import_react6.default.createElement(
1572
+ "svg",
1573
+ {
1574
+ width: "60",
1575
+ height: "60",
1576
+ viewBox: "0 0 60 60",
1577
+ fill: "none",
1578
+ xmlns: "http://www.w3.org/2000/svg"
1579
+ },
1580
+ /* @__PURE__ */ import_react6.default.createElement(
1581
+ "rect",
1582
+ {
1583
+ x: "0.5",
1584
+ y: "0.5",
1585
+ width: "59",
1586
+ height: "59",
1587
+ rx: "29.5",
1588
+ stroke: "#31B379"
1589
+ }
1590
+ ),
1591
+ /* @__PURE__ */ import_react6.default.createElement("g", { "clip-path": "url(#clip0_2659_5018)" }, /* @__PURE__ */ import_react6.default.createElement(
1592
+ "path",
1593
+ {
1594
+ d: "M41.1778 22.248C40.7483 21.8184 40.0518 21.8184 39.6222 22.248L26.4435 35.4268L21.3778 30.3611C20.9483 29.9315 20.2518 29.9316 19.8222 30.3611C19.3926 30.7907 19.3926 31.4871 19.8222 31.9167L25.6657 37.7601C26.0951 38.1897 26.7921 38.1894 27.2213 37.7601L41.1778 23.8036C41.6074 23.3741 41.6074 22.6776 41.1778 22.248Z",
1595
+ fill: "#31B379"
1596
+ }
1597
+ )),
1598
+ /* @__PURE__ */ import_react6.default.createElement("defs", null, /* @__PURE__ */ import_react6.default.createElement("clipPath", { id: "clip0_2659_5018" }, /* @__PURE__ */ import_react6.default.createElement(
1599
+ "rect",
1600
+ {
1601
+ width: "22",
1602
+ height: "22",
1603
+ fill: "white",
1604
+ transform: "translate(19.5 19.0039)"
1605
+ }
1606
+ )))
1607
+ ), /* @__PURE__ */ import_react6.default.createElement("h1", null, "Success!"), /* @__PURE__ */ import_react6.default.createElement("h4", null, "Payment link created successfully.")), /* @__PURE__ */ import_react6.default.createElement(import_react_bootstrap3.Modal.Footer, null, /* @__PURE__ */ import_react6.default.createElement("button", { className: "paymentBtn", onClick: handleClose }, "Ok"))));
1608
+ }
1609
+
1326
1610
  // src/app/components/RequestPayment/RequestPaymentonClick.tsx
1327
1611
  var import_react7 = __toESM(require("react"), 1);
1328
1612
  var import_react_bootstrap4 = require("react-bootstrap");
1613
+ function RequestPaymentonClick(props) {
1614
+ const [isLoading, setIsLoading] = (0, import_react7.useState)(false);
1615
+ const [show, setShow] = (0, import_react7.useState)(false);
1616
+ const handleClose = () => setShow(false);
1617
+ const handleShow = () => setShow(true);
1618
+ const { fractalpayClientKey, amount, phone_number, orderID, onSuccess, onError } = props;
1619
+ const sendRequestPayment = () => {
1620
+ setIsLoading(true);
1621
+ let formData = {
1622
+ fractalpayPublicKey: fractalpayClientKey,
1623
+ amount,
1624
+ phone_number,
1625
+ orderId: orderID,
1626
+ action: "request"
1627
+ };
1628
+ const jsonData = JSON.stringify(formData);
1629
+ fetch(`${baseUrl}create-widget-order`, {
1630
+ method: "POST",
1631
+ headers: {
1632
+ "Content-Type": "application/json"
1633
+ },
1634
+ body: jsonData
1635
+ }).then((response) => {
1636
+ setIsLoading(false);
1637
+ if (!response.ok) {
1638
+ throw new Error(ErrorText.networkresponseerror);
1639
+ }
1640
+ return response.json();
1641
+ }).then((data) => {
1642
+ setShow(true);
1643
+ console.log(data);
1644
+ }).catch((error) => {
1645
+ setIsLoading(false);
1646
+ console.error("Error:", error);
1647
+ });
1648
+ };
1649
+ return /* @__PURE__ */ import_react7.default.createElement(import_react7.default.Fragment, null, /* @__PURE__ */ import_react7.default.createElement(RequestPaymentstyles_default, null), /* @__PURE__ */ import_react7.default.createElement(
1650
+ "button",
1651
+ {
1652
+ onClick: sendRequestPayment,
1653
+ disabled: isLoading,
1654
+ className: "paymentBtn"
1655
+ },
1656
+ isLoading ? "Loading..." : "Request Payment"
1657
+ ), /* @__PURE__ */ import_react7.default.createElement(import_react_bootstrap4.Modal, { className: "payment-suc", show, onHide: handleClose }, /* @__PURE__ */ import_react7.default.createElement(import_react_bootstrap4.Modal.Header, { closeButton: true }), /* @__PURE__ */ import_react7.default.createElement(import_react_bootstrap4.Modal.Body, null, onSuccess && /* @__PURE__ */ import_react7.default.createElement(
1658
+ "svg",
1659
+ {
1660
+ width: "60",
1661
+ height: "60",
1662
+ viewBox: "0 0 60 60",
1663
+ fill: "none",
1664
+ xmlns: "http://www.w3.org/2000/svg"
1665
+ },
1666
+ /* @__PURE__ */ import_react7.default.createElement(
1667
+ "rect",
1668
+ {
1669
+ x: "0.5",
1670
+ y: "0.5",
1671
+ width: "59",
1672
+ height: "59",
1673
+ rx: "29.5",
1674
+ stroke: "#31B379"
1675
+ }
1676
+ ),
1677
+ /* @__PURE__ */ import_react7.default.createElement("g", { clipPath: "url(#clip0_2659_5018)" }, /* @__PURE__ */ import_react7.default.createElement(
1678
+ "path",
1679
+ {
1680
+ d: "M41.1778 22.248C40.7483 21.8184 40.0518 21.8184 39.6222 22.248L26.4435 35.4268L21.3778 30.3611C20.9483 29.9315 20.2518 29.9316 19.8222 30.3611C19.3926 30.7907 19.3926 31.4871 19.8222 31.9167L25.6657 37.7601C26.0951 38.1897 26.7921 38.1894 27.2213 37.7601L41.1778 23.8036C41.6074 23.3741 41.6074 22.6776 41.1778 22.248Z",
1681
+ fill: "#31B379"
1682
+ }
1683
+ )),
1684
+ /* @__PURE__ */ import_react7.default.createElement("defs", null, /* @__PURE__ */ import_react7.default.createElement("clipPath", { id: "clip0_2659_5018" }, /* @__PURE__ */ import_react7.default.createElement(
1685
+ "rect",
1686
+ {
1687
+ width: "22",
1688
+ height: "22",
1689
+ fill: "white",
1690
+ transform: "translate(19.5 19.0039)"
1691
+ }
1692
+ )))
1693
+ ), onSuccess ? /* @__PURE__ */ import_react7.default.createElement(import_react7.default.Fragment, null, /* @__PURE__ */ import_react7.default.createElement("h1", null, "Success!"), /* @__PURE__ */ import_react7.default.createElement("h4", null, onSuccess)) : /* @__PURE__ */ import_react7.default.createElement(import_react7.default.Fragment, null, /* @__PURE__ */ import_react7.default.createElement("h1", null, "Error!"), /* @__PURE__ */ import_react7.default.createElement("h4", null, onError))), /* @__PURE__ */ import_react7.default.createElement(import_react_bootstrap4.Modal.Footer, null, /* @__PURE__ */ import_react7.default.createElement("button", { className: "paymentBtn", onClick: handleClose }, "Ok"))));
1694
+ }
1329
1695
  // Annotate the CommonJS export names for ESM import in node:
1330
1696
  0 && (module.exports = {
1331
- RequestPayment
1697
+ RequestPayment,
1698
+ RequestPaymentAllInput,
1699
+ RequestPaymentDynamic,
1700
+ RequestPaymentonClick
1332
1701
  });
package/dist/index.d.cts CHANGED
@@ -6,4 +6,27 @@ interface Props {
6
6
  }
7
7
  declare function RequestPayment(props: Props): React.JSX.Element;
8
8
 
9
- export { RequestPayment };
9
+ interface RequestPaymentAllInputProps {
10
+ fractalpayClientKey: string;
11
+ }
12
+ declare function RequestPaymentAllInput({ fractalpayClientKey }: RequestPaymentAllInputProps): React.JSX.Element;
13
+
14
+ interface RequestPaymentDynamicProps {
15
+ fractalpayClientKey: string;
16
+ amount: string;
17
+ phone_number: string;
18
+ orderID: string;
19
+ }
20
+ declare function RequestPaymentDynamic({ fractalpayClientKey, amount, phone_number, orderID }: RequestPaymentDynamicProps): React.JSX.Element;
21
+
22
+ interface PaymentRequestProps {
23
+ fractalpayClientKey: string;
24
+ amount: string;
25
+ phone_number: string;
26
+ orderID: string;
27
+ onSuccess?: string;
28
+ onError?: string;
29
+ }
30
+ declare function RequestPaymentonClick(props: PaymentRequestProps): React.JSX.Element;
31
+
32
+ export { RequestPayment, RequestPaymentAllInput, RequestPaymentDynamic, RequestPaymentonClick };
package/dist/index.d.ts CHANGED
@@ -6,4 +6,27 @@ interface Props {
6
6
  }
7
7
  declare function RequestPayment(props: Props): React.JSX.Element;
8
8
 
9
- export { RequestPayment };
9
+ interface RequestPaymentAllInputProps {
10
+ fractalpayClientKey: string;
11
+ }
12
+ declare function RequestPaymentAllInput({ fractalpayClientKey }: RequestPaymentAllInputProps): React.JSX.Element;
13
+
14
+ interface RequestPaymentDynamicProps {
15
+ fractalpayClientKey: string;
16
+ amount: string;
17
+ phone_number: string;
18
+ orderID: string;
19
+ }
20
+ declare function RequestPaymentDynamic({ fractalpayClientKey, amount, phone_number, orderID }: RequestPaymentDynamicProps): React.JSX.Element;
21
+
22
+ interface PaymentRequestProps {
23
+ fractalpayClientKey: string;
24
+ amount: string;
25
+ phone_number: string;
26
+ orderID: string;
27
+ onSuccess?: string;
28
+ onError?: string;
29
+ }
30
+ declare function RequestPaymentonClick(props: PaymentRequestProps): React.JSX.Element;
31
+
32
+ export { RequestPayment, RequestPaymentAllInput, RequestPaymentDynamic, RequestPaymentonClick };
package/dist/index.js CHANGED
@@ -1285,14 +1285,380 @@ import React5, { useState as useState2 } from "react";
1285
1285
  import { Modal as Modal2 } from "react-bootstrap";
1286
1286
  import { toast, ToastContainer } from "react-toastify";
1287
1287
  import "react-toastify/dist/ReactToastify.css";
1288
+ function RequestPaymentAllInput({ fractalpayClientKey }) {
1289
+ const [isLoading, setIsLoading] = useState2(false);
1290
+ const [show, setShow] = useState2(false);
1291
+ const [phoneNumber, setPhoneNumber] = useState2("");
1292
+ const [amount, setAmount] = useState2("");
1293
+ const [orderId, setOrderId] = useState2("");
1294
+ const [isValidNumber, setIsValidNumber] = useState2(true);
1295
+ const [isValidAmount, setIsValidAmount] = useState2(true);
1296
+ const [isValidOrderId, setIsValidOrderId] = useState2(true);
1297
+ const [errorMessagephone, setErrorMessagephone] = useState2("");
1298
+ const [errorMessageamount, setErrorMessageamount] = useState2("");
1299
+ const [errorMessageorderid, setErrorMessageorderid] = useState2("");
1300
+ const [submitClicked, setSubmitClicked] = useState2(false);
1301
+ const handleClose = () => setShow(false);
1302
+ const handleShow = () => setShow(true);
1303
+ const sendRequestPayment = () => {
1304
+ if (!phoneNumber) {
1305
+ setErrorMessagephone(ErrorText.phonenumberrequired);
1306
+ setSubmitClicked(true);
1307
+ return;
1308
+ }
1309
+ if (!/^\d{10}$/.test(phoneNumber)) {
1310
+ setErrorMessagephone(ErrorText.phonenumbervalid);
1311
+ setSubmitClicked(true);
1312
+ return;
1313
+ }
1314
+ if (!amount) {
1315
+ setErrorMessageamount(ErrorText.amountenter);
1316
+ setSubmitClicked(true);
1317
+ return;
1318
+ }
1319
+ if (isNaN(Number(amount))) {
1320
+ setErrorMessageamount(ErrorText.amountvalid);
1321
+ setSubmitClicked(true);
1322
+ return;
1323
+ }
1324
+ if (!orderId) {
1325
+ setErrorMessageorderid(ErrorText.orderidenter);
1326
+ setSubmitClicked(true);
1327
+ return;
1328
+ }
1329
+ setErrorMessagephone("");
1330
+ setErrorMessageamount("");
1331
+ setErrorMessageorderid("");
1332
+ setSubmitClicked(true);
1333
+ setIsLoading(true);
1334
+ let formData = {
1335
+ fractalpayPublicKey: fractalpayClientKey,
1336
+ amount,
1337
+ phone_number: phoneNumber,
1338
+ orderId,
1339
+ action: "request"
1340
+ };
1341
+ const jsonData = JSON.stringify(formData);
1342
+ fetch(`${baseUrl}create-widget-order`, {
1343
+ method: "POST",
1344
+ headers: {
1345
+ "Content-Type": "application/json"
1346
+ },
1347
+ body: jsonData
1348
+ }).then((response) => {
1349
+ setIsLoading(false);
1350
+ if (!response.ok) {
1351
+ throw new Error(ErrorText.networkresponseerror);
1352
+ }
1353
+ return response.json();
1354
+ }).then((data) => {
1355
+ if (data.result === true) {
1356
+ setShow(true);
1357
+ }
1358
+ console.log(data);
1359
+ }).catch((error) => {
1360
+ setIsLoading(false);
1361
+ console.error("Error:", error);
1362
+ toast.error(ErrorText.anerroroccured);
1363
+ });
1364
+ };
1365
+ const handlePhoneNumberChange = (e) => {
1366
+ const number = e.target.value;
1367
+ const isValid = /^\d*$/.test(number);
1368
+ if (isValid) {
1369
+ setPhoneNumber(number);
1370
+ setIsValidNumber(number.length <= 10);
1371
+ if (number.length > 10) {
1372
+ setErrorMessagephone(ErrorText.phonenumberlength);
1373
+ } else {
1374
+ setErrorMessagephone("");
1375
+ }
1376
+ } else {
1377
+ setErrorMessagephone(ErrorText.phonenumbervalid);
1378
+ }
1379
+ };
1380
+ const handleAmountChange = (e) => {
1381
+ const amountValue = e.target.value;
1382
+ if (!isNaN(Number(amountValue))) {
1383
+ setAmount(amountValue);
1384
+ setIsValidAmount(true);
1385
+ setErrorMessageamount("");
1386
+ } else {
1387
+ setAmount("");
1388
+ setIsValidAmount(false);
1389
+ }
1390
+ };
1391
+ const handleOrderIdChange = (e) => {
1392
+ const orderIdValue = e.target.value;
1393
+ if (orderIdValue) {
1394
+ setOrderId(orderIdValue);
1395
+ setIsValidOrderId(true);
1396
+ setErrorMessageorderid("");
1397
+ } else {
1398
+ setOrderId("");
1399
+ setIsValidOrderId(false);
1400
+ }
1401
+ };
1402
+ return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(RequestPaymentstyles_default, null), /* @__PURE__ */ React5.createElement("div", { className: " border-container" }, /* @__PURE__ */ React5.createElement("div", { className: "payment-column" }, /* @__PURE__ */ React5.createElement("label", null, "Enter Phone Number:"), /* @__PURE__ */ React5.createElement("div", { className: "input-container" }, /* @__PURE__ */ React5.createElement(
1403
+ "input",
1404
+ {
1405
+ type: "text",
1406
+ value: phoneNumber,
1407
+ onChange: handlePhoneNumberChange,
1408
+ placeholder: "Enter phone number",
1409
+ maxLength: 10,
1410
+ className: submitClicked && (!phoneNumber || !isValidNumber) ? "error" : ""
1411
+ }
1412
+ ), errorMessagephone && /* @__PURE__ */ React5.createElement("div", { className: "error-message text-danger" }, errorMessagephone))), /* @__PURE__ */ React5.createElement("div", { className: "payment-column" }, /* @__PURE__ */ React5.createElement("label", null, "Enter Amount:"), /* @__PURE__ */ React5.createElement("div", { className: "input-container" }, /* @__PURE__ */ React5.createElement(
1413
+ "input",
1414
+ {
1415
+ type: "text",
1416
+ value: amount,
1417
+ onChange: handleAmountChange,
1418
+ placeholder: "Enter amount",
1419
+ className: submitClicked && (!amount || !isValidAmount) ? "error" : ""
1420
+ }
1421
+ ), errorMessageamount && /* @__PURE__ */ React5.createElement("div", { className: "error-message text-danger" }, errorMessageamount))), /* @__PURE__ */ React5.createElement("div", { className: "payment-column" }, /* @__PURE__ */ React5.createElement("label", null, "Enter Order ID:"), /* @__PURE__ */ React5.createElement("div", { className: "input-container" }, /* @__PURE__ */ React5.createElement(
1422
+ "input",
1423
+ {
1424
+ type: "text",
1425
+ value: orderId,
1426
+ onChange: handleOrderIdChange,
1427
+ placeholder: "Enter order ID",
1428
+ className: submitClicked && (!orderId || !isValidOrderId) ? "error" : ""
1429
+ }
1430
+ ), errorMessageorderid && /* @__PURE__ */ React5.createElement("div", { className: "error-message text-danger" }, errorMessageorderid))), /* @__PURE__ */ React5.createElement(
1431
+ "button",
1432
+ {
1433
+ onClick: sendRequestPayment,
1434
+ disabled: isLoading || !isValidNumber || !isValidAmount || !isValidOrderId,
1435
+ className: "paymentBtn"
1436
+ },
1437
+ isLoading ? "Loading..." : "Request Payment"
1438
+ )), /* @__PURE__ */ React5.createElement(Modal2, { className: "payment-suc", show, onHide: handleClose }, /* @__PURE__ */ React5.createElement(Modal2.Header, { closeButton: true }), /* @__PURE__ */ React5.createElement(Modal2.Body, null, /* @__PURE__ */ React5.createElement(
1439
+ "svg",
1440
+ {
1441
+ width: "60",
1442
+ height: "60",
1443
+ viewBox: "0 0 60 60",
1444
+ fill: "none",
1445
+ xmlns: "http://www.w3.org/2000/svg"
1446
+ },
1447
+ /* @__PURE__ */ React5.createElement(
1448
+ "rect",
1449
+ {
1450
+ x: "0.5",
1451
+ y: "0.5",
1452
+ width: "59",
1453
+ height: "59",
1454
+ rx: "29.5",
1455
+ stroke: "#31B379"
1456
+ }
1457
+ ),
1458
+ /* @__PURE__ */ React5.createElement("g", { clipPath: "url(#clip0_2659_5018)" }, /* @__PURE__ */ React5.createElement(
1459
+ "path",
1460
+ {
1461
+ d: "M41.1778 22.248C40.7483 21.8184 40.0518 21.8184 39.6222 22.248L26.4435 35.4268L21.3778 30.3611C20.9483 29.9315 20.2518 29.9316 19.8222 30.3611C19.3926 30.7907 19.3926 31.4871 19.8222 31.9167L25.6657 37.7601C26.0951 38.1897 26.7921 38.1894 27.2213 37.7601L41.1778 23.8036C41.6074 23.3741 41.6074 22.6776 41.1778 22.248Z",
1462
+ fill: "#31B379"
1463
+ }
1464
+ )),
1465
+ /* @__PURE__ */ React5.createElement("defs", null, /* @__PURE__ */ React5.createElement("clipPath", { id: "clip0_2659_5018" }, /* @__PURE__ */ React5.createElement(
1466
+ "rect",
1467
+ {
1468
+ width: "22",
1469
+ height: "22",
1470
+ fill: "white",
1471
+ transform: "translate(19.5 19.0039)"
1472
+ }
1473
+ )))
1474
+ ), /* @__PURE__ */ React5.createElement("h1", null, "Success!"), /* @__PURE__ */ React5.createElement("h4", null, "Payment link created successfully.")), /* @__PURE__ */ React5.createElement(Modal2.Footer, null, /* @__PURE__ */ React5.createElement("button", { className: "paymentBtn", onClick: handleClose }, "Ok"))), /* @__PURE__ */ React5.createElement(ToastContainer, null));
1475
+ }
1288
1476
 
1289
1477
  // src/app/components/RequestPayment/RequestPaymentDynamic.tsx
1290
1478
  import React6, { useState as useState3 } from "react";
1291
1479
  import { Modal as Modal3 } from "react-bootstrap";
1292
1480
 
1481
+ // src/app/components/Api/createWidgetOrder.ts
1482
+ var createWidgetOrder = (formData) => {
1483
+ const jsonData = JSON.stringify(formData);
1484
+ return fetch(`${baseUrl}create-widget-order`, {
1485
+ method: "POST",
1486
+ headers: {
1487
+ "Content-Type": "application/json"
1488
+ },
1489
+ body: jsonData
1490
+ }).then((response) => {
1491
+ if (!response.ok) {
1492
+ throw new Error(ErrorText.networkresponseerror);
1493
+ }
1494
+ return response.json();
1495
+ }).then((data) => {
1496
+ return data;
1497
+ });
1498
+ };
1499
+
1500
+ // src/app/components/RequestPayment/RequestPaymentDynamic.tsx
1501
+ function RequestPaymentDynamic({ fractalpayClientKey, amount, phone_number, orderID }) {
1502
+ console.log("props", { fractalpayClientKey, amount, phone_number, orderID });
1503
+ const [isLoading, setIsLoading] = useState3(false);
1504
+ const [show, setShow] = useState3(false);
1505
+ const handleClose = () => setShow(false);
1506
+ const handleShow = () => setShow(true);
1507
+ const sendRequestPayment = () => {
1508
+ setIsLoading(true);
1509
+ const formData = {
1510
+ fractalpayPublicKey: fractalpayClientKey,
1511
+ amount,
1512
+ phone_number,
1513
+ orderId: orderID,
1514
+ action: "request"
1515
+ };
1516
+ createWidgetOrder(formData).then((data) => {
1517
+ setIsLoading(false);
1518
+ if (data.result === true) {
1519
+ setShow(true);
1520
+ }
1521
+ console.log(data);
1522
+ }).catch((error) => {
1523
+ setIsLoading(false);
1524
+ console.error("Error:", error);
1525
+ });
1526
+ };
1527
+ return /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement("br", null), /* @__PURE__ */ React6.createElement(
1528
+ "button",
1529
+ {
1530
+ onClick: sendRequestPayment,
1531
+ disabled: isLoading,
1532
+ className: "paymentBtn"
1533
+ },
1534
+ isLoading ? "Loading..." : "Request Payment"
1535
+ ), /* @__PURE__ */ React6.createElement(Modal3, { className: "payment-suc", show, onHide: handleClose }, /* @__PURE__ */ React6.createElement(Modal3.Header, { closeButton: true }), /* @__PURE__ */ React6.createElement(Modal3.Body, null, /* @__PURE__ */ React6.createElement(
1536
+ "svg",
1537
+ {
1538
+ width: "60",
1539
+ height: "60",
1540
+ viewBox: "0 0 60 60",
1541
+ fill: "none",
1542
+ xmlns: "http://www.w3.org/2000/svg"
1543
+ },
1544
+ /* @__PURE__ */ React6.createElement(
1545
+ "rect",
1546
+ {
1547
+ x: "0.5",
1548
+ y: "0.5",
1549
+ width: "59",
1550
+ height: "59",
1551
+ rx: "29.5",
1552
+ stroke: "#31B379"
1553
+ }
1554
+ ),
1555
+ /* @__PURE__ */ React6.createElement("g", { "clip-path": "url(#clip0_2659_5018)" }, /* @__PURE__ */ React6.createElement(
1556
+ "path",
1557
+ {
1558
+ d: "M41.1778 22.248C40.7483 21.8184 40.0518 21.8184 39.6222 22.248L26.4435 35.4268L21.3778 30.3611C20.9483 29.9315 20.2518 29.9316 19.8222 30.3611C19.3926 30.7907 19.3926 31.4871 19.8222 31.9167L25.6657 37.7601C26.0951 38.1897 26.7921 38.1894 27.2213 37.7601L41.1778 23.8036C41.6074 23.3741 41.6074 22.6776 41.1778 22.248Z",
1559
+ fill: "#31B379"
1560
+ }
1561
+ )),
1562
+ /* @__PURE__ */ React6.createElement("defs", null, /* @__PURE__ */ React6.createElement("clipPath", { id: "clip0_2659_5018" }, /* @__PURE__ */ React6.createElement(
1563
+ "rect",
1564
+ {
1565
+ width: "22",
1566
+ height: "22",
1567
+ fill: "white",
1568
+ transform: "translate(19.5 19.0039)"
1569
+ }
1570
+ )))
1571
+ ), /* @__PURE__ */ React6.createElement("h1", null, "Success!"), /* @__PURE__ */ React6.createElement("h4", null, "Payment link created successfully.")), /* @__PURE__ */ React6.createElement(Modal3.Footer, null, /* @__PURE__ */ React6.createElement("button", { className: "paymentBtn", onClick: handleClose }, "Ok"))));
1572
+ }
1573
+
1293
1574
  // src/app/components/RequestPayment/RequestPaymentonClick.tsx
1294
1575
  import React7, { useState as useState4 } from "react";
1295
1576
  import { Modal as Modal4 } from "react-bootstrap";
1577
+ function RequestPaymentonClick(props) {
1578
+ const [isLoading, setIsLoading] = useState4(false);
1579
+ const [show, setShow] = useState4(false);
1580
+ const handleClose = () => setShow(false);
1581
+ const handleShow = () => setShow(true);
1582
+ const { fractalpayClientKey, amount, phone_number, orderID, onSuccess, onError } = props;
1583
+ const sendRequestPayment = () => {
1584
+ setIsLoading(true);
1585
+ let formData = {
1586
+ fractalpayPublicKey: fractalpayClientKey,
1587
+ amount,
1588
+ phone_number,
1589
+ orderId: orderID,
1590
+ action: "request"
1591
+ };
1592
+ const jsonData = JSON.stringify(formData);
1593
+ fetch(`${baseUrl}create-widget-order`, {
1594
+ method: "POST",
1595
+ headers: {
1596
+ "Content-Type": "application/json"
1597
+ },
1598
+ body: jsonData
1599
+ }).then((response) => {
1600
+ setIsLoading(false);
1601
+ if (!response.ok) {
1602
+ throw new Error(ErrorText.networkresponseerror);
1603
+ }
1604
+ return response.json();
1605
+ }).then((data) => {
1606
+ setShow(true);
1607
+ console.log(data);
1608
+ }).catch((error) => {
1609
+ setIsLoading(false);
1610
+ console.error("Error:", error);
1611
+ });
1612
+ };
1613
+ return /* @__PURE__ */ React7.createElement(React7.Fragment, null, /* @__PURE__ */ React7.createElement(RequestPaymentstyles_default, null), /* @__PURE__ */ React7.createElement(
1614
+ "button",
1615
+ {
1616
+ onClick: sendRequestPayment,
1617
+ disabled: isLoading,
1618
+ className: "paymentBtn"
1619
+ },
1620
+ isLoading ? "Loading..." : "Request Payment"
1621
+ ), /* @__PURE__ */ React7.createElement(Modal4, { className: "payment-suc", show, onHide: handleClose }, /* @__PURE__ */ React7.createElement(Modal4.Header, { closeButton: true }), /* @__PURE__ */ React7.createElement(Modal4.Body, null, onSuccess && /* @__PURE__ */ React7.createElement(
1622
+ "svg",
1623
+ {
1624
+ width: "60",
1625
+ height: "60",
1626
+ viewBox: "0 0 60 60",
1627
+ fill: "none",
1628
+ xmlns: "http://www.w3.org/2000/svg"
1629
+ },
1630
+ /* @__PURE__ */ React7.createElement(
1631
+ "rect",
1632
+ {
1633
+ x: "0.5",
1634
+ y: "0.5",
1635
+ width: "59",
1636
+ height: "59",
1637
+ rx: "29.5",
1638
+ stroke: "#31B379"
1639
+ }
1640
+ ),
1641
+ /* @__PURE__ */ React7.createElement("g", { clipPath: "url(#clip0_2659_5018)" }, /* @__PURE__ */ React7.createElement(
1642
+ "path",
1643
+ {
1644
+ d: "M41.1778 22.248C40.7483 21.8184 40.0518 21.8184 39.6222 22.248L26.4435 35.4268L21.3778 30.3611C20.9483 29.9315 20.2518 29.9316 19.8222 30.3611C19.3926 30.7907 19.3926 31.4871 19.8222 31.9167L25.6657 37.7601C26.0951 38.1897 26.7921 38.1894 27.2213 37.7601L41.1778 23.8036C41.6074 23.3741 41.6074 22.6776 41.1778 22.248Z",
1645
+ fill: "#31B379"
1646
+ }
1647
+ )),
1648
+ /* @__PURE__ */ React7.createElement("defs", null, /* @__PURE__ */ React7.createElement("clipPath", { id: "clip0_2659_5018" }, /* @__PURE__ */ React7.createElement(
1649
+ "rect",
1650
+ {
1651
+ width: "22",
1652
+ height: "22",
1653
+ fill: "white",
1654
+ transform: "translate(19.5 19.0039)"
1655
+ }
1656
+ )))
1657
+ ), onSuccess ? /* @__PURE__ */ React7.createElement(React7.Fragment, null, /* @__PURE__ */ React7.createElement("h1", null, "Success!"), /* @__PURE__ */ React7.createElement("h4", null, onSuccess)) : /* @__PURE__ */ React7.createElement(React7.Fragment, null, /* @__PURE__ */ React7.createElement("h1", null, "Error!"), /* @__PURE__ */ React7.createElement("h4", null, onError))), /* @__PURE__ */ React7.createElement(Modal4.Footer, null, /* @__PURE__ */ React7.createElement("button", { className: "paymentBtn", onClick: handleClose }, "Ok"))));
1658
+ }
1296
1659
  export {
1297
- RequestPayment
1660
+ RequestPayment,
1661
+ RequestPaymentAllInput,
1662
+ RequestPaymentDynamic,
1663
+ RequestPaymentonClick
1298
1664
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pinerohit11/testwidget",
3
- "version": "0.1.40",
3
+ "version": "0.1.41",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "dev": "next dev",