1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Payment session request |
4
|
|
|
* |
5
|
|
|
* @author Pronamic <[email protected]> |
6
|
|
|
* @copyright 2005-2020 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
|
|
|
/** |
14
|
|
|
* Payment session request |
15
|
|
|
* |
16
|
|
|
* @link https://docs.adyen.com/api-explorer/#/PaymentSetupAndVerificationService/v41/paymentSession |
17
|
|
|
* |
18
|
|
|
* @author Remco Tolsma |
19
|
|
|
* @version 1.0.5 |
20
|
|
|
* @since 1.0.0 |
21
|
|
|
*/ |
22
|
|
|
class PaymentSessionRequest extends AbstractPaymentRequest { |
23
|
|
|
/** |
24
|
|
|
* Allowed payment methods. |
25
|
|
|
* |
26
|
|
|
* List of payments methods to be presented to the shopper. To refer to payment methods, |
27
|
|
|
* use their brandCode from https://docs.adyen.com/developers/payment-methods/payment-methods-overview |
28
|
|
|
* |
29
|
|
|
* @var array<int, string>|null |
30
|
|
|
*/ |
31
|
|
|
private $allowed_payment_methods; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Origin. |
35
|
|
|
* |
36
|
|
|
* Required for the Web integration. Set this parameter to the |
37
|
|
|
* origin URL of the page that you are loading the SDK from. |
38
|
|
|
* |
39
|
|
|
* @var string|null |
40
|
|
|
*/ |
41
|
|
|
private $origin; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* SDK version. |
45
|
|
|
* |
46
|
|
|
* @var string|null |
47
|
|
|
*/ |
48
|
|
|
private $sdk_version; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Construct a payment request object. |
52
|
|
|
* |
53
|
|
|
* @param Amount $amount The amount information for the transaction. |
54
|
|
|
* @param string $merchant_account The merchant account identifier, with which you want to process the transaction. |
55
|
|
|
* @param string $reference The reference to uniquely identify a payment. |
56
|
|
|
* @param string $return_url The URL to return to. |
57
|
|
|
* @param string $country_code The collection that contains the type of the payment method and its specific information (e.g. idealIssuer). |
58
|
|
|
*/ |
59
|
5 |
|
public function __construct( Amount $amount, $merchant_account, $reference, $return_url, $country_code ) { |
60
|
5 |
|
parent::__construct( $amount, $merchant_account, $reference, $return_url ); |
61
|
|
|
|
62
|
5 |
|
$this->set_country_code( $country_code ); |
63
|
4 |
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get allowed payment methods. |
67
|
|
|
* |
68
|
|
|
* @return array<int, string>|null |
69
|
|
|
*/ |
70
|
1 |
|
public function get_allowed_payment_methods() { |
71
|
1 |
|
return $this->allowed_payment_methods; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Set allowed payment methods. |
76
|
|
|
* |
77
|
|
|
* @param array<int, string>|null $allowed_payment_methods Allowed payment methods. |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
2 |
|
public function set_allowed_payment_methods( $allowed_payment_methods ) { |
81
|
2 |
|
$this->allowed_payment_methods = $allowed_payment_methods; |
82
|
2 |
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get origin. |
86
|
|
|
* |
87
|
|
|
* @return string|null |
88
|
|
|
*/ |
89
|
1 |
|
public function get_origin() { |
90
|
1 |
|
return $this->origin; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Set origin. |
95
|
|
|
* |
96
|
|
|
* @param string|null $origin Origin. |
97
|
|
|
* @return void |
98
|
|
|
*/ |
99
|
2 |
|
public function set_origin( $origin ) { |
100
|
2 |
|
$this->origin = $origin; |
101
|
2 |
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Get SDK version. |
105
|
|
|
* |
106
|
|
|
* @return string|null |
107
|
|
|
*/ |
108
|
1 |
|
public function get_sdk_version() { |
109
|
1 |
|
return $this->sdk_version; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Set SDK version. |
114
|
|
|
* |
115
|
|
|
* @param string|null $sdk_version SDK version. |
116
|
|
|
* @return void |
117
|
|
|
*/ |
118
|
2 |
|
public function set_sdk_version( $sdk_version ) { |
119
|
2 |
|
$this->sdk_version = $sdk_version; |
120
|
2 |
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Get JSON. |
124
|
|
|
* |
125
|
|
|
* @return object |
126
|
|
|
*/ |
127
|
3 |
|
public function get_json() { |
128
|
3 |
|
$object = parent::get_json(); |
129
|
|
|
|
130
|
3 |
|
$properties = (array) $object; |
131
|
|
|
|
132
|
|
|
// Optional. |
133
|
3 |
|
$optional = Util::filter_null( |
134
|
|
|
array( |
135
|
3 |
|
'allowedPaymentMethods' => $this->allowed_payment_methods, |
136
|
3 |
|
'origin' => $this->origin, |
137
|
3 |
|
'sdkVersion' => $this->sdk_version, |
138
|
|
|
) |
139
|
|
|
); |
140
|
|
|
|
141
|
3 |
|
$properties = array_merge( $properties, $optional ); |
142
|
|
|
|
143
|
|
|
// Return object. |
144
|
3 |
|
$object = (object) $properties; |
145
|
|
|
|
146
|
3 |
|
return $object; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|