4 * Licensed to CiviCRM under the Academic Free License version 3.0.
6 * Written and contributed by Ideal Solution, LLC (http://www.idealso.com)
13 * @author Marshal Newrock <marshal@idealso.com>
14 * $Id: Dummy.php 45429 2013-02-06 22:11:18Z lobo $
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"
21 class CRM_Core_Payment_Dummy
extends CRM_Core_Payment
{
22 CONST CHARSET
= 'iso-8859-1';
24 protected $_mode = NULL;
26 protected $_params = array();
27 protected $_doDirectPaymentResult = array();
30 * @param array $doDirectPaymentResult
32 public function setDoDirectPaymentResult($doDirectPaymentResult) {
33 $this->_doDirectPaymentResult
= $doDirectPaymentResult;
37 * We only need one instance of this object. So we use the singleton
38 * pattern and cache the instance in this variable
43 static private $_singleton = NULL;
48 * @param string $mode the mode of operation: live or test
50 * @param $paymentProcessor
52 * @return \CRM_Core_Payment_Dummy
54 function __construct($mode, &$paymentProcessor) {
56 $this->_paymentProcessor
= $paymentProcessor;
57 $this->_processorName
= ts('Dummy Processor');
61 * singleton function used to manage this object
63 * @param string $mode the mode of operation: live or test
65 * @param object $paymentProcessor
66 * @param null $paymentForm
72 static function &singleton($mode, &$paymentProcessor, &$paymentForm = NULL, $force = FALSE) {
73 $processorName = $paymentProcessor['name'];
74 if (CRM_Utils_Array
::value($processorName, self
::$_singleton) === NULL) {
75 self
::$_singleton[$processorName] = new CRM_Core_Payment_Dummy($mode, $paymentProcessor);
77 return self
::$_singleton[$processorName];
81 * Submit a payment using Advanced Integration Method
83 * @param array $params assoc array of input parameters for this transaction
85 * @return array the result in a nice formatted array (or an error object)
88 function doDirectPayment(&$params) {
89 // Invoke hook_civicrm_paymentProcessor
90 // In Dummy's case, there is no translation of parameters into
91 // the back-end's canonical set of parameters. But if a processor
92 // does this, it needs to invoke this hook after it has done translation,
93 // but before it actually starts talking to its proprietary back-end.
95 // no translation in Dummy processor
96 $cookedParams = $params;
97 CRM_Utils_Hook
::alterPaymentProcessorParams($this,
101 //end of hook invocation
102 if (!empty($this->_doDirectPaymentResult
)) {
103 return $this->_doDirectPaymentResult
;
105 if ($this->_mode
== 'test') {
106 $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'test\\_%'";
108 $trxn_id = strval(CRM_Core_Dao
::singleValueQuery($query, $p));
109 $trxn_id = str_replace('test_', '', $trxn_id);
110 $trxn_id = intval($trxn_id) +
1;
111 $params['trxn_id'] = sprintf('test_%08d', $trxn_id);
114 $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'live_%'";
116 $trxn_id = strval(CRM_Core_Dao
::singleValueQuery($query, $p));
117 $trxn_id = str_replace('live_', '', $trxn_id);
118 $trxn_id = intval($trxn_id) +
1;
119 $params['trxn_id'] = sprintf('live_%08d', $trxn_id);
121 $params['gross_amount'] = $params['amount'];
126 * @param null $errorCode
127 * @param null $errorMessage
131 function &error($errorCode = NULL, $errorMessage = NULL) {
132 $e = CRM_Core_Error
::singleton();
134 $e->push($errorCode, 0, NULL, $errorMessage);
137 $e->push(9001, 0, NULL, 'Unknown System Error.');
143 * This function checks to see if we have the right config values
145 * @return string the error message if any
148 function checkConfig() {