Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Pieters committed Dec 30, 2015
0 parents commit dde31be
Show file tree
Hide file tree
Showing 28 changed files with 2,176 additions and 0 deletions.
13 changes: 13 additions & 0 deletions paynl_paymentmethods/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>paynl_paymentmethods</name>
<displayName><![CDATA[Pay.nl Payment methods]]></displayName>
<version><![CDATA[3.2.8]]></version>
<description><![CDATA[Accept payments by Pay.nl]]></description>
<author><![CDATA[]]></author>
<tab><![CDATA[payments_gateways]]></tab>
<confirmUninstall><![CDATA[Are you sure you want to delete your details?]]></confirmUninstall>
<is_configurable>1</is_configurable>
<need_instance>1</need_instance>
<limited_countries></limited_countries>
</module>
13 changes: 13 additions & 0 deletions paynl_paymentmethods/config_nl.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>paynl_paymentmethods</name>
<displayName><![CDATA[Pay.nl betaalmethoden]]></displayName>
<version><![CDATA[3.2.6]]></version>
<description><![CDATA[Acepteer betalingen via Pay.nl]]></description>
<author><![CDATA[]]></author>
<tab><![CDATA[payments_gateways]]></tab>
<confirmUninstall><![CDATA[Weet je zeker dat je de gegevens wilt verwijderen?]]></confirmUninstall>
<is_configurable>1</is_configurable>
<need_instance>1</need_instance>
<limited_countries></limited_countries>
</module>
53 changes: 53 additions & 0 deletions paynl_paymentmethods/controllers/front/exchange.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/*
* 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 [email protected] 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 <[email protected]>
* @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();
}
}
35 changes: 35 additions & 0 deletions paynl_paymentmethods/controllers/front/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*
* 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 [email protected] 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 <[email protected]>
* @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;
238 changes: 238 additions & 0 deletions paynl_paymentmethods/controllers/front/payment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
<?php

/*
* 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 [email protected] 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 <[email protected]>
* @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
}

}
Loading

0 comments on commit dde31be

Please sign in to comment.