# Payment Tokenization failed - in sandbox and production

**URL:** <https://developer.squareup.com/forums/t/payment-tokenization-failed-in-sandbox-and-production/15280>\
**Category:** Questions\
**Tags:** payments-api\
**Created:** [May 1, 2024, 2:54am UTC](https://developer.squareup.com/forums/t/payment-tokenization-failed-in-sandbox-and-production/15280 "2024-05-01T02:54:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![michealhall](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@michealhall](https://developer.squareup.com/forums/u/michealhall)\
**Post date:** [May 1, 2024, 2:54am UTC](https://developer.squareup.com/forums/t/payment-tokenization-failed-in-sandbox-and-production/15280/1 "2024-05-01T02:54:25Z")

</div>

Hi.

I run a low volume photography ecommerce website. I’m the photographer and the developer.

I’ve had a working Square integration since December. However, I am no longer able to take payments. I am getting: “Tokenization has failed An unknown error has occurred” on all attempts to tokenize payments, in production or sandbox.

I’m the only programmer - I know no code of ours has been changed in this area. I just checked the git history for the related files to confirm. I haven’t changed anything since I got this all in place 5 months ago.

I’m receiving a 400 BAD REQUEST response.

The error message is: “Tokenization has failed An unknown error has occurred”.

This is the tokenize request body sent by the square js library:

 ![image](https://global.discourse-cdn.com/square/original/2X/e/ef6fbb0fd76ef0647bd51b9793b4dbfdeeca90e3.png)

This is the error response received:  
 ![image](https://global.discourse-cdn.com/square/original/2X/8/8e0287ad6aed5cc6cb1a5c42a678c8733b6829d6.png)

These are the response headers:  
 ![image](https://global.discourse-cdn.com/square/original/2X/d/d9b01aa14a4f8bb4541ca3ba0a0efa6ab760c4f1.png)

These are the Square sandbox environment variables I am using:  
 ![image](https://global.discourse-cdn.com/square/original/2X/5/57e05a006fe4499b0985e3e1866744b33222e039.png)

I’ve seen another developer reported intermittent issues back on 24 March - but mine are 100% failure. No sandbox transactions are going through and I’ve not had a successful eCommerce Integration sourced transaction since the 18th of April - customers are emailing me in frustration.

I’m hoping there’s a simple fix … thanks for any insight!

~Micheal

---

<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:** [May 1, 2024, 2:54am UTC](https://developer.squareup.com/forums/t/payment-tokenization-failed-in-sandbox-and-production/15280/2 "2024-05-01T02:54:50Z")

</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:

> **[Troubleshoot In-App Payments SDK Problems](https://developer.squareup.com/docs/in-app-payments-sdk/troubleshooting)**
>
> Troubleshoot problems with the Square In-App Payments SDK.

> **[Handling Errors](https://developer.squareup.com/docs/build-basics/handling-errors)**
>
> Improve your user experience by handling error information from Square APIs and SDKs.

> **Additional Documentation**
>
> [Move OAuth from the Sandbox to Production](https://developer.squareup.com/docs/oauth-api/movetoprod)  
> [Make your First API Call](https://developer.squareup.com/docs/get-started/make-api-request)  
> [Receive Seller Authorization and Manage Seller OAuth Tokens](https://developer.squareup.com/docs/oauth-api/receive-and-manage-tokens)

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:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [May 1, 2024, 4:04pm UTC](https://developer.squareup.com/forums/t/payment-tokenization-failed-in-sandbox-and-production/15280/3 "2024-05-01T16:04:09Z")

</div>

Is your page publicly hosted? If so what’s the URL so we can take a look. 🙂

---

<div class="post-metadata">

**Author:** ![michealhall](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@michealhall](https://developer.squareup.com/forums/u/michealhall)\
**Post date:** [May 1, 2024, 6:31pm UTC](https://developer.squareup.com/forums/t/payment-tokenization-failed-in-sandbox-and-production/15280/4 "2024-05-01T18:31:04Z")

</div>

Hi Bryan,

The production site is. (The sandbox site is a local test server, not exposed online). It’s part of a large SPA. I’ve created a test account for you and built a simple cart:

User Name: squaretest  
PW: square

When you hit this link, you’ll be prompted to login:  
[https://ordering.vbpics.com/#r=order&oid=cart](https://ordering.vbpics.com/#r=order&oid=cart)

The cart will be displayed. If you click the Payment Link:  
 ![image](https://global.discourse-cdn.com/square/original/2X/b/bb004ede24d6ba8a9ddd87ddaf552dbe2ee7e215.png)

The payment dialog will be displayed.

The source for the SPA is all served in one large bundle, but not obfuscated/minified.

There is an object called paymentHandlers which basically defines the tenders (creditcard, googlepay, applepay) and their square methods. I starts at

Line 43270

Here are a couple of functions in that object you may want to break point:

Initialize Square Credit card payment type  
Line 43787

Tokenize Payment  
Line 43828

Thank your for having a look - I hope you’re able to spot something!

Regards,  
Micheal

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [May 1, 2024, 7:35pm UTC](https://developer.squareup.com/forums/t/payment-tokenization-failed-in-sandbox-and-production/15280/5 "2024-05-01T19:35:56Z")

</div>

Looks like the issue is that your using an unsupported version of the Web Payments SDK. You’ll need to point to a supported version which is `web.squarecdn.com/v1/square.js` 🙂

---

<div class="post-metadata">

**Author:** ![michealhall](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@michealhall](https://developer.squareup.com/forums/u/michealhall)\
**Post date:** [May 1, 2024, 8:40pm UTC](https://developer.squareup.com/forums/t/payment-tokenization-failed-in-sandbox-and-production/15280/6 "2024-05-01T20:40:10Z")

</div>

Thanks for pointing that out! Sounds simple enough. 😆

Is there a canonical place I can look for the sandbox and production URLs? I feel like I’ve seen them, but I’ve been looking on the site and in the docs and they’re not jumping out at me.

---

<div class="post-metadata">

**Author:** ![michealhall](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@michealhall](https://developer.squareup.com/forums/u/michealhall)\
**Post date:** [May 3, 2024, 11:20pm UTC](https://developer.squareup.com/forums/t/payment-tokenization-failed-in-sandbox-and-production/15280/7 "2024-05-03T23:20:40Z")

</div>

So things are working in sandbox … but still not in production. I’ve not been able to successfully use the production environment on my deployed online server or my in-house development machine. But sandbox is working in-house without issue.

I’m still getting a 400 response from a tokenization request with the following response:

![image](https://global.discourse-cdn.com/square/original/2X/0/00ee229ef2f7f441882d5d6be0436163b94f4670.png)

Here is the request data being POSTed:

 ![image](https://global.discourse-cdn.com/square/original/2X/0/0a1e2f9e2a91893766ad89366d80867a0de601ba.png)

I’m using:

 ![image](https://global.discourse-cdn.com/square/original/2X/6/6ffb5b0888e238d5bbc610189309769f2fc80f98.png)

`https://web/squarecdn.com/v1/square.js`

As the script source.

Is there something else I should be looking at?

Regards,  
Micheal

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [May 3, 2024, 11:51pm UTC](https://developer.squareup.com/forums/t/payment-tokenization-failed-in-sandbox-and-production/15280/8 "2024-05-03T23:51:51Z")

</div>

Have you searched the entire code base for the old version? 🙂

---

<div class="post-metadata">

**Author:** ![michealhall](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@michealhall](https://developer.squareup.com/forums/u/michealhall)\
**Post date:** [May 4, 2024, 1:08am UTC](https://developer.squareup.com/forums/t/payment-tokenization-failed-in-sandbox-and-production/15280/9 "2024-05-04T01:08:20Z")

</div>

Whatever it was, it’s working now. I was just able to complete a purchase on the live site and see the transaction in my Square Dashboard.

Hopefully it continues working! 🤞

~Micheal

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [May 6, 2024, 12:16pm UTC](https://developer.squareup.com/forums/t/payment-tokenization-failed-in-sandbox-and-production/15280/10 "2024-05-06T12:16:53Z")

</div>

Glad to here its working as expected. 🙂
