/** * @param FinancialTransactionInterface $transaction * @throws \JMS\Payment\CoreBundle\Plugin\Exception\ActionRequiredException * * @return string */ protected function obtainInvoiceId(FinancialTransactionInterface $transaction) { $data = $transaction->getExtendedData(); if ($data->has('invoice_id')) { return $data->get('invoice_id'); } $options = $data->get('options'); $invoice = $this->bitpay->createInvoice($data->get('orderId'), $transaction->getRequestedAmount(), $data->get('posData'), $data->get('options')); $this->throwUnlessSuccessResponse($invoice, $transaction); $data->set('invoice_id', $invoice->id); $data->set('invoice_time', $invoice->invoiceTime); $data->set('url', $invoice->url); $data->set('btc_price', $invoice->btcPrice); $transaction->setReferenceNumber($invoice->id); $actionRequest = new ActionRequiredException('User must confirm transaction'); $actionRequest->setFinancialTransaction($transaction); $actionRequest->setAction(new VisitUrl($invoice->url)); throw $actionRequest; }
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); } }
/** * @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(); }
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); }
/** * {@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; } }
/** * 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); }
/** * {@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 * @return mixed */ protected function findOrCreatePlan(FinancialTransactionInterface $transaction) { $data = $transaction->getExtendedData(); if ($data->has('plan_id')) { return $data->get('plan_id'); } $opts = $data->has('checkout_params') ? $data->get('checkout_params') : array(); $opts['id'] = array_key_exists('id', $opts) ? $opts['id'] : ''; $response = $this->client->retrievePlan($opts['id']); if (!$response->isSuccess()) { $opts['amount'] = $this->client->convertAmountToStripeFormat($transaction->getRequestedAmount()); $opts['currency'] = $transaction->getPayment()->getPaymentInstruction()->getCurrency(); $opts['interval'] = $this->getIntervalForStripe($transaction->getPayment()->getPaymentInstruction()->getBillingInterval()); $opts['interval_count'] = $transaction->getPayment()->getPaymentInstruction()->getBillingFrequency(); $response = $this->client->createPlan($opts); } $this->throwUnlessSuccessResponse($response, $transaction); $data->set('plan_id', $response->getResponse()->id); return $data->get('plan_id'); }
/** * 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)); }
/** * @param \JMS\Payment\CoreBundle\Model\FinancialTransactionInterface $transaction * @param string $paymentAction * * @throws \JMS\Payment\CoreBundle\Plugin\Exception\ActionRequiredException if user has to authenticate the token * * @return string */ protected function obtainExpressCheckoutToken(FinancialTransactionInterface $transaction, $paymentAction) { $data = $transaction->getExtendedData(); if ($data->has('express_checkout_token')) { return $data->get('express_checkout_token'); } $opts = $data->has('checkout_params') ? $data->get('checkout_params') : array(); $opts['PAYMENTREQUEST_0_PAYMENTACTION'] = $paymentAction; $opts['PAYMENTREQUEST_0_CURRENCYCODE'] = $transaction->getPayment()->getPaymentInstruction()->getCurrency(); $response = $this->client->requestSetExpressCheckout($transaction->getRequestedAmount(), $this->getReturnUrl($data), $this->getCancelUrl($data), $opts); $this->throwUnlessSuccessResponse($response, $transaction); $data->set('express_checkout_token', $response->body->get('TOKEN')); $authenticateTokenUrl = $this->client->getAuthenticateExpressCheckoutTokenUrl($response->body->get('TOKEN')); $actionRequest = new ActionRequiredException('User must authorize the transaction.'); $actionRequest->setFinancialTransaction($transaction); $actionRequest->setAction(new VisitUrl($authenticateTokenUrl)); throw $actionRequest; }
/** * @param FinancialTransactionInterface $transaction * @return array */ protected function getPurchaseParameters(FinancialTransactionInterface $transaction) { /** * @var \JMS\Payment\CoreBundle\Model\PaymentInterface $payment */ $payment = $transaction->getPayment(); /** * @var \JMS\Payment\CoreBundle\Model\PaymentInstructionInterface $paymentInstruction */ $paymentInstruction = $payment->getPaymentInstruction(); /** * @var \JMS\Payment\CoreBundle\Model\ExtendedDataInterface $data */ $data = $transaction->getExtendedData(); $transaction->setTrackingId($payment->getId()); $card = new \Omnipay\Common\CreditCard(); $parameters = array('transactionId' => $transaction->getTrackingId(), 'amount' => $payment->getTargetAmount(), 'currency' => $paymentInstruction->getCurrency(), 'description' => $data->has('description') ? $data->get('description') : 'Transaction ' . $payment->getId(), 'clientIp' => $data->get('client_ip'), 'gateway' => $this->getGateway($transaction), 'card' => $card, 'notifyUrl' => $this->reportUrl, 'cancelUrl' => $data->get('cancel_url'), 'returnUrl' => $data->get('return_url')); return $parameters; }
/** * @param FinancialTransactionInterface $transaction * @return array */ protected function getPurchaseParameters(FinancialTransactionInterface $transaction) { /** * @var \JMS\Payment\CoreBundle\Model\PaymentInterface $payment */ $payment = $transaction->getPayment(); /** * @var \JMS\Payment\CoreBundle\Model\ExtendedDataInterface $data */ $data = $transaction->getExtendedData(); $transaction->setTrackingId($payment->getId()); $parameters = array('amount' => $payment->getTargetAmount(), 'description' => $data->has('description') ? $data->get('description') : 'Transaction ' . $payment->getId(), 'returnUrl' => $data->get('return_url'), 'paymentMethod' => $this->getMethod($transaction)); return $parameters; }
/** * 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); }