Subversion Repositories SmartDukaan

Rev

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