@infosoftas/s4-orders-js-sdk 0.0.1-beta1.2 → 0.0.1-beta1.4

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
@@ -272,6 +272,7 @@ export const prepareConfig = ({
272
272
  errorInvalidEmailMsg: 'Invalid email address!',
273
273
  errorInvalidPhoneMsg: 'Invalid phone number!',
274
274
  paymentMethodNotAllowedMsg: 'This payment method not allowed!',
275
+ invoiceLookupNotFoundText: 'There was no recipient found for the given information',
275
276
  successText: 'Success message',
276
277
  failureText: 'Failed message',
277
278
  orderDefaultValues: {
@@ -322,14 +323,14 @@ const OrderPlace: FC = ({journey, userEmail, sub, emails, userId, name, city, co
322
323
  if (!moduleMount.current && idTokenClaims) {
323
324
  moduleMount.current = true;
324
325
  const config = prepareConfig({
325
- apiKey: process.env.API_KEY || '',
326
- apiUrl: process.env.ORDER_SDK_API_URL || '',
326
+ apiKey: API_KEY,
327
+ apiUrl: API_URL,
327
328
  userId: userId || '',
328
329
  subscriberId: userEmail || '',
329
- identityProviderId: process.env.IDENTITY_PROVIDER_ID || '',
330
- templatePackageId: process.env.TEMPLATE_PACKAGE_ID || '',
331
- selfServiceUrl: process.env.SELF_SERVICE_URL || '',
332
- organizationId: process.env.ORGANIZATION_ID || '',
330
+ identityProviderId: IDENTITY_PROVIDER_ID,
331
+ templatePackageId: TEMPLATE_PACKAGE_ID,
332
+ selfServiceUrl: SELF_SERVICE_URL,
333
+ organizationId: ORGANIZATION_ID,
333
334
  userEmail: userEmail || '',
334
335
  name: name,
335
336
  city: city,
@@ -372,4 +373,4 @@ export default OrderPlace;
372
373
  | availablePaymentMethods | [] | available payment methods |
373
374
  | language | 'en-US' | language |
374
375
  | merchantAgreementUrl | '' | vipps and MobilePay property |
375
- | settings | {successText: 'Order successful completed!',failureText: 'Something went wrong!',submitButtonText: 'Start',backButtonText: 'Back',verifyButtonText: 'Verify',organizationNumberLabel: 'CVR',glnLabel: 'GLN',paymentMethodLabel:'Select Payment Method', orderDefaultValues: 'Default order form values' } | label and text properties |
376
+ | settings | {successText: 'Order successful completed!',failureText: 'Something went wrong!',submitButtonText: 'Start',backButtonText: 'Back',verifyButtonText: 'Verify',organizationNumberLabel: 'CVR',glnLabel: 'GLN',paymentMethodLabel:'Select Payment Method', orderDefaultValues: 'Default order form values', paymentMethodNotAllowedMsg: 'This payment method not allowed!', invoiceLookupNotFoundText: 'There was no recipient found for the given information' } | label and text properties |
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@infosoftas/s4-orders-js-sdk",
3
- "version": "0.0.1-beta1.2",
3
+ "version": "0.0.1-beta1.4",
4
4
  "scripts": {
5
- "build": "rimraf lib && webpack --env mode=production",
5
+ "build": "rimraf lib && webpack --mode production",
6
6
  "release": "release-it"
7
7
  },
8
8
  "eslintConfig": {
@@ -26,7 +26,6 @@
26
26
  "babel-loader": "^8.3.0",
27
27
  "copy-webpack-plugin": "^12.0.2",
28
28
  "css-loader": "^7.1.2",
29
- "dotenv-webpack": "^8.1.0",
30
29
  "mini-css-extract-plugin": "^2.9.1",
31
30
  "release-it": "^17.10.0",
32
31
  "rimraf": "^6.0.1",
package/src/App.tsx CHANGED
@@ -59,6 +59,8 @@ const App: FC<ConfigType> = ({
59
59
  errorInvalidEmailMsg: '',
60
60
  errorInvalidPhoneMsg: '',
61
61
  paymentMethodNotAllowedMsg: '',
62
+ invoiceLookupNotFoundText:
63
+ 'There was no recipient found for the given information',
62
64
  },
63
65
  }) => {
64
66
  const [loading, setLoading] = useState<boolean>(false);
@@ -324,6 +326,9 @@ const App: FC<ConfigType> = ({
324
326
  invoiceAddressSelection={
325
327
  invoiceAddressSelection
326
328
  }
329
+ invoiceLookupNotFoundText={
330
+ settings?.invoiceLookupNotFoundText
331
+ }
327
332
  />
328
333
  )}
329
334
  {formType === FormTypeEnum.EHF && (
@@ -352,6 +357,9 @@ const App: FC<ConfigType> = ({
352
357
  invoiceAddressSelection={
353
358
  invoiceAddressSelection
354
359
  }
360
+ invoiceLookupNotFoundText={
361
+ settings?.invoiceLookupNotFoundText
362
+ }
355
363
  />
356
364
  )}
357
365
  {formType !== FormTypeEnum.OIO &&
@@ -17,9 +17,7 @@ export const invoiceLookup = (
17
17
  url: '/invoicelookup',
18
18
  headers: {
19
19
  'S4-ORDERS-API-KEY':
20
- sessionStorage.getItem('sdk_api_key') ||
21
- process.env.API_KEY ||
22
- '',
20
+ sessionStorage.getItem('sdk_api_key') || '',
23
21
  },
24
22
  body,
25
23
  }) as Promise<InvoiceLookupResponseType>;
@@ -26,9 +26,7 @@ export const orderStart = (
26
26
  url: '/order',
27
27
  headers: {
28
28
  'S4-ORDERS-API-KEY':
29
- sessionStorage.getItem('sdk_api_key') ||
30
- process.env.API_KEY ||
31
- '',
29
+ sessionStorage.getItem('sdk_api_key') || '',
32
30
  },
33
31
  body,
34
32
  }) as Promise<OrderResponseType>;
@@ -39,9 +37,7 @@ export const orderComplete = (id: string): Promise<OrderResponseType> =>
39
37
  url: `/order/${id}/complete`,
40
38
  headers: {
41
39
  'S4-ORDERS-API-KEY':
42
- sessionStorage.getItem('sdk_api_key') ||
43
- process.env.API_KEY ||
44
- '',
40
+ sessionStorage.getItem('sdk_api_key') || '',
45
41
  },
46
42
  body: null,
47
43
  }) as Promise<OrderResponseType>;
@@ -52,9 +48,7 @@ export const orderDelete = (id: string): Promise<OrderResponseType> =>
52
48
  url: `/order/${id}`,
53
49
  headers: {
54
50
  'S4-ORDERS-API-KEY':
55
- sessionStorage.getItem('sdk_api_key') ||
56
- process.env.API_KEY ||
57
- '',
51
+ sessionStorage.getItem('sdk_api_key') || '',
58
52
  },
59
53
  body: null,
60
54
  }) as Promise<OrderResponseType>;
@@ -22,9 +22,7 @@ export const createSubscriber = (
22
22
  url: '/subscriber',
23
23
  headers: {
24
24
  'S4-ORDERS-API-KEY':
25
- sessionStorage.getItem('sdk_api_key') ||
26
- process.env.API_KEY ||
27
- '',
25
+ sessionStorage.getItem('sdk_api_key') || '',
28
26
  },
29
27
  body,
30
28
  }) as Promise<CreateSubscriberResponseType>;
@@ -38,9 +36,7 @@ export const mapSubscriberToUser = (
38
36
  url: `/subscriber/${id}/user`,
39
37
  headers: {
40
38
  'S4-ORDERS-API-KEY':
41
- sessionStorage.getItem('sdk_api_key') ||
42
- process.env.API_KEY ||
43
- '',
39
+ sessionStorage.getItem('sdk_api_key') || '',
44
40
  },
45
41
  body,
46
42
  }) as Promise<MapSubscriberToUserResponseType>;
@@ -41,6 +41,7 @@ type Props = {
41
41
  fields?: OrderFormFiledType[];
42
42
  paymentMethods?: PaymentMethodEnum[];
43
43
  };
44
+ invoiceLookupNotFoundText?: string;
44
45
  };
45
46
 
46
47
  type EHFFormInputsType = {
@@ -72,6 +73,7 @@ const EHFForm: FC<Props> = ({
72
73
  orderValues,
73
74
  paymentMethodsOptions,
74
75
  invoiceAddressSelection,
76
+ invoiceLookupNotFoundText,
75
77
  }) => {
76
78
  const methods = useForm<EHFFormInputsType>({
77
79
  defaultValues: {
@@ -108,6 +110,7 @@ const EHFForm: FC<Props> = ({
108
110
  templatePackageId,
109
111
  invoiceAddressToggle: orderValues?.invoiceAddressSelection,
110
112
  invoiceOrderFields,
113
+ invoiceLookupNotFoundText,
111
114
  });
112
115
 
113
116
  const onSubmit: SubmitHandler<EHFFormInputsType> = async (
@@ -42,6 +42,7 @@ type Props = {
42
42
  fields?: OrderFormFiledType[];
43
43
  paymentMethods?: PaymentMethodEnum[];
44
44
  };
45
+ invoiceLookupNotFoundText?: string;
45
46
  };
46
47
 
47
48
  type OIOFormInputsType = {
@@ -76,6 +77,7 @@ const EHFForm: FC<Props> = ({
76
77
  orderValues,
77
78
  paymentMethodsOptions,
78
79
  invoiceAddressSelection,
80
+ invoiceLookupNotFoundText,
79
81
  }) => {
80
82
  const methods = useForm<OIOFormInputsType>({
81
83
  defaultValues: {
@@ -116,6 +118,7 @@ const EHFForm: FC<Props> = ({
116
118
  templatePackageId,
117
119
  invoiceAddressToggle: orderValues?.invoiceAddressSelection,
118
120
  invoiceOrderFields,
121
+ invoiceLookupNotFoundText,
119
122
  });
120
123
 
121
124
  const onSubmit: SubmitHandler<OIOFormInputsType> = async (
@@ -1,6 +1,6 @@
1
1
  import { PaymentMethodEnum } from '../enums/general';
2
2
 
3
- export const BASE_API = process.env.API_URL ?? '/';
3
+ export const BASE_API = '/';
4
4
 
5
5
  export const WRONG_MSG = 'Something went wrong!';
6
6
 
@@ -38,6 +38,7 @@ type Props = {
38
38
  orderFields: OrderFormFiledType[];
39
39
  invoiceAddressToggle?: boolean;
40
40
  invoiceOrderFields: OrderFormFiledType[];
41
+ invoiceLookupNotFoundText?: string;
41
42
  };
42
43
 
43
44
  const useOrderForm = ({
@@ -56,6 +57,7 @@ const useOrderForm = ({
56
57
  templatePackageId,
57
58
  invoiceAddressToggle,
58
59
  invoiceOrderFields,
60
+ invoiceLookupNotFoundText,
59
61
  }: Props) => {
60
62
  const [loading, setLoading] = useState<boolean>(false);
61
63
  const [apiErrorMsg, setApiErrorMsg] = useState<string>('');
@@ -69,8 +71,9 @@ const useOrderForm = ({
69
71
  setLoading(true);
70
72
  try {
71
73
  let id: string | undefined = subscriberId;
74
+ let invoiceResponse = null;
72
75
  if (data.paymentMethod === PaymentMethodEnum.OIO) {
73
- await invoiceLookup({
76
+ invoiceResponse = await invoiceLookup({
74
77
  network: data.gln
75
78
  ? InvoiceLookupNetworkEnum.OIO_GLN
76
79
  : InvoiceLookupNetworkEnum.OIO_Danish_CVR,
@@ -78,12 +81,22 @@ const useOrderForm = ({
78
81
  });
79
82
  }
80
83
  if (data.paymentMethod === PaymentMethodEnum.EHF) {
81
- await invoiceLookup({
84
+ invoiceResponse = await invoiceLookup({
82
85
  network: InvoiceLookupNetworkEnum.EHF,
83
86
  value: data.organizationNumber || '',
84
87
  });
85
88
  }
86
89
 
90
+ if (invoiceResponse && !invoiceResponse?.recievesInvoice) {
91
+ setLoading(false);
92
+ const value =
93
+ data.paymentMethod === PaymentMethodEnum.OIO
94
+ ? data.gln || data.cvr || ''
95
+ : data.organizationNumber || '';
96
+ setApiErrorMsg(`${invoiceLookupNotFoundText || ''} (${value})`);
97
+ return;
98
+ }
99
+
87
100
  const contactModel = prepareContactModel({ data, orderFields });
88
101
  if (!subscriberId) {
89
102
  const response = await createSubscriber({
@@ -61,6 +61,7 @@ export type ConfigType = {
61
61
  errorInvalidEmailMsg?: string;
62
62
  errorInvalidPhoneMsg?: string;
63
63
  paymentMethodNotAllowedMsg?: string;
64
+ invoiceLookupNotFoundText?: string;
64
65
  };
65
66
  };
66
67
 
@@ -14,6 +14,17 @@ type AgreementModelType = {
14
14
  accountId?: string;
15
15
  };
16
16
 
17
+ const mapToSwedbankLanguage = (language: string) => {
18
+ const allowedLanguages = [ 'en-US', 'sv-SE', 'nb-NO', 'da-DK', 'fi-FI', 'en-GB', 'nn-NO', 'no-NO', 'se-NO' ];
19
+ if (allowedLanguages.includes(language)) {
20
+ return language;
21
+ }
22
+
23
+ console.warn(`Language ${language} not supported.`);
24
+
25
+ return 'en-US'; // Default value for 'Swedbank'
26
+ };
27
+
17
28
  export const prepareAgreementModel = ({
18
29
  paymentMethod,
19
30
  redirectUrl,
@@ -57,7 +68,7 @@ export const prepareAgreementModel = ({
57
68
  model.swedbankPay = {
58
69
  cancelUrl: `${cancelUrl}`,
59
70
  completeUrl: `${confirmUrl}`,
60
- language,
71
+ language: mapToSwedbankLanguage(language),
61
72
  accountId,
62
73
  };
63
74