@reevit/react 0.2.4 → 0.2.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.js CHANGED
@@ -113,7 +113,7 @@ var ReevitAPIClient = class {
113
113
  "Content-Type": "application/json",
114
114
  "X-Reevit-Key": this.publicKey,
115
115
  "X-Reevit-Client": "@reevit/react",
116
- "X-Reevit-Client-Version": "0.2.3"
116
+ "X-Reevit-Client-Version": "0.2.5"
117
117
  };
118
118
  if (method === "POST" || method === "PATCH" || method === "PUT") {
119
119
  headers["Idempotency-Key"] = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
@@ -165,13 +165,20 @@ var ReevitAPIClient = class {
165
165
  * Creates a payment intent
166
166
  */
167
167
  async createPaymentIntent(config, method, country = "GH") {
168
+ const metadata = { ...config.metadata };
169
+ if (config.email) {
170
+ metadata.customer_email = config.email;
171
+ }
172
+ if (config.phone) {
173
+ metadata.customer_phone = config.phone;
174
+ }
168
175
  const request = {
169
176
  amount: config.amount,
170
177
  currency: config.currency,
171
178
  method: this.mapPaymentMethod(method),
172
179
  country,
173
- customer_id: config.metadata?.customerId,
174
- metadata: config.metadata
180
+ customer_id: config.email || config.metadata?.customerId,
181
+ metadata
175
182
  };
176
183
  return this.request("POST", "/v1/payments/intents", request);
177
184
  }
@@ -663,9 +670,18 @@ function PaystackBridge({
663
670
  const initialized = react.useRef(false);
664
671
  const startPayment = react.useCallback(async () => {
665
672
  try {
673
+ if (!publicKey) {
674
+ throw new Error("Paystack public key is required but was empty");
675
+ }
676
+ if (!email) {
677
+ throw new Error("Email is required for Paystack payments");
678
+ }
679
+ if (!amount || amount <= 0) {
680
+ throw new Error("Valid amount is required for Paystack payments");
681
+ }
666
682
  await loadPaystackScript();
667
683
  if (!window.PaystackPop) {
668
- throw new Error("Paystack not available");
684
+ throw new Error("Paystack script loaded but PaystackPop not available");
669
685
  }
670
686
  const handler = window.PaystackPop.setup({
671
687
  key: publicKey,
@@ -697,9 +713,10 @@ function PaystackBridge({
697
713
  });
698
714
  handler.openIframe();
699
715
  } catch (err) {
716
+ const errorMessage = err instanceof Error ? err.message : "Failed to initialize Paystack";
700
717
  const error = {
701
718
  code: "PSP_ERROR",
702
- message: "Failed to initialize Paystack",
719
+ message: errorMessage,
703
720
  recoverable: true,
704
721
  originalError: err
705
722
  };