public function __construct()
 {
     $this->VERSION = 'PHP' . phpversion() . ':3.0.6.2';
     Klarna::$debug = false;
 }
 public function __construct()
 {
     $this->VERSION = 'PHP' . phpversion() . ':VirtueMart:2.0.12f';
     Klarna::$debug = false;
 }
 public function __construct()
 {
     $this->VERSION = 'PHP:VirtueMart2:' . KLARNA_MODULE_VERSION . ':r74';
     Klarna::$debug = false;
 }
Beispiel #4
0
 /**
  * Initializes the Klarna object accordingly to the set config object.
  *
  * @ignore Do not show this in PHPDoc.
  * @throws KlarnaException|Exception
  * @return void
  */
 protected function init()
 {
     $this->hasFields('eid', 'secret', 'mode', 'pcStorage', 'pcURI');
     if (!is_int($this->config['eid'])) {
         $this->config['eid'] = intval($this->config['eid']);
     }
     if ($this->config['eid'] <= 0) {
         throw new Exception("Config field 'eid' is not valid!", 50001);
     }
     if (!is_string($this->config['secret'])) {
         $this->config['secret'] = strval($this->config['secret']);
     }
     if (strlen($this->config['secret']) == 0) {
         throw new Exception("Config field 'secret' not set!", 50001);
     }
     //Set the shop id and secret.
     $this->eid = $this->config['eid'];
     $this->secret = $this->config['secret'];
     if (!is_numeric($this->config['country']) && strlen($this->config['country']) == 2) {
         $this->setCountry($this->config['country']);
     } else {
         //Set the country specific attributes.
         try {
             $this->hasFields('country', 'language', 'currency');
             //If hasFields doesn't throw exception we can set them all.
             $this->setCountry($this->config['country']);
             $this->setLanguage($this->config['language']);
             $this->setCurrency($this->config['currency']);
         } catch (Exception $e) {
             //fields missing for country, language or currency
             $this->country = $this->language = $this->currency = null;
         }
     }
     //Set addr and port according to mode.
     $this->mode = (int) $this->config['mode'];
     if ($this->mode === self::LIVE) {
         $this->addr = self::$live_addr;
         $this->ssl = true;
     } else {
         $this->addr = self::$beta_addr;
         $this->ssl = true;
     }
     try {
         $this->hasFields('ssl');
         $this->ssl = (bool) $this->config['ssl'];
     } catch (Exception $e) {
         //No 'ssl' field ignore it...
     }
     if ($this->ssl) {
         $this->port = 443;
     } else {
         $this->port = 80;
     }
     try {
         $this->hasFields('candice');
         self::$candice = (bool) $this->config['candice'];
     } catch (Exception $e) {
         //No 'candice' field ignore it...
     }
     try {
         $this->hasFields('xmlrpcDebug');
         Klarna::$xmlrpcDebug = $this->config['xmlrpcDebug'];
     } catch (Exception $e) {
         //No 'xmlrpcDebug' field ignore it...
     }
     try {
         $this->hasFields('debug');
         Klarna::$debug = $this->config['debug'];
     } catch (Exception $e) {
         //No 'debug' field ignore it...
     }
     $this->pcStorage = $this->config['pcStorage'];
     $this->pcURI = $this->config['pcURI'];
     $this->xmlrpc = new xmlrpc_client('/', $this->addr, $this->port, $this->ssl ? 'https' : 'http');
     $this->xmlrpc->request_charset_encoding = 'ISO-8859-1';
 }
Beispiel #5
0
 /**
  * Initializes the Klarna object accordingly to the set config object.
  *
  * @throws KlarnaException
  * @return void
  */
 protected function init()
 {
     $this->hasFields('eid', 'secret', 'mode', 'pcStorage', 'pcURI');
     if (!is_int($this->config['eid'])) {
         $this->config['eid'] = intval($this->config['eid']);
     }
     if ($this->config['eid'] <= 0) {
         throw new Klarna_ConfigFieldMissingException('eid');
     }
     if (!is_string($this->config['secret'])) {
         $this->config['secret'] = strval($this->config['secret']);
     }
     if (strlen($this->config['secret']) == 0) {
         throw new Klarna_ConfigFieldMissingException('secret');
     }
     //Set the shop id and secret.
     $this->_eid = $this->config['eid'];
     $this->_secret = $this->config['secret'];
     //Set the country specific attributes.
     try {
         $this->hasFields('country', 'language', 'currency');
         //If hasFields doesn't throw exception we can set them all.
         $this->setCountry($this->config['country']);
         $this->setLanguage($this->config['language']);
         $this->setCurrency($this->config['currency']);
     } catch (Exception $e) {
         //fields missing for country, language or currency
         $this->_country = $this->_language = $this->_currency = null;
     }
     //Set addr and port according to mode.
     $this->mode = (int) $this->config['mode'];
     $this->_url = array();
     // If a custom url has been added to the config, use that as xmlrpc
     // recipient.
     if (isset($this->config['url'])) {
         $this->_url = parse_url($this->config['url']);
         if ($this->_url === false) {
             $message = "Configuration value 'url' could not be parsed. " . "(Was: '{$this->config['url']}')";
             Klarna::printDebug(__METHOD__, $message);
             throw new InvalidArgumentException($message);
         }
     } else {
         $this->_url['scheme'] = 'https';
         if ($this->mode === self::LIVE) {
             $this->_url['host'] = self::$_live_addr;
         } else {
             $this->_url['host'] = self::$_beta_addr;
         }
         if (isset($this->config['ssl']) && (bool) $this->config['ssl'] === false) {
             $this->_url['scheme'] = 'http';
         }
     }
     // If no port has been specified, deduce from url scheme
     if (!array_key_exists('port', $this->_url)) {
         if ($this->_url['scheme'] === 'https') {
             $this->_url['port'] = 443;
         } else {
             $this->_url['port'] = 80;
         }
     }
     try {
         $this->hasFields('candice');
         self::$_candice = (bool) $this->config['candice'];
     } catch (Exception $e) {
         //No 'candice' field ignore it...
     }
     try {
         $this->hasFields('xmlrpcDebug');
         Klarna::$xmlrpcDebug = $this->config['xmlrpcDebug'];
     } catch (Exception $e) {
         //No 'xmlrpcDebug' field ignore it...
     }
     try {
         $this->hasFields('debug');
         Klarna::$debug = $this->config['debug'];
     } catch (Exception $e) {
         //No 'debug' field ignore it...
     }
     $this->pcStorage = $this->config['pcStorage'];
     $this->pcURI = $this->config['pcURI'];
     // Default path to '/' if not set.
     if (!array_key_exists('path', $this->_url)) {
         $this->_url['path'] = '/';
     }
     $this->xmlrpc = new xmlrpc_client($this->_url['path'], $this->_url['host'], $this->_url['port'], $this->_url['scheme']);
     $this->xmlrpc->request_charset_encoding = 'ISO-8859-1';
 }
    /**
     * Payment form on checkout page
     *
     * @since 1.0.0
     */
    function payment_fields()
    {
        global $woocommerce;
        if ('yes' == $this->testmode) {
            ?>
			<p><?php 
            _e('TEST MODE ENABLED', 'woocommerce-gateway-klarna');
            ?>
</p>
		<?php 
        }
        $klarna = new Klarna();
        /**
         * Setup Klarna configuration
         */
        $country = $this->klarna_helper->get_klarna_country();
        $this->configure_klarna($klarna, $country);
        Klarna::$xmlrpcDebug = false;
        Klarna::$debug = false;
        // apply_filters to cart total so we can filter this if needed
        $klarna_cart_total = $woocommerce->cart->total;
        $sum = apply_filters('klarna_cart_total', $klarna_cart_total);
        // Cart total.
        $flag = KlarnaFlags::CHECKOUT_PAGE;
        // or KlarnaFlags::PRODUCT_PAGE, if you want to do it for one item.
        // Description
        if ($this->description) {
            $klarna_description = $this->description;
            // apply_filters to the description so we can filter this if needed
            echo '<p>' . apply_filters('klarna_invoice_description', $klarna_description) . '</p>';
        }
        // For countries other than NO do the old thing
        $pclass_type = $this->pclass_type;
        $klarna_select_pclass_element = $this->id . '_pclass';
        $klarna_dob_element = $this->id . '_pno';
        include KLARNA_DIR . 'views/public/payment-fields-invoice.php';
    }