Commit 31d093b9 by Tatang

np register

1 parent 5da8ce29
import logging
from importlib import import_module from importlib import import_module
from opensipkd.base.models import Partner, flush_row from opensipkd.base.models import Partner, flush_row
from opensipkd.base.tools.api import (auth_from_rpc, from opensipkd.base.tools.api import (auth_from_rpc,
...@@ -6,8 +7,8 @@ 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 import Produk, PartnerProduk
from opensipkd.pasar.models.produk import H2hArInvoice, H2hArInvoiceDet, PartnerLog from opensipkd.pasar.models.produk import H2hArInvoice, H2hArInvoiceDet, PartnerLog
from pyramid_rpc.jsonrpc import jsonrpc_method from pyramid_rpc.jsonrpc import jsonrpc_method
from opensipkd.base.tools import get_settings from ..tools import JsonRpcInvoiceFoundError, JsonRpcError
import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -17,16 +18,13 @@ def build_request(typ, vendor_produk, partner_log=None): ...@@ -17,16 +18,13 @@ def build_request(typ, vendor_produk, partner_log=None):
# bill_no = values['destination'] # bill_no = values['destination']
# customer_id = 'customer_id' in values and values['customer_id'] or None # 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 # cust_trx_id = 'cust_trx_id' in values and values['cust_trx_id'] or 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)
...@@ -42,15 +40,12 @@ def build_request(typ, vendor_produk, partner_log=None): ...@@ -42,15 +40,12 @@ def build_request(typ, vendor_produk, partner_log=None):
result["f_response"] = cls_module.response result["f_response"] = cls_module.response
result["f_result"] = cls_module.result result["f_result"] = cls_module.result
result["f_request"] = cls_module.request result["f_request"] = cls_module.request
else: else:
log.info("Module %s Not Found" % vendor_produk.modules) log.info("Module %s Not Found" % vendor_produk.modules)
data = dict(message='Fungsi %s tidak ada' % typ, data = dict(message='Fungsi %s tidak ada' % typ,
code=9999) code=9999)
result = {"f_result": data} result = {"f_result": data}
# dict(data=) # dict(data=)
return result return result
...@@ -74,64 +69,24 @@ def get_vendor_produk(produk_kd, vendor_kd=None, harga=None): ...@@ -74,64 +69,24 @@ 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 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 qry = qry_vendor_produk().filter(Produk.kode == produk_kd)
# Jika parameter vendor_kd disebutkan maka secara explisit mengambil dari
# settings = get_settings() # data vendor parameter secara default mengambil dari yang statusnya=1
qry = qry_vendor_produk()
if vendor_kd: if vendor_kd:
log.info(vendor_kd) qry = qry.filter(Partner.kode == vendor_kd)
return qry \ else:
.filter(Partner.kode == vendor_kd) \ qry = qry.filter(PartnerProduk.status == 1)
.filter(Produk.kode == produk_kd).first() row = qry.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()
return row return row
@jsonrpc_method(method='inquiry', endpoint='api-merchant') @jsonrpc_method(method='inquiry', endpoint='api-merchant')
def inquiry(request, data, **kwargs): def inquiry(request, data, **kwargs):
""" """
Digunakan untuk mendapatkan daftar produk Digunakan untuk mendapatkan data tagihan
: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
:param request: :param request:
:param data: :param data:
{ {
...@@ -140,20 +95,25 @@ def inquiry(request, data, **kwargs): ...@@ -140,20 +95,25 @@ def inquiry(request, data, **kwargs):
} }
:param token: :param token:
user_token user_token
:return: :return:
{ {
product_nm:string, "data": [{
"nopel": "530678910981",
denom: string, "nama": "SUBCRIBER NAME",
id_pel:string "refno": "25641544",
inv_no: string optional "rincian":{
denom:string, "pokok": 300000,
harga:integer, "denda": 0,
admin:integer, "admin": 2500,
discount:integer, "tarif": "R1\/1300VA",
total:integer, "no_meter": "530678910012",
status:success/pending/failed "power": "1300VA"
},
"subtotal": 302500,
"discount": 800,
"total": 301700
}]
}
""" """
user = auth_from_rpc(request) user = auth_from_rpc(request)
i = 0 i = 0
...@@ -162,74 +122,35 @@ def inquiry(request, data, **kwargs): ...@@ -162,74 +122,35 @@ def inquiry(request, data, **kwargs):
customer = Partner.query_user(user).filter(Partner.is_customer == 1).first() customer = Partner.query_user(user).filter(Partner.is_customer == 1).first()
if not customer: if not customer:
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)
produk_kd = 'denom' in prod and prod['denom'] or None produk_kd = 'denom' in prod and prod['denom'] or None
if not produk_kd: if not produk_kd:
raise JsonRpcProdukNotFoundError(message="Produk harus diisi") 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_produk = get_vendor_produk(produk_kd, vendor_kd=vendor_kd)
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)
# diremark by tatang log.info("Vendor %s Produk %s Module %s" % (vendor_produk.partner.kode,
# partner_log = PartnerLog() vendor_produk.produk.kode,
# partner_log.vendor_id = vendor_produk.partner_id vendor_produk.modules))
# partner_log.customer_id = customer.id values = dict(customer_id=customer.id,
# partner_log.produk_id = vendor_produk.produk.id id_pel=prod["id_pel"])
# # partner_log.cust_inv = dat["inv_no"] partner_log = save_partner_log(values, vendor_produk)
# partner_log.id_pel = prod["id_pel"] result = build_request('inquiry', vendor_produk, partner_log)
# flush_row(partner_log) result_code = "code" in result["f_result"] and result["f_result"]["code"] or None
# result = build_request('inquiry', vendor_produk, partner_log) if result_code:
raise JsonRpcError(message=result["f_result"]["message"])
if not invoice: if result["f_result"]["code"] == 0:
invoice = H2hArInvoice() prod.update(result["f_result"])
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: else:
prod.update(dict(status="FAILED", prod.update(dict(status="FAILED",
message=result["message"])) message=result["message"]))
r_data.append(prod) r_data.append(prod)
data = is_list and r_data or r_data[0] data = is_list and r_data or r_data[0]
return data return data
...@@ -238,9 +159,6 @@ def build_purchase(vendor_produk, partner_log=None): ...@@ -238,9 +159,6 @@ def build_purchase(vendor_produk, partner_log=None):
return build_request('payment', vendor_produk, partner_log) return build_request('payment', vendor_produk, partner_log)
from ..tools import JsonRpcInvoiceFoundError
@jsonrpc_method(method='purchase', endpoint='api-merchant') @jsonrpc_method(method='purchase', endpoint='api-merchant')
def purchase(request, data, **kwargs): def purchase(request, data, **kwargs):
""" """
...@@ -257,7 +175,6 @@ def purchase(request, data, **kwargs): ...@@ -257,7 +175,6 @@ def purchase(request, data, **kwargs):
:return: :return:
{ {
product_nm:string, product_nm:string,
denom: string, denom: string,
id_pel:string id_pel:string
inv_no: string optional inv_no: string optional
...@@ -268,18 +185,15 @@ def purchase(request, data, **kwargs): ...@@ -268,18 +185,15 @@ def purchase(request, data, **kwargs):
total:integer, total:integer,
status:success/pending/failed status:success/pending/failed
""" """
user = auth_from_rpc(request) user = auth_from_rpc(request)
i = 0 i = 0
if not data: if not data:
raise JsonRpcParameterNotFound raise JsonRpcParameterNotFound
is_list = type(data) == list is_list = type(data) == list
data = is_list and data or [data] data = is_list and data or [data]
customer = Partner.query_user(user).first() customer = Partner.query_user(user).first()
if not customer: if not customer:
raise JsonRpcCustomerNotFoundError raise JsonRpcCustomerNotFoundError
r_data = [] r_data = []
log.info("%s Payment Request: %s" % (customer.kode, data)) log.info("%s Payment Request: %s" % (customer.kode, data))
for dat in data: for dat in data:
...@@ -306,10 +220,7 @@ def purchase(request, data, **kwargs): ...@@ -306,10 +220,7 @@ def purchase(request, data, **kwargs):
prod["status"] = "FAILED" prod["status"] = "FAILED"
prod["message"] = "Denom atau id pelanggan tidak diisi" prod["message"] = "Denom atau id pelanggan tidak diisi"
else: else:
# produk = Produk.query_kode(produk_kd).first()
# todo: search product lowest price
vendor_produk = get_vendor_produk(produk_kd) vendor_produk = get_vendor_produk(produk_kd)
if not vendor_produk: if not vendor_produk:
prod["status"] = "FAILED" prod["status"] = "FAILED"
prod["message"] = "Data tidak ditemukan" prod["message"] = "Data tidak ditemukan"
...@@ -323,23 +234,20 @@ def purchase(request, data, **kwargs): ...@@ -323,23 +234,20 @@ def purchase(request, data, **kwargs):
flush_row(ar_invoice_det) flush_row(ar_invoice_det)
result = build_purchase(vendor_produk, ar_invoice_det) result = build_purchase(vendor_produk, ar_invoice_det)
total = "total" in result and result["total"] or 0 total = "total" in result and result["total"] or 0
prod.update(result) prod.update(result["f_result"])
# Perhitungan Total # # Perhitungan Total
# Jika harga jual lebih besar dari harga beli jual dipakai harga jual # # 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 # # jika harga lebih kecil dari harga beli maka harga beli ditambah admin_fee
if total: # if total:
if vendor_produk.produk.harga < total: # if vendor_produk.produk.harga < total:
total += vendor_produk.produk.harga # total += vendor_produk.produk.harga
elif vendor_produk.produk.harga > total: # elif vendor_produk.produk.harga > total:
total = vendor_produk.produk.harga # total = vendor_produk.produk.harga
# prod.update(dict(total=total))
prod.update(dict(total=total))
r_prod.append(prod) r_prod.append(prod)
ar_invoice.payment["response"] = r_prod ar_invoice.payment["response"] = r_prod
dat["produk"] = r_prod dat["produk"] = r_prod
r_data.append(dat) r_data.append(dat)
data = is_list and r_data or r_data[0] data = is_list and r_data or r_data[0]
log.info("%s Payment Response: %s " % (customer.kode, data)) log.info("%s Payment Response: %s " % (customer.kode, data))
return data return data
...@@ -361,7 +269,6 @@ def advice(request, data): ...@@ -361,7 +269,6 @@ def advice(request, data):
:return: :return:
{ {
product_nm:string, product_nm:string,
denom: string, denom: string,
id_pel:string id_pel:string
inv_no: string optional inv_no: string optional
...@@ -372,7 +279,6 @@ def advice(request, data): ...@@ -372,7 +279,6 @@ def advice(request, data):
total:integer, total:integer,
status:success/pending/failed status:success/pending/failed
""" """
user = auth_from_rpc(request) user = auth_from_rpc(request)
i = 0 i = 0
is_list = type(data) == list is_list = type(data) == list
...@@ -380,7 +286,6 @@ def advice(request, data): ...@@ -380,7 +286,6 @@ def advice(request, data):
customer = Partner.query_user(user).first() customer = Partner.query_user(user).first()
if not customer: if not customer:
raise JsonRpcCustomerNotFoundError raise JsonRpcCustomerNotFoundError
r_data = [] r_data = []
for dat in data: for dat in data:
if "invoice_no" not in dat: if "invoice_no" not in dat:
...@@ -400,9 +305,9 @@ def advice(request, data): ...@@ -400,9 +305,9 @@ def advice(request, data):
if "produk" in dat: if "produk" in dat:
prods = [] prods = []
for p in dat["produk"]: for p in dat["produk"]:
row = qry.join(Produk, Produk.id==H2hArInvoiceDet.produk_id)\ row = qry.join(Produk, Produk.id == H2hArInvoiceDet.produk_id) \
.filter(Produk.kode==p["denom"], .filter(Produk.kode == p["denom"],
H2hArInvoiceDet.id_pel==p["id_pel"]).first() H2hArInvoiceDet.id_pel == p["id_pel"]).first()
if not row: if not row:
status = "FAILED" status = "FAILED"
message = "Produk tidak ada" message = "Produk tidak ada"
...@@ -423,10 +328,8 @@ def advice(request, data): ...@@ -423,10 +328,8 @@ def advice(request, data):
for p in qry.all(): for p in qry.all():
produk = Produk.query(). \ produk = Produk.query(). \
filter(Produk.id == p.produk_id).first() filter(Produk.id == p.produk_id).first()
status = p.status == -1 and 'PENDING' or p.status == 1 and 'SUCCESS' \ status = p.status == -1 and 'PENDING' or p.status == 1 and 'SUCCESS' \
or p.status == -2 and 'PENDING' or "FAILED" or p.status == -2 and 'PENDING' or "FAILED"
r_prod.append(dict(denom=produk.kode, r_prod.append(dict(denom=produk.kode,
id_pel=p.id_pel, id_pel=p.id_pel,
subtotal=(p.amt_sell or 0) + (p.discount or 0), subtotal=(p.amt_sell or 0) + (p.discount or 0),
...@@ -435,14 +338,11 @@ def advice(request, data): ...@@ -435,14 +338,11 @@ def advice(request, data):
status=status, status=status,
serial_number=p.serial_number or "", ) serial_number=p.serial_number or "", )
) )
dat["produk"] = r_prod dat["produk"] = r_prod
r_data.append(dat) r_data.append(dat)
i += 1 i += 1
data = is_list and r_data or r_data[0] data = is_list and r_data or r_data[0]
return data return data
# #
# @jsonrpc_method(method='payment', endpoint='api-merchant') # @jsonrpc_method(method='payment', endpoint='api-merchant')
# def payment(request, token, data): # def payment(request, token, data):
...@@ -604,38 +504,3 @@ def advice(request, data): ...@@ -604,38 +504,3 @@ 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
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
import json import json
import base64
import logging
# Import Library (Mandatory) # Import Library (Mandatory)
from datetime import datetime, timedelta from datetime import datetime, timedelta
...@@ -7,161 +9,200 @@ from opensipkd.base import get_settings ...@@ -7,161 +9,200 @@ from opensipkd.base import get_settings
from opensipkd.base.models import Partner from opensipkd.base.models import Partner
from . import Nicepay from . import Nicepay
from ..vendor import VendorClass from ..vendor import VendorClass
import logging
import urllib3
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
urllib3.disable_warnings() # setMandatoryParameter
class Vendor(VendorClass): class Vendor(VendorClass): #VendorClass
def __init__(self, vendor_produk, invoice_det, **kwargs): # def __init__(self, vendor_produk, **kwargs):
VendorClass.__init__(self, vendor_produk, invoice_det, **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',
# )
#
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
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.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: customer = self.invoice_det.customer
self.cust_kd = self.row_customer.kode if customer:
self.cust_inv_no = self.row_invoice.cust_inv_no self.cust_kd = customer.kode
self.agra_cust_inv_no = self.cust_kd and self.cust_inv_no \ # self.cust_inv_no = self.cust_kd + self.invoice_det.cust_inv_no
and self.cust_kd + self.cust_inv_no or None self.cust_inv_no = self.invoice_det.cust_inv_no
self.mid = 'np_mid' in self.settings and self.settings['np_mid'] or None # self.cust_trx = 'REFERENCENO'
self.key = 'np_key' in self.settings and self.settings['np_key'] or None # self.pay_method = '01'
self.url = 'np_url' in self.settings and self.settings['np_url'] or None
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.bank_cd, self.pay_method = self.v_produk_kd.split('-') self.bank_cd, self.pay_method = self.v_produk_kd.split('-')
self.va_typ = "float" self.va_typ = None
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.invoice_det.amt_sell)
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" # self.ip = Nicepay.userIp()
def request_payment(self, response): def request_payment(self, response):
Nicepay.requestData={} Nicepay.requestData={}
Nicepay.set('timeStamp', self.time_stamp) Nicepay.set('timeStamp', self.invoice_det.time_stamp)
# Nicepay.set('referenceNo', self.time_stamp) #'20180109181300' Nicepay.set('referenceNo', self.cust_inv_no)
Nicepay.set('referenceNo', self.agra_cust_inv_no) Nicepay.set('tXid', response["tXid"])
Nicepay.set('tXid', response["tXid"]) # 'IONPAYTEST02201802051512483907'get tXid from register first Nicepay.set('cardNo', self.invoice_det.card_no)
# Nicepay.set('cardNo', self.values["card_no"]) #'5409120028181901' Nicepay.set('cardExpYymm', self.invoice_det.card_exp) # format Yymm '2012'
# Nicepay.set('cardExpYymm', self.values["card_exp"]) # format Yymm '2012' Nicepay.set('cardCvv', self.invoice_det.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.cust_inv_no:
return return
Nicepay.set('timeStamp', self.time_stamp) Nicepay.set('timeStamp', self.invoice_det.inv_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')
Nicepay.set('amt', self.amt) # Nicepay.set('amt', self.amt)
Nicepay.set('referenceNo', self.agra_cust_inv_no) Nicepay.set('referenceNo', self.cust_inv_no)
Nicepay.set('userIP', self.ip) Nicepay.set('userIP', self.invoice_det.inv_cust_ip)
Nicepay.set('dbProcessUrl', self.url) Nicepay.set('dbProcessUrl', self.notify_url)
# Nicepay.set('merchantKey', self.key)
Nicepay.merchantKey = self.key
Nicepay.set('merchantToken', Nicepay.merchantToken()) 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 return True
def set_billing_param(self): def set_billing_param(self):
if not self.customer: if not self.invoice_det:
return return
Nicepay.set('goodsNm', self.customer['barang']) Nicepay.set('goodsNm', self.invoice_det.notes)
Nicepay.set('billingNm', self.customer['nama']) Nicepay.set('billingNm', self.invoice_det.inv_cust_nm)
Nicepay.set('billingPhone', self.customer['phone']) Nicepay.set('billingPhone', self.invoice_det.inv_cust_phone)
Nicepay.set('billingEmail', self.customer['email']) Nicepay.set('billingEmail', self.invoice_det.inv_cust_email)
Nicepay.set('billingCity', self.customer['kota']) Nicepay.set('billingCity', self.invoice_det.inv_cust_city)
Nicepay.set('billingState', self.customer['provinsi']) Nicepay.set('billingState', self.invoice_det.inv_cust_state)
Nicepay.set('billingPostCd', self.customer['kd_pos']) Nicepay.set('billingPostCd', self.invoice_det.inv_cust_pos)
Nicepay.set('billingCountry', self.customer['negara']) 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 return True
def set_optional_param(self): def set_optional_param(self):
pass # pass
# setOptionalParameter # setOptionalParameter
# Nicepay.set('billingAddr', 'Billing Address') Nicepay.set('deliveryNm', self.invoice_det.delivery_nm)
# Nicepay.set('deliveryNm', 'Buyer Name') Nicepay.set('deliveryPhone', self.invoice_det.delivery_phone)
# Nicepay.set('deliveryPhone', '02112345678') Nicepay.set('deliveryAddr', self.invoice_det.delivery_addr)
# Nicepay.set('deliveryAddr', 'Billing Address') Nicepay.set('deliveryCity', self.invoice_det.delivery_city)
# Nicepay.set('deliveryCity', 'Jakarta') Nicepay.set('deliveryState', self.invoice_det.delivery_state)
# Nicepay.set('deliveryState', 'Jakarta') Nicepay.set('deliveryPostCd', self.invoice_det.delivery_pos)
# Nicepay.set('deliveryPostCd', '12345') Nicepay.set('deliveryCountry', self.invoice_det.delivery_country)
# Nicepay.set('deliveryCountry', 'Indonesia') Nicepay.set('vat', str(self.invoice_det.vat))
# Nicepay.set('vat', '0') Nicepay.set('fee', str(self.invoice_det.fee))
# Nicepay.set('fee', '0') Nicepay.set('notaxAmt', str(self.invoice_det.notax_amt))
# Nicepay.set('notaxAmt', '0') Nicepay.set('reqDt', self.invoice_det.req_dt) # Format (YYYYMMDD)
# Nicepay.set('description', 'Description') Nicepay.set('reqTm', self.invoice_det.req_tm) # Format (HHiiss)\
# Nicepay.set('reqDt', '20160301') # Format (YYYYMMDD) Nicepay.set('reqClientVer', '')
# Nicepay.set('reqTm', '135959') # Format (HHiiss) Nicepay.set('recurrOpt', str(self.invoice_det.recurr_opt))
# Nicepay.set('reqDomain', 'merchant.com') Nicepay.set('instmntMon', self.invoice_det.instmnt_mon)
# Nicepay.set('reqServerIP', '127.0.0.1') Nicepay.set('instmntType', self.invoice_det.instmnt_type)
# Nicepay.set('reqClientVer', '1.0') Nicepay.set('mRefNo', self.invoice_det.m_ref_no)
# Nicepay.set('userSessionID', 'userSessionID') Nicepay.set('payValidDt', self.invoice_det.pay_valid_dt)
# Nicepay.set('userAgent', 'Mozilla') Nicepay.set('payValidTm', self.invoice_det.pay_valid_tm)
# Nicepay.set('userLanguage', 'en-US') Nicepay.set('tXid', self.invoice_det.tx_id)
Nicepay.set('transDt', self.invoice_det.trans_dt)
def inquiry(self): Nicepay.set('transTm', self.invoice_det.trans_tm)
# Nicepay.requestData = {}
self.request = Nicepay.requestData def register(self):
if not self.set_static_params() or not self.set_billing_param(): Nicepay.requestData = {}
if not self.set_billing_param() or not self.set_static_params():
return 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') # For Credit Card (Don't forgot change payMethod to '01')
if self.pay_method == '01': if self.pay_method == '01':
Nicepay.set('instmntType', '2') Nicepay.set('instmntType', self.invoice_det.instmnt_type)
Nicepay.set('instmntMon', '1') Nicepay.set('instmntMon', self.invoice_det.instmnt_mon)
if self.reccuring: # if self.reccuring:
# For Credit Card Reccuring Only # # For Credit Card Reccuring Only
Nicepay.set('recurrOpt', '0') Nicepay.set('recurrOpt', '2')
# For Virtual Account (Don't forgot change payMethod to '02') # For Virtual Account (Don't forgot change payMethod to '02')
elif self.pay_method == '02': elif self.pay_method == '02':
Nicepay.set('bankCd', self.bank_cd) Nicepay.set('bankCd', self.bank_cd)
Nicepay.set('vacctValidDt', self.valid_date) # Format (YYYYMMDD) # Nicepay.set('vacctValidDt', self.valid_date) # Format (YYYYMMDD)
Nicepay.set('vacctValidTm', self.valid_time) # Format (HHiiss) # Nicepay.set('vacctValidTm', self.valid_time) # Format (HHiiss)
if self.va_typ == "fixed": Nicepay.set('vacctValidDt', self.invoice_det.inv_valid_date)
# For Virtual Account Fix Account Nicepay.set('vacctValidTm', self.invoice_det.inv_valid_time)
Nicepay.set('merFixAcctId', '12345679') if self.invoice_det.inv_cust_va:
# length value of merFixAcctId setting By Mid. Contact self.va_typ = 'fixed'
# Nicepay IT for Information 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']: elif self.pay_method in ['03', '04', '05']:
# For CVS,ClickPay or E-Wallet # For CVS,ClickPay or E-Wallet
...@@ -169,8 +210,8 @@ class Vendor(VendorClass): ...@@ -169,8 +210,8 @@ class Vendor(VendorClass):
Nicepay.set('mitraCd', self.bank_cd) Nicepay.set('mitraCd', self.bank_cd)
if self.pay_method == '03': if self.pay_method == '03':
# For CVS Only # For CVS Only
Nicepay.set('payValidDt', self.valid_date) # Format (YYYYMMDD) Nicepay.set('payValidDt', self.invoice_det.inv_valid_date) # Format (YYYYMMDD)
Nicepay.set('payValidTm', self.valid_time) # Format (HHiiss) Nicepay.set('payValidTm', self.invoice_det.inv_valid_time) # Format (HHiiss)
elif self.pay_method == '04': elif self.pay_method == '04':
# For ClickPay Only # For ClickPay Only
...@@ -178,15 +219,12 @@ class Vendor(VendorClass): ...@@ -178,15 +219,12 @@ class Vendor(VendorClass):
self.set_optional_param() self.set_optional_param()
self.request = Nicepay.requestData self.request = Nicepay.requestData
log.info("REQUEST: {}".format(json.dumps(self.request)))
self.save_log('inquiry') self.save_log('inquiry')
result_data = Nicepay.niceRegister()
# result = {} response = json.loads(result_data)
resultData = Nicepay.niceRegister() self.response = response
response = json.loads(resultData) log.info("RESPONSE: {}".format(json.dumps(self.response)))
# Jika kartu kredit
if self.pay_method == '01':
payment = self.request_payment(response)
self.response = response self.response = response
# # Payment Response String Format # # Payment Response String Format
...@@ -197,50 +235,49 @@ class Vendor(VendorClass): ...@@ -197,50 +235,49 @@ class Vendor(VendorClass):
return return
else: else:
result = dict() result = dict()
#
if response['resultCd'] == '0000': result_code = int(response['resultCd'])
result["resultCd"]=response['resultCd'] result["code"] = result_code
result["resultMsg"]=response['resultMsg'] result["message"] = response['resultMsg']
result["tXid"]=response['tXid'] if result_code == 0:
result["referenceNo"]=response['referenceNo'] result["tx_id"] = response['tXid']
result["payMethod"]=response['payMethod'] result['trans_dt'] = response['transDt']
result["amount"]=response['amt'] result['trans_tm'] = response['transTm']
result["transDt"]=response['transDt'] # Jika kartu kredit
result["transTm"]=response['transTm'] # if self.pay_method == '01':
if response['goodsNm']: # # C-Card
result["goodsNm"]=response['goodsNm'] # # payment = self.request_payment(response)
if response['billingNm']: # elif response['payMethod'] == "02":
result["billingNm"]=response['billingNm'] if response['payMethod'] == "02":
if response['currency']: # VA
result["currency"]=response['currency'] result["vacct_no"]=response['vacctNo']
elif response['payMethod'] == "02": # result["vacct_valid_dt"]=response['vacctValidDt']
result["bankCd"]=response['bankCd'] # result["vacct_valid_tm"]=response['vacctValidTm']
result["vacctNo"]=response['vacctNo'] # result["mer_fix_acct_id"]=response['merFixAcctId']
result["vacctValidDt"]=response['vacctValidDt']
result["vacctValidTm"]=response['vacctValidTm']
elif response['payMethod'] == "03": elif response['payMethod'] == "03":
result["mitraCd"]=response['mitraCd'] # CVS
result["payNo"]=response['payNo'] result["pay_no"]=response['payNo']
result["vacctValidDt"]=response['payValidDt'] # result["pay_valid_dt"]=response['payValidDt']
result["vacctValidTm"]=response['payValidTm'] # result["pay_valid_tm"]=response['payValidTm']
elif result['payMethod'] == "04": elif result['payMethod'] == "04":
result["mitraCd"]=response['mitraCd'] # clickpay
result["receiptCode"]=response['receiptCode'] result["receipt_code"]=response['receiptCode']
elif result['payMethod'] == "05": elif result['payMethod'] == "05":
result["mitraCd"]=response['mitraCd'] # e-wallet
result["receiptCode"]='receiptCode' in response and response['receiptCode'] or '' result["receipt_code"]='receiptCode' in response and response['receiptCode'] or ''
else: elif result['payMethod'] == "06":
result["resultCd"]=response['resultCd'] # akulaku
result["resultMsg"]=response['resultMsg'] pass
self.result = response
self.save_log('inquiry')
# else:
# result["resultCd"]=response['resultCd']
# result["resultMsg"]=response['resultMsg']
self.result = result
# 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",
......
...@@ -55,10 +55,6 @@ class VendorClass(object): ...@@ -55,10 +55,6 @@ class VendorClass(object):
self.amt_sell = 0 self.amt_sell = 0
self.discount = 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"): 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 "No Response From Biller" message = message and message or "No Response From Biller"
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!