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
activemerchant-1.30.0 lib/active_merchant/billing/integrations/dotpay/notification.rb
jelaniharris-activemerchant-1.29.2 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.29.3 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.29.2 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.29.1 lib/active_merchant/billing/integrations/dotpay/notification.rb
jelaniharris-activemerchant-1.29.1 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.29.0 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-nsp-1.27.0 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.28.0 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.27.0 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.26.0 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.25.0 lib/active_merchant/billing/integrations/dotpay/notification.rb
jelaniharris-activemerchant-1.24.1 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.24.0 lib/active_merchant/billing/integrations/dotpay/notification.rb
tlconnor-activemerchant-1.23.3 lib/active_merchant/billing/integrations/dotpay/notification.rb
tlconnor-activemerchant-1.23.2 lib/active_merchant/billing/integrations/dotpay/notification.rb
tlconnor-activemerchant-1.23.1 lib/active_merchant/billing/integrations/dotpay/notification.rb
tlconnor-activemerchant-1.23.0 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.23.0 lib/active_merchant/billing/integrations/dotpay/notification.rb
activemerchant-1.22.0 lib/active_merchant/billing/integrations/dotpay/notification.rb