@autobusal/order-process 1.4.0 → 1.5.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/services.ts +35 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobusal/order-process",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "author": "Ferjolt Ozuni",
5
5
  "type": "module",
6
6
  "main": "index.ts",
package/services.ts CHANGED
@@ -2,9 +2,39 @@ import { useQuery, UseQueryResult } from '@tanstack/react-query';
2
2
  import { apiClient } from '@autobusal/providers';
3
3
  import { BKTData, StripeData, MollieData, RaiffeisenData, NexiData } from './types';
4
4
 
5
+ /**
6
+ * Starting a payment must happen EXACTLY ONCE per attempt.
7
+ *
8
+ * Claude - 2026-08-31, after Ferjolt hit "Too Many Attempts" retrying a
9
+ * card payment.
10
+ *
11
+ * These are useQuery, and react-query's defaults are built for reads: it
12
+ * retries a failure three times, and refetches on window focus, on reconnect
13
+ * and on mount. So ONE failed payment fired four POSTs, and alt-tabbing away
14
+ * and back fired more.
15
+ *
16
+ * Two things wrong with that, and the rate limit is the milder one. Each
17
+ * call creates an ORDER ENTRY at the gateway, and RaiAccept requires
18
+ * merchantOrderReference to be unique per attempt - it rejects a repeat as
19
+ * error 1007 - so the silent retries were manufacturing duplicate gateway
20
+ * orders for a single click, and the visible failure could be the retry
21
+ * being refused rather than the original problem.
22
+ *
23
+ * A payment is not a read. It fires once, when the component mounts, and a
24
+ * failure is reported rather than quietly attempted again.
25
+ */
26
+ const ONCE = {
27
+ retry: false,
28
+ refetchOnWindowFocus: false,
29
+ refetchOnReconnect: false,
30
+ refetchOnMount: false,
31
+ staleTime: Infinity
32
+ } as const;
33
+
5
34
  export const useMakeStandard = (type: string, hash: string): UseQueryResult<string> => (
6
35
  useQuery({
7
36
  queryKey: ['process-payment-standard', { type, hash }],
37
+ ...ONCE,
8
38
  queryFn: async () => (
9
39
  await apiClient
10
40
  .post('/api/payment/make', {
@@ -21,6 +51,7 @@ export const useMakeStandard = (type: string, hash: string): UseQueryResult<stri
21
51
  export const useMakeBkt = (hash: string): UseQueryResult<BKTData> => (
22
52
  useQuery({
23
53
  queryKey: ['process-payment-bkt', { hash }],
54
+ ...ONCE,
24
55
  queryFn: async () => (
25
56
  await apiClient
26
57
  .post('/api/payment/bkt', { hash })
@@ -34,6 +65,7 @@ export const useMakeBkt = (hash: string): UseQueryResult<BKTData> => (
34
65
  export const useMakeStripe = (hash: string): UseQueryResult<StripeData> => (
35
66
  useQuery({
36
67
  queryKey: ['process-payment-stripe', { hash }],
68
+ ...ONCE,
37
69
  queryFn: async () => (
38
70
  await apiClient
39
71
  .post('/api/payment/stripe', { hash })
@@ -47,6 +79,7 @@ export const useMakeStripe = (hash: string): UseQueryResult<StripeData> => (
47
79
  export const useMakeMollie = (hash: string): UseQueryResult<MollieData> => (
48
80
  useQuery({
49
81
  queryKey: ['process-payment-mollie', { hash }],
82
+ ...ONCE,
50
83
  queryFn: async () => (
51
84
  await apiClient
52
85
  .post('/api/payment/mollie', { hash })
@@ -60,6 +93,7 @@ export const useMakeMollie = (hash: string): UseQueryResult<MollieData> => (
60
93
  export const useMakeRaiffeisen = (hash: string): UseQueryResult<RaiffeisenData> => (
61
94
  useQuery({
62
95
  queryKey: ['process-payment-raiffeisen', { hash }],
96
+ ...ONCE,
63
97
  queryFn: async () => (
64
98
  await apiClient
65
99
  .post('/api/payment/raiffeisen', { hash })
@@ -73,6 +107,7 @@ export const useMakeRaiffeisen = (hash: string): UseQueryResult<RaiffeisenData>
73
107
  export const useMakeNexi = (hash: string): UseQueryResult<NexiData> => (
74
108
  useQuery({
75
109
  queryKey: ['process-payment-nexi', { hash }],
110
+ ...ONCE,
76
111
  queryFn: async () => (
77
112
  await apiClient
78
113
  .post('/api/payment/nexi', { hash })