Class: Pay24::ResponseHandler
- Inherits:
-
Object
- Object
- Pay24::ResponseHandler
- Includes:
- Errors
- Defined in:
- lib/pay24/response_handler.rb
Defined Under Namespace
Classes: PaymentIsZero
Constant Summary collapse
- EMAIL_REGEX =
/\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/
- IDENTIFICATOR_REGEX =
/\A\d+\z/
- REQUEST_HANDLERS =
{ pay: :osmp_pay, check: :check_if_account_is_valid, }.freeze
Constants included from Errors
Errors::ERROR_CANNOT_CHECK_USER_ACCOUNT_STATE, Errors::ERROR_INACTIVE_USER, Errors::ERROR_INTERNAL, Errors::ERROR_INVALID_USER_ID_FORMAT, Errors::ERROR_PAYMENT_DENIED_BY_PROVIDER, Errors::ERROR_PAYMENT_DENIED_FOR_TECHNICAL_REASON, Errors::ERROR_SUM_IS_TOO_LARGE, Errors::ERROR_SUM_IS_TOO_SMALL, Errors::ERROR_USER_NOT_FOUND, Errors::PAYMENT_PROCESSING_NOT_FINISHED, Errors::SUCCESS, Errors::TEMPORARY_ERROR
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#sum ⇒ Object
readonly
Returns the value of attribute sum.
-
#transaction_date ⇒ Object
readonly
Returns the value of attribute transaction_date.
-
#transaction_id ⇒ Object
readonly
Returns the value of attribute transaction_id.
Attributes included from Errors
Instance Method Summary collapse
- #command_is_valid? ⇒ Boolean
- #generate_xml(result, comment = '') ⇒ Object
-
#initialize(params: {}, find_user_callback: nil, payment_callback: nil, raise_on_error: false) ⇒ ResponseHandler
constructor
A new instance of ResponseHandler.
- #payment_command? ⇒ Boolean
- #requested_account ⇒ Object
- #run_command ⇒ Object
Constructor Details
#initialize(params: {}, find_user_callback: nil, payment_callback: nil, raise_on_error: false) ⇒ ResponseHandler
Returns a new instance of ResponseHandler.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/pay24/response_handler.rb', line 28 def initialize(params: {}, find_user_callback: nil, payment_callback: nil, raise_on_error: false) @command = params[:command] @account = params[:account] @transaction_id = params[:txn_id] @transaction_date = params[:txn_date] @sum = params[:sum] @find_user_callback = find_user_callback @payment_callback = payment_callback @raise_on_error = raise_on_error freeze end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
18 19 20 |
# File 'lib/pay24/response_handler.rb', line 18 def account @account end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
18 19 20 |
# File 'lib/pay24/response_handler.rb', line 18 def command @command end |
#sum ⇒ Object (readonly)
Returns the value of attribute sum.
18 19 20 |
# File 'lib/pay24/response_handler.rb', line 18 def sum @sum end |
#transaction_date ⇒ Object (readonly)
Returns the value of attribute transaction_date.
18 19 20 |
# File 'lib/pay24/response_handler.rb', line 18 def transaction_date @transaction_date end |
#transaction_id ⇒ Object (readonly)
Returns the value of attribute transaction_id.
18 19 20 |
# File 'lib/pay24/response_handler.rb', line 18 def transaction_id @transaction_id end |
Instance Method Details
#command_is_valid? ⇒ Boolean
40 41 42 |
# File 'lib/pay24/response_handler.rb', line 40 def command_is_valid? @command.to_sym.in?(REQUEST_HANDLERS.keys) end |
#generate_xml(result, comment = '') ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/pay24/response_handler.rb', line 62 def generate_xml(result, comment = '') xml = Builder::XmlMarkup.new indent: 2 xml.instruct! xml.response do |req| req.result result.code req.comment comment if payment_command? req.txn_id @transaction_id req.sum @sum end end end |
#payment_command? ⇒ Boolean
44 45 46 |
# File 'lib/pay24/response_handler.rb', line 44 def payment_command? @command.to_sym == :pay end |
#requested_account ⇒ Object
58 59 60 |
# File 'lib/pay24/response_handler.rb', line 58 def requested_account @find_user_callback.(@account) rescue ERROR_CANNOT_CHECK_USER_ACCOUNT_STATE end |
#run_command ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/pay24/response_handler.rb', line 48 def run_command result_code = if command_is_valid? send(REQUEST_HANDLERS[@command.to_sym]) || ERROR_INTERNAL else ERROR_INTERNAL end Pay24::Result.new(result_code) end |