Applies to: Web Payments SDK | Payments API
Learn to use the Square Web Payments SDK to accept online payments by card, Apple Pay, Google Pay, and ACH bank transfer.
This guide walks you through integrating online payments using the Square Web Payments SDK. It covers credit and debit cards, digital wallets (Apple Pay and Google Pay), and ACH bank transfers.
The SDK converts sensitive payment data into a single-use token on the client side. Your server never handles raw card numbers or bank details. Pass the resulting payment token as source_id to the Payments API.

You need the following:
- A Square Developer account.
- An application ID and location ID from the Square Developer Dashboard.
- HTTPS, which is required as of October 1, 2025.
- Content Security Policy (CSP) headers configured to allow Square domains.
- A backend service to receive tokens and call the Square Payments API.
This client-side setup is shared by all payment methods in this guide.
Include the Web Payments SDK in your HTML:
<script async src="https://web.squarecdn.com/v1/square.js"></script>
Initialize the SDK:
const payments = Square.payments(APPLICATION_ID, LOCATION_ID);
Important
The script URL and API request examples in this guide use the production environment. For testing, use the Sandbox script, API endpoint, and matching credentials described in Test your integration. Keep access tokens on your server, not in client-side code.
The examples below show individual integration steps, not a complete application. Run initialization code after the SDK has loaded and the relevant HTML elements are available. Implement sendTokenToServer() in your application to send the payment token to your backend.
Add the card container and payment button to your HTML:
<div id="card-container"></div> <button id="card-button">Pay</button>
Create and attach the card form:
const card = await payments.card(); await card.attach('#card-container');
Tokenize the payment information when the buyer submits the form:
document.getElementById('card-button').addEventListener('click', async () => { const verificationDetails = { amount: '10.00', billingContact: { givenName: 'John', familyName: 'Doe', email: '[email protected]', phone: '5551234567', addressLines: ['123 Main St'], city: 'San Francisco', state: 'CA', countryCode: 'US', }, currencyCode: 'USD', intent: 'CHARGE', customerInitiated: true, sellerKeyedIn: false, }; const tokenResult = await card.tokenize(verificationDetails); if (tokenResult.status === 'OK') { // Send tokenResult.token to your backend. await sendTokenToServer(tokenResult.token); } });
Note
The verificationDetails object triggers buyer verification, such as 3D
Secure (3DS) or Strong Customer Authentication (SCA), when required. The buyer
information in this example is illustrative. Collect the buyer's details
rather than hard-coding them in production.
Before adding Apple Pay:
- Register and verify your domain in the Square Developer Dashboard under Apple Pay settings.
- Place the
.well-known/apple-developer-merchantid-domain-associationfile in your public directory.
Add the Apple Pay button to your HTML:
<button id="apple-pay-button"></button>
Create a payment request and initialize Apple Pay:
const paymentRequest = payments.paymentRequest({ countryCode: 'US', currencyCode: 'USD', total: { amount: '1.00', label: 'Total' }, }); const applePay = await payments.applePay(paymentRequest);
Tokenize the payment information in the button's click handler:
document .getElementById('apple-pay-button') .addEventListener('click', async (event) => { event.preventDefault(); const tokenResult = await applePay.tokenize(); if (tokenResult.status === 'OK') { await sendTokenToServer(tokenResult.token); } });
Important
Apple requires you to call tokenize() directly inside the button's click
handler. Don't perform asynchronous operations, such as API calls, before
calling tokenize().
Your integration must comply with the Google Pay API Terms of Service and brand guidelines.
Add a container for the Google Pay button to your HTML:
<div id="google-pay-button"></div>
Create a payment request, initialize Google Pay, and attach the button:
const paymentRequest = payments.paymentRequest({ countryCode: 'US', currencyCode: 'USD', total: { amount: '1.00', label: 'Total' }, }); const googlePay = await payments.googlePay(paymentRequest); await googlePay.attach('#google-pay-button');
Tokenize the payment information:
document .getElementById('google-pay-button') .addEventListener('click', async () => { const tokenResult = await googlePay.tokenize(); if (tokenResult.status === 'OK') { await sendTokenToServer(tokenResult.token); } });
Important
For Apple Pay and Google Pay, call tokenize() without the card-specific
verificationDetails argument. Successful wallet tokenization doesn't
guarantee that buyer verification ran for every integration. Follow the
buyer-verification guidance in Apple Pay and
Google Pay, including a separate
payments.verifyBuyer() step when required. In that flow, verify the buyer
after successful tokenization and before creating the payment. Send the
returned verification token along with the payment token to your server, and
include it as verification_token in the CreatePayment request. The wallet
examples above show tokenization only, not the separate verification step.
ACH bank transfers have the following limitations:
- They're available in the United States only.
- Settlements take 2–3 business days.
- They use Plaid for instant bank account verification.
Add form fields to collect the buyer's identity, which is required for ACH:
<form id="ach-form"> <fieldset> <label for="ach-given-name">First name</label> <input id="ach-given-name" type="text" autocomplete="given-name" name="givenName" required /> <label for="ach-family-name">Last name</label> <input id="ach-family-name" type="text" autocomplete="family-name" name="familyName" required /> </fieldset> <button id="ach-button" type="submit">Pay with Bank Account</button> <p id="ach-status" role="status"></p> </form>
Initialize the ACH payment method without options. The SDK generates a transaction ID when you don't provide one:
const ach = await payments.ach();
Note
ACH doesn't have an attach() method. Calling tokenize() starts the Plaid
bank authentication flow.
Register an ontokenization listener once, after initializing ach, to receive the payment token after the buyer authorizes their bank account through Plaid. Read the buyer's first and last names from the form, validate them, and pass the combined name to tokenize() to start authorization.
const achStatus = document.getElementById('ach-status'); // Register this listener once, before starting tokenization. ach.addEventListener('ontokenization', async (event) => { const { tokenResult, error } = event.detail; if (error) { achStatus.textContent = "We couldn't authorize your bank account. Try again."; return; } if (tokenResult?.status !== 'OK' || !tokenResult.token) { achStatus.textContent = "We couldn't generate a payment token. Try again."; return; } try { await sendTokenToServer(tokenResult.token); achStatus.textContent = 'Payment submitted. Check its status before confirming completion.'; } catch { achStatus.textContent = "We couldn't confirm the payment result. Check its status before retrying."; } }); const achForm = document.getElementById('ach-form'); achForm.addEventListener('submit', async (event) => { event.preventDefault(); achStatus.textContent = ''; if (!achForm.reportValidity()) { return; } const formData = new FormData(achForm); const givenName = String(formData.get('givenName') ?? '').trim(); const familyName = String(formData.get('familyName') ?? '').trim(); if (!givenName || !familyName) { achStatus.textContent = 'Enter your first and last name.'; return; } try { // Starts Plaid authorization. The token arrives in ontokenization. await ach.tokenize({ accountHolderName: `${givenName} ${familyName}`, intent: 'CHARGE', amount: '10.00', currency: 'USD', }); } catch { achStatus.textContent = "We couldn't start bank authorization. Try again."; } });
sendTokenToServer() must reject unsuccessful backend responses so the event listener can report an unconfirmed payment result. ACH submission doesn't mean the payment is complete; track its final status on your server.
Each payment method produces a token that you pass as source_id to the CreatePayment endpoint:
POST https://connect.squareup.com/v2/payments
Set SQUARE_ACCESS_TOKEN in your server environment to the access token for the environment you're using. Don't put the token in client-side code or commit it to source control.
The following example creates a $10.00 USD payment:
curl https://connect.squareup.com/v2/payments \ -X POST \ -H 'Square-Version: 2026-01-22' \ -H "Authorization: Bearer ${SQUARE_ACCESS_TOKEN}" \ -H 'Content-Type: application/json' \ -d '{ "idempotency_key": "UNIQUE_KEY_PER_UNIQUE_PAYMENT_REQUEST", "source_id": "TOKEN_FROM_FRONTEND", "amount_money": { "amount": 1000, "currency": "USD" }, "autocomplete": true }'
Use the following required fields:
| Field | Description |
|---|---|
source_id | The payment token from the client-side SDK. |
idempotency_key | A unique string, such as a UUID, for each new payment request. Reuse the same key when retrying that request to prevent duplicate charges. |
amount_money.amount | The amount in the currency's smallest denomination. For example, 1000 is $10.00 USD. |
amount_money.currency | The ISO 4217 currency code. |
Important
Keep the payment amount and currency consistent between client-side tokenization and the server-side payment request. The card and ACH examples use $10.00 USD; the Apple Pay and Google Pay examples use $1.00 USD. Adjust the server-side amount to match the payment you're creating.
To authorize a payment without immediately capturing funds, set autocomplete to false in the CreatePayment request:
curl https://connect.squareup.com/v2/payments \ -X POST \ -H 'Square-Version: 2026-01-22' \ -H "Authorization: Bearer ${SQUARE_ACCESS_TOKEN}" \ -H 'Content-Type: application/json' \ -d '{ "idempotency_key": "UNIQUE_KEY_PER_UNIQUE_PAYMENT_REQUEST", "source_id": "TOKEN_FROM_FRONTEND", "amount_money": { "amount": 1000, "currency": "USD" }, "autocomplete": false }'
The response includes a payment with the status APPROVED. Use the payment's id in subsequent requests.
For online (card-not-present) payments, the authorization hold lasts 7 days by default. To shorten the default authorization period, set delay_duration to at least 1 minute and less than 7 days.
To capture the authorized payment, replace PAYMENT_ID with the payment's id and call CompletePayment:
curl https://connect.squareup.com/v2/payments/PAYMENT_ID/complete \ -X POST \ -H "Authorization: Bearer ${SQUARE_ACCESS_TOKEN}" \ -H 'Content-Type: application/json'
To cancel the authorized payment, call CancelPayment:
curl https://connect.squareup.com/v2/payments/PAYMENT_ID/cancel \ -X POST \ -H "Authorization: Bearer ${SQUARE_ACCESS_TOKEN}" \ -H 'Content-Type: application/json'
If you don't complete or cancel the payment within the hold period, Square cancels it by default. To capture the payment automatically when the authorization period expires, set delay_action to COMPLETE. This option is supported only when the CreatePayment request doesn't explicitly specify an order_id.
Important
ACH payments don't support delayed capture. For ACH payments, set
autocomplete to true.
For more information, see Delayed capture of a card payment.
Use CreatePayment to record payments that weren't processed through Square. Set source_id to CASH or EXTERNAL instead of a payment token.
Note
Cash and external payments are for bookkeeping only. Square doesn't deposit these payment proceeds into the seller's Square account.
{ "idempotency_key": "UNIQUE_KEY_PER_UNIQUE_PAYMENT_REQUEST", "source_id": "CASH", "amount_money": { "amount": 1000, "currency": "USD" }, "cash_details": { "buyer_supplied_money": { "amount": 2000, "currency": "USD" } } }
The API calculates change_back_money in the response.
For more information, see Cash payments.
The following example records a payment processed by a third-party processor or delivery service:
{ "idempotency_key": "UNIQUE_KEY_PER_UNIQUE_PAYMENT_REQUEST", "source_id": "EXTERNAL", "amount_money": { "amount": 5000, "currency": "USD" }, "external_details": { "type": "OTHER", "source": "Food Delivery Service", "source_fee_money": { "amount": 500, "currency": "USD" } } }
For more information, see External payments.
- Open the Square Developer Dashboard.
- Select your application and switch to Sandbox mode.
- Copy your Sandbox application ID, access token, and location ID.
- API base URL:
https://connect.squareupsandbox.com. - SDK script URL:
https://sandbox.web.squarecdn.com/v1/square.js. - Initialize the SDK with your Sandbox application ID and location ID.
Use the current test values in Sandbox payment testing to test successful card payments, declined cards, and CVV checks. That reference provides the supported card numbers and the special input values for each scenario. Use Sandbox test values, not real payment card information.
- Apple Pay: Register a Sandbox domain in the Square Developer Dashboard under Apple Pay settings.
- Google Pay: Use your Sandbox credentials.
Use the Plaid Sandbox flow. You don't need a real bank connection.
- For an immediately captured card payment, confirm that the payment status is
COMPLETED. - ACH payments initially return
PENDING. Subscribe topayment.updatedwebhook events to track the final result. - Confirm that payments appear under Transactions in the Square Developer Dashboard.
| Issue | What to check |
|---|---|
| Missing HTTPS | The SDK requires HTTPS. Check the URL and certificate for your payment page. |
| Duplicate charges | Generate a unique idempotency_key for each new payment. Reuse that key when retrying the same request. |
| Amount mismatch | For USD, client-side tokenization uses a decimal string such as '10.00', while the Payments API uses an integer in cents, such as 1000. |
| Expired tokens | Payment tokens are single-use and short-lived. Tokenize immediately before calling your backend. |
| Apple Pay click handler | Call tokenize() directly inside the button's click handler. Don't add asynchronous operations before it. |