Class: Balanced::Marketplace

Inherits:
Object
  • Object
show all
Includes:
Resource
Defined in:
lib/balanced/resources/marketplace.rb

Constant Summary collapse

@@marketplace_uri =
nil

Instance Attribute Summary

Attributes included from Resource

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Resource

#copy_from, #destroy, #find, included, #initialize, #method_missing, #reload, #warn_on_positional

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Balanced::Resource

Class Method Details

.marketplace_exists?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/balanced/resources/marketplace.rb', line 34

def marketplace_exists?
  !!marketplace_uri
end

.marketplace_uriString?

Returns the marketplace’s URI.

Returns:

  • (String, nil)

    the marketplace’s URI



23
24
25
26
27
28
29
30
31
32
# File 'lib/balanced/resources/marketplace.rb', line 23

def marketplace_uri
  if !@@marketplace_uri and Balanced.is_configured_with_api_key?
    begin
      mine
    rescue Balanced::Error
      # do nothing..
    end
  end
  @@marketplace_uri
end

.mineMarketplace

Returns an instance representing the marketplace associated with the current API key.

Returns:



20
21
22
23
24
# File 'lib/balanced/resources/marketplace.rb', line 20

def my_marketplace
  marketplace = Balanced::Merchant.me.marketplace
  @@marketplace_uri = marketplace.uri if marketplace
  marketplace
end

.my_marketplaceMarketplace

Returns an instance representing the marketplace associated with the current API key.

Returns:



15
16
17
18
19
# File 'lib/balanced/resources/marketplace.rb', line 15

def my_marketplace
  marketplace = Balanced::Merchant.me.marketplace
  @@marketplace_uri = marketplace.uri if marketplace
  marketplace
end

Instance Method Details

#create_account(options = {}) ⇒ Account

Create an Account associated with this Marketplace. This account will have no roles associated with it.

Returns:



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/balanced/resources/marketplace.rb', line 60

def  options={}
  email_address = options.fetch(:email_address) { nil }
  name = options.fetch(:name) { nil }
  meta = options.fetch(:meta) { nil }

   = {
      :uri => self.accounts_uri,
      :email_address => email_address,
      :name => name,
      :meta => meta
  }

   = Account.new 
  .save
end

#create_bank_account(*args) ⇒ BankAccount

Creates a BankAccount object tied to this marketplace, for use with accounts

Returns:



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/balanced/resources/marketplace.rb', line 151

def  *args
  warn_on_positional args

  options = args.last.is_a?(Hash) ? args.pop : {}
  name = args[0] || options.fetch(:name) { }
   = args[1] || options.fetch(:account_number) { nil }
  bank_code = args[2] || options.fetch(:bank_code) {
    options.fetch(:routing_number) {
      nil
    }
  }
  meta = args[3] || options.fetch(:meta) { nil }

   = BankAccount.new(
      :uri => self.bank_accounts_uri,
      :name => name,
      :account_number => ,
      :bank_code => bank_code,
      :meta => meta
  )

  .save
end

#create_buyer(*args) ⇒ Account

Create a buyer Account associated with this Marketplace.

Returns:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/balanced/resources/marketplace.rb', line 80

def create_buyer *args
  warn_on_positional args

  options = args.last.is_a?(Hash) ? args.pop : {}
  email_address = args[0] || options.fetch(:email_address) { nil }
  card = args[1] || options.fetch(:card_uri) { options.fetch(:card) { nil} }
  name = args[2] || options.fetch(:name) { nil }
  meta = args[3] || options.fetch(:meta) { nil }

   = {
      :uri => self.accounts_uri,
      :email_address => email_address,
      :name => name,
      :meta => meta,
  }

  if card.respond_to? :keys
    [:card] = card
  else
    [:card_uri] = card
  end

   = Account.new 
  .save
end

#create_callback(*args) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/balanced/resources/marketplace.rb', line 212

def create_callback *args
  warn_on_positional args

  options = args.last.is_a?(Hash) ? args.pop : {}
  url = args[0] || options.fetch(:url) { nil }

  callback = Callback.new(
      'uri' => self.callbacks_uri,
      'url' => url
  )
  callback.save
end

#create_card(*args) ⇒ Card

Creates a Card object tied to this marketplace, for use with accounts

Returns:



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/balanced/resources/marketplace.rb', line 179

def create_card *args
  warn_on_positional args

  options = args.last.is_a?(Hash) ? args.pop : {}
  card_number = args[0] || options.fetch(:card_number) { nil }
  expiration_month = args[1] || options.fetch(:expiration_month) { nil }
  expiration_year = args[2] || options.fetch(:expiration_year) { nil }
  security_code = args[3] || options.fetch(:expiration_year) { nil }
  postal_code = args[4] || options.fetch(:postal_code) { nil }
  name = args[5] || options.fetch(:name) { nil }
  phone_number = args[6] || options.fetch(:phone_number) { nil }
  street_address = args[7] || options.fetch(:street_address) { nil }
  city = args[8] || options.fetch(:city) { nil }
  country_code = args[9] || options.fetch(:country_code) { nil }
  meta = args[10] || options.fetch(:meta) { nil }

  card = Card.new(
      :uri => self.cards_uri,
      :card_number => card_number,
      :expiration_month => expiration_month,
      :expiration_year => expiration_year,
      :name => name,
      :security_code => security_code,
      :street_address => street_address,
      :city => city,
      :postal_code => postal_code,
      :country_code => country_code,
      :phone_number => phone_number,
      :meta => meta
  )
  card.save
end

#create_merchant(*args) ⇒ Account

Creates a Merchant Account associated with this Marketplace.

This method may return 300 if you have not supplied enough information for Balanced to identify the Merchant. You may re-submit the request with more information, or redirect the Merchant to the supplied url so they may manually sign up.

When you receive a merchant_uri from balanced, just pass it in:

Examples:

Account.create_merchant('[email protected]', '/v1/TEST-MRxxxx')

Returns:



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/balanced/resources/marketplace.rb', line 119

def create_merchant *args
  warn_on_positional args

  options = args.last.is_a?(Hash) ? args.pop : {}
  email_address = args[0] || options.fetch(:email_address) { nil }
  merchant = args[1] || options.fetch(:merchant) { nil }
   = args[2] || options.fetch(:bank_account_uri) { nil }
  name = args[3] || options.fetch(:name) { nil }
  meta = args[4] || options.fetch(:meta) { nil }

   = {
      :uri => self.accounts_uri,
      :email_address => email_address,
      :bank_account_uri => ,
      :name => name,
      :meta => meta
  }

  if merchant.respond_to? :keys
    [:merchant] = merchant
  else
    [:merchant_uri] = merchant
  end

   = Account.new 
  .save
end

#my_marketplaceMarketplace Also known as: mine

Returns an instance representing the marketplace associated with the current API key.

Returns:



51
52
53
# File 'lib/balanced/resources/marketplace.rb', line 51

def my_marketplace
  self.class.my_marketplace
end

#saveMarketplace

Returns:



41
42
43
44
45
# File 'lib/balanced/resources/marketplace.rb', line 41

def save
  marketplace = super
  @@marketplace_uri = marketplace.uri
  marketplace
end