Failed Conditions
Push — develop ( d3c138...9b3794 )
by Remco
03:44
created

PaymentResponse::get_psp_reference()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Payment response
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2019 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\Adyen
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Adyen;
12
13
use JsonSchema\Constraints\Constraint;
14
use JsonSchema\Exception\ValidationException;
15
use JsonSchema\Validator;
16
17
/**
18
 * Payment response
19
 *
20
 * @link https://docs.adyen.com/api-explorer/#/PaymentSetupAndVerificationService/v41/payments
21
 *
22
 * @author  Remco Tolsma
23
 * @version 1.0.0
24
 * @since   1.0.0
25
 */
26
class PaymentResponse {
27
	/**
28
	 * This field contains additional data, which may be required to return in a particular payment response.
29
	 *
30
	 * @var object|null
31
	 */
32
	private $additional_data;
0 ignored issues
show
introduced by
The private property $additional_data is not used, and could be removed.
Loading history...
33
34
	/**
35
	 * When non-empty, contains all the fields that you must submit to the `/payments/details` endpoint.
36
	 *
37
	 * @var array|null
38
	 */
39
	private $details;
0 ignored issues
show
introduced by
The private property $details is not used, and could be removed.
Loading history...
40
41
	/**
42
	 * The fraud result properties of the payment
43
	 *
44
	 * @var object|null
45
	 */
46
	private $fraud_result;
0 ignored issues
show
introduced by
The private property $fraud_result is not used, and could be removed.
Loading history...
47
48
	/**
49
	 * Contains the details that will be presented to the shopper
50
	 *
51
	 * @var object|null
52
	 */
53
	private $output_details;
0 ignored issues
show
introduced by
The private property $output_details is not used, and could be removed.
Loading history...
54
55
	/**
56
	 * When non-empty, contains a value that you must submit to the `/payments/details` endpoint.
57
	 *
58
	 * @var string|null
59
	 */
60
	private $payment_data;
0 ignored issues
show
introduced by
The private property $payment_data is not used, and could be removed.
Loading history...
61
62
	/**
63
	 * Adyen's 16-character string reference associated with the transaction/request. This value is globally unique; quote it when communicating with us about this request.
64
	 *
65
	 * `pspReference` is returned only for non-redirect payment methods.
66
	 *
67
	 * @var string|null
68
	 */
69
	private $psp_reference;
70
71
	/**
72
	 * When the payment flow requires a redirect, this object contains information about the redirect URL.
73
	 *
74
	 * @var RedirectInformation|null
75
	 */
76
	private $redirect;
77
78
	/**
79
	 * If the payment's authorisation is refused or an error occurs during authorisation, this field holds Adyen's mapped reason for the refusal or a description of the error.
80
	 *
81
	 * When a transaction fails, the authorisation response includes `resultCode` and `refusalReason` values.
82
	 *
83
	 * @var string|null
84
	 */
85
	private $refusal_reason;
0 ignored issues
show
introduced by
The private property $refusal_reason is not used, and could be removed.
Loading history...
86
87
	/**
88
	 * Code that specifies the refusal reason.
89
	 *
90
	 * @var string|null
91
	 */
92
	private $refusal_reason_code;
0 ignored issues
show
introduced by
The private property $refusal_reason_code is not used, and could be removed.
Loading history...
93
94
	/**
95
	 * The result of the payment.
96
	 *
97
	 * @var string
98
	 */
99
	private $result_code;
100
101
	/**
102
	 * Construct payment response object.
103
	 *
104
	 * @param string $result_code Result code.
105
	 */
106 1
	public function __construct( $result_code ) {
107 1
		$this->result_code = $result_code;
108 1
	}
109
110
	/**
111
	 * Get result code.
112
	 *
113
	 * @return string
114
	 */
115 1
	public function get_result_code() {
116 1
		return $this->result_code;
117
	}
118
119
	/**
120
	 * Get PSP reference.
121
	 *
122
	 * @return string|null
123
	 */
124
	public function get_psp_reference() {
125
		return $this->psp_reference;
126
	}
127
128
	/**
129
	 * Set PSP reference.
130
	 *
131
	 * @param string|null $psp_reference PSP reference.
132
	 */
133
	public function set_psp_reference( $psp_reference ) {
134
		$this->psp_reference = $psp_reference;
135
	}
136
137
	/**
138
	 * Get redirect.
139
	 *
140
	 * @return RedirectInformation|null
141
	 */
142 1
	public function get_redirect() {
143 1
		return $this->redirect;
144
	}
145
146
	/**
147
	 * Set redirect.
148
	 *
149
	 * @param RedirectInformation|null $redirect Redirect information.
150
	 */
151 1
	public function set_redirect( RedirectInformation $redirect = null ) {
152 1
		$this->redirect = $redirect;
153 1
	}
154
155
	/**
156
	 * Create payment repsonse from object.
157
	 *
158
	 * @param object $object Object.
159
	 * @return PaymentResponse
160
	 * @throws InvalidArgumentException Throws invalid argument exception when object does not contains the required properties.
161
	 */
162 1
	public static function from_object( $object ) {
163 1
		$validator = new Validator();
164
165 1
		$validator->validate(
166 1
			$object,
167
			(object) array(
168 1
				'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/payment-response.json' ),
169
			),
170 1
			Constraint::CHECK_MODE_EXCEPTIONS
171
		);
172
173 1
		$payment_response = new self( $object->resultCode );
174
175 1
		if ( isset( $object->pspReference ) ) {
176
			$payment_response->set_psp_reference( $object->pspReference );
177
		}
178
179 1
		if ( isset( $object->redirect ) ) {
180 1
			$payment_response->set_redirect( RedirectInformation::from_object( $object->redirect ) );
181
		}
182
183 1
		return $payment_response;
184
	}
185
}
186