00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 class Mage_GoogleCheckout_Model_Payment extends Mage_Payment_Model_Method_Abstract
00028 {
00029 const ACTION_AUTHORIZE = 0;
00030 const ACTION_AUTHORIZE_CAPTURE = 1;
00031
00032 protected $_code = 'googlecheckout';
00033 protected $_formBlockType = 'googlecheckout/form';
00034
00035
00036
00037
00038 protected $_isGateway = false;
00039 protected $_canAuthorize = true;
00040 protected $_canCapture = true;
00041 protected $_canCapturePartial = true;
00042 protected $_canRefund = true;
00043 protected $_canRefundInvoicePartial = true;
00044 protected $_canVoid = true;
00045 protected $_canUseInternal = false;
00046 protected $_canUseCheckout = false;
00047 protected $_canUseForMultishipping = false;
00048
00049
00050
00051
00052
00053
00054 public function canEdit()
00055 {
00056 return false;
00057 }
00058
00059
00060
00061
00062
00063
00064
00065 public function isAvailable($quote=null)
00066 {
00067 return Mage::getStoreConfig('google/checkout/active') > 0;
00068 }
00069
00070
00071
00072
00073
00074
00075 public function getOrderPlaceRedirectUrl()
00076 {
00077 return Mage::getUrl('googlecheckout/redirect/redirect');
00078 }
00079
00080
00081
00082
00083
00084
00085
00086 public function authorize(Varien_Object $payment, $amount)
00087 {
00088 $api = Mage::getModel('googlecheckout/api')->setStoreId($payment->getOrder()->getStoreId());
00089 $api->authorize($payment->getOrder()->getExtOrderId());
00090
00091 return $this;
00092 }
00093
00094
00095
00096
00097
00098
00099
00100 public function capture(Varien_Object $payment, $amount)
00101 {
00102
00103
00104
00105
00106
00107
00108
00109
00110 if ($payment->getOrder()->getPaymentAuthorizationExpiration() < Mage::getModel('core/date')->gmtTimestamp()) {
00111 try {
00112 $this->authorize($payment, $amount);
00113 } catch (Exception $e) {
00114
00115 }
00116 }
00117
00118 $api = Mage::getModel('googlecheckout/api')->setStoreId($payment->getOrder()->getStoreId());
00119 $api->charge($payment->getOrder()->getExtOrderId(), $amount);
00120 $payment->setForcedState(Mage_Sales_Model_Order_Invoice::STATE_OPEN);
00121
00122 return $this;
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132 public function refund(Varien_Object $payment, $amount)
00133 {
00134 $hlp = Mage::helper('googlecheckout');
00135
00136
00137
00138
00139
00140
00141 $reason = $this->getReason() ? $this->getReason() : $hlp->__('No Reason');
00142 $comment = $this->getComment() ? $this->getComment() : $hlp->__('No Comment');
00143
00144 $api = Mage::getModel('googlecheckout/api')->setStoreId($payment->getOrder()->getStoreId());
00145 $api->refund($payment->getOrder()->getExtOrderId(), $amount, $reason, $comment);
00146
00147 return $this;
00148 }
00149
00150 public function void(Varien_Object $payment)
00151 {
00152 $this->cancel($payment);
00153
00154 return $this;
00155 }
00156
00157
00158
00159
00160
00161
00162
00163 public function cancel(Varien_Object $payment)
00164 {
00165 if (!$payment->getOrder()->getBeingCanceledFromGoogleApi()) {
00166 $hlp = Mage::helper('googlecheckout');
00167 $reason = $this->getReason() ? $this->getReason() : $hlp->__('Unknown Reason');
00168 $comment = $this->getComment() ? $this->getComment() : $hlp->__('No Comment');
00169
00170 $api = Mage::getModel('googlecheckout/api')->setStoreId($payment->getOrder()->getStoreId());
00171 $api->cancel($payment->getOrder()->getExtOrderId(), $reason, $comment);
00172 }
00173
00174 return $this;
00175 }
00176 }