pass request everywhere it is needed

This commit is contained in:
Thomas Steen Rasmussen 2018-07-26 15:03:49 +02:00
parent 016ac8adac
commit 9517fb25ea

View file

@ -84,45 +84,46 @@ def coinify_api_request(api_method, order, **kwargs):
return req return req
def handle_coinify_api_response(req, order): def handle_coinify_api_response(apireq, order, request):
if req.method == 'invoice_create' or req.method == 'invoice_get': if apireq.method == 'invoice_create' or apireq.method == 'invoice_get':
# Parse api response # Parse api response
if req.response['success']: if apireq.response['success']:
# save this new coinify invoice to the DB # save this new coinify invoice to the DB
coinifyinvoice = process_coinify_invoice_json( coinifyinvoice = process_coinify_invoice_json(
invoicejson=req.response['data'], invoicejson=req.response['data'],
order=order, order=order,
request=request,
) )
return coinifyinvoice return coinifyinvoice
else: else:
api_error = req.response['error'] api_error = apireq.response['error']
logger.error("coinify API error: %s (%s)" % ( logger.error("coinify API error: %s (%s)" % (
api_error['message'], api_error['message'],
api_error['code'] api_error['code']
)) ))
return False return False
else: else:
logger.error("coinify api method not supported" % req.method) logger.error("coinify api method not supported" % apireq.method)
return False return False
################### API CALLS ################################################ ################### API CALLS ################################################
def get_coinify_invoice(coinify_invoiceid, order): def get_coinify_invoice(coinify_invoiceid, order, request):
# put args for API request together # put args for API request together
invoicedict = { invoicedict = {
'invoice_id': coinify_invoiceid 'invoice_id': coinify_invoiceid
} }
# perform the api request # perform the api request
req = coinify_api_request( apireq = coinify_api_request(
api_method='invoice_get', api_method='invoice_get',
order=order, order=order,
**invoicedict **invoicedict
) )
coinifyinvoice = handle_coinify_api_response(req, order) coinifyinvoice = handle_coinify_api_response(apireq, order, request)
return coinifyinvoice return coinifyinvoice
@ -140,12 +141,12 @@ def create_coinify_invoice(order, request):
} }
# perform the API request # perform the API request
req = coinify_api_request( apireq = coinify_api_request(
api_method='invoice_create', api_method='invoice_create',
order=order, order=order,
**invoicedict **invoicedict
) )
coinifyinvoice = handle_coinify_api_response(req, order) coinifyinvoice = handle_coinify_api_response(apireq, order, request)
return coinifyinvoice return coinifyinvoice