@infosoftas/s4-orders-js-sdk 0.1.9 → 0.1.10
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 +1 -0
- package/package.json +2 -2
- package/src/App.tsx +7 -2
- package/src/api/OrdersApi.ts +8 -3
- package/src/api/SubscribeApi.ts +0 -23
- package/src/components/OrderForm/OrderForm.tsx +7 -1
- package/src/hooks/useOrderForm.tsx +3 -13
- package/src/index.tsx +1 -2
- package/src/types/api.ts +2 -0
package/README.md
CHANGED
|
@@ -75,6 +75,7 @@ type ConfigType = {
|
|
|
75
75
|
moduleTitle?: string;
|
|
76
76
|
submitStartCallback?: (subscriberId: string) => void;
|
|
77
77
|
userActionCallback?: (action: UserActionEnum, args: object | null | undefined) => void;
|
|
78
|
+
setContactCallback?: (contactInfo: contactRequestType) => void;
|
|
78
79
|
apiKey: string;
|
|
79
80
|
apiUrl: string;
|
|
80
81
|
templatePackageId: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infosoftas/s4-orders-js-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "rimraf lib && webpack --mode production",
|
|
6
6
|
"release": "release-it"
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"style-loader": "^4.0.0",
|
|
35
35
|
"ts-loader": "^9.5.4",
|
|
36
36
|
"typescript": "^5.9.3",
|
|
37
|
-
"webpack": "^5.
|
|
37
|
+
"webpack": "^5.105.2",
|
|
38
38
|
"webpack-cli": "^6.0.1"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
package/src/App.tsx
CHANGED
|
@@ -110,8 +110,13 @@ const App: FC<ConfigType> = ({
|
|
|
110
110
|
try {
|
|
111
111
|
// There is no way to detect the difference between "cancelled" and "accepted" payment for Vipps via UI
|
|
112
112
|
// Completing an order for cancelled payment is fine. The backend handles it correctly.
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
await orderComplete(orderId || data.orderId || '',
|
|
114
|
+
userId && identityProviderId
|
|
115
|
+
? {
|
|
116
|
+
userId,
|
|
117
|
+
identityProviderId,
|
|
118
|
+
}
|
|
119
|
+
: undefined);
|
|
115
120
|
setIsConfirmed(true);
|
|
116
121
|
setLoading(false);
|
|
117
122
|
if (window === top) {
|
package/src/api/OrdersApi.ts
CHANGED
|
@@ -13,6 +13,11 @@ type RequestOrderStartType = {
|
|
|
13
13
|
orderReference?: string;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
type OrderCompleteRequestType = {
|
|
17
|
+
userId: string;
|
|
18
|
+
identityProviderId: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
16
21
|
type OrderResponseType = {
|
|
17
22
|
terminalRedirectUrl: string;
|
|
18
23
|
id: string;
|
|
@@ -31,15 +36,15 @@ export const orderStart = (
|
|
|
31
36
|
body,
|
|
32
37
|
}) as Promise<OrderResponseType>;
|
|
33
38
|
|
|
34
|
-
export const orderComplete = (id: string): Promise<OrderResponseType> =>
|
|
35
|
-
fetcher<OrderResponseType, null>({
|
|
39
|
+
export const orderComplete = (id: string, body?: OrderCompleteRequestType): Promise<OrderResponseType> =>
|
|
40
|
+
fetcher<OrderResponseType, OrderCompleteRequestType | null>({
|
|
36
41
|
method: 'POST',
|
|
37
42
|
url: `/order/${id}/complete`,
|
|
38
43
|
headers: {
|
|
39
44
|
'S4-ORDERS-API-KEY':
|
|
40
45
|
sessionStorage.getItem('sdk_api_key') || '',
|
|
41
46
|
},
|
|
42
|
-
body: null,
|
|
47
|
+
body: body || null,
|
|
43
48
|
}) as Promise<OrderResponseType>;
|
|
44
49
|
|
|
45
50
|
export const orderDelete = (id: string): Promise<OrderResponseType> =>
|
package/src/api/SubscribeApi.ts
CHANGED
|
@@ -5,15 +5,6 @@ type CreateSubscriberResponseType = {
|
|
|
5
5
|
id: string;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
type MapSubscriberToUserRequestType = {
|
|
9
|
-
identityProviderId: string;
|
|
10
|
-
userId: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
type MapSubscriberToUserResponseType = {
|
|
14
|
-
id: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
8
|
export const createSubscriber = (
|
|
18
9
|
body: CreateSubscriberRequestType
|
|
19
10
|
): Promise<CreateSubscriberResponseType> =>
|
|
@@ -26,17 +17,3 @@ export const createSubscriber = (
|
|
|
26
17
|
},
|
|
27
18
|
body,
|
|
28
19
|
}) as Promise<CreateSubscriberResponseType>;
|
|
29
|
-
|
|
30
|
-
export const mapSubscriberToUser = (
|
|
31
|
-
id: string,
|
|
32
|
-
body: MapSubscriberToUserRequestType
|
|
33
|
-
): Promise<MapSubscriberToUserResponseType> =>
|
|
34
|
-
fetcher<MapSubscriberToUserResponseType, MapSubscriberToUserRequestType>({
|
|
35
|
-
method: 'POST',
|
|
36
|
-
url: `/subscriber/${id}/user`,
|
|
37
|
-
headers: {
|
|
38
|
-
'S4-ORDERS-API-KEY':
|
|
39
|
-
sessionStorage.getItem('sdk_api_key') || '',
|
|
40
|
-
},
|
|
41
|
-
body,
|
|
42
|
-
}) as Promise<MapSubscriberToUserResponseType>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FC, ChangeEvent, Suspense, useState, useMemo } from 'react';
|
|
1
|
+
import { FC, ChangeEvent, Suspense, useState, useMemo, useEffect } from 'react';
|
|
2
2
|
import { FormProvider, useForm, SubmitHandler } from 'react-hook-form';
|
|
3
3
|
|
|
4
4
|
import { PaymentMethodEnum, UserActionEnum } from '../../enums/general';
|
|
@@ -148,6 +148,12 @@ const OrderForm: FC<Props> = ({
|
|
|
148
148
|
formState: { errors },
|
|
149
149
|
} = methods;
|
|
150
150
|
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
userActionCallback?.(UserActionEnum.SELECT_PAYMENT_METHOD, {
|
|
153
|
+
paymentMethod: methods.getValues('paymentMethod'),
|
|
154
|
+
});
|
|
155
|
+
}, []);
|
|
156
|
+
|
|
151
157
|
const invoiceAddressToggle = watch('invoiceAddressSelection');
|
|
152
158
|
const paymentMethodInput = watch('paymentMethod');
|
|
153
159
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import { SubmitHandler } from 'react-hook-form';
|
|
3
3
|
|
|
4
|
-
import { createSubscriber
|
|
4
|
+
import { createSubscriber } from '../api/SubscribeApi';
|
|
5
5
|
import { orderStart } from '../api/OrdersApi';
|
|
6
6
|
import { invoiceLookup } from '../api/InvoiceApi';
|
|
7
7
|
import { InvoiceLookupNetworkEnum, PaymentMethodEnum, UserActionEnum } from '../enums/general';
|
|
@@ -130,22 +130,12 @@ const useOrderForm = ({
|
|
|
130
130
|
data.paymentMethod === PaymentMethodEnum.OIO
|
|
131
131
|
? data?.cvr
|
|
132
132
|
: data.organizationNumber || undefined,
|
|
133
|
+
...(userId &&
|
|
134
|
+
identityProviderId && { userId, identityProviderId }),
|
|
133
135
|
});
|
|
134
136
|
id = response.id;
|
|
135
137
|
|
|
136
138
|
sessionStorage.setItem('subscriberId', id); // For avoiding attempt of creating subscriber again
|
|
137
|
-
|
|
138
|
-
if (userId && identityProviderId) {
|
|
139
|
-
const mapResponse = await mapSubscriberToUser(id, {
|
|
140
|
-
userId: userId,
|
|
141
|
-
identityProviderId: identityProviderId,
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
if (!mapResponse.id) {
|
|
145
|
-
setErrorsMsg([WRONG_MSG]);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
139
|
}
|
|
150
140
|
|
|
151
141
|
if (setContactCallback) {
|
package/src/index.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { createRoot, Root } from 'react-dom/client';
|
|
|
2
2
|
import { createElement } from 'react';
|
|
3
3
|
|
|
4
4
|
import { ConfigType } from './types/general';
|
|
5
|
-
import { createSubscriber
|
|
5
|
+
import { createSubscriber } from './api/SubscribeApi';
|
|
6
6
|
import App from './App';
|
|
7
7
|
|
|
8
8
|
export const orderComponent = {
|
|
@@ -28,5 +28,4 @@ export const orderComponent = {
|
|
|
28
28
|
(orderComponent.root as Root)?.unmount();
|
|
29
29
|
},
|
|
30
30
|
createSubscriber,
|
|
31
|
-
mapSubscriberToUser,
|
|
32
31
|
};
|