setStoreId($payment->getOrder()->getStoreId()); $api->authorize($payment->getOrder()->getExtOrderId()); return $this; } /** * Capture payment * * @param Varien_Object $orderPayment * @return Mage_GoogleCheckout_Model_Payment */ public function capture(Varien_Object $payment, $amount) { /* try { $this->authorize($payment, $amount); } catch (Exception $e) { // authorization is not expired yet } */ if ($payment->getOrder()->getPaymentAuthorizationExpiration() < Mage::getModel('core/date')->gmtTimestamp()) { try { $this->authorize($payment, $amount); } catch (Exception $e) { // authorization is not expired yet } } $api = Mage::getModel('googlecheckout/api')->setStoreId($payment->getOrder()->getStoreId()); $api->charge($payment->getOrder()->getExtOrderId(), $amount); $payment->setForcedState(Mage_Sales_Model_Order_Invoice::STATE_OPEN); return $this; } /** * Refund money * * @param Varien_Object $payment * @param float $amount * * @return Mage_GoogleCheckout_Model_Payment */ public function refund(Varien_Object $payment, $amount) { $reason = $this->getReason() ? $this->getReason() : Mage::helper('googlecheckout')->__('No Reason'); $comment = $this->getComment() ? $this->getComment() : Mage::helper('googlecheckout')->__('No Comment'); $api = Mage::getModel('googlecheckout/api')->setStoreId($payment->getOrder()->getStoreId()); $api->refund($payment->getOrder()->getExtOrderId(), $amount, $reason, $comment); return $this; } public function void(Varien_Object $payment) { $this->cancel($payment); return $this; } /** * Void payment * * @param Varien_Object $payment * * @return Mage_GoogleCheckout_Model_Payment */ public function cancel(Varien_Object $payment) { if (!$payment->getOrder()->getBeingCanceledFromGoogleApi()) { $reason = $this->getReason() ? $this->getReason() : Mage::helper('googlecheckout')->__('Unknown Reason'); $comment = $this->getComment() ? $this->getComment() : Mage::helper('googlecheckout')->__('No Comment'); $api = Mage::getModel('googlecheckout/api')->setStoreId($payment->getOrder()->getStoreId()); $api->cancel($payment->getOrder()->getExtOrderId(), $reason, $comment); } return $this; } /** * Retrieve information from payment configuration * * @param string $field * @param int|string|null|Mage_Core_Model_Store $storeId * * @return mixed */ public function getConfigData($field, $storeId = null) { if (null === $storeId) { $storeId = $this->getStore(); } $path = 'google/checkout/' . $field; return Mage::getStoreConfig($path, $storeId); } /** * Check void availability * * @param Varien_Object $payment * @return bool */ public function canVoid(Varien_Object $payment) { if ($payment instanceof Mage_Sales_Model_Order_Invoice || $payment instanceof Mage_Sales_Model_Order_Creditmemo ) { return false; } return $this->_canVoid; } }