Skip to content

Commit

Permalink
New payment UI with QR Code (#1)
Browse files Browse the repository at this point in the history
* Release 2.0.0

* Perform refactoring
- simplify configuration section
- remove some code fragility and smells

* Remove old comment

* Remove/change messages

* Release version and notes updated

* Update system.xml

* Update version in api and add README.md and CHANGELOG.md files

* Fix "activate" button in config

Co-authored-by: Alessandro Ronchi <[email protected]>
Co-authored-by: StivenSatispay <[email protected]>
  • Loading branch information
3 people authored Jun 22, 2020
1 parent 1ad6fb8 commit 10a3b6f
Show file tree
Hide file tree
Showing 40 changed files with 1,539 additions and 470 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Change Log
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 2.0.0
New payment UI with QR Code

## 1.5.0
various improvements

## 1.4.3
updated sdk
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Satispay Magento Plugin

## Installation and configuration
1. Download ZIP file
2. Expand your ZIP file
3. Copy its content in your Magento root path
4. Login your Magento
5. Flush your cache from "System > Cache Management"
6. Log out
7. Log in again
8. Configure it under "System > Configuration > Payment methods > Satispay"


Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php


class Satispay_Satispay_Block_Adminhtml_System_Config_Form_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
{
/**
* Set template
*/
protected function _construct()
{
parent::_construct();
$this->setTemplate('satispay/system/config/button.phtml');
}

/**
* Return element html
*
* @param Varien_Data_Form_Element_Abstract $element
* @return string
*/
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
return $this->_toHtml();
}

/**
* Return ajax url for button
*
* @return string
*/
public function getAjaxGenerateKeys()
{
return Mage::helper('adminhtml')->getUrl('adminhtml/adminhtml_keysgenerator/generatekeys');
}

/**
* Generate button html
*
* @return string
*/
public function getButtonHtml()
{
$helper = Mage::helper('satispay');

$isActivated = $helper->isActivated();
$buttonData = array(
'id' => 'satispay_button',
'label' => $this->helper('adminhtml')->__($isActivated ? 'Activate with new activation code' : 'Activate'),
);

$isSandbox = $helper->isSandbox();
if ($isSandbox) {
$buttonData['label'] = $this->helper('adminhtml')->__($isActivated ? 'Activate sandbox with new activation code' : 'Activate sandbox');
}

$activationCodeNotSpecified = empty($helper->getToken($isSandbox));
if ($activationCodeNotSpecified) {
$buttonData['disabled'] = 'disabled';
} else {
$buttonData['onclick'] = 'javascript:generate(); return false;';
}

$button = $this->getLayout()
->createBlock('adminhtml/widget_button')
->setData($buttonData);

return $button->toHtml();
}
}
132 changes: 124 additions & 8 deletions app/code/community/Satispay/Satispay/Helper/Data.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,126 @@
<?php
class Satispay_Satispay_Helper_Data extends Mage_Core_Helper_Abstract {
public function getSecurityBearer($storeId = null) {
return Mage::getStoreConfig('payment/satispay/securityBearer', $storeId);
}

public function isStaging($storeId = null) {
return Mage::getStoreConfig('payment/satispay/staging', $storeId);
}

/**
* Class Satispay_Satispay_Helper_Data
*/
class Satispay_Satispay_Helper_Data extends Mage_Core_Helper_Abstract
{
/**
* @param null $storeId
* @return mixed
*/
public function isActive($storeId = null)
{
return Mage::getStoreConfig('payment/satispay/active', $storeId);
}

/**
* @param null $storeId
* @return mixed
*/
public function isSandbox($storeId = null)
{
return Mage::getStoreConfigFlag('payment/satispay/sandbox', $storeId);
}

public function isActivated($storeId = null)
{
$isSandbox = $this->isSandbox($storeId);
if (empty($this->getPrivateKey()) || empty($this->getPublicKey()) || empty($this->getKeyId($isSandbox))) {
return false;
}

return true;
}

/**
* @param null $storeId
* @param $isSandbox
* @return mixed
*/
public function getToken($isSandbox, $storeId = null)
{
if ($isSandbox) {
return Mage::getStoreConfig('payment/satispay/token_sandbox', $storeId);
}
return Mage::getStoreConfig('payment/satispay/token', $storeId);
}

/**
* @param $val
*/
public function setPublicKey($val)
{
$encryptedValue = Mage::helper('core')->encrypt($val);
Mage::getConfig()->saveConfig('payment/satispay/public_key', $encryptedValue, 'default', 0);
}

/**
* @param $val
*/
public function setPrivateKey($val)
{
$encryptedValue = Mage::helper('core')->encrypt($val);
Mage::getConfig()->saveConfig('payment/satispay/private_key', $encryptedValue, 'default', 0);
}

/**
* @param $val
* @param $isSandbox
*/
public function setKeyId($val, $isSandbox)
{
$encryptedValue = Mage::helper('core')->encrypt($val);
if ($isSandbox) {
Mage::getConfig()->saveConfig('payment/satispay/key_id_sandbox', $encryptedValue, 'default', 0);
} else {
Mage::getConfig()->saveConfig('payment/satispay/key_id', $encryptedValue, 'default', 0);
}
}

/**
* @param null $storeId
* @return mixed
*/
public function getPublicKey($storeId = null)
{
return Mage::helper('core')->decrypt(Mage::getStoreConfig('payment/satispay/public_key', $storeId));
}

/**
* @param null $storeId
* @param $isSandbox
* @return mixed
*/
public function getPrivateKey($storeId = null)
{
return Mage::helper('core')->decrypt(Mage::getStoreConfig('payment/satispay/private_key', $storeId));
}

/**
* @param null $storeId
* @param $isSandbox
* @return mixed
*/
public function getKeyId($isSandbox, $storeId = null)
{
if ($isSandbox) {
return Mage::helper('core')->decrypt(Mage::getStoreConfig('payment/satispay/key_id_sandbox', $storeId));
}
return Mage::helper('core')->decrypt(Mage::getStoreConfig('payment/satispay/key_id', $storeId));
}

/**
* @param null $storeId
* @return boolean
*/
public function debugModeEnable($storeId = null)
{
return Mage::getStoreConfigFlag('payment/satispay/debug_mode', $storeId);
}

public function getExtensionVersion()
{
return (string)Mage::getConfig()->getNode()->modules->Satispay_Satispay->version;
}
}
61 changes: 61 additions & 0 deletions app/code/community/Satispay/Satispay/Model/Logger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

class Satispay_Satispay_Model_Logger
{

const LOG_FILENAME = 'satispay.log';

/**
* @var Mage_Core_Model_Logger
*/
protected $logger;

/**
* @var boolean
*/
private $debugModeEnable;

/**
* Satispay_Satispay_Model_Logger constructor.
* @param boolean $debugModeEnable
*/
public function __construct($debugModeEnable)
{
$this->debugModeEnable = $debugModeEnable;
$this->logger = Mage::getModel('core/logger');
$this->logger->log(
sprintf(
'Magento v%s - Satispay Extension v%s',
Mage::getVersion(),
Mage::helper('satispay')->getExtensionVersion()
),
Zend_Log::INFO,
self::LOG_FILENAME,
$debugModeEnable
);
}

/**
* @param $message
*/
public function debug($message)
{
$this->logger->log($message, Zend_Log::DEBUG, self::LOG_FILENAME, $this->debugModeEnable);
}

/**
* @param $message
*/
public function error($message)
{
$this->logger->log($message, Zend_Log::ERR, self::LOG_FILENAME, $this->debugModeEnable);
}

/**
* @param Exception $e
*/
public function exception(Exception $e)
{
$this->logger->logException($e);
}
}
78 changes: 46 additions & 32 deletions app/code/community/Satispay/Satispay/Model/Payment.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,40 +1,54 @@
<?php
require_once(dirname(__FILE__).'/../includes/online-api-php-sdk/init.php');
require_once(dirname(__FILE__) . '/../includes/gbusiness-api-php-sdk/init.php');

class Satispay_Satispay_Model_Payment extends Mage_Payment_Model_Method_Abstract {
protected $_code = 'satispay';
protected $_canRefund = true;
protected $_canRefundInvoicePartial = true;
protected $_canUseForMultishipping = false;
class Satispay_Satispay_Model_Payment extends Mage_Payment_Model_Method_Abstract
{
protected $_code = 'satispay';
protected $_canRefund = true;
protected $_canRefundInvoicePartial = true;
protected $_canUseForMultishipping = false;

public function refund(Varien_Object $payment, $amount) {
$helper = Mage::helper('satispay');
public function refund(Varien_Object $payment, $amount)
{
$helper = Mage::helper('satispay');
$sandbox = $helper->isSandbox();
$logger = Mage::getModel('satispay/logger', array($helper->debugModeEnable()));
\SatispayGBusiness\Api::setSandbox($sandbox);
\SatispayGBusiness\Api::setPluginVersionHeader($helper->getExtensionVersion());
\SatispayGBusiness\Api::setPluginNameHeader('Magento');
\SatispayGBusiness\Api::setTypeHeader('ECOMMERCE-PLUGIN');
\SatispayGBusiness\Api::setPlatformVersionHeader(Mage::getVersion());
\SatispayGBusiness\Api::setPublicKey($helper->getPublicKey());
\SatispayGBusiness\Api::setPrivateKey($helper->getPrivateKey());
\SatispayGBusiness\Api::setKeyId($helper->getKeyId($sandbox));

\SatispayOnline\Api::setSecurityBearer($helper->getSecurityBearer($payment->getOrder()->getStoreId()));
\SatispayOnline\Api::setStaging($helper->isStaging($payment->getOrder()->getStoreId()));
\SatispayOnline\Api::setPluginName('Magento');
\SatispayOnline\Api::setType('ECOMMERCE-PLUGIN');
$magentoVersion = Mage::getVersionInfo();
\SatispayOnline\Api::setPlatformVersion($magentoVersion['major'].'.'.$magentoVersion['minor'].'.'.$magentoVersion['revision']);
$refundBody = array(
"flow" => "REFUND",
"amount_unit" => round($amount * 100),
"currency" => $payment->getOrder()->getBaseCurrencyCode(),
"parent_payment_uid" => $payment->getParentTransactionId()
);
$payment = \SatispayGBusiness\Payment::create($refundBody);
$logger->debug(print_r(array('refundBody' => $refundBody), true));

$refund = \SatispayOnline\Refund::create(array(
'charge_id' => $payment->getParentTransactionId(),
'currency' => $payment->getOrder()->getBaseCurrencyCode(),
'description' => '#'.$payment->getOrder()->getIncrementId(),
'amount' => round($amount * 100)
));
return $this;
}

return $this;
}
public function canUseForCurrency($currencyCode)
{
if ($currencyCode !== 'EUR') {
return false;
}
return true;
}

public function canUseForCurrency($currencyCode) {
if ($currencyCode !== 'EUR') return false;
return true;
}

public function getOrderPlaceRedirectUrl() {
return Mage::getUrl('satispay/payment', array(
'_secure' => true
));
}
public function getOrderPlaceRedirectUrl()
{
return Mage::getUrl(
'satispay/payment',
array(
'_secure' => true
)
);
}
}
Loading

0 comments on commit 10a3b6f

Please sign in to comment.