@monei-js/components 2.0.0 → 2.1.0

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 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, Google Pay, Apple Pay, and a full payment modal. Works with any framework or vanilla JS.
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, createToken, confirmPayment} from '@monei-js/components';
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 createToken(cardInput);
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
- ## Framework Drivers
68
+ ## Migrating from `createToken`
62
69
 
63
- Built-in rendering drivers for React, Vue 3, and Angular via `.driver()`:
70
+ Before:
64
71
 
65
72
  ```js
66
- const MoneiCardInput = CardInput.driver('react');
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,7 +182,7 @@ const validateComponentProps = ({ props }) => {
182
182
  };
183
183
  //#endregion
184
184
  //#region src/config.ts
185
- const stage = {}.env?.STAGE || "local";
185
+ const stage = {}.env?.STAGE || "prod";
186
186
  const domain = {}.env?.DOMAIN || "http://localhost:3001";
187
187
  const version = {}.env?.VERSION || "v1";
188
188
  const globalConfig = {
@@ -1037,6 +1037,16 @@ function attachRenderMethods(instance, options) {
1037
1037
  }
1038
1038
  //#endregion
1039
1039
  //#region src/bridge/create-component.ts
1040
+ const driverPackageMap = {
1041
+ react: "@monei-js/react-components",
1042
+ vue3: "@monei-js/vue-components",
1043
+ angular: "@monei-js/angular-components"
1044
+ };
1045
+ function warnDriverDeprecation(name) {
1046
+ const pkg = driverPackageMap[name];
1047
+ const replacement = pkg ? `Use ${pkg} instead.` : "";
1048
+ console.warn(`[MONEI] .driver('${name}') is deprecated. ${replacement}`.trim());
1049
+ }
1040
1050
  /**
1041
1051
  * Normalize aliased prop names to canonical names.
1042
1052
  * Aliases define alternative INPUT names: { style: 'innerStyle' } means
@@ -1073,6 +1083,7 @@ function createComponent(options) {
1073
1083
  else this.props = { ...normalizedProps };
1074
1084
  if (options.validate) options.validate({ props: this.props });
1075
1085
  attachRenderMethods(this, options);
1086
+ if (options.submit) this.submit = options.submit(this);
1076
1087
  }
1077
1088
  async render(_container) {
1078
1089
  throw new Error("render() not attached");
@@ -1087,6 +1098,7 @@ function createComponent(options) {
1087
1098
  throw new Error("destroy() not attached");
1088
1099
  }
1089
1100
  driver(name, deps) {
1101
+ warnDriverDeprecation(name);
1090
1102
  return resolveDriver(name, Component, deps);
1091
1103
  }
1092
1104
  }
@@ -1096,6 +1108,7 @@ function createComponent(options) {
1096
1108
  }
1097
1109
  ComponentWrapper.prototype = Component.prototype;
1098
1110
  ComponentWrapper.driver = function(name, deps) {
1111
+ warnDriverDeprecation(name);
1099
1112
  return resolveDriver(name, ComponentWrapper, deps);
1100
1113
  };
1101
1114
  Component.prototype.__options = options;
@@ -1260,6 +1273,7 @@ const getCreateTokenFunction = (ref) => {
1260
1273
  throw new Error("Index is not registered");
1261
1274
  };
1262
1275
  const createToken = async (component, options) => {
1276
+ console.warn("[MONEI] Standalone createToken() is deprecated. Use cardInput.submit() instead.");
1263
1277
  const { data } = await getCreateTokenFunction(component)(options);
1264
1278
  return data;
1265
1279
  };
@@ -1283,6 +1297,12 @@ const CardInput = createComponent({
1283
1297
  type: "function"
1284
1298
  } },
1285
1299
  validate: validateComponentProps,
1300
+ submit: (instance) => async (opts) => {
1301
+ const createTokenFn = instance.state?.__createToken;
1302
+ if (!createTokenFn) throw new Error("CardInput is not rendered or connection is pending — call render() first");
1303
+ const { data } = await createTokenFn(opts);
1304
+ return data;
1305
+ },
1286
1306
  containerTemplate: (params) => {
1287
1307
  params.state.__createToken = async (data = {}) => {
1288
1308
  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,7 +170,7 @@ const validateComponentProps = ({ props }) => {
170
170
  };
171
171
  //#endregion
172
172
  //#region src/config.ts
173
- const stage = import.meta.env?.STAGE || "local";
173
+ const stage = import.meta.env?.STAGE || "prod";
174
174
  const domain = import.meta.env?.DOMAIN || "http://localhost:3001";
175
175
  const version = import.meta.env?.VERSION || "v1";
176
176
  const globalConfig = {
@@ -1025,6 +1025,16 @@ function attachRenderMethods(instance, options) {
1025
1025
  }
1026
1026
  //#endregion
1027
1027
  //#region src/bridge/create-component.ts
1028
+ const driverPackageMap = {
1029
+ react: "@monei-js/react-components",
1030
+ vue3: "@monei-js/vue-components",
1031
+ angular: "@monei-js/angular-components"
1032
+ };
1033
+ function warnDriverDeprecation(name) {
1034
+ const pkg = driverPackageMap[name];
1035
+ const replacement = pkg ? `Use ${pkg} instead.` : "";
1036
+ console.warn(`[MONEI] .driver('${name}') is deprecated. ${replacement}`.trim());
1037
+ }
1028
1038
  /**
1029
1039
  * Normalize aliased prop names to canonical names.
1030
1040
  * Aliases define alternative INPUT names: { style: 'innerStyle' } means
@@ -1061,6 +1071,7 @@ function createComponent(options) {
1061
1071
  else this.props = { ...normalizedProps };
1062
1072
  if (options.validate) options.validate({ props: this.props });
1063
1073
  attachRenderMethods(this, options);
1074
+ if (options.submit) this.submit = options.submit(this);
1064
1075
  }
1065
1076
  async render(_container) {
1066
1077
  throw new Error("render() not attached");
@@ -1075,6 +1086,7 @@ function createComponent(options) {
1075
1086
  throw new Error("destroy() not attached");
1076
1087
  }
1077
1088
  driver(name, deps) {
1089
+ warnDriverDeprecation(name);
1078
1090
  return resolveDriver(name, Component, deps);
1079
1091
  }
1080
1092
  }
@@ -1084,6 +1096,7 @@ function createComponent(options) {
1084
1096
  }
1085
1097
  ComponentWrapper.prototype = Component.prototype;
1086
1098
  ComponentWrapper.driver = function(name, deps) {
1099
+ warnDriverDeprecation(name);
1087
1100
  return resolveDriver(name, ComponentWrapper, deps);
1088
1101
  };
1089
1102
  Component.prototype.__options = options;
@@ -1248,6 +1261,7 @@ const getCreateTokenFunction = (ref) => {
1248
1261
  throw new Error("Index is not registered");
1249
1262
  };
1250
1263
  const createToken = async (component, options) => {
1264
+ console.warn("[MONEI] Standalone createToken() is deprecated. Use cardInput.submit() instead.");
1251
1265
  const { data } = await getCreateTokenFunction(component)(options);
1252
1266
  return data;
1253
1267
  };
@@ -1271,6 +1285,12 @@ const CardInput = createComponent({
1271
1285
  type: "function"
1272
1286
  } },
1273
1287
  validate: validateComponentProps,
1288
+ submit: (instance) => async (opts) => {
1289
+ const createTokenFn = instance.state?.__createToken;
1290
+ if (!createTokenFn) throw new Error("CardInput is not rendered or connection is pending — call render() first");
1291
+ const { data } = await createTokenFn(opts);
1292
+ return data;
1293
+ },
1274
1294
  containerTemplate: (params) => {
1275
1295
  params.state.__createToken = async (data = {}) => {
1276
1296
  const callChild = params.state.__callChild;