Subversion Repositories SmartDukaan

Rev

Rev 701 | 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, change_payment_status, get_payment,\
    add_bank_details
from shop2020.payments.impl.converters import to_t_payment



class PaymentsHandler:
    
    def __init__(self):
        DataService.initialize()
        log_entry(self, "Initialized the data model")
    
    
    def createPayment(self, user_id, cart_id, amount, gateway_id):
        """
        Parameters:
         - user_id
         - cart_id
         - amount
         - gateway_id
        """
        id = create_payment(user_id, cart_id, amount, gateway_id)
        log_entry(self, "created payment for cart_id %d" %(cart_id))
        return id
    
    def createPaymentRequest(self, cart_id, application_id, merchant_tx_id, params):
        """
        Parameters:
         - cart_id
         - application_id
         - merchant_tx_id
         - params
        """
        pass
    
    def addCallbackUrl(self, application_id, callback_url, updateIfExisting):
        """
        Parameters:
         - application_id
         - callback_url
         - updateIfExisting
        """
        pass
    
    def getCallbackUrl(self, application_id):
        """
        Parameters:
         - application_id
        """
        pass
    
    def getPaymentsForUser(self, userId, from_time, to_time, status, gateway):
        """
        Parameters:
         - userId
         - from_time
         - to_time
         - status
         - gateway
        """
        payments = []
        pmnts = get_payments_for_user(userId, from_time, to_time, status, gateway)
        
        if pmnts:
            for pmnt in pmnts:
                payments.append(to_t_payment(pmnt))
        return payments
        
    def getPaymentsForCart(self, cartId, from_time, to_time, status, gateway):
        """
        Parameters:
         - cartId
         - from_time
         - to_time
         - status
         - gateway
        """
        payments = []
        pmnts = get_payments_for_user(cartId, from_time, to_time, status, gateway)
        
        if pmnts:
            for pmnt in pmnts:
                payments.append(to_t_payment(pmnt))
        return payments
        
    def getPayments(self, from_time, to_time, status, gateway):
        """
        Parameters:
         - from_time
         - to_time
         - status
         - gateway
        """
        payments = []
        pmnts = get_payments(from_time, to_time, status, gateway)
        
        if pmnts:
            for pmnt in pmnts:
                payments.append(to_t_payment(pmnt))
        return payments
        
    def getPaymentForMerchantId(self, merchant_tx_id):
        """
        Parameters:
         - merchant_tx_id
        """
        payments = []
        pmnts = get_payments_for_user(int(merchant_tx_id), 0, 0, -1, 0)
        
        if pmnts:
            for pmnt in pmnts:
                payments.append(to_t_payment(pmnt))
        return payments
        
    def changePaymentStatus(self, merchant_tx_id, newStatus):
        """
        Parameters:
         - merchant_tx_id
         - newStatus
        """
        change_payment_status(merchant_tx_id, newStatus)
        
    def changePaymentRequestStatus(self, request_id, requestStatus):
        """
        Parameters:
         - request_id
         - requestStatus
        """
        pass
        
    def getPaymentGateways(self, status):
        """
        Parameters:
         - status
        """
        pass
        
    def getPaymentGateway(self, id):
        """
        Parameters:
         - id
        """
        pass
        
    def changeGatewayStatus(self, id, status):
        """
        Parameters:
         - id
         - status
        """
        pass
    def getPayment(self, id):
        
        payment = get_payment(id)
        if payment:
            return to_t_payment(payment)
        return None
        pass
    
    def addBankDetails(self, id, bid, btxid, error_code, session_id, postdate, auth_code, ref_code):
        """
        Parameters:
         - id
         - bid
         - btxid
         - error_code
         - session_id
         - postdate
         - auth_code
         - ref_code
        """
        add_bank_details(id, bid, btxid, error_code, session_id, postdate, auth_code, ref_code)