@hanzo/commerce 7.3.8 → 7.3.9
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/package.json +1 -1
- package/util/promo-codes.ts +0 -2
- package/util/square-payment.ts +34 -27
package/package.json
CHANGED
package/util/promo-codes.ts
CHANGED
package/util/square-payment.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { Client, Environment } from 'square'
|
|
4
|
-
import { randomUUID } from 'crypto'
|
|
1
|
+
// Payment processing - requires API endpoint
|
|
2
|
+
// For static builds, this will call an external payment API
|
|
5
3
|
|
|
6
4
|
// https://developer.squareup.com/blog/online-payments-with-square-and-react/
|
|
7
5
|
declare global {
|
|
@@ -12,32 +10,41 @@ declare global {
|
|
|
12
10
|
|
|
13
11
|
BigInt.prototype.toJSON = function() { return this.toString(); }
|
|
14
12
|
|
|
15
|
-
const { paymentsApi } = new Client({
|
|
16
|
-
accessToken: process.env.SQUARE_ACCESS_TOKEN,
|
|
17
|
-
environment: process.env.SQUARE_ENVIRONMENT as Environment
|
|
18
|
-
})
|
|
19
|
-
|
|
20
13
|
const processPayment = async (sourceId: string, amount: number, verificationToken: string) => {
|
|
21
|
-
//
|
|
22
|
-
|
|
14
|
+
// For static builds, payments should be processed via an API endpoint
|
|
15
|
+
// Check if we're in a browser environment
|
|
16
|
+
if (typeof window !== 'undefined') {
|
|
17
|
+
// Client-side: call the payment API
|
|
18
|
+
try {
|
|
19
|
+
const response = await fetch('/api/payment', {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
headers: {
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
},
|
|
24
|
+
body: JSON.stringify({
|
|
25
|
+
sourceId,
|
|
26
|
+
amount,
|
|
27
|
+
verificationToken
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
if (!response.ok) {
|
|
32
|
+
console.error('Payment API error:', response.statusText)
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
23
35
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
currency: 'USD',
|
|
30
|
-
amount: BigInt(amountInCents)
|
|
31
|
-
},
|
|
32
|
-
verificationToken
|
|
33
|
-
})
|
|
34
|
-
return result
|
|
35
|
-
} catch (error) {
|
|
36
|
-
console.error('Error processing payment:', error)
|
|
37
|
-
return null
|
|
36
|
+
return await response.json()
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.error('Error processing payment:', error)
|
|
39
|
+
return null
|
|
40
|
+
}
|
|
38
41
|
}
|
|
42
|
+
|
|
43
|
+
// Server-side (for SSR builds only, not static export)
|
|
44
|
+
console.warn('Server-side payment processing not available in static export')
|
|
45
|
+
return null
|
|
39
46
|
}
|
|
40
47
|
|
|
41
48
|
export {
|
|
42
|
-
processPayment as default
|
|
43
|
-
}
|
|
49
|
+
processPayment as default
|
|
50
|
+
}
|