models.py 2.07 KB
from sqlalchemy import (
    Column,
    Integer,
    Float,
    DateTime,
    String,
    Text,
    JSON,
    ForeignKey,
    func,
    )
from sqlalchemy.ext.declarative import declarative_base


Base = declarative_base()

# Tabel pertama saat ada request dari LinkAja

class Rpc(Base):
    __tablename__ = 'linkaja_trx'
    id = Column(Integer, primary_key=True)  # Bill Ref
    created = Column(
        DateTime(timezone=True), nullable=False, server_default=func.now())
    ip = Column(String(15), nullable=False)
    conf_name = Column(String(16), nullable=False)
    merchant = Column(String(100), nullable=False)
    terminal = Column(String(100), nullable=False)
    trx_type = Column(String(3), nullable=False)
    msisdn = Column(String(20), nullable=False)
    # Invoice ID = SPPT ID di PBB
    acc_no = Column(String(64), nullable=False)
    msg = Column(String(100))
    trx_date = Column(DateTime(timezone=True), nullable=False)
    # Dari inquiry response
    amount = Column(Float)
    # Dari inquiry response (Bill Ref),
    # diisi saat payment request (bill_ref)
    inquiry_id = Column(Integer, ForeignKey('linkaja_trx.id'))
    # Dari payment request (trx_id)
    ntb = Column(String(32))
    # Penerjemahan bit 39
    resp_code = Column(String(2))
    # Penjelasan resp_code untuk pelanggan
    resp_msg = Column(String(200))
    # Penjelasan resp_code untuk audit sistem
    resp_orig_msg = Column(String(200))
    # Nama wajib pajak
    biller_name = Column(String(200))
    # Dari payment response (Transaction ID)
    ntp = Column(String(32))
    # Dari bit 11, dibutuhkan untuk reversal
    stan = Column(String(6))


# Tabel kedua saat berkomunikasi dengan bank

class Bank(Base):
    __tablename__ = 'linkaja_bank'
    id = Column(Integer, primary_key=True)
    created = Column(
            DateTime(timezone=True), nullable=False, server_default=func.now())
    rpc_id = Column(Integer, ForeignKey(Rpc.id), nullable=False)
    url = Column(Text, nullable=False)
    conf_name = Column(String(16), nullable=False)
    request = Column(JSON, nullable=False)
    response = Column(JSON)