Capture funds from a previously authorized transaction
439053
def capture_funds
      
      resp = StdClass.new      
      it = InvoiceTransaction.where(:invoice_id => self.id, :success => true).first
            
      if self.financial_status == Invoice::FINANCIAL_STATUS_CAPTURED
        resp.error = "Funds for this invoice have already been captured."    
      elsif self.total > it.amount
        resp.error = "The invoice total exceeds the authorized amount."
      elsif it.nil?
        resp.error = "This invoice doesn't seem to be authorized."
      else
                        
        sc = self.site.store_config                
        case sc.pp_name
          
          #when 'authorize.net'
          #  transaction = AuthorizeNet::AIM::Transaction.new(sc.authnet_api_login_id, sc.authnet_api_transaction_key)
          #  response = transaction.prior_auth_capture(t.transaction_id, self.total)
          #  
          #  ot = Caboose::InvoiceTransaction.create(
          #    :invoice_id        => self.id,
          #    :date_processed    => DateTime.now.utc,
          #    :transaction_type  => InvoiceTransaction::TYPE_CAPTURE,
          #    :payment_processor => sc.pp_name,
          #    :amount            => self.total,        
          #    :success           => response.response_code && response.response_code == '1',            
          #    :transaction_id    => response.transaction_id,
          #    :auth_code         => response.authorization_code,
          #    :response_code     => response.response_code
          #  )
          #  if ot.success
          #    self.date_captured = DateTime.now.utc
          #    self.save              
          #  end                                    
          #  self.update_attribute(:financial_status, Invoice::FINANCIAL_STATUS_CAPTURED)
          #  resp.success = 'Captured funds successfully'
                                    
          when StoreConfig::PAYMENT_PROCESSOR_STRIPE
                                          
            it = Caboose::InvoiceTransaction.where(:invoice_id => self.id, :success => true).first
            if it.nil?
              resp.error = "Error capturing funds for invoice #{self.id}. No previous successful authorization for this invoice exists."
              return false
            else                        
              Stripe.api_key = sc.stripe_secret_key.strip
              bt = nil
              begin
                c = Stripe::Charge.retrieve(it.transaction_id)
                c = c.capture
                bt = Stripe::BalanceTransaction.retrieve(c.balance_transaction)
              rescue Exception => ex
                resp.error = "Error during capture process\n#{ex.message}"                
              end
              
              if resp.error.nil?
                InvoiceTransaction.create(
                  :invoice_id => self.id,
                  :transaction_id => bt.id,
                  :transaction_type => InvoiceTransaction::TYPE_CAPTURE,
                  :payment_processor => sc.pp_name,
                  :amount => bt.amount / 100,                
                  :date_processed => DateTime.strptime(bt.created.to_s, '%s'),
                  :success => bt.status == 'succeeded' || bt.status == 'pending'
                )
                if bt.status == 'succeeded' || bt.status == 'pending'
                  self.financial_status = Invoice::FINANCIAL_STATUS_CAPTURED
                  self.save
                  resp.success = true
                else
                  resp.error = "Error capturing funds."
                end
              end
            end
          
        end        
      end      
      return resp
    end
469261
def fetch_deposits(self, limit: int) -> List[Deposit]:
        """"""
        return self._transactions(self._deposits, 'deposits', limit)
545533
public function capture($transactionId, $amount = null, $gratuity = null, $clientTransactionId = null, $directMarketData = null)
    {
        $xml = new DOMDocument();
        $hpsTransaction = $xml->createElement('hps:Transaction');
        $hpsCreditAddToBatch = $xml->createElement('hps:CreditAddToBatch');

        $hpsCreditAddToBatch->appendChild($xml->createElement('hps:GatewayTxnId', $transactionId));
        if ($amount != null) {
            $amount = sprintf("%0.2f", round($amount, 3));
            $hpsCreditAddToBatch->appendChild($xml->createElement('hps:Amt', $amount));
        }
        if ($gratuity != null) {
            $hpsCreditAddToBatch->appendChild($xml->createElement('hps:GratuityAmtInfo', $gratuity));
        }

        if ($directMarketData != null && $directMarketData->invoiceNumber != null) {
            $hpsCreditAddToBatch->appendChild($this->_hydrateDirectMarketData($directMarketData, $xml));
        }

        $hpsTransaction->appendChild($hpsCreditAddToBatch);
        $options = array();
        if ($clientTransactionId != null) {
            $options['clientTransactionId'] = $clientTransactionId;
        }
        $response = $this->doRequest($hpsTransaction, $options);
        $this->_processChargeGatewayResponse($response, 'CreditAddToBatch');

        return $this->get($transactionId);
    }
6402
def authorize_and_capture
      
      resp = StdClass.new                        
      if self.financial_status == Invoice::FINANCIAL_STATUS_CAPTURED
        resp.error = "Funds for this invoice have already been captured."
      else
                        
        sc = self.site.store_config                
        case sc.pp_name                                    
          when StoreConfig::PAYMENT_PROCESSOR_STRIPE
                                                                              
            Stripe.api_key = sc.stripe_secret_key.strip
            bt = nil
            begin
              c = Stripe::Charge.create(
                :amount => (self.total * 100).to_i,
                :currency => 'usd',
                :customer => self.customer.stripe_customer_id,
                :capture => true,
                :metadata => { :invoice_id => self.id },
                :statement_descriptor => "#{self.site.description.truncate(22)}"
              )                        
            rescue Exception => ex
              resp.error = "Error during capture process\n#{ex.message}"                
            end            
            if resp.error.nil?
              InvoiceTransaction.create(
                :invoice_id => self.id,
                :transaction_id => c.id,
                :transaction_type => InvoiceTransaction::TYPE_AUTHCAP,
                :payment_processor => sc.pp_name,
                :amount => c.amount / 100.0,
                :captured => true,
                :date_processed => DateTime.now.utc,
                :success => c.status == 'succeeded'
              )
              if c.status == 'succeeded'
                self.financial_status = Invoice::FINANCIAL_STATUS_CAPTURED
                self.save
                resp.success = true
              else
                resp.error = "Error capturing funds."
              end
            end
                      
        end        
      end      
      return resp
    end
1258924
def fetch_withdrawals(self, limit: int) -> List[Withdrawal]:
        """"""
        return self._transactions(self._withdrawals, 'withdrawals', limit)
1054335
public void newTransactionHandler(PersistedTransaction tx, PersistedV2Key key) throws Exception {
        listenForUpdates(tx);
        tx.keyId = key.getId();
        tx.walletId = this.descriptor.getKey();
        tx.account = key.account;
        System.out.println("Incoming transaction captured in API service: " + tx.toString());
        transactionDAO.create(tx);
        WalletChange change = new WalletChange(tx.value, getBalance(), createKey(key.account).address, tx);
        WalletChangeMessage out = new WalletChangeMessage();
        out.setCommand(Command.BALANCE_CHANGE_RECEIVED);
        out.setKey(this.descriptor.key);
        out.setPayload(change);
        router.sendUpdate(this.descriptor.key, out);
    }
429584
public function capture($money, $authorization, $options = array())
  {
      $options = array_merge($options, array('authorization' => $authorization));
      $this->build_xml($money, 'Capture', null, $options);

      return $this->commit();
  }
61500
def get_transactions_filtered(self, asset_id, operation=None):
        
        txids = backend.query.get_txids_filtered(self.connection, asset_id,
                                                 operation)
        for txid in txids:
            yield self.get_transaction(txid)
986931
def get_withdrawal(self, withdrawal_id, **params):
        """"""
        return self.api_client.get_withdrawal(self.id, withdrawal_id, **params)
911162
def capture(self, payment_id, amount, data={}, **kwargs):
        "
        url = "{}/{}/capture".format(self.base_url, payment_id)
        data['amount'] = amount
        return self.post_url(url, data, **kwargs)
882998
def UndoTransaction(self):
		
		from Ucs import ConfigMap

		self._transactionInProgress = False
		self._configMap = ConfigMap()
264191
def get_withdrawal(self, account_id, withdrawal_id, **params):
        """"""
        response = self._get(
            'v2', 'accounts', account_id, 'withdrawals', withdrawal_id, params=params)
        return self._make_api_object(response, Withdrawal)
1346817
def fetch_withdrawals_since(self, since: int) -> List[Withdrawal]:
        """"""
        return self._transactions_since(self._withdrawals_since, 'withdrawals', since)
710493
def receive_request(self, transaction):
        

        transaction.cached_element = self.cache.search_response(transaction.request)
        if transaction.cached_element is None:
            transaction.cacheHit = False
        else:
            transaction.response = transaction.cached_element.cached_response
            transaction.response.mid = transaction.request.mid
            transaction.cacheHit = True

            age = transaction.cached_element.creation_time + transaction.cached_element.max_age - time.time()
            if transaction.cached_element.freshness is True:
                if age <= 0:
                    logger.debug("resource not fresh")
                    """
                    if the resource is not fresh, its Etag must be added to the request so that the server might validate it instead of sending a new one
                    """
                    transaction.cached_element.freshness = False
                    """
                    ensuring that the request goes to the server
                    """
                    transaction.cacheHit = False
                    logger.debug("requesting etag %s", transaction.response.etag)
                    transaction.request.etag = transaction.response.etag
                else:
                    transaction.response.max_age = age
            else:
                transaction.cacheHit = False
        return transaction
169694
def get_transaction(self, account_id, transaction_id, **params):
        """"""
        response = self._get(
            'v2', 'accounts', account_id, 'transactions', transaction_id, params=params)
        return self._make_api_object(response, Transaction)
793305
function (transfer, cb) {

		Transfer.findOrCreate(transfer.id, transfer)
	    .exec(function (err, foundTransfer){
	      if (err) return cb(err);
	      if (foundTransfer.lastStripeEvent > transfer.lastStripeEvent) return cb(null, foundTransfer);
	      if (foundTransfer.lastStripeEvent == transfer.lastStripeEvent) return Transfer.afterStripeTransferCreated(foundTransfer, function(err, transfer){ return cb(err, transfer)});
	      Transfer.update(foundTransfer.id, transfer)
	      .exec(function(err, updatedTransfers){
	      	if (err) return cb(err);
	      	if(!updatedTransfers) return cb(null, null);
	      	Transfer.afterStripeTransferCreated(updatedTransfers[0], function(err, transfer){
	      		cb(err, transfer);
	      	});
	      });
	    });
	}
1175537
def get(self, limit=None, offset=None):
        
        return self.connection.get('account/transfer/admin/array', limit=limit, offset=offset)