Migrate Eway(Single Currency) Payment Processor Type out into its own extension
[civicrm-core.git] / ext / ewaysingle / lib / eWAY / eWAY_GatewayResponse.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 5 |
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
8 | |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
12 | |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25 */
26
27 /**************************************************************************************************************************
28 * Licensed to CiviCRM under the Academic Free License version 3.0
29 * Written & Contributed by Dolphin Software P/L - March 2008
30 *
31 * 'eWAY_GatewayResponse.php' - Loosley based on the standard supplied eWay sample code 'GatewayResponse.php'
32 *
33 * The 'simplexml_load_string' has been removed as it was causing major issues
34 * with Drupal V5.7 / CiviCRM 1.9 installtion's Home page.
35 * Filling the Home page with "Warning: session_start() [function.session-start]: Node no longer exists in ..." messages
36 *
37 * Found web reference indicating 'simplexml_load_string' was a probable cause.
38 * As soon as 'simplexml_load_string' was removed the problem fixed itself.
39 *
40 * Additionally the '$txStatus' var has been set as a string rather than a boolean.
41 * This is because the returned $params['trxn_result_code'] is in fact a string and not a boolean.
42 **************************************************************************************************************************/
43
44 class GatewayResponse
45 {
46 var $txAmount = 0;
47 var $txTransactionNumber = "";
48 var $txInvoiceReference = "";
49 var $txOption1 = "";
50 var $txOption2 = "";
51 var $txOption3 = "";
52 var $txStatus = "";
53 var $txAuthCode = "";
54 var $txError = "";
55 var $txBeagleScore = "";
56
57 function __construct()
58 {
59 // Empty Constructor
60 }
61
62 function ProcessResponse($Xml)
63 {
64 #####################################################################################
65 # #
66 # $xtr = simplexml_load_string($Xml) or die ("Unable to load XML string!"); #
67 # #
68 # $this->txError = $xtr->ewayTrxnError; #
69 # $this->txStatus = $xtr->ewayTrxnStatus; #
70 # $this->txTransactionNumber = $xtr->ewayTrxnNumber; #
71 # $this->txOption1 = $xtr->ewayTrxnOption1; #
72 # $this->txOption2 = $xtr->ewayTrxnOption2; #
73 # $this->txOption3 = $xtr->ewayTrxnOption3; #
74 # $this->txAmount = $xtr->ewayReturnAmount; #
75 # $this->txAuthCode = $xtr->ewayAuthCode; #
76 # $this->txInvoiceReference = $xtr->ewayTrxnReference; #
77 # #
78 #####################################################################################
79
80 $this->txError = self::GetNodeValue("ewayTrxnError", $Xml);
81 $this->txStatus = self::GetNodeValue("ewayTrxnStatus", $Xml);
82 $this->txTransactionNumber = self::GetNodeValue("ewayTrxnNumber", $Xml);
83 $this->txOption1 = self::GetNodeValue("ewayTrxnOption1", $Xml);
84 $this->txOption2 = self::GetNodeValue("ewayTrxnOption2", $Xml);
85 $this->txOption3 = self::GetNodeValue("ewayTrxnOption3", $Xml);
86 $amount = self::GetNodeValue("ewayReturnAmount", $Xml);
87 $this->txAuthCode = self::GetNodeValue("ewayAuthCode", $Xml);
88 $this->txInvoiceReference = self::GetNodeValue("ewayTrxnReference", $Xml);
89 $this->txBeagleScore = self::GetNodeValue("ewayBeagleScore", $Xml);
90 $this->txAmount = (int) $amount;
91 }
92
93
94 /************************************************************************
95 * Simple function to use in place of the 'simplexml_load_string' call.
96 *
97 * It returns the NodeValue for a given NodeName
98 * or returns and empty string.
99 ************************************************************************/
100 function GetNodeValue($NodeName, &$strXML)
101 {
102 $OpeningNodeName = "<" . $NodeName . ">";
103 $ClosingNodeName = "</" . $NodeName . ">";
104
105 $pos1 = stripos($strXML, $OpeningNodeName);
106 $pos2 = stripos($strXML, $ClosingNodeName);
107
108 if ( ($pos1 === false) || ($pos2 === false) )
109 return "";
110
111 $pos1 += strlen($OpeningNodeName);
112 $len = $pos2 - $pos1;
113
114 $return = substr($strXML, $pos1, $len);
115
116 return ($return);
117 }
118
119
120 function TransactionNumber()
121 {
122 return $this->txTransactionNumber;
123 }
124
125 function InvoiceReference()
126 {
127 return $this->txInvoiceReference;
128 }
129
130 function Option1()
131 {
132 return $this->txOption1;
133 }
134
135 function Option2()
136 {
137 return $this->txOption2;
138 }
139
140 function Option3()
141 {
142 return $this->txOption3;
143 }
144
145 function AuthorisationCode()
146 {
147 return $this->txAuthCode;
148 }
149
150 function Error()
151 {
152 return $this->txError;
153 }
154
155 function Amount()
156 {
157 return $this->txAmount;
158 }
159
160 function Status()
161 {
162 return $this->txStatus;
163 }
164
165 function BeagleScore ()
166 {
167 return $this->txBeagleScore ;
168 }
169 }
170
171 ?>