straumur-web-component 0.3.1 → 0.3.6

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/dist/index.cjs CHANGED
@@ -1020,8 +1020,12 @@ function CardComponent({ configuration, paymentMethods }) {
1020
1020
  const initializeAdyenComponent = async () => {
1021
1021
  adyenCardRef.current = await (0, import_adyen_web.AdyenCheckout)({
1022
1022
  clientKey: paymentMethods.clientKey,
1023
- locale: configuration.locale,
1024
1023
  environment: configuration.environment,
1024
+ amount: {
1025
+ value: paymentMethods.minorUnitsAmount,
1026
+ currency: paymentMethods.currency
1027
+ },
1028
+ locale: configuration.locale,
1025
1029
  countryCode: "IS",
1026
1030
  paymentMethodsResponse: paymentMethods.paymentMethods,
1027
1031
  onError: handleOnError,
@@ -1329,6 +1333,9 @@ var GooglePayIcon = () => /* @__PURE__ */ (0, import_preact18.h)(
1329
1333
  );
1330
1334
  var googlepay_default = GooglePayIcon;
1331
1335
 
1336
+ // src/models/constants.ts
1337
+ var CANCEL = "CANCEL";
1338
+
1332
1339
  // src/features/google-pay/google-pay-component.tsx
1333
1340
  function GooglePayComponent({ configuration, paymentMethods }) {
1334
1341
  const googlePayElementRef = (0, import_hooks5.useRef)(null);
@@ -1347,12 +1354,15 @@ function GooglePayComponent({ configuration, paymentMethods }) {
1347
1354
  const initializeAdyenComponent = async () => {
1348
1355
  adyenCardRef.current = await (0, import_adyen_web2.AdyenCheckout)({
1349
1356
  clientKey: paymentMethods.clientKey,
1350
- locale: paymentMethods.locale,
1351
1357
  environment: configuration.environment,
1358
+ locale: paymentMethods.locale,
1352
1359
  countryCode: "IS",
1353
- onError: handleOnError,
1354
- onSubmit: handleOnSubmit,
1360
+ amount: {
1361
+ value: paymentMethods.minorUnitsAmount,
1362
+ currency: paymentMethods.currency
1363
+ },
1355
1364
  onAdditionalDetails: handleOnSubmitAdditionalData,
1365
+ onError: handleOnError,
1356
1366
  onPaymentCompleted: configuration.onPaymentCompleted,
1357
1367
  onPaymentFailed: configuration.onPaymentFailed
1358
1368
  });
@@ -1364,6 +1374,7 @@ function GooglePayComponent({ configuration, paymentMethods }) {
1364
1374
  },
1365
1375
  countryCode: "IS",
1366
1376
  environment: configuration.environment,
1377
+ onSubmit: handleOnSubmit,
1367
1378
  configuration: {
1368
1379
  ...gpayConfig,
1369
1380
  merchantName: paymentMethods.merchantName
@@ -1373,7 +1384,7 @@ function GooglePayComponent({ configuration, paymentMethods }) {
1373
1384
  googlePayRef.current.isAvailable().then(() => {
1374
1385
  googlePayRef.current.mount(googlePayElementRef.current);
1375
1386
  updatePaymentMethodInitialization("googlepay", true);
1376
- }).catch((e) => {
1387
+ }).catch(() => {
1377
1388
  handleError("error.googlePayNotAvailable");
1378
1389
  });
1379
1390
  };
@@ -1390,8 +1401,10 @@ function GooglePayComponent({ configuration, paymentMethods }) {
1390
1401
  const handleBoxChange = () => {
1391
1402
  setActivePaymentMethod("googlepay");
1392
1403
  };
1393
- function handleOnError(_, __) {
1394
- handleError("error.unknownError");
1404
+ function handleOnError(data, __) {
1405
+ if (data.name !== CANCEL) {
1406
+ handleError("error.unknownError");
1407
+ }
1395
1408
  }
1396
1409
  async function handleOnSubmit(state, _, actions) {
1397
1410
  const data = {
@@ -1415,6 +1428,7 @@ function GooglePayComponent({ configuration, paymentMethods }) {
1415
1428
  if (resultCode === "RedirectShopper" || resultCode === "IdentifyShopper") {
1416
1429
  setThreeDSecureActive(true);
1417
1430
  adyenCardRef.current.createFromAction(action).mount(threeDSecureRef?.current);
1431
+ actions.resolve({});
1418
1432
  return;
1419
1433
  }
1420
1434
  actions.resolve({ resultCode, action });
@@ -1516,16 +1530,19 @@ function ApplePayComponent({ configuration, paymentMethods }) {
1516
1530
  const initializeAdyenComponent = async () => {
1517
1531
  adyenCardRef.current = await (0, import_adyen_web3.AdyenCheckout)({
1518
1532
  clientKey: paymentMethods.clientKey,
1519
- locale: paymentMethods.locale,
1520
1533
  environment: configuration.environment,
1534
+ locale: paymentMethods.locale,
1521
1535
  countryCode: "IS",
1522
- onError: handleOnError,
1523
- onSubmit: handleOnSubmit,
1536
+ amount: {
1537
+ value: paymentMethods.minorUnitsAmount,
1538
+ currency: paymentMethods.currency
1539
+ },
1524
1540
  onAdditionalDetails: handleOnSubmitAdditionalData,
1541
+ onError: handleOnError,
1525
1542
  onPaymentCompleted: configuration.onPaymentCompleted,
1526
1543
  onPaymentFailed: configuration.onPaymentFailed
1527
1544
  });
1528
- const gpayConfig = paymentMethods.paymentMethods.paymentMethods.find((x) => x.type === "applepay").configuration;
1545
+ const apayConfig = paymentMethods.paymentMethods.paymentMethods.find((x) => x.type === "applepay").configuration;
1529
1546
  const applePayConfiguration = {
1530
1547
  amount: {
1531
1548
  value: paymentMethods.minorUnitsAmount,
@@ -1533,16 +1550,16 @@ function ApplePayComponent({ configuration, paymentMethods }) {
1533
1550
  },
1534
1551
  environment: configuration.environment,
1535
1552
  configuration: {
1536
- ...gpayConfig,
1553
+ ...apayConfig,
1537
1554
  merchantName: paymentMethods.merchantName
1538
- }
1555
+ },
1556
+ onSubmit: handleOnSubmit
1539
1557
  };
1540
1558
  applePayRef.current = new import_adyen_web3.ApplePay(adyenCardRef.current, applePayConfiguration);
1541
1559
  applePayRef.current.isAvailable().then(() => {
1542
1560
  applePayRef.current.mount(applePayElementRef.current);
1543
1561
  updatePaymentMethodInitialization("applepay", true);
1544
- }).catch((e) => {
1545
- console.log(e);
1562
+ }).catch(() => {
1546
1563
  handleError("error.applePayNotAvailable");
1547
1564
  });
1548
1565
  };
@@ -1559,8 +1576,10 @@ function ApplePayComponent({ configuration, paymentMethods }) {
1559
1576
  const handleBoxChange = () => {
1560
1577
  setActivePaymentMethod("applepay");
1561
1578
  };
1562
- function handleOnError(_, __) {
1563
- handleError("error.unknownError");
1579
+ function handleOnError(data, _) {
1580
+ if (data.name !== CANCEL) {
1581
+ handleError("error.unknownError");
1582
+ }
1564
1583
  }
1565
1584
  async function handleOnSubmit(state, _, actions) {
1566
1585
  const data = {
@@ -1584,6 +1603,7 @@ function ApplePayComponent({ configuration, paymentMethods }) {
1584
1603
  if (resultCode === "RedirectShopper" || resultCode === "IdentifyShopper") {
1585
1604
  setThreeDSecureActive(true);
1586
1605
  adyenCardRef.current.createFromAction(action).mount(threeDSecureRef?.current);
1606
+ actions.resolve({});
1587
1607
  return;
1588
1608
  }
1589
1609
  actions.resolve({ resultCode, action });
@@ -1696,9 +1716,13 @@ function StoredCardComponent({
1696
1716
  const initializeAdyenComponent = async () => {
1697
1717
  adyenCardRef.current = await (0, import_adyen_web4.AdyenCheckout)({
1698
1718
  clientKey: paymentMethods.clientKey,
1699
- locale: configuration.locale,
1700
1719
  environment: configuration.environment,
1720
+ locale: configuration.locale,
1701
1721
  countryCode: "IS",
1722
+ amount: {
1723
+ value: paymentMethods.minorUnitsAmount,
1724
+ currency: paymentMethods.currency
1725
+ },
1702
1726
  paymentMethodsResponse: paymentMethods.paymentMethods,
1703
1727
  onError: handleOnError,
1704
1728
  onSubmit: handleOnSubmit,
@@ -2131,7 +2155,17 @@ var StraumurCheckout = class {
2131
2155
  paymentMethods = null;
2132
2156
  mountElement = null;
2133
2157
  constructor(config) {
2134
- this.configuration = { ...config, locale: config.locale || "en-US" };
2158
+ this.configuration = { ...config, locale: determineLocale(config.locale) };
2159
+ function determineLocale(locale) {
2160
+ switch (locale) {
2161
+ case "is":
2162
+ return "is-IS";
2163
+ case "en":
2164
+ return "en-US";
2165
+ default:
2166
+ return "is-IS";
2167
+ }
2168
+ }
2135
2169
  }
2136
2170
  async mount(selector) {
2137
2171
  try {
package/dist/index.d.cts CHANGED
@@ -77,7 +77,7 @@ type StraumurWebConfiguration = {
77
77
  onPaymentCompleted?: () => void;
78
78
  onPaymentFailed?: () => void;
79
79
  placeholders?: Placeholders;
80
- locale?: Language;
80
+ locale?: "is" | "en";
81
81
  };
82
82
  type StraumurCheckoutConfiguration = {
83
83
  sessionId: string;
package/dist/index.d.ts CHANGED
@@ -77,7 +77,7 @@ type StraumurWebConfiguration = {
77
77
  onPaymentCompleted?: () => void;
78
78
  onPaymentFailed?: () => void;
79
79
  placeholders?: Placeholders;
80
- locale?: Language;
80
+ locale?: "is" | "en";
81
81
  };
82
82
  type StraumurCheckoutConfiguration = {
83
83
  sessionId: string;
package/dist/index.mjs CHANGED
@@ -997,8 +997,12 @@ function CardComponent({ configuration, paymentMethods }) {
997
997
  const initializeAdyenComponent = async () => {
998
998
  adyenCardRef.current = await AdyenCheckout({
999
999
  clientKey: paymentMethods.clientKey,
1000
- locale: configuration.locale,
1001
1000
  environment: configuration.environment,
1001
+ amount: {
1002
+ value: paymentMethods.minorUnitsAmount,
1003
+ currency: paymentMethods.currency
1004
+ },
1005
+ locale: configuration.locale,
1002
1006
  countryCode: "IS",
1003
1007
  paymentMethodsResponse: paymentMethods.paymentMethods,
1004
1008
  onError: handleOnError,
@@ -1309,6 +1313,9 @@ var GooglePayIcon = () => /* @__PURE__ */ h17(
1309
1313
  );
1310
1314
  var googlepay_default = GooglePayIcon;
1311
1315
 
1316
+ // src/models/constants.ts
1317
+ var CANCEL = "CANCEL";
1318
+
1312
1319
  // src/features/google-pay/google-pay-component.tsx
1313
1320
  function GooglePayComponent({ configuration, paymentMethods }) {
1314
1321
  const googlePayElementRef = useRef4(null);
@@ -1327,12 +1334,15 @@ function GooglePayComponent({ configuration, paymentMethods }) {
1327
1334
  const initializeAdyenComponent = async () => {
1328
1335
  adyenCardRef.current = await AdyenCheckout2({
1329
1336
  clientKey: paymentMethods.clientKey,
1330
- locale: paymentMethods.locale,
1331
1337
  environment: configuration.environment,
1338
+ locale: paymentMethods.locale,
1332
1339
  countryCode: "IS",
1333
- onError: handleOnError,
1334
- onSubmit: handleOnSubmit,
1340
+ amount: {
1341
+ value: paymentMethods.minorUnitsAmount,
1342
+ currency: paymentMethods.currency
1343
+ },
1335
1344
  onAdditionalDetails: handleOnSubmitAdditionalData,
1345
+ onError: handleOnError,
1336
1346
  onPaymentCompleted: configuration.onPaymentCompleted,
1337
1347
  onPaymentFailed: configuration.onPaymentFailed
1338
1348
  });
@@ -1344,6 +1354,7 @@ function GooglePayComponent({ configuration, paymentMethods }) {
1344
1354
  },
1345
1355
  countryCode: "IS",
1346
1356
  environment: configuration.environment,
1357
+ onSubmit: handleOnSubmit,
1347
1358
  configuration: {
1348
1359
  ...gpayConfig,
1349
1360
  merchantName: paymentMethods.merchantName
@@ -1353,7 +1364,7 @@ function GooglePayComponent({ configuration, paymentMethods }) {
1353
1364
  googlePayRef.current.isAvailable().then(() => {
1354
1365
  googlePayRef.current.mount(googlePayElementRef.current);
1355
1366
  updatePaymentMethodInitialization("googlepay", true);
1356
- }).catch((e) => {
1367
+ }).catch(() => {
1357
1368
  handleError("error.googlePayNotAvailable");
1358
1369
  });
1359
1370
  };
@@ -1370,8 +1381,10 @@ function GooglePayComponent({ configuration, paymentMethods }) {
1370
1381
  const handleBoxChange = () => {
1371
1382
  setActivePaymentMethod("googlepay");
1372
1383
  };
1373
- function handleOnError(_, __) {
1374
- handleError("error.unknownError");
1384
+ function handleOnError(data, __) {
1385
+ if (data.name !== CANCEL) {
1386
+ handleError("error.unknownError");
1387
+ }
1375
1388
  }
1376
1389
  async function handleOnSubmit(state, _, actions) {
1377
1390
  const data = {
@@ -1395,6 +1408,7 @@ function GooglePayComponent({ configuration, paymentMethods }) {
1395
1408
  if (resultCode === "RedirectShopper" || resultCode === "IdentifyShopper") {
1396
1409
  setThreeDSecureActive(true);
1397
1410
  adyenCardRef.current.createFromAction(action).mount(threeDSecureRef?.current);
1411
+ actions.resolve({});
1398
1412
  return;
1399
1413
  }
1400
1414
  actions.resolve({ resultCode, action });
@@ -1499,16 +1513,19 @@ function ApplePayComponent({ configuration, paymentMethods }) {
1499
1513
  const initializeAdyenComponent = async () => {
1500
1514
  adyenCardRef.current = await AdyenCheckout3({
1501
1515
  clientKey: paymentMethods.clientKey,
1502
- locale: paymentMethods.locale,
1503
1516
  environment: configuration.environment,
1517
+ locale: paymentMethods.locale,
1504
1518
  countryCode: "IS",
1505
- onError: handleOnError,
1506
- onSubmit: handleOnSubmit,
1519
+ amount: {
1520
+ value: paymentMethods.minorUnitsAmount,
1521
+ currency: paymentMethods.currency
1522
+ },
1507
1523
  onAdditionalDetails: handleOnSubmitAdditionalData,
1524
+ onError: handleOnError,
1508
1525
  onPaymentCompleted: configuration.onPaymentCompleted,
1509
1526
  onPaymentFailed: configuration.onPaymentFailed
1510
1527
  });
1511
- const gpayConfig = paymentMethods.paymentMethods.paymentMethods.find((x) => x.type === "applepay").configuration;
1528
+ const apayConfig = paymentMethods.paymentMethods.paymentMethods.find((x) => x.type === "applepay").configuration;
1512
1529
  const applePayConfiguration = {
1513
1530
  amount: {
1514
1531
  value: paymentMethods.minorUnitsAmount,
@@ -1516,16 +1533,16 @@ function ApplePayComponent({ configuration, paymentMethods }) {
1516
1533
  },
1517
1534
  environment: configuration.environment,
1518
1535
  configuration: {
1519
- ...gpayConfig,
1536
+ ...apayConfig,
1520
1537
  merchantName: paymentMethods.merchantName
1521
- }
1538
+ },
1539
+ onSubmit: handleOnSubmit
1522
1540
  };
1523
1541
  applePayRef.current = new ApplePay(adyenCardRef.current, applePayConfiguration);
1524
1542
  applePayRef.current.isAvailable().then(() => {
1525
1543
  applePayRef.current.mount(applePayElementRef.current);
1526
1544
  updatePaymentMethodInitialization("applepay", true);
1527
- }).catch((e) => {
1528
- console.log(e);
1545
+ }).catch(() => {
1529
1546
  handleError("error.applePayNotAvailable");
1530
1547
  });
1531
1548
  };
@@ -1542,8 +1559,10 @@ function ApplePayComponent({ configuration, paymentMethods }) {
1542
1559
  const handleBoxChange = () => {
1543
1560
  setActivePaymentMethod("applepay");
1544
1561
  };
1545
- function handleOnError(_, __) {
1546
- handleError("error.unknownError");
1562
+ function handleOnError(data, _) {
1563
+ if (data.name !== CANCEL) {
1564
+ handleError("error.unknownError");
1565
+ }
1547
1566
  }
1548
1567
  async function handleOnSubmit(state, _, actions) {
1549
1568
  const data = {
@@ -1567,6 +1586,7 @@ function ApplePayComponent({ configuration, paymentMethods }) {
1567
1586
  if (resultCode === "RedirectShopper" || resultCode === "IdentifyShopper") {
1568
1587
  setThreeDSecureActive(true);
1569
1588
  adyenCardRef.current.createFromAction(action).mount(threeDSecureRef?.current);
1589
+ actions.resolve({});
1570
1590
  return;
1571
1591
  }
1572
1592
  actions.resolve({ resultCode, action });
@@ -1682,9 +1702,13 @@ function StoredCardComponent({
1682
1702
  const initializeAdyenComponent = async () => {
1683
1703
  adyenCardRef.current = await AdyenCheckout4({
1684
1704
  clientKey: paymentMethods.clientKey,
1685
- locale: configuration.locale,
1686
1705
  environment: configuration.environment,
1706
+ locale: configuration.locale,
1687
1707
  countryCode: "IS",
1708
+ amount: {
1709
+ value: paymentMethods.minorUnitsAmount,
1710
+ currency: paymentMethods.currency
1711
+ },
1688
1712
  paymentMethodsResponse: paymentMethods.paymentMethods,
1689
1713
  onError: handleOnError,
1690
1714
  onSubmit: handleOnSubmit,
@@ -2117,7 +2141,17 @@ var StraumurCheckout = class {
2117
2141
  paymentMethods = null;
2118
2142
  mountElement = null;
2119
2143
  constructor(config) {
2120
- this.configuration = { ...config, locale: config.locale || "en-US" };
2144
+ this.configuration = { ...config, locale: determineLocale(config.locale) };
2145
+ function determineLocale(locale) {
2146
+ switch (locale) {
2147
+ case "is":
2148
+ return "is-IS";
2149
+ case "en":
2150
+ return "en-US";
2151
+ default:
2152
+ return "is-IS";
2153
+ }
2154
+ }
2121
2155
  }
2122
2156
  async mount(selector) {
2123
2157
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "straumur-web-component",
3
- "version": "0.3.1",
3
+ "version": "0.3.6",
4
4
  "license": "MIT",
5
5
  "homepage": "https://docs.straumur.is",
6
6
  "type": "module",