Sha256: 123b13e9c9caf972e9f4c70e0478f168b37c6e8c98b5e138da06748f0108c424

Contents?: true

Size: 1.49 KB

Versions: 7

Compression:

Stored size: 1.49 KB

Contents

# -*- encoding : utf-8 -*-
require 'rubykassa/signature_generator'

module Rubykassa  
  class PaymentInterface
    include SignatureGenerator

    PARAMS_CONFORMITY = {
      login:       "MrchLogin",
      total:       "OutSum",
      invoice_id:  "InvId",
      signature:   "SignatureValue",
      email:       "Email",
      currency:    "IncCurrLabel",
      description: "Desc",
      culture:     "Culture"
    }

    attr_accessor :invoice_id, :total, :params

    def initialize &block
      instance_eval &block if block_given?
      shpfy_params
    end

    def test_mode?
      Rubykassa.mode == :test
    end

    def base_url
      test_mode? ? "http://test.robokassa.ru/Index.aspx" : "https://merchant.roboxchange.com/Index.aspx"
    end

    def pay_url(extra_params = {})
      extra_params = extra_params.slice(:currency, :description, :email, :culture)

      "#{base_url}?" + initial_options.merge(extra_params).map do |key, value| 
        if key =~ /^shp/
          "#{key}=#{value}"
        else
          "#{PARAMS_CONFORMITY[key]}=#{value}"
        end
      end.compact.join("&")
    end

    def initial_options
      {
        login: Rubykassa.login,
        total: @total,
        invoice_id: @invoice_id,
        signature: generate_signature_for(:payment)
      }.merge(Hash[@params.sort.map {|param_name| [param_name[0], param_name[1]]}])
    end

    private

      def shpfy_params
        @params = @params.map {|param_name| ["shp#{param_name[0]}".to_sym, param_name[1]]}
      end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rubykassa-0.4.2 lib/rubykassa/payment_interface.rb
rubykassa-0.4.1 lib/rubykassa/payment_interface.rb
rubykassa-0.4.0 lib/rubykassa/payment_interface.rb
rubykassa-0.3.2 lib/rubykassa/payment_interface.rb
rubykassa-0.3.1 lib/rubykassa/payment_interface.rb
rubykassa-0.3.0 lib/rubykassa/payment_interface.rb
rubykassa-0.2.6 lib/rubykassa/payment_interface.rb