@reevit/react 0.4.4 → 0.4.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.d.mts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +31 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -210,12 +210,14 @@ var ReevitAPIClient = class {
|
|
|
210
210
|
const request = {
|
|
211
211
|
amount: config.amount,
|
|
212
212
|
currency: config.currency,
|
|
213
|
-
method: this.mapPaymentMethod(method),
|
|
214
213
|
country,
|
|
215
214
|
customer_id: config.email || config.metadata?.customerId,
|
|
216
215
|
phone: config.phone,
|
|
217
216
|
metadata
|
|
218
217
|
};
|
|
218
|
+
if (method) {
|
|
219
|
+
request.method = this.mapPaymentMethod(method);
|
|
220
|
+
}
|
|
219
221
|
if (options?.preferredProviders?.length || options?.allowedProviders?.length) {
|
|
220
222
|
request.policy = {
|
|
221
223
|
prefer: options?.preferredProviders,
|
|
@@ -422,7 +424,8 @@ function useReevit(options) {
|
|
|
422
424
|
}
|
|
423
425
|
const reference = config.reference || generateReference();
|
|
424
426
|
const country = detectCountryFromCurrency(config.currency);
|
|
425
|
-
const
|
|
427
|
+
const defaultMethod = config.paymentMethods && config.paymentMethods.length === 1 ? config.paymentMethods[0] : void 0;
|
|
428
|
+
const paymentMethod = method ?? defaultMethod;
|
|
426
429
|
let data;
|
|
427
430
|
let error;
|
|
428
431
|
if (config.paymentLinkCode) {
|
|
@@ -1080,7 +1083,9 @@ function HubtelBridge({
|
|
|
1080
1083
|
publicKey,
|
|
1081
1084
|
merchantAccount,
|
|
1082
1085
|
amount,
|
|
1086
|
+
currency,
|
|
1083
1087
|
reference,
|
|
1088
|
+
email,
|
|
1084
1089
|
phone,
|
|
1085
1090
|
description = "Payment",
|
|
1086
1091
|
callbackUrl,
|
|
@@ -1095,7 +1100,6 @@ function HubtelBridge({
|
|
|
1095
1100
|
autoStart = true
|
|
1096
1101
|
}) {
|
|
1097
1102
|
const initialized = useRef(false);
|
|
1098
|
-
const checkoutRef = useRef(null);
|
|
1099
1103
|
const [authValue, setAuthValue] = useState("");
|
|
1100
1104
|
const [isLoading, setIsLoading] = useState(false);
|
|
1101
1105
|
const [resolvedMerchantAccount, setResolvedMerchantAccount] = useState(merchantAccount);
|
|
@@ -1109,19 +1113,17 @@ function HubtelBridge({
|
|
|
1109
1113
|
try {
|
|
1110
1114
|
const client = createReevitClient({ publicKey, baseUrl: apiBaseUrl });
|
|
1111
1115
|
const { data, error } = await client.createHubtelSession(paymentId, clientSecret);
|
|
1112
|
-
if (error) {
|
|
1116
|
+
if (error || !data?.basicAuth) {
|
|
1113
1117
|
onError({
|
|
1114
1118
|
code: "SESSION_ERROR",
|
|
1115
|
-
message: error
|
|
1119
|
+
message: error?.message || "Failed to create Hubtel session",
|
|
1116
1120
|
recoverable: true
|
|
1117
1121
|
});
|
|
1118
1122
|
return;
|
|
1119
1123
|
}
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
setResolvedMerchantAccount(data.merchantAccount);
|
|
1124
|
-
}
|
|
1124
|
+
setAuthValue(data.basicAuth);
|
|
1125
|
+
if (data.merchantAccount) {
|
|
1126
|
+
setResolvedMerchantAccount(data.merchantAccount);
|
|
1125
1127
|
}
|
|
1126
1128
|
} catch (err) {
|
|
1127
1129
|
onError({
|
|
@@ -1145,13 +1147,13 @@ function HubtelBridge({
|
|
|
1145
1147
|
}
|
|
1146
1148
|
try {
|
|
1147
1149
|
const checkout = new CheckoutSdk();
|
|
1148
|
-
checkoutRef.current = checkout;
|
|
1149
1150
|
const methodPreference = preferredMethod === "mobile_money" ? "momo" : preferredMethod === "card" ? "card" : void 0;
|
|
1150
1151
|
const purchaseInfo = {
|
|
1151
1152
|
amount: amount / 100,
|
|
1152
1153
|
// Convert from minor to major units
|
|
1153
1154
|
purchaseDescription: description,
|
|
1154
1155
|
customerPhoneNumber: phone || "",
|
|
1156
|
+
...email ? { customerEmail: email } : {},
|
|
1155
1157
|
clientReference: reference || `hubtel_${Date.now()}`,
|
|
1156
1158
|
...methodPreference ? { paymentMethod: methodPreference } : {}
|
|
1157
1159
|
};
|
|
@@ -1159,8 +1161,6 @@ function HubtelBridge({
|
|
|
1159
1161
|
branding: "enabled",
|
|
1160
1162
|
callbackUrl: callbackUrl || window.location.href,
|
|
1161
1163
|
merchantAccount: typeof resolvedMerchantAccount === "string" ? parseInt(resolvedMerchantAccount, 10) : resolvedMerchantAccount,
|
|
1162
|
-
// Use session token or basicAuth for authentication
|
|
1163
|
-
// Session tokens are base64-encoded credentials fetched securely from the server
|
|
1164
1164
|
basicAuth: authValue || "",
|
|
1165
1165
|
...methodPreference ? { paymentMethod: methodPreference } : {}
|
|
1166
1166
|
};
|
|
@@ -1174,8 +1174,8 @@ function HubtelBridge({
|
|
|
1174
1174
|
paymentId: data.transactionId || reference || "",
|
|
1175
1175
|
reference: data.clientReference || reference || "",
|
|
1176
1176
|
amount,
|
|
1177
|
-
currency: "GHS",
|
|
1178
|
-
paymentMethod: "mobile_money",
|
|
1177
|
+
currency: currency || "GHS",
|
|
1178
|
+
paymentMethod: preferredMethod || "mobile_money",
|
|
1179
1179
|
psp: "hubtel",
|
|
1180
1180
|
pspReference: data.transactionId || "",
|
|
1181
1181
|
status: "success"
|
|
@@ -1206,7 +1206,21 @@ function HubtelBridge({
|
|
|
1206
1206
|
};
|
|
1207
1207
|
onError(error);
|
|
1208
1208
|
}
|
|
1209
|
-
}, [
|
|
1209
|
+
}, [
|
|
1210
|
+
amount,
|
|
1211
|
+
reference,
|
|
1212
|
+
phone,
|
|
1213
|
+
description,
|
|
1214
|
+
callbackUrl,
|
|
1215
|
+
authValue,
|
|
1216
|
+
isLoading,
|
|
1217
|
+
preferredMethod,
|
|
1218
|
+
onSuccess,
|
|
1219
|
+
onError,
|
|
1220
|
+
onClose,
|
|
1221
|
+
resolvedMerchantAccount,
|
|
1222
|
+
currency
|
|
1223
|
+
]);
|
|
1210
1224
|
useEffect(() => {
|
|
1211
1225
|
if (autoStart && !initialized.current && !isLoading && authValue) {
|
|
1212
1226
|
initialized.current = true;
|
|
@@ -2240,7 +2254,7 @@ function ReevitCheckout({
|
|
|
2240
2254
|
{
|
|
2241
2255
|
paymentId: paymentIntent?.id || "",
|
|
2242
2256
|
publicKey,
|
|
2243
|
-
merchantAccount:
|
|
2257
|
+
merchantAccount: paymentIntent?.pspCredentials?.merchantAccount || "",
|
|
2244
2258
|
amount: paymentIntent?.amount ?? amount,
|
|
2245
2259
|
currency: paymentIntent?.currency ?? currency,
|
|
2246
2260
|
reference: paymentIntent?.reference || reference,
|