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 457ffbc1
authored
Aug 30, 2019
by
Solo Group
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'master' of
http://git.opensipkd.com:8088/pasar/api-merchant
2 parents
6d464ccb
31d093b9
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1059 additions
and
172 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/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/api_merchant.py
View file @
457ffbc
...
...
@@ -18,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
)
...
...
@@ -43,8 +40,6 @@ 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
,
...
...
@@ -82,10 +77,8 @@ def get_vendor_produk(produk_kd, vendor_kd=None, harga=None):
# data vendor parameter secara default mengambil dari yang statusnya=1
if
vendor_kd
:
qry
=
qry
.
filter
(
Partner
.
kode
==
vendor_kd
)
else
:
qry
=
qry
.
filter
(
PartnerProduk
.
status
==
1
)
row
=
qry
.
first
()
return
row
...
...
@@ -102,7 +95,6 @@ def inquiry(request, data, **kwargs):
}
:param token:
user_token
:return:
{
"data": [{
...
...
@@ -130,7 +122,6 @@ def inquiry(request, data, **kwargs):
customer
=
Partner
.
query_user
(
user
)
.
filter
(
Partner
.
is_customer
==
1
)
.
first
()
if
not
customer
:
raise
JsonRpcCustomerNotFoundError
()
r_data
=
[]
for
prod
in
data
:
# prods = "produk" in dat and dat["produk"] or None
...
...
@@ -144,7 +135,6 @@ def inquiry(request, data, **kwargs):
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
))
...
...
@@ -155,14 +145,12 @@ def inquiry(request, data, **kwargs):
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
...
...
@@ -187,7 +175,6 @@ def purchase(request, data, **kwargs):
:return:
{
product_nm:string,
denom: string,
id_pel:string
inv_no: string optional
...
...
@@ -198,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
:
...
...
@@ -259,14 +243,11 @@ def purchase(request, data, **kwargs):
# 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
...
...
@@ -288,7 +269,6 @@ def advice(request, data):
:return:
{
product_nm:string,
denom: string,
id_pel:string
inv_no: string optional
...
...
@@ -299,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
...
...
@@ -307,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
:
...
...
@@ -350,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
),
...
...
@@ -362,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):
...
...
src/agratek/api/merchant/views/api_payment.py
0 → 100644
View file @
457ffbc
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 @
457ffbc
import
json
import
base64
import
logging
# Import Library (Mandatory)
from
datetime
import
datetime
,
timedelta
...
...
@@ -7,73 +9,87 @@ from opensipkd.base import get_settings
from
opensipkd.base.models
import
Partner
from
.
import
Nicepay
from
..vendor
import
VendorClass
log
=
logging
.
getLogger
(
__name__
)
# setMandatoryParameter
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
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',
# )
#
args
=
kwargs
self
.
values
=
args
[
"values"
]
self
.
v_produk_kd
=
vendor_produk
.
kode
customer
=
Partner
.
query_id
(
self
.
values
[
"customer_id"
])
.
first
()
if
customer
:
self
.
cust_kd
=
customer
.
kode
self
.
cust_inv_no
=
"cust_inv_no"
in
self
.
values
\
and
self
.
values
[
"cust_inv_no"
]
or
None
self
.
agra_cust_inv_no
=
self
.
cust_kd
and
self
.
cust_inv_no
\
and
self
.
cust_kd
+
self
.
cust_inv_no
or
None
def
__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
Nicepay
.
merchantKey
=
self
.
key
Nicepay
.
iMid
=
self
.
mid
self
.
ip
=
Nicepay
.
userIp
()
self
.
customer
=
dict
(
barang
=
'GOODSNM'
,
nama
=
'BILLING NAME'
,
phone
=
'08123456789'
,
email
=
'ADETEST01@GMAIL.COM'
,
kota
=
'JAKARTA'
,
provinsi
=
'JAKARTA'
,
kd_pos
=
'14350'
,
negara
=
'INDONESIA'
,
)
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
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
# self.cust_trx = 'REFERENCENO'
# self.pay_method = '01'
self
.
url
=
'https://www.merchant.com/Notification'
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"
]
)
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
)
# '20180109181300'
# Nicepay.set('reffenceNo', self.time_stamp) #'20180109181300'
Nicepay
.
set
(
'referenceNo'
,
self
.
agra_cust_inv_no
)
#'5a44213129be40320ef1a4b57095bfa61cd3ff0436bc442a9d82232e62203f37')
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'
,
''
)
...
...
@@ -84,80 +100,109 @@ class Vendor(object): #VendorClass
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')
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
inquiry
(
self
):
def
register
(
self
):
Nicepay
.
requestData
=
{}
if
not
self
.
set_
static_params
()
or
not
self
.
set_billing_param
():
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
...
...
@@ -165,8 +210,8 @@ class Vendor(object): #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
...
...
@@ -174,15 +219,12 @@ class Vendor(object): #VendorClass
self
.
set_optional_param
()
self
.
request
=
Nicepay
.
requestData
# 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
)
log
.
info
(
"REQUEST: {}"
.
format
(
json
.
dumps
(
self
.
request
)))
self
.
save_log
(
'inquiry'
)
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
...
...
@@ -193,42 +235,44 @@ class Vendor(object): #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
# 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
)
...
...
src/agratek/api/merchant/views/np_original/Nicepay.py
0 → 100644
View file @
457ffbc
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 @
457ffbc
import
json
# Import Library (Mandatory)
from
datetime
import
datetime
,
timedelta
from
opensipkd.base
import
get_settings
from
opensipkd.base.models
import
Partner
from
.
import
Nicepay
# setMandatoryParameter
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
self
.
values
=
args
[
"values"
]
self
.
v_produk_kd
=
vendor_produk
.
kode
customer
=
Partner
.
query_id
(
self
.
values
[
"customer_id"
])
.
first
()
if
customer
:
self
.
cust_kd
=
customer
.
kode
self
.
cust_inv_no
=
"cust_inv_no"
in
self
.
values
\
and
self
.
values
[
"cust_inv_no"
]
or
None
self
.
agra_cust_inv_no
=
self
.
cust_kd
and
self
.
cust_inv_no
\
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
.
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
.
ip
=
Nicepay
.
userIp
()
self
.
customer
=
dict
(
barang
=
'GOODSNM'
,
nama
=
'BILLING NAME'
,
phone
=
'08123456789'
,
email
=
'ADETEST01@GMAIL.COM'
,
kota
=
'JAKARTA'
,
provinsi
=
'JAKARTA'
,
kd_pos
=
'14350'
,
negara
=
'INDONESIA'
,
)
# self.cust_trx = 'REFERENCENO'
# self.pay_method = '01'
self
.
url
=
'https://www.merchant.com/Notification'
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
.
reccuring
=
False
self
.
amt
=
str
(
self
.
values
[
"amount"
])
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"
def
request_payment
(
self
,
response
):
Nicepay
.
requestData
=
{}
Nicepay
.
set
(
'timeStamp'
,
self
.
time_stamp
)
# '20180109181300'
# Nicepay.set('reffenceNo', self.time_stamp) #'20180109181300'
Nicepay
.
set
(
'referenceNo'
,
self
.
agra_cust_inv_no
)
#'5a44213129be40320ef1a4b57095bfa61cd3ff0436bc442a9d82232e62203f37')
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
(
'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
:
return
Nicepay
.
set
(
'timeStamp'
,
self
.
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
(
'merchantToken'
,
Nicepay
.
merchantToken
())
return
True
def
set_billing_param
(
self
):
if
not
self
.
customer
:
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'
])
return
True
def
set_optional_param
(
self
):
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
=
{}
if
not
self
.
set_static_params
()
or
not
self
.
set_billing_param
():
return
Nicepay
.
set
(
'cartData'
,
'{}'
)
# 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'
)
# 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
elif
self
.
pay_method
in
[
'03'
,
'04'
,
'05'
]:
# For CVS,ClickPay or E-Wallet
# (Don't forgot change payMethod to '03'/'04'/'05')
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)
elif
self
.
pay_method
==
'04'
:
# For ClickPay Only
Nicepay
.
set
(
'mRefNo'
,
self
.
cust_inv_no
)
self
.
set_optional_param
()
self
.
request
=
Nicepay
.
requestData
# 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
)
self
.
response
=
response
# # Payment Response String Format
if
'resultCd'
not
in
response
:
self
.
result
=
dict
(
error
=
"Connection Timeout. Please Try Again!"
)
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'
]
elif
response
[
'payMethod'
]
==
"03"
:
result
[
"mitraCd"
]
=
response
[
'mitraCd'
]
result
[
"payNo"
]
=
response
[
'payNo'
]
result
[
"vacctValidDt"
]
=
response
[
'payValidDt'
]
result
[
"vacctValidTm"
]
=
response
[
'payValidTm'
]
elif
result
[
'payMethod'
]
==
"04"
:
result
[
"mitraCd"
]
=
response
[
'mitraCd'
]
result
[
"receiptCode"
]
=
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')
return
dict
(
data
=
result
)
# https://api.nicepay.co.id/nicepay/direct/v2/registration
# Request Body
"""
{
"deliveryPhone": "62-21-0000-0000",
"mitraCd": "ALMA",
"fee": "0",
"amt": "1000",
"description": "this is test transaction!!",
"notaxAmt": "0",
"reqDomain": "localhost",
"userLanguage": "ko-KR,en-US;q=0.8,ko;q=0.6,en;q=0.4",
"vacctValidDt": "",
"billingEmail": "no-reply@ionpay.net",
"merFixAcctId": "",
"payMethod": "01",
"deliveryAddr": "Jalan Jenderal Gatot Subroto Kav.57",
"billingCountry": "ID",
"userIP": "0:0:0:0:0:0:0:1",
"instmntMon": "1",
"currency": "IDR",
"payValidDt": "",
"deliveryCity": "Jakarta",
"merchantToken": "b5149659e1a2f1271fb0833f8ea20e174b6fd389db26bc6ad036cc0dae6fa797",
"goodsNm": "T-1000",
"referenceNo": "OrdNo2017717942577",
"vat": "0",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/60.0.3112.101 Safari/537.36",
"billingState": "Jakarta",
"userSessionID": "697D6922C961070967D3BA1BA5699C2C",
"instmntType": "1",
"deliveryNm": "HongGilDong",
"deliveryPostCd": "12950",
"reqClientVer": "",
"iMid": "IONPAYTEST",
"billingNm": "HongGilDong",
"timeStamp": "20170822170942",
"dbProcessUrl": "http://127.0.0.1:8080/nicepay/test3/dbProcess.do",
"payValidTm": "",
"cartData": "{“count”: “1”,
“item”: [{“img_url”: “https://www.lecs.com/image/introduction/img_vmd020101.jpg”,
“goods_name”: “Jam Tangan Army - Strap Kulit - Hitam”,
“goods_detail”: “jumlah 1”,
“goods_amt”: “400”}]}",
"deliveryState": "Jakarta",
"deliveryCountry": "ID",
"bankCd": "",
"billingPostCd": "12950",
"billingAddr": "Jalan Jenderal Gatot Subroto Kav.57",
"reqServerIP": "172.29.2.178",
"vacctValidTm": "",
"billingPhone": "021-579-00000",
"billingCity": "Jakarta"
}
// Response Body
{
"resultCd": "0000",
"resultMsg": "SUCCESS",
"tXid": "IONPAYTEST01201708221510237472",
"referenceNo": "OrdNo2017717942577",
"payMethod": "01",
"amt": "1000",
"transDt": "20170822",
"transTm": "171029",
"description": "this is test transaction!!",
"bankCd": null,
"vacctNo": null,
"mitraCd": null,
"payNo": null
….
}
"""
src/agratek/api/merchant/views/vendor.py
View file @
457ffbc
...
...
@@ -37,6 +37,7 @@ class VendorClass(object):
:param cust_trx:
:param row:
"""
self
.
settings
=
get_settings
()
self
.
vendor_produk
=
vendor_produk
self
.
invoice_det
=
invoice_det
self
.
v_produk_kd
=
vendor_produk
.
kode
...
...
@@ -53,7 +54,7 @@ class VendorClass(object):
self
.
amt_buy
=
0
self
.
amt_sell
=
0
self
.
discount
=
0
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