public function getUrl() { $order = $this->getOrder(); $amount = number_format($order->getGrandTotal(), 2, '.', ''); $billing = $order->getBillingAddress(); $security = $this->getSecurityKey(); $reason1_template = Mage::getStoreConfig('payment/sofort/pnsofort_reason_1', $this->getStore()); $reason2_template = Mage::getStoreConfig('payment/sofort/pnsofort_reason_2', $this->getStore()); $tmp_orderid = $order->getRealOrderId(); $address = $order->getBillingAddress(); $tmp_name = $this->_getFirstname($address) . " " . $this->_getLastname($address); $tmp_date = Mage::getModel('core/date')->date('d.m.Y'); $tmp_storename = Mage::getStoreConfig('general/store_information/name', $this->getStore()); $reason1 = preg_replace('#\\{\\{ordernr\\}\\}#', $tmp_orderid, $reason1_template); $reason2 = preg_replace('#\\{\\{ordernr\\}\\}#', $tmp_orderid, $reason2_template); $reason1 = preg_replace('#Order No.:#', Mage::helper('pnsofortueberweisung')->__('Order No.: '), $reason1); $reason2 = preg_replace('#Order No.:#', Mage::helper('pnsofortueberweisung')->__('Order No.: '), $reason2); $reason1 = preg_replace('#\\{\\{name\\}\\}#', $tmp_name, $reason1); $reason2 = preg_replace('#\\{\\{name\\}\\}#', $tmp_name, $reason2); $reason1 = preg_replace('#\\{\\{date\\}\\}#', $tmp_date, $reason1); $reason2 = preg_replace('#\\{\\{date\\}\\}#', $tmp_date, $reason2); $reason1 = preg_replace('#\\{\\{shopname\\}\\}#', $tmp_storename, $reason1); $reason2 = preg_replace('#\\{\\{shopname\\}\\}#', $tmp_storename, $reason2); $reason1 = preg_replace('#\\{\\{transaction\\}\\}#', '-TRANSACTION-', $reason1); $reason2 = preg_replace('#\\{\\{transaction\\}\\}#', '-TRANSACTION-', $reason2); $reason1 = preg_replace('#[^a-zA-Z0-9+-\\.,\\s]#', '', $reason1); $reason2 = preg_replace('#[^a-zA-Z0-9+-\\.,\\s]#', '', $reason2); $success_url = Mage::getUrl('pnsofortueberweisung/sofort/return', array('orderId' => $order->getRealOrderId(), '_secure' => true)); $cancel_url = Mage::getUrl('pnsofortueberweisung/sofort/error', array('orderId' => $order->getRealOrderId())); $notification_url = Mage::getUrl('pnsofortueberweisung/sofort/notification', array('orderId' => $order->getRealOrderId(), 'secret' => $security)); $sObj = new SofortLib_Multipay(Mage::getStoreConfig('payment/sofort/configkey', $this->getStore())); $sObj->setVersion(self::MODULE_VERSION); $sObj->setAmount($amount, $order->getOrderCurrencyCode()); $sObj->setReason($reason1, $reason2); $sObj->setSuccessUrl($success_url); $sObj->setAbortUrl($cancel_url); $sObj->setNotificationUrl($notification_url); $sObj->addUserVariable($order->getRealOrderId()); //$sObj->setEmailCustomer($order->customer['email_address']); //$sObj->setPhoneNumberCustomer($order->customer['telephone']); $sObj->setSofortueberweisung(); $sObj->setSofortueberweisungCustomerprotection($this->getConfigData("pnsofort_customerprotection") == 1); $sObj->sendRequest(); if (!$sObj->isError()) { $url = $sObj->getPaymentUrl(); $tid = $sObj->getTransactionId(); $order->getPayment()->setTransactionId($tid)->setIsTransactionClosed(0); $order->getPayment()->setAdditionalInformation('sofort_transaction', $tid); $order->getPayment()->setAdditionalInformation('sofort_lastchanged', 0); $order->getPayment()->setAdditionalInformation('sofort_secret', $security)->save(); return $url; } else { $errors = $sObj->getErrors(); foreach ($errors as $error) { Mage::getSingleton('checkout/session')->addError(Mage::helper('pnsofortueberweisung')->localizeXmlError($error)); } return $cancel_url; } }
public function getUrl() { $order = $this->getOrder(); $session = Mage::getSingleton('core/session'); $amount = number_format($order->getGrandTotal(), 2, '.', ''); $security = $this->getSecurityKey(); $reason1 = Mage::helper('pnsofortueberweisung')->__('Order No.: ') . $order->getRealOrderId(); $reason1 = preg_replace('#[^a-zA-Z0-9+-\\.,]#', ' ', $reason1); $reason2 = Mage::getStoreConfig('general/store_information/name'); $reason2 = preg_replace('#[^a-zA-Z0-9+-\\.,]#', ' ', $reason2); $success_url = Mage::getUrl('pnsofortueberweisung/sofort/return', array('orderId' => $order->getRealOrderId(), '_secure' => true)); $cancel_url = Mage::getUrl('pnsofortueberweisung/sofort/error', array('orderId' => $order->getRealOrderId())); $notification_url = Mage::getUrl('pnsofortueberweisung/sofort/notification', array('orderId' => $order->getRealOrderId(), 'secret' => $security)); $sObj = new SofortLib_Multipay(Mage::getStoreConfig('payment/sofort/configkey')); $sObj->setVersion(self::MODULE_VERSION); $sObj->setAmount($amount, $order->getOrderCurrencyCode()); $sObj->setReason($reason1, $reason2); $sObj->setSuccessUrl($success_url); $sObj->setAbortUrl($cancel_url); $sObj->setNotificationUrl($notification_url); $sObj->addUserVariable($order->getRealOrderId()); $sObj->setEmailCustomer($order->getCustomerEmail()); $sObj->setSenderAccount($session->getLsBankCode(), $session->getLsAccountNumber(), $session->getLsHolder()); // set address $sObj->setLastschriftAddress($this->_getFirstname($order->getBillingAddress()), $this->_getLastname($order->getBillingAddress()), $this->_getStreet($order->getBillingAddress()), $this->_getNumber($order->getBillingAddress()), $this->_getPostcode($order->getBillingAddress()), $this->_getCity($order->getBillingAddress()), ''); //$sObj->setPhoneNumberCustomer($order->getCustomerTelephone()); $sObj->setLastschrift(); $sObj->sendRequest(); if (!$sObj->isError()) { $url = $sObj->getPaymentUrl(); $tid = $sObj->getTransactionId(); $order->getPayment()->setTransactionId($tid)->setIsTransactionClosed(0); $order->getPayment()->setAdditionalInformation('sofort_transaction', $tid); $order->getPayment()->setAdditionalInformation('sofort_lastchanged', 0); $order->getPayment()->setAdditionalInformation('sofort_secret', $security)->save(); return $url; } else { $errors = $sObj->getErrors(); foreach ($errors as $error) { Mage::getSingleton('checkout/session')->addError(Mage::helper('pnsofortueberweisung')->localizeXmlError($error)); } return $cancel_url; } }
function sendTransactionRequest($cart, $order, $doRedirect = true) { $session = JFactory::getSession(); $return_context = $session->getId(); //$this->_debug = $method->debug; //$this->debugLog('plgVmConfirmedOrder order number: ' . $order['details']['BT']->order_number, 'message'); vmdebug('SOFORT sendTransactionRequest'); if (!class_exists('VirtueMartModelOrders')) { require VMPATH_ADMIN . DS . 'models' . DS . 'orders.php'; } if (!class_exists('VirtueMartModelCurrency')) { require VMPATH_ADMIN . DS . 'models' . DS . 'currency.php'; } if (!class_exists('CurrencyDisplay')) { require VMPATH_ADMIN . DS . 'helpers' . DS . 'currencydisplay.php'; } if (!class_exists('TableVendors')) { require VMPATH_ADMIN . DS . 'tables' . DS . 'vendors.php'; } $this->getPaymentCurrency($this->_currentMethod); $email_currency = $this->getEmailCurrency($this->_currentMethod); $currency_code_3 = shopFunctions::getCurrencyByID($this->_currentMethod->payment_currency, 'currency_code_3'); $totalInPaymentCurrency = vmPSPlugin::getAmountInCurrency($order['details']['BT']->order_total, $this->_currentMethod->payment_currency); $cd = CurrencyDisplay::getInstance($cart->pricesCurrency); // Prepare data that should be stored in the database $dbValues['order_number'] = $order['details']['BT']->order_number; $dbValues['payment_name'] = $this->renderPluginName($this->_currentMethod, 'create_order'); $dbValues['virtuemart_paymentmethod_id'] = $cart->virtuemart_paymentmethod_id; $dbValues['cost_per_transaction'] = $this->_currentMethod->cost_per_transaction; $dbValues['cost_percent_total'] = $this->_currentMethod->cost_percent_total; $dbValues['payment_currency'] = $this->_currentMethod->payment_currency; $dbValues['email_currency'] = $email_currency; $dbValues['payment_order_total'] = $totalInPaymentCurrency['value']; $dbValues['tax_id'] = $this->_currentMethod->tax_id; $dbValues['sofort_custom'] = $return_context; $security = self::getSecurityKey(); $dbValues['security'] = $security; $this->debugLog('comes from' . (int) $doRedirect . ' order number' . $order['details']['BT']->order_number, "sendTransactionRequest ", 'debug'); if (!class_exists('SofortLib')) { require VMPATH_ROOT . DS . 'plugins' . DS . 'vmpayment' . DS . 'sofort' . DS . 'sofort' . DS . 'library' . DS . 'sofortLib.php'; } $sofort = new SofortLib_Multipay(trim($this->_currentMethod->configuration_key)); $sofort->setVersion(self::RELEASE); $sofort->setAmount($totalInPaymentCurrency['value'], $currency_code_3); $sofort->setReason($order['details']['BT']->order_number); $sofort->setSuccessUrl(self::getSuccessUrl($order)); $sofort->setAbortUrl(self::getCancelUrl($order)); $sofort->setNotificationUrl(self::getNotificationUrl($security, $order['details']['BT']->order_number)); $sofort->setSofortueberweisung(); $sofort->setSofortueberweisungCustomerprotection($this->_currentMethod->buyer_protection); $jlang = JFactory::getLanguage(); $lang = $jlang->getTag(); $langArray = explode("-", $lang); $lang = strtolower($langArray[1]); $sofort->setLanguageCode($lang); $sofort->sendRequest(); vmdebug('SOFORT sendTransactionRequest ... SofortLib_Multipay ... sendRequest()'); if ($sofort->isError()) { $errors = $sofort->getErrors(); vmdebug('SOFORT sendTransactionRequest ... SofortLib_Multipay ... getErrors()', $errors); $this->displayErrors($errors); $this->redirectToCart(); return; } $url = $sofort->getPaymentUrl(); $dbValues['sofort_response_transaction'] = $sofort->getTransactionId(); $this->storePSPluginInternalData($dbValues); if ($doRedirect) { $mainframe = JFactory::getApplication(); $mainframe->redirect($url); } }
/** * create the connection class and add order info * * @param Mage_Sales_Model_Order_Item $order * @param string $security key for information */ public function createPaymentFromOrder($order, $security = null) { // check if security key is given if ($security === null) { // get existing security key $security = $order->getPayment()->getAdditionalInformation('sofort_secret'); // generate new one if (empty($security)) { $security = $this->getSecurityKey(); } } // create new object $sObj = new SofortLib_Multipay(Mage::getStoreConfig('payment/sofort/configkey')); $sObj->setVersion(self::MODULE_VERSION); // set type $sObj->setSofortrechnung(); // basic information $sObj->addUserVariable($order->getRealOrderId()); $sObj->setEmailCustomer($order->getCustomerEmail()); $sObj->setSofortrechnungCustomerId($order->getCustomerId()); $sObj->setSofortrechnungOrderId($order->getRealOrderId()); // add order number and shop name $reason1 = Mage::helper('pnsofortueberweisung')->__('Order No.: ') . $order->getRealOrderId(); $reason1 = preg_replace('#[^a-zA-Z0-9+-\\.,]#', ' ', $reason1); $reason2 = Mage::getStoreConfig('general/store_information/name'); $reason2 = preg_replace('#[^a-zA-Z0-9+-\\.,]#', ' ', $reason2); $sObj->setReason($reason1, $reason2); // set amount $amount = number_format($order->getGrandTotal(), 2, '.', ''); $sObj->setAmount($amount, $order->getOrderCurrencyCode()); // setup urls $success_url = Mage::getUrl('pnsofortueberweisung/sofort/return', array('orderId' => $order->getRealOrderId(), '_secure' => true)); $cancel_url = Mage::getUrl('pnsofortueberweisung/sofort/error', array('orderId' => $order->getRealOrderId())); $notification_url = Mage::getUrl('pnsofortueberweisung/sofort/notification', array('orderId' => $order->getRealOrderId(), 'secret' => $security)); $sObj->setSuccessUrl($success_url); $sObj->setAbortUrl($cancel_url); $sObj->setNotificationUrl($notification_url); // items, shipping, discount $this->_appendItems($order, $sObj); // invoice address $address = $order->getBillingAddress(); $sObj->setSofortrechnungInvoiceAddress($this->_getFirstname($address), $this->_getLastname($address), $this->_getStreet($address), $this->_getNumber($address), $this->_getPostcode($address), $this->_getCity($address), $this->_getSalutation($address), $this->_getCountry($address), $this->_getNameAdditive($address), $this->_getStreetAdditive($address), $this->_getCompany($address)); // shipping address $address = $order->getShippingAddress(); $sObj->setSofortrechnungShippingAddress($this->_getFirstname($address), $this->_getLastname($address), $this->_getStreet($address), $this->_getNumber($address), $this->_getPostcode($address), $this->_getCity($address), $this->_getSalutation($address), $this->_getCountry($address), $this->_getNameAdditive($address), $this->_getStreetAdditive($address), $this->_getCompany($address)); return $sObj; }