@infosoftas/s4-orders-js-sdk 0.0.1-beta1.5 → 0.1.0
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 +1 -1
- package/src/App.tsx +19 -1
- package/src/components/OrderForm/OrderForm.tsx +21 -0
- package/src/index.tsx +9 -0
- package/src/utils/order.helper.ts +12 -1
package/package.json
CHANGED
package/src/App.tsx
CHANGED
|
@@ -102,6 +102,24 @@ const App: FC<ConfigType> = ({
|
|
|
102
102
|
setFailedMsg('');
|
|
103
103
|
setErrorsMsg([]);
|
|
104
104
|
try {
|
|
105
|
+
if (!data.orderInfo) {
|
|
106
|
+
try {
|
|
107
|
+
if (data.orderId) {
|
|
108
|
+
await handleOrderDelete(data.orderId);
|
|
109
|
+
}
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.log(error);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
setLoading(false);
|
|
115
|
+
setOrderId(null);
|
|
116
|
+
setOrderInfo(null);
|
|
117
|
+
setIframeSrc(null);
|
|
118
|
+
setIsConfirmed(false);
|
|
119
|
+
setShowOrderForm(true);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
105
123
|
await orderComplete(orderId || data.orderId || '');
|
|
106
124
|
setIsConfirmed(true);
|
|
107
125
|
setLoading(false);
|
|
@@ -363,7 +381,7 @@ const App: FC<ConfigType> = ({
|
|
|
363
381
|
/>
|
|
364
382
|
)}
|
|
365
383
|
{formType !== FormTypeEnum.OIO &&
|
|
366
|
-
formType !== FormTypeEnum.EHF && (
|
|
384
|
+
formType !== FormTypeEnum.EHF && templatePackageId && (
|
|
367
385
|
<OrderForm
|
|
368
386
|
callback={handleForm}
|
|
369
387
|
updateFormData={updateFormData}
|
|
@@ -90,6 +90,27 @@ const OrderForm: FC<Props> = ({
|
|
|
90
90
|
errorInvalidEmailMsg = '',
|
|
91
91
|
errorInvalidPhoneMsg = '',
|
|
92
92
|
}) => {
|
|
93
|
+
|
|
94
|
+
if (!templatePackageId) {
|
|
95
|
+
console.error('"templatePackageId" should be set' );
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!organizationId) {
|
|
99
|
+
console.error('"organizationId" should be set' );
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!subscriberId) {
|
|
103
|
+
console.error('"subscriberId" should be set' );
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!userId) {
|
|
107
|
+
console.error('"userId" should be set' );
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (!identityProviderId) {
|
|
111
|
+
console.error('"identityProviderId" should be set' );
|
|
112
|
+
}
|
|
113
|
+
|
|
93
114
|
const [orderFields, setOrderFields] = useState<OrderFormFiledType[]>(
|
|
94
115
|
paymentMethodsOptions?.[
|
|
95
116
|
defaultValues?.paymentMethod || PAYMENT_METHOD_DEFAULT
|
package/src/index.tsx
CHANGED
|
@@ -8,6 +8,15 @@ import App from './App';
|
|
|
8
8
|
export const orderComponent = {
|
|
9
9
|
root: null as Root | null,
|
|
10
10
|
init: function (config: ConfigType) {
|
|
11
|
+
|
|
12
|
+
if (!config.apiKey) {
|
|
13
|
+
console.error('"apiKey" should be set' );
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (!config.apiUrl) {
|
|
17
|
+
console.error('"apiUrl" should be set' );
|
|
18
|
+
}
|
|
19
|
+
|
|
11
20
|
const domNode = document.getElementById(config.domElementId);
|
|
12
21
|
orderComponent.root = createRoot(
|
|
13
22
|
domNode || document.createElement('div')
|
|
@@ -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
|
|