Class: EVSS::PPIU::Service
- Inherits:
-
Service
- Object
- Common::Client::Base
- Service
- EVSS::PPIU::Service
- Defined in:
- lib/evss/ppiu/service.rb
Overview
Proxy Service for EVSS’s PPIU endpoints. For the foreseeable future, EVSS will only support the ‘CNP’ (Compensation and Pension) payment type and is therefore statically assigned in the request payloads.
Constant Summary
Constants inherited from Service
Instance Attribute Summary
Attributes inherited from Service
Instance Method Summary collapse
-
#get_payment_information ⇒ EVSS::PPIU::PaymentInformationResponse
GETs a user’s payment information.
- #handle_error(error) ⇒ Object private
-
#initialize(*args) ⇒ Service
constructor
A new instance of Service.
- #request_body(pay_info) ⇒ Object private
- #right_error_type?(error) ⇒ Boolean private
- #save_sanitized_req_body(req_body) ⇒ Object private
-
#update_payment_information(pay_info) ⇒ EVSS::PPIU::PaymentInformationResponse
POSTs a user’s payment information to EVSS and updates their current information.
Methods inherited from Service
#headers, #perform, #save_error_details, service_is_up?, #with_monitoring_and_error_handling
Methods included from Common::Client::Concerns::Monitoring
#increment, #increment_failure, #increment_total, #with_monitoring
Methods inherited from Common::Client::Base
#config, configuration, #connection, #delete, #get, #perform, #post, #put, #raise_backend_exception, #raise_not_authenticated, #request, #sanitize_headers!, #service_name
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata
Constructor Details
#initialize(*args) ⇒ Service
Returns a new instance of Service.
18 19 20 21 22 |
# File 'lib/evss/ppiu/service.rb', line 18 def initialize(*args) super raise Common::Exceptions::Unauthorized unless PPIUPolicy.new(@user).access? end |
Instance Method Details
#get_payment_information ⇒ EVSS::PPIU::PaymentInformationResponse
GETs a user’s payment information
28 29 30 31 32 33 |
# File 'lib/evss/ppiu/service.rb', line 28 def get_payment_information with_monitoring_and_error_handling do raw_response = perform(:get, 'paymentInformation', paymentType: 'CNP') PaymentInformationResponse.new(raw_response.status, raw_response) end end |
#handle_error(error) ⇒ Object (private)
61 62 63 64 65 66 67 68 |
# File 'lib/evss/ppiu/service.rb', line 61 def handle_error(error) if right_error_type?(error) && error.body.is_a?(Hash) save_error_details(error) raise EVSS::PPIU::ServiceException.new(error.body, @user, @sanitized_req_body) else super(error) end end |
#request_body(pay_info) ⇒ Object (private)
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/evss/ppiu/service.rb', line 75 def request_body(pay_info) pay_info.delete('financial_institution_name') if pay_info['financial_institution_name'].blank? { 'requests' => [ { 'paymentType' => 'CNP', 'paymentAccount' => pay_info.as_json.transform_keys { |k| k.camelize(:lower) } } ] }.to_json end |
#right_error_type?(error) ⇒ Boolean (private)
70 71 72 73 |
# File 'lib/evss/ppiu/service.rb', line 70 def right_error_type?(error) (error.is_a?(Common::Client::Errors::ClientError) && error.status != 403) || error.is_a?(EVSS::ErrorMiddleware::EVSSError) end |
#save_sanitized_req_body(req_body) ⇒ Object (private)
52 53 54 55 56 57 58 59 |
# File 'lib/evss/ppiu/service.rb', line 52 def save_sanitized_req_body(req_body) req_body = JSON.parse(req_body) req_body['requests'].each do |request| request['paymentAccount']['accountNumber'] = '****' end @sanitized_req_body = req_body end |
#update_payment_information(pay_info) ⇒ EVSS::PPIU::PaymentInformationResponse
POSTs a user’s payment information to EVSS and updates their current information
40 41 42 43 44 45 46 47 48 |
# File 'lib/evss/ppiu/service.rb', line 40 def update_payment_information(pay_info) body = request_body(pay_info) save_sanitized_req_body(body) with_monitoring_and_error_handling do raw_response = perform(:post, 'paymentInformation', body, headers) PaymentInformationResponse.new(raw_response.status, raw_response) end end |