authscape 1.0.140 → 1.0.141

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/index.js CHANGED
@@ -1178,13 +1178,13 @@ var _Dialog = _interopRequireDefault(require("@mui/material/Dialog"));
1178
1178
  var _DialogActions = _interopRequireDefault(require("@mui/material/DialogActions"));
1179
1179
  var _DialogContent = _interopRequireDefault(require("@mui/material/DialogContent"));
1180
1180
  var _DialogTitle = _interopRequireDefault(require("@mui/material/DialogTitle"));
1181
- var _checkoutForm = _interopRequireDefault(require("./checkoutForm"));
1182
1181
  var _IconButton = _interopRequireDefault(require("@mui/material/IconButton"));
1183
1182
  var _Close = _interopRequireDefault(require("@mui/icons-material/Close"));
1184
1183
  var _Typography = _interopRequireDefault(require("@mui/material/Typography"));
1185
1184
  var _Select = _interopRequireDefault(require("@mui/material/Select"));
1186
1185
  var _MenuItem = _interopRequireDefault(require("@mui/material/MenuItem"));
1187
1186
  var _Grid = _interopRequireDefault(require("@mui/material/Grid"));
1187
+ var _PaymentRounded = _interopRequireDefault(require("@mui/icons-material/PaymentRounded"));
1188
1188
  var _excluded = ["children", "value", "index"];
1189
1189
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
1190
1190
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -1201,36 +1201,217 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
1201
1201
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
1202
1202
  function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
1203
1203
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
1204
- var StripePayment = function StripePayment() {
1205
- var stripePromise = (0, _stripeJs.loadStripe)(process.env.stripePublicKey);
1206
- var _useState = (0, _react.useState)(null),
1204
+ var CheckoutForm = function CheckoutForm(_ref) {
1205
+ var payButtonText = _ref.payButtonText,
1206
+ clientSecret = _ref.clientSecret,
1207
+ onResponse = _ref.onResponse,
1208
+ amount = _ref.amount;
1209
+ var _useState = (0, _react.useState)(false),
1207
1210
  _useState2 = _slicedToArray(_useState, 2),
1208
- options = _useState2[0],
1209
- setOptions = _useState2[1];
1210
- var _useState3 = (0, _react.useState)(0),
1211
+ isPaymentProcessing = _useState2[0],
1212
+ setIsPaymentProcessing = _useState2[1];
1213
+ var stripe = (0, _reactStripeJs.useStripe)();
1214
+ var elements = (0, _reactStripeJs.useElements)();
1215
+ var _useState3 = (0, _react.useState)(null),
1211
1216
  _useState4 = _slicedToArray(_useState3, 2),
1212
- value = _useState4[0],
1213
- setValue = _useState4[1];
1214
- var _useState5 = (0, _react.useState)([]),
1217
+ errorMessage = _useState4[0],
1218
+ setErrorMessage = _useState4[1];
1219
+ var handleSubmit = /*#__PURE__*/function () {
1220
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
1221
+ var _yield$stripe$confirm, error, response, setupIntent, _yield$stripe$confirm2, _error, _response, paymentIntent;
1222
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1223
+ while (1) switch (_context.prev = _context.next) {
1224
+ case 0:
1225
+ setIsPaymentProcessing(true);
1226
+
1227
+ // We don't want to let default form submission happen here,
1228
+ // which would refresh the page.
1229
+ event.preventDefault();
1230
+ if (!(!stripe || !elements)) {
1231
+ _context.next = 4;
1232
+ break;
1233
+ }
1234
+ return _context.abrupt("return");
1235
+ case 4:
1236
+ if (!(amount == null)) {
1237
+ _context.next = 35;
1238
+ break;
1239
+ }
1240
+ _context.next = 7;
1241
+ return stripe.confirmSetup({
1242
+ //`Elements` instance that was used to create the Payment Element
1243
+ elements: elements,
1244
+ redirect: "if_required"
1245
+ // confirmParams: {
1246
+ // return_url: process.env.WebsiteBaseUri + '/confirmSetup?redirectUrl=' + encodeURIComponent(window.location.search),
1247
+ // },
1248
+ });
1249
+ case 7:
1250
+ _yield$stripe$confirm = _context.sent;
1251
+ error = _yield$stripe$confirm.error;
1252
+ if (!error) {
1253
+ _context.next = 14;
1254
+ break;
1255
+ }
1256
+ // This point will only be reached if there is an immediate error when
1257
+ // confirming the payment. Show error to your customer (for example, payment
1258
+ // details incomplete)
1259
+ setIsPaymentProcessing(false);
1260
+ setErrorMessage(error.message);
1261
+ _context.next = 33;
1262
+ break;
1263
+ case 14:
1264
+ // Your customer will be redirected to your `return_url`. For some payment
1265
+ // methods like iDEAL, your customer will be redirected to an intermediate
1266
+ // site first to authorize the payment, then redirected to the `return_url`.
1267
+ //setIsPaymentProcessing(false);
1268
+ response = null;
1269
+ _context.next = 17;
1270
+ return stripe.retrieveSetupIntent(clientSecret);
1271
+ case 17:
1272
+ response = _context.sent;
1273
+ setupIntent = response.setupIntent;
1274
+ _context.t0 = setupIntent.status;
1275
+ _context.next = _context.t0 === 'succeeded' ? 22 : _context.t0 === 'processing' ? 24 : _context.t0 === 'requires_payment_method' ? 27 : 30;
1276
+ break;
1277
+ case 22:
1278
+ // need to store the payment intent with the customer if they are logged in... currentUser
1279
+ onResponse("succeeded", setupIntent.id, setupIntent.payment_method);
1280
+ return _context.abrupt("break", 33);
1281
+ case 24:
1282
+ onResponse("processing", setupIntent.id, setupIntent.payment_method);
1283
+ setIsPaymentProcessing(false);
1284
+ return _context.abrupt("break", 33);
1285
+ case 27:
1286
+ onResponse("requires_payment_method", null);
1287
+ setIsPaymentProcessing(false);
1288
+ return _context.abrupt("break", 33);
1289
+ case 30:
1290
+ onResponse("failed", null);
1291
+ setIsPaymentProcessing(false);
1292
+ return _context.abrupt("break", 33);
1293
+ case 33:
1294
+ _context.next = 69;
1295
+ break;
1296
+ case 35:
1297
+ _context.next = 37;
1298
+ return stripe.confirmPayment({
1299
+ //`Elements` instance that was used to create the Payment Element
1300
+ elements: elements,
1301
+ redirect: "if_required",
1302
+ confirmParams: {
1303
+ return_url: process.env.WebsiteBaseUri + '/confirmPayment?redirectUrl=' + encodeURIComponent(window.location.search)
1304
+ }
1305
+ });
1306
+ case 37:
1307
+ _yield$stripe$confirm2 = _context.sent;
1308
+ _error = _yield$stripe$confirm2.error;
1309
+ if (!_error) {
1310
+ _context.next = 44;
1311
+ break;
1312
+ }
1313
+ // This point will only be reached if there is an immediate error when
1314
+ // confirming the payment. Show error to your customer (for example, payment
1315
+ // details incomplete)
1316
+ setIsPaymentProcessing(false);
1317
+ setErrorMessage(_error.message);
1318
+ _context.next = 69;
1319
+ break;
1320
+ case 44:
1321
+ // Your customer will be redirected to your `return_url`. For some payment
1322
+ // methods like iDEAL, your customer will be redirected to an intermediate
1323
+ // site first to authorize the payment, then redirected to the `return_url`.
1324
+ _response = null;
1325
+ if (!(amount == null)) {
1326
+ _context.next = 51;
1327
+ break;
1328
+ }
1329
+ _context.next = 48;
1330
+ return stripe.retrieveSetupIntent(clientSecret);
1331
+ case 48:
1332
+ _response = _context.sent;
1333
+ _context.next = 54;
1334
+ break;
1335
+ case 51:
1336
+ _context.next = 53;
1337
+ return stripe.retrievePaymentIntent(clientSecret);
1338
+ case 53:
1339
+ _response = _context.sent;
1340
+ case 54:
1341
+ paymentIntent = _response.paymentIntent;
1342
+ _context.t1 = paymentIntent.status;
1343
+ _context.next = _context.t1 === 'succeeded' ? 58 : _context.t1 === 'processing' ? 60 : _context.t1 === 'requires_payment_method' ? 63 : 66;
1344
+ break;
1345
+ case 58:
1346
+ // need to store the payment intent with the customer if they are logged in... currentUser
1347
+ onResponse("succeeded", paymentIntent.id);
1348
+ return _context.abrupt("break", 69);
1349
+ case 60:
1350
+ onResponse("processing", paymentIntent.id);
1351
+ setIsPaymentProcessing(false);
1352
+ return _context.abrupt("break", 69);
1353
+ case 63:
1354
+ onResponse("requires_payment_method", null);
1355
+ setIsPaymentProcessing(false);
1356
+ return _context.abrupt("break", 69);
1357
+ case 66:
1358
+ onResponse("failed", null);
1359
+ setIsPaymentProcessing(false);
1360
+ return _context.abrupt("break", 69);
1361
+ case 69:
1362
+ case "end":
1363
+ return _context.stop();
1364
+ }
1365
+ }, _callee);
1366
+ }));
1367
+ return function handleSubmit(_x2) {
1368
+ return _ref2.apply(this, arguments);
1369
+ };
1370
+ }();
1371
+ return /*#__PURE__*/_react["default"].createElement("form", {
1372
+ onSubmit: handleSubmit
1373
+ }, /*#__PURE__*/_react["default"].createElement(_reactStripeJs.PaymentElement, null), /*#__PURE__*/_react["default"].createElement(Button, {
1374
+ startIcon: /*#__PURE__*/_react["default"].createElement(_PaymentRounded["default"], null),
1375
+ type: "submit",
1376
+ fullWidth: true,
1377
+ variant: "contained",
1378
+ disabled: !stripe || isPaymentProcessing,
1379
+ sx: {
1380
+ marginTop: 2,
1381
+ padding: 2
1382
+ }
1383
+ }, payButtonText), errorMessage && /*#__PURE__*/_react["default"].createElement("div", null, errorMessage));
1384
+ };
1385
+ var StripePayment = function StripePayment() {
1386
+ var stripePromise = (0, _stripeJs.loadStripe)(process.env.stripePublicKey);
1387
+ var _useState5 = (0, _react.useState)(null),
1215
1388
  _useState6 = _slicedToArray(_useState5, 2),
1216
- paymentMethods = _useState6[0],
1217
- setPaymentMethods = _useState6[1];
1218
- var _useState7 = (0, _react.useState)(null),
1389
+ options = _useState6[0],
1390
+ setOptions = _useState6[1];
1391
+ var _useState7 = (0, _react.useState)(0),
1219
1392
  _useState8 = _slicedToArray(_useState7, 2),
1220
- paymentMethod = _useState8[0],
1221
- setPaymentMethod = _useState8[1];
1393
+ value = _useState8[0],
1394
+ setValue = _useState8[1];
1395
+ var _useState9 = (0, _react.useState)([]),
1396
+ _useState10 = _slicedToArray(_useState9, 2),
1397
+ paymentMethods = _useState10[0],
1398
+ setPaymentMethods = _useState10[1];
1399
+ var _useState11 = (0, _react.useState)(null),
1400
+ _useState12 = _slicedToArray(_useState11, 2),
1401
+ paymentMethod = _useState12[0],
1402
+ setPaymentMethod = _useState12[1];
1222
1403
  var paymentMethodOpened = /*#__PURE__*/function () {
1223
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1404
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
1224
1405
  var response, responsePayments;
1225
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1226
- while (1) switch (_context.prev = _context.next) {
1406
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1407
+ while (1) switch (_context2.prev = _context2.next) {
1227
1408
  case 0:
1228
1409
  response = null;
1229
1410
  if (!(currentUser == null)) {
1230
- _context.next = 7;
1411
+ _context2.next = 7;
1231
1412
  break;
1232
1413
  }
1233
- _context.next = 4;
1414
+ _context2.next = 4;
1234
1415
  return apiService().post("/Payment/ConnectCustomerNoAuth", {
1235
1416
  paymentRequestType: paymentRequestType,
1236
1417
  amount: amount,
@@ -1241,11 +1422,11 @@ var StripePayment = function StripePayment() {
1241
1422
  stripeCustomerId: stripeCustomerId
1242
1423
  });
1243
1424
  case 4:
1244
- response = _context.sent;
1245
- _context.next = 10;
1425
+ response = _context2.sent;
1426
+ _context2.next = 10;
1246
1427
  break;
1247
1428
  case 7:
1248
- _context.next = 9;
1429
+ _context2.next = 9;
1249
1430
  return apiService().post("/Payment/ConnectCustomer", {
1250
1431
  paymentRequestType: paymentRequestType,
1251
1432
  amount: amount,
@@ -1254,19 +1435,19 @@ var StripePayment = function StripePayment() {
1254
1435
  stripeCustomerId: stripeCustomerId
1255
1436
  });
1256
1437
  case 9:
1257
- response = _context.sent;
1438
+ response = _context2.sent;
1258
1439
  case 10:
1259
1440
  if (!(response != null && response.status == 200)) {
1260
- _context.next = 16;
1441
+ _context2.next = 16;
1261
1442
  break;
1262
1443
  }
1263
1444
  setOptions({
1264
1445
  clientSecret: response.data
1265
1446
  });
1266
- _context.next = 14;
1447
+ _context2.next = 14;
1267
1448
  return apiService().get("/Payment/GetPaymentMethods");
1268
1449
  case 14:
1269
- responsePayments = _context.sent;
1450
+ responsePayments = _context2.sent;
1270
1451
  if (responsePayments != null && responsePayments.status == 200) {
1271
1452
  if (responsePayments.data.length > 0) {
1272
1453
  setValue(1);
@@ -1275,12 +1456,12 @@ var StripePayment = function StripePayment() {
1275
1456
  }
1276
1457
  case 16:
1277
1458
  case "end":
1278
- return _context.stop();
1459
+ return _context2.stop();
1279
1460
  }
1280
- }, _callee);
1461
+ }, _callee2);
1281
1462
  }));
1282
1463
  return function paymentMethodOpened() {
1283
- return _ref.apply(this, arguments);
1464
+ return _ref3.apply(this, arguments);
1284
1465
  };
1285
1466
  }();
1286
1467
  (0, _react.useEffect)(function () {
@@ -1297,9 +1478,9 @@ var StripePayment = function StripePayment() {
1297
1478
  'aria-controls': "simple-tabpanel-".concat(index)
1298
1479
  };
1299
1480
  }
1300
- var PaymentMethod = function PaymentMethod(_ref2) {
1301
- var paymentMethod = _ref2.paymentMethod,
1302
- clicked = _ref2.clicked;
1481
+ var PaymentMethod = function PaymentMethod(_ref4) {
1482
+ var paymentMethod = _ref4.paymentMethod,
1483
+ clicked = _ref4.clicked;
1303
1484
  return /*#__PURE__*/_react["default"].createElement(_Box["default"], {
1304
1485
  fullWidth: true,
1305
1486
  sx: {
@@ -1435,7 +1616,7 @@ var StripePayment = function StripePayment() {
1435
1616
  }, options != null && process.env.stripePublicKey != null && /*#__PURE__*/_react["default"].createElement(_reactStripeJs.Elements, {
1436
1617
  stripe: stripePromise,
1437
1618
  options: options
1438
- }, /*#__PURE__*/_react["default"].createElement(_checkoutForm["default"], {
1619
+ }, /*#__PURE__*/_react["default"].createElement(CheckoutForm, {
1439
1620
  payButtonText: payButtonText,
1440
1621
  clientSecret: options != null ? options.clientSecret : null,
1441
1622
  onResponse: onResponse,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authscape",
3
- "version": "1.0.140",
3
+ "version": "1.0.141",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,18 +1,172 @@
1
1
  import React, {useEffect, useState} from 'react';
2
- import {Elements} from '@stripe/react-stripe-js';
2
+ import {Elements, useStripe, useElements, PaymentElement} from '@stripe/react-stripe-js';
3
3
  import {loadStripe} from '@stripe/stripe-js';
4
4
  import Box from '@mui/material/Box';
5
5
  import Dialog from '@mui/material/Dialog';
6
6
  import DialogActions from '@mui/material/DialogActions';
7
7
  import DialogContent from '@mui/material/DialogContent';
8
8
  import DialogTitle from '@mui/material/DialogTitle';
9
- import CheckoutForm from './checkoutForm';
10
9
  import IconButton from '@mui/material/IconButton';
11
10
  import CloseIcon from '@mui/icons-material/Close';
12
11
  import Typography from '@mui/material/Typography';
13
12
  import Select from '@mui/material/Select';
14
13
  import MenuItem from '@mui/material/MenuItem';
15
14
  import Grid from '@mui/material/Grid';
15
+ import PaymentRoundedIcon from '@mui/icons-material/PaymentRounded';
16
+
17
+
18
+ const CheckoutForm = ({payButtonText, clientSecret, onResponse, amount}) => {
19
+
20
+ const [isPaymentProcessing, setIsPaymentProcessing] = useState(false);
21
+
22
+ const stripe = useStripe();
23
+ const elements = useElements();
24
+
25
+ const [errorMessage, setErrorMessage] = useState(null);
26
+
27
+ const handleSubmit = async (event) => {
28
+
29
+ setIsPaymentProcessing(true);
30
+
31
+ // We don't want to let default form submission happen here,
32
+ // which would refresh the page.
33
+ event.preventDefault();
34
+
35
+ if (!stripe || !elements) {
36
+ // Stripe.js has not yet loaded.
37
+ // Make sure to disable form submission until Stripe.js has loaded.
38
+
39
+ //setIsPaymentProcessing(false);
40
+ return;
41
+ }
42
+
43
+
44
+ if (amount == null)
45
+ {
46
+ const {error} = await stripe.confirmSetup({
47
+ //`Elements` instance that was used to create the Payment Element
48
+ elements,
49
+ redirect:"if_required",
50
+ // confirmParams: {
51
+ // return_url: process.env.WebsiteBaseUri + '/confirmSetup?redirectUrl=' + encodeURIComponent(window.location.search),
52
+ // },
53
+ });
54
+
55
+ if (error) {
56
+ // This point will only be reached if there is an immediate error when
57
+ // confirming the payment. Show error to your customer (for example, payment
58
+ // details incomplete)
59
+ setIsPaymentProcessing(false);
60
+ setErrorMessage(error.message);
61
+ } else {
62
+ // Your customer will be redirected to your `return_url`. For some payment
63
+ // methods like iDEAL, your customer will be redirected to an intermediate
64
+ // site first to authorize the payment, then redirected to the `return_url`.
65
+
66
+ //setIsPaymentProcessing(false);
67
+
68
+ let response = null;
69
+
70
+ response = await stripe.retrieveSetupIntent(clientSecret);
71
+
72
+ let setupIntent = response.setupIntent;
73
+
74
+ switch (setupIntent.status) {
75
+ case 'succeeded':
76
+
77
+ // need to store the payment intent with the customer if they are logged in... currentUser
78
+ onResponse("succeeded", setupIntent.id, setupIntent.payment_method);
79
+ break;
80
+
81
+ case 'processing':
82
+ onResponse("processing", setupIntent.id, setupIntent.payment_method);
83
+ setIsPaymentProcessing(false);
84
+ break;
85
+
86
+ case 'requires_payment_method':
87
+ onResponse("requires_payment_method", null);
88
+ setIsPaymentProcessing(false);
89
+ break;
90
+
91
+ default:
92
+ onResponse("failed", null);
93
+ setIsPaymentProcessing(false);
94
+ break;
95
+ }
96
+ }
97
+
98
+ }
99
+ else
100
+ {
101
+ const {error} = await stripe.confirmPayment({
102
+ //`Elements` instance that was used to create the Payment Element
103
+ elements,
104
+ redirect:"if_required",
105
+ confirmParams: {
106
+ return_url: process.env.WebsiteBaseUri + '/confirmPayment?redirectUrl=' + encodeURIComponent(window.location.search),
107
+ },
108
+ });
109
+
110
+ if (error) {
111
+ // This point will only be reached if there is an immediate error when
112
+ // confirming the payment. Show error to your customer (for example, payment
113
+ // details incomplete)
114
+ setIsPaymentProcessing(false);
115
+ setErrorMessage(error.message);
116
+ } else {
117
+ // Your customer will be redirected to your `return_url`. For some payment
118
+ // methods like iDEAL, your customer will be redirected to an intermediate
119
+ // site first to authorize the payment, then redirected to the `return_url`.
120
+
121
+ let response = null;
122
+
123
+ if (amount == null)
124
+ {
125
+ response = await stripe.retrieveSetupIntent(clientSecret);
126
+ }
127
+ else
128
+ {
129
+ response = await stripe.retrievePaymentIntent(clientSecret);
130
+ }
131
+
132
+ let paymentIntent = response.paymentIntent;
133
+
134
+ switch (paymentIntent.status) {
135
+ case 'succeeded':
136
+
137
+ // need to store the payment intent with the customer if they are logged in... currentUser
138
+ onResponse("succeeded", paymentIntent.id);
139
+ break;
140
+
141
+ case 'processing':
142
+ onResponse("processing", paymentIntent.id);
143
+ setIsPaymentProcessing(false);
144
+ break;
145
+
146
+ case 'requires_payment_method':
147
+ onResponse("requires_payment_method", null);
148
+ setIsPaymentProcessing(false);
149
+ break;
150
+
151
+ default:
152
+ onResponse("failed", null);
153
+ setIsPaymentProcessing(false);
154
+ break;
155
+ }
156
+
157
+
158
+ }
159
+ }
160
+ };
161
+
162
+ return (
163
+ <form onSubmit={handleSubmit}>
164
+ <PaymentElement />
165
+ <Button startIcon={<PaymentRoundedIcon/>} type="submit" fullWidth={true} variant="contained" disabled={(!stripe || isPaymentProcessing)} sx={{marginTop:2, padding:2}}>{payButtonText}</Button>
166
+ {errorMessage && <div>{errorMessage}</div>}
167
+ </form>
168
+ )
169
+ };
16
170
 
17
171
  export const StripePayment = () => {
18
172