<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

class EPayBL
{
  public static function getClient(int $payonline): \EpayBL\EpayBLKonnektorClient
  {
    $settings = ePaymentApi::getEPayPluginSettings($payonline);
    $epayBLKonnektorClient = new \EpayBL\EpayBLKonnektorClient(
      $settings['konnektorurl'],
      $settings['mandantennummer'],
      $settings['bewirtschafternummer'],
      true,
      self::getProxyConfig()
    );
    if ($settings['usessl']) {
      $epayBLKonnektorClient->setSSL($settings['keystorepath'], $settings['clientstorepath'], $settings['certpassword'], true);
    }

    return $epayBLKonnektorClient;
  }

  private static function getProxyConfig(): array
  {
    $proxyConf = ProxyConfig::getProxyConfigFromSettings();

    return array(
      'proxy_host' => $proxyConf->getServer(),
      'proxy_port' => $proxyConf->getPort(),
      'proxy_type' => 'HTTP',
      'auth_type' => 'CURLAUTH_BASIC',
      'auth_username' => $proxyConf->getUser(),
      'auth_password' => $proxyConf->getPassword(),
    );
  }
}
