def smsapi_send_mobile_confirmation_sms(dbsession,
                                        client_id,
                                        application_name,
                                        confirmation_url,
                                        caller_area={}):
    _api_name = "smsapi_send_mobile_confirmation_sms"
    _api_entity = 'sms'
    _api_action = 'send_sms'
    _api_msgID = set_msgID(_api_name, _api_action, _api_entity)

    _process_identity_kwargs = {
        'type': 'api',
        'module': module_id,
        'name': _api_name,
        'action': _api_action,
        'entity': _api_entity,
        'msgID': _api_msgID,
    }
    _process_adapters_kwargs = {'dbsession': dbsession}
    _process_log_kwargs = {'indent_method': 'AUTO', 'indent_level': None}
    _process_debug_level = get_debug_level(caller_area.get('debug_level'),
                                           **_process_identity_kwargs,
                                           **_process_adapters_kwargs)
    _process_debug_files = get_debug_files(_process_debug_level,
                                           **_process_identity_kwargs,
                                           **_process_adapters_kwargs)
    _process_debug_kwargs = {
        'debug_level': _process_debug_level,
        'debug_files': _process_debug_files
    }

    _process_signature = build_process_signature(**_process_identity_kwargs,
                                                 **_process_adapters_kwargs,
                                                 **_process_debug_kwargs,
                                                 **_process_log_kwargs)
    _process_call_area = build_process_call_area(_process_signature,
                                                 caller_area)

    #_process_call_area.update({'debug_level': 99})

    log_process_start(_api_msgID, **_process_call_area)

    log_process_input('', 'client_id', client_id, **_process_call_area)
    log_process_input('', 'application_name', application_name,
                      **_process_call_area)
    log_process_input('', 'confirmation_url', confirmation_url,
                      **_process_call_area)
    log_process_input('', 'caller_area', caller_area, **_process_call_area)

    client = dbsession.get(db.CLIENT, {'client_id': client_id},
                           caller_area=_process_call_area)
    if not client:
        msg = f'client not found'
        reply = {'api_status': 'error', 'api_message': msg}
        return reply
    if not client.mobile:
        msg = f'no client mobile'
        reply = {'api_status': 'error', 'api_message': msg}
        return reply

    if client.mobile_confirmed:
        msg = f'mobile already confirmed'
        reply = {'api_status': 'error', 'api_message': msg}
        return reply

    phone_number = get_validated_phone_number(client.mobile)
    if not phone_number.get('api_status') == 'success':
        msg = phone_number.get('api_message', '?')
        msg = f'invalid mobile number {client.mobile}. ({msg})'
        api_result = {'api_status': 'error', 'api_message': msg}
        log_process_finish('', api_result, **_process_call_area)
        return api_result

    token_number = phone_number.get('international_number').replace('+', '')
    token = generate_sms_friendly_confirmation_token(token_number)
    if not token:
        msg = f'token generation failed'
        reply = {'api_status': 'error', 'api_message': msg}
        return reply

    otp = generate_otp()
    if not otp:
        msg = f'otp generation failed'
        reply = {'api_status': 'error', 'api_message': msg}
        return reply

    if not confirmation_url:
        msg = f'confirmation_url not provided'
        reply = {'api_status': 'error', 'api_message': msg}
        return reply

    client_record = client.to_dict()
    if len(client.mobile.strip()) < 11:
        client.mobile = '+357' + client.mobile.strip()

    confirmation_url = confirmation_url.replace('-token-', token)
    log_process_data('', 'confirmation_url', confirmation_url,
                     **_process_call_area)

    if not confirmation_url:
        msg = f'confirmation_url Failed. system error'
        reply = {'api_status': 'error', 'api_message': msg}
        return reply

    client_record.update({'confirmation_url': confirmation_url})
    client_record.update({'otp': otp})

    client_language = client.language
    if not client_language:
        client_language = 'En'

    sms_template = 'mobile_confirmation_sms'
    language = client_language
    template = dbsession.get(db.APPLICATION_TEMPLATE, {
        'template_name': sms_template,
        'application_name': application_name,
        'language': language
    },
                             caller_area=_process_call_area)
    if not template:
        msg = f'template [{sms_template}] not found for application [{application_name}] language [{language}]'
        log_process_message(_api_msgID, 'waring', msg, **_process_call_area)

        language = 'En'
        template = dbsession.get(db.APPLICATION_TEMPLATE, {
            'template_name': sms_template,
            'application_name': application_name,
            'language': language
        },
                                 caller_area=_process_call_area)
        if not template:
            msg = f'template [{sms_template}] not found for application [{application_name}] language [{language}]'
            log_process_message(_api_msgID, 'waring', msg,
                                **_process_call_area)
            language = client_language
            template = dbsession.get(db.APPLICATION_TEMPLATE, {
                'template_name': sms_template,
                'application_name': '',
                'language': language
            },
                                     caller_area=_process_call_area)
            if not template:
                msg = f'generic template [{sms_template}] not found for client_language {language}'
                log_process_message(_api_msgID, 'error', msg,
                                    **_process_call_area)

                language = 'En'
                template = dbsession.get(db.APPLICATION_TEMPLATE, {
                    'template_name': sms_template,
                    'application_name': '',
                    'language': language
                },
                                         caller_area=_process_call_area)
                if not template:
                    msg = f'generic template [{sms_template}] not found for language {language}'
                    log_process_message(_api_msgID, 'error', msg,
                                        **_process_call_area)
                    sms_message = f'the code to confirm your mobile is {otp} click #CONFIRMATION_URL#'

    if template:
        sms_message = template.text

    log_process_data('', 'sms message', sms_message, **_process_call_area)

    if sms_message.find('#') >= 0:
        sms_message = utilities.string_translate(sms_message, client_record)
        log_process_data('', 'sms message translated', sms_message,
                         **_process_call_area)

    From = thisApp.application_configuration.get('sms_sender')
    log_process_data('', 'From', From, **_process_call_area)
    if not (From):
        From = application_name
        msg = f'From set to application_name [{From}]'
        log_process_message(_api_msgID, 'warning', msg, **_process_call_area)
    # if not(From):
    #     From = 'ganimidesT'
    #     msg = f'From set to [{From}]'
    #     log_process_message(_api_msgID, 'warning', msg, **_process_call_area)
    if not (From):
        msg = f'sms sender not defined'
        api_result = {'api_status': 'error', 'api_message': msg}
        log_process_finish(_api_msgID, api_result, **_process_call_area)
        return api_result

    _process_call_area.update({'sms_simulation': True})

    sms_result = send_sms_service(dbsession,
                                  From=From,
                                  To=client.mobile,
                                  Message=sms_message,
                                  caller_area=_process_call_area)
    #provider_reply = {'provider_reply': reply, 'reply_code': status_code, 'reply_message': reply_message, 'provider': 'SINCH', 'provider_send_id': sms_uid}
    if sms_result.get('api_status') == 'success':
        verification_record = {
            'verification_token':
            token,
            'verification_code':
            otp,
            'verification_entity':
            'mobile',
            'client_id':
            client.client_id,
            'application_name':
            application_name,
            'mobile':
            client.mobile,
            'status':
            'SmsSent',
            'send_method':
            'sms',
            'send_provider':
            sms_result.get('api_data', {}).get('provider'),
            'send_ticket':
            sms_result.get('api_data', {}).get('provider_send_id'),
            'send_timestamp':
            datetime.datetime.utcnow(),
            'expiry_timestamp':
            datetime.datetime.utcnow() + datetime.timedelta(seconds=3600),
        }
        verification = dbsession.insert(db.VERIFICATION,
                                        verification_record,
                                        auto_commit=True,
                                        caller_area=_process_call_area)
        if not verification:
            msg = f'system error: verification record create failed'
            log_process_message('', 'error', msg, **_process_call_area)

    api_result = sms_result
    api_result.update({'api_action': _api_action, 'api_name': _api_name})

    log_process_finish(_api_msgID, api_result, **_process_call_area)
    return api_result
def send_sms_service(dbsession,
                     From='',
                     To='',
                     Cc='',
                     Bcc='',
                     Message='',
                     language='En',
                     sms_template='',
                     data_record={},
                     application_name='',
                     caller_area={}):
    _api_name = "send_sms_service"
    _api_entity = 'sms'
    _api_action = 'send_sms'
    _api_msgID = set_msgID(_api_name, _api_action, _api_entity)

    _process_identity_kwargs = {
        'type': 'api',
        'module': module_id,
        'name': _api_name,
        'action': _api_action,
        'entity': _api_entity,
        'msgID': _api_msgID,
    }
    _process_adapters_kwargs = {'dbsession': dbsession}
    _process_log_kwargs = {'indent_method': 'AUTO', 'indent_level': None}
    _process_debug_level = get_debug_level(caller_area.get('debug_level'),
                                           **_process_identity_kwargs,
                                           **_process_adapters_kwargs)
    _process_debug_files = get_debug_files(_process_debug_level,
                                           **_process_identity_kwargs,
                                           **_process_adapters_kwargs)
    _process_debug_kwargs = {
        'debug_level': _process_debug_level,
        'debug_files': _process_debug_files
    }

    _process_signature = build_process_signature(**_process_identity_kwargs,
                                                 **_process_adapters_kwargs,
                                                 **_process_debug_kwargs,
                                                 **_process_log_kwargs)
    _process_call_area = build_process_call_area(_process_signature,
                                                 caller_area)

    log_process_start(_api_msgID, **_process_call_area)

    log_process_input('', 'From', From, **_process_call_area)
    log_process_input('', 'To', To, **_process_call_area)
    log_process_input('', 'Cc', Cc, **_process_call_area)
    log_process_input('', 'Bcc', Bcc, **_process_call_area)
    log_process_input('', 'Message', Message, **_process_call_area)
    log_process_input('', 'language', language, **_process_call_area)
    log_process_input('', 'sms_template', sms_template, **_process_call_area)
    log_process_input('', 'application_name', application_name,
                      **_process_call_area)
    log_process_input('', 'caller_area', caller_area, **_process_call_area)

    sms_record = {
        'sender': From,
        'recipient': To,
        'cc': Cc,
        'bcc': Bcc,
        'message': Message,
        'language': language,
        'data_record': str(data_record),
        'application_name': application_name,
    }
    sms = dbsession.insert(db.SMS,
                           sms_record,
                           auto_commit=True,
                           caller_area=_process_call_area)

    sms_result = send_sms(From=From,
                          To=To,
                          Message=Message,
                          language=language,
                          sms_template=sms_template,
                          data_record=data_record,
                          application_name=application_name,
                          caller_area=caller_area)
    #provider_reply = {'provider_reply': reply, 'reply_code': status_code, 'reply_message': reply_message, 'provider': 'SINCH', 'provider_send_id': sms_uid}
    sms_record = {
        'sms_id': sms.sms_id,
        'sender': From,
        'recipient': To,
        'cc': Cc,
        'bcc': Bcc,
        'message': Message,
        'language': language,
        'data_record': str(data_record),
        'application_name': application_name,
        'sms_template': sms_template,
        'application_name': application_name,
        'send_provider': sms_result.get('api_data', {}).get('provider'),
        'send_ticket': sms_result.get('api_data', {}).get('provider_send_id'),
        'provider_reply': sms_result.get('api_data', {}).get('provider_reply'),
        'reply_code': sms_result.get('api_data', {}).get('reply_code'),
        'reply_message': sms_result.get('api_data', {}).get('reply_message'),
        'send_timestamp': datetime.datetime.utcnow(),
    }
    dbsession.refresh(db.SMS,
                      sms_record,
                      auto_commit=True,
                      caller_area=_process_call_area)

    api_result = sms_result
    log_process_finish(_api_msgID, api_result, **_process_call_area)
    return api_result
        'device_uid': device_uid,
        'geolocation_lat': geolocation_lat,
        'geolocation_lon': geolocation_lon,
        }

    caller_area.update({'debug_level': 0, 'caller_area_input_debug': False,})

    _process_name = "test_openbanking_apis"
    _process_entity = ''
    _process_action = 'test'
    _process_msgID = 'process: test_openbanking_apis'

    _process_identity_kwargs = {'type': 'process', 'module': module_id, 'name': _process_name, 'action': _process_action, 'entity': _process_entity, 'msgID': _process_msgID,}
    _process_adapters_kwargs = {'dbsession': None}
    _process_log_kwargs = {'indent_method': 'AUTO', 'indent_level':None}
    _process_debug_level = get_debug_level(caller_area.get('debug_level'), **_process_identity_kwargs, **_process_adapters_kwargs)
    _process_debug_files = get_debug_files(_process_debug_level, **_process_identity_kwargs, **_process_adapters_kwargs)
    _process_debug_kwargs={'debug_level':_process_debug_level,'debug_files':_process_debug_files}

    _process_signature = build_process_signature(**_process_identity_kwargs, **_process_adapters_kwargs, **_process_debug_kwargs, **_process_log_kwargs)
    _process_call_area = build_process_call_area(_process_signature, caller_area)

    #SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#
    #SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#
    #SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#
    _process_call_area.update({'simulation_enabled':True})
    #SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#
    #SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#
    #SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#SOS#
    
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
Пример #4
0
def emailapi_send_email_confirmation_email(dbsession,
                                           client_id,
                                           application_name,
                                           confirmation_url,
                                           caller_area={}):
    _api_name = "emailapi_send_email_confirmation_email"
    _api_entity = 'email'
    _api_action = 'send_email'
    _api_msgID = set_msgID(_api_name, _api_action, _api_entity)

    _process_identity_kwargs = {
        'type': 'api',
        'module': module_id,
        'name': _api_name,
        'action': _api_action,
        'entity': _api_entity,
        'msgID': _api_msgID,
    }
    _process_adapters_kwargs = {'dbsession': dbsession}
    _process_log_kwargs = {'indent_method': 'AUTO', 'indent_level': None}
    _process_debug_level = get_debug_level(caller_area.get('debug_level'),
                                           **_process_identity_kwargs,
                                           **_process_adapters_kwargs)
    _process_debug_files = get_debug_files(_process_debug_level,
                                           **_process_identity_kwargs,
                                           **_process_adapters_kwargs)
    _process_debug_kwargs = {
        'debug_level': _process_debug_level,
        'debug_files': _process_debug_files
    }

    _process_signature = build_process_signature(**_process_identity_kwargs,
                                                 **_process_adapters_kwargs,
                                                 **_process_debug_kwargs,
                                                 **_process_log_kwargs)
    _process_call_area = build_process_call_area(_process_signature,
                                                 caller_area)

    log_process_start(_api_msgID, **_process_call_area)

    log_process_input('', 'client_id', client_id, **_process_call_area)
    log_process_input('', 'application_name', application_name,
                      **_process_call_area)
    log_process_input('', 'confirmation_url', confirmation_url,
                      **_process_call_area)
    log_process_input('', 'caller_area', caller_area, **_process_call_area)

    client = dbsession.get(db.CLIENT, {'client_id': client_id},
                           caller_area=_process_call_area)
    if not client:
        msg = f'client not found'
        reply = {'api_status': 'error', 'api_message': msg}
        return reply
    if not client.email:
        msg = f'no client email'
        reply = {'api_status': 'error', 'api_message': msg}
        return reply

    if client.email_confirmed:
        msg = f'email already confirmed'
        reply = {'api_status': 'error', 'api_message': msg}
        return reply

    client_id = client.client_id
    client_record = client.to_dict()

    token = generate_confirmation_token(client.email)
    if not token:
        msg = f'token generation failed'
        reply = {'api_status': 'error', 'api_message': msg}
        return reply

    otp = generate_otp()
    if not otp:
        msg = f'otp generation failed'
        reply = {'api_status': 'error', 'api_message': msg}
        return reply

    if not confirmation_url:
        msg = f'confirmation_url not provided'
        reply = {'api_status': 'error', 'api_message': msg}
        return reply

    confirmation_url = confirmation_url.replace('-token-', token)
    log_process_data('', 'confirmation_url', confirmation_url,
                     **_process_call_area)

    if not confirmation_url:
        msg = f'confirmation_url Failed. system error'
        reply = {'api_status': 'error', 'api_message': msg}
        return reply

    client_record.update({'confirmation_url': confirmation_url})
    client_record.update({'otp': otp})

    client_language = client.language
    if not client_language:
        client_language = 'En'

    email_template = 'email_confirmation_email'
    language = client_language
    template = dbsession.get(db.APPLICATION_TEMPLATE, {
        'template_name': email_template,
        'application_name': application_name,
        'language': language
    },
                             caller_area=_process_call_area)
    if not template:
        msg = f'template [{email_template}] not found for application [{application_name}] language [{language}]'
        log_process_message(_api_msgID, 'waring', msg, **_process_call_area)

        language = 'En'
        template = dbsession.get(db.APPLICATION_TEMPLATE, {
            'template_name': email_template,
            'application_name': application_name,
            'language': language
        },
                                 caller_area=_process_call_area)
        if not template:
            msg = f'template [{email_template}] not found for application [{application_name}] language [{language}]'
            log_process_message(_api_msgID, 'waring', msg,
                                **_process_call_area)
            language = client_language
            template = dbsession.get(db.APPLICATION_TEMPLATE, {
                'template_name': email_template,
                'application_name': '',
                'language': language
            },
                                     caller_area=_process_call_area)
            if not template:
                msg = f'generic template [{email_template}] not found for client_language {language}'
                log_process_message(_api_msgID, 'error', msg,
                                    **_process_call_area)

                language = 'En'
                template = dbsession.get(db.APPLICATION_TEMPLATE, {
                    'template_name': email_template,
                    'application_name': '',
                    'language': language
                },
                                         caller_area=_process_call_area)
                if not template:
                    msg = f'generic template [{email_template}] not found for language {language}'
                    log_process_message(_api_msgID, 'error', msg,
                                        **_process_call_area)
                    email_subject = f'email confirmation'
                    email_content_text = f'please confirm your email by clicking the link below' + '\n' + f'{confirmation_url} and entering the code {otp}'
                    email_content_html = ''

    if template:
        email_subject = template.subject
        email_content_text = template.text
        email_content_html = template.html

    log_process_data('', 'email_subject', email_subject, **_process_call_area)
    log_process_data('', 'email_content_text', email_content_text,
                     **_process_call_area)
    log_process_data('', 'email_content_html', email_content_html,
                     **_process_call_area)

    if email_subject.find('#') >= 0:
        email_subject = utilities.string_translate(email_subject,
                                                   client_record)
        log_process_data('', 'email_subject translated', email_subject,
                         **_process_call_area)
    if email_content_text.find('#') >= 0:
        email_content_text = utilities.string_translate(
            email_content_text, client_record)
        log_process_data('', 'email_content_text translated',
                         email_content_text, **_process_call_area)
    if email_content_html.find('#') >= 0:
        email_content_html = utilities.string_translate(
            email_subject, client_record)
        log_process_data('', 'email_content_html translated',
                         email_content_html, **_process_call_area)

    From = thisApp.application_configuration.get('email_sender')
    log_process_data('', 'From', From, **_process_call_area)
    if not (From):
        From = application_name
        msg = f'From set to application_name [{From}]'
        log_process_message(_api_msgID, 'warning', msg, **_process_call_area)
    # if not(From):
    #     From = 'ganimidesT'
    #     msg = f'From set to [{From}]'
    #     log_process_message(_api_msgID, 'warning', msg, **_process_call_area)
    if not (From):
        msg = f'email sender not defined'
        api_result = {'api_status': 'error', 'api_message': msg}
        log_process_finish(_api_msgID, api_result, **_process_call_area)
        return api_result

    email_result = send_email_service(dbsession,
                                      From=From,
                                      To=client.email,
                                      Subject=email_subject,
                                      text_body=email_content_text,
                                      html_body=email_content_html,
                                      language=language,
                                      caller_area=_process_call_area)

    #provider_reply = {'provider_reply': reply, 'reply_code': status_code, 'reply_message': reply_message, 'provider': 'SINCH', 'provider_send_id': sms_uid}

    if email_result.get('api_status') == 'success':
        verification_record = {
            'verification_token':
            token,
            'verification_code':
            otp,
            'verification_entity':
            'email',
            'client_id':
            client.client_id,
            'application_name':
            application_name,
            'email':
            client.email,
            'status':
            'EmailSent',
            'send_method':
            'email',
            'send_provider':
            email_result.get('api_data', {}).get('provider'),
            'send_ticket':
            email_result.get('api_data', {}).get('provider_send_id'),
            'send_timestamp':
            datetime.datetime.utcnow(),
            'expiry_timestamp':
            datetime.datetime.utcnow() + datetime.timedelta(seconds=3600),
        }

        verification = dbsession.insert(db.VERIFICATION,
                                        verification_record,
                                        auto_commit=True,
                                        caller_area=_process_call_area)
        if not verification:
            msg = f'system error: verification record create failed'
            log_process_message('', 'error', msg, **_process_call_area)

    api_result = email_result
    api_result.update({'api_action': _api_action, 'api_name': _api_name})

    log_process_finish(_api_msgID, api_result, **_process_call_area)
    return api_result
Пример #5
0
def send_email_service(dbsession,
                       From='',
                       To='',
                       Cc='',
                       Bcc='',
                       Subject='',
                       text_body='',
                       html_body='',
                       email_template='',
                       data_record={},
                       attachments=[],
                       application_name='',
                       language='En',
                       caller_area={}):

    _api_name = "send_email_service"
    _api_entity = 'email'
    _api_action = 'send_email'
    _api_msgID = set_msgID(_api_name, _api_action, _api_entity)

    _process_identity_kwargs = {
        'type': 'api',
        'module': module_id,
        'name': _api_name,
        'action': _api_action,
        'entity': _api_entity,
        'msgID': _api_msgID,
    }
    _process_adapters_kwargs = {'dbsession': dbsession}
    _process_log_kwargs = {'indent_method': 'AUTO', 'indent_level': None}
    _process_debug_level = get_debug_level(caller_area.get('debug_level'),
                                           **_process_identity_kwargs,
                                           **_process_adapters_kwargs)
    _process_debug_files = get_debug_files(_process_debug_level,
                                           **_process_identity_kwargs,
                                           **_process_adapters_kwargs)
    _process_debug_kwargs = {
        'debug_level': _process_debug_level,
        'debug_files': _process_debug_files
    }

    _process_signature = build_process_signature(**_process_identity_kwargs,
                                                 **_process_adapters_kwargs,
                                                 **_process_debug_kwargs,
                                                 **_process_log_kwargs)
    _process_call_area = build_process_call_area(_process_signature,
                                                 caller_area)

    log_process_start(_api_msgID, **_process_call_area)

    log_process_input('', 'From', From, **_process_call_area)
    log_process_input('', 'To', To, **_process_call_area)
    log_process_input('', 'Cc', Cc, **_process_call_area)
    log_process_input('', 'Bcc', Bcc, **_process_call_area)
    log_process_input('', 'Subject', Subject, **_process_call_area)
    log_process_input('', 'text_body', text_body, **_process_call_area)
    log_process_input('', 'html_body', html_body, **_process_call_area)
    log_process_input('', 'email_template', email_template,
                      **_process_call_area)
    log_process_input('', 'application_name', application_name,
                      **_process_call_area)
    log_process_input('', 'language', language, **_process_call_area)
    log_process_input('', 'attachments', attachments, **_process_call_area)
    log_process_input('', 'caller_area', caller_area, **_process_call_area)

    email_record = {
        'sender': From,
        'recipient': To,
        'cc': Cc,
        'bcc': Bcc,
        'language': language,
        'subject': Subject,
        'text_body': text_body,
        'html_body': html_body,
        'email_template': email_template,
        'data_record': str(data_record),
        'attachments': str(attachments),
        'application_name': application_name,
    }
    email = dbsession.insert(db.EMAIL,
                             email_record,
                             auto_commit=True,
                             caller_area=_process_call_area)

    email_result = send_email(From=From,
                              To=To,
                              Subject=Subject,
                              text_body=text_body,
                              html_body=html_body,
                              caller_area=caller_area)
    #provider_reply = {'provider_reply': reply, 'reply_code': status_code, 'reply_message': reply_message, 'provider': 'SINCH', 'provider_send_id': sms_uid}
    email_record = {
        'email_id': email.email_id,
        'sender': From,
        'recipient': To,
        'cc': Cc,
        'bcc': Bcc,
        'language': language,
        'subject': Subject,
        'text_body': text_body,
        'html_body': html_body,
        'email_template': email_template,
        # 'data_record': data_record,
        # 'attachments': attachments,
        'application_name': application_name,
        'send_provider': email_result.get('api_data', {}).get('provider'),
        'send_ticket': email_result.get('api_data',
                                        {}).get('provider_send_id'),
        'provider_reply': email_result.get('api_data',
                                           {}).get('provider_reply'),
        'reply_code': email_result.get('api_data', {}).get('reply_code'),
        'reply_message': email_result.get('api_data', {}).get('reply_message'),
        'send_timestamp': datetime.datetime.utcnow(),
    }
    dbsession.refresh(db.EMAIL,
                      email_record,
                      auto_commit=True,
                      caller_area=_process_call_area)

    api_result = email_result
    log_process_finish(_api_msgID, api_result, **_process_call_area)
    return api_result
Пример #6
0
def xmerchant_banksubscription_register(dbsession, merchant_id, application_name, bank_id, subscription_options={},caller_area={}):
    _api_name = "merchant_banksubscription_register"
    _api_entity = 'BANK_SUBSCRIPTION'
    _api_action = 'register'
    _api_msgID = set_msgID(_api_name, _api_action, _api_entity)

    _process_identity_kwargs = {'type': 'api', 'module': module_id, 'name': _api_name, 'action': _api_action, 'entity': _api_entity, 'msgID': _api_msgID,}
    _process_adapters_kwargs = {'dbsession': dbsession}
    _process_log_kwargs = {'indent_method': 'AUTO', 'indent_level':None}
    _process_debug_level = get_debug_level(caller_area.get('debug_level'), **_process_identity_kwargs, **_process_adapters_kwargs)
    _process_debug_files = get_debug_files(_process_debug_level, **_process_identity_kwargs, **_process_adapters_kwargs)
    _process_debug_kwargs={'debug_level':_process_debug_level,'debug_files':_process_debug_files}

    _process_signature = build_process_signature(**_process_identity_kwargs, **_process_adapters_kwargs, **_process_debug_kwargs, **_process_log_kwargs)
    _process_call_area = build_process_call_area(_process_signature, caller_area)

    log_process_start(_api_msgID,**_process_call_area)

    log_process_input('', 'merchant_id', merchant_id,**_process_call_area)
    log_process_input('', 'bank_id', bank_id,**_process_call_area)
    log_process_input('', 'application_name', application_name,**_process_call_area)
    log_process_input('', 'subscription_options', subscription_options,**_process_call_area)
    log_process_input('', 'caller_area', caller_area,**_process_call_area)

    merchant = dbsession.get(db.MERCHANT, {'merchant_id':merchant_id}, caller_area=_process_call_area)
    client_id = merchant.client_id
    if not client_id:
        msg = f'merchant {merchant_id} not found'
        reply = {'api_status': 'error', 'api_message': msg}
        return reply
    if not merchant.status=='Active':
        msg = f'merchant not active. (status={merchant.status})'
        reply = {'api_status': 'error', 'api_message': msg}
        return reply
    client = dbsession.get(db.CLIENT, {'client_id':client_id}, caller_area=_process_call_area)
    if not client.status=='Active':
        msg = f'client not active. (status={client.status})'
        reply = {'api_status': 'error', 'api_message': msg}
        return reply

    application = dbsession.get(db.APPLICATION,  {'application_name': application_name}, caller_area=_process_call_area)
    if not application:
        msg = f'application not found'
        log_process_message('', 'error', msg, **_process_call_area)
        api_result = {'api_status': 'error', 'api_message': msg, 'api_action': _api_action.upper(), 'api_name': _api_name}
        log_process_finish(_api_msgID, api_result, **_process_call_area)
        return api_result
    if not application.status == 'Active':
        msg = f"application not Active.(status:{application.status})"
        log_process_message('', 'error', msg, **_process_call_area)
        api_result = {'api_status': 'error', 'api_message': msg, 'api_action': _api_action.upper(), 'api_name': _api_name}
        log_process_finish(_api_msgID, api_result, **_process_call_area)
        return api_result

    app_user_spec = {'application_name': application_name,'client_id':client_id,'user_role':None}
    application_user = dbsession.get(db.APPLICATION_USER, app_user_spec, caller_area=_process_call_area)
    if not application_user:
        msg = f'merchant [{merchant.name}] not subscribed for application [{application_name}]'
        log_process_message('', 'error', msg, **_process_call_area)
        api_result = {'api_status': 'error', 'api_message': msg, 'api_action': _api_action.upper(), 'api_name': _api_name}
        log_process_finish(_api_msgID, api_result, **_process_call_area)
        return api_result
    if not application_user.status == 'Active':
        msg = f'merchant [{merchant.name}] subscription for application [{application_name}] is not active (status={application_user.status})'
        log_process_message('', 'error', msg, **_process_call_area)
        api_result = {'api_status': 'error', 'api_message': msg, 'api_action': _api_action.upper(), 'api_name': _api_name}
        log_process_finish(_api_msgID, api_result, **_process_call_area)
        return api_result

    # subscription_options = request.json
    allow_transactionHistory = subscription_options.get('allow_transactionHistory', False)
    allow_balance = subscription_options.get('allow_balance', False)
    allow_details = subscription_options.get('allow_details', False)
    allow_checkFundsAvailability = subscription_options.get('allow_checkFundsAvailability', False)
    payments_limit = subscription_options.get('payments_limit', 100)
    payments_currency = subscription_options.get('payments_currency', 'EUR')
    payments_amount = subscription_options.get('payments_amount', 10)

    log_process_data('', 'allow_transactionHistory', allow_transactionHistory,**_process_call_area)
    log_process_data('', 'allow_balance', allow_balance,**_process_call_area)
    log_process_data('', 'allow_details', allow_details,**_process_call_area)
    log_process_data('', 'allow_checkFundsAvailability', allow_checkFundsAvailability,**_process_call_area)
    log_process_data('', 'payments_limit', payments_limit,**_process_call_area)
    log_process_data('', 'payments_currency', payments_currency,**_process_call_area)
    log_process_data('', 'payments_amount', payments_amount,**_process_call_area)
    
    action_result = bankingapi.banksubscription_register(dbsession, 
        client_id=client_id, bank_id=bank_id, application_name=application_name,
        allow_transactionHistory=allow_transactionHistory, allow_balance=allow_balance,
        allow_details=allow_details, allow_checkFundsAvailability=allow_checkFundsAvailability,
        payments_limit=payments_limit, payments_currency=payments_currency, payments_amount=payments_amount
        )
    api_result = action_result
    api_result.update({'api_action': _api_action, 'api_name': _api_name})
    
    log_process_finish(_api_msgID, api_result, **_process_call_area)    
    return api_result