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 * Dummy payment processor
20 class CRM_Core_Payment_Dummy
extends CRM_Core_Payment
{
21 const CHARSET
= 'iso-8859-1';
23 protected $_mode = NULL;
25 protected $_params = array();
26 protected $_doDirectPaymentResult = array();
29 * Set result from do Direct Payment for test purposes.
31 * @param array $doDirectPaymentResult
32 * Result to be returned from test.
34 public function setDoDirectPaymentResult($doDirectPaymentResult) {
35 $this->_doDirectPaymentResult
= $doDirectPaymentResult;
36 if (empty($this->_doDirectPaymentResult
['trxn_id'])) {
37 $this->_doDirectPaymentResult
['trxn_id'] = array();
40 $this->_doDirectPaymentResult
['trxn_id'] = (array) $doDirectPaymentResult['trxn_id'];
45 * We only need one instance of this object. So we use the singleton
46 * pattern and cache the instance in this variable
50 static private $_singleton = NULL;
56 * The mode of operation: live or test.
58 * @param $paymentProcessor
60 * @return \CRM_Core_Payment_Dummy
62 public function __construct($mode, &$paymentProcessor) {
64 $this->_paymentProcessor
= $paymentProcessor;
65 $this->_processorName
= ts('Dummy Processor');
69 * Submit a payment using Advanced Integration Method.
71 * @param array $params
72 * Assoc array of input parameters for this transaction.
75 * the result in a nice formatted array (or an error object)
77 public function doDirectPayment(&$params) {
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.
84 // no translation in Dummy processor
85 $cookedParams = $params;
86 CRM_Utils_Hook
::alterPaymentProcessorParams($this,
90 // This means we can test failing transactions by setting a past year in expiry. A full expiry check would
92 if (!empty($params['credit_card_exp_date']['Y']) && date('Y') >
93 CRM_Core_Payment_Form
::getCreditCardExpirationYear($params)) {
94 $error = new CRM_Core_Error(ts('transaction failed'));
97 //end of hook invocation
98 if (!empty($this->_doDirectPaymentResult
)) {
99 $result = $this->_doDirectPaymentResult
;
100 $result['trxn_id'] = array_shift($this->_doDirectPaymentResult
['trxn_id']);
103 if ($this->_mode
== 'test') {
104 $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'test\\_%'";
106 $trxn_id = strval(CRM_Core_Dao
::singleValueQuery($query, $p));
107 $trxn_id = str_replace('test_', '', $trxn_id);
108 $trxn_id = intval($trxn_id) +
1;
109 $params['trxn_id'] = 'test_' . $trxn_id . '_' . uniqid();
112 $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'live_%'";
114 $trxn_id = strval(CRM_Core_Dao
::singleValueQuery($query, $p));
115 $trxn_id = str_replace('live_', '', $trxn_id);
116 $trxn_id = intval($trxn_id) +
1;
117 $params['trxn_id'] = 'live_' . $trxn_id . '_' . uniqid();
119 $params['gross_amount'] = $params['amount'];
120 // Add a fee_amount so we can make sure fees are handled properly in underlying classes.
121 $params['fee_amount'] = 1.50;
122 $params['net_amount'] = $params['gross_amount'] - $params['fee_amount'];
128 * Are back office payments supported - e.g paypal standard won't permit you to enter a credit card associated with someone else's login
131 protected function supportsLiveMode() {
136 * Generate error object.
138 * Throwing exceptions is preferred over this.
140 * @param string $errorCode
141 * @param string $errorMessage
143 * @return CRM_Core_Error
146 public function &error($errorCode = NULL, $errorMessage = NULL) {
147 $e = CRM_Core_Error
::singleton();
149 $e->push($errorCode, 0, NULL, $errorMessage);
152 $e->push(9001, 0, NULL, 'Unknown System Error.');
158 * This function checks to see if we have the right config values.
161 * the error message if any
163 public function checkConfig() {