xendit-components-web 0.0.10 → 0.0.12

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/CHANGELOG.md CHANGED
@@ -2,15 +2,38 @@
2
2
 
3
3
  No unreleased changes.
4
4
 
5
+ # 0.0.12
6
+
7
+ ### Bug fixes
8
+
9
+ - Fixed a bug where the credit card expiry field would not insert a slash if the user pasted the expiry date without a slash.
10
+ - Fixed poor UX when typing a slash in the credit card expiry field.
11
+ - Allow card expiry up to 2099
12
+
13
+ # 0.0.11
14
+
15
+ ### Notable
16
+
17
+ Disabled Google Translate using the `translate=no` attribute as it causes issues.
18
+
19
+ Added new public method `pollImmediately` to immediently check for updates.
20
+
21
+ Changed the layout of the default action container.
22
+
23
+ ### Bug fixes
24
+
25
+ - Fixed UX bugs in the dropdown widget.
26
+ - Prevent auto-updating the phone number country code if the user already typed a phone number.
27
+
5
28
  # 0.0.10
6
29
 
7
- ## Bug fixes
30
+ ### Bug fixes
8
31
 
9
32
  Fixed npm publish.
10
33
 
11
34
  # 0.0.9
12
35
 
13
- ## Bug fixes
36
+ ### Bug fixes
14
37
 
15
38
  Missing `.d.ts` file is restored.
16
39
 
package/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # xendit-components-web
2
2
 
3
- Xendit Components allows you to accept payments directly on your website using the Xendit Sessions API.
3
+ [![npm badge](https://img.shields.io/npm/v/xendit-components-web)](https://www.npmjs.com/package/xendit-components-web) [![build status badge](https://img.shields.io/github/actions/workflow/status/xendit/xendit-components-web/build-and-test.yml)](https://github.com/xendit/xendit-components-web/actions/workflows/build-and-test.yml?query=branch%3Amain) [![coverage badge](https://img.shields.io/codecov/c/github/xendit/xendit-components-web)](https://app.codecov.io/gh/xendit/xendit-components-web)
4
4
 
5
- This SDK's role is to take a Session (created on your server using the Xendit Sessions API) and render a payment UI, and allow you to customize the UI to match your site's look & feel.
5
+ With Xendit Components, you can build a checkout experience tightly integrated into your site, powered by the Xendit Sessions API.
6
+
7
+ This SDK provides UI components for payment method selection, user input (e.g. credit cards), and user actions (e.g. 3DS), all of which can be customized to match your site's look & feel.
8
+
9
+ View a live demo [here](https://demo-store.xendit.co/) by choosing "Xendit Components". View the demo source code [here](https://github.com/xendit/demo-store/tree/main/src/integrations).
6
10
 
7
11
  ## Installation
8
12
 
@@ -15,10 +19,10 @@ npm install xendit-components-web --save
15
19
  Or load it directly from our CDN:
16
20
 
17
21
  ```html
18
- <script src="https://assets.xendit.co/components/v0.0.10/index.umd.js"></script>
22
+ <script src="https://assets.xendit.co/components/v0.0.12/index.umd.js"></script>
19
23
  ```
20
24
 
21
- Our npm package includes TypeScript types. If you're using the CDN, download type declarations from `https://assets.xendit.co/components/v0.0.10/index.d.ts`
25
+ Our npm package includes TypeScript types. You also download the [.d.ts file](https://assets.xendit.co/components/v0.0.12/index.d.ts) directly.
22
26
 
23
27
  ## Sessions
24
28
 
@@ -36,11 +40,11 @@ Two types of sessions are available:
36
40
 
37
41
  First, initialize the SDK either with either:
38
42
 
39
- - `XenditComponentsTest` for frontend development or unit tests
40
- - `XenditComponents`, for production, which requires a `componentsSdkKey`. That key comes from the session object you create on your server. Make an endpoint that creates a session for the user's current transaction, return the `components_sdk_key` to the client, and pass it into the constructor.
43
+ - Use `XenditComponentsTest` to use mock payment methods for development and testing.
44
+ - Use `XenditComponents` to connect to the Xendit backend (including Xendit's test mode). This requires a `componentsSdkKey` option, which you can get by calling the Create Session endpoint. Create a session from your server, passing the `components_sdk_key` property back to your frontend.
41
45
 
42
46
  ```typescript
43
- // For frontend development, use XenditComponentsTest
47
+ // For frontend development, use XenditComponentsTest, this provides built-in mock payment methods
44
48
  const components: XenditComponents = new XenditComponentsTest({});
45
49
  // For production or e2e testing, use XenditComponents, passing in the components_sdk_key from the Session object
46
50
  const components: XenditComponents = new XenditComponents({ componentsSdkKey });
@@ -69,11 +73,9 @@ components.addEventListener("session-expired-or-canceled", () => {
69
73
 
70
74
  ### `XenditComponents` and `XenditComponentsTest`
71
75
 
72
- The constructor.
73
-
74
- For production and e2e testing, you need to pass the `componentsSdkKey`, which you can get when you create a Session on your server.
76
+ Constructor functions.
75
77
 
76
- For development and unit testing, use `XenditComponentsTest`, which uses mock data and doesn't connect to Xendit servers.
78
+ Both have the same API. `XenditComponents` will connect to Xendit servers, while `XenditComponentsTest` provides mock payment channels.
77
79
 
78
80
  ### `createChannelPickerComponent`
79
81
 
@@ -112,7 +114,7 @@ your own channel selection UI. Each channel has a `uiGroup` property which match
112
114
  ```typescript
113
115
  const channel = components.getActiveChannels({ filter: "CARDS" })[0];
114
116
  if (channel) {
115
- const htmlElement = components.createChannelPickerComponent(channel);
117
+ const htmlElement = components.createChannelComponent(channel);
116
118
  myContainer.replaceChildren(htmlElement);
117
119
  }
118
120
  ```
@@ -129,7 +131,11 @@ values the user enters into any form fields. If you don't want that, use `destro
129
131
 
130
132
  ```typescript
131
133
  components.addEventListener("action-begin", () => {
132
- const htmlElement = components.createActionContainerComponent();
134
+ const htmlElement = components.createActionContainerComponent({
135
+ qrCode: {
136
+ qrCodeOnly: true,
137
+ },
138
+ });
133
139
  myActionContainer.replaceChildren(htmlElement);
134
140
  });
135
141
  ```
@@ -226,6 +232,14 @@ if (channel) {
226
232
 
227
233
  Makes the provided channel the current channel.
228
234
 
235
+ ### `pollImmediately`
236
+
237
+ ```typescript
238
+ components.pollImmediately();
239
+ ```
240
+
241
+ Immediately poll for the status of a submission. Only applicable while a submission is ongoing. Useful for handling payment affirmation (e.g. I have made the payment) by the user.
242
+
229
243
  ## Events
230
244
 
231
245
  ### `init`
package/package.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "name": "xendit-components-web",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "Xendit frontend payment components SDK",
5
5
  "type": "module",
6
6
  "author": "Xendit",
7
7
  "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/xendit/xendit-components-web"
11
+ },
8
12
  "keywords": [
9
13
  "xendit",
10
14
  "payment",
@@ -50,16 +54,15 @@
50
54
  "dependencies": {
51
55
  "card-validator": "^10.0.3",
52
56
  "classnames": "^2.5.1",
53
- "credit-card-type": "^10.1.0",
54
- "i18next": "^25.6.3",
55
- "libphonenumber-js": "^1.12.29",
56
- "preact": "^10.27.2",
57
- "react-circle-flags": "^0.0.24",
57
+ "i18next": "^25.8.0",
58
+ "libphonenumber-js": "^1.12.35",
59
+ "preact": "^10.28.2",
60
+ "qrcode": "^1.5.4",
58
61
  "tslib": "^2.8.1"
59
62
  },
60
63
  "devDependencies": {
61
- "@eslint/js": "^9.39.1",
62
- "@microsoft/api-extractor": "^7.55.1",
64
+ "@eslint/js": "^9.39.2",
65
+ "@microsoft/api-extractor": "^7.55.2",
63
66
  "@preact/preset-vite": "^2.10.2",
64
67
  "@rollup/plugin-alias": "^6.0.0",
65
68
  "@rollup/plugin-commonjs": "^29.0.0",
@@ -73,19 +76,20 @@
73
76
  "@testing-library/user-event": "^14.6.1",
74
77
  "@types/mime-types": "^3.0.1",
75
78
  "@types/node": "^24.10.1",
76
- "@vitest/coverage-v8": "4.0.14",
77
- "eslint": "^9.39.1",
79
+ "@types/qrcode": "^1.5.6",
80
+ "@vitest/coverage-v8": "4.0.17",
81
+ "eslint": "^9.39.2",
78
82
  "eslint-plugin-react-hooks": "^7.0.1",
79
83
  "husky": "^9.1.7",
80
- "jsdom": "^27.2.0",
84
+ "jsdom": "^27.4.0",
81
85
  "lint-staged": "^16.2.7",
82
86
  "mime-types": "^3.0.2",
83
- "prettier": "^3.6.2",
84
- "rollup": "^4.53.3",
87
+ "prettier": "^3.8.1",
88
+ "rollup": "^4.56.0",
85
89
  "rollup-plugin-import-css": "^4.1.2",
86
90
  "typescript": "^5.9.3",
87
- "typescript-eslint": "^8.48.0",
88
- "vitest": "^4.0.14"
91
+ "typescript-eslint": "^8.53.1",
92
+ "vitest": "^4.0.17"
89
93
  },
90
- "packageManager": "pnpm@10.15.1"
94
+ "packageManager": "pnpm@10.28.1"
91
95
  }
@@ -1,3 +1,19 @@
1
+ /**
2
+ * @public
3
+ * Options for configuring action containers.
4
+ */
5
+ export declare interface ActionContainerOptions {
6
+ /**
7
+ * QR code specific options.
8
+ */
9
+ qrCode?: {
10
+ /**
11
+ * If true, only the QR code will be displayed without any additional UI elements.
12
+ */
13
+ qrCodeOnly?: boolean;
14
+ };
15
+ }
16
+
1
17
  /**
2
18
  * @public
3
19
  * Channel properties for a payment method or payment token.
@@ -199,6 +215,13 @@ export declare class XenditComponents extends EventTarget {
199
215
  * the SDK will create an action container (in a modal dialog) for you.
200
216
  */
201
217
  createActionContainerComponent(): HTMLElement;
218
+ /**
219
+ * @public
220
+ * Creates a container element for rendering action UIs with options.
221
+ *
222
+ * @param options - Configuration options for the action container
223
+ */
224
+ createActionContainerComponent(options: ActionContainerOptions): HTMLElement;
202
225
  /**
203
226
  * @public
204
227
  * Destroys a component of any type created by the SDK. Removes it from the DOM if necessary.
@@ -251,6 +274,20 @@ export declare class XenditComponents extends EventTarget {
251
274
  * ```
252
275
  */
253
276
  simulatePayment(): void;
277
+ /**
278
+ * @public
279
+ * Request an immediate poll for session status. Useful for handling payment
280
+ * affirmation (e.g. I have made the payment) by the user. The session must still
281
+ * be active.
282
+ *
283
+ * @example
284
+ * ```
285
+ * function onUserAffirmPayment() {
286
+ * components.pollImmediately();
287
+ * }
288
+ * ```
289
+ */
290
+ pollImmediately(): void;
254
291
  /**
255
292
  * @public
256
293
  * The `init` event lets you know when the session data has been loaded.
@@ -359,6 +396,18 @@ export declare class XenditComponents extends EventTarget {
359
396
  * Fallback overload.
360
397
  */
361
398
  removeEventListener<K extends keyof XenditEventMap>(type: K, listener: (this: XenditComponents, ev: XenditEventMap[K]) => void, options?: boolean | AddEventListenerOptions): void;
399
+ /**
400
+ * @public
401
+ * Formats a currency value according to the currency's conventions.
402
+ *
403
+ * e.g.
404
+ * ```
405
+ * USD 1000 -> "$1,000"
406
+ * USD 1000.5 -> "$1,000.50"
407
+ * IDR 1000000 -> "Rp1.000.000"
408
+ * PHP 1000 -> "₱1,000.00"
409
+ * ```
410
+ */
362
411
  static amountFormat(amount: number, currency: string): string;
363
412
  }
364
413