Skip to content

Commit

Permalink
Transaction Type Verification
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyraul committed Nov 15, 2017
1 parent 56f27b7 commit 0ab036a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
46 changes: 46 additions & 0 deletions Model/Payment/Transaction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* @author Mygento
* @copyright See COPYING.txt for license details.
* @package Mygento_Base
*/

namespace Mygento\Base\Model\Payment;

use Magento\Framework\Exception\LocalizedException;

class Transaction extends \Magento\Sales\Model\Order\Payment\Transaction
{
const TYPE_FISCAL = 'fiscal_receipt';
const TYPE_FISCAL_REFUND = 'fiscal_receipt_refund';

/**
* Check whether specified or set transaction type is supported
*
* @param string $txnType
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function _verifyTxnType($txnType = null)
{
if (null === $txnType) {
$txnType = $this->getTxnType();
}
switch ($txnType) {
case self::TYPE_PAYMENT:
case self::TYPE_ORDER:
case self::TYPE_AUTH:
case self::TYPE_CAPTURE:
case self::TYPE_VOID:
case self::TYPE_REFUND:
case self::TYPE_FISCAL:
case self::TYPE_FISCAL_REFUND:
break;
default:
throw new LocalizedException(
__('We found an unsupported transaction type "%1".', $txnType)
);
}
}
}
4 changes: 2 additions & 2 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* @package Mygento_Base
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Sales\Model\Order\Payment\Transaction">
<plugin name="mygento_base_transaction_receipt" type="Mygento\Base\Plugin\Transaction"/>
</type>
<preference for="Magento\Sales\Model\Order\Payment\Transaction" type="Mygento\Base\Model\Payment\Transaction" />
</config>

0 comments on commit 0ab036a

Please sign in to comment.