/** * @param Request $request * @return Notification */ public static function createFromRequest(Request $request) { $notification = new Notification(); $parsed = Json::decode($request->getRawBody()); $notification->setLive($parsed->live === 'true'); $items = array(); foreach ($parsed->notificationItems as $rawItem) { $item = new NotificationRequestItem($notification); $item->setAdditionalData(self::getNotificationRequestItemValue($rawItem, 'additionalData')); $item->setAmountValue(self::getNotificationRequestItemValue($rawItem, 'amount.value')); $item->setAmountCurrency(self::getNotificationRequestItemValue($rawItem, 'amount.currency')); $item->setPspReference(self::getNotificationRequestItemValue($rawItem, 'pspReference')); $item->setEventCode(self::getNotificationRequestItemValue($rawItem, 'eventCode')); $date = new DateTime(self::getNotificationRequestItemValue($rawItem, 'eventDate')); $item->setEventDate($date); $item->setMerchantAccountCode(self::getNotificationRequestItemValue($rawItem, 'merchantAccountCode')); $item->setOperations(self::getNotificationRequestItemValue($rawItem, 'operations')); $item->setMerchantReference(self::getNotificationRequestItemValue($rawItem, 'merchantReference')); $item->setOriginalReference(self::getNotificationRequestItemValue($rawItem, 'originalReference')); $item->setPaymentMethod(self::getNotificationRequestItemValue($rawItem, 'paymentMethod')); $item->setReason(self::getNotificationRequestItemValue($rawItem, 'reason')); $item->setSuccess(self::getNotificationRequestItemValue($rawItem, 'success') === 'true'); $items[] = $item; } $notification->setNotificationItems($items); return $notification; }
public function handleNotification(Request $request) { $notification = Notification::createFromRequest($request); if ($notification->isLive() !== $this->adyen->isLive()) { // test notification on live environment or vice versa throw new AdyenException('Received notification is from test environment but extension is in live mode'); } foreach ($notification->getNotificationItems() as $item) { /** @var NotificationRequestItem $item */ if (isset($item->getAdditionalData()->hmacSignature)) { $signature = $item->getAdditionalData()->hmacSignature; // check signature $signatureGenerator = $this->adyen->getSignaturesGenerator(); $generated = $signatureGenerator->generateNotificationSignature($item); if ($signature !== $generated) { throw new InvalidSignatureException($item); } } else { // some reaction to processing not signed notification if (!$this->adyen->acceptUnsignedNotifications()) { throw new InvalidNotificationException('Received notification is unsigned but extension is configured to accept only signed notifications', 0, $item); } } $this->onNotification($this, $item); // standard process of notification if (!$item->isSuccess()) { $this->onFailed($this, $item); //onProblem, //onIssue continue; } $this->onSuccess($this, $item); if ($item->isAuthorised()) { $this->onAuthorised($this, $item); } elseif ($item->isCancelled()) { $this->onCancelled($this, $item); } elseif ($item->isRefund()) { $this->onRefund($this, $item); } else { $this->onOther($this, $item); } } }