Change eWAY processor to use guzzle, fix style issues and update info.xml and add...
[civicrm-core.git] / ext / ewaysingle / lib / eWAY / eWAY_GatewayResponse.php
CommitLineData
68f481e6
SL
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 */
43class GatewayResponse {
44 public $txAmount = 0;
45 public $txTransactionNumber = "";
46 public $txInvoiceReference = "";
47 public $txOption1 = "";
48 public $txOption2 = "";
49 public $txOption3 = "";
50 public $txStatus = "";
51 public $txAuthCode = "";
52 public $txError = "";
53 public $txBeagleScore = "";
54
55 public function __construct() {
56 // Empty Constructor
57 }
58
59 public function ProcessResponse($Xml) {
60 //$xtr = simplexml_load_string($Xml) or die ("Unable to load XML string!");
61
62 //$this->txError = $xtr->ewayTrxnError;
63 //$this->txStatus = $xtr->ewayTrxnStatus;
64 //$this->txTransactionNumber = $xtr->ewayTrxnNumber;
65 //$this->txOption1 = $xtr->ewayTrxnOption1;
66 //$this->txOption2 = $xtr->ewayTrxnOption2;
67 //$this->txOption3 = $xtr->ewayTrxnOption3;
68 //$this->txAmount = $xtr->ewayReturnAmount;
69 //$this->txAuthCode = $xtr->ewayAuthCode;
70 //$this->txInvoiceReference = $xtr->ewayTrxnReference;
71
72 $this->txError = self::GetNodeValue("ewayTrxnError", $Xml);
73 $this->txStatus = self::GetNodeValue("ewayTrxnStatus", $Xml);
74 $this->txTransactionNumber = self::GetNodeValue("ewayTrxnNumber", $Xml);
75 $this->txOption1 = self::GetNodeValue("ewayTrxnOption1", $Xml);
76 $this->txOption2 = self::GetNodeValue("ewayTrxnOption2", $Xml);
77 $this->txOption3 = self::GetNodeValue("ewayTrxnOption3", $Xml);
78 $amount = self::GetNodeValue("ewayReturnAmount", $Xml);
79 $this->txAuthCode = self::GetNodeValue("ewayAuthCode", $Xml);
80 $this->txInvoiceReference = self::GetNodeValue("ewayTrxnReference", $Xml);
81 $this->txBeagleScore = self::GetNodeValue("ewayBeagleScore", $Xml);
82 $this->txAmount = (int) $amount;
83 }
84
85 /**
86 * Simple function to use in place of the 'simplexml_load_string' call.
87 *
88 * It returns the NodeValue for a given NodeName
89 * or returns and empty string.
90 */
91 public function GetNodeValue($NodeName, &$strXML) {
92 $OpeningNodeName = "<" . $NodeName . ">";
93 $ClosingNodeName = "</" . $NodeName . ">";
94
95 $pos1 = stripos($strXML, $OpeningNodeName);
96 $pos2 = stripos($strXML, $ClosingNodeName);
97
98 if (($pos1 === FALSE) || ($pos2 === FALSE)) {
99 return "";
100 }
101
102 $pos1 += strlen($OpeningNodeName);
103 $len = $pos2 - $pos1;
104
105 $return = substr($strXML, $pos1, $len);
106
107 return ($return);
108 }
109
110 public function TransactionNumber() {
111 return $this->txTransactionNumber;
112 }
113
114 public function InvoiceReference() {
115 return $this->txInvoiceReference;
116 }
117
118 public function Option1() {
119 return $this->txOption1;
120 }
121
122 public function Option2() {
123 return $this->txOption2;
124 }
125
126 public function Option3() {
127 return $this->txOption3;
128 }
129
130 public function AuthorisationCode() {
131 return $this->txAuthCode;
132 }
133
134 public function Error() {
135 return $this->txError;
136 }
137
138 public function Amount() {
139 return $this->txAmount;
140 }
141
142 public function Status() {
143 return $this->txStatus;
144 }
145
146 public function BeagleScore () {
147 return $this->txBeagleScore;
148 }
149
150}