lib/active_merchant/billing/gateways/balanced.rb in activemerchant-1.42.5 vs lib/active_merchant/billing/gateways/balanced.rb in activemerchant-1.42.6
- old
+ new
@@ -129,11 +129,11 @@
end
post = {}
post[:amount] = money
post[:description] = options[:description]
- post[:appears_on_statement_as] = options[:appears_on_statement_as] if options[:appears_on_statement_as]
+ add_common_params(post, options)
create_or_find_account(post, options)
add_credit_card(post, credit_card, options)
add_address(credit_card, options)
@@ -159,19 +159,25 @@
#
# * <tt>email</tt> -- the email address of user associated with this
# purchase.
# * <tt>account_uri</tt> -- `account_uri` is the URI of an existing
# Balanced account.
+ #
+ # If you are passing a new card URI from balanced.js, you should pass
+ # the customer's name
+ #
+ # * <tt>name</tt> -- the customer's name, to appear on the Account
+ # on Balanced.
def purchase(money, credit_card, options = {})
if credit_card.respond_to?('number')
requires!(options, :email) unless options[:account_uri]
end
post = {}
post[:amount] = money
post[:description] = options[:description]
- post[:appears_on_statement_as] = options[:appears_on_statement_as] if options[:appears_on_statement_as]
+ add_common_params(post, options)
create_or_find_account(post, options)
add_credit_card(post, credit_card, options)
add_address(credit_card, options)
@@ -197,12 +203,11 @@
def capture(money, authorization, options = {})
post = {}
post[:hold_uri] = authorization
post[:amount] = money if money
post[:description] = options[:description] if options[:description]
- post[:appears_on_statement_as] = options[:appears_on_statement_as] if options[:appears_on_statement_as]
- post[:on_behalf_of_uri] = options[:on_behalf_of_uri] if options[:on_behalf_of_uri]
+ add_common_params(post, options)
create_transaction(:post, @debits_uri, post)
rescue Error => ex
failed_response(ex.response)
end
@@ -214,11 +219,11 @@
# * <tt>authorization</tt> -- The uri of the authorization returned from
# an `authorize` request.
def void(authorization, options = {})
post = {}
post[:is_void] = true
- post[:appears_on_statement_as] = options[:appears_on_statement_as] if options[:appears_on_statement_as]
+ add_common_params(post, options)
create_transaction(:put, authorization, post)
rescue Error => ex
failed_response(ex.response)
end
@@ -248,11 +253,11 @@
requires!(debit_uri)
post = {}
post[:debit_uri] = debit_uri
post[:amount] = amount
post[:description] = options[:description]
- post[:appears_on_statement_as] = options[:appears_on_statement_as] if options[:appears_on_statement_as]
+ add_common_params(post, options)
create_transaction(:post, @refunds_uri, post)
rescue Error => ex
failed_response(ex.response)
end
@@ -308,11 +313,13 @@
if options.has_key? :account_uri
account_uri = options[:account_uri]
end
if account_uri == nil
+ post[:name] = options[:name] if options[:name]
post[:email_address] = options[:email]
+ post[:meta] = options[:meta] if options[:meta]
# create an account
response = http_request(:post, @accounts_uri, post)
if response.has_key? 'uri'
@@ -338,10 +345,19 @@
credit_card[:postal_code] = address[:zip] if address[:zip]
credit_card[:country] = address[:country] if address[:country]
end
end
+ def add_common_params(post, options)
+ common_params = [
+ :appears_on_statement_as,
+ :on_behalf_of_uri,
+ :meta
+ ]
+ post.update(options.select{|key, _| common_params.include?(key)})
+ end
+
def add_credit_card(post, credit_card, options)
if credit_card.respond_to? :number
card = {}
card[:card_number] = credit_card.number
card[:expiration_month] = credit_card.month
@@ -359,9 +375,10 @@
associate_card_to_account(post[:account_uri], card_uri)
post[:card_uri] = card_uri
elsif credit_card.kind_of?(String)
+ associate_card_to_account(post[:account_uri], credit_card) unless options[:account_uri]
post[:card_uri] = credit_card
end
post[:card_uri]
end