lib/active_merchant/billing/gateways/forte.rb in activemerchant-1.79.2 vs lib/active_merchant/billing/gateways/forte.rb in activemerchant-1.80.0

- old
+ new

@@ -25,11 +25,11 @@ add_amount(post, money, options) add_invoice(post, options) add_payment_method(post, payment_method) add_billing_address(post, payment_method, options) add_shipping_address(post, options) - post[:action] = "sale" + post[:action] = 'sale' commit(:post, post) end def authorize(money, payment_method, options={}) @@ -37,40 +37,50 @@ add_amount(post, money, options) add_invoice(post, options) add_payment_method(post, payment_method) add_billing_address(post, payment_method, options) add_shipping_address(post, options) - post[:action] = "authorize" + post[:action] = 'authorize' commit(:post, post) end def capture(money, authorization, options={}) post = {} post[:transaction_id] = transaction_id_from(authorization) - post[:authorization_code] = authorization_code_from(authorization) || "" - post[:action] = "capture" + post[:authorization_code] = authorization_code_from(authorization) || '' + post[:action] = 'capture' commit(:put, post) end def credit(money, payment_method, options={}) post = {} add_amount(post, money, options) add_invoice(post, options) add_payment_method(post, payment_method) add_billing_address(post, payment_method, options) - post[:action] = "disburse" + post[:action] = 'disburse' commit(:post, post) end + def refund(money, authorization, options={}) + post = {} + add_amount(post, money, options) + post[:original_transaction_id] = transaction_id_from(authorization) + post[:authorization_code] = authorization_code_from(authorization) + post[:action] = 'reverse' + + commit(:post, post) + end + def void(authorization, options={}) post = {} post[:transaction_id] = transaction_id_from(authorization) post[:authorization_code] = authorization_code_from(authorization) - post[:action] = "void" + post[:action] = 'void' commit(:put, post) end def verify(credit_card, options={}) @@ -118,15 +128,15 @@ post[:billing_address][:physical_address][:postal_code] = address[:zip] if address[:zip] post[:billing_address][:physical_address][:region] = address[:state] if address[:state] post[:billing_address][:physical_address][:locality] = address[:city] if address[:city] end - if empty?(post[:billing_address][:first_name] && payment.first_name) + if empty?(post[:billing_address][:first_name]) && payment.first_name post[:billing_address][:first_name] = payment.first_name end - if empty?(post[:billing_address][:last_name] && payment.last_name) + if empty?(post[:billing_address][:last_name]) && payment.last_name post[:billing_address][:last_name] = payment.last_name end end def add_shipping_address(post, options) @@ -180,12 +190,12 @@ Response.new( success_from(response), message_from(response), response, authorization: authorization_from(response), - avs_result: AVSResult.new(code: response["response"]["avs_result"]), - cvv_result: CVVResult.new(response["response"]["cvv_code"]), + avs_result: AVSResult.new(code: response['response']['avs_result']), + cvv_result: CVVResult.new(response['response']['cvv_code']), test: test? ) end def handle_resp(response) @@ -200,28 +210,28 @@ def parse(response_body) JSON.parse(response_body) end def success_from(response) - response["response"]["response_code"] == "A01" + response['response']['response_code'] == 'A01' end def message_from(response) - response["response"]["response_desc"] + response['response']['response_desc'] end def authorization_from(response) - [response.try(:[], "transaction_id"), response.try(:[], "response").try(:[], "authorization_code")].join("#") + [response.try(:[], 'transaction_id'), response.try(:[], 'response').try(:[], 'authorization_code')].join('#') end def endpoint - "/accounts/act_#{@options[:account_id]}/locations/loc_#{@options[:location_id]}/transactions/" + "/accounts/act_#{@options[:account_id].strip}/locations/loc_#{@options[:location_id].strip}/transactions/" end def headers { - 'Authorization' => ("Basic " + Base64.strict_encode64("#{@options[:api_key]}:#{@options[:secret]}")), + 'Authorization' => ('Basic ' + Base64.strict_encode64("#{@options[:api_key]}:#{@options[:secret]}")), 'X-Forte-Auth-Account-Id' => "act_#{@options[:account_id]}", 'Content-Type' => 'application/json' } end @@ -237,10 +247,10 @@ return 'disc' end end def split_authorization(authorization) - authorization.split("#") + authorization.split('#') end def authorization_code_from(authorization) _, authorization_code = split_authorization(authorization) authorization_code