Class: WebpayBy::ConfirmationResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/webpay_by/confirmation_response.rb

Constant Summary collapse

PAYMENT_TYPES =
{
  'Completed':      'Завершенная',
  'Declined':       'Отклоненная',
  'Pending':        'Вобработке',
  'Authorized':     'Авторизованная',
  'Refunded':       'Возвращенная',
  'System':         'Системная',
  'Voided':         'Сброшенная после авторизации',
  'Failed':         'Ошибка в проведении операции',
  'Partial Voided': 'Частичный сброс',
  'Recurrent':      'Рекуррентный платеж'
}
SUCCESSFUL_TYPE_INDEXES =

Успешной оплате соответствуют следующие значения: Completed, Authorized, Recurrent Ниже храним в константе их типы

%w( 1 4 10 )

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(confirmation:, response:) ⇒ ConfirmationResponse

Returns a new instance of ConfirmationResponse.



38
39
40
41
42
# File 'lib/webpay_by/confirmation_response.rb', line 38

def initialize(confirmation:, response:)
  @confirmation     = confirmation
  @response         = response
  @parsed_response  = Hash.from_xml(@response).deep_symbolize_keys rescue {}
end

Instance Attribute Details

#confirmationObject (readonly)

Returns the value of attribute confirmation.



36
37
38
# File 'lib/webpay_by/confirmation_response.rb', line 36

def confirmation
  @confirmation
end

#parsed_responseObject (readonly)

Returns the value of attribute parsed_response.



36
37
38
# File 'lib/webpay_by/confirmation_response.rb', line 36

def parsed_response
  @parsed_response
end

#responseObject (readonly)

Returns the value of attribute response.



36
37
38
# File 'lib/webpay_by/confirmation_response.rb', line 36

def response
  @response
end

Instance Method Details

#approved?Boolean

Returns:



66
67
68
69
# File 'lib/webpay_by/confirmation_response.rb', line 66

def approved?
  payment_type_index = response_fields[:payment_type]
  valid_signature? && payment_type_index.in?(SUCCESSFUL_TYPE_INDEXES)
end

#response_fieldsObject



48
49
50
# File 'lib/webpay_by/confirmation_response.rb', line 48

def response_fields
  wsb_api_response[:fields] || {}
end

#signatureObject



59
60
61
62
63
64
# File 'lib/webpay_by/confirmation_response.rb', line 59

def signature
  signed_fields = i( transaction_id batch_timestamp currency_id amount payment_method payment_type order_id rrn )
  signed_attrs  = response_fields.values_at *signed_fields
  signed_attrs  << @confirmation.client.secret_key
  Digest::MD5.hexdigest signed_attrs.join
end

#valid_signature?Boolean

Проверка аутентичности XML-документа, пришедшего от банка

Returns:



53
54
55
56
57
# File 'lib/webpay_by/confirmation_response.rb', line 53

def valid_signature?
  return false unless response_fields.any?

  signature == response_fields[:wsb_signature]
end

#wsb_api_responseObject



44
45
46
# File 'lib/webpay_by/confirmation_response.rb', line 44

def wsb_api_response
  @parsed_response[:wsb_api_response] || {}
end