<commit_before>require 'net/http'

module ActiveMerchant #:nodoc:
  module Billing #:nodoc:
    module Integrations #:nodoc:
      module Cardpay
        class Notification < ActiveMerchant::Billing::Integrations::Notification

        end
      end
    end
  end
end<commit_msg>BAC-852 add cardpay notification methods<commit_after>require 'net/http'

module ActiveMerchant #:nodoc:
  module Billing #:nodoc:
    module Integrations #:nodoc:
      module Cardpay
        class Notification < ActiveMerchant::Billing::Integrations::Notification

          %w(orderXML sha512).each do |param_name|
            define_method(param_name.underscore){ params[param_name] }
          end

          alias_method :signature, :sha512

          def payment_params
            Hash.from_xml(request_xml)["order"]
          end

          def request_xml
            Base64.decode64(order_xml)
          end

          def status
            case payment_params["status"]
              when 'APPROVED' then 'completed'
              when 'DECLINED' then 'canceled'
              when 'PENDING' then 'pending'
              else 'unknown'
            end
          end

          def amount
            payment_params["amount"].to_f
          end

          def currency
            payment_params["currency"]
          end

          def payment_id
            payment_params["number"].to_i
          end

          def generate_signature
            Digest::SHA512.hexdigest(request_xml + @options[:secret])
          end

          def acknowledge
            signature = generate_signature
          end

        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.06963958460598656, 'fraction_numerical': 0.009773976786805132, 'mean_word_length': 1.8241379310344827, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 5}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6888693', 'n_tokens_mistral': 449, 'n_tokens_neox': 424, 'n_words': 105}