Class: EwayRapid::RapidClient
- Inherits:
-
Object
- Object
- EwayRapid::RapidClient
- Defined in:
- lib/eway_rapid/rapid_client.rb
Overview
This class abstracts the Rapid API 3.1 functions so that it can be consumed by Ruby applications
Class Method Summary collapse
-
.user_display_message(code, language = 'en') ⇒ String
Translate an error code to a user friendly message.
Instance Method Summary collapse
-
#cancel(refund) ⇒ RefundResponse
Cancel a non-captured transaction (an authorisation).
-
#create_customer(payment_method, customer) ⇒ CreateCustomerResponse
Creates a token customer to store card details in the secure eWAY Vault for charging later.
-
#create_transaction(payment_method, transaction) ⇒ CreateTransactionResponse
Creates a transaction either using an authorisation, the responsive shared page, transparent redirect, or direct as the source of funds.
-
#get_errors ⇒ Object
Returns all errors related to the query request of this client.
-
#get_valid? ⇒ Boolean
Gets the valid status of this Rapid client.
-
#initialize(api_key, password, rapid_endpoint) ⇒ RapidClient
constructor
A new instance of RapidClient.
-
#query_customer(token_customer_id) ⇒ QueryCustomerResponse
Returns the details of a Token Customer.
-
#query_transaction_by_access_code(access_code) ⇒ QueryTransactionResponse
Gets transaction details given an access code.
-
#query_transaction_by_filter(filter) ⇒ QueryTransactionResponse
Query a transaction by one of four properties transaction id, access code, invoice number, invoice reference.
-
#query_transaction_by_id(transaction_id) ⇒ QueryTransactionResponse
Gets transaction details given an eWAY Transaction ID.
-
#refund(refund) ⇒ RefundResponse
Refunds all or part of a transaction.
-
#set_credentials(api_key, password) ⇒ Object
Changes the API Key and Password the Client is configured to use.
-
#settlement_search(search_request) ⇒ SettlementSearchResponse
Performs a search of settlements.
-
#update_customer(payment_method, customer) ⇒ CreateCustomerResponse
Updates an existing token customer for the merchant in their eWAY account.
Constructor Details
#initialize(api_key, password, rapid_endpoint) ⇒ RapidClient
Returns a new instance of RapidClient.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/eway_rapid/rapid_client.rb', line 12 def initialize(api_key, password, rapid_endpoint) @logger = RapidLogger.logger @logger.info "Initiate client with end point: #{rapid_endpoint}" if @logger @api_key = api_key @password = password @rapid_endpoint = rapid_endpoint validate_api_param end |
Class Method Details
.user_display_message(code, language = 'en') ⇒ String
Translate an error code to a user friendly message
301 302 303 |
# File 'lib/eway_rapid/rapid_client.rb', line 301 def self.(code, language = 'en') find_error_code(code, language.downcase) end |
Instance Method Details
#cancel(refund) ⇒ RefundResponse
Cancel a non-captured transaction (an authorisation)
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/eway_rapid/rapid_client.rb', line 159 def cancel(refund) unless @is_valid return make_response_with_exception(Exceptions::APIKeyInvalidException.new('API key, password or Rapid endpoint missing or invalid'), RefundResponse) end begin url = @web_url + Constants::CANCEL_AUTHORISATION_METHOD request = Message::RefundProcess::CancelAuthorisationMsgProcess.create_request(refund) response = Message::RefundProcess::CancelAuthorisationMsgProcess.send_request(url, @api_key, @password, request) Message::RefundProcess::CancelAuthorisationMsgProcess.make_result(response) rescue => e @logger.error(e.to_s) if @logger make_response_with_exception(e, RefundResponse) end end |
#create_customer(payment_method, customer) ⇒ CreateCustomerResponse
Creates a token customer to store card details in the secure eWAY Vault for charging later
#create_transaction(payment_method, transaction) ⇒ CreateTransactionResponse
Creates a transaction either using an authorisation, the responsive shared page, transparent redirect, or direct as the source of funds
#get_errors ⇒ Object
Returns all errors related to the query request of this client
315 316 317 |
# File 'lib/eway_rapid/rapid_client.rb', line 315 def get_errors @list_error || [] end |
#get_valid? ⇒ Boolean
Gets the valid status of this Rapid client
308 309 310 |
# File 'lib/eway_rapid/rapid_client.rb', line 308 def get_valid? @is_valid end |
#query_customer(token_customer_id) ⇒ QueryCustomerResponse
Returns the details of a Token Customer. This includes the masked card information for displaying in a UI
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/eway_rapid/rapid_client.rb', line 256 def query_customer(token_customer_id) @logger.debug('Query customer with id:' + token_customer_id.to_s) if @logger unless @is_valid return make_response_with_exception(Exceptions::APIKeyInvalidException.new('API key, password or Rapid endpoint missing or invalid'), QueryCustomerResponse) end begin url = @web_url + Constants::DIRECT_CUSTOMER_SEARCH_METHOD + Constants::JSON_SUFFIX url = URI.encode(url) request = Message::CustomerProcess::QueryCustomerMsgProcess.create_request(token_customer_id.to_s) response = Message::CustomerProcess::QueryCustomerMsgProcess.send_request(url, @api_key, @password, request) Message::CustomerProcess::QueryCustomerMsgProcess.make_result(response) rescue => e @logger.error(e.to_s) if @logger make_response_with_exception(e, QueryCustomerResponse) end end |
#query_transaction_by_access_code(access_code) ⇒ QueryTransactionResponse
Gets transaction details given an access code
105 106 107 |
# File 'lib/eway_rapid/rapid_client.rb', line 105 def query_transaction_by_access_code(access_code) query_transaction_with_path(access_code, Constants::TRANSACTION_METHOD) end |
#query_transaction_by_filter(filter) ⇒ QueryTransactionResponse
Query a transaction by one of four properties transaction id, access code, invoice number, invoice reference
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/eway_rapid/rapid_client.rb', line 114 def query_transaction_by_filter(filter) index_of_value = filter.calculate_index_of_value if index_of_value.nil? return make_response_with_exception(Exceptions::APIKeyInvalidException.new('Invalid transaction filter'), QueryTransactionResponse) end case index_of_value when Enums::TransactionFilter::TRANSACTION_ID_INDEX query_transaction_by_id(filter.transaction_id.to_s) when Enums::TransactionFilter::ACCESS_CODE_INDEX query_transaction_by_access_code(filter.access_code) when Enums::TransactionFilter::INVOICE_NUMBER_INDEX query_transaction_with_path(filter.invoice_number, Constants::TRANSACTION_METHOD + '/' + Constants::TRANSACTION_QUERY_WITH_INVOICE_NUM_METHOD) when Enums::TransactionFilter::INVOICE_REFERENCE_INDEX query_transaction_with_path(filter.invoice_reference, Constants::TRANSACTION_METHOD + '/' + Constants::TRANSACTION_QUERY_WITH_INVOICE_REF_METHOD) else make_response_with_exception(Exceptions::APIKeyInvalidException.new('Invalid transaction filter'), QueryTransactionResponse) end end |
#query_transaction_by_id(transaction_id) ⇒ QueryTransactionResponse
Gets transaction details given an eWAY Transaction ID
97 98 99 |
# File 'lib/eway_rapid/rapid_client.rb', line 97 def query_transaction_by_id(transaction_id) query_transaction_by_access_code(transaction_id.to_s) end |
#refund(refund) ⇒ RefundResponse
Refunds all or part of a transaction
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/eway_rapid/rapid_client.rb', line 138 def refund(refund) unless @is_valid return make_response_with_exception(Exceptions::APIKeyInvalidException.new('API key, password or Rapid endpoint missing or invalid'), RefundResponse) end begin url = @web_url + Constants::TRANSACTION_METHOD request = Message::RefundProcess::RefundMsgProcess.create_request(refund) response = Message::RefundProcess::RefundMsgProcess.send_request(url, @api_key, @password, request) Message::RefundProcess::RefundMsgProcess.make_result(response) rescue => e @logger.error(e.to_s) if @logger make_response_with_exception(e, RefundResponse) end end |
#set_credentials(api_key, password) ⇒ Object
Changes the API Key and Password the Client is configured to use
27 28 29 30 31 32 |
# File 'lib/eway_rapid/rapid_client.rb', line 27 def set_credentials(api_key, password) @api_key = api_key @password = password validate_api_param end |
#settlement_search(search_request) ⇒ SettlementSearchResponse
Performs a search of settlements
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/eway_rapid/rapid_client.rb', line 278 def settlement_search(search_request) unless @is_valid return make_response_with_exception(Exceptions::APIKeyInvalidException.new('API key, password or Rapid endpoint missing or invalid'), QueryCustomerResponse) end begin request = Message::TransactionProcess::SettlementSearchMsgProcess.create_request(search_request) url = @web_url + Constants::SETTLEMENT_SEARCH_METHOD + request response = Message::TransactionProcess::SettlementSearchMsgProcess.send_request(url, @api_key, @password) Message::TransactionProcess::SettlementSearchMsgProcess.make_result(response) rescue => e @logger.error(e.to_s) if @logger make_response_with_exception(e, SettlementSearchResponse) end end |
#update_customer(payment_method, customer) ⇒ CreateCustomerResponse
Updates an existing token customer for the merchant in their eWAY account.