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