コード例 #1
0
 public function approveAndDeposit(FinancialTransactionInterface $transaction, $retry)
 {
     if ($transaction->getState() === FinancialTransactionInterface::STATE_NEW) {
         throw $this->createRedirectActionException($transaction);
     }
     /** @var PaymentInstructionInterface $instruction */
     $instruction = $transaction->getPayment()->getPaymentInstruction();
     $state_code = $this->client->requestOpState($instruction->getId());
     switch ($state_code) {
         case self::STATUS_COMPLETED:
             break;
         case self::STATUS_PENDING:
             throw new PaymentPendingException('Payment is still pending');
         case self::STATUS_CANCELLED:
             $ex = new FinancialException('PaymentAction rejected.');
             $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS);
             $transaction->setReasonCode(PluginInterface::REASON_CODE_BLOCKED);
             $ex->setFinancialTransaction($transaction);
             throw $ex;
         case self::STATUS_REFUND:
             return $this->reverseDeposit($transaction, $retry);
         default:
             $ex = new FinancialException('Payment status unknow: ' . $state_code);
             $ex->setFinancialTransaction($transaction);
             $transaction->setResponseCode('Failed');
             $transaction->setReasonCode($state_code);
             throw $ex;
     }
     $transaction->setProcessedAmount($instruction->getAmount());
     $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS);
     $transaction->setReasonCode(PluginInterface::REASON_CODE_SUCCESS);
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function approveAndDeposit(FinancialTransactionInterface $transaction, $retry)
 {
     if ($transaction->getState() === FinancialTransactionInterface::STATE_NEW) {
         throw $this->createPaymentRedirect($transaction);
     }
     $this->approve($transaction, $retry);
     $this->deposit($transaction, $retry);
 }
コード例 #3
0
ファイル: AbstractBankPlugin.php プロジェクト: bzis/zomba
 /**
  * @param FinancialTransactionInterface $transaction
  * @param bool                          $retry
  */
 public function approveAndDeposit(FinancialTransactionInterface $transaction, $retry)
 {
     /** @var PaymentInstructionInterface $instruction */
     $instruction = $transaction->getPayment()->getPaymentInstruction();
     if ($transaction->getState() === FinancialTransactionInterface::STATE_NEW) {
         /** @var Order $order */
         $order = $this->getOrderByPaymentInstruction($instruction);
         $order->setBillData($this->getBillData($transaction));
         throw $this->createRedirectActionException($transaction, $order);
     }
     $transaction->setProcessedAmount($instruction->getAmount());
     $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS);
     $transaction->setReasonCode(PluginInterface::REASON_CODE_SUCCESS);
 }
コード例 #4
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);
 }
コード例 #5
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)
 {
     if ($transaction->getState() === FinancialTransactionInterface::STATE_NEW) {
         throw $this->createRedirectActionException($transaction);
     }
     $response = $this->getResponse($transaction);
     if ($response->isDepositing()) {
         throw new PaymentPendingException(sprintf('Payment is still pending, status: %s.', $response->getStatus()));
     }
     if (!$response->isDeposited()) {
         $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);
 }
コード例 #6
0
 public function approveAndDeposit(FinancialTransactionInterface $transaction, $retry)
 {
     if ($transaction->getState() === FinancialTransactionInterface::STATE_NEW) {
         throw $this->createRedirectActionException($transaction);
     }
     if (null !== ($trackingId = $transaction->getTrackingId())) {
         /**
          * @var \Omnipay\MultiSafepay\Message\CompletePurchaseRequest $completePurchaseRequest
          */
         $completePurchaseRequest = $this->gateway->completePurchase(array('transactionId' => $trackingId));
         $status = $completePurchaseRequest->send();
         $rawData = $status->getData();
         if ($this->logger) {
             $this->logger->info('TransactionStatus: Paid=' . $status->isSuccessful() . ", Status=" . $status->getPaymentStatus() . ", TransactionId=" . $status->getTransactionReference() . ", ID=" . (string) $rawData->ewallet->id);
         }
         if ($status->isSuccessful()) {
             $transaction->setReferenceNumber((string) $rawData->ewallet->id);
             $transaction->setProcessedAmount((string) $rawData->customer->amount / 100);
             $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS);
             $transaction->setReasonCode(PluginInterface::REASON_CODE_SUCCESS);
             if ("IDEAL" === (string) $rawData->paymentdetails->type) {
                 $transaction->getExtendedData()->set('consumer_name', (string) $rawData->paymentdetails->accountholdername);
                 $transaction->getExtendedData()->set('consumer_account_number', (string) $rawData->paymentdetails->accountiban);
             }
             if ($this->logger) {
                 $this->logger->info(sprintf('Payment is successful for transaction "%s".', $transaction->getTrackingId()));
             }
             return;
         }
         if ($status->isCanceled()) {
             $ex = new FinancialException('Payment cancelled.');
             $ex->setFinancialTransaction($transaction);
             $transaction->setResponseCode('CANCELLED');
             $transaction->setReasonCode('CANCELLED');
             $transaction->setState(FinancialTransactionInterface::STATE_CANCELED);
             if ($this->logger) {
                 $this->logger->info(sprintf('Payment cancelled for transaction "%s".', $transaction->getTrackingId()));
             }
             throw $ex;
         }
         if ($status->isRejected()) {
             $ex = new FinancialException('Payment failed.');
             $ex->setFinancialTransaction($transaction);
             $transaction->setResponseCode('FAILED');
             $transaction->setReasonCode('FAILED');
             $transaction->setState(FinancialTransactionInterface::STATE_FAILED);
             if ($this->logger) {
                 $this->logger->info(sprintf('Payment failed for transaction "%s".', $transaction->getTrackingId()));
             }
             throw $ex;
         }
         if ($status->isExpired()) {
             $ex = new FinancialException('Payment expired.');
             $ex->setFinancialTransaction($transaction);
             $transaction->setResponseCode('EXPIRED');
             $transaction->setReasonCode('EXPIRED');
             $transaction->setState(FinancialTransactionInterface::STATE_FAILED);
             if ($this->logger) {
                 $this->logger->info(sprintf('Payment is expired for transaction "%s".', $transaction->getTrackingId()));
             }
             throw $ex;
         }
         if ($this->logger) {
             $this->logger->info(sprintf('Waiting for notification from MultiSafepay for transaction "%s".', $transaction->getTrackingId()));
         }
         throw new BlockedException("Waiting for notification from MultiSafepay.");
     }
 }
コード例 #7
0
 public function approveAndDeposit(FinancialTransactionInterface $transaction, $retry)
 {
     if ($transaction->getState() === FinancialTransactionInterface::STATE_NEW) {
         throw $this->createMollieRedirectActionException($transaction);
     }
     if (null !== ($trackingId = $transaction->getTrackingId())) {
         $response = $this->gateway->completePurchase(array('transactionReference' => $trackingId))->send();
         if ($this->logger) {
             $this->logger->info('TransactionStatus: Status=' . $response->getStatus() . ", TransactionId=" . $response->getTransactionReference() . ", " . json_encode($response->getData()));
         }
         if ($response->isSuccessful()) {
             $transaction->setReferenceNumber($response->getTransactionReference());
             $transaction->setProcessedAmount($response->getAmount());
             $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS);
             $transaction->setReasonCode(PluginInterface::REASON_CODE_SUCCESS);
             $data = $response->getData();
             if (!empty($data['details'])) {
                 if (!empty($data['details']['consumerName'])) {
                     $transaction->getExtendedData()->set('consumer_name', $data['details']['consumerName']);
                 }
                 if (!empty($data['details']['consumerAccount'])) {
                     $transaction->getExtendedData()->set('consumer_account_number', $data['details']['consumerAccount']);
                 }
             }
             if ($this->logger) {
                 $this->logger->info(sprintf('Payment is successful for transaction "%s".', $response->getTransactionReference()));
             }
             return;
         }
         if ($response->isCancelled()) {
             $ex = new FinancialException('Payment cancelled.');
             $ex->setFinancialTransaction($transaction);
             $transaction->setResponseCode('CANCELLED');
             $transaction->setReasonCode('CANCELLED');
             $transaction->setState(FinancialTransactionInterface::STATE_CANCELED);
             if ($this->logger) {
                 $this->logger->info(sprintf('Payment cancelled for transaction "%s".', $response->getTransactionReference()));
             }
             throw $ex;
         }
         if ($response->isExpired()) {
             $ex = new FinancialException('Payment expired.');
             $ex->setFinancialTransaction($transaction);
             $transaction->setResponseCode('EXPIRED');
             $transaction->setReasonCode('EXPIRED');
             $transaction->setState(FinancialTransactionInterface::STATE_FAILED);
             if ($this->logger) {
                 $this->logger->info(sprintf('Payment is expired for transaction "%s".', $response->getTransactionReference()));
             }
             throw $ex;
         }
         if ($response->isRedirect()) {
             $ex = new ActionRequiredException('Redirect the user to Mollie.');
             $ex->setFinancialTransaction($transaction);
             $ex->setAction(new VisitUrl($response->getRedirectUrl()));
             if ($this->logger) {
                 $this->logger->info(sprintf('Create a new redirect exception for transaction "%s".', $response->getTransactionReference()));
             }
             throw $ex;
         }
         if ($this->logger) {
             $this->logger->info(sprintf('Waiting for notification from Mollie for transaction "%s".', $response->getTransactionReference()));
         }
         throw new BlockedException("Waiting for notification from Mollie.");
     }
     $ex = new FinancialException('Payment failed.');
     $ex->setFinancialTransaction($transaction);
     $transaction->setResponseCode('FAILED');
     $transaction->setReasonCode('FAILED');
     $transaction->setState(FinancialTransactionInterface::STATE_FAILED);
     throw $ex;
 }