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.
-
#set_version(version) ⇒ Object
Sets the Rapid API version to use (e.g. 40).
-
#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 22 |
# 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 @version = 31 validate_api_param end |
Class Method Details
.user_display_message(code, language = 'en') ⇒ String
Translate an error code to a user friendly message
309 310 311 |
# File 'lib/eway_rapid/rapid_client.rb', line 309 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)
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/eway_rapid/rapid_client.rb', line 167 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, @version, 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
323 324 325 |
# File 'lib/eway_rapid/rapid_client.rb', line 323 def get_errors @list_error || [] end |
#get_valid? ⇒ Boolean
Gets the valid status of this Rapid client
316 317 318 |
# File 'lib/eway_rapid/rapid_client.rb', line 316 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
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/eway_rapid/rapid_client.rb', line 264 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, @version, 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
113 114 115 |
# File 'lib/eway_rapid/rapid_client.rb', line 113 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
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/eway_rapid/rapid_client.rb', line 122 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
105 106 107 |
# File 'lib/eway_rapid/rapid_client.rb', line 105 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
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/eway_rapid/rapid_client.rb', line 146 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, @version, 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
28 29 30 31 32 33 |
# File 'lib/eway_rapid/rapid_client.rb', line 28 def set_credentials(api_key, password) @api_key = api_key @password = password validate_api_param end |
#set_version(version) ⇒ Object
Sets the Rapid API version to use (e.g. 40)
38 39 40 |
# File 'lib/eway_rapid/rapid_client.rb', line 38 def set_version(version) @version = version end |
#settlement_search(search_request) ⇒ SettlementSearchResponse
Performs a search of settlements
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/eway_rapid/rapid_client.rb', line 286 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, @version) 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.