Class: Braintree::MerchantAccountGateway

Inherits:
Object
  • Object
show all
Includes:
BaseModule
Defined in:
lib/braintree/merchant_account_gateway.rb

Instance Method Summary collapse

Methods included from BaseModule

included

Methods included from BaseModule::Methods

#copy_instance_variables_from_object, #return_object_or_raise, #set_instance_variables_from_hash, #singleton_class

Constructor Details

#initialize(gateway) ⇒ MerchantAccountGateway

Returns a new instance of MerchantAccountGateway.



5
6
7
8
9
# File 'lib/braintree/merchant_account_gateway.rb', line 5

def initialize(gateway)
  @gateway = gateway
  @config = gateway.config
  @config.assert_has_access_token_or_keys
end

Instance Method Details

#_create_for_currency(params) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/braintree/merchant_account_gateway.rb', line 35

def _create_for_currency(params)
  response = @config.http.post("#{@config.base_merchant_path}/merchant_accounts/create_for_currency", :merchant_account => params)

  if response.has_key?(:response) && response[:response][:merchant_account]
    Braintree::SuccessfulResult.new(
      :merchant_account => MerchantAccount._new(@gateway, response[:response][:merchant_account]),
    )
  elsif response[:api_error_response]
    ErrorResult.new(@gateway, response[:api_error_response])
  else
    raise UnexpectedError, "expected :merchant or :api_error_response"
  end
end

#_fetch_merchant_accounts(page_number) ⇒ Object



16
17
18
19
20
21
# File 'lib/braintree/merchant_account_gateway.rb', line 16

def _fetch_merchant_accounts(page_number)
  response = @config.http.get("#{@config.base_merchant_path}/merchant_accounts?page=#{page_number}")
  body = response[:merchant_accounts]
  merchant_accounts = Util.extract_attribute_as_array(body, :merchant_account).map { || MerchantAccount._new(@gateway, ) }
  PaginatedResult.new(body[:total_items], body[:page_size], merchant_accounts)
end

#allObject



11
12
13
14
# File 'lib/braintree/merchant_account_gateway.rb', line 11

def all
  pc = PaginatedCollection.new { |page| _fetch_merchant_accounts(page) }
  SuccessfulResult.new(:merchant_accounts => pc)
end

#create_for_currency(params) ⇒ Object



31
32
33
# File 'lib/braintree/merchant_account_gateway.rb', line 31

def create_for_currency(params)
  _create_for_currency(params)
end

#find(merchant_account_id) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/braintree/merchant_account_gateway.rb', line 23

def find()
  raise ArgumentError if .nil? || .to_s.strip == ""
  response = @config.http.get("#{@config.base_merchant_path}/merchant_accounts/#{}")
  MerchantAccount._new(@gateway, response[:merchant_account])
rescue NotFoundError
  raise NotFoundError, "Merchant account with id #{} not found"
end