Subversion Repositories SmartDukaan

Rev

Rev 701 | Rev 766 | Go to most recent revision | Details | Compare with Previous | 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,\
701 chandransh 9
    get_payments_for_user, get_payments, get_payment, get_payment_for_txn, get_payment_gateway, update_payment_details
10
from shop2020.payments.impl.converters import to_t_payment, to_t_payment_gateway
420 ashish 11
 
12
class PaymentsHandler:
13
 
14
    def __init__(self):
15
        DataService.initialize()
16
        log_entry(self, "Initialized the data model")
17
 
701 chandransh 18
    def createPayment(self, userId, amount, gatewayId, txnId):
420 ashish 19
        """
701 chandransh 20
        create a new payment and return payment id, throws an exception if gateway is not active
21
 
22
 
420 ashish 23
        Parameters:
701 chandransh 24
        - userId
25
        - amount
26
        - gatewayId
27
        - txnId
420 ashish 28
        """
701 chandransh 29
        id = create_payment(userId, txnId, amount, gatewayId)
30
        log_entry(self, "created payment for txn %d" %(txnId))
420 ashish 31
        return id
32
 
701 chandransh 33
    def getPaymentsForUser(self, userId, fromTime, toTime, status, gatewayId):
420 ashish 34
        """
701 chandransh 35
        get payment for user. If status and gateway are null, it is ignored. Same for times as well.
36
 
37
 
420 ashish 38
        Parameters:
701 chandransh 39
        - userId
40
        - fromTime
41
        - toTime
42
        - status
43
        - gatewayId
420 ashish 44
        """
701 chandransh 45
        payments = get_payments_for_user(userId, fromTime, toTime, status, gatewayId)
46
        return [to_t_payment(payment) for payment in payments]
420 ashish 47
 
701 chandransh 48
    def getPayments(self, fromTime, toTime, status, gatewayId):
420 ashish 49
        """
701 chandransh 50
        get all payments for user. Gateway is mandatory.
51
 
52
 
420 ashish 53
        Parameters:
701 chandransh 54
        - fromTime
55
        - toTime
56
        - status
57
        - gatewayId
420 ashish 58
        """
701 chandransh 59
        payments = get_payments(fromTime, toTime, status, gatewayId)
60
        return [to_t_payment(payment) for payment in payments]
420 ashish 61
 
701 chandransh 62
    def getPaymentGateway(self, id):
420 ashish 63
        """
701 chandransh 64
        Get a particular gateway
420 ashish 65
 
66
 
67
        Parameters:
701 chandransh 68
        - id
420 ashish 69
        """
701 chandransh 70
        return to_t_payment_gateway(get_payment_gateway(id))
71
 
72
    def getPayment(self, id):
420 ashish 73
        """
701 chandransh 74
        Get a particular payment info
420 ashish 75
 
76
 
77
        Parameters:
701 chandransh 78
        - id
420 ashish 79
        """
701 chandransh 80
        return to_t_payment(get_payment(id))
81
 
82
    def getPaymentForTxnId(self, txnId):
420 ashish 83
        """
701 chandransh 84
        Get a particular payment for a transaction. Will raise exception.
420 ashish 85
 
86
 
87
        Parameters:
701 chandransh 88
        - txnId
420 ashish 89
        """
701 chandransh 90
        return to_t_payment(get_payment_for_txn(txnId))
91
 
92
    def updatePaymentDetails(self, id, gatewayPaymentId, sessionId, gatewayTxnStatus, description, gatewayTxnId, authCode, referenceCode, errorCode, status, attributes):
420 ashish 93
        """
701 chandransh 94
        mark payment successful and store parameters
420 ashish 95
 
96
 
97
        Parameters:
701 chandransh 98
        - id
99
        - gatewayPaymentId
100
        - sessionId
101
        - gatewayTxnStatus
102
        - description
103
        - gatewayTxnId
104
        - authCode
105
        - referenceCode
106
        - errorCode
107
        - status
108
        - attributes
420 ashish 109
        """
717 rajveer 110
        return update_payment_details(id, gatewayPaymentId, sessionId, gatewayTxnStatus, description, gatewayTxnId, authCode, referenceCode, errorCode, status, attributes)