public function codeRegister($code)
  {
      if (!$phone = $this->dissectPhone()) {
          throw new Exception('The provided phone number is not valid.');
      }

      $code = str_replace('-', '', $code);
      $countryCode = ($phone['ISO3166'] != '') ? $phone['ISO3166'] : 'US';
      $langCode = ($phone['ISO639'] != '') ? $phone['ISO639'] : 'en';

      // Build the url.
      $host = 'https://'.Constants::WHATSAPP_REGISTER_HOST;
      $query = [
      'cc'                 => $phone['cc'],
      'in'                 => $phone['phone'],
      'lg'                 => $langCode,
      'lc'                 => $countryCode,
      'id'                 => $this->identity,
      'mistyped'           => '6',
      'network_radio_type' => '1',
      'simnum'             => '1',
      's'                  => '',
      'copiedrc'           => '1',
      'hasinrc'            => '1',
      'rcmatch'            => '1',
      'pid'                => mt_rand(100, 9999),
      'rchash'             => hash('sha256', openssl_random_pseudo_bytes(20)),
      'anhash'             => md5(openssl_random_pseudo_bytes(20)),
      'extexist'           => '1',
      'extstate'           => '1',
      'code'               => $code,
      ];

      $this->debugPrint($query);

      $response = $this->getResponse($host, $query);

      $this->debugPrint($response);
      
      if ($response->status != 'ok') {
          $this->eventManager()->fire('onCodeRegisterFailed',
            [
                $this->phoneNumber,
                $response->status,
                $response->reason,
                isset($response->retry_after) ? $response->retry_after : null,
            ]);

          if ($response->reason == 'old_version') {
              $this->update();
          }

          throw new Exception("An error occurred registering the registration code from WhatsApp. Reason: $response->reason");
      } else {
          $this->eventManager()->fire('onCodeRegister',
            [
                $this->phoneNumber,
                $response->login,
                $response->pw,
                $response->type,
                $response->expiration,
                $response->kind,
                $response->price,
                $response->cost,
                $response->currency,
                $response->price_expiration,
            ]);
      }

      return $response;
  }