/**
  * Returns the klarna transaction id.
  *
  * @return string
  */
 protected function getKlarnaTransactionId()
 {
     $orderNumber = $this->order['number'];
     try {
         if ($this->pluginExists('PigmbhKlarnaPayment')) {
             // eid / shop_id
             $sql = 'SELECT shop_id FROM Pi_klarna_payment_multistore WHERE order_number = ?';
             $multistore = Shopware()->Db()->query($sql, array($orderNumber))->fetchObject();
             // pclass
             $sql = 'SELECT pclassid FROM Pi_klarna_payment_pclass where ordernumber = ?';
             $pclass = Shopware()->Db()->query($sql, array($orderNumber))->fetchObject();
             // Transaction ID
             $sql = 'SELECT transactionid FROM Pi_klarna_payment_order_data WHERE order_number = ?';
             $order = Shopware()->Db()->query($sql, array($orderNumber))->fetchObject();
             return sprintf('%s_%s_%s', $order->transactionid, $pclass->pclassid, $multistore->shop_id);
         } elseif ($this->pluginExists('SwagPaymentKlarna') || $this->pluginExists('SwagPaymentKlarnaKpm')) {
             /*
              * @var Klarna $klarna
              */
             $this->klarnaService = Shopware()->Container()->get('KlarnaService');
             if (!empty($this->order['languageIso'])) {
                 $this->klarnaService->setLanguage($this->order['languageIso']);
             } else {
                 throw new Exception('order language missing');
             }
             if (!empty($this->order['billing']['country']['iso'])) {
                 $this->klarnaService->setCountry($this->order['billing']['country']['iso']);
             } else {
                 throw new Exception('order country missing');
             }
             if (!empty($this->order['currency'])) {
                 $this->klarnaService->setCurrency($this->order['currency']);
             } else {
                 throw new Exception('order currency missing');
             }
             /**
              * @var KlarnaPClass
              */
             $pclass = $this->getKlarnaPClass();
             if (!empty($pclass)) {
                 if (isset($this->order['payment']['name']) && $this->order['payment']['name'] == 'klarna_invoice') {
                     $classId = KlarnaPClass::INVOICE;
                 } else {
                     $classId = $pclass->getId();
                 }
                 return sprintf('%s_%s_%s', $this->order['transactionId'], $classId, $pclass->getEid());
             } else {
                 throw new Exception('No compatible pclass found');
             }
         } else {
             throw new Exception('No compatible Klarna payment plugin found');
         }
     } catch (Exception $e) {
         PyLog()->error('Sync:Order:PaymentKlarna', $e->getMessage());
     }
     return '';
 }
예제 #2
0
 function getKlarnaAddress()
 {
     if (JVM_VERSION >= 2) {
         require_once JPATH_ROOT . DS . 'plugins' . DS . 'vmpayment' . DS . 'klarna' . DS . 'klarna.php';
         require_once JPATH_ROOT . DS . 'plugins' . DS . 'vmpayment' . DS . 'klarna' . DS . 'klarna' . DS . 'api' . DS . 'klarnaaddr.php';
     } else {
         require_once JPATH_ROOT . DS . 'plugins' . DS . 'vmpayment' . DS . 'klarna.php';
         require_once JPATH_ROOT . DS . 'plugins' . DS . 'vmpayment' . DS . 'klarna' . DS . 'api' . DS . 'klarnaaddr.php';
     }
     $klarna = new Klarna();
     $q = "select * from #__virtuemart_paymentmethods where payment_element = 'klarna' and published = '1' limit 0,1";
     $db = JFactory::getDBO();
     $db->setQuery($q);
     $res = $db->loadAssoc();
     if (empty($res)) {
         return null;
     }
     $id = $res['virtuemart_paymentmethod_id'];
     jimport('joomla.html.parameter');
     $params = explode('|', $res['payment_params']);
     $obj = new stdclass();
     foreach ($params as $item) {
         $item = explode('=', $item);
         $key = $item[0];
         unset($item[0]);
         $item = implode('=', $item);
         if (!empty($item)) {
             $obj->{$key} = @json_decode($item);
         }
     }
     $cData = KlarnaHandler::countryData($obj, 'SWE');
     $language = KlarnaLanguage::fromCode('SE');
     $currency = KlarnaCurrency::fromCode($cData['currency_code']);
     $klarna->config($cData['eid'], $cData['secret'], $cData['country_code'], $language, $currency, $cData['mode']);
     /*
     	$country = JRequest::getVar('virtuemart_country_id', ''); 
     	
     	if (!empty($country) && (is_numeric($country)))
     {
       $q = 'select * from #__virtuemart_countries where virtuemart_country_id = '.$country.' limit 0,1'; 
       $db->setQuery($q); 
       $r = $db->loadAssoc(); 
       $e = $db->getErrorMsg(); 
       
       if (empty($r)) $c = 'se';
       else
       $c = strtolower($r['country_2_code']); 
       
     }
     else 
     */
     $c = 'se';
     $klarna->setCountry($c);
     $klarna->setLanguage($language);
     $klarna->setCurrency($currency);
     //Attempt to get the address(es) associated with the SSN/PNO.
     $pn = JRequest::getVar('socialNumber', '');
     $addrs = $klarna->getAddresses($pn);
     if (empty($addrs)) {
         return null;
     }
     $a = array();
     foreach ($addrs as $key => $addr) {
         $a = $addr->toArray();
         foreach ($a as $k => $v) {
             $a[$k] = utf8_encode($v);
         }
         return $a;
         //if (empty($ar)) return null;
         if ($addr->isCompany) {
             $a['company_name'] = $addr->getCompanyName();
         } else {
             $a['company_name'] = '';
         }
         $a['first_name'] = $addr->getFirstName();
         $a['last_name'] = $addr->getLastName();
         $a['address_1'] = $addr->getStreet();
         $a['email'] = $addr->getEmail();
         $a['phone_1'] = $addr->getTelno();
         $a['phone_2'] = $addr->getCellno();
         $a['address_2'] = $addr->getHouseExt();
         $a['zip'] = $addr->getZipCode();
         $a['city'] = $addr->getCity();
         return $a;
     }
     return null;
     /* If there exists several addresses you would want to output a list in 
          which the customer could choose the address which suits him/her. 
        */
     // Print them if available:
     foreach ($addrs as $key => $addr) {
         echo "<table>\n";
         // This only works if the right getAddresses type is used.
         if ($addr->isCompany) {
             echo "\t<tr><td>Company</td><td> {$addr->getCompanyName()} </td></tr>\n";
         } else {
             echo "\t<tr><td>First name</td><td>{$addr->getFirstName()}</td></tr>\n";
             echo "\t<tr><td>Last name</td><td>{$addr->getLastName()}</td></tr>\n";
         }
         echo "\t<tr><td>Street</td><td>{$addr->getStreet()}</td></tr>\n";
         echo "\t<tr><td>Zip code</td><td>{$addr->getZipCode()}</td></tr>\n";
         echo "\t<tr><td>City</td><td>{$addr->getCity()}</td></tr>\n";
         echo "\t<tr><td>Country</td><td>{$addr->getCountryCode()}</td></tr>\n";
         echo "</table>\n";
     }
     //Something went wrong
     return null;
     echo "{$e->getMessage()} (#{$e->getCode()})\n";
     return null;
     return null;
 }