protected function _getPostData() { $data = parent::_getPostData(); if ($this->_apiToken == '') { throw Mage::exception('Pay_Payment_Helper_Api', 'apiToken not set', 1); } else { $data['token'] = $this->_apiToken; } if (!isset($this->_postData['transactionId'])) { throw Mage::exception('Pay_Payment_Helper_Api', 'transactionId is not set', 1); } return $data; }
protected function _getPostData() { $data = parent::_getPostData(); // Checken of alle verplichte velden geset zijn if ($this->_apiToken == '') { throw Mage::exception('Pay_Payment_Helper_Api', 'apiToken not set', 1); } else { $data['token'] = $this->_apiToken; } if (empty($this->_serviceId)) { throw Mage::exception('Pay_Payment_Helper_Api', 'apiToken not set', 1); } else { $data['serviceId'] = $this->_serviceId; } return $data; }
public function refund(Varien_Object $payment, $amount) { $order = $payment->getOrder(); $store = $order->getStore(); $serviceId = Mage::getStoreConfig('pay_payment/general/serviceid', $store); $apiToken = Mage::getStoreConfig('pay_payment/general/apitoken', $store); $useBackupApi = Mage::getStoreConfig('pay_payment/general/use_backup_api', $store); $backupApiUrl = Mage::getStoreConfig('pay_payment/general/backup_api_url', $store); if ($useBackupApi == 1) { Pay_Payment_Helper_Api::_setBackupApiUrl($backupApiUrl); } $parentTransactionId = $payment->getParentTransactionId(); $apiRefund = Mage::helper('pay_payment/api_refund'); $apiRefund instanceof Pay_Payment_Helper_Api_Refund; $apiRefund->setApiToken($apiToken); $apiRefund->setServiceId($serviceId); $apiRefund->setTransactionId($parentTransactionId); $amount = (int) round($amount * 100); $apiRefund->setAmount($amount); $apiRefund->doRequest(); return $this; }
public function getTransactionInfo($transactionId, $store = null) { if ($store == null) { $store = Mage::app()->getStore(); } $helperApi = Mage::helper('pay_payment/api_info'); /* @var $helperApi Pay_Payment_Helper_Api_Info */ $apiToken = $store->getConfig('pay_payment/general/apitoken'); $useBackupApi = Mage::getStoreConfig('pay_payment/general/use_backup_api', $store); $backupApiUrl = Mage::getStoreConfig('pay_payment/general/backup_api_url', $store); if ($useBackupApi == 1) { Pay_Payment_Helper_Api::_setBackupApiUrl($backupApiUrl); } $helperApi->setApiToken($apiToken); $helperApi->setTransactionId($transactionId); $transactionInfo = $helperApi->doRequest(); return $transactionInfo; }
public function loadOptions($store = null) { if ($store == null) { $store = Mage::app()->getStore(); } $serviceId = $store->getConfig('pay_payment/general/serviceid'); //$serviceId = Mage::getStoreConfig('pay_payment/general/serviceid', $store); $apiToken = $store->getConfig('pay_payment/general/apitoken'); //$apiToken = Mage::getStoreConfig('pay_payment/general/apitoken', $store); $useBackupApi = Mage::getStoreConfig('pay_payment/general/use_backup_api', $store); $backupApiUrl = Mage::getStoreConfig('pay_payment/general/backup_api_url', $store); if ($useBackupApi == 1) { Pay_Payment_Helper_Api::_setBackupApiUrl($backupApiUrl); } $api = Mage::helper('pay_payment/api_getservice'); /* @var $api Pay_Payment_Helper_Api_GetService */ $api->setApiToken($apiToken); $api->setServiceId($serviceId); $data = $api->doRequest(); $this->_saveOptions($data, $store); }
public function redirectAction() { Mage::log('Starting transaction', null, 'paynl.log'); $helper = Mage::helper('pay_payment'); $session = Mage::getSingleton('checkout/session'); /* @var $session Mage_Checkout_Model_Session */ if ($session->getLastRealOrderId()) { Mage::log('Order found in session, orderId: ' . $session->getLastRealOrderId(), null, 'paynl.log'); $order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId()); /* @var $order Mage_Sales_Model_Order */ $payment = $order->getPayment(); if ($order->getId()) { Mage::log('Order loaded from session, orderId: ' . $session->getLastRealOrderId(), null, 'paynl.log'); $optionId = $session->getOptionId(); $optionSubId = $session->getOptionSubId(); $birthdayDay = $session->getBirthdayDay(); $birthdayMonth = $session->getBirthdayMonth(); $birthdayYear = $session->getBirthdayYear(); $birthdate = ''; if (!empty($birthdayDay) && !empty($birthdayMonth) && !empty($birthdayYear)) { $birthdate = $birthdayDay . '-' . $birthdayMonth . '-' . $birthdayYear; } $iban = $session->getIban(); $serviceId = Mage::getStoreConfig('pay_payment/general/serviceid', Mage::app()->getStore()); $apiToken = Mage::getStoreConfig('pay_payment/general/apitoken', Mage::app()->getStore()); $useBackupApi = Mage::getStoreConfig('pay_payment/general/use_backup_api', Mage::app()->getStore()); $backupApiUrl = Mage::getStoreConfig('pay_payment/general/backup_api_url', Mage::app()->getStore()); if ($useBackupApi == 1) { Pay_Payment_Helper_Api::_setBackupApiUrl($backupApiUrl); } $amount = $order->getGrandTotal(); $sendOrderData = Mage::getStoreConfig('pay_payment/general/send_order_data', Mage::app()->getStore()); $api = Mage::helper('pay_payment/api_start'); /* @var $api Pay_Payment_Helper_Api_Start */ $api->setExtra2($order->getCustomerEmail()); if ($sendOrderData == 1) { $items = $order->getItemsCollection(); foreach ($items as $item) { /* @var $item Mage_Sales_Model_Order_Item */ $productId = $item->getId(); $description = $item->getName(); $price = $item->getPriceInclTax(); $taxAmount = $item->getTaxAmount(); $quantity = $item->getQtyOrdered(); if ($price != 0) { $taxClass = $helper->calculateTaxClass($price, $taxAmount / $quantity); $price = round($price * 100); $api->addProduct($productId, $description, $price, $quantity, $taxClass); } } $discountAmount = $order->getDiscountAmount(); if ($discountAmount < 0) { $api->addProduct(0, 'Korting (' . $order->getDiscountDescription() . ')', round($discountAmount * 100), 1, 'N'); } $shipping = $order->getShippingInclTax(); if ($shipping > 0) { $shippingTax = $order->getShippingTaxAmount(); $shippingTaxClass = $helper->calculateTaxClass($shipping, $shippingTax); $shipping = round($shipping * 100); if ($shipping != 0) { $api->addProduct('0', 'Verzendkosten', $shipping, 1, $shippingTaxClass); } } $extraFee = $order->getPaymentCharge(); if ($extraFee != 0) { $code = $payment->getMethod(); $taxClass = $helper->getPaymentChargeTaxClass($code); $taxCalculationModel = Mage::getSingleton('tax/calculation'); $request = $taxCalculationModel->getRateRequest($order->getShippingAddress(), $order->getBillingAddress()); $request->setStore(Mage::app()->getStore()); $rate = $taxCalculationModel->getRate($request->setProductClassId($taxClass)); $taxCode = $helper->getTaxCodeFromRate($rate); $api->addProduct('0', Mage::getStoreConfig('pay_payment/general/text_payment_charge', Mage::app()->getStore()), round($extraFee * 100), 1, $taxCode); } $arrEnduser = array(); $shippingAddress = $order->getShippingAddress(); $arrEnduser['gender'] = substr($order->getCustomerGender(), 0, 1); if (empty($birthdate)) { $birthdate = $order->getCustomerDob(); if (!empty($birthdate)) { $birthdate = substr($birthdate, 0, strpos($birthdate, ' ')); list($year, $month, $day) = explode('-', $birthdate); $birthdate = $day . '-' . $month . '-' . $year; } } if (isset($iban)) { $arrEnduser['iban'] = $iban; } $arrEnduser['dob'] = $birthdate; $arrEnduser['emailAddress'] = $order->getCustomerEmail(); $billingAddress = $order->getBillingAddress(); if (!empty($shippingAddress)) { $arrEnduser['initials'] = substr($shippingAddress->getFirstname(), 0, 1); $arrEnduser['lastName'] = substr($shippingAddress->getLastname(), 0, 30); $arrEnduser['phoneNumber'] = substr($shippingAddress->getTelephone(), 0, 30); $addressFull = $shippingAddress->getStreetFull(); $addressFull = str_replace("\n", ' ', $addressFull); $addressFull = str_replace("\r", ' ', $addressFull); list($address, $housenumber) = $helper->splitAddress($addressFull); $arrEnduser['address']['streetName'] = $address; $arrEnduser['address']['streetNumber'] = $housenumber; $arrEnduser['address']['zipCode'] = $shippingAddress->getPostcode(); $arrEnduser['address']['city'] = $shippingAddress->getCity(); $arrEnduser['address']['countryCode'] = $shippingAddress->getCountry(); } elseif (!empty($billingAddress)) { $arrEnduser['initials'] = substr($billingAddress->getFirstname(), 0, 1); $arrEnduser['lastName'] = substr($billingAddress->getLastname(), 0, 30); } if (!empty($billingAddress)) { $addressFull = $billingAddress->getStreetFull(); $addressFull = str_replace("\n", ' ', $addressFull); $addressFull = str_replace("\r", ' ', $addressFull); list($address, $housenumber) = $helper->splitAddress($addressFull); $arrEnduser['invoiceAddress']['streetName'] = $address; $arrEnduser['invoiceAddress']['streetNumber'] = $housenumber; $arrEnduser['invoiceAddress']['zipCode'] = $billingAddress->getPostcode(); $arrEnduser['invoiceAddress']['city'] = $billingAddress->getCity(); $arrEnduser['invoiceAddress']['countryCode'] = $billingAddress->getCountry(); $arrEnduser['invoiceAddress']['initials'] = substr($billingAddress->getFirstname(), 0, 1); $arrEnduser['invoiceAddress']['lastName'] = substr($billingAddress->getLastname(), 0, 30); } $api->setEnduser($arrEnduser); } $api->setServiceId($serviceId); $api->setApiToken($apiToken); $api->setAmount(round($amount * 100)); $api->setCurrency($order->getOrderCurrencyCode()); $api->setPaymentOptionId($optionId); $api->setFinishUrl(Mage::getUrl('pay_payment/order/return')); $api->setExchangeUrl(Mage::getUrl('pay_payment/order/exchange')); $api->setOrderId($order->getIncrementId()); if (!empty($optionSubId)) { $api->setPaymentOptionSubId($optionSubId); } try { Mage::log('Calling Pay api to start transaction', null, 'paynl.log'); $resultData = $api->doRequest(); } catch (Exception $e) { Mage::log("Creating transaction failed, Exception: " . $e->getMessage(), null, 'paynl.log'); // Reset previous errors Mage::getSingleton('checkout/session')->getMessages(true); // cart restoren $restoreCart = Mage::getStoreConfig('pay_payment/general/restore_cart', Mage::app()->getStore()); if ($restoreCart) { $items = $order->getItemsCollection(); foreach ($items as $item) { try { $cart = Mage::getSingleton('checkout/cart'); $cart->addOrderItem($item); } catch (Mage_Core_Exception $e) { if (Mage::getSingleton('checkout/session')->getUseNotice(true)) { Mage::getSingleton('checkout/session')->addNotice($e->getMessage()); } else { Mage::getSingleton('checkout/session')->addError($e->getMessage()); } } catch (Exception $e) { Mage::getSingleton('checkout/session')->addException($e, Mage::helper('checkout')->__('Cannot add the item to shopping cart.')); } } $cart->save(); } // Add error to cart Mage::getSingleton('checkout/session')->addError(Mage::helper('pay_payment')->__('Er is een storing bij de door u gekozen betaalmethode of bank. Kiest u alstublieft een andere betaalmethode of probeer het later nogmaals')); Mage::getSingleton('checkout/session')->addError($e->getMessage()); // Mage::getSingleton('checkout/session')->addError(print_r($api->getPostData(),1)); // Redirect via header Mage::app()->getResponse()->setRedirect(Mage::getUrl('checkout/cart')); return; // Fallback redirect via javascript //echo 'window.location = \'' . Mage::getUrl('checkout/cart') . '\''; } $transaction = Mage::getModel('pay_payment/transaction'); $transactionId = $resultData['transaction']['transactionId']; Mage::log('Transaction started, transactionId: ' . $transactionId, null, 'paynl.log'); $transaction->setData(array('transaction_id' => $transactionId, 'service_id' => $serviceId, 'option_id' => $optionId, 'option_sub_id' => $optionSubId, 'amount' => round($amount * 100), 'order_id' => $order->getId(), 'status' => Pay_Payment_Model_Transaction::STATE_PENDING, 'created' => time(), 'last_update' => time())); $transaction->save(); //redirecten $url = $resultData['transaction']['paymentURL']; $statusPending = Mage::getStoreConfig('payment/' . $payment->getMethod() . '/order_status', Mage::app()->getStore()); $order->addStatusHistoryComment('Transactie gestart, transactieId: ' . $transactionId . " \nBetaalUrl: " . $url); $order->save(); $sendMail = Mage::getStoreConfig('payment/' . $payment->getMethod() . '/send_mail', Mage::app()->getStore()); if ($sendMail == 'start') { $order->sendNewOrderEmail(); } Mage::app()->getResponse()->setRedirect($url); } else { // loading order failed Mage::log('Error: OrderId found in session but loading the order failed, orderId:' . $session->getLastRealOrderId(), null, 'paynl.log'); } } else { // no orderId in session Mage::log('Error: No order found in the session, so i cannot create a payment', null, 'paynl.log'); } }
public static function _setBackupApiUrl($url) { self::$_backupApiUrl = $url; }
protected function _getPostData() { $data = parent::_getPostData(); /* * Verplicht * * amount * paymentOptionId * finishUrl * exchangeUrl * orderId * * * Optioneel * * costs * paymentOptionSubId */ // Checken of alle verplichte velden geset zijn if ($this->_apiToken == '') { throw Mage::exception('Pay_Payment_Helper_Api', 'apiToken not set', 1); } else { $data['token'] = $this->_apiToken; } if (empty($this->_serviceId)) { throw Mage::exception('Pay_Payment_Helper_Api', 'apiToken not set', 1); } else { $data['serviceId'] = $this->_serviceId; } if (empty($this->_amount)) { throw Mage::exception('Pay_Payment_Helper_Api', 'Amount is niet geset', 1); } else { $data['amount'] = $this->_amount; } if (!empty($this->_currency)) { $data['transaction']['currency'] = $this->_currency; } if (empty($this->_paymentOptionId)) { throw Mage::exception('Pay_Payment_Helper_Api', 'PaymentOptionId is niet geset', 1); } else { $data['paymentOptionId'] = $this->_paymentOptionId; } if (empty($this->_finishUrl)) { throw Mage::exception('Pay_Payment_Helper_Api', 'FinishUrl is niet geset', 1); } else { $data['finishUrl'] = $this->_finishUrl; } if (empty($this->_exchangeUrl)) { throw Mage::exception('Pay_Payment_Helper_Api', 'exchangeUrl is niet geset', 1); } else { $data['transaction']['orderExchangeUrl'] = $this->_exchangeUrl; } if (empty($this->_orderId)) { throw Mage::exception('Pay_Payment_Helper_Api', 'orderId is niet geset', 1); } else { $data['statsData']['extra1'] = $this->_orderId; } if (empty($this->_description)) { $data['transaction']['description'] = $this->_orderId; } else { $data['transaction']['description'] = $this->_description; } if (!empty($this->_extra2)) { $data['statsData']['extra2'] = $this->_extra2; } if (!empty($this->_extra3)) { $data['statsData']['extra3'] = $this->_extra3; } if ($this->_costs_for_customer == 1) { $data['transaction']['costs'] = 1; } // $data['transaction']['currency'] = 'EUR'; if (!empty($this->_paymentOptionSubId)) { $data['paymentOptionSubId'] = $this->_paymentOptionSubId; } //ip en browserdata setten $data['ipAddress'] = Pay_Payment_Helper_Data::getIp(); $data['browserData'] = array('browser_name_regex' => '^mozilla/5\\.0 (windows; .; windows nt 5\\.1; .*rv:.*) gecko/.* firefox/0\\.9.*$', 'browser_name_pattern' => 'Mozilla/5.0 (Windows; ?; Windows NT 5.1; *rv:*) Gecko/* Firefox/0.9*', 'parent' => 'Firefox 0.9', 'platform' => 'WinXP', 'browser' => 'Firefox', 'version' => 0.9, 'majorver' => 0, 'minorver' => 9, 'cssversion' => 2, 'frames' => 1, 'iframes' => 1, 'tables' => 1, 'cookies' => 1); if (!empty($this->_products)) { $data['saleData']['invoiceDate'] = date('d-m-Y'); $data['saleData']['deliveryDate'] = date('d-m-Y', strtotime('+1 day')); $data['saleData']['orderData'] = $this->_products; } $data['enduser'] = array(); if (!empty($this->_enduser)) { $data['enduser'] = $this->_enduser; } //taal instellen $data['enduser']['language'] = Pay_Payment_Helper_Data::getLanguage(); return $data; }