Subversion Repositories SmartDukaan

Rev

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

Rev 420 Rev 701
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, change_payment_status, get_payment,\
9
    get_payments_for_user, get_payments, get_payment, get_payment_for_txn, get_payment_gateway, update_payment_details
10
    add_bank_details
-
 
11
from shop2020.payments.impl.converters import to_t_payment
10
from shop2020.payments.impl.converters import to_t_payment, to_t_payment_gateway
12
 
-
 
13
 
-
 
14
 
11
 
15
class PaymentsHandler:
12
class PaymentsHandler:
16
    
13
    
17
    def __init__(self):
14
    def __init__(self):
18
        DataService.initialize()
15
        DataService.initialize()
19
        log_entry(self, "Initialized the data model")
16
        log_entry(self, "Initialized the data model")
20
    
17
    
21
    
-
 
22
    def createPayment(self, user_id, cart_id, amount, gateway_id):
18
    def createPayment(self, userId, amount, gatewayId, txnId):
23
        """
19
        """
-
 
20
        create a new payment and return payment id, throws an exception if gateway is not active
-
 
21
        
-
 
22
        
24
        Parameters:
23
        Parameters:
25
         - user_id
24
        - userId
26
         - cart_id
25
        - amount
27
         - amount
26
        - gatewayId
28
         - gateway_id
27
        - txnId
29
        """
28
        """
30
        id = create_payment(user_id, cart_id, amount, gateway_id)
29
        id = create_payment(userId, txnId, amount, gatewayId)
31
        log_entry(self, "created payment for cart_id %d" %(cart_id))
30
        log_entry(self, "created payment for txn %d" %(txnId))
32
        return id
31
        return id
33
    
32
    
34
    def createPaymentRequest(self, cart_id, application_id, merchant_tx_id, params):
33
    def getPaymentsForUser(self, userId, fromTime, toTime, status, gatewayId):
35
        """
-
 
36
        Parameters:
-
 
37
         - cart_id
-
 
38
         - application_id
-
 
39
         - merchant_tx_id
-
 
40
         - params
-
 
41
        """
-
 
42
        pass
-
 
43
    
-
 
44
    def addCallbackUrl(self, application_id, callback_url, updateIfExisting):
-
 
45
        """
34
        """
-
 
35
        get payment for user. If status and gateway are null, it is ignored. Same for times as well.
-
 
36
        
-
 
37
        
46
        Parameters:
38
        Parameters:
-
 
39
        - userId
-
 
40
        - fromTime
47
         - application_id
41
        - toTime
48
         - callback_url
42
        - status
49
         - updateIfExisting
43
        - gatewayId
50
        """
44
        """
-
 
45
        payments = get_payments_for_user(userId, fromTime, toTime, status, gatewayId)
51
        pass
46
        return [to_t_payment(payment) for payment in payments]
52
    
47
    
53
    def getCallbackUrl(self, application_id):
48
    def getPayments(self, fromTime, toTime, status, gatewayId):
54
        """
49
        """
-
 
50
        get all payments for user. Gateway is mandatory.
-
 
51
        
-
 
52
        
55
        Parameters:
53
        Parameters:
-
 
54
        - fromTime
-
 
55
        - toTime
-
 
56
        - status
56
         - application_id
57
        - gatewayId
57
        """
58
        """
-
 
59
        payments = get_payments(fromTime, toTime, status, gatewayId)
58
        pass
60
        return [to_t_payment(payment) for payment in payments]
59
    
61
    
60
    def getPaymentsForUser(self, userId, from_time, to_time, status, gateway):
-
 
61
        """
-
 
62
        Parameters:
62
    def getPaymentGateway(self, id):
63
         - userId
-
 
64
         - from_time
-
 
65
         - to_time
-
 
66
         - status
-
 
67
         - gateway
-
 
68
        """
63
        """
69
        payments = []
64
        Get a particular gateway
70
        pmnts = get_payments_for_user(userId, from_time, to_time, status, gateway)
-
 
71
        
65
        
72
        if pmnts:
-
 
73
            for pmnt in pmnts:
-
 
74
                payments.append(to_t_payment(pmnt))
-
 
75
        return payments
-
 
76
        
66
        
77
    def getPaymentsForCart(self, cartId, from_time, to_time, status, gateway):
-
 
78
        """
-
 
79
        Parameters:
67
        Parameters:
80
         - cartId
68
        - id
81
         - from_time
-
 
82
         - to_time
-
 
83
         - status
-
 
84
         - gateway
-
 
85
        """
69
        """
86
        payments = []
-
 
87
        pmnts = get_payments_for_user(cartId, from_time, to_time, status, gateway)
-
 
88
        
-
 
89
        if pmnts:
-
 
90
            for pmnt in pmnts:
-
 
91
                payments.append(to_t_payment(pmnt))
70
        return to_t_payment_gateway(get_payment_gateway(id))
92
        return payments
-
 
93
        
71
    
94
    def getPayments(self, from_time, to_time, status, gateway):
-
 
95
        """
-
 
96
        Parameters:
72
    def getPayment(self, id):
97
         - from_time
-
 
98
         - to_time
-
 
99
         - status
-
 
100
         - gateway
-
 
101
        """
73
        """
102
        payments = []
74
        Get a particular payment info
103
        pmnts = get_payments(from_time, to_time, status, gateway)
-
 
104
        
75
        
105
        if pmnts:
-
 
106
            for pmnt in pmnts:
-
 
107
                payments.append(to_t_payment(pmnt))
-
 
108
        return payments
-
 
109
        
76
        
110
    def getPaymentForMerchantId(self, merchant_tx_id):
-
 
111
        """
-
 
112
        Parameters:
77
        Parameters:
113
         - merchant_tx_id
-
 
114
        """
78
        - id
115
        payments = []
-
 
116
        pmnts = get_payments_for_user(int(merchant_tx_id), 0, 0, -1, 0)
-
 
117
        
-
 
118
        if pmnts:
-
 
119
            for pmnt in pmnts:
-
 
120
                payments.append(to_t_payment(pmnt))
-
 
121
        return payments
-
 
122
        
-
 
123
    def changePaymentStatus(self, merchant_tx_id, newStatus):
-
 
124
        """
79
        """
125
        Parameters:
80
        return to_t_payment(get_payment(id))
126
         - merchant_tx_id
81
    
127
         - newStatus
82
    def getPaymentForTxnId(self, txnId):
128
        """
83
        """
129
        change_payment_status(merchant_tx_id, newStatus)
84
        Get a particular payment for a transaction. Will raise exception.
130
        
85
        
131
    def changePaymentRequestStatus(self, request_id, requestStatus):
-
 
132
        """
-
 
133
        Parameters:
-
 
134
         - request_id
-
 
135
         - requestStatus
-
 
136
        """
-
 
137
        pass
-
 
138
        
86
        
139
    def getPaymentGateways(self, status):
-
 
140
        """
-
 
141
        Parameters:
87
        Parameters:
142
         - status
88
        - txnId
143
        """
89
        """
144
        pass
-
 
145
        
-
 
146
    def getPaymentGateway(self, id):
90
        return to_t_payment(get_payment_for_txn(txnId))
147
        """
91
    
148
        Parameters:
92
    def updatePaymentDetails(self, id, gatewayPaymentId, sessionId, gatewayTxnStatus, description, gatewayTxnId, authCode, referenceCode, errorCode, status, attributes):
149
         - id
-
 
150
        """
93
        """
151
        pass
94
        mark payment successful and store parameters
152
        
95
        
153
    def changeGatewayStatus(self, id, status):
-
 
154
        """
-
 
155
        Parameters:
-
 
156
         - id
-
 
157
         - status
-
 
158
        """
-
 
159
        pass
-
 
160
    def getPayment(self, id):
-
 
161
        
96
        
162
        payment = get_payment(id)
97
        Parameters:
163
        if payment:
98
        - id
164
            return to_t_payment(payment)
99
        - gatewayPaymentId
165
        return None
100
        - sessionId
166
        pass
-
 
167
    
-
 
168
    def addBankDetails(self, id, bid, btxid, error_code, session_id, postdate, auth_code, ref_code):
-
 
169
        """
-
 
170
        Parameters:
101
        - gatewayTxnStatus
171
         - id
102
        - description
172
         - bid
103
        - gatewayTxnId
173
         - btxid
104
        - authCode
174
         - error_code
105
        - referenceCode
175
         - session_id
106
        - errorCode
176
         - postdate
107
        - status
177
         - auth_code
108
        - attributes
178
         - ref_code
-
 
179
        """
109
        """
180
        add_bank_details(id, bid, btxid, error_code, session_id, postdate, auth_code, ref_code)
-
 
181
110
        return update_payment_details(self, id, gatewayPaymentId, sessionId, gatewayTxnStatus, description, gatewayTxnId, authCode, referenceCode, errorCode, status, attributes)
-
 
111
182
112