Customer API Best Practices

Applies to: Customers API | Cards API | Web Payments SDK | In-App Payments SDK | Payments API

Learn about the best practices for creating an application that manages a seller's customer roster using the Customers API.

Link to section

Overview

To be listed in the Square App Marketplace, applications must meet specific requirements aligned with the best practices outlined in this guide. While optional for apps not intended for the App Marketplace, following these practices will help you build more reliable and valuable solutions for Square sellers.

Note

These best practices complement, but don't replace, the comprehensive documentation available in the Customers API documentation.

Link to section

Core requirements

The following requirements outline the essential implementations for managing customer data, processing payments, and storing card information. They're designed to prevent data inconsistencies, ensure accurate payment attribution, and uphold PCI compliance. Each requirement includes links to the relevant API documentation for further guidance.

Link to section

Customer data management

Link to section

Unique customer records

Duplicate customers in the seller's roster can present challenges to their business and must be addressed manually by the seller or with the help of Square technical support. To avoid creating duplicate customers, you should:

  • Use unique identifiers (an email or phone number is recommended) when creating customers.
  • Implement logic to detect and prevent duplicate entries for the same customer.

For more information, see Create customer profiles.

Link to section

Payment integration

Linking a payment to the customer who made it improves the accuracy of sales reporting and ensures that refunds are issued to the correct individual when needed.

Link to section

Customer ID integration

  • Always supply the correct customer_id when making payment-related API calls.
  • This applies to:
    • The Reader SDK.
    • The Point of Sale API.
    • Payment-related APIs.

For more information, see CreatePayment.

Link to section

Card-on-file requirements

Link to section

Terms of service requirements

  • Provide explicit Terms of Service/Privacy Policy stating the storage of credit card information.

For more information, see Cards API.

Link to section

Customer consent

  • Implement a checkbox mechanism to acquire customer consent for storing credit card details.
  • Ensure that consent is clearly documented and stored.

For more information, see Cards API.

Link to section

Implementation guidelines

The following code examples and patterns demonstrate the correct implementation of customer creation and payment processing. Each section includes sample JSON payloads, required fields, and validation steps. Follow these patterns to ensure reliable customer data management and payment attribution.

Link to section

Creating customers

Before creating a new customer, check to see whether a customer already exists with that email address or phone number. For more information see, Create customer profiles.

Link to section

Unique key implementation

{ "customer": { "email_address": "[email protected]", "phone_number": "+1-555-555-0123", "given_name": "John", "family_name": "Doe" }, "idempotency_key": "unique_idempotency_key" }
  • Use an email address or phone number as a unique identifier.
  • Always include idempotency keys in create requests.
  • Validate contact information before submission.
Link to section

Payment integration

When processing payments, include the customer_id in your CreatePayment request. This is required for card-on-file payments and recommended for all other payment types. Without a customer_id, Square attempts to match the customer using an email or phone number or creates a new customer record if no match is found.

Link to section

Customer ID usage

{ "source_id": "card_nonce_or_token", "customer_id": "CUSTOMER_ID", "amount_money": { "amount": 1000, "currency": "USD" } }
  • Include customer_id in all payment requests when available.
  • Validate that customer_id exists before making payment calls.
  • Handle cases where customer_id might be invalid.
Link to section

Best practices by feature

This section details specific implementation patterns for key API features. Each feature includes code-level considerations and common pitfalls to avoid. These practices are based on real integration scenarios and help prevent issues like duplicate customer records or incomplete card storage compliance.

Link to section

Card on file

Implementing card-on-file storage requires specific consent mechanisms and privacy policy components to maintain PCI compliance and protect customer data.

Link to section

Consent implementation

  • Display a clear consent checkbox.
  • Store consent records.
  • Include a consent timestamp.
  • Link to the Terms of Service.
Link to section

Privacy policy requirements

  • Clearly state your card storage policy.
  • Describe how customer data will be used.
  • Outline your data retention policies.
  • Explain customers’ rights and control over their data.
Link to section

Customer data management

Poor customer data management leads to duplicate records, which breaks customer-based reporting, complicates Point of Sale lookups, and causes redundant customer notifications.

Link to section

Duplicate prevention

  • Check for existing customers before creating new records.
  • Use reference keys to link customers with external systems.
  • Implement strategies to merge duplicate customer records.
  • Perform regular data cleanup to maintain accuracy and consistency.
Link to section

Troubleshooting guide

This guide addresses common integration issues related to customer data integrity and payment processing. Each issue includes identifiable symptoms, step-by-step resolution instructions, and code examples that illustrate effective error handling and recovery strategies.

Link to section

Common issues

Link to section

Duplicate customer records

  • Symptom: Multiple records for same customer.
  • Resolution:
    1. Search for existing customers using email and phone number before creating a new record.
    2. Use idempotency keys to prevent accidental duplicates.
    3. Implement functionality to merge duplicate records when identified.
Link to section

Invalid customer IDs

  • Symptom: Payment failures due to customer_id issues.
  • Resolution:
    1. Validate the customer_id before using it in requests.
    2. If validation fails, implement a retry mechanism that includes a customer lookup.
    3. Gracefully handle cases where the customer_id is expired or invalid, with appropriate error messaging and fallback logic.
Link to section

Monitoring recommendations

Monitor key metrics and error patterns to ensure reliable customer operations and quickly detect integration issues. Each metric offers valuable insights into system health and API performance. Set up alerts for anomalies—particularly those related to customer creation and payment processing—to enable fast response and resolution.

Link to section

Key metrics

Link to section

Customer creation

  • Success rate
  • Duplicate detection rate
  • Error rates by type
Link to section

Payment integration

  • Customer ID validation success
  • Card-on-file usage rates
  • Consent-tracking metrics
Link to section

Error tracking

Link to section

Priority errors

  • Customer creation failures
  • Payment integration issues
  • Consent-recording failures
Link to section

Response time

  • API latency monitoring
  • Error resolution time
  • Customer lookup performance