Class: Inpay::Postback

Inherits:
Object
  • Object
show all
Defined in:
lib/inpay/postback.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, secret_key) ⇒ Postback

Returns a new instance of Postback.

Raises:



10
11
12
13
14
15
16
17
18
19
# File 'lib/inpay/postback.rb', line 10

def initialize request, secret_key
  raise NoDataError if request.nil? || request.raw_post.to_s.blank?
  
  @secret_key = secret_key
  @remote_ip  = request.remote_ip
  @params     = {}
  @raw        = ''

  parse(request.raw_post)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



50
51
52
# File 'lib/inpay/postback.rb', line 50

def method_missing(method, *args)
  params[method.to_s] || super
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



8
9
10
# File 'lib/inpay/postback.rb', line 8

def error
  @error
end

#paramsObject

Returns the value of attribute params.



8
9
10
# File 'lib/inpay/postback.rb', line 8

def params
  @params
end

#rawObject

Returns the value of attribute raw.



8
9
10
# File 'lib/inpay/postback.rb', line 8

def raw
  @raw
end

Instance Method Details

#approved?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/inpay/postback.rb', line 30

def approved?
  status == :approved
end

#cancelled?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/inpay/postback.rb', line 34

def cancelled?
  status == :cancelled
end

#error?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/inpay/postback.rb', line 46

def error?
  status == :error
end

#genuine?Boolean

acknowledge postback data

Returns:

  • (Boolean)


55
56
57
58
59
60
# File 'lib/inpay/postback.rb', line 55

def genuine?
  self.error = InvalidIPError     unless Inpay::Config.server_ips.include?(@remote_ip)
  self.error = ForgedRequestError unless Inpay.checksum(:postback, params) == params[:checksum]
  
  error.nil?
end

#pending?Boolean

Transaction statuses

Returns:

  • (Boolean)


22
23
24
# File 'lib/inpay/postback.rb', line 22

def pending?
  status == :pending
end

#refund_pending?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/inpay/postback.rb', line 42

def refund_pending?
  status == :refund_pending
end

#refunded?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/inpay/postback.rb', line 38

def refunded?
  status == :refunded?
end

#statusObject



62
63
64
# File 'lib/inpay/postback.rb', line 62

def status
  @status ||= (params[:invoice_status] ? params[:invoice_status].to_sym : nil)
end

#sum_too_low?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/inpay/postback.rb', line 26

def sum_too_low?
  status == :sum_too_low
end