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 +190 -174
- package/dist/core/api.d.ts +1 -0
- package/dist/index.js +50 -47
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,248 +1,264 @@
|
|
|
1
|
-
# Epic
|
|
1
|
+
# Epic Collection Gateway SDK
|
|
2
2
|
|
|
3
|
-
A lightweight
|
|
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
|
-
|
|
5
|
+
---
|
|
6
6
|
|
|
7
|
-
|
|
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
|
-
|
|
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
|
-
|
|
15
|
+
---
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
## Installation
|
|
17
18
|
|
|
18
19
|
```bash
|
|
19
|
-
npm
|
|
20
|
+
npm install epic-collection-gateway-sdk
|
|
20
21
|
```
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
23
26
|
|
|
24
27
|
```ts
|
|
25
|
-
import {
|
|
28
|
+
import { startEpicCollectionPayment } from "epic-collection-gateway-sdk";
|
|
26
29
|
|
|
27
|
-
|
|
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
|
-
//
|
|
30
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
### ESM (bundlers like Vite, Webpack, Next.js)
|
|
44
|
+
On your `redirectUrl` page, parse the response:
|
|
39
45
|
|
|
40
46
|
```ts
|
|
41
|
-
import
|
|
42
|
-
initEpicPay,
|
|
43
|
-
openPaymentSheet,
|
|
44
|
-
closePaymentSheet,
|
|
45
|
-
} from "epic-pay-sdk";
|
|
47
|
+
import { parsePaymentResponseFromUrl } from "epic-collection-gateway-sdk";
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
49
|
+
const result = parsePaymentResponseFromUrl();
|
|
50
|
+
// { status, paymentRef, sessionId, ... }
|
|
51
|
+
console.log(result);
|
|
52
|
+
```
|
|
52
53
|
|
|
53
|
-
|
|
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
|
-
|
|
64
|
-
closePaymentSheet();
|
|
65
|
-
```
|
|
56
|
+
## API Reference
|
|
66
57
|
|
|
67
|
-
###
|
|
58
|
+
### `startEpicCollectionPayment(options)` → `Promise<string>`
|
|
68
59
|
|
|
69
|
-
|
|
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
|
-
|
|
72
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
82
|
+
**Example — React checkout button**
|
|
86
83
|
|
|
87
|
-
|
|
84
|
+
```tsx
|
|
85
|
+
import { startEpicCollectionPayment } from "epic-collection-gateway-sdk";
|
|
88
86
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
120
|
+
---
|
|
101
121
|
|
|
102
|
-
|
|
103
|
-
- Prevents multiple concurrent sheets; rejects if one is already open.
|
|
122
|
+
### `redirectToPortal(params)` → `string`
|
|
104
123
|
|
|
105
|
-
|
|
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
|
-
|
|
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
|
-
|
|
134
|
+
> **Note:** `initEpicPay({ redirectUrl: "..." })` must be called before `redirectToPortal`, or a `redirectUrl` must be passed directly in params.
|
|
110
135
|
|
|
111
|
-
|
|
112
|
-
-
|
|
113
|
-
- `payment_succeeded`
|
|
114
|
-
- `payment_failed`
|
|
115
|
-
- `payment_closed`
|
|
136
|
+
```ts
|
|
137
|
+
import { initEpicPay, redirectToPortal } from "epic-collection-gateway-sdk";
|
|
116
138
|
|
|
117
|
-
|
|
139
|
+
initEpicPay({
|
|
140
|
+
redirectUrl: "https://pay.your-portal.com/checkout",
|
|
141
|
+
clientId: "YOUR_CLIENT_ID",
|
|
142
|
+
clientSecret: "YOUR_CLIENT_SECRET",
|
|
143
|
+
});
|
|
118
144
|
|
|
119
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
152
|
+
window.location.assign(url);
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
---
|
|
124
156
|
|
|
125
|
-
|
|
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
|
|
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
|
-
|
|
175
|
+
You may also pass a raw query string:
|
|
132
176
|
|
|
133
|
-
|
|
177
|
+
```ts
|
|
178
|
+
const result = parsePaymentResponseFromUrl("?status=success&paymentRef=TXN_001");
|
|
179
|
+
```
|
|
134
180
|
|
|
135
|
-
|
|
181
|
+
---
|
|
136
182
|
|
|
137
|
-
|
|
138
|
-
- Success is simulated (~90% chance).
|
|
139
|
-
- Styles are injected dynamically by the SDK.
|
|
183
|
+
### `initEpicPay(options?)` → `void`
|
|
140
184
|
|
|
141
|
-
|
|
185
|
+
Sets global SDK configuration. Call this once at app startup. All options are optional.
|
|
142
186
|
|
|
143
|
-
|
|
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
|
|
198
|
+
import { initEpicPay } from "epic-collection-gateway-sdk";
|
|
147
199
|
|
|
148
200
|
initEpicPay({
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
##
|
|
208
|
+
## TypeScript Types
|
|
175
209
|
|
|
176
|
-
|
|
210
|
+
All types are exported from the package root:
|
|
177
211
|
|
|
178
|
-
|
|
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
|
-
|
|
181
|
-
|
|
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
|
-
|
|
184
|
-
const [paying, setPaying] = useState(false);
|
|
185
|
-
const total = cartItems.reduce((sum, i) => sum + i.price * i.quantity, 0);
|
|
235
|
+
---
|
|
186
236
|
|
|
187
|
-
|
|
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
|
-
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
setPaying(false);
|
|
207
|
-
}
|
|
208
|
-
};
|
|
241
|
+
```ts
|
|
242
|
+
import EpicCollectionSdk from "epic-collection-gateway-sdk";
|
|
209
243
|
|
|
210
|
-
|
|
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
|
-
|
|
247
|
+
---
|
|
222
248
|
|
|
223
|
-
|
|
249
|
+
## Environment Variables (SDK-internal)
|
|
224
250
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
264
|
+
MIT
|
package/dist/core/api.d.ts
CHANGED
|
@@ -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
|
|
2
|
-
environment:
|
|
3
|
-
apiBase:
|
|
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:
|
|
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
|
|
15
|
-
const { amount:
|
|
16
|
-
if (!
|
|
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(
|
|
20
|
-
sessionId:
|
|
19
|
+
amount: String(r),
|
|
20
|
+
sessionId: c
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
t[
|
|
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
|
|
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:
|
|
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:",
|
|
31
|
+
console.log("[EpicPay] redirectToPortal URL:", l);
|
|
32
32
|
} catch {
|
|
33
33
|
}
|
|
34
|
-
return
|
|
34
|
+
return l;
|
|
35
35
|
}
|
|
36
36
|
async function g(e) {
|
|
37
|
-
const { clientId:
|
|
38
|
-
if (!
|
|
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 (!
|
|
42
|
+
if (!n || typeof n != "string" || n.length < 16)
|
|
41
43
|
throw new Error("Invalid clientSecret");
|
|
42
|
-
if (!
|
|
44
|
+
if (!t || typeof t != "string" || t.length < 16)
|
|
43
45
|
throw new Error("Invalid sessionId");
|
|
44
|
-
if (!
|
|
46
|
+
if (!i || typeof i != "string")
|
|
45
47
|
throw new Error("Invalid redirectUrl");
|
|
46
48
|
p({
|
|
47
|
-
|
|
48
|
-
|
|
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
|
|
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:
|
|
58
|
-
clientSecret:
|
|
59
|
-
sessionId:
|
|
60
|
-
amount:
|
|
61
|
-
redirectUrl:
|
|
62
|
-
customerDetails:
|
|
60
|
+
clientId: c,
|
|
61
|
+
clientSecret: n,
|
|
62
|
+
sessionId: t,
|
|
63
|
+
amount: a,
|
|
64
|
+
redirectUrl: i,
|
|
65
|
+
customerDetails: o
|
|
63
66
|
})
|
|
64
67
|
});
|
|
65
|
-
if (!
|
|
68
|
+
if (!f.ok)
|
|
66
69
|
throw new Error("Authentication request failed");
|
|
67
70
|
try {
|
|
68
|
-
await
|
|
71
|
+
await f.json();
|
|
69
72
|
} catch {
|
|
70
73
|
}
|
|
71
|
-
const
|
|
72
|
-
return
|
|
73
|
-
amount:
|
|
74
|
-
sessionId:
|
|
75
|
-
additionalParams:
|
|
76
|
-
redirectUrl:
|
|
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
|
|
81
|
-
|
|
82
|
-
|
|
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",
|
|
88
|
+
console.log("[EpicPay] parsePaymentResponseFromUrl", i);
|
|
86
89
|
} catch {
|
|
87
90
|
}
|
|
88
|
-
return
|
|
91
|
+
return i;
|
|
89
92
|
}
|
|
90
|
-
function
|
|
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
|
|
108
|
+
const I = { initEpicPay: E, redirectToPortal: m, parsePaymentResponseFromUrl: w, startEpicCollectionPayment: g };
|
|
106
109
|
export {
|
|
107
|
-
|
|
110
|
+
I as default,
|
|
108
111
|
s as epicConfig,
|
|
109
|
-
|
|
112
|
+
E as initEpicPay,
|
|
110
113
|
w as parsePaymentResponseFromUrl,
|
|
111
|
-
|
|
114
|
+
m as redirectToPortal,
|
|
112
115
|
p as setConfig,
|
|
113
116
|
g as startEpicCollectionPayment
|
|
114
117
|
};
|