

@allow_remote_invocation
def create_backend(self, data):
    webhook_secret = self.get_cached_webhook_secret(data.get('request_token'))
    values = {
        'name': data.get('name'),
        'description': _("My Telerivet Gateway '{}'").format(data.get('name')),
        'api_key': data.get('api_key'),
        'project_id': data.get('project_id'),
        'phone_id': data.get('phone_id'),
        'webhook_secret': webhook_secret,
    }
    form = TelerivetBackendForm(values, domain=self.domain, backend_id=None)
    if form.is_valid():
        with transaction.atomic():
            backend = SQLTelerivetBackend(backend_type=SQLMobileBackend.SMS, inbound_api_key=webhook_secret, hq_api_id=SQLTelerivetBackend.get_api_id(), is_global=False, domain=self.domain, name=form.cleaned_data.get('name'), description=form.cleaned_data.get('description'))
            backend.set_extra_fields(api_key=form.cleaned_data.get('api_key'), project_id=form.cleaned_data.get('project_id'), phone_id=form.cleaned_data.get('phone_id'), webhook_secret=webhook_secret)
            backend.save()
            if (data.get('set_as_default') == FinalizeGatewaySetupForm.YES):
                SQLMobileBackendMapping.set_default_domain_backend(self.domain, backend)
            return {
                'success': True,
            }
    name_error = self.get_error_message(form, 'name')
    return {
        'success': False,
        'name_error': name_error,
        'unexpected_error': (None if name_error else self.unexpected_error),
    }

dataset/ETHPy150Open dimagi/commcare-hq/corehq/messaging/smsbackends/telerivet/views.py TelerivetSetupView.create_backend/original