@reevit/react 0.4.5 → 0.4.7

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.mjs CHANGED
@@ -360,6 +360,36 @@ function mapAvailableProviders(providers) {
360
360
  };
361
361
  }).filter((provider) => provider.methods.length > 0);
362
362
  }
363
+ function normalizeBranding(branding) {
364
+ if (!branding) {
365
+ return {};
366
+ }
367
+ const raw = branding;
368
+ const theme = { ...raw };
369
+ const getString = (value) => typeof value === "string" ? value : void 0;
370
+ const getBoolean = (value) => typeof value === "boolean" ? value : void 0;
371
+ const setIf = (key, value) => {
372
+ if (value !== void 0) {
373
+ theme[key] = value;
374
+ }
375
+ };
376
+ setIf("logoUrl", getString(raw.logoUrl ?? raw.logo_url));
377
+ setIf("companyName", getString(raw.companyName ?? raw.company_name));
378
+ setIf("primaryColor", getString(raw.primaryColor ?? raw.primary_color));
379
+ setIf("primaryForegroundColor", getString(raw.primaryForegroundColor ?? raw.primary_foreground_color));
380
+ setIf("backgroundColor", getString(raw.backgroundColor ?? raw.background_color));
381
+ setIf("surfaceColor", getString(raw.surfaceColor ?? raw.surface_color));
382
+ setIf("textColor", getString(raw.textColor ?? raw.text_color));
383
+ setIf("mutedTextColor", getString(raw.mutedTextColor ?? raw.muted_text_color));
384
+ setIf("borderRadius", getString(raw.borderRadius ?? raw.border_radius));
385
+ setIf("fontFamily", getString(raw.fontFamily ?? raw.font_family));
386
+ setIf("darkMode", getBoolean(raw.darkMode ?? raw.dark_mode));
387
+ setIf("pspSelectorBgColor", getString(raw.pspSelectorBgColor ?? raw.psp_selector_bg_color));
388
+ setIf("pspSelectorTextColor", getString(raw.pspSelectorTextColor ?? raw.psp_selector_text_color));
389
+ setIf("pspSelectorBorderColor", getString(raw.pspSelectorBorderColor ?? raw.psp_selector_border_color));
390
+ setIf("pspSelectorUseBorder", getBoolean(raw.pspSelectorUseBorder ?? raw.psp_selector_use_border));
391
+ return theme;
392
+ }
363
393
  function mapToPaymentIntent(response, config) {
364
394
  return {
365
395
  id: response.id,
@@ -379,7 +409,7 @@ function mapToPaymentIntent(response, config) {
379
409
  netAmount: response.net_amount,
380
410
  metadata: config.metadata,
381
411
  availableProviders: mapAvailableProviders(response.available_psps),
382
- branding: response.branding
412
+ branding: normalizeBranding(response.branding)
383
413
  };
384
414
  }
385
415
  function useReevit(options) {
@@ -1083,7 +1113,9 @@ function HubtelBridge({
1083
1113
  publicKey,
1084
1114
  merchantAccount,
1085
1115
  amount,
1116
+ currency,
1086
1117
  reference,
1118
+ email,
1087
1119
  phone,
1088
1120
  description = "Payment",
1089
1121
  callbackUrl,
@@ -1098,7 +1130,6 @@ function HubtelBridge({
1098
1130
  autoStart = true
1099
1131
  }) {
1100
1132
  const initialized = useRef(false);
1101
- const checkoutRef = useRef(null);
1102
1133
  const [authValue, setAuthValue] = useState("");
1103
1134
  const [isLoading, setIsLoading] = useState(false);
1104
1135
  const [resolvedMerchantAccount, setResolvedMerchantAccount] = useState(merchantAccount);
@@ -1112,19 +1143,17 @@ function HubtelBridge({
1112
1143
  try {
1113
1144
  const client = createReevitClient({ publicKey, baseUrl: apiBaseUrl });
1114
1145
  const { data, error } = await client.createHubtelSession(paymentId, clientSecret);
1115
- if (error) {
1146
+ if (error || !data?.basicAuth) {
1116
1147
  onError({
1117
1148
  code: "SESSION_ERROR",
1118
- message: error.message || "Failed to create Hubtel session",
1149
+ message: error?.message || "Failed to create Hubtel session",
1119
1150
  recoverable: true
1120
1151
  });
1121
1152
  return;
1122
1153
  }
1123
- if (data) {
1124
- setAuthValue(data.token);
1125
- if (data.merchantAccount) {
1126
- setResolvedMerchantAccount(data.merchantAccount);
1127
- }
1154
+ setAuthValue(data.basicAuth);
1155
+ if (data.merchantAccount) {
1156
+ setResolvedMerchantAccount(data.merchantAccount);
1128
1157
  }
1129
1158
  } catch (err) {
1130
1159
  onError({
@@ -1148,13 +1177,13 @@ function HubtelBridge({
1148
1177
  }
1149
1178
  try {
1150
1179
  const checkout = new CheckoutSdk();
1151
- checkoutRef.current = checkout;
1152
1180
  const methodPreference = preferredMethod === "mobile_money" ? "momo" : preferredMethod === "card" ? "card" : void 0;
1153
1181
  const purchaseInfo = {
1154
1182
  amount: amount / 100,
1155
1183
  // Convert from minor to major units
1156
1184
  purchaseDescription: description,
1157
1185
  customerPhoneNumber: phone || "",
1186
+ ...email ? { customerEmail: email } : {},
1158
1187
  clientReference: reference || `hubtel_${Date.now()}`,
1159
1188
  ...methodPreference ? { paymentMethod: methodPreference } : {}
1160
1189
  };
@@ -1162,8 +1191,6 @@ function HubtelBridge({
1162
1191
  branding: "enabled",
1163
1192
  callbackUrl: callbackUrl || window.location.href,
1164
1193
  merchantAccount: typeof resolvedMerchantAccount === "string" ? parseInt(resolvedMerchantAccount, 10) : resolvedMerchantAccount,
1165
- // Use session token or basicAuth for authentication
1166
- // Session tokens are base64-encoded credentials fetched securely from the server
1167
1194
  basicAuth: authValue || "",
1168
1195
  ...methodPreference ? { paymentMethod: methodPreference } : {}
1169
1196
  };
@@ -1177,8 +1204,8 @@ function HubtelBridge({
1177
1204
  paymentId: data.transactionId || reference || "",
1178
1205
  reference: data.clientReference || reference || "",
1179
1206
  amount,
1180
- currency: "GHS",
1181
- paymentMethod: "mobile_money",
1207
+ currency: currency || "GHS",
1208
+ paymentMethod: preferredMethod || "mobile_money",
1182
1209
  psp: "hubtel",
1183
1210
  pspReference: data.transactionId || "",
1184
1211
  status: "success"
@@ -1209,7 +1236,21 @@ function HubtelBridge({
1209
1236
  };
1210
1237
  onError(error);
1211
1238
  }
1212
- }, [merchantAccount, amount, reference, phone, description, callbackUrl, authValue, isLoading, preferredMethod, onSuccess, onError, onClose]);
1239
+ }, [
1240
+ amount,
1241
+ reference,
1242
+ phone,
1243
+ description,
1244
+ callbackUrl,
1245
+ authValue,
1246
+ isLoading,
1247
+ preferredMethod,
1248
+ onSuccess,
1249
+ onError,
1250
+ onClose,
1251
+ resolvedMerchantAccount,
1252
+ currency
1253
+ ]);
1213
1254
  useEffect(() => {
1214
1255
  if (autoStart && !initialized.current && !isLoading && authValue) {
1215
1256
  initialized.current = true;
@@ -2167,6 +2208,7 @@ function ReevitCheckout({
2167
2208
  };
2168
2209
  }, [paymentIntent?.branding, theme]);
2169
2210
  const themeStyles = resolvedTheme ? createThemeVariables(resolvedTheme) : {};
2211
+ const brandName = resolvedTheme?.companyName;
2170
2212
  const themeMode = resolvedTheme?.darkMode;
2171
2213
  const dataTheme = useMemo(() => {
2172
2214
  if (typeof themeMode === "boolean") {
@@ -2243,7 +2285,7 @@ function ReevitCheckout({
2243
2285
  {
2244
2286
  paymentId: paymentIntent?.id || "",
2245
2287
  publicKey,
2246
- merchantAccount: pspKey,
2288
+ merchantAccount: paymentIntent?.pspCredentials?.merchantAccount || "",
2247
2289
  amount: paymentIntent?.amount ?? amount,
2248
2290
  currency: paymentIntent?.currency ?? currency,
2249
2291
  reference: paymentIntent?.reference || reference,
@@ -2409,7 +2451,17 @@ function ReevitCheckout({
2409
2451
  "aria-modal": "true",
2410
2452
  children: [
2411
2453
  /* @__PURE__ */ jsxs("div", { className: "reevit-modal__header", children: [
2412
- /* @__PURE__ */ jsx("div", { className: "reevit-modal__branding", children: /* @__PURE__ */ jsx("img", { src: resolvedTheme?.logoUrl || "https://i.imgur.com/bzUR5Lm.png", alt: "Checkout", className: "reevit-modal__logo" }) }),
2454
+ /* @__PURE__ */ jsxs("div", { className: "reevit-modal__branding", children: [
2455
+ /* @__PURE__ */ jsx(
2456
+ "img",
2457
+ {
2458
+ src: resolvedTheme?.logoUrl || "https://i.imgur.com/bzUR5Lm.png",
2459
+ alt: brandName || "Reevit",
2460
+ className: "reevit-modal__logo"
2461
+ }
2462
+ ),
2463
+ brandName && /* @__PURE__ */ jsx("span", { className: "reevit-modal__brand-name", children: brandName })
2464
+ ] }),
2413
2465
  /* @__PURE__ */ jsx("button", { className: "reevit-modal__close", onClick: handleClose, "aria-label": "Close", children: "\u2715" })
2414
2466
  ] }),
2415
2467
  /* @__PURE__ */ jsxs("div", { className: "reevit-modal__amount", children: [