epic-collection-gateway-sdk 1.0.3 → 1.0.4

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,15 +1,13 @@
1
1
  # Epic Collection Gateway SDK
2
2
 
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.
3
+ A lightweight TypeScript/JavaScript SDK for integrating **Epic Collections Web Checkout** into your web storefront. It handles authentication and redirect-flow initiation.
4
4
 
5
5
  ---
6
6
 
7
7
  ## Features
8
8
 
9
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.).
10
+ - **`redirectToPortal`** – Build a portal redirect URL manually.
13
11
  - Zero dependencies, ESM-only, full TypeScript types included.
14
12
 
15
13
  ---
@@ -41,16 +39,6 @@ const url = await startEpicCollectionPayment({
41
39
  window.location.assign(url);
42
40
  ```
43
41
 
44
- On your `redirectUrl` page, parse the response:
45
-
46
- ```ts
47
- import { parsePaymentResponseFromUrl } from "epic-collection-gateway-sdk";
48
-
49
- const result = parsePaymentResponseFromUrl();
50
- // { status, paymentRef, sessionId, ... }
51
- console.log(result);
52
- ```
53
-
54
42
  ---
55
43
 
56
44
  ## API Reference
@@ -79,68 +67,22 @@ interface EpicCollectioncustomerDetails {
79
67
  }
80
68
  ```
81
69
 
82
- **Example — React checkout button**
83
-
84
- ```tsx
85
- import { startEpicCollectionPayment } from "epic-collection-gateway-sdk";
86
-
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);
90
-
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
- };
111
-
112
- return (
113
- <button onClick={handleCheckout} disabled={!cartItems.length || paying}>
114
- {paying ? "Processing…" : `Pay ₦${total.toFixed(2)}`}
115
- </button>
116
- );
117
- }
118
- ```
119
-
120
70
  ---
121
71
 
122
72
  ### `redirectToPortal(params)` → `string`
123
73
 
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.
74
+ Builds and returns the portal URL without making an auth API call.
125
75
 
126
76
  | Param | Type | Required | Description |
127
77
  |---|---|---|---|
128
78
  | `amount` | `number` | ✅ | Checkout amount. |
129
79
  | `sessionId` | `string` | ✅ | Unique checkout session ID. |
130
- | `redirectUrl` | `string` | — | Overrides the `redirectUrl` set in `initEpicPay`. |
80
+ | `redirectUrl` | `string` | — | Overrides the default redirect URL. |
131
81
  | `customerDetails` | `EpicCollectioncustomerDetails` | — | Optional customer metadata. |
132
82
  | `additionalParams` | `Record<string, string \| number \| boolean>` | — | Any extra query params to append to the URL. |
133
83
 
134
- > **Note:** `initEpicPay({ redirectUrl: "..." })` must be called before `redirectToPortal`, or a `redirectUrl` must be passed directly in params.
135
-
136
84
  ```ts
137
- import { initEpicPay, redirectToPortal } from "epic-collection-gateway-sdk";
138
-
139
- initEpicPay({
140
- redirectUrl: "https://pay.your-portal.com/checkout",
141
- clientId: "YOUR_CLIENT_ID",
142
- clientSecret: "YOUR_CLIENT_SECRET",
143
- });
85
+ import { redirectToPortal } from "epic-collection-gateway-sdk";
144
86
 
145
87
  const url = redirectToPortal({
146
88
  amount: 2300,
@@ -154,64 +96,12 @@ window.location.assign(url);
154
96
 
155
97
  ---
156
98
 
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.
160
-
161
- ```ts
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
- }
173
- ```
174
-
175
- You may also pass a raw query string:
176
-
177
- ```ts
178
- const result = parsePaymentResponseFromUrl("?status=success&paymentRef=TXN_001");
179
- ```
180
-
181
- ---
182
-
183
- ### `initEpicPay(options?)` → `void`
184
-
185
- Sets global SDK configuration. Call this once at app startup. All options are optional.
186
-
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. |
196
-
197
- ```ts
198
- import { initEpicPay } from "epic-collection-gateway-sdk";
199
-
200
- initEpicPay({
201
- environment: "production",
202
- onEvent: (e) => console.log("[EpicPay event]", e.type, e.payload),
203
- });
204
- ```
205
-
206
- ---
207
-
208
99
  ## TypeScript Types
209
100
 
210
101
  All types are exported from the package root:
211
102
 
212
103
  ```ts
213
104
  import type {
214
- EpicPayInitOptions,
215
105
  EpicPayEnvironment,
216
106
  StartEpicCollectionPaymentOptions,
217
107
  EpicCollectioncustomerDetails,
@@ -223,15 +113,6 @@ import type {
223
113
  } from "epic-collection-gateway-sdk";
224
114
  ```
225
115
 
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. |
234
-
235
116
  ---
236
117
 
237
118
  ## Default Export
@@ -241,24 +122,11 @@ A convenience object is available as the default export:
241
122
  ```ts
242
123
  import EpicCollectionSdk from "epic-collection-gateway-sdk";
243
124
 
244
- const { startEpicCollectionPayment, redirectToPortal, parsePaymentResponseFromUrl, initEpicPay } = EpicCollectionSdk;
125
+ const { startEpicCollectionPayment, redirectToPortal } = EpicCollectionSdk;
245
126
  ```
246
127
 
247
128
  ---
248
129
 
249
- ## Environment Variables (SDK-internal)
250
-
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.
259
-
260
- ---
261
-
262
130
  ## License
263
131
 
264
132
  MIT
@@ -1,21 +1,6 @@
1
1
  export type EpicPayEnvironment = 'sandbox' | 'production';
2
- export interface EpicPayInitOptions {
3
- merchantId?: string;
4
- environment?: EpicPayEnvironment;
5
- onEvent?: (event: {
6
- type: string;
7
- payload?: any;
8
- timestamp: number;
9
- }) => void;
10
- apiBase?: string;
11
- headers?: Record<string, string>;
12
- paymentMethodsUrl?: string;
13
- theme?: Record<string, string>;
14
- redirectUrl?: string;
15
- clientId?: string;
16
- clientSecret?: string;
17
- }
18
2
  export interface RedirectToPortalParams {
3
+ environment?: EpicPayEnvironment;
19
4
  amount: number;
20
5
  sessionId: string;
21
6
  additionalParams?: Record<string, string | number | boolean>;
@@ -39,5 +24,3 @@ export interface StartEpicCollectionPaymentOptions {
39
24
  }
40
25
  export declare function redirectToPortal(params: RedirectToPortalParams): string;
41
26
  export declare function startEpicCollectionPayment(options: StartEpicCollectionPaymentOptions): Promise<string>;
42
- export declare function parsePaymentResponseFromUrl(raw?: string): Record<string, string>;
43
- export declare function initEpicPay(options?: EpicPayInitOptions): void;
@@ -0,0 +1,5 @@
1
+ export declare const EPIC_PORTAL_URL = "https://checkout.epicpay.co";
2
+ export declare const EPIC_API_BASE = "https://zppicbcegi.execute-api.af-south-1.amazonaws.com/prod/api/v1";
3
+ export declare const EPIC_HEADERS: {
4
+ grabbersbeware: string;
5
+ };
@@ -2,4 +2,3 @@ import { EpicPayConfig } from './types';
2
2
 
3
3
  export declare const epicConfig: EpicPayConfig;
4
4
  export declare function setConfig(config: Partial<EpicPayConfig>): void;
5
- export declare function emit(type: string, payload?: any): void;
@@ -10,52 +10,4 @@ export interface EpicPayConfig {
10
10
  clientSecret?: string;
11
11
  /** If true, do not actually redirect; only log what would happen. */
12
12
  dryRun?: boolean;
13
- onEvent?: (event: PaymentEvent) => void;
14
- }
15
- export interface ThemeConfig {
16
- colorPrimaryViolet?: string;
17
- borderColor?: string;
18
- fontColor?: string;
19
- black?: string;
20
- white?: string;
21
- inputBackground?: string;
22
- tabBackground?: string;
23
- }
24
- export interface PaymentMethod {
25
- identityKey: string;
26
- methodName: string;
27
- icon?: string;
28
- }
29
- export interface PaymentSheetProps {
30
- amount: number;
31
- currency?: string;
32
- customer?: CustomerInfo;
33
- paymentMethods?: PaymentMethod[] | 'auto';
34
- onSuccess?: (result: PaymentResult) => void;
35
- onError?: (error: PaymentError) => void;
36
- onClose?: () => void;
37
- }
38
- export interface CustomerInfo {
39
- id?: string;
40
- email?: string;
41
- name?: string;
42
- phone?: string;
43
- }
44
- export interface PaymentResult {
45
- status: 'succeeded' | 'failed' | 'cancelled';
46
- method?: string;
47
- amount?: number;
48
- currency?: string;
49
- transactionId?: string;
50
- error?: string;
51
- }
52
- export interface PaymentError {
53
- status: 'failed';
54
- method?: string;
55
- error: string;
56
- }
57
- export interface PaymentEvent {
58
- type: string;
59
- payload: any;
60
- timestamp: number;
61
13
  }
package/dist/index.d.ts CHANGED
@@ -1,13 +1,11 @@
1
- import { initEpicPay, redirectToPortal, parsePaymentResponseFromUrl, startEpicCollectionPayment } from './core/api';
1
+ import { redirectToPortal, startEpicCollectionPayment } from './core/api';
2
2
  export { setConfig, epicConfig } from './core/epicConfig';
3
3
  export * from './core/types';
4
- export { initEpicPay, redirectToPortal, parsePaymentResponseFromUrl, startEpicCollectionPayment } from './core/api';
5
- export type { EpicPayInitOptions, EpicPayEnvironment } from './core/api';
4
+ export { redirectToPortal, startEpicCollectionPayment } from './core/api';
5
+ export type { EpicPayEnvironment } from './core/api';
6
6
  export type { RedirectToPortalParams, StartEpicCollectionPaymentOptions, EpicCollectioncustomerDetails } from './core/api';
7
7
  declare const EpicCollectionSdk: {
8
- initEpicPay: typeof initEpicPay;
9
8
  redirectToPortal: typeof redirectToPortal;
10
- parsePaymentResponseFromUrl: typeof parsePaymentResponseFromUrl;
11
9
  startEpicCollectionPayment: typeof startEpicCollectionPayment;
12
10
  };
13
11
  export default EpicCollectionSdk;
package/dist/index.js CHANGED
@@ -1,43 +1,44 @@
1
- const u = "https://checkout.epicpay.co", y = "https://zppicbcegi.execute-api.af-south-1.amazonaws.com/prod/api/v1", s = {
1
+ const u = "https://checkout.epicpay.co", g = "https://zppicbcegi.execute-api.af-south-1.amazonaws.com/prod/api/v1", m = {
2
+ grabbersbeware: "getthehellout989898"
3
+ }, c = {
2
4
  environment: "",
3
- apiBase: y,
5
+ apiBase: g,
4
6
  headers: {},
5
7
  redirectUrl: u,
6
8
  clientId: "",
7
9
  clientSecret: "",
8
- dryRun: !0,
9
- onEvent: void 0
10
+ dryRun: !0
10
11
  };
11
- function p(e) {
12
- Object.assign(s, e);
12
+ function w(l) {
13
+ Object.assign(c, l);
13
14
  }
14
- function m(e) {
15
- const { amount: r, sessionId: c, additionalParams: n, redirectUrl: i } = e, a = s.redirectUrl || s.apiBase;
16
- if (!a)
15
+ function p(l) {
16
+ const { environment: a, amount: r, sessionId: n, additionalParams: i, redirectUrl: d } = l, t = c.redirectUrl || c.apiBase;
17
+ if (!t)
17
18
  throw new Error('No redirectUrl configured. Call initEpicPay({ redirectUrl: "https://..." }).');
18
- const t = {
19
+ const e = {
19
20
  amount: String(r),
20
- sessionId: c
21
+ sessionId: n
21
22
  };
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]);
23
+ d && (e.redirectUrl = String(d)), c.clientId && (e.clientId = c.clientId), c.clientSecret && (e.clientSecret = c.clientSecret), a && (e.environment = String(a)), i && Object.keys(i).forEach((o) => {
24
+ e[o] = String(i[o]);
24
25
  });
25
- const o = Object.keys(t).map((d) => `${encodeURIComponent(d)}=${encodeURIComponent(t[d])}`).join("&"), l = a + (a.includes("?") ? "&" : "?") + o;
26
+ const s = Object.keys(e).map((o) => `${encodeURIComponent(o)}=${encodeURIComponent(e[o])}`).join("&"), f = t + (t.includes("?") ? "&" : "?") + s;
26
27
  try {
27
- console.log("[EpicPay] redirectToPortal", { portal: a, amount: r, sessionId: c });
28
+ console.log("[EpicPay] redirectToPortal", { portal: t, amount: r, sessionId: n });
28
29
  } catch {
29
30
  }
30
31
  try {
31
- console.log("[EpicPay] redirectToPortal URL:", l);
32
+ console.log("[EpicPay] redirectToPortal URL:", f);
32
33
  } catch {
33
34
  }
34
- return l;
35
+ return f;
35
36
  }
36
- async function g(e) {
37
- const { environment: r, clientId: c, clientSecret: n, redirectUrl: i, amount: a, sessionId: t, customerDetails: o } = e;
38
- if (!r || typeof r != "string")
37
+ async function E(l) {
38
+ const { environment: a, clientId: r, clientSecret: n, redirectUrl: i, amount: d, sessionId: t, customerDetails: e } = l;
39
+ if (!a || typeof a != "string")
39
40
  throw new Error("Invalid environment");
40
- if (!c || typeof c != "string" || c.length < 16)
41
+ if (!r || typeof r != "string" || r.length < 16)
41
42
  throw new Error("Invalid clientId");
42
43
  if (!n || typeof n != "string" || n.length < 16)
43
44
  throw new Error("Invalid clientSecret");
@@ -45,73 +46,45 @@ async function g(e) {
45
46
  throw new Error("Invalid sessionId");
46
47
  if (!i || typeof i != "string")
47
48
  throw new Error("Invalid redirectUrl");
48
- p({
49
- environment: r,
50
- clientId: c,
49
+ w({
50
+ environment: a,
51
+ clientId: r,
51
52
  clientSecret: n
52
53
  });
53
- const l = s.apiBase;
54
- if (!l)
54
+ const s = c.apiBase;
55
+ if (!s)
55
56
  throw new Error("No API base configured for authentication");
56
- const d = (l.endsWith("/") ? l.slice(0, -1) : l) + "/web-checkout/auth", f = await fetch(d, {
57
+ const f = (s.endsWith("/") ? s.slice(0, -1) : s) + "/web-checkout/auth", o = await fetch(f, {
57
58
  method: "POST",
58
- headers: { "Content-Type": "application/json", grabbersbeware: "getthehellout989898" },
59
+ headers: { "Content-Type": "application/json", ...m },
59
60
  body: JSON.stringify({
60
- clientId: c,
61
+ clientId: r,
61
62
  clientSecret: n,
62
63
  sessionId: t,
63
- amount: a,
64
+ amount: d,
64
65
  redirectUrl: i,
65
- customerDetails: o
66
+ customerDetails: e
66
67
  })
67
68
  });
68
- if (!f.ok)
69
+ if (!o.ok)
69
70
  throw new Error("Authentication request failed");
70
71
  try {
71
- await f.json();
72
+ await o.json();
72
73
  } catch {
73
74
  }
74
75
  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,
76
+ return h.clientSecret = n, e && (e.name && (h.clientName = String(e.name)), e.email && (h.clientEmail = String(e.email)), e.phone && (h.clientPhone = String(e.phone))), p({
77
+ amount: d,
77
78
  sessionId: t,
78
79
  additionalParams: h,
79
80
  redirectUrl: i
80
81
  });
81
82
  }
82
- function w(e) {
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;
86
- });
87
- try {
88
- console.log("[EpicPay] parsePaymentResponseFromUrl", i);
89
- } catch {
90
- }
91
- return i;
92
- }
93
- function E(e = {}) {
94
- p({
95
- environment: e.environment ?? "sandbox",
96
- apiBase: e.apiBase,
97
- headers: e.headers,
98
- onEvent: e.onEvent,
99
- redirectUrl: e.redirectUrl,
100
- clientId: e.clientId,
101
- clientSecret: e.clientSecret
102
- });
103
- try {
104
- console.log("[EpicPay] initEpicPay", { environment: e.environment ?? "sandbox", redirectUrl: e.redirectUrl, clientId: e.clientId, clientSecret: e.clientSecret });
105
- } catch {
106
- }
107
- }
108
- const I = { initEpicPay: E, redirectToPortal: m, parsePaymentResponseFromUrl: w, startEpicCollectionPayment: g };
83
+ const I = { redirectToPortal: p, startEpicCollectionPayment: E };
109
84
  export {
110
85
  I as default,
111
- s as epicConfig,
112
- E as initEpicPay,
113
- w as parsePaymentResponseFromUrl,
114
- m as redirectToPortal,
115
- p as setConfig,
116
- g as startEpicCollectionPayment
86
+ c as epicConfig,
87
+ p as redirectToPortal,
88
+ w as setConfig,
89
+ E as startEpicCollectionPayment
117
90
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "epic-collection-gateway-sdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",