Skip to content

Commit

Permalink
added python sdk to branch-first version commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashish Kumar committed Sep 1, 2020
1 parent ee672c7 commit d55c5a3
Show file tree
Hide file tree
Showing 1,049 changed files with 159,058 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pythonSDK/PayU/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

from payu.base import payubase

from payu.payuClient import payUClient
from payu.resources.hasher import Hasher
Binary file added pythonSDK/PayU/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file added pythonSDK/PayU/__pycache__/payuClient.cpython-37.pyc
Binary file not shown.
51 changes: 51 additions & 0 deletions pythonSDK/PayU/__test__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import unittest
import payu

'# Please Note below:'
'# 1). key (i.e. gtKFFx) is testing key, you need to put your own production key before going live'
'# 2). udf1 to udf5 are optional values (i.e. you pass user defined values to these fields e.g. street name, city, address etc.'
'# 3). You should always validate hash after transaction response at your success-failure urls'
'# 4). For more info, please follow document from here : https://github.com/payu-intrepos/Documentations/wiki/Server-Side '



parameters = {"key": "gtKFFx", "txnid": "20200429103010", "productinfo": "iPhone", "firstname": "Ashish",
"email": "[email protected]", "amount": "10","udf1":"","udf2":"","udf3":"","udf4":"","udf5":""}
payment_hash = "672de0802e96766044e473db706bdb1f14dea0ad3b3a69fed02377233a8bb73c646a43520bf0d7217647945ac0f0602c49e3b4109c379df75d8dbb1d4702ae6b"
reverse_hash = "57230620dcf90ed58c96b57c508d89431788cc7ab6b7d472aeb1e014ea7fa712cdc00f986bf3e6df8f5c6ebce70340286d57623590a3c8e4ced3b551e792b3d3"
class TestPayUHashes(unittest.TestCase):


def test_generate_hash(self):

result = payu.Hasher.generate_hash(parameters)
self.assertEqual(result, payment_hash)
self.assertEqual(len(parameters['key']), 6)
self.assertIsNot(parameters['key'], "", "key should not be empty")
self.assertIsNot(parameters['txnid'], "", "txnid should not be empty")
self.assertIsNot(parameters['amount'], "", "amount should not be empty")
self.assertIsNot(parameters['productinfo'], "", "productinfo should not be empty")
self.assertLess(len(parameters['txnid']), 25, "Length of txnid is allowed to 25")
self.assertLess(len(parameters['udf1']), 255, "Length of udf1 is allowed to 255")
self.assertLess(len(parameters['udf2']), 255, "Length of udf2 is allowed to 255")
self.assertLess(len(parameters['udf3']), 255, "Length of udf3 is allowed to 255")
self.assertLess(len(parameters['udf4']), 255, "Length of udf4 is allowed to 255")
self.assertLess(len(parameters['udf5']), 255, "Length of udf5 is allowed to 255")




def test_validate_hash(self):
result = payu.Hasher.validate_hash(parameters)
self.assertEqual(result, reverse_hash)
self.assertEqual(len(parameters['key']), 6)
self.assertIsNot(parameters['key'], "", "key should not be empty")
self.assertIsNot(parameters['txnid'], "", "txnid should not be empty")
self.assertIsNot(parameters['amount'], "", "amount should not be empty")
self.assertIsNot(parameters['productinfo'], "", "productinfo should not be empty")
self.assertLess(len(parameters['txnid']), 25, "Length of txnid is allowed to 25")
self.assertLess(len(parameters['udf1']), 255, "Length of udf1 is allowed to 255")
self.assertLess(len(parameters['udf2']), 255, "Length of udf2 is allowed to 255")
self.assertLess(len(parameters['udf3']), 255, "Length of udf3 is allowed to 255")
self.assertLess(len(parameters['udf4']), 255, "Length of udf4 is allowed to 255")
self.assertLess(len(parameters['udf5']), 255, "Length of udf5 is allowed to 255")
2 changes: 2 additions & 0 deletions pythonSDK/PayU/base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

from .payubase import Base
Binary file not shown.
Binary file not shown.
26 changes: 26 additions & 0 deletions pythonSDK/PayU/base/payubase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Base(object):
_instance = None

d = dict()
key = ""
salt = ""

def __new__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = super(Base, cls).__new__(
cls, *args, **kwargs)
return cls._instance


def set_params(self,params):


self.key = params.get("key")
self.salt = params.get("salt")
return (self.key ,self.salt)

def get_params(self):

return (self.key ,self.salt)


2 changes: 2 additions & 0 deletions pythonSDK/PayU/constants/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from payu.base import Base
from payu.resources import Hasher
Binary file not shown.
5 changes: 5 additions & 0 deletions pythonSDK/PayU/constants/payuconstants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ERROR_CODE(object):
BAD_REQUEST_ERROR_CODE = "BAD_REQUEST_ERRORCODE"
GATEWAY_ERROR_CODE = "GATEWAY_ERROR_CODE"
SERVER_ERROR_CODE = "SERVER_ERROR_CODE"
API_REQUEST_ERROR_CODE = "API_REQUEST_ERROR_CODE"
1 change: 1 addition & 0 deletions pythonSDK/PayU/errors/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from payu.errors import payuerrors
3 changes: 3 additions & 0 deletions pythonSDK/PayU/errors/payuerrors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class BadRequestError(Exception):
def __init__(self, message=None, *args, **kwargs):
super(BadRequestError, self).__init__(message)
21 changes: 21 additions & 0 deletions pythonSDK/PayU/payuClient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
import json
import pkg_resources
from payu.base import Base

class payUClient:

key = ""
salt = ""

def __init__(self, credes):
self.key = credes.get("key")
self.salt = credes.get("salt")
client = Base()
client.set_params(credes)






1 change: 1 addition & 0 deletions pythonSDK/PayU/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .hasher import Hasher
Binary file not shown.
Binary file not shown.
57 changes: 57 additions & 0 deletions pythonSDK/PayU/resources/hasher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import hashlib
from payu.base import Base

key = ""
salt = ""

class Hasher:



def generate_hash(params):
base = Base()
client_creds = base.get_params()
key = client_creds[0]
salt = client_creds[1]
txnid = params.get("txnid")
amount = params.get("amount")
productinfo = params.get("productinfo")
firstname = params.get("firstname")
email = params.get("email", "default")
udf1 = params.get("udf1", "")
udf2 = params.get("udf2", "")
udf3 = params.get("udf3", "")
udf4 = params.get("udf4", "")
udf5 = params.get("udf5", "")
if params.get("additional_charges") is True:
additional_charges = params.get("additional_charges")
payment_hash_sequence = f"{additional_charges}|{key}|{txnid}|{amount}|{productinfo}|{firstname}|{email}|{udf1}|{udf2}|{udf3}|{udf4}|{udf5}||||||{salt}"
else:
payment_hash_sequence = f"{key}|{txnid}|{amount}|{productinfo}|{firstname}|{email}|{udf1}|{udf2}|{udf3}|{udf4}|{udf5}||||||{salt}"

hash_value = hashlib.sha512((payment_hash_sequence).encode('utf-8')).hexdigest().lower()
return hash_value

def validate_hash(params):
client_creds = base.get_params()
key = client_creds[0]
salt = client_creds[1]
txnid = params.get("txnid")
amount = params.get("amount")
productinfo = params.get("productinfo")
firstname = params.get("firstname")
email = params.get("email", "default")
udf1 = params.get("udf1", "")
udf2 = params.get("udf2", "")
udf3 = params.get("udf3", "")
udf4 = params.get("udf4", "")
udf5 = params.get("udf5", "")

if params.get("additional_charges") is True:
additional_charges = params.get("additional_charges")
validate_hash_sequence = f"{additional_charges}|{salt}||||||{udf5}|{udf4}|{udf3}|{udf2}|{udf1}|{email}|{firstname}|{productinfo}|{amount}|{txnid}|{key}"
else:
validate_hash_sequence = f"{salt}||||||{udf5}|{udf4}|{udf3}|{udf2}|{udf1}|{email}|{firstname}|{productinfo}|{amount}|{txnid}|{key}"

validate_hash = hashlib.sha512((validate_hash_sequence).encode('utf-8')).hexdigest().lower()
return validate_hash
1 change: 1 addition & 0 deletions pythonSDK/PayU/venv/.Python
78 changes: 78 additions & 0 deletions pythonSDK/PayU/venv/bin/activate
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly

deactivate () {
unset -f pydoc >/dev/null 2>&1

# reset old environment variables
# ! [ -z ${VAR+_} ] returns true if VAR is declared at all
if ! [ -z "${_OLD_VIRTUAL_PATH+_}" ] ; then
PATH="$_OLD_VIRTUAL_PATH"
export PATH
unset _OLD_VIRTUAL_PATH
fi
if ! [ -z "${_OLD_VIRTUAL_PYTHONHOME+_}" ] ; then
PYTHONHOME="$_OLD_VIRTUAL_PYTHONHOME"
export PYTHONHOME
unset _OLD_VIRTUAL_PYTHONHOME
fi

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then
hash -r 2>/dev/null
fi

if ! [ -z "${_OLD_VIRTUAL_PS1+_}" ] ; then
PS1="$_OLD_VIRTUAL_PS1"
export PS1
unset _OLD_VIRTUAL_PS1
fi

unset VIRTUAL_ENV
if [ ! "${1-}" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
}

# unset irrelevant variables
deactivate nondestructive

VIRTUAL_ENV="/Users/ashish.kumar/UserExp/Design_patterns/PayU_framework_python/venv"
export VIRTUAL_ENV

_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH

# unset PYTHONHOME if set
if ! [ -z "${PYTHONHOME+_}" ] ; then
_OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME"
unset PYTHONHOME
fi

if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then
_OLD_VIRTUAL_PS1="${PS1-}"
if [ "x" != x ] ; then
PS1="${PS1-}"
else
PS1="(`basename \"$VIRTUAL_ENV\"`) ${PS1-}"
fi
export PS1
fi

# Make sure to unalias pydoc if it's already there
alias pydoc 2>/dev/null >/dev/null && unalias pydoc || true

pydoc () {
python -m pydoc "$@"
}

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then
hash -r 2>/dev/null
fi
42 changes: 42 additions & 0 deletions pythonSDK/PayU/venv/bin/activate.csh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This file must be used with "source bin/activate.csh" *from csh*.
# You cannot run it directly.
# Created by Davide Di Blasi <[email protected]>.

set newline='\
'

alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH:q" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT:q" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; test "\!:*" != "nondestructive" && unalias deactivate && unalias pydoc'

# Unset irrelevant variables.
deactivate nondestructive

setenv VIRTUAL_ENV "/Users/ashish.kumar/UserExp/Design_patterns/PayU_framework_python/venv"

set _OLD_VIRTUAL_PATH="$PATH:q"
setenv PATH "$VIRTUAL_ENV:q/bin:$PATH:q"



if ("" != "") then
set env_name = ""
else
set env_name = "$VIRTUAL_ENV:t:q"
endif

# Could be in a non-interactive environment,
# in which case, $prompt is undefined and we wouldn't
# care about the prompt anyway.
if ( $?prompt ) then
set _OLD_VIRTUAL_PROMPT="$prompt:q"
if ( "$prompt:q" =~ *"$newline:q"* ) then
:
else
set prompt = "[$env_name:q] $prompt:q"
endif
endif

unset env_name

alias pydoc python -m pydoc

rehash
Loading

0 comments on commit d55c5a3

Please sign in to comment.