def transfer(self, domain: Domain): if domain.epp_code is None: raise RegistrarConnectorException('EPP Code is missing') contact = domain.contact or domain.service.client owner_handle = self.find_or_create_customer(client=contact) nameserver_list = self._get_domain_nameservers_as_xml(domain) if not nameserver_list: raise RegistrarConnectorException( _('Nameservers for domain are required')) dom_req = E.createDomainRequest( self._xml_domain(domain), E.period(domain.registration_period), E.authCode(DomainUtils.decode_epp_code(domain.epp_code)), E.ownerHandle(owner_handle), E.adminHandle(owner_handle), E.techHandle(owner_handle), E.billingHandle(owner_handle), E.resellerHandle(''), E.nameServers(E.array(*nameserver_list))) response = self.api_request(data=dom_req) if response.data.status == 'ACT': domain.status = DomainStatus.active domain.registration_date = datetime.strptime( str(response.data.activationDate), '%Y-%m-%d %H:%M:%S').date() domain.expiry_date = datetime.strptime( str(response.data.expirationDate), '%Y-%m-%d %H:%M:%S').date() domain.epp_code = DomainUtils.encode_epp_code( str(response.data.authCode)) domain.save(update_fields=[ 'status', 'registration_date', 'expiry_date', 'epp_code' ]) return _('Domain transfered') elif response.data.status == 'REQ': domain.status = DomainStatus.pending domain.save(update_fields=['status']) return _('Domain pending registration') else: raise RegistrarConnectorException(_('Domain registration unknown'))
def initialize(self, service: Service) -> bool: """Initializes a new service object. This should be the first function called on a service. Keyword arguments: service -- the service to initialize Returns: True if service was initialized successfully """ LOG.debug('{} initialized called for service {}:{}'.format( self.module_name, service.id, service)) operation = service.plugin_data.get('operation', None) with transaction.atomic(): domain = Domain.objects.create( name=service.plugin_data['name'], status=DomainStatus.pending if operation == 'register' else DomainStatus.pending_transfer, tld=DomainUtils.get_tld( domain_name=service.plugin_data['name']), epp_code=DomainUtils.encode_epp_code( service.plugin_data.get('epp')), service=service, # TODO: this is now used instead of product data because edit item does not currently knows to update # TODO: product data registration_period=service.cycle.cycle_multiplier, ) for nameserver in [ service.plugin_data.get('nameserver1', None), service.plugin_data.get('nameserver2', None), service.plugin_data.get('nameserver3', None), service.plugin_data.get('nameserver4', None), ]: if nameserver: defaults = {'host_name': nameserver} db_nameserver, created = Nameserver.objects.get_or_create( **defaults, defaults=defaults) domain.nameservers.add(db_nameserver) contact_id = service.plugin_data.get('contact_id', None) domain.contact = Contact.objects.filter(id=contact_id).first() domain.save() return True
def get_epp_code(self, domain: Domain): response = self._retrieve_domain(domain) auth_code = str(response.data.authCode) domain.epp_code = DomainUtils.encode_epp_code(auth_code) domain.save(update_fields=['epp_code']) return auth_code