I have the following in a serverside function:
`async function processPayment(paymentRequest: any, environment: ‘sandbox’ | ‘production’) {
const client = new Client({
environment: environment === ‘sandbox’ ? Environment.Sandbox : Environment.Production,
accessToken:
environment === ‘sandbox’
? process.env.VITE_SQUARE_ACCESS_TOKEN_DEV
: process.env.VITE_SQUARE_ACCESS_TOKEN_PROD
});
try {
const { nonce, amount, currency, userId, paymentType, eventId, eventDescription, userEmail } =
paymentRequest;
console.log('Processing payment:', paymentRequest);
if (!nonce) {
throw new Error('Payment nonce is missing');
}
// Create a payment request using the Square API
const paymentsApi = client.paymentsApi;
const response = await paymentsApi.createPayment({
sourceId: nonce,
idempotencyKey: uuidv4(), // Generate a unique idempotency key
amountMoney: {
amount: amount, // Example: 100 for $1.00
currency: currency || 'USD'
}
});
if (
!response.result ||
!response.result.payment ||
response.result.payment.status !== 'COMPLETED'
) {
throw new Error(`Payment failed: ${response.result.payment?.status || 'Unknown error'}`);
}`
This works with no issues when running it in development mode locally. However, when running in production, i get this error
"code": "INVALID_CARD_DATA","detail": "Card nonce not found in this application environment. Please ensure an application ID belonging to the same environment is used when generating the nonce.","category": "INV… [message truncated due to size]
Im not sure what to do, my client and server are configured correctly. Is there a mistake I am making here?