Subversion Repositories SmartDukaan

Rev

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

Rev 717 Rev 766
Line 4... Line 4...
4
@author: ashish
4
@author: ashish
5
'''
5
'''
6
from shop2020.payments.impl import DataService
6
from shop2020.payments.impl import DataService
7
from shop2020.utils.Utils import log_entry
7
from shop2020.utils.Utils import log_entry
8
from shop2020.payments.impl.DataAccessor import create_payment,\
8
from shop2020.payments.impl.DataAccessor import create_payment,\
9
    get_payments_for_user, get_payments, get_payment, get_payment_for_txn, get_payment_gateway, update_payment_details
9
    get_payments_for_user, get_payments, get_payment, get_payment_for_txn,\
-
 
10
    get_payment_gateway, update_payment_details, close_session
10
from shop2020.payments.impl.converters import to_t_payment, to_t_payment_gateway
11
from shop2020.payments.impl.converters import to_t_payment, to_t_payment_gateway
11
 
12
 
12
class PaymentsHandler:
13
class PaymentsHandler:
13
    
14
    
14
    def __init__(self):
15
    def __init__(self):
Line 24... Line 25...
24
        - userId
25
        - userId
25
        - amount
26
        - amount
26
        - gatewayId
27
        - gatewayId
27
        - txnId
28
        - txnId
28
        """
29
        """
-
 
30
        try:
29
        id = create_payment(userId, txnId, amount, gatewayId)
31
            id = create_payment(userId, txnId, amount, gatewayId)
30
        log_entry(self, "created payment for txn %d" %(txnId))
32
            log_entry(self, "created payment for txn %d" %(txnId))
31
        return id
33
            return id
-
 
34
        finally:
-
 
35
            close_session()
32
    
36
            
33
    def getPaymentsForUser(self, userId, fromTime, toTime, status, gatewayId):
37
    def getPaymentsForUser(self, userId, fromTime, toTime, status, gatewayId):
34
        """
38
        """
35
        get payment for user. If status and gateway are null, it is ignored. Same for times as well.
39
        get payment for user. If status and gateway are null, it is ignored. Same for times as well.
36
        
40
        
37
        
41
        
Line 40... Line 44...
40
        - fromTime
44
        - fromTime
41
        - toTime
45
        - toTime
42
        - status
46
        - status
43
        - gatewayId
47
        - gatewayId
44
        """
48
        """
-
 
49
        try:
45
        payments = get_payments_for_user(userId, fromTime, toTime, status, gatewayId)
50
            payments = get_payments_for_user(userId, fromTime, toTime, status, gatewayId)
46
        return [to_t_payment(payment) for payment in payments]
51
            return [to_t_payment(payment) for payment in payments]
-
 
52
        finally:
-
 
53
            close_session()
47
    
54
            
48
    def getPayments(self, fromTime, toTime, status, gatewayId):
55
    def getPayments(self, fromTime, toTime, status, gatewayId):
49
        """
56
        """
50
        get all payments for user. Gateway is mandatory.
57
        get all payments for user. Gateway is mandatory.
51
        
58
        
52
        
59
        
Line 54... Line 61...
54
        - fromTime
61
        - fromTime
55
        - toTime
62
        - toTime
56
        - status
63
        - status
57
        - gatewayId
64
        - gatewayId
58
        """
65
        """
-
 
66
        try:
59
        payments = get_payments(fromTime, toTime, status, gatewayId)
67
            payments = get_payments(fromTime, toTime, status, gatewayId)
60
        return [to_t_payment(payment) for payment in payments]
68
            return [to_t_payment(payment) for payment in payments]
-
 
69
        finally:
-
 
70
            close_session()
61
    
71
            
62
    def getPaymentGateway(self, id):
72
    def getPaymentGateway(self, id):
63
        """
73
        """
64
        Get a particular gateway
74
        Get a particular gateway
65
        
75
        
66
        
76
        
67
        Parameters:
77
        Parameters:
68
        - id
78
        - id
69
        """
79
        """
-
 
80
        try:
70
        return to_t_payment_gateway(get_payment_gateway(id))
81
            return to_t_payment_gateway(get_payment_gateway(id))
-
 
82
        finally:
-
 
83
            close_session()
71
    
84
            
72
    def getPayment(self, id):
85
    def getPayment(self, id):
73
        """
86
        """
74
        Get a particular payment info
87
        Get a particular payment info
75
        
88
        
76
        
89
        
77
        Parameters:
90
        Parameters:
78
        - id
91
        - id
79
        """
92
        """
-
 
93
        try:
80
        return to_t_payment(get_payment(id))
94
            return to_t_payment(get_payment(id))
-
 
95
        finally:
-
 
96
            close_session()
81
    
97
            
82
    def getPaymentForTxnId(self, txnId):
98
    def getPaymentForTxnId(self, txnId):
83
        """
99
        """
84
        Get a particular payment for a transaction. Will raise exception.
100
        Get a particular payment for a transaction. Will raise exception.
85
        
101
        
86
        
102
        
87
        Parameters:
103
        Parameters:
88
        - txnId
104
        - txnId
89
        """
105
        """
-
 
106
        try:
90
        return to_t_payment(get_payment_for_txn(txnId))
107
            return to_t_payment(get_payment_for_txn(txnId))
-
 
108
        finally:
-
 
109
            close_session()
91
    
110
            
92
    def updatePaymentDetails(self, id, gatewayPaymentId, sessionId, gatewayTxnStatus, description, gatewayTxnId, authCode, referenceCode, errorCode, status, attributes):
111
    def updatePaymentDetails(self, id, gatewayPaymentId, sessionId, gatewayTxnStatus, description, gatewayTxnId, authCode, referenceCode, errorCode, status, attributes):
93
        """
112
        """
94
        mark payment successful and store parameters
113
        mark payment successful and store parameters
95
        
114
        
96
        
115
        
Line 105... Line 124...
105
        - referenceCode
124
        - referenceCode
106
        - errorCode
125
        - errorCode
107
        - status
126
        - status
108
        - attributes
127
        - attributes
109
        """
128
        """
110
        return update_payment_details(id, gatewayPaymentId, sessionId, gatewayTxnStatus, description, gatewayTxnId, authCode, referenceCode, errorCode, status, attributes)
-
 
111
129
        try:
-
 
130
            return update_payment_details(id, gatewayPaymentId, sessionId, gatewayTxnStatus, description, gatewayTxnId, authCode, referenceCode, errorCode, status, attributes)
-
 
131
        finally:
-
 
132
            close_session()
-
 
133
            
-
 
134
    def closeSession(self, ):
-
 
135
        close_session()
-
 
136
112
137