@infosoftas/s4-orders-js-sdk 0.0.1-alpha1e → 0.0.1-alpha2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infosoftas/s4-orders-js-sdk",
3
- "version": "0.0.1-alpha1e",
3
+ "version": "0.0.1-alpha2",
4
4
  "scripts": {
5
5
  "build": "rimraf lib && webpack --env mode=production"
6
6
  },
package/src/App.tsx CHANGED
@@ -186,7 +186,23 @@ const App: FC<ConfigType> = ({
186
186
  top?.location?.origin || '*'
187
187
  );
188
188
  }
189
- if (url) {
189
+ if (
190
+ data?.paymentMethod === PaymentMethodEnum.Email ||
191
+ data?.paymentMethod === PaymentMethodEnum.Invoice
192
+ ) {
193
+ if (window === top) {
194
+ setIsConfirmed(true);
195
+ setLoading(false);
196
+ top.postMessage(
197
+ {
198
+ type: MessageEventTypeEnum.ORDER_FLOW_COMPLETE,
199
+ isCompleted: true,
200
+ orderInfo: data || null,
201
+ },
202
+ top?.location?.origin || '*'
203
+ );
204
+ }
205
+ } else if (url) {
190
206
  if (
191
207
  showIframe &&
192
208
  data?.paymentMethod === PaymentMethodEnum.SwedbankPay
@@ -1,3 +1,4 @@
1
+ import { CreateSubscriberRequestType } from '../types/api';
1
2
  import { AgreementsType } from '../types/order';
2
3
  import fetcher from '../utils/fetcher';
3
4
 
@@ -8,6 +9,7 @@ type RequestOrderStartType = {
8
9
  templateSubscriptionPlanId?: string;
9
10
  };
10
11
  paymentAgreement: AgreementsType;
12
+ invoiceContact?: CreateSubscriberRequestType;
11
13
  };
12
14
 
13
15
  type OrderResponseType = {
@@ -1,14 +1,5 @@
1
1
  import fetcher from '../utils/fetcher';
2
-
3
- type CreateSubscriberRequestType = {
4
- name?: string;
5
- email?: string;
6
- phone?: string;
7
- country?: string;
8
- city?: string;
9
- addressLines?: string[];
10
- zip?: string;
11
- };
2
+ import { CreateSubscriberRequestType } from '../types/api';
12
3
 
13
4
  type CreateSubscriberResponseType = {
14
5
  id: string;
@@ -8,6 +8,10 @@ export const FIELD_TYPES = {
8
8
  CITY: 'city',
9
9
  ADDRESS: 'address',
10
10
  ZIP: 'zip',
11
+ CARE_OF: 'careOf',
12
+ ORGANIZATION_NUMBER: 'organizationNumber',
13
+ BUYER_REFERENCE: 'buyerReference',
14
+ ORDER_REFERENCE: 'orderReference',
11
15
  };
12
16
 
13
17
  export const DEFAULT_ORDER_FORM_FIELDS: OrderFormFiledType[] = [
@@ -14,6 +14,10 @@ const formFieldsMapper = {
14
14
  [FIELD_TYPES.COUNTRY]: InputField,
15
15
  [FIELD_TYPES.CITY]: InputField,
16
16
  [FIELD_TYPES.ZIP]: InputField,
17
+ [FIELD_TYPES.CARE_OF]: InputField,
18
+ [FIELD_TYPES.ORGANIZATION_NUMBER]: InputField,
19
+ [FIELD_TYPES.BUYER_REFERENCE]: InputField,
20
+ [FIELD_TYPES.ORDER_REFERENCE]: InputField,
17
21
  };
18
22
 
19
23
  export default formFieldsMapper;
@@ -15,7 +15,10 @@ import {
15
15
  OrderFormFiledType,
16
16
  ErrorsMsg,
17
17
  } from '../../types/general';
18
- import { prepareAgreementModel } from '../../utils/order.helper';
18
+ import {
19
+ prepareAgreementModel,
20
+ prepareContactModel,
21
+ } from '../../utils/order.helper';
19
22
  import {
20
23
  prepareErrorMessage,
21
24
  prepareErrorsArrayMessage,
@@ -79,14 +82,17 @@ const OrderForm: FC<Props> = ({
79
82
  const [apiErrorMsg, setApiErrorMsg] = useState<string>('');
80
83
  const [errorsMsg, setErrorsMsg] = useState<string[]>([]);
81
84
  const [orderFields, setOrderFields] = useState<OrderFormFiledType[]>(
82
- paymentMethodsOptions?.[PAYMENT_METHOD_DEFAULT]?.orderFormFields ??
83
- DEFAULT_ORDER_FORM_FIELDS
85
+ paymentMethodsOptions?.[
86
+ defaultValues?.paymentMethod || PAYMENT_METHOD_DEFAULT
87
+ ]?.orderFormFields ?? DEFAULT_ORDER_FORM_FIELDS
84
88
  );
85
89
 
86
90
  const methods = useForm<OrderFormInputsType>({
87
91
  defaultValues: {
88
92
  ...initialData,
89
93
  ...(defaultValues ?? {}),
94
+ paymentMethod:
95
+ defaultValues?.paymentMethod || PAYMENT_METHOD_DEFAULT,
90
96
  },
91
97
  });
92
98
 
@@ -106,35 +112,10 @@ const OrderForm: FC<Props> = ({
106
112
  setLoading(true);
107
113
  try {
108
114
  let id: string | undefined = subscriberId;
115
+ const contactModel = prepareContactModel({ data, orderFields });
109
116
  if (!subscriberId) {
110
117
  const response = await createSubscriber({
111
- name: orderFields.find((i) => i.name === 'name')
112
- ? data.name?.trim() || undefined
113
- : undefined,
114
- email: orderFields.find((i) => i.name === 'email')
115
- ? data.email?.trim() || undefined
116
- : undefined,
117
- phone: orderFields.find((i) => i.name === 'phoneNumber')
118
- ? data.phoneNumber?.trim() || undefined
119
- : undefined,
120
- country: orderFields.find((i) => i.name === 'country')
121
- ? data.country?.trim() || undefined
122
- : undefined,
123
- city: orderFields.find((i) => i.name === 'city')
124
- ? data.city?.trim() || undefined
125
- : undefined,
126
- addressLines: orderFields.find((i) => i.name === 'address')
127
- ? data.address?.trim()
128
- ? data.address
129
- ?.trim()
130
- .replace(/\r\n/g, '\n')
131
- .split('\n')
132
- .filter((line) => line)
133
- : undefined
134
- : undefined,
135
- zip: orderFields.find((i) => i.name === 'zip')
136
- ? data.zip?.trim() || undefined
137
- : undefined,
118
+ ...contactModel,
138
119
  });
139
120
  id = response.id;
140
121
 
package/src/enums/api.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export enum HttpStatusCode {
2
2
  UNAUTHORIZED = 401,
3
3
  FORBIDDEN = 403,
4
+ LIMIT = 429,
4
5
  }
@@ -2,6 +2,10 @@ export enum PaymentMethodEnum {
2
2
  Vipps = 'Vipps',
3
3
  MobilePay = 'MobilePay',
4
4
  SwedbankPay = 'SwedbankPay',
5
+ Invoice = 'Invoice',
6
+ Email = 'Email',
7
+ EHF = 'EHF',
8
+ OIO = 'OIO',
5
9
  }
6
10
 
7
11
  export enum MessageEventTypeEnum {
package/src/types/api.ts CHANGED
@@ -10,3 +10,14 @@ export interface ApiResponseType<T> {
10
10
  query: string;
11
11
  url: string;
12
12
  }
13
+
14
+ export type CreateSubscriberRequestType = {
15
+ name?: string;
16
+ email?: string;
17
+ phone?: string;
18
+ country?: string;
19
+ city?: string;
20
+ addressLines?: string[];
21
+ zip?: string;
22
+ careOf?: string;
23
+ };
@@ -9,6 +9,7 @@ export type OrderFormInputsType = {
9
9
  city?: string;
10
10
  address?: string;
11
11
  zip?: string;
12
+ careOf?: string;
12
13
  };
13
14
 
14
15
  export type VippsMobilePay = {
@@ -68,6 +68,10 @@ async function fetcher<ResponseType, BodyType = void>(
68
68
  reject({ message: 'Not Authorized user!' });
69
69
  } else if (response.status === HttpStatusCode.FORBIDDEN) {
70
70
  reject({ message: 'Something Wrong with permission!' });
71
+ } else if (response.status === HttpStatusCode.LIMIT) {
72
+ reject({
73
+ message: 'System busy please try again shortly!',
74
+ });
71
75
  } else {
72
76
  if (response.ok) {
73
77
  response
@@ -1,5 +1,6 @@
1
1
  import { MessageEventTypeEnum, PaymentMethodEnum } from '../enums/general';
2
- import { AgreementsType } from '../types/order';
2
+ import { AgreementsType, OrderFormInputsType } from '../types/order';
3
+ import { OrderFormFiledType } from '../types/general';
3
4
 
4
5
  type AgreementModelType = {
5
6
  paymentMethod: PaymentMethodEnum;
@@ -55,14 +56,65 @@ export const prepareAgreementModel = ({
55
56
  return model;
56
57
  }
57
58
 
58
- return {
59
- ...model,
60
- vippsMobilePay: {
59
+ if (
60
+ paymentMethod === PaymentMethodEnum.Vipps ||
61
+ paymentMethod === PaymentMethodEnum.MobilePay
62
+ ) {
63
+ model.vippsMobilePay = {
61
64
  generateSubscriberContact,
62
65
  merchantAgreementUrl,
63
66
  accountId,
64
67
  phoneNumber,
65
68
  merchantRedirectUrl: redirectUrl || window.location.href,
66
- },
69
+ };
70
+
71
+ return model;
72
+ }
73
+
74
+ return model;
75
+ };
76
+
77
+ type ContactModelType = {
78
+ data: OrderFormInputsType;
79
+ orderFields: OrderFormFiledType[];
80
+ };
81
+
82
+ export const prepareContactModel = ({
83
+ data,
84
+ orderFields,
85
+ }: ContactModelType) => {
86
+ const model = {
87
+ name: orderFields.find((i) => i.name === 'name')
88
+ ? data.name?.trim() || undefined
89
+ : undefined,
90
+ email: orderFields.find((i) => i.name === 'email')
91
+ ? data.email?.trim() || undefined
92
+ : undefined,
93
+ phone: orderFields.find((i) => i.name === 'phoneNumber')
94
+ ? data.phoneNumber?.trim() || undefined
95
+ : undefined,
96
+ country: orderFields.find((i) => i.name === 'country')
97
+ ? data.country?.trim() || undefined
98
+ : undefined,
99
+ city: orderFields.find((i) => i.name === 'city')
100
+ ? data.city?.trim() || undefined
101
+ : undefined,
102
+ addressLines: orderFields.find((i) => i.name === 'address')
103
+ ? data.address?.trim()
104
+ ? data.address
105
+ ?.trim()
106
+ .replace(/\r\n/g, '\n')
107
+ .split('\n')
108
+ .filter((line) => line)
109
+ : undefined
110
+ : undefined,
111
+ zip: orderFields.find((i) => i.name === 'zip')
112
+ ? data.zip?.trim() || undefined
113
+ : undefined,
114
+ careOf: orderFields.find((i) => i.name === 'careOf')
115
+ ? data.zip?.trim() || undefined
116
+ : undefined,
67
117
  };
118
+
119
+ return model;
68
120
  };