  In the current era of digitization, online payment systems are attracting
considerable interest. Improving the efficiency of a payment system is
important since it has a substantial impact on revenues for businesses. A
gateway is an integral component of a payment system through which every
transaction is routed. In an online payment system, payment processors
integrate with these gateways by means of various configurations such as
pricing, methods, risk checks, etc. These configurations are called terminals.
Each gateway can have multiple terminals associated with it. Routing a payment
transaction through the best terminal is crucial to increase the probability of
a payment transaction being successful. Machine learning (ML) and artificial
intelligence (AI) techniques can be used to accurately predict the best
terminals based on their previous performance and various payment-related
attributes. We have devised a pipeline consisting of static and dynamic
modules. The static module does the initial filtering of the terminals using
static rules and a logistic regression model that predicts gateway downtimes.
Subsequently, the dynamic module computes a lot of novel features based on
success rate, payment attributes, time lag, etc. to model the terminal
behaviour accurately. These features are updated using an adaptive time decay
rate algorithm in real-time using a feedback loop and passed to a random forest
classifier to predict the success probabilities for every terminal. This
pipeline is currently in production at Razorpay routing millions of
transactions through it in real-time and has given a 4-6\% improvement in
success rate across all payment methods (credit card, debit card, UPI, net
banking). This has made our payment system more resilient to performance drops,
which has improved the user experience, instilled more trust in the merchants,
and boosted the revenue of the business.
