Skip to content

Commit

Permalink
You can now disable refunds
Browse files Browse the repository at this point in the history
You can now disable payment methods for specific shipping methods
  • Loading branch information
Andy Pieters committed May 19, 2016
1 parent c8a9209 commit 775845b
Show file tree
Hide file tree
Showing 3 changed files with 1,140 additions and 103 deletions.
80 changes: 57 additions & 23 deletions app/code/community/Pay/Payment/Model/Paymentmethod.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

class Pay_Payment_Model_Paymentmethod extends Mage_Payment_Model_Method_Abstract {
class Pay_Payment_Model_Paymentmethod extends Mage_Payment_Model_Method_Abstract
{

const OPTION_ID = 0;

Expand All @@ -10,55 +11,87 @@ class Pay_Payment_Model_Paymentmethod extends Mage_Payment_Model_Method_Abstract
protected $_canCapture = true;
protected $_canRefund = true;
protected $_canRefundInvoicePartial = true;

protected $_paymentOptionId;
protected $_paymentOptionName;

public function getPaymentOptionId() {
public function getPaymentOptionId()
{
return $this->_paymentOptionId;
}


public function isApplicableToQuote($quote, $checksBitMask)
{
$store = $quote->getStore();
$limit_shipping = Mage::getStoreConfig('payment/' . $this->_code . '/limit_shipping', $store);
if ($limit_shipping) {
$disabled_shipping = Mage::getStoreConfig('payment/' . $this->_code . '/disabled_shippingmethods', $store);
$disabled_shipping = explode(',', $disabled_shipping);

$shippingMethod = $quote->getShippingAddress()->getShippingMethod();
if (in_array($shippingMethod, $disabled_shipping)) return false;
}

return parent::isApplicableToQuote($quote, $checksBitMask);
}

/**
* Check refund availability
*
* @return bool
*/
public function canRefund()
{
$enable_refund = Mage::getStoreConfig('pay_payment/general/enable_refund');
if (!$enable_refund) return false;
else return parent::canRefund();
}

/**
* Check partial refund availability for invoice
*
* @return bool
*/
public function canRefundPartialPerInvoice()
{
$enable_refund = Mage::getStoreConfig('pay_payment/general/enable_refund');
if (!$enable_refund) return false;
else return parent::canRefundPartialPerInvoice();
}

public function refund(Varien_Object $payment, $amount) {
$payment instanceof Mage_Sales_Model_Order_Payment;
public function refund(Varien_Object $payment, $amount)
{
$order = $payment->getOrder();
$store = $order->getStore();

$serviceId = Mage::getStoreConfig('pay_payment/general/serviceid', $store);
$apiToken = Mage::getStoreConfig('pay_payment/general/apitoken', $store);

$useBackupApi = Mage::getStoreConfig('pay_payment/general/use_backup_api', $store);
$backupApiUrl = Mage::getStoreConfig('pay_payment/general/backup_api_url', $store);
if($useBackupApi == 1){
if ($useBackupApi == 1) {
Pay_Payment_Helper_Api::_setBackupApiUrl($backupApiUrl);
}

//todo: Doe iets met de api
$parentTransactionId = $payment->getParentTransactionId();

$apiRefund = Mage::helper('pay_payment/api_refund');
$apiRefund instanceof Pay_Payment_Helper_Api_Refund;
$apiRefund->setApiToken($apiToken);
$apiRefund->setServiceId($serviceId);
$apiRefund->setTransactionId($parentTransactionId);
$amount = (int)round($amount*100);

$apiRefund->setTransactionId($parentTransactionId);
$amount = (int)round($amount * 100);
$apiRefund->setAmount($amount);

$apiRefund->doRequest();

// die($parentTransactionId);

return $this;
}

//
//
// public function processCreditmemo($creditmemo, $payment){//after refund
// return $this;
// }

public function getOrderPlaceRedirectUrl() {
public function getOrderPlaceRedirectUrl()
{
return Mage::getUrl('pay_payment/checkout/redirect');
}

Expand All @@ -67,7 +100,8 @@ public function getOrderPlaceRedirectUrl() {
// * @param string $paymentAction
// * @param Varien_Object
// */
public function initialize($paymentAction, $stateObject) {
public function initialize($paymentAction, $stateObject)
{
$session = Mage::getSingleton('checkout/session');
/* @var $session Mage_Checkout_Model_Session */

Expand Down
Loading

0 comments on commit 775845b

Please sign in to comment.