# Spend 1 point as 1 dollar

> For the complete documentation index, see [llms.txt](https://docs.talon.one/llms.txt).

Let's create a [promotion rule](/docs/product/rules/overview.md#promotion-rules) that allows customers to pay using the points they collected. One point should equal one dollar.

## Create the coupon promotion

In the current scenario, let's use one rule and name it `1 point = $1`.

### Condition

We want the rule to redeem points _when they are used_, meaning when the customer has paid
for the order. This is represented by a [closed session](/docs/dev/concepts/entities/customer-sessions.md#customer-session-states) in Talon.One.

1. Click **Add condition** and select **Check for event type and validate custom event values**.
1. Select **Customer Session Closing**.

### Effects

The logic of the rule relies on two effects:

1. Setting the value of a point via a discount effect.
1. Redeeming points when they are used.

We have to know how many points each customer wants to use. For this, we assume that your
shop system has a way for the customers to input how many points they want to use as they
are about to place their order.

This number of points must be communicated to Talon.One,
and we do this with a [**custom attribute**](/docs/dev/concepts/attributes.md) called <Attribute name="DEMO Points to spend (Current Session)" type="custom"/>.
This custom attribute
was created for the purpose of the demo. Attributes are set during
the request to the [Update customer session][cs] endpoint.

Let's set the **Set discount** effect, which sets the value of a point:

1. Set **Discount name** to `Spending loyalty points`.
1. Set **Discount value** to <Attribute name="[Session.Attributes.PointsToSpend]" type="custom"/>.
   In other words, the discount itself is the number of points used. So for example: 12 points is a discount of $12.

The next effect redeems points as they are used by the customer:

1. Set **Loyalty program** to **Sample Wallet**, which is provided in the Demo deployment.
1. Set **Recipient** to **Current Customer**.
1. Set **Reason** to `Spending loyalty points` to identify why points were deducted.
1. Set **Amount of point** to <Attribute name="[Session.Attributes.PointsToSpend]" type="custom"/>.

## Run the campaign

To run the campaign, use the following payload sent to the Integration API's [Update customer session][cs] endpoint:

<Tabs
  defaultValue="req"
  values={[
    {label: '🚀 Request', value: 'req'},
    {label: '✅ Response', value: 'res'},
  ]}>

<TabItem value="req">

To trigger the rule, we must:

- Line 5: Send a session with a `closed` state
- Line 23: Set a value for the <Attribute name="[Session.Attributes.PointsToSpend]" type="custom"/> attribute.

```json title="Sending a session update" {5,23} showLineNumbers
CURL -X PUT https://mycompany.europe-west1.talon.one/v2/customer_sessions/my_session_id -d
'{
  "customerSession": {
    "profileId": "{{Integration_id}}",
    "state": "closed",
    "cartItems": [
      {
        "name": "ProductC",
        "sku": "sku-00004",
        "quantity": 1,
        "price": 200,
        "Category": "",
        "weight": 0,
        "position": 0,
        "attributes": {}
      }
    ],
    "couponCodes": [
      ""
    ],
    "referralCode": "",
    "attributes": {
      "PointsToSpend": 50
    },
    "additionalCosts": {}
  },
  "responseContent": []
}'
```

</TabItem>
<TabItem value="res">

We receive this response, which shows our effects in the `effects` array:

- Line 15: `deductLoyaltyPoints` represents how many points were redeemed, in our case `50`.
- Line 28: `setDiscount` represents the value of the discount, which is also `50` to match our 1:1 point-to-dollar ratio.

```json title="Response" {15,28} showLineNumbers
{
  "createdCoupons": [],
  "createdReferrals": [],
  "effects": [
    {
      "campaignId": 5,
      "rulesetId": 19,
      "ruleIndex": 0,
      "ruleName": "1 point = $1",
      "effectType": "deductLoyaltyPoints",
      "props": {
        "ruleTitle": "1 point = $1",
        "programId": 1,
        "subLedgerId": "",
        "value": 50,
        "transactionUUID": "6c629d3b-aea0-4e08-92e1-c278fa11176f",
        "name": "Spending loyalty points"
      }
    },
    {
      "campaignId": 5,
      "rulesetId": 19,
      "ruleIndex": 0,
      "ruleName": "1 point = $1",
      "effectType": "setDiscount",
      "props": {
        "name": "Spending loyalty points",
        "value": 50
      }
    }
  ]
}
```

</TabItem>
</Tabs>

:::tip Key Takeaways

- You can redeem or deduct loyalty points with the **Redeem loyalty points** effect.
- To set the value of a loyalty point, use a discount effect and use an attribute related to points in the **Discount value** field.
- Attributes, custom or not, are set in the [Update customer session][cs] requests.

:::

## Related pages

- [Loyalty Programs][lp]
- [Use conditions](/docs/product/rules/conditions/overview.md) and [effects](/docs/product/rules/effects/overview.md)

[cs]: /integration-api#tag/Customer-sessions/operation/updateCustomerSessionV2
[lp]: /docs/product/loyalty-programs/overview.md
