33namespace Omnipay \AuthorizeNetApi \Message ;
44
55/**
6- *
6+ * TODO: validate the server request signature.
77 */
88
99use Omnipay \Common \Message \NotificationInterface ;
1313
1414use Omnipay \AuthorizeNetApi \Traits \HasGatewayParams ;
1515use Academe \AuthorizeNet \ServerRequest \Notification ;
16+ use Academe \AuthorizeNet \Response \Model \TransactionResponse ;
1617
1718class AcceptNotification extends AbstractRequest implements NotificationInterface //, RequestInterface
1819{
@@ -25,8 +26,6 @@ class AcceptNotification extends AbstractRequest implements NotificationInterfac
2526 */
2627 protected $ parsedData ;
2728
28- protected $ notification ;
29-
3029 public function __construct (ClientInterface $ httpClient , HttpRequest $ httpRequest )
3130 {
3231 // The request is a \Symfony/Component/HttpFoundation/Request object
@@ -77,7 +76,9 @@ public function getData()
7776 */
7877 public function getTransactionReference ()
7978 {
80- // TODO.
79+ if ($ this ->getEventTarget () === $ this ->getParsedData ()::EVENT_TARGET_PAYMENT ) {
80+ return $ this ->getPayload ()->getTransId ();
81+ }
8182 }
8283
8384 /**
@@ -88,7 +89,15 @@ public function getTransactionReference()
8889 */
8990 public function getTransactionStatus ()
9091 {
91- // TODO.
92+ $ responseCode = $ this ->getResponseCode ();
93+
94+ if ($ responseCode === TransactionResponse::RESPONSE_CODE_APPROVED ) {
95+ return static ::STATUS_COMPLETED ;
96+ } elseif ($ responseCode === TransactionResponse::RESPONSE_CODE_PENDING ) {
97+ return static ::STATUS_PENDIND ;
98+ } elseif ($ responseCode !== null ) {
99+ return static ::STATUS_FAILED ;
100+ }
92101 }
93102
94103 /**
@@ -98,7 +107,8 @@ public function getTransactionStatus()
98107 */
99108 public function getMessage ()
100109 {
101- // TODO.
110+ // There are actually no messages in the notifications.
111+ return '' ;
102112 }
103113
104114 /**
@@ -112,4 +122,92 @@ public function sendData($data)
112122 {
113123 return $ this ;
114124 }
125+
126+ /**
127+ * The main target of the notificaiton: payment or customer.
128+ */
129+ public function getEventTarget ()
130+ {
131+ return $ this ->getParsedData ()->getEventTarget ();
132+ }
133+
134+ /**
135+ * The sub-target of the notificaiton.
136+ */
137+ public function getEventSubtarget ()
138+ {
139+ return $ this ->getParsedData ()->getEventSubtarget ();
140+ }
141+
142+ /**
143+ * The action against the target of the notificaito.
144+ */
145+ public function getEventAction ()
146+ {
147+ return $ this ->getParsedData ()->getEventAction ();
148+ }
149+
150+ /**
151+ * The UUID identifying this specific notification.
152+ */
153+ public function getNotificationId ()
154+ {
155+ return $ this ->getParsedData ()->getNotificationId ();
156+ }
157+
158+ /**
159+ * The UUID identifying the webhook being fired.
160+ */
161+ public function getWebhookId ()
162+ {
163+ return $ this ->getParsedData ()->getWebhookId ();
164+ }
165+
166+ /**
167+ * Optional notification payload.
168+ */
169+ public function getPayload ()
170+ {
171+ return $ this ->getParsedData ()->getPayload ();
172+ }
173+
174+ /**
175+ * @return int Raw response code
176+ */
177+ public function getResponseCode ()
178+ {
179+ if ($ this ->getEventTarget () === $ this ->getParsedData ()::EVENT_TARGET_PAYMENT ) {
180+ return $ this ->getPayload ()->getResponseCode ();
181+ }
182+ }
183+
184+ /**
185+ * @return string Raw response code
186+ */
187+ public function getAuthCode ()
188+ {
189+ if ($ this ->getEventTarget () === $ this ->getParsedData ()::EVENT_TARGET_PAYMENT ) {
190+ return $ this ->getPayload ()->getAuthCode ();
191+ }
192+ }
193+
194+ /**
195+ * @return string Raw AVS response code
196+ */
197+ public function getAvsResponse ()
198+ {
199+ if ($ this ->getEventTarget () === $ this ->getParsedData ()::EVENT_TARGET_PAYMENT ) {
200+ return $ this ->getPayload ()->getAvsResponse ();
201+ }
202+ }
203+
204+ /**
205+ * @return float authAmount, no currency, no stated units
206+ */
207+ public function getAuthAmount ()
208+ {
209+ if ($ this ->getEventTarget () === $ this ->getParsedData ()::EVENT_TARGET_PAYMENT ) {
210+ return $ this ->getPayload ()->getAuthAmount ();
211+ }
212+ }
115213}
0 commit comments