Subversion Repositories SmartDukaan

Rev

Rev 420 | Rev 717 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

'''
Created on 26-Aug-2010

@author: ashish
'''
from shop2020.payments.impl import DataService
from shop2020.utils.Utils import log_entry
from shop2020.payments.impl.DataAccessor import create_payment,\
    get_payments_for_user, get_payments, get_payment, get_payment_for_txn, get_payment_gateway, update_payment_details
from shop2020.payments.impl.converters import to_t_payment, to_t_payment_gateway

class PaymentsHandler:
    
    def __init__(self):
        DataService.initialize()
        log_entry(self, "Initialized the data model")
    
    def createPayment(self, userId, amount, gatewayId, txnId):
        """
        create a new payment and return payment id, throws an exception if gateway is not active
        
        
        Parameters:
        - userId
        - amount
        - gatewayId
        - txnId
        """
        id = create_payment(userId, txnId, amount, gatewayId)
        log_entry(self, "created payment for txn %d" %(txnId))
        return id
    
    def getPaymentsForUser(self, userId, fromTime, toTime, status, gatewayId):
        """
        get payment for user. If status and gateway are null, it is ignored. Same for times as well.
        
        
        Parameters:
        - userId
        - fromTime
        - toTime
        - status
        - gatewayId
        """
        payments = get_payments_for_user(userId, fromTime, toTime, status, gatewayId)
        return [to_t_payment(payment) for payment in payments]
    
    def getPayments(self, fromTime, toTime, status, gatewayId):
        """
        get all payments for user. Gateway is mandatory.
        
        
        Parameters:
        - fromTime
        - toTime
        - status
        - gatewayId
        """
        payments = get_payments(fromTime, toTime, status, gatewayId)
        return [to_t_payment(payment) for payment in payments]
    
    def getPaymentGateway(self, id):
        """
        Get a particular gateway
        
        
        Parameters:
        - id
        """
        return to_t_payment_gateway(get_payment_gateway(id))
    
    def getPayment(self, id):
        """
        Get a particular payment info
        
        
        Parameters:
        - id
        """
        return to_t_payment(get_payment(id))
    
    def getPaymentForTxnId(self, txnId):
        """
        Get a particular payment for a transaction. Will raise exception.
        
        
        Parameters:
        - txnId
        """
        return to_t_payment(get_payment_for_txn(txnId))
    
    def updatePaymentDetails(self, id, gatewayPaymentId, sessionId, gatewayTxnStatus, description, gatewayTxnId, authCode, referenceCode, errorCode, status, attributes):
        """
        mark payment successful and store parameters
        
        
        Parameters:
        - id
        - gatewayPaymentId
        - sessionId
        - gatewayTxnStatus
        - description
        - gatewayTxnId
        - authCode
        - referenceCode
        - errorCode
        - status
        - attributes
        """
        return update_payment_details(self, id, gatewayPaymentId, sessionId, gatewayTxnStatus, description, gatewayTxnId, authCode, referenceCode, errorCode, status, attributes)