@payrails/web-sdk 5.41.0 → 5.42.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
@@ -10,14 +10,91 @@ You can integrate Payrails Web in two ways:
10
10
  - Elements: One component for each payment method, credit card forms and more.
11
11
  Fully customizable solution.
12
12
 
13
- ## Importing the SDK
13
+ ## Installation
14
14
 
15
- ```JavaScript
15
+ ```bash
16
16
  npm install @payrails/web-sdk
17
17
  ```
18
18
 
19
+ ## Integration
20
+
21
+ The SDK supports multiple integration methods depending on your setup.
22
+
23
+ ### With a Bundler (Webpack, Vite, Rollup, esbuild, etc.)
24
+
25
+ If you use a bundler, import the SDK directly using ES module syntax:
26
+
27
+ ```js
28
+ import { Payrails, PayrailsEnvironment } from '@payrails/web-sdk';
29
+ import '@payrails/web-sdk/payrails-styles.css';
30
+ ```
31
+
32
+ ### Without a Bundler (Native ESM in the Browser)
33
+
34
+ If your project uses native ES modules (e.g. `<script type="module">` or a
35
+ `"type": "module"` package), the SDK works out of the box:
36
+
37
+ ```js
38
+ import { Payrails, PayrailsEnvironment } from '@payrails/web-sdk';
39
+ ```
40
+
41
+ This resolves to the ESM build (`index.mjs`) automatically via the `exports`
42
+ field in `package.json`.
43
+
44
+ ### CommonJS (Node.js / Legacy)
45
+
46
+ For CommonJS environments, use `require`:
47
+
48
+ ```js
49
+ const { Payrails, PayrailsEnvironment } = require('@payrails/web-sdk');
50
+ ```
51
+
52
+ ## Quick Start
53
+
54
+ After installing, initialize the SDK with the response from the
55
+ `/merchant/client/init` API:
56
+
57
+ ```js
58
+ import { Payrails } from '@payrails/web-sdk';
59
+ import '@payrails/web-sdk/payrails-styles.css';
60
+
61
+ // 1. Initialize the SDK with the client init response
62
+ const payrails = Payrails.init(clientInitResponse, {
63
+ events: {
64
+ onClientInitialized: () => console.log('SDK ready'),
65
+ },
66
+ });
67
+
68
+ // 2a. Mount the dropin (all-in-one checkout)
69
+ const dropin = payrails.dropin({
70
+ events: {
71
+ onAuthorizeSuccess: (action, result) =>
72
+ console.log('Payment success', result),
73
+ onAuthorizeFailed: (action, error) => console.log('Payment failed', error),
74
+ },
75
+ });
76
+ dropin.mount('#dropin');
77
+
78
+ // 2b. Or mount individual elements for full control
79
+ const cardForm = payrails.cardForm({ showCardHolderName: true });
80
+ cardForm.mount('#card-form');
81
+
82
+ const paymentButton = payrails.paymentButton({
83
+ translations: { label: 'Pay Now' },
84
+ events: {
85
+ onAuthorizeSuccess: () => console.log('Payment authorized'),
86
+ onAuthorizeFailed: (e) => console.log('Payment failed', e),
87
+ },
88
+ });
89
+ paymentButton.mount('#payment-button');
90
+ ```
91
+
19
92
  ## Release Notes
20
93
 
94
+ ### 5.42.0
95
+
96
+ - FEATURE: Support mjs and cjs outputs.
97
+
21
98
  ### 5.41.0
22
99
 
23
100
  - FEATURE: Expose payment method configs through headless query API.