1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: class Mage_GoogleCheckout_Model_Payment extends Mage_Payment_Model_Method_Abstract
28: {
29: const ACTION_AUTHORIZE = 0;
30: const ACTION_AUTHORIZE_CAPTURE = 1;
31:
32: protected $_code = 'googlecheckout';
33: protected $_formBlockType = 'googlecheckout/form';
34:
35: 36: 37:
38: protected $_isGateway = false;
39: protected $_canAuthorize = true;
40: protected $_canCapture = true;
41: protected $_canCapturePartial = true;
42: protected $_canRefund = true;
43: protected $_canRefundInvoicePartial = true;
44: protected $_canVoid = true;
45: protected $_canUseInternal = false;
46: protected $_canUseCheckout = false;
47: protected $_canUseForMultishipping = false;
48:
49: 50: 51: 52: 53:
54: public function canEdit()
55: {
56: return false;
57: }
58:
59: 60: 61: 62: 63:
64: public function getOrderPlaceRedirectUrl()
65: {
66: return Mage::getUrl('googlecheckout/redirect/redirect');
67: }
68:
69: 70: 71: 72: 73: 74:
75: public function authorize(Varien_Object $payment, $amount)
76: {
77: $api = Mage::getModel('googlecheckout/api')->setStoreId($payment->getOrder()->getStoreId());
78: $api->authorize($payment->getOrder()->getExtOrderId());
79:
80: return $this;
81: }
82:
83: 84: 85: 86: 87: 88:
89: public function capture(Varien_Object $payment, $amount)
90: {
91: 92: 93: 94: 95: 96: 97:
98:
99: if ($payment->getOrder()->getPaymentAuthorizationExpiration() < Mage::getModel('core/date')->gmtTimestamp()) {
100: try {
101: $this->authorize($payment, $amount);
102: } catch (Exception $e) {
103:
104: }
105: }
106:
107: $api = Mage::getModel('googlecheckout/api')->setStoreId($payment->getOrder()->getStoreId());
108: $api->charge($payment->getOrder()->getExtOrderId(), $amount);
109: $payment->setForcedState(Mage_Sales_Model_Order_Invoice::STATE_OPEN);
110:
111: return $this;
112: }
113:
114: 115: 116: 117: 118: 119: 120: 121:
122: public function refund(Varien_Object $payment, $amount)
123: {
124: $reason = $this->getReason() ? $this->getReason() : Mage::helper('googlecheckout')->__('No Reason');
125: $comment = $this->getComment() ? $this->getComment() : Mage::helper('googlecheckout')->__('No Comment');
126:
127: $api = Mage::getModel('googlecheckout/api')->setStoreId($payment->getOrder()->getStoreId());
128: $api->refund($payment->getOrder()->getExtOrderId(), $amount, $reason, $comment);
129:
130: return $this;
131: }
132:
133: public function void(Varien_Object $payment)
134: {
135: $this->cancel($payment);
136:
137: return $this;
138: }
139:
140: 141: 142: 143: 144: 145: 146:
147: public function cancel(Varien_Object $payment)
148: {
149: if (!$payment->getOrder()->getBeingCanceledFromGoogleApi()) {
150: $reason = $this->getReason() ? $this->getReason() : Mage::helper('googlecheckout')->__('Unknown Reason');
151: $comment = $this->getComment() ? $this->getComment() : Mage::helper('googlecheckout')->__('No Comment');
152:
153: $api = Mage::getModel('googlecheckout/api')->setStoreId($payment->getOrder()->getStoreId());
154: $api->cancel($payment->getOrder()->getExtOrderId(), $reason, $comment);
155: }
156:
157: return $this;
158: }
159:
160: 161: 162: 163: 164: 165: 166: 167:
168: public function getConfigData($field, $storeId = null)
169: {
170: if (null === $storeId) {
171: $storeId = $this->getStore();
172: }
173: $path = 'google/checkout/' . $field;
174:
175: return Mage::getStoreConfig($path, $storeId);
176: }
177:
178: 179: 180: 181: 182: 183:
184: public function canVoid(Varien_Object $payment)
185: {
186: if ($payment instanceof Mage_Sales_Model_Order_Invoice
187: || $payment instanceof Mage_Sales_Model_Order_Creditmemo
188: ) {
189: return false;
190: }
191:
192: return $this->_canVoid;
193: }
194: }
195: