Class: CheckoutRu::ExpiredTicketResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/checkout_ru/expired_ticket_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ExpiredTicketResponse

Returns a new instance of ExpiredTicketResponse.



7
8
9
# File 'lib/checkout_ru/expired_ticket_response.rb', line 7

def initialize(response)
  @response = response || {}
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/checkout_ru/expired_ticket_response.rb', line 5

def response
  @response
end

Instance Method Details

#broken_error_as_of_oct_06_2014?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/checkout_ru/expired_ticket_response.rb', line 27

def broken_error_as_of_oct_06_2014?
  status == 500 && body =~ /Сервис\s+временно\s+не\s+доступен/
end

#json_style_error_after_jan_2015?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/checkout_ru/expired_ticket_response.rb', line 19

def json_style_error_after_jan_2015?
  error && error_code == 3 && error_message =~ /is\s+expired\s+or\s+invalid/
end

#match?Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
# File 'lib/checkout_ru/expired_ticket_response.rb', line 11

def match?
  # Checkout.ru changed (broke) invalid ticket responses a few times. These
  # predicates reflect various ways we've seen that tickets can expire.
  json_style_error_after_jan_2015? ||
    old_style_error_before_jan_2015? ||
    broken_error_as_of_oct_06_2014?
end

#old_style_error_before_jan_2015?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/checkout_ru/expired_ticket_response.rb', line 23

def old_style_error_before_jan_2015?
  [400, 500].include?(status) && body =~ /is\s+expired\s+or\s+invalid/
end