/** * Perform the reserve_amount call. * * @param int $paymentPlan pclass id * @param object $addrs KlarnaAddr object * @param string $option invoice, part or spec * * @return void */ public function performReservation($paymentPlan, $addrs, $option) { global $order; $addrHandler = new KlarnaAddressXtc(); // Fixes potential security problem. $order->delivery = array_merge($order->delivery, $addrHandler->klarnaAddrToXtcAddr($addrs)); // $_POST doesn't have phone number anymore, so it won't be // properly set by buildXtCommerceAddress $order->delivery['telephone'] = $addrs->getTelno(); $order->billing['telephone'] = $addrs->getTelno(); $order->customer['telephone'] = $addrs->getTelno(); $addrs->setEmail($order->customer['email_address']); $pno = $_POST['klarna_pno']; $reference = KiTT_String::encode($_POST['klarna_reference']); if ($_POST["klarna_{$option}_invoice_type"] == 'company' || $addrs->isCompany) { // Company purchase, set the firstname in osCommerce to the reference // So we don't lose it. $order->delivery['firstname'] = KiTT_String::decode($reference); // set Ref: comment to make sure KO finds it $this->_klarna->setComment("Ref: " . $reference); // Set First and Last name so KO doesn't complain one is missing. $name = explode(' ', $reference, 2); $addrs->setFirstName(strlen($name[0] > 0) ? $name[0] : " "); if (strlen($name[1]) > 0) { $addrs->setLastName($name[1]); } else { $addrs->setLastName(" "); } //Set Company to order $order->delivery['company'] = KiTT_String::decode($addrs->getCompanyName()); } else { $order->delivery['company'] = ''; } if (strlen($order->info['comments']) > 0) { $this->_klarna->addComment(KiTT_String::encode($order->info['comments'])); } $this->_klarna->setReference($reference, ""); $shipping = $addrs; $gender = null; if (KiTT_CountryLogic::needGender($this->_country)) { $gender = $_POST['klarna_gender']; } if (KiTT_CountryLogic::shippingSameAsBilling($this->_country)) { $billing = $shipping; $order->billing = $order->delivery; } else { $billing = $addrHandler->xtcAddressToKlarnaAddr($order->billing); } try { $this->_klarna->setAddress(KlarnaFlags::IS_SHIPPING, $shipping); $this->_klarna->setAddress(KlarnaFlags::IS_BILLING, $billing); $result = $this->_klarna->reserveAmount($pno, $gender, -1, KlarnaFlags::NO_FLAG, $paymentPlan); $this->_handleResponse($option, $result, $country); } catch (KlarnaException $e) { if ($e instanceof Klarna_ArgumentNotSetException || $e instanceof Klarna_InvalidPNOException) { $this->setError(htmlentities($this->translate('error_title_2'), ENT_COMPAT, 'UTF-8'), $option); } else { $this->setError(htmlentities($e->getMessage()) . " (#" . $e->getCode() . ")", $option); } xtc_redirect($this->errorLink(FILENAME_CHECKOUT_PAYMENT, '', 'SSL', true, false)); } }
/** * Build an xtcommerce address Array from a KlarnaAddr object. * * @param object $address KlarnaAddr object * * @return array xtcommerce address */ public function klarnaAddrToXtcAddr($address) { global $order; return array('firstname' => KiTT_String::decode($address->getFirstName()), 'lastname' => KiTT_String::decode($address->getLastName()), 'street_address' => KiTT_String::decode($address->getStreet() . ' ' . $address->getHouseNumber() . ' ' . $address->getHouseExt()), 'postcode' => KiTT_String::decode($address->getZipCode()), 'city' => KiTT_String::decode($address->getCity()), 'telephone' => KiTT_String::decode($address->getTelNo()), 'email_address' => KiTT_String::decode($address->getEmail()), 'company' => KiTT_String::decode($address->getCompanyName()), 'state' => $order->delivery['state'], 'zone_id' => $order->delivery['zone_id'], 'country_id' => $order->delivery['country_id'], 'country' => array('id' => $order->delivery['country']['id'], 'title' => $order->delivery['country']['title'], 'iso_code_2' => $order->delivery['country']['iso_code_2'], 'iso_code_3' => $order->delivery['country']['iso_code_3'])); }