class ActiveMerchant::Billing::PacNetRavenGateway
Constants
- AVS_ADDRESS_CODES
- AVS_POSTAL_CODES
- CVV2_CODES
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 37 def initialize(options = {}) requires!(options, :user, :secret, :prn) super end
Public Instance Methods
capture(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 70 def capture(money, authorization, options = {}) post = {} post['PreauthNumber'] = authorization post['PRN'] = @options[:prn] add_currency_code(post, money, options) commit('cc_settle', money, post) end
purchase(money, creditcard, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 52 def purchase(money, creditcard, options = {}) post = {} add_currency_code(post, money, options) add_creditcard(post, creditcard) add_address(post, options) post['PRN'] = @options[:prn] commit('cc_debit', money, post) end
refund(money, template_number, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 79 def refund(money, template_number, options = {}) post = {} post['PRN'] = @options[:prn] post['TemplateNumber'] = template_number add_currency_code(post, money, options) commit('cc_refund', money, post) end
void(authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 62 def void(authorization, options = {}) post = {} post['TrackingNumber'] = authorization post['PymtType'] = options[:pymt_type] commit('void', nil, post) end
Private Instance Methods
add_address(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 100 def add_address(post, options) if address = options[:billing_address] || options[:address] post['BillingStreetAddressLineOne'] = address[:address1].to_s post['BillingStreetAddressLineFour'] = address[:address2].to_s post['BillingPostalCode'] = address[:zip].to_s end end
add_creditcard(post, creditcard)
click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 90 def add_creditcard(post, creditcard) post['CardNumber'] = creditcard.number post['Expiry'] = expdate(creditcard) post['CVV2'] = creditcard.verification_value if creditcard.verification_value end
add_currency_code(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 96 def add_currency_code(post, money, options) post['Currency'] = options[:currency] || currency(money) end
commit(action, money, parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 112 def commit(action, money, parameters) parameters['Amount'] = amount(money) unless action == 'void' data = ssl_post url(action), post_data(action, parameters) response = parse(data) response[:action] = action message = message_from(response) test_mode = test? || message =~ /TESTMODE/ Response.new( success?(response), message, response, test: test_mode, authorization: response['TrackingNumber'], fraud_review: fraud_review?(response), avs_result: { postal_match: AVS_POSTAL_CODES[response['AVSPostalResponseCode']], street_match: AVS_ADDRESS_CODES[response['AVSAddressResponseCode']] }, cvv_result: CVV2_CODES[response['CVV2ResponseCode']] ) end
endpoint(action)
click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 143 def endpoint(action) return 'void' if action == 'void' 'submit' end
fraud_review?(response)
click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 149 def fraud_review?(response) false end
message_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 161 def message_from(response) return response['Message'] if response['Message'] if response['Status'] == 'Approved' 'This transaction has been approved' elsif response['Status'] == 'Declined' 'This transaction has been declined' elsif response['Status'] == 'Voided' 'This transaction has been voided' else response['Status'] end end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 108 def parse(body) Hash[body.split('&').map { |x| x.split('=').map { |y| CGI.unescape(y) } }] end
post_data(action, parameters = {})
click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 175 def post_data(action, parameters = {}) post = {} post['PymtType'] = action post['RAPIVersion'] = '2' post['UserName'] = @options[:user] post['Timestamp'] = timestamp post['RequestID'] = request_id post['Signature'] = signature(action, post, parameters) post.merge(parameters).collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join('&') end
request_id()
click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 192 def request_id SecureRandom.uuid end
signature(action, post, parameters = {})
click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 196 def signature(action, post, parameters = {}) string = if %w(cc_settle cc_debit cc_preauth cc_refund).include?(action) post['UserName'] + post['Timestamp'] + post['RequestID'] + post['PymtType'] + parameters['Amount'].to_s + parameters['Currency'] elsif action == 'void' post['UserName'] + post['Timestamp'] + post['RequestID'] + parameters['TrackingNumber'] else post['UserName'] end OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA1.new(@options[:secret]), @options[:secret], string) end
success?(response)
click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 153 def success?(response) if %w(cc_settle cc_debit cc_preauth cc_refund).include?(response[:action]) !response['ApprovalCode'].nil? && response['ErrorCode'].nil? && (response['Status'] == 'Approved') elsif response[:action] = 'void' !response['ApprovalCode'].nil? && response['ErrorCode'].nil? && (response['Status'] == 'Voided') end end
timestamp()
click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 188 def timestamp Time.now.strftime('%Y-%m-%dT%H:%M:%S.Z') end
url(action)
click to toggle source
# File lib/active_merchant/billing/gateways/pac_net_raven.rb, line 139 def url(action) (test? ? self.test_url : self.live_url) + endpoint(action) end