@reevit/react 0.7.0 → 0.8.0
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.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +67 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -509,8 +509,9 @@ function mapToPaymentIntent(response, config) {
|
|
|
509
509
|
status: response.status,
|
|
510
510
|
recommendedPsp: mapProviderToPsp(response.provider),
|
|
511
511
|
availableMethods: config.paymentMethods || ["card", "mobile_money"],
|
|
512
|
-
|
|
513
|
-
|
|
512
|
+
providerRefId: response.provider_ref_id,
|
|
513
|
+
reference: response.reference || response.provider_ref_id || response.id,
|
|
514
|
+
// Use backend reference or fallback to provider ref then ID
|
|
514
515
|
orgId: response.org_id,
|
|
515
516
|
connectionId: response.connection_id,
|
|
516
517
|
provider: response.provider,
|
|
@@ -1331,6 +1332,38 @@ function PaystackBridge({
|
|
|
1331
1332
|
/* @__PURE__ */ jsx("p", { children: "Connecting to Paystack..." })
|
|
1332
1333
|
] }) });
|
|
1333
1334
|
}
|
|
1335
|
+
var DEFAULT_REEVIT_API_BASE_URL = "https://api.reevit.io";
|
|
1336
|
+
function getHubtelCallbackURL(apiBaseUrl) {
|
|
1337
|
+
return `${apiBaseUrl || DEFAULT_REEVIT_API_BASE_URL}/v1/webhooks/incoming/hubtel`;
|
|
1338
|
+
}
|
|
1339
|
+
function parseHubtelCallbackPayload(input) {
|
|
1340
|
+
if (!input || typeof input !== "object") {
|
|
1341
|
+
return {};
|
|
1342
|
+
}
|
|
1343
|
+
const raw = input;
|
|
1344
|
+
const nested = raw.data;
|
|
1345
|
+
if (typeof nested === "string") {
|
|
1346
|
+
try {
|
|
1347
|
+
const parsed = JSON.parse(nested);
|
|
1348
|
+
if (parsed && typeof parsed === "object") {
|
|
1349
|
+
return { ...raw, ...parsed };
|
|
1350
|
+
}
|
|
1351
|
+
} catch {
|
|
1352
|
+
}
|
|
1353
|
+
} else if (nested && typeof nested === "object") {
|
|
1354
|
+
return { ...raw, ...nested };
|
|
1355
|
+
}
|
|
1356
|
+
return raw;
|
|
1357
|
+
}
|
|
1358
|
+
function readHubtelField(payload, keys) {
|
|
1359
|
+
for (const key of keys) {
|
|
1360
|
+
const value = payload[key];
|
|
1361
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
1362
|
+
return value.trim();
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
return "";
|
|
1366
|
+
}
|
|
1334
1367
|
function HubtelBridge({
|
|
1335
1368
|
paymentId,
|
|
1336
1369
|
publicKey,
|
|
@@ -1407,12 +1440,12 @@ function HubtelBridge({
|
|
|
1407
1440
|
purchaseDescription: description,
|
|
1408
1441
|
customerPhoneNumber: phone || "",
|
|
1409
1442
|
...email ? { customerEmail: email } : {},
|
|
1410
|
-
clientReference: reference || `hubtel_${Date.now()}`,
|
|
1443
|
+
clientReference: reference || paymentId || `hubtel_${Date.now()}`,
|
|
1411
1444
|
...methodPreference ? { paymentMethod: methodPreference } : {}
|
|
1412
1445
|
};
|
|
1413
1446
|
const config = {
|
|
1414
1447
|
branding: "enabled",
|
|
1415
|
-
callbackUrl: callbackUrl ||
|
|
1448
|
+
callbackUrl: callbackUrl || getHubtelCallbackURL(apiBaseUrl),
|
|
1416
1449
|
merchantAccount: typeof resolvedMerchantAccount === "string" ? parseInt(resolvedMerchantAccount, 10) : resolvedMerchantAccount,
|
|
1417
1450
|
basicAuth: authValue || "",
|
|
1418
1451
|
...methodPreference ? { paymentMethod: methodPreference } : {}
|
|
@@ -1423,24 +1456,41 @@ function HubtelBridge({
|
|
|
1423
1456
|
callBacks: {
|
|
1424
1457
|
onInit: () => console.log("Hubtel checkout initialized"),
|
|
1425
1458
|
onPaymentSuccess: (data) => {
|
|
1459
|
+
const payload = parseHubtelCallbackPayload(data);
|
|
1460
|
+
const transactionReference = readHubtelField(payload, [
|
|
1461
|
+
"transactionId",
|
|
1462
|
+
"transaction_id",
|
|
1463
|
+
"transactionReference",
|
|
1464
|
+
"paymentReference",
|
|
1465
|
+
"checkoutId"
|
|
1466
|
+
]);
|
|
1467
|
+
const clientReference = readHubtelField(payload, ["clientReference", "client_reference"]);
|
|
1426
1468
|
const result = {
|
|
1427
|
-
paymentId
|
|
1428
|
-
reference:
|
|
1469
|
+
paymentId,
|
|
1470
|
+
reference: clientReference || reference || paymentId,
|
|
1429
1471
|
amount,
|
|
1430
1472
|
currency: currency || "GHS",
|
|
1431
1473
|
paymentMethod: preferredMethod || "mobile_money",
|
|
1432
1474
|
psp: "hubtel",
|
|
1433
|
-
pspReference:
|
|
1434
|
-
status: "success"
|
|
1475
|
+
pspReference: transactionReference || paymentId,
|
|
1476
|
+
status: "success",
|
|
1477
|
+
metadata: {
|
|
1478
|
+
hubtel_payload: payload,
|
|
1479
|
+
hubtel_raw: data
|
|
1480
|
+
}
|
|
1435
1481
|
};
|
|
1436
1482
|
onSuccess(result);
|
|
1437
1483
|
checkout.closePopUp();
|
|
1438
1484
|
},
|
|
1439
1485
|
onPaymentFailure: (data) => {
|
|
1486
|
+
const payload = parseHubtelCallbackPayload(data);
|
|
1440
1487
|
const error = {
|
|
1441
1488
|
code: "PAYMENT_FAILED",
|
|
1442
|
-
message:
|
|
1443
|
-
recoverable: true
|
|
1489
|
+
message: readHubtelField(payload, ["message", "error", "reason"]) || "Payment failed",
|
|
1490
|
+
recoverable: true,
|
|
1491
|
+
details: {
|
|
1492
|
+
hubtel_payload: payload
|
|
1493
|
+
}
|
|
1444
1494
|
};
|
|
1445
1495
|
onError(error);
|
|
1446
1496
|
},
|
|
@@ -1465,6 +1515,8 @@ function HubtelBridge({
|
|
|
1465
1515
|
phone,
|
|
1466
1516
|
description,
|
|
1467
1517
|
callbackUrl,
|
|
1518
|
+
paymentId,
|
|
1519
|
+
apiBaseUrl,
|
|
1468
1520
|
authValue,
|
|
1469
1521
|
isLoading,
|
|
1470
1522
|
preferredMethod,
|
|
@@ -1497,7 +1549,7 @@ function openHubtelPopup(config) {
|
|
|
1497
1549
|
};
|
|
1498
1550
|
const checkoutConfig = {
|
|
1499
1551
|
branding: "enabled",
|
|
1500
|
-
callbackUrl: config.callbackUrl ||
|
|
1552
|
+
callbackUrl: config.callbackUrl || getHubtelCallbackURL(config.apiBaseUrl),
|
|
1501
1553
|
merchantAccount: typeof config.merchantAccount === "string" ? parseInt(config.merchantAccount, 10) : config.merchantAccount,
|
|
1502
1554
|
basicAuth: config.basicAuth || "",
|
|
1503
1555
|
...methodPreference ? { paymentMethod: methodPreference } : {}
|
|
@@ -1507,11 +1559,11 @@ function openHubtelPopup(config) {
|
|
|
1507
1559
|
config: checkoutConfig,
|
|
1508
1560
|
callBacks: {
|
|
1509
1561
|
onPaymentSuccess: (data) => {
|
|
1510
|
-
config.onSuccess?.(data);
|
|
1562
|
+
config.onSuccess?.(parseHubtelCallbackPayload(data));
|
|
1511
1563
|
checkout.closePopUp();
|
|
1512
1564
|
},
|
|
1513
1565
|
onPaymentFailure: (data) => {
|
|
1514
|
-
config.onError?.(data);
|
|
1566
|
+
config.onError?.(parseHubtelCallbackPayload(data));
|
|
1515
1567
|
},
|
|
1516
1568
|
onClose: () => {
|
|
1517
1569
|
config.onClose?.();
|
|
@@ -2571,10 +2623,11 @@ function ReevitCheckout({
|
|
|
2571
2623
|
merchantAccount: paymentIntent?.pspCredentials?.merchantAccount || "",
|
|
2572
2624
|
amount: paymentIntent?.amount ?? amount,
|
|
2573
2625
|
currency: paymentIntent?.currency ?? currency,
|
|
2574
|
-
reference: paymentIntent?.reference || reference,
|
|
2626
|
+
reference: paymentIntent?.providerRefId || paymentIntent?.reference || reference,
|
|
2575
2627
|
email,
|
|
2576
2628
|
phone: momoData?.phone || phone,
|
|
2577
2629
|
description: `Payment ${paymentIntent?.reference || reference || ""}`,
|
|
2630
|
+
callbackUrl: `${apiBaseUrl || "https://api.reevit.io"}/v1/webhooks/incoming/hubtel`,
|
|
2578
2631
|
hubtelSessionToken: paymentIntent?.id ? paymentIntent.id : void 0,
|
|
2579
2632
|
clientSecret: paymentIntent?.clientSecret,
|
|
2580
2633
|
apiBaseUrl,
|