structure.py
11 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# import colander
# from opensipkd.string.row import Row
# from .exceptions import InternalError
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
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_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"
}
PAY_REQ = \
{
"processingCode": PAY_CODE,
"sequenceNumber": "",
"sourceAccountNumber": "0098889231001",
"systemTraceAuditNumber": "",
"terminalAggregator": {
"cardAcceptorName": "NAEE ",
"terminalIdentifierNumber": "1 ",
"terminalName": "TERM "
},
"settlementDate": "0326",
"timeLocalTransaction": "090210",
"track2Data": "622011888888888888=9912?",
"transmissionDateTime": "0107180458"
}
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
# todo butuh server buat testing json sementara pake static response
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
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
#stan = int(self.data["systemTraceAuditNumber"])+1
#self.data["systemTraceAuditNumber"] = str(stan).zfill(6)
self.set_local_time()
#elf.data["systemTraceAuditNumber"] = str(stan).zfill(6)
self.data["systemTraceAuditNumber"] = self.data["timeLocalTransaction"]
else:
self.mti = "0200"
self.data = INQ_REQ.copy()
# self.data["systemTraceAuditNumber"] = "880977"
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"
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)
]
INQ_RESP = \
{
"additionalData": "361198483250691012345678901234564 54P879211 3603110611710004 TUMINO NUANSA MEKARSARI B - 1 / 15 RT 004/006 KA 3538 XCBIRU 001SEPEDA MOTOR R2YAMAHA 54P (CAST WHEEL) AT 20132020090920210909000000000000000000000000000000154000000000000000000000035000000000000000000000000000000000000000000000189000SUKSES 01",
"aggregatorCode": "W0216",
"amountInformation": {
"billAmount": "890000",
"feeAggregator": "0",
"feeBJB": "0",
"totalAmount": "890000"
},
"amountTransaction": "890000",
"billInformation": {
"bills": [
{
"info": "1000000108767"
}, {
"info": "ALBUS DUMBLEDORE"
}, {
"info": "BLACK MAGIC"
}, {
"info": "BLACK MAGIC 101"
}, {
"info": "890000"
}, {
"info": "0"
}, {
"info": "2019"
}, {
"info": "0"
}, {
"info": " "
}, {
"info": " REG"
}, {
"info": " "
}
]
},
"caCode": "CA1830",
"currencyCode": "360",
"destinationAccountNumber": "0012199936360 ",
"featureCode": "009",
"localTransactionDate": "0326",
"merchantType": "6015",
"pay": "PAY",
"posEntryModeCode": "110",
"primaryAccountNumber": "622011888888888888",
"processingCode": "321000",
"responseCode": "00",
"sequenceNumber": "000000880977",
"settlementDate": "0326",
"sourceAccountNumber": "0098889231001",
"systemTraceAuditNumber": "880977",
"terminalAggregator": {
"cardAcceptorName": "NAEE ",
"terminalIdentifierNumber": "1 ",
"terminalName": "TERM "
},
"timeLocalTransaction": "090210",
"track2Data": "622011888888888888=9912?",
"transmissionDateTime": "0107180458"
}
# PAYMENT
PAY_RESP = \
{
"additionalData": "'361198483250691012345678901234564 54P879211 3603110611710004 TUMINO NUANSA MEKARSARI B - 1 / 15 RT 004/006 KA 3538 XCBIRU 001SEPEDA MOTOR R2YAMAHA 54P (CAST WHEEL) AT 20132020090920210909000000000000000000000000000000154000000000000000000000035000000000000000000000000000000000000000000000189000SUKSES 01",
"aggregatorCode": "W0216",
"amountInformation": {
"billAmount": "206500",
"feeAggregator": "0",
"feeBJB": "0",
"totalAmount": "206500"
},
"amountTransaction": "000000890000",
"billInformation": {
"bills": [{
"info": "1000000108767"
}, {
"info": "ALBUS DUMBLEDORE"
}, {
"info": "BLACK MAGIC"
}, {
"info": "BLACK MAGIC 101"
}, {
"info": "890000"
}, {
"info": "0"
}, {
"info": "2019"
}, {
"info": "0"
}, {
"info": " "
}, {
"info": " REG"
}, {
"info": " "
}
]
},
"caCode": "CA1830",
"currencyCode": "360",
"destinationAccountNumber": "0012199936360 ",
"featureCode": "009",
"localTransactionDate": "0326",
"merchantType": "6015",
"numberTransactionBank": '1234567890',
"numberTransactionP": '0987654321',
"pay": "PAY",
"posEntryModeCode": "110",
"primaryAccountNumber": "622011888888888888",
"processingCode": "521000",
"responseCode": "00",
"sequenceNumber": "000000502959",
"settlementDate": "0326",
"sourceAccountNumber": "0098889231001",
"systemTraceAuditNumber": "502959",
"terminalAggregator": {
"cardAcceptorName": "NAEE ",
"terminalIdentifierNumber": "1 ",
"terminalName": "TERM "
},
"timeLocalTransaction": "090210",
"track2Data": "622011888888888888=9912?",
"transmissionDateTime": "0107180458"
}