@miden-npm/react 0.0.18 → 1.0.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.cts CHANGED
@@ -50,6 +50,15 @@ interface IPaymentObject {
50
50
  narration: string;
51
51
  redirectUrl?: string;
52
52
  }
53
+ interface ISuccessObject {
54
+ paymentDate: string | null;
55
+ paymentId: string;
56
+ paymentStatus: string;
57
+ message?: string;
58
+ }
59
+ interface IErrorObject {
60
+ errorMessage: string;
61
+ }
53
62
 
54
63
  declare function usePaymentIntents(): {
55
64
  create: (p: CreatePaymentIntentParams) => Promise<PaymentIntent>;
@@ -64,8 +73,9 @@ interface IBzpCheckoutButtonProps {
64
73
  environment?: "sandbox" | "production";
65
74
  paymentObject: IPaymentObject;
66
75
  mode?: "redirect" | "iframe";
76
+ onError?: (error: IErrorObject) => void;
67
77
  }
68
- declare function BzpCheckoutButton({ secretKey, environment, paymentObject, mode, }: IBzpCheckoutButtonProps): react_jsx_runtime.JSX.Element;
78
+ declare function BzpCheckoutButton({ secretKey, environment, paymentObject, mode, onError, }: IBzpCheckoutButtonProps): react_jsx_runtime.JSX.Element;
69
79
 
70
80
  interface IIframeStyle {
71
81
  width?: string;
@@ -80,8 +90,9 @@ interface IBzpCheckoutIframeProps {
80
90
  secretKey: string;
81
91
  environment?: "sandbox" | "production";
82
92
  paymentObject?: IPaymentObject;
93
+ onError?: (error: IErrorObject) => void;
83
94
  }
84
- declare function BzpCheckoutIframe({ style, url, secretKey, environment, paymentObject, }: IBzpCheckoutIframeProps): react_jsx_runtime.JSX.Element;
95
+ declare function BzpCheckoutIframe({ style, url, secretKey, environment, paymentObject, onError, }: IBzpCheckoutIframeProps): react_jsx_runtime.JSX.Element;
85
96
 
86
97
  interface CheckoutIframeStyle {
87
98
  [cssProp: string]: string | number;
@@ -102,7 +113,9 @@ interface IBzpCheckoutCardProps {
102
113
  environment: "sandbox" | "prod";
103
114
  paymentObject: IPaymentObject;
104
115
  options?: CheckoutCardOptions;
116
+ onPaymentAuthorized?: (data: ISuccessObject) => void;
117
+ onError?: (error: IErrorObject) => void;
105
118
  }
106
- declare function BzpCheckoutCard({ secretKey, options, environment, paymentObject, }: IBzpCheckoutCardProps): react_jsx_runtime.JSX.Element;
119
+ declare function BzpCheckoutCard({ secretKey, options, environment, paymentObject, onPaymentAuthorized, onError, }: IBzpCheckoutCardProps): react_jsx_runtime.JSX.Element;
107
120
 
108
121
  export { BzpCheckoutButton, BzpCheckoutCard, BzpCheckoutIframe, type CheckoutCardOptions, type CheckoutIframeStyle, type ConfirmCardPaymentParams, type CreatePaymentIntentParams, MidenPGClient, type MidenPGConfig, MidenPGProvider, type PaymentIntent, useMidenPGClient, usePaymentIntents };
package/dist/index.d.ts CHANGED
@@ -50,6 +50,15 @@ interface IPaymentObject {
50
50
  narration: string;
51
51
  redirectUrl?: string;
52
52
  }
53
+ interface ISuccessObject {
54
+ paymentDate: string | null;
55
+ paymentId: string;
56
+ paymentStatus: string;
57
+ message?: string;
58
+ }
59
+ interface IErrorObject {
60
+ errorMessage: string;
61
+ }
53
62
 
54
63
  declare function usePaymentIntents(): {
55
64
  create: (p: CreatePaymentIntentParams) => Promise<PaymentIntent>;
@@ -64,8 +73,9 @@ interface IBzpCheckoutButtonProps {
64
73
  environment?: "sandbox" | "production";
65
74
  paymentObject: IPaymentObject;
66
75
  mode?: "redirect" | "iframe";
76
+ onError?: (error: IErrorObject) => void;
67
77
  }
68
- declare function BzpCheckoutButton({ secretKey, environment, paymentObject, mode, }: IBzpCheckoutButtonProps): react_jsx_runtime.JSX.Element;
78
+ declare function BzpCheckoutButton({ secretKey, environment, paymentObject, mode, onError, }: IBzpCheckoutButtonProps): react_jsx_runtime.JSX.Element;
69
79
 
70
80
  interface IIframeStyle {
71
81
  width?: string;
@@ -80,8 +90,9 @@ interface IBzpCheckoutIframeProps {
80
90
  secretKey: string;
81
91
  environment?: "sandbox" | "production";
82
92
  paymentObject?: IPaymentObject;
93
+ onError?: (error: IErrorObject) => void;
83
94
  }
84
- declare function BzpCheckoutIframe({ style, url, secretKey, environment, paymentObject, }: IBzpCheckoutIframeProps): react_jsx_runtime.JSX.Element;
95
+ declare function BzpCheckoutIframe({ style, url, secretKey, environment, paymentObject, onError, }: IBzpCheckoutIframeProps): react_jsx_runtime.JSX.Element;
85
96
 
86
97
  interface CheckoutIframeStyle {
87
98
  [cssProp: string]: string | number;
@@ -102,7 +113,9 @@ interface IBzpCheckoutCardProps {
102
113
  environment: "sandbox" | "prod";
103
114
  paymentObject: IPaymentObject;
104
115
  options?: CheckoutCardOptions;
116
+ onPaymentAuthorized?: (data: ISuccessObject) => void;
117
+ onError?: (error: IErrorObject) => void;
105
118
  }
106
- declare function BzpCheckoutCard({ secretKey, options, environment, paymentObject, }: IBzpCheckoutCardProps): react_jsx_runtime.JSX.Element;
119
+ declare function BzpCheckoutCard({ secretKey, options, environment, paymentObject, onPaymentAuthorized, onError, }: IBzpCheckoutCardProps): react_jsx_runtime.JSX.Element;
107
120
 
108
121
  export { BzpCheckoutButton, BzpCheckoutCard, BzpCheckoutIframe, type CheckoutCardOptions, type CheckoutIframeStyle, type ConfirmCardPaymentParams, type CreatePaymentIntentParams, MidenPGClient, type MidenPGConfig, MidenPGProvider, type PaymentIntent, useMidenPGClient, usePaymentIntents };
package/dist/index.js CHANGED
@@ -1741,7 +1741,8 @@ function BzpCheckoutIframe({
1741
1741
  phoneNumber: "",
1742
1742
  narration: "",
1743
1743
  redirectUrl: "https://sandbox-merchant.buzapay.com/account/three-ds-status"
1744
- }
1744
+ },
1745
+ onError
1745
1746
  }) {
1746
1747
  const containerRef = useRef(null);
1747
1748
  const iframeRef = useRef(null);
@@ -1777,21 +1778,30 @@ function BzpCheckoutIframe({
1777
1778
  return setMessage("Secret key is required.");
1778
1779
  }
1779
1780
  setLoading(true);
1780
- const response = await createPaymentLink(
1781
- paymentObject,
1782
- environment,
1783
- secretKey
1784
- );
1785
- if (response?.isSuccessful) {
1786
- setLaunchUrl(response.launchUrl ?? "");
1787
- setMessage("Payment link created successfully");
1788
- if (response.launchUrl) {
1781
+ try {
1782
+ const response = await createPaymentLink(
1783
+ paymentObject,
1784
+ environment,
1785
+ secretKey
1786
+ );
1787
+ if (response?.isSuccessful) {
1788
+ setLaunchUrl(response.launchUrl ?? "");
1789
+ setMessage("Payment link created successfully");
1790
+ if (response.launchUrl) {
1791
+ setLoading(false);
1792
+ launchIframe(`${response.launchUrl}&merchantId=${btoa(secretKey)}`);
1793
+ }
1794
+ } else {
1789
1795
  setLoading(false);
1790
- launchIframe(`${response.launchUrl}&merchantId=${btoa(secretKey)}`);
1796
+ setMessage("Failed to create payment link");
1791
1797
  }
1792
- } else {
1798
+ } catch (e) {
1799
+ setMessage(e?.message || "Failed to create payment link");
1800
+ onError?.({
1801
+ errorMessage: message
1802
+ });
1803
+ } finally {
1793
1804
  setLoading(false);
1794
- setMessage("Failed to create payment link");
1795
1805
  }
1796
1806
  };
1797
1807
  useEffect2(() => {
@@ -1818,7 +1828,8 @@ function BzpCheckoutButton({
1818
1828
  narration: "",
1819
1829
  redirectUrl: "https://sandbox-merchant.buzapay.com/account/three-ds-status"
1820
1830
  },
1821
- mode = "redirect"
1831
+ mode = "redirect",
1832
+ onError
1822
1833
  }) {
1823
1834
  const [message, setMessage] = useState3("");
1824
1835
  const [launchUrl, setLaunchUrl] = useState3("");
@@ -1853,6 +1864,9 @@ function BzpCheckoutButton({
1853
1864
  }
1854
1865
  } catch (e) {
1855
1866
  setMessage(e?.message || "Failed to create payment link");
1867
+ onError?.({
1868
+ errorMessage: message
1869
+ });
1856
1870
  } finally {
1857
1871
  setLoading(false);
1858
1872
  }
@@ -1889,7 +1903,8 @@ function PayByCard({
1889
1903
  secretKey,
1890
1904
  paymentObject,
1891
1905
  environment = "sandbox",
1892
- onPaymentAuthorized
1906
+ onPaymentAuthorized,
1907
+ onError
1893
1908
  }) {
1894
1909
  const [formIndex, setFormIndex] = useState4(0);
1895
1910
  const [message, setMessage] = useState4("");
@@ -2069,7 +2084,8 @@ function PayByCard({
2069
2084
  paymentId: response.transactionReference,
2070
2085
  paymentDate: response?.data?.updatedAt,
2071
2086
  // optional if present
2072
- paymentStatus: "Authorized"
2087
+ paymentStatus: "authorized",
2088
+ message
2073
2089
  });
2074
2090
  }
2075
2091
  setMessage("Card payment authorized successfully");
@@ -2080,7 +2096,8 @@ function PayByCard({
2080
2096
  onPaymentAuthorized?.({
2081
2097
  paymentId: response?.transactionReference,
2082
2098
  paymentDate: response?.data?.updatedAt,
2083
- paymentStatus: "Payment failed"
2099
+ paymentStatus: "payment failed",
2100
+ message
2084
2101
  });
2085
2102
  setIsMakingPayment(false);
2086
2103
  } catch (err) {
@@ -2100,6 +2117,9 @@ function PayByCard({
2100
2117
  }
2101
2118
  setMessage(friendly);
2102
2119
  setIsMakingPayment(false);
2120
+ onError?.({
2121
+ errorMessage: message
2122
+ });
2103
2123
  }
2104
2124
  }
2105
2125
  };
@@ -2129,6 +2149,9 @@ function PayByCard({
2129
2149
  }
2130
2150
  } catch (e) {
2131
2151
  setMessage(e?.message || "Failed to create payment link");
2152
+ onError?.({
2153
+ errorMessage: message
2154
+ });
2132
2155
  } finally {
2133
2156
  setLoading(false);
2134
2157
  }
@@ -2150,6 +2173,9 @@ function PayByCard({
2150
2173
  }
2151
2174
  } catch (e) {
2152
2175
  setMessage(e?.message || "Failed to get countries");
2176
+ onError?.({
2177
+ errorMessage: message
2178
+ });
2153
2179
  } finally {
2154
2180
  setLoadingCountries(false);
2155
2181
  }
@@ -2174,6 +2200,9 @@ function PayByCard({
2174
2200
  }
2175
2201
  } catch (e) {
2176
2202
  setMessage(e?.message || "Failed to get country states");
2203
+ onError?.({
2204
+ errorMessage: message
2205
+ });
2177
2206
  } finally {
2178
2207
  setLoadingStates(false);
2179
2208
  }
@@ -2429,7 +2458,8 @@ var PayByTransfer = ({
2429
2458
  paymentObject,
2430
2459
  environment = "sandbox",
2431
2460
  onPaymentAuthorized,
2432
- onCancel
2461
+ onCancel,
2462
+ onError
2433
2463
  }) => {
2434
2464
  const [formIndex, setFormIndex] = useState5(0);
2435
2465
  const [isMakingPayment, setIsMakingPayment] = useState5(false);
@@ -2486,6 +2516,9 @@ var PayByTransfer = ({
2486
2516
  } catch (err) {
2487
2517
  setIsMakingPayment(false);
2488
2518
  setMessage(err.error.responseMessage || err.error.message);
2519
+ onError?.({
2520
+ errorMessage: message
2521
+ });
2489
2522
  }
2490
2523
  }
2491
2524
  return;
@@ -2512,14 +2545,16 @@ var PayByTransfer = ({
2512
2545
  onPaymentAuthorized?.({
2513
2546
  paymentId: transactionReference,
2514
2547
  paymentDate: response.data?.updatedAt,
2515
- paymentStatus: "pending"
2548
+ paymentStatus: "pending",
2549
+ message
2516
2550
  });
2517
2551
  } else {
2518
2552
  setPaymentReferenceStatus("confirmed");
2519
2553
  onPaymentAuthorized?.({
2520
2554
  paymentId: transactionReference,
2521
2555
  paymentDate: response.data?.updatedAt,
2522
- paymentStatus: "confirmed"
2556
+ paymentStatus: "confirmed",
2557
+ message
2523
2558
  });
2524
2559
  }
2525
2560
  } else if (response.data?.finalTransactionStatus === "Success" || response.data?.paymentStatus === "Received" || response.data?.paymentStatus === "Payment Received") {
@@ -2529,7 +2564,8 @@ var PayByTransfer = ({
2529
2564
  onPaymentAuthorized?.({
2530
2565
  paymentId: transactionReference,
2531
2566
  paymentDate: response.data?.updatedAt,
2532
- paymentStatus: "confirmed"
2567
+ paymentStatus: "confirmed",
2568
+ message
2533
2569
  });
2534
2570
  }
2535
2571
  } else if (!response?.isSuccessful && response?.responseCode === "119") {
@@ -2538,7 +2574,8 @@ var PayByTransfer = ({
2538
2574
  onPaymentAuthorized?.({
2539
2575
  paymentId: transactionReference,
2540
2576
  paymentDate: null,
2541
- paymentStatus: "used"
2577
+ paymentStatus: "used",
2578
+ message
2542
2579
  });
2543
2580
  }
2544
2581
  } catch (err) {
@@ -2546,6 +2583,9 @@ var PayByTransfer = ({
2546
2583
  setMessage(
2547
2584
  err?.error?.responseMessage || err?.error?.message || "Something went wrong"
2548
2585
  );
2586
+ onError?.({
2587
+ errorMessage: message
2588
+ });
2549
2589
  } finally {
2550
2590
  setIsFetchingPaymentDetails(false);
2551
2591
  }
@@ -2576,6 +2616,9 @@ var PayByTransfer = ({
2576
2616
  }
2577
2617
  } catch (e) {
2578
2618
  setMessage(e?.message || "Failed to create payment link");
2619
+ onError?.({
2620
+ errorMessage: message
2621
+ });
2579
2622
  } finally {
2580
2623
  setLoading(false);
2581
2624
  }
@@ -2718,7 +2761,8 @@ var PayByStableCoin = ({
2718
2761
  secretKey,
2719
2762
  paymentObject,
2720
2763
  environment = "sandbox",
2721
- onPaymentAuthorized
2764
+ onPaymentAuthorized,
2765
+ onError
2722
2766
  }) => {
2723
2767
  const [formIndex, setFormIndex] = useState6(0);
2724
2768
  const [message, setMessage] = useState6("");
@@ -2773,6 +2817,9 @@ var PayByStableCoin = ({
2773
2817
  }
2774
2818
  } catch (e) {
2775
2819
  setMessage(e?.message || "Failed to create payment link");
2820
+ onError?.({
2821
+ errorMessage: message
2822
+ });
2776
2823
  } finally {
2777
2824
  setLoading(false);
2778
2825
  }
@@ -2791,6 +2838,9 @@ var PayByStableCoin = ({
2791
2838
  }
2792
2839
  } catch (e) {
2793
2840
  setMessage(e?.message || "Failed to generate address");
2841
+ onError?.({
2842
+ errorMessage: message
2843
+ });
2794
2844
  } finally {
2795
2845
  setGeneratingAddress(false);
2796
2846
  }
@@ -2809,6 +2859,9 @@ var PayByStableCoin = ({
2809
2859
  }
2810
2860
  } catch (e) {
2811
2861
  setMessage(e?.message || "Failed to get stable coins");
2862
+ onError?.({
2863
+ errorMessage: message
2864
+ });
2812
2865
  } finally {
2813
2866
  setLoadingStableCoins(false);
2814
2867
  }
@@ -2830,6 +2883,9 @@ var PayByStableCoin = ({
2830
2883
  }
2831
2884
  } catch (e) {
2832
2885
  setMessage(e?.message || "Failed to get stable coin networks");
2886
+ onError?.({
2887
+ errorMessage: message
2888
+ });
2833
2889
  } finally {
2834
2890
  setLoadingStableCoinNetworks(false);
2835
2891
  }
@@ -2847,7 +2903,8 @@ var PayByStableCoin = ({
2847
2903
  onPaymentAuthorized?.({
2848
2904
  paymentId: transactionReference,
2849
2905
  paymentDate: response.data?.updatedAt ?? "",
2850
- paymentStatus: "pending"
2906
+ paymentStatus: "pending",
2907
+ message
2851
2908
  });
2852
2909
  } else if (response.data?.finalTransactionStatus === "Success" || response.data?.paymentStatus === "Payment Received") {
2853
2910
  setMessage("Transaction confirmed !!");
@@ -2855,7 +2912,8 @@ var PayByStableCoin = ({
2855
2912
  onPaymentAuthorized?.({
2856
2913
  paymentId: transactionReference,
2857
2914
  paymentDate: response.data?.updatedAt,
2858
- paymentStatus: "confirmed"
2915
+ paymentStatus: "confirmed",
2916
+ message
2859
2917
  });
2860
2918
  }
2861
2919
  } else if (!response?.isSuccessful && response?.responseCode === "119") {
@@ -2864,7 +2922,8 @@ var PayByStableCoin = ({
2864
2922
  onPaymentAuthorized?.({
2865
2923
  paymentId: transactionReference,
2866
2924
  paymentDate: null,
2867
- paymentStatus: "used"
2925
+ paymentStatus: "used",
2926
+ message
2868
2927
  });
2869
2928
  }
2870
2929
  } catch (err) {
@@ -2872,6 +2931,9 @@ var PayByStableCoin = ({
2872
2931
  setMessage(
2873
2932
  err?.error?.responseMessage || err?.error?.message || "Something went wrong"
2874
2933
  );
2934
+ onError?.({
2935
+ errorMessage: message
2936
+ });
2875
2937
  } finally {
2876
2938
  setIsConfirmingPayment(false);
2877
2939
  }
@@ -3049,7 +3111,9 @@ function BzpCheckoutCard({
3049
3111
  phoneNumber: "",
3050
3112
  narration: "",
3051
3113
  redirectUrl: "https://sandbox-merchant.buzapay.com/account/three-ds-status"
3052
- }
3114
+ },
3115
+ onPaymentAuthorized,
3116
+ onError
3053
3117
  }) {
3054
3118
  const [checkoutState, setCheckoutState] = useState7("PENDING");
3055
3119
  const paymentTypeOptions = [
@@ -3078,6 +3142,7 @@ function BzpCheckoutCard({
3078
3142
  } else {
3079
3143
  setCheckoutState("PENDING");
3080
3144
  }
3145
+ onPaymentAuthorized?.(event);
3081
3146
  };
3082
3147
  useEffect6(() => {
3083
3148
  let options2 = [];
@@ -3152,7 +3217,8 @@ function BzpCheckoutCard({
3152
3217
  secretKey,
3153
3218
  environment,
3154
3219
  paymentObject,
3155
- onPaymentAuthorized: setSuccess
3220
+ onPaymentAuthorized: setSuccess,
3221
+ onError
3156
3222
  }
3157
3223
  ) : paymentType === "BANK_TRANSFER" ? /* @__PURE__ */ jsx30(
3158
3224
  PayByTransfer,
@@ -3160,7 +3226,8 @@ function BzpCheckoutCard({
3160
3226
  secretKey,
3161
3227
  environment,
3162
3228
  paymentObject,
3163
- onPaymentAuthorized: setSuccess
3229
+ onPaymentAuthorized: setSuccess,
3230
+ onError
3164
3231
  }
3165
3232
  ) : /* @__PURE__ */ jsx30(
3166
3233
  PayByStableCoin,
@@ -3168,7 +3235,8 @@ function BzpCheckoutCard({
3168
3235
  secretKey,
3169
3236
  environment,
3170
3237
  paymentObject,
3171
- onPaymentAuthorized: setSuccess
3238
+ onPaymentAuthorized: setSuccess,
3239
+ onError
3172
3240
  }
3173
3241
  ) }),
3174
3242
  checkoutState === "SUCCESS" && /* @__PURE__ */ jsx30(