From 759df4ee7dc9d8cbc4eb45b4430dbfce7e6e5194 Mon Sep 17 00:00:00 2001 From: richard Date: Wed, 25 Aug 2021 14:37:54 +0200 Subject: [PATCH] Fix: Percentage extra costs. --- .gitignore | 30 --- .../cardgate-clientlib-php/.gitignore | 5 + .../cardgate-clientlib-php/src/Client.php | 42 +--- .../cardgate-clientlib-php/src/Method.php | 10 + modules/cardgate/cardgate.php | 2 +- modules/cardgate/cardgatepayment.php | 2 +- modules/cardgatespraypay/cardgatespraypay.php | 214 ++++++++++++++++++ modules/cardgatespraypay/config.xml | 13 ++ modules/cardgatespraypay/config_nl.xml | 13 ++ modules/cardgatespraypay/logo.gif | Bin 0 -> 417 bytes modules/cardgatespraypay/redirect.php | 18 ++ modules/cardgatespraypay/translations/nl.php | 9 + 12 files changed, 288 insertions(+), 70 deletions(-) create mode 100644 modules/cardgatespraypay/cardgatespraypay.php create mode 100644 modules/cardgatespraypay/config.xml create mode 100644 modules/cardgatespraypay/config_nl.xml create mode 100644 modules/cardgatespraypay/logo.gif create mode 100644 modules/cardgatespraypay/redirect.php create mode 100644 modules/cardgatespraypay/translations/nl.php diff --git a/.gitignore b/.gitignore index 2c45f86..e69de29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,30 +0,0 @@ -* -!.gitignore -!modules/ -modules/* -!modules/cardgate/ -!modules/cardgateafterpay/ -!modules/cardgatebanktransfer/ -!modules/cardgatebillink/ -!modules/cardgatebitcoin/ -!modules/cardgatecreditcard/ -!modules/cardgatedirectdebit/ -!modules/cardgatedirectebanking/ -!modules/cardgategiftcard/ -!modules/cardgategiropay/ -!modules/cardgateideal/ -!modules/cardgateidealqr/ -!modules/cardgateklarna/ -!modules/cardgatemc/ -!modules/cardgateonlineueberweisen/ -!modules/cardgatepaypal/ -!modules/cardgatepaysafecard/ -!modules/cardgatepaysafecash/ -!modules/cardgateprzelewy24/ -!tests/ -!README.md -!README_DE.md -!README_NL.md -!composer.json -!.travis.yml -!phpunit.xml.dist \ No newline at end of file diff --git a/modules/cardgate/cardgate-clientlib-php/.gitignore b/modules/cardgate/cardgate-clientlib-php/.gitignore index 689835a..439544e 100644 --- a/modules/cardgate/cardgate-clientlib-php/.gitignore +++ b/modules/cardgate/cardgate-clientlib-php/.gitignore @@ -4,3 +4,8 @@ /doc /doc.generate.sh INTERNAL +*.log +git.php +cardgate-clientlib.sublime-project +cardgate-clientlib.sublime-workspace +sftp-config.json diff --git a/modules/cardgate/cardgate-clientlib-php/src/Client.php b/modules/cardgate/cardgate-clientlib-php/src/Client.php index 42927f3..56cb4a7 100644 --- a/modules/cardgate/cardgate-clientlib-php/src/Client.php +++ b/modules/cardgate/cardgate-clientlib-php/src/Client.php @@ -35,7 +35,7 @@ final class Client { /** * Client version. */ - const CLIENT_VERSION = "1.1.12"; + const CLIENT_VERSION = "1.1.15"; /** * Url to use for production. @@ -382,46 +382,12 @@ public function getLastResult() { * @access public * @api */ - static public function pullConfig( $sToken_, $bTestmode_ = FALSE ) { + public function pullConfig( $sToken_ ) { if ( ! is_string( $sToken_ ) ) { throw new Exception( 'Client.Token.Invalid', 'invalid token for settings pull: ' . $sToken_ ); } - $sResource = "pullconfig/{$sToken_}/"; - $sUrl = ( $bTestmode_ ? self::URL_STAGING : self::URL_PRODUCTION ) . $sResource; - - $rCh = curl_init(); - curl_setopt( $rCh, CURLOPT_URL, $sUrl ); - curl_setopt( $rCh, CURLOPT_RETURNTRANSFER, 1 ); - curl_setopt( $rCh, CURLOPT_TIMEOUT, 60 ); - curl_setopt( $rCh, CURLOPT_HEADER, FALSE ); - curl_setopt( $rCh, CURLOPT_HTTPHEADER, [ - 'Content-Type: application/json', - 'Accept: application/json' - ] ); - if ( $bTestmode_ ) { - curl_setopt( $rCh, CURLOPT_SSL_VERIFYPEER, FALSE ); - curl_setopt( $rCh, CURLOPT_SSL_VERIFYHOST, 0 ); - } else { - curl_setopt( $rCh, CURLOPT_SSL_VERIFYPEER, TRUE ); // verify SSL peer - curl_setopt( $rCh, CURLOPT_SSL_VERIFYHOST, 2 ); // check for valid common name and verify host - } - - if ( FALSE == ( $sResults = curl_exec( $rCh ) ) ) { - $sError = curl_error( $rCh ); - curl_close( $rCh ); - throw new Exception( 'Client.Request.Curl.Error', $sError ); - } else { - curl_close( $rCh ); - } - if ( NULL === ( $aResults = json_decode( $sResults, TRUE ) ) ) { - throw new Exception( 'Client.Request.JSON.Invalid', 'remote gave invalid JSON: ' . $sResults ); - } - if ( isset( $aResults['error'] ) ) { - throw new Exception( 'Client.Request.Remote.' . $aResults['error']['code'], $aResults['error']['message'] ); - } - - return $aResults; + return $this->doRequest($sResource); } /** @@ -536,7 +502,7 @@ public function doRequest( $sResource_, $aData_ = NULL, $sHttpMethod_ = 'POST' ) } if ( 'POST' == $sHttpMethod_ ) { - $this->_sLastRequest = json_encode( $aData_ ); + $this->_sLastRequest = json_encode( $aData_, JSON_PARTIAL_OUTPUT_ON_ERROR ); curl_setopt( $rCh, CURLOPT_URL, $sUrl ); curl_setopt( $rCh, CURLOPT_POST, TRUE ); curl_setopt( $rCh, CURLOPT_POSTFIELDS, $this->_sLastRequest ); diff --git a/modules/cardgate/cardgate-clientlib-php/src/Method.php b/modules/cardgate/cardgate-clientlib-php/src/Method.php index 68b3826..5a5344e 100644 --- a/modules/cardgate/cardgate-clientlib-php/src/Method.php +++ b/modules/cardgate/cardgate-clientlib-php/src/Method.php @@ -132,6 +132,16 @@ final class Method { */ const GIFTCARD = 'giftcard'; + /** + * EPS + */ + const EPS = 'eps'; + + /** + * SprayPay + */ + const SPRAYPAY = 'spraypay'; + /** * The client associated with this payment method. * @var Client diff --git a/modules/cardgate/cardgate.php b/modules/cardgate/cardgate.php index d7b8d4c..b73c01f 100644 --- a/modules/cardgate/cardgate.php +++ b/modules/cardgate/cardgate.php @@ -10,7 +10,7 @@ class Cardgate extends PaymentModule { var $shop_version = _PS_VERSION_; public function __construct() { - Configuration::updateValue ( 'CARDGATE_MODULE_VERSION', '1.7.12' ); + Configuration::updateValue ( 'CARDGATE_MODULE_VERSION', '1.7.13' ); $this->name = 'cardgate'; $this->paymentcode = 'cardgate'; $this->paymentname = 'CardGate'; diff --git a/modules/cardgate/cardgatepayment.php b/modules/cardgate/cardgatepayment.php index 57d8601..07518bb 100644 --- a/modules/cardgate/cardgatepayment.php +++ b/modules/cardgate/cardgatepayment.php @@ -4,7 +4,7 @@ class CardgatePayment extends PaymentModule { - var $version = '1.7.12'; + var $version = '1.7.13'; var $tab = 'payments_gateways'; var $author = 'CardGate'; var $shop_version = _PS_VERSION_; diff --git a/modules/cardgatespraypay/cardgatespraypay.php b/modules/cardgatespraypay/cardgatespraypay.php new file mode 100644 index 0000000..ee3a3f5 --- /dev/null +++ b/modules/cardgatespraypay/cardgatespraypay.php @@ -0,0 +1,214 @@ +l('Pay with') + */ +class Cardgatespraypay extends PaymentModule { + + var $tab = 'payments_gateways'; + var $author = 'CardGate'; + var $shop_version = _PS_VERSION_; + var $currencies = true; + var $currencies_mode = 'radio'; + var $_html = ''; + var $extra_cost = ''; + protected $_paymentHookTpl = ''; + + private $_postErrors = array(); + protected $_childClassFile = __FILE__; + + /** + * Available payment methods setup + */ + public function __construct() { + global $cookie, $order; + + $this->name = 'cardgatespraypay'; + $this->paymentcode = 'spraypay'; + $this->ps_versions_compliancy = array('min' => '1.7.1.0', 'max' => _PS_VERSION_ ); + $this->paymentname = 'SprayPay'; + $this->logoname = 'spraypay'; + $this->version = Configuration::get('CARDGATE_MODULE_VERSION'); + $this->imageurl = 'https://gateway.cardgateplus.com/images/logo' . $this->paymentcode . '.gif'; + $this->extra_cost = Configuration::get('CARDGATE_' . strtoupper( $this->paymentcode ) . '_EXTRACOST'); + $this->controllers = array('validation'); + $this->is_eu_compatible = 1; + $this->currencies = true; + $this->currencies_mode = 'checkbox'; + $this->bootstrap = true; + + parent::__construct(); + $this->page = basename( __FILE__, '.php'); + $this->displayName = $this->l('CardGate SprayPay'); + $this->description = $this->l('Accepts payments with CardGate SprayPay.'); + $this->confirmUninstall = $this->l('Are you sure you want to delete your details?'); + + if ( !count( Currency::checkPaymentCurrencies( $this->id ) ) ) { + $this->warning = $this->l('No currency has been set for this module.'); + } + + $total = 0; + $rate = 'EUR'; + + if ( isset( $GLOBALS['cart'] ) && $GLOBALS['cart']->id_currency > 0 ) { + $currency = new Currency( $GLOBALS['cart']->id_currency ); + $total = round( Tools::convertPrice( $GLOBALS['cart']->getOrderTotal( true, 3 ), $currency ), 2 ); + $rate = $currency->iso_code; + } + $id_lang = (!isset( $cookie ) OR ! is_object( $cookie )) ? intval( Configuration::get('PS_LANG_DEFAULT') ) : intval( $cookie->id_lang ); + + if ( isset( $GLOBALS['CARDGATENOTFOUND'] ) ) + $this->warning = $this->l('The CardGate module is not found.'); + } + + public function install() { + + if ( !parent::install() || !$this->registerHook('paymentOptions') || !$this->registerHook('paymentReturn') ) { + return false; + } + return true; + + $payment = strtoupper( $this->paymentcode ); + + if ( !parent::install() OR ! $this->registerHook('payment') ) + return false; + return true; + } + + public function uninstall() { + + $paymentcode = $this->paymentcode; + + if ( $paymentcode == '') + return false; + + $paymentcode = strtoupper( $paymentcode ); + + if ( !parent::uninstall() ) + return false; + return true; + } + + public function hookPaymentOptions( $params ) { + + if ( !$this->active ) { + return; + } + if ( !$this->checkCurrency( $params['cart'] ) ) { + return; + } + + if (isset($_COOKIE['issuer'])){ + $issuer = $_COOKIE['issuer']; + } else { + $issuer = 0; + } + + $paymentOption = new PaymentOption(); + + $costText = ''; + $extraCosts = $this->extraCosts($this->extra_cost); + + if ($extraCosts > 0 ){ + $oCurrency = new Currency( $params['cart']->id_currency ); + $costText .= ' + '.$oCurrency->sign.' '.number_format($extraCosts, 2); + } + + if ($this->paymentcode == 'ideal'){ + $this->smarty->assign(['issuers'=>$this->getBanks(),'selected'=>$issuer]); + $additionalInformation = $this->fetch('module:cardgateideal/views/templates/front/payment_infos.tpl'); + } else { + $additionalInformation = null; + } + + $display = Configuration::get('CARDGATE_PAYMENT_DISPLAY'); + + if ($display == 'textandlogo' || $display == 'textonly'){ + $actionText = $this->l('Pay with').' '.$this->paymentname . $costText; + } else { + $actionText = null; + } + + if ($display == 'textandlogo' || $display == 'logoonly' ){ + $logo = Media::getMediaPath(_PS_MODULE_DIR_.$this->name.'/logo.gif'); + } else { + $logo = null; + } + $paymentOption->setCallToActionText($actionText ) + ->setAction($this->context->link->getModuleLink('cardgate', 'validation', array(), true)) + ->setInputs( $this->paymentData() ) + ->setAdditionalInformation($additionalInformation) + ->setLogo($logo); + + $payment_options = [ + $paymentOption + ]; + return $payment_options; + } + + public function checkCurrency( $cart ) { + $currency_order = new Currency( $cart->id_currency ); + $currencies_module = $this->getCurrency( $cart->id_currency ); + if ( is_array( $currencies_module ) ) { + foreach ( $currencies_module as $currency_module ) { + if ( $currency_order->id == $currency_module['id_currency'] ) { + return true; + } + } + } + return false; + } + + public function displayConf() { + + $this->_html = $this->displayConfirmation( $this->l('Settings updated') ); + } + + public function paymentData() { + $data = [ + 'option' => [ + 'name' => 'option', + 'type' => 'hidden', + 'value' => $this->paymentcode, + ] + ]; + + return $data; + } + + public function extraCosts( $extra_cost ) { + $cart = $this->context->cart; + $total = number_format( ($cart->getOrderTotal( true, Cart::BOTH ) ), 2, '.', ''); + if ( $extra_cost == 0 || $extra_cost == '') { + return 0; + } + if ( strstr( $extra_cost, '%') ) { + $percentage = str_replace('%', '', $extra_cost ); + return round( ($total * $percentage / 100 ), 2 ); + } + if ( is_numeric( $extra_cost ) ) { + return round( $extra_cost, 2 ); + } + } +} + +?> diff --git a/modules/cardgatespraypay/config.xml b/modules/cardgatespraypay/config.xml new file mode 100644 index 0000000..be31f6e --- /dev/null +++ b/modules/cardgatespraypay/config.xml @@ -0,0 +1,13 @@ + + + cardgatespraypay + + + + + + + 0 + 1 + + \ No newline at end of file diff --git a/modules/cardgatespraypay/config_nl.xml b/modules/cardgatespraypay/config_nl.xml new file mode 100644 index 0000000..e76876f --- /dev/null +++ b/modules/cardgatespraypay/config_nl.xml @@ -0,0 +1,13 @@ + + + cardgatespraypay + + + + + + + 0 + 1 + + \ No newline at end of file diff --git a/modules/cardgatespraypay/logo.gif b/modules/cardgatespraypay/logo.gif new file mode 100644 index 0000000000000000000000000000000000000000..1ec92d50a74a418cd11af298d990dfae90fca3f6 GIT binary patch literal 417 zcmZ?wbhEHbv|$it_^QjmAY92{(#UGx&gRg;?cBxd+AZSNE$H4W)P$wz0ad(uV?=O?}>+eCIit?pD9Our=9YhafX3h zp!k!8m4QK*K?h_2$WIJx`wmPi(9jX>Ji+p5M~>C}Bf`O1NnG3))`VGSO71=JDqxpx zdZ_LJ(Lb@1&VI1iarC29Z)a8rGLv)sHXJ61XO z@0~DdVzHEhlink ) ) { + Context::getContext()->link = new Link(); +} + +if ( isset( $_GET['extra'] ) && isset( $_GET['status'] ) ) { + header( 'Location: ' . Tools::getHttpHost( true, true ) . __PS_BASE_URI__ . 'order-confirmation.php' ); +} +?> \ No newline at end of file diff --git a/modules/cardgatespraypay/translations/nl.php b/modules/cardgatespraypay/translations/nl.php new file mode 100644 index 0000000..5bbf82f --- /dev/null +++ b/modules/cardgatespraypay/translations/nl.php @@ -0,0 +1,9 @@ +cardgategiropay_da9c72b9e543135f3f59e3c8ac68ef35'] = 'Betaal met'; +$_MODULE['<{cardgategiropay}prestashop>cardgategiropay_c6595881e4de8ffbafefed1eb1491479'] = 'CardGate Giropay'; +$_MODULE['<{cardgategiropay}prestashop>cardgategiropay_29ad3a89f3bbaa5522c505f2629c699a'] = 'Accepteert betalingen met CardGate Giropay'; +$_MODULE['<{cardgategiropay}prestashop>cardgategiropay_69a1a3ad8dd5da6db3c4da838a0cf9c7'] = 'Weet u zeker dat u uw details wilt verwijderen?'; +$_MODULE['<{cardgategiropay}prestashop>cardgategiropay_59ca7aaff7f6bfd9dd776a6add44770f'] = 'De CardGate module is niet gevonden';