Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | * Copyright (C) 2007 | |
4 | * Licensed to CiviCRM under the Academic Free License version 3.0. | |
5 | * | |
6 | * Written and contributed by Ideal Solution, LLC (http://www.idealso.com) | |
7 | * | |
8 | */ | |
9 | ||
10 | /** | |
11 | * | |
12 | * @package CRM | |
13 | * @author Marshal Newrock <marshal@idealso.com> | |
14 | * $Id: Dummy.php 45429 2013-02-06 22:11:18Z lobo $ | |
15 | */ | |
16 | ||
c866eb5f TO |
17 | /** |
18 | * Dummy payment processor | |
6a488035 TO |
19 | */ |
20 | class CRM_Core_Payment_Dummy extends CRM_Core_Payment { | |
7da04cde | 21 | const CHARSET = 'iso-8859-1'; |
6a488035 TO |
22 | |
23 | protected $_mode = NULL; | |
24 | ||
25 | protected $_params = array(); | |
f8fe0df6 | 26 | protected $_doDirectPaymentResult = array(); |
27 | ||
28 | /** | |
eca28728 EM |
29 | * Set result from do Direct Payment for test purposes. |
30 | * | |
f8fe0df6 | 31 | * @param array $doDirectPaymentResult |
eca28728 | 32 | * Result to be returned from test. |
f8fe0df6 | 33 | */ |
34 | public function setDoDirectPaymentResult($doDirectPaymentResult) { | |
35 | $this->_doDirectPaymentResult = $doDirectPaymentResult; | |
9d0f10b7 | 36 | if (empty($this->_doDirectPaymentResult['trxn_id'])) { |
f44bbd1d | 37 | $this->_doDirectPaymentResult['trxn_id'] = array(); |
9d0f10b7 EM |
38 | } |
39 | else { | |
40 | $this->_doDirectPaymentResult['trxn_id'] = (array) $doDirectPaymentResult['trxn_id']; | |
41 | } | |
f8fe0df6 | 42 | } |
6a488035 TO |
43 | |
44 | /** | |
45 | * We only need one instance of this object. So we use the singleton | |
46 | * pattern and cache the instance in this variable | |
47 | * | |
48 | * @var object | |
6a488035 TO |
49 | */ |
50 | static private $_singleton = NULL; | |
51 | ||
52 | /** | |
fe482240 | 53 | * Constructor. |
6a488035 | 54 | * |
6a0b768e TO |
55 | * @param string $mode |
56 | * The mode of operation: live or test. | |
6a488035 | 57 | * |
77b97be7 EM |
58 | * @param $paymentProcessor |
59 | * | |
60 | * @return \CRM_Core_Payment_Dummy | |
6a488035 | 61 | */ |
00be9182 | 62 | public function __construct($mode, &$paymentProcessor) { |
6a488035 TO |
63 | $this->_mode = $mode; |
64 | $this->_paymentProcessor = $paymentProcessor; | |
65 | $this->_processorName = ts('Dummy Processor'); | |
66 | } | |
67 | ||
6a488035 | 68 | /** |
fe482240 | 69 | * Submit a payment using Advanced Integration Method. |
6a488035 | 70 | * |
6a0b768e TO |
71 | * @param array $params |
72 | * Assoc array of input parameters for this transaction. | |
6a488035 | 73 | * |
a6c01b45 CW |
74 | * @return array |
75 | * the result in a nice formatted array (or an error object) | |
6a488035 | 76 | */ |
00be9182 | 77 | public function doDirectPayment(&$params) { |
6a488035 TO |
78 | // Invoke hook_civicrm_paymentProcessor |
79 | // In Dummy's case, there is no translation of parameters into | |
80 | // the back-end's canonical set of parameters. But if a processor | |
81 | // does this, it needs to invoke this hook after it has done translation, | |
82 | // but before it actually starts talking to its proprietary back-end. | |
83 | ||
84 | // no translation in Dummy processor | |
85 | $cookedParams = $params; | |
86 | CRM_Utils_Hook::alterPaymentProcessorParams($this, | |
87 | $params, | |
88 | $cookedParams | |
89 | ); | |
f8fe0df6 | 90 | //end of hook invocation |
91 | if (!empty($this->_doDirectPaymentResult)) { | |
9d0f10b7 EM |
92 | $result = $this->_doDirectPaymentResult; |
93 | $result['trxn_id'] = array_shift($this->_doDirectPaymentResult['trxn_id']); | |
94 | return $result; | |
f8fe0df6 | 95 | } |
6a488035 | 96 | if ($this->_mode == 'test') { |
353ffa53 TO |
97 | $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'test\\_%'"; |
98 | $p = array(); | |
99 | $trxn_id = strval(CRM_Core_Dao::singleValueQuery($query, $p)); | |
100 | $trxn_id = str_replace('test_', '', $trxn_id); | |
101 | $trxn_id = intval($trxn_id) + 1; | |
6a488035 TO |
102 | $params['trxn_id'] = sprintf('test_%08d', $trxn_id); |
103 | } | |
104 | else { | |
353ffa53 TO |
105 | $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'live_%'"; |
106 | $p = array(); | |
107 | $trxn_id = strval(CRM_Core_Dao::singleValueQuery($query, $p)); | |
108 | $trxn_id = str_replace('live_', '', $trxn_id); | |
109 | $trxn_id = intval($trxn_id) + 1; | |
6a488035 TO |
110 | $params['trxn_id'] = sprintf('live_%08d', $trxn_id); |
111 | } | |
112 | $params['gross_amount'] = $params['amount']; | |
3a2251cf DG |
113 | // Add a fee_amount so we can make sure fees are handled properly in underlying classes. |
114 | $params['fee_amount'] = 1.50; | |
115 | $params['net_amount'] = $params['gross_amount'] - $params['fee_amount']; | |
116 | ||
6a488035 TO |
117 | return $params; |
118 | } | |
119 | ||
fbcb6fba | 120 | /** |
100fef9d | 121 | * Are back office payments supported - e.g paypal standard won't permit you to enter a credit card associated with someone else's login |
fbcb6fba EM |
122 | * @return bool |
123 | */ | |
d8ce0d68 | 124 | protected function supportsLiveMode() { |
fbcb6fba EM |
125 | return FALSE; |
126 | } | |
127 | ||
6c786a9b | 128 | /** |
eca28728 EM |
129 | * Generate error object. |
130 | * | |
131 | * Throwing exceptions is preferred over this. | |
132 | * | |
133 | * @param string $errorCode | |
134 | * @param string $errorMessage | |
6c786a9b | 135 | * |
eca28728 EM |
136 | * @return CRM_Core_Error |
137 | * Error object. | |
6c786a9b | 138 | */ |
00be9182 | 139 | public function &error($errorCode = NULL, $errorMessage = NULL) { |
6a488035 TO |
140 | $e = CRM_Core_Error::singleton(); |
141 | if ($errorCode) { | |
142 | $e->push($errorCode, 0, NULL, $errorMessage); | |
143 | } | |
144 | else { | |
145 | $e->push(9001, 0, NULL, 'Unknown System Error.'); | |
146 | } | |
147 | return $e; | |
148 | } | |
149 | ||
150 | /** | |
fe482240 | 151 | * This function checks to see if we have the right config values. |
6a488035 | 152 | * |
a6c01b45 CW |
153 | * @return string |
154 | * the error message if any | |
6a488035 | 155 | */ |
00be9182 | 156 | public function checkConfig() { |
6a488035 TO |
157 | return NULL; |
158 | } | |
96025800 | 159 | |
6a488035 | 160 | } |