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);
 }
Exemple #2
0
 /**
  * @param FinancialTransactionInterface $transaction
  *
  * @return array
  */
 protected function getBillData(FinancialTransactionInterface $transaction)
 {
     /** @var PaymentInstruction $paymentInstruction */
     $paymentInstruction = $transaction->getPayment()->getPaymentInstruction();
     $order = $this->getOrderByPaymentInstruction($paymentInstruction);
     $data = ['bill' => ['order_id' => $order->getId(), 'sum' => $paymentInstruction->getAmount(), 'client_company_name' => $order->getUser()->getCompany()->getName()], 'template' => 'transfer'];
     return $data;
 }
Exemple #3
0
 /**
  * @param FinancialTransactionInterface $transaction
  *
  * @return array
  */
 protected function getBillData(FinancialTransactionInterface $transaction)
 {
     /** @var PaymentInstruction $paymentInstruction */
     $paymentInstruction = $transaction->getPayment()->getPaymentInstruction();
     $order = $this->getOrderByPaymentInstruction($paymentInstruction);
     $data = ['bill' => ['order_id' => $order->getId(), 'sum' => $paymentInstruction->getAmount()], 'template' => 'receipt'];
     return $data;
 }
 /**
  * @param FinancialTransactionInterface $transaction
  * @return array
  */
 protected function getPurchaseParameters(FinancialTransactionInterface $transaction)
 {
     /**
      * @var \JMS\Payment\CoreBundle\Model\ExtendedDataInterface $data
      */
     $data = $transaction->getExtendedData();
     $parameters = parent::getPurchaseParameters($transaction);
     $parameters['issuer'] = $data->get('bank');
     return $parameters;
 }
 protected function getRedirectUrl(FinancialTransactionInterface $transaction)
 {
     $data = $transaction->getExtendedData();
     $client = $this->requestClient;
     $client->setAmount($transaction->getPayment()->getApprovingAmount())->setCurrency($transaction->getPayment()->getPaymentInstruction()->getCurrency())->setOrderNumber($transaction->getPayment()->getId())->setReturnUrl($data->get('return_url'));
     if ($data->has('description')) {
         $client->setDescription($data->get('description'));
     }
     if ($data->has('merchantOrderNumber')) {
         $client->setMerchantOrderNumber($data->get('merchantOrderNumber'));
     }
     return $client->getRequestUrl();
 }
Exemple #6
0
 /**
  * @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);
 }
Exemple #7
0
 public function getRedirectUrl(FinancialTransactionInterface $transaction)
 {
     /** @var PaymentInstructionInterface $instruction */
     $instruction = $transaction->getPayment()->getPaymentInstruction();
     $inv_id = $instruction->getId();
     /** @var ExtendedDataInterface $data */
     $data = $transaction->getExtendedData();
     $data->set('inv_id', $inv_id);
     $description = 'test desc';
     if ($data->has('description')) {
         $description = $data->get('description');
     }
     $parameters = ['MrchLogin' => $this->login, 'OutSum' => $transaction->getRequestedAmount(), 'InvId' => $inv_id, 'Desc' => $description, 'IncCurrLabel' => '', 'IsTest' => $this->test ? 1 : 0, 'Signature' => $this->auth->sign($this->login, $transaction->getRequestedAmount(), $inv_id)];
     return $this->getWebServerUrl() . '?' . http_build_query($parameters);
 }
 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);
     }
 }
 /**
  * {@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;
     }
 }
 public function approveAndDeposit(FinancialTransactionInterface $transaction, $retry)
 {
     /** @var $payment \Jms\Payment\CoreBundle\Model\PaymentInterface */
     $payment = $transaction->getPayment();
     $transaction->setProcessedAmount($payment->getTargetAmount());
     $transaction->setState(FinancialTransactionInterface::STATE_SUCCESS);
     $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS);
     $transaction->setReasonCode(PluginInterface::REASON_CODE_SUCCESS);
 }
 /**
  * @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;
 }
 /**
  * Perform direct online payment operations
  *
  * @param FinancialTransactionInterface $transaction
  *
  * @return \ETS\Payment\OgoneBundle\Response\DirectResponse
  */
 protected function getDirectResponse(FinancialTransactionInterface $transaction)
 {
     $apiData = array('PSPID' => $this->token->getPspid(), 'USERID' => $this->token->getApiUser(), 'PSWD' => $this->token->getApiPassword(), 'ORDERID' => $transaction->getExtendedData()->get('ORDERID'));
     if ($transaction->getExtendedData()->has('PAYID')) {
         $apiData['PAYID'] = $transaction->getExtendedData()->get('PAYID');
     }
     return new DirectResponse($this->sendApiRequest($apiData));
 }
 protected function constructFinancialTransactionResult(FinancialTransactionInterface $transaction, $status, $reasonCode)
 {
     $this->financialTransaction = $transaction;
     $this->credit = $transaction->getCredit();
     $this->payment = $transaction->getPayment();
     $this->paymentInstruction = null !== $this->credit ? $this->credit->getPaymentInstruction() : $this->payment->getPaymentInstruction();
     $this->status = $status;
     $this->reasonCode = $reasonCode;
     $this->recoverable = false;
 }
 protected function getGateway(FinancialTransactionInterface $transaction)
 {
     $gateways = array('ideal' => 'IDEAL', 'mister_cash' => 'MISTERCASH', 'visa' => 'VISA', 'mastercard' => 'MASTERCARD', 'direct_ebanking' => 'DIRECTBANK', 'giropay' => 'GIROPAY', 'maestro' => 'MAESTRO', 'bank_transfer' => 'BANKTRANS', 'direct_debit' => 'DIRDEB');
     $name = substr($transaction->getPayment()->getPaymentInstruction()->getPaymentSystemName(), 13);
     return isset($gateways[$name]) ? $gateways[$name] : null;
 }
 /**
  * @param FinancialTransactionInterface $transaction
  * @return string
  */
 protected function getMethod(FinancialTransactionInterface $transaction)
 {
     return substr($transaction->getPayment()->getPaymentInstruction()->getPaymentSystemName(), 7);
 }
 /**
  * @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;
 }
 /**
  * @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;
     }
 }
 /**
  * {@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 FinancialTransactionInterface $transaction
  */
 private function process(FinancialTransactionInterface $transaction)
 {
     $transaction->setProcessedAmount($transaction->getRequestedAmount());
     $transaction->setResponseCode(PluginInterface::RESPONSE_CODE_SUCCESS);
     $transaction->setReasonCode(PluginInterface::REASON_CODE_SUCCESS);
 }
 /**
  * @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;
 }
 /**
  * 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);
 }