@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.d.mts
CHANGED
|
@@ -183,6 +183,8 @@ interface PaymentIntent {
|
|
|
183
183
|
recommendedPsp: 'paystack' | 'hubtel' | 'flutterwave' | 'monnify' | 'mpesa' | 'stripe';
|
|
184
184
|
/** Available payment methods for this intent */
|
|
185
185
|
availableMethods: PaymentMethod[];
|
|
186
|
+
/** Provider transaction reference returned by Reevit */
|
|
187
|
+
providerRefId?: string;
|
|
186
188
|
/** Reference provided or generated */
|
|
187
189
|
reference?: string;
|
|
188
190
|
/** Organization ID (from Reevit backend, required for webhook routing) */
|
|
@@ -361,6 +363,7 @@ declare function openHubtelPopup(config: {
|
|
|
361
363
|
amount: number;
|
|
362
364
|
clientReference?: string;
|
|
363
365
|
callbackUrl?: string;
|
|
366
|
+
apiBaseUrl?: string;
|
|
364
367
|
customerPhoneNumber?: string;
|
|
365
368
|
basicAuth?: string;
|
|
366
369
|
preferredMethod?: PaymentMethod;
|
|
@@ -623,6 +626,7 @@ interface PaymentIntentResponse {
|
|
|
623
626
|
org_id?: string;
|
|
624
627
|
connection_id: string;
|
|
625
628
|
provider: string;
|
|
629
|
+
provider_ref_id?: string;
|
|
626
630
|
status: string;
|
|
627
631
|
client_secret: string;
|
|
628
632
|
psp_public_key?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -183,6 +183,8 @@ interface PaymentIntent {
|
|
|
183
183
|
recommendedPsp: 'paystack' | 'hubtel' | 'flutterwave' | 'monnify' | 'mpesa' | 'stripe';
|
|
184
184
|
/** Available payment methods for this intent */
|
|
185
185
|
availableMethods: PaymentMethod[];
|
|
186
|
+
/** Provider transaction reference returned by Reevit */
|
|
187
|
+
providerRefId?: string;
|
|
186
188
|
/** Reference provided or generated */
|
|
187
189
|
reference?: string;
|
|
188
190
|
/** Organization ID (from Reevit backend, required for webhook routing) */
|
|
@@ -361,6 +363,7 @@ declare function openHubtelPopup(config: {
|
|
|
361
363
|
amount: number;
|
|
362
364
|
clientReference?: string;
|
|
363
365
|
callbackUrl?: string;
|
|
366
|
+
apiBaseUrl?: string;
|
|
364
367
|
customerPhoneNumber?: string;
|
|
365
368
|
basicAuth?: string;
|
|
366
369
|
preferredMethod?: PaymentMethod;
|
|
@@ -623,6 +626,7 @@ interface PaymentIntentResponse {
|
|
|
623
626
|
org_id?: string;
|
|
624
627
|
connection_id: string;
|
|
625
628
|
provider: string;
|
|
629
|
+
provider_ref_id?: string;
|
|
626
630
|
status: string;
|
|
627
631
|
client_secret: string;
|
|
628
632
|
psp_public_key?: string;
|
package/dist/index.js
CHANGED
|
@@ -515,8 +515,9 @@ function mapToPaymentIntent(response, config) {
|
|
|
515
515
|
status: response.status,
|
|
516
516
|
recommendedPsp: mapProviderToPsp(response.provider),
|
|
517
517
|
availableMethods: config.paymentMethods || ["card", "mobile_money"],
|
|
518
|
-
|
|
519
|
-
|
|
518
|
+
providerRefId: response.provider_ref_id,
|
|
519
|
+
reference: response.reference || response.provider_ref_id || response.id,
|
|
520
|
+
// Use backend reference or fallback to provider ref then ID
|
|
520
521
|
orgId: response.org_id,
|
|
521
522
|
connectionId: response.connection_id,
|
|
522
523
|
provider: response.provider,
|
|
@@ -1337,6 +1338,38 @@ function PaystackBridge({
|
|
|
1337
1338
|
/* @__PURE__ */ jsxRuntime.jsx("p", { children: "Connecting to Paystack..." })
|
|
1338
1339
|
] }) });
|
|
1339
1340
|
}
|
|
1341
|
+
var DEFAULT_REEVIT_API_BASE_URL = "https://api.reevit.io";
|
|
1342
|
+
function getHubtelCallbackURL(apiBaseUrl) {
|
|
1343
|
+
return `${apiBaseUrl || DEFAULT_REEVIT_API_BASE_URL}/v1/webhooks/incoming/hubtel`;
|
|
1344
|
+
}
|
|
1345
|
+
function parseHubtelCallbackPayload(input) {
|
|
1346
|
+
if (!input || typeof input !== "object") {
|
|
1347
|
+
return {};
|
|
1348
|
+
}
|
|
1349
|
+
const raw = input;
|
|
1350
|
+
const nested = raw.data;
|
|
1351
|
+
if (typeof nested === "string") {
|
|
1352
|
+
try {
|
|
1353
|
+
const parsed = JSON.parse(nested);
|
|
1354
|
+
if (parsed && typeof parsed === "object") {
|
|
1355
|
+
return { ...raw, ...parsed };
|
|
1356
|
+
}
|
|
1357
|
+
} catch {
|
|
1358
|
+
}
|
|
1359
|
+
} else if (nested && typeof nested === "object") {
|
|
1360
|
+
return { ...raw, ...nested };
|
|
1361
|
+
}
|
|
1362
|
+
return raw;
|
|
1363
|
+
}
|
|
1364
|
+
function readHubtelField(payload, keys) {
|
|
1365
|
+
for (const key of keys) {
|
|
1366
|
+
const value = payload[key];
|
|
1367
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
1368
|
+
return value.trim();
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
return "";
|
|
1372
|
+
}
|
|
1340
1373
|
function HubtelBridge({
|
|
1341
1374
|
paymentId,
|
|
1342
1375
|
publicKey,
|
|
@@ -1413,12 +1446,12 @@ function HubtelBridge({
|
|
|
1413
1446
|
purchaseDescription: description,
|
|
1414
1447
|
customerPhoneNumber: phone || "",
|
|
1415
1448
|
...email ? { customerEmail: email } : {},
|
|
1416
|
-
clientReference: reference || `hubtel_${Date.now()}`,
|
|
1449
|
+
clientReference: reference || paymentId || `hubtel_${Date.now()}`,
|
|
1417
1450
|
...methodPreference ? { paymentMethod: methodPreference } : {}
|
|
1418
1451
|
};
|
|
1419
1452
|
const config = {
|
|
1420
1453
|
branding: "enabled",
|
|
1421
|
-
callbackUrl: callbackUrl ||
|
|
1454
|
+
callbackUrl: callbackUrl || getHubtelCallbackURL(apiBaseUrl),
|
|
1422
1455
|
merchantAccount: typeof resolvedMerchantAccount === "string" ? parseInt(resolvedMerchantAccount, 10) : resolvedMerchantAccount,
|
|
1423
1456
|
basicAuth: authValue || "",
|
|
1424
1457
|
...methodPreference ? { paymentMethod: methodPreference } : {}
|
|
@@ -1429,24 +1462,41 @@ function HubtelBridge({
|
|
|
1429
1462
|
callBacks: {
|
|
1430
1463
|
onInit: () => console.log("Hubtel checkout initialized"),
|
|
1431
1464
|
onPaymentSuccess: (data) => {
|
|
1465
|
+
const payload = parseHubtelCallbackPayload(data);
|
|
1466
|
+
const transactionReference = readHubtelField(payload, [
|
|
1467
|
+
"transactionId",
|
|
1468
|
+
"transaction_id",
|
|
1469
|
+
"transactionReference",
|
|
1470
|
+
"paymentReference",
|
|
1471
|
+
"checkoutId"
|
|
1472
|
+
]);
|
|
1473
|
+
const clientReference = readHubtelField(payload, ["clientReference", "client_reference"]);
|
|
1432
1474
|
const result = {
|
|
1433
|
-
paymentId
|
|
1434
|
-
reference:
|
|
1475
|
+
paymentId,
|
|
1476
|
+
reference: clientReference || reference || paymentId,
|
|
1435
1477
|
amount,
|
|
1436
1478
|
currency: currency || "GHS",
|
|
1437
1479
|
paymentMethod: preferredMethod || "mobile_money",
|
|
1438
1480
|
psp: "hubtel",
|
|
1439
|
-
pspReference:
|
|
1440
|
-
status: "success"
|
|
1481
|
+
pspReference: transactionReference || paymentId,
|
|
1482
|
+
status: "success",
|
|
1483
|
+
metadata: {
|
|
1484
|
+
hubtel_payload: payload,
|
|
1485
|
+
hubtel_raw: data
|
|
1486
|
+
}
|
|
1441
1487
|
};
|
|
1442
1488
|
onSuccess(result);
|
|
1443
1489
|
checkout.closePopUp();
|
|
1444
1490
|
},
|
|
1445
1491
|
onPaymentFailure: (data) => {
|
|
1492
|
+
const payload = parseHubtelCallbackPayload(data);
|
|
1446
1493
|
const error = {
|
|
1447
1494
|
code: "PAYMENT_FAILED",
|
|
1448
|
-
message:
|
|
1449
|
-
recoverable: true
|
|
1495
|
+
message: readHubtelField(payload, ["message", "error", "reason"]) || "Payment failed",
|
|
1496
|
+
recoverable: true,
|
|
1497
|
+
details: {
|
|
1498
|
+
hubtel_payload: payload
|
|
1499
|
+
}
|
|
1450
1500
|
};
|
|
1451
1501
|
onError(error);
|
|
1452
1502
|
},
|
|
@@ -1471,6 +1521,8 @@ function HubtelBridge({
|
|
|
1471
1521
|
phone,
|
|
1472
1522
|
description,
|
|
1473
1523
|
callbackUrl,
|
|
1524
|
+
paymentId,
|
|
1525
|
+
apiBaseUrl,
|
|
1474
1526
|
authValue,
|
|
1475
1527
|
isLoading,
|
|
1476
1528
|
preferredMethod,
|
|
@@ -1503,7 +1555,7 @@ function openHubtelPopup(config) {
|
|
|
1503
1555
|
};
|
|
1504
1556
|
const checkoutConfig = {
|
|
1505
1557
|
branding: "enabled",
|
|
1506
|
-
callbackUrl: config.callbackUrl ||
|
|
1558
|
+
callbackUrl: config.callbackUrl || getHubtelCallbackURL(config.apiBaseUrl),
|
|
1507
1559
|
merchantAccount: typeof config.merchantAccount === "string" ? parseInt(config.merchantAccount, 10) : config.merchantAccount,
|
|
1508
1560
|
basicAuth: config.basicAuth || "",
|
|
1509
1561
|
...methodPreference ? { paymentMethod: methodPreference } : {}
|
|
@@ -1513,11 +1565,11 @@ function openHubtelPopup(config) {
|
|
|
1513
1565
|
config: checkoutConfig,
|
|
1514
1566
|
callBacks: {
|
|
1515
1567
|
onPaymentSuccess: (data) => {
|
|
1516
|
-
config.onSuccess?.(data);
|
|
1568
|
+
config.onSuccess?.(parseHubtelCallbackPayload(data));
|
|
1517
1569
|
checkout.closePopUp();
|
|
1518
1570
|
},
|
|
1519
1571
|
onPaymentFailure: (data) => {
|
|
1520
|
-
config.onError?.(data);
|
|
1572
|
+
config.onError?.(parseHubtelCallbackPayload(data));
|
|
1521
1573
|
},
|
|
1522
1574
|
onClose: () => {
|
|
1523
1575
|
config.onClose?.();
|
|
@@ -2577,10 +2629,11 @@ function ReevitCheckout({
|
|
|
2577
2629
|
merchantAccount: paymentIntent?.pspCredentials?.merchantAccount || "",
|
|
2578
2630
|
amount: paymentIntent?.amount ?? amount,
|
|
2579
2631
|
currency: paymentIntent?.currency ?? currency,
|
|
2580
|
-
reference: paymentIntent?.reference || reference,
|
|
2632
|
+
reference: paymentIntent?.providerRefId || paymentIntent?.reference || reference,
|
|
2581
2633
|
email,
|
|
2582
2634
|
phone: momoData?.phone || phone,
|
|
2583
2635
|
description: `Payment ${paymentIntent?.reference || reference || ""}`,
|
|
2636
|
+
callbackUrl: `${apiBaseUrl || "https://api.reevit.io"}/v1/webhooks/incoming/hubtel`,
|
|
2584
2637
|
hubtelSessionToken: paymentIntent?.id ? paymentIntent.id : void 0,
|
|
2585
2638
|
clientSecret: paymentIntent?.clientSecret,
|
|
2586
2639
|
apiBaseUrl,
|