Class: Braintree::MerchantAccountGateway

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

Class Method Summary collapse

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

Class Method Details

._create_signatureObject



122
123
124
# File 'lib/braintree/merchant_account_gateway.rb', line 122

def self._create_signature
  _signature + [:tos_accepted, :master_merchant_account_id, :id]
end

._deprecated_create_signatureObject

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



97
98
99
100
101
102
103
104
105
106
# 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) ⇒ Object

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



87
88
89
90
91
92
93
94
# 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

._signatureObject



108
109
110
111
112
113
114
115
116
117
118
119
120
# 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_signatureObject



126
127
128
# File 'lib/braintree/merchant_account_gateway.rb', line 126

def self._update_signature
  _signature
end

Instance Method Details

#_create_for_currency(params) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
# 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) ⇒ Object



54
55
56
57
58
59
60
61
# 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) ⇒ Object



63
64
65
66
67
68
69
70
# 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) ⇒ 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(attributes) ⇒ Object



23
24
25
26
27
# 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) ⇒ Object



29
30
31
# 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) ⇒ Object



50
51
52
# File 'lib/braintree/merchant_account_gateway.rb', line 50

def create_for_currency(params)
  _create_for_currency(params)
end

#find(merchant_account_id) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/braintree/merchant_account_gateway.rb', line 33

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

#update(merchant_account_id, attributes) ⇒ Object



41
42
43
44
# File 'lib/braintree/merchant_account_gateway.rb', line 41

def update(, attributes)
  Util.verify_keys(MerchantAccountGateway._update_signature, attributes)
  _do_update "/merchant_accounts/#{}/update_via_api", :merchant_account => attributes
end

#update!(*args) ⇒ Object



46
47
48
# File 'lib/braintree/merchant_account_gateway.rb', line 46

def update!(*args)
  return_object_or_raise(:merchant_account) { update(*args) }
end