@autobusal/order-process 0.0.1
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/BKT/Bkt.tsx +90 -0
- package/Content.tsx +21 -0
- package/OrderProcess.tsx +20 -0
- package/Standard/Standard.tsx +34 -0
- package/index.ts +3 -0
- package/package.json +6 -0
- package/services.ts +36 -0
- package/styles.ts +5 -0
- package/types.ts +34 -0
package/BKT/Bkt.tsx
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { TFunction } from 'i18next';
|
|
3
|
+
import { Inline } from '@autobusal/common';
|
|
4
|
+
import { useForm } from 'react-hook-form';
|
|
5
|
+
import { Container } from '../styles';
|
|
6
|
+
import { BKTFormData } from '../types';
|
|
7
|
+
import { PostBkt } from '../services';
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
hash?: string
|
|
11
|
+
t: TFunction<'common'>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const Bkt = ({ hash, t }: Props): JSX.Element => {
|
|
15
|
+
const { register, handleSubmit } = useForm<BKTFormData>();
|
|
16
|
+
|
|
17
|
+
const ref = useRef<HTMLFormElement>(null);
|
|
18
|
+
|
|
19
|
+
const { data, isLoading, isSuccess } = PostBkt(
|
|
20
|
+
String(hash)
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const onSubmit = (): void => {
|
|
24
|
+
ref.current?.submit();
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (isSuccess) {
|
|
29
|
+
handleSubmit(onSubmit)();
|
|
30
|
+
}
|
|
31
|
+
}, [isSuccess]);
|
|
32
|
+
|
|
33
|
+
if (isLoading) {
|
|
34
|
+
return (
|
|
35
|
+
<Container>
|
|
36
|
+
<Inline text={ t('order_process.bkt') } />
|
|
37
|
+
</Container>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<Container>
|
|
43
|
+
<Inline text={ t('order_process.bkt') } />
|
|
44
|
+
|
|
45
|
+
<form ref={ ref } action="https://pgw.bkt.com.al/fim/est3Dgate" method="POST" onSubmit={ handleSubmit(onSubmit) }>
|
|
46
|
+
<input type="hidden" defaultValue={ data?.clientid } { ...register('clientid') } />
|
|
47
|
+
<input type="hidden" defaultValue="3d_pay_hosting" { ...register('storetype') } />
|
|
48
|
+
<input type="hidden" defaultValue={ data?.trantype } { ...register('trantype') } />
|
|
49
|
+
<input type="hidden" defaultValue={ data?.currency } { ...register('currency') } />
|
|
50
|
+
<input type="hidden" defaultValue={ data?.okUrl } { ...register('okUrl') } />
|
|
51
|
+
<input type="hidden" defaultValue={ data?.failUrl } { ...register('failUrl') } />
|
|
52
|
+
<input type="hidden" defaultValue={ data?.oId } { ...register('oId') } />
|
|
53
|
+
<input type="hidden" defaultValue={ data?.amount } { ...register('amount') } />
|
|
54
|
+
<input type="hidden" defaultValue={ data?.lang } { ...register('lang') } />
|
|
55
|
+
|
|
56
|
+
<input type="hidden" defaultValue={ data?.Email } { ...register('Email') } />
|
|
57
|
+
<input type="hidden" defaultValue={ data?.tel } { ...register('tel') } />
|
|
58
|
+
|
|
59
|
+
<input type="hidden" defaultValue={ data?.ShipToCompany } { ...register('ShipToCompany') } />
|
|
60
|
+
<input type="hidden" defaultValue={ data?.ShippingNameSurname } { ...register('ShippingNameSurname') } />
|
|
61
|
+
<input type="hidden" defaultValue={ data?.ShipToStreet1 } { ...register('ShipToStreet1') } />
|
|
62
|
+
<input type="hidden" defaultValue={ data?.ShipToCity } { ...register('ShipToCity') } />
|
|
63
|
+
<input type="hidden" defaultValue={ data?.ShipToPostalCode } { ...register('ShipToPostalCode') } />
|
|
64
|
+
<input type="hidden" defaultValue={ data?.ShipToCountry } { ...register('ShipToCountry') } />
|
|
65
|
+
|
|
66
|
+
<input type="hidden" defaultValue={ data?.ShipToCompany } { ...register('BillToCompany') } />
|
|
67
|
+
<input type="hidden" defaultValue={ data?.ShippingNameSurname } { ...register('BillToName') } />
|
|
68
|
+
<input type="hidden" defaultValue={ data?.ShipToStreet1 } { ...register('BillToStreet1') } />
|
|
69
|
+
<input type="hidden" defaultValue={ data?.ShipToCity } { ...register('BillToCity') } />
|
|
70
|
+
<input type="hidden" defaultValue={ data?.ShipToPostalCode } { ...register('BillToPostalCode') } />
|
|
71
|
+
<input type="hidden" defaultValue={ data?.ShipToCountry } { ...register('BillToCountry') } />
|
|
72
|
+
|
|
73
|
+
<input type="hidden" defaultValue={ data?.rnd } { ...register('rnd') } />
|
|
74
|
+
<input type="hidden" defaultValue={ data?.hash } { ...register('hash') } />
|
|
75
|
+
<input type="hidden" defaultValue="utf-8" { ...register('encoding') } />
|
|
76
|
+
|
|
77
|
+
<input type="hidden" defaultValue={ data?.ObtBktId } { ...register('ObtBktId') } />
|
|
78
|
+
<input type="hidden" defaultValue={ data?.ObtBktPrice } { ...register('ObtBktPrice') } />
|
|
79
|
+
|
|
80
|
+
<input type="hidden" defaultValue={ data?.ObtBktDomain } { ...register('ObtBktDomain') } />
|
|
81
|
+
<input type="hidden" defaultValue={ data?.ObtBktLabelId } { ...register('ObtBktLabelId') } />
|
|
82
|
+
|
|
83
|
+
<input type="hidden" defaultValue={ data?.ObtBktUid } { ...register('ObtBktUid') } />
|
|
84
|
+
<input type="hidden" defaultValue={ 0 } { ...register('refreshtime') } />
|
|
85
|
+
</form>
|
|
86
|
+
</Container>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export default Bkt;
|
package/Content.tsx
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TFunction } from 'i18next';
|
|
2
|
+
import Standard from './Standard/Standard';
|
|
3
|
+
import Bkt from './BKT/Bkt';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
type?: string
|
|
7
|
+
hash?: string
|
|
8
|
+
t: TFunction<'common'>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const Content = ({ type, hash, t }: Props): JSX.Element => {
|
|
12
|
+
switch (type) {
|
|
13
|
+
case 'bkt':
|
|
14
|
+
return <Bkt hash={ hash } t={ t } />;
|
|
15
|
+
|
|
16
|
+
default:
|
|
17
|
+
return <Standard type={ type } hash={ hash } t={ t } />;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default Content;
|
package/OrderProcess.tsx
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TFunction } from 'i18next';
|
|
2
|
+
import { useParams } from 'react-router-dom';
|
|
3
|
+
import { Meta } from '@autobusal/common';
|
|
4
|
+
import Content from './Content';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
t: TFunction<'common'>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const OrderProcess = ({ t }: Props): JSX.Element => {
|
|
11
|
+
const { type, hash } = useParams();
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<Meta title={ t('order_process.title') }>
|
|
15
|
+
<Content type={ type } hash={ hash } t={ t } />
|
|
16
|
+
</Meta>
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default OrderProcess;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { TFunction } from 'i18next';
|
|
3
|
+
import { useNavigate } from 'react-router-dom';
|
|
4
|
+
import { Inline } from '@autobusal/common';
|
|
5
|
+
import { Container } from '../styles';
|
|
6
|
+
import { PostStandard } from '../services';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
type?: string
|
|
10
|
+
hash?: string
|
|
11
|
+
t: TFunction<'common'>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const Standard = ({ type, hash, t }: Props): JSX.Element => {
|
|
15
|
+
const { data, isSuccess } = PostStandard(
|
|
16
|
+
String(type), String(hash)
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const navigate = useNavigate();
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (isSuccess) {
|
|
23
|
+
navigate(data);
|
|
24
|
+
}
|
|
25
|
+
}, [isSuccess]);
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<Container>
|
|
29
|
+
<Inline text={ t('order_process.loading') } />
|
|
30
|
+
</Container>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default Standard;
|
package/index.ts
ADDED
package/package.json
ADDED
package/services.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useQuery, UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import { apiClient } from '@autobusal/providers';
|
|
3
|
+
import { BKTFormData } from './types';
|
|
4
|
+
|
|
5
|
+
export const PostStandard = (type: string, hash: string): UseQueryResult<string> => (
|
|
6
|
+
useQuery({
|
|
7
|
+
queryKey: ['process-payment-standard', { type, hash }],
|
|
8
|
+
queryFn: async () => (
|
|
9
|
+
await apiClient
|
|
10
|
+
.post('/api/payment/make', {
|
|
11
|
+
type,
|
|
12
|
+
hash
|
|
13
|
+
})
|
|
14
|
+
.then(response => (
|
|
15
|
+
response?.data ?? ''
|
|
16
|
+
))
|
|
17
|
+
.catch(() => {})
|
|
18
|
+
)
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export const PostBkt = (hash: string): UseQueryResult<BKTFormData> => (
|
|
23
|
+
useQuery({
|
|
24
|
+
queryKey: ['process-payment-bkt', { hash }],
|
|
25
|
+
queryFn: async () => (
|
|
26
|
+
await apiClient
|
|
27
|
+
.post('/api/payment/bkt', {
|
|
28
|
+
hash
|
|
29
|
+
})
|
|
30
|
+
.then(response => (
|
|
31
|
+
response?.data ?? ''
|
|
32
|
+
))
|
|
33
|
+
.catch(() => {})
|
|
34
|
+
)
|
|
35
|
+
})
|
|
36
|
+
);
|
package/styles.ts
ADDED
package/types.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface BKTFormData {
|
|
2
|
+
clientid: string
|
|
3
|
+
storetype: string
|
|
4
|
+
trantype: string
|
|
5
|
+
currency: number
|
|
6
|
+
okUrl: string
|
|
7
|
+
failUrl: string
|
|
8
|
+
oId: number
|
|
9
|
+
amount: number
|
|
10
|
+
lang: string
|
|
11
|
+
Email: string
|
|
12
|
+
tel: string
|
|
13
|
+
ShipToCompany?: string
|
|
14
|
+
ShippingNameSurname: string
|
|
15
|
+
ShipToStreet1: string
|
|
16
|
+
ShipToCity: string
|
|
17
|
+
ShipToPostalCode: string
|
|
18
|
+
ShipToCountry: string
|
|
19
|
+
BillToCompany?: string
|
|
20
|
+
BillToName: string
|
|
21
|
+
BillToStreet1: string
|
|
22
|
+
BillToCity: string
|
|
23
|
+
BillToPostalCode: string
|
|
24
|
+
BillToCountry: string
|
|
25
|
+
hash: string
|
|
26
|
+
rnd: string
|
|
27
|
+
encoding: string
|
|
28
|
+
ObtBktId: number
|
|
29
|
+
ObtBktPrice: number
|
|
30
|
+
ObtBktDomain: string
|
|
31
|
+
ObtBktLabelId: number
|
|
32
|
+
ObtBktUid: number
|
|
33
|
+
refreshtime: string
|
|
34
|
+
}
|