Commit a24b135b by Solo Group

pars odeo

1 parent 279c8cc7
......@@ -10,6 +10,7 @@ from datetime import datetime
from importlib import import_module
import colander
import requests
import xmltodict
from deform import widget, Form, ValidationFailure
from opensipkd.base.tools.api import JsonRpcParameterNotFound
......@@ -396,41 +397,79 @@ class VendorClass(object):
def payment(self):
pass
import hashlib
def sha256(hash_string):
return hashlib.sha256(hash_string.encode()).hexdigest()
def proses_odeo(request):
settings = get_settings()
data = json.loads('{a:1}')
mid = 'odeo_mid' in settings and settings["odeo_mid"] or None
key = 'odeo_key' in settings and settings["odeo_key"] or None
partner = Partner.query_kode("ODEO").first()
status = str(data["status"])
if status == "BROADCAST_NEW_PRICE":
signature = sha256("{mid}{key}{status}"\
.format(mid=mid, key=key, status=status))
if signature!=data["signature"]:
return
new_price = data["new_price"]
k, v = new_price
row = PartnerProduk.query().filter_by(kode=k, partner_id=partner.id).first()
if row:
row.harga = v
flush_row(row)
return
else:
order_id = str(data["order_id"])
signature = sha256("{order_id}{mid}{key}{status}"\
.format(order_id=order_id, mid=mid, key=key,
status=status))
if signature != data["signature"]:
return
order = PartnerLog.query()\
.filter(vendor_id=partner.id, vend_trx=str(order_id)).first()
if order:
if status == "COMPLETED":
order.status = 1
else:
order.status = -1
flush_row(order)
customer = Partner.query_id(order.customer_id).first()
if customer and customer.url:
users = customer.users
url = customer.url
c_data = dict(trx_id = order.cust_trx,
status = status,
signature = sha256(users.user_name+users.api_key))
with requests.session():
requests.post(url, data=c_data)
@view_config(route_name='api-vendor-notify', renderer='json')
def api_vendor_notify(request):
"""
:param request:
:return:
ODEO will notify to affiliate if item has been successfully purchased or
refunded.You can use any active url/IP you have to be registered, but ODEO
suggests you to use a secure HTTPS. Please use "signature" parameter to
validate any notification that come from ODEO. Compare the signature hash
by generate the same hash by this following
format:
sha256({order_id} + {MID} + {SECRET_KEY} + {status}) [COMPLETED/REFUNDED]
sha256({MID} + {SECRET_KEY} + {status}) [BROADCAST_NEW_PRICE]
Also from "message" parameter, you can get data such as newest price of the
product, and your current balance. Please refer to our apps to see all of
message examples you can get from notify.Responded Status
status reason
COMPLETED item has successfully purchased
REFUNDED purchase canceled, refunded to oCash balance
BROADCAST_NEW_PRICE there is new price for specific item
"""
vendor_nm = request.matchdict['name']
partner = Partner.query_kode(vendor_nm).first()
if partner:
row = PartnerLog()
if vendor_nm=='odeoo':
env = request.environ
if not 'HTTP_SIGNATURE' in env:
return JsonRpcParameterNotFound(message='SIGNATURE not found')
row.log=env['HTTP_SIGNATURE']
row.partner_id = partner.id
flush_row(row)
if vendor_nm == "odeo":
proses_odeo(request)
# if partner:
# row = PartnerLog()
#
# if vendor_nm=='vsi':
# env = request.environ
# if not 'HTTP_SIGNATURE' in env:
# return JsonRpcParameterNotFound(message='SIGNATURE not found')
#
# row.log=env['HTTP_SIGNATURE']
# row.partner_id = partner.id
# flush_row(row)
# from pyramid_xmlrpc import XMLRPCView, xmlrpc_response
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!