@lightspeed/online-payments-sdk 1.7.2 → 1.7.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 +94 -60
- package/dist/cjs/version.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# Lightspeed Online Payments SDK
|
|
2
2
|
|
|
3
|
-
`@lightspeed/online-payments-sdk` is a browser SDK for
|
|
3
|
+
`@lightspeed/online-payments-sdk` is a browser SDK for displaying Lightspeed Payments widgets in your web application.
|
|
4
|
+
|
|
5
|
+
This is intended for partners who wish to add payments functionality to an integration with a Lightspeed product.
|
|
6
|
+
|
|
7
|
+
For onboarding questions, account configuration, or production enablement: contact your Lightspeed
|
|
8
|
+
representative.
|
|
4
9
|
|
|
5
10
|
## Installation
|
|
6
11
|
|
|
@@ -8,94 +13,123 @@
|
|
|
8
13
|
npm install @lightspeed/online-payments-sdk
|
|
9
14
|
```
|
|
10
15
|
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
```ts
|
|
14
|
-
import {LightspeedPayments} from '@lightspeed/online-payments-sdk';
|
|
15
|
-
|
|
16
|
-
const controller = await LightspeedPayments.v1.mountPaymentWidget(sessionToken, {
|
|
17
|
-
mountPoint: document.getElementById('payment-widget')!,
|
|
18
|
-
});
|
|
16
|
+
## Requirements
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
- A browser environment with `window` and `document`
|
|
19
|
+
- A payment session obtained from your Lightspeed Payments integration
|
|
20
|
+
- An HTML element where the payment widget can be mounted
|
|
22
21
|
|
|
23
|
-
##
|
|
24
|
-
|
|
25
|
-
- TypeScript/JavaScript
|
|
26
|
-
- Browser runtime (requires `window`)
|
|
27
|
-
|
|
28
|
-
## Theming
|
|
22
|
+
## Quick start
|
|
29
23
|
|
|
30
|
-
|
|
24
|
+
Add a mount element to your page:
|
|
31
25
|
|
|
32
|
-
|
|
26
|
+
```html
|
|
27
|
+
<div id="payment-widget"></div>
|
|
28
|
+
```
|
|
33
29
|
|
|
34
|
-
|
|
35
|
-
- `invoicing`
|
|
36
|
-
- `dark`
|
|
30
|
+
Mount the widget with the payment session from your integration:
|
|
37
31
|
|
|
38
32
|
```ts
|
|
39
33
|
import {LightspeedPayments} from '@lightspeed/online-payments-sdk';
|
|
40
34
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
const mountPoint = document.getElementById('payment-widget');
|
|
36
|
+
|
|
37
|
+
if (!mountPoint) {
|
|
38
|
+
throw new Error('Payment widget mount point was not found');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const controller = await LightspeedPayments.v1.mountPaymentWidget(session, {
|
|
42
|
+
mountPoint,
|
|
44
43
|
});
|
|
45
44
|
```
|
|
46
45
|
|
|
47
|
-
|
|
46
|
+
Keep the returned controller to submit the widget or remove it when the containing page or component is no longer needed.
|
|
47
|
+
|
|
48
|
+
## Configuration
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
`mountPaymentWidget(session, configuration)` accepts a payment session and the following configuration:
|
|
51
|
+
|
|
52
|
+
| Option | Description |
|
|
53
|
+
| --------------- | ---------------------------------------------------------------- |
|
|
54
|
+
| `mountPoint` | Required `HTMLElement` where the SDK renders the payment widget. |
|
|
55
|
+
| `defaultValues` | Optional initial address values: `country` and `postalCode`. |
|
|
56
|
+
| `listeners` | Optional callbacks for widget lifecycle and payment events. |
|
|
57
|
+
| `theme` | Optional visual theme: `dark`. |
|
|
50
58
|
|
|
51
59
|
```ts
|
|
52
|
-
|
|
60
|
+
const controller = await LightspeedPayments.v1.mountPaymentWidget(session, {
|
|
61
|
+
mountPoint,
|
|
62
|
+
defaultValues: {
|
|
63
|
+
country: 'CA',
|
|
64
|
+
postalCode: 'H1H1H1',
|
|
65
|
+
},
|
|
66
|
+
listeners: {
|
|
67
|
+
onReady: () => {
|
|
68
|
+
// The widget is ready for payer input.
|
|
69
|
+
},
|
|
70
|
+
onChange: event => {
|
|
71
|
+
submitButton.disabled = event.code !== 'Complete';
|
|
72
|
+
},
|
|
73
|
+
onSucceeded: () => {
|
|
74
|
+
// Continue after a successful payment or payment-method save.
|
|
75
|
+
},
|
|
76
|
+
onDeclined: event => {
|
|
77
|
+
// Show a decline message appropriate for event.code.
|
|
78
|
+
},
|
|
79
|
+
onError: event => {
|
|
80
|
+
// Handle a widget or processing error.
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
});
|
|
53
84
|
```
|
|
54
85
|
|
|
55
|
-
|
|
86
|
+
### Events
|
|
56
87
|
|
|
57
|
-
|
|
58
|
-
- Sandbox releases (testing unreleased builds in a real app): `packages/lsp-online-payments-sdk/docs/sandbox-releases.md`
|
|
88
|
+
Listeners receive an event with a `status` and `code`. Available listener names are `onReady`, `onChange`, `onSucceeded`, `onPending`, `onDeclined`, and `onError`.
|
|
59
89
|
|
|
60
|
-
|
|
90
|
+
| Status | Codes |
|
|
91
|
+
| ----------- | -------------------------------------------------------------------------------------------------------------- |
|
|
92
|
+
| `Ready` | `Ready` |
|
|
93
|
+
| `Change` | `Complete`, `Incomplete` |
|
|
94
|
+
| `Succeeded` | `Authorized` |
|
|
95
|
+
| `Pending` | `Processing` |
|
|
96
|
+
| `Declined` | `CardValidation`, `Generic`, `PaymentMethodNotSupported` |
|
|
97
|
+
| `Error` | `Unexpected`, `InvalidSession`, `InvalidSessionPayload`, `UnsupportedLocation`, `Processing`, `FormValidation` |
|
|
61
98
|
|
|
62
|
-
|
|
99
|
+
## Submit and unmount
|
|
63
100
|
|
|
64
|
-
|
|
65
|
-
npm run lint --workspace @lightspeed/online-payments-sdk
|
|
66
|
-
npm run typecheck --workspace @lightspeed/online-payments-sdk
|
|
67
|
-
npm run test --workspace @lightspeed/online-payments-sdk
|
|
68
|
-
```
|
|
101
|
+
Call `submit()` in response to your application's payment action. Call `unmount()` before removing or replacing the mount element.
|
|
69
102
|
|
|
70
|
-
|
|
103
|
+
```ts
|
|
104
|
+
submitButton.addEventListener('click', async () => {
|
|
105
|
+
await controller.submit();
|
|
106
|
+
});
|
|
71
107
|
|
|
72
|
-
|
|
73
|
-
|
|
108
|
+
// For example, during page or component cleanup.
|
|
109
|
+
controller.unmount();
|
|
74
110
|
```
|
|
75
111
|
|
|
76
|
-
|
|
112
|
+
## Theming
|
|
77
113
|
|
|
78
|
-
|
|
79
|
-
npm pack --dry-run
|
|
80
|
-
```
|
|
114
|
+
Use `theme` to select a widget appearance:
|
|
81
115
|
|
|
82
|
-
|
|
116
|
+
- Omit `theme` to use the default appearance.
|
|
117
|
+
- `dark` uses a dark appearance and styles the mount element with a dark background.
|
|
83
118
|
|
|
84
|
-
|
|
119
|
+
Custom themes can be used with support from the Lightspeed Payments team.
|
|
85
120
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
121
|
+
```ts
|
|
122
|
+
await LightspeedPayments.v1.mountPaymentWidget(session, {
|
|
123
|
+
mountPoint,
|
|
124
|
+
theme: 'dark',
|
|
125
|
+
});
|
|
126
|
+
```
|
|
92
127
|
|
|
93
|
-
|
|
128
|
+
For a wrapper around a widget using the `dark` theme, use `THEME_COLORS` to match the SDK's dark container colors:
|
|
94
129
|
|
|
95
|
-
|
|
130
|
+
```ts
|
|
131
|
+
import {THEME_COLORS} from '@lightspeed/online-payments-sdk';
|
|
96
132
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
app requires no `import` changes — just an `.npmrc` scope + a `package.json`
|
|
101
|
-
alias. See `docs/sandbox-releases.md` for the full publish and consume steps.
|
|
133
|
+
wrapper.style.backgroundColor = THEME_COLORS.DARK.BACKGROUND;
|
|
134
|
+
wrapper.style.color = THEME_COLORS.DARK.TEXT;
|
|
135
|
+
```
|
package/dist/cjs/version.js
CHANGED
|
@@ -3,4 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SDK_VERSION = void 0;
|
|
4
4
|
// This file is auto-generated during the build process
|
|
5
5
|
// DO NOT EDIT MANUALLY - Version is extracted from package.json
|
|
6
|
-
exports.SDK_VERSION = '1.7.
|
|
6
|
+
exports.SDK_VERSION = '1.7.3';
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.7.
|
|
1
|
+
export declare const SDK_VERSION = "1.7.3";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED