/** * {@inheritdoc} */ public function isCallbackValid(TransactionInterface $transaction) { if (!$transaction->getOrder()) { return false; } if ($transaction->get('check') == $this->generateUrlCheck($transaction->getOrder())) { return true; } $transaction->setState(TransactionInterface::STATE_KO); $transaction->setStatusCode(TransactionInterface::STATUS_WRONG_CALLBACK); $transaction->addInformation('The callback is not valid'); return false; }
/** * {@inheritdoc} */ public function isRequestValid(TransactionInterface $transaction) { return $transaction->get('check') === $this->generateUrlCheck($transaction->getOrder()); }
/** * {@inheritdoc} */ public function callback(TransactionInterface $transaction) { // check if the order exists if (!$transaction->getOrder()) { $transaction->setStatusCode(TransactionInterface::STATUS_ORDER_UNKNOWN); $transaction->setState(TransactionInterface::STATE_KO); $transaction->setInformation('The order does not exist'); return $this->handleError($transaction); } // check if the request is valid if (!$this->isRequestValid($transaction)) { $transaction->setStatusCode(TransactionInterface::STATUS_WRONG_REQUEST); $transaction->setState(TransactionInterface::STATE_KO); $transaction->setInformation('The request is not valid'); return $this->handleError($transaction); } // check if the callback is valid if (!$this->isCallbackValid($transaction)) { $transaction->setStatusCode(TransactionInterface::STATUS_WRONG_CALLBACK); $transaction->setState(TransactionInterface::STATE_KO); $transaction->setInformation('The callback reference is not valid'); return $this->handleError($transaction); } // apply the transaction id $this->applyTransactionId($transaction); // if the order is not open, then something already happen ... (duplicate callback) if (!$transaction->getOrder()->isOpen()) { $transaction->setState(TransactionInterface::STATE_OK); // the transaction is valid, but not the order state $transaction->setStatusCode(TransactionInterface::STATUS_ORDER_NOT_OPEN); $transaction->setInformation('The order is not open, then something already happen ... (duplicate callback)'); return $this->handleError($transaction); } // send the confirmation request to the bank if (!($response = $this->sendConfirmationReceipt($transaction))) { $transaction->setInformation('Fail to send the confirmation receipt'); $response = $this->handleError($transaction); } return $response; }
/** * return true if the request contains a valid `check` parameter * * @param TransactionInterface $transaction * @return bool */ public function isRequestValid(TransactionInterface $transaction) { $checkUrl = $transaction->get('check'); $checkPrivate = $this->generateUrlCheck($transaction->getOrder()); return $checkUrl == $checkPrivate; }
/** * {@inheritdoc} */ public function sendConfirmationReceipt(TransactionInterface $transaction) { if (!$transaction->isValid()) { return new \Symfony\Component\HttpFoundation\Response(''); } $params = $transaction->getParameters(); $params['cmd'] = '_notify-validate'; //$this->getLogger()-> // retrieve the client $client = $this->getWebConnectorProvider()->getNamedClient($this->getOption('web_connector_name', 'default')); $client->request('POST', $this->getOption('url_action'), $params); if ($client->getResponse()->getContent() == 'VERIFIED') { $transaction->setState(TransactionInterface::STATE_OK); $transaction->setStatusCode(TransactionInterface::STATUS_VALIDATED); $transaction->getOrder()->setValidatedAt(new \DateTime()); $transaction->getOrder()->setStatus(OrderInterface::STATUS_VALIDATED); $transaction->getOrder()->setPaymentStatus(TransactionInterface::STATUS_VALIDATED); } else { $transaction->setState(TransactionInterface::STATE_KO); $transaction->setStatusCode(TransactionInterface::STATUS_ERROR_VALIDATION); // TODO error in status -> setting payment status to an order status value $transaction->getOrder()->setPaymentStatus(OrderInterface::STATUS_ERROR); if ($this->getLogger()) { $this->getLogger()->emergency('[Paypal::sendAccuseReception] Paypal failed to check the postback'); } } return new \Symfony\Component\HttpFoundation\Response(''); }