/** * {@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 $token * @param $amount * @param $transactionDetails * @param null $clientId * @param string $currency * * @return bool|OneTimePaymentResult */ public function makeOneTimePayment($token, $amount, $transactionDetails, $clientId = null, $currency = 'EUR', $paymentId = null) { $transaction = new \Paymill\Models\Request\Transaction(); $transaction->setAmount($amount * 100)->setCurrency($currency)->setDescription($transactionDetails); if ($paymentId) { $transaction->setPayment($paymentId); } else { $transaction->setToken($token); } if ($clientId) { $transaction->setClient($clientId); } try { /** @var Transaction $response */ $response = $this->request->create($transaction); } catch (\Paymill\Services\PaymillException $e) { s($e->getResponseCode()); s($e->getStatusCode()); s($e->getErrorMessage()); return false; } return new OneTimePaymentResult(['transaction_id' => $response->getId(), 'payment_id' => $response->getPayment()->getId()]); }