structure.py
6.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# import colander
# from opensipkd.string.row import Row
# from .exceptions import InternalError
# todo sebaiknya module ini masulk kedalam BJB-SAM-SAMSAT
import json
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, BaseError,
InquiryResponse as InquiryResponseBase)
from iso8583_web.scripts.views.linkaja.models import LogSam
from iso8583_web.scripts.views.linkaja.structure import INQUIRY_RESP_FIELDS, PAYMENT_RESP_FIELDS
from iso8583_web.tools.this_framework import get_settings
from datetime import datetime
import requests
from opensipkd.string.row import Row
INQ_CODE = "301099"
PAY_CODE = "541099"
FEAT_CODE = "017"
TERM_ID = "SLR"
TERM_NAME = "LINKAJA"
CARD_NAME = TERM_NAME
INQ_REQ = {
"primaryAccountNumber": "622011888888888888",
"processingCode": INQ_CODE,
"amountTransaction": "",
"settlementDate": "0326",
"merchantType": "6015",
"aggregatorCode": "W0216",
"caCode": "CA1830",
"terminalAggregator": {
"terminalIdentifierNumber": TERM_ID,
"terminalName": TERM_NAME,
"cardAcceptorName": CARD_NAME
},
"currencyCode": "360",
"amountInformation": {
"billAmount": "",
"feeBJB": "",
"feeAggregator": "",
"totalAmount": ""
},
"pay": "PAY",
"featureCode": FEAT_CODE,
"billInformation": {
"bills": [{
"info": "1000000108767"
}
]
},
"sourceAccountNumber": "10023269392100",
"destinationAccountNumber": "1",
"systemTraceAuditNumber": "",
"additionalData": "",
"timeLocalTransaction": "090210",
"localTransactionDate": "0326",
"transmissionDateTime": "0903173122",
"posEntryModeCode": "110",
"track2Data": "622011888888888888=9912?",
"sequenceNumber": "1"
}
def send_data(json_data, conf):
# settings = get_settings()
# pload = {'username': 'olivia', 'password': '123'}
bjb_sam_url = "bjb_sam_url" in conf and conf["bjb_sam_url"] or \
"http://localhost:7001/bjb/sambat/test"
data = json_data
if json_data["processingCode"] == INQ_CODE:
bjb_sam_url += "/inquiryPaymentRest"
elif json_data["processingCode"] == PAY_CODE:
bjb_sam_url += "/paymentRest"
log_web_info(json.dumps(data))
r = requests.post(bjb_sam_url, json=data)
if r:
log_web_info(r.text)
# log_web_info(r.json())
if r.text:
try:
return r.json()
except:
log_web_info(r.text)
raise BaseError
return
class Transaksi(object):
def __init__(self, p, method, inq, pay, conf):
self.settings = get_settings()
self.conf = conf
self.response = None
if method == "reversal": # data Payment ada (berarti reversal)
self.mti = "0400"
self.data["processingCode"] = PAY_CODE
# todo reversal tidak diperbolehkan
elif method == "payment": # data Inq ada (berarti payment)
db_session = get_db_session()
# pay = db_session.query(LogSam).filter_by(rpc_id=inq.id,
# mti="0200", bit_003=PAY_CODE).first()
# if pay:
pay = db_session.query(LogSam). \
filter_by(rpc_id=inq.id,
mti="0210", bit_003=PAY_CODE).first()
if pay:
raise AlreadyPaidError()
inq = db_session.query(LogSam). \
filter_by(rpc_id=inq.id,
mti="0210", bit_003=INQ_CODE).first()
if not inq:
raise BillRefNotFound()
self.mti = "0200"
self.data = inq.message
self.data["processingCode"] = PAY_CODE
self.set_local_time()
# todo: STAN seunik mungkin karena dikhawatirkan dengan detik yang
# sama terdapat payment dengan STAN yang sama
self.data["systemTraceAuditNumber"] = self.data["timeLocalTransaction"]
else:
self.mti = "0200"
# todo apa perlu dicopy?
self.data = INQ_REQ.copy()
self.data["aggregatorCode"] = "agg_code" in conf \
and conf["agg_code"] or "W0227"
self.data["caCode"] = "ca_code" in conf and conf["ca_code"] \
or "CA1864"
self.data["processingCode"] = INQ_CODE
self.data["billInformation"]["bills"][0]["info"] = p["invoice_id"]
self.set_local_time()
def set_local_time(self):
time = datetime.now()
self.data["timeLocalTransaction"] = time.strftime("%H%M%S")
self.data["localTransactionDate"] = time.strftime("%m%d")
self.data["transmissionDateTime"] = time.strftime("%m%d%H%M%S")
self.data["settlementDate"] = time.strftime("%m%d")
def get_stan(self):
return self.data["systemTraceAuditNumber"]
def send(self):
self.response = send_data(self.data, self.conf)
self.mti = self.mti == "0200" and "0210" or "0410"
class InquiryResponse(InquiryResponseBase):
def __init__(self):
inq_resp_field = INQUIRY_RESP_FIELDS
inq_resp_field.append('Bill Data')
Row.__init__(inq_resp_field)
class PaymentResponse(InquiryResponse):
def __init__(self):
inq_resp_field = PAYMENT_RESP_FIELDS
inq_resp_field.append('Bill Data')
Row.__init__(self, inq_resp_field)
INVOICE_PROFILE = [
("NOMOR BAYAR", 16, "N"),
("NOMOR RANGKA", 25),
("NOMOR MESIN", 25),
("NOMOR IDENTITAS", 18, "N"),
("NAMA PEMILIK", 25),
("ALAMAT PEMILIK", 40),
("NOMOR POLISI", 9),
("WARNA PLAT", 6),
("MILIK KE", 3, "N"),
("NAMA JENIS KB", 15),
("NAMA MEREK KB", 15),
("NAMA MODEL KB", 30),
("TAHUN BUATAN", 4, "N"),
("TGL AKHIR PAJAK LAMA", 8, "N"),
("TGL AKHIR PAJAK BARU", 8, "N"),
("POKOK BBN", 12, "N"),
("DENDA BBN", 12, "N"),
("POKOK PKB", 12, "N"),
("DENDA PKB", 12, "N"),
("POKOK SWD", 12, "N"),
("DENDA SWD", 12, "N"),
("POKOK ADM", 12, "N"),
# ("STNK POKOK", 12, "N"),
("ADM TNKB", 12, "N"),
("JUMLAH", 12, "N"),
("KETERANGAN", 90),
("RESERVED_01", 5)
]