@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 CHANGED
@@ -308,9 +308,9 @@ interface HubtelBridgeProps {
308
308
  callbackUrl?: string;
309
309
  apiBaseUrl?: string;
310
310
  clientSecret?: string;
311
- /** Session token from server (recommended - credentials never exposed to client) */
311
+ /** Session token from server (triggers session fetch) */
312
312
  hubtelSessionToken?: string;
313
- /** Basic auth credential (legacy - credentials exposed to client, deprecated) */
313
+ /** Base64 basic auth credential (legacy - credentials exposed) */
314
314
  basicAuth?: string;
315
315
  preferredMethod?: PaymentMethod;
316
316
  onSuccess: (result: PaymentResult) => void;
@@ -318,7 +318,7 @@ interface HubtelBridgeProps {
318
318
  onClose: () => void;
319
319
  autoStart?: boolean;
320
320
  }
321
- declare function HubtelBridge({ paymentId, publicKey, merchantAccount, amount, reference, phone, description, callbackUrl, apiBaseUrl, clientSecret, hubtelSessionToken, basicAuth, preferredMethod, onSuccess, onError, onClose, autoStart, }: HubtelBridgeProps): react_jsx_runtime.JSX.Element;
321
+ declare function HubtelBridge({ paymentId, publicKey, merchantAccount, amount, currency, reference, email, phone, description, callbackUrl, apiBaseUrl, clientSecret, hubtelSessionToken, basicAuth, preferredMethod, onSuccess, onError, onClose, autoStart, }: HubtelBridgeProps): react_jsx_runtime.JSX.Element;
322
322
  /**
323
323
  * Opens Hubtel checkout modal directly
324
324
  * Uses the @hubteljs/checkout npm package
@@ -616,6 +616,8 @@ interface HubtelSessionResponse {
616
616
  token: string;
617
617
  /** Hubtel merchant account number */
618
618
  merchantAccount: string;
619
+ /** Base64 basic auth for Hubtel checkout (exposes credentials) */
620
+ basicAuth?: string;
619
621
  /** Token expiry time in seconds */
620
622
  expiresInSeconds: number;
621
623
  /** Unix timestamp when the token expires */
@@ -668,7 +670,7 @@ declare class ReevitAPIClient {
668
670
  /**
669
671
  * Creates a payment intent
670
672
  */
671
- createPaymentIntent(config: ReevitCheckoutConfig, method: PaymentMethod, country?: string, options?: {
673
+ createPaymentIntent(config: ReevitCheckoutConfig, method?: PaymentMethod, country?: string, options?: {
672
674
  preferredProviders?: string[];
673
675
  allowedProviders?: string[];
674
676
  }): Promise<{
package/dist/index.d.ts CHANGED
@@ -308,9 +308,9 @@ interface HubtelBridgeProps {
308
308
  callbackUrl?: string;
309
309
  apiBaseUrl?: string;
310
310
  clientSecret?: string;
311
- /** Session token from server (recommended - credentials never exposed to client) */
311
+ /** Session token from server (triggers session fetch) */
312
312
  hubtelSessionToken?: string;
313
- /** Basic auth credential (legacy - credentials exposed to client, deprecated) */
313
+ /** Base64 basic auth credential (legacy - credentials exposed) */
314
314
  basicAuth?: string;
315
315
  preferredMethod?: PaymentMethod;
316
316
  onSuccess: (result: PaymentResult) => void;
@@ -318,7 +318,7 @@ interface HubtelBridgeProps {
318
318
  onClose: () => void;
319
319
  autoStart?: boolean;
320
320
  }
321
- declare function HubtelBridge({ paymentId, publicKey, merchantAccount, amount, reference, phone, description, callbackUrl, apiBaseUrl, clientSecret, hubtelSessionToken, basicAuth, preferredMethod, onSuccess, onError, onClose, autoStart, }: HubtelBridgeProps): react_jsx_runtime.JSX.Element;
321
+ declare function HubtelBridge({ paymentId, publicKey, merchantAccount, amount, currency, reference, email, phone, description, callbackUrl, apiBaseUrl, clientSecret, hubtelSessionToken, basicAuth, preferredMethod, onSuccess, onError, onClose, autoStart, }: HubtelBridgeProps): react_jsx_runtime.JSX.Element;
322
322
  /**
323
323
  * Opens Hubtel checkout modal directly
324
324
  * Uses the @hubteljs/checkout npm package
@@ -616,6 +616,8 @@ interface HubtelSessionResponse {
616
616
  token: string;
617
617
  /** Hubtel merchant account number */
618
618
  merchantAccount: string;
619
+ /** Base64 basic auth for Hubtel checkout (exposes credentials) */
620
+ basicAuth?: string;
619
621
  /** Token expiry time in seconds */
620
622
  expiresInSeconds: number;
621
623
  /** Unix timestamp when the token expires */
@@ -668,7 +670,7 @@ declare class ReevitAPIClient {
668
670
  /**
669
671
  * Creates a payment intent
670
672
  */
671
- createPaymentIntent(config: ReevitCheckoutConfig, method: PaymentMethod, country?: string, options?: {
673
+ createPaymentIntent(config: ReevitCheckoutConfig, method?: PaymentMethod, country?: string, options?: {
672
674
  preferredProviders?: string[];
673
675
  allowedProviders?: string[];
674
676
  }): Promise<{
package/dist/index.js CHANGED
@@ -216,12 +216,14 @@ var ReevitAPIClient = class {
216
216
  const request = {
217
217
  amount: config.amount,
218
218
  currency: config.currency,
219
- method: this.mapPaymentMethod(method),
220
219
  country,
221
220
  customer_id: config.email || config.metadata?.customerId,
222
221
  phone: config.phone,
223
222
  metadata
224
223
  };
224
+ if (method) {
225
+ request.method = this.mapPaymentMethod(method);
226
+ }
225
227
  if (options?.preferredProviders?.length || options?.allowedProviders?.length) {
226
228
  request.policy = {
227
229
  prefer: options?.preferredProviders,
@@ -428,7 +430,8 @@ function useReevit(options) {
428
430
  }
429
431
  const reference = config.reference || generateReference();
430
432
  const country = detectCountryFromCurrency(config.currency);
431
- const paymentMethod = method || config.paymentMethods?.[0] || "card";
433
+ const defaultMethod = config.paymentMethods && config.paymentMethods.length === 1 ? config.paymentMethods[0] : void 0;
434
+ const paymentMethod = method ?? defaultMethod;
432
435
  let data;
433
436
  let error;
434
437
  if (config.paymentLinkCode) {
@@ -1086,7 +1089,9 @@ function HubtelBridge({
1086
1089
  publicKey,
1087
1090
  merchantAccount,
1088
1091
  amount,
1092
+ currency,
1089
1093
  reference,
1094
+ email,
1090
1095
  phone,
1091
1096
  description = "Payment",
1092
1097
  callbackUrl,
@@ -1101,7 +1106,6 @@ function HubtelBridge({
1101
1106
  autoStart = true
1102
1107
  }) {
1103
1108
  const initialized = react.useRef(false);
1104
- const checkoutRef = react.useRef(null);
1105
1109
  const [authValue, setAuthValue] = react.useState("");
1106
1110
  const [isLoading, setIsLoading] = react.useState(false);
1107
1111
  const [resolvedMerchantAccount, setResolvedMerchantAccount] = react.useState(merchantAccount);
@@ -1115,19 +1119,17 @@ function HubtelBridge({
1115
1119
  try {
1116
1120
  const client = createReevitClient({ publicKey, baseUrl: apiBaseUrl });
1117
1121
  const { data, error } = await client.createHubtelSession(paymentId, clientSecret);
1118
- if (error) {
1122
+ if (error || !data?.basicAuth) {
1119
1123
  onError({
1120
1124
  code: "SESSION_ERROR",
1121
- message: error.message || "Failed to create Hubtel session",
1125
+ message: error?.message || "Failed to create Hubtel session",
1122
1126
  recoverable: true
1123
1127
  });
1124
1128
  return;
1125
1129
  }
1126
- if (data) {
1127
- setAuthValue(data.token);
1128
- if (data.merchantAccount) {
1129
- setResolvedMerchantAccount(data.merchantAccount);
1130
- }
1130
+ setAuthValue(data.basicAuth);
1131
+ if (data.merchantAccount) {
1132
+ setResolvedMerchantAccount(data.merchantAccount);
1131
1133
  }
1132
1134
  } catch (err) {
1133
1135
  onError({
@@ -1151,13 +1153,13 @@ function HubtelBridge({
1151
1153
  }
1152
1154
  try {
1153
1155
  const checkout = new CheckoutSdk__default.default();
1154
- checkoutRef.current = checkout;
1155
1156
  const methodPreference = preferredMethod === "mobile_money" ? "momo" : preferredMethod === "card" ? "card" : void 0;
1156
1157
  const purchaseInfo = {
1157
1158
  amount: amount / 100,
1158
1159
  // Convert from minor to major units
1159
1160
  purchaseDescription: description,
1160
1161
  customerPhoneNumber: phone || "",
1162
+ ...email ? { customerEmail: email } : {},
1161
1163
  clientReference: reference || `hubtel_${Date.now()}`,
1162
1164
  ...methodPreference ? { paymentMethod: methodPreference } : {}
1163
1165
  };
@@ -1165,8 +1167,6 @@ function HubtelBridge({
1165
1167
  branding: "enabled",
1166
1168
  callbackUrl: callbackUrl || window.location.href,
1167
1169
  merchantAccount: typeof resolvedMerchantAccount === "string" ? parseInt(resolvedMerchantAccount, 10) : resolvedMerchantAccount,
1168
- // Use session token or basicAuth for authentication
1169
- // Session tokens are base64-encoded credentials fetched securely from the server
1170
1170
  basicAuth: authValue || "",
1171
1171
  ...methodPreference ? { paymentMethod: methodPreference } : {}
1172
1172
  };
@@ -1180,8 +1180,8 @@ function HubtelBridge({
1180
1180
  paymentId: data.transactionId || reference || "",
1181
1181
  reference: data.clientReference || reference || "",
1182
1182
  amount,
1183
- currency: "GHS",
1184
- paymentMethod: "mobile_money",
1183
+ currency: currency || "GHS",
1184
+ paymentMethod: preferredMethod || "mobile_money",
1185
1185
  psp: "hubtel",
1186
1186
  pspReference: data.transactionId || "",
1187
1187
  status: "success"
@@ -1212,7 +1212,21 @@ function HubtelBridge({
1212
1212
  };
1213
1213
  onError(error);
1214
1214
  }
1215
- }, [merchantAccount, amount, reference, phone, description, callbackUrl, authValue, isLoading, preferredMethod, onSuccess, onError, onClose]);
1215
+ }, [
1216
+ amount,
1217
+ reference,
1218
+ phone,
1219
+ description,
1220
+ callbackUrl,
1221
+ authValue,
1222
+ isLoading,
1223
+ preferredMethod,
1224
+ onSuccess,
1225
+ onError,
1226
+ onClose,
1227
+ resolvedMerchantAccount,
1228
+ currency
1229
+ ]);
1216
1230
  react.useEffect(() => {
1217
1231
  if (autoStart && !initialized.current && !isLoading && authValue) {
1218
1232
  initialized.current = true;
@@ -2246,7 +2260,7 @@ function ReevitCheckout({
2246
2260
  {
2247
2261
  paymentId: paymentIntent?.id || "",
2248
2262
  publicKey,
2249
- merchantAccount: pspKey,
2263
+ merchantAccount: paymentIntent?.pspCredentials?.merchantAccount || "",
2250
2264
  amount: paymentIntent?.amount ?? amount,
2251
2265
  currency: paymentIntent?.currency ?? currency,
2252
2266
  reference: paymentIntent?.reference || reference,