public function getService(Payment $payment, $intent)
    {
        $method = 'create' . ucfirst($intent) . 'Service';
        $values = $this->extend($method, $payment);

        if (count($values) > 1) {
            throw new InvalidConfigurationException("Multiple extensions are trying to create a service for '$intent'");
        }

        if (count($values) === 1 && $values[0] instanceof PaymentService) {
            return $values[0];
        }

        if (method_exists($this, $method)) {
            return $this->$method($payment);
        }

        $serviceMap = $this->config()->get('services');

        if (is_array($serviceMap) && isset($serviceMap[$intent])) {
            $serviceType = $serviceMap[$intent];

            if (is_subclass_of($serviceType, PaymentService::class)) {
                return $serviceType::create($payment);
            }
        }

        throw new InvalidConfigurationException("Unable to create a service for '$intent'");
    }
public function getService(Payment $payment, $intent)
    {
        $method = 'create' . ucfirst($intent) . 'Service';
        $values = $this->extend($method, $payment);

        if (count($values) > 1) {
            throw new InvalidConfigurationException("Multiple extensions are trying to create a service for '$intent'");
        }

        if (count($values) === 1 && $values[0] instanceof PaymentService) {
            return $values[0];
        }

        if (method_exists($this, $method)) {
            return $this->$method($payment);
        }

        $serviceMap = $this->config()->get('services');

        if (is_array($serviceMap) && isset($serviceMap[$intent])) {
            $serviceType = $serviceMap[$intent];

            if (is_subclass_of($serviceType, PaymentService::class)) {
                return $serviceType::create($payment);
            }
        }

        throw new InvalidConfigurationException("Unable to create a service for '$intent'");
    }
public function getService ( Payment $ payment , $ intent ) { $ method = 'create' . ucfirst ( $ intent ) . 'Service' ; $ values = $ this -> extend ( $ method , $ payment ) ; if ( count ( $ values ) > 1 ) { throw new InvalidConfigurationException ( "Multiple extensions are trying to create a service for '$intent'" ) ; } if ( count ( $ values ) === 1 && $ values [ 0 ] instanceof PaymentService ) { return $ values [ 0 ] ; } if ( method_exists ( $ this , $ method ) ) { return $ this -> $ method ( $ payment ) ; } $ serviceMap = $ this -> config ( ) -> get ( 'services' ) ; if ( is_array ( $ serviceMap ) && isset ( $ serviceMap [ $ intent ] ) ) { $ serviceType = $ serviceMap [ $ intent ] ; if ( is_subclass_of ( $ serviceType , PaymentService :: class ) ) { return $ serviceType :: create ( $ payment ) ; } } throw new InvalidConfigurationException ( "Unable to create a service for '$intent'" ) ; }
Create a service for the given payment and intent.

This method will look for a method named `create{Intent}Service`, where
"{Intent}" has to be substituted with the intent. So an intent "authorize" will look for a method named
"createAuthorizeService". The method will be called on extensions first and then on this class itself, given
that no extension returned a valid PaymentService instance.

If the method didn't return an instance, this will fall back to the services configuration.

@param Payment $payment the payment instance
@param string $intent the intent of the service.

@return PaymentService
@throws InvalidConfigurationException when creation of the service failed due to misconfiguration
Create a service for the given payment and intent .