class ActiveMerchant::Billing::QuickpayV10Gateway
Constants
- API_VERSION
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 12 def initialize(options = {}) requires!(options, :api_key) super end
Public Instance Methods
capture(money, identification, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 47 def capture(money, identification, options = {}) post = {} add_amount(post, money, options) add_additional_params(:capture, post, options) commit(synchronized_path("/payments/#{identification}/capture"), post) end
credit(money, identification, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 42 def credit(money, identification, options = {}) ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE refund(money, identification, options) end
purchase(money, credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 17 def purchase(money, credit_card, options = {}) MultiResponse.run(true) do |r| r.process { create_payment(money, options) } r.process { post = authorization_params(money, credit_card, options) add_autocapture(post, true) commit(synchronized_path("/payments/#{r.authorization}/authorize"), post) } end end
refund(money, identification, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 54 def refund(money, identification, options = {}) post = {} add_amount(post, money, options) add_additional_params(:refund, post, options) commit(synchronized_path("/payments/#{identification}/refund"), post) end
store(credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 61 def store(credit_card, options = {}) MultiResponse.run(true) do |r| r.process { create_subscription(options) } r.process { authorize_subscription(r.authorization, credit_card, options) } end end
unstore(identification)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 70 def unstore(identification) commit(synchronized_path "/subscriptions/#{identification}/cancel") end
void(identification)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 38 def void(identification) commit(synchronized_path "/payments/#{identification}/cancel") end
Private Instance Methods
add_additional_params(action, post, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 164 def add_additional_params(action, post, options = {}) MD5_CHECK_FIELDS[API_VERSION][action].each do |key| key = key.to_sym post[key] = options[key] if options[key] end end
add_amount(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 135 def add_amount(post, money, options) post[:amount] = amount(money) end
add_autocapture(post, value)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 139 def add_autocapture(post, value) post[:auto_capture] = value end
add_credit_card(post, credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 171 def add_credit_card(post, credit_card, options = {}) post[:card] ||= {} post[:card][:number] = credit_card.number post[:card][:cvd] = credit_card.verification_value post[:card][:expiration] = expdate(credit_card) post[:card][:issued_to] = credit_card.name end
add_currency(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 131 def add_currency(post, money, options) post[:currency] = options[:currency] || currency(money) end
add_invoice(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 148 def add_invoice(post, options) add_order_id(post, options) if options[:billing_address] post[:invoice_address] = map_address(options[:billing_address]) end if options[:shipping_address] post[:shipping_address] = map_address(options[:shipping_address]) end [:metadata, :brading_id, :variables].each do |field| post[field] = options[field] if options[field] end end
add_order_id(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 143 def add_order_id(post, options) requires!(options, :order_id) post[:order_id] = options[:order_id] end
add_subscription_invoice(post, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 125 def add_subscription_invoice(post, options = {}) requires!(options, :order_id, :description) post[:order_id] = options[:order_id] post[:description] = options[:description] end
commit(action, params = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 108 def commit(action, params = {}) success = false begin response = parse(ssl_post(self.live_url + action, params.to_json, headers)) success = successful?(response) rescue ResponseError => e response = response_error(e.response.body) rescue JSON::ParserError response = json_error(response) end Response.new(success, message_from(success, response), response, :test => test?, :authorization => response['id'] ) end
create_payment(money, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 101 def create_payment(money, options = {}) post = {} add_currency(post, money, options) add_invoice(post, options) commit('/payments', post) end
create_subscription(options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 86 def create_subscription(options = {}) post = {} add_subscription_invoice(post, options) commit('/subscriptions', post) end
headers()
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 208 def headers auth = Base64.strict_encode64(":#{@options[:api_key]}") { "Authorization" => "Basic " + auth, "User-Agent" => "Quickpay-v#{API_VERSION} ActiveMerchantBindings/#{ActiveMerchant::VERSION}", "Accept" => "application/json", "Accept-Version" => "v#{API_VERSION}", "Content-Type" => "application/json" } end
json_error(raw_response)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 227 def json_error(raw_response) msg = 'Invalid response received from the Quickpay API.' msg += " (The raw response returned by the API was #{raw_response.inspect})" { "message" => msg } end
map_address(address)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 194 def map_address(address) return {} if address.nil? requires!(address, :name, :address1, :city, :zip, :country) mapped = { :name => address[:name], :street => address[:address1], :city => address[:city], :region => address[:address2], :zip_code => address[:zip], :country_code => address[:country] } mapped end
message_from(success, response)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 190 def message_from(success, response) success ? 'OK' : (response['message'] || response['qp_status_msg']) end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 179 def parse(body) JSON.parse(body) end
response_error(raw_response)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 219 def response_error(raw_response) begin parse(raw_response) rescue JSON::ParserError json_error(raw_response) end end
successful?(response)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 183 def successful?(response) has_error = response['errors'] invalid_code = (response.key?('qp_status_code') and response['qp_status_code'] != "20000") !(has_error || invalid_code) end
synchronized_path(path)
click to toggle source
# File lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb, line 233 def synchronized_path(path) "#{path}?synchronized" end