Skip to content

Commit

Permalink
Merge pull request #20 from RichardCardGate/master
Browse files Browse the repository at this point in the history
New payment method: SprayPay.
  • Loading branch information
cardgate authored Aug 25, 2021
2 parents 4410f5d + f9da07c commit cdf2d92
Show file tree
Hide file tree
Showing 12 changed files with 288 additions and 70 deletions.
30 changes: 0 additions & 30 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions modules/cardgate/cardgate-clientlib-php/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
/doc
/doc.generate.sh
INTERNAL
*.log
git.php
cardgate-clientlib.sublime-project
cardgate-clientlib.sublime-workspace
sftp-config.json
42 changes: 4 additions & 38 deletions modules/cardgate/cardgate-clientlib-php/src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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 );
Expand Down
10 changes: 10 additions & 0 deletions modules/cardgate/cardgate-clientlib-php/src/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/cardgate/cardgate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion modules/cardgate/cardgatepayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
214 changes: 214 additions & 0 deletions modules/cardgatespraypay/cardgatespraypay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
<?php

use PrestaShop\PrestaShop\Core\Payment\PaymentOption;

if ( file_exists( dirname( __FILE__ ) . '/../cardgate/cardgate.php') ) {
require_once dirname( __FILE__ ) . '/../cardgate/cardgate.php';
} else {
$GLOBALS['CARDGATENOTFOUND']=1;
if (!class_exists('CardgatePayment')) { class CardgatePayment extends PaymentModule { function get_url(){} } }
}

/**
* CardGate - Prestashop
*
* 2010-11-09 (LL) Version 1.00
* Initial release
*
* 2011-04-18 (BZ) Version 1.01
* Added PayPal, updated countries for payment options
*
* Data for langiange translations
*
* $this->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 );
}
}
}

?>
13 changes: 13 additions & 0 deletions modules/cardgatespraypay/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>cardgatespraypay</name>
<displayName><![CDATA[CardGate SprayPay]]></displayName>
<version><![CDATA[1.7.0]]></version>
<description><![CDATA[Accepts payments with CardGate SprayPay.]]></description>
<author><![CDATA[Richard Schoots]]></author>
<tab><![CDATA[payments_gateways]]></tab>
<confirmUninstall><![CDATA[Are you sure you want to delete your details?]]></confirmUninstall>
<is_configurable>0</is_configurable>
<need_instance>1</need_instance>
<limited_countries></limited_countries>
</module>
13 changes: 13 additions & 0 deletions modules/cardgatespraypay/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>cardgatespraypay</name>
<displayName><![CDATA[CardGate SprayPay]]></displayName>
<version><![CDATA[1.7.10]]></version>
<description><![CDATA[Accepteert betalingen met CardGate SprayPay]]></description>
<author><![CDATA[CardGate]]></author>
<tab><![CDATA[payments_gateways]]></tab>
<confirmUninstall><![CDATA[Weet u zeker dat u uw details wilt verwijderen?]]></confirmUninstall>
<is_configurable>0</is_configurable>
<need_instance>1</need_instance>
<limited_countries></limited_countries>
</module>
Binary file added modules/cardgatespraypay/logo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit cdf2d92

Please sign in to comment.