Transacts the given transaction

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

@return \Orkestra\Transactor\Entity\Result
331511
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, array('Content-Type' => 'application/xml'), $params);

        try {
            $response = $request->send();
            $data = (string) $response->getBody(true);
            $data = $this->removeNS($data);

            if ($data) {
                $data = $this->serializer->decode($data, 'xml');
            } else {
                throw new BadResponseException();
            }
        } catch (BadResponseException $e) {
            $data = array(
                'messages' => array(
                    'resultCode' => 'Error'
                ),
                'transactionResponse' => array(
                    'responseCode' => 200,
                    'errors' => array(
                        'error' => array(
                            'errorText' => 'An error occurred while processing the payment. Please try again.',
                            'errorCode' => 200
                        )
                    )
                )
            );
        }

        if ($data['messages']['resultCode'] != 'Ok' || $data['transactionResponse']['responseCode'] > 1) {
            $responseCode = (is_array($data['transactionResponse']) && isset($data['transactionResponse']['responseCode'])) ? $data['transactionResponse']['responseCode'] : $data['messages']['message']['code'];
            $error = array('errorCode' => 3, 'errorText' => 'An error occurred while processing the transaction');
            if (isset($data['transactionResponse'])
                && isset($data['transactionResponse']['errors'])
                && count($data['transactionResponse']['errors']) > 0
            ) {
                $error = $data['transactionResponse']['errors']['error'];
            } else if (is_array($data['transactionResponse'])
                && isset($data['transactionResponse']['responseCode'])
            ) {

                $error = array('errorCode' => $responseCode, 'errorText' => $responseCode == 2 ? 'The transaction was declined' : 'An error occurred while processing the transaction');
            }

            $result->setStatus(new Result\ResultStatus( 1 < $responseCode && $responseCode < 5 ? Result\ResultStatus::DECLINED : Result\ResultStatus::ERROR));
            $result->setMessage(sprintf('Error Code: %d. %s', $error['errorCode'], $error['errorText']));

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

            $result->setExternalId($data['transactionResponse']['transId']);
        }

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

        return $result;
    }
1111172
protected function validateTransaction(Transaction $transaction)
    {
        if (!$transaction->getParent() && in_array($transaction->getType()->getValue(), array(
            Transaction\TransactionType::REFUND))
        ) {
            throw ValidationException::parentTransactionRequired();
        }

        $credentials = $transaction->getCredentials();

        if (!$credentials) {
            throw ValidationException::missingCredentials();
        } elseif (null === $credentials->getCredential('username') || null === $credentials->getCredential('password')) {
            throw ValidationException::missingRequiredParameter('username or password');
        }

        /** @var BankAccount $account */
        $account = $transaction->getAccount();

        if (!$account || !$account instanceof BankAccount) {
            throw ValidationException::missingAccountInformation();
        }

        if (null === $account->getAccountNumber()) {
            throw ValidationException::missingRequiredParameter('account number');
        } elseif (null === $account->getRoutingNumber()) {
            throw ValidationException::missingRequiredParameter('routing number');
        } elseif (null === $account->getAccountType()) {
            throw ValidationException::missingRequiredParameter('account type');
        }
    }
103242
protected function buildParams(Transaction $transaction, array $options = array())
    {
        $credentials = $transaction->getCredentials();

        $params = array(
            'type' => $this->getNmiType($transaction),
            'username' => $credentials->getCredential('username'),
            'password' => $credentials->getCredential('password'),
        );

        if (in_array($transaction->getType()->getValue(), array(
            Transaction\TransactionType::CAPTURE,
            Transaction\TransactionType::REFUND,
            Transaction\TransactionType::VOID))
        ) {
            $params = array_merge($params, array(
                'transactionid' => $transaction->getParent()->getResult()->getExternalId(),
            ));
        } else {
            $account = $transaction->getAccount();

            if ($account instanceof SwipedCardAccount) {
                $params = array_merge($params, array(
                    'track_1' => $account->getTrackOne(),
                    'track_2' => $account->getTrackTwo(),
                    'track_3' => $account->getTrackThree()
                ));
            } else {
                $params = array_merge($params, array(
                    'ccnumber' => $account->getAccountNumber(),
                    'ccexp' => $account->getExpMonth()->getLongMonth() . $account->getExpYear()->getShortYear()
                ));

                if (isset($options['enable_cvv']) && true === $options['enable_cvv']) {
                    $params['cvv'] = $account->getCvv();
                }

                if (isset($options['enable_avs']) && true === $options['enable_avs']) {
                    $names = explode(' ', $account->getName(), 2);
                    $firstName = isset($names[0]) ? $names[0] : '';
                    $lastName = isset($names[1]) ? $names[1] : '';

                    $params = array_merge($params, array(
                        'firstname' => $firstName,
                        'lastname' => $lastName,
                        'address' => $account->getAddress(),
                        'city' => $account->getCity(),
                        'state' => $account->getRegion(),
                        'zip' => $account->getPostalCode(),
                        'country' => $account->getCountry(),
                        'ipaddress' => $account->getIpAddress()
                    ));
                }
            }
        }

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

        return $params;
    }
1303904
public function capture($money, $authorization, $options = array())
    {
        $this->required_options("order_id", $options);

        $this->post = array(
            "AuthTrxnNumber" => $authorization,
            "TotalAmount" => $this->amount($money)
        );

        $cc = new CreditCard(array());
        $this->addCreditcard($cc);
        #$this->addInvoice($options);
        $this->addOptionalData();
        return $this->commit("xmlauthcomplete", $money);
    }
1132423
private function commitInSingleUseTransaction(array $mutations, array $options = [])
    {
        $options['mutations'] = $mutations;

        return $this->runTransaction(function (Transaction $t) use ($options) {
            return $t->commit($options);
        }, [
            'singleUse' => true
        ]);
    }
398427
protected function validateTransaction(Transaction $transaction)
    {
        if (!$transaction->getParent() && in_array($transaction->getType()->getValue(), array(Transaction\TransactionType::CAPTURE, Transaction\TransactionType::REFUND, Transaction\TransactionType::VOID))) {
            throw ValidationException::parentTransactionRequired();
        }

        $credentials = $transaction->getCredentials();

        if (!$credentials) {
            throw ValidationException::missingCredentials();
        } elseif (null === $credentials->getCredential('username') || null === $credentials->getCredential('password')) {
            throw ValidationException::missingRequiredParameter('username or password');
        }

        $account = $transaction->getAccount();

        if (!$account) {
            throw ValidationException::missingAccountInformation();
        }

        if ((!($account instanceof CardAccount) && !($account instanceof SwipedCardAccount))
            || (!($account instanceof SwipedCardAccount) && $transaction->getNetwork() == Transaction\NetworkType::SWIPED)
        ) {
            throw ValidationException::invalidAccountType($account);
        }

        if (!$account instanceof SwipedCardAccount) {
            if (null === $account->getAccountNumber()) {
                throw ValidationException::missingRequiredParameter('account number');
            } elseif (null === $account->getExpMonth() || null === $account->getExpYear()) {
                throw ValidationException::missingRequiredParameter('card expiration');
            }
        }
    }
377561
public function perform($action, $table, $body, $options = [])
    {
        $query = $this->createQuery($action, $table, $options)->body($body);

        return $this->createRequest($query);
    }
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;
    }
319834
public function isSuccess( $transaction = RecordManager::TRANSACTIONS_ALL )
    {
        $output = true;
        foreach( $this->getStatus($transaction) as $transaction => $transactionStatus ) {
            foreach( $transactionStatus as $status ) {
                $output = ( $output && $status === self::SUCCESS );
            }
        }
        return $output;
    }
159753
public function process(Request $request, Transaction $transaction, Delivery $delivery)
    {
        
        // in your controller
        $transactionService = $this->get('transaction');
        $data = $request->get('braintree');
        $nonce = $data['payment_method_nonce'];

        $result = $transactionService::sale([
            'amount' => $transaction->getTotalPrice(),
            'paymentMethodNonce' => $nonce
        ]);
        
        
        $em = $this->container->get('doctrine')->getManager();
        $pm = $em->getRepository('EcommerceBundle:PaymentMethod')->findOneBySlug('braintree');
        if ($result->success || !is_null($result->transaction)) {
                        
            //UPDATE TRANSACTION
            $transaction->setStatus(Transaction::STATUS_PAID);
            $transaction->setPaymentMethod($pm);
            
            //details
            $details = new stdClass();
            $details->id = $result->transaction->id;
            $details->status = $result->transaction->status;
            $details->type = $result->transaction->type;
            $details->currencyIsoCode = $result->transaction->currencyIsoCode;
            $details->amount = $result->transaction->amount;
            $details->merchantAccountId = $result->transaction->merchantAccountId;
            $details->createdAt = $result->transaction->createdAt;
            $details->updatedAt = $result->transaction->updatedAt;
            $details->customer = $result->transaction->customer;
            $details->billing = $result->transaction->billing;
            $details->shipping = $result->transaction->shipping;
            
            $transaction->setPaymentDetails(json_encode($details));
            $em->persist($transaction);
            $em->flush();

            //confirmation payment
            $answer = new stdClass();
            $answer->redirectUrl = $this->container->get('router')->generate('ecommerce_checkout_confirmationpayment');

            return $answer;
       }else{
            //UPDATE TRANSACTION
            $transaction->setStatus(Transaction::STATUS_CANCELLED);
            $transaction->setPaymentMethod($pm);
            
            //details
            $errorString = "";
            foreach($result->errors->deepAll() as $error) {
               $errorString .= 'Error: ' . $error->code . ": " . $error->message . "\n";
            }
            $this->container->get('session')->getFlashBag()->add('error', $errorString);
            
            $transaction->setPaymentDetails(json_encode($errorString));
            $em->persist($transaction);
            $em->flush();

            //cancel payment
            $answer = new stdClass();
            $answer->redirectUrl = $this->container->get('router')->generate('ecommerce_checkout_cancelationpayment');

            return $answer;
        }
 
    }
268472
public function void($authorization, $options = array())
    {
        $this->required_options('pasref, order_id', $options);
        $this->buildVoidRequest($authorization, $options);

        return $this->commit();
    }
368982
protected function validateTransaction(Transaction $transaction)
    {
        if (!$transaction->getParent() && in_array($transaction->getType()->getValue(), array(
            Transaction\TransactionType::CAPTURE,
            Transaction\TransactionType::REFUND,
            Transaction\TransactionType::VOID,
            Transaction\TransactionType::QUERY,
            Transaction\TransactionType::UPDATE))
        ) {
            throw ValidationException::parentTransactionRequired();
        }

        $credentials = $transaction->getCredentials();

        if (!$credentials) {
            throw ValidationException::missingCredentials();
        } elseif (null === $credentials->getCredential('providerId')) {
            throw ValidationException::missingRequiredParameter('Provider ID');
        } elseif (null === $credentials->getCredential('providerGateId')) {
            throw ValidationException::missingRequiredParameter('Provider Gate ID');
        } elseif (null === $credentials->getCredential('providerGateKey')) {
            throw ValidationException::missingRequiredParameter('Provider Gate Key');
        } elseif (null === $credentials->getCredential('merchantId')) {
            throw ValidationException::missingRequiredParameter('Merchant ID');
        } elseif (null === $credentials->getCredential('merchantGateId')) {
            throw ValidationException::missingRequiredParameter('Merchant Gate ID');
        } elseif (null === $credentials->getCredential('merchantGateKey')) {
            throw ValidationException::missingRequiredParameter('Merchant Gate Key');
        }

        $account = $transaction->getAccount();

        if (!$account || !$account instanceof BankAccount) {
            throw ValidationException::missingAccountInformation();
        }

        if (null === $account->getAccountNumber()) {
            throw ValidationException::missingRequiredParameter('account number');
        } elseif (null === $account->getRoutingNumber()) {
            throw ValidationException::missingRequiredParameter('routing number');
        } elseif (null === $account->getIpAddress()) {
            throw ValidationException::missingRequiredParameter('IP address');
        } elseif (null === $account->getAccountType()) {
            throw ValidationException::missingRequiredParameter('account type');
        }
    }
494553
public function setTransactiontype($transaction = 0)
    {
        if ($this->isEmpty($transaction)) {
            throw new TpvException('Please add transaction type');
        }

        $this->_setParameters['DS_MERCHANT_TRANSACTIONTYPE'] = $transaction;

        return $this;
    }
7494
public function authorize($money, Merchant_Billing_CreditCard $creditcard, $options = array())
  {
      $this->required_options('customer_email', $options);
      $this->build_xml($money, 'PreAuth', $creditcard, $options);

      return $this->commit();
  }
1192433
public function transAlterTable($table, $options, $advanced_options)
    {
        $this->transInitTable($table);
        $this->schemaUpdateTransaction[$table]['alteredOptions'] = $options;
        $this->schemaUpdateTransaction[$table]['advancedOptions'] = $advanced_options;
    }
930786
def create_transaction(options = {})
      agent.create_transaction(self['id'], options) do |data, resp|
        yield(data, resp) if block_given?
      end
    end
1002724
public function update(Transaction $transaction, UpdateTransactionRequest $request)
    {
        $this->transaction->update($transaction, $request->all());

        return redirect()->route('admin.order.order.show', $transaction->order_id)
            ->withSuccess(trans('core::core.messages.resource updated', ['name' => trans('order::transactions.title.transactions')]));
    }