diff --git a/Api/Data/InvoiceInterface.php b/Api/Data/InvoiceInterface.php index 55d9ae2..0887c1e 100644 --- a/Api/Data/InvoiceInterface.php +++ b/Api/Data/InvoiceInterface.php @@ -71,5 +71,4 @@ public function getQrCode(); * @return $this */ public function setQrCode($qrCode); - } diff --git a/Api/Data/ItemInterface.php b/Api/Data/ItemInterface.php index fec7152..1fe36a2 100644 --- a/Api/Data/ItemInterface.php +++ b/Api/Data/ItemInterface.php @@ -89,5 +89,4 @@ public function getTaxPercent(); * @return $this */ public function setTaxPercent($taxPercent); - } diff --git a/Api/Data/TotalInterface.php b/Api/Data/TotalInterface.php index 5946e78..40b9cd2 100644 --- a/Api/Data/TotalInterface.php +++ b/Api/Data/TotalInterface.php @@ -53,5 +53,4 @@ public function getAmount(); * @return $this */ public function setAmount($amount); - } diff --git a/Api/Data/TransactionInterface.php b/Api/Data/TransactionInterface.php index 1839c20..45d5528 100644 --- a/Api/Data/TransactionInterface.php +++ b/Api/Data/TransactionInterface.php @@ -125,5 +125,4 @@ public function setBankId($bankId); * @return string|null */ public function getBankId(); - } diff --git a/Api/PaynlInterface.php b/Api/PaynlInterface.php index 753010a..8cc2f15 100644 --- a/Api/PaynlInterface.php +++ b/Api/PaynlInterface.php @@ -151,14 +151,14 @@ public function createAddress($line1, $line2, $city, $state, $postalCode, $count public function createBillingInfo($email, $firstname, $lastname, $businessName, $phone, $addtionalInfo = '', $invoiceAddress); /** - * @param string $line1 - * @param string $line2 - * @param string $city - * @param string $state - * @param string $postalCode - * @param string $countryCode - * @return \PayPal\Api\InvoiceAddress - */ + * @param string $line1 + * @param string $line2 + * @param string $city + * @param string $state + * @param string $postalCode + * @param string $countryCode + * @return \PayPal\Api\InvoiceAddress + */ public function createInvoiceAddress($line1, $line2, $city, $state, $postalCode, $countryCode); /** @@ -262,6 +262,4 @@ public function recordPaymentForInvoice($invoice, $paymentDetail); * @throws \Exception */ public function getAccessToken(); - - } diff --git a/Block/Adminhtml/Config/Instruction.php b/Block/Adminhtml/Config/Instruction.php index 45a4812..08be219 100644 --- a/Block/Adminhtml/Config/Instruction.php +++ b/Block/Adminhtml/Config/Instruction.php @@ -7,7 +7,6 @@ namespace Magestore\WebposPaynl\Block\Adminhtml\Config; - class Instruction extends \Magento\Config\Block\System\Config\Form\Fieldset { /** @@ -29,4 +28,4 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele { return $this->getChildHtml('paynl_setup_guide'); } -} \ No newline at end of file +} diff --git a/Block/Adminhtml/Config/Setupguide.php b/Block/Adminhtml/Config/Setupguide.php index c7d4c79..78ec13c 100644 --- a/Block/Adminhtml/Config/Setupguide.php +++ b/Block/Adminhtml/Config/Setupguide.php @@ -7,7 +7,6 @@ namespace Magestore\WebposPaynl\Block\Adminhtml\Config; - class Setupguide extends \Magento\Backend\Block\Template { /** @@ -19,8 +18,8 @@ class Setupguide extends \Magento\Backend\Block\Template * Get api test url * @return string */ - public function getTestApiUrl(){ + public function getTestApiUrl() + { return $this->getUrl('webpospaynl/api/test'); } - -} \ No newline at end of file +} diff --git a/Block/Container.php b/Block/Container.php index 47bd8f4..8ccb6ac 100644 --- a/Block/Container.php +++ b/Block/Container.php @@ -57,15 +57,16 @@ public function __construct( /** * @return string */ - public function isEnableSendInvoice(){ + public function isEnableSendInvoice() + { return ($this->helper->isAllowCustomerPayWithEmail())?'true':'false'; } /** * @return bool */ - public function isEnablePaynl(){ + public function isEnablePaynl() + { return $this->helper->isEnablePaynl(); } - } diff --git a/Controller/AbstractAction.php b/Controller/AbstractAction.php index 66b2dee..9628f30 100644 --- a/Controller/AbstractAction.php +++ b/Controller/AbstractAction.php @@ -37,7 +37,7 @@ public function __construct( \Magento\Framework\App\Action\Context $context, \Magestore\WebposPaynl\Api\PaynlServiceInterface $paypalService, \Magestore\WebposPaynl\Helper\Data $helper - ){ + ) { parent::__construct($context); $this->paypalService = $paypalService; $this->helper = $helper; @@ -48,7 +48,8 @@ public function __construct( * @param $data * @return mixed */ - public function createJsonResult($data){ + public function createJsonResult($data) + { $resultJson = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_JSON); return $resultJson->setData($data); } @@ -56,7 +57,8 @@ public function createJsonResult($data){ /** * @return mixed */ - public function createPageResult(){ + public function createPageResult() + { $resultPage = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_PAGE); return $resultPage; } diff --git a/Controller/Adminhtml/AbstractAction.php b/Controller/Adminhtml/AbstractAction.php index a397586..e9de7a5 100644 --- a/Controller/Adminhtml/AbstractAction.php +++ b/Controller/Adminhtml/AbstractAction.php @@ -36,7 +36,7 @@ public function __construct( \Magento\Backend\App\Action\Context $context, \Magestore\WebposPaynl\Api\PaynlServiceInterface $paypalService, \Magestore\WebposPaynl\Helper\Data $helper - ){ + ) { parent::__construct($context); $this->paypalService = $paypalService; $this->helper = $helper; @@ -47,8 +47,9 @@ public function __construct( * @param $data * @return mixed */ - public function createJsonResult($data){ + public function createJsonResult($data) + { $resultJson = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_JSON); return $resultJson->setData($data); } -} \ No newline at end of file +} diff --git a/Controller/Config/Paypalsignin.php b/Controller/Config/Paypalsignin.php index 751c0e7..443b288 100644 --- a/Controller/Config/Paypalsignin.php +++ b/Controller/Config/Paypalsignin.php @@ -40,11 +40,11 @@ class Paynlsignin extends \Magento\Framework\App\Action\Action */ public function __construct( \Magento\Framework\App\Action\Context $context, - \Magento\Framework\App\Config\ConfigResource\ConfigInterface $resourceConfig, + \Magento\Framework\App\Config\ConfigResource\ConfigInterface $resourceConfig, \Magestore\WebposPaynl\Model\Paynl $paynl, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Framework\Controller\Result\RawFactory $resultRawFactory - ){ + ) { parent::__construct($context); $this->resourceConfig = $resourceConfig; $this->paynl = $paynl; @@ -62,7 +62,7 @@ public function execute() $authCode = $this->getRequest()->getParam('code'); $tokenInfo = ''; $result = ''; - if($authCode) { + if ($authCode) { try { $tokenInfo = $this->paypal->getTokenInfo($authCode); } catch (\PayPal\Exception\PayPalConnectionException $ex) { @@ -78,7 +78,7 @@ public function execute() $response->setHeader('Content-type', 'text/plain'); $response->setContents($ex->getMessage()); } - if($tokenInfo) { + if ($tokenInfo) { $accessToken = $tokenInfo->access_token; $refreshToken = $tokenInfo->refresh_token; if ($accessToken) { @@ -136,4 +136,4 @@ public function getClosePopup() "; return $html; } -} \ No newline at end of file +} diff --git a/Controller/Payment/Success.php b/Controller/Payment/Success.php index 486ded9..594627d 100644 --- a/Controller/Payment/Success.php +++ b/Controller/Payment/Success.php @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ namespace Magestore\WebposPaynl\Controller\Payment; + use Magestore\Webpos\Model\Exception; /** @@ -24,13 +25,13 @@ public function execute() $paymentId = $this->getRequest()->getParam('paymentId'); $payerId = $this->getRequest()->getParam('PayerID'); $isApp = $this->getRequest()->getParam('isApp'); - if($isApp) { + if ($isApp) { if ($paymentId) { $transactionId = $this->paypalService->finishAppPayment($paymentId, $payerId); $response['transactionId'] = $transactionId; $response['message'] = __('Payment has been completed'); } - if($response['transactionId']) { + if ($response['transactionId']) { return $transactionId; // exit(); } else { @@ -43,7 +44,7 @@ public function execute() $transactionId = $this->paypalService->finishPayment($paymentId, $payerId); $response['transactionId'] = $transactionId; $response['message'] = __('Payment has been completed'); - } else{ + } else { $response['message'] = __('An error occur during the payment processing'); $response['success'] = false; } diff --git a/Helper/Data.php b/Helper/Data.php index b5bc256..161bd87 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -7,7 +7,6 @@ namespace Magestore\WebposPaynl\Helper; - /** * class \Magestore\WebposPaynl\Helper\Data * @@ -66,7 +65,7 @@ public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Framework\Stdlib\DateTime\DateTime $dateTime - ){ + ) { $this->_storeManager = $storeManager; $this->_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $this->_localeDate = $localeDate; @@ -78,7 +77,8 @@ public function __construct( * * @return Magento store */ - public function getStore(){ + public function getStore() + { return $this->_storeManager->getStore(); } @@ -87,7 +87,8 @@ public function getStore(){ * @param string $data * @return string */ - public function formatCurrency($data){ + public function formatCurrency($data) + { $currencyHelper = $this->_objectManager->get('Magento\Framework\Pricing\Helper\Data'); return $currencyHelper->currency($data, true, false); } @@ -97,7 +98,8 @@ public function formatCurrency($data){ * @param string $data * @return string */ - public function formatPrice($data){ + public function formatPrice($data) + { $checkoutHelper = $this->_objectManager->get('Magento\Checkout\Helper\Data'); return $checkoutHelper->formatPrice($data); } @@ -107,7 +109,8 @@ public function formatPrice($data){ * @param string $data * @return string */ - public function formatDate($data,$format = ''){ + public function formatDate($data, $format = '') + { $format = ($format == '')?'M d,Y H:i:s a':$format; return $this->_localeDate->date(new \DateTime($data))->format($format); } @@ -117,7 +120,8 @@ public function formatDate($data,$format = ''){ * @param string $path * @return string */ - public function getStoreConfig($path){ + public function getStoreConfig($path) + { return $this->scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); } @@ -125,7 +129,8 @@ public function getStoreConfig($path){ * * @return string */ - public function getCurrentDatetime(){ + public function getCurrentDatetime() + { return $this->_dateTime->gmtDate(); } @@ -133,7 +138,8 @@ public function getCurrentDatetime(){ * string class name * @return Model */ - public function getModel($class){ + public function getModel($class) + { return $this->_objectManager->get($class); } @@ -142,21 +148,23 @@ public function getModel($class){ * @param string $str * @return string */ - public function htmlEscape($str){ + public function htmlEscape($str) + { return htmlspecialchars($str); } /** * @return array */ - public function getPaynlConfig() { - $configData = array(); - $configItems = array( + public function getPaynlConfig() + { + $configData = []; + $configItems = [ 'enable', 'client_id', 'client_secret', 'is_sandbox', - ); + ]; foreach ($configItems as $configItem) { $configData[$configItem] = $this->getStoreConfig('webpos/payment/paynl/' . $configItem); } @@ -166,7 +174,8 @@ public function getPaynlConfig() { /** * @return bool */ - public function isAllowCustomerPayWithEmail(){ + public function isAllowCustomerPayWithEmail() + { $enable = $this->getStoreConfig('webpos/payment/paynl/enable_send_invoice'); return ($enable)?true:false; } @@ -174,7 +183,8 @@ public function isAllowCustomerPayWithEmail(){ /** * @return bool */ - public function isEnablePaynl(){ + public function isEnablePaynl() + { $enable = $this->getStoreConfig('webpos/payment/paynl/enable'); return ($enable)?true:false; } @@ -182,7 +192,8 @@ public function isEnablePaynl(){ /** * @return bool */ - public function isAllowPaypalHere(){ + public function isAllowPaypalHere() + { $enable = $this->getStoreConfig('webpos/payment/paynl/enable'); return ($enable)?true:false; } @@ -190,9 +201,10 @@ public function isAllowPaypalHere(){ /** * @return array */ - public function getMerchantInfo(){ - $configData = array(); - $configItems = array( + public function getMerchantInfo() + { + $configData = []; + $configItems = [ 'email', 'firstname', 'lastname', @@ -203,7 +215,7 @@ public function getMerchantInfo(){ 'state', 'postal_code', 'country_id' - ); + ]; foreach ($configItems as $configItem) { $configData[$configItem] = $this->getStoreConfig('webpos/payment/paypal/merchant_infomation/' . $configItem); } @@ -213,7 +225,8 @@ public function getMerchantInfo(){ /** * @return string */ - public function getLogoUrl(){ + public function getLogoUrl() + { $helper = $this->_objectManager->get('Magestore\Webpos\Helper\Data'); $url =$helper->getWebPosImages(); return (strpos($url, 'https') === false)?'':$url; @@ -222,7 +235,8 @@ public function getLogoUrl(){ /** * @return bool */ - public function isTaxCalculatedAfterDiscount(){ + public function isTaxCalculatedAfterDiscount() + { $configData = $this->getStoreConfig('tax/calculation/apply_after_discount'); return ($configData == 1)?true:false; } @@ -232,7 +246,8 @@ public function isTaxCalculatedAfterDiscount(){ * @param array $params * @return string */ - public function getUrl($path, $params = array()){ + public function getUrl($path, $params = []) + { return $this->_getUrl($path, $params); } @@ -240,8 +255,9 @@ public function getUrl($path, $params = array()){ * @param $message * @param string $type */ - public function addLog($message, $type = ''){ - switch ($type){ + public function addLog($message, $type = '') + { + switch ($type) { case 'info': $this->_logger->info($message); break; @@ -277,7 +293,8 @@ public function addLog($message, $type = ''){ /** * @return bool */ - public function validateRequiredSDK(){ + public function validateRequiredSDK() + { return (class_exists("\\Paynl\\Instore"))?true:false; } -} \ No newline at end of file +} diff --git a/Model/Config.php b/Model/Config.php index 5a239ca..eeb47c7 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -5,6 +5,7 @@ */ namespace Magestore\WebposPaynl\Model; + use Magento\Framework\App\Config\ScopeConfigInterface; /** @@ -21,8 +22,7 @@ class Config public function __construct( ScopeConfigInterface $configInterface - ) - { + ) { $this->_scopeConfigInterface = $configInterface; } @@ -44,12 +44,14 @@ public function isNeverCancel() { return $this->_scopeConfigInterface->getValue('payment/paynl/never_cancel', 'store') == 1; } - public function getLanguage(){ + public function getLanguage() + { $language = $this->_scopeConfigInterface->getValue('payment/paynl/language', 'store'); return $language?$language:'nl'; //default nl } - public function getPaymentOptionId($methodCode){ + public function getPaymentOptionId($methodCode) + { return $this->_scopeConfigInterface->getValue('payment/'.$methodCode.'/payment_option_id', 'store'); } @@ -58,11 +60,12 @@ public function getPaymentOptionId($methodCode){ * * @return bool TRUE when config loaded, FALSE when the apitoken or serviceId are empty */ - public function configureSDK(){ + public function configureSDK() + { if ($this->validateRequiredSDK()) { $apiToken = $this->getApiToken(); $serviceId = $this->getServiceId(); - if(!empty($apiToken) && !empty($serviceId)){ + if (!empty($apiToken) && !empty($serviceId)) { \Paynl\Config::setApiToken($apiToken); \Paynl\Config::setServiceId($serviceId); return true; @@ -75,7 +78,8 @@ public function configureSDK(){ /** * @return bool */ - public function validateRequiredSDK(){ + public function validateRequiredSDK() + { return (class_exists("\\Paynl\\Instore"))?true:false; } -} \ No newline at end of file +} diff --git a/Model/Data/Invoice.php b/Model/Data/Invoice.php index 0026edc..72ab904 100644 --- a/Model/Data/Invoice.php +++ b/Model/Data/Invoice.php @@ -21,7 +21,8 @@ class Invoice extends \Magento\Framework\Api\AbstractExtensibleObject implements * @api * @return string|null */ - public function getId(){ + public function getId() + { return $this->_get(self::ID); } @@ -32,7 +33,8 @@ public function getId(){ * @param string $id * @return $this */ - public function setId($id){ + public function setId($id) + { return $this->setData(self::ID, $id); } @@ -42,7 +44,8 @@ public function setId($id){ * @api * @return string|null */ - public function getNumber(){ + public function getNumber() + { return $this->_get(self::NUMBER); } @@ -53,7 +56,8 @@ public function getNumber(){ * @param string $number * @return $this */ - public function setNumber($number){ + public function setNumber($number) + { return $this->setData(self::NUMBER, $number); } @@ -63,7 +67,8 @@ public function setNumber($number){ * @api * @return string|null */ - public function getQrCode(){ + public function getQrCode() + { return $this->_get(self::QR_CODE); } @@ -74,7 +79,8 @@ public function getQrCode(){ * @param string $qrCode * @return $this */ - public function setQrCode($qrCode){ + public function setQrCode($qrCode) + { return $this->setData(self::QR_CODE, $qrCode); } -} \ No newline at end of file +} diff --git a/Model/Data/Item.php b/Model/Data/Item.php index 3636d1c..8f2a3ff 100644 --- a/Model/Data/Item.php +++ b/Model/Data/Item.php @@ -21,7 +21,8 @@ class Item extends \Magento\Framework\Api\AbstractExtensibleObject implements \M * @api * @return string|null */ - public function getName(){ + public function getName() + { return $this->_get(self::NAME); } @@ -32,7 +33,8 @@ public function getName(){ * @param string $name * @return $this */ - public function setName($name){ + public function setName($name) + { return $this->setData(self::NAME, $name); } @@ -42,7 +44,8 @@ public function setName($name){ * @api * @return string|null */ - public function getQty(){ + public function getQty() + { return $this->_get(self::QTY); } @@ -53,7 +56,8 @@ public function getQty(){ * @param string $qty * @return $this */ - public function setQty($qty){ + public function setQty($qty) + { return $this->setData(self::QTY, $qty); } @@ -63,7 +67,8 @@ public function setQty($qty){ * @api * @return string|null */ - public function getUnitPrice(){ + public function getUnitPrice() + { return $this->_get(self::UNIT_PRICE); } @@ -74,7 +79,8 @@ public function getUnitPrice(){ * @param string $unitPrice * @return $this */ - public function setUnitPrice($unitPrice){ + public function setUnitPrice($unitPrice) + { return $this->setData(self::UNIT_PRICE, $unitPrice); } @@ -84,7 +90,8 @@ public function setUnitPrice($unitPrice){ * @api * @return string|null */ - public function getTaxPercent(){ + public function getTaxPercent() + { return $this->_get(self::TAX_PERCENT); } @@ -95,7 +102,8 @@ public function getTaxPercent(){ * @param string $taxPercent * @return $this */ - public function setTaxPercent($taxPercent){ + public function setTaxPercent($taxPercent) + { return $this->setData(self::TAX_PERCENT, $taxPercent); } -} \ No newline at end of file +} diff --git a/Model/Data/Total.php b/Model/Data/Total.php index 9ba8bb0..1f30381 100644 --- a/Model/Data/Total.php +++ b/Model/Data/Total.php @@ -20,7 +20,8 @@ class Total extends \Magento\Framework\Api\AbstractExtensibleObject implements \ * @api * @return string|null */ - public function getCode(){ + public function getCode() + { return $this->_get(self::CODE); } @@ -31,7 +32,8 @@ public function getCode(){ * @param string $code * @return $this */ - public function setCode($code){ + public function setCode($code) + { return $this->setData(self::CODE, $code); } @@ -41,7 +43,8 @@ public function setCode($code){ * @api * @return string|null */ - public function getAmount(){ + public function getAmount() + { return $this->_get(self::AMOUNT); } @@ -52,7 +55,8 @@ public function getAmount(){ * @param string $amount * @return $this */ - public function setAmount($amount){ + public function setAmount($amount) + { return $this->setData(self::AMOUNT, $amount); } -} \ No newline at end of file +} diff --git a/Model/Data/Transaction.php b/Model/Data/Transaction.php index 12a668a..4136be6 100644 --- a/Model/Data/Transaction.php +++ b/Model/Data/Transaction.php @@ -20,7 +20,8 @@ class Transaction extends \Magento\Framework\Api\AbstractExtensibleObject implem * @api * @return float|null */ - public function getQuoteId(){ + public function getQuoteId() + { return $this->_get(self::QUOTE_ID); } @@ -31,7 +32,8 @@ public function getQuoteId(){ * @param float $quoteId * @return $this */ - public function setQuoteId($quoteId){ + public function setQuoteId($quoteId) + { return $this->setData(self::QUOTE_ID, $quoteId); } @@ -41,7 +43,8 @@ public function setQuoteId($quoteId){ * @api * @return string|null */ - public function getCurrency(){ + public function getCurrency() + { return $this->_get(self::CURRENCY); } @@ -52,7 +55,8 @@ public function getCurrency(){ * @param string $currency * @return $this */ - public function setCurrency($currency){ + public function setCurrency($currency) + { return $this->setData(self::CURRENCY, $currency); } @@ -62,7 +66,8 @@ public function setCurrency($currency){ * @api * @return float|null */ - public function getAmount(){ + public function getAmount() + { return $this->_get(self::AMOUNT); } @@ -74,7 +79,8 @@ public function getAmount(){ * @param float $total * @return $this */ - public function setAmount($amount){ + public function setAmount($amount) + { return $this->setData(self::TOTAL, $amount); } @@ -85,7 +91,8 @@ public function setAmount($amount){ * @param float $total * @return $this */ - public function setTotal($total){ + public function setTotal($total) + { return $this->setData(self::TOTAL, $total); } @@ -95,7 +102,8 @@ public function setTotal($total){ * @api * @return float|null */ - public function getTotal(){ + public function getTotal() + { return $this->_get(self::TOTAL); } @@ -117,7 +125,8 @@ public function setDescription($description) * @api * @return string|null */ - public function getDescription(){ + public function getDescription() + { return $this->_get(self::DESCRIPTION); } @@ -139,8 +148,8 @@ public function setBankId($bankId) * @api * @return string|null */ - public function getBankId(){ + public function getBankId() + { return $this->_get(self::BANK_ID); } - -} \ No newline at end of file +} diff --git a/Model/Instore.php b/Model/Instore.php index b05c9a5..c87686e 100644 --- a/Model/Instore.php +++ b/Model/Instore.php @@ -72,11 +72,11 @@ public function getBanks() // Probably instore is not activated, no terminals present } } - array_unshift($banks, array( + array_unshift($banks, [ 'id' => '', 'name' => __('Choose the pin terminal'), 'visibleName' => __('Choose the pin terminal') - )); + ]); return $banks; } @@ -91,4 +91,4 @@ private function getCache() $cache = $om->get('Magento\Framework\App\CacheInterface'); return $cache; } -} \ No newline at end of file +} diff --git a/Model/Paymentmethod/Paymentmethod.php b/Model/Paymentmethod/Paymentmethod.php index 74a1f8e..8fac424 100644 --- a/Model/Paymentmethod/Paymentmethod.php +++ b/Model/Paymentmethod/Paymentmethod.php @@ -27,8 +27,8 @@ class PaymentMethod extends AbstractMethod protected $paynlConfig; /** -* @var \Magento\Sales\Model\OrderRepository -*/ + * @var \Magento\Sales\Model\OrderRepository + */ protected $orderRepository; /** * @var \Magento\Sales\Model\Order\Config @@ -50,24 +50,36 @@ public function __construct( array $data = [] ) { parent::__construct( - $context, $registry, $extensionFactory, $customAttributeFactory, - $paymentData, $scopeConfig, $logger, $resource, $resourceCollection, $data ); + $context, + $registry, + $extensionFactory, + $customAttributeFactory, + $paymentData, + $scopeConfig, + $logger, + $resource, + $resourceCollection, + $data + ); $this->orderRepository = $orderRepository; $this->orderConfig = $orderConfig; $this->paynlConfig = new Config($this->_scopeConfig); } - protected function getState($status){ + protected function getState($status) + { $validStates = [ Order::STATE_NEW, Order::STATE_PENDING_PAYMENT, Order::STATE_HOLDED ]; - foreach($validStates as $state){ + foreach ($validStates as $state) { $statusses = $this->orderConfig->getStateStatuses($state, false); - if(in_array($status, $statusses)) return $state; + if (in_array($status, $statusses)) { + return $state; + } } return false; } @@ -81,7 +93,8 @@ public function getInstructions() { return trim($this->getConfigData('instructions')); } - public function getBanks(){ + public function getBanks() + { return []; } public function initialize($paymentAction, $stateObject) @@ -98,9 +111,9 @@ public function initialize($paymentAction, $stateObject) /** @var Order $order */ $order = $payment->getOrder(); - if($sendEmail == 'after_payment') { + if ($sendEmail == 'after_payment') { //prevent sending the order confirmation - $order->setCanSendNewEmailFlag( false ); + $order->setCanSendNewEmailFlag(false); } $this->orderRepository->save($order); @@ -118,12 +131,13 @@ public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount) return true; } - public function startTransaction($order, $total, $currency, $bankId) { + public function startTransaction($order, $total, $currency, $bankId) + { $transaction = $this->doStartTransaction($order, $total, $currency, $bankId); $holded = $this->_scopeConfig->getValue('payment/' . $this->_code . '/holded', 'store'); - if($holded){ + if ($holded) { $order->hold(); } $this->orderRepository->save($order); @@ -162,17 +176,17 @@ protected function doStartTransaction($order, $total, $currency, $bankId) // Use default initials $strBillingFirstName = substr($arrBillingAddress['firstname'], 0, 1); - $enduser = array( + $enduser = [ 'initials' => $strBillingFirstName, 'lastName' => $arrBillingAddress['lastname'], 'phoneNumber' => $arrBillingAddress['telephone'], 'emailAddress' => $arrBillingAddress['email'], - ); + ]; - $invoiceAddress = array( + $invoiceAddress = [ 'initials' => $strBillingFirstName, 'lastName' => $arrBillingAddress['lastname'] - ); + ]; $arrAddress = \Paynl\Helper::splitAddress($arrBillingAddress['street']); $invoiceAddress['streetName'] = $arrAddress[0]; @@ -180,7 +194,6 @@ protected function doStartTransaction($order, $total, $currency, $bankId) $invoiceAddress['zipCode'] = $arrBillingAddress['postcode']; $invoiceAddress['city'] = $arrBillingAddress['city']; $invoiceAddress['country'] = $arrBillingAddress['country_id']; - } $arrShippingAddress = $order->getShippingAddress(); @@ -190,20 +203,19 @@ protected function doStartTransaction($order, $total, $currency, $bankId) // Use default initials $strShippingFirstName = substr($arrShippingAddress['firstname'], 0, 1); - $shippingAddress = array( + $shippingAddress = [ 'initials' => $strShippingFirstName, 'lastName' => $arrShippingAddress['lastname'] - ); + ]; $arrAddress2 = \Paynl\Helper::splitAddress($arrShippingAddress['street']); $shippingAddress['streetName'] = $arrAddress2[0]; $shippingAddress['houseNumber'] = $arrAddress2[1]; $shippingAddress['zipCode'] = $arrShippingAddress['postcode']; $shippingAddress['city'] = $arrShippingAddress['city']; $shippingAddress['country'] = $arrShippingAddress['country_id']; - } - $data = array( + $data = [ 'amount' => $total, 'returnUrl' => $returnUrl, 'paymentMethod' => 1729, @@ -216,29 +228,29 @@ protected function doStartTransaction($order, $total, $currency, $bankId) 'extra3' => $order->getEntityId(), 'exchangeUrl' => $exchangeUrl, 'currency' => $currency, - ); - if(isset($shippingAddress)){ + ]; + if (isset($shippingAddress)) { $data['address'] = $shippingAddress; } - if(isset($invoiceAddress)) { + if (isset($invoiceAddress)) { $data['invoiceAddress'] = $invoiceAddress; } - if(isset($enduser)){ + if (isset($enduser)) { $data['enduser'] = $enduser; } - $arrProducts = array(); + $arrProducts = []; foreach ($items as $item) { $arrItem = $item->toArray(); if ($arrItem['price_incl_tax'] != null) { // taxamount is not valid, because on discount it returns the taxamount after discount $taxAmount = $arrItem['price_incl_tax'] - $arrItem['price']; - $product = array( + $product = [ 'id' => $arrItem['product_id'], 'name' => $arrItem['name'], 'price' => $arrItem['price_incl_tax'], 'qty' => $arrItem['qty'], 'tax' => $taxAmount, - ); + ]; $arrProducts[] = $product; } } @@ -248,14 +260,14 @@ protected function doStartTransaction($order, $total, $currency, $bankId) $shippingTax = $order->getShippingTaxAmount(); $shippingDescription = $order->getShippingDescription(); - if($shippingCost != 0) { - $arrProducts[] = array( + if ($shippingCost != 0) { + $arrProducts[] = [ 'id' => 'shipping', 'name' => $shippingDescription, 'price' => $shippingCost, 'qty' => 1, 'tax' => $shippingTax - ); + ]; } // kortingen @@ -263,13 +275,13 @@ protected function doStartTransaction($order, $total, $currency, $bankId) $discountDescription = $order->getDiscountDescription(); if ($discount != 0) { - $arrProducts[] = array( + $arrProducts[] = [ 'id' => 'discount', 'name' => $discountDescription, 'price' => $discount, 'qty' => 1, 'tax' => $order->getDiscountTaxCompensationAmount() * -1 - ); + ]; } $data['products'] = $arrProducts; @@ -279,7 +291,7 @@ protected function doStartTransaction($order, $total, $currency, $bankId) } $ipAddress = $order->getRemoteIp(); //The ip address field in magento is too short, if the ip is invalid, get the ip myself - if(!filter_var($ipAddress, FILTER_VALIDATE_IP)){ + if (!filter_var($ipAddress, FILTER_VALIDATE_IP)) { $ipAddress = \Paynl\Helper::getIp(); } $data['ipaddress'] = $ipAddress; @@ -292,4 +304,4 @@ public function getPaymentOptionId() { return $this->getConfigData('payment_option_id'); } -} \ No newline at end of file +} diff --git a/Model/Paynl.php b/Model/Paynl.php index ffbab1a..922823c 100644 --- a/Model/Paynl.php +++ b/Model/Paynl.php @@ -68,7 +68,7 @@ class Paynl implements \Magestore\WebposPaynl\Api\PaynlInterface public function __construct( \Magestore\WebposPaynl\Helper\Data $helper, \Magento\Framework\UrlInterface $url, - \Magento\Framework\App\Config\ConfigResource\ConfigInterface $resourceConfig, + \Magento\Framework\App\Config\ConfigResource\ConfigInterface $resourceConfig, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList ) { $this->helper = $helper; @@ -80,7 +80,8 @@ public function __construct( /** * @return bool */ - public function validateRequiredSDK(){ + public function validateRequiredSDK() + { return (class_exists("\\Paynl\\Instore"))?true:false; } @@ -88,7 +89,8 @@ public function validateRequiredSDK(){ * @param string $key * @return array */ - public function getConfig($key = ''){ + public function getConfig($key = '') + { $configs = $this->helper->getPaynlConfig(); return ($key)?$configs[$key]:$configs; } @@ -96,7 +98,8 @@ public function getConfig($key = ''){ /** * @return \PayPal\Rest\ApiContext */ - public function getApiContext(){ + public function getApiContext() + { $clientId = $this->getConfig('client_id'); $clientSecret = $this->getConfig('client_secret'); $apiContext = new \PayPal\Rest\ApiContext( @@ -106,12 +109,12 @@ public function getApiContext(){ ) ); $environment = 'live'; - if($this->getConfig('is_sandbox')) { + if ($this->getConfig('is_sandbox')) { $environment = 'sandbox'; } - $apiContext->setConfig(array( + $apiContext->setConfig([ 'mode' => $environment - )); + ]); $apiContext->addRequestHeader('PayPal-Partner-Attribution-Id', 'Magestore_POS'); return $apiContext; } @@ -123,7 +126,8 @@ public function getApiContext(){ * @return string * @throws \Exception */ - public function createPayment($successUrl, $cancelUrl, $transactions){ + public function createPayment($successUrl, $cancelUrl, $transactions) + { $apiContext = $this->getApiContext(); $payer = new Payer(); @@ -143,7 +147,7 @@ public function createPayment($successUrl, $cancelUrl, $transactions){ try { $payment->create($apiContext); $approvalUrl = $payment->getApprovalLink(); - if($approvalUrl){ + if ($approvalUrl) { $url = $approvalUrl; } } catch (\PayPal\Exception\PayPalConnectionException $e) { @@ -163,12 +167,13 @@ public function createPayment($successUrl, $cancelUrl, $transactions){ * @param string $description * @return \PayPal\Api\Transaction */ - public function createTransaction($subtotal, $shipping, $tax, $total, $currencyCode, $description = ''){ + public function createTransaction($subtotal, $shipping, $tax, $total, $currencyCode, $description = '') + { $amount = new Amount(); $amount->setCurrency($currencyCode) ->setTotal($total); - if($subtotal > 0 || $shipping > 0 || $tax > 0){ + if ($subtotal > 0 || $shipping > 0 || $tax > 0) { $details = new Details(); $details->setShipping($shipping) ->setTax($tax) @@ -188,7 +193,8 @@ public function createTransaction($subtotal, $shipping, $tax, $total, $currencyC * @return string * @throws \Exception */ - public function completePayment($paymentId, $payerId){ + public function completePayment($paymentId, $payerId) + { $apiContext = $this->getApiContext(); $payment = Payment::get($paymentId, $apiContext); $execution = new PaymentExecution(); @@ -198,9 +204,9 @@ public function completePayment($paymentId, $payerId){ try { $payment->execute($execution, $apiContext); $transactions = $payment->getTransactions(); - if(!empty($transactions) && isset($transactions[0])){ + if (!empty($transactions) && isset($transactions[0])) { $relatedResources = $transactions[0]->getRelatedResources(); - if(!empty($relatedResources) && isset($relatedResources[0])){ + if (!empty($relatedResources) && isset($relatedResources[0])) { $sale = $relatedResources[0]->getSale(); $transactionId = $sale->getId(); } @@ -218,7 +224,8 @@ public function completePayment($paymentId, $payerId){ * @return string * @throws \Exception */ - public function completeAppPayment($paymentId){ + public function completeAppPayment($paymentId) + { $apiContext = $this->getApiContext(); $payment = Payment::get($paymentId, $apiContext); @@ -226,9 +233,9 @@ public function completeAppPayment($paymentId){ try { $payment->get($paymentId, $apiContext); $transactions = $payment->getTransactions(); - if(!empty($transactions) && isset($transactions[0])){ + if (!empty($transactions) && isset($transactions[0])) { $relatedResources = $transactions[0]->getRelatedResources(); - if(!empty($relatedResources) && isset($relatedResources[0])){ + if (!empty($relatedResources) && isset($relatedResources[0])) { $sale = $relatedResources[0]->getSale(); $transactionId = $sale->getId(); } @@ -244,13 +251,14 @@ public function completeAppPayment($paymentId){ /** * @return bool */ - public function canConnectToApi(){ + public function canConnectToApi() + { $context = $this->getApiContext(); - $params = array('count' => 1, 'start_index' => 0); + $params = ['count' => 1, 'start_index' => 0]; $connected = true; - try{ + try { Payment::all($params, $context); - }catch (\Exception $e){ + } catch (\Exception $e) { $connected = false; } return $connected; @@ -266,16 +274,17 @@ public function canConnectToApi(){ * @return \PayPal\Api\Invoice * @throws \Exception */ - public function createInvoiceObject($merchantInfo, $billingInfo, $shippingInfo, $paymentTerm, $items, $note = ''){ + public function createInvoiceObject($merchantInfo, $billingInfo, $shippingInfo, $paymentTerm, $items, $note = '') + { $logo = $this->helper->getLogoUrl(); $invoice = new Invoice(); $invoice->setMerchantInfo($merchantInfo) - ->setBillingInfo(array($billingInfo)) + ->setBillingInfo([$billingInfo]) ->setNote($note) ->setPaymentTerm($paymentTerm) ->setShippingInfo($shippingInfo) ->setItems($items); - if($logo){ + if ($logo) { $invoice->setLogoUrl($logo); } return $invoice; @@ -286,7 +295,8 @@ public function createInvoiceObject($merchantInfo, $billingInfo, $shippingInfo, * @return mixed * @throws \Exception */ - public function createInvoice($invoice){ + public function createInvoice($invoice) + { $apiContext = $this->getApiContext(); try { $invoice->create($apiContext); @@ -301,7 +311,8 @@ public function createInvoice($invoice){ * @return \PayPal\Api\Invoice * @throws \Exception */ - public function createInvoiceAndSend($invoice){ + public function createInvoiceAndSend($invoice) + { $apiContext = $this->getApiContext(); try { $invoice->create($apiContext); @@ -317,7 +328,8 @@ public function createInvoiceAndSend($invoice){ * @return \Magestore\WebposPaynl\Model\Paynl * @throws \Exception */ - public function sendInvoice($invoice){ + public function sendInvoice($invoice) + { try { $apiContext = $this->getApiContext(); $invoice->send($apiContext); @@ -332,7 +344,8 @@ public function sendInvoice($invoice){ * @return \Magestore\WebposPaynl\Model\Paynl * @throws \Exception */ - public function sendInvoiceById($invoiceId){ + public function sendInvoiceById($invoiceId) + { try { $apiContext = $this->getApiContext(); $invoice = Invoice::get($invoiceId, $apiContext); @@ -348,10 +361,11 @@ public function sendInvoiceById($invoiceId){ * @return string * @throws \Exception */ - public function getInvoiceQrCode($invoice){ + public function getInvoiceQrCode($invoice) + { try { $apiContext = $this->getApiContext(); - $image = $invoice->qrCode($invoice->getId(), array(), $apiContext); + $image = $invoice->qrCode($invoice->getId(), [], $apiContext); $qrCode = $image->getImage(); } catch (\Exception $e) { throw $e; @@ -368,7 +382,8 @@ public function getInvoiceQrCode($invoice){ * @param \PayPal\Api\Address $address * @return \PayPal\Api\MerchantInfo */ - public function createMerchantInfo($email, $firstname, $lastname, $businessName, $phone, $address){ + public function createMerchantInfo($email, $firstname, $lastname, $businessName, $phone, $address) + { $merchantInfo = new MerchantInfo(); $merchantInfo->setEmail($email) ->setFirstName($firstname) @@ -384,7 +399,8 @@ public function createMerchantInfo($email, $firstname, $lastname, $businessName, * @param string $number * @return \PayPal\Api\Phone */ - public function createPhone($countryCode, $number){ + public function createPhone($countryCode, $number) + { $phone = new Phone(); $phone->setCountryCode($countryCode) ->setNationalNumber($number); @@ -400,7 +416,8 @@ public function createPhone($countryCode, $number){ * @param string $countryCode * @return \PayPal\Api\Address */ - public function createAddress($line1, $line2, $city, $state, $postalCode, $countryCode){ + public function createAddress($line1, $line2, $city, $state, $postalCode, $countryCode) + { $address = new Address(); $address->setLine1($line1)->setLine2($line2) ->setCity($city) @@ -420,7 +437,8 @@ public function createAddress($line1, $line2, $city, $state, $postalCode, $count * @param \PayPal\Api\InvoiceAddress $invoiceAddress * @return \PayPal\Api\BillingInfo */ - public function createBillingInfo($email, $firstname, $lastname, $businessName, $phone, $addtionalInfo = '', $invoiceAddress){ + public function createBillingInfo($email, $firstname, $lastname, $businessName, $phone, $addtionalInfo = '', $invoiceAddress) + { $billing = new BillingInfo(); $billing->setEmail($email); $billing->setFirstName($firstname); @@ -443,7 +461,8 @@ public function createBillingInfo($email, $firstname, $lastname, $businessName, * @param string $countryCode * @return \PayPal\Api\InvoiceAddress */ - public function createInvoiceAddress($line1, $line2, $city, $state, $postalCode, $countryCode){ + public function createInvoiceAddress($line1, $line2, $city, $state, $postalCode, $countryCode) + { $address = new InvoiceAddress(); $address->setLine1($line1)->setLine2($line2) ->setCity($city) @@ -461,7 +480,8 @@ public function createInvoiceAddress($line1, $line2, $city, $state, $postalCode, * @param \PayPal\Api\InvoiceAddress $invoiceAddress * @return \PayPal\Api\ShippingInfo */ - public function createShippingInfo($firstname, $lastname, $businessName, $phone, $invoiceAddress){ + public function createShippingInfo($firstname, $lastname, $businessName, $phone, $invoiceAddress) + { $shipping = new ShippingInfo(); $shipping->setFirstName($firstname) ->setLastName($lastname) @@ -476,12 +496,13 @@ public function createShippingInfo($firstname, $lastname, $businessName, $phone, * @param string $dueDate * @return \PayPal\Api\PaymentTerm */ - public function createPaymentTerm($termType, $dueDate = ''){ + public function createPaymentTerm($termType, $dueDate = '') + { $paymentTerm = new PaymentTerm(); - if($termType){ + if ($termType) { $paymentTerm->setTermType($termType); - }else{ - if($dueDate){ + } else { + if ($dueDate) { $paymentTerm->setDueDate($dueDate); } } @@ -492,7 +513,8 @@ public function createPaymentTerm($termType, $dueDate = ''){ * @param string $percent * @return \PayPal\Api\Cost */ - public function createPercentCost($percent){ + public function createPercentCost($percent) + { $cost = new Cost(); $cost->setPercent($percent); return $cost; @@ -502,7 +524,8 @@ public function createPercentCost($percent){ * @param \PayPal\Api\Currency $amount * @return \PayPal\Api\Cost */ - public function createFixedCost($amount){ + public function createFixedCost($amount) + { $cost = new Cost(); $cost->setAmount($amount); return $cost; @@ -513,7 +536,8 @@ public function createFixedCost($amount){ * @param string|float $value * @return \PayPal\Api\Currency */ - public function createCurrency($currencyCode, $value){ + public function createCurrency($currencyCode, $value) + { $currency = new Currency(); $currency->setCurrency($currencyCode); $currency->setValue($value); @@ -525,7 +549,8 @@ public function createCurrency($currencyCode, $value){ * @param string $name * @return \PayPal\Api\Tax */ - public function createPercentTax($percent, $name = ''){ + public function createPercentTax($percent, $name = '') + { $tax = new Tax(); $tax->setPercent($percent)->setName($name); return $tax; @@ -536,7 +561,8 @@ public function createPercentTax($percent, $name = ''){ * @param string $name * @return \PayPal\Api\Tax */ - public function createFixedTax($amount, $name = ''){ + public function createFixedTax($amount, $name = '') + { $tax = new Tax(); $tax->setAmount($amount)->setName($name); return $tax; @@ -548,7 +574,8 @@ public function createFixedTax($amount, $name = ''){ * @param \PayPal\Api\Currency $unitPrice * @return \PayPal\Api\InvoiceItem */ - public function createInvoiceItem($name, $qty, $unitPrice){ + public function createInvoiceItem($name, $qty, $unitPrice) + { $item = new InvoiceItem(); $item->setName($name) ->setQuantity($qty) @@ -560,7 +587,8 @@ public function createInvoiceItem($name, $qty, $unitPrice){ * @param \PayPal\Api\Currency $other * @return \PayPal\Api\PaymentSummary */ - public function createPaymentSummary($other){ + public function createPaymentSummary($other) + { $paymentSummary = new PaymentSummary(); $paymentSummary->setOther($other); return $paymentSummary; @@ -571,7 +599,8 @@ public function createPaymentSummary($other){ * @param \PayPal\Api\Tax $tax * @return \PayPal\Api\ShippingCost */ - public function createShippingCost($amount, $tax){ + public function createShippingCost($amount, $tax) + { $shippingCost = new ShippingCost(); $shippingCost->setAmount($amount); $shippingCost->setTax($tax); @@ -583,7 +612,8 @@ public function createShippingCost($amount, $tax){ * @return \PayPal\Api\Invoice * @throws \Exception */ - public function getInvoice($invoiceId){ + public function getInvoice($invoiceId) + { try { $apiContext = $this->getApiContext(); $invoice = Invoice::get($invoiceId, $apiContext); @@ -599,7 +629,8 @@ public function getInvoice($invoiceId){ * @param string $method * @return \PayPal\Api\PaymentDetail */ - public function createPaymentDetail($amount, $note = "", $method = "OTHER"){ + public function createPaymentDetail($amount, $note = "", $method = "OTHER") + { $paymentDetail = new PaymentDetail(); $paymentDetail->setMethod($method);//["BANK_TRANSFER", "CASH", "CHECK", "CREDIT_CARD", "DEBIT_CARD", "PAYPAL", "WIRE_TRANSFER", "OTHER"] $paymentDetail->setNote($note); @@ -613,10 +644,11 @@ public function createPaymentDetail($amount, $note = "", $method = "OTHER"){ * @return $this * @throws \Exception */ - public function recordPaymentForInvoice($invoice, $paymentDetail){ + public function recordPaymentForInvoice($invoice, $paymentDetail) + { try { $apiContext = $this->getApiContext(); - $invoice->recordPayment($paymentDetail,$apiContext); + $invoice->recordPayment($paymentDetail, $apiContext); } catch (\Exception $e) { throw $e; } @@ -634,11 +666,11 @@ public function getTokenInfo($authCode) $apiContext = $this->getApiContext(); $clientId = $this->getConfig('client_id'); $clientSecret = $this->getConfig('client_secret'); - $params = array( + $params = [ 'client_id' => $clientId, 'client_secret' => $clientSecret, 'code' => $authCode - ); + ]; $tokenInfo = OpenIdTokeninfo::createFromAuthorizationCode($params, null, null, $apiContext); return $tokenInfo; } @@ -649,22 +681,23 @@ public function getTokenInfo($authCode) * @return string * @throws \Magento\Framework\Exception\StateException */ - public function getAccessToken(){ + public function getAccessToken() + { $apiContext = $this->getApiContext(); $clientId = $this->getConfig('client_id'); $clientSecret = $this->getConfig('client_secret'); $refreshToken = $this->getConfig('refresh_token'); - if(!$refreshToken) { + if (!$refreshToken) { throw new StateException(__('Refresh token was missing')); } - $params = array( + $params = [ 'client_id' => $clientId, 'client_secret' => $clientSecret, 'refresh_token' => $refreshToken - ); + ]; $openIdTokenInfo = new OpenIdTokeninfo(); $tokenInfo = $openIdTokenInfo->createFromRefreshToken($params, $apiContext); - if($tokenInfo) { + if ($tokenInfo) { $accessToken = $tokenInfo->access_token; if ($accessToken) { $this->resourceConfig->saveConfig( diff --git a/Model/PaynlService.php b/Model/PaynlService.php index 56afc48..5ab45ac 100644 --- a/Model/PaynlService.php +++ b/Model/PaynlService.php @@ -6,6 +6,7 @@ */ namespace Magestore\WebposPaynl\Model; + use Magento\Payment\Helper\Data as PaymentHelper; use Magento\Quote\Model\QuoteRepository; use Magento\Sales\Model\OrderRepository; @@ -113,7 +114,8 @@ public function __construct( * Init default data * @return \Magestore\WebposPaynl\Api\PaynlServiceInterface */ - public function initDefaultData(){ + public function initDefaultData() + { $successUrl = $this->helper->getUrl('webpospaynl/payment/success'); $cancelUrl = $this->helper->getUrl('webpospaynl/payment/cancel'); $this->setSuccessUrl($successUrl); @@ -127,7 +129,8 @@ public function initDefaultData(){ * @api * @return string|null */ - public function getSuccessUrl(){ + public function getSuccessUrl() + { return $this->successUrl; } @@ -138,7 +141,8 @@ public function getSuccessUrl(){ * @param string $url * @return $this */ - public function setSuccessUrl($url){ + public function setSuccessUrl($url) + { $this->successUrl = $url; } @@ -148,7 +152,8 @@ public function setSuccessUrl($url){ * @api * @return string|null */ - public function getCancelUrl(){ + public function getCancelUrl() + { return $this->cancelUrl; } @@ -159,14 +164,16 @@ public function getCancelUrl(){ * @param string $url * @return $this */ - public function setCancelUrl($url){ + public function setCancelUrl($url) + { $this->cancelUrl = $url; } /** * @return bool */ - public function isEnable(){ + public function isEnable() + { $hasSDK = $this->paynl->validateRequiredSDK(); $configs = $this->paynl->getConfig(); return ($hasSDK && $configs['enable'] && !empty($configs['client_id']) && !empty($configs['client_secret']))?true:false; @@ -175,18 +182,19 @@ public function isEnable(){ /** * @return string */ - public function getConfigurationError(){ + public function getConfigurationError() + { $message = ''; $hasSDK = $this->paynl->validateRequiredSDK(); $configs = $this->paynl->getConfig(); - if(!$hasSDK){ + if (!$hasSDK) { $message = __('Paynl SDK not found, please go to the configuration to get the instruction to install the SDK'); - }else{ - if($configs['enable']){ - if(empty($configs['client_id']) || empty($configs['client_secret'])){ + } else { + if ($configs['enable']) { + if (empty($configs['client_id']) || empty($configs['client_secret'])) { $message = __('Paynl application client id and client secret are required'); } - }else{ + } else { $message = __('Paynl integration is disabled'); } } @@ -197,7 +205,8 @@ public function getConfigurationError(){ * Validate configruation * @return \Magestore\WebposPaynl\Api\PaynlServiceInterface */ - public function validate(){ + public function validate() + { $isEnable = $this->isEnable(); if (!$isEnable) { $message = $this->getConfigurationError(); @@ -212,7 +221,8 @@ public function validate(){ * @param \Magestore\WebposPaynl\Api\Data\TransactionInterface $transaction * @return string */ - public function startPayment($transaction){ + public function startPayment($transaction) + { $this->validate(); $total = $transaction->getTotal(); $quoteId = $transaction->getQuoteId(); @@ -242,7 +252,8 @@ protected function _getCheckoutSession() * @param string $payerId * @return string */ - public function finishPayment($paymentId, $payerId){ + public function finishPayment($paymentId, $payerId) + { return $this->paynl->completePayment($paymentId, $payerId); } @@ -250,14 +261,16 @@ public function finishPayment($paymentId, $payerId){ * @param string $paymentId * @return string */ - public function finishAppPayment($paymentId){ + public function finishAppPayment($paymentId) + { return $this->paynl->completeAppPayment($paymentId); } /** * @return bool */ - public function canConnectToApi(){ + public function canConnectToApi() + { return $this->paynl->canConnectToApi(); } @@ -271,11 +284,12 @@ public function canConnectToApi(){ * @param string $note * @return \Magestore\WebposPaynl\Api\Data\InvoiceInterface */ - public function createAndSendInvoiceToCustomer($billing, $shipping, $items, $totals, $totalPaid, $currencyCode, $note){ + public function createAndSendInvoiceToCustomer($billing, $shipping, $items, $totals, $totalPaid, $currencyCode, $note) + { // validate SDK installed and some configuration, thow exception if error $this->validate(); $enable = $this->helper->isAllowCustomerPayWithEmail(); - if($enable){ + if ($enable) { // prepare merchant info object $merchantInfoConfig = $this->helper->getMerchantInfo(); $merchantPhoneCode = $this->phoneSource->getPhoneCodeByCountry($merchantInfoConfig['country_id']); @@ -334,7 +348,7 @@ public function createAndSendInvoiceToCustomer($billing, $shipping, $items, $tot foreach ($items as $item) { $unitPrice = $this->paynl->createCurrency($currencyCode, $item->getUnitPrice()); $invoiceItem = $this->paynl->createInvoiceItem($item->getName(), $item->getQty(), $unitPrice); - if($item->getTaxPercent() > 0){ + if ($item->getTaxPercent() > 0) { $itemTax = $this->paynl->createPercentTax($item->getTaxPercent(), __('Tax')); $invoiceItem->setTax($itemTax); } @@ -345,27 +359,27 @@ public function createAndSendInvoiceToCustomer($billing, $shipping, $items, $tot $invoice = $this->paynl->createInvoiceObject($merchantInfo, $billingInfo, $shippingInfo, $paymentTerm, $invoiceItems, $note); // set some totals data - if(!empty($totals)){ + if (!empty($totals)) { $discount = 0; - foreach ($totals as $total){ + foreach ($totals as $total) { $amount = $total->getAmount(); $code = $total->getCode(); - if($code == 'grandtotal'){ + if ($code == 'grandtotal') { $grandTotal = $this->paynl->createCurrency($currencyCode, $amount); $invoice->setTotalAmount($grandTotal); } - if($code == 'shipping' && $amount > 0){ + if ($code == 'shipping' && $amount > 0) { $shippingTaxCurrency = $this->paynl->createCurrency($currencyCode, 0); $shippingTax = $this->paynl->createFixedTax($shippingTaxCurrency, __('Tax')); $shippingCurrency = $this->paynl->createCurrency($currencyCode, $amount); $shippingCost = $this->paynl->createShippingCost($shippingCurrency, $shippingTax); $invoice->setShippingCost($shippingCost); } - if($amount && $amount < 0){ + if ($amount && $amount < 0) { $discount -= floatval($amount); } } - if($discount > 0){ + if ($discount > 0) { $discountCurrency = $this->paynl->createCurrency($currencyCode, $discount); $discountCost = $this->paynl->createFixedCost($discountCurrency); $invoice->setDiscount($discountCost); @@ -380,7 +394,7 @@ public function createAndSendInvoiceToCustomer($billing, $shipping, $items, $tot $invoice = $this->paynl->createInvoice($invoice); // set total paid for invoice - if(!empty($totalPaid)){ + if (!empty($totalPaid)) { $totalPaid = $this->paynl->createCurrency($currencyCode, $totalPaid); $paymentDetail = $this->paynl->createPaymentDetail($totalPaid, __("Paid via Magento POS system")); $this->paynl->recordPaymentForInvoice($invoice, $paymentDetail); @@ -395,13 +409,14 @@ public function createAndSendInvoiceToCustomer($billing, $shipping, $items, $tot /** * @param $invoice */ - protected function getInvoiceData($invoice){ + protected function getInvoiceData($invoice) + { $data = $this->invoiceData; - if($invoice instanceof \PayPal\Api\Invoice){ + if ($invoice instanceof \PayPal\Api\Invoice) { $data->setId($invoice->getId()); $data->setNumber($invoice->getNumber()); $data->setQrCode($this->paynl->getInvoiceQrCode($invoice)); - }else{ + } else { $data->setId(''); $data->setNumber(''); $data->setQrCode(''); @@ -414,7 +429,8 @@ protected function getInvoiceData($invoice){ * @return \PayPal\Api\Invoice * @throws \Exception */ - public function getInvoice($invoiceId){ + public function getInvoice($invoiceId) + { return $this->paynl->getInvoice($invoiceId); } @@ -422,7 +438,8 @@ public function getInvoice($invoiceId){ * @param \PayPal\Api\Invoice $invoice * @return bool */ - public function isInvoicePaid($invoice){ + public function isInvoicePaid($invoice) + { $paidStatus = ['PAID', 'MARKED_AS_PAID', 'PARTIALLY_PAID']; $status = $invoice->getStatus(); return (in_array($status, $paidStatus))?true:false; @@ -432,7 +449,8 @@ public function isInvoicePaid($invoice){ * @param \PayPal\Api\Invoice $invoice * @return bool */ - public function isInvoiceCancelled($invoice){ + public function isInvoiceCancelled($invoice) + { $cancelledStatus = ['CANCELLED']; $status = $invoice->getStatus(); return (in_array($status, $cancelledStatus))?true:false; @@ -442,7 +460,8 @@ public function isInvoiceCancelled($invoice){ * @param \PayPal\Api\Invoice $invoice * @return bool */ - public function isInvoiceRefunded($invoice){ + public function isInvoiceRefunded($invoice) + { $refundedStatus = ['REFUNDED', 'PARTIALLY_REFUNDED', 'MARKED_AS_REFUNDED']; $status = $invoice->getStatus(); return (in_array($status, $refundedStatus))?true:false; @@ -452,7 +471,8 @@ public function isInvoiceRefunded($invoice){ * @param \PayPal\Api\Invoice $invoice * @return \PayPal\Api\PaymentSummary */ - public function getInvoicePaidAmount($invoice){ + public function getInvoicePaidAmount($invoice) + { return $invoice->getPaidAmount(); } @@ -460,14 +480,16 @@ public function getInvoicePaidAmount($invoice){ * @param \PayPal\Api\Invoice $invoice * @return \PayPal\Api\PaymentSummary */ - public function getInvoiceRefundedAmount($invoice){ + public function getInvoiceRefundedAmount($invoice) + { return $invoice->getRefundedAmount(); } /** * @return string */ - public function getAccessToken(){ + public function getAccessToken() + { return $this->paynl->getAccessToken(); } } diff --git a/Model/Source/PhoneCode.php b/Model/Source/PhoneCode.php index 1fb33d1..cffb71b 100644 --- a/Model/Source/PhoneCode.php +++ b/Model/Source/PhoneCode.php @@ -18,12 +18,13 @@ class PhoneCode * Parsed codes * @var array */ - protected $phoneCodes = array(); + protected $phoneCodes = []; /** * PhoneCode constructor. */ - public function __construct() { + public function __construct() + { $this->phoneCodes = \Zend_Json::decode(self::PHONECODE_JSON); } @@ -35,4 +36,4 @@ public function getPhoneCodeByCountry($countryId) { return isset($this->phoneCodes[$countryId])?$this->phoneCodes[$countryId]:''; } -} \ No newline at end of file +} diff --git a/Observer/GetPaymentAfter.php b/Observer/GetPaymentAfter.php index 581c3ef..2764d48 100644 --- a/Observer/GetPaymentAfter.php +++ b/Observer/GetPaymentAfter.php @@ -26,7 +26,7 @@ public function execute(EventObserver $observer) $payments = $observer->getData('payments'); $paymentList = $payments->getList(); $isPaynlEnable = $paynlHelper->isEnablePaynl(); - if($isPaynlEnable) { + if ($isPaynlEnable) { $paynlPayment = $this->addWebposPaynl(); $paymentList[] = $paynlPayment->getData(); } @@ -62,5 +62,4 @@ public function addWebposPaynl() $paymentModel->setIsSandbox($isSandbox); return $paymentModel; } - -} \ No newline at end of file +} diff --git a/Setup/InstallSchema.php b/Setup/InstallSchema.php index 8fa02dd..6003625 100644 --- a/Setup/InstallSchema.php +++ b/Setup/InstallSchema.php @@ -5,9 +5,11 @@ * See COPYING.txt for license details. */ namespace Magestore\WebposPaynl\Setup; + use Magento\Framework\Setup\InstallSchemaInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\SchemaSetupInterface; + class InstallSchema implements InstallSchemaInterface { @@ -19,4 +21,4 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con $installer->endSetup(); return $this; } -} \ No newline at end of file +} diff --git a/view/frontend/templates/container.phtml b/view/frontend/templates/container.phtml index 76e4a4b..795385e 100644 --- a/view/frontend/templates/container.phtml +++ b/view/frontend/templates/container.phtml @@ -2,7 +2,7 @@
-isEnablePaynl()):?> +isEnablePaynl()) :?>