Commit 8dab2fbb by Solo Group

response payment

1 parent 828f31b3
......@@ -226,6 +226,9 @@ def purchase(request, data, **kwargs):
result = build_purchase(vendor_produk, ar_invoice_det)
total = "total" in result and result["total"] or 0
prod.update(result)
# Perhitungan Total
# Jika harga jual lebih besar dari harga beli jual dipakai harga jual
# jika harga lebih kecil dari harga beli maka harga beli ditambah admin_fee
if total:
if vendor_produk.produk.harga < total:
total += vendor_produk.produk.harga
......@@ -233,18 +236,6 @@ def purchase(request, data, **kwargs):
total = vendor_produk.produk.harga
prod.update(dict(total=total))
# ar_invoice_det.status = 'status' in result and result["status"] or 'FAILED'
# if result["code"] == 9:
# ar_invoice_det.amt_buy = result["response"].total
# discount = 0
# prod.update(
# dict(
# subtotal=ar_invoice_det.amt_sell,
# discount=discount,
# total=ar_invoice_det.amt_sell + discount
# )
# )
# prod.update(status=result["status"])
r_prod.append(prod)
ar_invoice.payment["response"] = r_prod
......
......@@ -8,6 +8,7 @@ from .vendor import VendorClass
from ..tools import log
import urllib3
urllib3.disable_warnings()
......@@ -22,7 +23,6 @@ class Vendor(VendorClass):
key = ":".join([self.mid, self.key]).encode()
self.auth = base64.b64encode(key).decode()
def request_post(self, params, url=None):
headers = {'Authorization': 'Bearer {key}'.format(key=self.auth)}
data = json.dumps(params)
......@@ -45,7 +45,7 @@ class Vendor(VendorClass):
return dict(code=9999,
message='Parameter tidak lengkap')
if self.v_produk_kd[:3] =='PLN' and self.v_produk_kd != 'PLNPASCA':
if self.v_produk_kd[:3] == 'PLN' and self.v_produk_kd != 'PLNPASCA':
params = dict(
number=self.id_pel
)
......@@ -90,11 +90,24 @@ class Vendor(VendorClass):
message="Other Error")
self.response = result
# self.save_log('inquiry')
self.result = parsd
self.save_log('inquiry')
return parsd
def gagal_transaksi(self):
self.status = -2
parsd = dict(
status="FAILED",
code=-2,
message="Gagal Transaksi"
)
self.result = parsd
self.save_log('payment')
return parsd
def payment(self):
params = dict(data=dict(
params = dict(
data=dict(
denom=self.v_produk_kd,
number=self.id_pel
)
......@@ -105,60 +118,55 @@ class Vendor(VendorClass):
resp = self.request_post(params, '/prepaid/purchase')
try:
result = json.loads(resp.text)
success = True
except:
result = resp.text
success = False
self.response = result
log.info("ODEO Payment Response: %s" % self.response)
if resp.ok:
# self.status = 1 # sukses
if success:
#result["code"] = 0
#if result["status"]=="SUCCESS":
# self.status = 1
#elif result["status"]=="PENDING":
# self.status = -1
#elif result["status"]=="GAGAL":
# self.status = -2
# odeo mengembalikan result dalam bentuk status
# 0200 ok
# 0400 bad request
# 0401 auth error
parsd = {}
if resp.status_code == 200: # 0200
data = "data" in result and result["data"] or None
if data:
self.vend_inv_no = "order_id" in data and data["order_id"] or None
self.amt_buy = "price" in data and data["price"] or 0
parsd = self.pars_data(data)
else:
# parsd = self.pars_data(data)
# if not parsd:
self.status = -4
parsd = dict(code=500,
message="Other Error",
status="FAILED")
# cel rc status
if not data:
return self.gagal_transaksi()
if "rc" in data:
parsd["code"] = int(data["rc"])
elif resp.status_code==400: # BAD REQUEST
self.status = -3
parsd = dict(code=resp.status_code,
message=result,
status="FAILED")
if data["rc"] == "13":
parsd["status"] = "FAILED"
self.status = -2
elif data["rc"] == "68":
parsd["status"] = "PENDING"
self.status = -1 # pending
elif data["rc"] == "67":
parsd["status"] = "DOUBLE"
self.status = -2 # Gagal Karena Pernah Transaksi
# Status ini hanya sementara nunggu refund
# Status -2 ini harus dicari solusi mencari vendor lain
else:
self.status = -4 # Other Error
parsd = dict(code=500,
message="Other Error",
status="FAILED")
self.status = 1
parsd["code"] = 0
parsd["status"] = "SUCCESS"
self.serial_number = 'serial_number' in data and data["serial_numner"] \
or self.serial_number
#if 'ref_no' in parsd:
# self.vend_inv_no = parsd["ref_no"]
self.vend_inv_no = "order_id" in data and data["order_id"] or None
self.amt_buy = "price" in data and data["price"] or 0
parsd["total"] = self.amt_buy
self.result = parsd
self.save_log('payment')
#txt = "ODEO PARSING: {d}".format(d=json.dumps(parsd))
#log.info(txt)
return parsd
else: # BAD REQUEST
return self.gagal_transaksi()
def advice(self):
if not self.v_produk_kd or not self.id_pel or not self.invoice_det:
return dict(code=9999,
......@@ -192,7 +200,7 @@ class Vendor(VendorClass):
data = "data" in result and result["data"] or None
parsd = self.pars_data(data)
elif resp.status_code==400:
elif resp.status_code == 400:
self.status = -3
parsd = dict(code=resp.status_code,
message=resp.text)
......@@ -207,35 +215,9 @@ class Vendor(VendorClass):
def pars_data(self, data):
result = dict()
# result["trx_id"] = self.partner_log_id
# result["id_pel"] = self.id_pel
# result["cust_trx"] = self.cust_trx
# result["vend_trx"] = self.vend_trx
# result['harga'] = self.amt_buy
if not data:
return result
if "rc" in data:
if data["rc"] == "13":
result["status"] = "FAILED"
self.status = -2
elif data["rc"] == "68":
result["status"] = "PENDING"
self.status = 0 #pending
elif data["rc"] == "67":
result["status"] = "FAILED"
self.status = -2 # Gagal Karena Pernah Transaksi
else:
self.status = 1
result["code"] = 0
result["status"] = "SUCCESS"
self.serial_number = 'serial_number' in data and data["serial_numner"] \
or self.serial_number
if 'price' in data:
result["total"] = data["price"]
if "subscriber_id" in data and data["subscriber_id"]:
result['id_pel'] = data["subscriber_id"]
if "name" in data and data["name"]:
......@@ -265,7 +247,7 @@ class Vendor(VendorClass):
result["rincian"] = rincian
return result
if self.v_produk_kd=="PLNPASCA" or self.v_produk_kd[:3]=="PAM":
if self.v_produk_kd == "PLNPASCA" or self.v_produk_kd[:3] == "PAM":
pokok = denda = admin = 0
period = meter = ""
jml_period = 0
......@@ -357,13 +339,13 @@ class Vendor(VendorClass):
if "installment" in inquiries:
if "periode" in rincian:
rincian['periode'] += " "+inquiries["installment"]
rincian['periode'] += " " + inquiries["installment"]
else:
rincian['periode'] = inquiries["installment"]
if "due_date" in inquiries:
if "jth_tempo" in rincian:
rincian['jth_tempo'] += " "+inquiries["due_date"]
rincian['jth_tempo'] += " " + inquiries["due_date"]
else:
rincian['jth_tempo'] = inquiries["due_date"]
......@@ -379,7 +361,7 @@ class Vendor(VendorClass):
if "participant_counts" in inquiries:
rincian['anggota'] = inquiries["participant_counts"]
i+=1
i += 1
result['jml_data'] = i
result['rincian'] = rincian
......
......@@ -44,6 +44,7 @@ class VendorClass(object):
self.id_pel = invoice_det and invoice_det.id_pel or None
self.request = None
self.response = None
self.result = None
self.vend_inv_no = invoice_det and invoice_det.vend_inv_no or None
self.status = invoice_det and invoice_det.status or 0
......@@ -80,7 +81,8 @@ class VendorClass(object):
response=self.response)
elif typ == 'payment':
self.invoice_det.payment = dict(request=self.request,
response=self.response)
response=self.response,
result=self.result)
elif typ == 'advice':
self.invoice_det.advice = dict(request=self.request,
response=self.response)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!