Skip to content

Instantly share code, notes, and snippets.

@ramanathanrv
Last active February 15, 2017 17:35
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ramanathanrv/f244871d27d3db0f6788 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