@montonio/montonio-js 1.1.2 → 1.1.3

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
@@ -11,10 +11,13 @@ We support installation both as a JavaScript module (ESM) and as an embedded scr
11
11
  ## ES Module
12
12
 
13
13
  1. Install the package using npm or yarn:
14
+
14
15
  ```bash
15
16
  npm install @montonio/montonio-js
16
17
  ```
18
+
17
19
  2. Import the library in your JavaScript code:
20
+
18
21
  ```javascript
19
22
  import { MontonioCheckout } from '@montonio/montonio-js';
20
23
  ```
@@ -55,9 +58,9 @@ import { MontonioCheckout } from '@montonio/montonio-js'; // ES Module usage. Se
55
58
  const checkoutOptions = {
56
59
  sessionUuid: 'session-uuid', // The UUID of the session created on your server
57
60
  environment: 'sandbox', // Defaults to 'production'
58
- locale: 'en', // The language of the payment gateway. Defaults to your store default language.
59
- // Available values are ('en', 'et', 'lt', 'lv', 'pl', 'ru', 'fi')
60
- // TypeScript users can use LocaleEnum.EN (or ET, LT, etc.) by importing LocaleEnum from @montonio/montonio-js
61
+ locale: 'en', // The language of the payment gateway. Defaults to your store default language.
62
+ // Available values are ('en', 'et', 'lt', 'lv', 'pl', 'ru', 'fi')
63
+ // TypeScript users can use LocaleEnum.EN (or ET, LT, etc.) by importing LocaleEnum from @montonio/montonio-js
61
64
  onSuccess: (result) => {
62
65
  // Payment completed successfully
63
66
  // Redirect to the thank you page
@@ -67,7 +70,13 @@ const checkoutOptions = {
67
70
  // Payment failed or validation error occurred
68
71
  console.error('Payment failed:', error);
69
72
  // Unlock your checkout form to allow the user to try again
70
- }
73
+ },
74
+ onActionRequired: (payload) => {
75
+ // Optional. Called when additional user action is required (e.g. 3DS, OTP).
76
+ // Use it to lock the pay button or show an overlay. When payload.action is
77
+ // 'scrollIntoView', scroll or focus the payment area so the user can complete
78
+ // authentication there.
79
+ },
71
80
  };
72
81
 
73
82
  const montonioCheckout = new MontonioCheckout(checkoutOptions);
@@ -97,7 +106,7 @@ Once the user has clicked the "Pay" button in your checkout and you have validat
97
106
 
98
107
  Make sure you **include the session UUID in the order request**. See the [Order data structure](https://docs.montonio.com/api/stargate/guides/orders#1-order-data-structure) section of the Orders guide for more details.
99
108
 
100
- Once the order is created, you can call the `submitPayment` method on the `MontonioCheckout` instance.
109
+ Once the order is created, you can call the `submitPayment` method on the `MontonioCheckout` instance.
101
110
 
102
111
  Immediately after the user clicks "Pay" and even before you create the Montonio order, lock your checkout and prevent the user from making any further changes. Show a loading indicator to the user while the order is being created and while the payment is being submitted.
103
112
 
@@ -109,10 +118,12 @@ montonioCheckout.submitPayment();
109
118
  // The onError callback will be invoked if payment fails
110
119
  ```
111
120
 
112
- The `MontonioCheckout.submitPayment()` method will initiate the payment submission. In case a payment method requires additional user authentication (such as 3DS for card payments), a modal will pop up to handle the authentication.
121
+ The `MontonioCheckout.submitPayment()` method will initiate the payment submission. In case a payment method requires additional user authentication (such as 3DS for card payments), a modal will pop up to handle the authentication.
113
122
 
114
123
  When the payment completes (successfully or with an error), the appropriate callback you defined during initialization will be invoked:
124
+
115
125
  - **`onSuccess(result)`**: Called when payment is successful. The result contains `paymentStatus`, `orderToken`, and `returnUrl` fields.
116
126
  - **`onError(error)`**: Called when payment fails or validation errors occur.
127
+ - **`onActionRequired(payload)`** (Optional): Called when additional user action is required (e.g. authentication such as 3DS or OTP). Use it to lock the pay button or show an overlay. The `payload` has `action` (e.g. `'scrollIntoView'`); when it is `'scrollIntoView'`, scroll or focus the payment area so the user can complete authentication there.
117
128
 
118
129
  The `returnUrl` is the URL you provided in the backend request to create the order. As per the API documentation, this URL will contain the `order-token` query parameter, which you can use to validate the payment. In most cases, you should redirect the user to the `returnUrl` in your `onSuccess` callback and handle the token validation on that page.