Subversion Repositories SmartDukaan

Rev

Rev 701 | Blame | Compare with Previous | Last modification | View Log | RSS feed

'''
Created on 26-Aug-2010

@author: ashish
'''
from shop2020.payments.impl.DataService import Payment, PaymentGateway
from shop2020.thriftpy.payments.ttypes import Payment as TPayment, PaymentGateway as TPGateway, Attribute, PaymentGatewayStatus
from shop2020.utils.Utils import to_java_date

def to_t_payment(payment):
    t_payment = TPayment()
    t_payment.paymentId = payment.id
    t_payment.gatewayId = payment.gatewayId
    if payment.gatewayPaymentId:
        t_payment.gatewayPaymentId = payment.gatewayPaymentId
    t_payment.merchantTxnId = payment.merchantTxnId
    if payment.gatewayTxnId:
        t_payment.gatewayTxnId = payment.gatewayTxnId
    t_payment.amount = payment.amount
    if payment.gatewayTxnStatus:
        t_payment.gatewayTxnStatus = payment.gatewayTxnStatus
    t_payment.status = payment.status
    t_payment.userId = payment.userId
    if payment.errorCode:
        t_payment.errorCode = payment.errorCode
    t_payment.description = payment.description
    if payment.authCode:
        t_payment.authCode = payment.authCode
    if payment.referenceCode:
        t_payment.referenceCode = payment.referenceCode
    if payment.sessionId:
        t_payment.sessionId = payment.sessionId
    if payment.gatewayTxnDate:
        t_payment.gatewayTxnDate = payment.gatewayTxnDate
    t_payment.initTimestamp = to_java_date(payment.initTimestamp)
    if payment.successTimestamp:
        t_payment.successTimestamp = to_java_date(payment.successTimestamp)
    if payment.errorTimestamp:
        t_payment.errorTimestamp = to_java_date(payment.errorTimestamp)
    t_payment.attributes = [Attribute(name=attr.name, value=attr.value) for attr in payment.attributes]
    return t_payment

def to_t_payment_gateway(pg):
    t_pgateway = TPGateway()
    t_pgateway.id = pg.id
    t_pgateway.name = pg.name
    t_pgateway.url = pg.url
    t_pgateway.responseUrl = pg.responseUrl
    t_pgateway.errorUrl = pg.errorUrl
    t_pgateway.status = pg.status
    t_pgateway.aliasName = pg.aliasName
    t_pgateway.addedOn = to_java_date(pg.addedOn)
    t_pgateway.attributes = [Attribute(name=attr.name, value=attr.value) for attr in pg.attributes]
    return t_pgateway