Skip to content

Commit

Permalink
Merge pull request #138 from buckaroo-it/BP-3464-Add-Knaken-Settle-Pr…
Browse files Browse the repository at this point in the history
…estaShop

add Knaken payment method and update php sdk
  • Loading branch information
vegimcarkaxhija authored Mar 12, 2024
2 parents 097e1bb + 5a5ac54 commit 4ad7484
Show file tree
Hide file tree
Showing 39 changed files with 414 additions and 221 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The Buckaroo PrestaShop Payments Plugin ([Dutch](https://support.buckaroo.nl/cat

To use the Buckaroo plugin, please be aware of the following minimum requirements:
- A Buckaroo account ([Dutch](https://www.buckaroo.nl/start) or [English](https://www.buckaroo.eu/solutions/request-form))
- PrestaShop 1.7.x or 8.1.2
- PrestaShop 1.7.x or 8.1.4
- PHP 7.4 or higher

### Installation
Expand Down
2 changes: 1 addition & 1 deletion vendor/index.php → api/paymentmethods/knaken/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../../../../../');
header('Location: ../');
exit;
30 changes: 30 additions & 0 deletions api/paymentmethods/knaken/knaken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* It is available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this file
*
* @author Buckaroo.nl <[email protected]>
* @copyright Copyright (c) Buckaroo B.V.
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
if (!defined('_PS_VERSION_')) {
exit;
}

require_once dirname(__FILE__) . '/../paymentmethod.php';

class Knaken extends PaymentMethod
{
public function __construct()
{
$this->type = 'knaken';
$this->version = 1;
}
}
2 changes: 2 additions & 0 deletions api/paymentmethods/paymentrequestfactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class PaymentRequestFactory
public const REQUEST_TYPE_ALIPAY = 'alipay';
public const REQUEST_TYPE_MULTIBANCO = 'multibanco';
public const REQUEST_TYPE_MBWAY = 'mbway';
public const REQUEST_TYPE_KNAKEN = 'knaken';

// Request types (Payment Methods).
public static $valid_request_types = [
Expand Down Expand Up @@ -82,6 +83,7 @@ class PaymentRequestFactory
PaymentRequestFactory::REQUEST_TYPE_ALIPAY => 'Alipay',
PaymentRequestFactory::REQUEST_TYPE_MULTIBANCO => 'Multibanco',
PaymentRequestFactory::REQUEST_TYPE_MBWAY => 'Mbway',
PaymentRequestFactory::REQUEST_TYPE_KNAKEN => 'Knaken',
];

final public static function create($request_type_id, $data = [])
Expand Down
2 changes: 1 addition & 1 deletion buckaroo3.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct()
parent::__construct();

$this->displayName = $this->l('Buckaroo Payments') . ' (v ' . $this->version . ')';
$this->description = $this->l('Buckaroo Payment module. Compatible with PrestaShop version 1.7.x + 8.1.2');
$this->description = $this->l('Buckaroo Payment module. Compatible with PrestaShop version 1.7.x + 8.1.4');

$this->confirmUninstall = $this->l('Are you sure you want to delete Buckaroo Payments module?');
$this->tpl_folder = 'buckaroo3';
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
],
"require": {
"php": ">=7.4",
"buckaroo/sdk": "^1.9.1"
"buckaroo/sdk": "^1.11.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<name>buckaroo3</name>
<displayName><![CDATA[Buckaroo Payments (v 4.2.0)]]></displayName>
<version><![CDATA[4.2.0]]></version>
<description><![CDATA[Buckaroo Payment module. Compatible with PrestaShop version 1.7.x + 8.1.2]]></description>
<description><![CDATA[Buckaroo Payment module. Compatible with PrestaShop version 1.7.x + 8.1.4]]></description>
<author><![CDATA[Buckaroo]]></author>
<tab><![CDATA[payments_gateways]]></tab>
<confirmUninstall><![CDATA[Are you sure you want to delete Buckaroo Payments module?]]></confirmUninstall>
Expand Down
23 changes: 15 additions & 8 deletions controllers/front/request.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,21 @@ public function postProcess()
$debug = 'Currency: ' . $currency->name . "\nTotal Amount: " . $total . "\nPayment Method: " . $payment_method;
$logger->logInfo('Checkout info', $debug);

$this->checkout = Checkout::getInstance($payment_method, $cart, $this->context);
$this->checkout->platformName = 'PrestaShop';
$this->checkout->platformVersion = _PS_VERSION_;
$this->checkout->moduleSupplier = $this->module->author;
$this->checkout->moduleName = $this->module->name;
$this->checkout->moduleVersion = $this->module->version;
$this->checkout->returnUrl = 'http' . ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://' . $_SERVER['SERVER_NAME'] . __PS_BASE_URI__ . 'index.php?fc=module&module=buckaroo3&controller=userreturn'; // phpcs:ignore
$this->checkout->pushUrl = 'http' . ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://' . $_SERVER['SERVER_NAME'] . __PS_BASE_URI__ . 'index.php?fc=module&module=buckaroo3&controller=return';
try{
$this->checkout = Checkout::getInstance($payment_method, $cart, $this->context);
$this->checkout->platformName = 'PrestaShop';
$this->checkout->platformVersion = _PS_VERSION_;
$this->checkout->moduleSupplier = $this->module->author;
$this->checkout->moduleName = $this->module->name;
$this->checkout->moduleVersion = $this->module->version;
$this->checkout->returnUrl = 'http' . ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://' . $_SERVER['SERVER_NAME'] . __PS_BASE_URI__ . 'index.php?fc=module&module=buckaroo3&controller=userreturn'; // phpcs:ignore
$this->checkout->pushUrl = 'http' . ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://' . $_SERVER['SERVER_NAME'] . __PS_BASE_URI__ . 'index.php?fc=module&module=buckaroo3&controller=return';
} catch (Exception $e) {
$logger->logError('Set checkout info: ', $e->getMessage());
$this->displayError(null, $e->getMessage());

return;
}
$logger->logDebug('Get checkout class: ');
$pending = Configuration::get('BUCKAROO_ORDER_STATE_DEFAULT');

Expand Down
2 changes: 2 additions & 0 deletions dev/lang/php_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@
"payment_methods.transfer": "Überweisen",
"payment_methods.trustly": "Vertrauenswürdig",
"payment_methods.wechatpay": "WeChatPay",
"payment_methods.knaken": "Knaken",
"verification_methods.idin": "iDIN"
"verification_methods.idin": "iDIN",
"dashboard.pages.payments.displayInCheckout": "Group Credit-debitcards",
"dashboard.pages.payments.displayInCheckoutDesc": "Cards option on how to show the brands in the checkout. <br/> <b>Separate</b>: Card issuers are showed seperately in the checkout.</br><b>Grouped</b>: Card issuers are showed within one group."
Expand Down
2 changes: 2 additions & 0 deletions dev/lang/php_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@
"payment_methods.transfer": "Transfer",
"payment_methods.trustly": "Trustly",
"payment_methods.wechatpay": "WeChatPay",
"payment_methods.knaken": "Knaken",
"verification_methods.idin": "iDIN"
"verification_methods.idin": "iDIN",
"dashboard.pages.payments.displayInCheckout": "Group Credit-debitcards",
"dashboard.pages.payments.displayInCheckoutDesc": "Cards option on how to show the brands in the checkout. <br/> <b>Separate</b>: Card issuers are showed seperately in the checkout.</br><b>Grouped</b>: Card issuers are showed within one group."
Expand Down
2 changes: 2 additions & 0 deletions dev/lang/php_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@
"payment_methods.transfer": "Transfert",
"payment_methods.trustly": "En toute confiance",
"payment_methods.wechatpay": "WeChatPay",
"payment_methods.knaken": "Knaken",
"verification_methods.idin": "IDIN"
"verification_methods.idin": "IDIN",
"dashboard.pages.payments.displayInCheckout": "Group Credit-debitcards",
"dashboard.pages.payments.displayInCheckoutDesc": "Cards option on how to show the brands in the checkout. <br/> <b>Separate</b>: Card issuers are showed seperately in the checkout.</br><b>Grouped</b>: Card issuers are showed within one group."
Expand Down
2 changes: 2 additions & 0 deletions dev/lang/php_nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@
"payment_methods.transfer": "Transfer",
"payment_methods.trustly": "Trustly",
"payment_methods.wechatpay": "WeChatPay",
"payment_methods.knaken": "Knaken",
"verification_methods.idin": "iDIN"
"verification_methods.idin": "iDIN",
"dashboard.pages.payments.displayInCheckout": "Group Credit-debitcards",
"dashboard.pages.payments.displayInCheckoutDesc": "Cards option on how to show the brands in the checkout. <br/> <b>Separate</b>: Card issuers are showed seperately in the checkout.</br><b>Grouped</b>: Card issuers are showed within one group."
Expand Down
5 changes: 5 additions & 0 deletions library/checkout/checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ abstract class Checkout
public const CHECKOUT_TYPE_ALIPAY = 'alipay';
public const CHECKOUT_TYPE_MBWAY = 'mbway';
public const CHECKOUT_TYPE_MULTIBANCO = 'multibanco';
public const CHECKOUT_TYPE_KNAKEN = 'knaken';

// Request types (Payment Methods).
public static $payment_method_type = [
Expand Down Expand Up @@ -91,6 +92,7 @@ abstract class Checkout
Checkout::CHECKOUT_TYPE_ALIPAY => 'Alipay',
Checkout::CHECKOUT_TYPE_MBWAY => 'Mbway',
Checkout::CHECKOUT_TYPE_MULTIBANCO => 'Multibanco',
Checkout::CHECKOUT_TYPE_KNAKEN => 'Knaken',
];

protected $payment_request;
Expand Down Expand Up @@ -294,6 +296,7 @@ public function getResponse()
final public static function getInstance($payment_method, $cart, $context)
{
$class_name = self::$payment_method_type[$payment_method] . 'Checkout';

checkoutautoload($class_name); // Try to find class in api directory

if (!class_exists($class_name)) {
Expand Down Expand Up @@ -459,7 +462,9 @@ public function initials($str)
function checkoutautoload($payment_method)
{
$class_name = Tools::strtolower($payment_method);

$path = dirname(__FILE__) . "/{$class_name}.php";

if (file_exists($path)) {
require_once $path;
} else {
Expand Down
51 changes: 51 additions & 0 deletions library/checkout/knakencheckout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* It is available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this file
*
* @author Buckaroo.nl <[email protected]>
* @copyright Copyright (c) Buckaroo B.V.
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
include_once _PS_MODULE_DIR_ . 'buckaroo3/library/checkout/checkout.php';

if (!defined('_PS_VERSION_')) {
exit;
}

class KnakenCheckout extends Checkout
{
protected $customVars = [];

final public function setCheckout()
{
parent::setCheckout();
}

public function startPayment()
{
$this->payment_response = $this->payment_request->pay($this->customVars);
}

public function isRedirectRequired()
{
return true;
}

public function isVerifyRequired()
{
return false;
}

protected function initialize()
{
$this->payment_request = PaymentRequestFactory::create(PaymentRequestFactory::REQUEST_TYPE_KNAKEN);
}
}
1 change: 1 addition & 0 deletions src/Repository/RawPaymentMethodRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ private function getPaymentMethodsData()
['name' => 'idin', 'label' => 'iDIN', 'icon' => 'iDIN.svg', 'template' => 'idin.tpl', 'is_payment_method' => '0'],
['name' => 'multibanco', 'label' => 'Multibanco', 'icon' => 'Multibanco.svg', 'template' => '', 'is_payment_method' => '1'],
['name' => 'mbway', 'label' => 'MB WAY', 'icon' => 'MBWay.svg', 'template' => '', 'is_payment_method' => '1'],
['name' => 'knaken', 'label' => 'Knaken Settle', 'icon' => 'Knaken.svg', 'template' => '', 'is_payment_method' => '1'],
];
}

Expand Down
37 changes: 37 additions & 0 deletions upgrade/upgrade-4.2.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,52 @@
* @copyright Copyright (c) Buckaroo B.V.
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/

use Buckaroo\PrestaShop\Src\Repository\RawOrderingRepository;

if (!defined('_PS_VERSION_')) {
exit;
}

/**
* @return mixed
* @throws Exception
*/
function upgrade_module_4_2_0($object)
{
Db::getInstance()->execute('UPDATE ' . _DB_PREFIX_ . 'bk_payment_methods SET label = "Bancontact" WHERE name = "bancontactmrcash"');

// Insert the Knaken Settle payment method
$knakenData = [
'name' => 'knaken',
'label' => 'Knaken Settle',
'icon' => 'Knaken.svg',
'template' => '',
'is_payment_method' => '1',
];

$keys = array_keys($knakenData);
$values = array_map(function ($value) {
return pSQL($value);
}, array_values($knakenData));

$insertQuery = 'INSERT INTO ' . _DB_PREFIX_ . 'bk_payment_methods (' . implode(', ', $keys) . ') VALUES ("' . implode('", "', $values) . '")';
Db::getInstance()->execute($insertQuery);


// Get the inserted payment method ID
$paymentMethodId = Db::getInstance()->Insert_ID();

// Insert default configuration for Knaken Settle
$knakenConfig = [
'mode' => 'off'
];

$configInsertQuery = 'INSERT INTO ' . _DB_PREFIX_ . 'bk_configuration (configurable_id, value) VALUES (' . (int)$paymentMethodId . ', \'' . pSQL(json_encode($knakenConfig)) . '\')';
Db::getInstance()->execute($configInsertQuery);

$orderingRepository = new RawOrderingRepository();
$orderingRepository->insertCountryOrdering();

return true;
}
19 changes: 3 additions & 16 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,10 @@
// autoload.php @generated by Composer

if (PHP_VERSION_ID < 50600) {
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
if (!ini_get('display_errors')) {
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
fwrite(STDERR, $err);
} elseif (!headers_sent()) {
echo $err;
}
}
trigger_error(
$err,
E_USER_ERROR
);
echo 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
exit(1);
}

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

return ComposerAutoloaderInit8ecd0dc7aae942debb302425dde8f935::getLoader();
return ComposerAutoloaderInitec954cb8a735a3d6d924f21624d6b9cb::getLoader();
2 changes: 1 addition & 1 deletion vendor/buckaroo/sdk/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "buckaroo/sdk",
"description": "Buckaroo payment SDK",
"license": "MIT",
"version": "1.10.0",
"version": "1.11.0",
"type": "library",
"require": {
"php": ">=7.4|^8.0",
Expand Down
5 changes: 4 additions & 1 deletion vendor/buckaroo/sdk/src/Handlers/Logging/DefaultLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ class DefaultLogger implements Subject, LoggerInterface
*/
public function __construct()
{
$this->attach(new Monolog());
if (($_ENV['BPE_LOG'] ?? false) === 'true')
{
$this->attach(new Monolog());
}

if (($_ENV['BPE_REPORT_ERROR'] ?? false) === 'true')
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
class PhoneAdapter extends ServiceParametersKeysAdapter
{
protected array $keys = [
'mobile' => 'MobilePhone'
'mobile' => 'Phone'
];
}
Loading

0 comments on commit 4ad7484

Please sign in to comment.