Commit 8eb6a40a by aa.gusti

add acc_no to payment request

1 parent a0d578ad
...@@ -5,34 +5,34 @@ from sqlalchemy import create_engine ...@@ -5,34 +5,34 @@ from sqlalchemy import create_engine
from sqlalchemy.orm import ( from sqlalchemy.orm import (
sessionmaker, sessionmaker,
scoped_session, scoped_session,
) )
from zope.sqlalchemy import register from zope.sqlalchemy import register
from pyramid.view import ( from pyramid.view import (
view_config, view_config,
notfound_view_config, notfound_view_config,
) )
from pyramid.response import Response from pyramid.response import Response
from deform import ( from deform import (
Form, Form,
Button, Button,
ValidationFailure, ValidationFailure,
) )
import colander import colander
from opensipkd.string import ( from opensipkd.string import (
FixLength, FixLength,
FullDateTimeVar, FullDateTimeVar,
) )
from opensipkd.iso8583.bjb.pbb.structure import INVOICE_PROFILE from opensipkd.iso8583.bjb.pbb.structure import INVOICE_PROFILE
from iso8583_web.scripts.tools import iso_to_dict from iso8583_web.scripts.tools import iso_to_dict
from iso8583_web.read_conf import web_path_conf from iso8583_web.read_conf import web_path_conf
from iso8583_web.scripts.logger import ( from iso8583_web.scripts.logger import (
log_web_info, log_web_info,
log_web_error, log_web_error,
) )
from .. import ( from .. import (
WebJob as BaseWebJob, WebJob as BaseWebJob,
View as BaseView, View as BaseView,
) )
from .exceptions import ( from .exceptions import (
InvoiceIdError, InvoiceIdError,
NeedPostError, NeedPostError,
...@@ -45,18 +45,17 @@ from .exceptions import ( ...@@ -45,18 +45,17 @@ from .exceptions import (
AmountError, AmountError,
BillRefNotFound, BillRefNotFound,
PaymentNotFound, PaymentNotFound,
) )
from .structure import ( from .structure import (
DataRequest, DataRequest,
InquiryResponse, InquiryResponse,
PaymentResponse, PaymentResponse,
) )
from .renderer import Renderer from .renderer import Renderer
from .models import ( from .models import (
Rpc, Rpc,
Log, Log,
) )
ROUTE = 'linkaja' ROUTE = 'linkaja'
RENDERER = 'csv' RENDERER = 'csv'
...@@ -83,7 +82,7 @@ class WebJob(BaseWebJob): ...@@ -83,7 +82,7 @@ class WebJob(BaseWebJob):
def form_validator(form, value): def form_validator(form, value):
if value['trx_type'] not in METHOD: if value['trx_type'] not in METHOD:
raise TrxTypeError() raise TrxTypeError()
def get_form(): def get_form():
schema = DataRequest(validator=form_validator) schema = DataRequest(validator=form_validator)
...@@ -104,6 +103,9 @@ def get_inquiry(data): ...@@ -104,6 +103,9 @@ def get_inquiry(data):
DBSession = get_db_session() DBSession = get_db_session()
bill_ref = int(data['bill_ref']) bill_ref = int(data['bill_ref'])
q = DBSession.query(Rpc).filter_by(id=bill_ref) q = DBSession.query(Rpc).filter_by(id=bill_ref)
# todo: Perlu ditambahkan data["acc_no"] sebagai filter untuk meningkatkan
# validasi data sehingga kesalahan akibat dari client mengubah acc_no
# dapat ditingkatkan.
return q.first() return q.first()
...@@ -111,7 +113,7 @@ def get_payment(data): ...@@ -111,7 +113,7 @@ def get_payment(data):
DBSession = get_db_session() DBSession = get_db_session()
bill_ref = int(data['bill_ref']) bill_ref = int(data['bill_ref'])
q = DBSession.query(Rpc).filter_by( q = DBSession.query(Rpc).filter_by(
inquiry_id=bill_ref, trx_type='022') inquiry_id=bill_ref, trx_type='022')
q = q.order_by(Rpc.id.desc()) q = q.order_by(Rpc.id.desc())
return q.first() return q.first()
...@@ -150,7 +152,7 @@ class csv_method(object): ...@@ -150,7 +152,7 @@ class csv_method(object):
config.add_view(view=ob, renderer=RENDERER, **kw) config.add_view(view=ob, renderer=RENDERER, **kw)
info = venusian.attach( info = venusian.attach(
wrapped, callback, category='pyramid', depth=depth + 1) wrapped, callback, category='pyramid', depth=depth + 1)
if info.scope == 'class': if info.scope == 'class':
# ensure that attr is set if decorating a class method # ensure that attr is set if decorating a class method
kw.setdefault('attr', wrapped.__name__) kw.setdefault('attr', wrapped.__name__)
...@@ -211,7 +213,7 @@ class View(BaseView): ...@@ -211,7 +213,7 @@ class View(BaseView):
if data.get('amount'): if data.get('amount'):
row.amount = int(data['amount']) row.amount = int(data['amount'])
if not is_inquiry(data): if not is_inquiry(data):
row.inquiry_id = inq and inq.id or pay.inquiry_id row.inquiry_id = inq and inq.id or pay.inquiry_id
row.ntb = data['trx_id'] row.ntb = data['trx_id']
with transaction.manager: with transaction.manager:
DBSession.add(row) DBSession.add(row)
...@@ -237,7 +239,7 @@ class View(BaseView): ...@@ -237,7 +239,7 @@ class View(BaseView):
web_data['Biller Name'] = row.biller_name = \ web_data['Biller Name'] = row.biller_name = \
profile['Nama'].strip() profile['Nama'].strip()
web_data['Bill Amount'] = iso_data[4].lstrip('0') web_data['Bill Amount'] = iso_data[4].lstrip('0')
if iso_data.get(47): if iso_data.get(47):
web_data['Transaction ID'] = row.ntp = iso_data[47] # NTP web_data['Transaction ID'] = row.ntp = iso_data[47] # NTP
err = None err = None
elif iso_data[39] in ['33', '55']: elif iso_data[39] in ['33', '55']:
...@@ -253,7 +255,7 @@ class View(BaseView): ...@@ -253,7 +255,7 @@ class View(BaseView):
err = BaseError() err = BaseError()
if err: if err:
web_data.from_err(err) web_data.from_err(err)
row.resp_msg = web_data['Notification Message'] row.resp_msg = web_data['Notification Message']
self.log_send(web_data.values) self.log_send(web_data.values)
row.resp_code = web_data['Response Code'] row.resp_code = web_data['Response Code']
row.resp_msg = web_data['Notification Message'] row.resp_msg = web_data['Notification Message']
...@@ -272,28 +274,28 @@ class View(BaseView): ...@@ -272,28 +274,28 @@ class View(BaseView):
inq = get_inquiry(data) inq = get_inquiry(data)
if not inq: if not inq:
raise BillRefNotFound() raise BillRefNotFound()
#ditambahkan karena harus sesuai dengan inq # ditambahkan karena harus sesuai dengan inq
DBSession = get_db_session() DBSession = get_db_session()
iso_log = DBSession.query(Log).\ iso_log = DBSession.query(Log). \
filter(Log.rpc_id==inq.id, filter(Log.rpc_id == inq.id,
Log.bit_062 != None).first() Log.bit_062 != None).first()
if not iso_log: if not iso_log:
raise BillRefNotFound() raise BillRefNotFound()
p['bits']={"62": iso_log.bit_062, p['bits'] = {"62": iso_log.bit_062,
"37": "".join(['000000', iso_log.bit_011])} "37": "".join(['000000', iso_log.bit_011])}
else: else:
pay = get_payment(data) pay = get_payment(data)
if not pay: if not pay:
raise BillRefNotFound() raise BillRefNotFound()
p['stan'] = pay.stan p['stan'] = pay.stan
# ditambahkan disini untuk ngisi user dan cabang # ditambahkan disini untuk ngisi user dan cabang
if 'bits' not in p: if 'bits' not in p:
p['bits'] = {} p['bits'] = {}
p['bits']['107']='LINKAJA' p['bits']['107'] = 'LINKAJA'
p['bits']['49']='AGRATEK-LINKAJA' p['bits']['49'] = 'AGRATEK-LINKAJA'
conn = self.get_connection() conn = self.get_connection()
method = get_method(data) method = get_method(data)
iso_func = getattr(conn.job, method) iso_func = getattr(conn.job, method)
...@@ -336,7 +338,7 @@ class View(BaseView): ...@@ -336,7 +338,7 @@ class View(BaseView):
def view_not_found(self): def view_not_found(self):
msg = 'Path {} tidak ada'.format(self.request.path) msg = 'Path {} tidak ada'.format(self.request.path)
self.log_receive(msg, True) self.log_receive(msg, True)
return self.request.exception return self.request.exception
def log_prefix(request): def log_prefix(request):
...@@ -344,15 +346,15 @@ def log_prefix(request): ...@@ -344,15 +346,15 @@ def log_prefix(request):
name = web_conf['name'] name = web_conf['name']
return '{} {} {}'.format( return '{} {} {}'.format(
request.client_addr, name, id(request)) request.client_addr, name, id(request))
@view_config(context=BaseError) @view_config(context=BaseError)
def view_exception(exc, request): def view_exception(exc, request):
r = InquiryResponse() r = InquiryResponse()
r['Response Code'] = exc.code r['Response Code'] = exc.code
r['Notification Message'] = exc.message r['Notification Message'] = exc.message
prefix = log_prefix(request) prefix = log_prefix(request)
msg = '{} {} {}'.format(prefix, 'Send', r) msg = '{} {} {}'.format(prefix, 'Send', r)
log_web_error(msg) log_web_error(msg)
response = Response(str(r)) response = Response(str(r))
response.status_int = 200 response.status_int = 200
......
...@@ -14,21 +14,14 @@ from opensipkd.string import ( ...@@ -14,21 +14,14 @@ from opensipkd.string import (
from .structure import INVOICE_PROFILE from .structure import INVOICE_PROFILE
from .structure import Transaksi from .structure import Transaksi
from .. import View as BaseView from .. import View as BaseView
# View as BaseView,
from ..linkaja import ( from ..linkaja import (
WebJob, WebJob, is_inquiry, get_db_session, is_reversal, is_payment, get_method,
# View as BaseView, get_form, date_from_str, csv_method, get_template_response, get_inquiry,
is_inquiry, get_db_session, is_reversal, is_payment, get_method, get_payment)
get_form, date_from_str, csv_method, get_template_response, get_inquiry, get_payment)
from ..linkaja.exceptions import ( from ..linkaja.exceptions import (
InvoiceIdError, InvoiceIdError, NeedPostError, InternalError, HostError, AlreadyPaidError,
NeedPostError, BaseError, AmountError, BillRefNotFound, PaymentNotFound,
InternalError,
HostError,
AlreadyPaidError,
BaseError,
AmountError,
BillRefNotFound,
PaymentNotFound,
) )
from ..linkaja.models import (Rpc, LogSam) from ..linkaja.models import (Rpc, LogSam)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!