Calculate the needed fee for a provided `$transaction` NEM transaction
object.

This method can be used to calculate all needed fees for a given
`transaction` object.

@param   \NEM\Models\Transaction     $transaction
@return  \NEM\Models\Fee
12601
static public function calculateForTransaction(Transaction $transaction)
    {
        // generate each content fee accordingly
        $msgFee = self::calculateForMessage($transaction->message());

        // default content fee is XEM amount transfer fee
        $contentFee = Fee::FEE_FACTOR * self::calculateForXEM($transaction->amount()->toMicro() / Amount::XEM);

        // get the Transaction extension fee
        $extensionFee = $transaction->extendFee();

        if ($extensionFee > 0) {
            $contentFee = (int) $extensionFee;
        }

        return $msgFee + $contentFee;
    }
393830
public function destroy(Transaction $transaction)
    {
        $this->transaction->destroy($transaction);

        return redirect()->route('admin.order.order.show', $transaction->order_id)
            ->withSuccess(trans('core::core.messages.resource deleted', ['name' => trans('order::transactions.title.transactions')]));
    }
1144606
public function persist( $object, $transaction = self::TRANSACTION_LAST_USED )
    {
        if( !is_object( $object ) ) {
            throw new \InvalidArgumentException("I can only persist objects.");
        }

        if( !( $object instanceof Task) ) {
            $object = $this->getTask( $object, Task::PERSIST );
        }

        $transaction = $this->getTransaction($transaction, true);
        $this->queue[$transaction][] = $object;

        return $this;
    }
225136
public function setTransactionsAttribute($transactions)
    {
        if (!is_array($transactions)) {
            throw new \InvalidArgumentException('Transactions must be an array');
        }

        foreach ($transactions as $key => $transaction) {
            if (!($transaction instanceof Transaction)) {
                $transactions[$key] = new Transaction($transaction);
            }
        }

        $this->attributes['Transactions'] = $transactions;

        return $this;
    }
428593
public function createPaymentByTransactionIdQuery($transactionId)
    {
        $query = $this->getFactory()->createPaymentPayoneQuery();
        $query->filterByTransactionId($transactionId);

        return $query;
    }
715972
protected function createRequest(Transaction $transaction, BasePaymentForm $form = null)
    {
        // For authorize and capture we're referring to a transaction that already took place so no card or item shenanigans.
        if (in_array($transaction->type, [TransactionRecord::TYPE_REFUND, TransactionRecord::TYPE_CAPTURE], false)) {
            $request = $this->createPaymentRequest($transaction);
        } else {
            $order = $transaction->getOrder();

            $card = null;

            if ($form) {
                $card = $this->createCard($form, $order);
            }

            $itemBag = $this->getItemBagForOrder($order);

            $request = $this->createPaymentRequest($transaction, $card, $itemBag);
            $this->populateRequest($request, $form);
        }

        return $request;
    }
1181875
private static function setMasternodeCommandDefaults(string $address, Transaction $transaction): self
    {
        $transaction->setDestinationAddress($address);
        $transaction->setValue(self::VALUE_MASTERNODE_COMMAND);
        $transaction->setFee(self::FEE_MASTERNODE_COMMAND);

        return $transaction;
    }
88235
public static function hashTransaction($transaction) {
        $salt = 'SALT';

        if ($salt != null) {

              $s = $salt . microtime() . $transaction->date . $transaction->description . $transaction->value;
              $hash = hash('sha512',$s,false);
        } else {
            throw new Exception("TransactionPersistance.hash_salt setting empty");
        }

        return $hash;
    }
639942
public function _send($transaction)
        {
            $storeId        = $this->getConfigData('store_id');
            $apiToken       = $this->getConfigData('api_token');

            $request        = new mpgRequest($transaction);

            $mpgHttpsPost   = new mpgHttpsPost($storeId, $apiToken, $request);

            return $mpgHttpsPost->getMpgResponse();
        }
510408
private function setTransaction(TransactionInterface $transaction) {
        $transactions = $this->getTransactions();
        $transactions[$this->getDbService()] = $transaction;
        $this->setTransactions($transactions);
    }
720440
protected function getConnection($bindTransaction)
    {
        if (empty($this->connection)) {
            $this->connection = $this->getNewConnection(array($this->connectionInfo));
            $this->connections[] = $this->connection;

            if($bindTransaction)
                $this->TransactionManager->bindConnection($this->connection);
        }
        return $this->connection;
    }
534516
protected function doTransact(Transaction $transaction, array $options = array())
    {
        $this->validateTransaction($transaction);
        $params = $this->buildParams($transaction, $options);

        $result = $transaction->getResult();
        $result->setTransactor($this);

        $postUrl = $options['post_url'];
        $client = $this->getClient();

        $request = $client->post($postUrl)
            ->addPostFields($params);

        try {
            $response = $request->send();

            $data = Transaction\TransactionType::QUERY !== $transaction->getType()->getValue()
                ? json_decode($response->getBody(true))
                : $this->normalizeQueryResponse($response->getBody(true));
        } catch (BadResponseException $e) {
            $data = new \stdClass();
            $data->CommandStatus = 'Error';
            $data->Description = 'Client Error';
            $data->ErrorInformation = 'An error occurred while contacting the PaymentsXpress system';
            $data->Exception = $e->getMessage();
        }

        if ('Approved' !== $data->CommandStatus) {
            $result->setStatus(new Result\ResultStatus('Declined' !== $data->CommandStatus ? Result\ResultStatus::ERROR : Result\ResultStatus::DECLINED));
            $result->setMessage(!empty($data->ErrorInformation) ? $data->Description . ': ' . $data->ErrorInformation : $data->Description);

            if (!empty($data->TransAct_ReferenceID)) {
                $result->setExternalId($data->TransAct_ReferenceID);
            }
        } else {
            if (Transaction\TransactionType::QUERY === $transaction->getType()->getValue()) {
                $this->handleQueryResponse($transaction, $data);
            } else {
                $result->setStatus(new Result\ResultStatus(Result\ResultStatus::PENDING));
            }

            $result->setExternalId($data->TransAct_ReferenceID);
        }

        $result->setData('request', $params);
        $result->setData('response', $data);

        return $result;
    }
255815
public function calculateTotalsAdvert(Transaction $transaction, $delivery=null)
    {
        $totals['delivery_expenses'] = 0;
        $totals['amount'] = $transaction->getTotalPrice();
        $totals['amount_clean'] = $transaction->getItems()->first()->getTotalPrice();
        $totals['vat'] = $totals['amount_clean'] * ($transaction->getVat() / 100);
       
        // return total
        return $totals;
    }
1244706
public function getDelivery(Transaction $transaction = null)
    {
        if ($this->session->has('delivery-id')) {
            $delivery = $this->manager->getRepository('EcommerceBundle:Delivery')->find($this->session->get('delivery-id'));

            return $delivery;
        }

        $delivery = new Delivery();

        /** @var Address $billingAddress */
        $billingAddress = $this->manager->getRepository('EcommerceBundle:Address')->findOneBy(array(
            'actor' => $this->securityContext->getToken()->getUser(),
            'forBilling' => true
        ));

        if (false === is_null($billingAddress)) {
            $delivery->setFullName($this->securityContext->getToken()->getUser()->getFullName());
            $delivery->setContactPerson($billingAddress->getContactPerson());
            $delivery->setDni($billingAddress->getDni());
            $delivery->setAddressInfo($billingAddress->getAddressInfo());
            $delivery->setPhone($billingAddress->getPhone());
            $delivery->setPhone2($billingAddress->getPhone2());
            $delivery->setPreferredSchedule($billingAddress->getPreferredSchedule());
        }

        $country = $this->manager->getRepository('CoreBundle:Country')->find('es');
        $delivery->setCountry($country);

        if (false === is_null($transaction)) {
            $delivery->setTransaction($transaction);
        }

        return $delivery;
    }
282268
public function create(Transaction &$transaction)
    {
        $data = $transaction->exportData();
        $endpoint = '/admin/transactions.json';
        $response = $this->request(
            $endpoint, 'POST', array(
            'transaction' => $data
            )
        );
        $transaction->setData($response['transaction']);
    }
332879
protected function doTransact(Transaction $transaction, array $options = array())
    {
        $this->validateTransaction($transaction);

        $account = $transaction->getAccount();
        $result = $transaction->getResult();
        $result->setTransactor($this);

        $adjustment = $transaction->getAmount();
        if (Transaction\TransactionType::SALE === $transaction->getType()->getValue()) {
            if ($transaction->getAmount() > $account->getBalance()) {
                $result->setStatus(new Result\ResultStatus(Result\ResultStatus::DECLINED));
                $result->setMessage('Amount exceeds account balance');

                return $result;
            }

            $adjustment *= -1; // Negate the adjustment
        }

        $result->setStatus(new Result\ResultStatus(Result\ResultStatus::APPROVED));
        $account->adjustBalance($adjustment);

        return $result;
    }
561389
protected function createTransaction(Request $request)
    {
        $payment = $this->getPayment($request->get('bank'));

        $transaction = $this->transactionManager->create();
        $transaction->setPaymentCode($payment->getCode());
        $transaction->setParameters(array_replace($request->query->all(), $request->request->all()));

        return $transaction;
    }