Select the payment method by code

@since 2.1.0
@access public
@param string $name
@return \Icepay_Webservice_Paymentmethod
@throws Exception
196937
public function selectPaymentMethodByCode($name)
    {
        if (!isset($this->_paymentMethodsArray))
            throw new Exception("No data loaded");
        foreach ($this->_paymentMethodsArray as $paymentMethod) {
            if ($paymentMethod["PaymentMethodCode"] == strtoupper($name)) {
                $this->_methodData = $paymentMethod;
                break;
            }
        }
        return $this;
    }
1323821
public static function request(String $name = NULL, $value = NULL)
    {
        return self::_method($name, $value, $_REQUEST, __FUNCTION__);
    }
623036
public function getMethod($name)
    {
        return (isset($this->_methods[$name])) ? $this->_methods[$name] : null;
    }
373285
private function getPlan(string $name): Plan
    {
        if (empty($this->plans[$name])) {
            throw new Exception\DomainException(
                sprintf(
                    'Invalid plan "%s" specified.',
                    $name
                )
            );
        }

        return new Plan($name, $this->plans[$name], $this->stepInterface);
    }
755050
public function request($method, $api_method, $body = NULL, $checksum)
    {
        /**
         * Check if the Merchant ID is set
         */
        if (empty($this->api_key)) {
            throw new \Exception("Please configure your ICEPAY Merchant ID.");
        }

        /**
         * Check if the Secret Code is set
         */
        if (empty($this->api_secret)) {
            throw new \Exception("Please configure your ICEPAY Secret Code.");
        }

        /**
         * Check if the CompletedURL is set
         */
        if (empty($this->api_completed_url)) {
            throw new \Exception("Please configure your setCompletedURL()");
        }

        /**
         * Check if the ErrorURL is set
         */
        if (empty($this->api_error_url)) {
            throw new \Exception("Please configure your setErrorURL()");
        }

        /**
         * Start a curl session
         */
        if (empty($this->ch) || !function_exists("curl_reset")) {
            $this->ch = curl_init();
        } else {
            curl_reset($this->ch);
        }

        /**
         * Set the curl options
         */
        curl_setopt($this->ch, CURLOPT_URL, $this->api_endpoint . $api_method);
        curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($this->ch, CURLOPT_TIMEOUT, 15);
        curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($this->ch, CURLOPT_HEADER, TRUE);

        /**
         * Possible output: 5.6.9
         */
        $php_version = phpversion();

        /**
         * Prepare the curl headers
         */
        $api_headers = array(
            "MerchantID: {$this->api_key}",
            "Checksum: {$checksum}",
            "User-Agent: ICEPAY API/{$this->api_version} PHP/{$php_version}",
            "Accept: application/json"
        );

        /**
         * If the body is not null, let curl post the request as json content
         */
        if ($body !== NULL) {
            $api_headers[] = "Content-Type: application/json";

            curl_setopt($this->ch, CURLOPT_POST, 1);
            curl_setopt($this->ch, CURLOPT_POSTFIELDS, json_encode($body));
        }

        /**
         * Set the curl headers for the payment server
         */
        curl_setopt($this->ch, CURLOPT_HTTPHEADER, $api_headers);

        /**
         * Set the SSL options
         */
        curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, TRUE);

        /**
         * Execute the request
         */
        $response = curl_exec($this->ch);

        /**
         * Invalid or no certificate authority found, using bundled information
         */
        if (curl_errno($this->ch) == 77 /* CURLE_SSL_CACERT_BADFILE */ || curl_errno($this->ch) == 60 /* CURLE_SSL_CACERT */) {
            curl_setopt($this->ch, CURLOPT_CAINFO, realpath(dirname(__FILE__) . '/Assets/icepay.pem'));

            $response = curl_exec($this->ch);
        }

//        /**
//         * Verifying peer certificate fails on OpenSSL 0.9 or earlier.
//         * We done all we could to check the certificate on the host.
//         * This webserver simply will not accept it and we need to connect.
//         */
//        Uncommenting this code block can be insecure, use at your own risk
//        if (strpos(curl_error($this->ch), 'certificate subject name') !== FALSE) {
//            curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);
//
//            $response = curl_exec($this->ch);
//        }

        /**
         * Check if we got any error, if so, exception it
         */
        if (curl_errno($this->ch)) {

            $exception_no = curl_errno($this->ch);
            $exception = curl_error($this->ch);

            curl_close($this->ch);
            $this->ch = NULL;

            throw new \Exception('Unable to reach the ICEPAY payment server (' . $exception_no . '):' . $exception);
        }

        /**
         * Separate headers and response body
         */
        $header_size = curl_getinfo($this->ch, CURLINFO_HEADER_SIZE);
        $response_header = substr($response, 0, $header_size);
        $response_body = substr($response, $header_size);

        /**
         * Close the connection
         */
        if (!function_exists("curl_reset")) {
            curl_close($this->ch);
            $this->ch = null;
        } else {
            curl_reset($this->ch);
            $this->ch = null;
        }

        /**
         * Verify response checksum. If it does not match, throw an exception.
         * Always require presence of a checksum header.
         */
        $parsed_headers = $this->parse_headers($response_header);
        if (isset($parsed_headers[0]["Checksum"])) {
            $checksumVerification = $this->generateChecksum(
                $this->api_endpoint .
                $api_method .
                $this->api_post .
                $this->api_key .
                $this->api_secret .
                $response_body
            );
            if ($checksumVerification != $parsed_headers[0]["Checksum"]) {
                throw new \Exception("Response checksum invalid");
            }
        }
        else
        {
            //if no checksum header was present in the response, the most likely cause is that the sender ID was invalid
            throw new \Exception("Response checksum not found. Verify your merchant ID.");
        }

        /**
         * Return the decoded json response
         */
        return json_decode($response_body);
    }
356555
public function get($name)
    {
        // get from cache
        if (isset($this->pool[$name])) {
            return $this->pool[$name];
        }
        
        // check if connection exists
        if (!isset($this->configuration[$name])) {
            throw new Exception('Connection with name ' . $name . ' not found');
        }
        
        // check if dsn exists
        if (!isset($this->configuration[$name]['dsn'])) {
            $this->configuration[$name]['dsn'] = null;
        }
        
        // check if connect options exists
        if (empty($this->configuration[$name]['connectOptions'])) {
            $this->configuration[$name]['connectOptions'] = null;
        }
        
        // init client
        $client = new Client(
            $this->configuration[$name]['dsn'],
            $this->configuration[$name]['connectOptions']
        );
        
        if (isset($this->configuration[$name]['mapping'])) {
            $client->map($this->configuration[$name]['mapping']);
        }
        
        if (isset($this->configuration[$name]['defaultDatabase'])) {
            $client->useDatabase($this->configuration[$name]['defaultDatabase']);
        }
        
        $this->pool[$name] = $client;
        
        return $client;
    }
1227671
public function get($name) {
        $this->runCopy();
        if (in_array($name, ['css', 'js', 'style', 'script'])) {
            $return = $this->{$name};
        } else {
            throw new \Exception(" '$name' doesn't Exists is the '" . __CLASS__ . "' class. ");
        }
        return $return;
    }
1186145
public function method($name)
    {
        if ( ! $this->object->hasMethod($name))
        {
            throw new UnexpectedValueException(
                "Method {$name} does not exist"
            );
        }

        return $this->extractComment($this->object->getMethod($name));
    }
318352
public function findByName($name)
    {
        if (is_null($name)) {
            throw new \Exception('name is required');
        }
        $role = $this->getRepository('\erdiko\users\entities\Role');

        return $role->findOneBy(array('name' => $name));
    }
1271984
public function get(string $name): Method
    {
        if (!$this->has($name)) {
            //Automatically creating constant
            $method = new Method($name);
            $this->add($method);

            return $method;
        }

        return parent::get($name);
    }
147253
protected function get($name)
    {
        if (isset($this->site[$name])) {
            return $this->site[$name];
        }

        throw new Exception("The property $name could not be found on the website ID " . (int)$this->id);
    }
1268752
public function createSlaveClients($name)
    {
        $slaves = $this->slaves($name);
        $workingSlaves = array();
        foreach ($slaves as $slave) {
            if (!isset($slave[9])) {
                throw new Exception('Can\' retrieve slave status');
            }
            if (!strstr($slave[9], 's_down') && !strstr($slave[9], 'disconnected')) {
                $workingSlaves[] = new Client($slave[3], $slave[5], null, '', 0, $this->_authPassword);
            }
        }
        return $workingSlaves;
    }
620656
public function getProcess($name)
    {
        if (!isset($this->processes[$name])) {
            throw new WorkflowException(sprintf('Unknown process "%s".', $name));
        }

        return $this->processes[$name];
    }
1073396
public function addMethod($method, $name = null)
    {
        if (is_array($method)) {
            require_once 'Zend/Server/Method/Definition.php';
            $method = new Zend_Server_Method_Definition($method);
        } elseif (!$method instanceof Zend_Server_Method_Definition) {
            require_once 'Zend/Server/Exception.php';
            throw new Zend_Server_Exception('Invalid method provided');
        }

        if (is_numeric($name)) {
            $name = null;
        }
        if (null !== $name) {
            $method->setName($name);
        } else {
            $name = $method->getName();
        }
        if (null === $name) {
            require_once 'Zend/Server/Exception.php';
            throw new Zend_Server_Exception('No method name provided');
        }

        if (!$this->_overwriteExistingMethods && array_key_exists($name, $this->_methods)) {
            require_once 'Zend/Server/Exception.php';
            throw new Zend_Server_Exception(sprintf('Method by name of "%s" already exists', $name));
        }
        $this->_methods[$name] = $method;
        return $this;
    }
290299
public function validatePayment(Icepay_PaymentObject_Interface_Abstract $payment) {
        /* Clear the generated URL */
        $this->resetURL();

        $this->data = (object) array_merge((array) $this->data, (array) $payment->getData());

        if (!$payment->getPaymentMethod())
            return $this;

        $paymentmethod = $payment->getBasicPaymentmethodClass();

        if (!$this->exists($payment->getCountry(), $paymentmethod->getSupportedCountries()))
            throw new Exception('Country not supported');

        if (!$this->exists($payment->getCurrency(), $paymentmethod->getSupportedCurrency()))
            throw new Exception('Currency not supported');

        if (!$this->exists($payment->getLanguage(), $paymentmethod->getSupportedLanguages()))
            throw new Exception('Language not supported');

        if (!$this->exists($payment->getIssuer(), $paymentmethod->getSupportedIssuers()) && $payment->getPaymentMethod() != null)
            throw new Exception('Issuer not supported');

        /* used for webservice call */
        $this->paymentObj = $payment;

        return $this;
    }
834637
public function create(string $name)
    {
        if ($this->locator->has($name)) {
            return $this->locator->get($name);
        }

        throw new \Exception(\sprintf('Filter "%s" was not found.', $name));
    }
1325925
protected function getPayId($payment) {
		if (!is_string($payment) and $payment instanceof Payment) {
			$payment = $payment->getPayId();
			if (!$payment) {
				throw new Exception("Given Payment object does not have payId. Please call paymentInit() first.");
			}
		}
		if (is_array($payment) and isset($payment["payId"])) {
			$payment = $payment["payId"];
		}
		if (!is_string($payment) or strlen($payment) != 15) {
			throw new Exception("Given Payment ID is not valid - it should be a string with length 15 characters.");
		}
		return $payment;
	}