From f09eb83b3bee14716e693776a6cf318c6372ee7c Mon Sep 17 00:00:00 2001 From: John C Date: Wed, 23 Dec 2015 09:07:32 +1100 Subject: [PATCH] Initial commit --- .gitignore | 25 + .travis.yml | 11 + CHANGELOG.md | 7 + Gemfile | 2 + LICENSE.md | 21 + README.md | 96 ++++ Rakefile | 14 + eway_rapid.gemspec | 26 + lib/eway_rapid.rb | 78 +++ lib/eway_rapid/constants.rb | 126 +++++ .../entities/cancel_authorisation_request.rb | 9 + .../entities/cancel_authorisation_response.rb | 34 ++ .../entities/capture_payment_request.rb | 11 + .../entities/capture_payment_response.rb | 34 ++ .../entities/create_access_code_request.rb | 35 ++ .../entities/create_access_code_response.rb | 128 +++++ .../create_access_code_shared_request.rb | 53 +++ .../create_access_code_shared_response.rb | 40 ++ .../entities/create_customer_response.rb | 8 + .../direct_customer_search_request.rb | 9 + .../direct_customer_search_response.rb | 23 + .../entities/direct_payment_request.rb | 29 ++ .../entities/direct_payment_response.rb | 58 +++ .../entities/direct_refund_request.rb | 26 + .../entities/direct_refund_response.rb | 44 ++ .../entities/transaction_search_response.rb | 23 + lib/eway_rapid/exceptions.rb | 51 ++ .../convert/customer_to_internal_customer.rb | 70 +++ .../convert/direct_payment_to_trans_status.rb | 47 ++ .../convert/direct_refund_to_trans_status.rb | 33 ++ .../convert/internal_customer_to_customer.rb | 41 ++ .../convert/internal_trans_to_trans.rb | 62 +++ .../internal_transaction_to_address.rb | 27 ++ .../convert/internal_transaction_to_status.rb | 55 +++ .../convert/payment_to_payment_details.rb | 25 + .../request/refund_to_direct_refund_req.rb | 41 ++ .../request/transaction_to_capture_payment.rb | 28 ++ ...ansaction_to_create_access_code_request.rb | 58 +++ ...on_to_create_access_code_shared_request.rb | 54 +++ .../request/transaction_to_direct_payment.rb | 45 ++ .../access_code_shared_to_create_cust.rb | 23 + .../access_code_shared_to_create_trans.rb | 28 ++ .../response/access_code_to_create_cust.rb | 24 + .../response/access_code_to_create_trans.rb | 27 ++ .../cancel_authorisation_to_refund.rb | 37 ++ .../capture_payment_to_create_transaction.rb | 43 ++ .../direct_customer_to_query_customer.rb | 55 +++ .../response/direct_payment_to_create_cust.rb | 23 + .../direct_payment_to_create_trans.rb | 32 ++ .../direct_refund_to_refund_response.rb | 28 ++ .../convert/response/search_to_query_trans.rb | 30 ++ .../convert/shipping_details_to_address.rb | 35 ++ .../convert/transaction_shipping_address.rb | 37 ++ .../convert/transaction_to_arr_line_item.rb | 14 + .../convert/transaction_to_arr_option.rb | 25 + .../message/convert/transaction_to_payment.rb | 29 ++ .../verification_to_verification_result.rb | 33 ++ .../message/process/customer_process.rb | 255 ++++++++++ .../message/process/refund_process.rb | 76 +++ .../message/process/rest_process.rb | 87 ++++ .../message/process/transaction_process.rb | 139 ++++++ lib/eway_rapid/models/enums.rb | 126 +++++ lib/eway_rapid/models/internal_models.rb | 431 +++++++++++++++++ lib/eway_rapid/models/models.rb | 334 +++++++++++++ .../output/create_transaction_response.rb | 24 + .../output/query_customer_response.rb | 25 + .../output/query_transaction_response.rb | 16 + lib/eway_rapid/output/refund_response.rb | 9 + lib/eway_rapid/output/response_output.rb | 14 + lib/eway_rapid/rapid_client.rb | 444 ++++++++++++++++++ lib/eway_rapid/rapid_logger.rb | 40 ++ .../resources/err_code_resource_en.yml | 237 ++++++++++ lib/eway_rapid/resources/rapid-api.yml | 4 + lib/eway_rapid/version.rb | 3 + .../integration/customer/customer_test.rb | 148 ++++++ .../integration/integration_test.rb | 12 + .../authorization_transaction_test.rb | 45 ++ .../transaction/cancel_transaction_test.rb | 51 ++ .../transaction/direct_transaction_test.rb | 46 ++ .../transaction/query_transaction_test.rb | 40 ++ .../transaction/refund_transaction_test.rb | 97 ++++ .../responsive_transaction_test.rb | 43 ++ .../transaction/transaction_filter_test.rb | 117 +++++ .../transparent_transaction_test.rb | 33 ++ .../customer_to_internal_converter_test.rb | 53 +++ ..._payment_to_trans_status_converter_test.rb | 55 +++ ...t_refund_to_trans_status_converter_test.rb | 35 ++ ...nal_customer_to_customer_converter_test.rb | 25 + .../internal_trans_to_trans_converter_test.rb | 27 ++ ...l_transaction_to_address_converter_test.rb | 24 + ...al_transaction_to_status_converter_test.rb | 32 ++ ...ayment_to_payment_detail_converter_test.rb | 29 ++ ...und_to_direct_refund_req_converter_test.rb | 45 ++ ...action_to_direct_payment_converter_test.rb | 35 ++ ...de_shared_to_create_cust_converter_test.rb | 69 +++ ...e_shared_to_create_trans_converter_test.rb | 33 ++ ...cess_code_to_create_cust_converter_test.rb | 26 + ...ess_code_to_create_trans_converter_test.rb | 26 + ...stomer_to_query_customer_converter_test.rb | 34 ++ ...t_payment_to_create_cust_converter_test.rb | 27 ++ ..._payment_to_create_trans_converter_test.rb | 28 ++ ...efund_to_refund_response_converter_test.rb | 27 ++ .../search_to_query_trans_converter_test.rb | 25 + ...pping_details_to_address_converter_test.rb | 39 ++ ...saction_to_arr_line_item_converter_test.rb | 31 ++ .../transaction_to_payment_converter_test.rb | 29 ++ ...tion_to_shipping_address_converter_test.rb | 37 ++ ...n_to_verification_result_converter_test.rb | 29 ++ .../object/create/object_creator.rb | 152 ++++++ test/eway_rapid/rapid_client_test.rb | 112 +++++ test/input_model_factory.rb | 112 +++++ test/test_base.rb | 12 + 112 files changed, 6234 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 CHANGELOG.md create mode 100644 Gemfile create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 Rakefile create mode 100644 eway_rapid.gemspec create mode 100644 lib/eway_rapid.rb create mode 100644 lib/eway_rapid/constants.rb create mode 100644 lib/eway_rapid/entities/cancel_authorisation_request.rb create mode 100644 lib/eway_rapid/entities/cancel_authorisation_response.rb create mode 100644 lib/eway_rapid/entities/capture_payment_request.rb create mode 100644 lib/eway_rapid/entities/capture_payment_response.rb create mode 100644 lib/eway_rapid/entities/create_access_code_request.rb create mode 100644 lib/eway_rapid/entities/create_access_code_response.rb create mode 100644 lib/eway_rapid/entities/create_access_code_shared_request.rb create mode 100644 lib/eway_rapid/entities/create_access_code_shared_response.rb create mode 100644 lib/eway_rapid/entities/create_customer_response.rb create mode 100644 lib/eway_rapid/entities/direct_customer_search_request.rb create mode 100644 lib/eway_rapid/entities/direct_customer_search_response.rb create mode 100644 lib/eway_rapid/entities/direct_payment_request.rb create mode 100644 lib/eway_rapid/entities/direct_payment_response.rb create mode 100644 lib/eway_rapid/entities/direct_refund_request.rb create mode 100644 lib/eway_rapid/entities/direct_refund_response.rb create mode 100644 lib/eway_rapid/entities/transaction_search_response.rb create mode 100644 lib/eway_rapid/exceptions.rb create mode 100644 lib/eway_rapid/message/convert/customer_to_internal_customer.rb create mode 100644 lib/eway_rapid/message/convert/direct_payment_to_trans_status.rb create mode 100644 lib/eway_rapid/message/convert/direct_refund_to_trans_status.rb create mode 100644 lib/eway_rapid/message/convert/internal_customer_to_customer.rb create mode 100644 lib/eway_rapid/message/convert/internal_trans_to_trans.rb create mode 100644 lib/eway_rapid/message/convert/internal_transaction_to_address.rb create mode 100644 lib/eway_rapid/message/convert/internal_transaction_to_status.rb create mode 100644 lib/eway_rapid/message/convert/payment_to_payment_details.rb create mode 100644 lib/eway_rapid/message/convert/request/refund_to_direct_refund_req.rb create mode 100644 lib/eway_rapid/message/convert/request/transaction_to_capture_payment.rb create mode 100644 lib/eway_rapid/message/convert/request/transaction_to_create_access_code_request.rb create mode 100644 lib/eway_rapid/message/convert/request/transaction_to_create_access_code_shared_request.rb create mode 100644 lib/eway_rapid/message/convert/request/transaction_to_direct_payment.rb create mode 100644 lib/eway_rapid/message/convert/response/access_code_shared_to_create_cust.rb create mode 100644 lib/eway_rapid/message/convert/response/access_code_shared_to_create_trans.rb create mode 100644 lib/eway_rapid/message/convert/response/access_code_to_create_cust.rb create mode 100644 lib/eway_rapid/message/convert/response/access_code_to_create_trans.rb create mode 100644 lib/eway_rapid/message/convert/response/cancel_authorisation_to_refund.rb create mode 100644 lib/eway_rapid/message/convert/response/capture_payment_to_create_transaction.rb create mode 100644 lib/eway_rapid/message/convert/response/direct_customer_to_query_customer.rb create mode 100644 lib/eway_rapid/message/convert/response/direct_payment_to_create_cust.rb create mode 100644 lib/eway_rapid/message/convert/response/direct_payment_to_create_trans.rb create mode 100644 lib/eway_rapid/message/convert/response/direct_refund_to_refund_response.rb create mode 100644 lib/eway_rapid/message/convert/response/search_to_query_trans.rb create mode 100644 lib/eway_rapid/message/convert/shipping_details_to_address.rb create mode 100644 lib/eway_rapid/message/convert/transaction_shipping_address.rb create mode 100644 lib/eway_rapid/message/convert/transaction_to_arr_line_item.rb create mode 100644 lib/eway_rapid/message/convert/transaction_to_arr_option.rb create mode 100644 lib/eway_rapid/message/convert/transaction_to_payment.rb create mode 100644 lib/eway_rapid/message/convert/verification_to_verification_result.rb create mode 100644 lib/eway_rapid/message/process/customer_process.rb create mode 100644 lib/eway_rapid/message/process/refund_process.rb create mode 100644 lib/eway_rapid/message/process/rest_process.rb create mode 100644 lib/eway_rapid/message/process/transaction_process.rb create mode 100644 lib/eway_rapid/models/enums.rb create mode 100644 lib/eway_rapid/models/internal_models.rb create mode 100644 lib/eway_rapid/models/models.rb create mode 100644 lib/eway_rapid/output/create_transaction_response.rb create mode 100644 lib/eway_rapid/output/query_customer_response.rb create mode 100644 lib/eway_rapid/output/query_transaction_response.rb create mode 100644 lib/eway_rapid/output/refund_response.rb create mode 100644 lib/eway_rapid/output/response_output.rb create mode 100644 lib/eway_rapid/rapid_client.rb create mode 100644 lib/eway_rapid/rapid_logger.rb create mode 100644 lib/eway_rapid/resources/err_code_resource_en.yml create mode 100644 lib/eway_rapid/resources/rapid-api.yml create mode 100644 lib/eway_rapid/version.rb create mode 100644 test/eway_rapid/integration/customer/customer_test.rb create mode 100644 test/eway_rapid/integration/integration_test.rb create mode 100644 test/eway_rapid/integration/transaction/authorization_transaction_test.rb create mode 100644 test/eway_rapid/integration/transaction/cancel_transaction_test.rb create mode 100644 test/eway_rapid/integration/transaction/direct_transaction_test.rb create mode 100644 test/eway_rapid/integration/transaction/query_transaction_test.rb create mode 100644 test/eway_rapid/integration/transaction/refund_transaction_test.rb create mode 100644 test/eway_rapid/integration/transaction/responsive_transaction_test.rb create mode 100644 test/eway_rapid/integration/transaction/transaction_filter_test.rb create mode 100644 test/eway_rapid/integration/transaction/transparent_transaction_test.rb create mode 100644 test/eway_rapid/message/convert/customer_to_internal_converter_test.rb create mode 100644 test/eway_rapid/message/convert/direct_payment_to_trans_status_converter_test.rb create mode 100644 test/eway_rapid/message/convert/direct_refund_to_trans_status_converter_test.rb create mode 100644 test/eway_rapid/message/convert/internal_customer_to_customer_converter_test.rb create mode 100644 test/eway_rapid/message/convert/internal_trans_to_trans_converter_test.rb create mode 100644 test/eway_rapid/message/convert/internal_transaction_to_address_converter_test.rb create mode 100644 test/eway_rapid/message/convert/internal_transaction_to_status_converter_test.rb create mode 100644 test/eway_rapid/message/convert/payment_to_payment_detail_converter_test.rb create mode 100644 test/eway_rapid/message/convert/request/refund_to_direct_refund_req_converter_test.rb create mode 100644 test/eway_rapid/message/convert/request/transaction_to_direct_payment_converter_test.rb create mode 100644 test/eway_rapid/message/convert/response/access_code_shared_to_create_cust_converter_test.rb create mode 100644 test/eway_rapid/message/convert/response/access_code_shared_to_create_trans_converter_test.rb create mode 100644 test/eway_rapid/message/convert/response/access_code_to_create_cust_converter_test.rb create mode 100644 test/eway_rapid/message/convert/response/access_code_to_create_trans_converter_test.rb create mode 100644 test/eway_rapid/message/convert/response/direct_customer_to_query_customer_converter_test.rb create mode 100644 test/eway_rapid/message/convert/response/direct_payment_to_create_cust_converter_test.rb create mode 100644 test/eway_rapid/message/convert/response/direct_payment_to_create_trans_converter_test.rb create mode 100644 test/eway_rapid/message/convert/response/direct_refund_to_refund_response_converter_test.rb create mode 100644 test/eway_rapid/message/convert/response/search_to_query_trans_converter_test.rb create mode 100644 test/eway_rapid/message/convert/shipping_details_to_address_converter_test.rb create mode 100644 test/eway_rapid/message/convert/transaction_to_arr_line_item_converter_test.rb create mode 100644 test/eway_rapid/message/convert/transaction_to_payment_converter_test.rb create mode 100644 test/eway_rapid/message/convert/transaction_to_shipping_address_converter_test.rb create mode 100644 test/eway_rapid/message/convert/verification_to_verification_result_converter_test.rb create mode 100644 test/eway_rapid/object/create/object_creator.rb create mode 100644 test/eway_rapid/rapid_client_test.rb create mode 100644 test/input_model_factory.rb create mode 100644 test/test_base.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..28609e5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +*.gem +*.rbc +/.config +coverage +/InstalledFiles +/pkg/ +/spec/reports/ +/spec/examples.txt +/test/tmp/ +/test/version_tmp/ +/tmp/ + +/.yardoc +/_yardoc/ +/doc/ +/rdoc/ + +/.bundle/ +/vendor/bundle +/lib/bundler/man/ + +/Gemfile.lock +.idea +.ruby-version +.ruby-gemset \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8009bd0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: ruby +rvm: + - 1.9.3 + - 2.0.0 + - 2.1 + - 2.2 + - jruby-19mode + +before_install: gem install bundler -v 1.10.6 + +sudo: false \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..00706e2 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +All notable changes will be documented in this file + +## 1.0.0 + + - First release diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..d926697 --- /dev/null +++ b/Gemfile @@ -0,0 +1,2 @@ +source 'https://rubygems.org' +gemspec \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..d370f1b --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# The MIT License (MIT) + +Copyright (c) 2015 Web Active Corporation Pty Ltd + +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in +> all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +> THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..7c9464f --- /dev/null +++ b/README.md @@ -0,0 +1,96 @@ +# eWAY Rapid Ruby Library + +[![Latest Version on RubyGems][ico-version]][link-rubygems] +[![Software License][ico-license]](LICENSE.md) +[![Build Status][ico-travis]][link-travis] + +A Ruby Gem to integrate with eWAY's Rapid Payment API. + +Sign up with eWAY at: + - Australia: https://www.eway.com.au/ + - New Zealand: https://eway.io/nz/ + - UK: https://eway.io/uk/ + - Hong Kong: https://eway.io/hk/ + - Malaysia: https://eway.io/my/ + - Singapore: https://eway.io/sg/ + +For testing, get a free eWAY Partner account: https://www.eway.com.au/developers + +## Installation + +The eWAY Ruby Gem requires Ruby 1.9.3 or better, it also requires the rest-client and json gems. + +Add this line to your application's Gemfile: + +```ruby +gem 'eway_rapid' +``` + +And then execute: + +``` +$ bundle +``` + +Or install it yourself as: + +``` +$ gem install eway_rapid +``` + +## Usage + +See the [eWAY Rapid API Reference](https://eway.io/api-v3/?ruby) for usage details. + +A simple Direct payment: + +```ruby +require 'eway_rapid' + +api_key = 'Rapid API Key' +password = 'Rapid API Password' +endpoint = 'sandbox' + +client = RapidSDK::RapidClient.new(api_key, password, endpoint) + +transaction = EwayRapid::Models::Transaction.new +transaction.customer = EwayRapid::Models::Customer.new + +card_details = EwayRapid::Models::CardDetails.new +card_details.name = 'Ruby Dev' +card_details.number = '4444333322221111' +card_details.expiry_month = '05' +card_details.expiry_year = '22' +card_details.cvn = '123' +transaction.customer.card_details = card_details + +payment_details = EwayRapid::Models::PaymentDetails.new +payment_details.total_amount = 1000 +transaction.payment_details = payment_details +transaction.transaction_type = EwayRapid::Enums::TransactionType::PURCHASE + +response = client.create_transaction(EwayRapid::Enums::PaymentMethod::DIRECT, basic_direct) + +if response.transaction_status.status? + puts "Success! ID: #{response.transaction_status.transaction_id.to_s}" +end +``` + +## Testing + +All tests can be run by first installing all dependencies with `bundle install` then running `bundle exec rake` + +## Change log + +Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. + +## License + +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. + +[ico-version]: https://img.shields.io/gem/v/eway_rapid.svg?style=flat-square +[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square +[ico-travis]: https://img.shields.io/travis/eWAYPayment/eway-rapid-ruby/master.svg?style=flat-square + +[link-rubygems]: https://rubygems.org/gems/eway_rapid +[link-travis]: https://travis-ci.org/eWAYPayment/eway-rapid-ruby diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..166853a --- /dev/null +++ b/Rakefile @@ -0,0 +1,14 @@ +require 'bundler/gem_tasks' +require 'rake/testtask' + +task :default => [:test] + +Rake::TestTask.new do |t| + t.libs << 'test' + t.test_files = FileList[File.join('test', '**', '*test.rb')] + t.verbose = true +end + +task :gem do + exec('gem build eway_rapid.gemspec') +end \ No newline at end of file diff --git a/eway_rapid.gemspec b/eway_rapid.gemspec new file mode 100644 index 0000000..804c135 --- /dev/null +++ b/eway_rapid.gemspec @@ -0,0 +1,26 @@ +# coding: utf-8 +lib = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'eway_rapid/version' + +Gem::Specification.new do |spec| + spec.name = 'eway_rapid' + spec.version = EwayRapid::VERSION + spec.required_ruby_version = '>= 1.9.3' + spec.author = ['eWAY'] + spec.summary = 'Ruby gem for eWAY\'s Rapid API' + spec.description = 'Easy online payments with eWAY and the eWAY Rapid Ruby gem.' + spec.homepage = 'https://www.eway.com.au' + spec.license = 'MIT' + + spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + spec.require_paths = ['lib'] + + spec.add_dependency 'rest-client', '~> 1.8' + spec.add_dependency 'json', '~> 1.8.3' + + spec.add_development_dependency 'bundler', '~> 1.10' + spec.add_development_dependency 'rake', '~> 10.0' + spec.add_development_dependency 'test-unit' + spec.add_development_dependency 'simplecov' +end \ No newline at end of file diff --git a/lib/eway_rapid.rb b/lib/eway_rapid.rb new file mode 100644 index 0000000..a370a20 --- /dev/null +++ b/lib/eway_rapid.rb @@ -0,0 +1,78 @@ +# eWAY Rapid API Ruby Module +require 'json' +require 'rest-client' +require 'yaml' + +require File.join(File.dirname(__FILE__), 'eway_rapid', 'version') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'constants') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'exceptions') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'rapid_logger') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'rapid_client') + +require File.join(File.dirname(__FILE__), 'eway_rapid', 'models', 'enums') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'models', 'models') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'models', 'internal_models') + +require File.join(File.dirname(__FILE__), 'eway_rapid', 'output', 'response_output') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'output', 'create_transaction_response') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'output', 'query_customer_response') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'output', 'query_transaction_response') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'output', 'refund_response') + +require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'cancel_authorisation_request') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'cancel_authorisation_response') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'capture_payment_request') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'capture_payment_response') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'create_access_code_request') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'create_access_code_response') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'create_access_code_shared_request') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'create_access_code_shared_response') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'create_customer_response') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'direct_customer_search_request') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'direct_customer_search_response') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'direct_payment_request') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'direct_payment_response') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'direct_refund_request') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'direct_refund_response') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'entities', 'transaction_search_response') + +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'customer_to_internal_customer') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'direct_payment_to_trans_status') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'direct_refund_to_trans_status') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'internal_customer_to_customer') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'internal_trans_to_trans') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'internal_transaction_to_address') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'internal_transaction_to_status') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'payment_to_payment_details') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'shipping_details_to_address') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'transaction_shipping_address') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'transaction_to_arr_line_item') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'transaction_to_arr_option') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'transaction_to_payment') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'verification_to_verification_result') + +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'request', 'refund_to_direct_refund_req') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'request', 'transaction_to_capture_payment') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'request', 'transaction_to_create_access_code_request') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'request', 'transaction_to_create_access_code_shared_request') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'request', 'transaction_to_direct_payment') + +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'response', 'access_code_shared_to_create_cust') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'response', 'access_code_shared_to_create_trans') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'response', 'access_code_to_create_cust') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'response', 'access_code_to_create_trans') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'response', 'cancel_authorisation_to_refund') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'response', 'capture_payment_to_create_transaction') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'response', 'direct_customer_to_query_customer') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'response', 'direct_payment_to_create_cust') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'response', 'direct_payment_to_create_trans') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'response', 'direct_refund_to_refund_response') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'convert', 'response', 'search_to_query_trans') + +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'process', 'rest_process') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'process', 'customer_process') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'process', 'refund_process') +require File.join(File.dirname(__FILE__), 'eway_rapid', 'message', 'process', 'transaction_process') + +module EwayRapid +end diff --git a/lib/eway_rapid/constants.rb b/lib/eway_rapid/constants.rb new file mode 100644 index 0000000..3f4531e --- /dev/null +++ b/lib/eway_rapid/constants.rb @@ -0,0 +1,126 @@ +module EwayRapid + module Constants + EMAIL = 'Email' + PHONE = 'Phone' + VALUE = 'Value' + TOTAL_AMOUNT = 'TotalAmount' + INVOICE_NUMBER = 'InvoiceNumber' + INVOICE_DESCRIPTION = 'InvoiceDescription' + INVOICE_REFERENCE = 'InvoiceReference' + CURRENCY_CODE = 'CurrencyCode' + ORIGINAL_TRANSACTION_ID = 'TransactionID' + FIRST_NAME = 'FirstName' + LAST_NAME = 'LastName' + STREET1 = 'Street1' + STREET2 = 'Street2' + CITY = 'City' + STATE = 'State' + COUNTRY = 'Country' + POSTAL_CODE = 'PostalCode' + FAX = 'Fax' + SHIPPING_METHOD = 'ShippingMethod' + CVN = 'CVN' + MOBILE = 'Mobile' + ADDRESS = 'Address' + SKU = 'SKU' + DESCRIPTION = 'Description' + QUANTITY = 'Quantity' + UNIT_COST = 'UnitCost' + TAX = 'Tax' + TOTAL = 'Total' + TOKEN_CUSTOMER_ID = 'TokenCustomerID' + REFERENCE = 'Reference' + TITLE = 'Title' + COMPANY_NAME = 'CompanyName' + JOB_DESCRIPTION = 'JobDescription' + COMMENTS = 'Comments' + URL = 'Url' + CARD_NUMBER = 'CardNumber' + CARD_START_MONTH = 'CardStartMonth' + CARD_START_YEAR = 'CardStartYear' + CARD_ISSUE_NUMBER = 'CardIssueNumber' + CARD_NAME = 'CardName' + CARD_EXPIRY_MONTH = 'CardExpiryMonth' + CARD_EXPIRY_YEAR = 'CardExpiryYear' + IS_ACTIVE = 'IsActive' + CARD_DETAILS = 'CardDetails' + CUSTOMER_DEVICE_IP = 'CustomerIP' + NAME = 'Name' + NUMBER = 'Number' + EXPIRY_MONTH = 'ExpiryMonth' + EXPIRY_YEAR = 'ExpiryYear' + START_MONTH = 'StartMonth' + START_YEAR = 'StartYear' + ISSUE_NUMBER = 'IssueNumber' + CUSTOMER_NOTE = 'CustomerNote' + AUTHORISATION_CODE = 'AuthorisationCode' + RESPONSE_CODE = 'ResponseCode' + RESPONSE_MESSAGE = 'ResponseMessage' + TRANSACTION_ID = 'TransactionID' + TRANSACTION_STATUS = 'TransactionStatus' + BEAGLE_SCORE = 'BeagleScore' + OPTIONS = 'Options' + VERIFICATION = 'Verification' + CUSTOMER = 'Customer' + SHIPPING_ADDRESS = 'ShippingAddress' + BEAGLE_VERIFICATION = 'BeagleVerification' + ERRORS = 'errors' + CUSTOMERS = 'Customers' + PAYMENT = 'Payment' + REQUEST_TRANSACTION_ID = 'TransactionId' + ITEMS = 'Items' + REDIRECT_URL = 'RedirectUrl' + METHOD = 'Method' + DEVICE_ID = 'DeviceID' + CHECKOUT_PAYMENT = 'CheckoutPayment' + CHECKOUT_URL = 'CheckoutUrl' + TRANSACTION_TYPE = 'TransactionType' + PARTNER_ID = 'PartnerID' + TRANSACTIONS = 'Transactions' + ERRORS_CAPITALIZED = 'Errors' + REFUND = 'Refund' + LINE_ITEMS = 'LineItems' + TRANSACTION_CAPTURED = 'TransactionCaptured' + FRAUD_ACTION = 'FraudAction' + ACCESS_CODE = 'AccessCode' + FORM_ACTION_URL = 'FormActionURL' + SHARED_PAYMENT_URL = 'SharedPaymentUrl' + COMPLETE_CHECKOUT_URL = 'CompleteCheckoutURL' + CANCEL_URL = 'CancelUrl' + LOGO_URL = 'LogoUrl' + HEADER_TEXT = 'HeaderText' + LANGUAGE = 'Language' + CUSTOMER_READ_ONLY = 'CustomerReadOnly' + CUSTOMER_VIEW = 'CustomView' + VERIFY_CUSTOMER_PHONE = 'VerifyCustomerPhone' + VERIFY_CUSTOMER_EMAIL = 'VerifyCustomerEmail' + JSON_SUFFIX = '.json' + LIBRARY_NOT_HAVE_ENDPOINT_ERROR_CODE = 'S9990' + API_KEY_INVALID_ERROR_CODE = 'S9991' + COMMUNICATION_FAILURE_ERROR_CODE = 'S9992' + AUTHENTICATION_FAILURE_ERROR_CODE = 'S9993' + INTERNAL_RAPID_API_ERROR_CODE = 'S9995' + INTERNAL_RAPID_SERVER_ERROR_CODE = 'S9996' + ERROR_CODE_RESOURCE_EN = 'err_code_resource_en.yml' + RAPID_API_RESOURCE = 'rapid-api.yml' + RAPID_SDK_USER_AGENT_PARAM = 'rapid.sdk.user.agent' + GLOBAL_RAPID_PRODUCTION_REST_URL_PARAM = 'global.rapid.rest.production.url' + GLOBAL_RAPID_SANDBOX_REST_URL_PARAM = 'global.rapid.rest.sandbox.url' + RAPID_ENDPOINT_SANDBOX = 'Sandbox' + RAPID_ENDPOINT_PRODUCTION = 'Production' + DIRECT_PAYMENT_METHOD_NAME = 'DirectPayment' + RESPONSIVE_SHARED_METHOD_NAME = 'CreateAccessCodeShared' + TRANSPARENT_REDIRECT_METHOD_NAME = 'CreateAccessCode' + DIRECT_REFUND_METHOD_NAME = 'DirectRefund' + CANCEL_AUTHORISATION_METHOD_NAME = 'CancelAuthorisation' + CREATE_TOKEN_CUSTOMER_METHOD = 'CreateTokenCustomer' + UPDATE_TOKEN_CUSTOMER_METHOD = 'UpdateTokenCustomer' + CANCEL_AUTHORISATION_METHOD = 'CancelAuthorisation' + TRANSACTION_METHOD = 'Transaction' + DIRECT_CUSTOMER_SEARCH_METHOD = 'DirectCustomerSearch' + TRANSACTION_QUERY_WITH_INVOICE_NUM_METHOD = 'InvoiceNumber' + TRANSACTION_QUERY_WITH_INVOICE_REF_METHOD = 'InvoiceRef' + REFUND_SUB_PATH_METHOD = 'Refund' + CAPTURE_PAYMENT_METHOD = 'CapturePayment' + end +end diff --git a/lib/eway_rapid/entities/cancel_authorisation_request.rb b/lib/eway_rapid/entities/cancel_authorisation_request.rb new file mode 100644 index 0000000..b2564c6 --- /dev/null +++ b/lib/eway_rapid/entities/cancel_authorisation_request.rb @@ -0,0 +1,9 @@ +module EwayRapid + class CancelAuthorisationRequest + attr_accessor :transaction_id + + def to_json(options={}) + { Constants::REQUEST_TRANSACTION_ID => transaction_id }.to_json + end + end +end diff --git a/lib/eway_rapid/entities/cancel_authorisation_response.rb b/lib/eway_rapid/entities/cancel_authorisation_response.rb new file mode 100644 index 0000000..fc549bf --- /dev/null +++ b/lib/eway_rapid/entities/cancel_authorisation_response.rb @@ -0,0 +1,34 @@ +module EwayRapid + class CancelAuthorisationResponse + attr_accessor :response_code + attr_accessor :response_message + attr_accessor :transaction_id + attr_accessor :transaction_status + attr_accessor :errors + + alias_method :transaction_status?, :transaction_status + + def to_json(options={}) + { Constants::RESPONSE_CODE => response_code, + Constants::RESPONSE_MESSAGE => response_message, + Constants::TRANSACTION_ID => transaction_id, + Constants::TRANSACTION_STATUS => transaction_status, + Constants::ERRORS => errors }.to_json + end + + def self.from_json(json) + hash = JSON.parse(json) + from_hash(hash) + end + + def self.from_hash(hash) + cancel_authorisation_response = CancelAuthorisationResponse.new + cancel_authorisation_response.response_code = hash[Constants::RESPONSE_CODE] + cancel_authorisation_response.response_message = hash[Constants::RESPONSE_MESSAGE] + cancel_authorisation_response.transaction_id = hash[Constants::TRANSACTION_ID] + cancel_authorisation_response.transaction_status = hash[Constants::TRANSACTION_STATUS] + cancel_authorisation_response.errors = hash[Constants::ERRORS_CAPITALIZED] + cancel_authorisation_response + end + end +end diff --git a/lib/eway_rapid/entities/capture_payment_request.rb b/lib/eway_rapid/entities/capture_payment_request.rb new file mode 100644 index 0000000..af4de4f --- /dev/null +++ b/lib/eway_rapid/entities/capture_payment_request.rb @@ -0,0 +1,11 @@ +module EwayRapid + class CapturePaymentRequest + attr_accessor :transaction_id + attr_accessor :payment + + def to_json(options={}) + {Constants::REQUEST_TRANSACTION_ID => transaction_id, + Constants::PAYMENT => InternalModels::Payment.to_hash(payment)}.to_json + end + end +end diff --git a/lib/eway_rapid/entities/capture_payment_response.rb b/lib/eway_rapid/entities/capture_payment_response.rb new file mode 100644 index 0000000..450944b --- /dev/null +++ b/lib/eway_rapid/entities/capture_payment_response.rb @@ -0,0 +1,34 @@ +module EwayRapid + class CapturePaymentResponse + attr_accessor :response_code + attr_accessor :response_message + attr_accessor :transaction_id + attr_accessor :transaction_status + attr_accessor :errors + + alias_method :transaction_status?, :transaction_status + + def to_json(options={}) + {Constants::RESPONSE_CODE => response_code, + Constants::RESPONSE_MESSAGE => response_message, + Constants::TRANSACTION_ID => transaction_id, + Constants::TRANSACTION_STATUS => transaction_status, + Constants::ERRORS => errors}.to_json + end + + def self.from_json(json) + hash = JSON.parse(json) + from_hash(hash) + end + + def self.from_hash(hash) + capture_payment_response = CapturePaymentResponse.new + capture_payment_response.response_code = hash[Constants::RESPONSE_CODE] + capture_payment_response.response_message = hash[Constants::RESPONSE_MESSAGE] + capture_payment_response.transaction_id = hash[Constants::TRANSACTION_ID] + capture_payment_response.transaction_status = hash[Constants::TRANSACTION_STATUS] + capture_payment_response.errors = hash[Constants::ERRORS_CAPITALIZED] + capture_payment_response + end + end +end diff --git a/lib/eway_rapid/entities/create_access_code_request.rb b/lib/eway_rapid/entities/create_access_code_request.rb new file mode 100644 index 0000000..9bc2ecc --- /dev/null +++ b/lib/eway_rapid/entities/create_access_code_request.rb @@ -0,0 +1,35 @@ +module EwayRapid + class CreateAccessCodeRequest + attr_accessor :customer + attr_accessor :shipping_address + attr_accessor :shipping_method + attr_accessor :items + attr_accessor :options + attr_accessor :payment + attr_accessor :redirect_url + attr_accessor :method + attr_accessor :customer_ip + attr_accessor :device_id + attr_accessor :checkout_payment + attr_accessor :checkout_url + attr_accessor :transaction_type + attr_accessor :partner_id + + def to_json(opts={}) + {Constants::CUSTOMER => InternalModels::Customer.to_hash(customer), + Constants::SHIPPING_ADDRESS => InternalModels::ShippingAddress.to_hash(shipping_address), + Constants::SHIPPING_METHOD => shipping_method, + Constants::ITEMS => Models::LineItem.to_array(items), + Constants::OPTIONS => InternalModels::Option.to_array(options), + Constants::PAYMENT => InternalModels::Payment.to_hash(payment), + Constants::REDIRECT_URL => redirect_url, + Constants::METHOD => method, + Constants::CUSTOMER_DEVICE_IP => customer_ip, + Constants::DEVICE_ID => device_id, + Constants::CHECKOUT_PAYMENT => checkout_payment, + Constants::CHECKOUT_URL => checkout_url, + Constants::TRANSACTION_TYPE => transaction_type, + Constants::PARTNER_ID => partner_id}.to_json + end + end +end diff --git a/lib/eway_rapid/entities/create_access_code_response.rb b/lib/eway_rapid/entities/create_access_code_response.rb new file mode 100644 index 0000000..54dcc81 --- /dev/null +++ b/lib/eway_rapid/entities/create_access_code_response.rb @@ -0,0 +1,128 @@ +module EwayRapid + class CreateAccessCodeResponse + attr_accessor :customer + attr_accessor :payment + attr_accessor :access_code + attr_accessor :form_action_url + attr_accessor :errors + attr_accessor :complete_checkout_url + attr_accessor :total_amount + attr_accessor :invoice_number + attr_accessor :invoice_description + attr_accessor :invoice_reference + attr_accessor :currency_code + attr_accessor :token_customer_id + attr_accessor :reference + attr_accessor :title + attr_accessor :first_name + attr_accessor :last_name + attr_accessor :company_name + attr_accessor :job_description + attr_accessor :street1 + attr_accessor :street2 + attr_accessor :city + attr_accessor :state + attr_accessor :postal_code + attr_accessor :country + attr_accessor :email + attr_accessor :phone + attr_accessor :mobile + attr_accessor :comments + attr_accessor :fax + attr_accessor :url + attr_accessor :card_number + attr_accessor :card_name + attr_accessor :card_expiry_month + attr_accessor :card_expiry_year + attr_accessor :card_start_month + attr_accessor :card_start_year + attr_accessor :card_issue_number + + def to_json(options={}) + {Constants::CUSTOMER => customer, + Constants::PAYMENT => payment, + Constants::ACCESS_CODE => access_code, + Constants::FORM_ACTION_URL => form_action_url, + Constants::ERRORS_CAPITALIZED => errors, + Constants::COMPLETE_CHECKOUT_URL => complete_checkout_url, + Constants::TOTAL_AMOUNT => total_amount, + Constants::INVOICE_NUMBER => invoice_number, + Constants::INVOICE_DESCRIPTION => invoice_description, + Constants::INVOICE_REFERENCE => invoice_reference, + Constants::CURRENCY_CODE => currency_code, + Constants::TOKEN_CUSTOMER_ID => token_customer_id, + Constants::REFERENCE => reference, + Constants::TITLE => title, + Constants::FIRST_NAME => first_name, + Constants::LAST_NAME => last_name, + Constants::COMPANY_NAME => company_name, + Constants::JOB_DESCRIPTION => job_description, + Constants::STREET1 => street1, + Constants::STREET2 => street2, + Constants::CITY => city, + Constants::STATE => state, + Constants::POSTAL_CODE => postal_code, + Constants::COUNTRY => country, + Constants::EMAIL => email, + Constants::PHONE => phone, + Constants::MOBILE => mobile, + Constants::COMMENTS => comments, + Constants::FAX => fax, + Constants::URL => url, + Constants::CARD_NUMBER => card_number, + Constants::CARD_NAME => card_name, + Constants::CARD_EXPIRY_MONTH => card_expiry_month, + Constants::CARD_EXPIRY_YEAR => card_expiry_year, + Constants::CARD_START_MONTH => card_start_month, + Constants::CARD_START_YEAR => card_start_year, + Constants::CARD_ISSUE_NUMBER => card_issue_number}.to_json + end + + def self.from_json(json) + hash = JSON.parse(json) + from_hash(hash) + end + + def self.from_hash(hash) + create_access_code_response = CreateAccessCodeResponse.new + create_access_code_response.customer = InternalModels::Customer.from_hash(hash[Constants::CUSTOMER]) + create_access_code_response.payment = InternalModels::Payment.from_hash(hash[Constants::PAYMENT]) + create_access_code_response.access_code = hash[Constants::ACCESS_CODE] + create_access_code_response.form_action_url = hash[Constants::FORM_ACTION_URL] + create_access_code_response.errors = hash[Constants::ERRORS_CAPITALIZED] + create_access_code_response.complete_checkout_url = hash[Constants::COMPLETE_CHECKOUT_URL] + create_access_code_response.total_amount = hash[Constants::TOTAL_AMOUNT] + create_access_code_response.invoice_number = hash[Constants::INVOICE_NUMBER] + create_access_code_response.invoice_description = hash[Constants::INVOICE_DESCRIPTION] + create_access_code_response.invoice_reference = hash[Constants::INVOICE_REFERENCE] + create_access_code_response.currency_code = hash[Constants::CURRENCY_CODE] + create_access_code_response.token_customer_id = hash[Constants::TOKEN_CUSTOMER_ID] + create_access_code_response.reference = hash[Constants::REFERENCE] + create_access_code_response.title = hash[Constants::TITLE] + create_access_code_response.first_name = hash[Constants::FIRST_NAME] + create_access_code_response.last_name = hash[Constants::LAST_NAME] + create_access_code_response.company_name = hash[Constants::COMPANY_NAME] + create_access_code_response.job_description = hash[Constants::JOB_DESCRIPTION] + create_access_code_response.street1 = hash[Constants::STREET1] + create_access_code_response.street2 = hash[Constants::STREET2] + create_access_code_response.city = hash[Constants::CITY] + create_access_code_response.state = hash[Constants::STATE] + create_access_code_response.postal_code = hash[Constants::POSTAL_CODE] + create_access_code_response.country = hash[Constants::COUNTRY] + create_access_code_response.email = hash[Constants::EMAIL] + create_access_code_response.phone = hash[Constants::PHONE] + create_access_code_response.mobile = hash[Constants::MOBILE] + create_access_code_response.comments = hash[Constants::COMMENTS] + create_access_code_response.fax = hash[Constants::FAX] + create_access_code_response.url = hash[Constants::URL] + create_access_code_response.card_number = hash[Constants::CARD_NUMBER] + create_access_code_response.card_name = hash[Constants::CARD_NAME] + create_access_code_response.card_expiry_month = hash[Constants::CARD_EXPIRY_MONTH] + create_access_code_response.card_expiry_year = hash[Constants::CARD_EXPIRY_YEAR] + create_access_code_response.card_start_month = hash[Constants::CARD_START_MONTH] + create_access_code_response.card_start_year = hash[Constants::CARD_START_YEAR] + create_access_code_response.card_issue_number = hash[Constants::CARD_ISSUE_NUMBER] + create_access_code_response + end + end +end diff --git a/lib/eway_rapid/entities/create_access_code_shared_request.rb b/lib/eway_rapid/entities/create_access_code_shared_request.rb new file mode 100644 index 0000000..536ab96 --- /dev/null +++ b/lib/eway_rapid/entities/create_access_code_shared_request.rb @@ -0,0 +1,53 @@ +module EwayRapid + class CreateAccessCodeSharedRequest + attr_accessor :customer + attr_accessor :shipping_address + attr_accessor :shipping_method + attr_accessor :items + attr_accessor :options + attr_accessor :payment + attr_accessor :redirect_url + attr_accessor :cancel_url + attr_accessor :checkout_url + attr_accessor :method + attr_accessor :device_id + attr_accessor :customer_ip + attr_accessor :transaction_type + attr_accessor :logo_url + attr_accessor :header_text + attr_accessor :partner_id + attr_accessor :language + attr_accessor :customer_read_only + attr_accessor :custom_view + attr_accessor :verify_customer_phone + attr_accessor :verify_customer_email + attr_accessor :checkout_payment + + def to_json(opts={}) + { + Constants::CUSTOMER => InternalModels::Customer.to_hash(customer), + Constants::SHIPPING_ADDRESS => InternalModels::ShippingAddress.to_hash(shipping_address), + Constants::SHIPPING_METHOD => shipping_method, + Constants::ITEMS => Models::LineItem.to_array(items), + Constants::OPTIONS => InternalModels::Option.to_array(options), + Constants::PAYMENT => InternalModels::Payment.to_hash(payment), + Constants::REDIRECT_URL => redirect_url, + Constants::CANCEL_URL => cancel_url, + Constants::CHECKOUT_URL => checkout_url, + Constants::METHOD => method, + Constants::DEVICE_ID => device_id, + Constants::CUSTOMER_DEVICE_IP => customer_ip, + Constants::TRANSACTION_TYPE => transaction_type, + Constants::LOGO_URL => logo_url, + Constants::HEADER_TEXT => header_text, + Constants::PARTNER_ID => partner_id, + Constants::LANGUAGE => language, + Constants::CUSTOMER_READ_ONLY => customer_read_only, + Constants::CUSTOMER_VIEW => custom_view, + Constants::VERIFY_CUSTOMER_PHONE => verify_customer_phone, + Constants::VERIFY_CUSTOMER_EMAIL => verify_customer_email, + Constants::CHECKOUT_PAYMENT => checkout_payment + }.to_json + end + end +end diff --git a/lib/eway_rapid/entities/create_access_code_shared_response.rb b/lib/eway_rapid/entities/create_access_code_shared_response.rb new file mode 100644 index 0000000..6684a83 --- /dev/null +++ b/lib/eway_rapid/entities/create_access_code_shared_response.rb @@ -0,0 +1,40 @@ +module EwayRapid + class CreateAccessCodeSharedResponse + attr_accessor :customer + attr_accessor :payment + attr_accessor :access_code + attr_accessor :form_action_url + attr_accessor :errors + attr_accessor :shared_payment_url + attr_accessor :complete_checkout_url + + def to_json(options={}) + { + Constants::CUSTOMER => customer, + Constants::PAYMENT => payment, + Constants::ACCESS_CODE => access_code, + Constants::FORM_ACTION_URL => form_action_url, + Constants::ERRORS_CAPITALIZED => errors, + Constants::SHARED_PAYMENT_URL => shared_payment_url, + Constants::COMPLETE_CHECKOUT_URL => complete_checkout_url + }.to_json + end + + def self.from_json(json) + hash = JSON.parse(json) + from_hash(hash) + end + + def self.from_hash(hash) + create_access_code = CreateAccessCodeSharedResponse.new + create_access_code.customer = InternalModels::Customer.from_hash(hash[Constants::CUSTOMER]) + create_access_code.payment = InternalModels::Payment.from_hash(hash[Constants::PAYMENT]) + create_access_code.access_code = hash[Constants::ACCESS_CODE] + create_access_code.form_action_url = hash[Constants::FORM_ACTION_URL] + create_access_code.errors = hash[Constants::ERRORS_CAPITALIZED] + create_access_code.shared_payment_url = hash[Constants::SHARED_PAYMENT_URL] + create_access_code.complete_checkout_url = hash[Constants::COMPLETE_CHECKOUT_URL] + create_access_code + end + end +end diff --git a/lib/eway_rapid/entities/create_customer_response.rb b/lib/eway_rapid/entities/create_customer_response.rb new file mode 100644 index 0000000..fa5e160 --- /dev/null +++ b/lib/eway_rapid/entities/create_customer_response.rb @@ -0,0 +1,8 @@ +module EwayRapid + class CreateCustomerResponse < ResponseOutput + attr_accessor :customer + attr_accessor :shared_payment_url + attr_accessor :form_action_url + attr_accessor :access_code + end +end diff --git a/lib/eway_rapid/entities/direct_customer_search_request.rb b/lib/eway_rapid/entities/direct_customer_search_request.rb new file mode 100644 index 0000000..dbae766 --- /dev/null +++ b/lib/eway_rapid/entities/direct_customer_search_request.rb @@ -0,0 +1,9 @@ +module EwayRapid + class DirectCustomerSearchRequest + attr_accessor :token_customer_id + + def to_json(options={}) + {Constants::TOKEN_CUSTOMER_ID => token_customer_id}.to_json + end + end +end diff --git a/lib/eway_rapid/entities/direct_customer_search_response.rb b/lib/eway_rapid/entities/direct_customer_search_response.rb new file mode 100644 index 0000000..338dfe3 --- /dev/null +++ b/lib/eway_rapid/entities/direct_customer_search_response.rb @@ -0,0 +1,23 @@ +module EwayRapid + class DirectCustomerSearchResponse + attr_accessor :customers + attr_accessor :errors + + def to_json(options={}) + {Constants::CUSTOMERS => customers, + Constants::ERRORS => errors}.to_json + end + + def self.from_json(json) + hash = JSON.parse(json) + from_hash(hash) + end + + def self.from_hash(hash) + response = DirectCustomerSearchResponse.new + response.customers = InternalModels::Customer.from_array(hash[Constants::CUSTOMERS]) + response.errors = hash[Constants::ERRORS_CAPITALIZED] + response + end + end +end diff --git a/lib/eway_rapid/entities/direct_payment_request.rb b/lib/eway_rapid/entities/direct_payment_request.rb new file mode 100644 index 0000000..aaa4f1f --- /dev/null +++ b/lib/eway_rapid/entities/direct_payment_request.rb @@ -0,0 +1,29 @@ +module EwayRapid + class DirectPaymentRequest + attr_accessor :customer + attr_accessor :shipping_address + attr_accessor :items + attr_accessor :options + attr_accessor :payment + attr_accessor :method + attr_accessor :transaction_type + attr_accessor :customer_ip + attr_accessor :device_id + attr_accessor :partner_id + attr_accessor :redirect_url + + def to_json(opts={}) + {Constants::CUSTOMER => InternalModels::Customer.to_hash(customer), + Constants::SHIPPING_ADDRESS => InternalModels::ShippingAddress.to_hash(shipping_address), + Constants::ITEMS => Models::LineItem.to_array(items), + Constants::OPTIONS => InternalModels::Option.to_array(options), + Constants::PAYMENT => InternalModels::Payment.to_hash(payment), + Constants::METHOD => method, + Constants::TRANSACTION_TYPE => transaction_type, + Constants::CUSTOMER_DEVICE_IP => customer_ip, + Constants::DEVICE_ID => device_id, + Constants::PARTNER_ID => partner_id, + Constants::REDIRECT_URL => redirect_url}.to_json + end + end +end diff --git a/lib/eway_rapid/entities/direct_payment_response.rb b/lib/eway_rapid/entities/direct_payment_response.rb new file mode 100644 index 0000000..975913c --- /dev/null +++ b/lib/eway_rapid/entities/direct_payment_response.rb @@ -0,0 +1,58 @@ +module EwayRapid + class DirectPaymentResponse + attr_accessor :authorisation_code + attr_accessor :response_code + attr_accessor :response_message + attr_accessor :transaction_id + attr_accessor :transaction_status + attr_accessor :transaction_type + attr_accessor :beagle_score + attr_accessor :errors + attr_accessor :transaction_captured + attr_accessor :fraud_action + attr_accessor :verification + attr_accessor :customer + attr_accessor :payment + + alias_method :transaction_status?, :transaction_status + + def to_json(options={}) + {Constants::AUTHORISATION_CODE => authorisation_code, + Constants::RESPONSE_CODE => response_code, + Constants::RESPONSE_MESSAGE => response_message, + Constants::TRANSACTION_ID => transaction_id, + Constants::TRANSACTION_STATUS => transaction_status, + Constants::TRANSACTION_TYPE => transaction_type, + Constants::BEAGLE_SCORE => beagle_score, + Constants::ERRORS_CAPITALIZED => errors, + Constants::TRANSACTION_CAPTURED => transaction_captured, + Constants::FRAUD_ACTION => fraud_action, + Constants::VERIFICATION => verification, + Constants::CUSTOMER => customer, + Constants::PAYMENT => payment}.to_json + end + + def self.from_json(json) + hash = JSON.parse(json) + from_hash(hash) + end + + def self.from_hash(hash) + direct_payment_response = DirectPaymentResponse.new + direct_payment_response.authorisation_code = hash[Constants::AUTHORISATION_CODE] + direct_payment_response.response_code = hash[Constants::RESPONSE_CODE] + direct_payment_response.response_message = hash[Constants::RESPONSE_MESSAGE] + direct_payment_response.transaction_id = hash[Constants::TRANSACTION_ID] + direct_payment_response.transaction_status = hash[Constants::TRANSACTION_STATUS] + direct_payment_response.transaction_type = hash[Constants::TRANSACTION_TYPE] + direct_payment_response.beagle_score = hash[Constants::BEAGLE_SCORE] + direct_payment_response.errors = hash[Constants::ERRORS_CAPITALIZED] + direct_payment_response.transaction_captured = hash[Constants::TRANSACTION_CAPTURED] + direct_payment_response.fraud_action = hash[Constants::FRAUD_ACTION] + direct_payment_response.verification = InternalModels::Verification.from_hash(hash[Constants::VERIFICATION]) if hash[Constants::VERIFICATION] + direct_payment_response.customer = InternalModels::Customer.from_hash(hash[Constants::CUSTOMER]) + direct_payment_response.payment = InternalModels::Payment.from_hash(hash[Constants::PAYMENT]) + direct_payment_response + end + end +end diff --git a/lib/eway_rapid/entities/direct_refund_request.rb b/lib/eway_rapid/entities/direct_refund_request.rb new file mode 100644 index 0000000..cc73dc8 --- /dev/null +++ b/lib/eway_rapid/entities/direct_refund_request.rb @@ -0,0 +1,26 @@ +module EwayRapid + class DirectRefundRequest + attr_accessor :customer + attr_accessor :shipping_address + attr_accessor :refund + attr_accessor :line_items + attr_accessor :options + attr_accessor :device_id + attr_accessor :customer_ip + attr_accessor :partner_id + + def to_json(opts={}) + { + Constants::CUSTOMER => InternalModels::Customer.to_hash(customer), + Constants::SHIPPING_ADDRESS => InternalModels::ShippingAddress.to_hash(shipping_address), + Constants::REFUND => InternalModels::RefundDetails.to_hash(refund), + Constants::LINE_ITEMS => Models::LineItem.to_array(line_items), + Constants::OPTIONS => InternalModels::Option.to_array(options), + Constants::DEVICE_ID => device_id, + Constants::CUSTOMER_DEVICE_IP => customer_ip, + Constants::PARTNER_ID => partner_id + }.to_json + end + + end +end diff --git a/lib/eway_rapid/entities/direct_refund_response.rb b/lib/eway_rapid/entities/direct_refund_response.rb new file mode 100644 index 0000000..f37ea52 --- /dev/null +++ b/lib/eway_rapid/entities/direct_refund_response.rb @@ -0,0 +1,44 @@ +module EwayRapid + class DirectRefundResponse + attr_accessor :authorisation_code + attr_accessor :response_code + attr_accessor :response_message + attr_accessor :transaction_id + attr_accessor :transaction_status + attr_accessor :verification + attr_accessor :customer + attr_accessor :refund + attr_accessor :errors + + alias_method :transaction_status?, :transaction_status + + def to_json(options={}) + {Constants::AUTHORISATION_CODE => authorisation_code, + Constants::RESPONSE_CODE => response_code, + Constants::TRANSACTION_ID => transaction_id, + Constants::TRANSACTION_STATUS => transaction_status, + Constants::VERIFICATION => verification, + Constants::CUSTOMER => customer, + Constants::REFUND => refund, + Constants::ERRORS_CAPITALIZED => errors}.to_json + end + + def self.from_json(json) + hash = JSON.parse(json) + from_hash(hash) + end + + def self.from_hash(hash) + direct_refund_response = DirectRefundResponse.new + direct_refund_response.authorisation_code = hash[Constants::AUTHORISATION_CODE] + direct_refund_response.response_code = hash[Constants::RESPONSE_CODE] + direct_refund_response.transaction_id = hash[Constants::TRANSACTION_ID] + direct_refund_response.transaction_status = hash[Constants::TRANSACTION_STATUS] + direct_refund_response.verification = hash[Constants::VERIFICATION] + direct_refund_response.customer = InternalModels::Customer.from_hash(hash[Constants::CUSTOMER]) + direct_refund_response.refund = InternalModels::RefundDetails.from_hash(hash[Constants::REFUND]) + direct_refund_response.errors = hash[Constants::ERRORS_CAPITALIZED] + direct_refund_response + end + end +end diff --git a/lib/eway_rapid/entities/transaction_search_response.rb b/lib/eway_rapid/entities/transaction_search_response.rb new file mode 100644 index 0000000..0ea5bbe --- /dev/null +++ b/lib/eway_rapid/entities/transaction_search_response.rb @@ -0,0 +1,23 @@ +module EwayRapid + class TransactionSearchResponse + attr_accessor :transactions + attr_accessor :error + + def to_json(options={}) + {Constants::TRANSACTIONS => transactions, + Constants::ERRORS_CAPITALIZED => error}.to_json + end + + def self.from_json(json) + hash = JSON.parse(json) + from_hash(hash) + end + + def self.from_hash(hash) + transaction_search_response = TransactionSearchResponse.new + transaction_search_response.transactions = InternalModels::Transaction.from_array(hash[Constants::TRANSACTIONS]) + transaction_search_response.error = hash[Constants::ERRORS_CAPITALIZED] + transaction_search_response + end + end +end diff --git a/lib/eway_rapid/exceptions.rb b/lib/eway_rapid/exceptions.rb new file mode 100644 index 0000000..4b5d5b1 --- /dev/null +++ b/lib/eway_rapid/exceptions.rb @@ -0,0 +1,51 @@ +module EwayRapid + module Exceptions + + # The root exception class for all of business Rapid API exceptions + # Optional parameters : + # * :error_code the business error code + class RapidSdkException < StandardError + attr_accessor :error_code + + def initialize(error_code, message) + super(message) + @error_code = error_code + end + end + + # Rapid API key, password or endpoint invalid exception + class APIKeyInvalidException < RapidSdkException + def initialize(message) + super(Constants::API_KEY_INVALID_ERROR_CODE, message) + end + end + + # Authentication to Rapid API failed (server returned HTTP 40*) + class AuthenticationFailureException < RapidSdkException + def initialize(message) + super(Constants::AUTHENTICATION_FAILURE_ERROR_CODE, message) + end + end + + # Error connecting to Rapid API + class CommunicationFailureException < RapidSdkException + def initialize(message) + super(Constants::COMMUNICATION_FAILURE_ERROR_CODE, message) + end + end + + # Invalid parameter exception + class ParameterInvalidException < RapidSdkException + def initialize(message) + super(Constants::INTERNAL_RAPID_API_ERROR_CODE, message) + end + end + + # Invalid response from Rapid API + class SystemErrorException 0 + list_convert = [] + list_options.each do |value| + op = InternalModels::Option.new + op.value = value + list_convert.push(op) + end + request.options = list_convert + end + end + request + end + end + end + end + end +end diff --git a/lib/eway_rapid/message/convert/request/transaction_to_capture_payment.rb b/lib/eway_rapid/message/convert/request/transaction_to_capture_payment.rb new file mode 100644 index 0000000..d8b5b51 --- /dev/null +++ b/lib/eway_rapid/message/convert/request/transaction_to_capture_payment.rb @@ -0,0 +1,28 @@ +module EwayRapid + module Message + module Convert + module Request + class TransactionToCapturePayment + + # @param [Models::Transaction] transaction + # @return [CapturePaymentRequest] + def do_convert(transaction) + request = CapturePaymentRequest.new + request.transaction_id = transaction.auth_transaction_id + + if transaction.payment_details + payment = InternalModels::Payment.new + payment.currency_code = transaction.payment_details.currency_code + payment.invoice_description = transaction.payment_details.invoice_description + payment.invoice_number = transaction.payment_details.invoice_number + payment.invoice_reference = transaction.payment_details.invoice_reference + payment.total_amount = transaction.payment_details.total_amount + request.payment = payment + end + request + end + end + end + end + end +end diff --git a/lib/eway_rapid/message/convert/request/transaction_to_create_access_code_request.rb b/lib/eway_rapid/message/convert/request/transaction_to_create_access_code_request.rb new file mode 100644 index 0000000..f3b0031 --- /dev/null +++ b/lib/eway_rapid/message/convert/request/transaction_to_create_access_code_request.rb @@ -0,0 +1,58 @@ +module EwayRapid + module Message + module Convert + module Request + class TransactionToCreateAccessCodeRequest + + # @param [Models::Transaction] transaction + # @return [CreateAccessCodeRequest] + def do_convert(transaction) + request = CreateAccessCodeRequest.new + + if transaction + request.transaction_type = transaction.transaction_type + request.device_id = transaction.device_id + request.partner_id = transaction.partner_id + request.redirect_url = transaction.redirect_url + # request.payment.total_amount = transaction.payment_details.total_amount if transaction.payment_details + + if transaction.customer + internal_cust_convert = CustomerToInternalCustomer.new(false) + request.customer = internal_cust_convert.do_convert(transaction.customer) + request.customer_ip = transaction.customer.customer_device_ip + end + + ship_address_convert = TransactionShippingAddress.new + request.shipping_address = ship_address_convert.do_convert(transaction) + + payment_convert = TransactionToPayment.new + request.payment = payment_convert.do_convert(transaction) + + if transaction.checkout_url + request.checkout_payment = transaction.checkout_payment + request.checkout_url = transaction.checkout_url + end + + line_item_convert = TransactionToArrLineItem.new + request.items = line_item_convert.do_convert(transaction) + + option_convert = TransactionToArrOption.new + request.options = option_convert.do_convert(transaction) + + if transaction.shipping_details && transaction.shipping_details.shipping_method + request.shipping_method = transaction.shipping_details.shipping_method + end + + request.method = if transaction.capture + Enums::RequestMethod::PROCESS_PAYMENT + else + Enums::RequestMethod::AUTHORISE + end + end + request + end + end + end + end + end +end diff --git a/lib/eway_rapid/message/convert/request/transaction_to_create_access_code_shared_request.rb b/lib/eway_rapid/message/convert/request/transaction_to_create_access_code_shared_request.rb new file mode 100644 index 0000000..95b4f2f --- /dev/null +++ b/lib/eway_rapid/message/convert/request/transaction_to_create_access_code_shared_request.rb @@ -0,0 +1,54 @@ +module EwayRapid + module Message + module Convert + module Request + class TransactionToCreateAccessCodeSharedRequest + + # @param [Models::Transaction] input + # @return [CreateAccessCodeSharedRequest] + def do_convert(input) + request = CreateAccessCodeSharedRequest.new + + if input + request.cancel_url = input.cancel_url + request.transaction_type = input.transaction_type + request.device_id = input.device_id + request.partner_id = input.partner_id + request.redirect_url = input.redirect_url + request.custom_view = input.custom_view + request.header_text = input.header_text + request.customer_ip = input.customer.customer_device_ip if input.customer + request.logo_url = input.logo_url + request.language = input.language + request.verify_customer_email = input.verify_customer_email + request.verify_customer_phone = input.verify_customer_phone + request.customer_read_only = input.customer_read_only + + internal_cust_convert = CustomerToInternalCustomer.new + request.customer = internal_cust_convert.do_convert(input.customer) + + ship_address_convert = TransactionShippingAddress.new + request.shipping_address = ship_address_convert.do_convert(input) + + payment_convert = TransactionToPayment.new + request.payment = payment_convert.do_convert(input) + + line_item_convert = TransactionToArrLineItem.new + request.items = line_item_convert.do_convert(input) + + option_converter = TransactionToArrOption.new + request.options = option_converter.do_convert(input) + + request.method = if input.capture + Enums::RequestMethod::PROCESS_PAYMENT + else + Enums::RequestMethod::AUTHORISE + end + end + request + end + end + end + end + end +end diff --git a/lib/eway_rapid/message/convert/request/transaction_to_direct_payment.rb b/lib/eway_rapid/message/convert/request/transaction_to_direct_payment.rb new file mode 100644 index 0000000..e747aa9 --- /dev/null +++ b/lib/eway_rapid/message/convert/request/transaction_to_direct_payment.rb @@ -0,0 +1,45 @@ +module EwayRapid + module Message + module Convert + module Request + class TransactionToDirectPayment + + # @param [Models::Transaction] input + # @return [DirectPaymentRequest] + def do_convert(input) + request = DirectPaymentRequest.new + inter_cust_convert = CustomerToInternalCustomer.new + + if input.customer + request.customer_ip = input.customer.customer_device_ip + request.customer = inter_cust_convert.do_convert(input.customer) + end + + payment_convert = TransactionToPayment.new + request.payment = payment_convert.do_convert(input) + + ship_converter = TransactionShippingAddress.new + request.shipping_address = ship_converter.do_convert(input) + + line_item_convert = TransactionToArrLineItem.new + request.items = line_item_convert.do_convert(input) + + option_converter = TransactionToArrOption.new + request.options = option_converter.do_convert(input) + + request.device_id = input.device_id + request.partner_id = input.partner_id + request.transaction_type = input.transaction_type || '' + request.method = if input.capture + Enums::RequestMethod::PROCESS_PAYMENT + else + Enums::RequestMethod::AUTHORISE + end + request.redirect_url = input.redirect_url + request + end + end + end + end + end +end diff --git a/lib/eway_rapid/message/convert/response/access_code_shared_to_create_cust.rb b/lib/eway_rapid/message/convert/response/access_code_shared_to_create_cust.rb new file mode 100644 index 0000000..259689d --- /dev/null +++ b/lib/eway_rapid/message/convert/response/access_code_shared_to_create_cust.rb @@ -0,0 +1,23 @@ +module EwayRapid + module Message + module Convert + module Response + class AccessCodeSharedToCreateCust + + # @param [CreateAccessCodeSharedResponse] response + # @return [CreateCustomerResponse] + def do_convert(response) + customer_response = CreateCustomerResponse.new + customer_response.access_code = response.access_code + customer_response.errors = response.errors.split(/\s*,\s*/) if response.errors + + cust_convert = InternalCustomerToCustomer.new + customer_response.customer = cust_convert.do_convert(response.customer) + customer_response.shared_payment_url = response.shared_payment_url + customer_response + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/eway_rapid/message/convert/response/access_code_shared_to_create_trans.rb b/lib/eway_rapid/message/convert/response/access_code_shared_to_create_trans.rb new file mode 100644 index 0000000..32c2247 --- /dev/null +++ b/lib/eway_rapid/message/convert/response/access_code_shared_to_create_trans.rb @@ -0,0 +1,28 @@ +module EwayRapid + module Message + module Convert + module Response + class AccessCodeSharedToCreateTrans + + # @param [CreateAccessCodeSharedResponse] response + # @return [CreateTransactionResponse] + def do_convert(response) + transaction_response = CreateTransactionResponse.new + transaction = Models::Transaction.new + cust_convert = InternalCustomerToCustomer.new + transaction.customer = cust_convert.do_convert(response.customer) + + payment_convert = PaymentToPaymentDetails.new + transaction.payment_details = payment_convert.do_convert(response.payment) + + transaction_response.transaction = transaction + transaction_response.errors = response.errors.split(/\s*,\s*/) if response.errors + transaction_response.shared_payment_url = response.shared_payment_url + transaction_response.access_code = response.access_code + transaction_response + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/eway_rapid/message/convert/response/access_code_to_create_cust.rb b/lib/eway_rapid/message/convert/response/access_code_to_create_cust.rb new file mode 100644 index 0000000..26bc8a3 --- /dev/null +++ b/lib/eway_rapid/message/convert/response/access_code_to_create_cust.rb @@ -0,0 +1,24 @@ +module EwayRapid + module Message + module Convert + module Response + class AccessCodeToCreateCust + + # @param [CreateAccessCodeResponse] response + # @return [CreateCustomerResponse] + def do_convert(response) + customer_response = CreateCustomerResponse.new + customer_response.access_code = response.access_code + customer_response.form_action_url = response.form_action_url + + convert = InternalCustomerToCustomer.new + customer_response.customer = convert.do_convert(response.customer) + + customer_response.errors = response.errors.split(/\s*,\s*/) if response.errors + customer_response + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/eway_rapid/message/convert/response/access_code_to_create_trans.rb b/lib/eway_rapid/message/convert/response/access_code_to_create_trans.rb new file mode 100644 index 0000000..38cb999 --- /dev/null +++ b/lib/eway_rapid/message/convert/response/access_code_to_create_trans.rb @@ -0,0 +1,27 @@ +module EwayRapid + module Message + module Convert + module Response + class AccessCodeToCreateTrans + + # @param [CreateAccessCodeResponse] response + # @return [CreateTransactionResponse] + def do_convert(response) + transaction_response = CreateTransactionResponse.new + transaction = Models::Transaction.new + cust_convert = InternalCustomerToCustomer.new + transaction.customer = cust_convert.do_convert(response.customer) + + payment_convert = PaymentToPaymentDetails.new + transaction.payment_details = payment_convert.do_convert(response.payment) + transaction_response.transaction = transaction + transaction_response.errors = response.errors.split(/\s*,\s*/) if response.errors + transaction_response.access_code = response.access_code + transaction_response.form_action_url = response.form_action_url + transaction_response + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/eway_rapid/message/convert/response/cancel_authorisation_to_refund.rb b/lib/eway_rapid/message/convert/response/cancel_authorisation_to_refund.rb new file mode 100644 index 0000000..2b18642 --- /dev/null +++ b/lib/eway_rapid/message/convert/response/cancel_authorisation_to_refund.rb @@ -0,0 +1,37 @@ +module EwayRapid + module Message + module Convert + module Response + class CancelAuthorisationToRefund + attr_reader :refund + + # @param [Models::Refund] refund + def initialize(refund) + @refund = refund + end + + # @param [CancelAuthorisationResponse] cancel + # @return [RefundResponse] + def do_convert(cancel) + response = RefundResponse.new + response.refund = @refund + + status = Models::TransactionStatus.new + status.status = cancel.transaction_status + + detail = Models::ProcessingDetails.new + detail.response_code = cancel.errors + detail.response_code = cancel.response_code + + status.processing_details = detail + status.transaction_id = Integer(cancel.transaction_id) + + response.transaction_status = status + response.errors = cancel.errors.split(/\s*,\s*/) if cancel.errors + response + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/eway_rapid/message/convert/response/capture_payment_to_create_transaction.rb b/lib/eway_rapid/message/convert/response/capture_payment_to_create_transaction.rb new file mode 100644 index 0000000..671898f --- /dev/null +++ b/lib/eway_rapid/message/convert/response/capture_payment_to_create_transaction.rb @@ -0,0 +1,43 @@ +module EwayRapid + module Message + module Convert + module Response + class CapturePaymentToCreateTransaction + + # @param [CapturePaymentResponse] capture + # @return [CreateTransactionResponse] + def do_convert(capture) + response = CreateTransactionResponse.new + status = Models::TransactionStatus.new + begin + status.transaction_id = parse_int(capture.transaction_id) if capture.transaction_id + rescue + raise ArgumentError.new 'Convert transaction id ' + capture.transaction_id + ' to integer error' + end + + status.status = capture.transaction_status + + detail = Models::ProcessingDetails.new + detail.response_code = capture.errors + detail.response_code = capture.response_code + detail.response_message = capture.response_message + + status.processing_details = detail + + response.transaction_status = status + response.errors = capture.errors.split(/\s*,\s*/) if capture.errors + response + end + + def parse_int(string) + begin + Integer(string) + rescue RuntimeError + raise ArgumentError.new 'Convert transaction id ' + capture.transaction_id + ' to integer error' + end + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/eway_rapid/message/convert/response/direct_customer_to_query_customer.rb b/lib/eway_rapid/message/convert/response/direct_customer_to_query_customer.rb new file mode 100644 index 0000000..209c9e4 --- /dev/null +++ b/lib/eway_rapid/message/convert/response/direct_customer_to_query_customer.rb @@ -0,0 +1,55 @@ +module EwayRapid + module Message + module Convert + module Response + class DirectCustomerToQueryCustomer + + # @param [DirectCustomerSearchResponse] response + # @return [QueryCustomerResponse] + def do_convert(response) + result = QueryCustomerResponse.new + if response + result.errors = response.errors.split(/\s*,\s*/) if response.errors + + # @type [Array] + list_customer = response.customers + if list_customer && list_customer.length > 0 + list_customer.each do |cust| + result.reference = cust.reference + result.title = cust.title + result.first_name = cust.first_name + result.last_name = cust.last_name + result.company_name = cust.company_name + result.job_description = cust.job_description + + # @type [String] + street = cust.street1 + if street && street.strip + arr = street.split(',', 2) + result.street1 = street.split(',', 2).first + result.street2 = street.split(',', 2).last if arr.length > 1 + end + + result.token_customer_id = cust.token_customer_id + result.city = cust.city + result.state = cust.state + result.postal_code = cust.postal_code + result.phone = cust.phone + result.mobile = cust.mobile + result.email = cust.email + result.url = cust.url + result.card_detail = cust.card_details + result.country = cust.country + result.comments = cust.comments + result.fax = cust.fax + result + end + end + end + result + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/eway_rapid/message/convert/response/direct_payment_to_create_cust.rb b/lib/eway_rapid/message/convert/response/direct_payment_to_create_cust.rb new file mode 100644 index 0000000..209ad82 --- /dev/null +++ b/lib/eway_rapid/message/convert/response/direct_payment_to_create_cust.rb @@ -0,0 +1,23 @@ +module EwayRapid + module Message + module Convert + module Response + class DirectPaymentToCreateCust + + # @param [DirectPaymentResponse] response + # @return [CreateCustomerResponse] + def do_convert(response) + customer_response = CreateCustomerResponse.new + cust_convert = InternalCustomerToCustomer.new + + customer_response.customer = cust_convert.do_convert(response.customer) + + customer_response.errors = response.errors.split(/\s*,\s*/) if response.errors + + customer_response + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/eway_rapid/message/convert/response/direct_payment_to_create_trans.rb b/lib/eway_rapid/message/convert/response/direct_payment_to_create_trans.rb new file mode 100644 index 0000000..077cfa3 --- /dev/null +++ b/lib/eway_rapid/message/convert/response/direct_payment_to_create_trans.rb @@ -0,0 +1,32 @@ +module EwayRapid + module Message + module Convert + module Response + class DirectPaymentToCreateTrans + + # @param [DirectPaymentResponse] response + # @return [CreateTransactionResponse] + def do_convert(response) + transaction_response = CreateTransactionResponse.new + transaction = Models::Transaction.new + + transaction.transaction_type = response.transaction_type + + payment_converter = PaymentToPaymentDetails.new + transaction.payment_details = payment_converter.do_convert(response.payment) + + cust_convert = InternalCustomerToCustomer.new + transaction.customer = cust_convert.do_convert(response.customer) + + transaction_response.transaction = transaction + transaction_response.errors = response.errors.split(/\s*,\s*/) if response.errors + + status_convert = DirectPaymentToTransStatus.new + transaction_response.transaction_status = status_convert.do_convert(response) + transaction_response + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/eway_rapid/message/convert/response/direct_refund_to_refund_response.rb b/lib/eway_rapid/message/convert/response/direct_refund_to_refund_response.rb new file mode 100644 index 0000000..45c65b8 --- /dev/null +++ b/lib/eway_rapid/message/convert/response/direct_refund_to_refund_response.rb @@ -0,0 +1,28 @@ +module EwayRapid + module Message + module Convert + module Response + class DirectRefundToRefundResponse + + # @param [DirectRefundResponse] response + # @return [RefundResponse] + def do_convert(response) + refund = Models::Refund.new + refund.refund_details = response.refund + + cust_convert = InternalCustomerToCustomer.new + refund.customer = cust_convert.do_convert(response.customer) + + refund_response = RefundResponse.new + refund_response.errors = response.errors.split(/\s*,\s*/) if response.errors + refund_response.refund = refund + + trans_status_convert = DirectRefundToTransStatus.new + refund_response.transaction_status = trans_status_convert.do_convert(response) + refund_response + end + end + end + end + end +end diff --git a/lib/eway_rapid/message/convert/response/search_to_query_trans.rb b/lib/eway_rapid/message/convert/response/search_to_query_trans.rb new file mode 100644 index 0000000..7df24a3 --- /dev/null +++ b/lib/eway_rapid/message/convert/response/search_to_query_trans.rb @@ -0,0 +1,30 @@ +module EwayRapid + module Message + module Convert + module Response + class SearchToQueryTrans + + # @param [TransactionSearchResponse] response + # @return [QueryTransactionResponse] + def do_convert(response) + query_transaction_response = QueryTransactionResponse.new + + if response.transactions && response.transactions.length > 0 + trans_convert = InternalTransToTrans.new + query_transaction_response.transaction = trans_convert.do_convert(response.transactions[0]) + end + + query_transaction_response.errors = response.error.split(/\s*,\s*/) if response.error + + status_convert = InternalTransactionToStatus.new + if response.transactions && response.transactions.length > 0 + query_transaction_response.transaction_status = status_convert.do_convert(response.transactions[0]) + end + + query_transaction_response + end + end + end + end + end +end \ No newline at end of file diff --git a/lib/eway_rapid/message/convert/shipping_details_to_address.rb b/lib/eway_rapid/message/convert/shipping_details_to_address.rb new file mode 100644 index 0000000..dfa49ce --- /dev/null +++ b/lib/eway_rapid/message/convert/shipping_details_to_address.rb @@ -0,0 +1,35 @@ +module EwayRapid + module Message + module Convert + class ShippingDetailsToAddress + + # @param [Models::ShippingDetails] detail + # @return [InternalModels::ShippingAddress] + def do_convert(detail) + address = InternalModels::ShippingAddress.new + + if detail + # @type [InternalModels::ShippingAddress] + add = detail.shipping_address + + if add + address.city = add.city + address.country = add.country + address.state = add.state + address.street1 = add.street1 + address.street2 = add.street2 + address.postal_code = add.postal_code + end + + address.first_name = detail.first_name + address.last_name = detail.last_name + address.phone = detail.phone + address.fax = detail.fax + address.shipping_method = detail.shipping_method || '' + end + address + end + end + end + end +end diff --git a/lib/eway_rapid/message/convert/transaction_shipping_address.rb b/lib/eway_rapid/message/convert/transaction_shipping_address.rb new file mode 100644 index 0000000..c575417 --- /dev/null +++ b/lib/eway_rapid/message/convert/transaction_shipping_address.rb @@ -0,0 +1,37 @@ +module EwayRapid + module Message + module Convert + class TransactionShippingAddress + + # @param [Models::Transaction] transaction + # @return [InternalModels::ShippingAddress] + def do_convert(transaction) + shipping_address = InternalModels::ShippingAddress.new + + # @type [Models::ShippingDetails] + detail = transaction.shipping_details + if detail + shipping_address.first_name = detail.first_name + shipping_address.last_name = detail.last_name + shipping_address.shipping_method = detail.shipping_method + shipping_address.email = detail.email + shipping_address.phone = detail.phone + shipping_address.fax = detail.fax + + # @type [Models::Address] + address = detail.shipping_address + if address + shipping_address.city = address.city + shipping_address.country = address.country + shipping_address.postal_code = address.postal_code + shipping_address.state = address.state + shipping_address.street1 = address.street1 + shipping_address.street2 = address.street2 + end + end + shipping_address + end + end + end + end +end diff --git a/lib/eway_rapid/message/convert/transaction_to_arr_line_item.rb b/lib/eway_rapid/message/convert/transaction_to_arr_line_item.rb new file mode 100644 index 0000000..61f8e2f --- /dev/null +++ b/lib/eway_rapid/message/convert/transaction_to_arr_line_item.rb @@ -0,0 +1,14 @@ +module EwayRapid + module Message + module Convert + class TransactionToArrLineItem + + # @param [Models::Transaction] transaction + # @return [Array] + def do_convert(transaction) + transaction.line_items || [] + end + end + end + end +end diff --git a/lib/eway_rapid/message/convert/transaction_to_arr_option.rb b/lib/eway_rapid/message/convert/transaction_to_arr_option.rb new file mode 100644 index 0000000..abfd1c8 --- /dev/null +++ b/lib/eway_rapid/message/convert/transaction_to_arr_option.rb @@ -0,0 +1,25 @@ +module EwayRapid + module Message + module Convert + class TransactionToArrOption + + # @param [Models::Transaction] transaction + # @return [Array] + def do_convert(transaction) + if transaction.options + list_option = Array.new + + transaction.options.each do |opt| + option = InternalModels::Option.new + option.value = opt + list_option.push(option) + end + list_option + else + Array.new(3) + end + end + end + end + end +end diff --git a/lib/eway_rapid/message/convert/transaction_to_payment.rb b/lib/eway_rapid/message/convert/transaction_to_payment.rb new file mode 100644 index 0000000..38ea3ea --- /dev/null +++ b/lib/eway_rapid/message/convert/transaction_to_payment.rb @@ -0,0 +1,29 @@ +module EwayRapid + module Message + module Convert + class TransactionToPayment + + # @param [Models::Transaction] transaction + # @return [InternalModels::Payment] + def do_convert(transaction) + payment = InternalModels::Payment.new + + # @type [Models::PaymentDetails] + payment_details = transaction.payment_details + + if payment_details + payment.currency_code = payment_details.currency_code + payment.invoice_description = payment_details.invoice_description + payment.invoice_number = payment_details.invoice_number + payment.invoice_reference = payment_details.invoice_reference + payment.total_amount = payment_details.total_amount + else + payment.total_amount = 0 + end + + payment + end + end + end + end +end diff --git a/lib/eway_rapid/message/convert/verification_to_verification_result.rb b/lib/eway_rapid/message/convert/verification_to_verification_result.rb new file mode 100644 index 0000000..4d4168d --- /dev/null +++ b/lib/eway_rapid/message/convert/verification_to_verification_result.rb @@ -0,0 +1,33 @@ +module EwayRapid + module Message + module Convert + class VerificationToVerificationResult + + # @param [InternalModels::Verification] verification + def do_convert(verification) + result = Models::VerificationResult.new + + if verification + result.address = get_verify_status(verification.address) + result.cvn = get_verify_status(verification.cvn) + result.email = get_verify_status(verification.email) + result.mobile = get_verify_status(verification.mobile) + result.phone = get_verify_status(verification.mobile) + end + result + end + + # @param [String] status + # @return [String] + def get_verify_status(status) + begin + index = Integer(status) + Enums::VerifyStatus.calculate_status(index) + rescue StandardError + return nil + end + end + end + end + end +end diff --git a/lib/eway_rapid/message/process/customer_process.rb b/lib/eway_rapid/message/process/customer_process.rb new file mode 100644 index 0000000..086eab2 --- /dev/null +++ b/lib/eway_rapid/message/process/customer_process.rb @@ -0,0 +1,255 @@ +module EwayRapid + module Message + module CustomerProcess + + # Create customer with direct payment method message process + class CustDirectPaymentMsgProcess + include RestProcess + + # @param [Models::Customer] input + # @return [DirectPaymentRequest] + def self.create_request(input) + request = DirectPaymentRequest.new + convert = Convert::CustomerToInternalCustomer.new(false) + request.customer = convert.do_convert(input) + request.customer_ip = input.customer_device_ip + request.method = Constants::CREATE_TOKEN_CUSTOMER_METHOD + request.transaction_type = Enums::TransactionType::PURCHASE + request + end + + # @param [String] url + # @param [String] api_key + # @param [String] password + # @param [DirectPaymentRequest] request + # @return [String] + def self.send_request(url, api_key, password, request) + begin + CustDirectPaymentMsgProcess.new.do_post(url, api_key, password, request) + rescue SocketError => e + raise Exceptions::CommunicationFailureException.new(e.message) + rescue RestClient::Exception => e + if e.http_code == 401 || e.http_code == 403 || e.http_code == 404 + raise Exceptions::AuthenticationFailureException.new(e.message) + else + raise Exceptions::SystemErrorException.new(e.message) + end + end + end + + # @param [String] response + # @return [CreateCustomerResponse] + def self.make_result(response) + direct_payment_response = DirectPaymentResponse.from_json(response) + convert = Convert::Response::DirectPaymentToCreateCust.new + convert.do_convert(direct_payment_response) + end + end + + # Create customer with responsive shared method message process + class CustResponsiveSharedMsgProcess + include RestProcess + + # @param [Models::Customer] input + # @return [CreateAccessCodeSharedRequest] + def self.create_request(input) + request = CreateAccessCodeSharedRequest.new + convert = Convert::CustomerToInternalCustomer.new(false) + request.customer = convert.do_convert(input) + request.method = Constants::CREATE_TOKEN_CUSTOMER_METHOD + request.transaction_type = Enums::TransactionType::PURCHASE + request.redirect_url = input.redirect_url + request.cancel_url = input.cancel_url + request + end + + # @param [String] url + # @param [String] api_key + # @param [String] password + # @param [CreateAccessCodeSharedRequest] request + # @return [String] + def self.send_request(url, api_key, password, request) + CustResponsiveSharedMsgProcess.new.do_post(url, api_key, password, request) + end + + # @param [String] response + # @return [CreateCustomerResponse] + def self.make_result(response) + code_shared_response = CreateAccessCodeSharedResponse.from_json(response) + convert = Convert::Response::AccessCodeSharedToCreateCust.new + convert.do_convert(code_shared_response) + end + end + + # Create customer with transparent redirect message process + class CustTransparentRedirectMsgProcess + include RestProcess + + # @param [Models::Customer] input + # @return [CreateAccessCodeRequest] + def self.create_request(input) + request = CreateAccessCodeRequest.new + convert = Convert::CustomerToInternalCustomer.new(false) + request.customer = convert.do_convert(input) + request.method = Constants::CREATE_TOKEN_CUSTOMER_METHOD + request.transaction_type = Enums::TransactionType::PURCHASE + request.redirect_url = input.redirect_url + request + end + + # @param [String] url + # @param [String] api_key + # @param [String] password + # @param [CreateAccessCodeRequest] request + # @return [String] + def self.send_request(url, api_key, password, request) + CustTransparentRedirectMsgProcess.new.do_post(url, api_key, password, request) + end + + # @param [String] response + # @return [CreateCustomerResponse] + def self.make_result(response) + access_code_response = CreateAccessCodeResponse.from_json(response) + convert = Convert::Response::AccessCodeToCreateCust.new + convert.do_convert(access_code_response) + end + end + + # Query customer message process + class QueryCustomerMsgProcess + include RestProcess + + # @param [String] token_customer_id + # @return [DirectCustomerSearchRequest] + def self.create_request(token_customer_id) + request = DirectCustomerSearchRequest.new + request.token_customer_id = token_customer_id + request + end + + # @param [DirectCustomerSearchRequest] request + # @return [String] + def self.send_request(url, api_key, password, request) + QueryCustomerMsgProcess.new.do_post(url, api_key, password, request) + end + + # @param [String] response + # @return [DirectCustomerSearchResponse] + def self.make_result(response) + direct_customer_response = DirectCustomerSearchResponse.from_json(response) + converter = Convert::Response::DirectCustomerToQueryCustomer.new + converter.do_convert(direct_customer_response) + end + end + + # Create customer with direct payment method message process + class CustDirectUpdateMsgProcess + include RestProcess + + # @param [Models::Customer] input + # @return [DirectPaymentRequest] + def self.create_request(input) + request = DirectPaymentRequest.new + converter = Convert::CustomerToInternalCustomer.new + payment = InternalModels::Payment.new + payment.total_amount = 0 + request.payment = payment + request.customer = converter.do_convert(input) + request.customer_ip = input.customer_device_ip + request.method = Constants::UPDATE_TOKEN_CUSTOMER_METHOD + request.transaction_type = Enums::TransactionType::PURCHASE + request + end + + # @param [String] url + # @param [String] api_key + # @param [String] password + # @param [DirectPaymentRequest] request + def self.send_request(url, api_key, password, request) + CustDirectUpdateMsgProcess.new.do_post(url, api_key, password, request) + end + + # @param [String] response + # @return [CreateCustomerResponse] + def self.make_result(response) + direct_response = DirectPaymentResponse.from_json(response) + converter = Convert::Response::DirectPaymentToCreateCust.new + converter.do_convert(direct_response) + end + end + + # Create customer with responsive shared method message process + class CustResponsiveUpdateMsgProcess + include RestProcess + + # @param [Models::Customer] input + # @return [CreateAccessCodeSharedRequest] + def self.create_request(input) + request = CreateAccessCodeSharedRequest.new + converter = Convert::CustomerToInternalCustomer.new + payment = InternalModels::Payment.new + payment.total_amount = 0 + request.payment = payment + request.customer = converter.do_convert(input) + request.method = Constants::UPDATE_TOKEN_CUSTOMER_METHOD + request.transaction_type = Enums::TransactionType::PURCHASE + request.redirect_url = input.redirect_url + request.cancel_url = input.cancel_url + request + end + + # @param [String] url + # @param [String] api_key + # @param [String] password + # @param [CreateAccessCodeSharedRequest] request + def self.send_request(url, api_key, password, request) + CustResponsiveUpdateMsgProcess.new.do_post(url, api_key, password, request) + end + + # @param [String] response + # @return [CreateCustomerResponse] + def self.make_result(response) + shared_response = CreateAccessCodeSharedResponse.from_json(response) + converter = Convert::Response::AccessCodeSharedToCreateCust.new + converter.do_convert(shared_response) + end + end + + # Create customer with transparent redirect message process + class CustTransparentUpdateMsgProcess + include RestProcess + + # @param [Models::Customer] input + # @return [CreateAccessCodeRequest] + def self.create_request(input) + request = CreateAccessCodeRequest.new + converter = Convert::CustomerToInternalCustomer.new + payment = InternalModels::Payment.new + payment.total_amount = 0 + request.payment = payment + request.customer = converter.do_convert(input) + request.method = Constants::UPDATE_TOKEN_CUSTOMER_METHOD + request.transaction_type = Enums::TransactionType::PURCHASE + request.redirect_url = input.redirect_url + request + end + + # @param [String] url + # @param [String] api_key + # @param [String] password + # @param [CreateAccessCodeRequest] request + def self.send_request(url, api_key, password, request) + CustTransparentUpdateMsgProcess.new.do_post(url, api_key, password, request) + end + + # @param [String] response + # @return [CreateCustomerResponse] + def self.make_result(response) + access_code_response = CreateAccessCodeResponse.from_json(response) + converter = Convert::Response::AccessCodeToCreateCust.new + converter.do_convert(access_code_response) + end + end + end + end +end diff --git a/lib/eway_rapid/message/process/refund_process.rb b/lib/eway_rapid/message/process/refund_process.rb new file mode 100644 index 0000000..bce5a65 --- /dev/null +++ b/lib/eway_rapid/message/process/refund_process.rb @@ -0,0 +1,76 @@ +module EwayRapid + module Message + module RefundProcess + + # Refund message process + class RefundMsgProcess + include RestProcess + + # @param [Models::Refund] refund + # @return [DirectRefundRequest] + def self.create_request(refund) + converter = Convert::Request::RefundToDirectRefundReq.new + converter.do_convert(refund) + end + + # @param [DirectRefundRequest] request + # @return [String] + def self.send_request(url, api_key, password, request) + url = url + '/' + request.refund.original_transaction_id.to_s + '/' + Constants::REFUND_SUB_PATH_METHOD + url = URI.encode(url) + RefundMsgProcess.new.do_post(url, api_key, password, request) + end + + # @param [String] response + # @return [RefundResponse] + def self.make_result(response) + response = DirectRefundResponse.from_json(response) + converter = Convert::Response::DirectRefundToRefundResponse.new + converter.do_convert(response) + end + end + + # cancel authorisation message process + class CancelAuthorisationMsgProcess + include RestProcess + + # @param [Models::Refund] refund + # @return [CancelAuthorisationRequest] + def self.create_request(refund) + set_refund(refund) + request = CancelAuthorisationRequest.new + + # @type [InternalModels::RefundDetails] + refund_detail = refund.refund_details + unless refund_detail + fail 'Refund detail has been null' + end + request.transaction_id = refund_detail.original_transaction_id + request + end + + def self.send_request(url, api_key, password, request) + CancelAuthorisationMsgProcess.new.do_post(url, api_key, password, request) + end + + # @param [String] response + # @return [RefundResponse] + def self.make_result(response) + cancel_response = CancelAuthorisationResponse.from_json(response) + converter = Convert::Response::CancelAuthorisationToRefund.new(get_refund) + converter.do_convert(cancel_response) + end + + # @param [Models::Refund] refund + def self.set_refund(refund) + @refund = refund + end + + # @return [Models::Refund] + def self.get_refund + @refund + end + end + end + end +end diff --git a/lib/eway_rapid/message/process/rest_process.rb b/lib/eway_rapid/message/process/rest_process.rb new file mode 100644 index 0000000..bd805e0 --- /dev/null +++ b/lib/eway_rapid/message/process/rest_process.rb @@ -0,0 +1,87 @@ +module EwayRapid + module Message + module RestProcess + + # Call restful web service with post method + # + # @param [String] url rapid endpoint url + # @param [String] api_key rapid api key + # @param [String] password rapid password + # @param [String] request object to post + def do_post(url, api_key, password, request) + begin + RestClient::Request.execute( + :method => :post, + :url => url, + :user => api_key, + :password => password, + :payload => request.to_json, + :timeout => 9000000, + :headers => { + :accept => :json, + :content_type => :json, + :user_agent => get_user_agent + } + ) + rescue SocketError => e + raise Exceptions::CommunicationFailureException.new(e.to_s) + rescue RestClient::Exception => e + if e.http_code == 401 || e.http_code == 403 || e.http_code == 404 + raise Exceptions::AuthenticationFailureException.new(e.to_s) + else + raise Exceptions::SystemErrorException.new(e.to_s) + end + end + end + + # Call restful web service with get method + # + # @param [String] url rapid endpoint url + # @param [String] api_key rapid api key + # @param [String] password rapid password + def do_get(url, api_key, password) + begin + RestClient::Request.new( + :method => :get, + :url => url, + :user => api_key, + :password => password, + :headers => { + :accept => :json, + :content_type => :json, + :user_agent => get_user_agent + } + ).execute + rescue SocketError => e + raise Exceptions::CommunicationFailureException.new(e.to_s) + rescue RestClient::Exception => e + if e.http_code == 401 || e.http_code == 403 || e.http_code == 404 + raise Exceptions::AuthenticationFailureException.new(e.to_s) + else + raise Exceptions::SystemErrorException.new(e.to_s) + end + end + end + + private + + def get_user_agent + begin + property_array = YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', 'resources', 'rapid-api.yml')) + property_array.each do |h| + if Constants::RAPID_SDK_USER_AGENT_PARAM == h.keys.first + if h[h.keys.first] + return "#{h[h.keys.first]} #{EwayRapid::VERSION}" + else + fail "Rapid endpoint '#{Constants::RAPID_API_RESOURCE}' is invalid." + end + end + end + rescue => e + @logger.error "Error loading user agent parameter #{e}" if @logger + end + '' + end + end + end +end diff --git a/lib/eway_rapid/message/process/transaction_process.rb b/lib/eway_rapid/message/process/transaction_process.rb new file mode 100644 index 0000000..246c549 --- /dev/null +++ b/lib/eway_rapid/message/process/transaction_process.rb @@ -0,0 +1,139 @@ +module EwayRapid + module Message + module TransactionProcess + + # Create transaction with direct payment message process + class TransDirectPaymentMsgProcess + include RestProcess + + # @param [Models::Transaction] input + # @return [DirectPaymentRequest] + def self.create_request(input) + req_convert = Convert::Request::TransactionToDirectPayment.new + req_convert.do_convert(input) + end + + # @param [String] url + # @param [String] api_key + # @param [String] password + # @param [DirectPaymentRequest] request + # @return [String] + def self.send_request(url, api_key, password, request) + TransDirectPaymentMsgProcess.new.do_post(url, api_key, password, request) + end + + # @param [String] response + # @return [CreateTransactionResponse] + def self.make_result(response) + direct_payment_response = DirectPaymentResponse.from_json(response) + converter = Convert::Response::DirectPaymentToCreateTrans.new + converter.do_convert(direct_payment_response) + end + end + + # Create transaction with responsive shared message process + class TransResponsiveSharedMsgProcess + include RestProcess + + # @param [Models::Transaction] input + # @return [CreateAccessCodeSharedRequest]AccessCodeSharedToCreateCust + def self.create_request(input) + req_convert = Convert::Request::TransactionToCreateAccessCodeSharedRequest.new + req_convert.do_convert(input) + end + + # @param [String] url + # @param [String] api_key + # @param [String] password + # @param [CreateAccessCodeSharedRequest] request + # @return [String] + def self.send_request(url, api_key, password, request) + TransResponsiveSharedMsgProcess.new.do_post(url, api_key, password, request) + end + + # @param [String] response + # @return [CreateTransactionResponse] + def self.make_result(response) + access_code_shared_response = CreateAccessCodeSharedResponse.from_json(response) + converter = Convert::Response::AccessCodeSharedToCreateTrans.new + converter.do_convert(access_code_shared_response) + end + end + + # Create transaction with transparent redirect method message process + class TransTransparentRedirectMsgProcess + include RestProcess + + # @param [Models::Transaction] input + # @return [CreateAccessCodeRequest] + def self.create_request(input) + req_convert = Convert::Request::TransactionToCreateAccessCodeRequest.new + req_convert.do_convert(input) + end + + # @param [String] url + # @param [String] api_key + # @param [String] password + # @param [CreateAccessCodeRequest] request + # @return [String] + def self.send_request(url, api_key, password, request) + TransTransparentRedirectMsgProcess.new.do_post(url, api_key, password, request) + end + + # @param [String] response + # @return [CreateTransactionResponse] + def self.make_result(response) + create_access_code_response = CreateAccessCodeResponse.from_json(response) + converter = Convert::Response::AccessCodeToCreateTrans.new + converter.do_convert(create_access_code_response) + end + end + + # Capture payment message process + class CapturePaymentMsgProcess + include RestProcess + + # @param [Models::Transaction] input + # @return [CapturePaymentRequest] + def self.create_request(input) + req_convert = Convert::Request::TransactionToCapturePayment.new + req_convert.do_convert(input) + end + + # @param [String] url + # @param [String] api_key + # @param [String] password + # @param [CapturePaymentRequest] request + # @return [String] + def self.send_request(url, api_key, password, request) + CapturePaymentMsgProcess.new.do_post(url, api_key, password, request) + end + + # @param [String] response + # @return [CreateTransactionResponse] + def self.make_result(response) + capture_payment_response = CapturePaymentResponse.from_json(response) + converter = Convert::Response::CapturePaymentToCreateTransaction.new + converter.do_convert(capture_payment_response) + end + end + + # Query transaction message process + class TransQueryMsgProcess + include RestProcess + + def self.process_post_msg(url, api_key, password) + TransQueryMsgProcess.new.do_get(url, api_key, password) + end + + # @param [String] response + # @return [QueryTransactionResponse] + def self.make_result(response) + transaction_search_resp = TransactionSearchResponse.from_json(response) + converter = Convert::Response::SearchToQueryTrans.new + converter.do_convert(transaction_search_resp) + end + end + end + end +end diff --git a/lib/eway_rapid/models/enums.rb b/lib/eway_rapid/models/enums.rb new file mode 100644 index 0000000..b6bbe33 --- /dev/null +++ b/lib/eway_rapid/models/enums.rb @@ -0,0 +1,126 @@ +module EwayRapid + module Enums + + class BeagleVerifyStatus + NOT_VERIFIED = 'NotVerified' + ATTEMPTED = 'Attempted' + VERIFIED = 'Verified' + FAILED = 'Failed' + + # @param [Integer] index + # @return [String] + def self.calculate_beagle_status(index) + case index + when 0 then NOT_VERIFIED + when 1 then ATTEMPTED + when 2 then VERIFIED + when 3 then FAILED + else + nil + end + end + end + + class FraudAction + NOT_CHALLENGED = 'NotChallenged' + ALLOW = 'Allow' + REVIEW = 'Review' + PRE_AUTH = 'PreAuth' + PROCESSED = 'Processed' + APPROVED = 'Approved' + BLOCK = 'Block' + end + + class PaymentMethod + DIRECT = 'Direct' + RESPONSIVE_SHARED = 'ResponsiveShared' + TRANSPARENT_REDIRECT = 'TransparentRedirect' + WALLET = 'Wallet' + AUTHORISATION = 'Authorisation' + end + + class RequestMethod + PROCESS_PAYMENT = 'ProcessPayment' + CREATE_TOKEN_CUSTOMER = 'CreateTokenCustomer' + UPDATE_TOKEN_CUSTOMER = 'UpdateTokenCustomer' + TOKEN_PAYMENT = 'TokenPayment' + AUTHORISE = 'Authorise' + end + + class ShippingMethod + UNKNOWN = 'Unknown' + LOW_COST = 'LowCost' + DESIGNATED_BY_CUSTOMER = 'DesignatedByCustomer' + INTERNATIONAL = 'International' + MILITARY = 'Military' + NEXT_DAY = 'NextDay' + STORE_PICKUP = 'StorePickup' + TWO_DAY_SERVICE = 'TwoDayService' + THREE_DAY_SERVICE = 'ThreeDayService' + OTHER = 'Other' + end + + class TransactionType + PURCHASE = 'Purchase' + RECURRING = 'Recurring' + MOTO = 'MOTO' + end + + class TransactionFilter + TRANSACTION_ID_INDEX = 1 + ACCESS_CODE_INDEX = 2 + INVOICE_NUMBER_INDEX = 3 + INVOICE_REFERENCE_INDEX = 4 + + attr_accessor :transaction_id, + :access_code, + :invoice_number, + :invoice_reference + + # @return [Integer] + def calculate_index_of_value + index = 0 + count = 0 + unless transaction_id.nil? + index = TRANSACTION_ID_INDEX + count += 1 + end + unless access_code.nil? + index = ACCESS_CODE_INDEX + count += 1 + end + unless invoice_number.nil? + index = INVOICE_NUMBER_INDEX + count += 1 + end + unless invoice_reference.nil? + index = INVOICE_REFERENCE_INDEX + count += 1 + end + if count == 1 + index + else + nil + end + end + end + + class VerifyStatus + UNCHECKED = 'unchecked' + VALID = 'valid' + INVALID = 'invalid' + + # @param [Integer] index + # @return [String] + def self.calculate_status(index) + case index + when 0 then UNCHECKED + when 1 then VALID + when 2 then INVALID + else + nil + end + end + end + end +end diff --git a/lib/eway_rapid/models/internal_models.rb b/lib/eway_rapid/models/internal_models.rb new file mode 100644 index 0000000..d36651f --- /dev/null +++ b/lib/eway_rapid/models/internal_models.rb @@ -0,0 +1,431 @@ +module EwayRapid + module InternalModels + class BeagleVerification + attr_accessor :email + attr_accessor :phone + + def to_json(options={}) + hash = {} + hash[Constants::EMAIL] = email + hash[Constants::PHONE] = phone + hash.to_json + end + + def self.from_json(json) + hash = JSON.parse(json) + from_hash(hash) + end + + def self.from_hash(hash) + beagle_verification = self.new + beagle_verification.email = hash[Constants::EMAIL] + beagle_verification.phone = hash[Constants::PHONE] + beagle_verification + end + end + + class Customer + attr_accessor :token_customer_id + attr_accessor :reference + attr_accessor :title + attr_accessor :first_name + attr_accessor :last_name + attr_accessor :company_name + attr_accessor :job_description + attr_accessor :street1 + attr_accessor :street2 + attr_accessor :city + attr_accessor :state + attr_accessor :postal_code + attr_accessor :country + attr_accessor :email + attr_accessor :phone + attr_accessor :mobile + attr_accessor :comments + attr_accessor :fax + attr_accessor :url + attr_accessor :card_number + attr_accessor :card_start_month + attr_accessor :card_start_year + attr_accessor :card_issue_number + attr_accessor :card_name + attr_accessor :card_expiry_month + attr_accessor :card_expiry_year + attr_accessor :is_active + attr_accessor :card_details + attr_accessor :customer_device_ip + + def self.to_hash(customer) + hash = {} + if customer + hash[Constants::TOKEN_CUSTOMER_ID] = customer.token_customer_id if customer.token_customer_id + hash[Constants::REFERENCE] = customer.reference if customer.reference + hash[Constants::TITLE] = customer.title if customer.title + hash[Constants::FIRST_NAME] = customer.first_name if customer.first_name + hash[Constants::LAST_NAME] = customer.last_name if customer.last_name + hash[Constants::COMPANY_NAME] = customer.company_name if customer.company_name + hash[Constants::JOB_DESCRIPTION] = customer.job_description if customer.job_description + hash[Constants::STREET1] = customer.street1 if customer.street1 + hash[Constants::STREET2] = customer.street2 if customer.street2 + hash[Constants::CITY] = customer.city if customer.city + hash[Constants::STATE] = customer.state if customer.state + hash[Constants::POSTAL_CODE] = customer.postal_code if customer.postal_code + hash[Constants::COUNTRY] = customer.country if customer.country + hash[Constants::EMAIL] = customer.email if customer.email + hash[Constants::PHONE] = customer.phone if customer.phone + hash[Constants::MOBILE] = customer.mobile if customer.mobile + hash[Constants::COMMENTS] = customer.comments if customer.comments + hash[Constants::FAX] = customer.fax if customer.fax + hash[Constants::URL] = customer.url if customer.url + hash[Constants::CARD_DETAILS] = Models::CardDetails.to_hash(customer.card_details) if Models::CardDetails.to_hash(customer.card_details) + hash[Constants::IS_ACTIVE] = customer.is_active if customer.is_active + + hash[Constants::CARD_NUMBER] = customer.card_number if customer.card_number + hash[Constants::CARD_START_MONTH] = customer.card_start_month if customer.card_start_month + hash[Constants::CARD_START_YEAR] = customer.card_start_year if customer.card_start_year + hash[Constants::CARD_ISSUE_NUMBER] = customer.card_issue_number if customer.card_issue_number + hash[Constants::CARD_NAME] = customer.card_name if customer.card_name + hash[Constants::CARD_EXPIRY_MONTH] = customer.card_expiry_month if customer.card_expiry_month + hash[Constants::CARD_EXPIRY_YEAR] = customer.card_expiry_year if customer.card_expiry_year + hash[Constants::CUSTOMER_DEVICE_IP] = customer.customer_device_ip if customer.customer_device_ip + end + hash + end + + def self.from_json(json) + hash = JSON.parse(json) + from_hash(hash) + end + + def self.from_hash(hash) + customer = Customer.new + customer.token_customer_id = hash[Constants::TOKEN_CUSTOMER_ID] + customer.reference = hash[Constants::REFERENCE] + customer.title = hash[Constants::TITLE] + customer.first_name = hash[Constants::FIRST_NAME] + customer.last_name = hash[Constants::LAST_NAME] + customer.company_name = hash[Constants::COMPANY_NAME] + customer.job_description = hash[Constants::JOB_DESCRIPTION] + customer.street1 = hash[Constants::STREET1] + customer.street2 = hash[Constants::STREET2] + customer.city = hash[Constants::CITY] + customer.state = hash[Constants::STATE] + customer.postal_code = hash[Constants::POSTAL_CODE] + customer.country = hash[Constants::COUNTRY] + customer.email = hash[Constants::EMAIL] + customer.phone = hash[Constants::PHONE] + customer.mobile = hash[Constants::MOBILE] + customer.comments = hash[Constants::COMMENTS] + customer.fax = hash[Constants::FAX] + customer.url = hash[Constants::URL] + customer.card_number = hash[Constants::CARD_NUMBER] + customer.card_start_month = hash[Constants::CARD_START_MONTH] + customer.card_start_year = hash[Constants::CARD_START_YEAR] + customer.card_issue_number = hash[Constants::CARD_ISSUE_NUMBER] + customer.card_name = hash[Constants::CARD_NAME] + customer.card_expiry_month = hash[Constants::CARD_EXPIRY_MONTH] + customer.card_expiry_year = hash[Constants::CARD_EXPIRY_YEAR] + customer.is_active = hash[Constants::IS_ACTIVE] + customer.card_details = Models::CardDetails.from_hash(hash[Constants::CARD_DETAILS]) + customer.customer_device_ip = hash[Constants::CUSTOMER_DEVICE_IP] + customer + end + + def self.from_array(array) + options = [] + if array + array.each {|option_hash| + obj = Customer.from_hash(option_hash) + options.push(obj) + } + end + options + end + end + + class Option + attr_accessor :value + + def self.to_hash(option) + hash = {} + if option + hash[Constants::VALUE] = option.value if option.value + end + hash + end + + def self.to_array(array) + options = [] + if array + array.each {|option_hash| + if option_hash + obj = Option.to_hash(option_hash) + options.push(obj) + end + } + end + options + end + + def self.from_json(json) + hash = JSON.parse(json) + from_hash(hash) + end + + def self.from_hash(hash) + option = Option.new + option.value = hash[Constants::VALUE] + option + end + + def self.from_array(array) + options = [] + array.each {|option_hash| + obj = Option.from_hash(option_hash) + options.push(obj) + } + options + end + end + + class Payment + attr_accessor :total_amount + attr_accessor :invoice_number + attr_accessor :invoice_description + attr_accessor :invoice_reference + attr_accessor :currency_code + + def self.to_hash(payment) + hash = {} + if payment + hash[Constants::TOTAL_AMOUNT] = payment.total_amount if payment.total_amount + hash[Constants::INVOICE_NUMBER] = payment.invoice_number if payment.invoice_number + hash[Constants::INVOICE_DESCRIPTION] = payment.invoice_description if payment.invoice_description + hash[Constants::INVOICE_REFERENCE] = payment.invoice_reference if payment.invoice_reference + hash[Constants::CURRENCY_CODE] = payment.currency_code if payment.currency_code + end + hash + end + + def self.from_json(json) + hash = JSON.parse(json) + from_hash(hash) + end + + def self.from_hash(hash) + payment = Payment.new + payment.total_amount = hash[Constants::TOTAL_AMOUNT] + payment.invoice_number = hash[Constants::INVOICE_NUMBER] + payment.invoice_description = hash[Constants::INVOICE_DESCRIPTION] + payment.invoice_reference = hash[Constants::INVOICE_REFERENCE] + payment.currency_code = hash[Constants::CURRENCY_CODE] + payment + end + end + + class RefundDetails + attr_accessor :original_transaction_id + attr_accessor :total_amount + attr_accessor :invoice_number + attr_accessor :invoice_description + attr_accessor :invoice_reference + attr_accessor :currency_code + + def self.to_hash(refund_details) + hash = {} + if refund_details + hash[Constants::ORIGINAL_TRANSACTION_ID] = refund_details.original_transaction_id if refund_details.original_transaction_id + hash[Constants::TOTAL_AMOUNT] = refund_details.total_amount if refund_details.total_amount + hash[Constants::INVOICE_NUMBER] = refund_details.invoice_number if refund_details.invoice_number + hash[Constants::INVOICE_DESCRIPTION] = refund_details.invoice_description if refund_details.invoice_description + hash[Constants::INVOICE_REFERENCE] = refund_details.invoice_reference if refund_details.invoice_reference + hash[Constants::CURRENCY_CODE] = refund_details.currency_code if refund_details.currency_code + end + hash + end + + def self.from_json(json) + hash = JSON.parse(json) + from_hash(hash) + end + + def self.from_hash(hash) + refund_details = RefundDetails.new + refund_details.original_transaction_id = hash[Constants::ORIGINAL_TRANSACTION_ID] + refund_details.total_amount = hash[Constants::TOTAL_AMOUNT] + refund_details.invoice_number = hash[Constants::INVOICE_NUMBER] + refund_details.invoice_description = hash[Constants::INVOICE_DESCRIPTION] + refund_details.invoice_reference = hash[Constants::INVOICE_REFERENCE] + refund_details.currency_code = hash[Constants::CURRENCY_CODE] + refund_details + end + end + + class ShippingAddress + attr_accessor :first_name + attr_accessor :last_name + attr_accessor :street1 + attr_accessor :street2 + attr_accessor :city + attr_accessor :state + attr_accessor :country + attr_accessor :postal_code + attr_accessor :email + attr_accessor :phone + attr_accessor :fax + attr_accessor :shipping_method + + def self.to_hash(shipping_address) + hash = {} + if shipping_address + hash[Constants::FIRST_NAME] = shipping_address.first_name if shipping_address.first_name + hash[Constants::LAST_NAME] = shipping_address.last_name if shipping_address.last_name + hash[Constants::STREET1] = shipping_address.street1 if shipping_address.street1 + hash[Constants::STREET2] = shipping_address.street2 if shipping_address.street2 + hash[Constants::CITY] = shipping_address.city if shipping_address.city + hash[Constants::STATE] = shipping_address.state if shipping_address.state + hash[Constants::COUNTRY] = shipping_address.country if shipping_address.country + hash[Constants::POSTAL_CODE] = shipping_address.postal_code if shipping_address.postal_code + hash[Constants::EMAIL] = shipping_address.email if shipping_address.email + hash[Constants::PHONE] = shipping_address.phone if shipping_address.phone + hash[Constants::FAX] = shipping_address.fax if shipping_address.fax + hash[Constants::SHIPPING_METHOD] = shipping_address.shipping_method if shipping_address.shipping_method + end + hash + end + + def self.from_json(json) + hash = JSON.parse(json) + from_hash(hash) + end + + def self.from_hash(hash) + shipping_address = ShippingAddress.new + shipping_address.first_name = hash[Constants::FIRST_NAME] + shipping_address.last_name = hash[Constants::LAST_NAME] + shipping_address.street1 = hash[Constants::STREET1] + shipping_address.street2 = hash[Constants::STREET2] + shipping_address.city = hash[Constants::CITY] + shipping_address.state = hash[Constants::STATE] + shipping_address.country = hash[Constants::COUNTRY] + shipping_address.postal_code = hash[Constants::POSTAL_CODE] + shipping_address.email = hash[Constants::EMAIL] + shipping_address.phone = hash[Constants::PHONE] + shipping_address.fax = hash[Constants::FAX] + shipping_address.shipping_method = hash[Constants::SHIPPING_METHOD] + shipping_address + end + end + + class Transaction + attr_accessor :customer_note + attr_accessor :authorisation_code + attr_accessor :response_code + attr_accessor :response_message + attr_accessor :invoice_number + attr_accessor :invoice_reference + attr_accessor :total_amount + attr_accessor :transaction_id + attr_accessor :transaction_status + attr_accessor :token_customer_id + attr_accessor :beagle_score + attr_accessor :options + attr_accessor :verification + attr_accessor :customer + attr_accessor :shipping_address + attr_accessor :beagle_verification + attr_accessor :errors + + def to_json(opts={}) + hash = {} + hash[Constants::CUSTOMER_NOTE] = customer_note if customer_note + hash[Constants::AUTHORISATION_CODE] = authorisation_code if authorisation_code + hash[Constants::RESPONSE_CODE] = response_code if response_code + hash[Constants::RESPONSE_MESSAGE] = response_message if response_message + hash[Constants::INVOICE_NUMBER] = invoice_number if invoice_number + hash[Constants::INVOICE_REFERENCE] = invoice_reference if invoice_reference + hash[Constants::TOTAL_AMOUNT] = total_amount if total_amount + hash[Constants::TRANSACTION_ID] = transaction_id if transaction_id + hash[Constants::TRANSACTION_STATUS] = transaction_status if transaction_status + hash[Constants::TOKEN_CUSTOMER_ID] = token_customer_id if token_customer_id + hash[Constants::BEAGLE_SCORE] = beagle_score if beagle_score + hash[Constants::OPTIONS] = options if options + hash[Constants::VERIFICATION] = verification if verification + hash[Constants::CUSTOMER] = customer if customer + hash[Constants::SHIPPING_ADDRESS] = shipping_address if shipping_address + hash[Constants::BEAGLE_VERIFICATION] = beagle_verification if beagle_verification + hash[Constants::ERRORS] = errors if errors + hash.to_json + end + + def self.from_json(json) + hash = JSON.parse(json) + from_hash(hash) + end + + def self.from_hash(hash) + transaction = Transaction.new + transaction.customer_note = hash[Constants::CUSTOMER_NOTE] + transaction.authorisation_code = hash[Constants::AUTHORISATION_CODE] + transaction.response_code = hash[Constants::RESPONSE_CODE] + transaction.response_message = hash[Constants::RESPONSE_MESSAGE] + transaction.invoice_number = hash[Constants::INVOICE_NUMBER] + transaction.invoice_reference = hash[Constants::INVOICE_REFERENCE] + transaction.total_amount = hash[Constants::TOTAL_AMOUNT] + transaction.transaction_id = hash[Constants::TRANSACTION_ID] + transaction.transaction_status = hash[Constants::TRANSACTION_STATUS] + transaction.token_customer_id = hash[Constants::TOKEN_CUSTOMER_ID] + transaction.beagle_score = hash[Constants::BEAGLE_SCORE] + transaction.options = Option.from_array(hash[Constants::OPTIONS]) + transaction.verification = Verification.from_hash(hash[Constants::VERIFICATION]) + transaction.customer = Customer.from_hash(hash[Constants::CUSTOMER]) + transaction.shipping_address = ShippingAddress.from_hash(hash[Constants::SHIPPING_ADDRESS]) + transaction.beagle_verification = BeagleVerification.from_hash(hash[Constants::BEAGLE_VERIFICATION]) + transaction.errors = hash[Constants::ERRORS] + transaction + end + + def self.from_array(array) + transactions = [] + array.each {|transaction_hash| + obj = from_hash(transaction_hash) + transactions.push(obj) + } + transactions + end + end + + class Verification + attr_accessor :cvn + attr_accessor :address + attr_accessor :email + attr_accessor :mobile + attr_accessor :phone + + def to_json(options={}) + hash = {} + hash[Constants::CVN] = cvn if cvn + hash[Constants::ADDRESS] = address if address + hash[Constants::EMAIL] = email if email + hash[Constants::MOBILE] = mobile if mobile + hash[Constants::PHONE] = phone if phone + hash.to_json + end + + def self.from_json(json) + hash = JSON.parse(json) + from_hash(hash) + end + + def self.from_hash(hash) + verification = Verification.new + verification.cvn = hash[Constants::CVN] + verification.address = hash[Constants::ADDRESS] + verification.email = hash[Constants::EMAIL] + verification.mobile = hash[Constants::MOBILE] + verification.phone = hash[Constants::PHONE] + verification + end + end + end +end diff --git a/lib/eway_rapid/models/models.rb b/lib/eway_rapid/models/models.rb new file mode 100644 index 0000000..4366af9 --- /dev/null +++ b/lib/eway_rapid/models/models.rb @@ -0,0 +1,334 @@ +module EwayRapid + module Models + + # Customer's address + class Address + + # First line of the street address + attr_accessor :street1 + + # Second line of the street address + attr_accessor :street2 + + attr_accessor :city + attr_accessor :state + + # Two letter ISO 3166-1 alpha-2 code + attr_accessor :country + + attr_accessor :postal_code + end + + # Card information + class CardDetails + attr_accessor :name + attr_accessor :number + attr_accessor :expiry_month + attr_accessor :expiry_year + attr_accessor :start_month + attr_accessor :start_year + attr_accessor :issue_number + attr_accessor :cvn + + def self.to_hash(card_details) + { Constants::NAME => card_details.name, + Constants::NUMBER => card_details.number, + Constants::EXPIRY_MONTH => card_details.expiry_month, + Constants::EXPIRY_YEAR => card_details.expiry_year, + Constants::START_MONTH => card_details.start_month, + Constants::START_YEAR => card_details.start_year, + Constants::ISSUE_NUMBER => card_details.issue_number, + Constants::CVN => card_details.cvn } if card_details + end + + def self.from_json(json) + hash = JSON.parse(json) + from_hash(hash) + end + + def self.from_hash(hash) + unless hash.nil? + card_details = CardDetails.new + card_details.name = hash[Constants::NAME] + card_details.number = hash[Constants::NUMBER] + card_details.expiry_month = hash[Constants::EXPIRY_MONTH] + card_details.expiry_year = hash[Constants::EXPIRY_YEAR] + card_details.start_month = hash[Constants::START_MONTH] + card_details.start_year = hash[Constants::START_YEAR] + card_details.issue_number = hash[Constants::ISSUE_NUMBER] + card_details.cvn = hash[Constants::CVN] + card_details + end + end + end + + # Customer details + class Customer + attr_accessor :token_customer_id + attr_accessor :reference + attr_accessor :title + attr_accessor :first_name + attr_accessor :last_name + attr_accessor :company_name + attr_accessor :job_description + attr_accessor :address + attr_accessor :phone + attr_accessor :mobile + attr_accessor :email + attr_accessor :fax + attr_accessor :url + attr_accessor :comments + attr_accessor :card_details + attr_accessor :redirect_url + attr_accessor :cancel_url + attr_accessor :customer_device_ip + end + + # Item information + class LineItem + + # The stock keeping unit used to identify this line item + attr_accessor :sku + attr_accessor :description + attr_accessor :quantity + + # The unit cost of this line item in cents + attr_accessor :unit_cost + + # The tax amount that applies to this line item in cents + attr_accessor :tax + + # The total amount (including tax) charged for this line item in the cents + attr_accessor :total + + # Set the line item's values so that the total and tax add up + # correctly + # + # @param [Integer] unit_cost + # @param [Integer] unit_tax + # @param [Integer] quantity + def calculate(unit_cost, unit_tax, quantity) + if unit_cost && unit_tax && quantity + tax = unit_tax * quantity + quantity * unit_cost + tax + end + end + + def self.to_hash(line_item) + { Constants::SKU => line_item.sku, + Constants::DESCRIPTION => line_item.description, + Constants::QUANTITY => line_item.quantity, + Constants::UNIT_COST => line_item.unit_cost, + Constants::TAX => line_item.tax, + Constants::TOTAL => line_item.total } if line_item + end + + def self.to_array(array) + line_items = [] + if array + array.each {|line_item_hash| + obj = to_hash(line_item_hash) + line_items.push(obj) + } + end + line_items + end + + def self.from_json(json) + hash = JSON.parse(json) + from_hash(hash) + end + + def self.from_hash(hash) + line_item = LineItem.new + line_item.sku = hash[Constants::SKU] + line_item.description = hash[Constants::DESCRIPTION] + line_item.quantity = hash[Constants::QUANTITY] + line_item.unit_cost = hash[Constants::UNIT_COST] + line_item.tax = hash[Constants::TAX] + line_item.total = hash[Constants::TOTAL] + line_item + end + + def self.from_array(array) + line_items = Array.new + array.each {|line_item_hash| + obj = from_hash(line_item_hash) + line_items.push(obj) + } + line_items + end + end + + # Details of the payment + class PaymentDetails + + # The total amount of the transaction in cents + attr_accessor :total_amount + + attr_accessor :invoice_number + attr_accessor :invoice_description + attr_accessor :invoice_reference + + # The ISO 4217 3 character code of the currency that the transaction is + # to be processed in (e.g. 'AUD') + attr_accessor :currency_code + end + + # Combines together all the bank/gateway specific status information for a + # transaction + class ProcessingDetails + + # The bank's authorization code for the transaction + attr_accessor :authorisation_code + + # The bank's Response code + attr_accessor :response_code + + # The bank or gateway's Response message + attr_accessor :response_message + end + + # Contains the high level properties required to process a refund + # (or Authorisation Cancel) + class Refund + attr_accessor :customer + attr_accessor :shipping_details + attr_accessor :refund_details + attr_accessor :line_items + attr_accessor :options + attr_accessor :device_id + attr_accessor :partner_id + end + + # Contains the Shipping related information for a transaction + class ShippingDetails + attr_accessor :first_name + attr_accessor :last_name + attr_accessor :shipping_method + attr_accessor :shipping_address + attr_accessor :email + attr_accessor :phone + attr_accessor :fax + end + + # The details of a transaction that will be processed either via the responsive + # shared page, by transparent redirect, by Direct, or one that is captured from + # a previous Authorisation transaction + class Transaction + + # The type of transaction being performed - use Enums::TransactionType + attr_accessor :transaction_type + + # Set to true to capture funds immediately, false to authorise only + attr_accessor :capture + + # Customer details for the transaction + attr_accessor :customer + + # Shipping details fo the transaction + attr_accessor :shipping_details + + # Payment details for the transaction + attr_accessor :payment_details + + # Array of line items for the transaction + attr_accessor :line_items + + # Array of options to pass to eWAY + attr_accessor :options + + # The identification name/number for the device or application processing the transaction + attr_accessor :device_id + + # The partner ID generated from an eWAY partner agreement + attr_accessor :partner_id + + # The wallet ID of a third party wallet used for a payment + attr_accessor :third_party_wallet_id + + # The Transaction ID of an authorisation to capture + attr_accessor :auth_transaction_id + + # The URL that the shared page redirects to after a payment is processed + # (transparent redirect & responsive shared page only) + attr_accessor :redirect_url + + # The URL that the shared page redirects to if a customer cancels the transaction + # (responsive shared page only) + attr_accessor :cancel_url + + # Setting this to +true+ will process a PayPal Checkout payment. + attr_accessor :checkout_payment + + # The URL that the customer is to be returned to after logging in to their PayPal account. + # (transparent redirect & responsive shared page with PayPal Checkout only) + attr_accessor :checkout_url + + # Set the theme of the Responsive Shared Page from 12 available themes + attr_accessor :custom_view + + # Short text description to be placed under the logo on the Responsive Shared Page + attr_accessor :header_text + + # Language code determines the language that the shared page will be displayed in. + # One of: EN (English, default), ES (Spanish) + attr_accessor :language + + # When set to false, cardholders will be able to edit the information on the Responsive Shared Page + attr_accessor :customer_read_only + + # Set whether the customer's phone number should be confirmed using Beagle Verify + attr_accessor :verify_customer_phone + + # Set whether the customer's email should be confirmed using Beagle Verify + attr_accessor :verify_customer_email + + # The URL of the merchant's logo to display on the Responsive Shared Page + attr_accessor :logo_url + + alias_method :customer_read_only?, :customer_read_only + alias_method :checkout_payment?, :checkout_payment + alias_method :verify_customer_phone?, :verify_customer_phone + alias_method :verify_customer_email?, :verify_customer_email + + def initialize + @capture = true + end + end + + # Contains the status information for a transaction + class TransactionStatus + attr_accessor :transaction_id + attr_accessor :total + attr_accessor :status + attr_accessor :captured + attr_accessor :beagle_score + attr_accessor :fraud_action + attr_accessor :verification_result + attr_accessor :processing_details + + alias_method :status?, :status + end + + # Contains the result of all the Beagle and Payment provider verification + class VerificationResult + # Currently unused + attr_accessor :cvn + # Currently unused + attr_accessor :address + # Currently unused + attr_accessor :email + # Currently unused + attr_accessor :mobile + # Currently unused + attr_accessor :phone + + # The result of the Beagle Verify email verification + attr_accessor :beagle_email + + # The result of the Beagle Verify phone verification + attr_accessor :beagle_phone + end + end +end diff --git a/lib/eway_rapid/output/create_transaction_response.rb b/lib/eway_rapid/output/create_transaction_response.rb new file mode 100644 index 0000000..5e9772d --- /dev/null +++ b/lib/eway_rapid/output/create_transaction_response.rb @@ -0,0 +1,24 @@ +module EwayRapid + # Create transaction response + class CreateTransactionResponse < ResponseOutput + + # The transaction as returned by Rapid API. + attr_accessor :transaction + + # Contains transaction status information + attr_accessor :transaction_status + + # URL to the Responsive Shared Page that the cardholder's browser should + # be redirected to (Only for Responsive Shared) + attr_accessor :shared_payment_url + + # URL that the merchant's credit card form should post to to complete + # payment (Only for Transparent Redirect) + attr_accessor :form_action_url + + # An AccessCode for this transaction (Used with Transparent Redirect + # and Responsive Shared) + attr_accessor :access_code + + end +end diff --git a/lib/eway_rapid/output/query_customer_response.rb b/lib/eway_rapid/output/query_customer_response.rb new file mode 100644 index 0000000..88ad20b --- /dev/null +++ b/lib/eway_rapid/output/query_customer_response.rb @@ -0,0 +1,25 @@ +module EwayRapid + # Query customer response data + class QueryCustomerResponse < ResponseOutput + attr_accessor :token_customer_id + attr_accessor :state + attr_accessor :postal_code + attr_accessor :email + attr_accessor :reference + attr_accessor :title + attr_accessor :first_name + attr_accessor :last_name + attr_accessor :company_name + attr_accessor :job_description + attr_accessor :street1 + attr_accessor :street2 + attr_accessor :city + attr_accessor :phone + attr_accessor :mobile + attr_accessor :url + attr_accessor :card_detail + attr_accessor :country + attr_accessor :comments + attr_accessor :fax + end +end diff --git a/lib/eway_rapid/output/query_transaction_response.rb b/lib/eway_rapid/output/query_transaction_response.rb new file mode 100644 index 0000000..553c3ac --- /dev/null +++ b/lib/eway_rapid/output/query_transaction_response.rb @@ -0,0 +1,16 @@ +module EwayRapid + # Query transaction response + class QueryTransactionResponse < ResponseOutput + + # The Request as returned by Rapid API. Where a token customer is created as + # result of the transaction, then the Customer in this type will contain the + # Customer Token ID + attr_accessor :transaction + + # Contains transaction status information + attr_accessor :transaction_status + + # AccessCode for this transaction + attr_accessor :access_code + end +end diff --git a/lib/eway_rapid/output/refund_response.rb b/lib/eway_rapid/output/refund_response.rb new file mode 100644 index 0000000..eada165 --- /dev/null +++ b/lib/eway_rapid/output/refund_response.rb @@ -0,0 +1,9 @@ +module EwayRapid + # Refund response + class RefundResponse < ResponseOutput + attr_accessor :refund + + # Contains transaction status information + attr_accessor :transaction_status + end +end diff --git a/lib/eway_rapid/output/response_output.rb b/lib/eway_rapid/output/response_output.rb new file mode 100644 index 0000000..48ef107 --- /dev/null +++ b/lib/eway_rapid/output/response_output.rb @@ -0,0 +1,14 @@ +module EwayRapid + # Base class for the output data class inherits + class ResponseOutput + + # List of all validation, processing, fraud or system errors that occurred + # when processing this request. + attr_accessor :errors + + def initialize(*args, &block) + super + @errors = [] + end + end +end diff --git a/lib/eway_rapid/rapid_client.rb b/lib/eway_rapid/rapid_client.rb new file mode 100644 index 0000000..a90bb40 --- /dev/null +++ b/lib/eway_rapid/rapid_client.rb @@ -0,0 +1,444 @@ +module EwayRapid + + # This class abstracts the Rapid API 3.1 functions so that it can be consumed + # by Ruby applications + # + # @author eWAY + class RapidClient + + # @param [String] api_key eWAY Rapid API key + # @param [String] password eWAY Rapid API password + # @param [String] rapid_endpoint eWAY Rapid endpoint - either Sandbox or Production + 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 + + # Changes the API Key and Password the Client is configured to use + # + # @param [String] api_key eWAY Rapid API key + # @param [String] password eWAY Rapid API password + def set_credentials(api_key, password) + @api_key = api_key + @password = password + + validate_api_param + end + + # Creates a transaction either using an authorisation, the responsive shared + # page, transparent redirect, or direct as the source of funds + # + # @param [Enums::PaymentMethod] payment_method Describes where the card details will be coming from for this transaction (Direct, Responsive Shared, Transparent Redirect etc) + # @param [Models::Transaction] transaction Request containing the transaction details + # @return [CreateTransactionResponse] CreateTransactionResponse + def create_transaction(payment_method, transaction) + unless get_valid? + return make_response_with_exception(Exceptions::APIKeyInvalidException.new('API key, password or Rapid endpoint missing or invalid'), CreateTransactionResponse) + end + begin + case payment_method + when Enums::PaymentMethod::DIRECT + url = @rapid_endpoint + Constants::DIRECT_PAYMENT_METHOD_NAME + Constants::JSON_SUFFIX + + request = Message::TransactionProcess::TransDirectPaymentMsgProcess.create_request(transaction) + response = Message::TransactionProcess::TransDirectPaymentMsgProcess.send_request(url, @api_key, @password, request) + Message::TransactionProcess::TransDirectPaymentMsgProcess.make_result(response) + when Enums::PaymentMethod::RESPONSIVE_SHARED + url = @rapid_endpoint + Constants::RESPONSIVE_SHARED_METHOD_NAME + Constants::JSON_SUFFIX + + request = Message::TransactionProcess::TransResponsiveSharedMsgProcess.create_request(transaction) + response = Message::TransactionProcess::TransResponsiveSharedMsgProcess.send_request(url, @api_key, @password, request) + Message::TransactionProcess::TransResponsiveSharedMsgProcess.make_result(response) + when Enums::PaymentMethod::TRANSPARENT_REDIRECT + url = @rapid_endpoint + Constants::TRANSPARENT_REDIRECT_METHOD_NAME + Constants::JSON_SUFFIX + + request = Message::TransactionProcess::TransTransparentRedirectMsgProcess.create_request(transaction) + response = Message::TransactionProcess::TransTransparentRedirectMsgProcess.send_request(url, @api_key, @password, request) + Message::TransactionProcess::TransTransparentRedirectMsgProcess.make_result(response) + when Enums::PaymentMethod::WALLET + if transaction.capture + url = @rapid_endpoint + Constants::DIRECT_PAYMENT_METHOD_NAME + Constants::JSON_SUFFIX + + request = Message::TransactionProcess::TransDirectPaymentMsgProcess.create_request(transaction) + response = Message::TransactionProcess::TransDirectPaymentMsgProcess.send_request(url, @api_key, @password, request) + Message::TransactionProcess::TransDirectPaymentMsgProcess.make_result(response) + else + url = @rapid_endpoint + Constants::CAPTURE_PAYMENT_METHOD + + request = Message::TransactionProcess::CapturePaymentMsgProcess.create_request(transaction) + response = Message::TransactionProcess::CapturePaymentMsgProcess.send_request(url, @api_key, @password, request) + Message::TransactionProcess::CapturePaymentMsgProcess.make_result(response) + end + when Enums::PaymentMethod::AUTHORISATION + url = @rapid_endpoint + Constants::CAPTURE_PAYMENT_METHOD + + request = Message::TransactionProcess::CapturePaymentMsgProcess.create_request(transaction) + response = Message::TransactionProcess::CapturePaymentMsgProcess.send_request(url, @api_key, @password, request) + Message::TransactionProcess::CapturePaymentMsgProcess.make_result(response) + else + make_response_with_exception(Exceptions::ParameterInvalidException.new('Unsupported payment type'), CreateTransactionResponse) + end + rescue => e + @logger.error(e.to_s) if @logger + make_response_with_exception(e, CreateTransactionResponse) + end + end + + # Gets transaction details given an eWAY Transaction ID + # + # @param [Integer] transaction_id eWAY Transaction ID + # @return [QueryTransactionResponse] + def query_transaction_by_id(transaction_id) + query_transaction_by_access_code(transaction_id.to_s) + end + + # Gets transaction details given an access code + # + # @param [String] access_code Access code for the transaction to query + # @return [QueryTransactionResponse] + def query_transaction_by_access_code(access_code) + query_transaction_with_path(access_code, Constants::TRANSACTION_METHOD) + end + + # Query a transaction by one of four properties transaction id, access + # code, invoice number, invoice reference + # + # @param [Enums::TransactionFilter] filter Filter definition for searching + 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 + + # Refunds all or part of a transaction + # + # @param [Models::Refund] refund contains information to refund + # @return [RefundResponse] + 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 = @rapid_endpoint + 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 + + # Cancel a non-captured transaction (an authorisation) + # + # @param [Models::Refund] refund contains transaction to cancel + # @return [RefundResponse] + 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 = @rapid_endpoint + 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 + + # Creates a token customer to store card details in the secure eWAY Vault + # for charging later + # + # @param [Enums::PaymentMethod] payment_method Describes where the card details will be coming from for this transaction (Direct, Responsive Shared, Transparent Redirect etc). + # @param [Models::Customer] customer The customer's details + # @return [CreateCustomerResponse] + def create_customer(payment_method, customer) + unless get_valid? + return make_response_with_exception(Exceptions::APIKeyInvalidException.new('API key, password or Rapid endpoint missing or invalid'), CreateCustomerResponse) + end + begin + case payment_method + when Enums::PaymentMethod::DIRECT + url = @rapid_endpoint + Constants::DIRECT_PAYMENT_METHOD_NAME + Constants::JSON_SUFFIX + + request = Message::CustomerProcess::CustDirectPaymentMsgProcess.create_request(customer) + response = Message::CustomerProcess::CustDirectPaymentMsgProcess.send_request(url, @api_key, @password, request) + Message::CustomerProcess::CustDirectPaymentMsgProcess.make_result(response) + when Enums::PaymentMethod::RESPONSIVE_SHARED + url = @rapid_endpoint + Constants::RESPONSIVE_SHARED_METHOD_NAME + Constants::JSON_SUFFIX + + request = Message::CustomerProcess::CustResponsiveSharedMsgProcess.create_request(customer) + response = Message::CustomerProcess::CustResponsiveSharedMsgProcess.send_request(url, @api_key, @password, request) + Message::CustomerProcess::CustResponsiveSharedMsgProcess.make_result(response) + when Enums::PaymentMethod::TRANSPARENT_REDIRECT + url = @rapid_endpoint + Constants::TRANSPARENT_REDIRECT_METHOD_NAME + Constants::JSON_SUFFIX + + request = Message::CustomerProcess::CustTransparentRedirectMsgProcess.create_request(customer) + response = Message::CustomerProcess::CustTransparentRedirectMsgProcess.send_request(url, @api_key, @password, request) + Message::CustomerProcess::CustTransparentRedirectMsgProcess.make_result(response) + else + make_response_with_exception(Exceptions::ParameterInvalidException.new('Unsupported payment type'), CreateCustomerResponse) + end + rescue => e + @logger.error(e.to_s) if @logger + make_response_with_exception(e, CreateCustomerResponse) + end + end + + # Updates an existing token customer for the merchant in their eWAY account. + # + # @param [Enums::PaymentMethod] payment_method Describes where the card details will be coming from for this transaction (Direct, Responsive Shared, Transparent Redirect etc). + # @param [Models::Customer] customer The customer's details + # @return [CreateCustomerResponse] + def update_customer(payment_method, customer) + unless get_valid? + return make_response_with_exception(Exceptions::APIKeyInvalidException.new('API key, password or Rapid endpoint missing or invalid'), CreateCustomerResponse) + end + begin + case payment_method + when Enums::PaymentMethod::DIRECT + url = @rapid_endpoint + Constants::DIRECT_PAYMENT_METHOD_NAME + Constants::JSON_SUFFIX + request = Message::CustomerProcess::CustDirectUpdateMsgProcess.create_request(customer) + response = Message::CustomerProcess::CustDirectUpdateMsgProcess.send_request(url, @api_key, @password, request) + Message::CustomerProcess::CustDirectUpdateMsgProcess.make_result(response) + when Enums::PaymentMethod::RESPONSIVE_SHARED + url = @rapid_endpoint + Constants::RESPONSIVE_SHARED_METHOD_NAME + Constants::JSON_SUFFIX + + request = Message::CustomerProcess::CustResponsiveUpdateMsgProcess.create_request(customer) + response = Message::CustomerProcess::CustResponsiveUpdateMsgProcess.send_request(url, @api_key, @password, request) + Message::CustomerProcess::CustResponsiveUpdateMsgProcess.make_result(response) + when Enums::PaymentMethod::TRANSPARENT_REDIRECT + url = @rapid_endpoint + Constants::TRANSPARENT_REDIRECT_METHOD_NAME + Constants::JSON_SUFFIX + + request = Message::CustomerProcess::CustTransparentUpdateMsgProcess.create_request(customer) + response = Message::CustomerProcess::CustTransparentUpdateMsgProcess.send_request(url, @api_key, @password, request) + Message::CustomerProcess::CustTransparentUpdateMsgProcess.make_result(response) + else + return make_response_with_exception(Exceptions::ParameterInvalidException.new('Unsupported payment type'), CreateCustomerResponse) + end + rescue => e + @logger.error(e.to_s) if @logger + make_response_with_exception(e, CreateCustomerResponse) + end + end + + # Returns the details of a Token Customer. This includes the masked card information + # for displaying in a UI + # + # @param [Integer] token_customer_id eWAY Token Customer ID to look up. + # @return [QueryCustomerResponse] + 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 = @rapid_endpoint + 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 + + # Translate an error code to a user friendly message + # + # @param [String] code The code to translate + # @param [String] language The 2 letter code for the language to translate to (only en at this time) + # @return [String] Error message + def self.user_display_message(code, language = 'en') + find_error_code(code, language) + end + + # Gets the valid status of this Rapid client + # + # @return Rapid Client status + def get_valid? + @is_valid + end + + # Returns all errors related to the query request of this client + # + # @return List of error codes + def get_errors + @list_error || [] + end + + private + + # Perform a transaction query with the given path + # + # @param [String] request the transaction identifier to query + # @param [String] request_path the path to use for the query + # @return [QueryTransactionResponse] + def query_transaction_with_path(request, request_path) + unless @is_valid + return make_response_with_exception(Exceptions::APIKeyInvalidException.new('API key, password or Rapid endpoint missing or invalid'), QueryTransactionResponse) + end + begin + if request.nil? || request == '' + url = @rapid_endpoint + request_path + '/' + '0' + else + url = @rapid_endpoint + request_path + '/' + request + end + url = URI.encode(url) + + response = Message::TransactionProcess::TransQueryMsgProcess.process_post_msg(url, @api_key, @password) + Message::TransactionProcess::TransQueryMsgProcess.make_result(response) + rescue => e + @logger.error(e.to_s) if @logger + make_response_with_exception(e, QueryTransactionResponse) + end + end + + # Finds an error code from the properties file + # + # @param [String] code + # @return [String] the error code + def self.find_error_code(code, language) + error_file = 'err_code_resource_' + language + '.yml' + begin + property_array = YAML.load_file(File.join(File.dirname(__FILE__), 'resources', error_file)) + property_array.each do |h| + if code == h.keys.first + return h[h.keys.first] + end + end + return code + rescue + @logger.error "Load resource from file: #{error_file} error" if @logger + return '' + end + end + + # Validates the Rapid API key, password and endpoint + def validate_api_param + set_valid(true) + if @api_key.nil? || @api_key.empty? || @password.nil? || @password.empty? + add_error_code(Constants::API_KEY_INVALID_ERROR_CODE) + set_valid(false) + end + if @rapid_endpoint.nil? || @rapid_endpoint.empty? + add_error_code(Constants::LIBRARY_NOT_HAVE_ENDPOINT_ERROR_CODE) + set_valid(false) + end + if @is_valid + begin + parser_endpoint_to_web_url + if !@list_error.nil? + @list_error.clear + end + set_valid(true) + @logger.info "Initiate client [#{@rapid_endpoint}] successful!" if @logger + rescue => e + @logger.error "Error setting Rapid endpoint #{e.backtrace.inspect}" if @logger + set_valid(false) + add_error_code(Constants::LIBRARY_NOT_HAVE_ENDPOINT_ERROR_CODE) + end + else + @logger.warn "Invald parameter passed to Rapid client" if @logger + end + end + + # Converts an endpoint string to a URL + def parser_endpoint_to_web_url + # @type [String] + prop_name = nil + if Constants::RAPID_ENDPOINT_PRODUCTION.casecmp(@rapid_endpoint).zero? + prop_name = Constants::GLOBAL_RAPID_PRODUCTION_REST_URL_PARAM + elsif Constants::RAPID_ENDPOINT_SANDBOX.casecmp(@rapid_endpoint).zero? + prop_name = Constants::GLOBAL_RAPID_SANDBOX_REST_URL_PARAM + end + if prop_name.nil? + set_web_url(@rapid_endpoint) + else + property_array = YAML.load_file(File.join(File.dirname(__FILE__), 'resources', 'rapid-api.yml')) + property_array.each do |h| + if prop_name.casecmp(h.keys.first).zero? + set_web_url(h[h.keys.first]) + end + end + if @web_url.nil? + fail Exception, "The endpoint #{prop_name} is invalid." + end + end + # verify_endpoint_url(@web_url) # this is unreliable + end + + # Checks the Rapid endpoint url + # + # @param [String] web_url + def verify_endpoint_url(web_url) + begin + resource = RestClient::Resource.new web_url + resource.get + rescue RestClient::Exception => e + if e.http_code == 404 + set_valid(false) + end + end + end + + # @param [String] error_code + def add_error_code(error_code) + if error_code + if @list_error.nil? + @list_error = [] + @list_error.push(error_code) + else + unless @list_error.include? error_code + @list_error.push(error_code) + end + end + end + end + + # @param [Boolean] is_valid + def set_valid(is_valid) + @is_valid = is_valid + end + + # @param [String] web_url + def set_web_url(web_url) + @web_url = web_url + end + + # @param [RapidSdkException] rapid_exception Exception to output + # @param [ResponseOutput] klass Output class to use for response + # @return [ResponseOutput] + def make_response_with_exception(rapid_exception, klass) + response_output = klass.new + response_output.errors.push(rapid_exception.error_code) + response_output + end + end +end diff --git a/lib/eway_rapid/rapid_logger.rb b/lib/eway_rapid/rapid_logger.rb new file mode 100644 index 0000000..8d8b1da --- /dev/null +++ b/lib/eway_rapid/rapid_logger.rb @@ -0,0 +1,40 @@ +module EwayRapid + class RapidLogger + + # Creates a new Logger instance for logging + # + # @param [String] log_dev a filename (String) or IO object like +STDOUT+, +STDERR+ + def self.init(log_dev) + @logger = Logger.new(log_dev) + @logger + end + + # @return [Logger] + def self.logger + conf_log || @logger + end + + # Check for a logging configuration in rapid_log_config.yml + def self.conf_log + prop_name = 'logdev' + property_array = YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', 'rapid_log_config.yml')) + property_array.each do |h| + if prop_name.casecmp(h.keys.first).zero? + log_dev = h[h.keys.first] + if !log_dev.nil? && log_dev != '' + if log_dev.casecmp('stdout').zero? + return Logger.new(STDOUT) + elsif log_dev.casecmp('stderr').zero? + return Logger.new(STDERR) + else + return Logger.new(log_dev) + end + end + end + end + nil + rescue + nil + end + end +end diff --git a/lib/eway_rapid/resources/err_code_resource_en.yml b/lib/eway_rapid/resources/err_code_resource_en.yml new file mode 100644 index 0000000..1146c59 --- /dev/null +++ b/lib/eway_rapid/resources/err_code_resource_en.yml @@ -0,0 +1,237 @@ +--- +# Server error code +- V6000: Validation error +- V6001: Invalid CustomerIP +- V6002: Invalid DeviceID +- V6003: Invalid Request PartnerID +- V6004: Invalid Request Method +- V6010: Invalid TransactionType, account not certified for eCome only MOTO or Recurring available +- V6011: Invalid Payment TotalAmount +- V6012: Invalid Payment InvoiceDescription +- V6013: Invalid Payment InvoiceNumber +- V6014: Invalid Payment InvoiceReference +- V6015: Invalid Payment CurrencyCode +- V6016: Payment Required +- V6017: Payment CurrencyCode Required +- V6018: Unknown Payment CurrencyCode +- V6021: EWAY_CARDHOLDERNAME Required +- V6022: EWAY_CARDNUMBER Required +- V6023: EWAY_CARDCVN Required +- V6033: Invalid Expiry Date +- V6034: Invalid Issue Number +- V6035: Invalid Valid From Date +- V6040: Invalid TokenCustomerID +- V6041: Customer Required +- V6042: Customer FirstName Required +- V6043: Customer LastName Required +- V6044: Customer CountryCode Required +- V6045: Customer Title Required +- V6046: TokenCustomerID Required +- V6047: RedirectURL Required +- V6048: CheckoutURL Required when CheckoutPayment specified +- V6049: Invalid Checkout URL +- V6051: Invalid Customer FirstName +- V6052: Invalid Customer LastName +- V6053: Invalid Customer CountryCode +- V6058: Invalid Customer Title +- V6059: Invalid RedirectURL +- V6060: Invalid TokenCustomerID +- V6061: Invalid Customer Reference +- V6062: Invalid Customer CompanyName +- V6063: Invalid Customer JobDescription +- V6064: Invalid Customer Street1 +- V6065: Invalid Customer Street2 +- V6066: Invalid Customer City +- V6067: Invalid Customer State +- V6068: Invalid Customer PostalCode +- V6069: Invalid Customer Email +- V6070: Invalid Customer Phone +- V6071: Invalid Customer Mobile +- V6072: Invalid Customer Comments +- V6073: Invalid Customer Fax +- V6074: Invalid Customer URL +- V6075: Invalid ShippingAddress FirstName +- V6076: Invalid ShippingAddress LastName +- V6077: Invalid ShippingAddress Street1 +- V6078: Invalid ShippingAddress Street2 +- V6079: Invalid ShippingAddress City +- V6080: Invalid ShippingAddress State +- V6081: Invalid ShippingAddress PostalCode +- V6082: Invalid ShippingAddress Email +- V6083: Invalid ShippingAddress Phone +- V6084: Invalid ShippingAddress Country +- V6085: Invalid ShippingAddress ShippingMethod +- V6086: Invalid ShippingAddress Fax +- V6091: Unknown Customer CountryCode +- V6092: Unknown ShippingAddress CountryCode +- V6100: Invalid EWAY_CARDNAME +- V6101: Invalid EWAY_CARDEXPIRYMONTH +- V6102: Invalid EWAY_CARDEXPIRYYEAR +- V6103: Invalid EWAY_CARDSTARTMONTH +- V6104: Invalid EWAY_CARDSTARTYEAR +- V6105: Invalid EWAY_CARDISSUENUMBER +- V6106: Invalid EWAY_CARDCVN +- V6107: Invalid EWAY_ACCESSCODE +- V6108: Invalid CustomerHostAddress +- V6109: Invalid UserAgent +- V6110: Invalid EWAY_CARDNUMBER +- V6111: Unauthorised API Access, Account Not PCI Certified +- V6112: Redundant card details other than expiry year and month +- V6113: Invalid transaction for refund +- V6114: Gateway validation error +- V6115: Invalid DirectRefundRequest, Transaction ID +- V6116: Invalid card data on original TransactionID +- V6117: Invalid CreateAccessCodeSharedRequest, FooterText +- V6118: Invalid CreateAccessCodeSharedRequest, HeaderText +- V6119: Invalid CreateAccessCodeSharedRequest, Language +- V6120: Invalid CreateAccessCodeSharedRequest, LogoUrl +- V6121: Invalid TransactionSearch, Filter Match Type +- V6122: Invalid TransactionSearch, Non numeric Transaction ID +- V6123: Invalid TransactionSearch,no TransactionID or AccessCode specified +- V6124: Invalid Line,the line items have been provided however totals do not match TotalAmount field +- V6125: Selected Payment Type not enabled +- V6126: Invalid encrypted card number, decryption failed +- V6127: Invalid encrypted cvn, decryption failed +- V6128: Invalid Method for Payment Type +- V6129: Transaction has not been authorised for Capture/Cancellation +- V6130: Generic customer information error +- V6131: Generic shipping information error +- V6132: Transaction has already been completed or voided, operation not permitted +- V6133: Checkout not available for Payment Type +- V6134: Invalid Auth Transaction ID for Capture/Void +- V6135: PayPal Error Processing Refund +- V6140: Merchant account is suspended +- V6141: Invalid PayPal account details or API signature +- V6142: Authorise not available for Bank/Branch +- V6150: Invalid Refund Amount +- V6151: Refund amount greater than original transaction +- V6152: Original transaction already refunded for total amount +- V6153: Card type not support by merchant +- V6160: Encryption Method Not Supported +- V6165: Invalid Visa Checkout data or decryption failed +# Third party error code +- S5000: System Error +- S5011: PayPal Connection Error +- S5012: PayPal Settings Error +- S5085: Started 3dSecure +- S5086: Routed 3dSecure +- S5087: Completed 3dSecure +- S5088: PayPal Transaction Created +- S5099: Incomplete (Access Code in progress/incomplete) +- S5010: Unknown error returned by gateway +# internal error code +- S9990: Library does not have Endpoint initialised, or not initialise to a URL +- S9991: Library does not have PublicAPI key initialised, or Key is Invalid +- S9992: Communication error with Rapid API +- S9993: Authentication error with Rapid API +- S9994: Internal system error communicating with Rapid API +- S9995: Internal SDK Error, Bad Parameters ... +- S9996: Internal rapid server error (This error fire when post, get message from client to server has problem) +# Transaction response message +- A2000: Transaction Approved +- A2008: Honour With Identification +- A2010: Approved For Partial Amount +- A2011: Approved, VIP +- A2016: Approved, Update Track 3 +- D4401: Refer to Issuer +- D4402: Refer to Issuer, special +- D4403: No Merchant +- D4404: Pick Up Card +- D4405: Do Not Honour +- D4406: Error +- D4407: Pick Up Card, Special +- D4409: Request In Progress +- D4412: Invalid Transaction +- D4413: Invalid Amount +- D4414: Invalid Card Number +- D4415: No Issuer +- D4419: Re-enter Last Transaction +- D4421: No Action Taken +- D4422: Suspected Malfunction +- D4423: Unacceptable Transaction Fee +- D4425: Unable to Locate Record On File +- D4430: Format Error +- D4431: Bank Not Supported By Switch +- D4433: Expired Card, Capture +- D4434: Suspected Fraud, Retain Card +- D4435: Card Acceptor, Contact Acquirer, Retain Card +- D4436: Restricted Card, Retain Card +- D4437: Contact Acquirer Security Department, Retain Card +- D4438: PIN Tries Exceeded, Capture +- D4439: No Credit Account +- D4440: Function Not Supported +- D4441: Lost Card +- D4442: No Universal Account +- D4443: Stolen Card +- D4444: No Investment Account +- D4450: Visa Checkout Transaction Error +- D4451: Insufficient Funds +- D4452: No Cheque Account +- D4453: No Savings Account +- D4454: Expired Card +- D4455: Incorrect PIN +- D4456: No Card Record +- D4457: Function Not Permitted to Cardholder +- D4458: Function Not Permitted to Terminal +- D4459: Suspected Fraud +- D4460: Acceptor Contact Acquirer +- D4461: Exceeds Withdrawal Limit +- D4462: Restricted Card +- D4463: Security Violation +- D4464: Original Amount Incorrect +- D4466: Acceptor Contact Acquirer, Security +- D4467: Capture Card +- D4475: PIN Tries Exceeded +- D4482: CVV Validation Error +- D4490: Cut off In Progress +- D4491: Card Issuer Unavailable +- D4492: Unable To Route Transaction +- D4493: Cannot Complete, Violation Of Law +- D4494: Duplicate Transaction +- D4495: Amex Declined +- D4496: System Error +- D4497: MasterPass Error +- D4498: PayPal Create Transaction Error +- D4499: Invalid Transaction for Auth/Void +- D4450: Visa Checkout Transaction Error +# Beagle Fraud Alerts and Beagle Fraud Alerts (Enterprise) Fraud Response Messages +- F7000: Undefined Fraud Error +- F7001: Challenged Fraud +- F7002: Country Match Fraud +- F7003: High Risk Country Fraud +- F7004: Anonymous Proxy Fraud +- F7005: Transparent Proxy Fraud +- F7006: Free Email Fraud +- F7007: International Transaction Fraud +- F7008: Risk Score Fraud +- F7009: Denied Fraud +- F7010: Denied by PayPal Fraud Rules +- F9001: Custom Fraud Rule +- F9010: High Risk Billing Country +- F9011: High Risk Credit Card Country +- F9012: High Risk Customer IP Address +- F9013: High Risk Email Address +- F9014: High Risk Shipping Country +- F9015: Multiple card numbers for single email address +- F9016: Multiple card numbers for single location +- F9017: Multiple email addresses for single card number +- F9018: Multiple email addresses for single location +- F9019: Multiple locations for single card number +- F9020: Multiple locations for single email address +- F9021: Suspicious Customer First Name +- F9022: Suspicious Customer Last Name +- F9023: Transaction Declined +- F9024: Multiple transactions for same address with known credit card +- F9025: Multiple transactions for same address with new credit card +- F9026: Multiple transactions for same email with new credit card +- F9027: Multiple transactions for same email with known credit card +- F9028: Multiple transactions for new credit card +- F9029: Multiple transactions for known credit card +- F9030: Multiple transactions for same email address +- F9031: Multiple transactions for same credit card +- F9032: Invalid Customer Last Name +- F9033: Invalid Billing Street +- F9034: Invalid Shipping Street +- F9037: Suspicious Customer Email Address +- F9050: High Risk Email Address and amount +- F9113: Card issuing country differs from IP address country \ No newline at end of file diff --git a/lib/eway_rapid/resources/rapid-api.yml b/lib/eway_rapid/resources/rapid-api.yml new file mode 100644 index 0000000..78e3bff --- /dev/null +++ b/lib/eway_rapid/resources/rapid-api.yml @@ -0,0 +1,4 @@ +--- +- global.rapid.rest.production.url: https://api.ewaypayments.com/ +- global.rapid.rest.sandbox.url: https://api.sandbox.ewaypayments.com/ +- rapid.sdk.user.agent: eWAY SDK Ruby \ No newline at end of file diff --git a/lib/eway_rapid/version.rb b/lib/eway_rapid/version.rb new file mode 100644 index 0000000..cdb62da --- /dev/null +++ b/lib/eway_rapid/version.rb @@ -0,0 +1,3 @@ +module EwayRapid + VERSION = '1.0.0' +end diff --git a/test/eway_rapid/integration/customer/customer_test.rb b/test/eway_rapid/integration/customer/customer_test.rb new file mode 100644 index 0000000..807c3a0 --- /dev/null +++ b/test/eway_rapid/integration/customer/customer_test.rb @@ -0,0 +1,148 @@ +require_relative '../../../test_base' + +class CustomerTest < TestBase + + def setup + @customer = EwayRapid::InputModelFactory.create_customer + @address = EwayRapid::InputModelFactory.create_address + end + + def teardown + + end + + def test_create_customer_direct + customer = get_customer_direct(@customer, @address) + assert_equal(@customer.first_name, customer.first_name) + end + + def test_create_customer_direct_but_auth_failure + client = EwayRapid::RapidClient.new(IntegrationTest::API_KEY, 'ABCXYZ', IntegrationTest::SANDBOX_ENDPOINT) + card_details = EwayRapid::InputModelFactory.create_card_detail('12', '25') + @customer.card_details = card_details + @customer.address = @address + + response = client.create_customer(EwayRapid::Enums::PaymentMethod::DIRECT, @customer) + errors = response.errors + assert(errors.length != 0) + assert_equal(1, errors.length) + assert(errors.include? (EwayRapid::Constants::AUTHENTICATION_FAILURE_ERROR_CODE)) + end + + def test_create_customer_direct_but_wrong_endpoint + invalid_endpoint = 'https://api.sandbox.ewaypayments.com/' + client = EwayRapid::RapidClient.new(IntegrationTest::API_KEY, 'ABCXYZ', invalid_endpoint) + fake_web_url = 'https://hhhhhhh.ggg/' + client.instance_variable_set('@rapid_endpoint', fake_web_url) + + card_details = EwayRapid::InputModelFactory.create_card_detail('12', '25') + @customer.card_details = card_details + @customer.address = @address + + response = client.create_customer(EwayRapid::Enums::PaymentMethod::DIRECT, @customer) + errors = response.errors + assert(errors.length != 0) + assert_equal(1, errors.length) + assert(response.errors.include?(EwayRapid::Constants::COMMUNICATION_FAILURE_ERROR_CODE)) + end + + def test_create_customer_invalid_payment_method + response = IntegrationTest.get_sandbox_client.create_customer(EwayRapid::Enums::PaymentMethod::WALLET, @customer) + errors = response.errors + assert(errors.length != 0) + assert_equal(1, errors.length) + assert(response.errors.include?(EwayRapid::Constants::INTERNAL_RAPID_API_ERROR_CODE)) + end + + def test_create_customer_with_blank_input + address = EwayRapid::Models::Address.new + @customer.address = address + + card_details = EwayRapid::Models::CardDetails.new + @customer.card_details = card_details + + response = IntegrationTest.get_sandbox_client.create_customer(EwayRapid::Enums::PaymentMethod::DIRECT, @customer) + errors = response.errors + assert(errors.length != 0) + assert(response.errors.include?('V6021')) + assert(response.errors.include?('V6022')) + assert(response.errors.include?('V6101')) + assert(response.errors.include?('V6102')) + end + + def test_query_direct_valid_customer_id + @customer.address = @address + card_details = EwayRapid::InputModelFactory.create_card_detail('12', '25') + @customer.card_details = card_details + response = IntegrationTest.get_sandbox_client.create_customer(EwayRapid::Enums::PaymentMethod::DIRECT, @customer) + + token_customer_id = response.customer.token_customer_id + assert_not_nil(token_customer_id) + + token_id = Integer(token_customer_id) + cust_response = IntegrationTest.get_sandbox_client.query_customer(token_id) + errors = cust_response.errors + assert(errors.nil? || errors.length == 0) + end + + def test_create_customer_with_response_shared + @customer.address = @address + card_details = EwayRapid::InputModelFactory.create_card_detail('12', '25') + @customer.card_details = card_details + + response = IntegrationTest.get_sandbox_client.create_customer(EwayRapid::Enums::PaymentMethod::RESPONSIVE_SHARED, @customer) + assert(!response.shared_payment_url.empty?) + end + + def test_create_customer_with_transparent_redirect + @customer.address = @address + card_details = EwayRapid::InputModelFactory.create_card_detail('12', '25') + @customer.card_details = card_details + + response = IntegrationTest.get_sandbox_client.create_customer(EwayRapid::Enums::PaymentMethod::TRANSPARENT_REDIRECT, @customer) + assert(!response.form_action_url.empty?) + end + + def test_update_customer_direct + customer = get_customer_direct(@customer, @address) + customer.first_name = 'Steve' + customer.last_name = 'Christian' + card_details = EwayRapid::InputModelFactory.create_card_detail('12', '25') + customer.card_details = card_details + + response = IntegrationTest.get_sandbox_client.update_customer(EwayRapid::Enums::PaymentMethod::DIRECT, customer) + assert('Steve'.casecmp(response.customer.first_name) == 0) + assert('Christian'.casecmp(response.customer.last_name) == 0) + end + + def test_update_customer_responsive + customer = get_customer_direct(@customer, @address) + customer.first_name = 'Steve' + customer.last_name = 'Christian' + customer.redirect_url = 'http://www.eway.com.au' + customer.cancel_url= 'http://www.eway.com.au' + + response = IntegrationTest.get_sandbox_client.update_customer(EwayRapid::Enums::PaymentMethod::RESPONSIVE_SHARED, customer) + assert('Steve'.casecmp(response.customer.first_name) == 0) + assert('Christian'.casecmp(response.customer.last_name) == 0) + end + + def test_update_customer_transparent + customer = get_customer_direct(@customer, @address) + customer.first_name = 'Steve' + customer.last_name = 'Christian' + customer.redirect_url = 'http://www.eway.com.au' + + response = IntegrationTest.get_sandbox_client.update_customer(EwayRapid::Enums::PaymentMethod::TRANSPARENT_REDIRECT, customer) + assert('Steve'.casecmp(response.customer.first_name) == 0) + assert('Christian'.casecmp(response.customer.last_name) == 0) + end + + def get_customer_direct(customer, address) + card_details = EwayRapid::InputModelFactory.create_card_detail('12', '25') + customer.card_details = card_details + customer.address = address + response = IntegrationTest.get_sandbox_client.create_customer(EwayRapid::Enums::PaymentMethod::DIRECT, customer) + response.customer + end +end \ No newline at end of file diff --git a/test/eway_rapid/integration/integration_test.rb b/test/eway_rapid/integration/integration_test.rb new file mode 100644 index 0000000..5e1365f --- /dev/null +++ b/test/eway_rapid/integration/integration_test.rb @@ -0,0 +1,12 @@ +require_relative '../../../lib/eway_rapid' + +class IntegrationTest + PASSWORD = 'API-P4ss' + API_KEY = '60CF3Ce97nRS1Z1Wp5m9kMmzHHEh8Rkuj31QCtVxjPWGYA9FymyqsK0Enm1P6mHJf0THbR' + SANDBOX_ENDPOINT = 'https://api.sandbox.ewaypayments.com/' + + # @return [RapidClient] + def self.get_sandbox_client + EwayRapid::RapidClient.new(API_KEY, PASSWORD, SANDBOX_ENDPOINT) + end +end diff --git a/test/eway_rapid/integration/transaction/authorization_transaction_test.rb b/test/eway_rapid/integration/transaction/authorization_transaction_test.rb new file mode 100644 index 0000000..9dd8aca --- /dev/null +++ b/test/eway_rapid/integration/transaction/authorization_transaction_test.rb @@ -0,0 +1,45 @@ +require_relative '../../../test_base' + +class AuthorizationTransactionTest < TestBase + + def setup + @client = IntegrationTest.get_sandbox_client + @transaction = EwayRapid::InputModelFactory.create_transaction + customer = EwayRapid::InputModelFactory.create_customer + address = EwayRapid::InputModelFactory.create_address + payment_details = EwayRapid::InputModelFactory.create_payment_details + card_details = EwayRapid::InputModelFactory.create_card_detail('12', '24') + customer.card_details = card_details + customer.address = address + @transaction.customer = customer + @transaction.payment_details = payment_details + end + + def teardown + + end + + def test_valid_input + response = @client.create_transaction(EwayRapid::Enums::PaymentMethod::DIRECT, @transaction) + @transaction.auth_transaction_id = response.transaction_status.transaction_id + auth_response = @client.create_transaction(EwayRapid::Enums::PaymentMethod::AUTHORISATION, @transaction) + + assert(response.transaction_status.status) + assert_not_equal(0, auth_response.transaction_status.transaction_id) + end + + def test_invalid_input1 + @transaction.auth_transaction_id = 1234 + auth_response = @client.create_transaction(EwayRapid::Enums::PaymentMethod::AUTHORISATION, @transaction) + assert(auth_response.errors.include?('V6134')) + end + + def test_input2 + response = @client.create_transaction(EwayRapid::Enums::PaymentMethod::DIRECT, @transaction) + @transaction.auth_transaction_id = response.transaction_status.transaction_id + auth_response = @client.create_transaction(EwayRapid::Enums::PaymentMethod::AUTHORISATION, @transaction) + @transaction.auth_transaction_id = auth_response.transaction_status.transaction_id + auth_response2 = @client.create_transaction(EwayRapid::Enums::PaymentMethod::AUTHORISATION, @transaction) + assert(auth_response2.transaction_status.status) + end +end \ No newline at end of file diff --git a/test/eway_rapid/integration/transaction/cancel_transaction_test.rb b/test/eway_rapid/integration/transaction/cancel_transaction_test.rb new file mode 100644 index 0000000..3a3d38a --- /dev/null +++ b/test/eway_rapid/integration/transaction/cancel_transaction_test.rb @@ -0,0 +1,51 @@ +require_relative '../../../test_base' + +class CancelTransactionTest < TestBase + + def setup + @client = IntegrationTest.get_sandbox_client + @transaction = EwayRapid::InputModelFactory.create_transaction + customer = EwayRapid::InputModelFactory.create_customer + address = EwayRapid::InputModelFactory.create_address + payment_details = EwayRapid::InputModelFactory.create_payment_details + card_details = EwayRapid::InputModelFactory.create_card_detail('12', '24') + customer.card_details = card_details + customer.address = address + @transaction.customer = customer + @transaction.payment_details = payment_details + @refund = EwayRapid::Models::Refund.new + @refund.customer = customer + end + + def teardown + + end + + def test_valid_input + response = @client.create_transaction(EwayRapid::Enums::PaymentMethod::DIRECT, @transaction) + refund_details = EwayRapid::InternalModels::RefundDetails.new + refund_details.original_transaction_id = response.transaction_status.transaction_id.to_s + @refund.refund_details = refund_details + cancel_response = @client.cancel(@refund) + assert(cancel_response.transaction_status.status) + end + + def test_invalid_input1 + refund_details = EwayRapid::InternalModels::RefundDetails.new + refund_details.original_transaction_id = 1234 + @refund.refund_details = refund_details + cancel_response = @client.cancel(@refund) + assert(cancel_response.errors.include?('V6134')) + end + + def test_input2 + response = @client.create_transaction(EwayRapid::Enums::PaymentMethod::DIRECT, @transaction) + @transaction.auth_transaction_id = response.transaction_status.transaction_id + auth_response = @client.create_transaction(EwayRapid::Enums::PaymentMethod::AUTHORISATION, @transaction) + refund_details = EwayRapid::InternalModels::RefundDetails.new + refund_details.original_transaction_id = auth_response.transaction_status.transaction_id.to_s + @refund.refund_details = refund_details + cancel_response = @client.cancel(@refund) + assert(cancel_response.transaction_status.status) + end +end \ No newline at end of file diff --git a/test/eway_rapid/integration/transaction/direct_transaction_test.rb b/test/eway_rapid/integration/transaction/direct_transaction_test.rb new file mode 100644 index 0000000..4f64d9a --- /dev/null +++ b/test/eway_rapid/integration/transaction/direct_transaction_test.rb @@ -0,0 +1,46 @@ +require_relative '../../../test_base' + +class DirectTransactionTest < TestBase + + def setup + @client = IntegrationTest.get_sandbox_client + @transaction = EwayRapid::InputModelFactory.create_transaction + customer = EwayRapid::InputModelFactory.create_customer + address = EwayRapid::InputModelFactory.create_address + payment_details = EwayRapid::InputModelFactory.create_payment_details + card_details = EwayRapid::InputModelFactory.create_card_detail('12', '24') + customer.card_details = card_details + customer.address = address + @transaction.customer = customer + @transaction.payment_details = payment_details + shipping_details = EwayRapid::InputModelFactory.create_shipping_detail + @transaction.shipping_details = shipping_details + end + + def test_valid_input + response = @client.create_transaction(EwayRapid::Enums::PaymentMethod::DIRECT, @transaction) + assert(response.transaction_status.status) + assert_not_equal(0, response.transaction_status.transaction_id) + end + + def test_blank_input + transaction = EwayRapid::Models::Transaction.new + customer = EwayRapid::Models::Customer.new + card_detail = EwayRapid::Models::CardDetails.new + customer.card_details = card_detail + transaction.customer = customer + transaction.transaction_type = EwayRapid::Enums::TransactionType::PURCHASE + response = @client.create_transaction(EwayRapid::Enums::PaymentMethod::DIRECT, transaction) + assert(!response.transaction_status.status) + assert_equal(0, response.transaction_status.transaction_id) + + assert(response.errors.include?('V6021')) + assert(response.errors.include?('V6022')) + assert(response.errors.include?('V6101')) + assert(response.errors.include?('V6102')) + end + + def teardown + + end +end \ No newline at end of file diff --git a/test/eway_rapid/integration/transaction/query_transaction_test.rb b/test/eway_rapid/integration/transaction/query_transaction_test.rb new file mode 100644 index 0000000..3315b59 --- /dev/null +++ b/test/eway_rapid/integration/transaction/query_transaction_test.rb @@ -0,0 +1,40 @@ +require_relative '../../../test_base' + +class QueryTransactionTest < TestBase + + def setup + @client = IntegrationTest.get_sandbox_client + end + + def test_valid_input + @trans = EwayRapid::InputModelFactory.create_transaction + c = EwayRapid::InputModelFactory.create_customer + a = EwayRapid::InputModelFactory.create_address + p = EwayRapid::InputModelFactory.create_payment_details + cd = EwayRapid::InputModelFactory.create_card_detail('12', '24') + c.card_details = cd + c.address = a + @trans.customer = c + @trans.payment_details = p + trans_response = @client.create_transaction(EwayRapid::Enums::PaymentMethod::DIRECT, @trans) + assert(trans_response.transaction_status.status) + assert_not_equal(0, trans_response.transaction_status.transaction_id) + + transaction_id = trans_response.transaction_status.transaction_id + query = @client.query_transaction_by_id(transaction_id) + assert_equal(transaction_id, query.transaction_status.transaction_id) + assert(query.errors.nil? || query.errors.length == 0) + end + + def test_blank_input + res = @client.query_transaction_by_access_code('') + assert_nil(res.transaction) + end + + def test_invalid_input + res = @client.query_transaction_by_access_code(EwayRapid::InputModelFactory.random_string(50)) + assert_nil(res.transaction) + end + + def teardown; end +end \ No newline at end of file diff --git a/test/eway_rapid/integration/transaction/refund_transaction_test.rb b/test/eway_rapid/integration/transaction/refund_transaction_test.rb new file mode 100644 index 0000000..536499b --- /dev/null +++ b/test/eway_rapid/integration/transaction/refund_transaction_test.rb @@ -0,0 +1,97 @@ +require_relative '../../../test_base' + +class RefundTransactionTest < TestBase + + def setup + @client = IntegrationTest.get_sandbox_client + @transaction = EwayRapid::InputModelFactory.create_transaction + c = EwayRapid::InputModelFactory.create_customer + a = EwayRapid::InputModelFactory.create_address + p = EwayRapid::InputModelFactory.create_payment_details + cd = EwayRapid::InputModelFactory.create_card_detail('12', '24') + c.card_details = cd + c.address = a + @transaction.customer = c + @transaction.payment_details = p + @refund = EwayRapid::Models::Refund.new + @refund.customer = c + end + + def test_valid_input + res = @client.create_transaction(EwayRapid::Enums::PaymentMethod::DIRECT, @transaction); + rd = EwayRapid::InternalModels::RefundDetails.new + rd.original_transaction_id = res.transaction_status.transaction_id.to_s + @refund.refund_details = rd + @refund.customer.card_details.cvn = nil + @refund.customer.card_details.issue_number = nil + @refund.customer.card_details.name = nil + @refund.customer.card_details.number = nil + @refund.customer.card_details.start_month = nil + @refund.customer.card_details.start_year = nil + refund_res = @client.refund(@refund) + assert(refund_res.transaction_status.status) + end + + def test_invalid_input + res = @client.create_transaction(EwayRapid::Enums::PaymentMethod::DIRECT, @transaction); + rd = EwayRapid::InternalModels::RefundDetails.new + rd.original_transaction_id = res.transaction_status.transaction_id.to_s + rd.total_amount = 1001 + @refund.refund_details = rd + @refund.customer.card_details.cvn = nil + @refund.customer.card_details.issue_number = nil + @refund.customer.card_details.name = nil + @refund.customer.card_details.number = nil + @refund.customer.card_details.start_month = nil + @refund.customer.card_details.start_year = nil + refund_res = @client.refund(@refund) + assert(refund_res.errors.include? 'V6151') + end + + def test_invalid_input_2 + res = @client.create_transaction(EwayRapid::Enums::PaymentMethod::DIRECT, @transaction); + rd = EwayRapid::InternalModels::RefundDetails.new + rd.original_transaction_id = res.transaction_status.transaction_id.to_s + @refund.refund_details = rd + @refund.customer.card_details.cvn = nil + @refund.customer.card_details.issue_number = nil + @refund.customer.card_details.name = nil + @refund.customer.card_details.number = nil + @refund.customer.card_details.start_month = nil + @refund.customer.card_details.start_year = nil + refund_res = @client.refund(@refund) + @refund.refund_details.original_transaction_id = refund_res.transaction_status.transaction_id + refund_res2 = @client.refund(@refund) + assert(refund_res2.errors.include? 'V6113') + end + + def test_invalid_input_3 + @client.create_transaction(EwayRapid::Enums::PaymentMethod::DIRECT, @transaction) + rd = EwayRapid::InternalModels::RefundDetails.new + rd.original_transaction_id = 'abcd' + @refund.refund_details = rd + @refund.customer.card_details.cvn = nil + @refund.customer.card_details.issue_number = nil + @refund.customer.card_details.name = nil + @refund.customer.card_details.number = nil + @refund.customer.card_details.start_month = nil + @refund.customer.card_details.start_year = nil + refund_res = @client.refund(@refund) + assert(refund_res.errors.include? 'V6115') + end + + def test_invalid_input_4 + @client.create_transaction(EwayRapid::Enums::PaymentMethod::DIRECT, @transaction) + rd = EwayRapid::InternalModels::RefundDetails.new + rd.original_transaction_id = nil + @refund.refund_details = rd + @refund.customer.card_details.cvn = nil + @refund.customer.card_details.issue_number = nil + @refund.customer.card_details.name = nil + @refund.customer.card_details.number = nil + @refund.customer.card_details.start_month = nil + @refund.customer.card_details.start_year = nil + # refund_res = @client.refund(@refund) + # TODO assert(refund_res.errors.include? 'V6115') + end +end \ No newline at end of file diff --git a/test/eway_rapid/integration/transaction/responsive_transaction_test.rb b/test/eway_rapid/integration/transaction/responsive_transaction_test.rb new file mode 100644 index 0000000..670da7f --- /dev/null +++ b/test/eway_rapid/integration/transaction/responsive_transaction_test.rb @@ -0,0 +1,43 @@ +require_relative '../../../test_base' + +class ResponsiveTransactionTest < TestBase + + def setup + @client = IntegrationTest.get_sandbox_client + @transaction = EwayRapid::InputModelFactory.create_transaction + c = EwayRapid::InputModelFactory.create_customer + a = EwayRapid::InputModelFactory.create_address + p = EwayRapid::InputModelFactory.create_payment_details + cd = EwayRapid::InputModelFactory.create_card_detail('12', '24') + c.card_details = cd + c.address = a + @transaction.customer = c + @transaction.payment_details = p + @transaction.custom_view = 'bootstrap' + @transaction.header_text = 'My Site Header Text' + @transaction.customer_read_only = false + @transaction.logo_url = 'https://mysite.com/images/logo4eway.jpg' + @transaction.verify_customer_email = false + @transaction.verify_customer_phone = false + @transaction.language = 'EN' + @transaction.checkout_payment = false + end + + def test_valid_input + res = @client.create_transaction(EwayRapid::Enums::PaymentMethod::RESPONSIVE_SHARED, @transaction) + assert_not_nil(res.shared_payment_url) + end + + def test_blank_input + tran = EwayRapid::Models::Transaction.new + c = EwayRapid::Models::Customer.new + cd = EwayRapid::Models::CardDetails.new + c.card_details = cd + tran.customer = c + tran.transaction_type = EwayRapid::Enums::TransactionType::PURCHASE + res = @client.create_transaction(EwayRapid::Enums::PaymentMethod::RESPONSIVE_SHARED, tran) + assert(res.errors != nil && res.errors.length != 0) + end + + def teardown; end +end \ No newline at end of file diff --git a/test/eway_rapid/integration/transaction/transaction_filter_test.rb b/test/eway_rapid/integration/transaction/transaction_filter_test.rb new file mode 100644 index 0000000..917e632 --- /dev/null +++ b/test/eway_rapid/integration/transaction/transaction_filter_test.rb @@ -0,0 +1,117 @@ +require_relative '../../../test_base' + +class TransactionFilterTest < TestBase + def setup + @client = IntegrationTest.get_sandbox_client + end + + def test_valid_input + @transaction = EwayRapid::InputModelFactory.create_transaction + c = EwayRapid::InputModelFactory.create_customer + a = EwayRapid::InputModelFactory.create_address + p = EwayRapid::InputModelFactory.create_payment_details + cd = EwayRapid::InputModelFactory.create_card_detail('12', '24') + c.card_details = cd + c.address = a + @transaction.customer = c + @transaction.payment_details = p + trans_response = @client.create_transaction(EwayRapid::Enums::PaymentMethod::DIRECT, @transaction) + assert(trans_response.transaction_status.status) + assert_not_equal(0, trans_response.transaction_status.transaction_id) + + filter = EwayRapid::Enums::TransactionFilter.new + filter.transaction_id = trans_response.transaction_status.transaction_id + + res = @client.query_transaction_by_filter(filter) + assert(res.transaction_status.status) + assert_equal(trans_response.transaction_status.transaction_id, res.transaction_status.transaction_id) + end + + def test_blank_input + filter = EwayRapid::Enums::TransactionFilter.new + res = @client.query_transaction_by_filter(filter) + assert_nil(res.transaction) + end + + def test_invalid_input + filter = EwayRapid::Enums::TransactionFilter.new + filter.transaction_id = 11742962 + filter.invoice_number = 'Inv 21540' + res = @client.query_transaction_by_filter(filter) + assert(res.errors.include? 'S9991') + end + + def test_search_invoice_number_or_reference + @transaction = EwayRapid::InputModelFactory.create_transaction + c = EwayRapid::InputModelFactory.create_customer + a = EwayRapid::InputModelFactory.create_address + invoice_num = EwayRapid::InputModelFactory.random_string(10) + invoice_ref = EwayRapid::InputModelFactory.random_string(10) + p = EwayRapid::InputModelFactory.create_payment_details_with(invoice_num, invoice_ref) + cd = EwayRapid::InputModelFactory.create_card_detail('12', '24') + c.card_details = cd + c.address = a + @transaction.customer = c + @transaction.payment_details = p + trans_response = @client.create_transaction(EwayRapid::Enums::PaymentMethod::DIRECT, @transaction) + assert(trans_response.transaction_status.status) + transaction_id = trans_response.transaction_status.transaction_id + + # search invoice number + filter = EwayRapid::Enums::TransactionFilter.new + filter.invoice_number = invoice_num + res = @client.query_transaction_by_filter(filter) + assert(res.transaction_status.status) + assert_equal(transaction_id, res.transaction_status.transaction_id) + assert_equal(invoice_num, res.transaction.payment_details.invoice_number) + + # search invoice reference + filter = EwayRapid::Enums::TransactionFilter.new + filter.invoice_reference = invoice_ref + res = @client.query_transaction_by_filter(filter) + assert(res.transaction_status.status) + assert_equal(transaction_id, res.transaction_status.transaction_id) + assert_equal(invoice_ref, res.transaction.payment_details.invoice_reference) + end + + def test_search_access_code + @transaction = EwayRapid::InputModelFactory.create_transaction + c = EwayRapid::InputModelFactory.create_customer + a = EwayRapid::InputModelFactory.create_address + p = EwayRapid::InputModelFactory.create_payment_details + cd = EwayRapid::InputModelFactory.create_card_detail('12', '24') + c.card_details = cd + c.address = a + @transaction.customer = c + @transaction.payment_details = p + + trans_response = @client.create_transaction(EwayRapid::Enums::PaymentMethod::TRANSPARENT_REDIRECT, @transaction) + access_code = trans_response.access_code + assert(!access_code.nil? && access_code != '') + + filter = EwayRapid::Enums::TransactionFilter.new + filter.access_code = access_code + + res = @client.query_transaction_by_filter(filter) + assert(res.errors.nil? || res.errors.length == 0) + end + + def test_search_missing_invoice_number + invoice_num = EwayRapid::InputModelFactory.random_string(100) + filter = EwayRapid::Enums::TransactionFilter.new + filter.invoice_number = invoice_num + res = @client.query_transaction_by_filter(filter) + assert(!res.errors.nil? && res.errors.length != 0) + assert(res.errors.include? 'V6171') + end + + def test_missing_transaction_filter_object + invoice_num = EwayRapid::InputModelFactory.random_string(100) + invoice_ref = EwayRapid::InputModelFactory.random_string(100) + filter = EwayRapid::Enums::TransactionFilter.new + filter.invoice_number = invoice_num + filter.invoice_reference = invoice_ref + res = @client.query_transaction_by_filter(filter) + assert(!res.errors.nil? && res.errors.length != 0); + end +end \ No newline at end of file diff --git a/test/eway_rapid/integration/transaction/transparent_transaction_test.rb b/test/eway_rapid/integration/transaction/transparent_transaction_test.rb new file mode 100644 index 0000000..7f307aa --- /dev/null +++ b/test/eway_rapid/integration/transaction/transparent_transaction_test.rb @@ -0,0 +1,33 @@ +require_relative '../../../test_base' + +class TransparentTransactionTest < TestBase + + def setup + @client = IntegrationTest.get_sandbox_client + @transaction = EwayRapid::InputModelFactory.create_transaction + c = EwayRapid::InputModelFactory.create_customer + a = EwayRapid::InputModelFactory.create_address + p = EwayRapid::InputModelFactory.create_payment_details + cd = EwayRapid::InputModelFactory.create_card_detail('12', '24') + c.card_details = cd + c.address = a + @transaction.customer = c + @transaction.payment_details = p + end + + def test_valid_input + res = @client.create_transaction(EwayRapid::Enums::PaymentMethod::TRANSPARENT_REDIRECT, @transaction) + assert_not_nil(res.form_action_url) + end + + def test_blank_input + tran = EwayRapid::Models::Transaction.new + c = EwayRapid::Models::Customer.new + cd = EwayRapid::Models::CardDetails.new + c.card_details = cd + tran.customer = c + tran.transaction_type = EwayRapid::Enums::TransactionType::PURCHASE + res = @client.create_transaction(EwayRapid::Enums::PaymentMethod::TRANSPARENT_REDIRECT, tran) + assert(res.errors.include? 'V6047') + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/customer_to_internal_converter_test.rb b/test/eway_rapid/message/convert/customer_to_internal_converter_test.rb new file mode 100644 index 0000000..88b299d --- /dev/null +++ b/test/eway_rapid/message/convert/customer_to_internal_converter_test.rb @@ -0,0 +1,53 @@ +require_relative '../../../test_base' + +module EwayRapid + module Message + module Convert + class CustomerToInternalConverterTest < TestBase + def setup + @convert = CustomerToInternalCustomer.new + end + + def test_convert_customer_card_detail + cust = InputModelFactory.create_customer + cust.card_details = InputModelFactory.create_card_detail('12', '25') + inter_cust = @convert.do_convert(cust) + detail = inter_cust.card_details + assert_not_nil(detail) + assert_not_nil(detail.expiry_month) + assert_not_nil(detail.expiry_year) + assert_equal('12', detail.expiry_month) + assert_equal('25', detail.expiry_year) + end + + def test_convert_customer_address + cust = InputModelFactory.create_customer + city = 'Sydney' + postal_code = '084' + state = 'NSW' + country = 'Autralia' + add = InputModelFactory.create_address_by_object(city, country, postal_code, state) + cust.address = add + inter_cust = @convert.do_convert(cust) + assert_not_nil(inter_cust.state) + assert_equal(state, inter_cust.state) + assert_not_nil(inter_cust.city) + assert_equal(city, inter_cust.city) + assert_not_nil(inter_cust.country) + assert_equal(country, inter_cust.country) + assert_not_nil(inter_cust.postal_code) + assert_equal(postal_code, inter_cust.postal_code) + end + + def test_convert_customer_without_address + cust = InputModelFactory.create_customer + interCust = @convert.do_convert(cust) + assert_nil(interCust.state) + assert_nil(interCust.city) + assert_nil(interCust.country) + assert_nil(interCust.postal_code) + end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/direct_payment_to_trans_status_converter_test.rb b/test/eway_rapid/message/convert/direct_payment_to_trans_status_converter_test.rb new file mode 100644 index 0000000..b0d2ba8 --- /dev/null +++ b/test/eway_rapid/message/convert/direct_payment_to_trans_status_converter_test.rb @@ -0,0 +1,55 @@ +require_relative '../../../test_base' + +module EwayRapid + module Message + module Convert + class DirectPaymentToTransStatusConverterTest < TestBase + def setup + @convert = DirectPaymentToTransStatus.new + end + + def test_do_convert + response = DirectPaymentResponse.new + response.transaction_id = '123456' + response.beagle_score = 0.0 + response.fraud_action = Enums::FraudAction::ALLOW + response.transaction_captured = 'true' + response.transaction_status = true + payment = ObjectCreator.create_payment + response.payment = payment + verification = ObjectCreator.create_verification + response.verification = verification + status = @convert.do_convert(response) + assert_equal(response.beagle_score, 0.0, 0.001) + assert_equal(Enums::FraudAction::ALLOW, status.fraud_action) + assert(status.captured) + end + + def test_invalid_transaction_id + assert_raise ArgumentError do + response = DirectPaymentResponse.new + response.transaction_id = 'abcd' + payment = ObjectCreator.create_payment + response.payment = payment + @convert.do_convert(response) + end + end + + def test_invalid_verification + response = DirectPaymentResponse.new + response.transaction_id = '1234' + payment = ObjectCreator.create_payment + response.payment = payment + verification = ObjectCreator.create_verification + verification.address = 'a' + response.verification = verification + @convert.do_convert(response) + end + + def teardown + + end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/direct_refund_to_trans_status_converter_test.rb b/test/eway_rapid/message/convert/direct_refund_to_trans_status_converter_test.rb new file mode 100644 index 0000000..1fd9113 --- /dev/null +++ b/test/eway_rapid/message/convert/direct_refund_to_trans_status_converter_test.rb @@ -0,0 +1,35 @@ +require_relative '../../../test_base' + +module EwayRapid + module Message + module Convert + class DirectRefundToTransStatusConverterTest < TestBase + + def setup + @convert = DirectRefundToTransStatus.new + end + + def test_do_convert + response = DirectRefundResponse.new + response.transaction_id = '123456' + response.transaction_status = true + status = @convert.do_convert(response) + assert_equal(123456, status.transaction_id) + assert(status.status) + end + + def test_invalid_transaction_id + assert_raise ArgumentError do + response = DirectRefundResponse.new + response.transaction_id = 'abcd' + @convert.do_convert(response) + end + end + + def teardown + + end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/internal_customer_to_customer_converter_test.rb b/test/eway_rapid/message/convert/internal_customer_to_customer_converter_test.rb new file mode 100644 index 0000000..23259f0 --- /dev/null +++ b/test/eway_rapid/message/convert/internal_customer_to_customer_converter_test.rb @@ -0,0 +1,25 @@ +require_relative '../../../test_base' + +module EwayRapid + module Message + module Convert + class InternalCustomerToCustomerConverterTest < TestBase + + def setup + @convert = InternalCustomerToCustomer.new + end + + def test_do_convert + internal_customer = ObjectCreator.create_internal_customer + customer = @convert.do_convert(internal_customer) + assert_equal('John', customer.first_name) + assert_equal('12', customer.card_details.expiry_month) + end + + def teardown + + end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/internal_trans_to_trans_converter_test.rb b/test/eway_rapid/message/convert/internal_trans_to_trans_converter_test.rb new file mode 100644 index 0000000..e123746 --- /dev/null +++ b/test/eway_rapid/message/convert/internal_trans_to_trans_converter_test.rb @@ -0,0 +1,27 @@ +require_relative '../../../test_base' + +module EwayRapid + module Message + module Convert + class InternalTransToTransConverterTest < TestBase + + def setup + @convert = InternalTransToTrans.new + end + + def test_do_convert + internal_tran = ObjectCreator.create_internal_transaction + internal_tran.customer = ObjectCreator.create_internal_customer + tran = @convert.do_convert(internal_tran) + assert_equal('John', tran.customer.first_name) + assert_equal(1000, tran.payment_details.total_amount, 0.001) + assert_equal('Sydney', tran.shipping_details.shipping_address.city) + end + + def teardown + + end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/internal_transaction_to_address_converter_test.rb b/test/eway_rapid/message/convert/internal_transaction_to_address_converter_test.rb new file mode 100644 index 0000000..482084f --- /dev/null +++ b/test/eway_rapid/message/convert/internal_transaction_to_address_converter_test.rb @@ -0,0 +1,24 @@ +require_relative '../../../test_base' + +module EwayRapid + module Message + module Convert + class InternalTransactionToAddressConverterTest < TestBase + + def setup + @convert = InternalTransactionToAddress.new + end + + def test_do_convert + transaction = ObjectCreator.create_internal_transaction + address = @convert.do_convert(transaction) + assert_equal('Sydney', address.city) + end + + def teardown + + end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/internal_transaction_to_status_converter_test.rb b/test/eway_rapid/message/convert/internal_transaction_to_status_converter_test.rb new file mode 100644 index 0000000..4d3627a --- /dev/null +++ b/test/eway_rapid/message/convert/internal_transaction_to_status_converter_test.rb @@ -0,0 +1,32 @@ +require_relative '../../../test_base' + +module EwayRapid + module Message + module Convert + class InternalTransactionToStatusConverterTest < TestBase + + def setup + @convert = InternalTransactionToStatus.new + end + + def test_do_convert + transaction = ObjectCreator.create_internal_transaction + status = @convert.do_convert(transaction) + assert_equal(1000, status.total, 0.001) + end + + def test_invalid_transaction_id + assert_raise ArgumentError do + transaction = ObjectCreator.create_internal_transaction + transaction.transaction_id = 'abc' + @convert.do_convert(transaction) + end + end + + def teardown + + end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/payment_to_payment_detail_converter_test.rb b/test/eway_rapid/message/convert/payment_to_payment_detail_converter_test.rb new file mode 100644 index 0000000..fdfc05e --- /dev/null +++ b/test/eway_rapid/message/convert/payment_to_payment_detail_converter_test.rb @@ -0,0 +1,29 @@ +require_relative '../../../test_base' + +module EwayRapid + module Message + module Convert + class PaymentToPaymentDetailConverterTest < TestBase + + def setup + @convert = PaymentToPaymentDetails.new + end + + def test_do_convert + payment = ObjectCreator.create_payment + payment_details = @convert.do_convert(payment) + assert_equal(1000, payment_details.total_amount,0.001) + end + + def test_nil_payment + payment_details = @convert.do_convert(nil) + assert_equal(0, payment_details.total_amount) + end + + def teardown + + end + end + end + end +end diff --git a/test/eway_rapid/message/convert/request/refund_to_direct_refund_req_converter_test.rb b/test/eway_rapid/message/convert/request/refund_to_direct_refund_req_converter_test.rb new file mode 100644 index 0000000..4006b25 --- /dev/null +++ b/test/eway_rapid/message/convert/request/refund_to_direct_refund_req_converter_test.rb @@ -0,0 +1,45 @@ +require_relative '../../../../test_base' + +module EwayRapid + module Message + module Convert + module Request + class RefundToDirectRefundReqConverterTest < TestBase + def setup + @convert = RefundToDirectRefundReq.new + @refund = Models::Refund.new + refund_details = ObjectCreator.create_refund_details + customer = ObjectCreator.create_external_customer + address = ObjectCreator.create_address + card_details = ObjectCreator.create_card_details + customer.card_details = card_details + customer.address = address + shipping_details = Models::ShippingDetails.new + shipping_details.shipping_address = address + line_items = ObjectCreator.create_line_items + @refund.line_items = line_items + options=ObjectCreator.create_options + @refund.options = options + @refund.customer = customer + @refund.shipping_details = shipping_details + @refund.refund_details = refund_details + @refund.device_id = 'DZPC' + @refund.partner_id = 'ID' + end + + def test_do_convert + request = @convert.do_convert(@refund) + assert_equal('John', request.customer.first_name) + assert_equal('Sydney', request.shipping_address.city) + assert_equal(1, request.line_items.length) + assert_equal(1, request.options.length) + end + + def teardown + + end + end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/request/transaction_to_direct_payment_converter_test.rb b/test/eway_rapid/message/convert/request/transaction_to_direct_payment_converter_test.rb new file mode 100644 index 0000000..204c942 --- /dev/null +++ b/test/eway_rapid/message/convert/request/transaction_to_direct_payment_converter_test.rb @@ -0,0 +1,35 @@ +require_relative '../../../../test_base' + +module EwayRapid + module Message + module Convert + module Request + class TransactionToDirectPaymentConverterTest < TestBase + def setup + @convert = TransactionToDirectPayment.new + customer = ObjectCreator.create_external_customer + address = ObjectCreator.create_address + card_details = ObjectCreator.create_card_details + payment_details = ObjectCreator.create_payment_details + @input = Models::Transaction.new + customer.card_details = card_details + customer.address = address + @input.customer = customer + @input.payment_details = payment_details + @input.transaction_type = Enums::TransactionType::PURCHASE + @input.capture = true + end + + def test_do_convert + request = @convert.do_convert(@input) + assert_equal(1000, request.payment.total_amount,0.001) + assert_equal('John', request.customer.first_name) + assert_equal('Level 5', request.customer.street1) + assert_equal('12',request.customer.card_details.expiry_month) + assert_equal(Enums::TransactionType::PURCHASE,request.transaction_type) + end + end + end + end + end +end diff --git a/test/eway_rapid/message/convert/response/access_code_shared_to_create_cust_converter_test.rb b/test/eway_rapid/message/convert/response/access_code_shared_to_create_cust_converter_test.rb new file mode 100644 index 0000000..31f1672 --- /dev/null +++ b/test/eway_rapid/message/convert/response/access_code_shared_to_create_cust_converter_test.rb @@ -0,0 +1,69 @@ +require_relative '../../../../test_base' + +module EwayRapid + module Message + module Convert + module Response + class AccessCodeSharedToCreateCustConverterTest < TestBase + def setup + @convert = AccessCodeSharedToCreateCust.new + json = '{ + "SharedPaymentUrl": "https://secure-au.sandbox.ewaypayments.com/sharedpage/sharedpayment?AccessCode=44DD7aVwPYUPemGRf7pcWxyX2FJS-0Wk7xr9iE7Vatk_5vJimEbHveGSqX52B00QsBXqbLh9mGZxMHcjThQ_ITsCZ3JxKOY88WOVsFTLPrGtHRkK0E9ZDVh_Wz326QZlNlwx2", + "AccessCode": "44DD7aVwPYUPemGRf7pcWxyX2FJS-0Wk7xr9iE7Vatk_5vJimEbHveGSqX52B00QsBXqbLh9mGZxMHcjThQ_ITsCZ3JxKOY88WOVsFTLPrGtHRkK0E9ZDVh_Wz326QZlNlwx2", + "Customer": { + "CardNumber": "", + "CardStartMonth": "", + "CardStartYear": "", + "CardIssueNumber": "", + "CardName": "", + "CardExpiryMonth": "", + "CardExpiryYear": "", + "IsActive": false, + "TokenCustomerID": null, + "Reference": "A12345", + "Title": "Mr.", + "FirstName": "John", + "LastName": "Smith", + "CompanyName": "Demo Shop 123", + "JobDescription": "Developer", + "Street1": "Level 5", + "Street2": "369 Queen Street", + "City": "Sydney", + "State": "NSW", + "PostalCode": "2000", + "Country": "au", + "Email": "demo@example.org", + "Phone": "09 889 0986", + "Mobile": "09 889 6542", + "Comments": "", + "Fax": "", + "Url": "http://www.ewaypayments.com" + }, + "Payment": { + "TotalAmount": 1000, + "InvoiceNumber": "Inv 21540", + "InvoiceDescription": "Individual Invoice Description", + "InvoiceReference": "513456", + "CurrencyCode": "AUD" + }, + "FormActionURL": "https://secure-au.sandbox.ewaypayments.com/AccessCode/44DD7aVwPYUPemGRf7pcWxyX2FJS-0Wk7xr9iE7Vatk_5vJimEbHveGSqX52B00QsBXqbLh9mGZxMHcjThQ_ITsCZ3JxKOY88WOVsFTLPrGtHRkK0E9ZDVh_Wz326QZlNlwx2", + "CompleteCheckoutURL": null, + "Errors": null + }' + @response = CreateAccessCodeSharedResponse.from_json(json) + end + + def test_do_convert + customer_res = @convert.do_convert(@response) + assert_equal('John', customer_res.customer.first_name) + assert_equal('Level 5', customer_res.customer.address.street1) + end + + def teardown + + end + end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/response/access_code_shared_to_create_trans_converter_test.rb b/test/eway_rapid/message/convert/response/access_code_shared_to_create_trans_converter_test.rb new file mode 100644 index 0000000..def51a4 --- /dev/null +++ b/test/eway_rapid/message/convert/response/access_code_shared_to_create_trans_converter_test.rb @@ -0,0 +1,33 @@ +require_relative '../../../../test_base' + +module EwayRapid + module Message + module Convert + module Response + class AccessCodeSharedToCreateTransConverterTest < TestBase + + def setup + @convert = AccessCodeSharedToCreateTrans.new + json = '{"SharedPaymentUrl":"https://secure-au.sandbox.ewaypayments.com/sharedpage/sharedpayment?AccessCode=F9802QqDnIqsLNfb1_rjKo2LA8P-RAalL-7TkBkYaDLRLuh-KDFqKVuvD0hhCmaWvqNhTnf07s2Kqhkru_nyySX-ZAjqRz6675u4tlZlFi1huKGXA2aFcS_l4BXlvmralGqtj","AccessCode":"F9802QqDnIqsLNfb1_rjKo2LA8P-RAalL-7TkBkYaDLRLuh-KDFqKVuvD0hhCmaWvqNhTnf07s2Kqhkru_nyySX-ZAjqRz6675u4tlZlFi1huKGXA2aFcS_l4BXlvmralGqtj","Customer":{"CardNumber":"","CardStartMonth":"","CardStartYear":"","CardIssueNumber":"","CardName":"","CardExpiryMonth":"","CardExpiryYear":"","IsActive":false,"TokenCustomerID":null,"Reference":"","Title":"Mr.","FirstName":"John","LastName":"Smith","CompanyName":"SmartOSC","JobDescription":"Java Developer","Street1":"Level 5","Street2":"369 Queen Street","City":"Sydney","State":"NSW","PostalCode":"2000","Country":"au","Email":"","Phone":"0123456789","Mobile":"0123456789","Comments":"","Fax":"1234","Url":"http://www.ewaypayments.com"},"Payment":{"TotalAmount":1000,"InvoiceNumber":"Inv 21540","InvoiceDescription":"Individual Invoice Description","InvoiceReference":"513456","CurrencyCode":"AUD"},"FormActionURL":"https://secure-au.sandbox.ewaypayments.com/Process","CompleteCheckoutURL":null,"Errors":null}' + error_json = '{"SharedPaymentUrl":null,"AccessCode":null,"Customer":{"CardNumber":null,"CardStartMonth":null,"CardStartYear":null,"CardIssueNumber":null,"CardName":null,"CardExpiryMonth":null,"CardExpiryYear":null,"IsActive":false,"TokenCustomerID":null,"Reference":null,"Title":null,"FirstName":null,"LastName":null,"CompanyName":null,"JobDescription":null,"Street1":null,"Street2":null,"City":null,"State":null,"PostalCode":null,"Country":null,"Email":null,"Phone":null,"Mobile":null,"Comments":null,"Fax":null,"Url":null},"Payment":{"TotalAmount":1000,"InvoiceNumber":"Inv 21540","InvoiceDescription":"Individual Invoice Description","InvoiceReference":"513456","CurrencyCode":"AUD"},"FormActionURL":null,"CompleteCheckoutURL":null,"Errors":"V6047"}' + @response = CreateAccessCodeSharedResponse.from_json(json) + @error_response = CreateAccessCodeSharedResponse.from_json(error_json) + end + + def test_do_convert + transaction_response = @convert.do_convert(@response) + assert_equal(1000, transaction_response.transaction.payment_details.total_amount, 0.001) + assert_equal('John', transaction_response.transaction.customer.first_name) + end + + def test_error + error_transaction_response = @convert.do_convert(@error_response) + assert(error_transaction_response.errors.include?('V6047')) + end + + def teardown; end + end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/response/access_code_to_create_cust_converter_test.rb b/test/eway_rapid/message/convert/response/access_code_to_create_cust_converter_test.rb new file mode 100644 index 0000000..769e29c --- /dev/null +++ b/test/eway_rapid/message/convert/response/access_code_to_create_cust_converter_test.rb @@ -0,0 +1,26 @@ +require_relative '../../../../test_base' + +module EwayRapid + module Message + module Convert + module Response + class AccessCodeToCreateCustConverterTest < TestBase + + def setup + @convert = AccessCodeToCreateCust.new + json = '{"AccessCode":"C3AB9ps780Y_gslZ4qpPNvOUwynNt-HOLzfvNDAoxxCfljjZiFPJIrYs4k0TpSAaYWw2AGxNH3hZfIlqKdCX_qGgzVTa8jBFSFSTv3wwk9CiNIWVAOm64gHAS6frxFkmqHmOc","Customer":{"CardNumber":"","CardStartMonth":"","CardStartYear":"","CardIssueNumber":"","CardName":"","CardExpiryMonth":"","CardExpiryYear":"","IsActive":false,"TokenCustomerID":null,"Reference":"","Title":"Mr.","FirstName":"John","LastName":"Smith","CompanyName":"eWAY","JobDescription":"Ruby Developer","Street1":"Level 5","Street2":"369 Queen Street","City":"Sydney","State":"NSW","PostalCode":"2000","Country":"au","Email":"","Phone":"0123456789","Mobile":"0123456789","Comments":"","Fax":"1234","Url":"http://www.ewaypayments.com"},"Payment":{"TotalAmount":0,"InvoiceNumber":null,"InvoiceDescription":null,"InvoiceReference":null,"CurrencyCode":"AUD"},"FormActionURL":"https://secure-au.sandbox.ewaypayments.com/Process","CompleteCheckoutURL":null,"Errors":null}' + @response = CreateAccessCodeResponse.from_json(json) + end + + def test_do_convert + customer_response = @convert.do_convert(@response) + assert_equal('John', customer_response.customer.first_name) + assert_equal('Level 5', customer_response.customer.address.street1) + end + + def teardown; end + end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/response/access_code_to_create_trans_converter_test.rb b/test/eway_rapid/message/convert/response/access_code_to_create_trans_converter_test.rb new file mode 100644 index 0000000..ff53d16 --- /dev/null +++ b/test/eway_rapid/message/convert/response/access_code_to_create_trans_converter_test.rb @@ -0,0 +1,26 @@ +require_relative '../../../../test_base' + +module EwayRapid + module Message + module Convert + module Response + class AccessCodeToCreateTransConverterTest < TestBase + + def setup + @convert = AccessCodeToCreateTrans.new + json = '{"AccessCode":"60CF3L9mWK-zQ9wxakOtyfjcBpNSRIngC2X2gudGR07jB7w_a8RgW6vp3YfmUCXK9cuywC8whzukY6TldEWlq0digXA_OOlwOr5rrUiHtL6EzruLWCQS-1byCuv_lgWz8hBMp","Customer":{"CardNumber":"","CardStartMonth":"","CardStartYear":"","CardIssueNumber":"","CardName":"","CardExpiryMonth":"","CardExpiryYear":"","IsActive":false,"TokenCustomerID":null,"Reference":"","Title":"Mr.","FirstName":"John","LastName":"Smith","CompanyName":"eWAY","JobDescription":"Ruby Developer","Street1":"Level 5","Street2":"369 Queen Street","City":"Sydney","State":"NSW","PostalCode":"2000","Country":"au","Email":"","Phone":"0123456789","Mobile":"0123456789","Comments":"","Fax":"1234","Url":"http://www.ewaypayments.com"},"Payment":{"TotalAmount":1000,"InvoiceNumber":"Inv 21540","InvoiceDescription":"Individual Invoice Description","InvoiceReference":"513456","CurrencyCode":"AUD"},"FormActionURL":"https://secure-au.sandbox.ewaypayments.com/Process","CompleteCheckoutURL":null,"Errors":null}' + @response = CreateAccessCodeResponse.from_json(json) + end + + def test_do_convert + transRes = @convert.do_convert(@response) + assert_equal(1000, transRes.transaction.payment_details.total_amount, 0.001) + assert_equal('John', transRes.transaction.customer.first_name) + end + + def teardown; end + end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/response/direct_customer_to_query_customer_converter_test.rb b/test/eway_rapid/message/convert/response/direct_customer_to_query_customer_converter_test.rb new file mode 100644 index 0000000..772c908 --- /dev/null +++ b/test/eway_rapid/message/convert/response/direct_customer_to_query_customer_converter_test.rb @@ -0,0 +1,34 @@ +require_relative '../../../../test_base' + +module EwayRapid + module Message + module Convert + module Response + class DirectCustomerToQueryCustomerConverterTest < TestBase + + def setup + @convert = DirectCustomerToQueryCustomer.new + json = '{"Customers":[{"CardDetails":{"Number":"444433XXXXXX1111","Name":"John Smith","ExpiryMonth":"12","ExpiryYear":"25","StartMonth":"","StartYear":"","IssueNumber":""},"TokenCustomerID":912981244527,"Reference":"","Title":"Mr.","FirstName":"John","LastName":"Smith","CompanyName":"eWAY","JobDescription":"Ruby Developer","Street1":"Level 5, 369 Queen Street","Street2":null,"City":"Sydney","State":"NSW","PostalCode":"2000","Country":"Au","Email":"","Phone":"0123456789","Mobile":"0123456789","Comments":"","Fax":"1234","Url":"http://www.ewaypayments.com"}],"Errors":null}' + error_json = '{"Customers":[],"Errors":"V6040"}' + @response = DirectCustomerSearchResponse.from_json(json) + @error_response = DirectCustomerSearchResponse.from_json(error_json) + end + + def test_do_convert + customer_response = @convert.do_convert(@response) + assert_equal('12',customer_response.card_detail.expiry_month) + assert_equal('John', customer_response.first_name) + assert_equal('Sydney', customer_response.city) + end + + def test_error + customer_res = @convert.do_convert(@error_response) + assert(customer_res.errors[0].include?('V6040')) + end + + def teardown; end + end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/response/direct_payment_to_create_cust_converter_test.rb b/test/eway_rapid/message/convert/response/direct_payment_to_create_cust_converter_test.rb new file mode 100644 index 0000000..6ca4448 --- /dev/null +++ b/test/eway_rapid/message/convert/response/direct_payment_to_create_cust_converter_test.rb @@ -0,0 +1,27 @@ +require_relative '../../../../test_base' + +module EwayRapid + module Message + module Convert + module Response + class DirectPaymentToCreateCustConverterTest < TestBase + + def setup + @convert = DirectPaymentToCreateCust.new + json = '{"AuthorisationCode":null,"ResponseCode":"00","ResponseMessage":"A2000","TransactionID":null,"TransactionStatus":false,"TransactionType":"Purchase","BeagleScore":null,"Verification":{"CVN":0,"Address":0,"Email":0,"Mobile":0,"Phone":0},"Customer":{"CardDetails":{"Number":"444433XXXXXX1111","Name":"John Smith","ExpiryMonth":"12","ExpiryYear":"25","StartMonth":null,"StartYear":null,"IssueNumber":null},"TokenCustomerID":913079262890,"Reference":"","Title":"Mr.","FirstName":"John","LastName":"Smith","CompanyName":"eWAY","JobDescription":"Ruby Developer","Street1":"Level 5","Street2":"369 Queen Street","City":"Sydney","State":"NSW","PostalCode":"2000","Country":"Au","Email":"","Phone":"0123456789","Mobile":"0123456789","Comments":"","Fax":"1234","Url":"http://www.ewaypayments.com"},"Payment":{"TotalAmount":0,"InvoiceNumber":"","InvoiceDescription":"","InvoiceReference":"","CurrencyCode":"AUD"},"Errors":null}' + @response = DirectPaymentResponse.from_json(json) + end + + def test_do_convert + customer_response = @convert.do_convert(@response) + assert_equal('John', customer_response.customer.first_name) + assert_equal('Level 5', customer_response.customer.address.street1) + assert_equal('12',customer_response.customer.card_details.expiry_month) + end + + def teardown; end + end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/response/direct_payment_to_create_trans_converter_test.rb b/test/eway_rapid/message/convert/response/direct_payment_to_create_trans_converter_test.rb new file mode 100644 index 0000000..b0129dd --- /dev/null +++ b/test/eway_rapid/message/convert/response/direct_payment_to_create_trans_converter_test.rb @@ -0,0 +1,28 @@ +require_relative '../../../../test_base' + +module EwayRapid + module Message + module Convert + module Response + class DirectPaymentToCreateTransConverterTest < TestBase + + def setup + @convert = DirectPaymentToCreateTrans.new + json = '{"Errors":null,"AuthorisationCode":"843422","ResponseCode":"00","ResponseMessage":"A2000","TransactionID":11735584,"TransactionStatus":true,"TransactionType":"Purchase","BeagleScore":0,"Verification":{"CVN":0,"Address":0,"Email":0,"Mobile":0,"Phone":0},"Customer":{"CardDetails":{"Number":"444433XXXXXX1111","Name":"John Smith","ExpiryMonth":"12","ExpiryYear":"25","StartMonth":null,"StartYear":null,"IssueNumber":null},"TokenCustomerID":null,"Reference":"","Title":"Mr.","FirstName":"John","LastName":"Smith","CompanyName":"eWAY","JobDescription":"Ruby Developer","Street1":"Level 5","Street2":"369 Queen Street","City":"Sydney","State":"NSW","PostalCode":"2000","Country":"Au","Email":"","Phone":"0123456789","Mobile":"0123456789","Comments":"","Fax":"1234","Url":"http://www.ewaypayments.com"},"Payment":{"TotalAmount":1000,"InvoiceNumber":"Inv 21540","InvoiceDescription":"Individual Invoice Description","InvoiceReference":"513456","CurrencyCode":"AUD"}}' + @response = DirectPaymentResponse.from_json(json) + end + + def test_do_convert + transRes = @convert.do_convert(@response) + assert_equal(Enums::TransactionType::PURCHASE, transRes.transaction.transaction_type) + assert_equal(1000, transRes.transaction.payment_details.total_amount, 0.001) + assert_equal('John', transRes.transaction.customer.first_name) + assert_equal('843422',transRes.transaction_status.processing_details.authorisation_code) + end + + def teardown; end + end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/response/direct_refund_to_refund_response_converter_test.rb b/test/eway_rapid/message/convert/response/direct_refund_to_refund_response_converter_test.rb new file mode 100644 index 0000000..830bb6d --- /dev/null +++ b/test/eway_rapid/message/convert/response/direct_refund_to_refund_response_converter_test.rb @@ -0,0 +1,27 @@ +require_relative '../../../../test_base' + +module EwayRapid + module Message + module Convert + module Response + class DirectRefundToRefundResponseConverterTest < TestBase + + def setup + @convert = DirectRefundToRefundResponse.new + json = '{"AuthorisationCode":"480233","ResponseCode":null,"ResponseMessage":"A2000","TransactionID":11735642,"TransactionStatus":true,"Verification":null,"Customer":{"CardDetails":{"Number":"","Name":"","ExpiryMonth":"12","ExpiryYear":"25","StartMonth":"","StartYear":"","IssueNumber":""},"TokenCustomerID":null,"Reference":"","Title":"Mr.","FirstName":"John","LastName":"Smith","CompanyName":"eWAY","JobDescription":"Ruby Developer","Street1":"Level 5","Street2":"369 Queen Street","City":"Sydney","State":"NSW","PostalCode":"2000","Country":"au","Email":"","Phone":"0123456789","Mobile":"0123456789","Comments":"","Fax":"1234","Url":"http://www.ewaypayments.com"},"Refund":{"TransactionID":"11735641","TotalAmount":1000,"InvoiceNumber":"Inv 21540","InvoiceDescription":"Individual Invoice Description","InvoiceReference":"513456","CurrencyCode":"AUD"},"Errors":null}' + @response = DirectRefundResponse.from_json(json) + end + + def test_do_convert + res = @convert.do_convert(@response) + assert_equal(1000, res.refund.refund_details.total_amount, 0.001) + assert_equal('John', res.refund.customer.first_name) + assert_equal('12',res.refund.customer.card_details.expiry_month) + end + + def teardown; end + end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/response/search_to_query_trans_converter_test.rb b/test/eway_rapid/message/convert/response/search_to_query_trans_converter_test.rb new file mode 100644 index 0000000..81bd8b0 --- /dev/null +++ b/test/eway_rapid/message/convert/response/search_to_query_trans_converter_test.rb @@ -0,0 +1,25 @@ +require_relative '../../../../test_base' + +module EwayRapid + module Message + module Convert + module Response + class SearchToQueryTransConverterTest < TestBase + def setup + @convert = SearchToQueryTrans.new + json = '{"Transactions":[{"AuthorisationCode":"607313","ResponseCode":"00","ResponseMessage":"A2000","InvoiceNumber":"Inv 21540","InvoiceReference":"513456","TotalAmount":1000,"TransactionID":11735670,"TransactionStatus":true,"TokenCustomerID":null,"BeagleScore":0,"Options":[],"Verification":{"CVN":0,"Address":0,"Email":0,"Mobile":0,"Phone":0},"BeagleVerification":{"Email":0,"Phone":0},"Customer":{"TokenCustomerID":null,"Reference":null,"Title":null,"FirstName":"John","LastName":"Smith","CompanyName":null,"JobDescription":null,"Street1":"Level 5","Street2":"369 Queen Street","City":"Sydney","State":"NSW","PostalCode":"2000","Country":"Au","Email":"","Phone":"0123456789","Mobile":null,"Comments":null,"Fax":null,"Url":null},"CustomerNote":null,"ShippingAddress":{"ShippingMethod":null,"FirstName":"","LastName":"","Street1":"Level 5","Street2":"369 Queen Street","City":"Sydney","State":"NSW","Country":"Au","PostalCode":"2000","Email":"","Phone":"","Fax":null}}],"Errors":""}' + @response = TransactionSearchResponse.from_json(json) + end + + def test_do_convert + res = @convert.do_convert(@response) + assert_equal(1000, res.transaction.payment_details.total_amount, 0.001) + assert_equal(0, res.transaction_status.beagle_score, 0.001) + end + + def teardown; end + end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/shipping_details_to_address_converter_test.rb b/test/eway_rapid/message/convert/shipping_details_to_address_converter_test.rb new file mode 100644 index 0000000..5a36c38 --- /dev/null +++ b/test/eway_rapid/message/convert/shipping_details_to_address_converter_test.rb @@ -0,0 +1,39 @@ +require_relative '../../../test_base' + +module EwayRapid + module Message + module Convert +class ShippingDetailsToAddressConverterTest < TestBase + + def setup + @convert = ShippingDetailsToAddress.new + end + + def test_do_convert + detail = ObjectCreator.create_shipping_details + address = @convert.do_convert(detail) + assert_equal('John', address.first_name) + assert_equal('Sydney', address.city) + assert_equal(Enums::ShippingMethod::NEXT_DAY, address.shipping_method) + end + + def test_nil_shipping_detail + address = @convert.do_convert(nil) + assert_nil(address.first_name) + end + + def test_nil_address + detail = ObjectCreator.create_shipping_details + detail.shipping_address = nil + detail.shipping_method = nil + address = @convert.do_convert(detail) + assert_nil(address.city) + end + + def teardown + + end +end + end + end +end diff --git a/test/eway_rapid/message/convert/transaction_to_arr_line_item_converter_test.rb b/test/eway_rapid/message/convert/transaction_to_arr_line_item_converter_test.rb new file mode 100644 index 0000000..d9ac713 --- /dev/null +++ b/test/eway_rapid/message/convert/transaction_to_arr_line_item_converter_test.rb @@ -0,0 +1,31 @@ +require_relative '../../../test_base' + +module EwayRapid + module Message + module Convert + class TransactionToArrLineItemConverterTest < TestBase + + def setup + @convert = TransactionToArrLineItem.new + end + + def test_do_convert + transaction = ObjectCreator.create_transaction + transaction.line_items = ObjectCreator.create_line_items + items = @convert.do_convert(transaction) + assert_equal(1, items.length) + end + + def test_nil_item + t = ObjectCreator.create_transaction + items = @convert.do_convert(t) + assert(items.length == 0) + end + + def teardown + + end + end + end + end +end diff --git a/test/eway_rapid/message/convert/transaction_to_payment_converter_test.rb b/test/eway_rapid/message/convert/transaction_to_payment_converter_test.rb new file mode 100644 index 0000000..50e7ab6 --- /dev/null +++ b/test/eway_rapid/message/convert/transaction_to_payment_converter_test.rb @@ -0,0 +1,29 @@ +require_relative '../../../test_base' + +module EwayRapid + module Message + module Convert + class TransactionToPaymentConverterTest < TestBase + + def setup + @convert = TransactionToPayment.new + end + + def test_do_convert + transaction = ObjectCreator.create_transaction + transaction.payment_details = ObjectCreator.create_payment_details + payment = @convert.do_convert(transaction) + assert_equal(1000, payment.total_amount, 0.001) + end + + def test_nil_payment + t = ObjectCreator.create_transaction + payment = @convert.do_convert(t) + assert_equal(0, payment.total_amount) + end + + def teardown; end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/transaction_to_shipping_address_converter_test.rb b/test/eway_rapid/message/convert/transaction_to_shipping_address_converter_test.rb new file mode 100644 index 0000000..a880889 --- /dev/null +++ b/test/eway_rapid/message/convert/transaction_to_shipping_address_converter_test.rb @@ -0,0 +1,37 @@ +require_relative '../../../test_base' + +module EwayRapid + module Message + module Convert + class TransactionToShippingAddressConverterTest < TestBase + + def setup + @convert = TransactionShippingAddress.new + end + + def test_do_convert + transaction = ObjectCreator.create_transaction + transaction.shipping_details = ObjectCreator.create_shipping_details + address = @convert.do_convert(transaction) + assert_equal('Sydney', address.city) + end + + def test_nil_shipping_detail + t = ObjectCreator.create_transaction + address = @convert.do_convert(t) + assert_nil(address.city) + end + + def test_nil_address + transaction = ObjectCreator.create_transaction + transaction.shipping_details = ObjectCreator.create_shipping_details + transaction.shipping_details.shipping_address = nil + address = @convert.do_convert(transaction) + assert_nil(address.city) + end + + def teardown; end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/message/convert/verification_to_verification_result_converter_test.rb b/test/eway_rapid/message/convert/verification_to_verification_result_converter_test.rb new file mode 100644 index 0000000..cd61160 --- /dev/null +++ b/test/eway_rapid/message/convert/verification_to_verification_result_converter_test.rb @@ -0,0 +1,29 @@ +require_relative '../../../test_base' + +module EwayRapid + module Message + module Convert + class VerificationToVerificationResultConverterTest < TestBase + + def setup + @convert = VerificationToVerificationResult.new + end + + def test_do_convert + verification = ObjectCreator.create_verification + vr = @convert.do_convert(verification) + assert_equal(Enums::VerifyStatus::UNCHECKED, vr.cvn) + end + + def test_invalid_status + verification = ObjectCreator.create_verification + verification.address = 'a' + result = @convert.do_convert(verification) + assert_equal(result.address, nil) + end + + def teardown; end + end + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/object/create/object_creator.rb b/test/eway_rapid/object/create/object_creator.rb new file mode 100644 index 0000000..db59e65 --- /dev/null +++ b/test/eway_rapid/object/create/object_creator.rb @@ -0,0 +1,152 @@ +require_relative '../../../../lib/eway_rapid' +module EwayRapid + class ObjectCreator + + def self.create_external_customer + customer = Models::Customer.new + customer.title = 'Mr.' + customer.first_name = 'John' + customer.last_name = 'Smith' + customer.company_name = 'eWAY' + customer.job_description = 'Ruby Developer' + customer.phone = '0123456789' + customer.mobile = '0123456789' + customer.url = 'http://www.ewaypayments.com' + customer.reference = 'A12345' + customer.fax = '1234' + customer.redirect_url = 'http://www.eway.com.au' + customer.email = 'xxx@gmail.com' + customer + end + + def self.create_transaction + Models::Transaction.new + end + + def self.create_payment + payment = InternalModels::Payment.new + payment.total_amount = 1000 + payment.invoice_number = 'inv 4444' + payment.invoice_description = 'Individual Invoice Description' + payment.invoice_reference = '513456' + payment.currency_code = 'AUD' + payment + end + + def self.create_payment_details + payment_details = Models::PaymentDetails.new + payment_details.currency_code = 'AUD' + payment_details.invoice_description = 'Individual Invoice Description' + payment_details.invoice_number = 'Inv 4444' + payment_details.invoice_reference = '513456' + payment_details.total_amount = 1000 + payment_details + end + + def self.create_verification + verification = InternalModels::Verification.new + verification.address = '0' + verification.cvn = '0' + verification.email = '0' + verification.mobile = '0' + verification.phone = '0' + verification + end + + def self.create_card_details + card_details = Models::CardDetails.new + card_details.name = 'John Smith' + card_details.number = '4444333322221111' + card_details.expiry_month = '12' + card_details.expiry_year = '25' + card_details.cvn = '123' + card_details + end + + def self.create_internal_customer + customer = InternalModels::Customer.new + customer.token_customer_id = '123456789' + customer.title = 'Mr.' + customer.first_name = 'John' + customer.last_name = 'Smith' + customer.company_name = 'eWAY' + customer.job_description = 'Ruby Developer' + customer.phone = '0123456789' + customer.mobile = '0123456789' + customer.url = 'http://www.ewaypayments.com' + customer.fax = '1234' + customer.street1 = 'Level 5' + customer.street2 = '369 Queen Street' + customer.card_details = create_card_details + customer + end + + def self.create_internal_transaction + transaction = InternalModels::Transaction.new + transaction.beagle_score = 0.0 + transaction.transaction_status = true + transaction.total_amount = 1000 + transaction.transaction_id = '123456' + shipping_address = create_shipping_address + transaction.shipping_address = shipping_address + transaction + end + + def self.create_shipping_address + shipping_address = InternalModels::ShippingAddress.new + shipping_address.city = 'Sydney' + shipping_address.country = 'Au' + shipping_address.postal_code = '2000' + shipping_address.street1 = 'Level 5' + shipping_address.street2 = '369 Queen Street' + shipping_address.state = 'NSW' + shipping_address + end + + def self.create_address + address = Models::Address.new + address.city = 'Sydney' + address.country = 'Au' + address.postal_code = '2000' + address.street1 = 'Level 5' + address.street2 = '369 Queen Street' + address.state = 'NSW' + address + end + + def self.create_shipping_details + shipping_detail = Models::ShippingDetails.new + address = create_address + shipping_detail.shipping_address = address + shipping_detail.shipping_method = Enums::ShippingMethod::NEXT_DAY + shipping_detail.email = 'a@a.com' + shipping_detail.fax = '1234' + shipping_detail.first_name = 'John' + shipping_detail.last_name = 'Smith' + shipping_detail.phone = '0123456789' + shipping_detail + end + + def self.create_line_items + line_item = Models::LineItem.new + items = Array.new + items.push(line_item) + items + end + + def self.create_refund_details + refund_details = InternalModels::RefundDetails.new + refund_details.currency_code = 'AUD' + refund_details.invoice_description = 'Individual Invoice Description' + refund_details.invoice_number = 'Inv 21540' + refund_details.invoice_reference = '513456' + refund_details.total_amount = 1000 + end + + def self.create_options + options = Array.new + options.push('Option 1') + options + end + end +end \ No newline at end of file diff --git a/test/eway_rapid/rapid_client_test.rb b/test/eway_rapid/rapid_client_test.rb new file mode 100644 index 0000000..4d0e608 --- /dev/null +++ b/test/eway_rapid/rapid_client_test.rb @@ -0,0 +1,112 @@ +require_relative '../test_base' +class RapidClientTest < TestBase + + def test_valid_rapid_client_input_param + api_key = 'skjskj' + password = 'uncover' + endpoint = 'https://api.sandbox.ewaypayments.com/' + + client = EwayRapid::RapidClient.new(api_key, password, endpoint) + errors = client.get_errors + + assert(client.get_valid?) + assert_equal(errors.length, 0) + end + + def test_invalid_rapid_endpoint + api_key = 'skjskj' + password = 'uncover' + endpoint = '' + + client = EwayRapid::RapidClient.new(api_key, password, endpoint) + errors = client.get_errors + + assert(!client.get_valid?) + assert_equal(errors.length, 1) + assert_equal(errors[0], EwayRapid::Constants::LIBRARY_NOT_HAVE_ENDPOINT_ERROR_CODE) + end + + def test_missing_api_key_or_password + api_key = 'skjskj' + password = '' + endpoint = 'http://' + + client = EwayRapid::RapidClient.new(api_key, password, endpoint) + errors = client.get_errors + + assert(!client.get_valid?) + assert_equal(errors.length, 1) + assert_equal(errors[0], EwayRapid::Constants::API_KEY_INVALID_ERROR_CODE) + end + + def test_missing_api_key_and_rapid_endpoint + api_key = 'skjskj' + password = '' + endpoint = '' + + client = EwayRapid::RapidClient.new(api_key, password, endpoint) + errors = client.get_errors + + assert(!client.get_valid?) + assert_equal(errors.length, 2) + assert(errors.include?EwayRapid::Constants::LIBRARY_NOT_HAVE_ENDPOINT_ERROR_CODE) + assert(errors.include?EwayRapid::Constants::API_KEY_INVALID_ERROR_CODE) + end + + def test_invalid_set_credential + api_key = 'skjskj' + password = 'uncover' + endpoint = 'https://api.sandbox.ewaypayments.com/' + + client = EwayRapid::RapidClient.new(api_key, password, endpoint) + assert(client.get_valid?) + + api_key = '' + password = 'uncover' + + client.set_credentials(api_key, password) + errors = client.get_errors + assert(!client.get_valid?) + assert_equal(errors.length, 1) + assert(errors.include?EwayRapid::Constants::API_KEY_INVALID_ERROR_CODE) + end + + def test_invalid_when_install_client_but_valid_set_credential + api_key = 'skjskj' + password = '' + endpoint = 'https://api.sandbox.ewaypayments.com/' + + client = EwayRapid::RapidClient.new(api_key, password, endpoint) + errors = client.get_errors + assert(!client.get_valid?) + assert_equal(errors.length, 1) + + api_key = 'skjskj' + password = 'uncover' + client.set_credentials(api_key, password) + errors = client.get_errors + assert(client.get_valid?) + assert_equal(errors.length, 0) + end + + def test_init_client_with_rapid_enpoin_is_sandbox_or_production + api_key = 'skjskj' + password = 'jjhhjk' + endpoint = 'sandbox' + + client = EwayRapid::RapidClient.new(api_key, password, endpoint) + web_url = client.instance_variable_get('@web_url') + + property_array = YAML.load_file(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'eway_rapid', 'resources', 'rapid-api.yml')) + property_array.each do |h| + if EwayRapid::Constants::GLOBAL_RAPID_SANDBOX_REST_URL_PARAM.casecmp(h.keys.first).zero? + assert(web_url.casecmp(h[h.keys.first]).zero?) + end + end + end + + def test_find_error_code + error_code = 'S9991' + assert_equal('Library does not have PublicAPI key initialised, or Key is Invalid', EwayRapid::RapidClient.user_display_message(error_code)) + end +end \ No newline at end of file diff --git a/test/input_model_factory.rb b/test/input_model_factory.rb new file mode 100644 index 0000000..9d52c23 --- /dev/null +++ b/test/input_model_factory.rb @@ -0,0 +1,112 @@ +require_relative '../lib/eway_rapid' +module EwayRapid + class InputModelFactory + + # @return [Models::Transaction] + def self.create_transaction + transaction = Models::Transaction.new + transaction.partner_id = '9889897' + transaction.cancel_url = '' + transaction.capture = true + transaction.checkout_url = true + transaction.redirect_url = 'http://www.eway.com.au' + transaction.device_id = '546545' + transaction.transaction_type = Enums::TransactionType::PURCHASE + list_option = Array.new + list_option.push('Option1') + transaction.options = list_option + list_item = Array.new + item = Models::LineItem.new + item.sku = '12345678901234567890' + item.description = 'Item Description 1' + item.quantity = 1 + item.unit_cost = 400 + item.tax = 100 + item.total = 500 + list_item.push(item) + transaction.line_items = list_item + transaction + end + + def self.create_customer + customer = Models::Customer.new + customer.title = 'Mr.' + customer.first_name = 'John' + customer.last_name = 'Smith' + customer.company_name = 'eWay' + customer.job_description = 'Ruby Developer' + customer.phone = '0123456789' + customer.mobile = '0123456789' + customer.url = 'http://www.ewaypayments.com' + customer.redirect_url = 'http://www.eway.com.au' + customer.email = 'xxx@gmail.com' + customer + end + + def self.create_address + address = Models::Address.new + address.city = 'Sydney' + address.country = 'Au' + address.postal_code = '2000' + address.street1 = 'Level 5' + address.street2 = '369 Queen Street' + address.state = 'NSW' + address + end + + def self.create_address_by_object(city, country, postal_code, state) + address = Models::Address.new + address.city = city + address.country = country + address.postal_code = postal_code + address.state = state + address + end + + def self.create_payment_details + payment_details = Models::PaymentDetails.new + payment_details.currency_code = 'AUD' + payment_details.invoice_description = 'Individual Invoice Description' + payment_details.invoice_number = 'Inv 21540' + payment_details.invoice_reference = '513456' + payment_details.total_amount = 1000 + payment_details + end + + def self.create_payment_details_with(invoice_number, invoice_reference) + payment_details = Models::PaymentDetails.new + payment_details.currency_code = 'AUD' + payment_details.invoice_description = 'Individual Invoice Description' + payment_details.invoice_number = invoice_number + payment_details.invoice_reference = invoice_reference + payment_details.total_amount = 1000 + payment_details + end + + def self.create_card_detail(expiry_month, expiry_year) + card_details = Models::CardDetails.new + card_details.name = 'John Smith' + card_details.number = '4444333322221111' + card_details.expiry_month = expiry_month + card_details.expiry_year = expiry_year + card_details.cvn = '123' + card_details + end + + def self.create_shipping_detail + shipping_detail = Models::ShippingDetails.new + shipping_detail.shipping_method = Enums::ShippingMethod::LOW_COST + shipping_detail.email = 'someone@yahoo.com' + shipping_detail.fax = '12345689' + shipping_detail.first_name = 'Dave' + shipping_detail.last_name = 'David' + shipping_detail.phone = '0123456789' + shipping_detail + end + + def self.random_string(number) + o = [('a'..'z'), ('A'..'Z')].map { |i| i.to_a }.flatten + (0...number).map { o[rand(o.length)] }.join + end + end +end diff --git a/test/test_base.rb b/test/test_base.rb new file mode 100644 index 0000000..00eb926 --- /dev/null +++ b/test/test_base.rb @@ -0,0 +1,12 @@ +require 'simplecov' +SimpleCov.start + +require 'test/unit' +require_relative '../lib/eway_rapid' +require_relative 'input_model_factory' +require_relative 'eway_rapid/object/create/object_creator' +require_relative 'eway_rapid/integration/integration_test' + +class TestBase < Test::Unit::TestCase +end +