class Assist::PaymentInterface

Constants

PAYMENT_METHODS_MAPPING
PERMITTED_EXTRA_PARAMS
QIWI_METHODS_MAPPING
SERVICE_PATH

Public Class Methods

new(order_number, order_amount, extra_params = {}) click to toggle source
# File lib/assist/payment_interface.rb, line 28
def initialize(order_number, order_amount, extra_params = {})
  extra_params = normalize_keys(extra_params)
  extra_params.keep_if { |key| PERMITTED_EXTRA_PARAMS.include?(key) }

  params.merge!(extra_params)
  params.merge!(ordernumber: order_number, orderamount: order_amount)

  return unless Assist.config.checkvalue?
  params[:checkvalue] = generate_checkvalue(params)
end

Public Instance Methods

url() click to toggle source
# File lib/assist/payment_interface.rb, line 39
def url
  uri = URI(Assist.config.endpoint + SERVICE_PATH)
  uri.query = URI.encode_www_form(params)
  uri.to_s
end

Private Instance Methods

default_params() click to toggle source
# File lib/assist/payment_interface.rb, line 51
def default_params
  attrs = {merchant_id: Assist.config.merchant_id}

  {
    return_url: :url_return,
    success_url: :url_return_ok,
    fail_url: :url_return_no
  }
  .each do |key, value|
    attrs[value] = Assist.config[key] if Assist.config[key]
  end

  attrs.merge!(payment_methods_params) if Assist.config.payment_methods
  attrs
end
params() click to toggle source
# File lib/assist/payment_interface.rb, line 47
def params
  @params ||= default_params
end
payment_methods_params() click to toggle source
# File lib/assist/payment_interface.rb, line 67
def payment_methods_params
  attrs = {}

  PAYMENT_METHODS_MAPPING.each do |key, value|
    attrs[value] = 0 unless Assist.config.payment_methods[key]
  end

  if Assist.config.payment_methods[:qiwi].is_a?(Hash)
    QIWI_METHODS_MAPPING.each do |key, value|
      attrs[value] = 0 unless Assist.config.payment_methods[:qiwi][key]
    end
  end

  attrs
end