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 | ||
17 | /* NOTE: | |
18 | * When looking up response codes in the Authorize.Net API, they | |
19 | * begin at one, so always delete one from the "Position in Response" | |
20 | */ | |
21 | class CRM_Core_Payment_Dummy extends CRM_Core_Payment { | |
22 | CONST CHARSET = 'iso-8859-1'; | |
23 | ||
24 | protected $_mode = NULL; | |
25 | ||
26 | protected $_params = array(); | |
27 | ||
28 | /** | |
29 | * We only need one instance of this object. So we use the singleton | |
30 | * pattern and cache the instance in this variable | |
31 | * | |
32 | * @var object | |
33 | * @static | |
34 | */ | |
35 | static private $_singleton = NULL; | |
36 | ||
37 | /** | |
38 | * Constructor | |
39 | * | |
40 | * @param string $mode the mode of operation: live or test | |
41 | * | |
77b97be7 EM |
42 | * @param $paymentProcessor |
43 | * | |
44 | * @return \CRM_Core_Payment_Dummy | |
6a488035 TO |
45 | */ |
46 | function __construct($mode, &$paymentProcessor) { | |
47 | $this->_mode = $mode; | |
48 | $this->_paymentProcessor = $paymentProcessor; | |
49 | $this->_processorName = ts('Dummy Processor'); | |
50 | } | |
51 | ||
52 | /** | |
53 | * singleton function used to manage this object | |
54 | * | |
55 | * @param string $mode the mode of operation: live or test | |
56 | * | |
dd244018 EM |
57 | * @param object $paymentProcessor |
58 | * @param null $paymentForm | |
59 | * @param bool $force | |
60 | * | |
6a488035 TO |
61 | * @return object |
62 | * @static | |
6a488035 TO |
63 | */ |
64 | static function &singleton($mode, &$paymentProcessor, &$paymentForm = NULL, $force = FALSE) { | |
65 | $processorName = $paymentProcessor['name']; | |
66 | if (CRM_Utils_Array::value($processorName, self::$_singleton) === NULL) { | |
67 | self::$_singleton[$processorName] = new CRM_Core_Payment_Dummy($mode, $paymentProcessor); | |
68 | } | |
69 | return self::$_singleton[$processorName]; | |
70 | } | |
71 | ||
72 | /** | |
73 | * Submit a payment using Advanced Integration Method | |
74 | * | |
75 | * @param array $params assoc array of input parameters for this transaction | |
76 | * | |
77 | * @return array the result in a nice formatted array (or an error object) | |
78 | * @public | |
79 | */ | |
80 | function doDirectPayment(&$params) { | |
81 | // Invoke hook_civicrm_paymentProcessor | |
82 | // In Dummy's case, there is no translation of parameters into | |
83 | // the back-end's canonical set of parameters. But if a processor | |
84 | // does this, it needs to invoke this hook after it has done translation, | |
85 | // but before it actually starts talking to its proprietary back-end. | |
86 | ||
87 | // no translation in Dummy processor | |
88 | $cookedParams = $params; | |
89 | CRM_Utils_Hook::alterPaymentProcessorParams($this, | |
90 | $params, | |
91 | $cookedParams | |
92 | ); | |
93 | //end of hook invokation | |
94 | ||
95 | if ($this->_mode == 'test') { | |
96 | $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'test\\_%'"; | |
97 | $p = array(); | |
98 | $trxn_id = strval(CRM_Core_Dao::singleValueQuery($query, $p)); | |
99 | $trxn_id = str_replace('test_', '', $trxn_id); | |
100 | $trxn_id = intval($trxn_id) + 1; | |
101 | $params['trxn_id'] = sprintf('test_%08d', $trxn_id); | |
102 | } | |
103 | else { | |
104 | $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'live_%'"; | |
105 | $p = array(); | |
106 | $trxn_id = strval(CRM_Core_Dao::singleValueQuery($query, $p)); | |
107 | $trxn_id = str_replace('live_', '', $trxn_id); | |
108 | $trxn_id = intval($trxn_id) + 1; | |
109 | $params['trxn_id'] = sprintf('live_%08d', $trxn_id); | |
110 | } | |
111 | $params['gross_amount'] = $params['amount']; | |
112 | return $params; | |
113 | } | |
114 | ||
6c786a9b EM |
115 | /** |
116 | * @param null $errorCode | |
117 | * @param null $errorMessage | |
118 | * | |
119 | * @return object | |
120 | */ | |
6a488035 TO |
121 | function &error($errorCode = NULL, $errorMessage = NULL) { |
122 | $e = CRM_Core_Error::singleton(); | |
123 | if ($errorCode) { | |
124 | $e->push($errorCode, 0, NULL, $errorMessage); | |
125 | } | |
126 | else { | |
127 | $e->push(9001, 0, NULL, 'Unknown System Error.'); | |
128 | } | |
129 | return $e; | |
130 | } | |
131 | ||
132 | /** | |
133 | * This function checks to see if we have the right config values | |
134 | * | |
135 | * @return string the error message if any | |
136 | * @public | |
137 | */ | |
138 | function checkConfig() { | |
139 | return NULL; | |
140 | } | |
141 | } | |
142 |