Subversion Repositories SmartDukaan

Rev

Rev 1493 | Rev 1657 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1493 Rev 1627
Line 12... Line 12...
12
from shop2020.thriftpy.payments.ttypes import PaymentException
12
from shop2020.thriftpy.payments.ttypes import PaymentException
13
from shop2020.payments.impl.DataService import Payment, PaymentGateway,\
13
from shop2020.payments.impl.DataService import Payment, PaymentGateway,\
14
    PaymentAttribute
14
    PaymentAttribute
15
from shop2020.thriftpy.payments.ttypes import PaymentStatus
15
from shop2020.thriftpy.payments.ttypes import PaymentStatus
16
from shop2020.utils.Utils import to_py_date
16
from shop2020.utils.Utils import to_py_date
-
 
17
from sqlalchemy.sql.expression import select, func
17
 
18
 
18
def create_payment(userId, txnId, amount, gatewayId):
19
def create_payment(userId, txnId, amount, gatewayId):
19
    if not userId:
20
    if not userId:
20
        raise PaymentException(101, "User cannot be null")
21
        raise PaymentException(101, "User cannot be null")
21
    if not txnId:
22
    if not txnId:
Line 40... Line 41...
40
    if from_time:
41
    if from_time:
41
        from_date = to_py_date(from_time)
42
        from_date = to_py_date(from_time)
42
        query = query.filter(Payment.initTimestamp >= from_date)
43
        query = query.filter(Payment.initTimestamp >= from_date)
43
    if to_time:
44
    if to_time:
44
        to_date = to_py_date(to_time)
45
        to_date = to_py_date(to_time)
-
 
46
        if status != PaymentStatus.INIT:
45
        query = query.filter(or_(Payment.successTimestamp <= to_date, Payment.errorTimestamp <= to_date))
47
            query = query.filter(or_(Payment.successTimestamp <= to_date, Payment.errorTimestamp <= to_date))
-
 
48
        else:
-
 
49
            query = query.filter(Payment.initTimestamp <= to_date)
46
    if status is not None:
50
    if status is not None:
47
        query = query.filter(Payment.status == status)
51
        query = query.filter(Payment.status == status)
48
    if gateway_id:
52
    if gateway_id:
49
        query = query.filter(Payment.gatewayId == gateway_id)
53
        query = query.filter(Payment.gatewayId == gateway_id)
50
    return query
54
    return query
Line 83... Line 87...
83
def get_payment_for_txn(txnId):
87
def get_payment_for_txn(txnId):
84
    try:
88
    try:
85
        return Payment.query.filter_by(merchantTxnId=txnId).one()
89
        return Payment.query.filter_by(merchantTxnId=txnId).one()
86
    except:
90
    except:
87
        raise PaymentException(103, "Unable to get payment for the given transaction")
91
        raise PaymentException(103, "Unable to get payment for the given transaction")
-
 
92
 
-
 
93
def get_max_payment_amount():
-
 
94
    return round(select([func.max(Payment.amount)]).execute().scalar(), 2)
-
 
95
 
-
 
96
def get_min_payment_amount():
-
 
97
    return round(select([func.min(Payment.amount)]).execute().scalar(), 2)
88
        
98
        
89
def update_payment_details(id, gatewayPaymentId, sessionId, gatewayTxnStatus, description, gatewayTxnId, authCode, referenceCode, errorCode, status, gatewayTxnDate, attributes):
99
def update_payment_details(id, gatewayPaymentId, sessionId, gatewayTxnStatus, description, gatewayTxnId, authCode, referenceCode, errorCode, status, gatewayTxnDate, attributes):
90
    if not id:
100
    if not id:
91
        raise PaymentException(101, "Can't update a payment without an id")
101
        raise PaymentException(101, "Can't update a payment without an id")
92
    try:
102
    try: