lib/active_merchant/billing/gateways/balanced.rb in activemerchant-1.79.2 vs lib/active_merchant/billing/gateways/balanced.rb in activemerchant-1.80.0
- old
+ new
@@ -15,11 +15,11 @@
# 3. The next screen will give you a test API key of your own
# 4. When you're ready to generate a production API key click the "Go
# live" button on the Balanced dashboard and fill in your marketplace
# details.
class BalancedGateway < Gateway
- VERSION = "2.0.0"
+ VERSION = '2.0.0'
self.live_url = 'https://api.balancedpayments.com'
self.supported_countries = ['US']
self.supported_cardtypes = [:visa, :master, :american_express, :discover]
@@ -48,11 +48,11 @@
r.process{store(payment_method, options)}
r.authorization
else
payment_method
end
- r.process{commit("debits", "cards/#{card_identifier_from(identifier)}/debits", post)}
+ r.process{commit('debits', "cards/#{card_identifier_from(identifier)}/debits", post)}
end
end
def authorize(money, payment_method, options = {})
post = {}
@@ -65,38 +65,38 @@
r.process{store(payment_method, options)}
r.authorization
else
payment_method
end
- r.process{commit("card_holds", "cards/#{card_identifier_from(identifier)}/card_holds", post)}
+ r.process{commit('card_holds', "cards/#{card_identifier_from(identifier)}/card_holds", post)}
end
end
def capture(money, identifier, options = {})
post = {}
add_amount(post, money)
post[:description] = options[:description] if options[:description]
add_common_params(post, options)
- commit("debits", "card_holds/#{reference_identifier_from(identifier)}/debits", post)
+ commit('debits', "card_holds/#{reference_identifier_from(identifier)}/debits", post)
end
def void(identifier, options = {})
post = {}
post[:is_void] = true
add_common_params(post, options)
- commit("card_holds", "card_holds/#{reference_identifier_from(identifier)}", post, :put)
+ commit('card_holds', "card_holds/#{reference_identifier_from(identifier)}", post, :put)
end
def refund(money, identifier, options = {})
post = {}
add_amount(post, money)
post[:description] = options[:description]
add_common_params(post, options)
- commit("refunds", "debits/#{reference_identifier_from(identifier)}/refunds", post)
+ commit('refunds', "debits/#{reference_identifier_from(identifier)}/refunds", post)
end
def store(credit_card, options={})
post = {}
@@ -106,31 +106,31 @@
post[:cvv] = credit_card.verification_value if credit_card.verification_value?
post[:name] = credit_card.name if credit_card.name
add_address(post, options)
- commit("cards", "cards", post)
+ commit('cards', 'cards', post)
end
private
def reference_identifier_from(identifier)
case identifier
when %r{\|}
uri = identifier.
- split("|").
+ split('|').
detect{|part| part.size > 0}
- uri.split("/")[2]
+ uri.split('/')[2]
when %r{\/}
- identifier.split("/")[5]
+ identifier.split('/')[5]
else
identifier
end
end
def card_identifier_from(identifier)
- identifier.split("/").last
+ identifier.split('/').last
end
def add_amount(post, money)
post[:amount] = amount(money) if money
end
@@ -178,43 +178,43 @@
def success_from(entity_name, raw_response)
entity = (raw_response[entity_name] || []).first
if(!entity)
false
- elsif((entity_name == "refunds") && entity.include?("status"))
- %w(succeeded pending).include?(entity["status"])
- elsif(entity.include?("status"))
- (entity["status"] == "succeeded")
- elsif(entity_name == "cards")
- !!entity["id"]
+ elsif((entity_name == 'refunds') && entity.include?('status'))
+ %w(succeeded pending).include?(entity['status'])
+ elsif(entity.include?('status'))
+ (entity['status'] == 'succeeded')
+ elsif(entity_name == 'cards')
+ !!entity['id']
else
false
end
end
def message_from(raw_response)
- if(raw_response["errors"])
- error = raw_response["errors"].first
- (error["additional"] || error["message"] || error["description"])
+ if(raw_response['errors'])
+ error = raw_response['errors'].first
+ (error['additional'] || error['message'] || error['description'])
else
- "Success"
+ 'Success'
end
end
def authorization_from(entity_name, raw_response)
entity = (raw_response[entity_name] || []).first
- (entity && entity["id"])
+ (entity && entity['id'])
end
def parse(body)
JSON.parse(body)
rescue JSON::ParserError
message = 'Invalid response received from the Balanced API. Please contact support@balancedpayments.com if you continue to receive this message.'
message += " (The raw response returned by the API was #{raw_response.inspect})"
{
- "errors" => [{
- "message" => message
+ 'errors' => [{
+ 'message' => message
}]
}
end
def post_data(params)
@@ -229,11 +229,11 @@
end
post_data(h)
else
"#{key}=#{CGI.escape(value.to_s)}"
end
- end.compact.join("&")
+ end.compact.join('&')
end
def headers
@@ua ||= JSON.dump(
bindings_version: ActiveMerchant::VERSION,
@@ -243,13 +243,13 @@
platform: RUBY_PLATFORM,
publisher: 'active_merchant'
)
{
- "Authorization" => "Basic " + Base64.encode64(@options[:login].to_s + ":").strip,
- "User-Agent" => "Balanced/v1.1 ActiveMerchantBindings/#{ActiveMerchant::VERSION}",
- "Accept" => "application/vnd.api+json;revision=1.1",
- "X-Balanced-User-Agent" => @@ua,
+ 'Authorization' => 'Basic ' + Base64.encode64(@options[:login].to_s + ':').strip,
+ 'User-Agent' => "Balanced/v1.1 ActiveMerchantBindings/#{ActiveMerchant::VERSION}",
+ 'Accept' => 'application/vnd.api+json;revision=1.1',
+ 'X-Balanced-User-Agent' => @@ua,
}
end
end
end
end