lib/braintree/transaction.rb in braintree-2.1.0 vs lib/braintree/transaction.rb in braintree-2.2.0
- old
+ new
@@ -221,18 +221,17 @@
end
# Returns a ResourceCollection of transactions matching the search query.
# If <tt>query</tt> is a string, the search will be a basic search.
# If <tt>query</tt> is a hash, the search will be an advanced search.
- def self.search(query = nil, page=1, &block)
- if block_given?
- _advanced_search page, &block
- elsif query.is_a?(String)
- _basic_search query, page
- else
- raise ArgumentError, "expected search to be a string or a block"
- end
+ # See: http://www.braintreepaymentsolutions.com/gateway/transaction-api#searching
+ def self.search(&block)
+ search = TransactionSearch.new
+ block.call(search) if block
+
+ response = Http.post "/transactions/advanced_search_ids", {:search => search.to_hash}
+ ResourceCollection.new(response) { |ids| _fetch_transactions(search, ids) }
end
# Submits transaction with +transaction_id+ for settlement.
def self.submit_for_settlement(transaction_id, amount = nil)
raise ArgumentError, "transaction_id is invalid" unless transaction_id =~ /\A[0-9a-z]+\z/
@@ -393,41 +392,30 @@
else
raise UnexpectedError, "expected :transaction or :api_error_response"
end
end
- def self._advanced_search(page, &block) # :nodoc:
- search = TransactionSearch.new
- block.call(search)
-
- response = Http.post "/transactions/advanced_search?page=#{page}", {:search => search.to_hash}
- attributes = response[:credit_card_transactions]
- attributes[:items] = Util.extract_attribute_as_array(attributes, :transaction).map { |attrs| _new(attrs) }
-
- ResourceCollection.new(attributes) { |page_number| Transaction.search(nil, page_number, &block) }
- end
-
def self._attributes # :nodoc:
[:amount, :created_at, :credit_card_details, :customer_details, :id, :status, :type, :updated_at]
end
- def self._basic_search(query, page) # :nodoc:
- response = Http.get "/transactions/all/search?q=#{Util.url_encode(query)}&page=#{Util.url_encode(page)}"
- attributes = response[:credit_card_transactions]
- attributes[:items] = Util.extract_attribute_as_array(attributes, :transaction).map { |attrs| _new(attrs) }
- ResourceCollection.new(attributes) { |page_number| Transaction.search(query, page_number) }
- end
-
def self._create_signature # :nodoc:
[
:amount, :customer_id, :merchant_account_id, :order_id, :payment_method_token, :type,
{:credit_card => [:token, :cardholder_name, :cvv, :expiration_date, :expiration_month, :expiration_year, :number]},
{:customer => [:id, :company, :email, :fax, :first_name, :last_name, :phone, :website]},
{:billing => [:first_name, :last_name, :company, :country_name, :extended_address, :locality, :postal_code, :region, :street_address]},
{:shipping => [:first_name, :last_name, :company, :country_name, :extended_address, :locality, :postal_code, :region, :street_address]},
{:options => [:store_in_vault, :submit_for_settlement, :add_billing_address_to_payment_method, :store_shipping_address_in_vault]},
{:custom_fields => :_any_key_}
]
+ end
+
+ def self._fetch_transactions(search, ids)
+ search.ids.in ids
+ response = Http.post "/transactions/advanced_search", {:search => search.to_hash}
+ attributes = response[:credit_card_transactions]
+ Util.extract_attribute_as_array(attributes, :transaction).map { |attrs| _new(attrs) }
end
def _init(attributes) # :nodoc:
set_instance_variables_from_hash(attributes)
@amount = Util.to_big_decimal(amount)