Skip to content

Commit

Permalink
Order no longer processed on return page
Browse files Browse the repository at this point in the history
Fixed an error regarding refunds and bank transfer payments
  • Loading branch information
Andy Pieters committed Sep 15, 2017
1 parent fd00a17 commit d0e8fd0
Show file tree
Hide file tree
Showing 19 changed files with 360 additions and 67 deletions.
2 changes: 1 addition & 1 deletion paynlpaymentmethods/composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "paynl/prestashop-plugin",
"name": "paynl/paynlpaymentmethods",
"description": "PrestaShop module paymentexample",
"homepage": "https://github.com/Paynl/prestashop-plugin",
"license": "AFL - Academic Free License (AFL 3.0)",
Expand Down
14 changes: 7 additions & 7 deletions paynlpaymentmethods/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion paynlpaymentmethods/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>paynlpaymentmethods</name>
<displayName><![CDATA[Pay.nl Payment Methods]]></displayName>
<version><![CDATA[4.0.0]]></version>
<version><![CDATA[4.0.1]]></version>
<description><![CDATA[]]></description>
<author><![CDATA[Pay.nl]]></author>
<tab><![CDATA[payments_gateways]]></tab>
Expand Down
2 changes: 1 addition & 1 deletion paynlpaymentmethods/config_nl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>paynlpaymentmethods</name>
<displayName><![CDATA[Pay.nl]]></displayName>
<version><![CDATA[4.0.0]]></version>
<version><![CDATA[4.0.1]]></version>
<description><![CDATA[Add many payment methods to you webshop]]></description>
<author><![CDATA[Pay.nl]]></author>
<tab><![CDATA[payments_gateways]]></tab>
Expand Down
2 changes: 1 addition & 1 deletion paynlpaymentmethods/controllers/front/finish.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function postProcess()
* @var $module PaynlPaymentMethods
*/

$transaction = $module->processPayment($transactionId);
$transaction = $module->getTransaction($transactionId);

if ($transaction->isPaid() || $transaction->isPending() || $transaction->isBeingVerified()) {
// naar success
Expand Down
59 changes: 42 additions & 17 deletions paynlpaymentmethods/paynlpaymentmethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
require_once __DIR__ . '/vendor/autoload.php';
//check if the SDK nieeds to be loaded
if(!class_exists('\Paynl\Paymentmethods')){
$autoload_location = __DIR__ . '/vendor/autoload.php';
if(file_exists($autoload_location)){
require_once $autoload_location;
}
}
use PrestaShop\PrestaShop\Core\Payment\PaymentOption;

if (!defined('_PS_VERSION_')) {
Expand All @@ -47,7 +53,7 @@ public function __construct()
{
$this->name = 'paynlpaymentmethods';
$this->tab = 'payments_gateways';
$this->version = '4.0.0';
$this->version = '4.0.1';
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
$this->author = 'Pay.nl';
$this->controllers = array('startPayment', 'finish', 'exchange');
Expand All @@ -69,6 +75,7 @@ public function __construct()
if (!count(Currency::checkPaymentCurrencies($this->id))) {
$this->warning = $this->l('No currency has been set for this module.');
}

}

public function install()
Expand Down Expand Up @@ -110,7 +117,7 @@ public function checkCurrency($cart)
return false;
}

private function getPaymentMethods($cart)
private function getPaymentMethods($cart = null)
{
/**
* @var $cart CartCore
Expand Down Expand Up @@ -148,9 +155,11 @@ private function getPaymentMethodsForCart(Cart $cart)
/**
* @var $cart CartCore
*/
$cartTotal = $cart->getOrderTotal(true, Cart::BOTH);

$paymentMethods = json_decode(Configuration::get('PAYNL_PAYMENTMETHODS'));
if($cart === null) return $paymentMethods;

$cartTotal = $cart->getOrderTotal(true, Cart::BOTH);
$result = array();
foreach ($paymentMethods as $paymentMethod) {
if (isset($paymentMethod->enabled) && $paymentMethod->enabled == true) {
Expand Down Expand Up @@ -190,17 +199,21 @@ private function sdkLogin()
\Paynl\Config::setServiceId($serviceId);
}

public function getTransaction($transactionId){
$this->sdkLogin();

$transaction = \Paynl\Transaction::get($transactionId);

return $transaction;
}

public function processPayment($transactionId, &$message = null)
{
$this->sdkLogin();

$transaction = \Paynl\Transaction::get($transactionId);
$transaction = $this->getTransaction($transactionId);

$order_state = $this->statusPending;
if ($transaction->isPaid()) {
$order_state = $this->statusPaid;


} elseif ($transaction->isCanceled()) {
$order_state = $this->statusCanceled;
$status = 'CANCELED';
Expand All @@ -214,13 +227,16 @@ public function processPayment($transactionId, &$message = null)
* @var $orderState OrderStateCore
*/
$orderState = new OrderState($order_state);

$orderStateName = $orderState->name;
if(is_array($orderStateName)){
$orderStateName = array_pop($orderStateName);
}
$cart = new Cart($transaction->getExtra1());
/**
* @var $cart CartCore
*/

if ($orderId = Order::getOrderByCartId($transaction->getExtra1())) {
if ($orderId = Order::getIdByCartId($transaction->getExtra1())) {
$order = new Order($orderId);

/**
Expand All @@ -230,10 +246,15 @@ public function processPayment($transactionId, &$message = null)
$message = 'Order is already paid | OrderRefercene: ' . $order->reference;
return $transaction;
}
/**
* @var $history OrderHistoryCore
*/
$orderPayment = OrderPayment::getByOrderReference($order->reference);

$orderPayment = null;
$arrOrderPayment = OrderPayment::getByOrderReference($order->reference);
foreach($arrOrderPayment as $objOrderPayment){
if($objOrderPayment->transaction_id == $transactionId){
$orderPayment = $objOrderPayment;
}
}

/**
* @var $orderPayment OrderPaymentCore
*/
Expand All @@ -257,7 +278,7 @@ public function processPayment($transactionId, &$message = null)
$history->changeIdOrderState($order_state, $order->id, true);
$history->addWs();

$message = "Updated order (" . $order->reference . ") to: " . $orderState->name;
$message = "Updated order (" . $order->reference . ") to: " . $orderStateName;

} else {
if ($transaction->isPaid()) {
Expand All @@ -268,7 +289,7 @@ public function processPayment($transactionId, &$message = null)
$orderId = Order::getOrderByCartId($transaction->getExtra1());
$order = new Order($orderId);

$message = "Validated order (" . $order->reference . ") with status: " . $orderState->name;
$message = "Validated order (" . $order->reference . ") with status: " . $orderStateName;
}
}
return $transaction;
Expand Down Expand Up @@ -427,6 +448,10 @@ public function getContent()
$this->_html .= '<br />';
}
$loggedin = false;
if(!class_exists('\Paynl\Paymentmethods')){
$this->adminDisplayWarning($this->l('Cannot find Pay.nl SDK, did you install the source code instead of the package?'));
return;
}
try {
$this->sdkLogin();
//call api to check if the credentials are correct
Expand Down
4 changes: 2 additions & 2 deletions paynlpaymentmethods/vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

// autoload.php @generated by Composer

require_once __DIR__ . '/composer' . '/autoload_real.php';
require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit6b58c58329851c79dd02ede5a034cbfe::getLoader();
return ComposerAutoloaderInit41828881b756f2e22f2f489bd2e486dd::getLoader();
12 changes: 7 additions & 5 deletions paynlpaymentmethods/vendor/composer/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class ClassLoader

private $useIncludePath = false;
private $classMap = array();

private $classMapAuthoritative = false;
private $missingClasses = array();

public function getPrefixes()
{
Expand Down Expand Up @@ -322,20 +322,20 @@ public function findFile($class)
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative) {
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}

$file = $this->findFileWithExtension($class, '.php');

// Search for Hack files if we are running on HHVM
if ($file === null && defined('HHVM_VERSION')) {
if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}

if ($file === null) {
if (false === $file) {
// Remember that this class does not exist.
return $this->classMap[$class] = false;
$this->missingClasses[$class] = true;
}

return $file;
Expand Down Expand Up @@ -399,6 +399,8 @@ private function findFileWithExtension($class, $ext)
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}

return false;
}
}

Expand Down
8 changes: 4 additions & 4 deletions paynlpaymentmethods/vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit6b58c58329851c79dd02ede5a034cbfe
class ComposerAutoloaderInit41828881b756f2e22f2f489bd2e486dd
{
private static $loader;

Expand All @@ -19,15 +19,15 @@ public static function getLoader()
return self::$loader;
}

spl_autoload_register(array('ComposerAutoloaderInit6b58c58329851c79dd02ede5a034cbfe', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit41828881b756f2e22f2f489bd2e486dd', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit6b58c58329851c79dd02ede5a034cbfe', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit41828881b756f2e22f2f489bd2e486dd', 'loadClassLoader'));

$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION');
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';

call_user_func(\Composer\Autoload\ComposerStaticInit6b58c58329851c79dd02ede5a034cbfe::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit41828881b756f2e22f2f489bd2e486dd::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
Expand Down
6 changes: 3 additions & 3 deletions paynlpaymentmethods/vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInit6b58c58329851c79dd02ede5a034cbfe
class ComposerStaticInit41828881b756f2e22f2f489bd2e486dd
{
public static $prefixLengthsPsr4 = array (
'P' =>
Expand All @@ -31,8 +31,8 @@ class ComposerStaticInit6b58c58329851c79dd02ede5a034cbfe
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit6b58c58329851c79dd02ede5a034cbfe::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit6b58c58329851c79dd02ede5a034cbfe::$prefixDirsPsr4;
$loader->prefixLengthsPsr4 = ComposerStaticInit41828881b756f2e22f2f489bd2e486dd::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit41828881b756f2e22f2f489bd2e486dd::$prefixDirsPsr4;

}, null, ClassLoader::class);
}
Expand Down
12 changes: 6 additions & 6 deletions paynlpaymentmethods/vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@
},
{
"name": "paynl/sdk",
"version": "v1.2.9",
"version_normalized": "1.2.9.0",
"version": "v1.3.2",
"version_normalized": "1.3.2.0",
"source": {
"type": "git",
"url": "https://github.com/paynl/sdk.git",
"reference": "3521f99df7f9d34709b8fb1acfab10423084407f"
"reference": "f558a14cd61e270eba3be8a8c14502558cdd3c12"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/paynl/sdk/zipball/3521f99df7f9d34709b8fb1acfab10423084407f",
"reference": "3521f99df7f9d34709b8fb1acfab10423084407f",
"url": "https://api.github.com/repos/paynl/sdk/zipball/f558a14cd61e270eba3be8a8c14502558cdd3c12",
"reference": "f558a14cd61e270eba3be8a8c14502558cdd3c12",
"shasum": ""
},
"require": {
Expand All @@ -79,7 +79,7 @@
"phpunit/phpunit": "^4.8",
"satooshi/php-coveralls": "~1.0"
},
"time": "2017-03-14 16:42:11",
"time": "2017-06-06 15:12:07",
"type": "library",
"installation-source": "dist",
"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion paynlpaymentmethods/vendor/paynl/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ You can download the zip on the projects [releases](https://github.com/paynl/sdk

### Requirements

The Pay.nl PHP SDK works on php versions 5.3, 5.4, 5.5 and 5.6.
The Pay.nl PHP SDK works on php versions 5.3, 5.4, 5.5, 5.6, 7.0 and 7.1
Also the php curl extension needs to be installed.

### Quick start and examples
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*
* Copyright (C) 2015 Andy Pieters <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

require_once '../../vendor/autoload.php';
require_once '../config.php';

try {
$result = \Paynl\Transaction::addRecurring(array(
'transactionId' => '12345678Xbf1234',
'amount' => 0.01,
'description' => 'Your recurring payment',
'extra1' => 'SDK',
'extra2' => 'extra2',
'extra3' => 'extra3'
));

echo $result->getTransactionId();
} catch (\Paynl\Error\Error $e) {
echo $e->getMessage();
}
Loading

0 comments on commit d0e8fd0

Please sign in to comment.