Exemple #1
0
def create(tastypie, payload, request):
    try:
        print(payload.copy())
        _validate_transaction_payload(payload.copy())
        token = get_request_token(request)
        transaction_type = payload.get('type')
        if transaction_type in AGENT_TRANSACTIONS:
            print('hhhhhhhh') # print de test à enlever
            transaction = _create_agent_transaction(payload, token)
        else:
            transaction = _create_wallet_transaction(payload, token)

        insert_operation(transaction)
        _ = _addtitional_transactions_informations(transaction, payload)
        _response = _add_agent_informations(transaction, _)
        response = _add_payer_informations(transaction, _response)
        print (response)
        print('hhhhhhhh')  # print de test à enlever
        save_transaction_response_payload(transaction, response)
        print('hhhhhhhh') # print de test à enlever
        return tastypie.create_response(request, response)
    except ValidationError as err:
        print(err)
        return tastypie.create_response(request, {'response_text': str(err), 'response_code': '100'}, HttpUnauthorized)
    except CoreException as err:
        return tastypie.create_response(request, err.errors, HttpForbidden)
Exemple #2
0
def get_agent_transactions_historique(tastypie, request):
    try:
        agent_code = decode_jwt_token(get_request_token(request), 'agent_api_secret_key')
        agent = AgentRepository.fetch_by_code(agent_code.get('code'))
        result = TransactionRepository.retreive_transactions_stat_by_type_giving_entity_agent(agent)

        return tastypie.create_response(request, result)
    except CoreException as err:
        return tastypie.create_response(request, err.errors, HttpForbidden)
Exemple #3
0
def search(tastypie, payload, request):
    try:
        _validate_search_transaction_by_code_payload(payload.copy())
        token = get_request_token(request)
        result = search_transaction_code(payload, token)
        return tastypie.create_response(request, result)
    except ValidationError as err:
        return tastypie.create_response(request, {'response_text': str(err.messages), 'response_code': '100'}, HttpUnauthorized)
    except CoreException as err:
        return tastypie.create_response(request, err.errors, HttpForbidden)
def otp_renew(tastypie, request):
    try:
        agent_code = decode_jwt_token(get_request_token(request), 'agent_api_secret_key')
        agent = AgentRepository.fetch_by_code(agent_code.get('code'))
        otp = generate_totp()
        sms_task.run(agent.phone_number, otp)

        return tastypie.create_response(request, {'response_text': 'OK', 'response_code': '000'})
    except Exception:
        return tastypie.create_response(request, {'response_text': 'Unable to renew OTP', 'response_code': '100'}, HttpForbidden)
Exemple #5
0
def get_entity_financial_situation(tastypie, request):
    try:
        agent_code = decode_jwt_token(get_request_token(request), 'agent_api_secret_key')
        agent = AgentRepository.fetch_by_code(agent_code.get('code'))
        balance = get_entity_balance_by_agent(agent)
        commission = get_entity_commission(agent.entity)

        result = {'balance': balance, 'commission': commission, 'response_code': '000'}

        return tastypie.create_response(request, result)
    except CoreException as err:
        return tastypie.create_response(request, err.errors, HttpForbidden)
Exemple #6
0
def pay(tastypie, payload, request):
    try:
        _validate_transaction_payload(payload.copy())
        token = get_request_token(request)
        transaction = _pay_transaction(payload, token)
        response = get_parent_transaction_payload(transaction)

        return tastypie.create_response(request, response)
    except ValidationError as err:
        return tastypie.create_response(request, {'response_text': str(err.messages), 'response_code': '100'}, HttpUnauthorized)
    except CoreException as err:
        return tastypie.create_response(request, err.errors, HttpForbidden)
def create_customer_with_card(tastypie, payload, request):
    try:
        payload.update({'type': 'ACTIVATION_CARTE'})
        _validate_transaction_payload(payload.copy())
        token = get_request_token(request)
        result = _create_customer_with_card(payload, token)
        return tastypie.create_response(request, result)
    except ValidationError as err:
        return tastypie.create_response(request, {
            'response_text': str(err),
            'response_code': '100'
        }, HttpUnauthorized)
    except CoreException as err:
        return tastypie.create_response(request, err.errors, HttpForbidden)