Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,48 @@
# mod-magento_2

PayFast Magento Module v2.4.0 for Magento 2.4.4+ on PHP 8.1
Payfast Magento Module v2.4.0 for Magento 2.4.4+ on PHP 8.1
-----------------------------------------------------------------------------
Copyright (c) 2023 Payfast (Pty) Ltd
You (being anyone who is not Payfast (Pty) Ltd) may download and use this plugin / code in your own website in conjunction with a registered and active Payfast account. If your Payfast account is terminated for any reason, you may not use this plugin / code or part thereof.
Except as expressly indicated in this licence, you may not use, copy, modify or distribute this plugin / code or part thereof in any way.
You (being anyone who is not Payfast (Pty) Ltd) may download and use this plugin / code in your own website in
conjunction with a registered and active Payfast account. If your Payfast account is terminated for any reason, you may
not use this plugin / code or part thereof.
Except as expressly indicated in this licence, you may not use, copy, modify or distribute this plugin / code or part
thereof in any way.

In order to use Payfast with Magento 2, you will need a working Magento installation. To install Payfast follow the below instructions:
In order to use Payfast with Magento 2, you will need a working Magento installation. To install Payfast follow the
below instructions:

1. Setup ZAR on your Magento site.
In the admin panel navigate to 'Stores', and add ZAR under currency Symbols and Rates.
2. Copy the PayFast app folder to your root Magento folder.
This will not override any files on your system.
In the admin panel navigate to 'Stores', and add ZAR under currency Symbols and Rates.
2. Copy the Payfast app folder to your root Magento folder.
This will not override any files on your system.
3. You will now need to run the following commands in the given order:

3.1 php ./bin/magento module:enable PayFast_Payfast
3.1 php ./bin/magento module:enable Payfast_Payfast

3.2 php ./bin/magento setup:di:compile
3.2 php ./bin/magento setup:di:compile

3.3 php ./bin/magento setup:static-content:deploy
3.3 php ./bin/magento setup:static-content:deploy

3.4 php ./bin/magento cache:clean
3.4 php ./bin/magento cache:clean

4. Log into the admin panel and navigate to 'Stores'>'Configuration'>'Sales'>'Payment Method' and click on Payfast
5. Enable the module, as well as debugging. To test in sandbox insert 'test' in the 'server' field and use the following credentials:
5. Enable the module, as well as debugging. To test in sandbox insert 'test' in the 'server' field and use the following
credentials:

Merchant ID: 10000100
Merchant ID: 10000100

Merchant Key: 46f0cd694581a
Merchant Key: 46f0cd694581a

Leave the passphrase blank and setup the other options as required.
Leave the passphrase blank and setup the other options as required.

##NB: configure sending of emails by default magento source code does not allow sending of emails when a payment module does a redirect.
##NB: configure sending of emails by default magento source code does not allow sending of emails when a payment
module does a redirect.

6. Click 'Save Config', you are now ready to test in sandbox, click 'Save Config'.

7. Once you are ready to go live, insert 'live' into the 'server' field and input your Payfast credentials. Set debug log to 'No', and the other options as required.
7. Once you are ready to go live, insert 'live' into the 'server' field and input your Payfast credentials. Set debug
log to 'No', and the other options as required.
8. Click 'Save Config', you are now ready to process live transactions via Payfast.

Please [click here](https://payfast.io/integration/shopping-carts/magento/) for more information concerning this module.
37 changes: 19 additions & 18 deletions app/code/Payfast/Payfast/Block/Form.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php
/**
* Copyright (c) 2008 PayFast (Pty) Ltd
* You (being anyone who is not PayFast (Pty) Ltd) may download and use this plugin / code in your own website in conjunction with a registered and active PayFast account. If your PayFast account is terminated for any reason, you may not use this plugin / code or part thereof.
* Copyright (c) 2023 Payfast (Pty) Ltd
* You (being anyone who is not Payfast (Pty) Ltd) may download and use this plugin / code in your own website in conjunction with a registered and active Payfast account. If your Payfast account is terminated for any reason, you may not use this plugin / code or part thereof.
* Except as expressly indicated in this licence, you may not use, copy, modify or distribute this plugin / code or part thereof in any way.
*/

namespace Payfast\Payfast\Block;

use Magento\Customer\Helper\Session\CurrentCustomer;
Expand Down Expand Up @@ -51,12 +52,12 @@ class Form extends \Magento\Payment\Block\Form
protected $currentCustomer;

/**
* @param Context $context
* @param Context $context
* @param \Payfast\Payfast\Model\ConfigFactory $payfastConfigFactory
* @param ResolverInterface $localeResolver
* @param Data $payfastData
* @param CurrentCustomer $currentCustomer
* @param array $data
* @param ResolverInterface $localeResolver
* @param Data $payfastData
* @param CurrentCustomer $currentCustomer
* @param array $data
*/
public function __construct(
Context $context,
Expand All @@ -66,8 +67,8 @@ public function __construct(
CurrentCustomer $currentCustomer,
array $data = []
) {
$pre = __METHOD__ . " : ";
$this->_payfastData = $payfastData;
$pre = __METHOD__ . " : ";
$this->_payfastData = $payfastData;
$this->payfastConfigFactory = $payfastConfigFactory;
parent::__construct($context, $data);
$this->_logger->debug($pre . 'bof');
Expand All @@ -79,27 +80,27 @@ public function __construct(
}

/**
* Set template and redirect message
* Payment method code getter
*
* @return void
* @return string 'payfast'
*/
protected function _construct()
public function getMethodCode()
{
$pre = __METHOD__ . " : ";
$this->_logger->debug($pre . 'bof');
$this->_config = $this->payfastConfigFactory->create()->setMethod($this->getMethodCode());

return $this->_methodCode;
}

/**
* Payment method code getter
* Set template and redirect message
*
* @return string 'payfast'
* @return void
*/
public function getMethodCode()
protected function _construct()
{
$pre = __METHOD__ . " : ";
$this->_logger->debug($pre . 'bof');

return $this->_methodCode;
$this->_config = $this->payfastConfigFactory->create()->setMethod($this->getMethodCode());
}
}
6 changes: 4 additions & 2 deletions app/code/Payfast/Payfast/Block/Info.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php namespace Payfast\Payfast\Block;
<?php
namespace Payfast\Payfast\Block;

use Magento\Framework\Phrase;
use Magento\Payment\Block\ConfigurableInfo;
Expand All @@ -8,7 +9,8 @@ class Info extends ConfigurableInfo
/**
* Returns label
*
* @param string $field
* @param string $field
*
* @return Phrase
*/
protected function getLabel($field): Phrase
Expand Down
11 changes: 6 additions & 5 deletions app/code/Payfast/Payfast/Block/Payment/Info.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?php
/**
* Copyright (c) 2008 PayFast (Pty) Ltd
* You (being anyone who is not PayFast (Pty) Ltd) may download and use this plugin / code in your own website in conjunction with a registered and active PayFast account. If your PayFast account is terminated for any reason, you may not use this plugin / code or part thereof.
* Copyright (c) 2023 Payfast (Pty) Ltd
* You (being anyone who is not Payfast (Pty) Ltd) may download and use this plugin / code in your own website in conjunction with a registered and active Payfast account. If your Payfast account is terminated for any reason, you may not use this plugin / code or part thereof.
* Except as expressly indicated in this licence, you may not use, copy, modify or distribute this plugin / code or part thereof in any way.
*/

namespace Payfast\Payfast\Block\Payment;

use Magento\Framework\View\Element\Template\Context;
use Payfast\Payfast\Model\InfoFactory;

/**
* PayFast common payment info block
* Payfast common payment info block
* Uses default templates
*/
class Info extends \Magento\Payment\Block\Info
Expand All @@ -21,9 +22,9 @@ class Info extends \Magento\Payment\Block\Info
protected $_payfastInfoFactory;

/**
* @param Context $context
* @param Context $context
* @param InfoFactory $payfastInfoFactory
* @param array $data
* @param array $data
*/
public function __construct(
Context $context,
Expand Down
44 changes: 23 additions & 21 deletions app/code/Payfast/Payfast/Block/Payment/Request.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright (c) 2008 PayFast (Pty) Ltd
* You (being anyone who is not PayFast (Pty) Ltd) may download and use this plugin / code in your own website in conjunction with a registered and active PayFast account. If your PayFast account is terminated for any reason, you may not use this plugin / code or part thereof.
* Copyright (c) 2023 Payfast (Pty) Ltd
* You (being anyone who is not Payfast (Pty) Ltd) may download and use this plugin / code in your own website in conjunction with a registered and active Payfast account. If your Payfast account is terminated for any reason, you may not use this plugin / code or part thereof.
* Except as expressly indicated in this licence, you may not use, copy, modify or distribute this plugin / code or part thereof in any way.
*/

Expand Down Expand Up @@ -35,7 +35,7 @@ class Request extends Template
protected $_checkoutSession;

/**
* @var ReadFactory $readFactory
* @var ReadFactory $readFactory
*/
protected $readFactory;

Expand All @@ -45,14 +45,14 @@ class Request extends Template
protected $reader;

/**
* @param Context $context
* @param Context $context
* @param OrderFactory $orderFactory
* @param Session $checkoutSession
* @param Data $pfHelper
* @param ReadFactory $readFactory
* @param Reader $reader
* @param Payfast $paymentMethod
* @param array $data
* @param Session $checkoutSession
* @param Data $pfHelper
* @param ReadFactory $readFactory
* @param Reader $reader
* @param Payfast $paymentMethod
* @param array $data
*/
public function __construct(
Context $context,
Expand All @@ -64,25 +64,27 @@ public function __construct(
Payfast $paymentMethod,
array $data = []
) {
$this->_hssHelper = $pfHelper;
$this->_orderFactory = $orderFactory;
$this->_hssHelper = $pfHelper;
$this->_orderFactory = $orderFactory;
$this->_checkoutSession = $checkoutSession;
parent::__construct($context, $data);
$this->_isScopePrivate = true;
$this->readFactory = $readFactory;
$this->reader = $reader;
$this->_paymentMethod = $paymentMethod;
$this->readFactory = $readFactory;
$this->reader = $reader;
$this->_paymentMethod = $paymentMethod;
}

public function _prepareLayout()
{
$this->setMessage('Redirecting to Payfast')
->setId('payfast_checkout')
->setName('payfast_checkout')
->setFormMethod('POST')
->setFormAction($this->_paymentMethod->getPayFastUrl())
->setFormData($this->_paymentMethod->getStandardCheckoutFormFields())
->setSubmitForm('<script type="text/javascript">document.getElementById( "payfast_checkout" ).submit();</script>');
->setId('payfast_checkout')
->setName('payfast_checkout')
->setFormMethod('POST')
->setFormAction($this->_paymentMethod->getPayfastUrl())
->setFormData($this->_paymentMethod->getStandardCheckoutFormFields())
->setSubmitForm(
'<script type="text/javascript">document.getElementById( "payfast_checkout" ).submit();</script>'
);

return parent::_prepareLayout(); // TODO: Change the autogenerated stub
}
Expand Down
Loading