def define_wallet_password(tastypie, data, request): phone_number = data['phone_number'] password = data['password'] otp = data['otp'] result = result = verify_totp( otp) # Il y a une redondance dans la declaration de la variable result if result is False: return tastypie.create_response(request, { 'response_text': 'wrong OTP', 'response_code': '100' }, HttpUnauthorized) try: customer = CustomerRepository.fetch_customer_by_phone_number( phone_number) customer.informations.set_password(password) customer.informations.save() customer.status = True customer.save() bundle = tastypie.build_bundle(obj=customer, request=request) bundle = tastypie.full_dehydrate(bundle) bundle.data.update({'response_code': '000'}) bundle.data.update( create_jwt_token_for(customer, 'wallet_api_secret_key')) return tastypie.create_response(request, bundle) except Exception: return tastypie.create_response(request, { 'response_text': 'unable to define password ', 'response_code': '100' }, HttpForbidden)
def _addtitional_customer_informations(payload): customer = CustomerRepository.fetch_customer_by_phone_number( payload.get('phone_number')) info = {'first_name': customer.informations.first_name, 'last_name': customer.informations.last_name} payload.update(info) return payload
def customer_beneficiaries(tastypie, phone_number, request): try: customer = CustomerRepository.fetch_customer_by_phone_number( phone_number) relations = customer.relations.all() beneficiaries = [] bundle = tastypie.build_bundle(obj=customer, request=request) bundle = tastypie.full_dehydrate(bundle) bundle.data.update({'response_code': '000'}) bundle.data.update({ 'customer': { 'first_name': customer.informations.first_name, 'last_name': customer.informations.last_name } }) for beneficiary in relations: data = { 'first_name': beneficiary.informations.first_name, 'last_name': beneficiary.informations.last_name, 'phone_number': beneficiary.informations.username, 'address': beneficiary.address } beneficiaries.append(data) bundle.data.update({'beneficiaries': beneficiaries}) return tastypie.create_response(request, bundle) except Exception as err: return tastypie.create_response(request, { 'response_text': 'no beneficiairies', 'response_code': '100' }, HttpForbidden)
def create_customer_with_wallet(tastypie, payload, request): try: data = payload.copy() data.update({'type': 'CREATION_WALLET'}) _validate_transaction_payload(data) CustomerRepository.fetch_or_create_customer(payload) payload.update({'response_code': '000'}) otp = generate_totp() sms_task.run(payload.get('phone_number'), otp) return tastypie.create_response(request, payload) 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)
def get_wallet_to_wallet_fee_payload(payload): data = {} destination_country = CustomerRepository.fetch_customer_by_phone_number( payload.get('destination_content_object').get( 'phone_number')).country.iso.code data.update({'source_country': payload.get('source_country')}) data.update({'type': payload.get('type')}) data.update({'destination_country': destination_country}) data.update({'amount': payload.get('amount')}) return data
def wallet_login(tastypie, data, request): try: _validate_login_payload(data) phone_number = data['phone_number'] password = data['password'] user = User.objects.get(username=phone_number) if user and user.is_active: result = user.check_password(password) if result: wallet = CustomerRepository.fetch_customer_by_phone_number( user, status=True) bundle = tastypie.build_bundle(obj=wallet, request=request) bundle = tastypie.full_dehydrate(bundle) bundle.data.update({'response_code': '000'}) bundle.data.update( {'first_name': wallet.informations.first_name}) bundle.data.update( {'last_name': wallet.informations.last_name}) bundle.data.update( create_jwt_token_for(wallet, 'wallet_api_secret_key')) return tastypie.create_response(request, bundle) else: return tastypie.create_response(request, { 'response_text': 'wrong password', 'response_code': '100' }, HttpForbidden) else: return tastypie.create_response(request, { 'response_text': 'Inactive Wallet', 'response_code': '100' }, HttpUnauthorized) except User.DoesNotExist: return tastypie.create_response(request, { 'response_text': 'unknwonw user', 'response_code': '100' }, HttpForbidden) except Exception as err: return tastypie.create_response(request, { 'response_text': err, 'response_code': '100' }, HttpForbidden)
def get_wallet_balance(tastypie, payload, request): try: data = payload.copy() data.update({'type': 'WALLET_BALANCE'}) _validate_transaction_payload(data) customer = CustomerRepository.fetch_customer_by_phone_number( payload.get('phone_number')) balance = get_customer_balance(customer) payload.update({ 'response_code': '000', 'balance': balance, 'currency': customer.country.currency.iso }) return tastypie.create_response(request, payload) 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)
def customer_info(tastypie, phone_number, request): try: customer = CustomerRepository.fetch_customer_by_phone_number( phone_number) bundle = tastypie.build_bundle(obj=customer, request=request) bundle = tastypie.full_dehydrate(bundle) bundle.data.update({'response_code': '000'}) bundle.data.update({ 'customer': { 'first_name': customer.informations.first_name, 'last_name': customer.informations.last_name } }) return tastypie.create_response(request, bundle) except Exception: return tastypie.create_response(request, { 'response_text': 'no customer', 'response_code': '100' }, HttpForbidden)
def _get_customer_info(payload): return CustomerRepository.fetch_customer_by_phone_number(payload.get('source_content_object').get('phone_number'))
def get_source_and_destination_of_recouvrement(payload): source = CustomerRepository.fetch_customer_by_phone_number( payload.get('phone_number')) destination = EntityRepository.fetch_by_account_number( payload.get('account_number')) return source, destination
def get_source_and_destination_of_cash_to_bank_account(payload): source = CustomerRepository.fetch_or_create_customer( payload.get('source_content_object')) destination = CustomerRepository.fetch_or_create_customer( payload.get('destination_content_object')) return source, destination
def get_source_and_destination_of_wallet_to_cash(payload): source = None destination = CustomerRepository.fetch_or_create_customer( payload.get('destination_content_object')) return source, destination
def get_source_and_destination_of_wallet_to_wallet(payload): source = CustomerRepository.fetch_customer_by_phone_number( payload.get('destination_content_object').get('phone_number')) destination = CustomerRepository.fetch_customer_by_phone_number( payload.get('destination_content_object').get('phone_number')) return source, destination
def get_source_and_destination_of_activation_carte(payload): source = CustomerRepository.fetch_or_create_customer( payload.get('customer'), True) destination = EntityRepository.fetch_by_agent_code( payload.get('agent').get('code')) return source, destination