Saves a transaction
@param array $transaction
173601
protected function applyTransaction(Array $transaction)
    {
        $changes = $transaction['changes'];
        $newCBDs = $transaction['newCBDs'];

        $subjectsOfChange = array();
        foreach($changes as $c)
        {
            if($c['rdf:type'][VALUE_URI]=="cs:ChangeSet")
            {
                array_push($subjectsOfChange, $c['cs:subjectOfChange']['u']);
            }
        }

        foreach($subjectsOfChange as $s)
        {
            foreach($newCBDs as $n)
            {
                if($n[_ID_KEY][_ID_RESOURCE]==$s)
                {
                    $this->updateCollection(array(_ID_KEY=>$n[_ID_KEY]), $n, array('upsert'=>true));
                    break;
                }
            }
        }
    }
877674
public function write(array $events = []): void
    {
        if ($this->isRolledBack) {
            throw new \RuntimeException('Cannot commit a rolledback transaction');
        }

        if ($this->isCommitted) {
            throw new \RuntimeException('Transaction is already committed');
        }

        $this->connection->transactionalWrite($this, $events, $this->userCredentials);
    }
399270
protected function initTransaction(array $options = [])
    {
        if (!isset($options['transactionId'])) {
            $this->transactionId = IdGenerator::generateId();
            $this->getClient()->sendFrame(
                $this->getProtocol()->getBeginFrame($this->transactionId)
            );
        } else {
            $this->transactionId = $options['transactionId'];
        }
    }
195257
public function normalize($transaction, $format = null, array $context = array())
    {
        /** @var  $transaction Transaction */
        $credentials = $transaction->getCredentials();

        $createTransactionRequest = array();

        if ($format == 'xml') {
            $createTransactionRequest['@xmlns'] = 'AnetApi/xml/v1/schema/AnetApiSchema.xsd';
        }

        $merchantAuthentication = array(
            'name' => $credentials->getCredential('username'),
            'transactionKey' => $credentials->getCredential('password'),
        );

        $transactionRequest = array(
            "transactionType" => $this->getTransactionType($transaction)
        );

        if ($transaction->getType()->getValue() != Transaction\TransactionType::VOID) {
            $transactionRequest['amount'] = $transaction->getAmount();
        }

        $account = $transaction->getAccount();
        if (in_array($transaction->getType()->getValue(), array(
            Transaction\TransactionType::SALE,
            Transaction\TransactionType::AUTH,
            Transaction\TransactionType::REFUND))
        ){
            $payment = array();
            if ($account instanceof CardAccount) {
                if ($account instanceof SwipedCardAccount
                    && $transaction->getType()->getValue() != Transaction\TransactionType::REFUND
                ){
                    $payment['trackData'] = array();
                    if ($account->getTrackOne()) {
                        $payment['trackData']['track1'] = $account->getTrackOne();
                    } elseif ($account->getTrackTwo()) {
                        $payment['trackData']['track2'] = $account->getTrackTwo();
                    }
                } else {
                    $payment = array(
                        'creditCard' => array(
                            'cardNumber' => $account->getAccountNumber(),
                            'expirationDate' => $account->getExpMonth()->getLongMonth() . $account->getExpYear()->getShortYear(),
                        )
                    );

                    if (isset($options['enable_cvv']) && true === $options['enable_cvv']
                        && $transaction->getType()->getValue() != Transaction\TransactionType::REFUND) {
                        $payment['creditCard']['cardCode'] = $account->getCvv();
                    }
                }
            } elseif ($account instanceof BankAccount) {
                $payment = array(
                    'bankAccount' => array(
                        'accountType' => 'checking',
                        'routingNumber' => $account->getRoutingNumber(),
                        'accountNumber' => $account->getAccountNumber(),
                        'nameOnAccount' => $account->getName()
                    )
                );
            } else {
                throw new InvalidArgumentException(sprintf("Unsupported Account Type %s", get_class($account)));
            }

            $transactionRequest['payment'] = $payment;
        }

        if ($context['event_id']) {
            $transactionRequest['order'] = array();
            $transactionRequest['order']['invoiceNumber'] = $context['event_id'];
        }


        if (in_array($transaction->getType()->getValue(), array(
            Transaction\TransactionType::CAPTURE,
            Transaction\TransactionType::REFUND,
            Transaction\TransactionType::VOID))
        ) {
            $transactionRequest['refTransId'] = $transaction->getParent()->getResult()->getExternalId();
        }


        if (in_array($transaction->getType()->getValue(), array(
            Transaction\TransactionType::SALE,
            Transaction\TransactionType::AUTH))
        ) {
                $names = explode(' ', $account->getName(), 2);
                $firstName = isset($names[0]) ? $names[0] : '';
                $lastName = isset($names[1]) ? $names[1] : '';

                if (isset($context['email'])) {
                    $transactionRequest['customer'] = array(
                        'email' => $context['email']
                    );
                }

                $transactionRequest['billTo'] = array(
                    'firstName' => $firstName,
                    'lastName' => $lastName,
                    'address' => $account->getAddress(),
                    'city' => $account->getCity(),
                    'state' => $account->getRegion(),
                    'zip' => $account->getPostalCode(),
                    'country' => $account->getCountry(),
                );
        }

        if ($account instanceof SwipedCardAccount
            && !in_array($transaction->getType()->getValue(), array(Transaction\TransactionType::REFUND, Transaction\TransactionType::VOID))
        ){
            $transactionRequest['retail'] = array(
                'marketType' => 2,
                'deviceType' => 7
            );
        }

        if (isset($context['test']) && $context['test'])  {
            $transactionRequest['transactionSettings']['setting'][] = array(
                'settingName' => 'testRequest',
                'settingValue' => 'true'
            );
        }

        if (isset($context['userFields'])) {
            $transactionRequest['userFields'] = array();
            $transactionRequest['userFields']['userField'] = array();
            foreach ($context['userFields'] as $name => $value) {
                $transactionRequest['userFields']['userField'][] = array(
                    'name' => $name,
                    'value' => $value
                );
            }
        }

        $createTransactionRequest['merchantAuthentication'] = $merchantAuthentication;
        $createTransactionRequest['transactionRequest'] = $transactionRequest;

        return $createTransactionRequest;
    }
285567
function(transaction, cb){
		contract(arguments)
			.params('array', 'function')
			.end()
		;
		
		// Execute transaction
		async.series(transaction,function(err){
			cb(err instanceof Error? err : undefined);
		});
	}
863400
private function setShippingMethod($quote, $transaction)
    {
        if ($quote->isVirtual()) {
            return;
        }

        $shippingAddress = $quote->getShippingAddress();
        $shippingAddress->setCollectShippingRates(true);

        $shippingMethod = $transaction->order->cart->shipments[0]->reference;

        $shippingAddress->setShippingMethod($shippingMethod)->save();
    }
460865
private function assertValidTransaction(array $transaction)
    {
        if(!isset($transaction['transaction_type'])) {
            throw new InvalidArgumentException("Transaction type is empty");
        }

        $this->assertValidContent($transaction['content']);
        $this->assertValidSender($transaction['from']);
        $this->assertValidRecipient($transaction['to']);
    }
105614
public function save($cascade = null, $use_transaction = false)
	{
		if ($this->frozen())
		{
			return false;
		}

		if ($use_transaction)
		{
			$db = \Database_Connection::instance(static::connection(true));
			$db->start_transaction();
		}

		try
		{
			$this->observe('before_save');

			$this->freeze();
			foreach($this->relations() as $rel_name => $rel)
			{
				if (array_key_exists($rel_name, $this->_reset_relations))
				{
					if (method_exists($rel, 'delete_related'))
					{
						$rel->delete_related($this);
						$this->_original_relations[$rel_name] = $rel->singular ? null : array();
					}
					else
					{
						if (empty($this->_original_relations[$rel_name]))
						{
							$data = $rel->get($this);
							if (is_array($data))
							{
								$this->_original_relations[$rel_name] = array();
								foreach ($data as $obj)
								{
									$this->_original_relations[$rel_name][] = $obj ? $obj->implode_pk($obj) : null;
								}
							}
							else
							{
								$this->_original_relations[$rel_name] = $data ? $data->implode_pk($data) : null;
							}
						}
					}
					unset($this->_reset_relations[$rel_name]);
				}
				if (array_key_exists($rel_name, $this->_data_relations))
				{
					$rel->save($this, $this->{$rel_name},
						array_key_exists($rel_name, $this->_original_relations) ? $this->_original_relations[$rel_name] : null,
						false, is_array($cascade) ? in_array($rel_name, $cascade) : $cascade
					);
				}
			}
			$this->unfreeze();

			// Insert or update
			$return = $this->_is_new ? $this->create() : $this->update();

			$this->freeze();
			foreach($this->relations() as $rel_name => $rel)
			{
				if (array_key_exists($rel_name, $this->_data_relations))
				{
					$rel->save($this, $this->{$rel_name},
						array_key_exists($rel_name, $this->_original_relations) ? $this->_original_relations[$rel_name] : null,
						true, is_array($cascade) ? in_array($rel_name, $cascade) : $cascade
					);
				}
			}
			$this->unfreeze();

			$this->_update_original();

			$this->observe('after_save');

			$use_transaction and $db->commit_transaction();
		}
		catch (\Exception $e)
		{
			$use_transaction and $db->rollback_transaction();
			throw $e;
		}

		return $return;
	}
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;
    }
1211986
public function transaction(Transaction $transaction): void
	{
		if ($this->config->gaClientId) {
			$data = new ArrayHash;
			$data->transaction_id = $transaction->id;
			if ($transaction->affiliation !== null) {
				$data->affiliation = $transaction->affiliation;
			}
			if ($transaction->value !== null) {
				$data->value = $transaction->value;
			}
			if ($transaction->currency !== null) {
				$data->currency = $transaction->currency;
			}
			if ($transaction->tax !== null) {
				$data->tax = $transaction->tax;
			}
			if ($transaction->shipping !== null) {
				$data->shipping = $transaction->shipping;
			}
			$data->items = [];
			foreach ($transaction->items as $item) {
				$itemData = new ArrayHash;
				$itemData->id = $item->id;
				$itemData->name = $item->name;
				if ($item->category !== null) {
					$itemData->category = $item->category;
				}
				if ($item->quantity !== null) {
					$itemData->quantity = $item->quantity;
				}
				if ($item->price !== null) {
					$itemData->price = $item->price;
				}
				$data->items[] = $itemData;
			}

			$this->event('purchase',
				$this->config->gaClientId,
				$data);
		}
	}
1274840
public function beginTransaction( $autoCommit = 1 )
	{
		$this->openTransactions ++;
		if( $this->openTransactions == 1 )
		{
			if( $autoCommit )
			{
				$query = "SET AUTOCOMMIT=0";
			}
			$this->Execute( $query );
			$query = "START TRANSACTION";
			$this->Execute ($query);
		}
	}
669385
public static void resume(Transaction transaction)
   {
      try {
         transactionManager.resume(transaction);
      }
      catch (Exception e) {
         throw new RuntimeException("Unable to resume transaction", e);
      }
   }
795686
public function commit(array $queries)
    {
        $this->transactionStart();
        $this->queries($queries, true);
        $this->transactionCommit();
    }
187696
public function commitTransaction(): bool
    {
        --$this->transactionLevel;

        if ($this->transactionLevel == 0) {
            $this->isProfiling() && $this->getLogger()->info('Commit transaction');

            try {
                return $this->getPDO()->commit();
            } catch (\PDOException $e) {
                throw $this->mapException($e, "COMMIT TRANSACTION");
            }
        }

        $this->savepointRelease($this->transactionLevel + 1);

        return true;
    }
1306531
public function save(array $options = array())
    {

        try {
            DB::transaction(function() use($options) {
                $this->fill($options);
                parent::save();
            });

            return true;
        } catch (Exception $e) {
            Log::emergency($e);
            return false;
        }
    }
520677
public function afterCommit(TransactionEvent $event) {
    if ($event->getPhase() == TransactionEvent::AFTER_COMMIT) {
      $response = $this->getResponse();
      $locationOid = $response->getHeader('Location');

      // replace changed oids
      $changedOids = $event->getInsertedOids();
      foreach ($changedOids as $oldOid => $newOid) {
        if ($response->hasValue($oldOid)) {
          $value = $response->getValue($oldOid);
          $response->setValue($newOid, $value);
          $response->clearValue($oldOid);
        }
        if ($locationOid == $oldOid) {
          $this->setLocationHeaderFromOid($newOid);
        }
      }
    }
  }
1020846
public function commit()
    {
        $this->assert();

        $current = $this->current;
        $this->current = $current->getParentKeepingChildren();

        if (!$this->current instanceof Transaction) {
            // There are no transactions, dispatch all reserved payloads
            foreach ($current->flatten() as $payload) {
                $payload->fire();
            }
        }
    }