authscape 1.0.140 → 1.0.142
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 +219 -37
- package/package.json +1 -1
- package/src/components/GoogleMapsAutoComplete.js +2 -2
- package/src/components/StripePayment.js +156 -2
package/index.js
CHANGED
|
@@ -717,7 +717,7 @@ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" =
|
|
|
717
717
|
Object.defineProperty(exports, "__esModule", {
|
|
718
718
|
value: true
|
|
719
719
|
});
|
|
720
|
-
exports
|
|
720
|
+
exports.GooglePlacesModal = void 0;
|
|
721
721
|
var _react = _interopRequireWildcard(require("react"));
|
|
722
722
|
var _Button = _interopRequireDefault(require("@mui/material/Button"));
|
|
723
723
|
var _system = require("@mui/system");
|
|
@@ -994,7 +994,7 @@ var AutoCompleteDialog = function AutoCompleteDialog(_ref) {
|
|
|
994
994
|
}
|
|
995
995
|
}, renderSuggestions()));
|
|
996
996
|
};
|
|
997
|
-
function GooglePlacesModal(_ref3) {
|
|
997
|
+
var GooglePlacesModal = function GooglePlacesModal(_ref3) {
|
|
998
998
|
var onSave = _ref3.onSave,
|
|
999
999
|
_ref3$createButtonTex = _ref3.createButtonText,
|
|
1000
1000
|
createButtonText = _ref3$createButtonTex === void 0 ? "Save" : _ref3$createButtonTex;
|
|
@@ -1104,7 +1104,8 @@ function GooglePlacesModal(_ref3) {
|
|
|
1104
1104
|
}, createButtonText))), /*#__PURE__*/_react["default"].createElement(_script["default"], {
|
|
1105
1105
|
src: "https://maps.googleapis.com/maps/api/js?key=" + process.env.googleMapsKey + "&libraries=places"
|
|
1106
1106
|
}));
|
|
1107
|
-
}
|
|
1107
|
+
};
|
|
1108
|
+
exports.GooglePlacesModal = GooglePlacesModal;
|
|
1108
1109
|
"use strict";
|
|
1109
1110
|
|
|
1110
1111
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
@@ -1178,13 +1179,13 @@ var _Dialog = _interopRequireDefault(require("@mui/material/Dialog"));
|
|
|
1178
1179
|
var _DialogActions = _interopRequireDefault(require("@mui/material/DialogActions"));
|
|
1179
1180
|
var _DialogContent = _interopRequireDefault(require("@mui/material/DialogContent"));
|
|
1180
1181
|
var _DialogTitle = _interopRequireDefault(require("@mui/material/DialogTitle"));
|
|
1181
|
-
var _checkoutForm = _interopRequireDefault(require("./checkoutForm"));
|
|
1182
1182
|
var _IconButton = _interopRequireDefault(require("@mui/material/IconButton"));
|
|
1183
1183
|
var _Close = _interopRequireDefault(require("@mui/icons-material/Close"));
|
|
1184
1184
|
var _Typography = _interopRequireDefault(require("@mui/material/Typography"));
|
|
1185
1185
|
var _Select = _interopRequireDefault(require("@mui/material/Select"));
|
|
1186
1186
|
var _MenuItem = _interopRequireDefault(require("@mui/material/MenuItem"));
|
|
1187
1187
|
var _Grid = _interopRequireDefault(require("@mui/material/Grid"));
|
|
1188
|
+
var _PaymentRounded = _interopRequireDefault(require("@mui/icons-material/PaymentRounded"));
|
|
1188
1189
|
var _excluded = ["children", "value", "index"];
|
|
1189
1190
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
1190
1191
|
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 +1202,217 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
1201
1202
|
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
1203
|
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
1204
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
1204
|
-
var
|
|
1205
|
-
var
|
|
1206
|
-
|
|
1205
|
+
var CheckoutForm = function CheckoutForm(_ref) {
|
|
1206
|
+
var payButtonText = _ref.payButtonText,
|
|
1207
|
+
clientSecret = _ref.clientSecret,
|
|
1208
|
+
onResponse = _ref.onResponse,
|
|
1209
|
+
amount = _ref.amount;
|
|
1210
|
+
var _useState = (0, _react.useState)(false),
|
|
1207
1211
|
_useState2 = _slicedToArray(_useState, 2),
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
var
|
|
1212
|
+
isPaymentProcessing = _useState2[0],
|
|
1213
|
+
setIsPaymentProcessing = _useState2[1];
|
|
1214
|
+
var stripe = (0, _reactStripeJs.useStripe)();
|
|
1215
|
+
var elements = (0, _reactStripeJs.useElements)();
|
|
1216
|
+
var _useState3 = (0, _react.useState)(null),
|
|
1211
1217
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
var
|
|
1218
|
+
errorMessage = _useState4[0],
|
|
1219
|
+
setErrorMessage = _useState4[1];
|
|
1220
|
+
var handleSubmit = /*#__PURE__*/function () {
|
|
1221
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
|
|
1222
|
+
var _yield$stripe$confirm, error, response, setupIntent, _yield$stripe$confirm2, _error, _response, paymentIntent;
|
|
1223
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1224
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1225
|
+
case 0:
|
|
1226
|
+
setIsPaymentProcessing(true);
|
|
1227
|
+
|
|
1228
|
+
// We don't want to let default form submission happen here,
|
|
1229
|
+
// which would refresh the page.
|
|
1230
|
+
event.preventDefault();
|
|
1231
|
+
if (!(!stripe || !elements)) {
|
|
1232
|
+
_context.next = 4;
|
|
1233
|
+
break;
|
|
1234
|
+
}
|
|
1235
|
+
return _context.abrupt("return");
|
|
1236
|
+
case 4:
|
|
1237
|
+
if (!(amount == null)) {
|
|
1238
|
+
_context.next = 35;
|
|
1239
|
+
break;
|
|
1240
|
+
}
|
|
1241
|
+
_context.next = 7;
|
|
1242
|
+
return stripe.confirmSetup({
|
|
1243
|
+
//`Elements` instance that was used to create the Payment Element
|
|
1244
|
+
elements: elements,
|
|
1245
|
+
redirect: "if_required"
|
|
1246
|
+
// confirmParams: {
|
|
1247
|
+
// return_url: process.env.WebsiteBaseUri + '/confirmSetup?redirectUrl=' + encodeURIComponent(window.location.search),
|
|
1248
|
+
// },
|
|
1249
|
+
});
|
|
1250
|
+
case 7:
|
|
1251
|
+
_yield$stripe$confirm = _context.sent;
|
|
1252
|
+
error = _yield$stripe$confirm.error;
|
|
1253
|
+
if (!error) {
|
|
1254
|
+
_context.next = 14;
|
|
1255
|
+
break;
|
|
1256
|
+
}
|
|
1257
|
+
// This point will only be reached if there is an immediate error when
|
|
1258
|
+
// confirming the payment. Show error to your customer (for example, payment
|
|
1259
|
+
// details incomplete)
|
|
1260
|
+
setIsPaymentProcessing(false);
|
|
1261
|
+
setErrorMessage(error.message);
|
|
1262
|
+
_context.next = 33;
|
|
1263
|
+
break;
|
|
1264
|
+
case 14:
|
|
1265
|
+
// Your customer will be redirected to your `return_url`. For some payment
|
|
1266
|
+
// methods like iDEAL, your customer will be redirected to an intermediate
|
|
1267
|
+
// site first to authorize the payment, then redirected to the `return_url`.
|
|
1268
|
+
//setIsPaymentProcessing(false);
|
|
1269
|
+
response = null;
|
|
1270
|
+
_context.next = 17;
|
|
1271
|
+
return stripe.retrieveSetupIntent(clientSecret);
|
|
1272
|
+
case 17:
|
|
1273
|
+
response = _context.sent;
|
|
1274
|
+
setupIntent = response.setupIntent;
|
|
1275
|
+
_context.t0 = setupIntent.status;
|
|
1276
|
+
_context.next = _context.t0 === 'succeeded' ? 22 : _context.t0 === 'processing' ? 24 : _context.t0 === 'requires_payment_method' ? 27 : 30;
|
|
1277
|
+
break;
|
|
1278
|
+
case 22:
|
|
1279
|
+
// need to store the payment intent with the customer if they are logged in... currentUser
|
|
1280
|
+
onResponse("succeeded", setupIntent.id, setupIntent.payment_method);
|
|
1281
|
+
return _context.abrupt("break", 33);
|
|
1282
|
+
case 24:
|
|
1283
|
+
onResponse("processing", setupIntent.id, setupIntent.payment_method);
|
|
1284
|
+
setIsPaymentProcessing(false);
|
|
1285
|
+
return _context.abrupt("break", 33);
|
|
1286
|
+
case 27:
|
|
1287
|
+
onResponse("requires_payment_method", null);
|
|
1288
|
+
setIsPaymentProcessing(false);
|
|
1289
|
+
return _context.abrupt("break", 33);
|
|
1290
|
+
case 30:
|
|
1291
|
+
onResponse("failed", null);
|
|
1292
|
+
setIsPaymentProcessing(false);
|
|
1293
|
+
return _context.abrupt("break", 33);
|
|
1294
|
+
case 33:
|
|
1295
|
+
_context.next = 69;
|
|
1296
|
+
break;
|
|
1297
|
+
case 35:
|
|
1298
|
+
_context.next = 37;
|
|
1299
|
+
return stripe.confirmPayment({
|
|
1300
|
+
//`Elements` instance that was used to create the Payment Element
|
|
1301
|
+
elements: elements,
|
|
1302
|
+
redirect: "if_required",
|
|
1303
|
+
confirmParams: {
|
|
1304
|
+
return_url: process.env.WebsiteBaseUri + '/confirmPayment?redirectUrl=' + encodeURIComponent(window.location.search)
|
|
1305
|
+
}
|
|
1306
|
+
});
|
|
1307
|
+
case 37:
|
|
1308
|
+
_yield$stripe$confirm2 = _context.sent;
|
|
1309
|
+
_error = _yield$stripe$confirm2.error;
|
|
1310
|
+
if (!_error) {
|
|
1311
|
+
_context.next = 44;
|
|
1312
|
+
break;
|
|
1313
|
+
}
|
|
1314
|
+
// This point will only be reached if there is an immediate error when
|
|
1315
|
+
// confirming the payment. Show error to your customer (for example, payment
|
|
1316
|
+
// details incomplete)
|
|
1317
|
+
setIsPaymentProcessing(false);
|
|
1318
|
+
setErrorMessage(_error.message);
|
|
1319
|
+
_context.next = 69;
|
|
1320
|
+
break;
|
|
1321
|
+
case 44:
|
|
1322
|
+
// Your customer will be redirected to your `return_url`. For some payment
|
|
1323
|
+
// methods like iDEAL, your customer will be redirected to an intermediate
|
|
1324
|
+
// site first to authorize the payment, then redirected to the `return_url`.
|
|
1325
|
+
_response = null;
|
|
1326
|
+
if (!(amount == null)) {
|
|
1327
|
+
_context.next = 51;
|
|
1328
|
+
break;
|
|
1329
|
+
}
|
|
1330
|
+
_context.next = 48;
|
|
1331
|
+
return stripe.retrieveSetupIntent(clientSecret);
|
|
1332
|
+
case 48:
|
|
1333
|
+
_response = _context.sent;
|
|
1334
|
+
_context.next = 54;
|
|
1335
|
+
break;
|
|
1336
|
+
case 51:
|
|
1337
|
+
_context.next = 53;
|
|
1338
|
+
return stripe.retrievePaymentIntent(clientSecret);
|
|
1339
|
+
case 53:
|
|
1340
|
+
_response = _context.sent;
|
|
1341
|
+
case 54:
|
|
1342
|
+
paymentIntent = _response.paymentIntent;
|
|
1343
|
+
_context.t1 = paymentIntent.status;
|
|
1344
|
+
_context.next = _context.t1 === 'succeeded' ? 58 : _context.t1 === 'processing' ? 60 : _context.t1 === 'requires_payment_method' ? 63 : 66;
|
|
1345
|
+
break;
|
|
1346
|
+
case 58:
|
|
1347
|
+
// need to store the payment intent with the customer if they are logged in... currentUser
|
|
1348
|
+
onResponse("succeeded", paymentIntent.id);
|
|
1349
|
+
return _context.abrupt("break", 69);
|
|
1350
|
+
case 60:
|
|
1351
|
+
onResponse("processing", paymentIntent.id);
|
|
1352
|
+
setIsPaymentProcessing(false);
|
|
1353
|
+
return _context.abrupt("break", 69);
|
|
1354
|
+
case 63:
|
|
1355
|
+
onResponse("requires_payment_method", null);
|
|
1356
|
+
setIsPaymentProcessing(false);
|
|
1357
|
+
return _context.abrupt("break", 69);
|
|
1358
|
+
case 66:
|
|
1359
|
+
onResponse("failed", null);
|
|
1360
|
+
setIsPaymentProcessing(false);
|
|
1361
|
+
return _context.abrupt("break", 69);
|
|
1362
|
+
case 69:
|
|
1363
|
+
case "end":
|
|
1364
|
+
return _context.stop();
|
|
1365
|
+
}
|
|
1366
|
+
}, _callee);
|
|
1367
|
+
}));
|
|
1368
|
+
return function handleSubmit(_x2) {
|
|
1369
|
+
return _ref2.apply(this, arguments);
|
|
1370
|
+
};
|
|
1371
|
+
}();
|
|
1372
|
+
return /*#__PURE__*/_react["default"].createElement("form", {
|
|
1373
|
+
onSubmit: handleSubmit
|
|
1374
|
+
}, /*#__PURE__*/_react["default"].createElement(_reactStripeJs.PaymentElement, null), /*#__PURE__*/_react["default"].createElement(Button, {
|
|
1375
|
+
startIcon: /*#__PURE__*/_react["default"].createElement(_PaymentRounded["default"], null),
|
|
1376
|
+
type: "submit",
|
|
1377
|
+
fullWidth: true,
|
|
1378
|
+
variant: "contained",
|
|
1379
|
+
disabled: !stripe || isPaymentProcessing,
|
|
1380
|
+
sx: {
|
|
1381
|
+
marginTop: 2,
|
|
1382
|
+
padding: 2
|
|
1383
|
+
}
|
|
1384
|
+
}, payButtonText), errorMessage && /*#__PURE__*/_react["default"].createElement("div", null, errorMessage));
|
|
1385
|
+
};
|
|
1386
|
+
var StripePayment = function StripePayment() {
|
|
1387
|
+
var stripePromise = (0, _stripeJs.loadStripe)(process.env.stripePublicKey);
|
|
1388
|
+
var _useState5 = (0, _react.useState)(null),
|
|
1215
1389
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
var _useState7 = (0, _react.useState)(
|
|
1390
|
+
options = _useState6[0],
|
|
1391
|
+
setOptions = _useState6[1];
|
|
1392
|
+
var _useState7 = (0, _react.useState)(0),
|
|
1219
1393
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
1220
|
-
|
|
1221
|
-
|
|
1394
|
+
value = _useState8[0],
|
|
1395
|
+
setValue = _useState8[1];
|
|
1396
|
+
var _useState9 = (0, _react.useState)([]),
|
|
1397
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
1398
|
+
paymentMethods = _useState10[0],
|
|
1399
|
+
setPaymentMethods = _useState10[1];
|
|
1400
|
+
var _useState11 = (0, _react.useState)(null),
|
|
1401
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
1402
|
+
paymentMethod = _useState12[0],
|
|
1403
|
+
setPaymentMethod = _useState12[1];
|
|
1222
1404
|
var paymentMethodOpened = /*#__PURE__*/function () {
|
|
1223
|
-
var
|
|
1405
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
1224
1406
|
var response, responsePayments;
|
|
1225
|
-
return _regeneratorRuntime().wrap(function
|
|
1226
|
-
while (1) switch (
|
|
1407
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1408
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
1227
1409
|
case 0:
|
|
1228
1410
|
response = null;
|
|
1229
1411
|
if (!(currentUser == null)) {
|
|
1230
|
-
|
|
1412
|
+
_context2.next = 7;
|
|
1231
1413
|
break;
|
|
1232
1414
|
}
|
|
1233
|
-
|
|
1415
|
+
_context2.next = 4;
|
|
1234
1416
|
return apiService().post("/Payment/ConnectCustomerNoAuth", {
|
|
1235
1417
|
paymentRequestType: paymentRequestType,
|
|
1236
1418
|
amount: amount,
|
|
@@ -1241,11 +1423,11 @@ var StripePayment = function StripePayment() {
|
|
|
1241
1423
|
stripeCustomerId: stripeCustomerId
|
|
1242
1424
|
});
|
|
1243
1425
|
case 4:
|
|
1244
|
-
response =
|
|
1245
|
-
|
|
1426
|
+
response = _context2.sent;
|
|
1427
|
+
_context2.next = 10;
|
|
1246
1428
|
break;
|
|
1247
1429
|
case 7:
|
|
1248
|
-
|
|
1430
|
+
_context2.next = 9;
|
|
1249
1431
|
return apiService().post("/Payment/ConnectCustomer", {
|
|
1250
1432
|
paymentRequestType: paymentRequestType,
|
|
1251
1433
|
amount: amount,
|
|
@@ -1254,19 +1436,19 @@ var StripePayment = function StripePayment() {
|
|
|
1254
1436
|
stripeCustomerId: stripeCustomerId
|
|
1255
1437
|
});
|
|
1256
1438
|
case 9:
|
|
1257
|
-
response =
|
|
1439
|
+
response = _context2.sent;
|
|
1258
1440
|
case 10:
|
|
1259
1441
|
if (!(response != null && response.status == 200)) {
|
|
1260
|
-
|
|
1442
|
+
_context2.next = 16;
|
|
1261
1443
|
break;
|
|
1262
1444
|
}
|
|
1263
1445
|
setOptions({
|
|
1264
1446
|
clientSecret: response.data
|
|
1265
1447
|
});
|
|
1266
|
-
|
|
1448
|
+
_context2.next = 14;
|
|
1267
1449
|
return apiService().get("/Payment/GetPaymentMethods");
|
|
1268
1450
|
case 14:
|
|
1269
|
-
responsePayments =
|
|
1451
|
+
responsePayments = _context2.sent;
|
|
1270
1452
|
if (responsePayments != null && responsePayments.status == 200) {
|
|
1271
1453
|
if (responsePayments.data.length > 0) {
|
|
1272
1454
|
setValue(1);
|
|
@@ -1275,12 +1457,12 @@ var StripePayment = function StripePayment() {
|
|
|
1275
1457
|
}
|
|
1276
1458
|
case 16:
|
|
1277
1459
|
case "end":
|
|
1278
|
-
return
|
|
1460
|
+
return _context2.stop();
|
|
1279
1461
|
}
|
|
1280
|
-
},
|
|
1462
|
+
}, _callee2);
|
|
1281
1463
|
}));
|
|
1282
1464
|
return function paymentMethodOpened() {
|
|
1283
|
-
return
|
|
1465
|
+
return _ref3.apply(this, arguments);
|
|
1284
1466
|
};
|
|
1285
1467
|
}();
|
|
1286
1468
|
(0, _react.useEffect)(function () {
|
|
@@ -1297,9 +1479,9 @@ var StripePayment = function StripePayment() {
|
|
|
1297
1479
|
'aria-controls': "simple-tabpanel-".concat(index)
|
|
1298
1480
|
};
|
|
1299
1481
|
}
|
|
1300
|
-
var PaymentMethod = function PaymentMethod(
|
|
1301
|
-
var paymentMethod =
|
|
1302
|
-
clicked =
|
|
1482
|
+
var PaymentMethod = function PaymentMethod(_ref4) {
|
|
1483
|
+
var paymentMethod = _ref4.paymentMethod,
|
|
1484
|
+
clicked = _ref4.clicked;
|
|
1303
1485
|
return /*#__PURE__*/_react["default"].createElement(_Box["default"], {
|
|
1304
1486
|
fullWidth: true,
|
|
1305
1487
|
sx: {
|
|
@@ -1435,7 +1617,7 @@ var StripePayment = function StripePayment() {
|
|
|
1435
1617
|
}, options != null && process.env.stripePublicKey != null && /*#__PURE__*/_react["default"].createElement(_reactStripeJs.Elements, {
|
|
1436
1618
|
stripe: stripePromise,
|
|
1437
1619
|
options: options
|
|
1438
|
-
}, /*#__PURE__*/_react["default"].createElement(
|
|
1620
|
+
}, /*#__PURE__*/_react["default"].createElement(CheckoutForm, {
|
|
1439
1621
|
payButtonText: payButtonText,
|
|
1440
1622
|
clientSecret: options != null ? options.clientSecret : null,
|
|
1441
1623
|
onResponse: onResponse,
|
package/package.json
CHANGED
|
@@ -333,10 +333,10 @@ const AutoCompleteDialog = ({placeholder, onSelected, defaultValue, onChange}) =
|
|
|
333
333
|
);
|
|
334
334
|
};
|
|
335
335
|
|
|
336
|
-
export
|
|
336
|
+
export const GooglePlacesModal = ({
|
|
337
337
|
onSave,
|
|
338
338
|
createButtonText = "Save"
|
|
339
|
-
}) {
|
|
339
|
+
}) => {
|
|
340
340
|
const [address, setAddress] = useState("");
|
|
341
341
|
const [city, setCity] = useState("");
|
|
342
342
|
const [state, setState] = useState("");
|
|
@@ -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
|
|