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

# JS SDK: Record Sales Transactions and Reward Partners

> Call kiflo('transaction', ...) when a sale occurs to record the transaction in Kiflo and automatically trigger the correct partner reward.

Call `kiflo('transaction', ...)` each time a sale or payment is completed. Kiflo links the transaction to the customer who made it, traces that customer back to their referring partner, and triggers any reward or commission rules you have configured. Recording transactions is what enables revenue-share and commission-based partner programs in Kiflo.

## Syntax

```javascript theme={null}
kiflo('transaction', {
  // transactionObject
},
function(response) {
  // handle success
},
function(error) {
  // handle error
});
```

Both callback functions are optional — omit them if you do not need to react to the result.

## Example

```javascript theme={null}
kiflo('transaction', {
  currency: 'USD',
  properties: {
    name: 'Invoice_2024_001',
    amount: 255.00,
    // your custom transaction properties
  },
  customer: {
    email: 'john.doe@example.com'
  }
},
function(response) {
  // handle success
},
function(error) {
  // handle error
});
```

## Parameters

### TransactionObject

<ParamField body="currency" type="string" required>
  The currency of the transaction as an [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code (e.g., `"USD"`, `"EUR"`, `"JPY"`). All amounts in `properties` are interpreted in this currency.
</ParamField>

<ParamField body="properties" type="object" required>
  The properties of the transaction as configured in your Kiflo [account properties](https://app.kiflo.com/account/properties). Both `name` and `amount` are required inside this object.

  ```json theme={null}
  {
    "name": "Invoice_2024_001",
    "amount": 255.00,
    "plan": "pro"
  }
  ```

  | Field               | Type   | Description                                                                 |
  | ------------------- | ------ | --------------------------------------------------------------------------- |
  | `name` (required)   | string | A unique name or identifier for this transaction (e.g., an invoice number). |
  | `amount` (required) | number | The transaction amount in the specified currency.                           |
</ParamField>

<ParamField body="customer" type="object" required>
  Identifies the customer associated with this transaction so Kiflo can look up their partner attribution. Pass at least one identifying property — typically `email` — that matches the customer record already in Kiflo.

  ```json theme={null}
  {
    "email": "john.doe@example.com"
  }
  ```
</ParamField>

## Automating transaction creation

For most production setups, you will not want to call `kiflo('transaction', ...)` manually on a client-side confirmation page. Instead, trigger transaction recording automatically from your payment provider:

* **Stripe, Recurly, Chargify, Chargebee** — use Kiflo's native payment provider integrations to create transactions automatically whenever a payment succeeds, without writing any additional code.
* **Webhooks / custom backends** — call the [Kiflo REST API](https://docs-api.kiflo.com) from your server when your payment provider fires a webhook, passing the same `currency`, `properties`, and `customer` fields.

<Note>
  The customer referenced in the `customer` field must already exist in Kiflo (created via [`kiflo('customer', ...)`](/developers/js-sdk/create-customer) or the REST API). Kiflo uses the customer record to find the originating partner and apply the correct reward.
</Note>

<Tip>
  Using the client-side JS call on a purchase-confirmation page is a quick way to get started. Migrate to a server-side webhook integration before going to production to avoid missed transactions if a user closes their browser before the confirmation page loads.
</Tip>
