Test Failed
Push — develop ( 6098b1...78195a )
by Reüel
02:46
created

src/Connect/Client.php (12 issues)

1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\MultiSafepay\Connect;
4
5
use Pronamic\WordPress\Pay\Core\Util as Core_Util;
6
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\MultiSafepay;
7
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Connect\XML\DirectTransactionRequestMessage;
8
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Connect\XML\DirectTransactionResponseMessage;
9
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Connect\XML\GatewaysRequestMessage;
10
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Connect\XML\GatewaysResponseMessage;
11
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Connect\XML\IDealIssuersRequestMessage;
12
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Connect\XML\IDealIssuersResponseMessage;
13
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Connect\XML\RedirectTransactionRequestMessage;
14
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Connect\XML\RedirectTransactionResponseMessage;
15
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Connect\XML\StatusRequestMessage;
16
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Connect\XML\StatusResponseMessage;
17
use WP_Error;
0 ignored issues
show
The type WP_Error was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
19
/**
20
 * Title: MultiSafepay Connect client
21
 * Description:
22
 * Copyright: 2005-2019 Pronamic
23
 * Company: Pronamic
24
 *
25
 * @author  Remco Tolsma
26
 * @version 2.0.2
27
 * @since   1.0.0
28
 */
29
class Client {
30
	/**
31
	 * Error
32
	 *
33
	 * @var WP_Error
34
	 */
35
	private $error;
36
37
	/**
38
	 * API URL
39
	 *
40
	 * @var string
41
	 */
42
	public $api_url;
43
44
	/**
45
	 * Constructs and initializes an MultiSafepay Connect client
46
	 */
47
	public function __construct() {
48
		$this->api_url = MultiSafepay::API_PRODUCTION_URL;
49
	}
50
51
	/**
52
	 * Get error
53
	 *
54
	 * @return WP_Error
55
	 */
56
	public function get_error() {
57
		return $this->error;
58
	}
59
60
	private function parse_xml( $xml ) {
61
		switch ( $xml->getName() ) {
62
			case IDealIssuersRequestMessage::NAME:
63
				return IDealIssuersResponseMessage::parse( $xml );
64
65
			case GatewaysRequestMessage::NAME:
66
				return GatewaysResponseMessage::parse( $xml );
67
68
			case DirectTransactionRequestMessage::NAME:
69
				return DirectTransactionResponseMessage::parse( $xml );
70
71
			case RedirectTransactionRequestMessage::NAME:
72
				return RedirectTransactionResponseMessage::parse( $xml );
73
74
			case StatusRequestMessage::NAME:
75
				return StatusResponseMessage::parse( $xml );
76
		}
77
78
		return false;
79
	}
80
81
	private function request( $message ) {
82
		$return = false;
83
84
		$result = Core_Util::remote_get_body( $this->api_url, 200, array(
85
			'method' => 'POST',
86
			'body'   => (string) $message,
87
		) );
88
89
		if ( is_wp_error( $result ) ) {
0 ignored issues
show
The function is_wp_error was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

89
		if ( /** @scrutinizer ignore-call */ is_wp_error( $result ) ) {
Loading history...
90
			$this->error = $result;
91
92
			return false;
93
		}
94
95
		$xml = Core_Util::simplexml_load_string( $result );
0 ignored issues
show
It seems like $result can also be of type array; however, parameter $string of Pronamic\WordPress\Pay\C...simplexml_load_string() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

95
		$xml = Core_Util::simplexml_load_string( /** @scrutinizer ignore-type */ $result );
Loading history...
96
97
		if ( is_wp_error( $xml ) ) {
98
			$this->error = $xml;
0 ignored issues
show
Documentation Bug introduced by
It seems like $xml of type SimpleXMLElement is incompatible with the declared type WP_Error of property $error.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
99
		} else {
100
			$return = $this->parse_xml( $xml );
101
102
			if ( is_object( $return ) && isset( $return->result ) && 'error' === $return->result ) {
103
				$this->error = new WP_Error( 'multisafepay_error', $xml->error->description, $xml->error );
104
				$return      = false;
105
			}
106
		}
107
108
		return $return;
109
	}
110
111
	/**
112
	 * Get iDEAL issuers
113
	 *
114
	 * @since 1.2.0
115
	 */
116
	public function get_ideal_issuers( $merchant ) {
117
		$return = false;
118
119
		$request = new IDealIssuersRequestMessage( $merchant );
120
121
		$response = $this->request( $request );
122
123
		if ( $response ) {
124
			$return = $response->issuers;
0 ignored issues
show
The property issuers does not seem to exist on Pronamic\WordPress\Pay\G...L\StatusResponseMessage.
Loading history...
The property issuers does not seem to exist on Pronamic\WordPress\Pay\G...nsactionResponseMessage.
Loading history...
The property issuers does not exist on Pronamic\WordPress\Pay\G...nsactionResponseMessage. Did you mean issuer_id?
Loading history...
The property issuers does not seem to exist on Pronamic\WordPress\Pay\G...GatewaysResponseMessage.
Loading history...
125
		}
126
127
		return $return;
128
	}
129
130
	/**
131
	 * Get gateways
132
	 *
133
	 * @since 1.2.0
134
	 */
135
	public function get_gateways( $merchant, $customer ) {
136
		$return = false;
137
138
		$request = new GatewaysRequestMessage( $merchant, $customer );
139
140
		$response = $this->request( $request );
141
142
		if ( $response ) {
143
			$return = $response->gateways;
0 ignored issues
show
The property gateways does not exist on Pronamic\WordPress\Pay\G...nsactionResponseMessage. Did you mean gateway_info?
Loading history...
The property gateways does not seem to exist on Pronamic\WordPress\Pay\G...lIssuersResponseMessage.
Loading history...
The property gateways does not seem to exist on Pronamic\WordPress\Pay\G...nsactionResponseMessage.
Loading history...
The property gateways does not seem to exist on Pronamic\WordPress\Pay\G...L\StatusResponseMessage.
Loading history...
144
		}
145
146
		return $return;
147
	}
148
149
	/**
150
	 * Start transaction
151
	 *
152
	 * @param array $message
153
	 */
154
	public function start_transaction( $message ) {
155
		$return = false;
156
157
		$response = $this->request( $message );
158
159
		if ( $response ) {
160
			$return = $response;
161
		}
162
163
		return $return;
164
	}
165
166
	/**
167
	 * Get status
168
	 *
169
	 * @param array $message
170
	 */
171
	public function get_status( $message ) {
172
		$return = false;
173
174
		$response = $this->request( $message );
175
176
		if ( $response ) {
177
			$return = $response;
178
		}
179
180
		return $return;
181
	}
182
}
183