btcpayserver / btcpayserver-php-client

PHP implementation for the BTCPayServer cryptographically secure RESTful API
MIT License
29 stars 33 forks source link

Port is null using legitimate payserver URL #32

Open dcentrica opened 4 years ago

dcentrica commented 4 years ago

Given a BTCPay instance URL of: https://testnet.demo.btcpayserver.org/ then the logic in Client.php:639 will return null. One can argue that PHP's port sniffing capabilities leave something to be desired, or we can workaround this:

#> php -a
php > var_dump(parse_url('https://testnet.demo.btcpayserver.org/', PHP_URL_PORT));
NULL

Assuming port acquisition is really needed, then some simple logic to determine the correct port to use from the scheme should be implemented, or a suitable default e.g. 443.

public function getPort(): int
{
    if ($this->port) {
        return $this->port;
    }

   return parse_url($this->uri, PHP_URL_SCHEME) === 'https' ? 443 : 80;
}

Otherwise, some hints in the docs that a port should be included in the host URL in library config, should be added. Having said that, it is possible (but not probable) that userland https schemes might be used while stipulating port 80...

rukykf commented 3 years ago

I am currently developing a BTCPay extension for CiviCRM and I am having this exact same issue. Are there any updates on this? Are you interested in making a pull request for it or should I?

dcentrica commented 3 years ago

I am currently developing a BTCPay extension for CiviCRM and I am having this exact same issue. Are there any updates on this? Are you interested in making a pull request for it or should I?

Feel free. The maintainers are aware that the PHP setup scripts need to be overhauled.