Class: PaynetEasy::PaynetEasyApi::PaymentProcessor
- Inherits:
-
Object
- Object
- PaynetEasy::PaynetEasyApi::PaymentProcessor
- Includes:
- Callback, PaymentData, Query, Transport
- Defined in:
- lib/paynet_easy/paynet_easy_api/payment_processor.rb
Constant Summary collapse
- HANDLER_SAVE_CHANGES =
Payment changed and should be saved
'save_payment'
- HANDLER_STATUS_UPDATE =
Payment status not changed and should be updated
'status_update'
- HANDLER_SHOW_HTML =
Html received and should be displayed
'show_html'
- HANDLER_REDIRECT =
Redirect url received, customer should be to it
'redirect'
- HANDLER_FINISH_PROCESSING =
Payment processing ended
'finish_processing'
- HANDLER_CATCH_EXCEPTION =
Exception handle needed
'catch_exception'
- @@allowed_handlers =
Allowed handlers list
[ HANDLER_SAVE_CHANGES, HANDLER_STATUS_UPDATE, HANDLER_SHOW_HTML, HANDLER_REDIRECT, HANDLER_FINISH_PROCESSING, HANDLER_CATCH_EXCEPTION ]
Instance Attribute Summary collapse
-
#callback_factory ⇒ Object
Returns the value of attribute callback_factory.
-
#gateway_client ⇒ Object
Returns the value of attribute gateway_client.
-
#query_factory ⇒ Object
Returns the value of attribute query_factory.
Instance Method Summary collapse
-
#callback(callback_type) ⇒ CallbackPrototype
Create API callback processor by callback response.
-
#execute_query(query_name, payment_transaction) ⇒ Response
Executes payment API query.
-
#initialize(handlers = {}) ⇒ PaymentProcessor
constructor
A new instance of PaymentProcessor.
-
#make_request(request) ⇒ Response
Make request to the PaynetEasy gateway.
-
#process_customer_return(callback_response, payment_transaction) ⇒ CallbackResponse
Executes payment gateway processor for customer return from payment form or 3D-auth.
-
#process_paynet_easy_callback(callback_response, payment_transaction) ⇒ CallbackResponse
Executes payment gateway processor for PaynetEasy payment callback.
-
#query(api_query_name) ⇒ Prototype::Query
Create API query object by API query method.
-
#remove_handler(handler_name) ⇒ Object
Remove handler for processing action.
-
#remove_handlers ⇒ Object
Remove all handlers.
-
#set_handler(handler_name, &handler_callback) ⇒ Object
Set handler callback for processing action.
-
#set_handlers(handlers = {}) ⇒ Object
Set handlers.
Constructor Details
#initialize(handlers = {}) ⇒ PaymentProcessor
Returns a new instance of PaymentProcessor.
51 52 53 54 |
# File 'lib/paynet_easy/paynet_easy_api/payment_processor.rb', line 51 def initialize(handlers = {}) @handlers = {} set_handlers handlers end |
Instance Attribute Details
#callback_factory ⇒ Object
Returns the value of attribute callback_factory.
49 50 51 |
# File 'lib/paynet_easy/paynet_easy_api/payment_processor.rb', line 49 def callback_factory @callback_factory end |
#gateway_client ⇒ Object
Returns the value of attribute gateway_client.
47 48 49 |
# File 'lib/paynet_easy/paynet_easy_api/payment_processor.rb', line 47 def gateway_client @gateway_client end |
#query_factory ⇒ Object
Returns the value of attribute query_factory.
48 49 50 |
# File 'lib/paynet_easy/paynet_easy_api/payment_processor.rb', line 48 def query_factory @query_factory end |
Instance Method Details
#callback(callback_type) ⇒ CallbackPrototype
Create API callback processor by callback response
123 124 125 |
# File 'lib/paynet_easy/paynet_easy_api/payment_processor.rb', line 123 def callback(callback_type) callback_factory.callback callback_type end |
#execute_query(query_name, payment_transaction) ⇒ Response
Executes payment API query
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/paynet_easy/paynet_easy_api/payment_processor.rb', line 62 def execute_query(query_name, payment_transaction) query = query(query_name) begin request = query.create_request payment_transaction response = make_request request query.process_response payment_transaction, response rescue Exception => error handle_exception error, payment_transaction, response return end handle_query_result payment_transaction, response response end |
#make_request(request) ⇒ Response
Make request to the PaynetEasy gateway
132 133 134 |
# File 'lib/paynet_easy/paynet_easy_api/payment_processor.rb', line 132 def make_request(request) gateway_client.make_request request end |
#process_customer_return(callback_response, payment_transaction) ⇒ CallbackResponse
Executes payment gateway processor for customer return from payment form or 3D-auth
85 86 87 88 |
# File 'lib/paynet_easy/paynet_easy_api/payment_processor.rb', line 85 def process_customer_return(callback_response, payment_transaction) callback_response.type = 'customer_return' process_paynet_easy_callback callback_response, payment_transaction end |
#process_paynet_easy_callback(callback_response, payment_transaction) ⇒ CallbackResponse
Executes payment gateway processor for PaynetEasy payment callback
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/paynet_easy/paynet_easy_api/payment_processor.rb', line 96 def process_paynet_easy_callback(callback_response, payment_transaction) begin callback(callback_response.type).process_callback(payment_transaction, callback_response) rescue Exception => error handle_exception error, payment_transaction, callback_response return end handle_query_result payment_transaction, callback_response callback_response end |
#query(api_query_name) ⇒ Prototype::Query
Create API query object by API query method
114 115 116 |
# File 'lib/paynet_easy/paynet_easy_api/payment_processor.rb', line 114 def query(api_query_name) query_factory.query api_query_name end |
#remove_handler(handler_name) ⇒ Object
Remove handler for processing action
157 158 159 160 161 |
# File 'lib/paynet_easy/paynet_easy_api/payment_processor.rb', line 157 def remove_handler(handler_name) check_handler_name handler_name @handlers.delete handler_name end |
#remove_handlers ⇒ Object
Remove all handlers
164 165 166 |
# File 'lib/paynet_easy/paynet_easy_api/payment_processor.rb', line 164 def remove_handlers @handlers = {} end |
#set_handler(handler_name, &handler_callback) ⇒ Object
Set handler callback for processing action.
140 141 142 143 144 |
# File 'lib/paynet_easy/paynet_easy_api/payment_processor.rb', line 140 def set_handler(handler_name, &handler_callback) check_handler_name handler_name @handlers[handler_name] = handler_callback end |
#set_handlers(handlers = {}) ⇒ Object
Set handlers. Handlers array must follow new format: => <handlerCallback>:Proc
150 151 152 |
# File 'lib/paynet_easy/paynet_easy_api/payment_processor.rb', line 150 def set_handlers(handlers = {}) handlers.each {|handler_name, handler_callback| set_handler handler_name, &handler_callback} end |