Skip to content

Commit

Permalink
New version od payment widget and fix of calculating checksum when wi…
Browse files Browse the repository at this point in the history
…dget is used
  • Loading branch information
tbajorek committed Feb 22, 2018
1 parent 9d331fa commit d42f01a
Show file tree
Hide file tree
Showing 10 changed files with 11,512 additions and 153 deletions.
12 changes: 8 additions & 4 deletions app/code/local/Dotpay/Dotpay/Block/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ protected function _construct() {
* @return Mage_Sales_Model_Order Order object
*/
protected function _getOrder() {
if ($this->getOrder())
if ($this->getOrder()) {
return $this->getOrder();
if ($orderIncrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId())
}
if ($orderIncrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId()) {
return Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
}
}

/**
Expand All @@ -55,8 +57,9 @@ protected function _getOrder() {
*/
public function getPaymentImageSrc() {
$pathData = array('images', 'dotpay', 'dotpay', 'logotypy_kanalow.png');
if (!file_exists(Mage::getDesign()->getFilename(implode(DS, $pathData), array('_type' => 'skin'))))
if (!file_exists(Mage::getDesign()->getFilename(implode(DS, $pathData), array('_type' => 'skin')))) {
return false;
}
return $this->getSkinUrl(implode('/', $pathData));
}

Expand All @@ -67,8 +70,9 @@ public function getPaymentImageSrc() {
public function getPaymentLogoSrc() {
$pathData = array('images', 'dotpay', 'dotpay', 'dotpay_logo.png');
$filename = Mage::getDesign()->getFilename(implode(DS, $pathData), array('_type' => 'skin'));
if (!file_exists($filename))
if (!file_exists($filename)) {
return false;
}
return $this->getSkinUrl(implode('/', $pathData));
}
}
54 changes: 47 additions & 7 deletions app/code/local/Dotpay/Dotpay/Block/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ class Dotpay_Dotpay_Block_Redirect extends Mage_Core_Block_Template {
* @return Dotpay_Dotpay_Model_PaymentMethod Object of main Dotpay payment model
*/
public function getMethodInstance() {
if($this->methodInstance === null)
if($this->methodInstance === null) {
$this->methodInstance = $this->_getOrder()->getPayment()->getMethodInstance();
}
return $this->methodInstance;
}

Expand All @@ -58,14 +59,41 @@ public function setOrdrerId($orderId) {
* @return Mage_Sales_Model_Order Order object
*/
protected function _getOrder() {
if($this->orderId !== null)
if($this->orderId !== null) {
return Mage::getModel('sales/order')->loadByIncrementId($this->orderId);
if ($this->getOrder())
}
if ($this->getOrder()) {
return $this->getOrder();
if ($orderIncrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId())
}
if ($orderIncrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId()) {
return Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
}
}

/**
* Return current order for template
* @return Mage_Sales_Model_Order
*/
public function getCurrentOrder() {
return $this->_getOrder();
}

/**
* Returns url of controller, which is responsible for generating CHK signature
* @return string
*/
public function getSignatureUrl() {
return Mage::getUrl('dotpay/processing/signature');
}

/**
* Checks, if test mode is switch on
* @return boolean
*/
public function isTestMode() {
return ($this->getMethodInstance()->getConfigData('test') && $this->getMethodInstance()->getConfigData('apiversion') == 'dev');
}

/**
* Checks, if widget mode is switch on
* @return boolean
Expand All @@ -81,6 +109,15 @@ public function isWidgetMode() {
public function getOrderId() {
return $this->_getOrder()->getRealOrderId();
}

/**
* Return language id selected by client
* @return string
*/
public function getLangCode() {
$langCode = explode('_', Mage::app()->getLocale()->getLocaleCode());
return $langCode[0];
}

/**
* Returns form, which can be sent to Dotpay server
Expand All @@ -94,17 +131,19 @@ public function getForm() {
->setMethod('post')
->setUseContainer(TRUE);

foreach ($this->getMethodInstance()->getRedirectionFormData() as $name => $value)
foreach ($this->getMethodInstance()->getRedirectionFormData() as $name => $value) {
$form->addField($name, 'hidden', array('name' => $name, 'value' => $value));
}

if($this->isWidgetMode()) {
$form->addType('dotpay_widget','Dotpay_Dotpay_Model_Form_Widget');
$form->addType('dotpay_agreement','Dotpay_Dotpay_Model_Form_Agreement');
$form->addField('dpwidget', 'dotpay_widget', array());

$bylaw = $this->getMethodInstance()->getAgreements('bylaw');
if(trim($bylaw) == '')
if(trim($bylaw) == '') {
$bylaw = 'I accept Dotpay S.A. <a title="regulations of payments" target="_blank" href="https://ssl.dotpay.pl/files/regulamin_dotpay_sa_dokonywania_wplat_w_serwisie_dotpay_en.pdf">Regulations of Payments</a>.';
}
$form->addField('bylaw', 'dotpay_agreement', array(
'label' => $bylaw,
'name' => 'bylaw',
Expand All @@ -114,8 +153,9 @@ public function getForm() {
));

$personalData = $this->getMethodInstance()->getAgreements('personal_data');
if(trim($personalData) == '')
if(trim($personalData) == '') {
$personalData = 'I agree to the use of my personal data by Dotpay S.A. 30-552 Kraków (Poland), Wielicka 72 for the purpose of conducting a process of payments in accordance with applicable Polish laws (Act of 29.08.1997 for the protection of personal data, Dz. U. No 133, pos. 883, as amended). I have the right to inspect and correct my data.';
}
$form->addField('personal_data', 'dotpay_agreement', array(
'label' => $personalData,
'name' => 'personal_data',
Expand Down
4 changes: 1 addition & 3 deletions app/code/local/Dotpay/Dotpay/Model/Form/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public function getLabelHtml($idSuffix = '') {
* @return string
*/
public function getElementHtml() {
return '<div class="selected-channel-message">'.Mage::helper('dotpay')->__('Selected payment channel').': <a href="#" class="channel-selected-change">'.Mage::helper('dotpay')->__('change channel').'&nbsp;&raquo;</a></div>
<div class="selectedChannelContainer channels-wrapper"><hr /></div>
<div class="collapsibleWidgetTitle">'.Mage::helper('dotpay')->__('Available channels').':</div><p class="dotpay-form-widget-container"></p>';
return '<p class="dotpay-widget-container"></p>';
}
}
25 changes: 16 additions & 9 deletions app/code/local/Dotpay/Dotpay/Model/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Dotpay_Dotpay_Model_PaymentMethod extends Mage_Payment_Model_Method_Abstra
*
* @var string Payment method code
*/
protected $_code = 'dotpay';
protected $_code = 'dotpay';

/**
*
Expand All @@ -50,8 +50,9 @@ class Dotpay_Dotpay_Model_PaymentMethod extends Mage_Payment_Model_Method_Abstra
* @return Mage_Sales_Model_Order
*/
public function getOrder() {
if(!$this->_order)
if(!$this->_order) {
$this->_order = $this->getInfoInstance()->getOrder();
}
return $this->_order;
}

Expand All @@ -68,12 +69,13 @@ public function getOrderPlaceRedirectUrl() {
* @return string
*/
public function getRedirectUrl() {
if (!$this->getConfigData('test') && $this->getConfigData('apiversion') == 'dev')
if (!$this->getConfigData('test') && $this->getConfigData('apiversion') == 'dev') {
return $this->getConfigData('redirect_url');
else if ($this->getConfigData('apiversion') == 'dev')
} else if ($this->getConfigData('apiversion') == 'dev') {
return $this->getConfigData('redirect_url_test');
else
} else {
return $this->getConfigData('redirect_url_legacy');
}
}

/**
Expand All @@ -82,8 +84,9 @@ public function getRedirectUrl() {
* @return string
*/
public function getAgreements($what) {
if($this->_agreements === false)
if($this->_agreements === false) {
$this->_agreements = $this->downloadAgreements();
}

$resultStr = '';
if(isset($this->_agreements['forms']) && is_array($this->_agreements['forms'])) {
Expand Down Expand Up @@ -135,10 +138,11 @@ private function downloadAgreements() {
curl_close($curl);
}

if($resultJson !== false)
if($resultJson !== false) {
return json_decode($resultJson, true);
else
} else {
return array();
}
}

/**
Expand All @@ -152,8 +156,11 @@ public function getRedirectionFormData() {
$api = new Dotpay_Dotpay_Model_Api_Legacy();
}
$data = $api->getPaymentData($this->getConfigData('id'), $this->getOrder(), $this->getConfigData('widget')?4:0);
if($this->getConfigData('apiversion') != 'dev' || !$this->getConfigData('widget'))
if($this->getConfigData('apiversion') != 'dev' || !$this->getConfigData('widget')) {
$data[$api::CHK] = $api->generateCHK($this->getConfigData('id'), $this->getConfigData('pin'), $data);
} else {//choose payment channel before calculation CHK
$data[$api::CHK] = null;
}
return $data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private function updatePaymentStatus() {
* Sets status of payment as completed
* @param Mage_Sales_Model_Order_Payment $payment object with payment data
*/
private function setPaymentStatusCompleted(Mage_Sales_Model_Order_Payment $payment) {echo 'new';
private function setPaymentStatusCompleted(Mage_Sales_Model_Order_Payment $payment) {
$order = $this->getOrder();
$order->setTotalPaid($this->api->getTotalAmount())
->sendOrderUpdateEmail(true)
Expand All @@ -104,7 +104,7 @@ private function setPaymentStatusCompleted(Mage_Sales_Model_Order_Payment $payme
if ($lastStatus !== Mage_Sales_Model_Order::STATE_COMPLETE || $lastStatus !== Mage_Sales_Model_Order::STATE_PROCESSING) {
$message = Mage::helper('dotpay')->__('The order has been paid by Dotpay').': '.
$this->api->getTotalAmount().' '.
$this->api->getOperationCurrency().
$this->api->getOperationCurrency().'. '.
Mage::helper('dotpay')->__('Transaction number').': '.
$this->api->getTransactionId();
$order->setTotalPaid($this->api->getTotalAmount())
Expand Down Expand Up @@ -290,8 +290,8 @@ protected function createInvoice($order) {
return;
}
$invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
$invoice->sendEmail(true, Mage::helper('dotpay')->__('The invoice has been created.'));
$invoice->setEmailSent(true);
$invoice->sendEmail(true, Mage::helper('dotpay')->__('The invoice has been created.'));
$invoice->setEmailSent(true);
$invoice->register();
$invoice->save();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ public function retryAction() {
* @return null
*/
public function statusAction() {
if(!$this->getRequest()->getParam('status') && !$this->getRequest()->getParam('error_code'))
if(!$this->getRequest()->getParam('status') && !$this->getRequest()->getParam('error_code')) {
return $this->norouteAction();
}
$resultAction = $this->getResultInBackPage().'Action';
$this->$resultAction();
}
Expand Down Expand Up @@ -102,8 +103,9 @@ public function cancelAction() {
* @return Mage_Core_Controller_Response_Http
*/
public function signatureAction() {
if($this->getRequest()->getParam('order') === null)
if($this->getRequest()->getParam('order') === null) {
die('BAD ORDER');
}
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getRequest()->getParam('order'));
$model = $order->getPayment()->getMethodInstance();
if($model->getConfigData('apiversion') == 'dev') {
Expand All @@ -122,9 +124,10 @@ public function signatureAction() {
* @return string
*/
private function getResultInBackPage() {
if($this->getRequest()->getParam('status') == 'OK' && !$this->getRequest()->getParam('error_code'))
if($this->getRequest()->getParam('status') == 'OK' && !$this->getRequest()->getParam('error_code')) {
return 'success';
else
} else {
return 'cancel';
}
}
}
3 changes: 3 additions & 0 deletions app/design/frontend/base/default/layout/dotpay_dotpay.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0"?>
<layout version="0.1.0">
<dotpay_processing_redirect translate="label">
<reference name="head">
<action method="addItem"><type>skin_js</type><name>js/dotpay/widget.js</name></action>
</reference>
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
Expand Down
Loading

0 comments on commit d42f01a

Please sign in to comment.