> ## Documentation Index
> Fetch the complete documentation index at: https://docs.automate.ax/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Automate.ax automations are TypeScript programs.
> Use Bun for installation and command examples.
> Use Automate.ax for the product name and automate.ax for the package, CLI, and domain.
> Treat documented public APIs as current; do not invent transitional or deprecated names.

# Calculate Loyalty Points

> Calculates the number of points a buyer can earn from a purchase.

`square.calculateLoyaltyPoints` calculates the number of points a buyer can earn from a purchase.

## Example

```ts automations/square-calculate-loyalty-points.automation.ts theme={null}
import { automation, onDashboardRun } from "automate.ax"
import { square } from "automate.ax/square"

export default automation("Calculate Square Loyalty Points", () => {
  onDashboardRun({ title: "Calculate Square Loyalty Points" })

  square.calculateLoyaltyPoints({
    programId: "program_id",
    orderId: "RFZfrdtm3mhO1oGzf5Cx7fEMsmGZY",
    loyaltyAccountId: "79b807d2-d786-46a9-933b-918028d7a8c5",
  })
})
```

## Inputs

Every input accepts a compatible signal. It requires `LOYALTY_READ`.

| Field                    | Type             | Required | Default | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ------------------------ | ---------------- | -------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `programId`              | `string`         | Yes      | —       | The ID of the loyalty program, which defines the rules for accruing points.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `orderId`                | `string \| null` | No       | —       | The order ID for which to calculate the points. Specify this field if your application uses the Orders API to process orders. Otherwise, specify the `transaction_amount_money`.                                                                                                                                                                                                                                                                                                                                                                                                        |
| `transactionAmountMoney` | `Square.Money`   | No       | —       | The purchase amount for which to calculate the points. Specify this field if your application does not use the Orders API to process orders. Otherwise, specify the `order_id`.                                                                                                                                                                                                                                                                                                                                                                                                         |
| `loyaltyAccountId`       | `string \| null` | No       | —       | The ID of the target loyalty account. Optionally specify this field if your application uses the Orders API to process orders. If specified, the `promotion_points` field in the response shows the number of points the buyer would earn from the purchase. In this case, Square uses the account ID to determine whether the promotion's `trigger_limit` (the maximum number of times that a buyer can trigger the promotion) has been reached. If not specified, the `promotion_points` field shows the number of points the purchase qualifies for regardless of the trigger limit. |

Use the official [CalculateLoyaltyPoints reference](https://developer.squareup.com/reference/square/loyalty-api/calculate-loyalty-points) for provider field semantics and limits.

## Output

Returns the official `Square.CalculateLoyaltyPointsResponse` response as a codec-safe object. Square integer money amounts remain `bigint` values.
