remove a couple of unrequired lines from test
[civicrm-core.git] / CRM / Core / Payment / Dummy.php
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 *
42 * @return void
43 */
44 function __construct($mode, &$paymentProcessor) {
45 $this->_mode = $mode;
46 $this->_paymentProcessor = $paymentProcessor;
47 $this->_processorName = ts('Dummy Processor');
48 }
49
50 /**
51 * singleton function used to manage this object
52 *
53 * @param string $mode the mode of operation: live or test
54 *
55 * @return object
56 * @static
57 *
58 */
59 static function &singleton($mode, &$paymentProcessor, &$paymentForm = NULL, $force = FALSE) {
60 $processorName = $paymentProcessor['name'];
61 if (CRM_Utils_Array::value($processorName, self::$_singleton) === NULL) {
62 self::$_singleton[$processorName] = new CRM_Core_Payment_Dummy($mode, $paymentProcessor);
63 }
64 return self::$_singleton[$processorName];
65 }
66
67 /**
68 * Submit a payment using Advanced Integration Method
69 *
70 * @param array $params assoc array of input parameters for this transaction
71 *
72 * @return array the result in a nice formatted array (or an error object)
73 * @public
74 */
75 function doDirectPayment(&$params) {
76 // Invoke hook_civicrm_paymentProcessor
77 // In Dummy's case, there is no translation of parameters into
78 // the back-end's canonical set of parameters. But if a processor
79 // does this, it needs to invoke this hook after it has done translation,
80 // but before it actually starts talking to its proprietary back-end.
81
82 // no translation in Dummy processor
83 $cookedParams = $params;
84 CRM_Utils_Hook::alterPaymentProcessorParams($this,
85 $params,
86 $cookedParams
87 );
88 //end of hook invokation
89
90 if ($this->_mode == 'test') {
91 $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'test\\_%'";
92 $p = array();
93 $trxn_id = strval(CRM_Core_Dao::singleValueQuery($query, $p));
94 $trxn_id = str_replace('test_', '', $trxn_id);
95 $trxn_id = intval($trxn_id) + 1;
96 $params['trxn_id'] = sprintf('test_%08d', $trxn_id);
97 }
98 else {
99 $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'live_%'";
100 $p = array();
101 $trxn_id = strval(CRM_Core_Dao::singleValueQuery($query, $p));
102 $trxn_id = str_replace('live_', '', $trxn_id);
103 $trxn_id = intval($trxn_id) + 1;
104 $params['trxn_id'] = sprintf('live_%08d', $trxn_id);
105 }
106 $params['gross_amount'] = $params['amount'];
107 return $params;
108 }
109
110 function &error($errorCode = NULL, $errorMessage = NULL) {
111 $e = CRM_Core_Error::singleton();
112 if ($errorCode) {
113 $e->push($errorCode, 0, NULL, $errorMessage);
114 }
115 else {
116 $e->push(9001, 0, NULL, 'Unknown System Error.');
117 }
118 return $e;
119 }
120
121 /**
122 * This function checks to see if we have the right config values
123 *
124 * @return string the error message if any
125 * @public
126 */
127 function checkConfig() {
128 return NULL;
129 }
130 }
131