# paymentsApi.createPayment working in development, failing in production

**URL:** <https://developer.squareup.com/forums/t/paymentsapi-createpayment-working-in-development-failing-in-production/19296>\
**Category:** Questions\
**Tags:** payments-api\
**Created:** [October 24, 2024, 1:02am UTC](https://developer.squareup.com/forums/t/paymentsapi-createpayment-working-in-development-failing-in-production/19296 "2024-10-24T01:02:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mixmatchAdmin](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@mixmatchAdmin](https://developer.squareup.com/forums/u/mixmatchAdmin)\
**Post date:** [October 24, 2024, 1:02am UTC](https://developer.squareup.com/forums/t/paymentsapi-createpayment-working-in-development-failing-in-production/19296/1 "2024-10-24T01:02:31Z")

</div>

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

```auto
"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?

---

<div class="post-metadata">

**Author:** ![Square-Dev-AI](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/square-dev-ai/32/2513_2.png) [@Square-Dev-AI](https://developer.squareup.com/forums/u/Square-Dev-AI)\
**Post date:** [October 24, 2024, 1:02am UTC](https://developer.squareup.com/forums/t/paymentsapi-createpayment-working-in-development-failing-in-production/19296/2 "2024-10-24T01:02:49Z")

</div>

👋 I’m Square Dev AI, here to help answer your question!  
Based on the information you’ve provided, the following documentation will help answer your question:

> **[Deploy the Server](https://developer.squareup.com/docs/in-app-payments-sdk/quick-start/step-4)**
>
> Configure a test server for the Square In-App Payments SDK Quickstart.

> **[Deploy the Server](https://developer.squareup.com/docs/in-app-payments-sdk/quick-start/deploy-server-backend)**
>
> Configure a test server for the Square In-App Payments SDK Quickstart.

> **Additional Documentation**
>
> [Troubleshoot In-App Payments SDK Problems](https://developer.squareup.com/docs/in-app-payments-sdk/troubleshooting)  
> [Postman](https://developer.squareup.com/docs/devtools/postman)  
> [Payment API: Process Online and In-Person Payments](https://developer.squareup.com/docs/payments)

If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.  
Otherwise one of our Developer Advocates will provide additional assistance shortly.

---

<div class="post-metadata">

**Author:** ![Square-Dev-AI](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/square-dev-ai/32/2513_2.png) [@Square-Dev-AI](https://developer.squareup.com/forums/u/Square-Dev-AI)\
**Post date:** [October 24, 2024, 3:39pm UTC](https://developer.squareup.com/forums/t/paymentsapi-createpayment-working-in-development-failing-in-production/19296/3 "2024-10-24T15:39:50Z")

</div>

The error message suggests that the card nonce was generated in a different environment than the one you’re trying to use it in. If you generate a nonce in a sandbox environment, you can’t use it in a production environment, and vice versa.

Ensure that both your client-side and server-side environments match. If you’re testing in a sandbox environment, make sure your client-side code is also generating nonces in the sandbox environment. Similarly, if you’re in a production environment, ensure your client-side code is generating nonces in the production environment.

Also, make sure that the access token you’re using on the server-side matches the environment you’re working in. If you’re in a sandbox environment, use your sandbox access token, and if you’re in a production environment, use your production access token.

_This answer was reviewed by @Bryan-Square._
