[ADD] connector_signifyd: Automate fraud detection on orders with the Signifyd API.

This commit is contained in:
Brett Spaulding
2020-11-18 22:11:04 -05:00
parent 4ac984c852
commit 05574fc1fb
19 changed files with 877 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
import json
from odoo.http import Controller, request, route
from odoo.http import Response
class SignifydWebhooks(Controller):
@route(['/cases/creation'], type='json', auth='public', methods=['POST'], csrf=False)
def case_creation(self, *args, **post):
data = json.loads(request.httprequest.data)
vals = request.env['signifyd.connector'].process_post_values(data)
# Update case with info
case = request.env['signifyd.case'].sudo().search([('case_id', '=', vals['case_id'])])
if case:
case.sudo().update_case_info(vals)
# Request guarantee for case if eligible
try:
case.request_guarantee()
if case.guarantee_requested and not case.guarantee_eligible:
# Only alert Signifyd to stop trying if we have at least tried once already
return Response({'response': 'success'}, status=200, mimetype='application/json')
except:
# Signifyd API will try again up to 15 times if a non-2** code is returned
return Response({'response': 'failed'}, status=500, mimetype='application/json')
@route(['/cases/update'], type='json', auth='public', methods=['POST'], csrf=False)
def case_update(self, *args, **post):
data = json.loads(request.httprequest.data)
vals = request.env['signifyd.connector'].process_post_values(data)
case = request.env['signifyd.case'].sudo().search([('case_id', '=', vals['case_id'])])
if case:
case.update_case_info(vals)
outcome = vals.get('guarantee_disposition')
if case and outcome == 'DECLINED':
for user in request.env.company.signifyd_connector_id.notify_user_ids:
case.sudo().create_notification(user, outcome)