<commit_before>require 'net/http'

module ActiveMerchant #:nodoc:
  module Billing #:nodoc:
    module Integrations #:nodoc:
      module Fatpay
        class Notification < ActiveMerchant::Billing::Integrations::Notification
          %w(
            data
            sign
          ).each do |param_name|
            define_method(param_name.underscore){ params[param_name] }
          end

          alias_method :encoded_params, :data
          alias_method :signature, :sign

          def status
            case decoded_params['status']
            when '0'
              'pending'
            when '99'
              'failed'
            when '3'
              'completed'
            else 'unknown'
            end
          end

          def decoded_params
            JSON.parse(Base64.decode64(encoded_params))
          end

          def payment_id
            decoded_params['reference'].to_i
          end

          def generate_signature
            OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('md5'), @options[:secret], encoded_params)
          end

          def acknowledge
            (generate_signature == signature) && (status == 'completed')
          end

        end
      end
    end
  end
end<commit_msg>BAC-912 add .strip to signature from fatpay processing<commit_after>require 'net/http'

module ActiveMerchant #:nodoc:
  module Billing #:nodoc:
    module Integrations #:nodoc:
      module Fatpay
        class Notification < ActiveMerchant::Billing::Integrations::Notification
          %w(
            data
            sign
          ).each do |param_name|
            define_method(param_name.underscore){ params[param_name] }
          end

          alias_method :encoded_params, :data
          alias_method :signature, :sign

          def status
            case decoded_params['status']
            when '0'
              'pending'
            when '99'
              'failed'
            when '3'
              'completed'
            else 'unknown'
            end
          end

          def decoded_params
            JSON.parse(Base64.decode64(encoded_params))
          end

          def payment_id
            decoded_params['reference'].to_i
          end

          def generate_signature
            OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('md5'), @options[:secret], encoded_params)
          end

          def acknowledge
            (generate_signature.strip == signature.strip) && (status == 'completed')
          end

        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08185753640299095, 'fraction_numerical': 0.008264462809917356, 'mean_word_length': 1.6045081967213115, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2403381', 'n_tokens_mistral': 685, 'n_tokens_neox': 648, 'n_words': 154}