No announcement yet.

Problem using SocketTools to collect payment using Square API

  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem using SocketTools to collect payment using Square API

    I have a website where I'm collecting a credit card payment using Square's API.
    I'm using SocketTools to make the API calls.
    The process is straight forward.

    In sandbox mode:
    1) Put the square sandbox JS file link in the web page header.
    2) Collect the credit card info and make a request to Square using my sandbox application ID which returns a "nonce" token
    3) Send the payment amount and nonce token to my PB CGI. It sets a couple HTTP headers including my sandbox authorization key, connects to the sandbox server, and sends a JSON string.
    4) I receive a JSON string with either success or failure information

    That is all working.

    Now, I'm trying to switch to live mode.
    The process is the same, I just have to change a few things.

    1) switch out Square's sandbox JS with the live JS link in the web page header
    2) switch out the sandbox app ID with my live app ID
    3) change the auth code from sandbox to live in the HTTP header
    4) change the endpoint URL from the sandbox server to live

    When I do that, I get NOTHING in return. The Socket Tools HttpPostJson() function returns an empty string.
    My Square dashboard log shows nothing.
    Square tells me that they see the nonce request returned but nothing afterwards.
    Switching everything back to sandbox works.

    I'm stumped. I know it's several steps but it's pretty straight forward and I've double and triple checked stuff.
    Anybody have any experience with this and have an idea?

  • #2
    The request looks like this:
    nResult =   HttpPostJson(hClient, szResource, lpszJsonData, szBuffer, lpcbResult, dwOptions)
    nResult has the value of 426

    I'm not sure if that is an HTTP status code but it is, it means "Upgrade Required" but I'm not sure what that means in this case


    • #3
      Socket Tools documentation:
      Return Value
      If the function succeeds, the return value is the server result code. If the function fails, the return value is HTTP_ERROR. To get extended error information, call HttpGetLastError.

      The HTTP 426 Upgrade Required client error response code indicates that the server refuses to perform the request using the current protocol but might be willing to do so after the client upgrades to a different protocol. The server sends an Upgrade header with this response to indicate the required protocol(s).

      Are you using an HTTP connection where an HTTPS connection is required?

      Note the "sends an Upgrade header" above and this from SocketTools documentation:
      "It is common for servers to return additional information about a failed request in their response to the client. If you need to process this information, use the HTTP_POST_ERRORDATA option which causes the error message to be returned in the lpvResult buffer provided by the caller."


      • #4
        The endpoint URL I'm using is
        I'm wondering if Square requires HTTPS v.2, which SocketTools doesn't do yet.
        It would be odd that the sandbox works with HTTPS v1 but not the live server.
        I will try HTTP_POST_ERRORDATA for more information.
        Thank you