epic-collection-gateway-sdk 1.0.2 → 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 +83 -199
- package/dist/core/api.d.ts +2 -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 +57 -81
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,248 +1,132 @@
|
|
|
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 and redirect-flow initiation.
|
|
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.
|
|
11
|
+
- Zero dependencies, ESM-only, full TypeScript types included.
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
---
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
## Installation
|
|
17
16
|
|
|
18
17
|
```bash
|
|
19
|
-
npm
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Quick start
|
|
23
|
-
|
|
24
|
-
```ts
|
|
25
|
-
import { initEpicPay, openPaymentSheet } from "epic-pay-sdk";
|
|
26
|
-
|
|
27
|
-
initEpicPay({ environment: "sandbox" });
|
|
28
|
-
|
|
29
|
-
// Trigger at checkout
|
|
30
|
-
const result = await openPaymentSheet({ amount: 999, currency: "₦" });
|
|
31
|
-
if (result.status === "succeeded") {
|
|
32
|
-
console.log("Paid", result.transactionId);
|
|
33
|
-
}
|
|
18
|
+
npm install epic-collection-gateway-sdk
|
|
34
19
|
```
|
|
35
20
|
|
|
36
|
-
|
|
21
|
+
---
|
|
37
22
|
|
|
38
|
-
|
|
23
|
+
## Quick Start
|
|
39
24
|
|
|
40
25
|
```ts
|
|
41
|
-
import
|
|
42
|
-
initEpicPay,
|
|
43
|
-
openPaymentSheet,
|
|
44
|
-
closePaymentSheet,
|
|
45
|
-
} from "epic-pay-sdk";
|
|
46
|
-
|
|
47
|
-
initEpicPay({
|
|
48
|
-
merchantId: "demo_merchant_123",
|
|
49
|
-
environment: "sandbox",
|
|
50
|
-
onEvent: (e) => console.log("[EpicPay event]", e),
|
|
51
|
-
});
|
|
26
|
+
import { startEpicCollectionPayment } from "epic-collection-gateway-sdk";
|
|
52
27
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
28
|
+
const url = await startEpicCollectionPayment({
|
|
29
|
+
environment: "sandbox",
|
|
30
|
+
clientId: "YOUR_CLIENT_ID",
|
|
31
|
+
clientSecret: "YOUR_CLIENT_SECRET",
|
|
32
|
+
redirectUrl: "https://your-site.com/order-result",
|
|
33
|
+
amount: 2500,
|
|
34
|
+
sessionId: "unique_order_session_id",
|
|
35
|
+
customerDetails: { email: "user@example.com" },
|
|
58
36
|
});
|
|
59
|
-
if (result.status === "succeeded") {
|
|
60
|
-
console.log("Paid", result.transactionId);
|
|
61
|
-
}
|
|
62
37
|
|
|
63
|
-
//
|
|
64
|
-
|
|
38
|
+
// Navigate the user to the hosted payment portal
|
|
39
|
+
window.location.assign(url);
|
|
65
40
|
```
|
|
66
41
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
Import via your bundler/ESM pipeline and call from regular scripts:
|
|
70
|
-
|
|
71
|
-
```js
|
|
72
|
-
import { initEpicPay, openPaymentSheet, closePaymentSheet } from "epic-pay-sdk";
|
|
73
|
-
|
|
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
|
-
});
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
## API
|
|
86
|
-
|
|
87
|
-
- **`initEpicPay(options)`**
|
|
88
|
-
|
|
89
|
-
- `merchantId?: string`
|
|
90
|
-
- `environment?: 'sandbox' | 'production'` (default: `sandbox`)
|
|
91
|
-
- `onEvent?: (event) => void` event callback
|
|
92
|
-
|
|
93
|
-
- **`openPaymentSheet(params)` -> `Promise<PaymentResult>`**
|
|
94
|
-
|
|
95
|
-
- `amount: number` (required)
|
|
96
|
-
- `currency?: string` (default: `₦`)
|
|
97
|
-
- `customer?: Record<string, any>`
|
|
98
|
-
- `paymentMethods?: ('card' | 'bank' | 'epic')[]` (default: all)
|
|
99
|
-
|
|
100
|
-
Notes:
|
|
101
|
-
|
|
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.
|
|
104
|
-
|
|
105
|
-
- **`closePaymentSheet()`** closes the sheet.
|
|
106
|
-
|
|
107
|
-
### Events
|
|
108
|
-
|
|
109
|
-
Events emitted to `onEvent`:
|
|
42
|
+
---
|
|
110
43
|
|
|
111
|
-
|
|
112
|
-
- `payment_initiated`
|
|
113
|
-
- `payment_succeeded`
|
|
114
|
-
- `payment_failed`
|
|
115
|
-
- `payment_closed`
|
|
44
|
+
## API Reference
|
|
116
45
|
|
|
117
|
-
|
|
46
|
+
### `startEpicCollectionPayment(options)` → `Promise<string>`
|
|
118
47
|
|
|
119
|
-
|
|
48
|
+
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.
|
|
120
49
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
50
|
+
| Option | Type | Required | Description |
|
|
51
|
+
|---|---|---|---|
|
|
52
|
+
| `environment` | `string` | ✅ | Environment (sandbox or production). |
|
|
53
|
+
| `clientId` | `string` | ✅ | Issued from the Epic Collections Admin Portal (min 16 chars). |
|
|
54
|
+
| `clientSecret` | `string` | ✅ | Issued from the Epic Collections Admin Portal (min 16 chars). |
|
|
55
|
+
| `redirectUrl` | `string` | ✅ | Merchant callback URL — where the user lands after payment or cancellation. |
|
|
56
|
+
| `amount` | `number` | ✅ | Checkout amount (e.g. `2500` for ₦2,500). |
|
|
57
|
+
| `sessionId` | `string` | ✅ | Unique identifier for this checkout session / order (min 16 chars). |
|
|
58
|
+
| `customerDetails` | `EpicCollectioncustomerDetails` | — | Optional customer info forwarded to the portal. |
|
|
124
59
|
|
|
125
|
-
|
|
60
|
+
**`EpicCollectioncustomerDetails`**
|
|
126
61
|
|
|
127
62
|
```ts
|
|
128
|
-
|
|
63
|
+
interface EpicCollectioncustomerDetails {
|
|
64
|
+
name?: string;
|
|
65
|
+
email?: string;
|
|
66
|
+
phone?: string;
|
|
67
|
+
}
|
|
129
68
|
```
|
|
130
69
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
A simple integration demo is available in this repo at `epic-demo/`.
|
|
134
|
-
|
|
135
|
-
## Notes
|
|
70
|
+
---
|
|
136
71
|
|
|
137
|
-
|
|
138
|
-
- Success is simulated (~90% chance).
|
|
139
|
-
- Styles are injected dynamically by the SDK.
|
|
72
|
+
### `redirectToPortal(params)` → `string`
|
|
140
73
|
|
|
141
|
-
|
|
74
|
+
Builds and returns the portal URL without making an auth API call.
|
|
142
75
|
|
|
143
|
-
|
|
76
|
+
| Param | Type | Required | Description |
|
|
77
|
+
|---|---|---|---|
|
|
78
|
+
| `amount` | `number` | ✅ | Checkout amount. |
|
|
79
|
+
| `sessionId` | `string` | ✅ | Unique checkout session ID. |
|
|
80
|
+
| `redirectUrl` | `string` | — | Overrides the default redirect URL. |
|
|
81
|
+
| `customerDetails` | `EpicCollectioncustomerDetails` | — | Optional customer metadata. |
|
|
82
|
+
| `additionalParams` | `Record<string, string \| number \| boolean>` | — | Any extra query params to append to the URL. |
|
|
144
83
|
|
|
145
84
|
```ts
|
|
146
|
-
import {
|
|
85
|
+
import { redirectToPortal } from "epic-collection-gateway-sdk";
|
|
147
86
|
|
|
148
|
-
|
|
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({
|
|
87
|
+
const url = redirectToPortal({
|
|
155
88
|
amount: 2300,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
returnUrl: 'https://merchant.example.com/order-success',
|
|
89
|
+
sessionId: "sess_123456789",
|
|
90
|
+
redirectUrl: "https://your-site.com/order-result",
|
|
91
|
+
customerDetails: { email: "user@example.com" },
|
|
160
92
|
});
|
|
161
93
|
|
|
162
|
-
|
|
163
|
-
const res = parsePaymentResponseFromUrl();
|
|
164
|
-
// res may contain: sessionId, paymentRef, status, and any other keys your portal includes
|
|
165
|
-
console.log(res);
|
|
94
|
+
window.location.assign(url);
|
|
166
95
|
```
|
|
167
96
|
|
|
168
|
-
|
|
97
|
+
---
|
|
169
98
|
|
|
170
|
-
|
|
99
|
+
## TypeScript Types
|
|
171
100
|
|
|
172
|
-
|
|
101
|
+
All types are exported from the package root:
|
|
173
102
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const total = cartItems.reduce((sum, i) => sum + i.price * i.quantity, 0);
|
|
186
|
-
|
|
187
|
-
const handleCheckout = async () => {
|
|
188
|
-
if (cartItems.length === 0) return;
|
|
189
|
-
try {
|
|
190
|
-
setPaying(true);
|
|
191
|
-
const sessionId = '2349283949994959000345340212778'; // generate per order in production
|
|
192
|
-
|
|
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
|
-
});
|
|
203
|
-
|
|
204
|
-
window.location.assign(url);
|
|
205
|
-
} finally {
|
|
206
|
-
setPaying(false);
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
|
|
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
|
-
}
|
|
103
|
+
```ts
|
|
104
|
+
import type {
|
|
105
|
+
EpicPayEnvironment,
|
|
106
|
+
StartEpicCollectionPaymentOptions,
|
|
107
|
+
EpicCollectioncustomerDetails,
|
|
108
|
+
RedirectToPortalParams,
|
|
109
|
+
EpicPayConfig,
|
|
110
|
+
PaymentEvent,
|
|
111
|
+
PaymentResult,
|
|
112
|
+
CustomerInfo,
|
|
113
|
+
} from "epic-collection-gateway-sdk";
|
|
219
114
|
```
|
|
220
115
|
|
|
221
|
-
|
|
116
|
+
---
|
|
222
117
|
|
|
223
|
-
|
|
118
|
+
## Default Export
|
|
224
119
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
"sessionId": "<sessionId>",
|
|
232
|
-
"customerDetails": {
|
|
233
|
-
"email": "user@example.com"
|
|
234
|
-
}
|
|
235
|
-
}
|
|
120
|
+
A convenience object is available as the default export:
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import EpicCollectionSdk from "epic-collection-gateway-sdk";
|
|
124
|
+
|
|
125
|
+
const { startEpicCollectionPayment, redirectToPortal } = EpicCollectionSdk;
|
|
236
126
|
```
|
|
237
127
|
|
|
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`).
|
|
128
|
+
---
|
|
243
129
|
|
|
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).
|
|
130
|
+
## License
|
|
247
131
|
|
|
248
|
-
|
|
132
|
+
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>;
|
|
@@ -28,6 +13,7 @@ export interface EpicCollectioncustomerDetails {
|
|
|
28
13
|
phone?: string;
|
|
29
14
|
}
|
|
30
15
|
export interface StartEpicCollectionPaymentOptions {
|
|
16
|
+
environment?: EpicPayEnvironment;
|
|
31
17
|
clientId: string;
|
|
32
18
|
clientSecret: string;
|
|
33
19
|
/** Merchant callback URL where the shopper is sent back after payment/cancel */
|
|
@@ -38,5 +24,3 @@ export interface StartEpicCollectionPaymentOptions {
|
|
|
38
24
|
}
|
|
39
25
|
export declare function redirectToPortal(params: RedirectToPortalParams): string;
|
|
40
26
|
export declare function startEpicCollectionPayment(options: StartEpicCollectionPaymentOptions): Promise<string>;
|
|
41
|
-
export declare function parsePaymentResponseFromUrl(raw?: string): Record<string, string>;
|
|
42
|
-
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,114 +1,90 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
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 = {
|
|
4
|
+
environment: "",
|
|
5
|
+
apiBase: g,
|
|
4
6
|
headers: {},
|
|
5
|
-
redirectUrl:
|
|
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:
|
|
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
|
-
amount: String(
|
|
20
|
-
sessionId:
|
|
19
|
+
const e = {
|
|
20
|
+
amount: String(r),
|
|
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 { clientId:
|
|
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")
|
|
40
|
+
throw new Error("Invalid environment");
|
|
41
|
+
if (!r || typeof r != "string" || r.length < 16)
|
|
39
42
|
throw new Error("Invalid clientId");
|
|
40
|
-
if (!
|
|
43
|
+
if (!n || typeof n != "string" || n.length < 16)
|
|
41
44
|
throw new Error("Invalid clientSecret");
|
|
42
|
-
if (!
|
|
45
|
+
if (!t || typeof t != "string" || t.length < 16)
|
|
43
46
|
throw new Error("Invalid sessionId");
|
|
44
|
-
if (!
|
|
47
|
+
if (!i || typeof i != "string")
|
|
45
48
|
throw new Error("Invalid redirectUrl");
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
w({
|
|
50
|
+
environment: a,
|
|
51
|
+
clientId: r,
|
|
52
|
+
clientSecret: n
|
|
49
53
|
});
|
|
50
|
-
const
|
|
51
|
-
if (!
|
|
54
|
+
const s = c.apiBase;
|
|
55
|
+
if (!s)
|
|
52
56
|
throw new Error("No API base configured for authentication");
|
|
53
|
-
const
|
|
57
|
+
const f = (s.endsWith("/") ? s.slice(0, -1) : s) + "/web-checkout/auth", o = await fetch(f, {
|
|
54
58
|
method: "POST",
|
|
55
|
-
headers: { "Content-Type": "application/json",
|
|
59
|
+
headers: { "Content-Type": "application/json", ...m },
|
|
56
60
|
body: JSON.stringify({
|
|
57
|
-
clientId:
|
|
58
|
-
clientSecret:
|
|
59
|
-
sessionId:
|
|
60
|
-
amount:
|
|
61
|
-
redirectUrl:
|
|
62
|
-
customerDetails:
|
|
61
|
+
clientId: r,
|
|
62
|
+
clientSecret: n,
|
|
63
|
+
sessionId: t,
|
|
64
|
+
amount: d,
|
|
65
|
+
redirectUrl: i,
|
|
66
|
+
customerDetails: e
|
|
63
67
|
})
|
|
64
68
|
});
|
|
65
|
-
if (!
|
|
69
|
+
if (!o.ok)
|
|
66
70
|
throw new Error("Authentication request failed");
|
|
67
71
|
try {
|
|
68
|
-
await
|
|
69
|
-
} catch {
|
|
70
|
-
}
|
|
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
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
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
|
-
});
|
|
84
|
-
try {
|
|
85
|
-
console.log("[EpicPay] parsePaymentResponseFromUrl", o);
|
|
72
|
+
await o.json();
|
|
86
73
|
} catch {
|
|
87
74
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
headers: e.headers,
|
|
95
|
-
onEvent: e.onEvent,
|
|
96
|
-
redirectUrl: e.redirectUrl,
|
|
97
|
-
clientId: e.clientId,
|
|
98
|
-
clientSecret: e.clientSecret
|
|
75
|
+
const h = {};
|
|
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,
|
|
78
|
+
sessionId: t,
|
|
79
|
+
additionalParams: h,
|
|
80
|
+
redirectUrl: i
|
|
99
81
|
});
|
|
100
|
-
try {
|
|
101
|
-
console.log("[EpicPay] initEpicPay", { environment: e.environment ?? "sandbox", redirectUrl: e.redirectUrl, clientId: e.clientId, clientSecret: e.clientSecret });
|
|
102
|
-
} catch {
|
|
103
|
-
}
|
|
104
82
|
}
|
|
105
|
-
const
|
|
83
|
+
const I = { redirectToPortal: p, startEpicCollectionPayment: E };
|
|
106
84
|
export {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
w as
|
|
111
|
-
|
|
112
|
-
p as setConfig,
|
|
113
|
-
g as startEpicCollectionPayment
|
|
85
|
+
I as default,
|
|
86
|
+
c as epicConfig,
|
|
87
|
+
p as redirectToPortal,
|
|
88
|
+
w as setConfig,
|
|
89
|
+
E as startEpicCollectionPayment
|
|
114
90
|
};
|