def set_default(user_id):
try:
if not request.data:
raise DataValidationError('Invalid request: body of request contained no data')
if not request.is_json:
raise DataValidationError('Invalid request: request not json')
data = request.get_json()
if data['payment_id']:
resp = payment_service.perform_payment_action(user_id,payment_attributes=data)
if resp == True:
message = { 'success' : 'Payment with id: %s set as default for user with user_id: %s.' % (data['payment_id'], str(user_id)) }
rc = status.HTTP_200_OK
else:
message = { 'error' : 'No Payment with id: %s was found for user with user_id: %s.' % (data['payment_id'], str(user_id)) }
rc = status.HTTP_404_NOT_FOUND
except DataValidationError as e:
message = {'error' : e.message}
rc = status.HTTP_400_BAD_REQUEST
except KeyError as e:
message = {'error' : 'Invalid request: body of request does not have the payment_id'}
rc = status.HTTP_400_BAD_REQUEST
return make_response(jsonify(message), rc)
######################################################################
# RETRIEVE A PAYMENT
######################################################################
评论列表
文章目录