Class ActiveMerchant::Billing::TrustCommerceGateway
In: lib/active_merchant/billing/gateways/trust_commerce.rb
Parent: Gateway

TO USE: First, make sure you have everything setup correctly and all of your dependencies in place with:

  require 'rubygems'
  require 'active_merchant'

ActiveMerchant expects amounts to be Integer values in cents

  tendollar = 1000

Next, create a credit card object using a TC approved test card.

  creditcard = ActiveMerchant::Billing::CreditCard.new(
      :number => '4111111111111111',
      :month => 8,
      :year => 2006,
      :first_name => 'Longbob',
    :last_name => 'Longsen'
  )

To finish setting up, create the active_merchant object you will be using, with the TrustCommerce gateway. If you have a functional TrustCommerce account, replace login and password with your account info. Otherwise the defaults will work for testing.

  gateway = ActiveMerchant::Billing::Base.gateway(:trust_commerce).new(:login => "TestMerchant", :password => "password")

Now we are ready to process our transaction

  response = gateway.purchase(tendollar, creditcard)

Sending a transaction to TrustCommerce with active_merchant returns a Response object, which consistently allows you to:

1) Check whether the transaction was successful

  response.success?

2) Retrieve any message returned by TrustCommerce, either a "transaction was successful" note or an explanation of why the transaction was rejected.

  response.message

3) Retrieve and store the unique transaction ID returned by Trust Commerece, for use in referencing the transaction in the future.

  response.params["transid"]

For higher performance and failover with the TrustCommerceGateway you can install the TCLink library from www.trustcommerce.com/tclink.html. Follow the instructions available there to get it working on your system. ActiveMerchant will automatically use tclink if available.

The TCLink library has the following added benefits:

 * Good transaction times. Transaction duration under 1.2 seconds are common.
 * Fail-over to geographically distributed servers for extreme reliability

Once it is installed, you should be able to make sure that it is visible to your ruby install by opening irb and typing "require ‘tclink’", which should return "true".

This should be enough to get you started with Trust Commerce and active_merchant. For further information, review the methods below and the rest of active_merchant‘s documentation, as well as Trust Commerce‘s user and developer documentation.

Methods

authorize   capture   credit   new   purchase   recurring   store   tclink?   tclink?   test?   unstore   void  

Constants

URL = 'https://vault.trustcommerce.com/trans/'
SUCCESS_TYPES = ["approved", "accepted"]
DECLINE_CODES = { "decline" => "The credit card was declined", "avs" => "AVS failed; the address entered does not match the billing address on file at the bank", "cvv" => "CVV failed; the number provided is not the correct verification number for the card", "call" => "The card must be authorized manually over the phone", "expiredcard" => "Issuer was not certified for card verification", "carderror" => "Card number is invalid", "authexpired" => "Attempt to postauth an expired (more than 14 days old) preauth", "fraud" => "CrediGuard fraud score was below requested threshold", "blacklist" => "CrediGuard blacklist value was triggered", "velocity" => "CrediGuard velocity control value was triggered", "dailylimit" => "Daily limit in transaction count or amount as been reached", "weeklylimit" => "Weekly limit in transaction count or amount as been reached", "monthlylimit" => "Monthly limit in transaction count or amount as been reached"
BADDATA_CODES = { "missingfields" => "One or more parameters required for this transaction type were not sent", "extrafields" => "Parameters not allowed for this transaction type were sent", "badformat" => "A field was improperly formatted, such as non-digit characters in a number field", "badlength" => "A field was longer or shorter than the server allows", "merchantcantaccept" => "The merchant can't accept data passed in this field", "mismatch" => "Data in one of the offending fields did not cross-check with the other offending field"
ERROR_CODES = { "cantconnect" => "Couldn't connect to the TrustCommerce gateway", "dnsfailure" => "The TCLink software was unable to resolve DNS hostnames", "linkfailure" => "The connection was established, but was severed before the transaction could complete", "failtoprocess" => "The bank servers are offline and unable to authorize transactions"

Public Class methods

Creates a new TrustCommerceGateway

The gateway requires that a valid login and password be passed in the options hash.

Options

  • :login — The TrustCommerce account login.
  • :password — The TrustCommerce account password.
  • :test => true or false — Perform test transactions

Test Account Credentials

  • :login — TestMerchant
  • :password — password

[Source]

     # File lib/active_merchant/billing/gateways/trust_commerce.rb, line 128
128:       def initialize(options = {})
129:         requires!(options, :login, :password)
130:       
131:         @options = options
132:         super
133:       end

[Source]

     # File lib/active_merchant/billing/gateways/trust_commerce.rb, line 110
110:       def self.tclink?
111:         defined?(TCLink)
112:       end

Public Instance methods

authorize() is the first half of the preauth(authorize)/postauth(capture) model. The TC API docs call this preauth, we preserve active_merchant‘s nomenclature of authorize() for consistency with the rest of the library. This method simply checks to make sure funds are available for a transaction, and returns a transid that can be used later to postauthorize (capture) the funds.

[Source]

     # File lib/active_merchant/billing/gateways/trust_commerce.rb, line 148
148:       def authorize(money, creditcard_or_billing_id, options = {})
149:         parameters = {
150:           :amount => amount(money),
151:         }                                                             
152:         
153:         add_order_id(parameters, options)
154:         add_customer_data(parameters, options)
155:         add_payment_source(parameters, creditcard_or_billing_id)
156:         add_addresses(parameters, options)
157:         commit('preauth', parameters)
158:       end

capture() is the second half of the preauth(authorize)/postauth(capture) model. The TC API docs call this postauth, we preserve active_merchant‘s nomenclature of capture() for consistency with the rest of the library. To process a postauthorization with TC, you need an amount in cents or a money object, and a TC transid.

[Source]

     # File lib/active_merchant/billing/gateways/trust_commerce.rb, line 177
177:       def capture(money, authorization, options = {})
178:         parameters = {
179:           :amount => amount(money),
180:           :transid => authorization,
181:         }
182:                                                   
183:         commit('postauth', parameters)
184:       end

credit() allows you to return money to a card that was previously billed. You need to supply the amount, in cents or a money object, that you want to refund, and a TC transid for the transaction that you are refunding.

[Source]

     # File lib/active_merchant/billing/gateways/trust_commerce.rb, line 188
188:       def credit(money, identification, options = {})  
189:         parameters = {
190:           :amount => amount(money),
191:           :transid => identification
192:         }
193:                                                   
194:         commit('credit', parameters)
195:       end

purchase() is a simple sale. This is one of the most common types of transactions, and is extremely simple. All that you need to process a purchase are an amount in cents or a money object and a creditcard object or billingid string.

[Source]

     # File lib/active_merchant/billing/gateways/trust_commerce.rb, line 162
162:       def purchase(money, creditcard_or_billing_id, options = {})        
163:         parameters = {
164:           :amount => amount(money),
165:         }                                                             
166:         
167:         add_order_id(parameters, options)
168:         add_customer_data(parameters, options)
169:         add_payment_source(parameters, creditcard_or_billing_id)
170:         add_addresses(parameters, options)
171:         commit('sale', parameters)
172:       end

recurring() a TrustCommerce account that is activated for Citatdel, TrustCommerce‘s hosted customer billing info database.

Recurring billing uses the same TC action as a plain-vanilla ‘store’, but we have a separate method for clarity. It can be called like store, with the addition of a required ‘periodicity’ parameter:

The parameter :periodicity should be specified as either :bimonthly, :monthly, :biweekly, :weekly, :yearly or :daily

  gateway.recurring(tendollar, creditcard, :periodicity => :weekly)

You can optionally specify how long you want payments to continue using ‘payments‘

[Source]

     # File lib/active_merchant/billing/gateways/trust_commerce.rb, line 230
230:       def recurring(money, creditcard, options = {})        
231:         requires!(options, [:periodicity, :bimonthly, :monthly, :biweekly, :weekly, :yearly, :daily] )
232:       
233:         cycle = case options[:periodicity]
234:         when :monthly
235:           '1m'
236:         when :bimonthly
237:           '2m'
238:         when :weekly
239:           '1w'
240:         when :biweekly
241:           '2w'
242:         when :yearly
243:           '1y'
244:         when :daily
245:           '1d'
246:         end
247:         
248:         parameters = {
249:           :amount => amount(money),
250:           :cycle => cycle,
251:           :verify => options[:verify] || 'y',
252:           :billingid => options[:billingid] || nil,
253:           :payments => options[:payments] || nil,
254:         }
255:         
256:         add_creditcard(parameters, creditcard)
257:                                                   
258:         commit('store', parameters)
259:       end

store() requires a TrustCommerce account that is activated for Citatdel. You can call it with a credit card and a billing ID you would like to use to reference the stored credit card info for future captures. Use ‘verify’ to specify whether you want to simply store the card in the DB, or you want TC to verify the data first.

[Source]

     # File lib/active_merchant/billing/gateways/trust_commerce.rb, line 265
265:       def store(creditcard, options = {})   
266:         parameters = {
267:           :verify => options[:verify] || 'y',
268:           :billingid => options[:billingid] || options[:billing_id] || nil,
269:         }
270:         
271:         add_creditcard(parameters, creditcard)
272:         add_addresses(parameters, options)                              
273:         commit('store', parameters)
274:       end

[Source]

     # File lib/active_merchant/billing/gateways/trust_commerce.rb, line 135
135:       def tclink?
136:         self.class.tclink?
137:       end

[Source]

     # File lib/active_merchant/billing/gateways/trust_commerce.rb, line 139
139:       def test?
140:         @options[:test] || super
141:       end

To unstore a creditcard stored in Citadel using store() or recurring(), all that is required is the billing id. When you run unstore() the information will be removed and a Response object will be returned indicating the success of the action.

[Source]

     # File lib/active_merchant/billing/gateways/trust_commerce.rb, line 278
278:       def unstore(identification, options = {})
279:         parameters = {
280:           :billingid => identification,
281:         }
282:                                                   
283:         commit('unstore', parameters)
284:       end

void() clears an existing authorization and releases the reserved fund s back to the cardholder. The TC API refers to this transaction as a reversal. After voiding, you will no longer be able to capture funds from this authorization. TrustCommerce seems to always return a status of "accepted" even if the transid you are trying to deauthorize has already been captured. Note: Your account needs to be configured by TrustCommerce to allow for reversal transactions before you can use this method.

NOTE: AMEX preauth‘s cannot be reversed. If you want to clear it more quickly than the automatic expiration (7-10 days), you will have to capture it and then immediately issue a credit for the same amount which should clear the customers credit card with 48 hours according to TC.

[Source]

     # File lib/active_merchant/billing/gateways/trust_commerce.rb, line 211
211:       def void(authorization, options = {})
212:         parameters = {
213:           :transid => authorization,
214:         }
215:         
216:         commit('reversal', parameters)
217:       end

[Validate]