@reevit/react 0.2.3 → 0.2.5
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 +19 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -107,15 +107,19 @@ var ReevitAPIClient = class {
|
|
|
107
107
|
async request(method, path, body) {
|
|
108
108
|
const controller = new AbortController();
|
|
109
109
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
110
|
+
const headers = {
|
|
111
|
+
"Content-Type": "application/json",
|
|
112
|
+
"X-Reevit-Key": this.publicKey,
|
|
113
|
+
"X-Reevit-Client": "@reevit/react",
|
|
114
|
+
"X-Reevit-Client-Version": "0.2.3"
|
|
115
|
+
};
|
|
116
|
+
if (method === "POST" || method === "PATCH" || method === "PUT") {
|
|
117
|
+
headers["Idempotency-Key"] = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
|
|
118
|
+
}
|
|
110
119
|
try {
|
|
111
120
|
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
112
121
|
method,
|
|
113
|
-
headers
|
|
114
|
-
"Content-Type": "application/json",
|
|
115
|
-
"Authorization": `Bearer ${this.publicKey}`,
|
|
116
|
-
"X-Reevit-Client": "@reevit/react",
|
|
117
|
-
"X-Reevit-Client-Version": "1.0.0"
|
|
118
|
-
},
|
|
122
|
+
headers,
|
|
119
123
|
body: body ? JSON.stringify(body) : void 0,
|
|
120
124
|
signal: controller.signal
|
|
121
125
|
});
|
|
@@ -159,13 +163,20 @@ var ReevitAPIClient = class {
|
|
|
159
163
|
* Creates a payment intent
|
|
160
164
|
*/
|
|
161
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
|
+
}
|
|
162
173
|
const request = {
|
|
163
174
|
amount: config.amount,
|
|
164
175
|
currency: config.currency,
|
|
165
176
|
method: this.mapPaymentMethod(method),
|
|
166
177
|
country,
|
|
167
|
-
customer_id: config.metadata?.customerId,
|
|
168
|
-
metadata
|
|
178
|
+
customer_id: config.email || config.metadata?.customerId,
|
|
179
|
+
metadata
|
|
169
180
|
};
|
|
170
181
|
return this.request("POST", "/v1/payments/intents", request);
|
|
171
182
|
}
|