@infosoftas/s4-orders-js-sdk 0.0.1-beta1.1 → 0.0.1-beta1.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 CHANGED
@@ -49,6 +49,7 @@ type PaymentMethodOptionsType = {
49
49
  generateSubscriberContact?: boolean;
50
50
  accountId?: string;
51
51
  orderFormFields?: OrderFormFiledType[] | never[];
52
+ paymentInvoiceFields?: OrderFormFiledType[] | never[] | null;
52
53
  };
53
54
  }
54
55
 
@@ -66,6 +67,7 @@ type OrderFormInputsType = {
66
67
  type ConfigType = {
67
68
  domElementId: string;
68
69
  moduleTitle?: string;
70
+ submitStartCallback?: (subscriberId: string) => void;
69
71
  apiKey: string;
70
72
  apiUrl: string;
71
73
  templatePackageId: string;
@@ -130,6 +132,7 @@ enum OrderModuleFiledNameEnum {
130
132
  }
131
133
 
132
134
  export const prepareConfig = ({
135
+ submitStartCallback,
133
136
  apiKey,
134
137
  apiUrl,
135
138
  userId,
@@ -147,6 +150,7 @@ export const prepareConfig = ({
147
150
  }: Props) => {
148
151
 
149
152
  const config = {
153
+ submitStartCallback,
150
154
  moduleTitle: '',
151
155
  domElementId: ORDER_PLACE_ID,
152
156
  redirectUrl: window.location.href,
@@ -214,6 +218,14 @@ export const prepareConfig = ({
214
218
  readOnly: false,
215
219
  },
216
220
  ],
221
+ paymentInvoiceFields: [
222
+ {
223
+ name: OrderModuleFiledNameEnum.invoiceEmail,
224
+ label: 'Email',
225
+ required: true,
226
+ readOnly: false,
227
+ },
228
+ ],
217
229
  },
218
230
  EHF: {
219
231
  orderFormFields: [
@@ -252,12 +264,15 @@ export const prepareConfig = ({
252
264
  submitButtonText: 'Continue',
253
265
  backButtonText: 'Back',
254
266
  verifyButtonText: 'Verify',
255
- organizationNumberLabel: 'CVR',
267
+ organizationNumberLabel: 'Organization Number',
256
268
  glnLabel: 'GLN/EAN',
269
+ cvrLabel: 'CVR',
257
270
  paymentMethodLabel: 'Select Payment Method',
258
271
  errorReqMsg: 'This field is required!',
259
272
  errorInvalidEmailMsg: 'Invalid email address!',
260
273
  errorInvalidPhoneMsg: 'Invalid phone number!',
274
+ paymentMethodNotAllowedMsg: 'This payment method not allowed!',
275
+ invoiceLookupNotFoundText: 'There was no recipient found for the given information',
261
276
  successText: 'Success message',
262
277
  failureText: 'Failed message',
263
278
  orderDefaultValues: {
@@ -277,15 +292,32 @@ export const prepareConfig = ({
277
292
  };
278
293
 
279
294
 
280
- import { FC, useEffect, useRef } from 'react';
295
+ import { FC, useEffect, useRef, useCallback } from 'react';
296
+ import { useSearchParams } from 'react-router-dom';
281
297
  import { orderComponent } from '@infosoftas/s4-orders-js-sdk/src/index';
282
298
 
283
299
  import { prepareConfig } from 'Utils/moduleConfig';
300
+ import { encodeJwt } from 'Utils/helper';
284
301
 
285
302
  const ORDER_PLACE_ID = 'sdk-order';
286
303
 
287
- const OrderPlace: FC = ({userEmail, userId, name, city, country, postalCode, streetAddress}) => {
304
+ const OrderPlace: FC = ({journey, userEmail, sub, emails, userId, name, city, country, postalCode, streetAddress}) => {
288
305
  const moduleMount = useRef(false);
306
+ const [searchParams, setSearchParams] = useSearchParams();
307
+
308
+ const submitStartCallback = useCallback(
309
+ (subscriberId: string) => {
310
+ const hashTokenValue = {
311
+ extension_SubscriberId: subscriberId,
312
+ emails: emails,
313
+ sub: sub,
314
+ };
315
+
316
+ searchParams?.set('hashToken', encodeJwt(hashTokenValue) as string);
317
+ setSearchParams(searchParams);
318
+ },
319
+ [emails, sub, searchParams, setSearchParams]
320
+ );
289
321
 
290
322
  useEffect(() => {
291
323
  if (!moduleMount.current && idTokenClaims) {
@@ -305,11 +337,13 @@ const OrderPlace: FC = ({userEmail, userId, name, city, country, postalCode, str
305
337
  country: country,
306
338
  postalCode: postalCode,
307
339
  streetAddress: streetAddress,
340
+ journey: journey,
341
+ submitStartCallback: submitStartCallback,
308
342
  });
309
343
  orderComponent?.remove();
310
344
  orderComponent?.init(config);
311
345
  }
312
- }, [userEmail, userId, name, city, country, postalCode, streetAddress]);
346
+ }, [userEmail, userId, name, city, country, postalCode, streetAddress, journey, submitStartCallback]);
313
347
 
314
348
  return (
315
349
  <div
@@ -339,4 +373,4 @@ export default OrderPlace;
339
373
  | availablePaymentMethods | [] | available payment methods |
340
374
  | language | 'en-US' | language |
341
375
  | 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 |
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@infosoftas/s4-orders-js-sdk",
3
- "version": "0.0.1-beta1.1",
3
+ "version": "0.0.1-beta1.3",
4
4
  "scripts": {
5
5
  "build": "rimraf lib && webpack --env mode=production",
6
6
  "release": "release-it"
package/src/App.tsx CHANGED
@@ -59,12 +59,17 @@ 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);
65
67
  const [showOrderForm, setShowOrderForm] = useState<boolean>(true);
66
68
  const [iframeSrc, setIframeSrc] = useState<string | null>(null);
67
69
  const [orderId, setOrderId] = useState<string | null>(null);
70
+ const [subscriberSdkId, setSubscriberSdkId] = useState<string | undefined>(
71
+ subscriberId || undefined
72
+ );
68
73
  const [isConfirmed, setIsConfirmed] = useState<boolean>(false);
69
74
  const [isFailed, setIsFailed] = useState<boolean>(false);
70
75
  const [failedMsg, setFailedMsg] = useState<string>('');
@@ -271,6 +276,11 @@ const App: FC<ConfigType> = ({
271
276
  });
272
277
  };
273
278
 
279
+ const onSubmitStart = (id: string) => {
280
+ setSubscriberSdkId(id);
281
+ submitStartCallback?.(id);
282
+ };
283
+
274
284
  if (window !== top) {
275
285
  return null;
276
286
  }
@@ -304,7 +314,7 @@ const App: FC<ConfigType> = ({
304
314
  }
305
315
  orderValues={orderFormValues}
306
316
  templatePackageId={templatePackageId}
307
- subscriberId={subscriberId}
317
+ subscriberId={subscriberSdkId}
308
318
  userId={userId}
309
319
  identityProviderId={identityProviderId}
310
320
  organizationId={organizationId}
@@ -316,6 +326,9 @@ const App: FC<ConfigType> = ({
316
326
  invoiceAddressSelection={
317
327
  invoiceAddressSelection
318
328
  }
329
+ invoiceLookupNotFoundText={
330
+ settings?.invoiceLookupNotFoundText
331
+ }
319
332
  />
320
333
  )}
321
334
  {formType === FormTypeEnum.EHF && (
@@ -332,7 +345,7 @@ const App: FC<ConfigType> = ({
332
345
  }
333
346
  orderValues={orderFormValues}
334
347
  templatePackageId={templatePackageId}
335
- subscriberId={subscriberId}
348
+ subscriberId={subscriberSdkId}
336
349
  userId={userId}
337
350
  identityProviderId={identityProviderId}
338
351
  organizationId={organizationId}
@@ -344,6 +357,9 @@ const App: FC<ConfigType> = ({
344
357
  invoiceAddressSelection={
345
358
  invoiceAddressSelection
346
359
  }
360
+ invoiceLookupNotFoundText={
361
+ settings?.invoiceLookupNotFoundText
362
+ }
347
363
  />
348
364
  )}
349
365
  {formType !== FormTypeEnum.OIO &&
@@ -351,9 +367,9 @@ const App: FC<ConfigType> = ({
351
367
  <OrderForm
352
368
  callback={handleForm}
353
369
  updateFormData={updateFormData}
354
- submitStartCallback={submitStartCallback}
370
+ submitStartCallback={onSubmitStart}
355
371
  templatePackageId={templatePackageId}
356
- subscriberId={subscriberId}
372
+ subscriberId={subscriberSdkId}
357
373
  userId={userId}
358
374
  identityProviderId={identityProviderId}
359
375
  organizationId={organizationId}
@@ -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 (
@@ -104,12 +104,6 @@ const OrderForm: FC<Props> = ({
104
104
  defaultValues?.paymentMethod || PAYMENT_METHOD_DEFAULT,
105
105
  },
106
106
  });
107
- const invoiceOrderFields =
108
- invoiceAddressSelection?.fields || orderInvoiceContactFields;
109
-
110
- const invoicePaymentMethods =
111
- invoiceAddressSelection?.paymentMethods ||
112
- INVOICE_ALLOWED_PAYMENT_METHODS;
113
107
 
114
108
  const {
115
109
  register,
@@ -122,6 +116,16 @@ const OrderForm: FC<Props> = ({
122
116
  const invoiceAddressToggle = watch('invoiceAddressSelection');
123
117
  const paymentMethodInput = watch('paymentMethod');
124
118
 
119
+ const invoiceOrderFields =
120
+ paymentMethodsOptions?.[paymentMethodInput || PAYMENT_METHOD_DEFAULT]
121
+ ?.paymentInvoiceFields ||
122
+ invoiceAddressSelection?.fields ||
123
+ orderInvoiceContactFields;
124
+
125
+ const invoicePaymentMethods =
126
+ invoiceAddressSelection?.paymentMethods ||
127
+ INVOICE_ALLOWED_PAYMENT_METHODS;
128
+
125
129
  const { orderSubmit, loading, apiErrorMsg, errorsMsg } = useOrderForm({
126
130
  callback,
127
131
  submitStartCallback,
@@ -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,6 +71,32 @@ const useOrderForm = ({
69
71
  setLoading(true);
70
72
  try {
71
73
  let id: string | undefined = subscriberId;
74
+ let invoiceResponse = null;
75
+ if (data.paymentMethod === PaymentMethodEnum.OIO) {
76
+ invoiceResponse = await invoiceLookup({
77
+ network: data.gln
78
+ ? InvoiceLookupNetworkEnum.OIO_GLN
79
+ : InvoiceLookupNetworkEnum.OIO_Danish_CVR,
80
+ value: data.gln || data.cvr || '',
81
+ });
82
+ }
83
+ if (data.paymentMethod === PaymentMethodEnum.EHF) {
84
+ invoiceResponse = await invoiceLookup({
85
+ network: InvoiceLookupNetworkEnum.EHF,
86
+ value: data.organizationNumber || '',
87
+ });
88
+ }
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
+
72
100
  const contactModel = prepareContactModel({ data, orderFields });
73
101
  if (!subscriberId) {
74
102
  const response = await createSubscriber({
@@ -130,20 +158,7 @@ const useOrderForm = ({
130
158
  : undefined,
131
159
  orderReference: data.orderReference || undefined,
132
160
  });
133
- if (data.paymentMethod === PaymentMethodEnum.OIO) {
134
- await invoiceLookup({
135
- network: data.gln
136
- ? InvoiceLookupNetworkEnum.OIO_GLN
137
- : InvoiceLookupNetworkEnum.OIO_Danish_CVR,
138
- value: data.gln || data.cvr || '',
139
- });
140
- }
141
- if (data.paymentMethod === PaymentMethodEnum.EHF) {
142
- await invoiceLookup({
143
- network: InvoiceLookupNetworkEnum.EHF,
144
- value: data.organizationNumber || '',
145
- });
146
- }
161
+
147
162
  callback(responseOrder.terminalRedirectUrl, {
148
163
  ...(data || {}),
149
164
  orderId: responseOrder.id,
@@ -19,6 +19,7 @@ export type PaymentMethodOptionsType = {
19
19
  generateSubscriberContact?: boolean;
20
20
  accountId?: string;
21
21
  orderFormFields: OrderFormFiledType[];
22
+ paymentInvoiceFields?: OrderFormFiledType[] | never[] | null;
22
23
  };
23
24
  };
24
25
 
@@ -60,6 +61,7 @@ export type ConfigType = {
60
61
  errorInvalidEmailMsg?: string;
61
62
  errorInvalidPhoneMsg?: string;
62
63
  paymentMethodNotAllowedMsg?: string;
64
+ invoiceLookupNotFoundText?: string;
63
65
  };
64
66
  };
65
67