Commit 76673c1b by aa.gusti

Penambahan LINKAJA TO Sambat

1 parent f1f3c235
import transaction
import venusian
from ISO8583.ISOErrors import BitNotSet
from deform import (
ValidationFailure,
......@@ -11,19 +10,15 @@ from iso8583_web.scripts.views import WebJob
from opensipkd.string import (
FixLength,
)
from pyramid.view import (
notfound_view_config,
)
from .structure import INVOICE_PROFILE
from .structure import Transaksi
from .. import View as BaseView
from ..linkaja import (
WebJob,
# View as BaseView,
is_inquiry, RENDERER, get_db_session, is_reversal, is_payment, get_method,
is_inquiry, get_db_session, is_reversal, is_payment, get_method,
get_form, date_from_str, csv_method, get_template_response, get_inquiry, get_payment)
from .. import View as BaseView
from ..linkaja.exceptions import (
InvoiceIdError,
NeedPostError,
......@@ -36,63 +31,12 @@ from ..linkaja.exceptions import (
PaymentNotFound,
)
from ..linkaja.models import (Rpc, LogSam)
from ..linkaja.structure import (
InquiryResponse,
PaymentResponse,
)
ROUTE = 'linkaja/sambat'
conf = dict()
# def get_inquiry(data):
# DBSession = get_db_session()
# bill_ref = int(data['bill_ref'])
# q = DBSession.query(Rpc).filter_by(id=bill_ref)
# return q.first()
# def get_payment(data):
# DBSession = get_db_session()
# bill_ref = int(data['bill_ref'])
# q = DBSession.query(Rpc).\
# filter_by(inquiry_id=bill_ref, trx_type='022')
# q = q.order_by(Rpc.id.desc())
# return q.first()
# def get_template_response(data):
# if is_inquiry(data):
# return InquiryResponse()
# d = PaymentResponse()
# d['Bill Ref'] = data['bill_ref']
# return d
# view decorator
# class sambat_method(object):
# def __init__(self, **kw):
# self.kw = kw
#
# def __call__(self, wrapped):
# kw = self.kw.copy()
# depth = kw.pop('_depth', 0)
#
# def callback(context, name, ob):
# config = context.config.with_package(info.module)
# config.add_view(view=ob, renderer=RENDERER, **kw)
#
# info = venusian.attach(
# wrapped, callback, category='pyramid', depth=depth + 1)
# if info.scope == 'class':
# # ensure that attr is set if decorating a class method
# kw.setdefault('attr', wrapped.__name__)
#
# kw['_info'] = info.codeinfo # fbo action_method
# return wrapped
class View(BaseView):
def get_web_job_cls(self): # Override
return WebJob
......@@ -113,13 +57,6 @@ class View(BaseView):
conf_name=conf['name'],
message=iso.data,
bit_003=iso.data["processingCode"])
# for bit in iso.get_bit_definition():
# try:
# value = iso.getBit(bit)
# except BitNotSet:
# continue
# field = 'bit_{}'.format(str(bit).zfill(3))
# setattr(iso_log, field, value)
try:
data = iso.data["additionalData"]
profile = FixLength(INVOICE_PROFILE)
......@@ -225,6 +162,9 @@ class View(BaseView):
iso_req = Transaksi(p, method, inq, pay)
row = self.before_send_iso(data, inq, pay, iso_req)
iso_req.send()
if type(iso_req.response) != dict:
raise BaseError
return self.after_send_iso(data, inq, pay, row, iso_req)
@csv_method(route_name=ROUTE)
......@@ -248,21 +188,6 @@ class View(BaseView):
raise InternalError(msg)
data = dict(c)
return self.get_response(data)
# try:
# r = self.get_response(data)
# self.log_send(r)
# return r
# except BaseError as e:
# r = get_template_response(data)
# r['Response Code'] = e.code
# r['Notification Message'] = e.message
# return r
# @notfound_view_config()
# def view_not_found(self):
# msg = 'Path {} tidak ada'.format(self.request.path)
# self.log_receive(msg, True)
# return self.request.exception
# Dipanggil read_conf.py
......
# import colander
# from opensipkd.string.row import Row
# from .exceptions import InternalError
from iso8583_web.scripts.logger import (
log_web_info,
log_web_debug)
import requests
from iso8583_web.scripts.views.linkaja import get_db_session, AlreadyPaidError, BillRefNotFound
from iso8583_web.scripts.views.linkaja import get_db_session, AlreadyPaidError, BillRefNotFound, BaseError
from iso8583_web.scripts.views.linkaja.models import LogSam
from iso8583_web.tools.this_framework import get_settings
from datetime import datetime
import requests
INQ_REQ = {
"primaryAccountNumber": "622011888888888888",
......@@ -67,15 +72,25 @@ PAY_REQ = \
def send_data(json_data):
settings = get_settings()
pload = {'username': 'olivia', 'password': '123'}
bjb_sambat_url = "bjb_sambat_url" in settings and settings["bjb_sambat_url"] or \
"http://localhost/bjb/sambat/test"
"http://localhost:7001/bjb/sambat/test"
data = json_data
# todo butuh server buat testing json sementara pake static response
if json_data["processingCode"] == '321000':
return INQ_RESP
elif json_data["processingCode"] == '521000':
return PAY_RESP
return requests.post(bjb_sambat_url, data=data)
r = requests.post(bjb_sambat_url, data=data)
if r.text:
try:
return r.json()
except:
log_web_info(r.text)
raise BaseError
return
class Transaksi(object):
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!