Files
ui/pkg/commerce/util/square-payment.ts
zeekayandHanzo Dev 57f9435929 Keep every package in one directory
The workspace declared pkg/* and pkgs/* both, so one repo had two names
for one concept and a package's home was a coin toss. The shared build
tooling already lived in pkg/ui/scripts and pkgs reached back into it
two levels up; now it is a sibling. hanzo.yml gates on pkg/ui, so the
published library stays where CI already looks and the rest joins it.

The publish glob follows: one root, one pattern, nothing invisible to it.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-08 23:50:28 -07:00

51 lines
1.3 KiB
TypeScript

// Payment processing - requires API endpoint
// For static builds, this will call an external payment API
// https://developer.squareup.com/blog/online-payments-with-square-and-react/
declare global {
interface BigInt {
toJSON(): string;
}
}
BigInt.prototype.toJSON = function() { return this.toString(); }
const processPayment = async (sourceId: string, amount: number, verificationToken: string) => {
// For static builds, payments should be processed via an API endpoint
// Check if we're in a browser environment
if (typeof window !== 'undefined') {
// Client-side: call the payment API
try {
const response = await fetch('/api/payment', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
sourceId,
amount,
verificationToken
})
})
if (!response.ok) {
console.error('Payment API error:', response.statusText)
return null
}
return await response.json()
} catch (error) {
console.error('Error processing payment:', error)
return null
}
}
// Server-side (for SSR builds only, not static export)
console.warn('Server-side payment processing not available in static export')
return null
}
export {
processPayment as default
}