Commit 3f5ca6d8 by Tatang

np

1 parent 533f0000
...@@ -22,21 +22,21 @@ def build_request(typ, vendor_produk, partner_log=None): ...@@ -22,21 +22,21 @@ def build_request(typ, vendor_produk, partner_log=None):
pckgs = 'agratek.api.merchant.views' pckgs = 'agratek.api.merchant.views'
moduls = vendor_produk.modules.split('.') moduls = vendor_produk.modules.split('.')
if len(moduls)>1: if len(moduls) > 1:
pckg = ".".join(moduls[:-1]) pckg = ".".join(moduls[:-1])
pckgs = ".".join([pckgs, pckg]) pckgs = ".".join([pckgs, pckg])
moduls = moduls[-1:] moduls = moduls[-1:]
modul = moduls[0] modul = moduls[0]
log.info("Module: %s Pckgs: %s" %(modul, pckgs)) log.info("Module: %s Pckgs: %s" % (modul, pckgs))
modul = '.' + modul modul = '.' + modul
modules = import_module(modul, pckgs) modules = import_module(modul, pckgs)
cls_module = modules.Vendor(vendor_produk, partner_log) cls_module = modules.Vendor(vendor_produk, partner_log)
cls = hasattr(cls_module, typ) and getattr(cls_module, typ) or None cls = hasattr(cls_module, typ) and getattr(cls_module, typ) or None
if cls: if cls:
result = cls() result = cls()
#log.info("Build Req: mod %s rslt: %s" % (vendor_produk.modules, data)) # log.info("Build Req: mod %s rslt: %s" % (vendor_produk.modules, data))
log.info("Request %s" % cls_module.request) log.info("Request %s" % cls_module.request)
log.info("Response %s" % cls_module.response) log.info("Response %s" % cls_module.response)
log.info("Result %s" % cls_module.result) log.info("Result %s" % cls_module.result)
...@@ -52,6 +52,7 @@ def build_request(typ, vendor_produk, partner_log=None): ...@@ -52,6 +52,7 @@ def build_request(typ, vendor_produk, partner_log=None):
code=9999) code=9999)
result = {"f_result": data} result = {"f_result": data}
# dict(data=) # dict(data=)
return result return result
...@@ -66,12 +67,13 @@ def get_vendor_produk(produk_kd, vendor_kd=None, harga=None): ...@@ -66,12 +67,13 @@ def get_vendor_produk(produk_kd, vendor_kd=None, harga=None):
Fungsi ini digunakan untuk mencari vendor yang paling murah Fungsi ini digunakan untuk mencari vendor yang paling murah
:param produk_kd: String Kode Produk :param produk_kd: String Kode Produk
:param level: Digunakan sebagai parameter jika yang paling murah tidak ditemukan :param level: Digunakan sebagai parameter jika yang paling murah tidak ditemukan
:vendor_kd: Kode Vendor :param vendor_kd: Kode Vendor
:param harga: harga produk
:return: row objek dari Partner Produk :return: row objek dari Partner Produk
""" """
### Jika parameter level tidak disebutkan ### Jika parameter level tidak disebutkan
settings = get_settings() # settings = get_settings()
qry = qry_vendor_produk() qry = qry_vendor_produk()
if vendor_kd: if vendor_kd:
log.info(vendor_kd) log.info(vendor_kd)
...@@ -79,20 +81,21 @@ def get_vendor_produk(produk_kd, vendor_kd=None, harga=None): ...@@ -79,20 +81,21 @@ def get_vendor_produk(produk_kd, vendor_kd=None, harga=None):
.filter(Partner.kode == vendor_kd) \ .filter(Partner.kode == vendor_kd) \
.filter(Produk.kode == produk_kd).first() .filter(Produk.kode == produk_kd).first()
if is_devel(): # if is_devel():
settings = get_settings() # settings = get_settings()
vend_kd = 'dev_vend_kd' in settings and settings ['dev_vend_kd'] or 'test' # vend_kd = 'dev_vend_kd' in settings and settings ['dev_vend_kd'] or 'test'
log.info(vend_kd) # log.info(vend_kd)
return qry \ # return qry \
.filter(Partner.kode == vend_kd) \ # .filter(Partner.kode == vend_kd) \
.filter(Produk.kode == produk_kd).first() # .filter(Produk.kode == produk_kd).first()
else: # else:
result = qry \ result = qry \
.filter(Produk.kode == produk_kd).order_by(PartnerProduk.harga) .filter(Produk.kode == produk_kd).order_by(PartnerProduk.harga)
row = result.filter(PartnerProduk.harga > harga).first() # row = result.filter(PartnerProduk.harga > harga).first()
if not row: row = result.first()
harga = 0 # if not row:
row = result.filter(PartnerProduk.harga > harga).first() # harga = 0
# row = result.filter(PartnerProduk.harga > harga).first()
return row return row
...@@ -153,7 +156,14 @@ def inquiry(request, data, **kwargs): ...@@ -153,7 +156,14 @@ def inquiry(request, data, **kwargs):
raise JsonRpcCustomerNotFoundError() raise JsonRpcCustomerNotFoundError()
r_data = [] r_data = []
for prod in data:
for dat in data:
cust_inv_no = 'invoice_no' in data and dat['invoice_no'] or None
invoice = H2hArInvoice.query_invoice(cust_inv_no).first()
produks = 'produk' in dat and dat['produk'] or []
for prod in produks:
# prods = "produk" in dat and dat["produk"] or None # prods = "produk" in dat and dat["produk"] or None
# for prod in prods: # for prod in prods:
# log.info(prod) # log.info(prod)
...@@ -165,15 +175,33 @@ def inquiry(request, data, **kwargs): ...@@ -165,15 +175,33 @@ def inquiry(request, data, **kwargs):
if not vendor_produk: if not vendor_produk:
raise JsonRpcProdukNotFoundError(message="Produk %s tidak ditemukan" % produk_kd) raise JsonRpcProdukNotFoundError(message="Produk %s tidak ditemukan" % produk_kd)
partner_log = PartnerLog() # diremark by tatang
partner_log.vendor_id = vendor_produk.partner_id # partner_log = PartnerLog()
partner_log.customer_id = customer.id # partner_log.vendor_id = vendor_produk.partner_id
partner_log.produk_id = vendor_produk.produk.id # partner_log.customer_id = customer.id
# partner_log.cust_inv = dat["inv_no"] # partner_log.produk_id = vendor_produk.produk.id
partner_log.id_pel = prod["id_pel"] # # partner_log.cust_inv = dat["inv_no"]
# partner_log.id_pel = prod["id_pel"]
# flush_row(partner_log)
# result = build_request('inquiry', vendor_produk, partner_log)
if not invoice:
invoice = H2hArInvoice()
invoice.customer_id = customer.id
invoice.cust_inv_type = 2
invoice.cust_inv_no = cust_inv_no
flush_row(invoice)
invoice_det = H2hArInvoiceDet()
invoice_det.vendor_id = vendor_produk.partner_id
invoice_det.ar_invoice_id = invoice.id
invoice_det.produk_id = vendor_produk.produk.id
invoice_det.vendor_id = vendor_produk.partner_id
invoice_det.id_pel = prod['id_pel']
flush_row(invoice_det)
result = build_request('inquiry', vendor_produk, invoice_det)
flush_row(partner_log)
result = build_request('inquiry', vendor_produk, partner_log)
if result["code"] == 0: if result["code"] == 0:
prod.update(result) prod.update(result)
...@@ -260,7 +288,6 @@ def purchase(request, data, **kwargs): ...@@ -260,7 +288,6 @@ def purchase(request, data, **kwargs):
ar_invoice = H2hArInvoice() ar_invoice = H2hArInvoice()
ar_invoice.customer_id = customer.id ar_invoice.customer_id = customer.id
ar_invoice.cust_inv_no = inv_no ar_invoice.cust_inv_no = inv_no
ar_invoice.cust_inv_no = inv_no
ar_invoice.payment = dict(request=dat) ar_invoice.payment = dict(request=dat)
flush_row(ar_invoice) flush_row(ar_invoice)
r_prod = [] r_prod = []
...@@ -569,3 +596,38 @@ def advice(request, data): ...@@ -569,3 +596,38 @@ def advice(request, data):
# data[i]=r_data # data[i]=r_data
# i += 1 # i += 1
# return data # return data
"""
bikin method baru sesuai nicepay
- registration
- payment
"""
"""
"referenceNo":"ORD12345",
"goodsNm":"Test Transaction Nicepay",
"billingNm":"Customer Name",
"billingPhone":"12345678",
"billingEmail":"email@merchant.com",
"billingAddr":"Jalan Bukit Berbunga 22",
"billingCity":"Jakarta",
"billingState":"DKI Jakarta",
"billingPostCd":"12345",
"billingCountry":"Indonesia",
"deliveryNm":"email@merchant.com",
"deliveryPhone":"12345678",
"deliveryAddr":"Jalan Bukit Berbunga 22",
"deliveryCity":"Jakarta",
"deliveryState":"DKI Jakarta",
"deliveryPostCd":"12345",
"deliveryCountry":"Indonesia",
"description":"Transaction Description",
"dbProcessUrl":"http://ptsv2.com/t/0ftrz-1519971382/post",
"reqDomain":"merchant.com",
"cartData":"{}",
"vacctValidDt":"20180306",
"vacctValidTm":"091309",
"merFixAcctId":""
"""
\ No newline at end of file \ No newline at end of file
...@@ -8,46 +8,50 @@ from opensipkd.base.models import Partner ...@@ -8,46 +8,50 @@ from opensipkd.base.models import Partner
from . import Nicepay from . import Nicepay
from ..vendor import VendorClass
# setMandatoryParameter import logging
import urllib3
log = logging.getLogger(__name__)
urllib3.disable_warnings()
class Vendor(object): #VendorClass
def __init__(self, vendor_produk, **kwargs):
# VendorClass.__init__(self, vendor_produk, bill_no, **kwargs)
if not vendor_produk or kwargs is None or not "values" in kwargs:
return
args = kwargs class Vendor(VendorClass):
self.values = args["values"] def __init__(self, vendor_produk, invoice_det, **kwargs):
VendorClass.__init__(self, vendor_produk, invoice_det, **kwargs)
self.v_produk_kd = vendor_produk.kode self.v_produk_kd = vendor_produk.kode
customer = Partner.query_id(self.values["customer_id"]).first() self.cust_kd = None
if customer: self.cust_inv_no = None
self.cust_kd = customer.kode self.agra_cust_inv_no = None
self.cust_inv_no = "cust_inv_no" in self.values \
and self.values["cust_inv_no"] or None if self.row_customer and self.row_invoice:
self.cust_kd = self.row_customer.kode
self.cust_inv_no = self.row_invoice.cust_inv_no
self.agra_cust_inv_no = self.cust_kd and self.cust_inv_no \ self.agra_cust_inv_no = self.cust_kd and self.cust_inv_no \
and self.cust_kd + self.cust_inv_no or None and self.cust_kd + self.cust_inv_no or None
settings = get_settings()
self.mid = 'np_mid' in settings and settings['np_mid'] or None self.mid = 'np_mid' in self.settings and self.settings['np_mid'] or None
self.key = 'np_key' in settings and settings['np_key'] or None self.key = 'np_key' in self.settings and self.settings['np_key'] or None
self.url = 'np_url' in settings and settings['np_url'] or None self.url = 'np_url' in self.settings and self.settings['np_url'] or None
Nicepay.merchantKey = self.key Nicepay.merchantKey = self.key
Nicepay.iMid = self.mid Nicepay.iMid = self.mid
self.ip = Nicepay.userIp() self.ip = Nicepay.userIp()
self.customer = dict( self.customer = dict(
barang='GOODSNM', barang=invoice_det.produk.nama, # 'GOODSNM',
nama='BILLING NAME', nama=self.row_customer.nama, # 'BILLING NAME',
phone='08123456789', phone=self.row_customer.phone, # '08123456789',
email='ADETEST01@GMAIL.COM', email=self.row_customer.email, # 'ADETEST01@GMAIL.COM',
kota='JAKARTA', kota=self.row_customer.kota, # 'JAKARTA',
provinsi='JAKARTA', provinsi=self.row_customer.provinsi, # 'JAKARTA',
kd_pos='14350', kd_pos=None, # '14350',
negara='INDONESIA', negara='INDONESIA',
) )
# self.cust_trx = 'REFERENCENO'
# self.pay_method = '01'
self.url = 'https://www.merchant.com/Notification' self.url = 'https://www.merchant.com/Notification'
self.bank_cd, self.pay_method = self.v_produk_kd.split('-') self.bank_cd, self.pay_method = self.v_produk_kd.split('-')
...@@ -55,38 +59,38 @@ class Vendor(object): #VendorClass ...@@ -55,38 +59,38 @@ class Vendor(object): #VendorClass
self.notify_url = "dev.agratek.co.id/api/np/notify" self.notify_url = "dev.agratek.co.id/api/np/notify"
self.callback_url = "dev.agratek.co.id/api/np/calllback" self.callback_url = "dev.agratek.co.id/api/np/calllback"
self.reccuring = False self.reccuring = False
self.amt = str(self.values["amount"]) # self.amt = str(self.values["amount"])
self.amt = '0'
now = datetime.now() now = datetime.now()
self.time_stamp = now.strftime("%Y%m%d%H%M%S") self.time_stamp = now.strftime("%Y%m%d%H%M%S")
tommorow = now + timedelta(days=1) tommorow = now + timedelta(days=1)
self.valid_date = tommorow.strftime("%Y%m%d") self.valid_date = tommorow.strftime("%Y%m%d")
self.valid_time = "235500" self.valid_time = "235500"
def request_payment(self, response): def request_payment(self, response):
Nicepay.requestData={} Nicepay.requestData={}
Nicepay.set('timeStamp', self.time_stamp) Nicepay.set('timeStamp', self.time_stamp)
# '20180109181300' # Nicepay.set('referenceNo', self.time_stamp) #'20180109181300'
# Nicepay.set('reffenceNo', self.time_stamp) #'20180109181300'
Nicepay.set('referenceNo', self.agra_cust_inv_no) Nicepay.set('referenceNo', self.agra_cust_inv_no)
#'5a44213129be40320ef1a4b57095bfa61cd3ff0436bc442a9d82232e62203f37')
Nicepay.set('tXid', response["tXid"]) # 'IONPAYTEST02201802051512483907'get tXid from register first Nicepay.set('tXid', response["tXid"]) # 'IONPAYTEST02201802051512483907'get tXid from register first
Nicepay.set('cardNo', self.values["card_no"]) #'5409120028181901' # Nicepay.set('cardNo', self.values["card_no"]) #'5409120028181901'
Nicepay.set('cardExpYymm', self.values["card_exp"]) # format Yymm '2012' # Nicepay.set('cardExpYymm', self.values["card_exp"]) # format Yymm '2012'
Nicepay.set('cardCvv', self.values["card_cvv"]) # Nicepay.set('cardCvv', self.values["card_cvv"])
Nicepay.set('recurringToken', '') Nicepay.set('recurringToken', '')
Nicepay.set('preauthToken', '') Nicepay.set('preauthToken', '')
Nicepay.set('clickPayNo', '') Nicepay.set('clickPayNo', '')
Nicepay.set('dataField3', '') Nicepay.set('dataField3', '')
Nicepay.set('clickPayToken', '') Nicepay.set('clickPayToken', '')
Nicepay.set('callBackUrl', self.callback_url) Nicepay.set('callBackUrl', self.callback_url)
result = Nicepay.nicePayment() result = Nicepay.nicePayment()
return result return result
def set_static_params(self): def set_static_params(self):
if not self.agra_cust_inv_no: if not self.agra_cust_inv_no:
return return
Nicepay.set('timeStamp', self.time_stamp) # Nicepay.set('timeStamp', self.time_stamp)
Nicepay.set('iMid', self.mid) Nicepay.set('iMid', self.mid)
Nicepay.set('payMethod', self.pay_method) Nicepay.set('payMethod', self.pay_method)
Nicepay.set('currency', 'IDR') Nicepay.set('currency', 'IDR')
...@@ -134,9 +138,9 @@ class Vendor(object): #VendorClass ...@@ -134,9 +138,9 @@ class Vendor(object): #VendorClass
# Nicepay.set('userAgent', 'Mozilla') # Nicepay.set('userAgent', 'Mozilla')
# Nicepay.set('userLanguage', 'en-US') # Nicepay.set('userLanguage', 'en-US')
def inquiry(self): def inquiry(self):
Nicepay.requestData = {} # Nicepay.requestData = {}
self.request = Nicepay.requestData
if not self.set_static_params() or not self.set_billing_param(): if not self.set_static_params() or not self.set_billing_param():
return return
Nicepay.set('cartData', '{}') Nicepay.set('cartData', '{}')
...@@ -144,7 +148,7 @@ class Vendor(object): #VendorClass ...@@ -144,7 +148,7 @@ class Vendor(object): #VendorClass
if self.pay_method == '01': if self.pay_method == '01':
Nicepay.set('instmntType', '2') Nicepay.set('instmntType', '2')
Nicepay.set('instmntMon', '1') Nicepay.set('instmntMon', '1')
if (self.reccuring): if self.reccuring:
# For Credit Card Reccuring Only # For Credit Card Reccuring Only
Nicepay.set('recurrOpt', '0') Nicepay.set('recurrOpt', '0')
...@@ -174,7 +178,7 @@ class Vendor(object): #VendorClass ...@@ -174,7 +178,7 @@ class Vendor(object): #VendorClass
self.set_optional_param() self.set_optional_param()
self.request = Nicepay.requestData self.request = Nicepay.requestData
# self.save_log('inquiry') self.save_log('inquiry')
# result = {} # result = {}
resultData = Nicepay.niceRegister() resultData = Nicepay.niceRegister()
...@@ -229,11 +233,14 @@ class Vendor(object): #VendorClass ...@@ -229,11 +233,14 @@ class Vendor(object): #VendorClass
result["resultCd"]=response['resultCd'] result["resultCd"]=response['resultCd']
result["resultMsg"]=response['resultMsg'] result["resultMsg"]=response['resultMsg']
self.result = response self.result = response
# self.save_log('inquiry') self.save_log('inquiry')
return dict(data=result) return dict(data=result)
# https://api.nicepay.co.id/nicepay/direct/v2/registration # https://api.nicepay.co.id/nicepay/direct/v2/registration
# Request Body # Request Body
""" """
{ {
"deliveryPhone": "62-21-0000-0000", "deliveryPhone": "62-21-0000-0000",
......
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
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
….
}
"""
...@@ -37,6 +37,7 @@ class VendorClass(object): ...@@ -37,6 +37,7 @@ class VendorClass(object):
:param cust_trx: :param cust_trx:
:param row: :param row:
""" """
self.settings = get_settings()
self.vendor_produk = vendor_produk self.vendor_produk = vendor_produk
self.invoice_det = invoice_det self.invoice_det = invoice_det
self.v_produk_kd = vendor_produk.kode self.v_produk_kd = vendor_produk.kode
...@@ -52,6 +53,10 @@ class VendorClass(object): ...@@ -52,6 +53,10 @@ class VendorClass(object):
and invoice_det.serial_number or None and invoice_det.serial_number or None
self.amt_buy = 0 self.amt_buy = 0
# tambahan by tatang
self.row_invoice = invoice_det and invoice_det.h2h_ar_invoice or None
self.row_customer = self.row_invoice and self.row_invoice.customer or None
def set_response(self, data=None, message=None, code=999, typ="inquiry"): def set_response(self, data=None, message=None, code=999, typ="inquiry"):
if not data and message: if not data and message:
message = message and message or "Biller No Response" message = message and message or "Biller No Response"
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!