|
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
|
|
|
* Create notification request item from object. |
|
93
|
|
|
* |
|
94
|
|
|
* @param object $object Object. |
|
95
|
|
|
* @return NotificationRequestItem |
|
96
|
|
|
* @throws InvalidArgumentException Throws invalid argument exception when object does not contains the required properties. |
|
97
|
|
|
*/ |
|
98
|
1 |
|
public static function from_object( $object ) { |
|
99
|
1 |
|
if ( ! isset( $object->amount ) ) { |
|
100
|
|
|
throw new InvalidArgumentException( 'Object must contain `amount` property.' ); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
1 |
|
if ( ! isset( $object->pspReference ) ) { |
|
104
|
|
|
throw new InvalidArgumentException( 'Object must contain `pspReference` property.' ); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
1 |
|
if ( ! isset( $object->eventCode ) ) { |
|
108
|
|
|
throw new InvalidArgumentException( 'Object must contain `eventCode` property.' ); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
1 |
|
if ( ! isset( $object->eventDate ) ) { |
|
112
|
|
|
throw new InvalidArgumentException( 'Object must contain `eventDate` property.' ); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
1 |
|
if ( ! isset( $object->merchantAccountCode ) ) { |
|
116
|
|
|
throw new InvalidArgumentException( 'Object must contain `merchantAccountCode` property.' ); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
1 |
|
if ( ! isset( $object->operations ) ) { |
|
120
|
|
|
throw new InvalidArgumentException( 'Object must contain `operations` property.' ); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
1 |
|
if ( ! isset( $object->merchantReference ) ) { |
|
124
|
|
|
throw new InvalidArgumentException( 'Object must contain `merchantReference` property.' ); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
1 |
|
if ( ! isset( $object->paymentMethod ) ) { |
|
128
|
|
|
throw new InvalidArgumentException( 'Object must contain `paymentMethod` property.' ); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
1 |
|
if ( ! isset( $object->success ) ) { |
|
132
|
|
|
throw new InvalidArgumentException( 'Object must contain `success` property.' ); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
1 |
|
if ( ! is_array( $object->operations ) ) { |
|
136
|
|
|
throw new InvalidArgumentException( 'Object property `operations` must be an array.' ); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
1 |
|
$item = new self(); |
|
140
|
|
|
|
|
141
|
1 |
|
return $item; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|