simulator.py
2.01 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
from pprint import pprint
from datetime import datetime
from hashlib import md5
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.view import view_config
from resp_test import (
INQ_RESP,
PAY_RESP,
REV_RESP,
)
BASE_PATH = '/api/v2/intg'
INQUIRY_PATH = '/'.join([
BASE_PATH,
'ext_bjb_inq/{username}/{password}/{invoice_id}'])
PAYMENT_PATH = '/'.join([
BASE_PATH,
'ext_bjb_pay/{username}/{password}/{invoice_id}/{ntb}/{nominal}'])
REVERSAL_PATH = '/'.join([
BASE_PATH,
'ext_bjb_rev/{username}/{password}/{invoice_id}/{ntb}'])
def send(r):
print('Response:')
pprint(r)
return r
def create_ntp():
ntp = datetime.now().strftime('%Y%m%d%H%M%S')
return md5(ntp.encode('utf-8')).hexdigest()
@view_config(renderer='json', route_name='inquiry')
def view_inquiry(request):
resp = dict(INQ_RESP)
resp['data'][0]['nomor_resi'] = request.matchdict['invoice_id']
return send(resp)
@view_config(renderer='json', route_name='payment')
def view_payment(request):
ntp = create_ntp()
waktu = datetime.now()
resp = dict(PAY_RESP)
resp['data'][0]['tgl'] = waktu.strftime('%d-%m-%Y')
resp['data'][0]['jam'] = waktu.strftime('%H:%M:%S')
resp['data'][0]['nomor_resi'] = request.matchdict['invoice_id']
resp['data'][0]['ntb'] = request.matchdict['ntb']
resp['data'][0]['ntp'] = ntp
return send(resp)
@view_config(renderer='json', route_name='reversal')
def view_reversal(request):
waktu = datetime.now()
resp = dict(REV_RESP)
resp['data'][0]['tgl'] = waktu.strftime('%d-%m-%Y')
resp['data'][0]['jam'] = waktu.strftime('%H:%M:%S')
resp['data'][0]['ntb'] = request.matchdict['ntb']
return send(resp)
with Configurator() as config:
config.add_route('inquiry', INQUIRY_PATH)
config.add_route('payment', PAYMENT_PATH)
config.add_route('reversal', REVERSAL_PATH)
config.scan()
app = config.make_wsgi_app()
server = make_server('0.0.0.0', 8080, app)
server.serve_forever()