Subversion Repositories SmartDukaan

Rev

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

'''
Created on 26-Aug-2010

@author: ashish
'''
from sqlalchemy import create_engine
from elixir import *
import elixir


class PaymentGateway(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    name = Field(String(100))
    aliasName = Field(String(100))
    url = Field(String(500))
    responseUrl = Field(String(500))
    errorUrl = Field(String(500))
    status = Field(Integer)
    addedOn = Field(DateTime)
    attributes = OneToMany("GatewayAttribute")
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class GatewayAttribute(Entity):
    payment_gateway = ManyToOne("PaymentGateway", primary_key=True)
    name = Field(String(50), primary_key=True)
    value = Field(String(100))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class PaymentAttribute(Entity):
    payment = ManyToOne("Payment", primary_key=True)
    name = Field(String(50), primary_key=True)
    value = Field(String(250))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class Payment(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    gatewayId = Field(Integer)
    gatewayPaymentId = Field(String(50))
    merchantTxnId = Field(Integer)
    gatewayTxnId = Field(String(50))
    amount = Field(Float)
    gatewayTxnStatus = Field(String(20))
    status = Field(Integer)
    userId = Field(Integer)
    errorCode = Field(String(20))
    description = Field(String(200))
    authCode = Field(String(20))
    referenceCode = Field(String(20))
    sessionId = Field(String(50))
    gatewayTxnDate = Field(String(50))
    attributes = OneToMany("PaymentAttribute")
    initTimestamp = Field(DateTime)
    successTimestamp = Field(DateTime)
    errorTimestamp = Field(DateTime)
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class Refund(Entity):
    id = Field(Integer, primary_key=True, autoincrement=True)
    paymentId = Field(Integer)
    gatewayId = Field(Integer)
    orderId = Field(Integer)
    amount = Field(Float)
    gatewayTxnId = Field(String(50))
    attempts = Field(Integer)
    createdAt = Field(DateTime)
    processedAt = Field(DateTime)
    attributes = OneToMany("RefundAttribute")
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")

class RefundAttribute(Entity):
    refund = ManyToOne("Refund", primary_key=True)
    name = Field(String(50), primary_key=True)
    value = Field(String(250))
    using_options(shortnames=True)
    using_table_options(mysql_engine="InnoDB")
    
def initialize(dbname='payment'):
    #metadata.bind = "sqlite:///payment.sqlite" #need to read it from configserver.
    engine = create_engine('mysql://root:shop2020@localhost/' + dbname, pool_recycle=7200)
    metadata.bind = engine
    metadata.bind.echo = True
    setup_all(True)

if __name__=="__main__":
    initialize()