bpjskes.py
6.48 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
from opensipkd.pasar.models import PartnerProduk
import requests
import xmltodict
from . import Vendor as VendorClass, vsi_status
from opensipkd.base.tools import log
class Vendor(VendorClass):
def get_bulan(self):
return int(self.invoice_det.produk.kode[6:])
def pars_data(self, data):
bulan = self.get_bulan()
product_id = self.invoice_det.produk.id
partner_id = self.invoice_det.h2h_ar_invoice.customer_id
discount = PartnerProduk.get_discount(partner_id, product_id)
admin = self.vendor_produk.produk.harga
pokok = "jmltagihan" in data and data["jmltagihan"] or 0
subtotal = pokok + admin
total = subtotal - discount
self.amt_buy = "totaltag" in data and int(data["totaltag"]) or 0
self.ant_sell = total
code = "rc" in data and int(data["rc"]) or 500
if code == 0:
self.status = 1
message="SUCCESS"
else:
self.status = vsi_status[str(code)]["status"]
if self.status == -3:
message = "GAGAL"
else:
message = "PENDING"
txts = "text" in data and data["text"].split("<br/>")
i = 0
nama = ""
anggota = 0
if len(txts)==9:
nama = txts[2]
str_ang = txts[3].split(":")
anggota = len(str_ang)>1 and int(str_ang[1]) or 0
"""
"data": [{
"nopel": "2091161532456",
"nama": "SUBCRIBER NAME",
"refno": "25641544",
"rincian":{
"pokok": 154200,
"denda": 0,
"admin": 2500,
"jml_bulan": 1,
"cabang": "-",
"bill_rest": 0,
"nm_cabang": "XXX",
"anggota": 3
},
"subtotal": 156700,
"discount": 300,
"total": 156400
}]
"""
"""
<?xml version="1.0"?>
<root>
<status>SUCCESS</status>
<rc>0000</rc>
<rcm>[0] Cek Tagihan Sukses ke:888880000100 refnum:1362F31B7D42455DAE3942E1F0292C02</rcm>
<text>INFORMASI TAGIHAN BPJS KESEHATAN<br/>
ID PEL:888880000100, JML BLN:1, NO HP:<br/>
EKI HENDRAWANBRATA<br/>
JUMLAH PESERTA : 3<br/>
TAG Rp:255.000<br/>
ADM Rp:2.500<br/>
TOTALRp:257.500<br/>
TOTAL SALDO : 0<br/>
TOTAL PREMI : 255.000<br/>
</text>
<refnum>1362F31B7D42455DAE3942E1F0292C02</refnum>
<input1>888880000100</input1>
<jmltagihan>255000</jmltagihan>
<admin>2500</admin>
<totaltag>257500</totaltag>
<info1>0</info1>
<info2>255000</info2>
<infotext/>
</root>
"""
return {
"code": code,
"status": message,
"message": "rcm" in data and "Transaksi %s" % message or "No Response From Biller",
"refno": "refnum" in data and data["refnum"] or "",
"nopel": "idpel" in data and data["idpel"] or self.id_pel,
"nama": nama,
"rincian":{
"pokok": pokok,
"denda": 0,
"admin": admin,
"jml_bulan": bulan,
"cabang": "-",
"bill_rest": 0,
"nm_cabang": "XXX",
"anggota": anggota
},
"subtotal": subtotal,
"discount": discount,
"total": total,
}
def save_response(self, data, typ="inquiry"):
self.response = data
log.info("Response: %s", data)
self.save_log(typ)
return data
def inquiry(self):
params = self.get_params(cmd='INQ', modul='gp')
params["input1"] = self.id_pel
params["input2"] = self.get_bulan()
params["biller"] = '0060012'
self.request = params
self.save_log('inquiry')
log.info("Request: %s", params)
try:
resp = requests.get(self.url, params=params, timeout=15)
if resp and resp.ok:
data = dict(xmltodict.parse(resp.text)["root"])
log.info("Response: %s", data)
self.response = data
else:
data = dict(message=resp.text,
code=resp.status_code)
self.response = data
except requests.exceptions.RequestException as e:
data = dict(message = e.strerror,
code = e.errno)
return self.save_response(data)
if not resp:
data = dict(message="No Response From Biller ",
code=500)
return self.save_response(data)
data = self.pars_data(data)
self.result = data
return self.save_response(data)
def payment(self):
params = self.get_params(cmd='PAY', modul='gp')
params["input1"] = self.id_pel
params["input2"] = self.get_bulan()
params["biller"] = '0060012'
self.request = params
self.save_log('payment')
try:
resp = requests.get(self.url, params=params, timeout=15)
if resp.ok:
data = dict(xmltodict.parse(resp.text)["root"])
else:
data = dict(code=resp.status_code,
message=resp.text)
self.response = data
except:
data = dict(code=500,
message="No Response From Biller")
data = self.pars_data(data)
self.save_log('payment')
return data
def advice(self):
params = self.get_params(cmd='ADV', modul='gp')
params["input1"] = self.id_pel
params["input2"] = self.get_bulan()
params["biller"] = '0060012'
self.request = params
self.save_log('advice')
try:
resp = requests.get(self.url, params=params, timeout=15)
if resp.ok:
data = dict(xmltodict.parse(resp.text)["root"])
self.response = data
else:
data = dict(code=resp.status_code,
message=resp.text)
self.response = data
except:
data = dict(code=500,
message="No Response From Biller")
self.response = data
data = self.pars_data(data)
self.result = data
self.save_log('advice')
return data