@monei-js/components 2.0.0 → 2.1.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/README.md +41 -13
- package/dist/index.cjs +60 -41
- package/dist/index.d.cts +45 -27
- package/dist/index.d.ts +45 -27
- package/dist/index.js +60 -41
- package/dist/monei.umd.production.min.js +2 -2
- package/dist/monei.umd.production.min.js.map +1 -1
- package/package.json +4 -3
- package/src/bridge/types.ts +4 -0
package/README.md
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
# @monei-js/components
|
|
2
2
|
|
|
3
|
-
MONEI UI Components — drop-in payment UI for the web. Renders secure iframes for card input, PayPal, Bizum,
|
|
3
|
+
MONEI UI Components — drop-in payment UI for the web. Renders secure iframes for card input, PayPal, Bizum, Apple Pay, and a full payment modal. Works with any framework or vanilla JS.
|
|
4
|
+
|
|
5
|
+
## Framework Packages
|
|
6
|
+
|
|
7
|
+
For framework-specific components with idiomatic APIs and full type support:
|
|
8
|
+
|
|
9
|
+
| Package | Framework | Install |
|
|
10
|
+
| ------------------------------ | ----------- | ------------------------------------ |
|
|
11
|
+
| `@monei-js/react-components` | React 17+ | `npm i @monei-js/react-components` |
|
|
12
|
+
| `@monei-js/vue-components` | Vue 3.3+ | `npm i @monei-js/vue-components` |
|
|
13
|
+
| `@monei-js/angular-components` | Angular 14+ | `npm i @monei-js/angular-components` |
|
|
14
|
+
| `@monei-js/svelte-components` | Svelte 5+ | `npm i @monei-js/svelte-components` |
|
|
15
|
+
|
|
16
|
+
All framework packages require `@monei-js/components` as a peer dependency for API functions (`confirmPayment`, `api`, etc.).
|
|
4
17
|
|
|
5
18
|
## Install
|
|
6
19
|
|
|
@@ -22,28 +35,23 @@ Or load via CDN:
|
|
|
22
35
|
| `PaymentModal` | Full-screen payment flow modal |
|
|
23
36
|
| `Bizum` | Bizum button + phone verification modal |
|
|
24
37
|
| `PayPal` | PayPal checkout button |
|
|
25
|
-
| `GooglePay` | Google Pay button |
|
|
26
38
|
| `PaymentRequest` | Apple Pay / browser Payment Request button |
|
|
27
39
|
|
|
28
|
-
## Quick Start
|
|
40
|
+
## Quick Start (Vanilla JS)
|
|
29
41
|
|
|
30
42
|
```js
|
|
31
|
-
import {CardInput,
|
|
43
|
+
import {CardInput, confirmPayment} from '@monei-js/components';
|
|
32
44
|
|
|
33
|
-
// Render card input
|
|
34
45
|
const cardInput = CardInput({
|
|
35
46
|
paymentId: 'pay_...',
|
|
36
47
|
onChange({isTouched, error, cardType}) {
|
|
37
48
|
// handle validation state
|
|
38
|
-
},
|
|
39
|
-
onLoad() {
|
|
40
|
-
// component ready
|
|
41
49
|
}
|
|
42
50
|
});
|
|
43
51
|
cardInput.render('#card-input');
|
|
44
52
|
|
|
45
53
|
// Tokenize and confirm
|
|
46
|
-
const {token} = await
|
|
54
|
+
const {token} = await cardInput.submit();
|
|
47
55
|
const result = await confirmPayment({paymentId: 'pay_...', paymentToken: token});
|
|
48
56
|
```
|
|
49
57
|
|
|
@@ -51,21 +59,41 @@ const result = await confirmPayment({paymentId: 'pay_...', paymentToken: token})
|
|
|
51
59
|
|
|
52
60
|
Exported via `api` namespace:
|
|
53
61
|
|
|
54
|
-
- `createToken(request)` — tokenize a payment method (card, PayPal, Google Pay, Apple Pay, Bizum)
|
|
55
62
|
- `confirmPayment({paymentId, ...})` — confirm a payment with token
|
|
56
63
|
- `getPaymentMethods({accountId | paymentId})` — list available payment methods
|
|
57
64
|
- `getPayment(paymentId)` — fetch payment status
|
|
58
65
|
- `createPayment({accountId, amount, currency, ...})` — create a client-side payment (POS)
|
|
59
66
|
- `sendPaymentReceipt({paymentId, customerEmail, ...})` — send receipt email
|
|
60
67
|
|
|
61
|
-
##
|
|
68
|
+
## Migrating from `createToken`
|
|
62
69
|
|
|
63
|
-
|
|
70
|
+
Before:
|
|
64
71
|
|
|
65
72
|
```js
|
|
66
|
-
|
|
73
|
+
import {CardInput, createToken} from '@monei-js/components';
|
|
74
|
+
|
|
75
|
+
const cardInput = CardInput({paymentId: 'pay_...'});
|
|
76
|
+
cardInput.render('#card-input');
|
|
77
|
+
const {token} = await createToken(cardInput);
|
|
67
78
|
```
|
|
68
79
|
|
|
80
|
+
After (instance `submit()`):
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
import {CardInput} from '@monei-js/components';
|
|
84
|
+
|
|
85
|
+
const cardInput = CardInput({paymentId: 'pay_...'});
|
|
86
|
+
cardInput.render('#card-input');
|
|
87
|
+
const {token} = await cardInput.submit({cardholderName: 'John'});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`createToken()` still works but logs a deprecation warning.
|
|
91
|
+
|
|
92
|
+
## Deprecated APIs
|
|
93
|
+
|
|
94
|
+
- **`.driver()`** — Use the framework-specific packages above instead. `.driver('react')` → `@monei-js/react-components`, `.driver('vue3')` → `@monei-js/vue-components`, `.driver('angular')` → `@monei-js/angular-components`.
|
|
95
|
+
- **`createToken(instance)`** — Use `instance.submit()` instead (see above).
|
|
96
|
+
|
|
69
97
|
## Server-Side
|
|
70
98
|
|
|
71
99
|
For creating payments on your server, use [@monei-js/node-sdk](https://github.com/MONEI/monei-node-sdk).
|
package/dist/index.cjs
CHANGED
|
@@ -182,76 +182,75 @@ const validateComponentProps = ({ props }) => {
|
|
|
182
182
|
};
|
|
183
183
|
//#endregion
|
|
184
184
|
//#region src/config.ts
|
|
185
|
-
const stage = {}.env?.STAGE || "
|
|
186
|
-
const domain = {}.env?.DOMAIN || "http://localhost:3001";
|
|
185
|
+
const stage = {}.env?.STAGE || "prod";
|
|
187
186
|
const version = {}.env?.VERSION || "v1";
|
|
188
|
-
const
|
|
189
|
-
domain,
|
|
190
|
-
version,
|
|
191
|
-
stage,
|
|
192
|
-
isProduction: stage === "prod",
|
|
193
|
-
paymentPageUrl: `${domain}/${version}/payment-page/`,
|
|
194
|
-
cardInputUrl: `${domain}/${version}/inner-card-input/`,
|
|
195
|
-
paymentModalUrl: `${domain}/${version}/inner-payment-modal/`,
|
|
196
|
-
paypalUrl: `${domain}/${version}/inner-paypal/`,
|
|
197
|
-
bizumUrl: `${domain}/${version}/inner-bizum/`,
|
|
198
|
-
bizumButtonUrl: `${domain}/${version}/inner-bizum-button/`,
|
|
199
|
-
paymentRequestUrl: `${domain}/${version}/inner-payment-request/`
|
|
200
|
-
};
|
|
201
|
-
const stageConfig = {
|
|
187
|
+
const sc = {
|
|
202
188
|
local: {
|
|
203
189
|
domain: "http://card-input.localhost:1355",
|
|
204
|
-
paymentPageUrl:
|
|
205
|
-
cardInputUrl:
|
|
206
|
-
paymentModalUrl:
|
|
207
|
-
paypalUrl:
|
|
208
|
-
bizumUrl:
|
|
209
|
-
bizumButtonUrl:
|
|
210
|
-
paymentRequestUrl:
|
|
190
|
+
paymentPageUrl: "http://payment-page.localhost:1355/",
|
|
191
|
+
cardInputUrl: "http://card-input.localhost:1355/",
|
|
192
|
+
paymentModalUrl: "http://payment-modal.localhost:1355/",
|
|
193
|
+
paypalUrl: "http://paypal.localhost:1355/",
|
|
194
|
+
bizumUrl: "http://bizum.localhost:1355/",
|
|
195
|
+
bizumButtonUrl: "http://bizum-button.localhost:1355/",
|
|
196
|
+
paymentRequestUrl: "http://payment-request.localhost:1355/",
|
|
211
197
|
apiUrl: "https://api.monei-dev.com/v1",
|
|
212
198
|
secureDomain: "https://secure.monei-dev.com",
|
|
213
199
|
rootDomain: "monei-dev.com"
|
|
214
200
|
},
|
|
215
201
|
"local-prod": {
|
|
216
202
|
domain: "http://card-input.localhost:1355",
|
|
217
|
-
paymentPageUrl:
|
|
218
|
-
cardInputUrl:
|
|
219
|
-
paymentModalUrl:
|
|
220
|
-
paypalUrl:
|
|
221
|
-
bizumUrl:
|
|
222
|
-
bizumButtonUrl:
|
|
223
|
-
paymentRequestUrl:
|
|
203
|
+
paymentPageUrl: "http://payment-page.localhost:1355/",
|
|
204
|
+
cardInputUrl: "http://card-input.localhost:1355/",
|
|
205
|
+
paymentModalUrl: "http://payment-modal.localhost:1355/",
|
|
206
|
+
paypalUrl: "http://paypal.localhost:1355/",
|
|
207
|
+
bizumUrl: "http://bizum.localhost:1355/",
|
|
208
|
+
bizumButtonUrl: "http://bizum-button.localhost:1355/",
|
|
209
|
+
paymentRequestUrl: "http://payment-request.localhost:1355/",
|
|
224
210
|
apiUrl: "https://api.monei.com/v1",
|
|
225
211
|
secureDomain: "https://secure.monei.com",
|
|
226
212
|
rootDomain: "monei.com"
|
|
227
213
|
},
|
|
228
214
|
tunnel: {
|
|
229
215
|
domain: "https://card-input.monei-dev-tunnel.com",
|
|
230
|
-
paymentPageUrl:
|
|
231
|
-
cardInputUrl:
|
|
232
|
-
paymentModalUrl:
|
|
233
|
-
paypalUrl:
|
|
234
|
-
bizumUrl:
|
|
235
|
-
bizumButtonUrl:
|
|
236
|
-
paymentRequestUrl:
|
|
216
|
+
paymentPageUrl: "https://payment-page.monei-dev-tunnel.com/",
|
|
217
|
+
cardInputUrl: "https://card-input.monei-dev-tunnel.com/",
|
|
218
|
+
paymentModalUrl: "https://payment-modal.monei-dev-tunnel.com/",
|
|
219
|
+
paypalUrl: "https://paypal.monei-dev-tunnel.com/",
|
|
220
|
+
bizumUrl: "https://bizum.monei-dev-tunnel.com/",
|
|
221
|
+
bizumButtonUrl: "https://bizum-button.monei-dev-tunnel.com/",
|
|
222
|
+
paymentRequestUrl: "https://payment-request.monei-dev-tunnel.com/",
|
|
237
223
|
apiUrl: "https://api.monei.com/v1",
|
|
238
224
|
secureDomain: "https://secure.monei.com",
|
|
239
225
|
rootDomain: "monei.com"
|
|
240
226
|
},
|
|
241
227
|
dev: {
|
|
228
|
+
domain: {}.env?.DOMAIN || "https://js.monei-dev.com",
|
|
242
229
|
apiUrl: "https://api.monei-dev.com/v1",
|
|
243
230
|
secureDomain: "https://secure.monei-dev.com",
|
|
244
231
|
rootDomain: "monei-dev.com"
|
|
245
232
|
},
|
|
246
233
|
prod: {
|
|
234
|
+
domain: {}.env?.DOMAIN || "https://js.monei.com",
|
|
247
235
|
apiUrl: "https://api.monei.com/v1",
|
|
248
236
|
secureDomain: "https://secure.monei.com",
|
|
249
237
|
rootDomain: "monei.com"
|
|
250
238
|
}
|
|
251
|
-
};
|
|
239
|
+
}[stage];
|
|
240
|
+
const domain = sc.domain;
|
|
252
241
|
const config = {
|
|
253
|
-
|
|
254
|
-
|
|
242
|
+
domain,
|
|
243
|
+
version,
|
|
244
|
+
stage,
|
|
245
|
+
isProduction: stage === "prod",
|
|
246
|
+
paymentPageUrl: sc.paymentPageUrl || `${domain}/${version}/payment-page/`,
|
|
247
|
+
cardInputUrl: sc.cardInputUrl || `${domain}/${version}/inner-card-input/`,
|
|
248
|
+
paymentModalUrl: sc.paymentModalUrl || `${domain}/${version}/inner-payment-modal/`,
|
|
249
|
+
paypalUrl: sc.paypalUrl || `${domain}/${version}/inner-paypal/`,
|
|
250
|
+
bizumUrl: sc.bizumUrl || `${domain}/${version}/inner-bizum/`,
|
|
251
|
+
bizumButtonUrl: sc.bizumButtonUrl || `${domain}/${version}/inner-bizum-button/`,
|
|
252
|
+
paymentRequestUrl: sc.paymentRequestUrl || `${domain}/${version}/inner-payment-request/`,
|
|
253
|
+
...sc
|
|
255
254
|
};
|
|
256
255
|
//#endregion
|
|
257
256
|
//#region src/api.ts
|
|
@@ -287,7 +286,7 @@ const getPaymentMethods = async ({ accountId, paymentId }) => {
|
|
|
287
286
|
else throw new Error("You need to provide paymentId or accountId");
|
|
288
287
|
const query = stringify(params);
|
|
289
288
|
if (query in pmCache) return pmCache[query];
|
|
290
|
-
const promise = request(`/payment-methods?${query}`);
|
|
289
|
+
const promise = request(`/client-payment-methods?${query}`);
|
|
291
290
|
pmCache[query] = promise;
|
|
292
291
|
promise.catch(() => delete pmCache[query]);
|
|
293
292
|
return promise;
|
|
@@ -1037,6 +1036,16 @@ function attachRenderMethods(instance, options) {
|
|
|
1037
1036
|
}
|
|
1038
1037
|
//#endregion
|
|
1039
1038
|
//#region src/bridge/create-component.ts
|
|
1039
|
+
const driverPackageMap = {
|
|
1040
|
+
react: "@monei-js/react-components",
|
|
1041
|
+
vue3: "@monei-js/vue-components",
|
|
1042
|
+
angular: "@monei-js/angular-components"
|
|
1043
|
+
};
|
|
1044
|
+
function warnDriverDeprecation(name) {
|
|
1045
|
+
const pkg = driverPackageMap[name];
|
|
1046
|
+
const replacement = pkg ? `Use ${pkg} instead.` : "";
|
|
1047
|
+
console.warn(`[MONEI] .driver('${name}') is deprecated. ${replacement}`.trim());
|
|
1048
|
+
}
|
|
1040
1049
|
/**
|
|
1041
1050
|
* Normalize aliased prop names to canonical names.
|
|
1042
1051
|
* Aliases define alternative INPUT names: { style: 'innerStyle' } means
|
|
@@ -1073,6 +1082,7 @@ function createComponent(options) {
|
|
|
1073
1082
|
else this.props = { ...normalizedProps };
|
|
1074
1083
|
if (options.validate) options.validate({ props: this.props });
|
|
1075
1084
|
attachRenderMethods(this, options);
|
|
1085
|
+
if (options.submit) this.submit = options.submit(this);
|
|
1076
1086
|
}
|
|
1077
1087
|
async render(_container) {
|
|
1078
1088
|
throw new Error("render() not attached");
|
|
@@ -1087,6 +1097,7 @@ function createComponent(options) {
|
|
|
1087
1097
|
throw new Error("destroy() not attached");
|
|
1088
1098
|
}
|
|
1089
1099
|
driver(name, deps) {
|
|
1100
|
+
warnDriverDeprecation(name);
|
|
1090
1101
|
return resolveDriver(name, Component, deps);
|
|
1091
1102
|
}
|
|
1092
1103
|
}
|
|
@@ -1096,6 +1107,7 @@ function createComponent(options) {
|
|
|
1096
1107
|
}
|
|
1097
1108
|
ComponentWrapper.prototype = Component.prototype;
|
|
1098
1109
|
ComponentWrapper.driver = function(name, deps) {
|
|
1110
|
+
warnDriverDeprecation(name);
|
|
1099
1111
|
return resolveDriver(name, ComponentWrapper, deps);
|
|
1100
1112
|
};
|
|
1101
1113
|
Component.prototype.__options = options;
|
|
@@ -1260,6 +1272,7 @@ const getCreateTokenFunction = (ref) => {
|
|
|
1260
1272
|
throw new Error("Index is not registered");
|
|
1261
1273
|
};
|
|
1262
1274
|
const createToken = async (component, options) => {
|
|
1275
|
+
console.warn("[MONEI] Standalone createToken() is deprecated. Use cardInput.submit() instead.");
|
|
1263
1276
|
const { data } = await getCreateTokenFunction(component)(options);
|
|
1264
1277
|
return data;
|
|
1265
1278
|
};
|
|
@@ -1283,6 +1296,12 @@ const CardInput = createComponent({
|
|
|
1283
1296
|
type: "function"
|
|
1284
1297
|
} },
|
|
1285
1298
|
validate: validateComponentProps,
|
|
1299
|
+
submit: (instance) => async (opts) => {
|
|
1300
|
+
const createTokenFn = instance.state?.__createToken;
|
|
1301
|
+
if (!createTokenFn) throw new Error("CardInput is not rendered or connection is pending — call render() first");
|
|
1302
|
+
const { data } = await createTokenFn(opts);
|
|
1303
|
+
return data;
|
|
1304
|
+
},
|
|
1286
1305
|
containerTemplate: (params) => {
|
|
1287
1306
|
params.state.__createToken = async (data = {}) => {
|
|
1288
1307
|
const callChild = params.state.__callChild;
|
package/dist/index.d.cts
CHANGED
|
@@ -204,32 +204,6 @@ declare const validateComponentProps: ({
|
|
|
204
204
|
props: any;
|
|
205
205
|
}) => void;
|
|
206
206
|
//#endregion
|
|
207
|
-
//#region src/bridge/types.d.ts
|
|
208
|
-
type Cancelable = {
|
|
209
|
-
cancel: () => void;
|
|
210
|
-
};
|
|
211
|
-
type EventEmitterType = {
|
|
212
|
-
on: (eventName: string, handler: (...args: any[]) => void) => Cancelable;
|
|
213
|
-
once: (eventName: string, handler: (...args: any[]) => void) => Cancelable;
|
|
214
|
-
trigger: (eventName: string, ...args: any[]) => void;
|
|
215
|
-
off: (eventName: string, handler: (...args: any[]) => void) => void;
|
|
216
|
-
destroy: () => void;
|
|
217
|
-
};
|
|
218
|
-
interface BridgeComponent<P> {
|
|
219
|
-
render: (container?: string | HTMLElement) => Promise<void>;
|
|
220
|
-
updateProps: (props: Partial<P>) => Promise<void>;
|
|
221
|
-
close: () => Promise<void>;
|
|
222
|
-
destroy: () => Promise<void>;
|
|
223
|
-
state: Record<string, any>;
|
|
224
|
-
event: EventEmitterType;
|
|
225
|
-
props: P;
|
|
226
|
-
driver: (name: string, deps?: Record<string, any>) => any;
|
|
227
|
-
}
|
|
228
|
-
interface BridgeComponentConstructor<P> {
|
|
229
|
-
new (props: P): BridgeComponent<P>;
|
|
230
|
-
driver: (name: string, deps?: Record<string, any>) => any;
|
|
231
|
-
}
|
|
232
|
-
//#endregion
|
|
233
207
|
//#region src/payment-modal/types.d.ts
|
|
234
208
|
type Style = {
|
|
235
209
|
width: string;
|
|
@@ -503,8 +477,52 @@ type Config = {
|
|
|
503
477
|
};
|
|
504
478
|
declare const config: Config;
|
|
505
479
|
//#endregion
|
|
480
|
+
//#region src/bridge/types.d.ts
|
|
481
|
+
type Cancelable = {
|
|
482
|
+
cancel: () => void;
|
|
483
|
+
};
|
|
484
|
+
type EventEmitterType = {
|
|
485
|
+
on: (eventName: string, handler: (...args: any[]) => void) => Cancelable;
|
|
486
|
+
once: (eventName: string, handler: (...args: any[]) => void) => Cancelable;
|
|
487
|
+
trigger: (eventName: string, ...args: any[]) => void;
|
|
488
|
+
off: (eventName: string, handler: (...args: any[]) => void) => void;
|
|
489
|
+
destroy: () => void;
|
|
490
|
+
};
|
|
491
|
+
interface BridgeComponent<P> {
|
|
492
|
+
render: (container?: string | HTMLElement) => Promise<void>;
|
|
493
|
+
updateProps: (props: Partial<P>) => Promise<void>;
|
|
494
|
+
close: () => Promise<void>;
|
|
495
|
+
destroy: () => Promise<void>;
|
|
496
|
+
submit?: (options?: any) => Promise<any>;
|
|
497
|
+
state: Record<string, any>;
|
|
498
|
+
event: EventEmitterType;
|
|
499
|
+
props: P;
|
|
500
|
+
driver: (name: string, deps?: Record<string, any>) => any;
|
|
501
|
+
}
|
|
502
|
+
interface BridgeComponentConstructor<P> {
|
|
503
|
+
new (props: P): BridgeComponent<P>;
|
|
504
|
+
driver: (name: string, deps?: Record<string, any>) => any;
|
|
505
|
+
}
|
|
506
|
+
//#endregion
|
|
507
|
+
//#region src/framework-types.d.ts
|
|
508
|
+
/** Public CardInput props — excludes internal bridge props */
|
|
509
|
+
type CardInputComponentProps = Omit<CardInputProps, 'ref' | 'onProps' | 'innerStyle' | 'orderId'>;
|
|
510
|
+
/** Public Bizum props — excludes internal bridge props */
|
|
511
|
+
type BizumComponentProps = Omit<BizumProps, 'onProps'>;
|
|
512
|
+
/** Public PayPal props — excludes internal bridge props */
|
|
513
|
+
type PayPalComponentProps = Omit<PayPalProps, 'onProps'>;
|
|
514
|
+
/** Public PaymentRequest props — excludes internal bridge props */
|
|
515
|
+
type PaymentRequestComponentProps = Omit<PaymentRequestProps, 'onProps'>;
|
|
516
|
+
/** Imperative handle for CardInput ref (framework packages) */
|
|
517
|
+
type CardInputHandle = {
|
|
518
|
+
submit(options?: any): Promise<{
|
|
519
|
+
token?: string;
|
|
520
|
+
error?: string;
|
|
521
|
+
}>;
|
|
522
|
+
};
|
|
523
|
+
//#endregion
|
|
506
524
|
//#region src/index.d.ts
|
|
507
525
|
declare const api: typeof api_d_exports;
|
|
508
526
|
declare const utils: typeof utils_d_exports;
|
|
509
527
|
//#endregion
|
|
510
|
-
export { Address, BillingDetails, Bizum, BizumModal, BizumModalProps, BizumProps, CardBrand, CardInput, CardInputOnChangeEvent, CardInputProps, CardInputStyle, ConfirmPaymentParams, CreateApplePaySessionRequest, CreatePaymentRequest, CreateTokenRequest, CreateTokenResponse, Customer, GetPaymentMethodsRequest, GetPaymentMethodsResponse, GooglePay, GooglePayProps, NextActionType, PayPal, PayPalProps, PaymentMethod, PaymentModal, PaymentModalProps, PaymentRequest, PaymentRequestProps, PaymentResult, SendPaymentReceiptRequest, TransactionType, ValidateBizumPhoneRequest, api, config, confirmPayment, createToken, utils };
|
|
528
|
+
export { Address, BillingDetails, Bizum, BizumComponentProps, BizumModal, BizumModalProps, BizumProps, type BridgeComponent, type BridgeComponentConstructor, CardBrand, CardInput, CardInputComponentProps, CardInputHandle, CardInputOnChangeEvent, CardInputProps, CardInputStyle, ConfirmPaymentParams, CreateApplePaySessionRequest, CreatePaymentRequest, CreateTokenRequest, CreateTokenResponse, Customer, GetPaymentMethodsRequest, GetPaymentMethodsResponse, GooglePay, GooglePayProps, NextActionType, PayPal, PayPalComponentProps, PayPalProps, PaymentMethod, PaymentModal, PaymentModalProps, PaymentRequest, PaymentRequestComponentProps, PaymentRequestProps, PaymentResult, SendPaymentReceiptRequest, TransactionType, ValidateBizumPhoneRequest, api, config, confirmPayment, createToken, utils };
|
package/dist/index.d.ts
CHANGED
|
@@ -202,32 +202,6 @@ declare const validateComponentProps: ({
|
|
|
202
202
|
props: any;
|
|
203
203
|
}) => void;
|
|
204
204
|
//#endregion
|
|
205
|
-
//#region src/bridge/types.d.ts
|
|
206
|
-
type Cancelable = {
|
|
207
|
-
cancel: () => void;
|
|
208
|
-
};
|
|
209
|
-
type EventEmitterType = {
|
|
210
|
-
on: (eventName: string, handler: (...args: any[]) => void) => Cancelable;
|
|
211
|
-
once: (eventName: string, handler: (...args: any[]) => void) => Cancelable;
|
|
212
|
-
trigger: (eventName: string, ...args: any[]) => void;
|
|
213
|
-
off: (eventName: string, handler: (...args: any[]) => void) => void;
|
|
214
|
-
destroy: () => void;
|
|
215
|
-
};
|
|
216
|
-
interface BridgeComponent<P> {
|
|
217
|
-
render: (container?: string | HTMLElement) => Promise<void>;
|
|
218
|
-
updateProps: (props: Partial<P>) => Promise<void>;
|
|
219
|
-
close: () => Promise<void>;
|
|
220
|
-
destroy: () => Promise<void>;
|
|
221
|
-
state: Record<string, any>;
|
|
222
|
-
event: EventEmitterType;
|
|
223
|
-
props: P;
|
|
224
|
-
driver: (name: string, deps?: Record<string, any>) => any;
|
|
225
|
-
}
|
|
226
|
-
interface BridgeComponentConstructor<P> {
|
|
227
|
-
new (props: P): BridgeComponent<P>;
|
|
228
|
-
driver: (name: string, deps?: Record<string, any>) => any;
|
|
229
|
-
}
|
|
230
|
-
//#endregion
|
|
231
205
|
//#region src/payment-modal/types.d.ts
|
|
232
206
|
type Style = {
|
|
233
207
|
width: string;
|
|
@@ -501,8 +475,52 @@ type Config = {
|
|
|
501
475
|
};
|
|
502
476
|
declare const config: Config;
|
|
503
477
|
//#endregion
|
|
478
|
+
//#region src/bridge/types.d.ts
|
|
479
|
+
type Cancelable = {
|
|
480
|
+
cancel: () => void;
|
|
481
|
+
};
|
|
482
|
+
type EventEmitterType = {
|
|
483
|
+
on: (eventName: string, handler: (...args: any[]) => void) => Cancelable;
|
|
484
|
+
once: (eventName: string, handler: (...args: any[]) => void) => Cancelable;
|
|
485
|
+
trigger: (eventName: string, ...args: any[]) => void;
|
|
486
|
+
off: (eventName: string, handler: (...args: any[]) => void) => void;
|
|
487
|
+
destroy: () => void;
|
|
488
|
+
};
|
|
489
|
+
interface BridgeComponent<P> {
|
|
490
|
+
render: (container?: string | HTMLElement) => Promise<void>;
|
|
491
|
+
updateProps: (props: Partial<P>) => Promise<void>;
|
|
492
|
+
close: () => Promise<void>;
|
|
493
|
+
destroy: () => Promise<void>;
|
|
494
|
+
submit?: (options?: any) => Promise<any>;
|
|
495
|
+
state: Record<string, any>;
|
|
496
|
+
event: EventEmitterType;
|
|
497
|
+
props: P;
|
|
498
|
+
driver: (name: string, deps?: Record<string, any>) => any;
|
|
499
|
+
}
|
|
500
|
+
interface BridgeComponentConstructor<P> {
|
|
501
|
+
new (props: P): BridgeComponent<P>;
|
|
502
|
+
driver: (name: string, deps?: Record<string, any>) => any;
|
|
503
|
+
}
|
|
504
|
+
//#endregion
|
|
505
|
+
//#region src/framework-types.d.ts
|
|
506
|
+
/** Public CardInput props — excludes internal bridge props */
|
|
507
|
+
type CardInputComponentProps = Omit<CardInputProps, 'ref' | 'onProps' | 'innerStyle' | 'orderId'>;
|
|
508
|
+
/** Public Bizum props — excludes internal bridge props */
|
|
509
|
+
type BizumComponentProps = Omit<BizumProps, 'onProps'>;
|
|
510
|
+
/** Public PayPal props — excludes internal bridge props */
|
|
511
|
+
type PayPalComponentProps = Omit<PayPalProps, 'onProps'>;
|
|
512
|
+
/** Public PaymentRequest props — excludes internal bridge props */
|
|
513
|
+
type PaymentRequestComponentProps = Omit<PaymentRequestProps, 'onProps'>;
|
|
514
|
+
/** Imperative handle for CardInput ref (framework packages) */
|
|
515
|
+
type CardInputHandle = {
|
|
516
|
+
submit(options?: any): Promise<{
|
|
517
|
+
token?: string;
|
|
518
|
+
error?: string;
|
|
519
|
+
}>;
|
|
520
|
+
};
|
|
521
|
+
//#endregion
|
|
504
522
|
//#region src/index.d.ts
|
|
505
523
|
declare const api: typeof api_d_exports;
|
|
506
524
|
declare const utils: typeof utils_d_exports;
|
|
507
525
|
//#endregion
|
|
508
|
-
export { Address, BillingDetails, Bizum, BizumModal, BizumModalProps, BizumProps, CardBrand, CardInput, CardInputOnChangeEvent, CardInputProps, CardInputStyle, ConfirmPaymentParams, CreateApplePaySessionRequest, CreatePaymentRequest, CreateTokenRequest, CreateTokenResponse, Customer, GetPaymentMethodsRequest, GetPaymentMethodsResponse, GooglePay, GooglePayProps, NextActionType, PayPal, PayPalProps, PaymentMethod, PaymentModal, PaymentModalProps, PaymentRequest, PaymentRequestProps, PaymentResult, SendPaymentReceiptRequest, TransactionType, ValidateBizumPhoneRequest, api, config, confirmPayment, createToken, utils };
|
|
526
|
+
export { Address, BillingDetails, Bizum, BizumComponentProps, BizumModal, BizumModalProps, BizumProps, type BridgeComponent, type BridgeComponentConstructor, CardBrand, CardInput, CardInputComponentProps, CardInputHandle, CardInputOnChangeEvent, CardInputProps, CardInputStyle, ConfirmPaymentParams, CreateApplePaySessionRequest, CreatePaymentRequest, CreateTokenRequest, CreateTokenResponse, Customer, GetPaymentMethodsRequest, GetPaymentMethodsResponse, GooglePay, GooglePayProps, NextActionType, PayPal, PayPalComponentProps, PayPalProps, PaymentMethod, PaymentModal, PaymentModalProps, PaymentRequest, PaymentRequestComponentProps, PaymentRequestProps, PaymentResult, SendPaymentReceiptRequest, TransactionType, ValidateBizumPhoneRequest, api, config, confirmPayment, createToken, utils };
|
package/dist/index.js
CHANGED
|
@@ -170,76 +170,75 @@ const validateComponentProps = ({ props }) => {
|
|
|
170
170
|
};
|
|
171
171
|
//#endregion
|
|
172
172
|
//#region src/config.ts
|
|
173
|
-
const stage = import.meta.env?.STAGE || "
|
|
174
|
-
const domain = import.meta.env?.DOMAIN || "http://localhost:3001";
|
|
173
|
+
const stage = import.meta.env?.STAGE || "prod";
|
|
175
174
|
const version = import.meta.env?.VERSION || "v1";
|
|
176
|
-
const
|
|
177
|
-
domain,
|
|
178
|
-
version,
|
|
179
|
-
stage,
|
|
180
|
-
isProduction: stage === "prod",
|
|
181
|
-
paymentPageUrl: `${domain}/${version}/payment-page/`,
|
|
182
|
-
cardInputUrl: `${domain}/${version}/inner-card-input/`,
|
|
183
|
-
paymentModalUrl: `${domain}/${version}/inner-payment-modal/`,
|
|
184
|
-
paypalUrl: `${domain}/${version}/inner-paypal/`,
|
|
185
|
-
bizumUrl: `${domain}/${version}/inner-bizum/`,
|
|
186
|
-
bizumButtonUrl: `${domain}/${version}/inner-bizum-button/`,
|
|
187
|
-
paymentRequestUrl: `${domain}/${version}/inner-payment-request/`
|
|
188
|
-
};
|
|
189
|
-
const stageConfig = {
|
|
175
|
+
const sc = {
|
|
190
176
|
local: {
|
|
191
177
|
domain: "http://card-input.localhost:1355",
|
|
192
|
-
paymentPageUrl:
|
|
193
|
-
cardInputUrl:
|
|
194
|
-
paymentModalUrl:
|
|
195
|
-
paypalUrl:
|
|
196
|
-
bizumUrl:
|
|
197
|
-
bizumButtonUrl:
|
|
198
|
-
paymentRequestUrl:
|
|
178
|
+
paymentPageUrl: "http://payment-page.localhost:1355/",
|
|
179
|
+
cardInputUrl: "http://card-input.localhost:1355/",
|
|
180
|
+
paymentModalUrl: "http://payment-modal.localhost:1355/",
|
|
181
|
+
paypalUrl: "http://paypal.localhost:1355/",
|
|
182
|
+
bizumUrl: "http://bizum.localhost:1355/",
|
|
183
|
+
bizumButtonUrl: "http://bizum-button.localhost:1355/",
|
|
184
|
+
paymentRequestUrl: "http://payment-request.localhost:1355/",
|
|
199
185
|
apiUrl: "https://api.monei-dev.com/v1",
|
|
200
186
|
secureDomain: "https://secure.monei-dev.com",
|
|
201
187
|
rootDomain: "monei-dev.com"
|
|
202
188
|
},
|
|
203
189
|
"local-prod": {
|
|
204
190
|
domain: "http://card-input.localhost:1355",
|
|
205
|
-
paymentPageUrl:
|
|
206
|
-
cardInputUrl:
|
|
207
|
-
paymentModalUrl:
|
|
208
|
-
paypalUrl:
|
|
209
|
-
bizumUrl:
|
|
210
|
-
bizumButtonUrl:
|
|
211
|
-
paymentRequestUrl:
|
|
191
|
+
paymentPageUrl: "http://payment-page.localhost:1355/",
|
|
192
|
+
cardInputUrl: "http://card-input.localhost:1355/",
|
|
193
|
+
paymentModalUrl: "http://payment-modal.localhost:1355/",
|
|
194
|
+
paypalUrl: "http://paypal.localhost:1355/",
|
|
195
|
+
bizumUrl: "http://bizum.localhost:1355/",
|
|
196
|
+
bizumButtonUrl: "http://bizum-button.localhost:1355/",
|
|
197
|
+
paymentRequestUrl: "http://payment-request.localhost:1355/",
|
|
212
198
|
apiUrl: "https://api.monei.com/v1",
|
|
213
199
|
secureDomain: "https://secure.monei.com",
|
|
214
200
|
rootDomain: "monei.com"
|
|
215
201
|
},
|
|
216
202
|
tunnel: {
|
|
217
203
|
domain: "https://card-input.monei-dev-tunnel.com",
|
|
218
|
-
paymentPageUrl:
|
|
219
|
-
cardInputUrl:
|
|
220
|
-
paymentModalUrl:
|
|
221
|
-
paypalUrl:
|
|
222
|
-
bizumUrl:
|
|
223
|
-
bizumButtonUrl:
|
|
224
|
-
paymentRequestUrl:
|
|
204
|
+
paymentPageUrl: "https://payment-page.monei-dev-tunnel.com/",
|
|
205
|
+
cardInputUrl: "https://card-input.monei-dev-tunnel.com/",
|
|
206
|
+
paymentModalUrl: "https://payment-modal.monei-dev-tunnel.com/",
|
|
207
|
+
paypalUrl: "https://paypal.monei-dev-tunnel.com/",
|
|
208
|
+
bizumUrl: "https://bizum.monei-dev-tunnel.com/",
|
|
209
|
+
bizumButtonUrl: "https://bizum-button.monei-dev-tunnel.com/",
|
|
210
|
+
paymentRequestUrl: "https://payment-request.monei-dev-tunnel.com/",
|
|
225
211
|
apiUrl: "https://api.monei.com/v1",
|
|
226
212
|
secureDomain: "https://secure.monei.com",
|
|
227
213
|
rootDomain: "monei.com"
|
|
228
214
|
},
|
|
229
215
|
dev: {
|
|
216
|
+
domain: import.meta.env?.DOMAIN || "https://js.monei-dev.com",
|
|
230
217
|
apiUrl: "https://api.monei-dev.com/v1",
|
|
231
218
|
secureDomain: "https://secure.monei-dev.com",
|
|
232
219
|
rootDomain: "monei-dev.com"
|
|
233
220
|
},
|
|
234
221
|
prod: {
|
|
222
|
+
domain: import.meta.env?.DOMAIN || "https://js.monei.com",
|
|
235
223
|
apiUrl: "https://api.monei.com/v1",
|
|
236
224
|
secureDomain: "https://secure.monei.com",
|
|
237
225
|
rootDomain: "monei.com"
|
|
238
226
|
}
|
|
239
|
-
};
|
|
227
|
+
}[stage];
|
|
228
|
+
const domain = sc.domain;
|
|
240
229
|
const config = {
|
|
241
|
-
|
|
242
|
-
|
|
230
|
+
domain,
|
|
231
|
+
version,
|
|
232
|
+
stage,
|
|
233
|
+
isProduction: stage === "prod",
|
|
234
|
+
paymentPageUrl: sc.paymentPageUrl || `${domain}/${version}/payment-page/`,
|
|
235
|
+
cardInputUrl: sc.cardInputUrl || `${domain}/${version}/inner-card-input/`,
|
|
236
|
+
paymentModalUrl: sc.paymentModalUrl || `${domain}/${version}/inner-payment-modal/`,
|
|
237
|
+
paypalUrl: sc.paypalUrl || `${domain}/${version}/inner-paypal/`,
|
|
238
|
+
bizumUrl: sc.bizumUrl || `${domain}/${version}/inner-bizum/`,
|
|
239
|
+
bizumButtonUrl: sc.bizumButtonUrl || `${domain}/${version}/inner-bizum-button/`,
|
|
240
|
+
paymentRequestUrl: sc.paymentRequestUrl || `${domain}/${version}/inner-payment-request/`,
|
|
241
|
+
...sc
|
|
243
242
|
};
|
|
244
243
|
//#endregion
|
|
245
244
|
//#region src/api.ts
|
|
@@ -275,7 +274,7 @@ const getPaymentMethods = async ({ accountId, paymentId }) => {
|
|
|
275
274
|
else throw new Error("You need to provide paymentId or accountId");
|
|
276
275
|
const query = stringify(params);
|
|
277
276
|
if (query in pmCache) return pmCache[query];
|
|
278
|
-
const promise = request(`/payment-methods?${query}`);
|
|
277
|
+
const promise = request(`/client-payment-methods?${query}`);
|
|
279
278
|
pmCache[query] = promise;
|
|
280
279
|
promise.catch(() => delete pmCache[query]);
|
|
281
280
|
return promise;
|
|
@@ -1025,6 +1024,16 @@ function attachRenderMethods(instance, options) {
|
|
|
1025
1024
|
}
|
|
1026
1025
|
//#endregion
|
|
1027
1026
|
//#region src/bridge/create-component.ts
|
|
1027
|
+
const driverPackageMap = {
|
|
1028
|
+
react: "@monei-js/react-components",
|
|
1029
|
+
vue3: "@monei-js/vue-components",
|
|
1030
|
+
angular: "@monei-js/angular-components"
|
|
1031
|
+
};
|
|
1032
|
+
function warnDriverDeprecation(name) {
|
|
1033
|
+
const pkg = driverPackageMap[name];
|
|
1034
|
+
const replacement = pkg ? `Use ${pkg} instead.` : "";
|
|
1035
|
+
console.warn(`[MONEI] .driver('${name}') is deprecated. ${replacement}`.trim());
|
|
1036
|
+
}
|
|
1028
1037
|
/**
|
|
1029
1038
|
* Normalize aliased prop names to canonical names.
|
|
1030
1039
|
* Aliases define alternative INPUT names: { style: 'innerStyle' } means
|
|
@@ -1061,6 +1070,7 @@ function createComponent(options) {
|
|
|
1061
1070
|
else this.props = { ...normalizedProps };
|
|
1062
1071
|
if (options.validate) options.validate({ props: this.props });
|
|
1063
1072
|
attachRenderMethods(this, options);
|
|
1073
|
+
if (options.submit) this.submit = options.submit(this);
|
|
1064
1074
|
}
|
|
1065
1075
|
async render(_container) {
|
|
1066
1076
|
throw new Error("render() not attached");
|
|
@@ -1075,6 +1085,7 @@ function createComponent(options) {
|
|
|
1075
1085
|
throw new Error("destroy() not attached");
|
|
1076
1086
|
}
|
|
1077
1087
|
driver(name, deps) {
|
|
1088
|
+
warnDriverDeprecation(name);
|
|
1078
1089
|
return resolveDriver(name, Component, deps);
|
|
1079
1090
|
}
|
|
1080
1091
|
}
|
|
@@ -1084,6 +1095,7 @@ function createComponent(options) {
|
|
|
1084
1095
|
}
|
|
1085
1096
|
ComponentWrapper.prototype = Component.prototype;
|
|
1086
1097
|
ComponentWrapper.driver = function(name, deps) {
|
|
1098
|
+
warnDriverDeprecation(name);
|
|
1087
1099
|
return resolveDriver(name, ComponentWrapper, deps);
|
|
1088
1100
|
};
|
|
1089
1101
|
Component.prototype.__options = options;
|
|
@@ -1248,6 +1260,7 @@ const getCreateTokenFunction = (ref) => {
|
|
|
1248
1260
|
throw new Error("Index is not registered");
|
|
1249
1261
|
};
|
|
1250
1262
|
const createToken = async (component, options) => {
|
|
1263
|
+
console.warn("[MONEI] Standalone createToken() is deprecated. Use cardInput.submit() instead.");
|
|
1251
1264
|
const { data } = await getCreateTokenFunction(component)(options);
|
|
1252
1265
|
return data;
|
|
1253
1266
|
};
|
|
@@ -1271,6 +1284,12 @@ const CardInput = createComponent({
|
|
|
1271
1284
|
type: "function"
|
|
1272
1285
|
} },
|
|
1273
1286
|
validate: validateComponentProps,
|
|
1287
|
+
submit: (instance) => async (opts) => {
|
|
1288
|
+
const createTokenFn = instance.state?.__createToken;
|
|
1289
|
+
if (!createTokenFn) throw new Error("CardInput is not rendered or connection is pending — call render() first");
|
|
1290
|
+
const { data } = await createTokenFn(opts);
|
|
1291
|
+
return data;
|
|
1292
|
+
},
|
|
1274
1293
|
containerTemplate: (params) => {
|
|
1275
1294
|
params.state.__createToken = async (data = {}) => {
|
|
1276
1295
|
const callChild = params.state.__callChild;
|