public function approveAndDeposit(FinancialTransactionInterface $transaction, $retry)
 {
     $data = $transaction->getExtendedData();
     if (0 != $data->get('code')) {
         $transaction->setResponseCode(self::RESPONSE_CODE_FAILED);
         $transaction->setReasonCode($data->get('error'));
         $transaction->setState(FinancialTransactionInterface::STATE_FAILED);
         $this->logger->info(sprintf('Payment failed with error code %s. Error: %s', $data->get('code'), $data->get('error')));
         $ex = new FinancialException(sprintf('Payment failed with error code %s. Error: %s', $data->get('code'), $data->get('error')));
         $ex->setFinancialTransaction($transaction);
         throw $ex;
     }
     $transaction->setReferenceNumber($data->get('order_id'));
     if (17 == $data->get('response_code')) {
         $transaction->setResponseCode(self::RESPONSE_CODE_CANCELED);
         $transaction->setReasonCode('Payment canceled');
     } elseif (0 != $data->get('response_code')) {
         $transaction->setResponseCode(self::RESPONSE_CODE_FAILED);
         $transaction->setReasonCode(sprintf('Response code: %s', $data->get('response_code')));
         $this->logger->info(sprintf('Payment failed with error response_code %s. Error: %s', $data->get('response_code'), $data->get('error')));
     } else {
         $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS);
         $transaction->setReasonCode(PluginInterface::REASON_CODE_SUCCESS);
         $transaction->setProcessedAmount($data->get('sub_amount') / 100);
     }
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function approveAndDeposit(FinancialTransactionInterface $transaction, $retry)
 {
     try {
         $data = $transaction->getExtendedData();
         $client = $this->api->getClient($data->has('client') ? $data->get('client') : null);
         $apiTransaction = new \Paymill\Models\Request\Transaction();
         $apiTransaction->setToken($data->get('token'))->setClient($client)->setAmount($transaction->getRequestedAmount() * 100)->setCurrency($transaction->getPayment()->getPaymentInstruction()->getCurrency())->setDescription($data->has('description') ? $data->get('description') : null);
         $apiTransaction = $this->api->create($apiTransaction);
     } catch (PaymillException $e) {
         $ex = new FinancialException($e->getErrorMessage());
         $ex->setFinancialTransaction($transaction);
         $transaction->setResponseCode($e->getStatusCode());
         $transaction->setReasonCode($e->getResponseCode());
         throw $ex;
     }
     switch ($apiTransaction->getStatus()) {
         case 'closed':
             $transaction->setReferenceNumber($apiTransaction->getId());
             $transaction->setProcessedAmount($apiTransaction->getAmount() / 100);
             $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS);
             $transaction->setReasonCode(PluginInterface::REASON_CODE_SUCCESS);
             break;
         case 'open':
         case 'pending':
             $ex = new PaymentPendingException('Payment is still pending');
             $transaction->setReferenceNumber($apiTransaction->getId());
             $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_PENDING);
             $transaction->setReasonCode(PluginInterface::REASON_CODE_SUCCESS);
             $ex->setFinancialTransaction($transaction);
             throw $ex;
         default:
             $ex = new FinancialException('Transaction failed');
             $ex->setFinancialTransaction($transaction);
             $transaction->setResponseCode('Failed');
             $transaction->setReasonCode($apiTransaction->getResponseCode());
             throw $ex;
     }
 }
 /**
  * @param BatchResponse $response
  * @param FinancialTransactionInterface $transaction
  * @throws FinancialException
  */
 private function handleUnsuccessfulResponse(BatchResponse $response, FinancialTransactionInterface $transaction)
 {
     $transaction->setResponseCode($response->getErrorCode());
     $transaction->setReasonCode($response->getStatusError());
     $ex = new FinancialException('Ogone-Response was not successful: ' . $response->getErrorDescription());
     $ex->setFinancialTransaction($transaction);
     throw $ex;
 }
 /**
  * {@inheritdoc}
  */
 public function deposit(FinancialTransactionInterface $transaction, $retry)
 {
     $data = $transaction->getExtendedData();
     if ($transaction->getResponseCode() !== PluginInterface::RESPONSE_CODE_SUCCESS || $transaction->getReasonCode() !== PluginInterface::REASON_CODE_SUCCESS) {
         $e = new FinancialException('Peyment is not completed');
         $e->setFinancialTransaction($transaction);
         throw $e;
     }
     // różnica kwoty zatwierdzonej i kwoty wymaganej musi być równa zero
     // && nazwa waluty musi się zgadzać
     if (Number::compare($transaction->getProcessedAmount(), $transaction->getRequestedAmount()) === 0 && $transaction->getPayment()->getPaymentInstruction()->getCurrency() == "BTC") {
         // wszystko ok
         // można zakakceptować zamówienie
         $event = new PaymentEvent($this->getName(), $transaction, $transaction->getPayment()->getPaymentInstruction());
         $this->dispatcher->dispatch('deposit', $event);
     } else {
         // coś się nie zgadza, nie można tego zakaceptować
         $e = new FinancialException('The deposit has not passed validation');
         $e->setFinancialTransaction($transaction);
         $transaction->setResponseCode('Unknown');
         $transaction->setReasonCode($data->get('confirmations'));
         throw $e;
     }
 }
 /**
  * @param Response $response
  * @param FinancialTransactionInterface $transaction
  * @throws \JMS\Payment\CoreBundle\Plugin\Exception\FinancialException
  */
 protected function throwUnlessSuccessResponse(Response $response, FinancialTransactionInterface $transaction)
 {
     if ($response->isSuccess()) {
         return;
     }
     $transaction->setResponseCode($response->getErrorResponseCode());
     $transaction->setReasonCode($response->getErrorReasonCode());
     $ex = new FinancialException('Stripe-Response was not successful: ' . $response->getErrorMessage());
     $ex->setFinancialTransaction($transaction);
     throw $ex;
 }
 /**
  * Return direct response content
  *
  * @param \JMS\Payment\CoreBundle\Model\FinancialTransactionInterface $transaction
  * @return type
  * @throws \JMS\Payment\CoreBundle\Plugin\Exception\FinancialException
  */
 public function getDirectResponseContent(FinancialTransactionInterface $transaction)
 {
     $response = $this->getDirectResponse($transaction);
     if (!$response->isSuccessful()) {
         $ex = new FinancialException('Direct Ogone-Response was not successful: ' . $response->getErrorDescription());
         $ex->setFinancialTransaction($transaction);
         throw $ex;
     }
     return $response;
 }
 /**
  * @param stdClass $response
  * @param FinancialTransactionInterface $transaction
  * @throws \JMS\Payment\CoreBundle\Plugin\Exception\FinancialException
  * @return null
  */
 protected function throwUnlessSuccessResponse($response, FinancialTransactionInterface $transaction)
 {
     if (!empty($response->error)) {
         $transaction->setResponseCode('Failed');
         $transaction->setReasonCode($response->error);
         $ex = new FinancialException('Bitpay request was not successful: ' . $response->error);
         $ex->setFinancialTransaction($transaction);
         throw $ex;
     }
 }
Ejemplo n.º 9
0
 /**
  * @param \JMS\Payment\CoreBundle\Model\FinancialTransactionInterface $transaction
  * @param \JMS\Payment\PaypalBundle\Client\Response $response
  * @return null
  * @throws \JMS\Payment\CoreBundle\Plugin\Exception\FinancialException
  */
 protected function throwUnlessSuccessResponse(Response $response, FinancialTransactionInterface $transaction)
 {
     if ($response->isSuccess()) {
         return;
     }
     $transaction->setResponseCode($response->body->get('ACK'));
     $transaction->setReasonCode($response->body->get('L_ERRORCODE0'));
     $ex = new FinancialException('PayPal-Response was not successful: ' . $response);
     $ex->setFinancialTransaction($transaction);
     throw $ex;
 }
 public function createRedirectActionException(FinancialTransactionInterface $transaction)
 {
     $parameters = $this->getPurchaseParameters($transaction);
     /**
      * @var \Omnipay\MultiSafepay\Message\PurchaseRequest $purchaseRequest
      */
     $purchaseRequest = $this->gateway->purchase($parameters);
     /**
      * @var \Omnipay\MultiSafepay\Message\PurchaseResponse $purchaseResponse
      */
     $purchaseResponse = $purchaseRequest->send();
     if ($this->logger) {
         $this->logger->info($purchaseRequest->getData()->asXML());
         $this->logger->info($purchaseResponse->getData()->asXML());
     }
     $url = $purchaseResponse->getRedirectUrl();
     if (empty($url)) {
         $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" with reason: ', $transaction->getTrackingId(), $purchaseResponse->getMessage()));
         }
         throw $ex;
     }
     $actionRequest = new ActionRequiredException('Redirect the user to MultiSafepay.');
     $actionRequest->setFinancialTransaction($transaction);
     $actionRequest->setAction(new VisitUrl($purchaseResponse->getRedirectUrl()));
     if ($this->logger) {
         $this->logger->info(sprintf('Create a new redirect exception for transaction "%s".', $purchaseResponse->getTransactionReference()));
     }
     return $actionRequest;
 }
Ejemplo n.º 11
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;
 }
 /**
  * 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
  */
 public function deposit(FinancialTransactionInterface $transaction, $retry)
 {
     $data = $transaction->getExtendedData();
     $this->checkExtendedDataBeforeApproveAndDeposit($data);
     switch ($data->get('t_status')) {
         case self::STATUS_CLOSED:
             $ex = new TimeoutException('PaymentAction closed');
             $ex->setFinancialTransaction($transaction);
             throw $ex;
         case self::STATUS_NEW:
             // TODO: The status should not be NEW at this point, I think
             // we should throw an Exception that trigger the PENDING state
         // TODO: The status should not be NEW at this point, I think
         // we should throw an Exception that trigger the PENDING state
         case self::STATUS_COMPLAINT:
             // TODO: What is this status ? should we deal with it ?
         // TODO: What is this status ? should we deal with it ?
         case self::STATUS_DONE:
             break;
         case self::STATUS_REJECTED:
             $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: ' . $data->get('t_status'));
             $ex->setFinancialTransaction($transaction);
             $transaction->setResponseCode('Unknown');
             throw $ex;
     }
     $transaction->setReferenceNumber($data->get('t_id'));
     $transaction->setProcessedAmount($data->get('amount'));
     $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS);
     $transaction->setReasonCode(PluginInterface::REASON_CODE_SUCCESS);
 }