Skip to content

Commit

Permalink
1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zlatinov committed Jun 20, 2017
1 parent 8420c9a commit 29b9330
Show file tree
Hide file tree
Showing 106 changed files with 5,886 additions and 8,318 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Requirements
------------

* Magento Community Edition > 1.7 (Tested up to: __1.9.3.1__)
* [GenesisPHP v1.4.2](https://github.com/GenesisGateway/genesis_php) - (Integrated in Module)
* [GenesisPHP v1.7.0](https://github.com/GenesisGateway/genesis_php) - (Integrated in Module)
* PCI-certified server in order to use ```eMerchantPay Direct```

*Note:* This module has been tested only with Magento __Community Edition__, it may not work
Expand Down Expand Up @@ -81,25 +81,36 @@ Supported Transactions
* __Authorize__
* __Authorize (3D-Secure)__
* __CashU__
* __Citadel Payin__
* __eZeeWallet__
* __iDebit Payin__
* __INPay__
* __InstaDebit Payin__
* __InitRecurringSale__
* __InitRecurringSale (3D-Secure)__
* __Neteller__
* __P24__
* __PayPal Express__
* __PaySafeCard__
* __PayByVoucher (Sale)__
* __PayByVoucher (oBeP)__
* __POLi__
* __PPRO__
* __eps__
* __GiroPay__
* __Qiwi__
* __Mr.Cash__
* __MyBank__
* __Przelewy24__
* __Qiwi__
* __SafetyPay__
* __TeleIngreso__
* __TrustPay__
* __RecurringSale__
* __Sale__
* __Sale (3D-Secure)__
* __SDD Sale__
* __SOFORT__
* __Trustly Sale__
* __WebMoney__

_Note_: If you have trouble with your credentials or terminal configuration, get in touch with our [support] team
Expand Down
96 changes: 94 additions & 2 deletions app/code/community/EMerchantPay/Genesis/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,15 @@ public function getRedirectUrl($model)
* and salted to avoid duplication
*
* @param string $prefix Prefix of the orderId
* @param int $length Length of the generated string
*
* @return string
*/
public function genTransactionId($prefix = '')
public function genTransactionId($prefix = '', $length = 30)
{
$hash = Mage::helper('core')->uniqHash();

return (string)$prefix . substr($hash, -(strlen($hash) - strlen($prefix)));
return substr($prefix . substr($hash, -(strlen($hash) - strlen($prefix))), 0, $length);
}

/**
Expand Down Expand Up @@ -903,4 +904,95 @@ public function getReconciledFailureActionMessage($default = '')

return $default;
}

/**
* Retrieves the consumer's user id
*
* @return int
*/
public static function getCurrentUserId()
{
/** @var Mage_Customer_Helper_Data $helper */
$helper = Mage::helper('customer');
if ($helper->isLoggedIn()) {
return $helper->getCurrentCustomer()->getId();
}
return 0;
}

/**
* @param int $length
* @return string
*/
public static function getCurrentUserIdHash($length = 30)
{
$userId = self::getCurrentUserId();

$userHash = $userId > 0 ? sha1($userId) : self::genTransactionId();

return substr($userHash, 0, $length);
}

/**
* @param Varien_Object|Mage_Sales_Model_Order_Payment $payment
*
* @return bool
*/
public function getIsRefundable(Varien_Object $payment)
{
$refundableGatewayTransactionTypes = array(
\Genesis\API\Constants\Transaction\Types::SALE,
\Genesis\API\Constants\Transaction\Types::SALE_3D,
\Genesis\API\Constants\Transaction\Types::INIT_RECURRING_SALE,
\Genesis\API\Constants\Transaction\Types::INIT_RECURRING_SALE_3D,
\Genesis\API\Constants\Transaction\Types::CASHU,
\Genesis\API\Constants\Transaction\Types::PPRO,
\Genesis\API\Constants\Transaction\Types::INPAY,
\Genesis\API\Constants\Transaction\Types::P24,
\Genesis\API\Constants\Transaction\Types::PAYPAL_EXPRESS,
\Genesis\API\Constants\Transaction\Types::TRUSTLY_SALE
);

return in_array(
$this->getGenesisPaymentTransactionType($payment),
$refundableGatewayTransactionTypes
);
}

/**
* Looks for the capture transaction, checks if it supports refunds and returns it.
* Adds to Mage::log, if capture transaction is not found or is not refundable.
*
* @param Varien_Object|Mage_Sales_Model_Order_Payment $payment
* @return Mage_Sales_Model_Order_Payment_Transaction|null
*/
public function getCaptureForRefund(Varien_Object $payment) {
$capture = $payment->lookupTransaction(
null,
Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE
);

/* Refund Transaction is only possible, when Capture Transaction Exists */
if ($capture === false) {
Mage::log(
'Refund transaction for order #' .
$payment->getOrder()->getIncrementId() .
' could not be completed! (No Capture Transaction Exists)'
);

return null;
}

if (!$this->getIsRefundable($capture)) {
Mage::log(
'Refund transaction for order #' .
$payment->getOrder()->getIncrementId() .
' could not be completed! (This transaction type does\'t support refund)'
);

return null;
}

return $capture;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,45 +65,67 @@ public function toOptionArray()
protected function getTransactionTypes()
{
return array(
\Genesis\API\Constants\Transaction\Types::ABNIDEAL =>
\Genesis\API\Constants\Transaction\Types::ABNIDEAL =>
Mage::helper('emerchantpay')->__('ABN iDEAL'),
\Genesis\API\Constants\Transaction\Types::AUTHORIZE =>
\Genesis\API\Constants\Transaction\Types::AUTHORIZE =>
Mage::helper('emerchantpay')->__('Authorize'),
\Genesis\API\Constants\Transaction\Types::AUTHORIZE_3D =>
\Genesis\API\Constants\Transaction\Types::AUTHORIZE_3D =>
Mage::helper('emerchantpay')->__('Authorize (3D-Secure)'),
\Genesis\API\Constants\Transaction\Types::CASHU =>
\Genesis\API\Constants\Transaction\Types::CASHU =>
Mage::helper('emerchantpay')->__('CashU'),
\Genesis\API\Constants\Payment\Methods::EPS =>
\Genesis\API\Constants\Transaction\Types::CITADEL_PAYIN =>
Mage::helper('emerchantpay')->__('Citadel'),
\Genesis\API\Constants\Payment\Methods::EPS =>
Mage::helper('emerchantpay')->__('eps'),
\Genesis\API\Constants\Payment\Methods::GIRO_PAY =>
\Genesis\API\Constants\Transaction\Types::EZEEWALLET =>
Mage::helper('emerchantpay')->__('eZeeWallet'),
\Genesis\API\Constants\Payment\Methods::GIRO_PAY =>
Mage::helper('emerchantpay')->__('GiroPay'),
\Genesis\API\Constants\Transaction\Types::NETELLER =>
\Genesis\API\Constants\Transaction\Types::IDEBIT_PAYIN =>
Mage::helper('emerchantpay')->__('iDebit'),
\Genesis\API\Constants\Transaction\Types::INPAY =>
Mage::helper('emerchantpay')->__('INPay'),
\Genesis\API\Constants\Transaction\Types::INSTA_DEBIT_PAYIN =>
Mage::helper('emerchantpay')->__('InstaDebit'),
\Genesis\API\Constants\Payment\Methods::BCMC =>
Mage::helper('emerchantpay')->__('Mr.Cash'),
\Genesis\API\Constants\Payment\Methods::MYBANK =>
Mage::helper('emerchantpay')->__('MyBank'),
\Genesis\API\Constants\Transaction\Types::NETELLER =>
Mage::helper('emerchantpay')->__('Neteller'),
\Genesis\API\Constants\Payment\Methods::QIWI =>
Mage::helper('emerchantpay')->__('Qiwi'),
\Genesis\API\Constants\Transaction\Types::PAYSAFECARD =>
\Genesis\API\Constants\Transaction\Types::P24 =>
Mage::helper('emerchantpay')->__('P24'),
\Genesis\API\Constants\Transaction\Types::PAYSAFECARD =>
Mage::helper('emerchantpay')->__('PaySafeCard'),
\Genesis\API\Constants\Transaction\Types::PAYBYVOUCHER_SALE =>
\Genesis\API\Constants\Transaction\Types::PAYBYVOUCHER_SALE =>
Mage::helper('emerchantpay')->__('PayByVoucher (Sale)'),
\Genesis\API\Constants\Transaction\Types::PAYBYVOUCHER_YEEPAY =>
Mage::helper('emerchantpay')->__('PayByVoucher (oBeP)'),
\Genesis\API\Constants\Payment\Methods::PRZELEWY24 =>
Mage::helper('emerchantpay')->__('Przelewy24'),
\Genesis\API\Constants\Transaction\Types::POLI =>
\Genesis\API\Constants\Transaction\Types::PAYPAL_EXPRESS =>
Mage::helper('emerchantpay')->__('PayPal Express'),
\Genesis\API\Constants\Transaction\Types::POLI =>
Mage::helper('emerchantpay')->__('POLi'),
\Genesis\API\Constants\Payment\Methods::SAFETY_PAY =>
\Genesis\API\Constants\Payment\Methods::PRZELEWY24 =>
Mage::helper('emerchantpay')->__('Przelewy24'),
\Genesis\API\Constants\Payment\Methods::QIWI =>
Mage::helper('emerchantpay')->__('Qiwi'),
\Genesis\API\Constants\Payment\Methods::SAFETY_PAY =>
Mage::helper('emerchantpay')->__('SafetyPay'),
\Genesis\API\Constants\Transaction\Types::SALE =>
\Genesis\API\Constants\Transaction\Types::SALE =>
Mage::helper('emerchantpay')->__('Sale'),
\Genesis\API\Constants\Transaction\Types::SALE_3D =>
\Genesis\API\Constants\Transaction\Types::SALE_3D =>
Mage::helper('emerchantpay')->__('Sale (3D-Secure)'),
\Genesis\API\Constants\Transaction\Types::SOFORT =>
\Genesis\API\Constants\Transaction\Types::SDD_SALE =>
Mage::helper('emerchantpay')->__('Sepa Direct Debit'),
\Genesis\API\Constants\Transaction\Types::SOFORT =>
Mage::helper('emerchantpay')->__('SOFORT'),
\Genesis\API\Constants\Payment\Methods::TELEINGRESO =>
\Genesis\API\Constants\Payment\Methods::TELEINGRESO =>
Mage::helper('emerchantpay')->__('TeleIngreso'),
\Genesis\API\Constants\Payment\Methods::TRUST_PAY =>
\Genesis\API\Constants\Transaction\Types::TRUSTLY_SALE =>
Mage::helper('emerchantpay')->__('Trustly'),
\Genesis\API\Constants\Payment\Methods::TRUST_PAY =>
Mage::helper('emerchantpay')->__('TrustPay'),
\Genesis\API\Constants\Transaction\Types::WEBMONEY =>
\Genesis\API\Constants\Transaction\Types::WEBMONEY =>
Mage::helper('emerchantpay')->__('WebMoney'),
);
}
Expand Down
Loading

0 comments on commit 29b9330

Please sign in to comment.