Request::get_parameter()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * Request
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2022 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Payments
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Sisow;
12
13
/**
14
 * Title: iDEAL Sisow transaction request
15
 * Description:
16
 * Copyright: Copyright (c) 2015
17
 * Company: Pronamic
18
 *
19
 * @author  Remco Tolsma
20
 * @version 2.0.0
21
 * @since   1.0.0
22
 */
23
class Request {
24
	/**
25
	 * Parameters.
26
	 *
27
	 * @var array<string,int|string|null>
28
	 */
29
	private $parameters = array();
30
31
	/**
32
	 * Construct request.
33
	 *
34
	 * @param string      $merchant_id    Merchant ID.
35
	 * @param string|null $shop_id        Shop ID.
36
	 */
37 2
	public function __construct( $merchant_id, $shop_id = null ) {
38 2
		$this->set_parameter( 'merchantid', $merchant_id );
39 2
		$this->set_parameter( 'shopid', $shop_id );
40 2
	}
41
42
	/**
43
	 * Get parameter.
44
	 *
45
	 * @param string $parameter Parameter.
46
	 * @return int|string|null
47
	 */
48 2
	public function get_parameter( $parameter ) {
49 2
		if ( isset( $this->parameters[ $parameter ] ) ) {
50 2
			return $this->parameters[ $parameter ];
51
		}
52
53 2
		return null;
54
	}
55
56
	/**
57
	 * Set parameter.
58
	 *
59
	 * @param string          $parameter Parameter.
60
	 * @param int|string|null $value     Value.
61
	 * @return void
62
	 */
63 2
	public function set_parameter( $parameter, $value ) {
64 2
		$this->parameters[ $parameter ] = $value;
65 2
	}
66
67
	/**
68
	 * Get parameters.
69
	 *
70
	 * @return array<string,int|string|null>
71
	 */
72
	public function get_parameters() {
73
		return $this->parameters;
74
	}
75
76
	/**
77
	 * Merge parameters.
78
	 *
79
	 * @param array<string,int|string|null> $parameters Parameters.
80
	 * @return void
81
	 */
82
	public function merge_parameters( $parameters ) {
83
		$this->parameters = array_merge( $this->parameters, $parameters );
84
	}
85
86
	/**
87
	 * Get signature data.
88
	 *
89
	 * @return array<int,int|string|null>
90
	 */
91
	public function get_signature_data() {
92
		return array();
93
	}
94
95
	/**
96
	 * Get signature.
97
	 *
98
	 * @param string $merchant_key Merchant key.
99
	 * @return string
100
	 */
101 2
	public function get_signature( $merchant_key ) {
102 2
		$data = $this->get_signature_data();
103
104 2
		$data[] = $merchant_key;
105
106 2
		$string = implode( '', $data );
107
108 2
		$signature = sha1( $string );
109
110 2
		return $signature;
111
	}
112
113
	/**
114
	 * Sign this request with the specified merchant key.
115
	 *
116
	 * @param string $merchant_key Merchant key.
117
	 * @return void
118
	 */
119
	public function sign( $merchant_key ) {
120
		$signature = $this->get_signature( $merchant_key );
121
122
		$this->set_parameter( 'sha1', $signature );
123
	}
124
}
125