コード例 #1
0
 /**
  * This method executes a deposit transaction (aka capture transaction).
  *
  * This method requires that the Payment has already been approved in
  * a prior transaction.
  *
  * A typical use case are Credit Card payments.
  *
  * @param FinancialTransactionInterface $transaction The transaction
  * @param boolean                       $retry       Retry
  *
  * @return mixed
  *
  * @throws ActionRequiredException If the transaction's state is NEW
  * @throws FinancialException      If payment is not approved
  * @throws PaymentPendingException If payment is still approving
  */
 public function deposit(FinancialTransactionInterface $transaction, $retry)
 {
     $this->logger->debug('depositing transaction {id} with PAYID {payid}...', array('id' => $transaction->getId(), 'payid' => $transaction->getExtendedData()->get('PAYID')));
     if ($transaction->getState() === FinancialTransactionInterface::STATE_NEW) {
         throw new ActionRequiredException('Transaction needs to be in state 4');
     }
     if (!isset($this->feedbackResponse)) {
         $this->logger->debug('No feedback response set.');
         $response = $this->sendPayment($transaction);
         $this->logger->debug('response status is {status}', array('status' => $response->getStatus()));
         if ($response->hasError()) {
             $this->logger->debug(sprintf('Payment is not successful: %s', $response->getErrorDescription()));
             $this->handleUnsuccessfulResponse($response, $transaction);
         }
         $transaction->setReferenceNumber($response->getPaymentId());
     } else {
         if (($response = $this->feedbackResponse) && $response->isAuthorized()) {
             $response = $this->sendPayment($transaction);
             $this->logger->debug('response status is {status}', array('status' => $response->getStatus()));
             if ($response->hasError()) {
                 $this->logger->debug(sprintf('response is not successful! %s', $response->getErrorDescription()));
                 $this->handleUnsuccessfulResponse($response, $transaction);
             }
             $transaction->setReferenceNumber($response->getPaymentId());
         }
     }
     if ($response->isDepositing() || $response->isIncomplete()) {
         $this->logger->debug('response {res} is still depositing', array('res' => $response));
         throw new PaymentPendingException(sprintf('Payment is still pending, status: %s.', $response->getStatus()));
     }
     if (!$response->isDeposited()) {
         $this->logger->debug('response {res} is not deposited', array('res' => $response));
         $ex = new FinancialException(sprintf('Payment status "%s" is not valid for depositing', $response->getStatus()));
         $ex->setFinancialTransaction($transaction);
         $transaction->setResponseCode($response->getErrorCode());
         $transaction->setReasonCode($response->getStatus());
         throw $ex;
     }
     $transaction->setProcessedAmount($response->getAmount());
     $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS);
     $transaction->setReasonCode(PluginInterface::REASON_CODE_SUCCESS);
 }