private function setupServices()
{
$builder = $this->getContainerBuilder();
$config = $this->validateConfig($this->defaults);
$gopay = $builder->getDefinition($this->prefix('gopay'));
$services = ['payment' => PaymentService::class, 'recurrentPayment' => RecurrentPaymentService::class, 'preAuthorizedPayment' => PreAuthorizedPaymentService::class];
foreach ($services as $serviceName => $serviceClass) {
$def = $builder->addDefinition($this->prefix("service.{$serviceName}"))->setClass($serviceClass, [$gopay]);
if (is_bool($config['payments']['changeChannel'])) {
$def->addSetup('allowChangeChannel', [$config['payments']['changeChannel']]);
}
if (isset($config['payments']['channels'])) {
$constants = ClassType::from(Gopay::class);
foreach ($config['payments']['channels'] as $code => $channel) {
$constChannel = 'METHOD_' . strtoupper($code);
if ($constants->hasConstant($constChannel)) {
$code = $constants->getConstant($constChannel);
}
if (is_array($channel)) {
$channel['code'] = $code;
$def->addSetup('addChannel', $channel);
} else {
if (is_scalar($channel)) {
$def->addSetup('addChannel', [$code, $channel]);
}
}
}
}
}
}