payments.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:payments 作者: devops-s17-payments 项目源码 文件源码
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
######################################################################
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号