epic-collection-gateway-sdk 1.0.1
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/LICENSE +21 -0
- package/README.md +248 -0
- package/dist/core/api.d.ts +42 -0
- package/dist/core/epicConfig.d.ts +5 -0
- package/dist/core/types.d.ts +61 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +114 -0
- package/package.json +29 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 naderepic
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# Epic Pay Collection Payment Gateway SDK (Demo)
|
|
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.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
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)
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Published name: `epic-pay-sdk` (demo).
|
|
15
|
+
|
|
16
|
+
Install from npm:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm i epic-pay-sdk
|
|
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
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
### ESM (bundlers like Vite, Webpack, Next.js)
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import EpicPay, {
|
|
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
|
+
});
|
|
52
|
+
|
|
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
|
+
}
|
|
62
|
+
|
|
63
|
+
// You can programmatically close the sheet if needed
|
|
64
|
+
closePaymentSheet();
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Vanilla JS (no framework)
|
|
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`:
|
|
110
|
+
|
|
111
|
+
- `payment_opened`
|
|
112
|
+
- `payment_initiated`
|
|
113
|
+
- `payment_succeeded`
|
|
114
|
+
- `payment_failed`
|
|
115
|
+
- `payment_closed`
|
|
116
|
+
|
|
117
|
+
## TypeScript
|
|
118
|
+
|
|
119
|
+
Type definitions are included at `epic-pay-sdk/index.d.ts`.
|
|
120
|
+
|
|
121
|
+
- `EpicPayInitOptions`
|
|
122
|
+
- `OpenPaymentSheetParams`
|
|
123
|
+
- `PaymentResult` union with `succeeded | cancelled | failed`
|
|
124
|
+
|
|
125
|
+
Importing with types:
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import type { OpenPaymentSheetParams, PaymentResult } from "epic-pay-sdk";
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Demo app
|
|
132
|
+
|
|
133
|
+
A simple integration demo is available in this repo at `epic-demo/`.
|
|
134
|
+
|
|
135
|
+
## Notes
|
|
136
|
+
|
|
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.
|
|
140
|
+
|
|
141
|
+
## Redirect-only integration (new flow)
|
|
142
|
+
|
|
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`:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
import { initEpicPay, redirectToPortal, parsePaymentResponseFromUrl } from 'epic-pay-sdk';
|
|
147
|
+
|
|
148
|
+
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',
|
|
160
|
+
});
|
|
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
|
+
```
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
MIT
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Epic Collections Web Checkout integration (React example)
|
|
175
|
+
|
|
176
|
+
This is a concrete example of how a React storefront (like `eCommerceFE`) integrates with this SDK for the Epic Collections Web Checkout flow.
|
|
177
|
+
|
|
178
|
+
### Example: Checkout button in a React header/cart component
|
|
179
|
+
|
|
180
|
+
```tsx
|
|
181
|
+
import { startEpicCollectionPayment } from '@naderepic/epic-collection-payment-gateway-sdk';
|
|
182
|
+
|
|
183
|
+
function CheckoutButton({ cartItems }) {
|
|
184
|
+
const [paying, setPaying] = useState(false);
|
|
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
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Options passed from frontend to the SDK
|
|
222
|
+
|
|
223
|
+
The options object passed to `startEpicCollectionPayment` has the following shape on the **frontend**:
|
|
224
|
+
|
|
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
|
+
```
|
|
237
|
+
|
|
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`).
|
|
243
|
+
|
|
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).
|
|
247
|
+
|
|
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.
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
export interface RedirectToPortalParams {
|
|
19
|
+
amount: number;
|
|
20
|
+
sessionId: string;
|
|
21
|
+
additionalParams?: Record<string, string | number | boolean>;
|
|
22
|
+
redirectUrl?: string;
|
|
23
|
+
customerDetails?: EpicCollectioncustomerDetails;
|
|
24
|
+
}
|
|
25
|
+
export interface EpicCollectioncustomerDetails {
|
|
26
|
+
name?: string;
|
|
27
|
+
email?: string;
|
|
28
|
+
phone?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface StartEpicCollectionPaymentOptions {
|
|
31
|
+
clientId: string;
|
|
32
|
+
clientSecret: string;
|
|
33
|
+
/** Merchant callback URL where the shopper is sent back after payment/cancel */
|
|
34
|
+
redirectUrl: string;
|
|
35
|
+
amount: number;
|
|
36
|
+
sessionId: string;
|
|
37
|
+
customerDetails?: EpicCollectioncustomerDetails;
|
|
38
|
+
}
|
|
39
|
+
export declare function redirectToPortal(params: RedirectToPortalParams): string;
|
|
40
|
+
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;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export interface EpicPayConfig {
|
|
2
|
+
environment?: 'sandbox' | 'production' | string;
|
|
3
|
+
apiBase?: string;
|
|
4
|
+
headers?: Record<string, string>;
|
|
5
|
+
/** Full URL to the hosted payment portal for redirect flow */
|
|
6
|
+
redirectUrl?: string;
|
|
7
|
+
/** Optional client id provided to integrator page */
|
|
8
|
+
clientId?: string;
|
|
9
|
+
/** Optional client secret provided to integrator page */
|
|
10
|
+
clientSecret?: string;
|
|
11
|
+
/** If true, do not actually redirect; only log what would happen. */
|
|
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
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { initEpicPay, redirectToPortal, parsePaymentResponseFromUrl, startEpicCollectionPayment } from './core/api';
|
|
2
|
+
export { setConfig, epicConfig } from './core/epicConfig';
|
|
3
|
+
export * from './core/types';
|
|
4
|
+
export { initEpicPay, redirectToPortal, parsePaymentResponseFromUrl, startEpicCollectionPayment } from './core/api';
|
|
5
|
+
export type { EpicPayInitOptions, EpicPayEnvironment } from './core/api';
|
|
6
|
+
export type { RedirectToPortalParams, StartEpicCollectionPaymentOptions, EpicCollectioncustomerDetails } from './core/api';
|
|
7
|
+
declare const EpicCollectionSdk: {
|
|
8
|
+
initEpicPay: typeof initEpicPay;
|
|
9
|
+
redirectToPortal: typeof redirectToPortal;
|
|
10
|
+
parsePaymentResponseFromUrl: typeof parsePaymentResponseFromUrl;
|
|
11
|
+
startEpicCollectionPayment: typeof startEpicCollectionPayment;
|
|
12
|
+
};
|
|
13
|
+
export default EpicCollectionSdk;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
const f = { BASE_URL: "/", MODE: "production", DEV: !1, PROD: !0, SSR: !1 }, m = f.VITE_PORTAL_URL || "https://collections.epicpay.co/web-checkout", 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,
|
|
4
|
+
headers: {},
|
|
5
|
+
redirectUrl: m,
|
|
6
|
+
clientId: "",
|
|
7
|
+
clientSecret: "",
|
|
8
|
+
dryRun: !0,
|
|
9
|
+
onEvent: void 0
|
|
10
|
+
};
|
|
11
|
+
function p(e) {
|
|
12
|
+
Object.assign(s, e);
|
|
13
|
+
}
|
|
14
|
+
function u(e) {
|
|
15
|
+
const { amount: n, sessionId: i, additionalParams: c, redirectUrl: o } = e, r = s.redirectUrl || s.apiBase;
|
|
16
|
+
if (!r)
|
|
17
|
+
throw new Error('No redirectUrl configured. Call initEpicPay({ redirectUrl: "https://..." }).');
|
|
18
|
+
const t = {
|
|
19
|
+
amount: String(n),
|
|
20
|
+
sessionId: i
|
|
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]);
|
|
24
|
+
});
|
|
25
|
+
const l = Object.keys(t).map((a) => `${encodeURIComponent(a)}=${encodeURIComponent(t[a])}`).join("&"), h = r + (r.includes("?") ? "&" : "?") + l;
|
|
26
|
+
try {
|
|
27
|
+
console.log("[EpicPay] redirectToPortal", { portal: r, amount: n, sessionId: i });
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
console.log("[EpicPay] redirectToPortal URL:", h);
|
|
32
|
+
} catch {
|
|
33
|
+
}
|
|
34
|
+
return h;
|
|
35
|
+
}
|
|
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)
|
|
39
|
+
throw new Error("Invalid clientId");
|
|
40
|
+
if (!i || typeof i != "string" || i.length < 16)
|
|
41
|
+
throw new Error("Invalid clientSecret");
|
|
42
|
+
if (!r || typeof r != "string" || r.length < 16)
|
|
43
|
+
throw new Error("Invalid sessionId");
|
|
44
|
+
if (!c || typeof c != "string")
|
|
45
|
+
throw new Error("Invalid redirectUrl");
|
|
46
|
+
p({
|
|
47
|
+
clientId: n,
|
|
48
|
+
clientSecret: i
|
|
49
|
+
});
|
|
50
|
+
const l = s.apiBase;
|
|
51
|
+
if (!l)
|
|
52
|
+
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, {
|
|
54
|
+
method: "POST",
|
|
55
|
+
headers: { "Content-Type": "application/json", grabbersbeware: "getthehellout989898" },
|
|
56
|
+
body: JSON.stringify({
|
|
57
|
+
clientId: n,
|
|
58
|
+
clientSecret: i,
|
|
59
|
+
sessionId: r,
|
|
60
|
+
amount: o,
|
|
61
|
+
redirectUrl: c,
|
|
62
|
+
customerDetails: t
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
if (!a.ok)
|
|
66
|
+
throw new Error("Authentication request failed");
|
|
67
|
+
try {
|
|
68
|
+
await a.json();
|
|
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);
|
|
86
|
+
} catch {
|
|
87
|
+
}
|
|
88
|
+
return o;
|
|
89
|
+
}
|
|
90
|
+
function I(e = {}) {
|
|
91
|
+
p({
|
|
92
|
+
environment: e.environment ?? "sandbox",
|
|
93
|
+
apiBase: e.apiBase,
|
|
94
|
+
headers: e.headers,
|
|
95
|
+
onEvent: e.onEvent,
|
|
96
|
+
redirectUrl: e.redirectUrl,
|
|
97
|
+
clientId: e.clientId,
|
|
98
|
+
clientSecret: e.clientSecret
|
|
99
|
+
});
|
|
100
|
+
try {
|
|
101
|
+
console.log("[EpicPay] initEpicPay", { environment: e.environment ?? "sandbox", redirectUrl: e.redirectUrl, clientId: e.clientId, clientSecret: e.clientSecret });
|
|
102
|
+
} catch {
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const S = { initEpicPay: I, redirectToPortal: u, parsePaymentResponseFromUrl: w, startEpicCollectionPayment: g };
|
|
106
|
+
export {
|
|
107
|
+
S as default,
|
|
108
|
+
s as epicConfig,
|
|
109
|
+
I as initEpicPay,
|
|
110
|
+
w as parsePaymentResponseFromUrl,
|
|
111
|
+
u as redirectToPortal,
|
|
112
|
+
p as setConfig,
|
|
113
|
+
g as startEpicCollectionPayment
|
|
114
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "epic-collection-gateway-sdk",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"dev": "vite",
|
|
19
|
+
"build": "tsc && vite build",
|
|
20
|
+
"preview": "vite preview"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {},
|
|
23
|
+
"dependencies": {},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"typescript": "^5.0.2",
|
|
26
|
+
"vite": "^4.4.0",
|
|
27
|
+
"vite-plugin-dts": "^3.5.3"
|
|
28
|
+
}
|
|
29
|
+
}
|