epic-collection-gateway-sdk 1.0.3 → 1.0.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/README.md +51 -155
- package/dist/core/api.d.ts +1 -18
- package/dist/core/constants.d.ts +5 -0
- package/dist/core/epicConfig.d.ts +0 -1
- package/dist/core/types.d.ts +0 -48
- package/dist/index.d.ts +3 -5
- package/dist/index.js +41 -68
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
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
|
|
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.).
|
|
13
10
|
- Zero dependencies, ESM-only, full TypeScript types included.
|
|
14
11
|
|
|
15
12
|
---
|
|
@@ -41,166 +38,89 @@ const url = await startEpicCollectionPayment({
|
|
|
41
38
|
window.location.assign(url);
|
|
42
39
|
```
|
|
43
40
|
|
|
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
41
|
---
|
|
55
42
|
|
|
56
|
-
##
|
|
57
|
-
|
|
58
|
-
### `startEpicCollectionPayment(options)` → `Promise<string>`
|
|
59
|
-
|
|
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.
|
|
61
|
-
|
|
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. |
|
|
71
|
-
|
|
72
|
-
**`EpicCollectioncustomerDetails`**
|
|
73
|
-
|
|
74
|
-
```ts
|
|
75
|
-
interface EpicCollectioncustomerDetails {
|
|
76
|
-
name?: string;
|
|
77
|
-
email?: string;
|
|
78
|
-
phone?: string;
|
|
79
|
-
}
|
|
80
|
-
```
|
|
43
|
+
## React Integration Example
|
|
81
44
|
|
|
82
|
-
|
|
45
|
+
Here is a practical example of integrating the SDK within a React component (e.g., a Header or Checkout button).
|
|
83
46
|
|
|
84
47
|
```tsx
|
|
85
|
-
import {
|
|
48
|
+
import { useState } from 'react';
|
|
49
|
+
import { startEpicCollectionPayment } from 'epic-collection-gateway-sdk';
|
|
86
50
|
|
|
87
|
-
|
|
51
|
+
const CheckoutButton = ({ cart, total }) => {
|
|
88
52
|
const [paying, setPaying] = useState(false);
|
|
89
|
-
const total = cartItems.reduce((sum, i) => sum + i.price * i.quantity, 0);
|
|
90
53
|
|
|
91
54
|
const handleCheckout = async () => {
|
|
92
|
-
if (
|
|
55
|
+
if (cart.length === 0) return;
|
|
93
56
|
try {
|
|
94
57
|
setPaying(true);
|
|
58
|
+
|
|
59
|
+
// Generate a unique session ID
|
|
60
|
+
const sessionId = `${Date.now()}${Math.floor(Math.random() * 1e9)}`;
|
|
61
|
+
|
|
95
62
|
const url = await startEpicCollectionPayment({
|
|
96
|
-
environment:
|
|
97
|
-
clientId:
|
|
98
|
-
clientSecret:
|
|
99
|
-
redirectUrl:
|
|
63
|
+
environment: 'production', // or 'sandbox'
|
|
64
|
+
clientId: 'YOUR_CLIENT_ID',
|
|
65
|
+
clientSecret: 'YOUR_CLIENT_SECRET',
|
|
66
|
+
redirectUrl: 'https://your-site.com/checkout-success',
|
|
100
67
|
amount: total,
|
|
101
|
-
sessionId
|
|
102
|
-
customerDetails: {
|
|
68
|
+
sessionId,
|
|
69
|
+
customerDetails: {
|
|
70
|
+
email: 'user@example.com',
|
|
71
|
+
name: 'John Doe'
|
|
72
|
+
},
|
|
103
73
|
});
|
|
74
|
+
|
|
75
|
+
// Redirect the user to the portal
|
|
104
76
|
window.location.assign(url);
|
|
105
|
-
} catch (
|
|
106
|
-
console.error("Payment
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error("Payment failed", error);
|
|
107
79
|
} finally {
|
|
108
80
|
setPaying(false);
|
|
109
81
|
}
|
|
110
82
|
};
|
|
111
83
|
|
|
112
84
|
return (
|
|
113
|
-
<button
|
|
114
|
-
{
|
|
85
|
+
<button
|
|
86
|
+
onClick={handleCheckout}
|
|
87
|
+
disabled={paying || cart.length === 0}
|
|
88
|
+
className="btn-primary"
|
|
89
|
+
>
|
|
90
|
+
{paying ? 'Processing…' : `Proceed to Pay (₦${total})`}
|
|
115
91
|
</button>
|
|
116
92
|
);
|
|
117
|
-
}
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
---
|
|
121
|
-
|
|
122
|
-
### `redirectToPortal(params)` → `string`
|
|
123
|
-
|
|
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.
|
|
125
|
-
|
|
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. |
|
|
133
|
-
|
|
134
|
-
> **Note:** `initEpicPay({ redirectUrl: "..." })` must be called before `redirectToPortal`, or a `redirectUrl` must be passed directly in params.
|
|
135
|
-
|
|
136
|
-
```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
|
-
});
|
|
144
|
-
|
|
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
|
-
});
|
|
93
|
+
};
|
|
151
94
|
|
|
152
|
-
|
|
95
|
+
export default CheckoutButton;
|
|
153
96
|
```
|
|
154
97
|
|
|
155
98
|
---
|
|
156
99
|
|
|
157
|
-
|
|
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
|
-
---
|
|
100
|
+
## API Reference
|
|
182
101
|
|
|
183
|
-
### `
|
|
102
|
+
### `startEpicCollectionPayment(options)` → `Promise<string>`
|
|
184
103
|
|
|
185
|
-
|
|
104
|
+
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.
|
|
186
105
|
|
|
187
|
-
| Option | Type |
|
|
106
|
+
| Option | Type | Required | Description |
|
|
188
107
|
|---|---|---|---|
|
|
189
|
-
| `environment` | `
|
|
190
|
-
| `
|
|
191
|
-
| `
|
|
192
|
-
| `
|
|
193
|
-
| `
|
|
194
|
-
| `
|
|
195
|
-
| `
|
|
108
|
+
| `environment` | `string` | ✅ | Environment (sandbox or production). |
|
|
109
|
+
| `clientId` | `string` | ✅ | Issued from the Epic Collections Admin Portal (min 16 chars). |
|
|
110
|
+
| `clientSecret` | `string` | ✅ | Issued from the Epic Collections Admin Portal (min 16 chars). |
|
|
111
|
+
| `redirectUrl` | `string` | ✅ | Merchant callback URL — where the user lands after payment or cancellation. |
|
|
112
|
+
| `amount` | `number` | ✅ | Checkout amount (e.g. `2500` for ₦2,500). |
|
|
113
|
+
| `sessionId` | `string` | ✅ | Unique identifier for this checkout session / order (min 16 chars). |
|
|
114
|
+
| `customerDetails` | `EpicCollectioncustomerDetails` | — | Optional customer info forwarded to the portal. |
|
|
196
115
|
|
|
197
|
-
|
|
198
|
-
import { initEpicPay } from "epic-collection-gateway-sdk";
|
|
116
|
+
**`EpicCollectioncustomerDetails`**
|
|
199
117
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
118
|
+
```ts
|
|
119
|
+
interface EpicCollectioncustomerDetails {
|
|
120
|
+
name?: string;
|
|
121
|
+
email?: string;
|
|
122
|
+
phone?: string;
|
|
123
|
+
}
|
|
204
124
|
```
|
|
205
125
|
|
|
206
126
|
---
|
|
@@ -211,11 +131,9 @@ All types are exported from the package root:
|
|
|
211
131
|
|
|
212
132
|
```ts
|
|
213
133
|
import type {
|
|
214
|
-
EpicPayInitOptions,
|
|
215
134
|
EpicPayEnvironment,
|
|
216
135
|
StartEpicCollectionPaymentOptions,
|
|
217
136
|
EpicCollectioncustomerDetails,
|
|
218
|
-
RedirectToPortalParams,
|
|
219
137
|
EpicPayConfig,
|
|
220
138
|
PaymentEvent,
|
|
221
139
|
PaymentResult,
|
|
@@ -223,15 +141,6 @@ import type {
|
|
|
223
141
|
} from "epic-collection-gateway-sdk";
|
|
224
142
|
```
|
|
225
143
|
|
|
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
144
|
---
|
|
236
145
|
|
|
237
146
|
## Default Export
|
|
@@ -241,24 +150,11 @@ A convenience object is available as the default export:
|
|
|
241
150
|
```ts
|
|
242
151
|
import EpicCollectionSdk from "epic-collection-gateway-sdk";
|
|
243
152
|
|
|
244
|
-
const { startEpicCollectionPayment
|
|
153
|
+
const { startEpicCollectionPayment } = EpicCollectionSdk;
|
|
245
154
|
```
|
|
246
155
|
|
|
247
156
|
---
|
|
248
157
|
|
|
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
158
|
## License
|
|
263
159
|
|
|
264
160
|
MIT
|
package/dist/core/api.d.ts
CHANGED
|
@@ -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;
|
package/dist/core/types.d.ts
CHANGED
|
@@ -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 {
|
|
1
|
+
import { redirectToPortal, startEpicCollectionPayment } from './core/api';
|
|
2
2
|
export { setConfig, epicConfig } from './core/epicConfig';
|
|
3
3
|
export * from './core/types';
|
|
4
|
-
export {
|
|
5
|
-
export type {
|
|
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",
|
|
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:
|
|
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
|
|
12
|
-
Object.assign(
|
|
12
|
+
function w(l) {
|
|
13
|
+
Object.assign(c, l);
|
|
13
14
|
}
|
|
14
|
-
function
|
|
15
|
-
const { amount: r, sessionId:
|
|
16
|
-
if (!
|
|
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
|
|
19
|
+
const e = {
|
|
19
20
|
amount: String(r),
|
|
20
|
-
sessionId:
|
|
21
|
+
sessionId: n
|
|
21
22
|
};
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
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:
|
|
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:",
|
|
32
|
+
console.log("[EpicPay] redirectToPortal URL:", f);
|
|
32
33
|
} catch {
|
|
33
34
|
}
|
|
34
|
-
return
|
|
35
|
+
return f;
|
|
35
36
|
}
|
|
36
|
-
async function
|
|
37
|
-
const { environment:
|
|
38
|
-
if (!
|
|
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 (!
|
|
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
|
-
|
|
49
|
-
environment:
|
|
50
|
-
clientId:
|
|
49
|
+
w({
|
|
50
|
+
environment: a,
|
|
51
|
+
clientId: r,
|
|
51
52
|
clientSecret: n
|
|
52
53
|
});
|
|
53
|
-
const
|
|
54
|
-
if (!
|
|
54
|
+
const s = c.apiBase;
|
|
55
|
+
if (!s)
|
|
55
56
|
throw new Error("No API base configured for authentication");
|
|
56
|
-
const
|
|
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",
|
|
59
|
+
headers: { "Content-Type": "application/json", ...m },
|
|
59
60
|
body: JSON.stringify({
|
|
60
|
-
clientId:
|
|
61
|
+
clientId: r,
|
|
61
62
|
clientSecret: n,
|
|
62
63
|
sessionId: t,
|
|
63
|
-
amount:
|
|
64
|
+
amount: d,
|
|
64
65
|
redirectUrl: i,
|
|
65
|
-
customerDetails:
|
|
66
|
+
customerDetails: e
|
|
66
67
|
})
|
|
67
68
|
});
|
|
68
|
-
if (!
|
|
69
|
+
if (!o.ok)
|
|
69
70
|
throw new Error("Authentication request failed");
|
|
70
71
|
try {
|
|
71
|
-
await
|
|
72
|
+
await o.json();
|
|
72
73
|
} catch {
|
|
73
74
|
}
|
|
74
75
|
const h = {};
|
|
75
|
-
return h.clientSecret = n,
|
|
76
|
-
amount:
|
|
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
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
w as
|
|
114
|
-
|
|
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
|
};
|