class ActiveMerchant::Billing::QuickpayV4to7Gateway
Constants
- APPROVED
Public Class Methods
new(options = {})
click to toggle source
The login is the QuickpayId The password is the md5checkword from the Quickpay manager To use the API-key from the Quickpay manager, specify :api-key Using the API-key, requires that you use version 4+. Specify :version => 4/5/6/7 in options.
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 16 def initialize(options = {}) requires!(options, :login, :password) @protocol = options.delete(:version) || 7 # default to protocol version 7 super end
Public Instance Methods
capture(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 51 def capture(money, authorization, options = {}) post = {} add_finalize(post, options) add_reference(post, authorization) add_amount_without_currency(post, money) commit(:capture, post) end
credit(money, identification, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 77 def credit(money, identification, options = {}) ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE refund(money, identification, options) end
purchase(money, credit_card_or_reference, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 37 def purchase(money, credit_card_or_reference, options = {}) post = {} action = recurring_or_authorize(credit_card_or_reference) add_amount(post, money, options) add_creditcard_or_reference(post, credit_card_or_reference, options) add_invoice(post, options) add_fraud_parameters(post, options) if action.eql?(:authorize) add_autocapture(post, true) commit(action, post) end
refund(money, identification, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 68 def refund(money, identification, options = {}) post = {} add_amount_without_currency(post, money) add_reference(post, identification) commit(:refund, post) end
store(creditcard, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 82 def store(creditcard, options = {}) post = {} add_creditcard(post, creditcard, options) add_amount(post, 0, options) if @protocol >= 7 add_invoice(post, options) add_description(post, options) add_fraud_parameters(post, options) add_testmode(post) commit(:subscribe, post) end
void(identification, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 60 def void(identification, options = {}) post = {} add_reference(post, identification) commit(:cancel, post) end
Private Instance Methods
add_amount(post, money, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 97 def add_amount(post, money, options = {}) post[:amount] = amount(money) post[:currency] = options[:currency] || currency(money) end
add_amount_without_currency(post, money, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 102 def add_amount_without_currency(post, money, options = {}) post[:amount] = amount(money) end
add_autocapture(post, autocapture)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 130 def add_autocapture(post, autocapture) post[:autocapture] = autocapture ? 1 : 0 end
add_creditcard(post, credit_card, options)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 110 def add_creditcard(post, credit_card, options) post[:cardnumber] = credit_card.number post[:cvd] = credit_card.verification_value post[:expirationdate] = expdate(credit_card) post[:cardtypelock] = options[:cardtypelock] unless options[:cardtypelock].blank? post[:acquirers] = options[:acquirers] unless options[:acquirers].blank? end
add_creditcard_or_reference(post, credit_card_or_reference, options)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 122 def add_creditcard_or_reference(post, credit_card_or_reference, options) if credit_card_or_reference.is_a?(String) add_reference(post, credit_card_or_reference) else add_creditcard(post, credit_card_or_reference, options) end end
add_description(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 138 def add_description(post, options) post[:description] = options[:description] || 'Description' end
add_finalize(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 160 def add_finalize(post, options) post[:finalize] = options[:finalize] ? '1' : '0' end
add_fraud_parameters(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 148 def add_fraud_parameters(post, options) if @protocol >= 4 post[:fraud_remote_addr] = options[:ip] if options[:ip] post[:fraud_http_accept] = options[:fraud_http_accept] if options[:fraud_http_accept] post[:fraud_http_accept_language] = options[:fraud_http_accept_language] if options[:fraud_http_accept_language] post[:fraud_http_accept_encoding] = options[:fraud_http_accept_encoding] if options[:fraud_http_accept_encoding] post[:fraud_http_accept_charset] = options[:fraud_http_accept_charset] if options[:fraud_http_accept_charset] post[:fraud_http_referer] = options[:fraud_http_referer] if options[:fraud_http_referer] post[:fraud_http_user_agent] = options[:fraud_http_user_agent] if options[:fraud_http_user_agent] end end
add_invoice(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 106 def add_invoice(post, options) post[:ordernumber] = format_order_number(options[:order_id]) end
add_reference(post, identification)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 118 def add_reference(post, identification) post[:transaction] = identification end
add_testmode(post)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 142 def add_testmode(post) return if post[:transaction].present? post[:testmode] = test? ? '1' : '0' end
commit(action, params)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 164 def commit(action, params) response = parse(ssl_post(self.live_url, post_data(action, params))) Response.new( successful?(response), message_from(response), response, test: test?, authorization: response[:transaction] ) end
expdate(credit_card)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 217 def expdate(credit_card) year = format(credit_card.year, :two_digits) month = format(credit_card.month, :two_digits) "#{year}#{month}" end
format_order_number(number)
click to toggle source
Limited to 20 digits max
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 225 def format_order_number(number) number.to_s.gsub(/[^\w]/, '').rjust(4, '0')[0...20] end
generate_check_hash(action, params)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 206 def generate_check_hash(action, params) string = MD5_CHECK_FIELDS[@protocol][action].collect do |key| params[key.to_sym] end.join('') # Add the md5checkword string << @options[:password].to_s Digest::MD5.hexdigest(string) end
message_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 192 def message_from(response) response[:qpstatmsg].to_s end
parse(data)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 180 def parse(data) response = {} doc = REXML::Document.new(data) doc.root.elements.each do |element| response[element.name.to_sym] = element.text end response end
post_data(action, params = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 196 def post_data(action, params = {}) params[:protocol] = @protocol params[:msgtype] = action.to_s params[:merchant] = @options[:login] params[:apikey] = @options[:apikey] if @options[:apikey] params[:md5check] = generate_check_hash(action, params) params.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join('&') end
successful?(response)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb, line 176 def successful?(response) response[:qpstat] == APPROVED end