Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sengupta/b0452291154ff851d4af2391c7a401d0 to your computer and use it in GitHub Desktop.
Save sengupta/b0452291154ff851d4af2391c7a401d0 to your computer and use it in GitHub Desktop.
Routing Logic for choosing the best gateway to handle your transaction
// WARNING: This code is a sample to test your logic of gateway priority. This is NOT to be used as such.
def order = [order_id: "ord_id", amount: 1000.00, udf1:"web", udf2: "desktop", gateway_id: 2]
def txn = [txn_id: "txn_id", express_checkout: true, add_to_locker: false ]
def payment = [card_isin: "524368", card_issuer: "HDFC Bank", card_type: "CREDIT"]
def setGatewayPriority = { gateways ->
println "priority: " + gateways;
}
def channelRouter = { order, txn, payment ->
def priorities = ["HDFC", "ICICI", "PAYU"] // if udf1 is not set
if (order.udf1 == "web") {
priorities = ["HDFC","PAYU","ICICI"]
}
else if (order.udf1 == "mobile" && order.udf2 == "android")
priorities = ["ICICI","HDFC","PAYU"]
}
setGatewayPriority(priorities)
}
def volumeRouter = { order, txn, payment->
def priorities = []
// def myGateways = ["HDFC","ICICI"]
// 50% approx split between two gateways
setGatewayPriority(shuffle(['HDFC', 'ICICI']))
// def myGateways = ["HDFC","ICICI", "AXIS"]
// 1/3 split between three gateways
setGatewayPriority(shuffle(['HDFC', 'ICICI', "AXIS"]))
// def myGateways = ["HDFC","ICICI", "AXIS"]
// 1/2 split between two gateways and use third as backup
setGatewayPriority(shuffle(['HDFC', 'ICICI']), "AXIS"])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment