react-native-seel-widget 0.1.21 → 0.1.22
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 +388 -36
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,60 +1,131 @@
|
|
|
1
1
|
# react-native-seel-widget
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/react-native-seel-widget)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
Seel Widget SDK for React Native - Integrate Seel's Worry-Free Purchase (WFP) widget into your React Native applications for iOS, Android, and Web.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
## Features
|
|
8
9
|
|
|
10
|
+
- 🎯 **Cross-platform**: Works on iOS, Android, and Web
|
|
11
|
+
- 🔒 **Type-safe**: Full TypeScript support
|
|
12
|
+
- ⚡ **Easy Integration**: Simple API with minimal setup
|
|
13
|
+
- 🎨 **Customizable**: Flexible styling and configuration options
|
|
14
|
+
- 💾 **Persistent Storage**: Automatic opt-in/opt-out preference management
|
|
15
|
+
- 🌍 **Multi-domain Support**: Support for US and EU regions
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
### Using npm
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install react-native-seel-widget
|
|
9
23
|
```
|
|
24
|
+
|
|
25
|
+
### Using yarn
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
yarn add react-native-seel-widget
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Using Expo
|
|
32
|
+
|
|
33
|
+
```bash
|
|
10
34
|
npx expo install react-native-seel-widget
|
|
11
35
|
```
|
|
12
36
|
|
|
13
|
-
###
|
|
37
|
+
### iOS Setup (React Native CLI only)
|
|
38
|
+
|
|
39
|
+
If you're using React Native CLI (not Expo), you need to install iOS dependencies:
|
|
14
40
|
|
|
15
|
-
|
|
41
|
+
```bash
|
|
42
|
+
cd ios && pod install
|
|
43
|
+
```
|
|
16
44
|
|
|
17
|
-
|
|
18
|
-
yarn add react-native-seel-widget
|
|
19
|
-
```
|
|
45
|
+
### Additional Dependencies
|
|
20
46
|
|
|
21
|
-
|
|
47
|
+
This library requires `@react-native-async-storage/async-storage` for storing user preferences. It should be installed automatically, but if you encounter issues:
|
|
22
48
|
|
|
23
|
-
|
|
49
|
+
```bash
|
|
50
|
+
npm install @react-native-async-storage/async-storage
|
|
51
|
+
# or
|
|
52
|
+
yarn add @react-native-async-storage/async-storage
|
|
53
|
+
```
|
|
24
54
|
|
|
25
|
-
|
|
26
|
-
cd ios && pod install
|
|
27
|
-
```
|
|
55
|
+
## Quick Start
|
|
28
56
|
|
|
29
|
-
|
|
57
|
+
### Step 1: Configure the SDK
|
|
58
|
+
|
|
59
|
+
Configure the SDK in your app entry point (e.g., `App.tsx`):
|
|
30
60
|
|
|
31
61
|
```tsx
|
|
32
|
-
|
|
62
|
+
import { SeelWidgetSDK, SeelEnvironment } from 'react-native-seel-widget';
|
|
63
|
+
|
|
64
|
+
// Configure SDK before using any components
|
|
33
65
|
SeelWidgetSDK.shared.configure({
|
|
34
|
-
apiKey: '
|
|
35
|
-
environment: SeelEnvironment.Development,
|
|
66
|
+
apiKey: 'your-api-key-here',
|
|
67
|
+
environment: SeelEnvironment.Development, // or SeelEnvironment.Production
|
|
68
|
+
requestTimeout: 5000, // Optional: Request timeout in milliseconds (default: 5000)
|
|
69
|
+
optOutExpiredTime: 31536000000, // Optional: Opt-out expiration time in milliseconds (default: 365 days)
|
|
36
70
|
});
|
|
37
71
|
```
|
|
38
72
|
|
|
73
|
+
### Step 2: Use the Widget Component
|
|
74
|
+
|
|
39
75
|
```tsx
|
|
40
|
-
|
|
41
|
-
import {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
76
|
+
import React, { useRef, useEffect, useState } from 'react';
|
|
77
|
+
import { View } from 'react-native';
|
|
78
|
+
import {
|
|
79
|
+
SeelWFPWidget,
|
|
80
|
+
DomainEnum,
|
|
81
|
+
type IQuotesRequest,
|
|
82
|
+
type IQuotesResponse,
|
|
83
|
+
} from 'react-native-seel-widget';
|
|
84
|
+
|
|
85
|
+
export default function CheckoutPage() {
|
|
86
|
+
const [domain, setDomain] = useState<DomainEnum>(DomainEnum.US);
|
|
87
|
+
const [request, setRequest] = useState<IQuotesRequest>({
|
|
88
|
+
session_id: 'session-123',
|
|
89
|
+
type: 'checkout',
|
|
90
|
+
device_category: 'mobile',
|
|
91
|
+
device_platform: 'ios',
|
|
92
|
+
line_items: [
|
|
93
|
+
{
|
|
94
|
+
product_id: 'product-123',
|
|
95
|
+
product_title: 'Example Product',
|
|
96
|
+
price: 99.99,
|
|
97
|
+
quantity: 1,
|
|
98
|
+
image_urls: ['https://example.com/image.jpg'],
|
|
99
|
+
allocated_discounts: 0,
|
|
100
|
+
category_1: 'Electronics',
|
|
101
|
+
category_2: 'Mobile',
|
|
102
|
+
currency: 'USD',
|
|
103
|
+
final_price: 99.99,
|
|
104
|
+
is_final_sale: false,
|
|
105
|
+
line_item_id: 'line-item-123',
|
|
106
|
+
requires_shipping: true,
|
|
107
|
+
sales_tax: 0,
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
customer: {
|
|
111
|
+
customer_id: 'customer-123',
|
|
112
|
+
email: 'customer@example.com',
|
|
113
|
+
},
|
|
114
|
+
shipping_address: {
|
|
115
|
+
address1: '123 Main St',
|
|
116
|
+
city: 'New York',
|
|
117
|
+
state: 'NY',
|
|
118
|
+
zip: '10001',
|
|
119
|
+
country: 'US',
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const seelWidgetRef = useRef<any>(null);
|
|
124
|
+
|
|
50
125
|
useEffect(() => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
seelWidgetRef.current.setup(request);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
setup();
|
|
126
|
+
if (seelWidgetRef.current) {
|
|
127
|
+
seelWidgetRef.current.setup(request);
|
|
128
|
+
}
|
|
58
129
|
}, [request]);
|
|
59
130
|
|
|
60
131
|
return (
|
|
@@ -62,18 +133,299 @@ export default function YourPage() {
|
|
|
62
133
|
<SeelWFPWidget
|
|
63
134
|
ref={seelWidgetRef}
|
|
64
135
|
domain={domain}
|
|
136
|
+
defaultOptedIn={false}
|
|
65
137
|
onChangeValue={({
|
|
66
138
|
optedIn,
|
|
67
139
|
quotesResponse,
|
|
68
140
|
}: {
|
|
69
141
|
optedIn: boolean;
|
|
70
142
|
quotesResponse?: IQuotesResponse;
|
|
71
|
-
})
|
|
72
|
-
console.log(
|
|
143
|
+
}) => {
|
|
144
|
+
console.log('Opt-in status:', optedIn);
|
|
145
|
+
console.log('Quote response:', quotesResponse);
|
|
73
146
|
}}
|
|
74
147
|
/>
|
|
75
148
|
</View>
|
|
76
149
|
);
|
|
77
150
|
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## API Reference
|
|
154
|
+
|
|
155
|
+
### SeelWidgetSDK
|
|
156
|
+
|
|
157
|
+
The main SDK class for configuration.
|
|
158
|
+
|
|
159
|
+
#### Methods
|
|
160
|
+
|
|
161
|
+
##### `configure(props: SeelWidgetSDKProps)`
|
|
162
|
+
|
|
163
|
+
Configure the SDK with your API key and settings.
|
|
164
|
+
|
|
165
|
+
**Parameters:**
|
|
166
|
+
|
|
167
|
+
- `apiKey` (string, required): Your Seel API key
|
|
168
|
+
- `environment` (SeelEnvironment, optional): `SeelEnvironment.Development` or `SeelEnvironment.Production` (default: `Production`)
|
|
169
|
+
- `apiVersion` (string, optional): API version (default: `'2.6.0'`)
|
|
170
|
+
- `requestTimeout` (number, optional): Request timeout in milliseconds (default: `5000`)
|
|
171
|
+
- `optOutExpiredTime` (number, optional): Opt-out expiration time in milliseconds (default: `31536000000` = 365 days)
|
|
172
|
+
|
|
173
|
+
**Example:**
|
|
174
|
+
|
|
175
|
+
```tsx
|
|
176
|
+
SeelWidgetSDK.shared.configure({
|
|
177
|
+
apiKey: 'your-api-key',
|
|
178
|
+
environment: SeelEnvironment.Development,
|
|
179
|
+
requestTimeout: 10000,
|
|
180
|
+
optOutExpiredTime: 86400000, // 1 day
|
|
181
|
+
});
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
#### Properties
|
|
185
|
+
|
|
186
|
+
- `SeelWidgetSDK.shared.apiKey`: Get current API key
|
|
187
|
+
- `SeelWidgetSDK.shared.apiVersion`: Get current API version
|
|
188
|
+
- `SeelWidgetSDK.shared.environment`: Get current environment
|
|
189
|
+
- `SeelWidgetSDK.shared.requestTimeout`: Get current request timeout
|
|
190
|
+
- `SeelWidgetSDK.shared.optOutExpiredTime`: Get current opt-out expiration time
|
|
191
|
+
|
|
192
|
+
### SeelWFPWidget
|
|
193
|
+
|
|
194
|
+
The main widget component for displaying the Worry-Free Purchase option.
|
|
195
|
+
|
|
196
|
+
#### Props
|
|
197
|
+
|
|
198
|
+
| Prop | Type | Required | Description |
|
|
199
|
+
|------|------|----------|-------------|
|
|
200
|
+
| `domain` | `DomainEnum` | Yes | The domain/region (`DomainEnum.US` or `DomainEnum.EU`) |
|
|
201
|
+
| `defaultOptedIn` | `boolean` | No | Default opt-in state (default: `false`) |
|
|
202
|
+
| `onChangeValue` | `(params: { optedIn: boolean; quotesResponse?: IQuotesResponse }) => void` | No | Callback when opt-in status changes |
|
|
203
|
+
|
|
204
|
+
#### Ref Methods
|
|
205
|
+
|
|
206
|
+
##### `setup(quote: IQuotesRequest)`
|
|
207
|
+
|
|
208
|
+
Setup the widget with quote request data.
|
|
209
|
+
|
|
210
|
+
**Parameters:**
|
|
211
|
+
|
|
212
|
+
- `quote` (IQuotesRequest): The quote request containing line items
|
|
213
|
+
|
|
214
|
+
**Example:**
|
|
215
|
+
|
|
216
|
+
```tsx
|
|
217
|
+
const quote: IQuotesRequest = {
|
|
218
|
+
session_id: 'session-123',
|
|
219
|
+
type: 'checkout',
|
|
220
|
+
device_category: 'mobile',
|
|
221
|
+
device_platform: 'ios',
|
|
222
|
+
line_items: [
|
|
223
|
+
{
|
|
224
|
+
product_id: 'product-123',
|
|
225
|
+
product_title: 'Product Name',
|
|
226
|
+
price: 99.99,
|
|
227
|
+
quantity: 1,
|
|
228
|
+
image_urls: ['https://example.com/image.jpg'],
|
|
229
|
+
allocated_discounts: 0,
|
|
230
|
+
category_1: 'Electronics',
|
|
231
|
+
category_2: 'Mobile',
|
|
232
|
+
currency: 'USD',
|
|
233
|
+
final_price: 99.99,
|
|
234
|
+
is_final_sale: false,
|
|
235
|
+
line_item_id: 'line-item-123',
|
|
236
|
+
requires_shipping: true,
|
|
237
|
+
sales_tax: 0,
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
customer: {
|
|
241
|
+
customer_id: 'customer-123',
|
|
242
|
+
email: 'customer@example.com',
|
|
243
|
+
},
|
|
244
|
+
shipping_address: {
|
|
245
|
+
address1: '123 Main St',
|
|
246
|
+
city: 'New York',
|
|
247
|
+
state: 'NY',
|
|
248
|
+
zip: '10001',
|
|
249
|
+
country: 'US',
|
|
250
|
+
},
|
|
251
|
+
is_default_on: false, // Optional: Default opt-in state
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
seelWidgetRef.current?.setup(quote);
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### IQuotesRequest
|
|
258
|
+
|
|
259
|
+
Interface for quote request data.
|
|
260
|
+
|
|
261
|
+
```tsx
|
|
262
|
+
interface IQuotesRequest {
|
|
263
|
+
session_id: string;
|
|
264
|
+
type: string;
|
|
265
|
+
device_category: string;
|
|
266
|
+
device_platform: string;
|
|
267
|
+
line_items: IQuotesRequestLineItem[];
|
|
268
|
+
customer: IQuotesRequestCustomer;
|
|
269
|
+
shipping_address: IShippingAddress;
|
|
270
|
+
is_default_on?: boolean; // Optional: Default opt-in state
|
|
271
|
+
// ... other optional fields
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
interface IQuotesRequestLineItem {
|
|
275
|
+
product_id: string;
|
|
276
|
+
product_title: string;
|
|
277
|
+
price: number;
|
|
278
|
+
quantity: number;
|
|
279
|
+
image_urls?: string[];
|
|
280
|
+
allocated_discounts: number;
|
|
281
|
+
category_1: string;
|
|
282
|
+
category_2: string;
|
|
283
|
+
currency: string;
|
|
284
|
+
final_price: number | string;
|
|
285
|
+
is_final_sale: boolean;
|
|
286
|
+
line_item_id: string;
|
|
287
|
+
requires_shipping: boolean;
|
|
288
|
+
sales_tax: number;
|
|
289
|
+
// ... other optional fields
|
|
290
|
+
}
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
> **Note**: For a complete list of all available fields, refer to the TypeScript definitions in the package.
|
|
294
|
+
|
|
295
|
+
### DomainEnum
|
|
296
|
+
|
|
297
|
+
Enum for supported domains/regions.
|
|
298
|
+
|
|
299
|
+
```tsx
|
|
300
|
+
enum DomainEnum {
|
|
301
|
+
Idle = '',
|
|
302
|
+
US = 'US',
|
|
303
|
+
EU = 'EU',
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### SeelEnvironment
|
|
308
|
+
|
|
309
|
+
Enum for SDK environments.
|
|
310
|
+
|
|
311
|
+
```tsx
|
|
312
|
+
enum SeelEnvironment {
|
|
313
|
+
Development = 'development',
|
|
314
|
+
Production = 'production',
|
|
315
|
+
}
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
## Additional Components
|
|
319
|
+
|
|
320
|
+
### SeelWFPTitleView
|
|
321
|
+
|
|
322
|
+
A standalone title view component for displaying the widget title and price.
|
|
323
|
+
|
|
324
|
+
```tsx
|
|
325
|
+
import { SeelWFPTitleView, ResponseStatusEnum } from 'react-native-seel-widget';
|
|
326
|
+
|
|
327
|
+
<SeelWFPTitleView
|
|
328
|
+
status={ResponseStatusEnum.Accepted}
|
|
329
|
+
title="Worry-Free Purchase"
|
|
330
|
+
price={4.99}
|
|
331
|
+
optedIn={false}
|
|
332
|
+
onChangeOptedInValue={(optedIn) => {
|
|
333
|
+
console.log('Opt-in changed:', optedIn);
|
|
334
|
+
}}
|
|
335
|
+
/>
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### SeelWFPInfoView
|
|
339
|
+
|
|
340
|
+
A standalone info view component for displaying detailed widget information.
|
|
341
|
+
|
|
342
|
+
```tsx
|
|
343
|
+
import { SeelWFPInfoView, DomainEnum } from 'react-native-seel-widget';
|
|
344
|
+
|
|
345
|
+
<SeelWFPInfoView
|
|
346
|
+
domain={DomainEnum.US}
|
|
347
|
+
widgetTitle="Worry-Free Purchase"
|
|
348
|
+
termsUrl="https://example.com/terms"
|
|
349
|
+
privacyPolicyUrl="https://example.com/privacy"
|
|
350
|
+
onChangeOptedInValue={(optedIn) => {
|
|
351
|
+
console.log('Opt-in changed:', optedIn);
|
|
352
|
+
}}
|
|
353
|
+
/>
|
|
354
|
+
```
|
|
78
355
|
|
|
356
|
+
## Examples
|
|
357
|
+
|
|
358
|
+
Check out the [example](./example) directory for complete working examples including:
|
|
359
|
+
|
|
360
|
+
- Basic widget integration
|
|
361
|
+
- Cart page with widget
|
|
362
|
+
- Settlement page with widget
|
|
363
|
+
- Settings page
|
|
364
|
+
- Products page with waterfall layout
|
|
365
|
+
|
|
366
|
+
To run the example:
|
|
367
|
+
|
|
368
|
+
```bash
|
|
369
|
+
cd example
|
|
370
|
+
yarn install
|
|
371
|
+
yarn start
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
## TypeScript Support
|
|
375
|
+
|
|
376
|
+
This library is written in TypeScript and includes full type definitions. All exported types are available for import:
|
|
377
|
+
|
|
378
|
+
```tsx
|
|
379
|
+
import type {
|
|
380
|
+
IQuotesRequest,
|
|
381
|
+
IQuotesResponse,
|
|
382
|
+
IQuotesRequestLineItem,
|
|
383
|
+
SeelWFPWidgetRef,
|
|
384
|
+
SeelWFPTitleViewProps,
|
|
385
|
+
SeelWFPInfoViewProps,
|
|
386
|
+
} from 'react-native-seel-widget';
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
## Storage
|
|
390
|
+
|
|
391
|
+
The SDK uses `@react-native-async-storage/async-storage` to persist user opt-in/opt-out preferences. The preferences are automatically managed and respect the `optOutExpiredTime` configuration.
|
|
392
|
+
|
|
393
|
+
## Troubleshooting
|
|
394
|
+
|
|
395
|
+
### Widget not showing
|
|
396
|
+
|
|
397
|
+
1. Ensure the SDK is configured before rendering the widget
|
|
398
|
+
2. Check that `setup()` is called with valid quote data
|
|
399
|
+
3. Verify your API key is correct
|
|
400
|
+
4. Check network connectivity
|
|
401
|
+
|
|
402
|
+
### TypeScript errors
|
|
403
|
+
|
|
404
|
+
Make sure you have TypeScript 4.5+ installed and have enabled strict mode in your `tsconfig.json`.
|
|
405
|
+
|
|
406
|
+
### iOS build issues
|
|
407
|
+
|
|
408
|
+
If you encounter build issues on iOS:
|
|
409
|
+
|
|
410
|
+
```bash
|
|
411
|
+
cd ios
|
|
412
|
+
pod deintegrate
|
|
413
|
+
pod install
|
|
79
414
|
```
|
|
415
|
+
|
|
416
|
+
## Contributing
|
|
417
|
+
|
|
418
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
419
|
+
|
|
420
|
+
## License
|
|
421
|
+
|
|
422
|
+
MIT
|
|
423
|
+
|
|
424
|
+
## Support
|
|
425
|
+
|
|
426
|
+
For issues and feature requests, please use the [GitHub issue tracker](https://github.com/kover-ai/react-native-seel-widget/issues).
|
|
427
|
+
|
|
428
|
+
## Related Links
|
|
429
|
+
|
|
430
|
+
- [GitHub Repository](https://github.com/kover-ai/react-native-seel-widget)
|
|
431
|
+
- [NPM Package](https://www.npmjs.com/package/react-native-seel-widget)
|