The object contains :
- the order : the related order
- the transaction_id : the transaction token from the bank
- the state : the current state of the transaction, only OK or KO
- the status : the current status of the transaction
- the error code : the current error code of the transaction from the payment handler
/** * Retrieves the order matching $transaction and adds it to $transaction * * @param TransactionInterface $transaction The request's transaction (will be linked to the order in the process) * * @return \Sonata\Component\Order\OrderInterface * @throws \Doctrine\ORM\EntityNotFoundException * @throws InvalidTransactionException */ protected function getValidOrder(TransactionInterface $transaction) { $payment = $this->getPayment($transaction->getPaymentCode()); // retrieve the related order $reference = $payment->getOrderReference($transaction); if (!$reference) { throw new InvalidTransactionException(); } $order = $this->orderManager->findOneby(array('reference' => $reference)); if (!$order) { throw new EntityNotFoundException(sprintf('Order %s', $reference)); } $transaction->setOrder($order); // control the handshake value if (!$payment->isRequestValid($transaction)) { throw new InvalidTransactionException($order->getReference()); } return $order; }
/** * @param TransactionInterface $transaction * @return void */ public function applyTransactionId(TransactionInterface $transaction) { $transaction->setTransactionId('n/a'); }
/** * {@inheritdoc} */ public function isRequestValid(TransactionInterface $transaction) { return $transaction->get('check') === $this->generateUrlCheck($transaction->getOrder()); }
/** * return the order reference from the transaction object * * @param TransactionInterface $transaction * @return string */ public function getOrderReference(TransactionInterface $transaction) { $order = $transaction->get('order', null); if ($this->getLogger()) { $this->getLogger()->notice(sprintf("[BasePaypalPayment::loadOrder] order=%s", $order)); } return $order; }
/** * @param TransactionInterface $transaction * * @throws \RuntimeException * * @return array */ private function getResponseData(TransactionInterface $transaction) { $cmd = sprintf('cd %s && %s pathfile=%s message=%s ', $this->getOption('base_folder'), $this->getOption('response_command'), $this->getOption('pathfile'), $this->encodeString($transaction->get('DATA'))); $this->logger->debug(sprintf('Response Command : %s', $cmd)); $process = new Process($cmd); $process->run(); if (!$process->isSuccessful()) { throw new \RuntimeException(sprintf('Error %d when executing Scellius command: "%s".', $process->getExitCode(), trim($process->getErrorOutput()))); } //Sortie de la fonction : !code!error!v1!v2!v3!...!v29 // - code = 0 : la fonction retourne les données de la transaction dans les variables v1, v2, ... // : Ces variables sont décrites dans le GUIDE DU PROGRAMMEUR // - code = -1 : La fonction retourne un message d'erreur dans la variable error $data = explode('!', $process->getOutput()); if (count($data) != 33) { throw new \RuntimeException('Invalid data count'); } return array('code' => $data[1], 'error' => $data[2], 'merchant_id' => $data[3], 'merchant_country' => $data[4], 'amount' => $data[5], 'transaction_id' => $data[6], 'payment_means' => $data[7], 'transmission_date' => $data[8], 'payment_time' => $data[9], 'payment_date' => $data[10], 'response_code' => $data[11], 'payment_certificate' => $data[12], 'authorisation_id' => $data[13], 'currency_code' => $data[14], 'card_number' => $data[15], 'cvv_flag' => $data[16], 'cvv_response_code' => $data[17], 'bank_response_code' => $data[18], 'complementary_code' => $data[19], 'complementary_info' => $data[20], 'return_context' => $data[21], 'caddie' => $data[22], 'receipt_complement' => $data[23], 'merchant_language' => $data[24], 'language' => $data[25], 'customer_id' => $data[26], 'order_id' => $data[27], 'customer_email' => $data[28], 'customer_ip_address' => $data[29], 'capture_day' => $data[30], 'capture_mode' => $data[31], 'data' => $data[32]); }
/** * @param TransactionInterface $transaction */ public function report(TransactionInterface $transaction) { if (!$this->logger) { return; } if ($transaction->getState() == TransactionInterface::STATE_KO) { $method = 'crit'; } else { $method = 'info'; } foreach (explode("\n", $transaction->getInformation()) as $message) { call_user_func(array($this->logger, $method), $message); } }
/** * {@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(''); }