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