Failed Conditions
Push — develop ( 79532f...94eaa0 )
by Remco
03:25
created

PaymentResultResponse::set_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 1
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 result 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 InvalidArgumentException;
14
15
/**
16
 * Payment result response
17
 *
18
 * @link https://docs.adyen.com/api-explorer/#/PaymentSetupAndVerificationService/v41/payments/result
19
 *
20
 * @author  Remco Tolsma
21
 * @version 1.0.0
22
 * @since   1.0.0
23
 */
24
class PaymentResultResponse extends ResponseObject {
25
	/**
26
	 * A unique value that you provided in the initial `/paymentSession` request as a `reference` field.
27
	 *
28
	 * @var string
29
	 */
30
	private $merchant_reference;
31
32
	/**
33
	 * The payment method used in the transaction.
34
	 *
35
	 * @var string
36
	 */
37
	private $payment_method;
38
39
	/**
40
	 * The result of the payment.
41
	 *
42
	 * @var string|null
43
	 */
44
	private $result_code;
45
46
	/**
47
	 * 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.
48
	 *
49
	 * @var string|null
50
	 */
51
	private $psp_reference;
52
53
	/**
54
	 * Construct payment result response object.
55
	 *
56
	 * @param string $merchant_reference Merchant reference.
57
	 * @param string $payment_method     Payment method.
58
	 */
59
	public function __construct( $merchant_reference, $payment_method ) {
60
		$this->merchant_reference = $merchant_reference;
61
		$this->payment_method     = $payment_method;
62
	}
63
64
	/**
65
	 * Get merchant reference.
66
	 *
67
	 * @return string
68
	 */
69
	public function get_merchant_reference() {
70
		return $this->merchant_reference;
71
	}
72
73
	/**
74
	 * Get result code.
75
	 *
76
	 * @return string|null
77
	 */
78
	public function get_result_code() {
79
		return $this->result_code;
80
	}
81
82
	/**
83
	 * Set result code.
84
	 *
85
	 * @param string|null $result_code Result code.
86
	 */
87
	public function set_result_code( $result_code ) {
88
		$this->result_code = $result_code;
89
	}
90
91
	/**
92
	 * Get PSP reference.
93
	 *
94
	 * @return string|null
95
	 */
96
	public function get_psp_reference() {
97
		return $this->psp_reference;
98
	}
99
100
	/**
101
	 * Set PSP reference.
102
	 *
103
	 * @param string|null $psp_reference PSP reference.
104
	 */
105
	public function set_psp_reference( $psp_reference ) {
106
		$this->psp_reference = $psp_reference;
107
	}
108
109
	/**
110
	 * Create payment result repsonse from object.
111
	 *
112
	 * @param object $object Object.
113
	 * @return PaymentResultResponse
114
	 */
115
	public static function from_object( $object ) {
116
		$response = new self(
117
			$object->merchantReference,
118
			$object->paymentMethod
119
		);
120
121
		if ( isset( $object->pspReference ) ) {
122
			$response->set_psp_reference( $object->pspReference );
123
		}
124
125
		if ( isset( $object->resultCode ) ) {
126
			$response->set_result_code( $object->resultCode );
127
		}
128
129
		$response->set_original_object( $object );
130
131
		return $response;
132
	}
133
}
134