| 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 | /** |
| 18 | * Dummy payment processor |
| 19 | */ |
| 20 | class CRM_Core_Payment_Dummy extends CRM_Core_Payment { |
| 21 | const CHARSET = 'iso-8859-1'; |
| 22 | |
| 23 | protected $_mode = NULL; |
| 24 | |
| 25 | protected $_params = array(); |
| 26 | protected $_doDirectPaymentResult = array(); |
| 27 | |
| 28 | /** |
| 29 | * @param array $doDirectPaymentResult |
| 30 | */ |
| 31 | public function setDoDirectPaymentResult($doDirectPaymentResult) { |
| 32 | $this->_doDirectPaymentResult = $doDirectPaymentResult; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * We only need one instance of this object. So we use the singleton |
| 37 | * pattern and cache the instance in this variable |
| 38 | * |
| 39 | * @var object |
| 40 | * @static |
| 41 | */ |
| 42 | static private $_singleton = NULL; |
| 43 | |
| 44 | /** |
| 45 | * Constructor |
| 46 | * |
| 47 | * @param string $mode |
| 48 | * The mode of operation: live or test. |
| 49 | * |
| 50 | * @param $paymentProcessor |
| 51 | * |
| 52 | * @return \CRM_Core_Payment_Dummy |
| 53 | */ |
| 54 | public function __construct($mode, &$paymentProcessor) { |
| 55 | $this->_mode = $mode; |
| 56 | $this->_paymentProcessor = $paymentProcessor; |
| 57 | $this->_processorName = ts('Dummy Processor'); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Submit a payment using Advanced Integration Method |
| 62 | * |
| 63 | * @param array $params |
| 64 | * Assoc array of input parameters for this transaction. |
| 65 | * |
| 66 | * @return array |
| 67 | * the result in a nice formatted array (or an error object) |
| 68 | */ |
| 69 | public function doDirectPayment(&$params) { |
| 70 | // Invoke hook_civicrm_paymentProcessor |
| 71 | // In Dummy's case, there is no translation of parameters into |
| 72 | // the back-end's canonical set of parameters. But if a processor |
| 73 | // does this, it needs to invoke this hook after it has done translation, |
| 74 | // but before it actually starts talking to its proprietary back-end. |
| 75 | |
| 76 | // no translation in Dummy processor |
| 77 | $cookedParams = $params; |
| 78 | CRM_Utils_Hook::alterPaymentProcessorParams($this, |
| 79 | $params, |
| 80 | $cookedParams |
| 81 | ); |
| 82 | //end of hook invocation |
| 83 | if (!empty($this->_doDirectPaymentResult)) { |
| 84 | return $this->_doDirectPaymentResult; |
| 85 | } |
| 86 | if ($this->_mode == 'test') { |
| 87 | $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'test\\_%'"; |
| 88 | $p = array(); |
| 89 | $trxn_id = strval(CRM_Core_Dao::singleValueQuery($query, $p)); |
| 90 | $trxn_id = str_replace('test_', '', $trxn_id); |
| 91 | $trxn_id = intval($trxn_id) + 1; |
| 92 | $params['trxn_id'] = sprintf('test_%08d', $trxn_id); |
| 93 | } |
| 94 | else { |
| 95 | $query = "SELECT MAX(trxn_id) FROM civicrm_contribution WHERE trxn_id LIKE 'live_%'"; |
| 96 | $p = array(); |
| 97 | $trxn_id = strval(CRM_Core_Dao::singleValueQuery($query, $p)); |
| 98 | $trxn_id = str_replace('live_', '', $trxn_id); |
| 99 | $trxn_id = intval($trxn_id) + 1; |
| 100 | $params['trxn_id'] = sprintf('live_%08d', $trxn_id); |
| 101 | } |
| 102 | $params['gross_amount'] = $params['amount']; |
| 103 | // Add a fee_amount so we can make sure fees are handled properly in underlying classes. |
| 104 | $params['fee_amount'] = 1.50; |
| 105 | $params['net_amount'] = $params['gross_amount'] - $params['fee_amount']; |
| 106 | |
| 107 | return $params; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Are back office payments supported - e.g paypal standard won't permit you to enter a credit card associated with someone else's login |
| 112 | * @return bool |
| 113 | */ |
| 114 | protected function supportsLiveMode() { |
| 115 | return FALSE; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * @param null $errorCode |
| 120 | * @param null $errorMessage |
| 121 | * |
| 122 | * @return object |
| 123 | */ |
| 124 | public function &error($errorCode = NULL, $errorMessage = NULL) { |
| 125 | $e = CRM_Core_Error::singleton(); |
| 126 | if ($errorCode) { |
| 127 | $e->push($errorCode, 0, NULL, $errorMessage); |
| 128 | } |
| 129 | else { |
| 130 | $e->push(9001, 0, NULL, 'Unknown System Error.'); |
| 131 | } |
| 132 | return $e; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * This function checks to see if we have the right config values |
| 137 | * |
| 138 | * @return string |
| 139 | * the error message if any |
| 140 | */ |
| 141 | public function checkConfig() { |
| 142 | return NULL; |
| 143 | } |
| 144 | } |