epic-collection-gateway-sdk 1.0.2 → 1.0.3

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/README.md CHANGED
@@ -1,248 +1,264 @@
1
- # Epic Pay Collection Payment Gateway SDK (Demo)
1
+ # Epic Collection Gateway SDK
2
2
 
3
- A lightweight demo SDK exposing a payment sheet with three flows: Pay by Card, Pay by Bank, and Pay by Epic Pay. Intended for integration demos and sandbox presentations.
3
+ A lightweight TypeScript/JavaScript SDK for integrating **Epic Collections Web Checkout** into your web storefront. It handles authentication, redirect-flow initiation, and return-URL parsing no backend proxy required on your end.
4
4
 
5
- ## Features
5
+ ---
6
6
 
7
- - Minimal, framework-agnostic checkout modal
8
- - Three demo payment methods: `card`, `bank`, `epic`
9
- - Simple event callbacks via `onEvent`
10
- - Zero backend required (simulated success/failure)
7
+ ## Features
11
8
 
12
- ## Installation
9
+ - **`startEpicCollectionPayment`** – Authenticate with the Epic Collections API and get the redirect URL to the hosted payment portal in one call.
10
+ - **`redirectToPortal`** – Build a portal redirect URL manually (useful when you already have credentials configured via `initEpicPay`).
11
+ - **`parsePaymentResponseFromUrl`** – Parse query-string / hash parameters on your return page after the user completes (or cancels) payment.
12
+ - **`initEpicPay`** – Optional global config initializer (environment, APIbase, event callbacks, etc.).
13
+ - Zero dependencies, ESM-only, full TypeScript types included.
13
14
 
14
- Published name: `epic-pay-sdk` (demo).
15
+ ---
15
16
 
16
- Install from npm:
17
+ ## Installation
17
18
 
18
19
  ```bash
19
- npm i epic-pay-sdk
20
+ npm install epic-collection-gateway-sdk
20
21
  ```
21
22
 
22
- ## Quick start
23
+ ---
24
+
25
+ ## Quick Start
23
26
 
24
27
  ```ts
25
- import { initEpicPay, openPaymentSheet } from "epic-pay-sdk";
28
+ import { startEpicCollectionPayment } from "epic-collection-gateway-sdk";
26
29
 
27
- initEpicPay({ environment: "sandbox" });
30
+ const url = await startEpicCollectionPayment({
31
+ environment: "sandbox",
32
+ clientId: "YOUR_CLIENT_ID",
33
+ clientSecret: "YOUR_CLIENT_SECRET",
34
+ redirectUrl: "https://your-site.com/order-result",
35
+ amount: 2500,
36
+ sessionId: "unique_order_session_id",
37
+ customerDetails: { email: "user@example.com" },
38
+ });
28
39
 
29
- // Trigger at checkout
30
- const result = await openPaymentSheet({ amount: 999, currency: "₦" });
31
- if (result.status === "succeeded") {
32
- console.log("Paid", result.transactionId);
33
- }
40
+ // Navigate the user to the hosted payment portal
41
+ window.location.assign(url);
34
42
  ```
35
43
 
36
- ## Usage
37
-
38
- ### ESM (bundlers like Vite, Webpack, Next.js)
44
+ On your `redirectUrl` page, parse the response:
39
45
 
40
46
  ```ts
41
- import EpicPay, {
42
- initEpicPay,
43
- openPaymentSheet,
44
- closePaymentSheet,
45
- } from "epic-pay-sdk";
47
+ import { parsePaymentResponseFromUrl } from "epic-collection-gateway-sdk";
46
48
 
47
- initEpicPay({
48
- merchantId: "demo_merchant_123",
49
- environment: "sandbox",
50
- onEvent: (e) => console.log("[EpicPay event]", e),
51
- });
49
+ const result = parsePaymentResponseFromUrl();
50
+ // { status, paymentRef, sessionId, ... }
51
+ console.log(result);
52
+ ```
52
53
 
53
- // On checkout
54
- const result = await openPaymentSheet({
55
- amount: 999,
56
- currency: "₦",
57
- paymentMethods: ["card", "bank", "epic"],
58
- });
59
- if (result.status === "succeeded") {
60
- console.log("Paid", result.transactionId);
61
- }
54
+ ---
62
55
 
63
- // You can programmatically close the sheet if needed
64
- closePaymentSheet();
65
- ```
56
+ ## API Reference
66
57
 
67
- ### Vanilla JS (no framework)
58
+ ### `startEpicCollectionPayment(options)` `Promise<string>`
68
59
 
69
- Import via your bundler/ESM pipeline and call from regular scripts:
60
+ Authenticates your session with the Epic Collections backend and returns the fully-qualified portal redirect URL. This is the **primary integration function** for most storefronts.
70
61
 
71
- ```js
72
- import { initEpicPay, openPaymentSheet, closePaymentSheet } from "epic-pay-sdk";
62
+ | Option | Type | Required | Description |
63
+ |---|---|---|---|
64
+ | `environment` | `string` | ✅ | Environment (sandbox or production). |
65
+ | `clientId` | `string` | ✅ | Issued from the Epic Collections Admin Portal (min 16 chars). |
66
+ | `clientSecret` | `string` | ✅ | Issued from the Epic Collections Admin Portal (min 16 chars). |
67
+ | `redirectUrl` | `string` | ✅ | Merchant callback URL — where the user lands after payment or cancellation. |
68
+ | `amount` | `number` | ✅ | Checkout amount (e.g. `2500` for ₦2,500). |
69
+ | `sessionId` | `string` | ✅ | Unique identifier for this checkout session / order (min 16 chars). |
70
+ | `customerDetails` | `EpicCollectioncustomerDetails` | — | Optional customer info forwarded to the portal. |
73
71
 
74
- initEpicPay({ environment: "sandbox" });
75
- document.getElementById("pay-btn").addEventListener("click", async () => {
76
- try {
77
- const res = await openPaymentSheet({ amount: 500, currency: "₦" });
78
- console.log(res);
79
- } catch (err) {
80
- console.error(err);
81
- }
82
- });
72
+ **`EpicCollectioncustomerDetails`**
73
+
74
+ ```ts
75
+ interface EpicCollectioncustomerDetails {
76
+ name?: string;
77
+ email?: string;
78
+ phone?: string;
79
+ }
83
80
  ```
84
81
 
85
- ## API
82
+ **Example — React checkout button**
86
83
 
87
- - **`initEpicPay(options)`**
84
+ ```tsx
85
+ import { startEpicCollectionPayment } from "epic-collection-gateway-sdk";
88
86
 
89
- - `merchantId?: string`
90
- - `environment?: 'sandbox' | 'production'` (default: `sandbox`)
91
- - `onEvent?: (event) => void` event callback
87
+ function CheckoutButton({ cartItems }: { cartItems: CartItem[] }) {
88
+ const [paying, setPaying] = useState(false);
89
+ const total = cartItems.reduce((sum, i) => sum + i.price * i.quantity, 0);
92
90
 
93
- - **`openPaymentSheet(params)` -> `Promise<PaymentResult>`**
91
+ const handleCheckout = async () => {
92
+ if (!cartItems.length) return;
93
+ try {
94
+ setPaying(true);
95
+ const url = await startEpicCollectionPayment({
96
+ environment: "sandbox",
97
+ clientId: "YOUR_CLIENT_ID",
98
+ clientSecret: "YOUR_CLIENT_SECRET",
99
+ redirectUrl: "https://your-site.com",
100
+ amount: total,
101
+ sessionId: crypto.randomUUID(), // unique per order
102
+ customerDetails: { email: "user@example.com" },
103
+ });
104
+ window.location.assign(url);
105
+ } catch (err) {
106
+ console.error("Payment initiation failed:", err);
107
+ } finally {
108
+ setPaying(false);
109
+ }
110
+ };
94
111
 
95
- - `amount: number` (required)
96
- - `currency?: string` (default: `₦`)
97
- - `customer?: Record<string, any>`
98
- - `paymentMethods?: ('card' | 'bank' | 'epic')[]` (default: all)
112
+ return (
113
+ <button onClick={handleCheckout} disabled={!cartItems.length || paying}>
114
+ {paying ? "Processing…" : `Pay ₦${total.toFixed(2)}`}
115
+ </button>
116
+ );
117
+ }
118
+ ```
99
119
 
100
- Notes:
120
+ ---
101
121
 
102
- - Must be called in a browser environment (uses DOM to render a modal sheet).
103
- - Prevents multiple concurrent sheets; rejects if one is already open.
122
+ ### `redirectToPortal(params)` `string`
104
123
 
105
- - **`closePaymentSheet()`** closes the sheet.
124
+ Builds and returns the portal URL without making an auth API call. Use this if credentials are already set via `initEpicPay` and you want manual control.
106
125
 
107
- ### Events
126
+ | Param | Type | Required | Description |
127
+ |---|---|---|---|
128
+ | `amount` | `number` | ✅ | Checkout amount. |
129
+ | `sessionId` | `string` | ✅ | Unique checkout session ID. |
130
+ | `redirectUrl` | `string` | — | Overrides the `redirectUrl` set in `initEpicPay`. |
131
+ | `customerDetails` | `EpicCollectioncustomerDetails` | — | Optional customer metadata. |
132
+ | `additionalParams` | `Record<string, string \| number \| boolean>` | — | Any extra query params to append to the URL. |
108
133
 
109
- Events emitted to `onEvent`:
134
+ > **Note:** `initEpicPay({ redirectUrl: "..." })` must be called before `redirectToPortal`, or a `redirectUrl` must be passed directly in params.
110
135
 
111
- - `payment_opened`
112
- - `payment_initiated`
113
- - `payment_succeeded`
114
- - `payment_failed`
115
- - `payment_closed`
136
+ ```ts
137
+ import { initEpicPay, redirectToPortal } from "epic-collection-gateway-sdk";
116
138
 
117
- ## TypeScript
139
+ initEpicPay({
140
+ redirectUrl: "https://pay.your-portal.com/checkout",
141
+ clientId: "YOUR_CLIENT_ID",
142
+ clientSecret: "YOUR_CLIENT_SECRET",
143
+ });
118
144
 
119
- Type definitions are included at `epic-pay-sdk/index.d.ts`.
145
+ const url = redirectToPortal({
146
+ amount: 2300,
147
+ sessionId: "sess_123456789",
148
+ redirectUrl: "https://your-site.com/order-result",
149
+ customerDetails: { email: "user@example.com" },
150
+ });
120
151
 
121
- - `EpicPayInitOptions`
122
- - `OpenPaymentSheetParams`
123
- - `PaymentResult` union with `succeeded | cancelled | failed`
152
+ window.location.assign(url);
153
+ ```
154
+
155
+ ---
124
156
 
125
- Importing with types:
157
+ ### `parsePaymentResponseFromUrl(raw?)` → `Record<string, string>`
158
+
159
+ Parses query-string or hash parameters from the current page URL (or a custom string) and returns them as a plain object. Call this on your `redirectUrl` return page.
126
160
 
127
161
  ```ts
128
- import type { OpenPaymentSheetParams, PaymentResult } from "epic-pay-sdk";
162
+ import { parsePaymentResponseFromUrl } from "epic-collection-gateway-sdk";
163
+
164
+ // Automatically reads window.location.search or window.location.hash
165
+ const result = parsePaymentResponseFromUrl();
166
+
167
+ if (result.status === "success") {
168
+ console.log("Payment reference:", result.paymentRef);
169
+ console.log("Session ID:", result.sessionId);
170
+ } else {
171
+ console.warn("Payment not completed:", result.status);
172
+ }
129
173
  ```
130
174
 
131
- ## Demo app
175
+ You may also pass a raw query string:
132
176
 
133
- A simple integration demo is available in this repo at `epic-demo/`.
177
+ ```ts
178
+ const result = parsePaymentResponseFromUrl("?status=success&paymentRef=TXN_001");
179
+ ```
134
180
 
135
- ## Notes
181
+ ---
136
182
 
137
- - This is a front-end only demo. No real payments are processed.
138
- - Success is simulated (~90% chance).
139
- - Styles are injected dynamically by the SDK.
183
+ ### `initEpicPay(options?)` `void`
140
184
 
141
- ## Redirect-only integration (new flow)
185
+ Sets global SDK configuration. Call this once at app startup. All options are optional.
142
186
 
143
- If you want a redirect-only flow (the SDK only performs the redirect to your hosted portal and helps parse the return), initialize with `redirectUrl` and optional `clientId`/`clientSecret`:
187
+ | Option | Type | Default | Description |
188
+ |---|---|---|---|
189
+ | `environment` | `'sandbox' \| 'production'` | `'sandbox'` | Target environment. |
190
+ | `apiBase` | `string` | — | Base URL for the Epic Collections API. |
191
+ | `redirectUrl` | `string` | — | Default portal redirect URL. |
192
+ | `clientId` | `string` | — | Client ID (can be passed here or per-call). |
193
+ | `clientSecret` | `string` | — | Client secret (can be passed here or per-call). |
194
+ | `headers` | `Record<string, string>` | — | Custom headers appended to API requests. |
195
+ | `onEvent` | `(event: PaymentEvent) => void` | — | Global event callback. |
144
196
 
145
197
  ```ts
146
- import { initEpicPay, redirectToPortal, parsePaymentResponseFromUrl } from 'epic-pay-sdk';
198
+ import { initEpicPay } from "epic-collection-gateway-sdk";
147
199
 
148
200
  initEpicPay({
149
- redirectUrl: 'https://pay.your-portal.com/checkout',
150
- clientId: 'your_public_client_id',
151
- });
152
-
153
- // When user clicks "Proceed to pay" on the integrator page:
154
- redirectToPortal({
155
- amount: 2300,
156
- currency: 'NGN',
157
- customerEmail: 'user@example.com', // optional
158
- sessionId: 'sess_123456789',
159
- returnUrl: 'https://merchant.example.com/order-success',
201
+ environment: "production",
202
+ onEvent: (e) => console.log("[EpicPay event]", e.type, e.payload),
160
203
  });
161
-
162
- // On your returnUrl page, parse the response:
163
- const res = parsePaymentResponseFromUrl();
164
- // res may contain: sessionId, paymentRef, status, and any other keys your portal includes
165
- console.log(res);
166
204
  ```
167
205
 
168
- ## License
169
-
170
- MIT
171
-
172
206
  ---
173
207
 
174
- ## Epic Collections Web Checkout integration (React example)
208
+ ## TypeScript Types
175
209
 
176
- This is a concrete example of how a React storefront (like `eCommerceFE`) integrates with this SDK for the Epic Collections Web Checkout flow.
210
+ All types are exported from the package root:
177
211
 
178
- ### Example: Checkout button in a React header/cart component
212
+ ```ts
213
+ import type {
214
+ EpicPayInitOptions,
215
+ EpicPayEnvironment,
216
+ StartEpicCollectionPaymentOptions,
217
+ EpicCollectioncustomerDetails,
218
+ RedirectToPortalParams,
219
+ EpicPayConfig,
220
+ PaymentEvent,
221
+ PaymentResult,
222
+ CustomerInfo,
223
+ } from "epic-collection-gateway-sdk";
224
+ ```
179
225
 
180
- ```tsx
181
- import { startEpicCollectionPayment } from '@naderepic/epic-collection-payment-gateway-sdk';
226
+ | Type | Description |
227
+ |---|---|
228
+ | `EpicPayInitOptions` | Options for `initEpicPay()`. |
229
+ | `StartEpicCollectionPaymentOptions` | Options for `startEpicCollectionPayment()`. |
230
+ | `RedirectToPortalParams` | Params for `redirectToPortal()`. |
231
+ | `EpicCollectioncustomerDetails` | Optional customer fields forwarded to the portal. |
232
+ | `PaymentEvent` | Event object emitted via `onEvent`. Shape: `{ type, payload, timestamp }`. |
233
+ | `PaymentResult` | Result shape returned from the portal on the return URL. |
182
234
 
183
- function CheckoutButton({ cartItems }) {
184
- const [paying, setPaying] = useState(false);
185
- const total = cartItems.reduce((sum, i) => sum + i.price * i.quantity, 0);
235
+ ---
186
236
 
187
- const handleCheckout = async () => {
188
- if (cartItems.length === 0) return;
189
- try {
190
- setPaying(true);
191
- const sessionId = '2349283949994959000345340212778'; // generate per order in production
237
+ ## Default Export
192
238
 
193
- const url = await startEpicCollectionPayment({
194
- clientId: '3cEePs32ipRTQkBRn0c33gAb7UOqcLPwMBMNhDgK',
195
- clientSecret: 'mye008uvYFzqWUQEjLGBbIuWd8eEJmhSRUPy1IlmsZlCa84apHxNrsDGvSLVVL5z',
196
- redirectUrl: 'https://your-site.com/order-result',
197
- amount: total,
198
- sessionId,
199
- customerDetails: {
200
- email: 'user@gmail.com',
201
- },
202
- });
239
+ A convenience object is available as the default export:
203
240
 
204
- window.location.assign(url);
205
- } finally {
206
- setPaying(false);
207
- }
208
- };
241
+ ```ts
242
+ import EpicCollectionSdk from "epic-collection-gateway-sdk";
209
243
 
210
- return (
211
- <button
212
- onClick={handleCheckout}
213
- disabled={cartItems.length === 0 || paying}
214
- >
215
- {paying ? 'Processing...' : `Proceed to Pay ( ₦${total.toFixed(2)})`}
216
- </button>
217
- );
218
- }
244
+ const { startEpicCollectionPayment, redirectToPortal, parsePaymentResponseFromUrl, initEpicPay } = EpicCollectionSdk;
219
245
  ```
220
246
 
221
- ### Options passed from frontend to the SDK
247
+ ---
222
248
 
223
- The options object passed to `startEpicCollectionPayment` has the following shape on the **frontend**:
249
+ ## Environment Variables (SDK-internal)
224
250
 
225
- ```json
226
- {
227
- "clientId": "<clientId>",
228
- "clientSecret": "<clientSecret>",
229
- "redirectUrl": "https://your-site.com/order-result",
230
- "amount": <amount>,
231
- "sessionId": "<sessionId>",
232
- "customerDetails": {
233
- "email": "user@example.com"
234
- }
235
- }
236
- ```
251
+ When bundling the SDK from source, the following `VITE_` environment variables are resolved at build time:
252
+
253
+ | Variable | Purpose |
254
+ |---|---|
255
+ | `VITE_PORTAL_URL` | Overrides the default payment portal base URL. |
256
+ | `VITE_EPIC_ENVIRONMENT` | Sets the default environment (`sandbox` / `production`). |
257
+
258
+ > These are for SDK development only. Integrators do **not** need to set these — pass `apiBase` / `redirectUrl` via `initEpicPay` or `startEpicCollectionPayment` instead.
237
259
 
238
- - `clientId`, `clientSecret` – provided by the Epic Collections Admin Portal.
239
- - `redirectUrl` – **merchant callback URL** where the shopper is sent back after payment/cancel.
240
- - `amount` – total amount for this checkout (computed from cart).
241
- - `sessionId` – unique per checkout session/order.
242
- - `customerDetails` – optional customer metadata forwarded as query params (`clientEmail`, `clientName`, `clientPhone`).
260
+ ---
243
261
 
244
- The SDK uses this **frontend** payload to:
245
- - Call the Epic backend `/web-checkout/auth` with `clientId`, `clientSecret`, `sessionId`, `amount`, `redirectUrl`, and any `customerDetails`.
246
- - Build and return the final redirect URL for the **Collections payment portal** (from `VITE_PORTAL_URL` / `VITE_EPIC_COLLECTION_PORTAL_URL` inside the SDK), which your frontend then navigates to with `window.location.assign(url)` (or your router of choice).
262
+ ## License
247
263
 
248
- > Note: For this Epic Collections Web Checkout flow you **do not need to call `initEpicPay`**. The payment portal URL is resolved inside the SDK from environment variables.
264
+ MIT
@@ -28,6 +28,7 @@ export interface EpicCollectioncustomerDetails {
28
28
  phone?: string;
29
29
  }
30
30
  export interface StartEpicCollectionPaymentOptions {
31
+ environment?: EpicPayEnvironment;
31
32
  clientId: string;
32
33
  clientSecret: string;
33
34
  /** Merchant callback URL where the shopper is sent back after payment/cancel */
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- const f = { BASE_URL: "/", MODE: "production", DEV: !1, PROD: !0, SSR: !1 }, m = f.VITE_PORTAL_URL || "https://checkout.epicpay.co", E = f.VITE_PORTAL_URL || "https://zppicbcegi.execute-api.af-south-1.amazonaws.com/prod/api/v1", y = f.VITE_EPIC_ENVIRONMENT || "", s = {
2
- environment: y,
3
- apiBase: E,
1
+ const u = "https://checkout.epicpay.co", y = "https://zppicbcegi.execute-api.af-south-1.amazonaws.com/prod/api/v1", s = {
2
+ environment: "",
3
+ apiBase: y,
4
4
  headers: {},
5
- redirectUrl: m,
5
+ redirectUrl: u,
6
6
  clientId: "",
7
7
  clientSecret: "",
8
8
  dryRun: !0,
@@ -11,83 +11,86 @@ const f = { BASE_URL: "/", MODE: "production", DEV: !1, PROD: !0, SSR: !1 }, m =
11
11
  function p(e) {
12
12
  Object.assign(s, e);
13
13
  }
14
- function u(e) {
15
- const { amount: n, sessionId: i, additionalParams: c, redirectUrl: o } = e, r = s.redirectUrl || s.apiBase;
16
- if (!r)
14
+ function m(e) {
15
+ const { amount: r, sessionId: c, additionalParams: n, redirectUrl: i } = e, a = s.redirectUrl || s.apiBase;
16
+ if (!a)
17
17
  throw new Error('No redirectUrl configured. Call initEpicPay({ redirectUrl: "https://..." }).');
18
18
  const t = {
19
- amount: String(n),
20
- sessionId: i
19
+ amount: String(r),
20
+ sessionId: c
21
21
  };
22
- o && (t.redirectUrl = String(o)), s.clientId && (t.clientId = s.clientId), s.clientSecret && (t.clientSecret = s.clientSecret), c && Object.keys(c).forEach((a) => {
23
- t[a] = String(c[a]);
22
+ i && (t.redirectUrl = String(i)), s.clientId && (t.clientId = s.clientId), s.clientSecret && (t.clientSecret = s.clientSecret), n && Object.keys(n).forEach((d) => {
23
+ t[d] = String(n[d]);
24
24
  });
25
- const l = Object.keys(t).map((a) => `${encodeURIComponent(a)}=${encodeURIComponent(t[a])}`).join("&"), h = r + (r.includes("?") ? "&" : "?") + l;
25
+ const o = Object.keys(t).map((d) => `${encodeURIComponent(d)}=${encodeURIComponent(t[d])}`).join("&"), l = a + (a.includes("?") ? "&" : "?") + o;
26
26
  try {
27
- console.log("[EpicPay] redirectToPortal", { portal: r, amount: n, sessionId: i });
27
+ console.log("[EpicPay] redirectToPortal", { portal: a, amount: r, sessionId: c });
28
28
  } catch {
29
29
  }
30
30
  try {
31
- console.log("[EpicPay] redirectToPortal URL:", h);
31
+ console.log("[EpicPay] redirectToPortal URL:", l);
32
32
  } catch {
33
33
  }
34
- return h;
34
+ return l;
35
35
  }
36
36
  async function g(e) {
37
- const { clientId: n, clientSecret: i, redirectUrl: c, amount: o, sessionId: r, customerDetails: t } = e;
38
- if (!n || typeof n != "string" || n.length < 16)
37
+ const { environment: r, clientId: c, clientSecret: n, redirectUrl: i, amount: a, sessionId: t, customerDetails: o } = e;
38
+ if (!r || typeof r != "string")
39
+ throw new Error("Invalid environment");
40
+ if (!c || typeof c != "string" || c.length < 16)
39
41
  throw new Error("Invalid clientId");
40
- if (!i || typeof i != "string" || i.length < 16)
42
+ if (!n || typeof n != "string" || n.length < 16)
41
43
  throw new Error("Invalid clientSecret");
42
- if (!r || typeof r != "string" || r.length < 16)
44
+ if (!t || typeof t != "string" || t.length < 16)
43
45
  throw new Error("Invalid sessionId");
44
- if (!c || typeof c != "string")
46
+ if (!i || typeof i != "string")
45
47
  throw new Error("Invalid redirectUrl");
46
48
  p({
47
- clientId: n,
48
- clientSecret: i
49
+ environment: r,
50
+ clientId: c,
51
+ clientSecret: n
49
52
  });
50
53
  const l = s.apiBase;
51
54
  if (!l)
52
55
  throw new Error("No API base configured for authentication");
53
- const h = (l.endsWith("/") ? l.slice(0, -1) : l) + "/web-checkout/auth", a = await fetch(h, {
56
+ const d = (l.endsWith("/") ? l.slice(0, -1) : l) + "/web-checkout/auth", f = await fetch(d, {
54
57
  method: "POST",
55
58
  headers: { "Content-Type": "application/json", grabbersbeware: "getthehellout989898" },
56
59
  body: JSON.stringify({
57
- clientId: n,
58
- clientSecret: i,
59
- sessionId: r,
60
- amount: o,
61
- redirectUrl: c,
62
- customerDetails: t
60
+ clientId: c,
61
+ clientSecret: n,
62
+ sessionId: t,
63
+ amount: a,
64
+ redirectUrl: i,
65
+ customerDetails: o
63
66
  })
64
67
  });
65
- if (!a.ok)
68
+ if (!f.ok)
66
69
  throw new Error("Authentication request failed");
67
70
  try {
68
- await a.json();
71
+ await f.json();
69
72
  } catch {
70
73
  }
71
- const d = {};
72
- return d.clientSecret = i, t && (t.name && (d.clientName = String(t.name)), t.email && (d.clientEmail = String(t.email)), t.phone && (d.clientPhone = String(t.phone))), u({
73
- amount: o,
74
- sessionId: r,
75
- additionalParams: d,
76
- redirectUrl: c
74
+ const h = {};
75
+ return h.clientSecret = n, o && (o.name && (h.clientName = String(o.name)), o.email && (h.clientEmail = String(o.email)), o.phone && (h.clientPhone = String(o.phone))), m({
76
+ amount: a,
77
+ sessionId: t,
78
+ additionalParams: h,
79
+ redirectUrl: i
77
80
  });
78
81
  }
79
82
  function w(e) {
80
- const n = e ?? (typeof window < "u" ? window.location.search || window.location.hash : ""), i = n.startsWith("?") || n.startsWith("#") ? n.substring(1) : n, c = new URLSearchParams(i), o = {};
81
- c.forEach((r, t) => {
82
- o[t] = r;
83
+ const r = e ?? (typeof window < "u" ? window.location.search || window.location.hash : ""), c = r.startsWith("?") || r.startsWith("#") ? r.substring(1) : r, n = new URLSearchParams(c), i = {};
84
+ n.forEach((a, t) => {
85
+ i[t] = a;
83
86
  });
84
87
  try {
85
- console.log("[EpicPay] parsePaymentResponseFromUrl", o);
88
+ console.log("[EpicPay] parsePaymentResponseFromUrl", i);
86
89
  } catch {
87
90
  }
88
- return o;
91
+ return i;
89
92
  }
90
- function I(e = {}) {
93
+ function E(e = {}) {
91
94
  p({
92
95
  environment: e.environment ?? "sandbox",
93
96
  apiBase: e.apiBase,
@@ -102,13 +105,13 @@ function I(e = {}) {
102
105
  } catch {
103
106
  }
104
107
  }
105
- const S = { initEpicPay: I, redirectToPortal: u, parsePaymentResponseFromUrl: w, startEpicCollectionPayment: g };
108
+ const I = { initEpicPay: E, redirectToPortal: m, parsePaymentResponseFromUrl: w, startEpicCollectionPayment: g };
106
109
  export {
107
- S as default,
110
+ I as default,
108
111
  s as epicConfig,
109
- I as initEpicPay,
112
+ E as initEpicPay,
110
113
  w as parsePaymentResponseFromUrl,
111
- u as redirectToPortal,
114
+ m as redirectToPortal,
112
115
  p as setConfig,
113
116
  g as startEpicCollectionPayment
114
117
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "epic-collection-gateway-sdk",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",