/** * 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 ''; }
/** * Creates an instance of the Klarna Object * * @param String $myordernumber Current ordernumber * * @return Object $k Klarnaobject */ function piKlarnaCreateKlarnaInstance($myordernumber=false,$isoCode=false) { $piKlarnaConfig = array(); $shopId = false; $shopesecret = false; $countryIso = ""; $piKlarnaMyMode = 0; $piKlarnaConfig = Shopware()->Plugins()->Frontend()->PigmbhKlarnaPayment()->Config(); require_once dirname(__FILE__) . '/../api/Klarna.php'; require_once dirname(__FILE__) . '/../api/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc'; require_once dirname(__FILE__) . '/../api/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc'; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE); curl_setopt($ch, CURLOPT_CAINFO, "pathto/cacert.pem"); if ($myordernumber) { $sql = "Select shop_id FROM Pi_klarna_payment_multistore WHERE order_number = ?"; $shopId = Shopware()->Db()->fetchOne($sql, array($myordernumber)); $sql = "Select secret FROM Pi_klarna_payment_multistore WHERE order_number = ?"; $shopesecret = Shopware()->Db()->fetchOne($sql, array($myordernumber)); $sql = "Select liveserver FROM Pi_klarna_payment_multistore WHERE order_number = ?"; $piKlarnaLivemode = Shopware()->Db()->fetchOne($sql, array($myordernumber)); $sql = "SELECT id FROM s_order WHERE ordernumber = ?"; $orderId = Shopware()->Db()->fetchOne($sql, array($myordernumber)); $sql = "SELECT countryID FROM s_order_billingaddress WHERE orderID = ?"; $countryId = Shopware()->Db()->fetchOne($sql, array((int)$orderId)); $sql = "SELECT countryiso FROM s_core_countries WHERE id = ?"; $countryIso = Shopware()->Db()->fetchOne($sql, array((int)$countryId)); if ($piKlarnaLivemode == true) $piKlarnaMyMode = Klarna::LIVE; else $piKlarnaMyMode = Klarna::BETA; } else { if ($piKlarnaConfig->pi_klarna_liveserver == true) $piKlarnaMyMode = Klarna::LIVE; else $piKlarnaMyMode = Klarna::BETA; $shopId = $piKlarnaConfig->pi_klarna_Merchant_ID; $shopesecret = $piKlarnaConfig->pi_klarna_Secret; } $k = new Klarna(); if(!$shopId) throw new Exception("Es ist keine PClass vorhanden. Bitte kontaktieren Sie den Händler"); if(!$shopesecret) throw new Exception("Es ist kein Secret vorhanden. Bitte kontaktieren Sie den Händler"); $k->config( $shopId, $shopesecret, KlarnaCountry::DE, KlarnaLanguage::DE, KlarnaCurrency::EUR, $piKlarnaMyMode, 'json', dirname(__FILE__) . '/../classes/Pclass_' . $shopId . '.php', true, true ); if($myordernumber){ $k->setCountry($countryIso); } return $k; }
/** * Ajax request callback function */ function ajax_request() { // The $_REQUEST contains all the data sent via ajax if (isset($_REQUEST)) { if ('' != $this->partpay_eid && '' != $this->partpay_secret) { $klarna_eid = $this->partpay_eid; $klarna_secret = $this->partpay_secret; $klarna_testmode = $this->partpay_testmode; } elseif ('' != $this->invo_eid && '' != $this->invo_secret) { $klarna_eid = $this->invo_eid; $klarna_secret = $this->invo_secret; $klarna_testmode = $this->invo_testmode; } // Test mode or Live mode if ($klarna_testmode == 'yes') { // Disable SSL if in testmode $klarna_ssl = 'false'; $klarna_mode = Klarna::BETA; } else { // Set SSL if used in webshop if (is_ssl()) { $klarna_ssl = 'true'; } else { $klarna_ssl = 'false'; } $klarna_mode = Klarna::LIVE; } $k = new Klarna(); $k->config($klarna_eid, $klarna_secret, 'SE', 'SE', get_woocommerce_currency(), $klarna_mode, $pcStorage = 'json', $pcURI = '/srv/pclasses.json'); $pno_getadress = $_REQUEST['pno_getadress']; $return = array(); $k->setCountry('SE'); // Sweden only try { $addrs = $k->getAddresses($pno_getadress); foreach ($addrs as $addr) { //$return[] = $addr->toArray(); $return[] = array('email' => utf8_encode($addr->getEmail()), 'telno' => utf8_encode($addr->getTelno()), 'cellno' => utf8_encode($addr->getCellno()), 'fname' => utf8_encode($addr->getFirstName()), 'lname' => utf8_encode($addr->getLastName()), 'company' => utf8_encode($addr->getCompanyName()), 'careof' => utf8_encode($addr->getCareof()), 'street' => utf8_encode($addr->getStreet()), 'zip' => utf8_encode($addr->getZipCode()), 'city' => utf8_encode($addr->getCity()), 'country' => utf8_encode($addr->getCountry())); } } catch (Exception $e) { // $message = "{$e->getMessage()} (#{$e->getCode()})\n"; $return = $e; $return = array('get_address_message' => __('No address found', 'woocommerce-gateway-klarna')); } wp_send_json($return); // If you're debugging, it might be useful to see what was sent in the $_REQUEST // print_r($_REQUEST); } else { echo ''; die; } die; }
<?php require_once dirname(dirname(__FILE__)) . '/Klarna.php'; // Dependencies from http://phpxmlrpc.sourceforge.net/ require_once dirname(dirname(__FILE__)) . '/transport/xmlrpc-3.0.0.beta/lib/xmlrpc.inc'; require_once dirname(dirname(__FILE__)) . '/transport/xmlrpc-3.0.0.beta/lib/xmlrpc_wrappers.inc'; $k = new Klarna(); $k->config(0, 'sharedSecret', KlarnaCountry::SE, KlarnaLanguage::SV, KlarnaCurrency::SEK, Klarna::BETA, 'json', './pclasses.json'); $k->setCountry('se'); // Sweden only try { $addrs = $k->getAddresses('410321-9202'); // $addrs is a list of KlarnaAddr instances. echo "OK\n"; } catch (Exception $e) { echo "{$e->getMessage()} (#{$e->getCode()})\n"; }
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; }