@param \Orkestra\Transactor\Entity\Transaction $transaction
@param array                                   $options

@throws \RuntimeException
@return array
337450
protected function buildParams(Transaction $transaction, array $options = array())
    {
        $credentials = $transaction->getCredentials();
        $account = $transaction->getAccount();

        $params = $params = array(
            'ProviderID' => $credentials->getCredential('providerId'),
            'Provider_GateID' => $credentials->getCredential('providerGateId'),
            'Provider_GateKey' => $credentials->getCredential('providerGateKey'),
            'Command' => $this->getCommand($transaction),
            'CommandVersion' => '1.0',
            'TestMode' => !empty($options['test_mode']) ? 'On' : 'Off',
            'MerchantID' => $credentials->getCredential('merchantId'),
            'Merchant_GateID' => $credentials->getCredential('merchantGateId'),
            'Merchant_GateKey' => $credentials->getCredential('merchantGateKey'),
        );

        $transactionType = $transaction->getType()->getValue();

        if (Transaction\TransactionType::SALE === $transactionType) {
            $params = array_merge($params, array(
                'ResponseType' => 'JSON',
                'PaymentDirection' => 'FromCustomer',
                'Amount' => $transaction->getAmount(),
                'CheckType' => in_array($account->getAccountType()->getValue(), array(
                    AccountType::PERSONAL_SAVINGS,
                    AccountType::PERSONAL_CHECKING
                )) ? 'Personal' : 'Business',
                'AccountType' => in_array($account->getAccountType()->getValue(), array(
                    AccountType::PERSONAL_SAVINGS,
                    AccountType::BUSINESS_SAVINGS
                )) ? 'Savings' : 'Checking',
                'RoutingNumber' => $account->getRoutingNumber(),
                'AccountNumber' => $account->getAccountNumber(),
                'Billing_CustomerName' => $account->getName(),
                'Billing_Address1' => $account->getAddress(),
                'Billing_City' => $account->getCity(),
                'Billing_State' => $account->getRegion(),
                'Billing_Zip' => $account->getPostalCode(),
                'Billing_Phone' => $account->getPhoneNumber(),
                'SendEmailToCustomer' => 'No',
                'Run_ExpressVerify' => 'No',
                'SECCode' => 'WEB',
                'Customer_IPAddress' => $account->getIpAddress(),
            ));
        } elseif (Transaction\TransactionType::QUERY === $transactionType) {
            $params['TrackingDate'] = !empty($options['date']) ? $options['date'] : date('mdY');
        } else {
            throw new \RuntimeException(sprintf('The transaction type %s is not yet implemented', $transaction->getType()->getValue()));
        }

        return $params;
    }
1153187
public function addTransaction(Transaction $transaction)
    {
        $transaction->setAdvert($this);
        $this->transactions->add($transaction);

        return $this;
    }
1366739
public function getStatus( $transaction = RecordManager::TRANSACTIONS_ALL )
    {

        if( $transaction === RecordManager::TRANSACTIONS_ALL ) {
            return $this->status;
        }

        if( !array_key_exists( $transaction, $this->status ) ) {
            throw new TransactionDoesNotExistException("Transaction with this name `{$transaction}` doesn't exist. Sorry.");
        }

        return array( $transaction => $this->status[$transaction] );

    }
1355519
public function setOptions($options)
    {
        // Valid Options
        $validOptions = ['delete', 'update', 'constraint'];
        foreach ($options as $option => $value) {
            if (!in_array($option, $validOptions, true)) {
                throw new \RuntimeException(sprintf('"%s" is not a valid foreign key option.', $option));
            }

            // handle $options['delete'] as $options['update']
            if ('delete' === $option) {
                $this->setOnDelete($value);
            } elseif ('update' === $option) {
                $this->setOnUpdate($value);
            } else {
                $method = 'set' . ucfirst($option);
                $this->$method($value);
            }
        }

        return $this;
    }
1321531
public function update(array $attributes = [], array $options = [])
    {
        $relations = [];
        $transaction = false;

        foreach ($attributes as $key => $value) {
            if ($this->isRelationMapped($key)) {
                $relations[$key] = $value;
                unset($attributes[$key]);
            }
        }

        if (count($relations) > 0) {
            DB::beginTransaction();
            $transaction = true;
        }

        try {
            $userId = SessionUtility::getCurrentUserId();
            if ($userId && static::isField('last_modified_by_id')) {
                $this->last_modified_by_id = $userId;
            }
            $updated = parent::update($attributes);

            if ($updated && $this->exists && count($relations) > 0) {
                foreach ($relations as $name => $value) {
                    $relatedModel = $this->getReferencingModel($name);

                    if (RelationSchema::HAS_ONE === $this->getReferencingType($name)) {
                        $hasOne = $this->getHasOneByRelationName($name);
                        $this->saveHasOneData($relatedModel, $hasOne, $value, $name);
                    } elseif (RelationSchema::HAS_MANY === $this->getReferencingType($name)) {
                        $hasMany = $this->getHasManyByRelationName($name);
                        $this->saveHasManyData($relatedModel, $hasMany, $value, $name);
                    }
                }
            }

            if ($transaction) {
                DB::commit();
            }
        } catch (\Exception $e) {
            if ($transaction) {
                DB::rollBack();
            }

            throw $e;
        }

        return $updated;
    }
1070583
public function transaction()
    {
        $options = array(
            'order' => 'desc',
            'sort' => 'created',
            'limit' => array(0, $this->config->get('dashboard_limit', 10)));

        $items = $this->transaction->getList($options);

        array_walk($items, function (&$item) {
            $this->setItemTotalFormatted($item, $this->price);
        });

        return $items;
    }
983684
private function _submitTransaction($transaction, $txnType, $clientTransactionId = null)
    {
        $options = array();
        if ($clientTransactionId !== null) {
            $options['clientTransactionId'] = $clientTransactionId;
        }
        $rsp = $this->doRequest($transaction, $options);
        HpsGatewayResponseValidation::checkResponse($rsp, $txnType);
        $response = HpsCheckResponse::fromDict($rsp, $txnType);

        if ($response->responseCode != 0) {
            throw new HpsCheckException(
                $rsp->Header->GatewayTxnId,
                $response->details,
                $response->responseCode,
                $response->responseText
            );
        }

        return $response;
    }
1102693
public static function run_transaction(Transaction $transaction) {
		ob_start();
		echo date('[r] ') . 'Running ' . $transaction->classname . ' - ' . $transaction->id . "\n";

		$failed = false;
		try {
			$transaction->run();
		} catch (\Throwable $e) {
			$failed = true;
		} catch (\Exception $e) {
			$failed = true;
		}
		echo "\n";
		echo date('[r] ') . 'Finished ' . $transaction->classname . ' - ' . $transaction->id . "\n";

		$content = ob_get_contents();
		ob_get_clean();

		if ($failed) {
			$transaction->mark_failed($content, $e);
		} else {
			$transaction->mark_completed($content);
		}
	}
510408
private function setTransaction(TransactionInterface $transaction) {
        $transactions = $this->getTransactions();
        $transactions[$this->getDbService()] = $transaction;
        $this->setTransactions($transactions);
    }
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']);
    }
675346
public function queryAssoc($query, $options = array())
    {
        $statement = $this->_runQuery($query, $options);
        return $statement->fetch(\PDO::FETCH_ASSOC);
    }
264259
public function handleVersionOne(Transaction $transaction): Transaction
    {
        if (isset($transaction->secondSignature)) {
            $transaction->signSignature = $transaction->secondSignature;
        }

        if (Types::VOTE === $transaction->type) {
            $transaction->recipientId = Address::fromPublicKey($transaction->senderPublicKey, $transaction->network);
        }

        if (Types::MULTI_SIGNATURE_REGISTRATION === $transaction->type) {
            $transaction->asset['multisignature']['keysgroup'] = array_map(function ($key) {
                return '+'.$key;
            }, $transaction->asset['multisignature']['keysgroup']);
        }

        if (isset($transaction->vendorFieldHex)) {
            $transaction->vendorField = hex2bin($transaction->vendorFieldHex);
        }

        if (! isset($transaction->id)) {
            $transaction->id = $transaction->getId();
        }

        if (Types::SECOND_SIGNATURE_REGISTRATION === $transaction->type) {
            $transaction->recipientId = Address::fromPublicKey($transaction->senderPublicKey, $transaction->network);
        }

        if (Types::MULTI_SIGNATURE_REGISTRATION === $transaction->type) {
            $transaction->recipientId = Address::fromPublicKey($transaction->senderPublicKey, $transaction->network);
        }

        return $transaction;
    }
977962
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 = array();
            parse_str($response->getBody(true), $data);
        } catch (BadResponseException $e) {
            $data = array(
                'response' => '3',
                'message' => $e->getMessage()
            );
        }

        if (empty($data['response']) || '1' != $data['response']) {
            $result->setStatus(new Result\ResultStatus((!empty($data['response']) && '2' == $data['response']) ? Result\ResultStatus::DECLINED : Result\ResultStatus::ERROR));
            $result->setMessage(empty($data['responsetext']) ? 'An error occurred while processing the payment. Please try again.' : $data['responsetext']);

            if (!empty($data['transactionid'])) {
                $result->setExternalId($data['transactionid']);
            }
        } else {
            $result->setStatus(new Result\ResultStatus(Result\ResultStatus::APPROVED));
            $result->setExternalId($data['transactionid']);
        }

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

        return $result;
    }
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();
        }
714664
protected function runAction($action, array $options = array())
    {
        switch ($action) {
            case 'merge':
                return $this->runMergeAction($options);

            case 'tag':
                return $this->runTagAction($options);

            case 'pull':
                return $this->runPullAction($options);

            case 'push':
                return $this->runPushAction($options);
        }


        return false;
    }
546879
public function getNativeQuery(array $options = array())
    {
        if(!$this->persister) {
            throw new \RuntimeException('Persister is not specified.');
        }
        return $this->persister->getNativeQuery($this, $options);
    }
382929
public static function transformFilterTimestamp($transaction)
    {
        if (isset($transaction->timestamp)) {
            try {
                $transaction->timestamp = new \DateTime($transaction->timestamp);
            } catch (\Exception $e) {
                // Just log the attempt
                error_log($e->getMessage());
            }
        }

        return $transaction;
    }