Class: WebpayBy::ConfirmationResponse
- Inherits:
-
Object
- Object
- WebpayBy::ConfirmationResponse
- 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
-
#confirmation ⇒ Object
readonly
Returns the value of attribute confirmation.
-
#parsed_response ⇒ Object
readonly
Returns the value of attribute parsed_response.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #approved? ⇒ Boolean
-
#initialize(confirmation:, response:) ⇒ ConfirmationResponse
constructor
A new instance of ConfirmationResponse.
- #response_fields ⇒ Object
- #signature ⇒ Object
-
#valid_signature? ⇒ Boolean
Проверка аутентичности XML-документа, пришедшего от банка.
- #wsb_api_response ⇒ Object
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
#confirmation ⇒ Object (readonly)
Returns the value of attribute confirmation.
36 37 38 |
# File 'lib/webpay_by/confirmation_response.rb', line 36 def confirmation @confirmation end |
#parsed_response ⇒ Object (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 |
#response ⇒ Object (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
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_fields ⇒ Object
48 49 50 |
# File 'lib/webpay_by/confirmation_response.rb', line 48 def response_fields wsb_api_response[:fields] || {} end |
#signature ⇒ Object
59 60 61 62 63 64 |
# File 'lib/webpay_by/confirmation_response.rb', line 59 def signature signed_fields = i( transaction_id 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-документа, пришедшего от банка
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_response ⇒ Object
44 45 46 |
# File 'lib/webpay_by/confirmation_response.rb', line 44 def wsb_api_response @parsed_response[:wsb_api_response] || {} end |