Payfast_Payment_Gateway_by_Modulesoft - Version 0.1.1

Version Notes

Please note that this extension is provided as is. It is highly recommended to always backup your installation prior to usage.

Download this release

Release Info

Developer Magento Core Team
Extension Payfast_Payment_Gateway_by_Modulesoft
Version 0.1.1
Comparing to
See all releases


Version 0.1.1

app/code/community/Mspl/Payfast/Block/Form.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Version : 0.1.0
4
+ FILE : Form.php
5
+ Date : 18-AUG-2010
6
+ Created By : Modulesoft Solution Private Limited (Sudhansu Ranjan Mangaraj)
7
+ Company : Modulesoft.com
8
+ Mail : sudhansumspl@live.com, sudhansu@modulesoft.in, info@modulesoft.in
9
+
10
+ This extension will help you to place your order payment with PayFast:
11
+ @ Payment Service Provider (http://www.payfast.co.za/).
12
+
13
+ Thanks
14
+ Modulesoft.com team
15
+ */
16
+ class Mspl_Payfast_Block_Form extends Mage_Payment_Block_Form
17
+ {
18
+ protected function _construct()
19
+ {
20
+ parent::_construct();
21
+ $this->setTemplate('payfast/form.phtml');
22
+ }
23
+
24
+ }
app/code/community/Mspl/Payfast/Block/Payment/Info.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Version : 0.1.0
4
+ FILE : Request.php
5
+ Date : 18-AUG-2010
6
+ Created By : Modulesoft Solution Private Limited (Sudhansu Ranjan Mangaraj)
7
+ Company : Modulesoft.com
8
+ Mail : sudhansumspl@live.com, sudhansu@modulesoft.in, info@modulesoft.in
9
+
10
+ This extension will help you to place your order payment with PayFast:
11
+ @ Payment Service Provider (http://www.payfast.co.za/).
12
+
13
+ Thanks
14
+ Modulesoft.com team
15
+ */
16
+ class Mspl_Payfast_Block_Payment_Info extends Mage_Payment_Block_Info_Cc
17
+ {
18
+ protected function _prepareSpecificInformation($transport = null)
19
+ {
20
+ $transport = parent::_prepareSpecificInformation($transport);
21
+ $payment = $this->getInfo();
22
+ $paypalInfo = Mage::getModel('payfast/info');
23
+ if (!$this->getIsSecureMode()) {
24
+ $info = $paypalInfo->getPaymentInfo($payment, true);
25
+ } else {
26
+ $info = $paypalInfo->getPublicPaymentInfo($payment, true);
27
+ }
28
+ return $transport->addData($info);
29
+ }
30
+ }
app/code/community/Mspl/Payfast/Block/Request.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Version : 0.1.0
4
+ FILE : Request.php
5
+ Date : 18-AUG-2010
6
+ Created By : Modulesoft Solution Private Limited (Sudhansu Ranjan Mangaraj)
7
+ Company : Modulesoft.com
8
+ Mail : sudhansumspl@live.com, sudhansu@modulesoft.in, info@modulesoft.in
9
+
10
+ This extension will help you to place your order payment with PayFast:
11
+ @ Payment Service Provider (http://www.payfast.co.za/).
12
+
13
+ Thanks
14
+ Modulesoft.com team
15
+ */
16
+ class Mspl_Payfast_Block_Request extends Mage_Core_Block_Abstract
17
+ {
18
+ protected function _toHtml()
19
+ {
20
+ $standard = Mage::getModel('payfast/standard');
21
+ $form = new Varien_Data_Form();
22
+ $form->setAction($standard->getPayFastUrl())
23
+ ->setId('payfast_checkout')
24
+ ->setName('payfast_checkout')
25
+ ->setMethod('POST')
26
+ ->setUseContainer(true);
27
+ foreach ($standard->getStandardCheckoutFormFields() as $field=>$value) {
28
+ $form->addField($field, 'hidden', array('name'=>$field, 'value'=>$value, 'size'=>200));
29
+ }
30
+ $html = '<html><body>';
31
+ $html.= $this->__('You will be redirected to PayFast in a few seconds.');
32
+ $html.= $form->toHtml();
33
+ #echo $html;exit;
34
+ $html.= '<script type="text/javascript">document.getElementById("payfast_checkout").submit();</script>';
35
+ $html.= '</body></html>';
36
+ return $html;
37
+ }
38
+ }
app/code/community/Mspl/Payfast/Helper/Data.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Version : 0.1.0
4
+ FILE : Data.php
5
+ Date : 18-AUG-2010
6
+ Created By : Modulesoft Solution Private Limited (Sudhansu Ranjan Mangaraj)
7
+ Company : Modulesoft.com
8
+ Mail : sudhansumspl@live.com, sudhansu@modulesoft.in, info@modulesoft.in
9
+
10
+ This extension will help you to place your order payment with PayFast:
11
+ @ Payment Service Provider (http://www.payfast.co.za/).
12
+
13
+ Thanks
14
+ Modulesoft.com team
15
+ */
16
+ class Mspl_Payfast_Helper_Data extends Mage_Payment_Helper_Data
17
+ {
18
+ public function getPendingPaymentStatus()
19
+ {
20
+ if (version_compare(Mage::getVersion(), '1.4.0', '<')) {
21
+ return Mage_Sales_Model_Order::STATE_HOLDED;
22
+ }
23
+ return Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
24
+ }
25
+ }
app/code/community/Mspl/Payfast/Logs/notify.txt ADDED
File without changes
app/code/community/Mspl/Payfast/Model/Info.php ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mspl_Payfast_Model_Info
4
+ {
5
+ const PAYMENT_STATUS = 'payment_status';
6
+ const M_PAYMENT_ID = 'm_payment_id';
7
+ const PF_PAYMENT_ID = 'pf_payment_id';
8
+ const EMAIL_ADDRESS = 'email_address';
9
+ const SIGNATURE = 'signature';
10
+
11
+ protected $_paymentMap = array(
12
+ self::PAYMENT_STATUS => 'payment_status',
13
+ self::M_PAYMENT_ID => 'm_payment_id',
14
+ self::PF_PAYMENT_ID => 'pf_payment_id',
15
+ self::EMAIL_ADDRESS => 'email_address',
16
+ self::SIGNATURE => 'signature'
17
+ );
18
+
19
+ protected $_paymentPublicMap = array( 'email_address',
20
+ );
21
+
22
+ public function getPaymentInfo(Mage_Payment_Model_Info $payment, $labelValuesOnly = false)
23
+ {
24
+ // collect paypal-specific info
25
+ $result = $this->_getFullInfo(array_values($this->_paymentMap), $payment, $labelValuesOnly);
26
+
27
+ return $result;
28
+ }
29
+
30
+ protected function _getFullInfo(array $keys, Mage_Payment_Model_Info $payment, $labelValuesOnly)
31
+ {
32
+ $result = array();
33
+ foreach ($keys as $key) {
34
+ if (!isset($this->_paymentMapFull[$key])) {
35
+ $this->_paymentMapFull[$key] = array();
36
+ }
37
+ if (!isset($this->_paymentMapFull[$key]['label'])) {
38
+ if (!$payment->hasAdditionalInformation($key)) {
39
+ $this->_paymentMapFull[$key]['label'] = false;
40
+ $this->_paymentMapFull[$key]['value'] = false;
41
+ } else {
42
+ $value = $payment->getAdditionalInformation($key);
43
+ $this->_paymentMapFull[$key]['label'] = $this->_getLabel($key);
44
+ $this->_paymentMapFull[$key]['value'] = $this->_getValue($value, $key);
45
+ }
46
+ }
47
+ if (!empty($this->_paymentMapFull[$key]['value'])) {
48
+ if ($labelValuesOnly) {
49
+ $result[$this->_paymentMapFull[$key]['label']] = $this->_paymentMapFull[$key]['value'];
50
+ } else {
51
+ $result[$key] = $this->_paymentMapFull[$key];
52
+ }
53
+ }
54
+ }
55
+ return $result;
56
+ }
57
+
58
+ protected function _getLabel($key)
59
+ {
60
+ switch ($key) {
61
+ case 'payment_status':
62
+ return Mage::helper('payfast')->__('Payment Status');
63
+ case 'm_payment_id':
64
+ return Mage::helper('payfast')->__('Payment ID');
65
+ case 'pf_payment_id':
66
+ return Mage::helper('payfast')->__('Payfast Payment ID');
67
+ case 'email_address':
68
+ return Mage::helper('payfast')->__('Email Address');
69
+ case 'amount_fee':
70
+ return Mage::helper('payfast')->__('Amount Fee');
71
+ case 'signature':
72
+ return Mage::helper('payfast')->__('Signature');
73
+ }
74
+ return '';
75
+ }
76
+
77
+ protected function _getValue($value, $key)
78
+ {
79
+ $label = '';
80
+ switch ($key) {
81
+ case 'paypal_avs_code':
82
+ $label = $this->_getAvsLabel($value);
83
+ break;
84
+ default:
85
+ return $value;
86
+ }
87
+ return sprintf('#%s%s', $value, $value == $label ? '' : ': ' . $label);
88
+ }
89
+
90
+ public function getPublicPaymentInfo(Mage_Payment_Model_Info $payment, $labelValuesOnly = false)
91
+ {
92
+ return $this->_getFullInfo($this->_paymentPublicMap, $payment, $labelValuesOnly);
93
+ }
94
+
95
+ }
app/code/community/Mspl/Payfast/Model/Itn.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Version : 0.1.0
4
+ FILE : Itn.php
5
+ Date : 18-AUG-2010
6
+ Created By : Modulesoft Solution Private Limited (Sudhansu Ranjan Mangaraj)
7
+ Company : Modulesoft.com
8
+ Mail : sudhansumspl@live.com, sudhansu@modulesoft.in, info@modulesoft.in
9
+
10
+ This extension will help you to place your order payment with PayFast:
11
+ @ Payment Service Provider (http://www.payfast.co.za/).
12
+
13
+ Thanks
14
+ Modulesoft.com team
15
+ */
16
+ class Mage_Paypal_Model_Itn
17
+ {
18
+ public function getWriteLog($data){
19
+ $text = "\n";
20
+ $text .= "RESPONSE: From PayFast[".date("Y-m-d H:i:s")."]"."\n";
21
+ foreach($_REQUEST as $key => $val){
22
+ $text .= $key."=>".$val."\n";
23
+ }
24
+ $file = dirname(dirname(__FILE__))."/Logs/notify.txt";
25
+
26
+ $handle = fopen($file, 'a');
27
+ fwrite($handle, $text);
28
+ fclose($handle);
29
+ }
30
+ }
app/code/community/Mspl/Payfast/Model/Source/Server.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Version : 0.1.0
4
+ FILE : Server.php
5
+ Date : 18-AUG-2010
6
+ Created By : Modulesoft Solution Private Limited (Sudhansu Ranjan Mangaraj)
7
+ Company : Modulesoft.com
8
+ Mail : sudhansumspl@live.com, sudhansu@modulesoft.in, info@modulesoft.in
9
+
10
+ This extension will help you to place your order payment with PayFast:
11
+ @ Payment Service Provider (http://www.payfast.co.za/).
12
+
13
+ Thanks
14
+ Modulesoft.com team
15
+ */
16
+ class Mspl_Payfast_Model_Source_Server
17
+ {
18
+ public function toOptionArray()
19
+ {
20
+ return array(
21
+ array('value' => 'test', 'label' => Mage::helper('payfast')->__('Test')),
22
+ array('value' => 'live', 'label' => Mage::helper('payfast')->__('Live')),
23
+ );
24
+ }
25
+ }
app/code/community/Mspl/Payfast/Model/Standard.php ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Version : 0.1.0
4
+ FILE : Standard.php
5
+ Date : 18-AUG-2010
6
+ Created By : Modulesoft Solution Private Limited (Sudhansu Ranjan Mangaraj)
7
+ Company : Modulesoft.com
8
+ Mail : sudhansumspl@live.com, sudhansu@modulesoft.in, info@modulesoft.in
9
+
10
+ This extension will help you to place your order payment with PayFast:
11
+ @ Payment Service Provider (http://www.payfast.co.za/).
12
+
13
+ Thanks
14
+ Modulesoft.com team
15
+ */
16
+ class Mspl_Payfast_Model_Standard extends Mage_Payment_Model_Method_Abstract
17
+ {
18
+ protected $_code = 'payfast';
19
+ protected $_formBlockType = 'payfast/form';
20
+ protected $_infoBlockType = 'payfast/payment_info';
21
+ protected $_order;
22
+
23
+ protected $_isGateway = true;
24
+ protected $_canAuthorize = true;
25
+ protected $_canCapture = true;
26
+ protected $_canCapturePartial = false;
27
+ protected $_canRefund = false;
28
+ protected $_canVoid = true;
29
+ protected $_canUseInternal = true;
30
+ protected $_canUseCheckout = true;
31
+ protected $_canUseForMultishipping = true;
32
+ protected $_canSaveCc = false;
33
+
34
+
35
+ public function getCheckout()
36
+ {
37
+ return Mage::getSingleton('checkout/session');
38
+ }
39
+
40
+ public function getQuote()
41
+ {
42
+ return $this->getCheckout()->getQuote();
43
+ }
44
+
45
+ public function getConfig()
46
+ {
47
+ return Mage::getSingleton('payfast/config');
48
+ }
49
+
50
+ public function getOrderPlaceRedirectUrl()
51
+ {
52
+ return Mage::getUrl('payfast/redirect/redirect', array('_secure' => true));
53
+ }
54
+
55
+ public function getPaidSuccessUrl()
56
+ {
57
+ return Mage::getUrl('payfast/redirect/success', array('_secure' => true));
58
+ }
59
+
60
+ public function getPaidCancelUrl()
61
+ {
62
+ return Mage::getUrl('payfast/redirect/cancel', array('_secure' => true));
63
+ }
64
+
65
+ public function getPaidNotifyUrl()
66
+ {
67
+ return Mage::getUrl('payfast/notify', array('_secure' => true));
68
+ }
69
+
70
+ public function getRealOrderId()
71
+ {
72
+ return Mage::getSingleton('checkout/session')->getLastRealOrderId();
73
+ }
74
+
75
+ public function getNumberFormat($number)
76
+ {
77
+ return number_format($number,2,'.','');
78
+ }
79
+
80
+ public function getTotalAmount($order){
81
+ if ($this->getConfigData('use_store_currency')) {
82
+ $price = $this->getNumberFormat($order->getGrandTotal());
83
+ } else {
84
+ $price = $this->getNumberFormat($order->getBaseGrandTotal());
85
+ }
86
+ return $price;
87
+ }
88
+
89
+ public function getStoreName(){
90
+ $store_info = Mage::app()->getStore();
91
+ return $store_info->getName();
92
+ }
93
+
94
+ public function getStandardCheckoutFormFields()
95
+ {
96
+ $orderIncrementId = $this->getCheckout()->getLastRealOrderId();
97
+ $order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
98
+ $item_desc = '';
99
+ foreach($order->getAllItems() as $items){
100
+ $tot_prc = $this->getNumberFormat($items->getQtyOrdered() * $items->getPrice());
101
+ $item_desc .= $this->getNumberFormat($items->getQtyOrdered()).' x '.$items->getName().' @ '.$order->getOrderCurrencyCode().$this->getNumberFormat($items->getPrice()).' = '.$order->getOrderCurrencyCode().$tot_prc.'; ';
102
+ }
103
+ $item_desc .= 'Shipping = '.$order->getOrderCurrencyCode().$this->getNumberFormat($order->getShippingAmount()).';';
104
+ $item_desc .= 'Total = '.$order->getOrderCurrencyCode().$this->getTotalAmount($order).';';
105
+
106
+ //1 x ITEM 1 @ R2.99ea = R2.99; 2 x ITEM 2 @ R4.99ea = R9.98; Shipping = R10.00; Total = R22.97
107
+
108
+ $pArr = array(
109
+ 'merchant_id' => $this->getConfigData('merchant_id'),
110
+ 'merchant_key' => $this->getConfigData('merchant_key'),
111
+ 'return_url' => $this->getPaidSuccessUrl(),
112
+ 'cancel_url' => $this->getPaidCancelUrl(),
113
+ 'notify_url' => $this->getPaidNotifyUrl(),
114
+ 'currency_code' => $order->getOrderCurrencyCode(),
115
+ 'name_first' => $order->getData('customer_firstname'),
116
+ 'name_last' => $order->getData('customer_lastname'),
117
+ 'email_address' => $order->getData('customer_email'),
118
+ 'm_payment_id' => $this->getRealOrderId(),
119
+ 'amount' => $this->getTotalAmount($order),
120
+ 'item_name' => $this->getStoreName().', Order #'.$this->getRealOrderId(),
121
+ 'item_description' => $item_desc,
122
+ 'email_confirmation'=> '',
123
+ 'signature' => ''
124
+ );
125
+ return $pArr;
126
+ }
127
+
128
+ public function initialize($paymentAction, $stateObject)
129
+ {
130
+ $state = Mage_Sales_Model_Order::STATE_PENDING_PAYMENT;
131
+ $stateObject->setState($state);
132
+ $stateObject->setStatus('pending_payment');
133
+ $stateObject->setIsNotified(false);
134
+ }
135
+
136
+ public function getPayFastUrl()
137
+ {
138
+ switch ($this->getConfigData('server')){
139
+ case 'test':
140
+ $url='https://sandbox.payfast.co.za/eng/process';
141
+ break;
142
+
143
+ case 'live':
144
+ default :
145
+ $url='https://www.payfast.co.za/eng/process';
146
+ break;
147
+ }
148
+ return $url;
149
+ }
150
+
151
+ }
app/code/community/Mspl/Payfast/controllers/NotifyController.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Version : 0.1.0
4
+ FILE : NotifyController.php
5
+ Date : 18-AUG-2010
6
+ Created By : Modulesoft Solution Private Limited (Sudhansu Ranjan Mangaraj)
7
+ Company : Modulesoft.com
8
+ Mail : sudhansumspl@live.com, sudhansu@modulesoft.in, info@modulesoft.in
9
+
10
+ This extension will help you to place your order payment with PayFast:
11
+ @ Payment Service Provider (http://www.payfast.co.za/).
12
+
13
+ Thanks
14
+ Modulesoft.com team
15
+ */
16
+ class Mspl_Payfast_NotifyController extends Mage_Core_Controller_Front_Action
17
+ {
18
+ /**
19
+ ** Instantiate ITN model and pass ITN request to it
20
+ **/
21
+ public function indexAction()
22
+ {
23
+ if (!$this->getRequest()->isPost()) {
24
+ return;
25
+ }
26
+
27
+ $data = $this->getRequest()->getPost();
28
+
29
+ // Load order
30
+ $trnsOrdId = $data['m_payment_id'];
31
+ $order = Mage::getModel('sales/order');
32
+ $order->loadByIncrementId($trnsOrdId);
33
+ $this->_storeID = $order->getStoreId();
34
+
35
+ // Save invoice
36
+ if ($data['payment_status'] == "COMPLETE"){
37
+ $this->saveInvoice($order);
38
+ }
39
+
40
+ $paymentStatus = $data['payment_status'];
41
+ $pf_payment_id = $data['pf_payment_id'];
42
+ $message = Mage::helper('payfast')->__('ITN "%s". ', $paymentStatus);
43
+ $message .= Mage::helper('payfast')->__('PayFast Payment id "%s".', $pf_payment_id);
44
+
45
+ $order->getPayment()->setAdditionalInformation("payment_status", $this->getRequest()->payment_status)
46
+ ->setAdditionalInformation("m_payment_id", $this->getRequest()->m_payment_id)
47
+ ->setAdditionalInformation("pf_payment_id", $this->getRequest()->pf_payment_id)
48
+ ->setAdditionalInformation("email_address", $this->getRequest()->email_address)
49
+ ->setAdditionalInformation("amount_fee", $this->getRequest()->amount_fee)
50
+ ->setAdditionalInformation("signature", $this->getRequest()->signature);
51
+
52
+ $comment = $order->addStatusHistoryComment($message);
53
+ $comment->setIsCustomerNotified(null);
54
+ $comment->save();
55
+
56
+ try {
57
+ if(Mage::getStoreConfig('payment/payfast/debugging')){
58
+ $this->getWriteLog($data);
59
+ }
60
+ } catch (Exception $e) {
61
+ Mage::logException($e);
62
+ }
63
+ }
64
+
65
+ protected function saveInvoice (Mage_Sales_Model_Order $order)
66
+ {
67
+ //check for mail msg
68
+ $invoice = $order->prepareInvoice();
69
+
70
+ $invoice->register()->capture();
71
+ Mage::getModel('core/resource_transaction')
72
+ ->addObject($invoice)
73
+ ->addObject($invoice->getOrder())
74
+ ->save();
75
+ //$invoice->sendEmail();
76
+
77
+ $message = Mage::helper('payfast')->__('Notified customer about invoice #%s.', $invoice->getIncrementId());
78
+ $comment = $order->sendNewOrderEmail()->addStatusHistoryComment($message)
79
+ ->setIsCustomerNotified(true)
80
+ ->save();
81
+ }
82
+
83
+ public function getWriteLog($data){
84
+ $text = "\n";
85
+ $text .= "RESPONSE: From PayFast[".date("Y-m-d H:i:s")."] :: ";
86
+ $text .= serialize($data);
87
+ $file = dirname(dirname(__FILE__))."/Logs/notify.txt";
88
+ $handle = fopen($file, 'a');
89
+ fwrite($handle, $text);
90
+ fclose($handle);
91
+ }
92
+
93
+ }
app/code/community/Mspl/Payfast/controllers/RedirectController.php ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Version : 0.1.0
4
+ FILE : RedirectConroller.php
5
+ Date : 18-AUG-2010
6
+ Created By : Modulesoft Solution Private Limited (Sudhansu Ranjan Mangaraj)
7
+ Company : Modulesoft.com
8
+ Mail : sudhansumspl@live.com, sudhansu@modulesoft.in, info@modulesoft.in
9
+
10
+ This extension will help you to place your order payment with PayFast:
11
+ @ Payment Service Provider (http://www.payfast.co.za/).
12
+
13
+ Thanks
14
+ Modulesoft.com team
15
+ */
16
+ class Mspl_Payfast_RedirectController extends Mage_Core_Controller_Front_Action
17
+ {
18
+ protected $_order;
19
+ protected $_WHAT_STATUS = false;
20
+
21
+ public function getOrder()
22
+ {
23
+ if ($this->_order == null) {
24
+ }
25
+ return $this->_order;
26
+ }
27
+
28
+ protected function _expireAjax()
29
+ {
30
+ if (!Mage::getSingleton('checkout/session')->getQuote()->hasItems()) {
31
+ $this->getResponse()->setHeader('HTTP/1.1','403 Session Expired');
32
+ exit;
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Get singleton of Checkout Session Model
38
+ *
39
+ * @return Mage_Checkout_Model_Session
40
+ */
41
+ protected function _getCheckout()
42
+ {
43
+ return Mage::getSingleton('checkout/session');
44
+ }
45
+
46
+ public function getQuote()
47
+ {
48
+ return $this->getCheckout()->getQuote();
49
+ }
50
+
51
+ public function getStandard()
52
+ {
53
+ return Mage::getSingleton('payfast/standard');
54
+ }
55
+
56
+ public function getConfig()
57
+ {
58
+ return $this->getStandard()->getConfig();
59
+ }
60
+
61
+ protected function _getPendingPaymentStatus()
62
+ {
63
+ return Mage::helper('payfast')->getPendingPaymentStatus();
64
+ }
65
+
66
+ public function redirectAction()
67
+ {
68
+ /*
69
+ $session = Mage::getSingleton('checkout/session');
70
+ $this->getResponse()->setBody($this->getLayout()->createBlock('payfast/request')->toHtml());
71
+ $session->unsQuoteId();
72
+ */
73
+
74
+ try {
75
+ $session = Mage::getSingleton('checkout/session');
76
+
77
+ $order = Mage::getModel('sales/order');
78
+ $order->loadByIncrementId($session->getLastRealOrderId());
79
+ if (!$order->getId()) {
80
+ Mage::throwException('No order for processing found');
81
+ }
82
+ if ($order->getState() != Mage_Sales_Model_Order::STATE_PENDING_PAYMENT) {
83
+ $order->setState(
84
+ Mage_Sales_Model_Order::STATE_PENDING_PAYMENT,
85
+ $this->_getPendingPaymentStatus(),
86
+ Mage::helper('payfast')->__('Customer was redirected to PayFast.')
87
+ )->save();
88
+ }
89
+
90
+ if ($session->getQuoteId() && $session->getLastSuccessQuoteId()) {
91
+ $session->setPayfastQuoteId($session->getQuoteId());
92
+ $session->setPayfastSuccessQuoteId($session->getLastSuccessQuoteId());
93
+ $session->setPayfastRealOrderId($session->getLastRealOrderId());
94
+ $session->getQuote()->setIsActive(false)->save();
95
+ $session->clear();
96
+ }
97
+
98
+ $this->getResponse()->setBody($this->getLayout()->createBlock('payfast/request')->toHtml());
99
+ $session->unsQuoteId();
100
+ return;
101
+ } catch (Mage_Core_Exception $e) {
102
+ $this->_getCheckout()->addError($e->getMessage());
103
+ } catch(Exception $e) {
104
+ Mage::logException($e);
105
+ }
106
+ $this->_redirect('checkout/cart');
107
+ }
108
+
109
+ public function cancelAction()
110
+ {
111
+ $session = Mage::getSingleton('checkout/session');
112
+ $session->setQuoteId($session->getPayfastQuoteId(true));
113
+ $session = $this->_getCheckout();
114
+ if ($quoteId = $session->getPayfastQuoteId()) {
115
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
116
+ if ($quote->getId()) {
117
+ $quote->setIsActive(true)->save();
118
+ $session->setQuoteId($quoteId);
119
+ }
120
+ }
121
+
122
+ $order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId());
123
+ if ($this->getRequest()->pt != '') {
124
+ $history = Mage::helper('payfast')->__('Order '.$session->getLastRealOrderId().' was canceled by customer. PT:#'.$this->getRequest()->pt.'. ');
125
+ }
126
+ $history .= Mage::helper('payfast')->__('Customer was returned from Payfast.');
127
+ $order->addStatusToHistory($order->getStatus(), $history);
128
+
129
+ if ($order->getId()) {
130
+ $order->cancel()->save();
131
+ }
132
+
133
+ /*
134
+ Cancel the order
135
+ */
136
+ /*if ($session->getLastRealOrderId()) {
137
+ $order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId());
138
+ if ($this->responseArr['pt'] != '') {
139
+ $history = Mage::helper('payfast')->__('Order '.$order->getId().' was canceled by customer. ID:#'.$this->responseArr['pt']);
140
+ }
141
+ $history = Mage::helper('payfast')->__('Customer was returned from Payfast.');
142
+ $order->addStatusToHistory($order->getStatus(), $history);
143
+
144
+ if ($order->getId()) {
145
+ $order->cancel()->save();
146
+ }$session->getData('steps/login/allow')
147
+ }*/
148
+
149
+ $customer_session = Mage::getSingleton('customer/session');
150
+ if($customer_session->getData('id') != ''){
151
+ $this->_redirect('sales/order/view/order_id/'.$order->getId());
152
+ }else{
153
+ $this->_redirect('checkout/cart');
154
+ }
155
+ }
156
+
157
+ public function successAction()
158
+ {
159
+ try {
160
+ $session = Mage::getSingleton('checkout/session');;
161
+ $session->unsPayfastRealOrderId();
162
+ $session->setQuoteId($session->getPayfastQuoteId(true));
163
+ $session->setLastSuccessQuoteId($session->getPayfastSuccessQuoteId(true));
164
+ $this->_redirect('checkout/onepage/success', array('_secure'=>true));
165
+ return;
166
+ } catch (Mage_Core_Exception $e) {
167
+ $this->_getCheckout()->addError($e->getMessage());
168
+ } catch(Exception $e) {
169
+ Mage::logException($e);
170
+ }
171
+ $this->_redirect('checkout/cart');
172
+ }
173
+
174
+ }
app/code/community/Mspl/Payfast/etc/config.xml ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ Version : 0.1.0
4
+ FILE : config.xml
5
+ Date : 18-AUG-2010
6
+ Created By : Modulesoft Solution Private Limited (Sudhansu Ranjan Mangaraj)
7
+ Company : Modulesoft.com
8
+ Mail : sudhansumspl@live.com, sudhansu@modulesoft.in, info@modulesoft.in
9
+
10
+ This extension will help you to place your order payment with PayFast:
11
+ @ Payment Service Provider (http://www.payfast.co.za/).
12
+
13
+ Thanks
14
+ Modulesoft.com team
15
+ -->
16
+ <config>
17
+ <modules>
18
+ <Mspl_Payfast>
19
+ <version>0.1.0</version>
20
+ </Mspl_Payfast>
21
+ </modules>
22
+ <global>
23
+ <blocks>
24
+ <payfast>
25
+ <class>Mspl_Payfast_Block</class>
26
+ </payfast>
27
+ </blocks>
28
+ <helpers>
29
+ <payfast>
30
+ <class>Mspl_Payfast_Helper</class>
31
+ </payfast>
32
+ </helpers>
33
+ <models>
34
+ <payfast>
35
+ <class>Mspl_Payfast_Model</class>
36
+ </payfast>
37
+ </models>
38
+ <resources>
39
+ <payfast_setup>
40
+ <setup>
41
+ <module>Mspl_Payfast</module>
42
+ </setup>
43
+ <connection>
44
+ <use>core_setup</use>
45
+ </connection>
46
+ </payfast_setup>
47
+ <newmodule_write>
48
+ <connection>
49
+ <use>core_write</use>
50
+ </connection>
51
+ </newmodule_write>
52
+ <newmodule_read>
53
+ <connection>
54
+ <use>core_read</use>
55
+ </connection>
56
+ </newmodule_read>
57
+ </resources>
58
+ </global>
59
+
60
+ <frontend>
61
+ <routers>
62
+ <payfast>
63
+ <use>standard</use>
64
+ <args>
65
+ <module>Mspl_Payfast</module>
66
+ <frontName>payfast</frontName>
67
+ </args>
68
+ </payfast>
69
+ </routers>
70
+ </frontend>
71
+
72
+ <default>
73
+ <payment>
74
+ <payfast>
75
+ <model>payfast/standard</model>
76
+ <active>0</active>
77
+ <title><![CDATA[PayFast's Standard Website Payment]]></title>
78
+ <server>test</server>
79
+ <debugging>0</debugging>
80
+ </payfast>
81
+ </payment>
82
+ </default>
83
+ </config>
app/code/community/Mspl/Payfast/etc/system.xml ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ Version : 0.1.0
4
+ FILE : system.xml
5
+ Date : 18-AUG-2010
6
+ Created By : Modulesoft Solution Private Limited (Sudhansu Ranjan Mangaraj)
7
+ Company : Modulesoft.com
8
+ Mail : sudhansumspl@live.com, sudhansu@modulesoft.in, info@modulesoft.in
9
+
10
+ This extension will help you to place your order payment with PayFast:
11
+ @ Payment Service Provider (http://www.payfast.co.za/).
12
+
13
+ Thanks
14
+ Modulesoft.com team
15
+ -->
16
+ <config>
17
+ <sections>
18
+ <payment>
19
+ <groups>
20
+ <payfast translate="label" module="payfast">
21
+ <label><![CDATA[PayFast's Standard HTML integrations]]></label>
22
+ <sort_order>100</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>0</show_in_store>
26
+ <fields>
27
+ <active translate="label">
28
+ <label>Enabled</label>
29
+ <frontend_type>select</frontend_type>
30
+ <source_model>adminhtml/system_config_source_yesno</source_model>
31
+ <sort_order>1</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>1</show_in_website>
34
+ <show_in_store>0</show_in_store>
35
+ </active>
36
+
37
+ <title translate="label">
38
+ <label>Title</label>
39
+ <frontend_type>text</frontend_type>
40
+ <sort_order>2</sort_order>
41
+ <show_in_default>1</show_in_default>
42
+ <show_in_website>1</show_in_website>
43
+ <show_in_store>0</show_in_store>
44
+ </title>
45
+
46
+ <merchant_id translate="label">
47
+ <label>Merchant ID</label>
48
+ <frontend_type>text</frontend_type>
49
+ <sort_order>3</sort_order>
50
+ <show_in_default>1</show_in_default>
51
+ <show_in_website>1</show_in_website>
52
+ <show_in_store>0</show_in_store>
53
+ </merchant_id>
54
+
55
+ <merchant_key translate="label">
56
+ <label>Merchant Key</label>
57
+ <frontend_type>text</frontend_type>
58
+ <sort_order>4</sort_order>
59
+ <show_in_default>1</show_in_default>
60
+ <show_in_website>1</show_in_website>
61
+ <show_in_store>0</show_in_store>
62
+ </merchant_key>
63
+
64
+ <server translate="label">
65
+ <label>Server</label>
66
+ <frontend_type>select</frontend_type>
67
+ <source_model>payfast/source_server</source_model>
68
+ <sort_order>5</sort_order>
69
+ <show_in_default>1</show_in_default>
70
+ <show_in_website>1</show_in_website>
71
+ <show_in_store>0</show_in_store>
72
+ </server>
73
+
74
+ <debugging translate="label">
75
+ <label>Debugging</label>
76
+ <frontend_type>select</frontend_type>
77
+ <source_model>adminhtml/system_config_source_yesno</source_model>
78
+ <sort_order>6</sort_order>
79
+ <show_in_default>1</show_in_default>
80
+ <show_in_website>1</show_in_website>
81
+ <show_in_store>0</show_in_store>
82
+ </debugging>
83
+
84
+ <debugging_email translate="label">
85
+ <label>Debugging Email</label>
86
+ <frontend_type>select</frontend_type>
87
+ <source_model>adminhtml/system_config_source_yesno</source_model>
88
+ <sort_order>7</sort_order>
89
+ <show_in_default>1</show_in_default>
90
+ <show_in_website>1</show_in_website>
91
+ <show_in_store>0</show_in_store>
92
+ </debugging_email>
93
+
94
+ </fields>
95
+ </payfast>
96
+ </groups>
97
+ </payment>
98
+ </sections>
99
+ </config>
app/etc/modules/Mspl_Payfast.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ Version : 0.1.0
4
+ FILE : Mspl_Payfast.xml
5
+ Date : 18-AUG-2010
6
+ Created By : Modulesoft Solution Private Limited (Sudhansu Ranjan Mangaraj)
7
+ Company : Modulesoft.com
8
+ Mail : sudhansumspl@live.com, sudhansu@modulesoft.in, info@modulesoft.in
9
+
10
+ This extension will help you to place your order payment with PayFast:
11
+ @ Payment Service Provider (http://www.payfast.co.za/).
12
+
13
+ Thanks
14
+ Modulesoft.com team
15
+ -->
16
+ <config>
17
+ <modules>
18
+ <Mspl_Payfast>
19
+ <active>true</active>
20
+ <codePool>community</codePool>
21
+ </Mspl_Payfast>
22
+ </modules>
23
+ </config>
package.xml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Payfast_Payment_Gateway_by_Modulesoft</name>
4
+ <version>0.1.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>This extension will help you to make payments with payfast (http://www.payfast.co.za/).</summary>
10
+ <description>PayFast is a payments processing service for South Africa. We make it safe for buyers to send money and easy for sellers to receive money.
11
+
12
+ PayFast is a payments collection service for South Africans and South African websites.
13
+
14
+ This extension was developed by Modulesoft Solution Pvt. Ltd.
15
+
16
+ Thanks
17
+ MSPL team</description>
18
+ <notes>Please note that this extension is provided as is. It is highly recommended to always backup your installation prior to usage.</notes>
19
+ <authors><author><name>Modulesoft Solutions Private Limited</name><user>auto-converted</user><email>info@modulesoft.in</email></author><author><name>Sudhansu Ranjan Mangaraj</name><user>auto-converted</user><email>sudhansumspl@live.com</email></author><author><name>Modulesoft.com (Sudhansu Ranjan Mangaraj)</name><user>auto-converted</user><email>sudhansumspl@live.com</email></author><author><name>Modulesoft.com (Sudhansu Ranjan Mangaraj)</name><user>auto-converted</user><email>sudhansumspl@live.com</email></author></authors>
20
+ <date>2010-09-14</date>
21
+ <time>12:32:15</time>
22
+ <contents><target name="mageetc"><dir name="modules"><file name="Mspl_Payfast.xml" hash="cb20b7f59ca123846d5492907f044ae7"/></dir></target><target name="magecommunity"><dir name="Mspl"><dir name="Payfast"><dir name="Block"><dir name="Payment"><file name="Info.php" hash="be987baa0adfadb3bbc2e7cad2ac55bc"/></dir><file name="Form.php" hash="0272d54c5a52b9e1ad892665f9019fb6"/><file name="Request.php" hash="e1c2c940a3f5712c9b1b8eff19f211e4"/></dir><dir name="controllers"><file name="NotifyController.php" hash="ca3de3754350c0ec9d94d43603ca3343"/><file name="RedirectController.php" hash="631cdca18d8844e34b3d8cf4e6dfbae6"/></dir><dir name="etc"><file name="config.xml" hash="dd50a1c3f447ec6262ebdc4e9298ca45"/><file name="system.xml" hash="ad4ab9cf72f5583ae81f7e50d8a0e5c8"/></dir><dir name="Helper"><file name="Data.php" hash="24cbd65161defa890b224f7788aa83f7"/></dir><dir name="Logs"><file name="notify.txt" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir><dir name="Model"><dir name="Source"><file name="Server.php" hash="7fd495828565a943478e661f2b624ada"/></dir><file name="Info.php" hash="04ece5efbc7c9a69622b6e226469ba09"/><file name="Itn.php" hash="21507b1b3f52451286545fb6e07116f4"/><file name="Standard.php" hash="a4a1a4567a80791e64161569db8e9fd8"/></dir></dir></dir></target></contents>
23
+ <compatible/>
24
+ <dependencies/>
25
+ </package>