wp-pay-gateways /
adyen
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Notification request item |
||
| 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 DateTime; |
||
| 14 | use InvalidArgumentException; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Notification request item |
||
| 18 | * |
||
| 19 | * @link https://docs.adyen.com/developers/api-reference/notifications-api#notificationrequestitem |
||
| 20 | * @author Remco Tolsma |
||
| 21 | * @version 1.0.0 |
||
| 22 | * @since 1.0.0 |
||
| 23 | */ |
||
| 24 | class NotificationRequestItem { |
||
| 25 | /** |
||
| 26 | * Amount. |
||
| 27 | * |
||
| 28 | * @var Amount |
||
| 29 | */ |
||
| 30 | private $amount; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Adyen's 16-character unique reference associated with the transaction/the request. This value is globally unique; quote it when communicating with us about this request. |
||
| 34 | * |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | private $psp_reference; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * The type of event the notification item refers to. |
||
| 41 | * |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | private $event_code; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * The time when the event was generated. |
||
| 48 | * |
||
| 49 | * @var DateTime |
||
| 50 | */ |
||
| 51 | private $event_date; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * The merchant account identifier used in the transaction the notification item refers to. |
||
| 55 | * |
||
| 56 | * @var string |
||
| 57 | */ |
||
| 58 | private $merchant_account_code; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * This field holds a list of the modification operations supported by the transaction the notification item refers to. |
||
| 62 | * |
||
| 63 | * @var array |
||
| 64 | */ |
||
| 65 | private $operations; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * A reference to uniquely identify the payment. |
||
| 69 | * |
||
| 70 | * @var string |
||
| 71 | */ |
||
| 72 | private $merchant_reference; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * The payment method used in the transaction the notification item refers to. |
||
| 76 | * |
||
| 77 | * @var string |
||
| 78 | */ |
||
| 79 | private $payment_method; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Informs about the outcome of the event (`eventCode`) the notification refers to: |
||
| 83 | * |
||
| 84 | * - `true`: the event (`eventCode`) the notification refers to was executed successfully. |
||
| 85 | * - `false`: the event was not executed successfully. |
||
| 86 | * |
||
| 87 | * @var boolean |
||
| 88 | */ |
||
| 89 | private $success; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Get amount. |
||
| 93 | * |
||
| 94 | * @return Amount |
||
| 95 | */ |
||
| 96 | public function get_amount() { |
||
| 97 | return $this->amount; |
||
| 98 | } |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Set amount. |
||
| 102 | * |
||
| 103 | * @param Amount $amount Amount. |
||
| 104 | */ |
||
| 105 | 1 | public function set_amount( Amount $amount ) { |
|
| 106 | 1 | $this->amount = $amount; |
|
| 107 | 1 | } |
|
| 108 | |||
| 109 | /** |
||
| 110 | * Get PSP reference. |
||
| 111 | * |
||
| 112 | * @return string |
||
| 113 | */ |
||
| 114 | 1 | public function get_psp_reference() { |
|
| 115 | 1 | return $this->psp_reference; |
|
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Set PSP reference. |
||
| 120 | * |
||
| 121 | * @param string $psp_reference PSP reference. |
||
| 122 | */ |
||
| 123 | 1 | public function set_psp_reference( $psp_reference ) { |
|
| 124 | 1 | $this->psp_reference = $psp_reference; |
|
| 125 | 1 | } |
|
| 126 | |||
| 127 | /** |
||
| 128 | * Get event code. |
||
| 129 | * |
||
| 130 | * @return Amount |
||
| 131 | */ |
||
| 132 | 1 | public function get_event_code() { |
|
| 133 | 1 | return $this->event_code; |
|
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 134 | } |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Set event code. |
||
| 138 | * |
||
| 139 | * @param string $event_code Event code. |
||
| 140 | */ |
||
| 141 | 1 | public function set_event_code( $event_code ) { |
|
| 142 | 1 | $this->event_code = $event_code; |
|
| 143 | 1 | } |
|
| 144 | |||
| 145 | /** |
||
| 146 | * Get event date. |
||
| 147 | * |
||
| 148 | * @return DateTime |
||
| 149 | */ |
||
| 150 | 1 | public function get_event_date() { |
|
| 151 | 1 | return $this->event_date; |
|
| 152 | } |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Set event date. |
||
| 156 | * |
||
| 157 | * @param DateTime $event_date Event date. |
||
| 158 | */ |
||
| 159 | 1 | public function set_event_date( DateTime $event_date ) { |
|
| 160 | 1 | $this->event_date = $event_date; |
|
| 161 | 1 | } |
|
| 162 | |||
| 163 | /** |
||
| 164 | * Get merchant account code. |
||
| 165 | * |
||
| 166 | * @return DateTime |
||
| 167 | */ |
||
| 168 | 1 | public function get_merchant_account_code() { |
|
| 169 | 1 | return $this->merchant_account_code; |
|
|
0 ignored issues
–
show
|
|||
| 170 | } |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Set merchant account code. |
||
| 174 | * |
||
| 175 | * @param string $merchant_account_code Merchant account code. |
||
| 176 | */ |
||
| 177 | 1 | public function set_merchant_account_code( $merchant_account_code ) { |
|
| 178 | 1 | $this->merchant_account_code = $merchant_account_code; |
|
| 179 | 1 | } |
|
| 180 | |||
| 181 | /** |
||
| 182 | * Get operations. |
||
| 183 | * |
||
| 184 | * @return array |
||
| 185 | */ |
||
| 186 | 1 | public function get_operations() { |
|
| 187 | 1 | return $this->operations; |
|
| 188 | } |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Set operations. |
||
| 192 | * |
||
| 193 | * @param array $operations Operations. |
||
| 194 | */ |
||
| 195 | 1 | public function set_operations( $operations ) { |
|
| 196 | 1 | $this->operations = $operations; |
|
| 197 | 1 | } |
|
| 198 | |||
| 199 | /** |
||
| 200 | * Get operations. |
||
| 201 | * |
||
| 202 | * @return array |
||
| 203 | */ |
||
| 204 | 1 | public function get_merchant_reference() { |
|
| 205 | 1 | return $this->merchant_reference; |
|
|
0 ignored issues
–
show
|
|||
| 206 | } |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Set merchant reference. |
||
| 210 | * |
||
| 211 | * @param string $merchant_reference Merchant reference. |
||
| 212 | */ |
||
| 213 | 1 | public function set_merchant_reference( $merchant_reference ) { |
|
| 214 | 1 | $this->merchant_reference = $merchant_reference; |
|
| 215 | 1 | } |
|
| 216 | |||
| 217 | /** |
||
| 218 | * Get payment method. |
||
| 219 | * |
||
| 220 | * @return string |
||
| 221 | */ |
||
| 222 | 1 | public function get_payment_method() { |
|
| 223 | 1 | return $this->payment_method; |
|
| 224 | } |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Set payment method. |
||
| 228 | * |
||
| 229 | * @param string $payment_method Payment method. |
||
| 230 | */ |
||
| 231 | 1 | public function set_payment_method( $payment_method ) { |
|
| 232 | 1 | $this->payment_method = $payment_method; |
|
| 233 | 1 | } |
|
| 234 | |||
| 235 | /** |
||
| 236 | * Is success. |
||
| 237 | * |
||
| 238 | * @return boolean |
||
| 239 | */ |
||
| 240 | 1 | public function is_success() { |
|
| 241 | 1 | return $this->success; |
|
| 242 | } |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Set success. |
||
| 246 | * |
||
| 247 | * @param boolean $success Success. |
||
| 248 | */ |
||
| 249 | 1 | public function set_success( $success ) { |
|
| 250 | 1 | $this->success = $success; |
|
| 251 | 1 | } |
|
| 252 | |||
| 253 | /** |
||
| 254 | * Create notification request item from object. |
||
| 255 | * |
||
| 256 | * @param object $object Object. |
||
| 257 | * @return NotificationRequestItem |
||
| 258 | * @throws InvalidArgumentException Throws invalid argument exception when object does not contains the required properties. |
||
| 259 | */ |
||
| 260 | 1 | public static function from_object( $object ) { |
|
| 261 | 1 | if ( ! isset( $object->amount ) ) { |
|
| 262 | throw new InvalidArgumentException( 'Object must contain `amount` property.' ); |
||
| 263 | } |
||
| 264 | |||
| 265 | 1 | if ( ! isset( $object->pspReference ) ) { |
|
| 266 | throw new InvalidArgumentException( 'Object must contain `pspReference` property.' ); |
||
| 267 | } |
||
| 268 | |||
| 269 | 1 | if ( ! isset( $object->eventCode ) ) { |
|
| 270 | throw new InvalidArgumentException( 'Object must contain `eventCode` property.' ); |
||
| 271 | } |
||
| 272 | |||
| 273 | 1 | if ( ! isset( $object->eventDate ) ) { |
|
| 274 | throw new InvalidArgumentException( 'Object must contain `eventDate` property.' ); |
||
| 275 | } |
||
| 276 | |||
| 277 | 1 | if ( ! isset( $object->merchantAccountCode ) ) { |
|
| 278 | throw new InvalidArgumentException( 'Object must contain `merchantAccountCode` property.' ); |
||
| 279 | } |
||
| 280 | |||
| 281 | 1 | if ( ! isset( $object->operations ) ) { |
|
| 282 | throw new InvalidArgumentException( 'Object must contain `operations` property.' ); |
||
| 283 | } |
||
| 284 | |||
| 285 | 1 | if ( ! isset( $object->merchantReference ) ) { |
|
| 286 | throw new InvalidArgumentException( 'Object must contain `merchantReference` property.' ); |
||
| 287 | } |
||
| 288 | |||
| 289 | 1 | if ( ! isset( $object->paymentMethod ) ) { |
|
| 290 | throw new InvalidArgumentException( 'Object must contain `paymentMethod` property.' ); |
||
| 291 | } |
||
| 292 | |||
| 293 | 1 | if ( ! isset( $object->success ) ) { |
|
| 294 | throw new InvalidArgumentException( 'Object must contain `success` property.' ); |
||
| 295 | } |
||
| 296 | |||
| 297 | 1 | if ( ! is_array( $object->operations ) ) { |
|
| 298 | throw new InvalidArgumentException( 'Object property `operations` must be an array.' ); |
||
| 299 | } |
||
| 300 | |||
| 301 | 1 | $item = new self(); |
|
| 302 | |||
| 303 | 1 | $item->set_amount( Amount::from_object( $object->amount ) ); |
|
| 304 | 1 | $item->set_psp_reference( $object->pspReference ); |
|
| 305 | 1 | $item->set_event_code( $object->eventCode ); |
|
| 306 | 1 | $item->set_event_date( new DateTime( $object->eventDate ) ); |
|
| 307 | 1 | $item->set_merchant_account_code( $object->merchantAccountCode ); |
|
| 308 | 1 | $item->set_operations( $object->operations ); |
|
| 309 | 1 | $item->set_merchant_reference( $object->merchantReference ); |
|
| 310 | 1 | $item->set_payment_method( $object->paymentMethod ); |
|
| 311 | 1 | $item->set_success( filter_var( $object->success, FILTER_VALIDATE_BOOLEAN ) ); |
|
| 312 | |||
| 313 | 1 | return $item; |
|
| 314 | } |
||
| 315 | } |
||
| 316 |