Sha256: 66eb1b4477d2483cf98b43763c639c6f16ea06e5d7a3a59d9b621f7166bd9d71

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

module Sisow
  module Api
    class Callback

      attr_accessor :transaction_id,
                    :entrance_code,
                    :status,
                    :sha1

      def initialize(attributes = {})
        attributes.each do |k,v|
          send("#{k}=", v)
        end
      end

      def valid?
        valid_callback == true
      end

      def validate!
        return true if valid_callback == true
        raise Sisow::Exception, "This callback is forged" and return if valid_callback == false
      end

      def success?
        @status == 'Success'
      end

      def expired?
        @status == 'Expired'
      end

      def cancelled?
        @status == 'Cancelled'
      end

      def failure?
        @status == 'Failure'
      end

      def pending?
        @status == 'Pending'
      end

      def reversed?
        @status == 'Reversed'
      end

      private

        def valid_callback
          string = [ @transaction_id, @entrance_code, @status, Sisow.configuration.merchant_id, Sisow.configuration.merchant_key ].join
          calculated_sha1 = Digest::SHA1.hexdigest(string)

          calculated_sha1 == @sha1
        end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sisow-1.7 lib/sisow/api/callback.rb
sisow-1.6 lib/sisow/api/callback.rb
sisow-1.5 lib/sisow/api/callback.rb
sisow-1.4 lib/sisow/api/callback.rb
sisow-1.3 lib/sisow/api/callback.rb
sisow-1.2 lib/sisow/api/callback.rb