Class Index [+]

Quicksearch

ActiveMerchant::Billing::PayJunctionGateway

PayJunction Gateway

This gateway accepts the following arguments:

  :login    => your PayJunction username
  :password => your PayJunction pass

Example use:

  gateway = ActiveMerchant::Billing::Base.gateway(:pay_junction).new(
              :login => "my_account", 
              :password => "my_pass"
           )

  # set up credit card obj as in main ActiveMerchant example
  creditcard = ActiveMerchant::Billing::CreditCard.new(
    :type       => 'visa',
    :number     => '4242424242424242',
    :month      => 8,
    :year       => 2009,
    :first_name => 'Bob',
    :last_name  => 'Bobsen'
  )

  # optionally specify address if using AVS
  address = { :address1 => '101 Test Ave', :city => 'Test', :state => 'TS',
              :zip  => '10101', :country => 'US' }

  # run request
  response = gateway.purchase(1000, creditcard, :address => address) # charge 10 dollars

1) Check whether the transaction was successful

  response.success?

2) Retrieve the message returned by PayJunction

  response.message

3) Retrieve the unique transaction ID returned by PayJunction

  response.authorization

This gateway supports “instant” transactions. These transactions allow you to execute an operation on a previously run card without card information provided you have the transaction id from a previous transaction with the same card. All functions that take a credit card object for this gateway can take a transaction id string instead.

Test Transactions

See the source for initialize() for test account information. Note that PayJunction does not allow test transactions on your account, so if the gateway is running in :test mode your transaction will be run against PayJunction’s global test account and will not show up in your account.

Transactions ran on this account go through a test processor, so there is no need to void or otherwise cancel transactions. However, for further safety, please use the special card numbers 4433221111223344 or 4444333322221111 and keep transaction amounts below $4.00 when testing.

Also note, transactions ran for an amount between $0.00 and $1.99 will likely result in denial. To demonstrate approvals, use amounts between $2.00 and $4.00.

Test transactions can be checked by logging into PayJunction Web Login with username ‘pj-cm-01’ and password ‘pj-cm-01p’

Usage Details

Below is a map of values accepted by PayJunction and how you should submit each to ActiveMerchant

PayJunction Field ActiveMerchant Use

dc_logon provide as :login value to gateway instantation dc_password provide as :password value to gateway instantiation

dc_name will be retrieved from credit_card.name dc_first_name :first_name on CreditCard object instantation dc_last_name :last_name on CreditCard object instantation dc_number :number on CreditCard object instantation dc_expiration_month :month on CreditCard object instantation dc_expiration_year :year on CreditCard object instantation dc_verification_number :verification_value on CC object instantation

dc_transaction_amount include as argument to method for your transaction type dc_transaction_type do nothing, set by your transaction type dc_version do nothing, always “1.2“

dc_transaction_id submit as a string in place of CreditCard obj for

                        "instant" transactions.

dc_invoice :order_id in options for transaction method dc_notes :description in options for transaction method

See example use above for address AVS fields See # for periodic transaction fields

Constants

API_VERSION
TEST_LOGIN
TEST_PASSWORD
SUCCESS_CODES
SUCCESS_MESSAGE
FAILURE_MESSAGE
DECLINE_CODES

Public Class Methods

new(options = {}) click to toggle source
     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 158
158:       def initialize(options = {})
159:         requires!(options, :login, :password)
160:         @options = options
161:         super
162:       end

Public Instance Methods

authorize(money, payment_source, options = {}) click to toggle source

The first half of the preauth(authorize)/postauth(capture) model. Checks to make sure funds are available for a transaction, and returns a transaction_id that can be used later to postauthorize (capture) the funds.

     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 167
167:       def authorize(money, payment_source, options = {})
168:         parameters = {
169:           :transaction_amount => amount(money),
170:         }                                                             
171:         
172:         add_payment_source(parameters, payment_source)
173:         add_address(parameters, options)
174:         add_optional_fields(parameters, options)
175:         commit('AUTHORIZATION', parameters)
176:       end
capture(money, authorization, options = {}) click to toggle source

The second half of the preauth(authorize)/postauth(capture) model. Retrieve funds that have been previously authorized with authorization

     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 193
193:       def capture(money, authorization, options = {})
194:         parameters = {
195:           :transaction_id => authorization,
196:           :posture => 'capture'
197:         }
198:         
199:         add_optional_fields(parameters, options)                                          
200:         commit('update', parameters)
201:       end
credit(money, authorization, options = {}) click to toggle source
     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 214
214:       def credit(money, authorization, options = {})
215:         deprecated CREDIT_DEPRECATION_MESSAGE
216:         refund(money, authorization, options)
217:       end
purchase(money, payment_source, options = {}) click to toggle source

A simple sale, capturing funds immediately. Execute authorization and capture in a single step.

     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 180
180:       def purchase(money, payment_source, options = {})        
181:         parameters = {
182:           :transaction_amount => amount(money),
183:         }                                                             
184:         
185:         add_payment_source(parameters, payment_source)
186:         add_address(parameters, options)
187:         add_optional_fields(parameters, options)
188:         commit('AUTHORIZATION_CAPTURE', parameters)
189:       end
recurring(money, payment_source, options = {}) click to toggle source

Set up a sale that will be made on a regular basis for the same amount (ex. $20 a month for 12 months)

The parameter :periodicity should be specified as either :monthly, :weekly, or :daily The parameter :payments should be the number of payments to be made

  gateway.recurring('2000', creditcard, :periodicity => :monthly, :payments => 12)

The optional parameter :starting_at takes a date or time argument or a string in YYYYMMDD format and can be used to specify when the first charge will be made. If omitted the first charge will be immediate.

     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 242
242:       def recurring(money, payment_source, options = {})        
243:         requires!(options, [:periodicity, :monthly, :weekly, :daily], :payments)
244:       
245:         periodic_type = case options[:periodicity]
246:         when :monthly
247:           'month'
248:         when :weekly
249:           'week'
250:         when :daily
251:           'day'
252:         end
253:         
254:         if options[:starting_at].nil?
255:           start_date = Time.now.strftime('%Y-%m-%d')
256:         elsif options[:starting_at].is_a?(String)
257:           sa = options[:starting_at]
258:           start_date = "#{sa[0..3]}-#{sa[4..5]}-#{sa[6..7]}"
259:         else
260:           start_date = options[:starting_at].strftime('%Y-%m-%d')
261:         end
262:         
263:         parameters = {
264:           :transaction_amount => amount(money),
265:           :schedule_periodic_type => periodic_type,
266:           :schedule_create => 'true',
267:           :schedule_limit => options[:payments].to_i > 1 ? options[:payments] : 1,
268:           :schedule_periodic_number => 1,
269:           :schedule_start => start_date
270:         }
271:         
272:         add_payment_source(parameters, payment_source)
273:         add_optional_fields(parameters, options)
274:         add_address(parameters, options)                                   
275:         commit('AUTHORIZATION_CAPTURE', parameters)
276:       end
refund(money, authorization, options = {}) click to toggle source

Return money to a card that was previously billed. authorization should be the transaction id of the transaction we are returning.

     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 205
205:       def refund(money, authorization, options = {})  
206:         parameters = {
207:           :transaction_amount => amount(money),
208:           :transaction_id => authorization
209:         }
210: 
211:         commit('CREDIT', parameters)
212:       end
test?() click to toggle source
     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 278
278:       def test?
279:         test_login? || @options[:test] || super
280:       end
void(authorization, options = {}) click to toggle source

Cancel a transaction that has been charged but has not yet made it through the batch process.

     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 221
221:       def void(authorization, options = {})
222:         parameters = {
223:           :transaction_id => authorization,
224:           :posture => 'void'
225:         }
226: 
227:         add_optional_fields(parameters, options)
228:         commit('update', parameters)
229:       end

Private Instance Methods

add_address(params, options) click to toggle source

add address fields if present

     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 312
312:       def add_address(params, options)
313:         address = options[:billing_address] || options[:address]
314:         
315:         if address          
316:           params[:address]  = address[:address1] unless address[:address1].blank?
317:           params[:city]      = address[:city]     unless address[:city].blank?
318:           params[:state]     = address[:state]    unless address[:state].blank?
319:           params[:zipcode]   = address[:zip]      unless address[:zip].blank?
320:           params[:country]   = address[:country]  unless address[:country].blank?
321:         end     
322:       end
add_billing_id(params, billingid) click to toggle source

add field for “instant” transaction, using previous transaction id

     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 307
307:       def add_billing_id(params, billingid)
308:         params[:transaction_id] = billingid
309:       end
add_creditcard(params, creditcard) click to toggle source

add fields for credit card

     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 298
298:       def add_creditcard(params, creditcard)
299:         params[:name]                 = creditcard.name
300:         params[:number]               = creditcard.number
301:         params[:expiration_month]     = creditcard.month
302:         params[:expiration_year]      = creditcard.year 
303:         params[:verification_number]  = creditcard.verification_value if creditcard.verification_value?
304:       end
add_optional_fields(params, options) click to toggle source
     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 324
324:       def add_optional_fields(params, options)
325:         params[:notes] = options[:description] unless options[:description].blank?
326:         params[:invoice] = options[:order_id].to_s.gsub(/[^-\/\w.,']/, '') unless options[:order_id].blank?
327:       end
add_payment_source(params, source) click to toggle source

add fields depending on payment source selected (cc or transaction id)

     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 289
289:       def add_payment_source(params, source)
290:         if source.is_a?(String)
291:           add_billing_id(params, source)
292:         else
293:           add_creditcard(params, source)
294:         end
295:       end
commit(action, parameters) click to toggle source
     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 329
329:       def commit(action, parameters)
330:         url = test? ? self.test_url : self.live_url
331: 
332:         response = parse( ssl_post(url, post_data(action, parameters)) )
333:         
334:         Response.new(successful?(response), message_from(response), response, 
335:           :test => test?, 
336:           :authorization => response[:transaction_id] || parameters[:transaction_id]
337:         )
338:       end
message_from(response) click to toggle source
     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 344
344:       def message_from(response)
345:         if successful?(response)
346:           SUCCESS_MESSAGE
347:         else
348:           DECLINE_CODES[response[:response_code]] || FAILURE_MESSAGE
349:         end
350:       end
normalize(field) click to toggle source

Make a ruby type out of the response string

     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 385
385:       def normalize(field)
386:         case field
387:         when "true"   then true
388:         when "false"  then false
389:         when ""       then nil
390:         when "null"   then nil
391:         else field
392:         end        
393:       end
parse(body) click to toggle source
     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 367
367:       def parse(body)
368:         # PayJunction uses the Field Separator ASCII character to separate key/val
369:         # pairs in the response. The <FS> character's octal value is 034.
370:         #
371:         # Sample response:
372:         # 
373:         # transaction_id=44752<FS>response_code=M4<FS>response_message=Declined (INV TEST CARD).  
374:         
375:         pairs = body.chomp.split("\0034")
376:         response = {}
377:         pairs.each do |pair|
378:           key, val = pair.split('=')
379:           response[key[3..1].to_sym] = val ? normalize(val) : nil
380:         end
381:         response
382:       end
post_data(action, params) click to toggle source
     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 352
352:       def post_data(action, params)
353:         if test?
354:           # test requests must use global test account
355:           params[:logon]      = TEST_LOGIN
356:           params[:password]   = TEST_PASSWORD
357:         else
358:           params[:logon]      = @options[:login]
359:           params[:password]   = @options[:password]
360:         end
361:         params[:version] = API_VERSION
362:         params[:transaction_type] = action
363:         
364:         params.reject{|k,v| v.blank?}.collect{ |k, v| "dc_#{k.to_s}=#{CGI.escape(v.to_s)}" }.join("&")
365:       end
successful?(response) click to toggle source
     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 340
340:       def successful?(response)
341:         SUCCESS_CODES.include?(response[:response_code]) || response[:query_status] == true
342:       end
test_login?() click to toggle source
     # File lib/active_merchant/billing/gateways/pay_junction.rb, line 284
284:       def test_login?
285:         @options[:login] == TEST_LOGIN && @options[:password] == TEST_PASSWORD
286:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.