Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Kunto
/
backoffice
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 4ce7d60d
authored
Nov 06, 2019
by
yasir
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
merapikan, merubah status purchase ke pending, merubah value MCC, update nilai total admin
1 parent
2f67bcc4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
166 deletions
src/agratek/api/merchant/views/mkm/__init__.py
src/agratek/api/merchant/views/mkm/__init__.py
View file @
4ce7d60
...
...
@@ -22,7 +22,7 @@ timeout = 30
class
Vendor
(
VendorClass
):
def
__init__
(
self
,
vendor_produk
,
invoice_det
):
VendorClass
.
__init__
(
self
,
vendor_produk
,
invoice_det
=
invoice_det
)
VendorClass
.
__init__
(
self
,
vendor_produk
,
invoice_det
=
invoice_det
)
# id_pel, customer_id, cust_trx, row
settings
=
get_settings
()
# self.mid = 'odeo_mid' in settings and settings['odeo_mid'] or None
...
...
@@ -43,17 +43,11 @@ class Vendor(VendorClass):
params
=
{}
params
[
'Action'
]
=
'inquiry'
params
[
'ClientId'
]
=
self
.
userid
params
[
'MCC'
]
=
'6008'
params
[
'MCC'
]
=
6025
params
[
'KodeProduk'
]
=
self
.
v_produk_kd
params
[
'NomorPelanggan'
]
=
self
.
id_pel
# params = dict(
# 'Action' = 'inquiry',
# 'ClientId' = self.userid,
# 'MCC' = '6008',
# 'KodeProduk' = self.v_produk_kd,
# NomorPelanggan = self.id_pel
# )
params
=
json
.
dumps
(
params
)
self
.
request
=
params
log
.
info
(
"Inquiry Request: url:
%
s params
%
s"
%
(
self
.
url
,
params
))
...
...
@@ -67,40 +61,7 @@ class Vendor(VendorClass):
return
return
resp
def
inquiry
(
self
):
if
not
self
.
v_produk_kd
or
not
self
.
id_pel
:
return
self
.
set_response
(
message
=
'Parameter tidak lengkap'
)
resp
=
self
.
_inquiry
()
if
resp
is
None
or
not
resp
.
text
:
log
.
info
(
"Resp Tidak Ada, {}"
.
format
(
resp
))
return
try
:
result
=
json
.
loads
(
resp
.
text
)
except
:
self
.
response
=
resp
.
text
return
self
.
set_failed
(
typ
=
"inquiry"
)
self
.
response
=
result
log
.
info
(
"Inquiry Response:
%
s"
%
self
.
response
)
if
resp
.
status_code
==
200
:
self
.
status
=
1
# sukses
data
=
self
.
response
parsd
=
self
.
pars_data
(
data
)
return
self
.
set_success
(
parsd
,
"inquiry"
)
# parsd
elif
resp
.
status_code
==
400
:
data
=
self
.
response
message
=
""
if
data
and
"ErrorMessage"
in
data
:
msg
=
data
[
"ErrorMessage"
][
0
]
pos
=
msg
.
find
(
"Sisa saldo"
)
message
=
pos
>
-
1
and
msg
[:
pos
]
or
msg
parsd
=
self
.
pars_data
(
data
)
return
self
.
set_failed
(
parsd
,
message
=
message
,
typ
=
"inquiry"
)
def
payment
(
self
):
def
_integrate_inquiry
(
self
):
parsd
=
None
response_inquiry
=
self
.
_inquiry
()
#plain json type
...
...
@@ -119,38 +80,78 @@ class Vendor(VendorClass):
self
.
response
=
result_inquiry
# should be json serializable
message_log
=
'Success'
parsd
=
self
.
pars_data
(
result_inquiry
)
# parsing to user information
if
response_inquiry
.
status_code
==
200
:
#answered request
is_error
=
'ErrorMessage'
in
result_inquiry
and
result_inquiry
[
'ErrorMessage'
]
or
''
is_error
=
is_error
!=
''
and
result_inquiry
[
'Status'
]
!=
'0000'
if
is_error
:
self
.
status
=
0
error_msg
=
result_inquiry
[
'ErrorMessage'
]
error_status
=
result_inquiry
[
'Status'
]
error_msg
=
is_error
message_log
=
'['
+
error_status
+
'] '
+
error_msg
parsd
=
self
.
pars_data
(
result_inquiry
)
# parsing to user information
is_error
=
is_error
!=
''
and
error_status
!=
'0000'
if
is_error
:
self
.
status
=
0
return
self
.
set_failed
(
parsd
,
message
=
message_log
,
typ
=
"inquiry"
)
# error means failed
else
:
# nothing goes wrong, will continue to payment sequences
self
.
status
=
1
# sukses
parsd
=
self
.
pars_data
(
result_inquiry
)
print
(
'inq_sukses >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
)
return
result_inquiry
# return self.set_success(parsd, typ = "inquiry")
else
:
# network fail or any other errors
message_log
=
'Terjadi kesalahan Server Pembayaran.'
return
self
.
set_failed
(
parsd
,
typ
=
"inquiry"
)
def
inquiry
(
self
):
if
not
self
.
v_produk_kd
or
not
self
.
id_pel
:
return
self
.
set_response
(
message
=
'Parameter tidak lengkap'
)
response_inquiry
=
self
.
_inquiry
()
if
response_inquiry
is
None
or
not
response_inquiry
.
text
:
log
.
info
(
"Resp Tidak Ada, {}"
.
format
(
response_inquiry
))
return
try
:
result_inquiry
=
json
.
loads
(
response_inquiry
.
text
)
except
:
self
.
response
=
response_inquiry
.
text
return
self
.
set_failed
(
typ
=
"inquiry"
)
self
.
response
=
result_inquiry
log
.
info
(
"Inquiry Response:
%
s"
%
self
.
response
)
parsd
=
self
.
pars_data
(
result_inquiry
)
# parsing to user information
if
response_inquiry
.
status_code
==
200
:
#answered request
is_error
=
'ErrorMessage'
in
result_inquiry
and
result_inquiry
[
'ErrorMessage'
]
or
''
is_error
=
is_error
!=
''
and
result_inquiry
[
'Status'
]
!=
'0000'
if
is_error
:
error_msg
=
result_inquiry
[
'ErrorMessage'
]
error_status
=
result_inquiry
[
'Status'
]
error_msg
=
is_error
message_log
=
'['
+
error_status
+
'] '
+
error_msg
parsd
=
self
.
pars_data
(
result_inquiry
)
is_error
=
is_error
!=
''
and
error_status
!=
'0000'
if
is_error
:
self
.
status
=
0
return
self
.
set_failed
(
parsd
,
message
=
message_log
,
typ
=
"inquiry"
)
# error means failed
else
:
# nothing goes wrong, will continue to payment sequences
self
.
status
=
1
# sukses
return
self
.
set_success
(
parsd
,
typ
=
"inquiry"
)
else
:
# network fail or any other errors
return
self
.
set_failed
(
parsd
,
typ
=
"inquiry"
)
def
payment
(
self
):
parsd
=
None
return
self
.
set_failed
(
parsd
,
message
=
message_log
,
typ
=
"inquiry"
)
result_inquiry
=
self
.
_integrate_inquiry
()
tagihan_list_inq
=
result_inquiry
[
'Tagihan'
]
tagihan_list_pay
=
[]
...
...
@@ -169,7 +170,7 @@ class Vendor(VendorClass):
Action
=
"payment"
,
ClientId
=
self
.
userid
,
KodeProduk
=
self
.
v_produk_kd
,
MCC
=
60
08
,
MCC
=
60
25
,
SessionId
=
result_inquiry
[
'SessionId'
],
NomorPelanggan
=
result_inquiry
[
'NomorPelanggan'
],
Tagihan
=
tagihan_list_pay
,
...
...
@@ -201,93 +202,54 @@ class Vendor(VendorClass):
self
.
response
=
result_payment
log
.
info
(
"Payment Response:
%
s"
%
self
.
response
)
if
response_payment
.
status_code
==
200
:
#answered request
is_error
=
'ErrorMessage'
in
result_payment
and
result_payment
[
'ErrorMessage'
]
or
''
is_error
=
is_error
!=
''
and
result_payment
[
'Status'
]
!=
'0000'
if
is_error
:
self
.
status
=
0
error_msg
=
result_payment
[
'ErrorMessage'
]
error_status
=
result_payment
[
'Status'
]
message_log
=
'['
+
error_status
+
'] '
+
error_msg
parsd
=
self
.
pars_data
(
result_payment
)
# parsing to user information
return
self
.
set_failed
(
parsd
,
message
=
message_log
,
typ
=
"payment"
)
# error means failed
else
:
# nothing goes wrong, the next process should be waiting for the notify ? or just checking regularly by advice request ?
# there is no notify url parameter in the payment request.
# so i set it in pending status ?
self
.
status
=
1
# sukses
parsd
=
self
.
pars_data
(
result_payment
)
message_log
=
"Request Advice untuk cek status."
return
self
.
set_pending
(
parsd
,
message
=
message_log
,
typ
=
"payment"
)
def
advice
(
self
):
# if not self.v_produk_kd or not self.id_pel or not self.invoice_det:
# return dict(code=9999,
# message='Parameter tidak lengkap')
parsd
=
None
response_inquiry
=
self
.
_inquiry
()
#plain json type
if
response_inquiry
is
None
or
not
response_inquiry
.
text
:
log
.
info
(
"Resp Tidak Ada, {}"
.
format
(
response_inquiry
))
return
try
:
result_inquiry
=
json
.
loads
(
response_inquiry
.
text
)
# converting to dictionary type
except
:
self
.
response
=
response_inquiry
.
text
#converting to readable string
return
self
.
set_failed
(
typ
=
"inquiry"
)
# failing while parsing json to dictionary
if
response_payment
.
status_code
==
200
:
#answered request
is_error
=
'ErrorMessage'
in
result_payment
and
result_payment
[
'ErrorMessage'
]
or
''
log
.
info
(
"Inquiry Response:
%
s"
%
self
.
response
)
error_status
=
result_payment
[
'Status'
]
error_msg
=
is_error
message_log
=
'['
+
error_status
+
'] '
+
error_msg
self
.
response
=
result_inquiry
# should be json serializable
message_log
=
'Success'
is_error
=
is_error
!=
''
and
error_status
!=
'0000'
if
response_inquiry
.
status_code
==
200
:
#answered request
is_error
=
'ErrorMessage'
in
result_inquiry
and
result_inquiry
[
'ErrorMessage'
]
or
''
is_error
=
is_error
!=
''
and
result_inquiry
[
'Status'
]
!=
'0000'
if
is_error
:
self
.
status
=
0
error_msg
=
result_inquiry
[
'ErrorMessage'
]
error_status
=
result_inquiry
[
'Status'
]
message_log
=
'['
+
error_status
+
'] '
+
error_msg
parsd
=
self
.
pars_data
(
result_inquiry
)
# parsing to user information
return
self
.
set_failed
(
parsd
,
message
=
message_log
,
typ
=
"inquiry"
)
# error means failed
if
error_status
==
'0068'
:
return
self
.
set_pending
(
parsd
,
typ
=
"payment"
)
else
:
# nothing goes wrong, will continue to advice sequences
return
self
.
set_failed
(
parsd
,
message
=
message_log
,
typ
=
"payment"
)
# error means failed
else
:
# nothing goes wrong, will continue to payment sequences
self
.
status
=
1
# sukses
parsd
=
self
.
pars_data
(
result_inquiry
)
print
(
'inq_sukses >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
)
return
self
.
set_pending
(
parsd
,
typ
=
"payment"
)
else
:
# network fail or any other errors
message_log
=
'Terjadi kesalahan Server.'
is_error
=
'ErrorMessage'
in
result_inquiry
and
result_inquiry
[
'ErrorMessage'
]
or
''
is_error
=
is_error
!=
''
and
result_inquiry
[
'Status'
]
!=
'0000'
if
is_error
:
error_msg
=
result_inquiry
[
'ErrorMessage'
]
error_status
=
result_inquiry
[
'Status'
]
message_log
=
'['
+
error_status
+
'] '
+
error_msg
return
self
.
set_failed
(
parsd
,
typ
=
"payment"
)
def
advice
(
self
):
# if not self.v_produk_kd or not self.id_pel or not self.invoice_det:
# return dict(code=9999,
# message='Parameter tidak lengkap')
parsd
=
self
.
pars_data
(
result_inquiry
)
parsd
=
None
return
self
.
set_failed
(
parsd
,
message
=
message_log
,
typ
=
"inquiry"
)
result_inquiry
=
self
.
_integrate_inquiry
()
tagihan_list_inq
=
result_inquiry
[
'Tagihan'
]
tagihan_list_pay
=
[]
total_admin
=
0
# total_admin = 0
total_admin
=
int
(
self
.
vendor_produk
.
produk
.
harga
*
len
(
tagihan_list_inq
))
for
item
in
tagihan_list_inq
:
tagihan_pay
=
{}
tagihan_pay
[
'Periode'
]
=
item
[
'Periode'
]
tagihan_pay
[
'Total'
]
=
item
[
'Total'
]
total_admin
=
total_admin
+
item
[
'Total'
]
#
total_admin = total_admin + item['Total']
tagihan_list_pay
.
append
(
tagihan_pay
)
...
...
@@ -295,7 +257,7 @@ class Vendor(VendorClass):
Action
=
"advice"
,
ClientId
=
self
.
userid
,
KodeProduk
=
self
.
v_produk_kd
,
MCC
=
60
08
,
MCC
=
60
25
,
SessionId
=
result_inquiry
[
'SessionId'
],
NomorPelanggan
=
result_inquiry
[
'NomorPelanggan'
],
Tagihan
=
tagihan_list_pay
,
...
...
@@ -327,51 +289,6 @@ class Vendor(VendorClass):
return
parsd
# if self.kategori == 'e-payment':
# order_id = self.invoice_det.vend_inv_no
# url = self.get_url()
# params = None
# self.request = url
# else:
# params = dict(
# data=dict(
# denom=self.v_produk_kd,
# number=self.id_pel
# )
# )
# self.request = params
# url = self.get_url()
# self.save_log("advice")
# try:
# resp = requests.get(url, params=params, verify=False,
# headers=self.get_headers(), timeout=timeout)
# except:
# return self.set_response()
# try:
# result = json.loads(resp.text)
# except:
# result = resp.text
# self.response = result
# if resp.ok:
# self.status = 1 # sukses
# data = "data" in result and result["data"] or None
# parsd = self.pars_data(data)
# return self.set_success(parsd, "payment")
# elif resp.status_code == 400:
# self.status = -3
# parsd = dict(code=resp.status_code,
# message=resp.text)
# else:
# self.status = -4
# parsd = dict(code=500,
# message="Other Error")
# self.save_log('advice')
# return parsd
def
pars_data
(
self
,
data
):
result
=
dict
()
print
(
'isi data pars data >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
)
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment