Sha256: d4f25a21c4b4f52fb177271c658573a1c8130efe1a25f050252e1eef4b061cf1

Contents?: true

Size: 1.92 KB

Versions: 40

Compression:

Stored size: 1.92 KB

Contents

require 'net/http'

module ActiveMerchant #:nodoc:
  module Billing #:nodoc:
    module Integrations #:nodoc:
      module Dotpay
        class Notification < ActiveMerchant::Billing::Integrations::Notification
          def complete?
            status == 'OK' && %w(2 4 5).include?(t_status)
          end

          def currency
            orginal_amount.split(' ')[1]
          end

          # the money amount we received in X.2 decimal.
          def gross
            params['amount']
          end

          def pin=(value)
            @options[:pin] = value
          end

          def status
            params['status']
          end

          def test?
            params['t_id'].match('.*-TST\d+') ? true : false
          end

          PAYMENT_HOOK_FIELDS = [
            :id,
            :control,
            :t_id,
            :orginal_amount,
            :email,
            :service,
            :code,
            :username,
            :password,
            :t_status,
            :description,
            :md5,
            :p_info,
            :p_email,
            :t_date
          ]

          PAYMENT_HOOK_SIGNATURE_FIELDS = [
            :id,
            :control,
            :t_id,
            :amount,
            :email,
            :service,
            :code,
            :username,
            :password,
            :t_status
          ]

          # Provide access to raw fields
          PAYMENT_HOOK_FIELDS.each do |key|
            define_method(key.to_s) do
               params[key.to_s]
            end
          end

          def generate_signature_string
            "#{@options[:pin]}:" + PAYMENT_HOOK_SIGNATURE_FIELDS.map {|key| params[key.to_s]} * ":"
          end

          def generate_signature
            Digest::MD5.hexdigest(generate_signature_string)
          end

          def acknowledge      
            generate_signature.to_s == md5.to_s
          end
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 5 rubygems

Version Path
tanga_activemerchant-1.38.0.5 lib/active_merchant/billing/integrations/dotpay/notification.rb
tanga_activemerchant-1.38.0.4 lib/active_merchant/billing/integrations/dotpay/notification.rb
tanga_activemerchant-1.38.0.3 lib/active_merchant/billing/integrations/dotpay/notification.rb
tanga_activemerchant-1.38.0.2 lib/active_merchant/billing/integrations/dotpay/notification.rb
tanga_activemerchant-1.38.0.1 lib/active_merchant/billing/integrations/dotpay/notification.rb
tanga_activemerchant-1.38.0 lib/active_merchant/billing/integrations/dotpay/notification.rb
tanga_activemerchant-1.37.0 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.38.1 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.38.0 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.37.0 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.36.0 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.35.0 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.35.1 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.34.1 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.34.0 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.33.0 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.32.1 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.32.0 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.31.1 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.31.0 lib/active_merchant/billing/integrations/dotpay/notification.rb