/** * @return \Klarna */ protected function getKlarna() { $this->klarna->config($this->config->eid, $this->config->secret, $this->config->country, $this->config->language, $this->config->currency, $this->config->mode); $this->klarna->clear(); $rp = new \ReflectionProperty($this->klarna, 'xmlrpc'); $rp->setAccessible(true); /** @var \xmlrpc_client $xmlrpc */ $xmlrpc = $rp->getValue($this->klarna); $xmlrpc->verifyhost = $this->config->xmlRpcVerifyHost; $xmlrpc->verifypeer = $this->config->xmlRpcVerifyPeer; $rp->setAccessible(false); return $this->klarna; }
public function getMonthlyCoast($cart, $countries, $country) { if (!$this->klarna->active) { return; } $klarna = new Klarna(); $klarna->config(Configuration::get('KLARNA_STORE_ID_' . $countries[$country->iso_code]['name']), Configuration::get('KLARNA_SECRET_' . $countries[$country->iso_code]['name']), $countries[$country->iso_code]['code'], $countries[$country->iso_code]['langue'], $countries[$country->iso_code]['currency'], Configuration::get('KLARNA_MOD'), 'mysql', array('user' => _DB_USER_, 'passwd' => _DB_PASSWD_, 'dsn' => _DB_SERVER_, 'db' => _DB_NAME_, 'table' => _DB_PREFIX_ . 'klarna_payment_pclasses')); $accountPrice = array(); $pclasses = array_merge($klarna->getPClasses(KlarnaPClass::ACCOUNT), $klarna->getPClasses(KlarnaPClass::CAMPAIGN)); $total = (double) $cart->getOrderTotal(); foreach ($pclasses as $val) { if ($val->getMinAmount() < $total) { $accountPrice[$val->getId()] = array('price' => KlarnaCalc::calc_monthly_cost($total, $val, KlarnaFlags::CHECKOUT_PAGE), 'month' => (int) $val->getMonths(), 'description' => htmlspecialchars_decode(Tools::safeOutput($val->getDescription()))); } } return $accountPrice; }
<?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'); $invNo = '123456'; try { $k->sendInvoice($invNo); echo "OK\n"; } catch (Exception $e) { echo "{$e->getMessage()} (#{$e->getCode()})\n"; }
/** * 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; }
/** * Fetches PClass * * @param String $piKlarnaEid ShopId * @param String $piKlarnaSecret ShopSecret * * @return String Result message */ function piKlarnaFetchKlarnaPClass($piKlarnaEid, $piKlarnaSecret) { if ($piKlarnaEid && $piKlarnaSecret) { 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); $piKlarnaConfig = Shopware()->Plugins()->Frontend()->PigmbhKlarnaPayment()->Config(); // $sql = "SELECT shopID FROM s_core_plugin_configs WHERE name LIKE 'pi_klarna_Merchant_ID' AND value like ?"; // $piKlarnaShopId = Shopware()->Db()->fetchOne($sql, array("%" . $piKlarnaEid . "%")); // if($piKlarnaShopId){ // $sql = "SELECT value FROM s_core_plugin_configs WHERE name LIKE 'pi_klarna_liveserver' AND shopID = ?"; // $piKlarnaLivecheck = $piKlarnaConfig->pi_klarna_liveserver; // $piKlarnaLivecheckSub = substr($piKlarnaLivecheck, -3, -2); if ($piKlarnaConfig->pi_klarna_liveserver) { $mymode = Klarna::LIVE; } else { $mymode = Klarna::BETA; } $countrys=Array(81,59,73,154,164,209); $currencys=Array(2,3,2,2,1,0); $languages=Array(28,37,97,101,27,138); $countryNames=Array('Deutschland','Dänemark','Finnland','Niederlande','Norwegen','Schweden'); $counter=0; $errortext=""; $piKlarnaErrorText=""; for($i=0;$i<count($countrys);$i++){ $k = new Klarna(); $k->config( $piKlarnaEid, $piKlarnaSecret, KlarnaCountry::DE, KlarnaLanguage::DE, KlarnaCurrency::EUR, $mymode, 'json', dirname(__FILE__) . '/../classes/Pclass_' . $piKlarnaEid . '.php', true, true ); try{ if($i==0)$piKlarnaErrorText='Ratenzahlungsmodalitäten für folgende Länder gespeichert: <br />'; $k->fetchPClasses($countrys[$i],$languages[$i],$currencys[$i]); $counter++; $piKlarnaErrorText .= "<b>" . $countryNames[$i] . "</b>"; $piKlarnaErrorText .=", "; } catch(Exception $e){ $errortext= $e->getMessage(). ' (#' . $e->getCode() . ')'; } } $rest = substr($piKlarnaErrorText, 0, -2); if($counter==0) return $errortext; else return $rest; } }
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; }
public function setPayment($type) { $address_invoice = new Address((int) $this->context->cart->id_address_invoice); $country = new Country((int) $address_invoice->id_country); $currency = new Currency((int) $this->context->cart->id_currency); if (!$this->verifCountryAndCurrency($country, $currency)) { return false; } $klarna = new Klarna(); $klarnaInt = new KlarnaIntegration($klarna); $klarna->config(Configuration::get('KLARNA_STORE_ID_' . $this->countries[$country->iso_code]['name']), Configuration::get('KLARNA_SECRET_' . $this->countries[$country->iso_code]['name']), $this->countries[$country->iso_code]['code'], $this->countries[$country->iso_code]['langue'], $this->countries[$country->iso_code]['currency'], Configuration::get('KLARNA_MOD'), 'mysql', $this->_getDb()); if ($type == 'invoice' && Configuration::get('KLARNA_INVOICE_FEE_' . $this->countries[$country->iso_code]['name']) > 0 && !$this->isInCart($this->context->cart, (int) Configuration::get('KLARNA_INV_FEE_ID_' . $this->countries[$country->iso_code]['name']))) { $this->context->cart->updateQty(1, (int) Configuration::get('KLARNA_INV_FEE_ID_' . $this->countries[$country->iso_code]['name'])); $productInvoicefee = new Product((int) Configuration::get('KLARNA_INV_FEE_ID_' . $this->countries[$country->iso_code]['name'])); $productInvoicefee->addStockMvt(1, 1); $productInvoicefee->update(); } $this->initReservation($klarna, $this->context->cart, $this->context->customer, isset($_POST['klarna_house_number']) ? htmlentities($_POST['klarna_house_number'], ENT_QUOTES, 'ISO-8859-1') : null, isset($_POST['klarna_house_ext']) ? htmlentities($_POST['klarna_house_ext'], ENT_QUOTES, 'ISO-8859-1') : null); if (Tools::isSubmit('klarna_pno')) { $pno = Tools::safeOutput(Tools::getValue('klarna_pno')); } else { $day = $_POST['klarna_pno_day'] < 10 ? '0' . (int) $_POST['klarna_pno_day'] : (int) $_POST['klarna_pno_day']; $month = $_POST['klarna_pno_month'] < 10 ? '0' . (int) $_POST['klarna_pno_month'] : (int) $_POST['klarna_pno_month']; $pno = Tools::safeOutput($day . $month . Tools::getValue('klarna_pno_year')); } $pclass = $type == 'invoice' ? KlarnaPClass::INVOICE : (int) Tools::getValue('paymentAccount'); try { if ($country->iso_code == 'DE' || $country->iso_code == 'NL') { if ($this->context->customer->id_gender != 1 && $this->context->customer->id_gender != 2 && $this->context->customer->id_gender != 3) { $gender = (int) $_POST['klarna_gender']; $customer = new Customer($this->context->customer->id); $customer->id_gender = (int) $_POST['klarna_gender']; $Customer->birthday = (int) $_POST['klarna_pno_year'] . '-' . $month . '-' . $day; $customer->update(); } else { $gender = $this->context->customer->id_gender == 1 ? 1 : 0; } } else { $gender = null; } $result = $klarnaInt->reserve($pno, $gender, -1, KlarnaFlags::NO_FLAG, (int) $pclass); // Here we get the reservation number or invoice number $rno = $result[0]; Db::getInstance()->autoExecute(_DB_PREFIX_ . 'klarna_rno', array('id_cart' => (int) $this->context->cart->id, 'rno' => pSQL($rno), 'pno' => pSQL($pno), 'house_number' => isset($_POST['klarna_house_number']) ? pSQL($_POST['klarna_house_number']) : null, 'house_ext' => isset($_POST['klarna_house_ext']) ? pSQL($_POST['klarna_house_ext']) : null, 'state' => self::RESERVED, 'type' => pSQL($type), 'pclass' => $type == 'invoice' ? null : (int) Tools::getValue('paymentAccount')), 'INSERT'); $updateResult = $klarnaInt->updateOrderNo($rno, (int) $this->context->cart->id); if ($result[1] == KlarnaFlags::PENDING) { $this->validateOrder((int) $this->context->cart->id, Configuration::get('KLARNA_PAYMENT_PENDING'), (double) $this->context->cart->getOrderTotal(), $this->displayName, null, array(), null, false, $this->context->cart->secure_key); } else { if ($result[1] == KlarnaFlags::ACCEPTED) { $this->validateOrder((int) $this->context->cart->id, Configuration::get('KLARNA_PAYMENT_ACCEPTED'), (double) $this->context->cart->getOrderTotal(), $this->displayName, null, array(), null, false, $this->context->cart->secure_key); } } $redirect = __PS_BASE_URI__ . 'index.php?controller=order-confirmation&id_cart=' . (int) $this->context->cart->id . '&id_module=' . (int) $this->id . '&id_order=' . (int) $this->currentOrder . '&key=' . $this->context->cart->secure_key; header('Location: ' . $redirect); exit; } catch (Exception $e) { /*remove invoiceFee if existe*/ $this->context->cart->deleteProduct((int) Configuration::get('KLARNA_INV_FEE_ID_' . $this->countries[$country->iso_code]['name'])); return array('error' => true, 'message' => Tools::safeOutput(utf8_encode($e->getMessage()))); } }