class Braintree::MerchantAccountGateway

Public Class Methods

_create_signature() click to toggle source
# File lib/braintree/merchant_account_gateway.rb, line 122
def self._create_signature
  _signature + [:tos_accepted, :master_merchant_account_id, :id]
end
_deprecated_create_signature() click to toggle source

NEXT_MAJOR_VERSION this is part of Marketplace and shouldn’t be removed unless we’re removing all Marketplace code

# File lib/braintree/merchant_account_gateway.rb, line 97
def self._deprecated_create_signature
  [
    {:applicant_details => [
      :first_name, :last_name, :email, :date_of_birth, :ssn, :routing_number,
      :account_number, :tax_id, :company_name, :phone,
      {:address => [:street_address, :postal_code, :locality, :region]}]
    },
    :tos_accepted, :master_merchant_account_id, :id
  ]
end
_detect_signature(attributes) click to toggle source

NEXT_MAJOR_VERSION this is part of Marketplace and shouldn’t be removed unless we’re removing all Marketplace code

# File lib/braintree/merchant_account_gateway.rb, line 87
def self._detect_signature(attributes)
  if attributes.has_key?(:applicant_details)
    warn "[DEPRECATED] Passing :applicant_details to create is deprecated. Please use :individual, :business, and :funding."
    MerchantAccountGateway._deprecated_create_signature
  else
    MerchantAccountGateway._create_signature
  end
end
_signature() click to toggle source
# File lib/braintree/merchant_account_gateway.rb, line 108
def self._signature
  [
    {:individual => [
      :first_name, :last_name, :email, :date_of_birth, :ssn, :phone,
      {:address => [:street_address, :locality, :region, :postal_code]}]
    },
    {:business => [
      :dba_name, :legal_name, :tax_id,
      {:address => [:street_address, :locality, :region, :postal_code]}]
    },
    {:funding => [:destination, :email, :mobile_phone, :routing_number, :account_number, :descriptor]}
  ]
end
_update_signature() click to toggle source
# File lib/braintree/merchant_account_gateway.rb, line 126
def self._update_signature
  _signature
end
new(gateway) click to toggle source
# 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

Public Instance Methods

_create_for_currency(params) click to toggle source
# File lib/braintree/merchant_account_gateway.rb, line 72
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
_do_create(path, params=nil) click to toggle source
# File lib/braintree/merchant_account_gateway.rb, line 54
def _do_create(path, params=nil)
  response = @config.http.post("#{@config.base_merchant_path}#{path}", params)
  if response[:api_error_response]
    ErrorResult.new(@gateway, response[:api_error_response])
  else
    SuccessfulResult.new(:merchant_account => MerchantAccount._new(@gateway, response[:merchant_account]))
  end
end
_do_update(path, params=nil) click to toggle source
# File lib/braintree/merchant_account_gateway.rb, line 63
def _do_update(path, params=nil)
  response = @config.http.put("#{@config.base_merchant_path}#{path}", params)
  if response[:api_error_response]
    ErrorResult.new(@gateway, response[:api_error_response])
  else
    SuccessfulResult.new(:merchant_account => MerchantAccount._new(@gateway, response[:merchant_account]))
  end
end
_fetch_merchant_accounts(page_number) click to toggle source
# 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 { |merchant_account| MerchantAccount._new(@gateway, merchant_account) }
  PaginatedResult.new(body[:total_items], body[:page_size], merchant_accounts)
end
all() click to toggle source
# 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(attributes) click to toggle source
# File lib/braintree/merchant_account_gateway.rb, line 23
def create(attributes)
  signature = MerchantAccountGateway._detect_signature(attributes)
  Util.verify_keys(signature, attributes)
  _do_create "/merchant_accounts/create_via_api", :merchant_account => attributes
end
create!(*args) click to toggle source
# File lib/braintree/merchant_account_gateway.rb, line 29
def create!(*args)
  return_object_or_raise(:merchant_account) { create(*args) }
end
create_for_currency(params) click to toggle source
# File lib/braintree/merchant_account_gateway.rb, line 50
def create_for_currency(params)
  _create_for_currency(params)
end
find(merchant_account_id) click to toggle source
# File lib/braintree/merchant_account_gateway.rb, line 33
def find(merchant_account_id)
  raise ArgumentError if merchant_account_id.nil? || merchant_account_id.to_s.strip == ""
  response = @config.http.get("#{@config.base_merchant_path}/merchant_accounts/#{merchant_account_id}")
  MerchantAccount._new(@gateway, response[:merchant_account])
rescue NotFoundError
  raise NotFoundError, "Merchant account with id #{merchant_account_id} not found"
end
update(merchant_account_id, attributes) click to toggle source
# File lib/braintree/merchant_account_gateway.rb, line 41
def update(merchant_account_id, attributes)
  Util.verify_keys(MerchantAccountGateway._update_signature, attributes)
  _do_update "/merchant_accounts/#{merchant_account_id}/update_via_api", :merchant_account => attributes
end
update!(*args) click to toggle source
# File lib/braintree/merchant_account_gateway.rb, line 46
def update!(*args)
  return_object_or_raise(:merchant_account) { update(*args) }
end