diff --git a/paynl_paymentmethods/config.xml b/paynl_paymentmethods/config.xml new file mode 100644 index 0000000..64216fe --- /dev/null +++ b/paynl_paymentmethods/config.xml @@ -0,0 +1,13 @@ + + + paynl_paymentmethods + + + + + + + 1 + 1 + + \ No newline at end of file diff --git a/paynl_paymentmethods/config_nl.xml b/paynl_paymentmethods/config_nl.xml new file mode 100644 index 0000000..ed55a29 --- /dev/null +++ b/paynl_paymentmethods/config_nl.xml @@ -0,0 +1,13 @@ + + + paynl_paymentmethods + + + + + + + 1 + 1 + + \ No newline at end of file diff --git a/paynl_paymentmethods/controllers/front/exchange.php b/paynl_paymentmethods/controllers/front/exchange.php new file mode 100644 index 0000000..2013ac6 --- /dev/null +++ b/paynl_paymentmethods/controllers/front/exchange.php @@ -0,0 +1,53 @@ + +* @copyright 2007-2014 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +/** + * @since 1.5.0 + */ +class paynl_paymentmethodsExchangeModuleFrontController extends ModuleFrontController +{ + public function initContent() + { + $transactionId = Tools::getValue('order_id'); + $action = Tools::getValue('action'); + + try{ + if(strpos($action, 'refund') !== false){ + throw new Pay_Exception('Ignoring refund'); + } + if(strpos($action, 'pending') !== false){ + throw new Pay_Exception('Ignoring pending'); + } + $result = Pay_Helper_Transaction::processTransaction($transactionId); + } catch (Exception $ex) { + echo "TRUE| "; + echo $ex->getMessage(); + die(); + } + echo 'TRUE| Status updated to '.$result['state']. ' for cartId: '.$result['orderId'].' orderId: '.@$result['real_order_id']; + die(); + } +} diff --git a/paynl_paymentmethods/controllers/front/index.php b/paynl_paymentmethods/controllers/front/index.php new file mode 100644 index 0000000..a41987d --- /dev/null +++ b/paynl_paymentmethods/controllers/front/index.php @@ -0,0 +1,35 @@ + +* @copyright 2007-2014 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); +header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); + +header("Cache-Control: no-store, no-cache, must-revalidate"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); + +header("Location: ../"); +exit; \ No newline at end of file diff --git a/paynl_paymentmethods/controllers/front/payment.php b/paynl_paymentmethods/controllers/front/payment.php new file mode 100644 index 0000000..1f40ec0 --- /dev/null +++ b/paynl_paymentmethods/controllers/front/payment.php @@ -0,0 +1,238 @@ + + * @copyright 2007-2014 PrestaShop SA + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + * International Registered Trademark & Property of PrestaShop SA + */ + +/** + * @since 1.5.0 + */ +class paynl_paymentmethodsPaymentModuleFrontController extends ModuleFrontController { + + public $ssl = true; + public $display_column_left = false; + + /** + * @see FrontController::initContent() + */ + public function initContent() { + +// parent::initContent(); + + $cart = $this->context->cart; + + $deliveryAddress = new Address((int) $cart->id_address_delivery); + $invoiceAddress = new Address((int) $cart->id_address_invoice); + + $paymentOptionId = Tools::getValue('pid'); + + + + $token = Configuration::get('PAYNL_TOKEN'); + $serviceId = Configuration::get('PAYNL_SERVICE_ID'); + + $statusPending = Configuration::get('PAYNL_WAIT'); + + if (!isset($cart->id)) { + echo "Can't find cart"; + exit(); + } + try { + //validate the order + $customer = new Customer($cart->id_customer); + $total = (float) $cart->getOrderTotal(true, Cart::BOTH); + + $orderStatus = Configuration::get('PAYNL_WAIT'); + $module = $this->module; + + $currencyId = $this->context->currency->id; + + $currencyCode = $this->context->currency->iso_code; + + //$paymentMethodName = $module->getPaymentMethodName($paymentOptionId); + + $extraFee = $module->getExtraCosts($paymentOptionId, $total); + + + $total += $extraFee; + //$cart->additional_shipping_cost = $extraFee; + //$module->validateOrderPay((int) $cart->id, $orderStatus, $total, $extraFee, $module->getPaymentMethodName($paymentOptionId), NULL, array(), (int) $currencyId, false, $customer->secure_key); + + $cartId = $cart->id; + + $apiStart = new Pay_Api_Start(); + + //Klantgegevens meesturen + /* array( + * initals + * lastName + * language + * accessCode + * gender (M or F) + * dob (DD-MM-YYYY) + * phoneNumber + * emailAddress + * bankAccount + * iban + * bic + * sendConfirmMail + * confirmMailTemplate + * address => array( + * streetName + * streetNumber + * zipCode + * city + * countryCode + * ) + * invoiceAddress => array( + * initials + * lastname + * streetName + * streetNumber + * zipCode + * city + * countryCode + * ) + * ) + */ + $language = new Language($cart->id_lang); + $arrEnduser = array(); + $arrEnduser['language'] = $language->iso_code; + $arrEnduser['phoneNumber'] = (!empty($invoiceAddress->phone) ? $invoiceAddress->phone : $invoiceAddress->phone_mobile); + $arrEnduser['initials'] = $customer->firstname; + $arrEnduser['lastName'] = $customer->lastname; + + list($year, $month, $day) = explode('-', $customer->birthday); + $arrEnduser['dob'] = $day . '-' . $month . '-' . $year; + + + $arrEnduser['emailAddress'] = $customer->email; + + + + + // delivery address + $arrAddress = array(); + $strAddress = $deliveryAddress->address1 . $deliveryAddress->address2; + $arrStreetHouseNr = Pay_Helper::splitAddress($strAddress); + $arrAddress['streetName'] = $arrStreetHouseNr[0]; + $arrAddress['streetNumber'] = $arrStreetHouseNr[1]; + $arrAddress['zipCode'] = $deliveryAddress->postcode; + $arrAddress['city'] = $deliveryAddress->city; + $country = new Country($deliveryAddress->id_country); + $arrAddress['countryCode'] = $country->iso_code; + + $arrEnduser['address'] = $arrAddress; + + // invoice address + $arrAddress = array(); + $arrAddress['initials'] = $customer->firstname; + $arrAddress['lastName'] = $customer->lastname; + + $strAddress = $invoiceAddress->address1 . $invoiceAddress->address2; + $arrStreetHouseNr = Pay_Helper::splitAddress($strAddress); + $arrAddress['streetName'] = $arrStreetHouseNr[0]; + $arrAddress['streetNumber'] = $arrStreetHouseNr[1]; + $arrAddress['zipCode'] = $invoiceAddress->postcode; + $arrAddress['city'] = $invoiceAddress->city; + $country = new Country($invoiceAddress->id_country); + $arrAddress['countryCode'] = $country->iso_code; + + $arrEnduser['invoiceAddress'] = $arrAddress; + + $apiStart->setEnduser($arrEnduser); + + // producten toevoegen + $products = $cart->getProducts(); + foreach ($products as $product) { + $apiStart->addProduct($product['id_product'], $product['name'], round($product['price_wt'] * 100), $product['cart_quantity'], 'H'); + } + + //verzendkosten toevoegen + $shippingCost = $cart->getTotalShippingCost(); + if ($shippingCost != 0) { + $apiStart->addProduct('SHIPPING', 'Verzendkosten', round($shippingCost * 100), 1, 'H'); + } + + //Inpakservice toevoegen + if ($cart->gift != 0) { + $packingCost = $cart->getGiftWrappingPrice(true); + if ($packingCost != 0) { + $apiStart->addProduct('PACKING', 'Inpakservice', round($packingCost * 100), 1, 'H'); + } + } + + $cartRules = $cart->getCartRules(); + + foreach($cartRules as $cartRule){ + $apiStart->addProduct('DISCOUNT'.$cartRule['id_cart_rule'], $cartRule['description'], round($cartRule['value_real'] * -100), 1, 'H'); + } + + if ($extraFee != 0) { + $apiStart->addProduct('PAYMENTFEE', 'Betaalkosten', round($extraFee * 100), 1, 'H'); + } + + + $apiStart->setApiToken($token); + $apiStart->setServiceId($serviceId); + $apiStart->setDescription($cart->id); + $apiStart->setExtra1('CartId: ' . $cart->id); + //$apiStart->setExtra2(); + + + + $apiStart->setPaymentOptionId($paymentOptionId); + + $finishUrl = Context::getContext()->link->getModuleLink('paynl_paymentmethods', 'return'); + $exchangeUrl = Context::getContext()->link->getModuleLink('paynl_paymentmethods', 'exchange'); + + + $apiStart->setFinishUrl($finishUrl); + $apiStart->setExchangeUrl($exchangeUrl); + + $apiStart->setAmount(round($total * 100)); + + $apiStart->setCurrency($currencyCode); + + $result = $apiStart->doRequest(); + + $startData = $apiStart->getPostData(); + + Pay_Helper_Transaction::addTransaction($result['transaction']['transactionId'], $paymentOptionId, round($total * 100), $currencyCode, $cartId, $startData); + + if ($this->module->validateOnStart($paymentOptionId)) { + $module->validateOrderPay((int) $cart->id, $statusPending, $total, $extraFee, $module->getPaymentMethodName($paymentOptionId), NULL, array('transaction_id' => $result['transaction']['transactionId']), (int) $currencyId, false, $customer->secure_key); + } + + + Tools::redirect($result['transaction']['paymentURL']); + +//$url = $paynl->startTransaction($cart); + } catch (Exception $e) { + echo $e->getMessage(); + } + //betaling starten + } + +} diff --git a/paynl_paymentmethods/controllers/front/return.php b/paynl_paymentmethods/controllers/front/return.php new file mode 100644 index 0000000..74065a5 --- /dev/null +++ b/paynl_paymentmethods/controllers/front/return.php @@ -0,0 +1,73 @@ + + * @copyright 2007-2014 PrestaShop SA + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + * International Registered Trademark & Property of PrestaShop SA + */ + +/** + * @since 1.5.0 + */ +class paynl_paymentmethodsReturnModuleFrontController extends ModuleFrontController { + + public function initContent() { + parent::initContent(); + $transactionId = Tools::getValue('orderId'); + + try { + $result = Pay_Helper_Transaction::processTransaction($transactionId); + + $order = new Order($result['real_order_id']); + $customer = new Customer($order->id_customer); + + $this->context->smarty->assign(array( + 'reference_order' => $result['real_order_id'], + 'email' => $customer->email, + 'id_order_formatted'=> $order->reference, + )); + + if ($result['state'] == 'PAID') { + Tools::redirect('index.php?controller=order-confirmation&id_cart='.$result['orderId'].'&id_module='.$this->module->id.'&id_order='.$result['real_order_id'].'&key='.$customer->secure_key); + + } + if ($result['state'] == 'CHECKAMOUNT') { + $this->setTemplate('return_checkamount.tpl'); + } + if ($result['state'] == 'CANCEL') { + if(!empty($result['real_order_id'])){ + Tools::redirect('index.php?controller=order&submitReorder=Reorder&id_order='.$result['real_order_id']); + }else { + Tools::redirect('/order'); + } + } + if ($result['state'] == 'PENDING') { + Tools::redirect('index.php?controller=order-confirmation&id_cart='.$result['orderId'].'&id_module='.$this->module->id.'&id_order='.$result['real_order_id'].'&key='.$customer->secure_key); + } + } catch (Exception $ex) { + + echo 'Error: ' . $ex->getMessage(); + die(); + } + } + +} diff --git a/paynl_paymentmethods/controllers/index.php b/paynl_paymentmethods/controllers/index.php new file mode 100644 index 0000000..a41987d --- /dev/null +++ b/paynl_paymentmethods/controllers/index.php @@ -0,0 +1,35 @@ + +* @copyright 2007-2014 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); +header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); + +header("Cache-Control: no-store, no-cache, must-revalidate"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); + +header("Location: ../"); +exit; \ No newline at end of file diff --git a/paynl_paymentmethods/includes/classes/Autoload.php b/paynl_paymentmethods/includes/classes/Autoload.php new file mode 100644 index 0000000..f232977 --- /dev/null +++ b/paynl_paymentmethods/includes/classes/Autoload.php @@ -0,0 +1,10 @@ +_serviceId = $serviceId; + } + + /** + * Set the API token + * The API token is used to identify your company. + * The API token can be found on: https://admin.pay.nl/my_merchant on the bottom + * + * @param string $apiToken + */ + public function setApiToken($apiToken) { + $this->_apiToken = $apiToken; + } + + protected function _getPostData() { + + return $this->_postData; + } + + protected function _processResult($data) { + return $data; + } + + /** + * Generates the api url + * + * @return string The full url to the api + * @throws Pay_Exception + */ + private function _getApiUrl() { + if ($this->_version == '') { + throw new Pay_Exception('version not set', 1); + } + if ($this->_controller == '') { + throw new Pay_Exception('controller not set', 1); + } + if ($this->_action == '') { + throw new Pay_Exception('action not set', 1); + } + + return $this->_apiUrl . '/' . $this->_version . '/' . $this->_controller . '/' . $this->_action . '/json/'; + } + + /** + * Get the data to post to the api for debug use + * + * @return array The post data + */ + public function getPostData(){ + return $this->_getPostData(); + } + /** + * Do the request and get the result + * + * @return array The result + * @throws Pay_Exception On error generated before sending + * @throws Pay_Api_Exception On error returned by the pay.nl api + */ + public function doRequest() { + if ($this->_getPostData()) { + + $url = $this->_getApiUrl(); + $data = $this->_getPostData(); + + $strData = http_build_query($data); + + $apiUrl = $url; + + $ch = curl_init(); + if ($this->_requestType == self::REQUEST_TYPE_GET) { + $apiUrl .= '?' . $strData; + } else { + curl_setopt($ch, CURLOPT_POSTFIELDS, $strData); + } + + + curl_setopt($ch, CURLOPT_URL, $apiUrl); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + $result = curl_exec($ch); + + + if ($result == false) { + $error = curl_error($ch); + } + curl_close($ch); + + $arrResult = json_decode($result, true); + + if ($this->validateResult($arrResult)) { + return $this->_processResult($arrResult); + } + } + } + + /** + * Validate the result and throw an exception when there is an error + * + * @param array $arrResult The result + * @return boolean Result valid + * @throws Pay_Api_Exception + */ + protected function validateResult($arrResult) { + if ($arrResult['request']['result'] == 1) { + return true; + } else { + if(isset($arrResult['request']['errorId']) && isset($arrResult['request']['errorMessage']) ){ + throw new Pay_Api_Exception($arrResult['request']['errorId'] . ' - ' . $arrResult['request']['errorMessage']); + } elseif(isset($arrResult['error'])){ + throw new Pay_Api_Exception($arrResult['error']); + } else { + throw new Pay_Api_Exception('Unexpected api result'); + } + } + } +} diff --git a/paynl_paymentmethods/includes/classes/Pay/Api/Exception.php b/paynl_paymentmethods/includes/classes/Pay/Api/Exception.php new file mode 100644 index 0000000..fc2c414 --- /dev/null +++ b/paynl_paymentmethods/includes/classes/Pay/Api/Exception.php @@ -0,0 +1,7 @@ +_apiToken == '') { + throw new Pay_Exception('apiToken not set', 1); + } else { + $data['token'] = $this->_apiToken; + } + if (empty($this->_serviceId)) { + throw new Pay_Exception('serviceId not set', 1); + } else { + $data['serviceId'] = $this->_serviceId; + } + return $data; + } + /** + * Process the result + * + * @param array $arrReturn + * @return array the result + */ + protected function _processResult($arrReturn) { + if (!$arrReturn['request']['result']) { + return $arrReturn; + } + + $arrReturn['paymentOptions'] = array(); + + $countryOptionList = $arrReturn['countryOptionList']; + unset($arrReturn['countryOptionList']); + if (isset($countryOptionList) && is_array($countryOptionList)) { + foreach ($countryOptionList AS $strCountrCode => $arrCountry) { + foreach ($arrCountry['paymentOptionList'] AS $arrPaymentProfile) { + + if (!isset($arrReturn['paymentOptions'][$arrPaymentProfile['id']])) { + $arrReturn['paymentOptions'][$arrPaymentProfile['id']] = array( + 'id' => $arrPaymentProfile['id'], + 'name' => $arrPaymentProfile['name'], + 'visibleName' => $arrPaymentProfile['name'], + 'img' => $arrPaymentProfile['img'], + 'path' => $arrPaymentProfile['path'], + 'paymentOptionSubList' => array(), + 'countries' => array(), + ); + } + + if (!empty($arrPaymentProfile['paymentOptionSubList'])) { + $arrReturn['paymentOptions'][$arrPaymentProfile['id']]['paymentOptionSubList'] = $arrPaymentProfile['paymentOptionSubList']; + } + + + $arrReturn['paymentOptions'][$arrPaymentProfile['id']]['countries'][$strCountrCode] = array( + 'id' => $strCountrCode, + 'name' => $arrCountry['visibleName'], + ); + } + } + } + return $arrReturn; + } + +} diff --git a/paynl_paymentmethods/includes/classes/Pay/Api/Info.php b/paynl_paymentmethods/includes/classes/Pay/Api/Info.php new file mode 100644 index 0000000..39bce6e --- /dev/null +++ b/paynl_paymentmethods/includes/classes/Pay/Api/Info.php @@ -0,0 +1,49 @@ +_postData['transactionId'] = $transactionId; + } + /** + * Check if all required fields are set, if all required fields are set, returns the fields + * + * @return array The data to post + * @throws Pay_Exception + */ + protected function _getPostData() { + $data = parent::_getPostData(); + if ($this->_apiToken == '') { + throw new Pay_Exception('apiToken not set', 1); + } else { + $data['token'] = $this->_apiToken; + } + if(!isset($this->_postData['transactionId'])){ + throw new Pay_Exception('transactionId is not set', 1); + } + return $data; + } +} diff --git a/paynl_paymentmethods/includes/classes/Pay/Api/Start.php b/paynl_paymentmethods/includes/classes/Pay/Api/Start.php new file mode 100644 index 0000000..4f5578b --- /dev/null +++ b/paynl_paymentmethods/includes/classes/Pay/Api/Start.php @@ -0,0 +1,304 @@ +_currency = strtoupper($currency); + } + public function setPromotorId($promotorId){ + $this->_promotorId = $promotorId; + } + public function setInfo($info){ + $this->_info = $info; + } + public function setTool($tool){ + $this->_tool = $tool; + } + public function setObject($object){ + $this->_object = $object; + } + + public function setTransferData($transferData){ + $this->_transferData = $transferData; + } + /** + * Add a product to an order + * Attention! This is purely an adminstrative option, the amount of the order is not modified. + * + * @param string $id + * @param string $description + * @param int $price + * @param int $quantity + * @param int $vatPercentage + * @throws Pay_Exception + */ + public function addProduct($id, $description, $price, $quantity, $vatPercentage = 'H') { + if (!is_numeric($price)) { + throw new Pay_Exception('Price moet numeriek zijn', 1); + } + if (!is_numeric($quantity)) { + throw new Pay_Exception('Quantity moet numeriek zijn', 1); + } + + $quantity = $quantity * 1; + + //description mag maar 45 chars lang zijn + $description = substr($description, 0, 45); + + $arrProduct = array( + 'productId' => $id, + 'description' => $description, + 'price' => $price, + 'quantity' => $quantity, + 'vatCode' => $vatPercentage, + ); + $this->_products[] = $arrProduct; + } + + /** + * Set the enduser data in the following format + * + * array( + * initals + * lastName + * language + * accessCode + * gender (M or F) + * dob (DD-MM-YYYY) + * phoneNumber + * emailAddress + * bankAccount + * iban + * bic + * sendConfirmMail + * confirmMailTemplate + * address => array( + * streetName + * streetNumber + * zipCode + * city + * countryCode + * ) + * invoiceAddress => array( + * initials + * lastname + * streetName + * streetNumber + * zipCode + * city + * countryCode + * ) + * ) + * @param array $enduser + */ + public function setEnduser($enduser) { + $this->_enduser = $enduser; + } + + /** + * Set the amount(in cents) of the transaction + * + * @param int $amount + * @throws Pay_Exception + */ + public function setAmount($amount) { + if (is_numeric($amount)) { + $this->_amount = $amount; + } else { + throw new Pay_Exception('Amount is niet numeriek', 1); + } + } + + public function setPaymentOptionId($paymentOptionId) { + if (is_numeric($paymentOptionId)) { + $this->_paymentOptionId = $paymentOptionId; + } else { + throw new Pay_Exception('PaymentOptionId is niet numeriek', 1); + } + } + + public function setPaymentOptionSubId($paymentOptionSubId) { + if (is_numeric($paymentOptionSubId)) { + $this->_paymentOptionSubId = $paymentOptionSubId; + } else { + throw new Pay_Exception('PaymentOptionSubId is niet numeriek', 1); + } + } + + /** + * Set the url where the user will be redirected to after payment. + * + * @param string $finishUrl + */ + public function setFinishUrl($finishUrl) { + $this->_finishUrl = $finishUrl; + } + + /** + * Set the comunication url, the pay.nl server will call this url when the status of the transaction changes + * + * @param string $exchangeUrl + */ + public function setExchangeUrl($exchangeUrl) { + $this->_exchangeUrl = $exchangeUrl; + } + + + + public function setExtra1($extra1) { + $this->_extra1 = $extra1; + } + public function setExtra2($extra2) { + $this->_extra2 = $extra2; + } + + public function setExtra3($extra3) { + $this->_extra3 = $extra3; + } + public function setDomainId($domainId) { + $this->_domainId = $domainId; + } + + /** + * Set the description for the transaction + * @param type $description + */ + public function setDescription($description) { + $this->_description = $description; + } + + /** + * Get the post data, if not all required variables are set, this wil rthrow an exception + * + * @return array + * @throws Pay_Exception + */ + protected function _getPostData() { + $data = parent::_getPostData(); + + if ($this->_apiToken == '') { + throw new Pay_Exception('apiToken not set', 1); + } else { + $data['token'] = $this->_apiToken; + } + if (empty($this->_serviceId)) { + throw new Pay_Exception('apiToken not set', 1); + } else { + $data['serviceId'] = $this->_serviceId; + } + if (empty($this->_amount)) { + throw new Pay_Exception('Amount is niet geset', 1); + } else { + $data['amount'] = $this->_amount; + } + if(!empty($this->_currency)){ + $data['transaction']['currency'] = $this->_currency; + } + if (!empty($this->_paymentOptionId)) { + $data['paymentOptionId'] = $this->_paymentOptionId; + } + if (empty($this->_finishUrl)) { + throw new Pay_Exception('FinishUrl is niet geset', 1); + } else { + $data['finishUrl'] = $this->_finishUrl; + } + if (!empty($this->_exchangeUrl)) { + $data['transaction']['orderExchangeUrl'] = $this->_exchangeUrl; + } + + if (!empty($this->_description)) { + $data['transaction']['description'] = $this->_description; + } + + if (!empty($this->_paymentOptionSubId)) { + $data['paymentOptionSubId'] = $this->_paymentOptionSubId; + } + + + $data['ipAddress'] = $_SERVER['REMOTE_ADDR']; + + // I set the browser data with dummydata, because most servers dont have the get_browser function available + $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; + } + + if (!empty($this->_enduser)) { + $data['enduser'] = $this->_enduser; + } + + if (!empty($this->_extra1)) { + $data['statsData']['extra1'] = $this->_extra1; + } + if (!empty($this->_extra2)) { + $data['statsData']['extra2'] = $this->_extra2; + } + if (!empty($this->_extra3)) { + $data['statsData']['extra3'] = $this->_extra3; + } + if(!empty($this->_promotorId)){ + $data['statsData']['promotorId'] = $this->_promotorId; + } + if(!empty($this->_info)){ + $data['statsData']['info'] = $this->_info; + } + if(!empty($this->_tool)){ + $data['statsData']['tool'] = $this->_tool; + } + if(!empty($this->_object)){ + $data['statsData']['object'] = $this->_object; + } + if(!empty($this->_domainId)){ + $data['statsData']['domain_id'] = $this->_domainId; + } + if(!empty($this->_transferData)){ + $data['statsData']['transferData'] = $this->_transferData; + } + + return $data; + } + +} diff --git a/paynl_paymentmethods/includes/classes/Pay/Exception.php b/paynl_paymentmethods/includes/classes/Pay/Exception.php new file mode 100644 index 0000000..cd7566b --- /dev/null +++ b/paynl_paymentmethods/includes/classes/Pay/Exception.php @@ -0,0 +1,7 @@ + $value) { + if (is_array($value)) { + $value = self::filterArrayRecursive($value); + } + if (!empty($value)) { + $newArray[$key] = $value; + } + } + return $newArray; + } + + /** + * Find out if the connection is secure + * + * @return boolean Secure + */ + public static function isSecure() { + $isSecure = false; + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { + $isSecure = true; + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { + $isSecure = true; + } + return $isSecure; + } + /** + * Get the uri of the current script without the filename. + * We use this to generate the return- and exchangeurl + * + * @return string The uri + */ + public static function getUri(){ + if(self::isSecure()){ + $uri='https://'; + } else { + $uri='http://'; + } + + $uri .= $_SERVER['SERVER_NAME']; + + if(!empty($_SERVER['REQUEST_URI'])){ + $uri .= $_SERVER['REQUEST_URI']; + $uriDir = $uri; + if(substr($uri, -4) == '.php'){ + $uriDir = dirname($uri); + } + + + if($uriDir != 'http:' && $uriDir != 'https:'){ + $uri = $uriDir; + } + } + + return $uri.'/'; + } + public static function splitAddress($strAddress) { + $strAddress = trim($strAddress); + + $a = preg_split('/([0-9]+)/', $strAddress, 2, PREG_SPLIT_DELIM_CAPTURE); + $strStreetName = trim(array_shift($a)); + $strStreetNumber = trim(implode('', $a)); + + if (empty($strStreetName)) { // American address notation + $a = preg_split('/([a-zA-Z]{2,})/', $strAddress, 2, PREG_SPLIT_DELIM_CAPTURE); + + $strStreetNumber = trim(array_shift($a)); + $strStreetName = implode(' ',$a); + } + + return array($strStreetName, $strStreetNumber); + } + + /** + * Sort the paymentoptions by name + * + * @param array $paymentOptions + * @return array + */ + public static function sortPaymentOptions($paymentOptions){ + uasort($paymentOptions, 'sortPaymentOptions'); + return $paymentOptions; + } +} +function sortPaymentOptions($a,$b){ + return strcmp($a['name'], $b['name']); +} \ No newline at end of file diff --git a/paynl_paymentmethods/includes/classes/Pay/Helper/Transaction.php b/paynl_paymentmethods/includes/classes/Pay/Helper/Transaction.php new file mode 100644 index 0000000..2faf118 --- /dev/null +++ b/paynl_paymentmethods/includes/classes/Pay/Helper/Transaction.php @@ -0,0 +1,192 @@ + $transaction_id, + 'option_id' => (int)$option_id, + 'amount' => (int)$amount, + 'currency' => $currency, + 'order_id' => $order_id, + 'start_data' => $db->escape(json_encode($startData)), + ); + + $db->insert('pay_transactions', $data); + } + + private static function updateTransactionState($transactionId, $statusText) { + $db = Db::getInstance(); + + $db->update('pay_transactions', array('status' => $statusText), "transaction_id = '" . $db->escape($transactionId) . "'"); + } + + public static function getTransaction($transaction_id) { + $db = Db::getInstance(); + + $sql = "SELECT * FROM " . _DB_PREFIX_ . "pay_transactions WHERE transaction_id = '" . $db->escape($transaction_id) . "'"; + + $row = $db->getRow($sql); + if (empty($row)) { + throw new Pay_Exception('Transaction not found'); + } + return $row; + } + + /** + * Check if the order is already paid, it is possible that an order has more than 1 transaction. + * So we heck if another transaction for this order is already paid + * + * @param integer $order_id + */ + public static function orderPaid($order_id) { + $db = Db::getInstance(); + + $sql = "SELECT * FROM " . _DB_PREFIX_ . "pay_transactions WHERE order_id = '" . $db->escape($order_id) . "' AND status = 'PAID'"; + + $row = $db->getRow($sql); + if (empty($row)) { + return false; + } else { + return true; + } + } + + public static function processTransaction($transactionId) { + + $token = Configuration::get('PAYNL_TOKEN'); + $serviceId = Configuration::get('PAYNL_SERVICE_ID'); + + $apiInfo = new Pay_Api_Info(); + + $apiInfo->setApiToken($token); + $apiInfo->setServiceId($serviceId); + $apiInfo->setTransactionId($transactionId); + + $result = $apiInfo->doRequest(); + $transactionAmount = $result['paymentDetails']['paidAmount']; + + $stateId = $result['paymentDetails']['state']; + + $stateText = self::getStateText($stateId); + + //de transactie ophalen + try{ + $transaction = self::getTransaction($transactionId); + } catch (Pay_Exception $ex) { + // transactie is niet gevonden... quickfix, we voegen hem opnieuw toe + self::addTransaction($transactionId, $result['paymentDetails']['paymentOptionId'], $result['paymentDetails']['amount'], $result['paymentDetails']['paidCurrency'], str_replace('CartId: ', '', $result['statsDetails']['extra1']), 'Inserted after not found'); + + $transaction = self::getTransaction($transactionId); + } + + $cartId = $orderId = $transaction['order_id']; + + $orderPaid = self::orderPaid($orderId); + + if ($orderPaid == true && $stateText != 'PAID') { + throw new Pay_Exception('Order already paid'); + } + + if ($stateText == $transaction['status']) { + //nothing changed so return without changing anything + $real_order_id = Order::getOrderByCartId($orderId); + return array( + 'orderId' => $orderId, + 'state' => $stateText, + 'real_order_id' => $real_order_id, + ); + } + + //update the transaction state + self::updateTransactionState($transactionId, $stateText); + + $objOrder = Order::getOrderByCartId($cartId); + //$objOrder = new Order($orderId); + + $statusPending = Configuration::get('PAYNL_WAIT'); + $statusPaid = Configuration::get('PAYNL_SUCCESS'); + $statusCancel = Configuration::get('PAYNL_CANCEL'); + + + $id_order_state = ''; + + $paid = false; + + if ($stateText == 'PAID') { + $id_order_state = $statusPaid; + + $module = Module::getInstanceByName(Tools::getValue('module')); + + $cart = new Cart($cartId); + $customer = new Customer($cart->id_customer); + + $currency = $cart->id_currency; + + + $orderTotal = $cart->getOrderTotal(); + $extraFee = $module->getExtraCosts($transaction['option_id'], $orderTotal); + + $cart->additional_shipping_cost += $extraFee; + + $cart->save(); + + $paymentMethodName = $module->getPaymentMethodName($transaction['option_id']); + + + // als de valuta afwijkt, sturen we het originele orderbedrag mee als betaald bedrag, omdat anders prestashop in payment error schiet + $objCurrency = new CurrencyCore($currency); + if($objCurrency->iso_code != 'EUR'){ + $paidAmount = $orderTotal+$extraFee; + } else { + $paidAmount = $transactionAmount / 100; + } + + + $module->validateOrderPay((int) $cart->id, $id_order_state, $paidAmount, $extraFee, $paymentMethodName, NULL, array('transaction_id' => $transactionId), (int) $currency, false, $customer->secure_key); + + $real_order_id = Order::getOrderByCartId($cart->id); + } elseif ($stateText == 'CANCEL') { + $real_order_id = Order::getOrderByCartId($cartId); + + if ($real_order_id) { + $objOrder = new Order($real_order_id); + $history = new OrderHistory(); + $history->id_order = (int) $objOrder->id; + $history->changeIdOrderState((int) $statusCancel, $objOrder); + $history->addWithemail(); + } + } + + return array( + 'orderId' => $orderId, + 'real_order_id' => $real_order_id, + 'state' => $stateText, + ); + } + + /** + * Get the status by statusId + * + * @param int $statusId + * @return string The status + */ + public static function getStateText($stateId) { + switch ($stateId) { + case 80: + case -51: + return 'CHECKAMOUNT'; + case 100: + return 'PAID'; + default: + if ($stateId < 0) { + return 'CANCEL'; + } else { + return 'PENDING'; + } + } + } + +} diff --git a/paynl_paymentmethods/index.php b/paynl_paymentmethods/index.php new file mode 100644 index 0000000..cf673a8 --- /dev/null +++ b/paynl_paymentmethods/index.php @@ -0,0 +1,35 @@ + +* @copyright 2007-2014 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ +error_reporting(E_ALL); +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); +header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); + +header("Cache-Control: no-store, no-cache, must-revalidate"); +header("Cache-Control: post-check=0, pre-check=0", false); +header("Pragma: no-cache"); + +header("Location: ../"); +exit; \ No newline at end of file diff --git a/paynl_paymentmethods/logo.gif b/paynl_paymentmethods/logo.gif new file mode 100644 index 0000000..8d2a084 Binary files /dev/null and b/paynl_paymentmethods/logo.gif differ diff --git a/paynl_paymentmethods/logo.png b/paynl_paymentmethods/logo.png new file mode 100644 index 0000000..89109b6 Binary files /dev/null and b/paynl_paymentmethods/logo.png differ diff --git a/paynl_paymentmethods/pay.nl.logo.gif b/paynl_paymentmethods/pay.nl.logo.gif new file mode 100644 index 0000000..f46341e Binary files /dev/null and b/paynl_paymentmethods/pay.nl.logo.gif differ diff --git a/paynl_paymentmethods/payment.tpl b/paynl_paymentmethods/payment.tpl new file mode 100644 index 0000000..157476c --- /dev/null +++ b/paynl_paymentmethods/payment.tpl @@ -0,0 +1,15 @@ + + + +{foreach from=$profiles key=k item=v} +
+
+

+ + {$v.name} + {$v.name}{if $v.extraCosts != 0} + € {number_format($v.extraCosts,2,',', '.')} {/if} + +

+
+
+{/foreach} diff --git a/paynl_paymentmethods/paynl.css b/paynl_paymentmethods/paynl.css new file mode 100644 index 0000000..4ac2a58 --- /dev/null +++ b/paynl_paymentmethods/paynl.css @@ -0,0 +1,26 @@ +p.payment_module a.paynl_paymentmethod:after { + color: #777777; + content: ""; + display: block; + font-family: "FontAwesome"; + font-size: 25px; + height: 22px; + margin-top: -11px; + position: absolute; + right: 15px; + top: 50%; + width: 14px; +} + +p.payment_module a.paynl_paymentmethod *, +p.payment_module a.paynl_paymentmethod{ + padding: 3px; + padding-left: 10px; + vertical-align: middle; +} +p.payment_module a.paynl_paymentmethod label{ + margin-right:10px; +} +a.paynl_paymentmethod{ + height: 85px; +} \ No newline at end of file diff --git a/paynl_paymentmethods/paynl_paymentmethods.php b/paynl_paymentmethods/paynl_paymentmethods.php new file mode 100644 index 0000000..f18ca02 --- /dev/null +++ b/paynl_paymentmethods/paynl_paymentmethods.php @@ -0,0 +1,605 @@ +name = 'paynl_paymentmethods'; + $this->tab = 'payments_gateways'; + $this->version = '3.2.9'; + $this->_postErrors = array(); + $this->module_key = '6c2f48f238008e8f68271f5e4763d308'; + + $this->currencies = true; + $this->currencies_mode = 'radio'; + + parent::__construct(); + + $this->page = basename(__FILE__, '.php'); + $this->displayName = $this->l('Pay.nl Payment methods'); + $this->description = $this->l('Accept payments by Pay.nl'); + $this->confirmUninstall = $this->l('Are you sure you want to delete your details?'); + } + + public function validateOrderPay($id_cart, $id_order_state, $amount_paid, $extraCosts, $payment_method = 'Unknown', $message = null, $extra_vars = array(), $currency_special = null, $dont_touch_amount = false, $secure_key = false, Shop $shop = null) { + $statusPending = Configuration::get('PAYNL_WAIT'); + $statusPaid = Configuration::get('PAYNL_SUCCESS'); + + // Als er nog geen order van dit cartid is, de order valideren. + $orderId = Order::getOrderByCartId($id_cart); + if ($orderId == false) { + if ($id_order_state == $statusPaid) { + if ($extraCosts != 0) { + $id_order_state_tmp = $statusPending; + } else { + $id_order_state_tmp = $statusPaid; + } + } else { + $id_order_state_tmp = $id_order_state; + } + $result = parent::validateOrder($id_cart, $id_order_state_tmp, $amount_paid, $this->displayName, $message, $extra_vars, $currency_special, $dont_touch_amount, $secure_key, $shop); + $orderId = $this->currentOrder; + + if ($extraCosts == 0 && $id_order_state_tmp == $statusPaid) { + //Als er geen extra kosten zijn, en de order staat op betaald zijn we klaar + return $result; + } + } + + if ($orderId && $id_order_state == $statusPaid) { + $order = new Order($orderId); + $shippingCost = $order->total_shipping; + + $newShippingCosts = $shippingCost + $extraCosts; + $extraCostsExcl = round($extraCosts / (1 + (21 / 100)), 2); + + if ($extraCosts != 0) { + //als de order extra kosten heeft, moeten deze worden toegevoegd. + $order->total_shipping = $newShippingCosts; + $order->total_shipping_tax_excl = $order->total_shipping_tax_excl + $extraCostsExcl; + $order->total_shipping_tax_incl = $newShippingCosts; + + $order->total_paid_tax_excl = $order->total_paid_tax_excl + $extraCostsExcl; + + $order->total_paid_tax_incl = $order->total_paid_real = $order->total_paid = $order->total_paid + $extraCosts; + } + + $result = $order->addOrderPayment($amount_paid, $payment_method, $extra_vars['transaction_id']); + + if (number_format($order->total_paid_tax_incl, 2) !== number_format($amount_paid, 2)) { + $id_order_state = Configuration::get('PS_OS_ERROR'); + } + //paymentid ophalen + $orderPayment = OrderPayment::getByOrderId($order->id); + + $history = new OrderHistory(); + $history->id_order = (int) $order->id; + $history->changeIdOrderState((int) $id_order_state, $order, $orderPayment); + $res = Db::getInstance()->getRow(' + SELECT `invoice_number`, `invoice_date`, `delivery_number`, `delivery_date` + FROM `' . _DB_PREFIX_ . 'orders` + WHERE `id_order` = ' . (int) $order->id); + $order->invoice_date = $res['invoice_date']; + $order->invoice_number = $res['invoice_number']; + $order->delivery_date = $res['delivery_date']; + $order->delivery_number = $res['delivery_number']; + + $order->update(); + + $history->addWithemail(); + } + return $result; + } + + public function install() { + if (!parent::install() || !$this->createTransactionTable() || !Configuration::updateValue('PAYNL_TOKEN', '') || !Configuration::updateValue('PAYNL_SERVICE_ID', '') || !Configuration::updateValue('PAYNL_ORDER_DESC', '') || !Configuration::updateValue('PAYNL_WAIT', '10') || !Configuration::updateValue('PAYNL_SUCCESS', '2') || !Configuration::updateValue('PAYNL_AMOUNTNOTVALID', '0') || !Configuration::updateValue('PAYNL_CANCEL', '6') || !Configuration::updateValue('PAYNL_COUNTRY_EXCEPTIONS', '') || !Configuration::updateValue('PAYNL_PAYMENT_METHOD_ORDER', '') || !$this->registerHook('paymentReturn') || !$this->registerHook('payment')) { + return false; + } + return true; + } + + private function createTransactionTable() { + $sql = "CREATE TABLE IF NOT EXISTS `" . _DB_PREFIX_ . "pay_transactions` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `transaction_id` varchar(50) NOT NULL, + `option_id` int(11) NOT NULL, + `amount` int(11) NOT NULL, + `currency` char(3) NOT NULL, + `order_id` int(11) NOT NULL, + `status` varchar(10) NOT NULL DEFAULT 'PENDING', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `last_update` datetime DEFAULT NULL, + `start_data` text NOT NULL, + PRIMARY KEY (`id`) + ) ENGINE=myisam AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;"; + + DB::getInstance()->execute($sql); + return true; + } + + public function validateOnStart($paymentMethodId) { + $arrValidateOnStart = Configuration::get('PAYNL_VALIDATE_ON_START'); + if (!empty($arrValidateOnStart)) { + $arrValidateOnStart = unserialize($arrValidateOnStart); + if (isset($arrValidateOnStart[$paymentMethodId]) && $arrValidateOnStart[$paymentMethodId] == 1) { + return true; + } + } + + return false; + } + + public function getExtraCosts($paymentMethodId, $totalAmount) { + $arrExtraCosts = Configuration::get('PAYNL_PAYMENT_EXTRA_COSTS'); + $arrExtraCosts = unserialize($arrExtraCosts); + + $arrExtraCosts = $arrExtraCosts[$paymentMethodId]; + if (empty($arrExtraCosts)) { + return 0; + } + + $fixed = !empty($arrExtraCosts['fixed']) ? $arrExtraCosts['fixed'] : 0; + $percentage = !empty($arrExtraCosts['percentage']) ? $arrExtraCosts['percentage'] : 0; + $max = !empty($arrExtraCosts['max']) ? $arrExtraCosts['max'] : 0; + + $extraCosts = $fixed; + $extraCosts += ($totalAmount * ($percentage / 100)); + if ($extraCosts > $max && $max != 0) { + $extraCosts = $max; + } + + return round($extraCosts, 2); + } + + public function getPaymentMethodName($paymentMethodId) { + $token = Configuration::get('PAYNL_TOKEN'); + $serviceId = Configuration::get('PAYNL_SERVICE_ID'); + + $names = Configuration::get('PAYNL_PAYMENT_METHOD_NAME'); + $names = @unserialize($names); + if(is_array($names) && !empty($names[$paymentMethodId])){ + return $names[$paymentMethodId]; + } + + $apiService = new Pay_Api_Getservice(); + $apiService->setApiToken($token); + $apiService->setServiceId($serviceId); + + $result = $apiService->doRequest(); + + if (isset($result['paymentOptions'][$paymentMethodId])) { + return $result['paymentOptions'][$paymentMethodId]['name']; + } else { + return false; + } + } + + public function uninstall() { + if (!Configuration::deleteByName('PAYNL_TOKEN', '') || !Configuration::deleteByName('PAYNL_SERVICE_ID', '') || !Configuration::deleteByName('PAYNL_ORDER_DESC', '') || !Configuration::deleteByName('PAYNL_WAIT', '0') || !Configuration::deleteByName('PAYNL_SUCCESS', '0') || !Configuration::deleteByName('PAYNL_AMOUNTNOTVALID', '0') || !Configuration::deleteByName('PAYNL_CANCEL', '0') || !Configuration::deleteByName('PAYNL_COUNTRY_EXCEPTIONS', '0') || !Configuration::deleteByName('PAYNL_PAYMENT_METHOD_ORDER', '') || !parent::uninstall()) { + return false; + } + return true; + } + + public function hookPayment($params) { + $objCurrency = $this->getCurrency(); + $intOrderAmount = round(number_format(Tools::convertPrice($params['cart']->getOrderTotal(), $objCurrency), 2, '.', '') * 100); + + if ($this->validateOrderData($intOrderAmount)) { + global $smarty; + + $token = Configuration::get('PAYNL_TOKEN'); + $serviceId = Configuration::get('PAYNL_SERVICE_ID'); + + $methodOrder = Configuration::get('PAYNL_PAYMENT_METHOD_ORDER'); + $methodOrder = @unserialize($methodOrder); + if ($methodOrder == false) { + $methodOrder = array(); + } + + $countryExceptions = Configuration::get('PAYNL_COUNTRY_EXCEPTIONS'); + $countryExceptions = @unserialize($countryExceptions); + if ($countryExceptions == false) { + $countryExceptions = array(); + } + + $apiGetservice = new Pay_Api_Getservice(); + $apiGetservice->setApiToken($token); + $apiGetservice->setServiceId($serviceId); + + $activeProfiles = $apiGetservice->doRequest(); + $activeProfiles = $activeProfiles['paymentOptions']; + + + $paymentaddress = new Address($params['cart']->id_address_invoice); + $countryid = $paymentaddress->id_country; + + // Only the profiles of the target country should remain in this array :). (Only when the count is > 0, otherwise it might indicate problems) + if (count($countryExceptions) > 0) { + if (isset($countryExceptions[$countryid])) { + foreach ($activeProfiles as $id => $profile) { + if (!isset($countryExceptions[$countryid][$profile['id']])) { + unset($activeProfiles[$id]); + } + } + } + } + + // Order remaining profiles based by order... + asort($methodOrder); + + $activeProfilesTemp = $activeProfiles; + $activeProfiles = array(); + + foreach (array_keys($methodOrder) as $iProfileId) { + foreach ($activeProfilesTemp as $iKey => $arrActiveProfile) { + if ($arrActiveProfile['id'] == $iProfileId) { + $arrActiveProfile['name'] = $this->getPaymentMethodName($iProfileId); + $arrActiveProfile['extraCosts'] = number_format($this->getExtraCosts($arrActiveProfile['id'], $intOrderAmount / 100), 2); + array_push($activeProfiles, $arrActiveProfile); + unset($activeProfilesTemp[$iKey]); + } + } + } + + $smarty->assign(array( + 'this_path' => $this->_path, + 'profiles' => $activeProfiles, + //'banks' => $paynl->getIdealBanks(), + 'this_path_ssl' => (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/' . $this->name . '/' + )); + + return $this->display(_PS_MODULE_DIR_ . '/' . $this->name . '/' . $this->name . '.php', 'payment.tpl'); + } else { + return; + } + } + + public function hookPaymentReturn($params) { + if (!$this->active) + return; + + $this->smarty->assign(array( + 'status' => 'ok', + 'id_order' => $params['objOrder']->id + )); + + return $this->display(__FILE__, 'payment_return.tpl'); + } + + public function getContent() { + $this->_html = '

' . $this->displayName . '

'; + + + if (isset($_POST['submitPaynl'])) { + if (!isset($_POST['api'])) + $_POST['api'] = 1; + + if (!sizeof($this->_postErrors)) { + Configuration::updateValue('PAYNL_TOKEN', $_POST['paynltoken']); + Configuration::updateValue('PAYNL_SERVICE_ID', $_POST['service_id']); + Configuration::updateValue('PAYNL_WAIT', $_POST['wait']); + Configuration::updateValue('PAYNL_SUCCESS', $_POST['success']); + Configuration::updateValue('PAYNL_CANCEL', $_POST['cancel']); + if (isset($_POST['enaC'])) { + Configuration::updateValue('PAYNL_COUNTRY_EXCEPTIONS', serialize($_POST['enaC'])); + } + if (isset($_POST['enaO'])) { + Configuration::updateValue('PAYNL_PAYMENT_METHOD_ORDER', serialize($_POST['enaO'])); + } + if (isset($_POST['payExtraCosts'])) { + //kommas voor punten vervangen, en zorgen dat het allemaal getallen zijn + $arrExtraCosts = array(); + + foreach ($_POST['payExtraCosts'] as $paymentMethodId => $paymentMethod) { + foreach ($paymentMethod as $type => $value) { + $value = str_replace(',', '.', $value); + $value = $value * 1; + if ($value == 0) + $value = ''; + $arrExtraCosts[$paymentMethodId][$type] = $value; + } + } + Configuration::updateValue('PAYNL_PAYMENT_EXTRA_COSTS', serialize($arrExtraCosts)); + } + if(isset($_POST['profileName'])){ + Configuration::updateValue('PAYNL_PAYMENT_METHOD_NAME', serialize($_POST['profileName'])); + } + + if (isset($_POST['validateOnStart'])) { + Configuration::updateValue('PAYNL_VALIDATE_ON_START', serialize($_POST['validateOnStart'])); + } + + $this->displayConf(); + } else { + $this->displayErrors(); + } + } + + $this->displayPaynl(); + $this->displayFormSettings(); + + return $this->_html; + } + + public function displayConf() { + $this->_html .= ' +
+ ' . $this->l('Confirmation') . ' + ' . $this->l('Settings updated') . ' +
'; + } + + public function displayErrors() { + $nbErrors = sizeof($this->_postErrors); + $this->_html .= ' +
+

' . ($nbErrors > 1 ? $this->l('There are') : $this->l('There is')) . ' ' . $nbErrors . ' ' . ($nbErrors > 1 ? $this->l('errors') : $this->l('error')) . '

+
    '; + foreach ($this->_postErrors AS $error) + $this->_html .= '
  1. ' . $error . '
  2. '; + $this->_html .= ' +
+
'; + } + + public function displayPaynl() { + $this->_html .= ' + + ' . $this->l('This module allows you to accept payments by Pay.nl.') . ' +


'; + } + + public function displayFormSettings() { + + $arrConfig = array(); + $arrConfig[] = 'PAYNL_TOKEN'; + $arrConfig[] = 'PAYNL_SERVICE_ID'; + $arrConfig[] = 'PAYNL_WAIT'; + $arrConfig[] = 'PAYNL_SUCCESS'; + $arrConfig[] = 'PAYNL_AMOUNTNOTVALID'; + $arrConfig[] = 'PAYNL_CANCEL'; + $arrConfig[] = 'PAYNL_COUNTRY_EXCEPTIONS'; + $arrConfig[] = 'PAYNL_PAYMENT_METHOD_ORDER'; + $arrConfig[] = 'PAYNL_PAYMENT_EXTRA_COSTS'; + $arrConfig[] = 'PAYNL_VALIDATE_ON_START'; + $arrConfig[] = 'PAYNL_PAYMENT_METHOD_NAME'; + + $conf = Configuration::getMultiple($arrConfig); + + + $paynltoken = array_key_exists('paynltoken', $_POST) ? $_POST['paynltoken'] : (array_key_exists('PAYNL_TOKEN', $conf) ? $conf['PAYNL_TOKEN'] : ''); + $service_id = array_key_exists('service_id', $_POST) ? $_POST['service_id'] : (array_key_exists('PAYNL_SERVICE_ID', $conf) ? $conf['PAYNL_SERVICE_ID'] : ''); + + $wait = array_key_exists('wait', $_POST) ? $_POST['wait'] : (array_key_exists('PAYNL_WAIT', $conf) ? $conf['PAYNL_WAIT'] : '10'); + $success = array_key_exists('success', $_POST) ? $_POST['success'] : (array_key_exists('PAYNL_SUCCESS', $conf) ? $conf['PAYNL_SUCCESS'] : '2'); + $amountnotvalid = array_key_exists('amountnotvalid', $_POST) ? $_POST['amountnotvalid'] : (array_key_exists('PAYNL_AMOUNTNOTVALID', $conf) ? $conf['PAYNL_AMOUNTNOTVALID'] : '1'); + $cancel = array_key_exists('cancel', $_POST) ? $_POST['cancel'] : (array_key_exists('PAYNL_CANCEL', $conf) ? $conf['PAYNL_CANCEL'] : '6'); + + // Get states + $states = OrderState::getOrderStates($this->context->language->id); + + $osWait = ''; + + $osSuccess = ''; + + $osCancel = ''; + + $countries = DB::getInstance()->ExecuteS('SELECT id_country FROM ' . _DB_PREFIX_ . 'module_country WHERE id_module = ' . (int) ($this->id)); + foreach ($countries as $country) + $this->country[$country['id_country']] = $country['id_country']; + + $exceptions = ''; + try { + $token = Configuration::get('PAYNL_TOKEN'); + $serviceId = Configuration::get('PAYNL_SERVICE_ID'); + + $serviceApi = new Pay_Api_Getservice(); + $serviceApi->setApiToken($token); + $serviceApi->setServiceId($serviceId); + + $profiles = $serviceApi->doRequest(); + $profiles = $profiles['paymentOptions']; + + + + + $countries = Country::getCountries($this->context->language->id); + + + + + $forceProfilesEnable = false; + $profilesEnable = (array_key_exists('PAYNL_COUNTRY_EXCEPTIONS', $conf) ? $conf['PAYNL_COUNTRY_EXCEPTIONS'] : ''); + if (strlen($profilesEnable) == 0) { + $profilesEnable = array(); + $forceProfilesEnable = true; + } else { + $profilesEnable = @unserialize($profilesEnable); + if ($profilesEnable == false) { + $forceProfilesEnable = true; + $profilesEnable = array(); + } + } + + $profilesOrder = (array_key_exists('PAYNL_PAYMENT_METHOD_ORDER', $conf) ? $conf['PAYNL_PAYMENT_METHOD_ORDER'] : ''); + $extraCosts = (array_key_exists('PAYNL_PAYMENT_EXTRA_COSTS', $conf) ? $conf['PAYNL_PAYMENT_EXTRA_COSTS'] : ''); + $validateOnStart = (array_key_exists('PAYNL_VALIDATE_ON_START', $conf) ? $conf['PAYNL_VALIDATE_ON_START'] : ''); + + if (strlen($profilesOrder) == 0) { + $profilesOrder = array(); + } else { + $profilesOrder = @unserialize($profilesOrder); + if ($profilesOrder == false) { + $profilesOrder = array(); + } + } + + if (strlen($extraCosts) == 0) { + $extraCosts = array(); + } else { + $extraCosts = @unserialize($extraCosts); + if ($extraCosts == false) { + $extraCosts = array(); + } + } + if (strlen($validateOnStart) == 0) { + $validateOnStart = array(); + } else { + $validateOnStart = @unserialize($validateOnStart); + if ($validateOnStart == false) { + $validateOnStart = array(); + } + } + + + $exceptions = '

' . $this->l('Payment restrictions') . '

'; + $exceptions.=''; + $exceptions.=''; + foreach ($profiles as $profile) { + $exceptions.= ''; + } + $exceptions.= ''; + + foreach ($countries as $countryid => $country) { + if (!isset($this->country[$countryid])) { + continue; + } + + + $exceptions.=""; + + foreach ($profiles as $profile) { + $exceptions.="'; + } + $exceptions.=""; + } + $exceptions.="
' . $this->l('Country') . '' . $this->l('Payment methods') . '
 ' . $profile['name'] . '
" . $country['name'] . ""; + + if (!$forceProfilesEnable) { + + $exceptions.=''; + } else { + $exceptions.=''; + } + + $exceptions.='
"; + + $exceptions.= '

' . $this->l('Payment priority') . '

'; + $exceptions.= '

' . $this->l('Lower priority is more important') . '

'; + $exceptions.=''; + $exceptions.= ''; + $exceptions.= ''; + $exceptions.= ''; + $exceptions.= ''; + $exceptions .= ''; + + $names = (array_key_exists('PAYNL_PAYMENT_METHOD_NAME', $conf) ? $conf['PAYNL_PAYMENT_METHOD_NAME'] : ''); + $names = unserialize($names); + + foreach ($profiles as $profile) { + $name = $profile['name']; + if(is_array($names) && !empty($names[$profile['id']])){ + $name = $names[$profile['id']]; + } + + $exceptions.=''; + + $fixed = @$extraCosts[$profile['id']]['fixed']; + $percentage = @$extraCosts[$profile['id']]['percentage']; + $max = @$extraCosts[$profile['id']]['max']; + + $exceptions .= ''; + $exceptions .= ''; + $exceptions .= ''; + + $validateOnStartChecked = ''; + if (isset($validateOnStart[$profile['id']]) && $validateOnStart[$profile['id']] == 1) { + $validateOnStartChecked = "checked='checked'"; + } + + $exceptions .= ''; + + $exceptions .= ''; + } + $exceptions.= '
' . $this->l('Payment method') . '' . $this->l('Order') . '' . $this->l('Extra costs fixed') . '' . $this->l('Extra costs percentage') . '' . $this->l('Extra costs max') . '' . $this->l('Validate on transaction start') . '
'; + + $exceptions.=''; + $exceptions.='
'; + } catch (Exception $ex) { + $exceptions = '

' . $this->l('Payment restrictions') . '

' . + '
' . $this->l('Payment restrictions available after connecting to Pay.nl'); + } + + + + $this->_html .= ' +
+
+ ' . $this->l('Settings') . ' + + +
+ +
+
+
+
+ +
' . $osWait . ' Alleen van toepassing op betalingen waarbij extra kosten worden gerekend, de status gaat daarna meteen naar success
+ +
' . $osSuccess . '
+ +
' . $osCancel . '
+
' + . $exceptions . + '
+
+


'; + } + + protected function validateOrderData($intOrderAmount) { + return true; + } + +} diff --git a/paynl_paymentmethods/translations/nl.php b/paynl_paymentmethods/translations/nl.php new file mode 100644 index 0000000..a249e50 --- /dev/null +++ b/paynl_paymentmethods/translations/nl.php @@ -0,0 +1,36 @@ +paynl_paymentmethods_4ea713b9ffdda58ce48ccec052e29fd6'] = 'Pay.nl betaalmethoden'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_da11e586f68cd9528c0c16328cdf9f5f'] = 'Acepteer betalingen via Pay.nl'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_69a1a3ad8dd5da6db3c4da838a0cf9c7'] = 'Weet je zeker dat je de gegevens wilt verwijderen?'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_f4d1ea475eaa85102e2b4e6d95da84bd'] = 'Bevestiging'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_c888438d14855d7d96a2724ee9c306bd'] = 'Instellingen opgeslagen'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_6357d3551190ec7e79371a8570121d3a'] = 'Er zijn'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_4ce81305b7edb043d0a7a5c75cab17d0'] = 'Er is'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_07213a0161f52846ab198be103b5ab43'] = 'Fouten'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_cb5e100e5a9a3e7f6d1fd97512215282'] = 'Fout'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_2a7f0f0dda13226e03ae1c8c7fbebcaa'] = 'Met deze module kan je betalingen accepteren via Pay.nl'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_b44454331645c7abacf93973e3e9441e'] = 'Betaalmethode beperkingen (per land)'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_59716c97497eb9694541f7c3d37b1a4d'] = 'Land'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_0da8d9a75492046bea7f314521e07cae'] = 'Betaalmethoden'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_6d83fe3c2593f45274a02e4a30d873bc'] = 'Prioriteit'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_7c07e4dabdbfc97696f3e793b4ef844b'] = 'Lager getal betekend belangrijker'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_f0aaaae189e9c7711931a65ffcd22543'] = 'Betaalmethode'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_a240fa27925a635b08dc28c9e4f9216d'] = 'Bestelling'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_09a9ee6692aff45ed9a3bb1c4767c969'] = 'Extra kosten vast'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_489acbfc9724eb9af3e6b0a44f2ce94e'] = 'Extra kosten percentage'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_5632f21957d92c5caa6bd0434ec69d80'] = 'Extra kosten max'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_1b3964c4f3c9d1ae68b527438d77ccf5'] = 'Valideer bij starten transactie'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_502996d9790340c5fd7b86a5b93b1c9f'] = 'Prioriteit'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_f3acb6766cb169e128744166cb9aed80'] = 'Betaalmethode beperkingen zijn in te stellen nadat u uw gegevens heeft ingevuld'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_f4f70727dc34561dfde1a3c529b6205c'] = 'Instellingen'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_459a6f79ad9b13cbcb5f692d2cc7a94d'] = 'APItoken'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_0612c008c0ceac34b53b5ca6a5ac4814'] = 'ServiceId'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_2d13df6f8b5e4c5af9f87e0dc39df69d'] = 'Wacht op betaling'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_505a83f220c02df2f85c3810cd9ceb38'] = 'Betaald'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_ea4788705e6873b424c65e91c2846b19'] = 'Geannuleerd'; +$_MODULE['<{paynl_paymentmethods}prestashop>paynl_paymentmethods_b17f3f4dcf653a5776792498a9b44d6a'] = 'Instellingen opslaan'; +$_MODULE['<{paynl_paymentmethods}prestashop>payment_return_88526efe38fd18179a127024aba8c1d7'] = 'Uw bestelling bij %s is voltooid'; +$_MODULE['<{paynl_paymentmethods}prestashop>payment_return_ae569d4f9d42a8a2e5fef14f18becb25'] = 'Uw ordernummer is: %s'; diff --git a/paynl_paymentmethods/views/templates/front/return_checkamount.tpl b/paynl_paymentmethods/views/templates/front/return_checkamount.tpl new file mode 100644 index 0000000..94b9fe4 --- /dev/null +++ b/paynl_paymentmethods/views/templates/front/return_checkamount.tpl @@ -0,0 +1,6 @@ +
+
+

Fout bij betaling

+

Neem a.u.b. contact met ons op.

+
+
diff --git a/paynl_paymentmethods/views/templates/front/return_paid.tpl b/paynl_paymentmethods/views/templates/front/return_paid.tpl new file mode 100644 index 0000000..2d6c603 --- /dev/null +++ b/paynl_paymentmethods/views/templates/front/return_paid.tpl @@ -0,0 +1,6 @@ +
+
+

Bedankt voor uw bestelling

+

Uw bestelling is ontvangen en zal wordeasdfasdfn verwerkt.

+
+
diff --git a/paynl_paymentmethods/views/templates/front/return_pending.tpl b/paynl_paymentmethods/views/templates/front/return_pending.tpl new file mode 100644 index 0000000..d71e927 --- /dev/null +++ b/paynl_paymentmethods/views/templates/front/return_pending.tpl @@ -0,0 +1,6 @@ +
+
+

Bedankt voor uw bestelling

+

Uw bestelling is ontvangen en zal worden verwerkt.

+
+
diff --git a/paynl_paymentmethods/views/templates/hook/payment_return.tpl b/paynl_paymentmethods/views/templates/hook/payment_return.tpl new file mode 100644 index 0000000..34738c3 --- /dev/null +++ b/paynl_paymentmethods/views/templates/hook/payment_return.tpl @@ -0,0 +1,29 @@ +{* +* 2007-2014 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2014 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} +Hallo +

{l s='Your order on %s is complete.' sprintf=$shop_name mod='paynl_paymentmethods'}

+ +

{l s='Your ordernumber is: %s' sprintf=$id_order mod='paynl_paymentmethods'}

+