Subversion Repositories SmartDukaan

Rev

Rev 701 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
420 ashish 1
'''
2
Created on 26-Aug-2010
3
 
4
@author: ashish
5
'''
6
from shop2020.payments.impl import DataService
7
from shop2020.utils.Utils import log_entry
8
from shop2020.payments.impl.DataAccessor import create_payment,\
9
    get_payments_for_user, get_payments, change_payment_status, get_payment,\
10
    add_bank_details
11
from shop2020.payments.impl.converters import to_t_payment
12
 
13
 
14
 
15
class PaymentsHandler:
16
 
17
    def __init__(self):
18
        DataService.initialize()
19
        log_entry(self, "Initialized the data model")
20
 
21
 
22
    def createPayment(self, user_id, cart_id, amount, gateway_id):
23
        """
24
        Parameters:
25
         - user_id
26
         - cart_id
27
         - amount
28
         - gateway_id
29
        """
30
        id = create_payment(user_id, cart_id, amount, gateway_id)
31
        log_entry(self, "created payment for cart_id %d" %(cart_id))
32
        return id
33
 
34
    def createPaymentRequest(self, cart_id, application_id, merchant_tx_id, params):
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
        """
46
        Parameters:
47
         - application_id
48
         - callback_url
49
         - updateIfExisting
50
        """
51
        pass
52
 
53
    def getCallbackUrl(self, application_id):
54
        """
55
        Parameters:
56
         - application_id
57
        """
58
        pass
59
 
60
    def getPaymentsForUser(self, userId, from_time, to_time, status, gateway):
61
        """
62
        Parameters:
63
         - userId
64
         - from_time
65
         - to_time
66
         - status
67
         - gateway
68
        """
69
        payments = []
70
        pmnts = get_payments_for_user(userId, from_time, to_time, status, gateway)
71
 
72
        if pmnts:
73
            for pmnt in pmnts:
74
                payments.append(to_t_payment(pmnt))
75
        return payments
76
 
77
    def getPaymentsForCart(self, cartId, from_time, to_time, status, gateway):
78
        """
79
        Parameters:
80
         - cartId
81
         - from_time
82
         - to_time
83
         - status
84
         - gateway
85
        """
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))
92
        return payments
93
 
94
    def getPayments(self, from_time, to_time, status, gateway):
95
        """
96
        Parameters:
97
         - from_time
98
         - to_time
99
         - status
100
         - gateway
101
        """
102
        payments = []
103
        pmnts = get_payments(from_time, to_time, status, gateway)
104
 
105
        if pmnts:
106
            for pmnt in pmnts:
107
                payments.append(to_t_payment(pmnt))
108
        return payments
109
 
110
    def getPaymentForMerchantId(self, merchant_tx_id):
111
        """
112
        Parameters:
113
         - merchant_tx_id
114
        """
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
        """
125
        Parameters:
126
         - merchant_tx_id
127
         - newStatus
128
        """
129
        change_payment_status(merchant_tx_id, newStatus)
130
 
131
    def changePaymentRequestStatus(self, request_id, requestStatus):
132
        """
133
        Parameters:
134
         - request_id
135
         - requestStatus
136
        """
137
        pass
138
 
139
    def getPaymentGateways(self, status):
140
        """
141
        Parameters:
142
         - status
143
        """
144
        pass
145
 
146
    def getPaymentGateway(self, id):
147
        """
148
        Parameters:
149
         - id
150
        """
151
        pass
152
 
153
    def changeGatewayStatus(self, id, status):
154
        """
155
        Parameters:
156
         - id
157
         - status
158
        """
159
        pass
160
    def getPayment(self, id):
161
 
162
        payment = get_payment(id)
163
        if payment:
164
            return to_t_payment(payment)
165
        return None
166
        pass
167
 
168
    def addBankDetails(self, id, bid, btxid, error_code, session_id, postdate, auth_code, ref_code):
169
        """
170
        Parameters:
171
         - id
172
         - bid
173
         - btxid
174
         - error_code
175
         - session_id
176
         - postdate
177
         - auth_code
178
         - ref_code
179
        """
180
        add_bank_details(id, bid, btxid, error_code, session_id, postdate, auth_code, ref_code)