# Payment gateway routing Payment gateway routing is the process of dynamically routing transactions between payment gateways, based on real-time data and selected parameters. To configure payment routing you must have more than one gateway account connected to Rebilly. This automation uses the [Gateway account requested](/docs/automations/event-types#gateway-account-requested) event and the [Pick gateway account](/docs/automations/action-types#pick-gateway-account) action. If you have not yet added a payment gateway, see [Add gateway account](/docs/settings/set-up-a-gateway). To configure payment routing you must have more than one gateway account connected to Rebilly. ## Set up gateway routing This process describes how to configure gateway routing. 1. Optionally, deactivate sticky gatewaysGateway routing is optimal on gateways that do not have the [sticky gateways](#sticky-gateway-accounts) option activated. If sticky gateways is active when using gateway routing, a gateway is only available to: - New payment instruments that were not used on a gateway — a sticky gateway account ID is not applied. - Payment instruments that have not completed a successful transaction on another gateway. 1. In the left navigation bar, press . 2. In the **Configuration** section, press **Gateway accounts**. 3. Select a gateway account. 4. Press **Edit gateway account**. 5. In the **Advanced configuration** section, turn on the **Advanced configuration** toggle. 6. Under **Sticky gateway account**, clear the **Activate sticky gateway** checkbox. For more information, see [Sticky gateway accounts](#sticky-gateway-accounts). 2. Create an automation on the 'gateway account requested' eventThis step describes how to create an automation that is triggered when a customer attempts to make a transaction for the first time. 1. In the left navigation bar, press . 2. In the **Rules engine** section, press **Rules engine**. 3. Press **Core events**. 4. Press the **Gateway account requested** event. 5. Press **Rule set**, then press **Create rule**. 6. In the **Name** field, enter a unique name to help differentiate between multiple rules. 7. Optionally, to add labels that help you identify the rule: In the **Labels** field, add one or more labels. 8. Optionally, to not stop further processing after this rule is executed: clear the **Stop further processing** checkbox. 3. Optionally, configure conditions that determine when a transaction is routedComplete this step to configure conditions that determine when a transaction is routed to specific gateway accounts. For example, based on certain conditions, such as: payment card attributes, bank country, currency, and so on. 1. In the **Conditions** section, clear the **No conditions** checkbox. 2. In the **Select filter** field, select the filters you want to apply. Examples: - To route based on the customer's address being in the US: Select 'Transaction > Customer > Primary address > Country' `is in` 'US - United States'. - To route based on the USD currency: Select 'Transaction > Currency' `is in` 'USD - US Dollar'. - To route based on a custom field that is created on the customer resource: [Create a custom field](/docs/settings/custom-fields#create-custom-fields), then select 'Transaction > Customer > Custom fields > 'Field name''. - To route based on whether a customer related value is not in a list of values: [Create a value list](/docs/automations/create-a-value-list#create-a-value-list), then use a similar condition to this example: 'Transaction > Customer > Primary address > Emails > Value' `is not in` 'Value list name'. - To route based on tags that are assigned to the customer: Select 'Transaction > Customer > Tags > Name' `is in` 'Tag name'. For more information, see [Tags](/docs/settings/tags). 4. Configure the action to route transactions to gateway accountsThis step describes how to configure an action to route transactions to payment gateway accounts based on the weights assigned to each gateway account and the routing algorithm. Use weights to configure the probability of a gateway being selected to process a transaction. For more information, see [Weights](#weights). 1. In the **Actions section**, press **Add action**, then select **Pick gateway account**. 2. In the **Weight algorithm** section, select the [Weighted-random](#weighted-random) or [Round-robin](#round-robin) routing algorithm. 3. In the **Weight distribution** section: - To distribute weight based on gateway account, select **Use gateway account weights**. - To distribute weight based on acquirer, select **Use acquirer weights**. 4. Assign weights to each payment gateway. To configure which payment methods are displayed to the customer at payment, based on their geographic location, see [Display payment methods by location](/docs/settings/display-payment-methods-by-location). ## Weights This section describes the transaction routing weights that are available in Rebilly. ### Weighted-random When this rule is activate, a transaction is randomly assigned to a gateway account based on the specified weighted distribution. Gateways with higher weight values have a higher chance of getting selected. For example, 4 gateway accounts are set as follows: | Value | Gateway | Chance of processing a transaction | | --- | --- | --- | | 70 | Gateway A | 70% | | 15 | Gateway B | 15% | | 10 | Gateway C | 10% | | 5 | Gateway D | 5% | ### Round-robin When this rule is activate, a transaction is randomly assigned to a gateway account based on the specified weighted distribution. Gateways with higher weight values have a higher chance of getting selected. Each time a gateway is used, it is then removed from the next round. When the last gateway is used, and no other gateways remain, the process begins again. For example, 4 gateway accounts are set as follows, and the same payment instrument carries out transactions over a period of time: #### Round one | Value | Gateway | Chance of processing a transaction | | --- | --- | --- | | 70 | Gateway A | 70% | | 15 | Gateway B | 15% | | 10 | Gateway C | 10% | | 5 | Gateway D | 5% | #### Round two | Value | Gateway | Chance of processing a transaction | | --- | --- | --- | | 15 | Gateway B | 49.98 | | 10 | Gateway C | 33.33% | | 5 | Gateway D | 16.66% | #### Round three | Value | Gateway | Chance of processing a transaction | | --- | --- | --- | | 10 | Gateway C | 66.66% | | 5 | Gateway D | 33.33% | #### Round four | Value | Gateway | Chance of processing a transaction | | --- | --- | --- | | 5 | Gateway D | 100% | #### Round five | Value | Gateway | Chance of processing a transaction | | --- | --- | --- | | 70 | Gateway A | 70% | | 15 | Gateway B | 15% | | 10 | Gateway C | 10% | | 5 | Gateway D | 5% | ## Sticky gateway accounts By default, Rebilly assigns a sticky gateway account ID to a payment instrument when it performs an approved transaction on a payment gateway. On first use, the selection of this payment gateway is random. From this point on, the sticky gateway account ID is used to bind the payment instrument to that particular payment gateway, so that all future payments are processed by the same payment gateway. When gateway payment routing is active: - If the payment instrument does not have a sticky gateway account ID: The rules engine evaluates the transaction and finds the best gateway account to process the transaction. -Or- - If a payment instrument has a sticky gateway account ID assigned: The associated gateway is selected to process the transaction. ## Further reading - [Set up a payment gateway](/docs/settings/manage-payment-gateways) - [Manage payment gateways](/docs/settings/manage-payment-gateways) - [Events](/docs/automations/event-types) - [Actions](/docs/automations/action-types) - [Payment gateways](/docs/settings/payment-gateway)