Sha256: f415b73efa2c3ec4be4125e967d941fb88d54f855e552b2f08bd79fb564eb0d5

Contents?: true

Size: 2 KB

Versions: 27

Compression:

Stored size: 2 KB

Contents

require 'net/http'

module ActiveMerchant #:nodoc:
  module Billing #:nodoc:
    module Integrations #:nodoc:
      module Liqpay
        class Notification < ActiveMerchant::Billing::Integrations::Notification
          def self.recognizes?(params)
            params.has_key?('amount') && params.has_key?('order_id')
          end

          def initialize(post, options = {})
            raise ArgumentError if post.blank?
            super
            @params.merge!(Hash.from_xml(Base64.decode64(xml))["response"])
          end

          def xml
            @params["operation_xml"]
          end

          def complete?
            status == 'success'
          end

          def account
            params['merchant_id']
          end

          def amount
            BigDecimal.new(gross)
          end

          def item_id
            params['order_id']
          end

          def transaction_id
            params['transaction_id']
          end

          def action_name
            params['action_name'] # either 'result_url' or 'server_url'
          end

          def version
            params['version']
          end

          def sender_phone
            params['sender_phone']
          end

          def security_key
            params[ActiveMerchant::Billing::Integrations::Liqpay.signature_parameter_name]
          end

          def gross
            params['amount']
          end

          def currency
            params['currency']
          end

          def status
            params['status'] # 'success', 'failure' or 'wait_secure'
          end

          def code
            params['code']
          end

          def generate_signature_string
            "#{@options[:secret]}#{Base64.decode64(xml)}#{@options[:secret]}"
          end

          def generate_signature
            Base64.encode64(Digest::SHA1.digest(generate_signature_string)).strip
          end

          def acknowledge
            security_key == generate_signature
          end
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 3 rubygems

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