Aggregations
Count, sum, and list your past payments in a rule condition, with every filter, time period, function, and field the builder offers.
An aggregation reads your past payments and returns one value for the payment being evaluated, such as the number of cards used from its IP address in the last hour. Build one in a rule condition as a Custom Aggregation, or save it in Rule Inputs and pick it as an Aggregated Field. To do arithmetic with aggregations, such as dividing declines by approvals, use a calculated field.
Build a custom aggregation
Build the aggregation inside a rule condition:
- 1
Open the builder
In the rule's Logic section, set the condition's field type to Custom Aggregation and click Build custom aggregation.
- 2
Pick the transactions
Under From all the transactions with, add the fields that past payments share with this payment, or the values they match. See Choose the transactions.
- 3
Set the time period
Choose Last, Since the start of, or All time. See Time period.
- 4
Choose a function and a field
Choose the Function, then the field it reads in Of field. See Functions.
- 5
Use it
Click Use Custom Aggregation. To reuse the aggregation in other rules, check Save in Aggregation Fields first, then click Use Aggregated Field.
- 6
Compare it
Choose an operator and a value, for example is greater than
5.
Choose the transactions
From all the transactions with sets which past payments the aggregation reads. Add one or more fields from its list, which has two sections:
- Dimensions, such as Email or Card Country. Click a dimension to add it as Same as current, shown as a chip such as same Email. To match a value of your own instead, hover over the dimension and click Set value, or click its chip, then choose Specific value.
- Metrics · compared to a value, such as Declines. A metric always takes a value you set.
In the editor, choose the operator and the value, then click Apply. To take a field out, click Remove field or the × on its chip. A past payment counts only when it matches every field you add. Each field can be added once, and there's no limit on how many you add.
Same as current
With Same as current, a past payment counts when it has the same value as the payment being evaluated. For example, IP Address set to Same as current reads the past payments from this payment's IP address.
If the payment being evaluated has no value for the field, for example no email, the aggregation has no value and the condition doesn't match. Decline Code, CVV Check Result, AVS Address Line 1 Check Result, and AVS Postal Code Check Result don't offer Same as current. Match them with Specific value, or read them with a function.
Specific value
With Specific value, a past payment counts when its value matches the one you set:
- A dimension takes is or is not, and one value. Some dimensions, such as countries and currencies, offer a list to choose from.
- A metric takes is, is not, is greater than, is greater than
or equal, is less than, or is less than or equal, and a number of
0or more. - A text value can contain only letters, digits,
.,_,-, and@, and can't start or end with_. Values with spaces or other characters, such as a full user agent or an IPv6 address, can only be matched with Same as current. - Values are compared exactly, and text is case-sensitive, so
John@example.comandjohn@example.comare different emails.
Filter by an event
Pay.com records each event of a payment separately, such as its creation, its decline, or its approval. A metric in From all the transactions with keeps the records where that event happened:
- Declines is greater than
0keeps the declines. With Count Unique of Payment method (Card), the aggregation counts the cards that were declined. - A volume, such as Approvals Volume (USD), compares the amount of each
event. Approvals Volume (USD) is greater than
500keeps the approvals over USD 500. - Use is greater than
0or is greater than or equal1to keep the payments where the event happened. is0and is less than1don't find the payments without the event, because those payments also have records from before it. - Read a metric of the same event, or a dimension. Sum of Approvals
with Declines is greater than
0is always0.
Dimensions
These dimensions can be added to From all the transactions with, and read with Get the latest, Count Unique, and List Unique:
| Dimension | What it holds | Same as current |
|---|---|---|
| Card BIN | The first 6 digits of the card number | Yes |
| Card Brand | The card brand: Visa, MasterCard, AMEX, Discover, JCB, UnionPay, or UNKNOWN | Yes |
| Card Country | The country that issued the card | Yes |
| Card Fingerprint | The fingerprint of the card number, the same for every token of one card | Yes |
| Card Type | The card's funding: DEBIT, CREDIT, PREPAID, DEFERRED_DEBIT, or UNKNOWN | Yes |
| Currency | The payment's currency | Yes |
| Customer ID | The customer_reference_id you send | Yes |
| Customer First Name | The customer's first name | Yes |
| Customer Last Name | The customer's last name | Yes |
| The customer's email address | Yes | |
| IP Address | The customer's IP address | Yes |
| Merchant ID | Your merchant ID. Aggregations read only your own payments, so it doesn't narrow them. | Yes |
| Payment Method Type | The payment method's type, such as card, applepay, googlepay, or paypal | Yes |
| Payment method (Card) | The card's token on your account. Counts cards only. | Yes |
| Payment method (Card & Wallets) | The token of a card, Apple Pay, or Google Pay payment method | Yes |
| Payment method | The token of any payment method | Yes |
| Settlement Account | The settlement account that processed the payment | Yes |
| User Agent | The customer's browser user agent | Yes |
| Shipping Country | The shipping address's country | Yes |
| Billing Country | The billing address's country | Yes |
| Decline Code | The response code from the issuer or acquirer, such as 05 or 51. It isn't the decline_code the API returns. | No |
| CVV Check Result | The CVV check: PASS, FAIL, UNAVAILABLE, or UNCHECKED | No |
| AVS Address Line 1 Check Result | The address line check, with the same values | No |
| AVS Postal Code Check Result | The postal code check, with the same values | No |
The Count and Sum fields can also be added, as metrics. See Count and Sum.
Time period
Time Period sets how far back the aggregation reads:
| Option | Reads | Notes |
|---|---|---|
| Last a number of Minute(s), Hour(s), Day(s), Week(s), or Year(s) | Payments created in that span before now | A whole number of 1 or more, with no maximum. A year is 365.25 days. There's no month unit, so use Day(s), or Since the start of Month. |
| Since the start of Day, Week, Month, or Year | Payments created since the current period started | Periods follow UTC, and weeks start on Sunday. |
| All time | Every payment recorded for your account |
A new aggregation starts with Last 1 Day(s). Pay.com places a payment in time by when the payment was created. Its decline, approval, dispute, or alert counts in the period that contains the payment's creation, not when the event happened. For example, Count of Disputes over the Last 30 Day(s) counts the disputes on payments created in the last 30 days. Refunds and payouts are placed by their own creation.
Functions
Function sets what the aggregation returns, and which fields Of field offers:
| Function | Of field | Returns |
|---|---|---|
| Count | A metric, such as Declines | The number of those events |
| Sum | A volume, such as Charges (USD) | The total amount, in major units |
| Count Unique | A dimension, such as Email | The number of different values. Empty values aren't counted. |
| Get the latest | A dimension | The value from the most recent record |
| List Unique | A dimension | The different values, as a list |
Where you build the aggregation decides which functions it offers:
- On the left side of a condition: Count, Sum, Count Unique, and Get the latest.
- On the right side, compared with a number field: the same four. Compared with a text, country, currency, option, or settlement account field: Get the latest of a dimension of the same type, such as Card Country for a country field.
- With the is in aggregation and is not in aggregation operators: List Unique only. See Match a list of past values.
- In Rule Inputs: all five.
Fields for each function
Each function reads its own set of fields.
Get the latest, Count Unique, and List Unique
These functions read the dimensions. CVV Check Result, AVS Address Line 1 Check Result, and AVS Postal Code Check Result work with Get the latest only, and skip records without a result.
Get the latest reads the most recent matching record, which can belong to the payment being evaluated. That happens when you group by a value the payment has from its creation, such as its Email or Customer ID. Its results, such as Decline Code, are still empty then, so the aggregation has no value.
Count
Count reads these metrics:
| Metric | Counts |
|---|---|
| Approvals | Approved sales and authorizations. Verifications and captures don't count. |
| Authorizations | Approved authorizations and card verifications |
| Captures | Approved captures |
| Charges | Successful charges, meaning approved sales and captures. Attempts don't count. |
| Sales | Approved sales, which authorize and capture in one step |
| Declines | Declined sales, authorizations, and verifications. Pay.com's own retries don't count. |
| Refunds | Approved refunds |
| Payouts | Approved payouts |
| Disputes | Disputes, one for each dispute on a payment |
| Collaborations | Collaborations, the pre-dispute alerts from Ethoca, Verifi CDRN, and Mastercard Collaboration |
| Domestic | Card payments with a card issued in your merchant country, regardless of outcome |
| Intraregional | Card payments with a card issued in another EEA country, when your merchant country is in the EU, regardless of outcome |
| International | Every other card payment, regardless of outcome |
| Round transactions | Approved transactions with a whole amount, such as 100.00, including verifications, refunds, and payouts |
| 3DS authenticated | Approved payments with a successful 3D Secure authentication. Exemptions don't count. |
| Non-3DS authenticated | Approved sales and authorizations without 3D Secure, or with an exemption |
| 3DS challenge | Approved payments authenticated with a challenge |
| 3DS frictionless | Approved payments authenticated without a challenge |
| 3DS failure | Payments whose 3D Secure authentication failed, regardless of outcome |
Sum
Sum adds up the amounts of a metric's events. Every metric in the Count table has volumes, except Domestic, Intraregional, International, and Round transactions. Rolling reserve has a volume only, the reserve held from your payments.
Each volume comes in three versions, shown here for Charges:
| Of field | Amount |
|---|---|
| Charges | Each payment's amount in its own currency, not converted. Payments in different currencies are added as plain numbers, so add Currency with Same as current, or use a converted version. |
| Charges (USD) | Each amount converted to US dollars when Pay.com recorded the payment, at that day's rate |
| Charges (EUR) | Each amount converted to euros the same way |
A few volumes add a different amount:
- Declines and 3DS failure add the amount requested.
- Disputes and Collaborations add the payment's amount, not the disputed amount.
- Authorizations adds the amounts of authorizations. Verifications have no amount.
- Rolling reserve isn't converted, so use its version without a currency.
Amounts are in major units, so 100 is USD 100.00. In From all the
transactions with, the same volumes are named with Volume, such as
Charges Volume (USD).
How aggregations read past payments
A few rules apply to every aggregation:
- Your own payments. An aggregation reads your account's payments, across all your settlement accounts. To read one account, add Settlement Account. Sandbox and live payments are kept apart.
- The payment being evaluated. In routing, configuration, payment, and cancel rules, Count and Sum never include the payment being evaluated. Count Unique, List Unique, and Get the latest can include the values it had when it was created, such as its email. Review and Action rules run after the payment completes, and the payment may or may not be included yet.
- No past payments. Count, Sum, and Count Unique return
0, so equals0matches a customer with no history. Get the latest has no value. List Unique returns an empty list, so is not in aggregation matches. - No value to group by. If the payment has no value for a Same as
current field, the aggregation has no value, and no operator matches it,
including equals
0. - Unavailable data. If Pay.com can't read your past payments in time, the aggregation has no value, and the condition doesn't match.
How customers and cards are counted
Aggregations count customers and cards separately:
- Customers are identified by Customer ID, which is the
customer_reference_idyou send. A payment without one gets an ID of its own, so it counts as one more customer. Sendcustomer_reference_idon every payment, or payments from the same person can't be counted together. - Cards are identified in one of four ways. Payment method (Card) is the card's token on your account, and counts cards only. Payment method (Card & Wallets) also counts Apple Pay and Google Pay. Payment method counts every payment method. Card Fingerprint is the fingerprint of the card number, the same for every token of that card.
To tie the two together, group by one and count the other. For example, to find a card used by more than one customer, group by Payment method (Card) with Same as current, and count Customer ID with Count Unique. To count one customer's use of one card, add both with Same as current.
Use an aggregation in a condition
The operators you can choose depend on what the aggregation returns:
| Returns | Functions | Operators |
|---|---|---|
| A number | Count, Sum, and Count Unique | equals, does not equal, is in, is not in, is less than, is greater than, is less than or equal, is greater than or equal |
| Text | Get the latest of a text dimension, such as Email | The text operators |
| A country, currency, option, or settlement account | Get the latest of that dimension, such as Card Country | equals, does not equal, is in, is not in, exists |
To compare a field of the payment with an aggregation, put the field on the left, and choose Aggregated Field or Custom Aggregation as the value type on the right. For example, Email does not equal Get the latest of Email, for the same Payment method (Card), finds a card used with a different email than last time.
Match a list of past values
List Unique returns the past values themselves, so a condition can check whether the payment's value is among them:
- 1
Add a List Unique aggregation
In Settings → Product Settings → Rule Inputs → Aggregations, add an aggregation with the List Unique function. The is in aggregation and is not in aggregation operators appear in the rule builder once your account has one.
- 2
Write the condition
Choose the field, such as Card token, and the operator is in aggregation or is not in aggregation. On the right, build the list with Custom Aggregation and List Unique.
The match is exact and case-sensitive. When the list is empty, is in aggregation doesn't match, and is not in aggregation does.
Save an aggregation
Saved aggregations can be reused in other rules and in calculated fields. Save one in either place:
- In the builder, check Save in Aggregation Fields and enter a Name of aggregated field. The option appears if your role can manage Rule Inputs.
- In Rule Inputs. See Aggregation fields.
If you leave the name empty, Pay.com names the aggregation from its function, field, filters, and time period. Names must be unique, ignoring case, and the same aggregation can't be saved twice. A saved aggregation can't be edited. To change one, save a new one and switch your rules to it.
Examples
Each example puts the aggregation on the left of a condition, and compares it as the last column shows:
| Goal | From all the transactions with | Time Period | Function and field | Condition |
|---|---|---|---|---|
| Card testing from one IP address | IP Address, same as current | Last 1 Hour(s) | Count Unique of Payment method (Card) | is greater than 5 |
| Declined cards from one IP address | IP Address, same as current, and Declines is greater than 0 | Last 1 Hour(s) | Count Unique of Payment method (Card) | is greater than 3 |
| One card used by several customers | Payment method (Card), same as current | Last 30 Day(s) | Count Unique of Customer ID | is greater than 1 |
| Many emails on one card number | Card Fingerprint, same as current | Last 7 Day(s) | Count Unique of Email | is greater than 2 |
| Repeated declines on a card | Payment method (Card), same as current | Last 24 Hour(s) | Count of Declines | is greater than or equal 3 |
Two declines with code 51 on a card today | Payment method (Card), same as current, and Decline Code is 51 | Since the start of Day | Count of Declines | is greater than or equal 2 |
| A customer's daily spend | Customer ID, same as current | Since the start of Day | Sum of Charges (USD) | is greater than 2000 |
| A customer's first successful charge | Customer ID, same as current | All time | Count of Charges | equals 0 |
| Frequent refunds to one email | Email, same as current | Last 30 Day(s) | Count of Refunds | is greater than or equal 3 |
| Past disputes on a card number | Card Fingerprint, same as current | All time | Count of Disputes | is greater than or equal 1 |
| Several large approvals for one customer | Customer ID, same as current, and Approvals Volume (USD) is greater than 1000 | Last 7 Day(s) | Count of Approvals | is greater than or equal 2 |
| Several billing countries for one customer | Customer ID, same as current | Last 30 Day(s) | Count Unique of Billing Country | is greater than 2 |
| Settlement account volume this month | Settlement Account, same as current | Since the start of Month | Sum of Charges (EUR) | is greater than 100000 |
Two more patterns compare the payment with its own history:
- A card the customer paid with before. Card token is in
aggregation, with List Unique of Payment method (Card) for the same
Customer ID, with Approvals is greater than
0, over the Last 90 Day(s). In a payment rule, is not in aggregation can require 3D Secure for a card the customer hasn't paid with before. - A larger amount than usual. Amount (in USD) is greater than a
calculated field that divides the customer's Sum of Charges (USD) by
their Count of Charges, times
3. See Calculated fields.
Next steps
- Calculated fields: Divide, multiply, and add aggregations and number fields.
- Rule conditions: Every field and operator.
- Rule inputs: Save aggregations to reuse them.
- Payment rules: Block or authenticate payments that match.