@autobusal/order-process 1.0.0 → 1.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/BKT/Bkt.tsx CHANGED
@@ -4,7 +4,7 @@ import { useForm } from 'react-hook-form';
4
4
  import { Inline } from '@autobusal/common';
5
5
  import { Container } from '../styles';
6
6
  import { BKTFormData } from '../types';
7
- import { MakeBkt } from '../services';
7
+ import { useMakeBkt } from '../services';
8
8
 
9
9
  interface Props {
10
10
  hash?: string
@@ -16,7 +16,7 @@ const Bkt = ({ hash, t }: Props): JSX.Element => {
16
16
 
17
17
  const ref = useRef<HTMLFormElement>(null);
18
18
 
19
- const { data, isLoading, isSuccess } = MakeBkt(String(hash));
19
+ const { data, isLoading, isSuccess } = useMakeBkt(String(hash));
20
20
 
21
21
  const onSubmit = (): void => {
22
22
  ref.current?.submit();
package/Content.tsx CHANGED
@@ -1,6 +1,7 @@
1
1
  import { TFunction } from 'i18next';
2
2
  import Standard from './Standard/Standard';
3
3
  import Bkt from './BKT/Bkt';
4
+ import Stripe from './Stripe/Stripe';
4
5
 
5
6
  interface Props {
6
7
  type?: string
@@ -13,6 +14,9 @@ const Content = ({ type, hash, t }: Props): JSX.Element => {
13
14
  case 'bkt':
14
15
  return <Bkt hash={ hash } t={ t } />;
15
16
 
17
+ case 'stripe':
18
+ return <Stripe hash={ hash } t={ t } />;
19
+
16
20
  default:
17
21
  return <Standard type={ type } hash={ hash } t={ t } />;
18
22
  }
@@ -2,7 +2,7 @@ import { TFunction } from 'i18next';
2
2
  import { Navigate } from 'react-router-dom';
3
3
  import { Inline } from '@autobusal/common';
4
4
  import { Container } from '../styles';
5
- import { MakeStandard } from '../services';
5
+ import { useMakeStandard } from '../services';
6
6
 
7
7
  interface Props {
8
8
  type?: string
@@ -11,7 +11,7 @@ interface Props {
11
11
  }
12
12
 
13
13
  const Standard = ({ type, hash, t }: Props): JSX.Element => {
14
- const { data, isSuccess } = MakeStandard(String(type), String(hash));
14
+ const { data, isSuccess } = useMakeStandard(String(type), String(hash));
15
15
 
16
16
  if (isSuccess) {
17
17
  return <Navigate to={ data } />;
@@ -0,0 +1,28 @@
1
+ import { useEffect } from 'react';
2
+ import { TFunction } from 'i18next';
3
+ import { Inline } from '@autobusal/common';
4
+ import { Container } from '../styles';
5
+ import { useMakeStripe } from '../services';
6
+
7
+ interface Props {
8
+ hash?: string
9
+ t: TFunction<'common'>
10
+ }
11
+
12
+ const Stripe = ({ hash, t }: Props): JSX.Element => {
13
+ const { data, isSuccess } = useMakeStripe(String(hash));
14
+
15
+ useEffect(() => {
16
+ if (isSuccess) {
17
+ window.location.href = data.redirect;
18
+ }
19
+ }, [data, isSuccess]);
20
+
21
+ return (
22
+ <Container>
23
+ <Inline text={ t('order_process.stripe') } />
24
+ </Container>
25
+ );
26
+ };
27
+
28
+ export default Stripe;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobusal/order-process",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "main": "index.ts"
6
6
  }
package/services.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { useQuery, UseQueryResult } from '@tanstack/react-query';
2
2
  import { apiClient } from '@autobusal/providers';
3
- import { BKTData } from './types';
3
+ import { BKTData, StripeData } from './types';
4
4
 
5
- export const MakeStandard = (type: string, hash: string): UseQueryResult<string> => (
5
+ export const useMakeStandard = (type: string, hash: string): UseQueryResult<string> => (
6
6
  useQuery({
7
7
  queryKey: ['process-payment-standard', { type, hash }],
8
8
  queryFn: async () => (
@@ -18,7 +18,7 @@ export const MakeStandard = (type: string, hash: string): UseQueryResult<string>
18
18
  })
19
19
  );
20
20
 
21
- export const MakeBkt = (hash: string): UseQueryResult<BKTData> => (
21
+ export const useMakeBkt = (hash: string): UseQueryResult<BKTData> => (
22
22
  useQuery({
23
23
  queryKey: ['process-payment-bkt', { hash }],
24
24
  queryFn: async () => (
@@ -29,4 +29,17 @@ export const MakeBkt = (hash: string): UseQueryResult<BKTData> => (
29
29
  ))
30
30
  )
31
31
  })
32
+ );
33
+
34
+ export const useMakeStripe = (hash: string): UseQueryResult<StripeData> => (
35
+ useQuery({
36
+ queryKey: ['process-payment-stripe', { hash }],
37
+ queryFn: async () => (
38
+ await apiClient
39
+ .post('/api/payment/stripe', { hash })
40
+ .then(response => (
41
+ response?.data ?? ''
42
+ ))
43
+ )
44
+ })
32
45
  );
package/types.ts CHANGED
@@ -60,4 +60,8 @@ export interface BKTData {
60
60
  trantype: string
61
61
  user_id: number
62
62
  hash: string
63
+ }
64
+
65
+ export interface StripeData {
66
+ redirect: string
63
67
  }