Class: Balanced::Marketplace
- Inherits:
-
Object
- Object
- Balanced::Marketplace
- Includes:
- Resource
- Defined in:
- lib/balanced/resources/marketplace.rb
Constant Summary collapse
- @@marketplace_uri =
nil
Instance Attribute Summary
Attributes included from Resource
Class Method Summary collapse
- .marketplace_exists? ⇒ Boolean
-
.marketplace_uri ⇒ String?
The marketplace’s URI.
-
.mine ⇒ Marketplace
Returns an instance representing the marketplace associated with the current API key.
-
.my_marketplace ⇒ Marketplace
Returns an instance representing the marketplace associated with the current API key.
Instance Method Summary collapse
-
#create_account(options = {}) ⇒ Account
Create an Account associated with this Marketplace.
-
#create_bank_account(*args) ⇒ BankAccount
Creates a BankAccount object tied to this marketplace, for use with accounts.
-
#create_buyer(*args) ⇒ Account
Create a buyer Account associated with this Marketplace.
- #create_callback(*args) ⇒ Object
-
#create_card(*args) ⇒ Card
Creates a Card object tied to this marketplace, for use with accounts.
-
#create_merchant(*args) ⇒ Account
Creates a Merchant Account associated with this Marketplace.
-
#my_marketplace ⇒ Marketplace
(also: #mine)
Returns an instance representing the marketplace associated with the current API key.
- #save ⇒ Marketplace
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
34 35 36 |
# File 'lib/balanced/resources/marketplace.rb', line 34 def marketplace_exists? !!marketplace_uri end |
.marketplace_uri ⇒ String?
Returns 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 |
.mine ⇒ Marketplace
Returns an instance representing the marketplace associated with the current API key.
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_marketplace ⇒ Marketplace
Returns an instance representing the marketplace associated with the current API key.
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.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/balanced/resources/marketplace.rb', line 60 def create_account ={} email_address = .fetch(:email_address) { nil } name = .fetch(:name) { nil } = .fetch(:meta) { nil } account_attributes = { :uri => self.accounts_uri, :email_address => email_address, :name => name, :meta => } account = Account.new account_attributes account.save end |
#create_bank_account(*args) ⇒ BankAccount
Creates a BankAccount object tied to this marketplace, for use with accounts
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 create_bank_account *args warn_on_positional args = args.last.is_a?(Hash) ? args.pop : {} name = args[0] || .fetch(:name) { } account_number = args[1] || .fetch(:account_number) { nil } bank_code = args[2] || .fetch(:bank_code) { .fetch(:routing_number) { nil } } = args[3] || .fetch(:meta) { nil } bank_account = BankAccount.new( :uri => self.bank_accounts_uri, :name => name, :account_number => account_number, :bank_code => bank_code, :meta => ) bank_account.save end |
#create_buyer(*args) ⇒ Account
Create a buyer Account associated with this Marketplace.
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 = args.last.is_a?(Hash) ? args.pop : {} email_address = args[0] || .fetch(:email_address) { nil } card = args[1] || .fetch(:card_uri) { .fetch(:card) { nil} } name = args[2] || .fetch(:name) { nil } = args[3] || .fetch(:meta) { nil } account_attributes = { :uri => self.accounts_uri, :email_address => email_address, :name => name, :meta => , } if card.respond_to? :keys account_attributes[:card] = card else account_attributes[:card_uri] = card end account = Account.new account_attributes account.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 = args.last.is_a?(Hash) ? args.pop : {} url = args[0] || .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
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 = args.last.is_a?(Hash) ? args.pop : {} card_number = args[0] || .fetch(:card_number) { nil } expiration_month = args[1] || .fetch(:expiration_month) { nil } expiration_year = args[2] || .fetch(:expiration_year) { nil } security_code = args[3] || .fetch(:expiration_year) { nil } postal_code = args[4] || .fetch(:postal_code) { nil } name = args[5] || .fetch(:name) { nil } phone_number = args[6] || .fetch(:phone_number) { nil } street_address = args[7] || .fetch(:street_address) { nil } city = args[8] || .fetch(:city) { nil } country_code = args[9] || .fetch(:country_code) { nil } = args[10] || .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 => ) 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:
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 = args.last.is_a?(Hash) ? args.pop : {} email_address = args[0] || .fetch(:email_address) { nil } merchant = args[1] || .fetch(:merchant) { nil } bank_account_uri = args[2] || .fetch(:bank_account_uri) { nil } name = args[3] || .fetch(:name) { nil } = args[4] || .fetch(:meta) { nil } account_attributes = { :uri => self.accounts_uri, :email_address => email_address, :bank_account_uri => bank_account_uri, :name => name, :meta => } if merchant.respond_to? :keys account_attributes[:merchant] = merchant else account_attributes[:merchant_uri] = merchant end account = Account.new account_attributes account.save end |
#my_marketplace ⇒ Marketplace Also known as: mine
Returns an instance representing the marketplace associated with the current API key.
51 52 53 |
# File 'lib/balanced/resources/marketplace.rb', line 51 def my_marketplace self.class.my_marketplace end |
#save ⇒ Marketplace
41 42 43 44 45 |
# File 'lib/balanced/resources/marketplace.rb', line 41 def save marketplace = super @@marketplace_uri = marketplace.uri marketplace end |