Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Rretzko's avatar
Level 15

Square in-app web payment tutorial

I'm trying to implement an in-app payment workflow using Square, hitting one problem after the next. The current issue is: "Uncaught (in promise) NotSupportedError: Failed to read the 'ready' property from 'ServiceWorkerContainer': 'ready' is only supported in pages." Simple workflow:

  1. Button to send user to Square for payment
  2. API feed back to app to register payment. Are there any step-by-step tutorials out there that you'd recommend? Thanks!
0 likes
2 replies
LaryAI's avatar
Level 58

To implement an in-app payment workflow using Square, you need to follow a series of steps to ensure that the payment process is smooth and secure. The error you're encountering, "Uncaught (in promise) NotSupportedError: Failed to read the 'ready' property from 'ServiceWorkerContainer': 'ready' is only supported in pages," suggests that there might be an issue with how the service worker is being used in your application. This error typically occurs when trying to use service workers in contexts that don't support them, such as web workers or non-page contexts.

Here's a step-by-step guide to help you set up a Square payment workflow:

Step 1: Set Up Your Square Account

  1. Create a Square Developer Account: Go to the Square Developer Portal and sign up for an account.
  2. Create an Application: Once logged in, create a new application to get your application ID and access tokens.

Step 2: Integrate Square Payment Form

  1. Include Square's Payment Form Library: Add the Square payment form library to your HTML file.

    <script type="text/javascript" src="https://js.squareup.com/v2/paymentform"></script>
    
  2. Create a Payment Form: Set up the HTML for your payment form.

    <div id="form-container">
      <div id="sq-card-number"></div>
      <div id="sq-expiration-date"></div>
      <div id="sq-cvv"></div>
      <div id="sq-postal-code"></div>
      <button id="sq-creditcard" class="button-credit-card" onclick="onGetCardNonce(event)">Pay</button>
    </div>
    
  3. Initialize the Payment Form: Use JavaScript to initialize the Square payment form.

Step 3: Handle Payment on the Server

  1. Create a Server Endpoint: Set up a server endpoint to handle the payment processing.

Step 4: Test Your Integration

  • Test in Sandbox Mode: Use Square's sandbox environment to test your payment workflow without processing real transactions.
  • Debug and Fix Errors: Ensure that your service worker is correctly set up and only used in supported contexts.

By following these steps, you should be able to set up a basic Square payment workflow in your application. Make sure to replace placeholders like YOUR_APPLICATION_ID and YOUR_ACCESS_TOKEN with your actual Square credentials.

Rretzko's avatar
Level 15

I'm unclear on the architecture of this; is all of this in one html file?

Please or to participate in this conversation.