/** * @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 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; } }
/** * @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'); }
/** * @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 \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; }