1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_GoogleCheckout
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Google Checkout notification model
29: *
30: * @method Mage_GoogleCheckout_Model_Resource_Notification _getResource()
31: * @method Mage_GoogleCheckout_Model_Resource_Notification getResource()
32: * @method string getSerialNumber()
33: * @method Mage_GoogleCheckout_Model_Notification setSerialNumber(string $value)
34: * @method string getStartedAt()
35: * @method Mage_GoogleCheckout_Model_Notification setStartedAt(string $value)
36: * @method int getStatus()
37: * @method Mage_GoogleCheckout_Model_Notification setStatus(int $value)
38: *
39: * @category Mage
40: * @package Mage_GoogleCheckout
41: * @author Magento Core Team <core@magentocommerce.com>
42: */
43: class Mage_GoogleCheckout_Model_Notification extends Mage_Core_Model_Abstract
44: {
45: const TIMEOUT_LIMIT = 3600;
46: const STATUS_INPROCESS = 0;
47: const STATUS_PROCESSED = 1;
48:
49: /**
50: * Intialize model
51: */
52: function _construct()
53: {
54: $this->_init('googlecheckout/notification');
55: }
56:
57: /**
58: * Assign previously saved notification data to model
59: *
60: * @return Mage_GoogleCheckout_Model_Notification
61: */
62: public function loadNotificationData()
63: {
64: $data = $this->getResource()->getNotificationData($this->getSerialNumber());
65: if (is_array($data)) {
66: $this->addData($data);
67: }
68: return $this;
69: }
70:
71: /**
72: * Check if current notification is already processed
73: *
74: * @return bool
75: */
76: public function isProcessed()
77: {
78: return $this->getStatus() == self::STATUS_PROCESSED;
79: }
80:
81: /**
82: * Check if current notification is time out
83: *
84: * @return bool
85: */
86: public function isTimeout()
87: {
88: $startedTime = strtotime($this->getStartedAt());
89: $currentTime = time();
90:
91: if ($currentTime - $startedTime > self::TIMEOUT_LIMIT) {
92: return true;
93: }
94: return false;
95: }
96:
97: /**
98: * Start process of current notification
99: *
100: * @return Mage_GoogleCheckout_Model_Notification
101: */
102: public function startProcess()
103: {
104: $this->getResource()->startProcess($this->getSerialNumber());
105: return $this;
106: }
107:
108: /**
109: * Update process of current notification
110: *
111: * @return Mage_GoogleCheckout_Model_Notification
112: */
113: public function updateProcess()
114: {
115: $this->getResource()->updateProcess($this->getSerialNumber());
116: return $this;
117: }
118:
119: /**
120: * Stop process of current notification
121: *
122: * @return Mage_GoogleCheckout_Model_Notification
123: */
124: public function stopProcess()
125: {
126: $this->getResource()->stopProcess($this->getSerialNumber());
127: return $this;
128: }
129: }
130: