ActiveMerchant PSL Card Gateway
Notes:
-To be able to use the capture function, the IP address of the machine must be registered with PSL -ESALE_KEYED should only be used in situations where the cardholder perceives the transaction to be Internet-based, such as purchasing from a web site/on-line store. If the Internet is used purely for the transport of information from the merchant directly to the gateway then the appropriate cardholder present or not present message type should be used rather than the āEā equivalent. -The CV2 / AVS policies are set up with the account settings when signing up for an account
PslCard server URL - The url is the same whether testing or live - use the test account when testing...
eCommerce sale transaction, details keyed by merchant or cardholder
The type of response that we want to get from PSL, options are HTML, XML or REDIRECT
Currency Codes
The terminal used - only for swipe transactions, so hard coded to 32 for online
Different Dispatch types
Return codes
Nominal amount to authorize for a ‘dispatch later’ type The nominal amount is held straight away, when the goods are ready to be dispatched, PSL is informed and the full amount is the taken.
Create a new PslCardGateway
The gateway requires that a valid :login be passed in the options hash
Paramaters:
-options: :login - the PslCard account login (required)
# File lib/active_merchant/billing/gateways/psl_card.rb, line 90 90: def initialize(options = {}) 91: requires!(options, :login) 92: 93: @options = options 94: super 95: end
Post an authorization.
Captures the funds from an authorized transaction.
Parameters:
-money: Amount to be charged as an Integer value in cents -authorization: The PSL Cross Reference -options:
Returns:
-ActiveRecord::Billing::Response object
# File lib/active_merchant/billing/gateways/psl_card.rb, line 159 159: def capture(money, authorization, options = {}) 160: post = {} 161: 162: add_amount(post, money, DISPATCH_NOW, options) 163: add_reference(post, authorization) 164: add_purchase_details(post) 165: 166: commit(post) 167: end
Purchase the item straight away
Parameters:
-money: Amount to be charged as an Integer value in cents -authorization: the PSL cross reference from the previous authorization -options:
Returns:
-ActiveRecord::Billing::Response object
# File lib/active_merchant/billing/gateways/psl_card.rb, line 107 107: def purchase(money, credit_card, options = {}) 108: post = {} 109: 110: add_amount(post, money, DISPATCH_NOW, options) 111: add_credit_card(post, credit_card) 112: add_address(post, options) 113: add_invoice(post, options) 114: add_purchase_details(post) 115: 116: commit(post) 117: end
# File lib/active_merchant/billing/gateways/psl_card.rb, line 189 189: def add_address(post, options) 190: address = options[:billing_address] || options[:address] 191: return if address.nil? 192: 193: post[:QAAddress] = [:address1, :address2, :city, :state].collect{|a| address[a]}.reject{|a| a.blank?}.join(' ') 194: post[:QAPostcode] = address[:zip] 195: end
# File lib/active_merchant/billing/gateways/psl_card.rb, line 206 206: def add_amount(post, money, dispatch_type, options) 207: post[:CurrencyCode] = currency_code(options[:currency] || currency(money)) 208: 209: if dispatch_type == DISPATCH_LATER 210: post[:amount] = amount(NOMINAL_AMOUNT) 211: post[:DispatchLaterAmount] = amount(money) 212: else 213: post[:amount] = amount(money) 214: end 215: 216: post[:Dispatch] = dispatch_type 217: end
# File lib/active_merchant/billing/gateways/psl_card.rb, line 171 171: def add_credit_card(post, credit_card) 172: post[:QAName] = credit_card.name 173: post[:CardNumber] = credit_card.number 174: post[:EMVTerminalType] = EMV_TERMINAL_TYPE 175: post[:ExpMonth] = credit_card.month 176: post[:ExpYear] = credit_card.year 177: 178: if requires_start_date_or_issue_number?(credit_card) 179: post[:IssueNumber] = credit_card.issue_number unless credit_card.issue_number.blank? 180: post[:StartMonth] = credit_card.start_month unless credit_card.start_month.blank? 181: post[:StartYear] = credit_card.start_year unless credit_card.start_year.blank? 182: end 183: 184: # CV2 check 185: post[:AVSCV2Check] = credit_card.verification_value? ? 'YES' : 'NO' 186: post[:CV2] = credit_card.verification_value if credit_card.verification_value? 187: end
# File lib/active_merchant/billing/gateways/psl_card.rb, line 197 197: def add_invoice(post, options) 198: post[:MerchantName] = options[:merchant] || 'Merchant Name' # May use this as the order_id field 199: post[:OrderID] = options[:order_id] unless options[:order_id].blank? 200: end
# File lib/active_merchant/billing/gateways/psl_card.rb, line 219 219: def add_purchase_details(post) 220: post[:EchoAmount] = 'YES' 221: post[:SCBI] = 'YES' # Return information about the transaction 222: post[:MessageType] = MESSAGE_TYPE 223: end
# File lib/active_merchant/billing/gateways/psl_card.rb, line 202 202: def add_reference(post, authorization) 203: post[:CrossReference] = authorization 204: end
Send the passed data to PSL for processing
Parameters:
-request: The data that is to be sent to PSL
Returns:
* ActiveMerchant::Billing::Response object
# File lib/active_merchant/billing/gateways/psl_card.rb, line 267 267: def commit(request) 268: response = parse( ssl_post(URL, post_data(request)) ) 269: 270: Response.new(response[:ResponseCode] == APPROVED, response[:Message], response, 271: :test => test?, 272: :authorization => response[:CrossReference], 273: :cvv_result => CVV_CODE[response[:AVSCV2Check]], 274: :avs_result => { :code => AVS_CODE[response[:AVSCV2Check]] } 275: ) 276: end
Get the currency code for the passed money object
The money class stores the currency as an ISO 4217:2001 Alphanumeric, however PSL requires the ISO 4217:2001 Numeric code.
Parameters:
-money: Integer value in cents
Returns:
-the ISO 4217:2001 Numberic currency code
# File lib/active_merchant/billing/gateways/psl_card.rb, line 236 236: def currency_code(currency) 237: CURRENCY_CODES[currency] 238: end
Parse the PSL response and create a Response object
Parameters:
-body: The response string returned from PSL, Formatted: Key=value&key=value...
Returns:
-a hash with all of the values returned in the PSL response
# File lib/active_merchant/billing/gateways/psl_card.rb, line 249 249: def parse(body) 250: 251: fields = {} 252: for line in body.split('&') 253: key, value = *line.scan( %{^(\w+)\=(.*)$} ).flatten 254: fields[key] = CGI.unescape(value) 255: end 256: fields.symbolize_keys 257: end
Put the passed data into a format that can be submitted to PSL Key=Value&Key=Value…
Any ampersands and equal signs are removed from the data being posted as PSL puts them back into the response string which then cannot be parsed. This is after escaping before sending the request to PSL - this is a work around for the time being
Parameters:
-post: Hash of all the data to be sent
Returns:
-String: the data to be sent
# File lib/active_merchant/billing/gateways/psl_card.rb, line 292 292: def post_data(post) 293: post[:CountryCode] = self.location 294: post[:MerchantID] = @options[:login] 295: post[:ValidityID] = @options[:password] 296: post[:ResponseAction] = RESPONSE_ACTION 297: 298: post.collect { |key, value| 299: "#{key}=#{CGI.escape(value.to_s.tr('&=', ' '))}" 300: }.join("&") 301: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.