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