Skip to Content
Docs

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. 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. 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. 3

    Set the time period

    Choose Last, Since the start of, or All time. See Time period.

  4. 4

    Choose a function and a field

    Choose the Function, then the field it reads in Of field. See Functions.

  5. 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. 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 0 or 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.com and john@example.com are 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 0 keeps 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 500 keeps the approvals over USD 500.
  • Use is greater than 0 or is greater than or equal 1 to keep the payments where the event happened. is 0 and is less than 1 don'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 0 is always 0.

Dimensions

These dimensions can be added to From all the transactions with, and read with Get the latest, Count Unique, and List Unique:

DimensionWhat it holdsSame as current
Card BINThe first 6 digits of the card numberYes
Card BrandThe card brand: Visa, MasterCard, AMEX, Discover, JCB, UnionPay, or UNKNOWNYes
Card CountryThe country that issued the cardYes
Card FingerprintThe fingerprint of the card number, the same for every token of one cardYes
Card TypeThe card's funding: DEBIT, CREDIT, PREPAID, DEFERRED_DEBIT, or UNKNOWNYes
CurrencyThe payment's currencyYes
Customer IDThe customer_reference_id you sendYes
Customer First NameThe customer's first nameYes
Customer Last NameThe customer's last nameYes
EmailThe customer's email addressYes
IP AddressThe customer's IP addressYes
Merchant IDYour merchant ID. Aggregations read only your own payments, so it doesn't narrow them.Yes
Payment Method TypeThe payment method's type, such as card, applepay, googlepay, or paypalYes
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 methodYes
Payment methodThe token of any payment methodYes
Settlement AccountThe settlement account that processed the paymentYes
User AgentThe customer's browser user agentYes
Shipping CountryThe shipping address's countryYes
Billing CountryThe billing address's countryYes
Decline CodeThe response code from the issuer or acquirer, such as 05 or 51. It isn't the decline_code the API returns.No
CVV Check ResultThe CVV check: PASS, FAIL, UNAVAILABLE, or UNCHECKEDNo
AVS Address Line 1 Check ResultThe address line check, with the same valuesNo
AVS Postal Code Check ResultThe postal code check, with the same valuesNo

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:

OptionReadsNotes
Last a number of Minute(s), Hour(s), Day(s), Week(s), or Year(s)Payments created in that span before nowA 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 YearPayments created since the current period startedPeriods follow UTC, and weeks start on Sunday.
All timeEvery 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:

FunctionOf fieldReturns
CountA metric, such as DeclinesThe number of those events
SumA volume, such as Charges (USD)The total amount, in major units
Count UniqueA dimension, such as EmailThe number of different values. Empty values aren't counted.
Get the latestA dimensionThe value from the most recent record
List UniqueA dimensionThe 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:

MetricCounts
ApprovalsApproved sales and authorizations. Verifications and captures don't count.
AuthorizationsApproved authorizations and card verifications
CapturesApproved captures
ChargesSuccessful charges, meaning approved sales and captures. Attempts don't count.
SalesApproved sales, which authorize and capture in one step
DeclinesDeclined sales, authorizations, and verifications. Pay.com's own retries don't count.
RefundsApproved refunds
PayoutsApproved payouts
DisputesDisputes, one for each dispute on a payment
CollaborationsCollaborations, the pre-dispute alerts from Ethoca, Verifi CDRN, and Mastercard Collaboration
DomesticCard payments with a card issued in your merchant country, regardless of outcome
IntraregionalCard payments with a card issued in another EEA country, when your merchant country is in the EU, regardless of outcome
InternationalEvery other card payment, regardless of outcome
Round transactionsApproved transactions with a whole amount, such as 100.00, including verifications, refunds, and payouts
3DS authenticatedApproved payments with a successful 3D Secure authentication. Exemptions don't count.
Non-3DS authenticatedApproved sales and authorizations without 3D Secure, or with an exemption
3DS challengeApproved payments authenticated with a challenge
3DS frictionlessApproved payments authenticated without a challenge
3DS failurePayments 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 fieldAmount
ChargesEach 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 equals 0 matches 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_id you send. A payment without one gets an ID of its own, so it counts as one more customer. Send customer_reference_id on 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:

ReturnsFunctionsOperators
A numberCount, Sum, and Count Uniqueequals, does not equal, is in, is not in, is less than, is greater than, is less than or equal, is greater than or equal
TextGet the latest of a text dimension, such as EmailThe text operators
A country, currency, option, or settlement accountGet the latest of that dimension, such as Card Countryequals, 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. 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. 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:

GoalFrom all the transactions withTime PeriodFunction and fieldCondition
Card testing from one IP addressIP Address, same as currentLast 1 Hour(s)Count Unique of Payment method (Card)is greater than 5
Declined cards from one IP addressIP Address, same as current, and Declines is greater than 0Last 1 Hour(s)Count Unique of Payment method (Card)is greater than 3
One card used by several customersPayment method (Card), same as currentLast 30 Day(s)Count Unique of Customer IDis greater than 1
Many emails on one card numberCard Fingerprint, same as currentLast 7 Day(s)Count Unique of Emailis greater than 2
Repeated declines on a cardPayment method (Card), same as currentLast 24 Hour(s)Count of Declinesis greater than or equal 3
Two declines with code 51 on a card todayPayment method (Card), same as current, and Decline Code is 51Since the start of DayCount of Declinesis greater than or equal 2
A customer's daily spendCustomer ID, same as currentSince the start of DaySum of Charges (USD)is greater than 2000
A customer's first successful chargeCustomer ID, same as currentAll timeCount of Chargesequals 0
Frequent refunds to one emailEmail, same as currentLast 30 Day(s)Count of Refundsis greater than or equal 3
Past disputes on a card numberCard Fingerprint, same as currentAll timeCount of Disputesis greater than or equal 1
Several large approvals for one customerCustomer ID, same as current, and Approvals Volume (USD) is greater than 1000Last 7 Day(s)Count of Approvalsis greater than or equal 2
Several billing countries for one customerCustomer ID, same as currentLast 30 Day(s)Count Unique of Billing Countryis greater than 2
Settlement account volume this monthSettlement Account, same as currentSince the start of MonthSum 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

Was this page helpful?