setState() public method

public setState ( integer $state )
$state integer
Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function sendConfirmationReceipt(TransactionInterface $transaction)
 {
     $parameters = $transaction->getParameters();
     if (!array_key_exists('action', $parameters)) {
         throw new \RuntimeException('"action" parameter is missing from Transaction.');
     }
     switch ($parameters['action']) {
         case 'accept':
             $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);
             return new Response('ok', 200, array('Content-Type' => 'text/plain'));
         case 'refuse':
             $transaction->setState(TransactionInterface::STATE_KO);
             $transaction->setStatusCode(TransactionInterface::STATUS_ERROR_VALIDATION);
             return false;
         default:
             $transaction->setState(TransactionInterface::STATE_KO);
             $transaction->setStatusCode(TransactionInterface::STATUS_ERROR_VALIDATION);
             return false;
     }
 }
Ejemplo n.º 2
0
 /**
  * {@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;
 }
Ejemplo n.º 3
0
 /**
  * {@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;
 }
Ejemplo n.º 4
0
 /**
  * {@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('');
 }