@autobusal/order-process 1.0.1 → 1.2.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/Content.tsx CHANGED
@@ -1,6 +1,8 @@
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';
5
+ import Mollie from './Mollie/Mollie';
4
6
 
5
7
  interface Props {
6
8
  type?: string
@@ -13,6 +15,12 @@ const Content = ({ type, hash, t }: Props): JSX.Element => {
13
15
  case 'bkt':
14
16
  return <Bkt hash={ hash } t={ t } />;
15
17
 
18
+ case 'stripe':
19
+ return <Stripe hash={ hash } t={ t } />;
20
+
21
+ case 'mollie':
22
+ return <Mollie hash={ hash } t={ t } />;
23
+
16
24
  default:
17
25
  return <Standard type={ type } hash={ hash } t={ t } />;
18
26
  }
@@ -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 { useMakeMollie } from '../services';
6
+
7
+ interface Props {
8
+ hash?: string
9
+ t: TFunction<'common'>
10
+ }
11
+
12
+ const Mollie = ({ hash, t }: Props): JSX.Element => {
13
+ const { data, isSuccess } = useMakeMollie(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.mollie') } />
24
+ </Container>
25
+ );
26
+ };
27
+
28
+ export default Mollie;
@@ -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.1",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "main": "index.ts"
6
6
  }
package/services.ts CHANGED
@@ -1,6 +1,6 @@
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, MollieData } from './types';
4
4
 
5
5
  export const useMakeStandard = (type: string, hash: string): UseQueryResult<string> => (
6
6
  useQuery({
@@ -29,4 +29,30 @@ export const useMakeBkt = (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
+ })
45
+ );
46
+
47
+ export const useMakeMollie = (hash: string): UseQueryResult<MollieData> => (
48
+ useQuery({
49
+ queryKey: ['process-payment-mollie', { hash }],
50
+ queryFn: async () => (
51
+ await apiClient
52
+ .post('/api/payment/mollie', { hash })
53
+ .then(response => (
54
+ response?.data ?? ''
55
+ ))
56
+ )
57
+ })
32
58
  );
package/types.ts CHANGED
@@ -60,4 +60,12 @@ 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
67
+ }
68
+
69
+ export interface MollieData {
70
+ redirect: string
63
71
  }