@autobusal/order-process 1.5.0 → 1.5.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/Content.tsx +3 -0
- package/Mgpay/Mgpay.tsx +49 -0
- package/package.json +1 -1
- package/services.ts +16 -2
- package/types.ts +5 -1
package/Content.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import Stripe from './Stripe/Stripe';
|
|
|
5
5
|
import Mollie from './Mollie/Mollie';
|
|
6
6
|
import Raiffeisen from './Reiffeisen/Raiffeisen';
|
|
7
7
|
import Nexi from './Nexi/Nexi';
|
|
8
|
+
import Mgpay from './Mgpay/Mgpay';
|
|
8
9
|
|
|
9
10
|
interface Props {
|
|
10
11
|
type?: string
|
|
@@ -28,6 +29,8 @@ const Content = ({ type, hash, t }: Props): JSX.Element => {
|
|
|
28
29
|
|
|
29
30
|
case 'nexi':
|
|
30
31
|
return <Nexi hash={ hash } t={ t } />;
|
|
32
|
+
case 'mgpay':
|
|
33
|
+
return <Mgpay hash={ hash } t={ t } />;
|
|
31
34
|
|
|
32
35
|
default:
|
|
33
36
|
return <Standard type={ type } hash={ hash } t={ t } />;
|
package/Mgpay/Mgpay.tsx
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
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 { useMakeMgpay } from '../services';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
hash?: string
|
|
10
|
+
t: TFunction<'common'>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The Magus Pay Hub - Claude, 2026-09-07.
|
|
15
|
+
*
|
|
16
|
+
* Same shape as Raiffeisen: one call to obtapi registers the order with the
|
|
17
|
+
* hub and answers with its pay_url; the browser goes there and comes back
|
|
18
|
+
* to /orders/purchased or /orders/cancelled, which are hints - the booking
|
|
19
|
+
* is marked paid only by the hub's signed notification to obtapi.
|
|
20
|
+
*/
|
|
21
|
+
const Mgpay = ({ hash, t }: Props): JSX.Element => {
|
|
22
|
+
const { data, isSuccess, isError, error } = useMakeMgpay(String(hash));
|
|
23
|
+
|
|
24
|
+
const navigate = useNavigate();
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (isSuccess) {
|
|
28
|
+
window.location.href = data.redirect;
|
|
29
|
+
}
|
|
30
|
+
}, [data, isSuccess]);
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (isError) {
|
|
34
|
+
const message = (error as { response?: { data?: { message?: string } } })?.response?.data?.message;
|
|
35
|
+
|
|
36
|
+
const reason = message ?? t('order_process.error', { ns: 'common', defaultValue: 'We could not complete your payment. Please try again.' });
|
|
37
|
+
|
|
38
|
+
navigate(hash ? `/orders/cancelled/${ hash }?msg=${ encodeURIComponent(reason) }` : '/', { replace: true });
|
|
39
|
+
}
|
|
40
|
+
}, [isError, error, hash, navigate, t]);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<Container>
|
|
44
|
+
<Inline text={ t('order_process.mgpay', { defaultValue: t('order_process.raiffeisen') }) } />
|
|
45
|
+
</Container>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default Mgpay;
|
package/package.json
CHANGED
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, StripeData, MollieData, RaiffeisenData, NexiData } from './types';
|
|
3
|
+
import { BKTData, StripeData, MollieData, RaiffeisenData, NexiData, MgpayData } from './types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Starting a payment must happen EXACTLY ONCE per attempt.
|
|
@@ -116,4 +116,18 @@ export const useMakeNexi = (hash: string): UseQueryResult<NexiData> => (
|
|
|
116
116
|
))
|
|
117
117
|
)
|
|
118
118
|
})
|
|
119
|
-
);
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
export const useMakeMgpay = (hash: string): UseQueryResult<MgpayData> => (
|
|
122
|
+
useQuery({
|
|
123
|
+
queryKey: ['process-payment-mgpay', { hash }],
|
|
124
|
+
...ONCE,
|
|
125
|
+
queryFn: async () => (
|
|
126
|
+
await apiClient
|
|
127
|
+
.post('/api/payment/mgpay', { hash })
|
|
128
|
+
.then(response => (
|
|
129
|
+
response?.data ?? ''
|
|
130
|
+
))
|
|
131
|
+
)
|
|
132
|
+
})
|
|
133
|
+
);
|