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 3f5ca6d8
authored
Aug 26, 2019
by
Tatang
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
np
1 parent
533f0000
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
310 additions
and
67 deletions
src/agratek/api/merchant/views/merchant.py
src/agratek/api/merchant/views/np/__init__.py
src/agratek/api/merchant/views/np_original/Nicepay.py
src/agratek/api/merchant/views/np_original/__init__.py
src/agratek/api/merchant/views/vendor.py
src/agratek/api/merchant/views/merchant.py
View file @
3f5ca6d
...
@@ -22,21 +22,21 @@ def build_request(typ, vendor_produk, partner_log=None):
...
@@ -22,21 +22,21 @@ def build_request(typ, vendor_produk, partner_log=None):
pckgs
=
'agratek.api.merchant.views'
pckgs
=
'agratek.api.merchant.views'
moduls
=
vendor_produk
.
modules
.
split
(
'.'
)
moduls
=
vendor_produk
.
modules
.
split
(
'.'
)
if
len
(
moduls
)
>
1
:
if
len
(
moduls
)
>
1
:
pckg
=
"."
.
join
(
moduls
[:
-
1
])
pckg
=
"."
.
join
(
moduls
[:
-
1
])
pckgs
=
"."
.
join
([
pckgs
,
pckg
])
pckgs
=
"."
.
join
([
pckgs
,
pckg
])
moduls
=
moduls
[
-
1
:]
moduls
=
moduls
[
-
1
:]
modul
=
moduls
[
0
]
modul
=
moduls
[
0
]
log
.
info
(
"Module:
%
s Pckgs:
%
s"
%
(
modul
,
pckgs
))
log
.
info
(
"Module:
%
s Pckgs:
%
s"
%
(
modul
,
pckgs
))
modul
=
'.'
+
modul
modul
=
'.'
+
modul
modules
=
import_module
(
modul
,
pckgs
)
modules
=
import_module
(
modul
,
pckgs
)
cls_module
=
modules
.
Vendor
(
vendor_produk
,
partner_log
)
cls_module
=
modules
.
Vendor
(
vendor_produk
,
partner_log
)
cls
=
hasattr
(
cls_module
,
typ
)
and
getattr
(
cls_module
,
typ
)
or
None
cls
=
hasattr
(
cls_module
,
typ
)
and
getattr
(
cls_module
,
typ
)
or
None
if
cls
:
if
cls
:
result
=
cls
()
result
=
cls
()
#log.info("Build Req: mod %s rslt: %s" % (vendor_produk.modules, data))
#
log.info("Build Req: mod %s rslt: %s" % (vendor_produk.modules, data))
log
.
info
(
"Request
%
s"
%
cls_module
.
request
)
log
.
info
(
"Request
%
s"
%
cls_module
.
request
)
log
.
info
(
"Response
%
s"
%
cls_module
.
response
)
log
.
info
(
"Response
%
s"
%
cls_module
.
response
)
log
.
info
(
"Result
%
s"
%
cls_module
.
result
)
log
.
info
(
"Result
%
s"
%
cls_module
.
result
)
...
@@ -52,6 +52,7 @@ def build_request(typ, vendor_produk, partner_log=None):
...
@@ -52,6 +52,7 @@ def build_request(typ, vendor_produk, partner_log=None):
code
=
9999
)
code
=
9999
)
result
=
{
"f_result"
:
data
}
result
=
{
"f_result"
:
data
}
# dict(data=)
# dict(data=)
return
result
return
result
...
@@ -66,12 +67,13 @@ def get_vendor_produk(produk_kd, vendor_kd=None, harga=None):
...
@@ -66,12 +67,13 @@ def get_vendor_produk(produk_kd, vendor_kd=None, harga=None):
Fungsi ini digunakan untuk mencari vendor yang paling murah
Fungsi ini digunakan untuk mencari vendor yang paling murah
:param produk_kd: String Kode Produk
:param produk_kd: String Kode Produk
:param level: Digunakan sebagai parameter jika yang paling murah tidak ditemukan
:param level: Digunakan sebagai parameter jika yang paling murah tidak ditemukan
:vendor_kd: Kode Vendor
:param vendor_kd: Kode Vendor
:param harga: harga produk
:return: row objek dari Partner Produk
:return: row objek dari Partner Produk
"""
"""
### Jika parameter level tidak disebutkan
### Jika parameter level tidak disebutkan
settings
=
get_settings
()
#
settings = get_settings()
qry
=
qry_vendor_produk
()
qry
=
qry_vendor_produk
()
if
vendor_kd
:
if
vendor_kd
:
log
.
info
(
vendor_kd
)
log
.
info
(
vendor_kd
)
...
@@ -79,20 +81,21 @@ def get_vendor_produk(produk_kd, vendor_kd=None, harga=None):
...
@@ -79,20 +81,21 @@ def get_vendor_produk(produk_kd, vendor_kd=None, harga=None):
.
filter
(
Partner
.
kode
==
vendor_kd
)
\
.
filter
(
Partner
.
kode
==
vendor_kd
)
\
.
filter
(
Produk
.
kode
==
produk_kd
)
.
first
()
.
filter
(
Produk
.
kode
==
produk_kd
)
.
first
()
if
is_devel
():
#
if is_devel():
settings
=
get_settings
()
#
settings = get_settings()
vend_kd
=
'dev_vend_kd'
in
settings
and
settings
[
'dev_vend_kd'
]
or
'test'
#
vend_kd = 'dev_vend_kd' in settings and settings ['dev_vend_kd'] or 'test'
log
.
info
(
vend_kd
)
#
log.info(vend_kd)
return
qry
\
#
return qry \
.
filter
(
Partner
.
kode
==
vend_kd
)
\
#
.filter(Partner.kode == vend_kd) \
.
filter
(
Produk
.
kode
==
produk_kd
)
.
first
()
#
.filter(Produk.kode == produk_kd).first()
else
:
#
else:
result
=
qry
\
result
=
qry
\
.
filter
(
Produk
.
kode
==
produk_kd
)
.
order_by
(
PartnerProduk
.
harga
)
.
filter
(
Produk
.
kode
==
produk_kd
)
.
order_by
(
PartnerProduk
.
harga
)
row
=
result
.
filter
(
PartnerProduk
.
harga
>
harga
)
.
first
()
# row = result.filter(PartnerProduk.harga > harga).first()
if
not
row
:
row
=
result
.
first
()
harga
=
0
# if not row:
row
=
result
.
filter
(
PartnerProduk
.
harga
>
harga
)
.
first
()
# harga = 0
# row = result.filter(PartnerProduk.harga > harga).first()
return
row
return
row
...
@@ -153,7 +156,14 @@ def inquiry(request, data, **kwargs):
...
@@ -153,7 +156,14 @@ def inquiry(request, data, **kwargs):
raise
JsonRpcCustomerNotFoundError
()
raise
JsonRpcCustomerNotFoundError
()
r_data
=
[]
r_data
=
[]
for
prod
in
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
# prods = "produk" in dat and dat["produk"] or None
# for prod in prods:
# for prod in prods:
# log.info(prod)
# log.info(prod)
...
@@ -165,15 +175,33 @@ def inquiry(request, data, **kwargs):
...
@@ -165,15 +175,33 @@ def inquiry(request, data, **kwargs):
if
not
vendor_produk
:
if
not
vendor_produk
:
raise
JsonRpcProdukNotFoundError
(
message
=
"Produk
%
s tidak ditemukan"
%
produk_kd
)
raise
JsonRpcProdukNotFoundError
(
message
=
"Produk
%
s tidak ditemukan"
%
produk_kd
)
partner_log
=
PartnerLog
()
# diremark by tatang
partner_log
.
vendor_id
=
vendor_produk
.
partner_id
# partner_log = PartnerLog()
partner_log
.
customer_id
=
customer
.
id
# partner_log.vendor_id = vendor_produk.partner_id
partner_log
.
produk_id
=
vendor_produk
.
produk
.
id
# partner_log.customer_id = customer.id
# partner_log.cust_inv = dat["inv_no"]
# partner_log.produk_id = vendor_produk.produk.id
partner_log
.
id_pel
=
prod
[
"id_pel"
]
# # 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
)
flush_row
(
partner_log
)
result
=
build_request
(
'inquiry'
,
vendor_produk
,
partner_log
)
if
result
[
"code"
]
==
0
:
if
result
[
"code"
]
==
0
:
prod
.
update
(
result
)
prod
.
update
(
result
)
...
@@ -260,7 +288,6 @@ def purchase(request, data, **kwargs):
...
@@ -260,7 +288,6 @@ def purchase(request, data, **kwargs):
ar_invoice
=
H2hArInvoice
()
ar_invoice
=
H2hArInvoice
()
ar_invoice
.
customer_id
=
customer
.
id
ar_invoice
.
customer_id
=
customer
.
id
ar_invoice
.
cust_inv_no
=
inv_no
ar_invoice
.
cust_inv_no
=
inv_no
ar_invoice
.
cust_inv_no
=
inv_no
ar_invoice
.
payment
=
dict
(
request
=
dat
)
ar_invoice
.
payment
=
dict
(
request
=
dat
)
flush_row
(
ar_invoice
)
flush_row
(
ar_invoice
)
r_prod
=
[]
r_prod
=
[]
...
@@ -569,3 +596,38 @@ def advice(request, data):
...
@@ -569,3 +596,38 @@ def advice(request, data):
# data[i]=r_data
# data[i]=r_data
# i += 1
# i += 1
# return data
# 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
\ No newline at end of file
src/agratek/api/merchant/views/np/__init__.py
View file @
3f5ca6d
...
@@ -8,46 +8,50 @@ from opensipkd.base.models import Partner
...
@@ -8,46 +8,50 @@ from opensipkd.base.models import Partner
from
.
import
Nicepay
from
.
import
Nicepay
from
..vendor
import
VendorClass
# setMandatoryParameter
import
logging
import
urllib3
log
=
logging
.
getLogger
(
__name__
)
urllib3
.
disable_warnings
()
class
Vendor
(
object
):
#VendorClass
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
args
=
kwargs
class
Vendor
(
VendorClass
):
self
.
values
=
args
[
"values"
]
def
__init__
(
self
,
vendor_produk
,
invoice_det
,
**
kwargs
):
VendorClass
.
__init__
(
self
,
vendor_produk
,
invoice_det
,
**
kwargs
)
self
.
v_produk_kd
=
vendor_produk
.
kode
self
.
v_produk_kd
=
vendor_produk
.
kode
customer
=
Partner
.
query_id
(
self
.
values
[
"customer_id"
])
.
first
()
self
.
cust_kd
=
None
if
customer
:
self
.
cust_inv_no
=
None
self
.
cust_kd
=
customer
.
kode
self
.
agra_cust_inv_no
=
None
self
.
cust_inv_no
=
"cust_inv_no"
in
self
.
values
\
and
self
.
values
[
"cust_inv_no"
]
or
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
\
self
.
agra_cust_inv_no
=
self
.
cust_kd
and
self
.
cust_inv_no
\
and
self
.
cust_kd
+
self
.
cust_inv_no
or
None
and
self
.
cust_kd
+
self
.
cust_inv_no
or
None
settings
=
get_settings
()
self
.
mid
=
'np_mid'
in
settings
and
settings
[
'np_mid'
]
or
None
self
.
mid
=
'np_mid'
in
self
.
settings
and
self
.
settings
[
'np_mid'
]
or
None
self
.
key
=
'np_key'
in
settings
and
settings
[
'np_key'
]
or
None
self
.
key
=
'np_key'
in
self
.
settings
and
self
.
settings
[
'np_key'
]
or
None
self
.
url
=
'np_url'
in
settings
and
settings
[
'np_url'
]
or
None
self
.
url
=
'np_url'
in
self
.
settings
and
self
.
settings
[
'np_url'
]
or
None
Nicepay
.
merchantKey
=
self
.
key
Nicepay
.
merchantKey
=
self
.
key
Nicepay
.
iMid
=
self
.
mid
Nicepay
.
iMid
=
self
.
mid
self
.
ip
=
Nicepay
.
userIp
()
self
.
ip
=
Nicepay
.
userIp
()
self
.
customer
=
dict
(
self
.
customer
=
dict
(
barang
=
'GOODSNM'
,
barang
=
invoice_det
.
produk
.
nama
,
#
'GOODSNM',
nama
=
'BILLING NAME'
,
nama
=
self
.
row_customer
.
nama
,
#
'BILLING NAME',
phone
=
'08123456789'
,
phone
=
self
.
row_customer
.
phone
,
#
'08123456789',
email
=
'ADETEST01@GMAIL.COM'
,
email
=
self
.
row_customer
.
email
,
#
'ADETEST01@GMAIL.COM',
kota
=
'JAKARTA'
,
kota
=
self
.
row_customer
.
kota
,
#
'JAKARTA',
provinsi
=
'JAKARTA'
,
provinsi
=
self
.
row_customer
.
provinsi
,
#
'JAKARTA',
kd_pos
=
'14350'
,
kd_pos
=
None
,
#
'14350',
negara
=
'INDONESIA'
,
negara
=
'INDONESIA'
,
)
)
# self.cust_trx = 'REFERENCENO'
# self.pay_method = '01'
self
.
url
=
'https://www.merchant.com/Notification'
self
.
url
=
'https://www.merchant.com/Notification'
self
.
bank_cd
,
self
.
pay_method
=
self
.
v_produk_kd
.
split
(
'-'
)
self
.
bank_cd
,
self
.
pay_method
=
self
.
v_produk_kd
.
split
(
'-'
)
...
@@ -55,38 +59,38 @@ class Vendor(object): #VendorClass
...
@@ -55,38 +59,38 @@ class Vendor(object): #VendorClass
self
.
notify_url
=
"dev.agratek.co.id/api/np/notify"
self
.
notify_url
=
"dev.agratek.co.id/api/np/notify"
self
.
callback_url
=
"dev.agratek.co.id/api/np/calllback"
self
.
callback_url
=
"dev.agratek.co.id/api/np/calllback"
self
.
reccuring
=
False
self
.
reccuring
=
False
self
.
amt
=
str
(
self
.
values
[
"amount"
])
# self.amt = str(self.values["amount"])
self
.
amt
=
'0'
now
=
datetime
.
now
()
now
=
datetime
.
now
()
self
.
time_stamp
=
now
.
strftime
(
"
%
Y
%
m
%
d
%
H
%
M
%
S"
)
self
.
time_stamp
=
now
.
strftime
(
"
%
Y
%
m
%
d
%
H
%
M
%
S"
)
tommorow
=
now
+
timedelta
(
days
=
1
)
tommorow
=
now
+
timedelta
(
days
=
1
)
self
.
valid_date
=
tommorow
.
strftime
(
"
%
Y
%
m
%
d"
)
self
.
valid_date
=
tommorow
.
strftime
(
"
%
Y
%
m
%
d"
)
self
.
valid_time
=
"235500"
self
.
valid_time
=
"235500"
def
request_payment
(
self
,
response
):
def
request_payment
(
self
,
response
):
Nicepay
.
requestData
=
{}
Nicepay
.
requestData
=
{}
Nicepay
.
set
(
'timeStamp'
,
self
.
time_stamp
)
Nicepay
.
set
(
'timeStamp'
,
self
.
time_stamp
)
# '20180109181300'
# Nicepay.set('referenceNo', self.time_stamp) #'20180109181300'
# Nicepay.set('reffenceNo', self.time_stamp) #'20180109181300'
Nicepay
.
set
(
'referenceNo'
,
self
.
agra_cust_inv_no
)
Nicepay
.
set
(
'referenceNo'
,
self
.
agra_cust_inv_no
)
#'5a44213129be40320ef1a4b57095bfa61cd3ff0436bc442a9d82232e62203f37')
Nicepay
.
set
(
'tXid'
,
response
[
"tXid"
])
# 'IONPAYTEST02201802051512483907'get tXid from register first
Nicepay
.
set
(
'tXid'
,
response
[
"tXid"
])
# 'IONPAYTEST02201802051512483907'get tXid from register first
Nicepay
.
set
(
'cardNo'
,
self
.
values
[
"card_no"
])
#'5409120028181901'
#
Nicepay.set('cardNo', self.values["card_no"]) #'5409120028181901'
Nicepay
.
set
(
'cardExpYymm'
,
self
.
values
[
"card_exp"
])
# format Yymm '2012'
#
Nicepay.set('cardExpYymm', self.values["card_exp"]) # format Yymm '2012'
Nicepay
.
set
(
'cardCvv'
,
self
.
values
[
"card_cvv"
])
#
Nicepay.set('cardCvv', self.values["card_cvv"])
Nicepay
.
set
(
'recurringToken'
,
''
)
Nicepay
.
set
(
'recurringToken'
,
''
)
Nicepay
.
set
(
'preauthToken'
,
''
)
Nicepay
.
set
(
'preauthToken'
,
''
)
Nicepay
.
set
(
'clickPayNo'
,
''
)
Nicepay
.
set
(
'clickPayNo'
,
''
)
Nicepay
.
set
(
'dataField3'
,
''
)
Nicepay
.
set
(
'dataField3'
,
''
)
Nicepay
.
set
(
'clickPayToken'
,
''
)
Nicepay
.
set
(
'clickPayToken'
,
''
)
Nicepay
.
set
(
'callBackUrl'
,
self
.
callback_url
)
Nicepay
.
set
(
'callBackUrl'
,
self
.
callback_url
)
result
=
Nicepay
.
nicePayment
()
result
=
Nicepay
.
nicePayment
()
return
result
return
result
def
set_static_params
(
self
):
def
set_static_params
(
self
):
if
not
self
.
agra_cust_inv_no
:
if
not
self
.
agra_cust_inv_no
:
return
return
Nicepay
.
set
(
'timeStamp'
,
self
.
time_stamp
)
#
Nicepay
.
set
(
'timeStamp'
,
self
.
time_stamp
)
Nicepay
.
set
(
'iMid'
,
self
.
mid
)
Nicepay
.
set
(
'iMid'
,
self
.
mid
)
Nicepay
.
set
(
'payMethod'
,
self
.
pay_method
)
Nicepay
.
set
(
'payMethod'
,
self
.
pay_method
)
Nicepay
.
set
(
'currency'
,
'IDR'
)
Nicepay
.
set
(
'currency'
,
'IDR'
)
...
@@ -134,9 +138,9 @@ class Vendor(object): #VendorClass
...
@@ -134,9 +138,9 @@ class Vendor(object): #VendorClass
# Nicepay.set('userAgent', 'Mozilla')
# Nicepay.set('userAgent', 'Mozilla')
# Nicepay.set('userLanguage', 'en-US')
# Nicepay.set('userLanguage', 'en-US')
def
inquiry
(
self
):
def
inquiry
(
self
):
Nicepay
.
requestData
=
{}
# Nicepay.requestData = {}
self
.
request
=
Nicepay
.
requestData
if
not
self
.
set_static_params
()
or
not
self
.
set_billing_param
():
if
not
self
.
set_static_params
()
or
not
self
.
set_billing_param
():
return
return
Nicepay
.
set
(
'cartData'
,
'{}'
)
Nicepay
.
set
(
'cartData'
,
'{}'
)
...
@@ -144,7 +148,7 @@ class Vendor(object): #VendorClass
...
@@ -144,7 +148,7 @@ class Vendor(object): #VendorClass
if
self
.
pay_method
==
'01'
:
if
self
.
pay_method
==
'01'
:
Nicepay
.
set
(
'instmntType'
,
'2'
)
Nicepay
.
set
(
'instmntType'
,
'2'
)
Nicepay
.
set
(
'instmntMon'
,
'1'
)
Nicepay
.
set
(
'instmntMon'
,
'1'
)
if
(
self
.
reccuring
)
:
if
self
.
reccuring
:
# For Credit Card Reccuring Only
# For Credit Card Reccuring Only
Nicepay
.
set
(
'recurrOpt'
,
'0'
)
Nicepay
.
set
(
'recurrOpt'
,
'0'
)
...
@@ -174,7 +178,7 @@ class Vendor(object): #VendorClass
...
@@ -174,7 +178,7 @@ class Vendor(object): #VendorClass
self
.
set_optional_param
()
self
.
set_optional_param
()
self
.
request
=
Nicepay
.
requestData
self
.
request
=
Nicepay
.
requestData
#
self.save_log('inquiry')
self
.
save_log
(
'inquiry'
)
# result = {}
# result = {}
resultData
=
Nicepay
.
niceRegister
()
resultData
=
Nicepay
.
niceRegister
()
...
@@ -229,11 +233,14 @@ class Vendor(object): #VendorClass
...
@@ -229,11 +233,14 @@ class Vendor(object): #VendorClass
result
[
"resultCd"
]
=
response
[
'resultCd'
]
result
[
"resultCd"
]
=
response
[
'resultCd'
]
result
[
"resultMsg"
]
=
response
[
'resultMsg'
]
result
[
"resultMsg"
]
=
response
[
'resultMsg'
]
self
.
result
=
response
self
.
result
=
response
# self.save_log('inquiry')
self
.
save_log
(
'inquiry'
)
return
dict
(
data
=
result
)
return
dict
(
data
=
result
)
# https://api.nicepay.co.id/nicepay/direct/v2/registration
# https://api.nicepay.co.id/nicepay/direct/v2/registration
# Request Body
# Request Body
"""
"""
{
{
"deliveryPhone": "62-21-0000-0000",
"deliveryPhone": "62-21-0000-0000",
...
...
src/agratek/api/merchant/views/np_original/Nicepay.py
0 → 100644
View file @
3f5ca6d
import
socket
import
hashlib
import
sys
import
requests
py3
=
sys
.
version
>=
'3'
from
urllib.parse
import
urlparse
,
urlencode
import
http.client
if
py3
:
pass
else
:
import
urlparse
import
httplib
# import urllib
import
json
# global iMid
global
merchantKey
# iMid = 'IONPAYTEST'
# merchantKey = '33F49GnCMS1mFYlGXisbUDzVf2ATWCl9k3R++d5hDd3Frmuos/XLx8XhXpe+LDYAbpGKZYSwtlyyLOtS/8aD7A=='
timeout_connect
=
30
timeout_read
=
25
requestData
=
{}
requestDataJson
=
{}
resultData
=
{}
def
set
(
name
,
value
):
requestData
[
name
]
=
value
return
requestData
def
merchantToken
():
if
not
requestData
[
'timeStamp'
]:
sys
.
exit
(
"Cannot set Merchant Token, please setting timeStamp"
)
elif
not
requestData
[
'referenceNo'
]:
sys
.
exit
(
"Cannot set Merchant Token, please setting referenceNo"
)
elif
not
requestData
[
'amt'
]:
sys
.
exit
(
"Cannot set Merchant Token, please setting amt"
)
else
:
mercToken
=
requestData
[
'timeStamp'
]
+
requestData
[
"iMid"
]
+
\
requestData
[
'referenceNo'
]
+
requestData
[
'amt'
]
+
\
merchantKey
token
=
hashlib
.
sha256
(
mercToken
.
encode
(
'ascii'
))
.
hexdigest
()
return
token
def
merchantTokenCancel
():
if
not
requestData
[
'timeStamp'
]:
sys
.
exit
(
"Cannot set Merchant Token, please setting timeStamp"
)
elif
not
requestData
[
'tXid'
]:
sys
.
exit
(
"Cannot set Merchant Token, please setting tXid"
)
elif
not
requestData
[
'amt'
]:
sys
.
exit
(
"Cannot set Merchant Token, please setting amt"
)
else
:
mercToken
=
requestData
[
'timeStamp'
]
+
requestData
[
"iMid"
]
+
requestData
[
'tXid'
]
+
requestData
[
'amt'
]
+
merchantKey
token
=
hashlib
.
sha256
(
mercToken
.
encode
(
'ascii'
))
.
hexdigest
()
return
token
def
merchantTokenVacctInquiry
():
if
not
requestData
[
'vacctNo'
]:
sys
.
exit
(
"Cannot set Merchant Token, please setting vacctNo"
)
elif
not
requestData
[
'startDt'
]:
sys
.
exit
(
"Cannot set Merchant Token, please setting startDt"
)
else
:
mercToken
=
requestData
[
"iMid"
]
+
requestData
[
'vacctNo'
]
+
requestData
[
'startDt'
]
+
merchantKey
token
=
hashlib
.
sha256
(
mercToken
.
encode
(
'ascii'
))
.
hexdigest
()
return
token
def
merchantTokenCustomerIdInquiry
():
if
not
requestData
[
'customerId'
]:
sys
.
exit
(
"Cannot set Merchant Token, please setting customerId"
)
elif
not
requestData
[
'startDt'
]:
sys
.
exit
(
"Cannot set Merchant Token, please setting startDt"
)
else
:
mercToken
=
requestData
[
"iMid"
]
+
requestData
[
'customerId'
]
+
requestData
[
'startDt'
]
+
merchantKey
token
=
hashlib
.
sha256
(
mercToken
.
encode
(
'ascii'
))
.
hexdigest
()
return
token
def
userIp
():
return
socket
.
gethostbyname
(
socket
.
gethostname
())
def
niceRegister
():
requestDataJson
=
json
.
dumps
(
requestData
)
apiUrl
=
"https://api.nicepay.co.id/nicepay/direct/v2/registration"
resultData
=
sendDataJson
(
requestDataJson
,
apiUrl
)
return
resultData
def
niceInquiry
():
requestDataJson
=
json
.
dumps
(
requestData
)
apiUrl
=
"https://api.nicepay.co.id/nicepay/direct/v2/inquiry"
resultData
=
sendDataJson
(
requestDataJson
,
apiUrl
)
return
resultData
def
niceCancel
():
requestDataJson
=
json
.
dumps
(
requestData
)
apiUrl
=
"https://api.nicepay.co.id/nicepay/direct/v2/cancel"
resultData
=
sendDataJson
(
requestDataJson
,
apiUrl
)
return
resultData
def
nicePayment
():
apiUrl
=
"https://api.nicepay.co.id/nicepay/direct/v2/payment"
resultData
=
sendData
(
requestData
,
apiUrl
)
return
resultData
def
niceVacctInquiry
():
apiUrl
=
"https://api.nicepay.co.id/nicepay/api/vacctInquiry.do"
resultData
=
sendData
(
requestData
,
apiUrl
)
return
resultData
def
niceCustomerIdInquiry
():
apiUrl
=
"https://api.nicepay.co.id/nicepay/api/vacctCustomerIdInquiry.do"
resultData
=
sendData
(
requestData
,
apiUrl
)
return
resultData
def
niceInstallmentInfo
():
requestDataJson
=
json
.
dumps
(
requestData
)
apiUrl
=
"https://api.nicepay.co.id/nicepay/direct/v2/instInfoInquiry"
resp
=
sendDataJson
(
requestDataJson
,
apiUrl
)
resultData
=
sendDataJson
(
requestDataJson
,
apiUrl
)
return
resultData
def
sendDataJson
(
data
,
apiUrl
):
requestData
=
data
host
=
urlparse
(
apiUrl
)
hostUrl
=
host
.
netloc
hostPath
=
host
.
path
headers
=
{
"Content-type"
:
"application/json"
}
# if py3:
# conn = http.client.HTTPSConnection(hostUrl,timeout=timeout_connect)
# else:
# conn = httplib.HTTPSConnection(hostUrl, 443, 0, 0, 0, timeout_connect)
# conn.request("POST", hostPath, requestData, headers)
# readData = conn.getresponse(timeout_read)
# resultData = readData.read()
resp
=
requests
.
post
(
apiUrl
,
headers
=
headers
,
data
=
data
)
return
resp
.
text
def
sendData
(
data
,
apiUrl
):
host
=
urlparse
(
apiUrl
)
hostUrl
=
host
.
netloc
hostPath
=
host
.
path
params
=
urlencode
(
data
)
headers
=
{
"Content-type"
:
"application/x-www-form-urlencoded"
}
# if py3:
# conn = http.client.HTTPSConnection(hostUrl,timeout=timeout_connect)
# else:
# conn = httplib.HTTPSConnection(hostUrl, 443, 0, 0, 0, timeout_connect)
#
# conn.request("POST", hostPath, params, headers)
# readData = conn.getresponse(timeout_read)
# resultData = readData.read()
resp
=
requests
.
post
(
apiUrl
,
headers
=
headers
,
data
=
data
)
return
resp
.
text
src/agratek/api/merchant/views/np_original/__init__.py
0 → 100644
View file @
3f5ca6d
This diff is collapsed.
Click to expand it.
src/agratek/api/merchant/views/vendor.py
View file @
3f5ca6d
...
@@ -37,6 +37,7 @@ class VendorClass(object):
...
@@ -37,6 +37,7 @@ class VendorClass(object):
:param cust_trx:
:param cust_trx:
:param row:
:param row:
"""
"""
self
.
settings
=
get_settings
()
self
.
vendor_produk
=
vendor_produk
self
.
vendor_produk
=
vendor_produk
self
.
invoice_det
=
invoice_det
self
.
invoice_det
=
invoice_det
self
.
v_produk_kd
=
vendor_produk
.
kode
self
.
v_produk_kd
=
vendor_produk
.
kode
...
@@ -52,6 +53,10 @@ class VendorClass(object):
...
@@ -52,6 +53,10 @@ class VendorClass(object):
and
invoice_det
.
serial_number
or
None
and
invoice_det
.
serial_number
or
None
self
.
amt_buy
=
0
self
.
amt_buy
=
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"
):
def
set_response
(
self
,
data
=
None
,
message
=
None
,
code
=
999
,
typ
=
"inquiry"
):
if
not
data
and
message
:
if
not
data
and
message
:
message
=
message
and
message
or
"Biller No Response"
message
=
message
and
message
or
"Biller No Response"
...
...
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