@bates-solutions/squareup API Reference - v3.2.0
    Preparing search index...

    Class LoyaltyService

    Loyalty service for managing Square loyalty programs

    // Create a loyalty account
    const account = await square.loyalty.createAccount({
    programId: 'PROG_123',
    phoneNumber: '+15551234567',
    });

    // Add points
    await square.loyalty.accumulatePoints(account.id, {
    points: 100,
    });

    // Redeem a reward
    await square.loyalty.redeemReward(account.id, 'REWARD_123');
    Index
    • Accumulate (add) points to a loyalty account

      Parameters

      • accountId: string

        Loyalty account ID

      • options: { idempotencyKey?: string; orderId?: string; points?: number }

        Accumulation options

      Returns Promise<LoyaltyEvent>

      Loyalty event

      // Add points from an order
      await square.loyalty.accumulatePoints('ACCT_123', {
      orderId: 'ORDER_456',
      });

      // Add points manually
      await square.loyalty.accumulatePoints('ACCT_123', {
      points: 50,
      });
    • Adjust points on a loyalty account (add or subtract)

      Parameters

      • accountId: string

        Loyalty account ID

      • points: number

        Points to add (positive) or subtract (negative)

      • Optionalreason: string

        Reason for adjustment

      • OptionalidempotencyKey: string

      Returns Promise<LoyaltyEvent>

      Loyalty event

      // Add bonus points
      await square.loyalty.adjustPoints('ACCT_123', 100, 'Birthday bonus');

      // Remove points
      await square.loyalty.adjustPoints('ACCT_123', -50, 'Points correction');
    • Calculate points that would be earned for an order

      Parameters

      • programId: string

        Loyalty program ID

      • orderId: string

        Order ID to calculate points for

      Returns Promise<number>

      Points that would be earned

      const points = await square.loyalty.calculatePoints('PROG_123', 'ORDER_123');
      console.log(`This order earns ${points} points`);
    • Create a new loyalty account

      Parameters

      • options: CreateLoyaltyAccountOptions

        Account creation options

      Returns Promise<LoyaltyAccount>

      Created loyalty account

      const account = await square.loyalty.createAccount({
      programId: 'PROG_123',
      phoneNumber: '+15551234567',
      });
    • Get a loyalty account by ID

      Parameters

      • accountId: string

        Loyalty account ID

      Returns Promise<LoyaltyAccount>

      Loyalty account details

      const account = await square.loyalty.getAccount('ACCT_123');
      console.log(`Balance: ${account.balance} points`);
    • Get the loyalty program for the current location

      Parameters

      • OptionalprogramId: string

        Optional program ID (uses main program if not provided)

      Returns Promise<LoyaltyProgram>

      Loyalty program details

      const program = await square.loyalty.getProgram();
      console.log(`Points name: ${program.terminology?.other}`);
    • Redeem a reward

      Parameters

      • accountId: string

        Loyalty account ID

      • rewardTierId: string

        Reward tier ID to redeem

      • OptionalorderId: string

        Optional order ID to apply reward to

      • OptionalidempotencyKey: string

        Covers both the create and redeem calls (the redeem key is derived from it); reuse it when retrying

      Returns Promise<{ id: string; status: string }>

      Created reward

      const reward = await square.loyalty.redeemReward(
      'ACCT_123',
      'TIER_123',
      'ORDER_456'
      );
    • Search for loyalty accounts

      Parameters

      • Optionaloptions: { cursor?: string; customerId?: string; limit?: number; phoneNumber?: string }

        Search options

      Returns Promise<{ cursor?: string; data: LoyaltyAccount[] }>

      Matching loyalty accounts

      // Find by phone number
      const accounts = await square.loyalty.searchAccounts({
      phoneNumber: '+15551234567',
      });

      // Find by customer ID
      const accounts = await square.loyalty.searchAccounts({
      customerId: 'CUST_123',
      });