@infosoftas/s4-orders-js-sdk 0.0.1-alpha2b → 0.0.1-alpha2c.1
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 +340 -1
- package/package.json +44 -42
- package/src/components/OIOForm/OIOForm.tsx +2 -2
package/README.md
CHANGED
|
@@ -1,3 +1,342 @@
|
|
|
1
1
|
# INFO-Subscription JS/TS Order SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This repository contains code for the Orders SDK usable to add orders for Tenants within INFO-Subscription.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the package with:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @infosoftas/s4-orders-js-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Available Scripts
|
|
14
|
+
|
|
15
|
+
In the project directory, you can run:
|
|
16
|
+
|
|
17
|
+
### `npm run build`
|
|
18
|
+
|
|
19
|
+
Builds the app for production to the `dist` folder.\
|
|
20
|
+
It correctly bundles React in production mode and optimizes the build for the best performance.
|
|
21
|
+
|
|
22
|
+
The build is minified and the filenames include the hashes.\
|
|
23
|
+
Your app is ready to be deployed!
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
The package needs to be configured with configuration object:
|
|
28
|
+
|
|
29
|
+
<!-- prettier-ignore -->
|
|
30
|
+
```ts
|
|
31
|
+
|
|
32
|
+
enum PaymentMethodEnum {
|
|
33
|
+
Vipps = 'Vipps',
|
|
34
|
+
MobilePay = 'MobilePay',
|
|
35
|
+
SwedbankPay = 'SwedbankPay',
|
|
36
|
+
Invoice = 'Invoice',
|
|
37
|
+
Email = 'Email',
|
|
38
|
+
EHF = 'EHF',
|
|
39
|
+
OIO = 'OIO',
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type OrderFormFiledType = {
|
|
43
|
+
name: string;
|
|
44
|
+
required?: boolean;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
type PaymentMethodOptionsType = {
|
|
48
|
+
[key in PaymentMethodEnum]: {
|
|
49
|
+
generateSubscriberContact?: boolean;
|
|
50
|
+
accountId?: string;
|
|
51
|
+
orderFormFields?: OrderFormFiledType[] | never[];
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type OrderFormInputsType = {
|
|
56
|
+
name?: string;
|
|
57
|
+
email?: string;
|
|
58
|
+
phoneNumber?: string;
|
|
59
|
+
paymentMethod?: PaymentMethodEnum;
|
|
60
|
+
country?: string;
|
|
61
|
+
city?: string;
|
|
62
|
+
address?: string;
|
|
63
|
+
zip?: string;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
type ConfigType = {
|
|
67
|
+
domElementId: string;
|
|
68
|
+
moduleTitle?: string;
|
|
69
|
+
apiKey: string;
|
|
70
|
+
apiUrl: string;
|
|
71
|
+
templatePackageId: string;
|
|
72
|
+
subscriberId: string;
|
|
73
|
+
userId: string;
|
|
74
|
+
identityProviderId: string;
|
|
75
|
+
organizationId: string;
|
|
76
|
+
redirectUrl?: string;
|
|
77
|
+
showIframe?: boolean;
|
|
78
|
+
availablePaymentMethods?: { label: string; value: PaymentMethodEnum }[];
|
|
79
|
+
paymentMethodsOptions?: PaymentMethodOptionsType;
|
|
80
|
+
language?: string;
|
|
81
|
+
merchantAgreementUrl?: string;
|
|
82
|
+
invoiceAddressSelection?: {
|
|
83
|
+
enabled?: boolean;
|
|
84
|
+
label?: string;
|
|
85
|
+
fields?: OrderFormFiledType[] | never[];
|
|
86
|
+
};
|
|
87
|
+
settings?: {
|
|
88
|
+
successText?: string;
|
|
89
|
+
failureText?: string;
|
|
90
|
+
submitButtonText?: string;
|
|
91
|
+
backButtonText?: string;
|
|
92
|
+
verifyButtonText?: string;
|
|
93
|
+
organizationNumberLabel?: string;
|
|
94
|
+
glnLabel?: string;
|
|
95
|
+
orderDefaultValues?: OrderFormInputsType;
|
|
96
|
+
paymentMethodLabel?: string;
|
|
97
|
+
errorReqMsg?: string;
|
|
98
|
+
errorInvalidEmailMsg?: string;
|
|
99
|
+
errorInvalidPhoneMsg?: string;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Usage example OrderPlace react component:
|
|
105
|
+
|
|
106
|
+
<!-- prettier-ignore -->
|
|
107
|
+
```tsx
|
|
108
|
+
|
|
109
|
+
enum OrderModuleFiledNameEnum {
|
|
110
|
+
name = 'name',
|
|
111
|
+
email = 'email',
|
|
112
|
+
phoneNumber = 'phoneNumber',
|
|
113
|
+
address = 'address',
|
|
114
|
+
country = 'country',
|
|
115
|
+
city = 'city',
|
|
116
|
+
zip = 'zip',
|
|
117
|
+
careOf = 'careOf',
|
|
118
|
+
organizationNumber = 'organizationNumber',
|
|
119
|
+
buyerReference = 'buyerReference',
|
|
120
|
+
orderReference = 'orderReference',
|
|
121
|
+
invoiceName = 'invoiceName',
|
|
122
|
+
invoiceAddress = 'invoiceAddress',
|
|
123
|
+
invoiceCity = 'invoiceCity',
|
|
124
|
+
invoiceZip = 'invoiceZip',
|
|
125
|
+
invoiceCountry = 'invoiceCountry',
|
|
126
|
+
invoicePhone = 'invoicePhoneNumber',
|
|
127
|
+
invoiceEmail = 'invoiceEmail',
|
|
128
|
+
invoiceCareOf = 'invoiceCareOf',
|
|
129
|
+
invoiceBuyerReference ='invoiceBuyerReference',
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export const prepareConfig = ({
|
|
133
|
+
apiKey,
|
|
134
|
+
apiUrl,
|
|
135
|
+
userId,
|
|
136
|
+
subscriberId,
|
|
137
|
+
templatePackageId,
|
|
138
|
+
identityProviderId,
|
|
139
|
+
organizationId,
|
|
140
|
+
selfServiceUrl,
|
|
141
|
+
userEmail,
|
|
142
|
+
name,
|
|
143
|
+
city,
|
|
144
|
+
country,
|
|
145
|
+
postalCode,
|
|
146
|
+
streetAddress,
|
|
147
|
+
}: Props) => {
|
|
148
|
+
|
|
149
|
+
const config = {
|
|
150
|
+
moduleTitle: '',
|
|
151
|
+
domElementId: ORDER_PLACE_ID,
|
|
152
|
+
redirectUrl: window.location.href,
|
|
153
|
+
merchantAgreementUrl: selfServiceUrl,
|
|
154
|
+
showIframe: true,
|
|
155
|
+
apiKey,
|
|
156
|
+
apiUrl,
|
|
157
|
+
userId,
|
|
158
|
+
subscriberId,
|
|
159
|
+
templatePackageId,
|
|
160
|
+
identityProviderId,
|
|
161
|
+
organizationId,
|
|
162
|
+
language: 'en-US',
|
|
163
|
+
availablePaymentMethods: [
|
|
164
|
+
{ label: "Vipps", value: "Vipps" },
|
|
165
|
+
{ label: "MobilePay", value: "MobilePay" },
|
|
166
|
+
{ label: "Credit Card/Debit Card", value: "SwedbankPay" },
|
|
167
|
+
{ label: 'Invoice', translateKey: 'Invoice', value: 'Invoice' },
|
|
168
|
+
{ label: 'Email', translateKey: 'Email', value: 'Email' },
|
|
169
|
+
{ label: 'EHF', translateKey: 'EHF', value: 'EHF' },
|
|
170
|
+
{ label: 'OIO', translateKey: 'OIO', value: 'OIO' },
|
|
171
|
+
],
|
|
172
|
+
paymentMethodsOptions: {
|
|
173
|
+
Vipps: {
|
|
174
|
+
generateSubscriberContact: true,
|
|
175
|
+
orderFormFields: [],
|
|
176
|
+
},
|
|
177
|
+
SwedbankPay: {
|
|
178
|
+
orderFormFields: [
|
|
179
|
+
{
|
|
180
|
+
name: OrderModuleFiledNameEnum.name,
|
|
181
|
+
label: 'Name',
|
|
182
|
+
required: false,
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
name: OrderModuleFiledNameEnum.phoneNumber,
|
|
186
|
+
label: 'Phone',
|
|
187
|
+
readOnly: false,
|
|
188
|
+
required: false,
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
name: OrderModuleFiledNameEnum.email,
|
|
192
|
+
label: 'Email',
|
|
193
|
+
required: true,
|
|
194
|
+
readOnly: !!userEmail,
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
},
|
|
198
|
+
Invoice: {
|
|
199
|
+
orderFormFields: [
|
|
200
|
+
{
|
|
201
|
+
name: OrderModuleFiledNameEnum.address,
|
|
202
|
+
label: 'Address',
|
|
203
|
+
required: false,
|
|
204
|
+
readOnly: false,
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
},
|
|
208
|
+
Email: {
|
|
209
|
+
orderFormFields: [
|
|
210
|
+
{
|
|
211
|
+
name: OrderModuleFiledNameEnum.address,
|
|
212
|
+
label: 'Address',
|
|
213
|
+
required: false,
|
|
214
|
+
readOnly: false,
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
},
|
|
218
|
+
EHF: {
|
|
219
|
+
orderFormFields: [
|
|
220
|
+
{
|
|
221
|
+
name: OrderModuleFiledNameEnum.address,
|
|
222
|
+
label: 'Address',
|
|
223
|
+
required: false,
|
|
224
|
+
readOnly: false,
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
},
|
|
228
|
+
OIO: {
|
|
229
|
+
orderFormFields: [
|
|
230
|
+
{
|
|
231
|
+
name: OrderModuleFiledNameEnum.address,
|
|
232
|
+
label: 'Address',
|
|
233
|
+
required: false,
|
|
234
|
+
readOnly: false,
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
invoiceAddressSelection: {
|
|
240
|
+
enabled: true,
|
|
241
|
+
label: 'Invoice Address',
|
|
242
|
+
fields: [
|
|
243
|
+
{
|
|
244
|
+
name: OrderModuleFiledNameEnum.invoiceAddress,
|
|
245
|
+
label: 'Address',
|
|
246
|
+
required: false,
|
|
247
|
+
readOnly: false,
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
},
|
|
251
|
+
settings: {
|
|
252
|
+
submitButtonText: 'Continue',
|
|
253
|
+
backButtonText: 'Back',
|
|
254
|
+
verifyButtonText: 'Verify',
|
|
255
|
+
organizationNumberLabel: 'CVR',
|
|
256
|
+
glnLabel: 'GLN/EAN',
|
|
257
|
+
paymentMethodLabel: 'Select Payment Method',
|
|
258
|
+
errorReqMsg: 'This field is required!',
|
|
259
|
+
errorInvalidEmailMsg: 'Invalid email address!',
|
|
260
|
+
errorInvalidPhoneMsg: 'Invalid phone number!',
|
|
261
|
+
successText: 'Success message',
|
|
262
|
+
failureText: 'Failed message',
|
|
263
|
+
orderDefaultValues: {
|
|
264
|
+
name,
|
|
265
|
+
email: userEmail || '',
|
|
266
|
+
phoneNumber: '',
|
|
267
|
+
city,
|
|
268
|
+
country,
|
|
269
|
+
zip: postalCode,
|
|
270
|
+
address: streetAddress,
|
|
271
|
+
paymentMethod: undefined,
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
return config as ConfigType;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
import { FC, useEffect, useRef } from 'react';
|
|
281
|
+
import { orderComponent } from '@infosoftas/s4-orders-js-sdk/src/index';
|
|
282
|
+
|
|
283
|
+
import { prepareConfig } from 'Utils/moduleConfig';
|
|
284
|
+
|
|
285
|
+
const ORDER_PLACE_ID = 'sdk-order';
|
|
286
|
+
|
|
287
|
+
const OrderPlace: FC = ({userEmail, userId, name, city, country, postalCode, streetAddress}) => {
|
|
288
|
+
const moduleMount = useRef(false);
|
|
289
|
+
|
|
290
|
+
useEffect(() => {
|
|
291
|
+
if (!moduleMount.current && idTokenClaims) {
|
|
292
|
+
moduleMount.current = true;
|
|
293
|
+
const config = prepareConfig({
|
|
294
|
+
apiKey: process.env.API_KEY || '',
|
|
295
|
+
apiUrl: process.env.ORDER_SDK_API_URL || '',
|
|
296
|
+
userId: userId || '',
|
|
297
|
+
subscriberId: userEmail || '',
|
|
298
|
+
identityProviderId: process.env.IDENTITY_PROVIDER_ID || '',
|
|
299
|
+
templatePackageId: process.env.TEMPLATE_PACKAGE_ID || '',
|
|
300
|
+
selfServiceUrl: process.env.SELF_SERVICE_URL || '',
|
|
301
|
+
organizationId: process.env.ORGANIZATION_ID || '',
|
|
302
|
+
userEmail: userEmail || '',
|
|
303
|
+
name: name,
|
|
304
|
+
city: city,
|
|
305
|
+
country: country,
|
|
306
|
+
postalCode: postalCode,
|
|
307
|
+
streetAddress: streetAddress,
|
|
308
|
+
});
|
|
309
|
+
orderComponent?.remove();
|
|
310
|
+
orderComponent?.init(config);
|
|
311
|
+
}
|
|
312
|
+
}, [userEmail, userId, name, city, country, postalCode, streetAddress]);
|
|
313
|
+
|
|
314
|
+
return (
|
|
315
|
+
<div
|
|
316
|
+
id={ORDER_PLACE_ID}
|
|
317
|
+
className="w-100 order-wrapper"
|
|
318
|
+
data-testid="order-place-id"
|
|
319
|
+
/>
|
|
320
|
+
);
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
export default OrderPlace;
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
<!-- prettier-ignore -->
|
|
327
|
+
| Option | Default | Description |
|
|
328
|
+
| --------------------- | :----------------------------------------------------------------------------: | -------------------------: |
|
|
329
|
+
| moduleTitle | '' | module title |
|
|
330
|
+
| apiKey | '' | order api key |
|
|
331
|
+
| apiUrl | '' | order api url |
|
|
332
|
+
| templatePackageId | '' | template package id |
|
|
333
|
+
| subscriberId | '' | subscriber id |
|
|
334
|
+
| identityProviderId | '' | identity provider id |
|
|
335
|
+
| organizationId | '' | organization id |
|
|
336
|
+
| redirectUrl | window.location.href | redirect url |
|
|
337
|
+
| showIframe | false | show credit card in iframe |
|
|
338
|
+
| paymentMethodsOptions | orderFormFields: [{name: 'phone, required: false, readOnly: false, label: ''}] | default form fields |
|
|
339
|
+
| availablePaymentMethods | [] | available payment methods |
|
|
340
|
+
| language | 'en-US' | language |
|
|
341
|
+
| merchantAgreementUrl | '' | vipps and MobilePay property |
|
|
342
|
+
| settings | {successText: 'Order successful completed!',failureText: 'Something went wrong!',submitButtonText: 'Start',backButtonText: 'Back',verifyButtonText: 'Verify',organizationNumberLabel: 'CVR',glnLabel: 'GLN',paymentMethodLabel:'Select Payment Method',} | label and text properties |
|
package/package.json
CHANGED
|
@@ -1,42 +1,44 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@infosoftas/s4-orders-js-sdk",
|
|
3
|
+
"version": "0.0.1-alpha2c.1",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"build": "rimraf lib && webpack --env mode=production",
|
|
6
|
+
"release": "release-it"
|
|
7
|
+
},
|
|
8
|
+
"eslintConfig": {
|
|
9
|
+
"extends": [
|
|
10
|
+
"react-app"
|
|
11
|
+
]
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"prop-types": "^15.8.1",
|
|
15
|
+
"react": "^18.3.1",
|
|
16
|
+
"react-dom": "^18.3.1",
|
|
17
|
+
"react-hook-form": "^7.53.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@babel/core": "^7.24.3",
|
|
21
|
+
"@babel/preset-env": "^7.18.10",
|
|
22
|
+
"@babel/preset-react": "^7.18.6",
|
|
23
|
+
"@babel/preset-typescript": "^7.24.7",
|
|
24
|
+
"@types/react": "^18.0.17",
|
|
25
|
+
"@types/react-dom": "^18.0.6",
|
|
26
|
+
"babel-loader": "^8.3.0",
|
|
27
|
+
"copy-webpack-plugin": "^12.0.2",
|
|
28
|
+
"css-loader": "^7.1.2",
|
|
29
|
+
"dotenv-webpack": "^8.1.0",
|
|
30
|
+
"mini-css-extract-plugin": "^2.9.1",
|
|
31
|
+
"release-it": "^17.10.0",
|
|
32
|
+
"rimraf": "^6.0.1",
|
|
33
|
+
"sass": "^1.79.2",
|
|
34
|
+
"sass-loader": "^16.0.1",
|
|
35
|
+
"style-loader": "^4.0.0",
|
|
36
|
+
"ts-loader": "^9.5.1",
|
|
37
|
+
"typescript": "^5.6.2",
|
|
38
|
+
"webpack": "^5.95.0",
|
|
39
|
+
"webpack-cli": "^5.1.4"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -106,14 +106,14 @@ const EHFForm: FC<Props> = ({
|
|
|
106
106
|
label={organizationNumberLabel}
|
|
107
107
|
required={!gln}
|
|
108
108
|
readOnly={false}
|
|
109
|
-
errors={errors}
|
|
109
|
+
errors={!gln ? errors : undefined}
|
|
110
110
|
/>
|
|
111
111
|
<InputField
|
|
112
112
|
name="gln"
|
|
113
113
|
label={glnLabel}
|
|
114
114
|
required={!cvr}
|
|
115
115
|
readOnly={false}
|
|
116
|
-
errors={errors}
|
|
116
|
+
errors={!cvr ? errors : undefined}
|
|
117
117
|
/>
|
|
118
118
|
<div className="d-flex justify-center flex-wrap gap-2">
|
|
119
119
|
<Button
|