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

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,14 @@ 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!',
261
275
  successText: 'Success message',
262
276
  failureText: 'Failed message',
263
277
  orderDefaultValues: {
@@ -277,15 +291,32 @@ export const prepareConfig = ({
277
291
  };
278
292
 
279
293
 
280
- import { FC, useEffect, useRef } from 'react';
294
+ import { FC, useEffect, useRef, useCallback } from 'react';
295
+ import { useSearchParams } from 'react-router-dom';
281
296
  import { orderComponent } from '@infosoftas/s4-orders-js-sdk/src/index';
282
297
 
283
298
  import { prepareConfig } from 'Utils/moduleConfig';
299
+ import { encodeJwt } from 'Utils/helper';
284
300
 
285
301
  const ORDER_PLACE_ID = 'sdk-order';
286
302
 
287
- const OrderPlace: FC = ({userEmail, userId, name, city, country, postalCode, streetAddress}) => {
303
+ const OrderPlace: FC = ({journey, userEmail, sub, emails, userId, name, city, country, postalCode, streetAddress}) => {
288
304
  const moduleMount = useRef(false);
305
+ const [searchParams, setSearchParams] = useSearchParams();
306
+
307
+ const submitStartCallback = useCallback(
308
+ (subscriberId: string) => {
309
+ const hashTokenValue = {
310
+ extension_SubscriberId: subscriberId,
311
+ emails: emails,
312
+ sub: sub,
313
+ };
314
+
315
+ searchParams?.set('hashToken', encodeJwt(hashTokenValue) as string);
316
+ setSearchParams(searchParams);
317
+ },
318
+ [emails, sub, searchParams, setSearchParams]
319
+ );
289
320
 
290
321
  useEffect(() => {
291
322
  if (!moduleMount.current && idTokenClaims) {
@@ -305,11 +336,13 @@ const OrderPlace: FC = ({userEmail, userId, name, city, country, postalCode, str
305
336
  country: country,
306
337
  postalCode: postalCode,
307
338
  streetAddress: streetAddress,
339
+ journey: journey,
340
+ submitStartCallback: submitStartCallback,
308
341
  });
309
342
  orderComponent?.remove();
310
343
  orderComponent?.init(config);
311
344
  }
312
- }, [userEmail, userId, name, city, country, postalCode, streetAddress]);
345
+ }, [userEmail, userId, name, city, country, postalCode, streetAddress, journey, submitStartCallback]);
313
346
 
314
347
  return (
315
348
  <div
@@ -339,4 +372,4 @@ export default OrderPlace;
339
372
  | availablePaymentMethods | [] | available payment methods |
340
373
  | language | 'en-US' | language |
341
374
  | 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 |
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 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infosoftas/s4-orders-js-sdk",
3
- "version": "0.0.1-beta1.0",
3
+ "version": "0.0.1-beta1.2",
4
4
  "scripts": {
5
5
  "build": "rimraf lib && webpack --env mode=production",
6
6
  "release": "release-it"
package/src/App.tsx CHANGED
@@ -65,6 +65,9 @@ const App: FC<ConfigType> = ({
65
65
  const [showOrderForm, setShowOrderForm] = useState<boolean>(true);
66
66
  const [iframeSrc, setIframeSrc] = useState<string | null>(null);
67
67
  const [orderId, setOrderId] = useState<string | null>(null);
68
+ const [subscriberSdkId, setSubscriberSdkId] = useState<string | undefined>(
69
+ subscriberId || undefined
70
+ );
68
71
  const [isConfirmed, setIsConfirmed] = useState<boolean>(false);
69
72
  const [isFailed, setIsFailed] = useState<boolean>(false);
70
73
  const [failedMsg, setFailedMsg] = useState<string>('');
@@ -271,6 +274,11 @@ const App: FC<ConfigType> = ({
271
274
  });
272
275
  };
273
276
 
277
+ const onSubmitStart = (id: string) => {
278
+ setSubscriberSdkId(id);
279
+ submitStartCallback?.(id);
280
+ };
281
+
274
282
  if (window !== top) {
275
283
  return null;
276
284
  }
@@ -304,7 +312,7 @@ const App: FC<ConfigType> = ({
304
312
  }
305
313
  orderValues={orderFormValues}
306
314
  templatePackageId={templatePackageId}
307
- subscriberId={subscriberId}
315
+ subscriberId={subscriberSdkId}
308
316
  userId={userId}
309
317
  identityProviderId={identityProviderId}
310
318
  organizationId={organizationId}
@@ -332,7 +340,7 @@ const App: FC<ConfigType> = ({
332
340
  }
333
341
  orderValues={orderFormValues}
334
342
  templatePackageId={templatePackageId}
335
- subscriberId={subscriberId}
343
+ subscriberId={subscriberSdkId}
336
344
  userId={userId}
337
345
  identityProviderId={identityProviderId}
338
346
  organizationId={organizationId}
@@ -351,9 +359,9 @@ const App: FC<ConfigType> = ({
351
359
  <OrderForm
352
360
  callback={handleForm}
353
361
  updateFormData={updateFormData}
354
- submitStartCallback={submitStartCallback}
362
+ submitStartCallback={onSubmitStart}
355
363
  templatePackageId={templatePackageId}
356
- subscriberId={subscriberId}
364
+ subscriberId={subscriberSdkId}
357
365
  userId={userId}
358
366
  identityProviderId={identityProviderId}
359
367
  organizationId={organizationId}
@@ -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,
@@ -69,6 +69,21 @@ const useOrderForm = ({
69
69
  setLoading(true);
70
70
  try {
71
71
  let id: string | undefined = subscriberId;
72
+ if (data.paymentMethod === PaymentMethodEnum.OIO) {
73
+ await invoiceLookup({
74
+ network: data.gln
75
+ ? InvoiceLookupNetworkEnum.OIO_GLN
76
+ : InvoiceLookupNetworkEnum.OIO_Danish_CVR,
77
+ value: data.gln || data.cvr || '',
78
+ });
79
+ }
80
+ if (data.paymentMethod === PaymentMethodEnum.EHF) {
81
+ await invoiceLookup({
82
+ network: InvoiceLookupNetworkEnum.EHF,
83
+ value: data.organizationNumber || '',
84
+ });
85
+ }
86
+
72
87
  const contactModel = prepareContactModel({ data, orderFields });
73
88
  if (!subscriberId) {
74
89
  const response = await createSubscriber({
@@ -130,20 +145,7 @@ const useOrderForm = ({
130
145
  : undefined,
131
146
  orderReference: data.orderReference || undefined,
132
147
  });
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
- }
148
+
147
149
  callback(responseOrder.terminalRedirectUrl, {
148
150
  ...(data || {}),
149
151
  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