class ActiveMerchant::Billing::AlfabankGateway
Constants
- STATUSES_HASH
Public Class Methods
new(options = {})
click to toggle source
Creates a new AlfabankGateway
The gateway requires that valid credentials be passed in the options
hash.
Options¶ ↑
-
:account
– The Alfabank API account (REQUIRED) -
:secret
– The Alfabank API secret (REQUIRED)
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/alfabank.rb, line 33 def initialize(options = {}) requires!(options, :account, :secret) super end
Public Instance Methods
get_order_status(options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/alfabank.rb, line 48 def get_order_status(options = {}) post = {} add_order_number(post, options) add_order_id(post, options) commit('getOrderStatusExtended', nil, post) end
make_order(options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/alfabank.rb, line 38 def make_order(options = {}) post = {} add_order_number(post, options) add_return_url(post, options) add_amount(post, options) add_description(post, options) commit('register', options[:amount], post) end
Private Instance Methods
add_amount(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/alfabank.rb, line 70 def add_amount(post, options) post[:amount] = amount(options[:amount]) end
add_description(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/alfabank.rb, line 74 def add_description(post, options) post[:description] = options[:description] end
add_order_id(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/alfabank.rb, line 62 def add_order_id(post, options) post[:orderId] = options[:order_id] end
add_order_number(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/alfabank.rb, line 58 def add_order_number(post, options) post[:orderNumber] = options[:order_number] end
add_return_url(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/alfabank.rb, line 66 def add_return_url(post, options) post[:returnUrl] = options[:return_url] end
commit(action, money, parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/alfabank.rb, line 78 def commit(action, money, parameters) base_url = (test? ? self.test_url : self.live_url) response = parse(ssl_post("#{base_url}/#{action}.do", post_data(action, parameters))) success = !has_error?(response) message = raw_message(response) || parse_status(response) || response['orderId'] params = convert_hash(response) Response.new(success, message, params) end
convert_hash(hash)
click to toggle source
# File lib/active_merchant/billing/gateways/alfabank.rb, line 108 def convert_hash(hash) Hash[hash.map { |key, value| [key.underscore, value] }] end
has_error?(response)
click to toggle source
# File lib/active_merchant/billing/gateways/alfabank.rb, line 100 def has_error?(response) response.blank? || !response['errorCode'].to_i.zero? end
parse(response)
click to toggle source
# File lib/active_merchant/billing/gateways/alfabank.rb, line 96 def parse(response) ActiveSupport::JSON.decode(response) end
parse_status(response)
click to toggle source
# File lib/active_merchant/billing/gateways/alfabank.rb, line 112 def parse_status(response) STATUSES_HASH[response['orderStatus'].to_s] end
post_data(action, parameters = {})
click to toggle source
# File lib/active_merchant/billing/gateways/alfabank.rb, line 89 def post_data(action, parameters = {}) parameters.merge!({ :userName => @options[:account], :password => @options[:secret] }).to_query end
raw_message(response)
click to toggle source
# File lib/active_merchant/billing/gateways/alfabank.rb, line 104 def raw_message(response) response['errorMessage'] end