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_Paygate
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: * Paygate data helper
29: */
30: class Mage_Paygate_Helper_Data extends Mage_Core_Helper_Abstract
31: {
32: /**
33: * Converts a lot of messages to message
34: *
35: * @param array $messages
36: * @return string
37: */
38: public function convertMessagesToMessage($messages)
39: {
40: return implode(' | ', $messages);
41: }
42:
43: /**
44: * Return message for gateway transaction request
45: *
46: * @param Mage_Payment_Model_Info $payment
47: * @param string $requestType
48: * @param string $lastTransactionId
49: * @param Varien_Object $card
50: * @param float $amount
51: * @param string $exception
52: * @return bool|string
53: */
54: public function getTransactionMessage($payment, $requestType, $lastTransactionId, $card, $amount = false,
55: $exception = false
56: ) {
57: return $this->getExtendedTransactionMessage(
58: $payment, $requestType, $lastTransactionId, $card, $amount, $exception
59: );
60: }
61:
62: /**
63: * Return message for gateway transaction request
64: *
65: * @param Mage_Payment_Model_Info $payment
66: * @param string $requestType
67: * @param string $lastTransactionId
68: * @param Varien_Object $card
69: * @param float $amount
70: * @param string $exception
71: * @param string $additionalMessage Custom message, which will be added to the end of generated message
72: * @return bool|string
73: */
74: public function getExtendedTransactionMessage($payment, $requestType, $lastTransactionId, $card, $amount = false,
75: $exception = false, $additionalMessage = false
76: ) {
77: $operation = $this->_getOperation($requestType);
78:
79: if (!$operation) {
80: return false;
81: }
82:
83: if ($amount) {
84: $amount = $this->__('amount %s', $this->_formatPrice($payment, $amount));
85: }
86:
87: if ($exception) {
88: $result = $this->__('failed');
89: } else {
90: $result = $this->__('successful');
91: }
92:
93: $card = $this->__('Credit Card: xxxx-%s', $card->getCcLast4());
94:
95: $pattern = '%s %s %s - %s.';
96: $texts = array($card, $amount, $operation, $result);
97:
98: if (!is_null($lastTransactionId)) {
99: $pattern .= ' %s.';
100: $texts[] = $this->__('Authorize.Net Transaction ID %s', $lastTransactionId);
101: }
102:
103: if ($additionalMessage) {
104: $pattern .= ' %s.';
105: $texts[] = $additionalMessage;
106: }
107: $pattern .= ' %s';
108: $texts[] = $exception;
109:
110: return call_user_func_array(array($this, '__'), array_merge(array($pattern), $texts));
111: }
112:
113: /**
114: * Return operation name for request type
115: *
116: * @param string $requestType
117: * @return bool|string
118: */
119: protected function _getOperation($requestType)
120: {
121: switch ($requestType) {
122: case Mage_Paygate_Model_Authorizenet::REQUEST_TYPE_AUTH_ONLY:
123: return $this->__('authorize');
124: case Mage_Paygate_Model_Authorizenet::REQUEST_TYPE_AUTH_CAPTURE:
125: return $this->__('authorize and capture');
126: case Mage_Paygate_Model_Authorizenet::REQUEST_TYPE_PRIOR_AUTH_CAPTURE:
127: return $this->__('capture');
128: case Mage_Paygate_Model_Authorizenet::REQUEST_TYPE_CREDIT:
129: return $this->__('refund');
130: case Mage_Paygate_Model_Authorizenet::REQUEST_TYPE_VOID:
131: return $this->__('void');
132: default:
133: return false;
134: }
135: }
136:
137: /**
138: * Format price with currency sign
139: * @param Mage_Payment_Model_Info $payment
140: * @param float $amount
141: * @return string
142: */
143: protected function _formatPrice($payment, $amount)
144: {
145: return $payment->getOrder()->getBaseCurrency()->formatTxt($amount);
146: }
147: }
148: