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 31d093b9
authored
Aug 28, 2019
by
Tatang
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
np register
1 parent
5da8ce29
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
658 additions
and
367 deletions
src/agratek/api/merchant/views/api_merchant.py
src/agratek/api/merchant/views/api_payment.py
src/agratek/api/merchant/views/np/__init__.py
src/agratek/api/merchant/views/vendor.py
src/agratek/api/merchant/views/api_merchant.py
View file @
31d093b
import
logging
from
importlib
import
import_module
from
opensipkd.base.models
import
Partner
,
flush_row
from
opensipkd.base.tools.api
import
(
auth_from_rpc
,
...
...
@@ -6,8 +7,8 @@ from opensipkd.base.tools.api import (auth_from_rpc,
from
opensipkd.pasar.models
import
Produk
,
PartnerProduk
from
opensipkd.pasar.models.produk
import
H2hArInvoice
,
H2hArInvoiceDet
,
PartnerLog
from
pyramid_rpc.jsonrpc
import
jsonrpc_method
from
opensipkd.base.tools
import
get_settings
import
logging
from
..tools
import
JsonRpcInvoiceFoundError
,
JsonRpcError
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -17,16 +18,13 @@ def build_request(typ, vendor_produk, partner_log=None):
# bill_no = values['destination']
# customer_id = 'customer_id' in values and values['customer_id'] or None
# cust_trx_id = 'cust_trx_id' in values and values['cust_trx_id'] or None
pckgs
=
'agratek.api.merchant.views'
moduls
=
vendor_produk
.
modules
.
split
(
'.'
)
if
len
(
moduls
)
>
1
:
pckg
=
"."
.
join
(
moduls
[:
-
1
])
pckgs
=
"."
.
join
([
pckgs
,
pckg
])
moduls
=
moduls
[
-
1
:]
modul
=
moduls
[
0
]
log
.
info
(
"Module:
%
s Pckgs:
%
s"
%
(
modul
,
pckgs
))
modul
=
'.'
+
modul
modules
=
import_module
(
modul
,
pckgs
)
...
...
@@ -42,15 +40,12 @@ def build_request(typ, vendor_produk, partner_log=None):
result
[
"f_response"
]
=
cls_module
.
response
result
[
"f_result"
]
=
cls_module
.
result
result
[
"f_request"
]
=
cls_module
.
request
else
:
log
.
info
(
"Module
%
s Not Found"
%
vendor_produk
.
modules
)
data
=
dict
(
message
=
'Fungsi
%
s tidak ada'
%
typ
,
code
=
9999
)
result
=
{
"f_result"
:
data
}
# dict(data=)
return
result
...
...
@@ -74,64 +69,24 @@ def get_vendor_produk(produk_kd, vendor_kd=None, harga=None):
"""
Fungsi ini digunakan untuk mencari vendor yang paling murah
:param produk_kd: String Kode Produk
:param level: Digunakan sebagai parameter jika yang paling murah tidak ditemukan
:param vendor_kd: Kode Vendor
:param harga: harga produk
:return: row objek dari Partner Produk
"""
### Jika parameter level tidak disebutkan
# settings = get_settings()
qry
=
qry_vendor_produk
()
qry
=
qry_vendor_produk
()
.
filter
(
Produk
.
kode
==
produk_kd
)
# Jika parameter vendor_kd disebutkan maka secara explisit mengambil dari
# data vendor parameter secara default mengambil dari yang statusnya=1
if
vendor_kd
:
log
.
info
(
vendor_kd
)
return
qry
\
.
filter
(
Partner
.
kode
==
vendor_kd
)
\
.
filter
(
Produk
.
kode
==
produk_kd
)
.
first
()
# if is_devel():
# settings = get_settings()
# vend_kd = 'dev_vend_kd' in settings and settings ['dev_vend_kd'] or 'test'
# log.info(vend_kd)
# return qry \
# .filter(Partner.kode == vend_kd) \
# .filter(Produk.kode == produk_kd).first()
# else:
result
=
qry
\
.
filter
(
Produk
.
kode
==
produk_kd
)
.
order_by
(
PartnerProduk
.
harga
)
# row = result.filter(PartnerProduk.harga > harga).first()
row
=
result
.
first
()
# if not row:
# harga = 0
# row = result.filter(PartnerProduk.harga > harga).first()
qry
=
qry
.
filter
(
Partner
.
kode
==
vendor_kd
)
else
:
qry
=
qry
.
filter
(
PartnerProduk
.
status
==
1
)
row
=
qry
.
first
()
return
row
@jsonrpc_method
(
method
=
'inquiry'
,
endpoint
=
'api-merchant'
)
def
inquiry
(
request
,
data
,
**
kwargs
):
"""
Digunakan untuk mendapatkan daftar produk
:param request:
:param data:
{
product_kd: string, //optional
cid:string //optional
}
:param token:
user_token
:return:
{
product_kd:string,
product_nm:string,
harga:integer,
admin:integer,
discount:integer
}
"""
"""
Digunakan untuk mendapatkan daftar produk
Digunakan untuk mendapatkan data tagihan
:param request:
:param data:
{
...
...
@@ -140,20 +95,25 @@ def inquiry(request, data, **kwargs):
}
:param token:
user_token
:return:
{
product_nm:string,
denom: string,
id_pel:string
inv_no: string optional
denom:string,
harga:integer,
admin:integer,
discount:integer,
total:integer,
status:success/pending/failed
{
"data": [{
"nopel": "530678910981",
"nama": "SUBCRIBER NAME",
"refno": "25641544",
"rincian":{
"pokok": 300000,
"denda": 0,
"admin": 2500,
"tarif": "R1
\
/1300VA",
"no_meter": "530678910012",
"power": "1300VA"
},
"subtotal": 302500,
"discount": 800,
"total": 301700
}]
}
"""
user
=
auth_from_rpc
(
request
)
i
=
0
...
...
@@ -162,74 +122,35 @@ def inquiry(request, data, **kwargs):
customer
=
Partner
.
query_user
(
user
)
.
filter
(
Partner
.
is_customer
==
1
)
.
first
()
if
not
customer
:
raise
JsonRpcCustomerNotFoundError
()
r_data
=
[]
for
dat
in
data
:
cust_inv_no
=
'invoice_no'
in
data
and
dat
[
'invoice_no'
]
or
None
invoice
=
H2hArInvoice
.
query_invoice
(
cust_inv_no
)
.
first
()
produks
=
'produk'
in
dat
and
dat
[
'produk'
]
or
[]
for
prod
in
produks
:
# prods = "produk" in dat and dat["produk"] or None
# for prod in prods:
# log.info(prod)
produk_kd
=
'denom'
in
prod
and
prod
[
'denom'
]
or
None
if
not
produk_kd
:
raise
JsonRpcProdukNotFoundError
(
message
=
"Produk harus diisi"
)
vendor_produk
=
get_vendor_produk
(
produk_kd
)
if
not
vendor_produk
:
raise
JsonRpcProdukNotFoundError
(
message
=
"Produk
%
s tidak ditemukan"
%
produk_kd
)
# diremark by tatang
# partner_log = PartnerLog()
# partner_log.vendor_id = vendor_produk.partner_id
# partner_log.customer_id = customer.id
# partner_log.produk_id = vendor_produk.produk.id
# # partner_log.cust_inv = dat["inv_no"]
# partner_log.id_pel = prod["id_pel"]
# flush_row(partner_log)
# result = build_request('inquiry', vendor_produk, partner_log)
if
not
invoice
:
invoice
=
H2hArInvoice
()
invoice
.
customer_id
=
customer
.
id
invoice
.
cust_inv_type
=
2
invoice
.
cust_inv_no
=
cust_inv_no
flush_row
(
invoice
)
invoice_det
=
H2hArInvoiceDet
()
invoice_det
.
vendor_id
=
vendor_produk
.
partner_id
invoice_det
.
ar_invoice_id
=
invoice
.
id
invoice_det
.
produk_id
=
vendor_produk
.
produk
.
id
invoice_det
.
vendor_id
=
vendor_produk
.
partner_id
invoice_det
.
id_pel
=
prod
[
'id_pel'
]
flush_row
(
invoice_det
)
result
=
build_request
(
'inquiry'
,
vendor_produk
,
invoice_det
)
if
result
[
"code"
]
==
0
:
prod
.
update
(
result
)
# rincian = "rincian" in result and result["rincian"] or []
# if rincian:
# pokok = "pokok" in rincian and rincian["pokok"] or 0
# admin = result["jml_data"]*vendor_produk.produk.harga
# subtotal = pokok+admin
#
# discount = result["discount"] - result["jml_data"] * vendor_produk.produk.harga
# prod.update(dict(
# subtotal=result["subtotal"],
# discount=discount,
# total=result["subtotal"] - discount))
else
:
prod
.
update
(
dict
(
status
=
"FAILED"
,
message
=
result
[
"message"
]))
r_data
.
append
(
prod
)
for
prod
in
data
:
# prods = "produk" in dat and dat["produk"] or None
# for prod in prods:
# log.info(prod)
produk_kd
=
'denom'
in
prod
and
prod
[
'denom'
]
or
None
if
not
produk_kd
:
raise
JsonRpcProdukNotFoundError
(
message
=
"Produk harus diisi"
)
vendor_kd
=
'vendor_kd'
in
prod
and
prod
[
'vendor_kd'
]
or
None
vendor_produk
=
get_vendor_produk
(
produk_kd
,
vendor_kd
=
vendor_kd
)
if
not
vendor_produk
:
raise
JsonRpcProdukNotFoundError
(
message
=
"Produk
%
s tidak ditemukan"
%
produk_kd
)
log
.
info
(
"Vendor
%
s Produk
%
s Module
%
s"
%
(
vendor_produk
.
partner
.
kode
,
vendor_produk
.
produk
.
kode
,
vendor_produk
.
modules
))
values
=
dict
(
customer_id
=
customer
.
id
,
id_pel
=
prod
[
"id_pel"
])
partner_log
=
save_partner_log
(
values
,
vendor_produk
)
result
=
build_request
(
'inquiry'
,
vendor_produk
,
partner_log
)
result_code
=
"code"
in
result
[
"f_result"
]
and
result
[
"f_result"
][
"code"
]
or
None
if
result_code
:
raise
JsonRpcError
(
message
=
result
[
"f_result"
][
"message"
])
if
result
[
"f_result"
][
"code"
]
==
0
:
prod
.
update
(
result
[
"f_result"
])
else
:
prod
.
update
(
dict
(
status
=
"FAILED"
,
message
=
result
[
"message"
]))
r_data
.
append
(
prod
)
data
=
is_list
and
r_data
or
r_data
[
0
]
return
data
...
...
@@ -238,9 +159,6 @@ def build_purchase(vendor_produk, partner_log=None):
return
build_request
(
'payment'
,
vendor_produk
,
partner_log
)
from
..tools
import
JsonRpcInvoiceFoundError
@jsonrpc_method
(
method
=
'purchase'
,
endpoint
=
'api-merchant'
)
def
purchase
(
request
,
data
,
**
kwargs
):
"""
...
...
@@ -257,7 +175,6 @@ def purchase(request, data, **kwargs):
:return:
{
product_nm:string,
denom: string,
id_pel:string
inv_no: string optional
...
...
@@ -268,18 +185,15 @@ def purchase(request, data, **kwargs):
total:integer,
status:success/pending/failed
"""
user
=
auth_from_rpc
(
request
)
i
=
0
if
not
data
:
raise
JsonRpcParameterNotFound
is_list
=
type
(
data
)
==
list
data
=
is_list
and
data
or
[
data
]
customer
=
Partner
.
query_user
(
user
)
.
first
()
if
not
customer
:
raise
JsonRpcCustomerNotFoundError
r_data
=
[]
log
.
info
(
"
%
s Payment Request:
%
s"
%
(
customer
.
kode
,
data
))
for
dat
in
data
:
...
...
@@ -306,10 +220,7 @@ def purchase(request, data, **kwargs):
prod
[
"status"
]
=
"FAILED"
prod
[
"message"
]
=
"Denom atau id pelanggan tidak diisi"
else
:
# produk = Produk.query_kode(produk_kd).first()
# todo: search product lowest price
vendor_produk
=
get_vendor_produk
(
produk_kd
)
if
not
vendor_produk
:
prod
[
"status"
]
=
"FAILED"
prod
[
"message"
]
=
"Data tidak ditemukan"
...
...
@@ -323,23 +234,20 @@ def purchase(request, data, **kwargs):
flush_row
(
ar_invoice_det
)
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
elif
vendor_produk
.
produk
.
harga
>
total
:
total
=
vendor_produk
.
produk
.
harga
prod
.
update
(
dict
(
total
=
total
))
prod
.
update
(
result
[
"f_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
# elif vendor_produk.produk.harga > total:
# total = vendor_produk.produk.harga
# prod.update(dict(total=total))
r_prod
.
append
(
prod
)
ar_invoice
.
payment
[
"response"
]
=
r_prod
dat
[
"produk"
]
=
r_prod
r_data
.
append
(
dat
)
data
=
is_list
and
r_data
or
r_data
[
0
]
log
.
info
(
"
%
s Payment Response:
%
s "
%
(
customer
.
kode
,
data
))
return
data
...
...
@@ -361,7 +269,6 @@ def advice(request, data):
:return:
{
product_nm:string,
denom: string,
id_pel:string
inv_no: string optional
...
...
@@ -372,7 +279,6 @@ def advice(request, data):
total:integer,
status:success/pending/failed
"""
user
=
auth_from_rpc
(
request
)
i
=
0
is_list
=
type
(
data
)
==
list
...
...
@@ -380,7 +286,6 @@ def advice(request, data):
customer
=
Partner
.
query_user
(
user
)
.
first
()
if
not
customer
:
raise
JsonRpcCustomerNotFoundError
r_data
=
[]
for
dat
in
data
:
if
"invoice_no"
not
in
dat
:
...
...
@@ -400,9 +305,9 @@ def advice(request, data):
if
"produk"
in
dat
:
prods
=
[]
for
p
in
dat
[
"produk"
]:
row
=
qry
.
join
(
Produk
,
Produk
.
id
==
H2hArInvoiceDet
.
produk_id
)
\
.
filter
(
Produk
.
kode
==
p
[
"denom"
],
H2hArInvoiceDet
.
id_pel
==
p
[
"id_pel"
])
.
first
()
row
=
qry
.
join
(
Produk
,
Produk
.
id
==
H2hArInvoiceDet
.
produk_id
)
\
.
filter
(
Produk
.
kode
==
p
[
"denom"
],
H2hArInvoiceDet
.
id_pel
==
p
[
"id_pel"
])
.
first
()
if
not
row
:
status
=
"FAILED"
message
=
"Produk tidak ada"
...
...
@@ -423,10 +328,8 @@ def advice(request, data):
for
p
in
qry
.
all
():
produk
=
Produk
.
query
()
.
\
filter
(
Produk
.
id
==
p
.
produk_id
)
.
first
()
status
=
p
.
status
==
-
1
and
'PENDING'
or
p
.
status
==
1
and
'SUCCESS'
\
or
p
.
status
==
-
2
and
'PENDING'
or
"FAILED"
r_prod
.
append
(
dict
(
denom
=
produk
.
kode
,
id_pel
=
p
.
id_pel
,
subtotal
=
(
p
.
amt_sell
or
0
)
+
(
p
.
discount
or
0
),
...
...
@@ -435,14 +338,11 @@ def advice(request, data):
status
=
status
,
serial_number
=
p
.
serial_number
or
""
,
)
)
dat
[
"produk"
]
=
r_prod
r_data
.
append
(
dat
)
i
+=
1
data
=
is_list
and
r_data
or
r_data
[
0
]
return
data
#
# @jsonrpc_method(method='payment', endpoint='api-merchant')
# def payment(request, token, data):
...
...
@@ -604,38 +504,3 @@ def advice(request, data):
# data[i]=r_data
# i += 1
# return data
"""
bikin method baru sesuai nicepay
- registration
- payment
"""
"""
"referenceNo":"ORD12345",
"goodsNm":"Test Transaction Nicepay",
"billingNm":"Customer Name",
"billingPhone":"12345678",
"billingEmail":"email@merchant.com",
"billingAddr":"Jalan Bukit Berbunga 22",
"billingCity":"Jakarta",
"billingState":"DKI Jakarta",
"billingPostCd":"12345",
"billingCountry":"Indonesia",
"deliveryNm":"email@merchant.com",
"deliveryPhone":"12345678",
"deliveryAddr":"Jalan Bukit Berbunga 22",
"deliveryCity":"Jakarta",
"deliveryState":"DKI Jakarta",
"deliveryPostCd":"12345",
"deliveryCountry":"Indonesia",
"description":"Transaction Description",
"dbProcessUrl":"http://ptsv2.com/t/0ftrz-1519971382/post",
"reqDomain":"merchant.com",
"cartData":"{}",
"vacctValidDt":"20180306",
"vacctValidTm":"091309",
"merFixAcctId":""
"""
\ No newline at end of file
src/agratek/api/merchant/views/api_payment.py
0 → 100644
View file @
31d093b
import
logging
from
importlib
import
import_module
from
agratek.api.merchant.views.api_merchant
import
get_vendor_produk
,
build_request
from
opensipkd.base.models
import
Partner
,
flush_row
from
opensipkd.base.tools.api
import
(
auth_from_rpc
,
JsonRpcProdukNotFoundError
,
JsonRpcCustomerNotFoundError
,
JsonRpcParameterNotFound
)
from
opensipkd.pasar.models
import
Produk
,
PartnerProduk
from
opensipkd.pasar.models.produk
import
H2hArInvoice
,
H2hArInvoiceDet
,
PartnerLog
,
PartnerPay
from
pyramid_rpc.jsonrpc
import
jsonrpc_method
from
..tools
import
JsonRpcInvoiceFoundError
,
JsonRpcError
log
=
logging
.
getLogger
(
__name__
)
def
save_partner_pay
(
values
,
vendor_produk
):
partner_pay
=
PartnerPay
()
partner_pay
.
from_dict
(
values
)
partner_pay
.
vendor_id
=
vendor_produk
.
partner_id
partner_pay
.
produk_id
=
vendor_produk
.
produk
.
id
flush_row
(
partner_pay
)
return
partner_pay
def
build_register
(
vendor_produk
,
partner_log
=
None
):
return
build_request
(
'register'
,
vendor_produk
,
partner_log
)
@jsonrpc_method
(
method
=
'register'
,
endpoint
=
'api-merchant'
)
def
register
(
request
,
data
,
**
kwargs
):
"""
Digunakan untuk mendapatkan daftar produk
:param request:
:param data:
{
denom: string,
id_pel:string
inv_no: string optional
}
:param token:
user_token
:return:
{
product_nm:string,
denom: string,
id_pel:string
inv_no: string optional
denom:string,
harga:integer,
admin:integer,
discount:integer,
total:integer,
status:success/pending/failed
"""
user
=
auth_from_rpc
(
request
)
i
=
0
if
not
data
:
raise
JsonRpcParameterNotFound
is_list
=
type
(
data
)
==
list
data
=
is_list
and
data
or
[
data
]
customer
=
Partner
.
query_user
(
user
)
.
first
()
if
not
customer
:
raise
JsonRpcCustomerNotFoundError
r_data
=
[]
log
.
info
(
"
%
s Payment Request:
%
s"
%
(
customer
.
kode
,
data
))
for
dat
in
data
:
if
"invoice_no"
not
in
dat
or
"produk"
not
in
dat
or
not
dat
[
"produk"
]
or
\
'amount'
not
in
dat
or
not
dat
[
'amount'
]:
dat
[
"status"
]
=
"FAILED"
dat
[
"message"
]
=
"Parameter tidak lengkap"
else
:
inv_no
=
dat
[
"invoice_no"
]
produk
=
dat
[
"produk"
]
# todo cek apakah invoice sudah ada atau belum
ar_invoice
=
PartnerPay
.
query
()
.
filter_by
(
cust_inv_no
=
inv_no
)
.
first
()
if
ar_invoice
:
raise
JsonRpcInvoiceFoundError
()
produk_kd
=
'denom'
in
dat
and
dat
[
'denom'
]
or
None
vendor_produk
=
get_vendor_produk
(
produk_kd
)
if
not
vendor_produk
:
raise
JsonRpcProdukNotFoundError
values
=
dict
(
customer_id
=
customer
.
id
,
id_pel
=
dat
[
'id_pel'
],
cart
=
produk
,
cust_inv_no
=
inv_no
,
amt_sell
=
dat
[
'amount'
],
notes
=
dat
[
'notes'
],
inv_cust_nm
=
dat
[
'cust_nm'
],
inv_cust_phone
=
dat
[
'cust_phone'
],
inv_cust_email
=
dat
[
'cust_email'
],
inv_cust_city
=
dat
[
'cust_city'
],
inv_cust_state
=
dat
[
'cust_state'
],
inv_cust_pos
=
dat
[
'cust_pos'
],
inv_cust_country
=
dat
[
'cust_country'
],
inv_cust_addr
=
dat
[
'cust_addr'
],
domain
=
dat
[
'domain'
],
server_ip
=
dat
[
'server_ip'
],
inv_cust_agent
=
dat
[
'cust_agent'
],
inv_cust_ip
=
dat
[
'cust_ip'
],
inv_cust_session
=
dat
[
'cust_session_id'
],
description
=
dat
[
'description'
],
inv_valid_date
=
dat
[
'valid_date'
],
inv_valid_time
=
dat
[
'valid_time'
],
inv_time_stamp
=
dat
[
'time_stamp'
],
inv_cust_va
=
dat
[
'cust_va'
],
delivery_addr
=
dat
[
'delivery_addr'
],
delivery_city
=
dat
[
'delivery_city'
],
delivery_country
=
dat
[
'delivery_country'
],
delivery_nm
=
dat
[
'delivery_nm'
],
delivery_phone
=
dat
[
'delivery_phone'
],
delivery_pos
=
dat
[
'delivery_pos'
],
delivery_state
=
dat
[
'delivery_state'
],
fee
=
dat
[
'fee'
],
instmnt_mon
=
dat
[
'instmnt_mon'
],
instmnt_type
=
dat
[
'instmnt_type'
],
m_ref_no
=
dat
[
'm_ref_no'
],
notax_amt
=
dat
[
'notax_amt'
],
pay_valid_dt
=
dat
[
'pay_valid_dt'
],
pay_valid_tm
=
dat
[
'pay_valid_tm'
],
recurr_opt
=
dat
[
'recurr_opt'
],
req_dt
=
dat
[
'req_dt'
],
req_tm
=
dat
[
'req_tm'
],
vat
=
dat
[
'vat'
],
tx_id
=
dat
[
'tx_id'
],
trans_dt
=
dat
[
'trans_dt'
],
trans_tm
=
dat
[
'trans_tm'
],
)
ar_invoice
=
save_partner_pay
(
values
,
vendor_produk
)
result
=
build_register
(
vendor_produk
,
ar_invoice
)
dat
.
update
(
result
[
"f_result"
])
r_data
.
append
(
dat
)
data
=
is_list
and
r_data
or
r_data
[
0
]
log
.
info
(
"
%
s Payment Response:
%
s "
%
(
customer
.
kode
,
data
))
return
data
# @jsonrpc_method(method='advice', endpoint='api-merchant')
# def advice(request, data):
# """
# Digunakan untuk mendapatkan daftar produk
# :param request:
# :param data:
# {
# denom: string,
# id_pel:string
# inv_no: string optional
# }
# :param token:
# user_token
# :return:
# {
# product_nm:string,
# denom: string,
# id_pel:string
# inv_no: string optional
# denom:string,
# harga:integer,
# admin:integer,
# discount:integer,
# total:integer,
# status:success/pending/failed
# """
# user = auth_from_rpc(request)
# i = 0
# is_list = type(data) == list
# data = is_list and data or [data]
# customer = Partner.query_user(user).first()
# if not customer:
# raise JsonRpcCustomerNotFoundError
# r_data = []
# for dat in data:
# if "invoice_no" not in dat:
# dat["status"] = "FAILED"
# dat["message"] = "Parameter tidak lengkap"
# else:
# inv_no = dat["invoice_no"]
# invoice = H2hArInvoice.query() \
# .filter_by(cust_inv_no=inv_no,
# customer_id=customer.id).first()
# if not invoice:
# dat["status"] = "FAILED"
# dat["message"] = "Invoice %s Tidak Ditemukan" % inv_no
# else:
# qry = H2hArInvoiceDet.query().filter_by(ar_invoice_id=invoice.id)
# r_prod = []
# if "produk" in dat:
# prods = []
# for p in dat["produk"]:
# row = qry.join(Produk, Produk.id == H2hArInvoiceDet.produk_id) \
# .filter(Produk.kode == p["denom"],
# H2hArInvoiceDet.id_pel == p["id_pel"]).first()
# if not row:
# status = "FAILED"
# message = "Produk tidak ada"
# p.update(dict(status=status,
# message=message))
# else:
# status = row.status == -1 and 'PENDING' or row.status == 1 and 'SUCCESS' \
# or row.status == -2 and 'PENDING' or "FAILED"
# p.update(dict(
# subtotal=(row.amt_sell or 0) + (row.discount or 0),
# discount=row.discount or 0,
# total=row.amt_sell,
# status=status,
# serial_number=row.serial_number or "", )
# )
# r_prod.append(p)
# else:
# for p in qry.all():
# produk = Produk.query(). \
# filter(Produk.id == p.produk_id).first()
# status = p.status == -1 and 'PENDING' or p.status == 1 and 'SUCCESS' \
# or p.status == -2 and 'PENDING' or "FAILED"
# r_prod.append(dict(denom=produk.kode,
# id_pel=p.id_pel,
# subtotal=(p.amt_sell or 0) + (p.discount or 0),
# discount=p.discount or 0,
# total=p.amt_sell,
# status=status,
# serial_number=p.serial_number or "", )
# )
# dat["produk"] = r_prod
# r_data.append(dat)
# i += 1
# data = is_list and r_data or r_data[0]
# return data
#
# @jsonrpc_method(method='payment', endpoint='api-merchant')
# def payment(request, token, data):
# """
# Digunakan untuk mendapatkan daftar produk
# :param request:
# :param data:
# {
# denom: string,
# id_pel:string
# inv_no: string optional
# }
# :param token:
# user_token
# :return:
# {
# product_nm:string,
#
# denom: string,
# id_pel:string
# inv_no: string optional
# denom:string,
# harga:integer,
# admin:integer,
# discount:integer,
# total:integer,
# status:success/pending/failed 00/01/02
# """
# user = auth_from_rpc(request, token)
# i = 0
# dat = data is list and data or [data]
# costumer = Partner.query_user(user)
# for dat in data:
# produk_kd = 'denom' in dat and dat['denom'] or None
# if not produk_kd :
# raise JsonRpcProdukNotFound(message="Produk harus diisi")
#
# produk = Produk.query_kode(produk_kd).first()
# if not produk:
# raise JsonRpcProdukNotFound(message="Produk %s tidak ditemukan" % produk_kd)
#
# # todo: search product lowest price
# vend_kd = 'ODEO'
#
# qry = PartnerProduk.query() \
# .filter(Partner.kode == vend_kd) \
# .filter(Produk.kode == produk_kd).first()
#
# r_data = dat
# r_data.update(dict(data=result))
# data[i] = r_data
# i += 1
# return data
#
#
# @jsonrpc_method(method='get_product', endpoint='api-merchant')
# def get_product(request, token, data ):
# """
# Digunakan untuk mendapatkan daftar produk
# :param request:
# :param data:
# {
# product_kd: string, //optional
# page:integer, //optional
# length:integer, //optional
# category:string, //optional
# search:string //optional
# }
# :return: [
# {
# product_kd:string,
# product_nm:string,
# harga:integer
# }
#
# ]
# """
# auth_from_rpc(request)
# i =0
# qry = DepartemenProduk.query() \
# .filter(Departemen.kode == '100000')
# for dat in data:
# page = 'page' in dat and dat['page'] or 1
# length = 'length' in dat and dat['length'] or 5
# product_kd = 'product_kd' in dat and dat['product_kd'] or None
# search = 'search' in dat and dat['search'] or None
# category = 'category' in dat and dat['category'] or None
# if product_kd :
# rst = qry.join(Produk).filter(Produk.kode == product_kd)
# elif search:
# rst = qry.join(Produk).filter(Produk.nama.ilike("".join(['%',search,'%' ])))
# elif category:
# rst = qry.join(Produk).join(ProdukKategori) \
# .filter(ProdukKategori.nama.ilike("".join(['%', category, '%'])))
# else:
# rst = qry
#
# rst = rst.limit(length).offset((page-1)*length)
# result = []
# for row in rst.all():
# result.append(dict(product_kd=row.produk.kode,
# produk_nm=row.produk.nama,
# harga=row.harga ))
# r_data = dat
# r_data.update(dict(data=result))
# data[i]=r_data
# i += 1
# return data
#
# @jsonrpc_method(method='get_biaya', endpoint='api-merchant')
# def get_biaya(request, data, token=None):
# """
# Digunakan untuk mencari methode pembayaran dan biaya layanan
# :param request:
# :param data:
# {
# biaya_kd: string,
# harga:integer,
# cname:string,
# cid:string,
# cvv:string, optional
# }
# :param token:
# user_token
# :return:
# {
# product_kd:string,
# product_nm:string,
# harga:integer
# }
# """
#
# user = auth_from_rpc(request, token)
# i =0
# qry = DepartemenProduk.query() \
# .filter(Departemen.kode == '100000')
# for dat in data:
# product_kd = 'biaya_kd' in dat and dat['biaya_kd'] or None
# cid = 'cid' in dat and dat['cid'] or None
# if not product_kd :
# raise JsonRpcParameterNotFound(message='Paramter product_kd wajib di isi')
#
# rst = qry.join(Produk).filter(Produk.kode == product_kd)
# result = []
# for row in rst.all():
# if row.is_cid and not cid:
# raise JsonRpcParameterNotFound(message="Parameter cid wajib di isi")
# if row.produk.fixed:
# harga = row.harga
# else:
# harga = dat['harga']*row.harga
#
# result.append(dict(biaya_kd=row.produk.kode,
# produk_nm=row.produk.nama,
# harga=harga))
#
# r_data = dat
# r_data.update(dict(data=result))
# data[i]=r_data
# i += 1
# return data
src/agratek/api/merchant/views/np/__init__.py
View file @
31d093b
import
json
import
base64
import
logging
# Import Library (Mandatory)
from
datetime
import
datetime
,
timedelta
...
...
@@ -7,161 +9,200 @@ from opensipkd.base import get_settings
from
opensipkd.base.models
import
Partner
from
.
import
Nicepay
from
..vendor
import
VendorClass
import
logging
import
urllib3
log
=
logging
.
getLogger
(
__name__
)
urllib3
.
disable_warnings
()
# setMandatoryParameter
class
Vendor
(
VendorClass
):
#VendorClass
# def __init__(self, vendor_produk, **kwargs):
# def __init__(self, vendor_produk, **kwargs):
# # VendorClass.__init__(self, vendor_produk, bill_no, **kwargs)
# if not vendor_produk or kwargs is None or not "values" in kwargs:
# return
#
# settings = get_settings()
# self.mid = 'np_mid' in settings and settings['np_mid'] or None
# self.key = 'np_key' in settings and settings['np_key'] or None
# self.url = 'np_url' in settings and settings['np_url'] or None
# Nicepay.merchantKey = self.key
# Nicepay.iMid = self.mid
#
# self.customer = dict(
# barang='GOODSNM',
# nama='BILLING NAME',
# phone='08123456789',
# email='ADETEST01@GMAIL.COM',
# kota='JAKARTA',
# provinsi='JAKARTA',
# kd_pos='14350',
# negara='INDONESIA',
# )
#
class
Vendor
(
VendorClass
):
def
__init__
(
self
,
vendor_produk
,
invoice_det
,
**
kwargs
):
VendorClass
.
__init__
(
self
,
vendor_produk
,
invoice_det
,
**
kwargs
)
VendorClass
.
__init__
(
self
,
vendor_produk
,
invoice_det
=
invoice_det
)
# id_pel, customer_id, cust_trx, row
settings
=
get_settings
()
self
.
mid
=
'np_mid'
in
settings
and
settings
[
'np_mid'
]
or
None
self
.
key
=
'np_key'
in
settings
and
settings
[
'np_key'
]
or
None
self
.
url
=
'np_url'
in
settings
and
settings
[
'np_url'
]
or
None
self
.
callback_url
=
'np_callback'
in
settings
and
settings
[
'np_callback'
]
or
\
'https://www.merchant.com/Notification'
self
.
notify_url
=
'np_notify'
in
settings
and
settings
[
'np_notify'
]
or
\
'https://www.merchant.com/Notification'
key
=
":"
.
join
([
self
.
mid
,
self
.
key
])
.
encode
()
self
.
auth
=
base64
.
b64encode
(
key
)
.
decode
()
# args = kwargs
# self.values = args["values"]
self
.
v_produk_kd
=
vendor_produk
.
kode
self
.
cust_kd
=
None
self
.
cust_inv_no
=
None
self
.
agra_cust_inv_no
=
None
if
self
.
row_customer
and
self
.
row_invoice
:
self
.
cust_kd
=
self
.
row_customer
.
kode
self
.
cust_inv_no
=
self
.
row_invoice
.
cust_inv_no
self
.
agra_cust_inv_no
=
self
.
cust_kd
and
self
.
cust_inv_no
\
and
self
.
cust_kd
+
self
.
cust_inv_no
or
None
self
.
mid
=
'np_mid'
in
self
.
settings
and
self
.
settings
[
'np_mid'
]
or
None
self
.
key
=
'np_key'
in
self
.
settings
and
self
.
settings
[
'np_key'
]
or
None
self
.
url
=
'np_url'
in
self
.
settings
and
self
.
settings
[
'np_url'
]
or
None
customer
=
self
.
invoice_det
.
customer
if
customer
:
self
.
cust_kd
=
customer
.
kode
# self.cust_inv_no = self.cust_kd + self.invoice_det.cust_inv_no
self
.
cust_inv_no
=
self
.
invoice_det
.
cust_inv_no
Nicepay
.
merchantKey
=
self
.
key
Nicepay
.
iMid
=
self
.
mid
self
.
ip
=
Nicepay
.
userIp
()
self
.
customer
=
dict
(
barang
=
invoice_det
.
produk
.
nama
,
# 'GOODSNM',
nama
=
self
.
row_customer
.
nama
,
# 'BILLING NAME',
phone
=
self
.
row_customer
.
phone
,
# '08123456789',
email
=
self
.
row_customer
.
email
,
# 'ADETEST01@GMAIL.COM',
kota
=
self
.
row_customer
.
kota
,
# 'JAKARTA',
provinsi
=
self
.
row_customer
.
provinsi
,
# 'JAKARTA',
kd_pos
=
None
,
# '14350',
negara
=
'INDONESIA'
,
)
self
.
url
=
'https://www.merchant.com/Notification'
# self.cust_trx = 'REFERENCENO'
# self.pay_method = '01'
self
.
bank_cd
,
self
.
pay_method
=
self
.
v_produk_kd
.
split
(
'-'
)
self
.
va_typ
=
"float"
self
.
notify_url
=
"dev.agratek.co.id/api/np/notify"
self
.
callback_url
=
"dev.agratek.co.id/api/np/calllback"
self
.
va_typ
=
None
#
self.notify_url = "dev.agratek.co.id/api/np/notify"
#
self.callback_url = "dev.agratek.co.id/api/np/calllback"
self
.
reccuring
=
False
# self.amt = str(self.values["amount"]
)
self
.
amt
=
'0'
now
=
datetime
.
now
(
)
self
.
time_stamp
=
now
.
strftime
(
"
%
Y
%
m
%
d
%
H
%
M
%
S"
)
tommorow
=
now
+
timedelta
(
days
=
1
)
self
.
valid_date
=
tommorow
.
strftime
(
"
%
Y
%
m
%
d"
)
self
.
valid_time
=
"235500"
self
.
amt
=
str
(
self
.
invoice_det
.
amt_sell
)
# now = datetime.now()
# self.time_stamp = now.strftime("%Y%m%d%H%M%S"
)
# tommorow = now + timedelta(days=1
)
# self.valid_date = tommorow.strftime("%Y%m%d"
)
# self.valid_time = "235500"
# self.ip = Nicepay.userIp()
def
request_payment
(
self
,
response
):
Nicepay
.
requestData
=
{}
Nicepay
.
set
(
'timeStamp'
,
self
.
time_stamp
)
# Nicepay.set('referenceNo', self.time_stamp) #'20180109181300'
Nicepay
.
set
(
'referenceNo'
,
self
.
agra_cust_inv_no
)
Nicepay
.
set
(
'tXid'
,
response
[
"tXid"
])
# 'IONPAYTEST02201802051512483907'get tXid from register first
# Nicepay.set('cardNo', self.values["card_no"]) #'5409120028181901'
# Nicepay.set('cardExpYymm', self.values["card_exp"]) # format Yymm '2012'
# Nicepay.set('cardCvv', self.values["card_cvv"])
Nicepay
.
set
(
'timeStamp'
,
self
.
invoice_det
.
time_stamp
)
Nicepay
.
set
(
'referenceNo'
,
self
.
cust_inv_no
)
Nicepay
.
set
(
'tXid'
,
response
[
"tXid"
])
Nicepay
.
set
(
'cardNo'
,
self
.
invoice_det
.
card_no
)
Nicepay
.
set
(
'cardExpYymm'
,
self
.
invoice_det
.
card_exp
)
# format Yymm '2012'
Nicepay
.
set
(
'cardCvv'
,
self
.
invoice_det
.
card_cvv
)
Nicepay
.
set
(
'recurringToken'
,
''
)
Nicepay
.
set
(
'preauthToken'
,
''
)
Nicepay
.
set
(
'clickPayNo'
,
''
)
Nicepay
.
set
(
'dataField3'
,
''
)
Nicepay
.
set
(
'clickPayToken'
,
''
)
Nicepay
.
set
(
'callBackUrl'
,
self
.
callback_url
)
result
=
Nicepay
.
nicePayment
()
return
result
def
set_static_params
(
self
):
if
not
self
.
agra_
cust_inv_no
:
if
not
self
.
cust_inv_no
:
return
Nicepay
.
set
(
'timeStamp'
,
self
.
time_stamp
)
Nicepay
.
set
(
'timeStamp'
,
self
.
invoice_det
.
inv_time_stamp
)
#
Nicepay
.
set
(
'iMid'
,
self
.
mid
)
Nicepay
.
set
(
'payMethod'
,
self
.
pay_method
)
Nicepay
.
set
(
'currency'
,
'IDR'
)
Nicepay
.
set
(
'amt'
,
self
.
amt
)
Nicepay
.
set
(
'referenceNo'
,
self
.
agra_cust_inv_no
)
Nicepay
.
set
(
'userIP'
,
self
.
ip
)
Nicepay
.
set
(
'dbProcessUrl'
,
self
.
url
)
# Nicepay.set('amt', self.amt)
Nicepay
.
set
(
'referenceNo'
,
self
.
cust_inv_no
)
Nicepay
.
set
(
'userIP'
,
self
.
invoice_det
.
inv_cust_ip
)
Nicepay
.
set
(
'dbProcessUrl'
,
self
.
notify_url
)
# Nicepay.set('merchantKey', self.key)
Nicepay
.
merchantKey
=
self
.
key
Nicepay
.
set
(
'merchantToken'
,
Nicepay
.
merchantToken
())
Nicepay
.
set
(
"userLanguage"
,
"ko-KR,en-US;q=0.8,ko;q=0.6,en;q=0.4"
)
Nicepay
.
set
(
'reqClientVer'
,
'2.0'
)
return
True
def
set_billing_param
(
self
):
if
not
self
.
customer
:
if
not
self
.
invoice_det
:
return
Nicepay
.
set
(
'goodsNm'
,
self
.
customer
[
'barang'
])
Nicepay
.
set
(
'billingNm'
,
self
.
customer
[
'nama'
])
Nicepay
.
set
(
'billingPhone'
,
self
.
customer
[
'phone'
])
Nicepay
.
set
(
'billingEmail'
,
self
.
customer
[
'email'
])
Nicepay
.
set
(
'billingCity'
,
self
.
customer
[
'kota'
])
Nicepay
.
set
(
'billingState'
,
self
.
customer
[
'provinsi'
])
Nicepay
.
set
(
'billingPostCd'
,
self
.
customer
[
'kd_pos'
])
Nicepay
.
set
(
'billingCountry'
,
self
.
customer
[
'negara'
])
Nicepay
.
set
(
'goodsNm'
,
self
.
invoice_det
.
notes
)
Nicepay
.
set
(
'billingNm'
,
self
.
invoice_det
.
inv_cust_nm
)
Nicepay
.
set
(
'billingPhone'
,
self
.
invoice_det
.
inv_cust_phone
)
Nicepay
.
set
(
'billingEmail'
,
self
.
invoice_det
.
inv_cust_email
)
Nicepay
.
set
(
'billingCity'
,
self
.
invoice_det
.
inv_cust_city
)
Nicepay
.
set
(
'billingState'
,
self
.
invoice_det
.
inv_cust_state
)
Nicepay
.
set
(
'billingPostCd'
,
self
.
invoice_det
.
inv_cust_pos
)
Nicepay
.
set
(
'billingCountry'
,
self
.
invoice_det
.
inv_cust_country
)
Nicepay
.
set
(
'amt'
,
str
(
self
.
invoice_det
.
amt_sell
))
Nicepay
.
set
(
'billingAddr'
,
self
.
invoice_det
.
inv_cust_addr
)
Nicepay
.
set
(
'description'
,
self
.
invoice_det
.
notes
)
Nicepay
.
set
(
'reqDomain'
,
self
.
invoice_det
.
domain
)
Nicepay
.
set
(
'reqServerIP'
,
self
.
invoice_det
.
server_ip
)
Nicepay
.
set
(
'userAgent'
,
self
.
invoice_det
.
inv_cust_agent
)
Nicepay
.
set
(
'userIP'
,
self
.
invoice_det
.
inv_cust_ip
)
Nicepay
.
set
(
'userSessionID'
,
self
.
invoice_det
.
inv_cust_session
)
return
True
def
set_optional_param
(
self
):
pass
#
pass
# setOptionalParameter
# Nicepay.set('billingAddr', 'Billing Address')
# Nicepay.set('deliveryNm', 'Buyer Name')
# Nicepay.set('deliveryPhone', '02112345678')
# Nicepay.set('deliveryAddr', 'Billing Address')
# Nicepay.set('deliveryCity', 'Jakarta')
# Nicepay.set('deliveryState', 'Jakarta')
# Nicepay.set('deliveryPostCd', '12345')
# Nicepay.set('deliveryCountry', 'Indonesia')
# Nicepay.set('vat', '0')
# Nicepay.set('fee', '0')
# Nicepay.set('notaxAmt', '0')
# Nicepay.set('description', 'Description')
# Nicepay.set('reqDt', '20160301') # Format (YYYYMMDD)
# Nicepay.set('reqTm', '135959') # Format (HHiiss)
# Nicepay.set('reqDomain', 'merchant.com')
# Nicepay.set('reqServerIP', '127.0.0.1')
# Nicepay.set('reqClientVer', '1.0')
# Nicepay.set('userSessionID', 'userSessionID')
# Nicepay.set('userAgent', 'Mozilla')
# Nicepay.set('userLanguage', 'en-US')
def
inquiry
(
self
):
# Nicepay.requestData = {}
self
.
request
=
Nicepay
.
requestData
if
not
self
.
set_static_params
()
or
not
self
.
set_billing_param
():
Nicepay
.
set
(
'deliveryNm'
,
self
.
invoice_det
.
delivery_nm
)
Nicepay
.
set
(
'deliveryPhone'
,
self
.
invoice_det
.
delivery_phone
)
Nicepay
.
set
(
'deliveryAddr'
,
self
.
invoice_det
.
delivery_addr
)
Nicepay
.
set
(
'deliveryCity'
,
self
.
invoice_det
.
delivery_city
)
Nicepay
.
set
(
'deliveryState'
,
self
.
invoice_det
.
delivery_state
)
Nicepay
.
set
(
'deliveryPostCd'
,
self
.
invoice_det
.
delivery_pos
)
Nicepay
.
set
(
'deliveryCountry'
,
self
.
invoice_det
.
delivery_country
)
Nicepay
.
set
(
'vat'
,
str
(
self
.
invoice_det
.
vat
))
Nicepay
.
set
(
'fee'
,
str
(
self
.
invoice_det
.
fee
))
Nicepay
.
set
(
'notaxAmt'
,
str
(
self
.
invoice_det
.
notax_amt
))
Nicepay
.
set
(
'reqDt'
,
self
.
invoice_det
.
req_dt
)
# Format (YYYYMMDD)
Nicepay
.
set
(
'reqTm'
,
self
.
invoice_det
.
req_tm
)
# Format (HHiiss)\
Nicepay
.
set
(
'reqClientVer'
,
''
)
Nicepay
.
set
(
'recurrOpt'
,
str
(
self
.
invoice_det
.
recurr_opt
))
Nicepay
.
set
(
'instmntMon'
,
self
.
invoice_det
.
instmnt_mon
)
Nicepay
.
set
(
'instmntType'
,
self
.
invoice_det
.
instmnt_type
)
Nicepay
.
set
(
'mRefNo'
,
self
.
invoice_det
.
m_ref_no
)
Nicepay
.
set
(
'payValidDt'
,
self
.
invoice_det
.
pay_valid_dt
)
Nicepay
.
set
(
'payValidTm'
,
self
.
invoice_det
.
pay_valid_tm
)
Nicepay
.
set
(
'tXid'
,
self
.
invoice_det
.
tx_id
)
Nicepay
.
set
(
'transDt'
,
self
.
invoice_det
.
trans_dt
)
Nicepay
.
set
(
'transTm'
,
self
.
invoice_det
.
trans_tm
)
def
register
(
self
):
Nicepay
.
requestData
=
{}
if
not
self
.
set_billing_param
()
or
not
self
.
set_static_params
():
return
Nicepay
.
set
(
'cartData'
,
'{}'
)
# f9d30f6c972e2b5718751bd087b178534673a91bbac845f8a24e60e8e4abbbc5
# Nicepay.set('merchantToken', 'a20e500ecd7eb786fcda1761765ca59f344a25716ff0b576f3b42ff4ac9f7224')
data
=
str
(
json
.
dumps
(
self
.
invoice_det
.
cart
))
# Nicepay.set('cartData', self.invoice_det.cart)
Nicepay
.
set
(
'cartData'
,
'{}'
.
format
(
data
))
self
.
set_optional_param
()
# For Credit Card (Don't forgot change payMethod to '01')
if
self
.
pay_method
==
'01'
:
Nicepay
.
set
(
'instmntType'
,
'2'
)
Nicepay
.
set
(
'instmntMon'
,
'1'
)
if
self
.
reccuring
:
# For Credit Card Reccuring Only
Nicepay
.
set
(
'recurrOpt'
,
'0
'
)
Nicepay
.
set
(
'instmntType'
,
self
.
invoice_det
.
instmnt_type
)
Nicepay
.
set
(
'instmntMon'
,
self
.
invoice_det
.
instmnt_mon
)
#
if self.reccuring:
#
# For Credit Card Reccuring Only
Nicepay
.
set
(
'recurrOpt'
,
'2
'
)
# For Virtual Account (Don't forgot change payMethod to '02')
elif
self
.
pay_method
==
'02'
:
Nicepay
.
set
(
'bankCd'
,
self
.
bank_cd
)
Nicepay
.
set
(
'vacctValidDt'
,
self
.
valid_date
)
# Format (YYYYMMDD)
Nicepay
.
set
(
'vacctValidTm'
,
self
.
valid_time
)
# Format (HHiiss)
if
self
.
va_typ
==
"fixed"
:
# For Virtual Account Fix Account
Nicepay
.
set
(
'merFixAcctId'
,
'12345679'
)
# length value of merFixAcctId setting By Mid. Contact
# Nicepay IT for Information
# Nicepay.set('vacctValidDt', self.valid_date) # Format (YYYYMMDD)
# Nicepay.set('vacctValidTm', self.valid_time) # Format (HHiiss)
Nicepay
.
set
(
'vacctValidDt'
,
self
.
invoice_det
.
inv_valid_date
)
Nicepay
.
set
(
'vacctValidTm'
,
self
.
invoice_det
.
inv_valid_time
)
if
self
.
invoice_det
.
inv_cust_va
:
self
.
va_typ
=
'fixed'
Nicepay
.
set
(
'merFixAcctId'
,
self
.
invoice_det
.
inv_cust_va
)
# if self.va_typ == "fixed":
# # For Virtual Account Fix Account
# Nicepay.set('merFixAcctId', '12345679')
# # length value of merFixAcctId setting By Mid. Contact
# # Nicepay IT for Information
else
:
self
.
va_typ
=
'float'
Nicepay
.
set
(
'merFixAcctId'
,
''
)
elif
self
.
pay_method
in
[
'03'
,
'04'
,
'05'
]:
# For CVS,ClickPay or E-Wallet
...
...
@@ -169,8 +210,8 @@ class Vendor(VendorClass):
Nicepay
.
set
(
'mitraCd'
,
self
.
bank_cd
)
if
self
.
pay_method
==
'03'
:
# For CVS Only
Nicepay
.
set
(
'payValidDt'
,
self
.
valid_date
)
# Format (YYYYMMDD)
Nicepay
.
set
(
'payValidTm'
,
self
.
valid_time
)
# Format (HHiiss)
Nicepay
.
set
(
'payValidDt'
,
self
.
invoice_det
.
inv_
valid_date
)
# Format (YYYYMMDD)
Nicepay
.
set
(
'payValidTm'
,
self
.
invoice_det
.
inv_
valid_time
)
# Format (HHiiss)
elif
self
.
pay_method
==
'04'
:
# For ClickPay Only
...
...
@@ -178,15 +219,12 @@ class Vendor(VendorClass):
self
.
set_optional_param
()
self
.
request
=
Nicepay
.
requestData
log
.
info
(
"REQUEST: {}"
.
format
(
json
.
dumps
(
self
.
request
)))
self
.
save_log
(
'inquiry'
)
# result = {}
resultData
=
Nicepay
.
niceRegister
()
response
=
json
.
loads
(
resultData
)
# Jika kartu kredit
if
self
.
pay_method
==
'01'
:
payment
=
self
.
request_payment
(
response
)
result_data
=
Nicepay
.
niceRegister
()
response
=
json
.
loads
(
result_data
)
self
.
response
=
response
log
.
info
(
"RESPONSE: {}"
.
format
(
json
.
dumps
(
self
.
response
)))
self
.
response
=
response
# # Payment Response String Format
...
...
@@ -197,50 +235,49 @@ class Vendor(VendorClass):
return
else
:
result
=
dict
()
#
if
response
[
'resultCd'
]
==
'0000'
:
result
[
"resultCd"
]
=
response
[
'resultCd'
]
result
[
"resultMsg"
]
=
response
[
'resultMsg'
]
result
[
"tXid"
]
=
response
[
'tXid'
]
result
[
"referenceNo"
]
=
response
[
'referenceNo'
]
result
[
"payMethod"
]
=
response
[
'payMethod'
]
result
[
"amount"
]
=
response
[
'amt'
]
result
[
"transDt"
]
=
response
[
'transDt'
]
result
[
"transTm"
]
=
response
[
'transTm'
]
if
response
[
'goodsNm'
]:
result
[
"goodsNm"
]
=
response
[
'goodsNm'
]
if
response
[
'billingNm'
]:
result
[
"billingNm"
]
=
response
[
'billingNm'
]
if
response
[
'currency'
]:
result
[
"currency"
]
=
response
[
'currency'
]
elif
response
[
'payMethod'
]
==
"02"
:
result
[
"bankCd"
]
=
response
[
'bankCd'
]
result
[
"vacctNo"
]
=
response
[
'vacctNo'
]
result
[
"vacctValidDt"
]
=
response
[
'vacctValidDt'
]
result
[
"vacctValidTm"
]
=
response
[
'vacctValidTm'
]
result_code
=
int
(
response
[
'resultCd'
])
result
[
"code"
]
=
result_code
result
[
"message"
]
=
response
[
'resultMsg'
]
if
result_code
==
0
:
result
[
"tx_id"
]
=
response
[
'tXid'
]
result
[
'trans_dt'
]
=
response
[
'transDt'
]
result
[
'trans_tm'
]
=
response
[
'transTm'
]
# Jika kartu kredit
# if self.pay_method == '01':
# # C-Card
# # payment = self.request_payment(response)
# elif response['payMethod'] == "02":
if
response
[
'payMethod'
]
==
"02"
:
# VA
result
[
"vacct_no"
]
=
response
[
'vacctNo'
]
# result["vacct_valid_dt"]=response['vacctValidDt']
# result["vacct_valid_tm"]=response['vacctValidTm']
# result["mer_fix_acct_id"]=response['merFixAcctId']
elif
response
[
'payMethod'
]
==
"03"
:
result
[
"mitraCd"
]
=
response
[
'mitraCd'
]
result
[
"pay
N
o"
]
=
response
[
'payNo'
]
result
[
"vacctValidD
t"
]
=
response
[
'payValidDt'
]
result
[
"vacctValidT
m"
]
=
response
[
'payValidTm'
]
# CVS
result
[
"pay
_n
o"
]
=
response
[
'payNo'
]
# result["pay_valid_d
t"]=response['payValidDt']
# result["pay_valid_t
m"]=response['payValidTm']
elif
result
[
'payMethod'
]
==
"04"
:
result
[
"mitraCd"
]
=
response
[
'mitraCd'
]
result
[
"receipt
C
ode"
]
=
response
[
'receiptCode'
]
# clickpay
result
[
"receipt
_c
ode"
]
=
response
[
'receiptCode'
]
elif
result
[
'payMethod'
]
==
"05"
:
result
[
"mitraCd"
]
=
response
[
'mitraCd'
]
result
[
"receiptCode"
]
=
'receiptCode'
in
response
and
response
[
'receiptCode'
]
or
''
else
:
result
[
"resultCd"
]
=
response
[
'resultCd'
]
result
[
"resultMsg"
]
=
response
[
'resultMsg'
]
self
.
result
=
response
self
.
save_log
(
'inquiry'
)
# e-wallet
result
[
"receipt_code"
]
=
'receiptCode'
in
response
and
response
[
'receiptCode'
]
or
''
elif
result
[
'payMethod'
]
==
"06"
:
# akulaku
pass
# else:
# result["resultCd"]=response['resultCd']
# result["resultMsg"]=response['resultMsg']
self
.
result
=
result
# self.save_log('inquiry')
return
dict
(
data
=
result
)
# https://api.nicepay.co.id/nicepay/direct/v2/registration
# Request Body
"""
{
"deliveryPhone": "62-21-0000-0000",
...
...
src/agratek/api/merchant/views/vendor.py
View file @
31d093b
...
...
@@ -54,11 +54,7 @@ class VendorClass(object):
self
.
amt_buy
=
0
self
.
amt_sell
=
0
self
.
discount
=
0
# tambahan by tatang
self
.
row_invoice
=
invoice_det
and
invoice_det
.
h2h_ar_invoice
or
None
self
.
row_customer
=
self
.
row_invoice
and
self
.
row_invoice
.
customer
or
None
def
set_response
(
self
,
data
=
None
,
message
=
None
,
code
=
999
,
typ
=
"inquiry"
):
if
not
data
and
message
:
message
=
message
and
message
or
"No Response From Biller"
...
...
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