Skip to content

Commit

Permalink
Forte: update to v3 api
Browse files Browse the repository at this point in the history
Update the Forte gateway to the new v3 API:  https://restdocs.forte.net/?version=latest

* In the endpoint URI, change v2 to v3
* In the endpoint URI, change /accounts to /organizations
* In the X-Forte-Auth header change “Account” to “Organization”
* Allow either organization_id or account_id to be used for configuration for backwards compatibility
* Instead of act_XXXXXX use org_XXXXXX
* remove the unused check_number attribute
* change the 'disburse' action to 'credit'

Fixes: activemerchant#3614

Unit:
20 tests, 67 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Remote:
22 tests, 63 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
  • Loading branch information
wsmoak committed May 26, 2020
1 parent 1c4b108 commit b5a87c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions lib/active_merchant/billing/gateways/forte.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module Billing #:nodoc:
class ForteGateway < Gateway
include Empty

self.test_url = 'https://sandbox.forte.net/api/v2'
self.live_url = 'https://api.forte.net/v2'
self.test_url = 'https://sandbox.forte.net/api/v3'
self.live_url = 'https://api.forte.net/v3'

self.supported_countries = ['US']
self.default_currency = 'USD'
Expand All @@ -16,7 +16,10 @@ class ForteGateway < Gateway
self.display_name = 'Forte'

def initialize(options={})
requires!(options, :api_key, :secret, :location_id, :account_id)
requires!(options, :api_key, :secret, :location_id)
unless options.has_key?(:organization_id) || options.has_key?(:account_id)
raise ArgumentError.new("Missing required parameter: organization_id or account_id")
end
super
end

Expand Down Expand Up @@ -59,7 +62,7 @@ def credit(money, payment_method, options={})
add_invoice(post, options)
add_payment_method(post, payment_method, options)
add_billing_address(post, payment_method, options)
post[:action] = 'disburse'
post[:action] = 'credit'

commit(:post, post)
end
Expand Down Expand Up @@ -104,7 +107,7 @@ def scrub(transcript)
private

def add_auth(post)
post[:account_id] = "act_#{@options[:account_id]}"
post[:organization_id] = "org_#{organization_id}"
post[:location_id] = "loc_#{@options[:location_id]}"
end

Expand Down Expand Up @@ -165,7 +168,6 @@ def add_echeck(post, payment, options)
post[:echeck][:account_number] = payment.account_number
post[:echeck][:routing_number] = payment.routing_number
post[:echeck][:account_type] = payment.account_type
post[:echeck][:check_number] = payment.number
post[:echeck][:sec_code] = options[:sec_code] || "WEB"
end

Expand Down Expand Up @@ -226,13 +228,13 @@ def authorization_from(response, parameters)
end

def endpoint
"/accounts/act_#{@options[:account_id].strip}/locations/loc_#{@options[:location_id].strip}/transactions/"
"/organizations/org_#{organization_id.strip}/locations/loc_#{@options[:location_id].strip}/transactions/"
end

def headers
{
'Authorization' => ('Basic ' + Base64.strict_encode64("#{@options[:api_key]}:#{@options[:secret]}")),
'X-Forte-Auth-Account-Id' => "act_#{@options[:account_id]}",
'X-Forte-Auth-Organization-Id' => "org_#{organization_id}",
'Content-Type' => 'application/json'
}
end
Expand Down Expand Up @@ -263,6 +265,10 @@ def transaction_id_from(authorization)
transaction_id, _, original_auth_transaction_id, _ = split_authorization(authorization)
original_auth_transaction_id.present? ? original_auth_transaction_id : transaction_id
end

def organization_id
@options[:organization_id] || @options[:account_id]
end
end
end
end
2 changes: 1 addition & 1 deletion test/fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ flo2cash_simple:

forte:
location_id: "176008"
account_id: "300111"
organization_id: "300111"
api_key: "f087a90f00f0ae57050c937ed3815c9f"
secret: "d793d64064e3113a74fa72035cfc3a1d"

Expand Down

0 comments on commit b5a87c5

Please sign in to comment.