workarea-usaepay 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/Gemfile +17 -0
  4. data/LICENSE +52 -0
  5. data/README.md +43 -0
  6. data/Rakefile +56 -0
  7. data/app/assets/images/workarea/admin/usaepay/.keep +0 -0
  8. data/app/assets/images/workarea/storefront/usaepay/.keep +0 -0
  9. data/app/assets/javascripts/workarea/admin/usaepay/.keep +0 -0
  10. data/app/assets/javascripts/workarea/storefront/usaepay/.keep +0 -0
  11. data/app/assets/stylesheets/workarea/admin/usaepay/.keep +0 -0
  12. data/app/assets/stylesheets/workarea/storefront/usaepay/.keep +0 -0
  13. data/app/controllers/.keep +0 -0
  14. data/app/helpers/.keep +0 -0
  15. data/app/mailers/.keep +0 -0
  16. data/app/models/.keep +0 -0
  17. data/app/models/workarea/payment/authorize/credit_card.decorator +34 -0
  18. data/app/models/workarea/payment/credit_card_data.rb +29 -0
  19. data/app/models/workarea/payment/store_credit_card.decorator +13 -0
  20. data/app/views/.keep +0 -0
  21. data/bin/rails +25 -0
  22. data/config/initializers/workarea.rb +5 -0
  23. data/config/routes.rb +2 -0
  24. data/lib/usaepay/gateway.rb +94 -0
  25. data/lib/workarea/storefront/system_test.rb +156 -0
  26. data/lib/workarea/usaepay.rb +44 -0
  27. data/lib/workarea/usaepay/engine.rb +10 -0
  28. data/lib/workarea/usaepay/version.rb +5 -0
  29. data/test/dummy/.ruby-version +1 -0
  30. data/test/dummy/Rakefile +6 -0
  31. data/test/dummy/app/assets/config/manifest.js +2 -0
  32. data/test/dummy/app/assets/images/.keep +0 -0
  33. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  34. data/test/dummy/app/controllers/application_controller.rb +2 -0
  35. data/test/dummy/app/controllers/concerns/.keep +0 -0
  36. data/test/dummy/app/helpers/application_helper.rb +2 -0
  37. data/test/dummy/app/javascript/packs/application.js +14 -0
  38. data/test/dummy/app/jobs/application_job.rb +7 -0
  39. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  40. data/test/dummy/app/models/concerns/.keep +0 -0
  41. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  42. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  43. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  44. data/test/dummy/bin/rails +4 -0
  45. data/test/dummy/bin/rake +4 -0
  46. data/test/dummy/bin/setup +25 -0
  47. data/test/dummy/config.ru +5 -0
  48. data/test/dummy/config/application.rb +33 -0
  49. data/test/dummy/config/boot.rb +5 -0
  50. data/test/dummy/config/environment.rb +5 -0
  51. data/test/dummy/config/environments/development.rb +53 -0
  52. data/test/dummy/config/environments/production.rb +101 -0
  53. data/test/dummy/config/environments/test.rb +47 -0
  54. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  55. data/test/dummy/config/initializers/assets.rb +12 -0
  56. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  57. data/test/dummy/config/initializers/content_security_policy.rb +28 -0
  58. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  59. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  60. data/test/dummy/config/initializers/inflections.rb +16 -0
  61. data/test/dummy/config/initializers/mime_types.rb +4 -0
  62. data/test/dummy/config/initializers/workarea.rb +5 -0
  63. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  64. data/test/dummy/config/locales/en.yml +33 -0
  65. data/test/dummy/config/puma.rb +38 -0
  66. data/test/dummy/config/routes.rb +5 -0
  67. data/test/dummy/config/spring.rb +6 -0
  68. data/test/dummy/db/seeds.rb +2 -0
  69. data/test/dummy/lib/assets/.keep +0 -0
  70. data/test/dummy/log/.keep +0 -0
  71. data/test/models/workarea/payment/authorize/credit_card_test.decorator +15 -0
  72. data/test/models/workarea/payment/credit_card_integration_test.decorator +5 -0
  73. data/test/support/workarea/usaepay_transaction_vcr_gateway.rb +22 -0
  74. data/test/teaspoon_env.rb +6 -0
  75. data/test/test_helper.rb +10 -0
  76. data/workarea-usaepay.gemspec +21 -0
  77. metadata +132 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b30df041f01334ecf40f091fe0d143970fbb5fd05347061507541e920ecb621b
4
+ data.tar.gz: 9cfb153b53d92da60ec617fc7eb4176ea864b6f8ebd732c40d18a16d046c1104
5
+ SHA512:
6
+ metadata.gz: 49784db44ef5aa1d0699e1c6c56f98280435cf058e5ff1113d823ee216bb1e440a7eb8fe4b931359fcbc01280853d3b23cccb8dd87874acf5aae678afb52018a
7
+ data.tar.gz: c4a9ff01451151fe376caf45b3dc61fddc9afc6da7a66293973022957a9d48d2a24a8906e089b0a0bb927c42d4a09ae24036ba45aed9cda742a4071905c4eab1
@@ -0,0 +1,21 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/log/*.log
5
+ test/dummy/tmp/
6
+ .DS_Store
7
+ .byebug_history
8
+ .bundle/
9
+ .sass-cache/
10
+ Gemfile.lock
11
+ pkg/
12
+ test/dummy/tmp/
13
+ test/dummy/public/
14
+ log/*.log
15
+ test/dummy/log/*.log
16
+ test/dummy/db/*.sqlite3
17
+ test/dummy/db/*.sqlite3-journal
18
+ node_modules
19
+ yarn.lock
20
+ yarn-error.log
21
+ package-lock.json
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+
4
+ # Declare your gem's dependencies in usaepay.gemspec.
5
+ # Bundler will treat runtime dependencies like base dependencies, and
6
+ # development dependencies will be added by default to the :development group.
7
+ gemspec
8
+
9
+ # Declare any dependencies that are still in development here instead of in
10
+ # your gemspec. These might include edge Rails or gems from your path or
11
+ # Git. Remember to move these dependencies to your gemspec before releasing
12
+ # your gem to rubygems.org.
13
+
14
+ # To use a debugger
15
+ # gem 'byebug', group: [:development, :test]
16
+
17
+ gem 'workarea', github: 'workarea-commerce/workarea'
data/LICENSE ADDED
@@ -0,0 +1,52 @@
1
+ WebLinc
2
+ Business Source License
3
+
4
+ Licensor: WebLinc Corporation, 22 S. 3rd Street, 2nd Floor, Philadelphia PA 19106
5
+
6
+ Licensed Work: Workarea Commerce Platform
7
+ The Licensed Work is (c) 2019 WebLinc Corporation
8
+
9
+ Additional Use Grant:
10
+ You may make production use of the Licensed Work without an additional license agreement with WebLinc so long as you do not use the Licensed Work for a Commerce Service.
11
+
12
+ A "Commerce Service" is a commercial offering that allows third parties (other than your employees and contractors) to access the functionality of the Licensed Work by creating or managing commerce functionality, the products, taxonomy, assets and/or content of which are controlled by such third parties.
13
+
14
+ For information about obtaining an additional license agreement with WebLinc, contact licensing@workarea.com.
15
+
16
+ Change Date: 2019-08-20
17
+
18
+ Change License: Version 2.0 or later of the GNU General Public License as published by the Free Software Foundation
19
+
20
+ Terms
21
+
22
+ The Licensor hereby grants you the right to copy, modify, create derivative works, redistribute, and make non-production use of the Licensed Work. The Licensor may make an Additional Use Grant, above, permitting limited production use.
23
+
24
+ Effective on the Change Date, or the fourth anniversary of the first publicly available distribution of a specific version of the Licensed Work under this License, whichever comes first, the Licensor hereby grants you rights under the terms of the Change License, and the rights granted in the paragraph above terminate.
25
+
26
+ If your use of the Licensed Work does not comply with the requirements currently in effect as described in this License, you must purchase a commercial license from the Licensor, its affiliated entities, or authorized resellers, or you must refrain from using the Licensed Work.
27
+
28
+ All copies of the original and modified Licensed Work, and derivative works of the Licensed Work, are subject to this License. This License applies separately for each version of the Licensed Work and the Change Date may vary for each version of the Licensed Work released by Licensor.
29
+
30
+ You must conspicuously display this License on each original or modified copy of the Licensed Work. If you receive the Licensed Work in original or modified form from a third party, the terms and conditions set forth in this License apply to your use of that work.
31
+
32
+ Any use of the Licensed Work in violation of this License will automatically terminate your rights under this License for the current and all other versions of the Licensed Work.
33
+
34
+ This License does not grant you any right in any trademark or logo of Licensor or its affiliates (provided that you may use a trademark or logo of Licensor as expressly required by this License). TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE. MariaDB hereby grants you permission to use this License’s text to license your works and to refer to it using the trademark "Business Source License" as long as you comply with the Covenants of Licensor below.
35
+
36
+ Covenants of Licensor
37
+ In consideration of the right to use this License’s text and the "Business Source License" name and trademark, Licensor covenants to MariaDB, and to all other recipients of the licensed work to be provided by Licensor:
38
+
39
+ To specify as the Change License the GPL Version 2.0 or any later version, or a license that is compatible with GPL Version 2.0 or a later version, where "compatible" means that software provided under the Change License can be included in a program with software provided under GPL Version 2.0 or a later version. Licensor may specify additional Change Licenses without limitation.
40
+
41
+ To either: (a) specify an additional grant of rights to use that does not impose any additional restriction on the right granted in this License, as the Additional Use Grant; or (b) insert the text "None."
42
+
43
+ To specify a Change Date.
44
+
45
+ Not to modify this License in any other way.
46
+
47
+ Notice
48
+ The Business Source License (this document, or the "License") is not an Open Source license. However, the Licensed Work will eventually be made available under an Open Source License, as stated in this License.
49
+
50
+ For more information on the use of the Business Source License generally, please visit the Adopting and Developing Business Source License FAQ.
51
+
52
+ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved. "Business Source License" is a trademark of MariaDB Corporation Ab.
@@ -0,0 +1,43 @@
1
+ Workarea Usaepay
2
+ ================================================================================
3
+
4
+ Usaepay plugin for the Workarea platform developed by Trika Tehnologies
5
+
6
+ Overview
7
+ --------------------------------------------------------------------------------
8
+
9
+ A plugin to integrate USA ePay transaction gateway with workarea E-Commerce. This will connect to sanbox / live using site urls and test params. This gateway plugin was written on top of ActiveMerchant::Billing::UsaEpayTransactionGateway
10
+
11
+ Getting Started
12
+ --------------------------------------------------------------------------------
13
+
14
+ This gem contains a Rails engine that must be mounted onto a host Rails application.
15
+
16
+ Then add the gem to your application's Gemfile specifying the source:
17
+
18
+ # ...
19
+ gem 'workarea-usaepay'
20
+ # ...
21
+
22
+ Update your application's bundle.
23
+
24
+ cd path/to/application
25
+ bundle
26
+
27
+ Features
28
+ --------------------------------------------------------------------------------
29
+
30
+ - Ability to perform Auth only, Purchase, Capture and Void payments
31
+ - Ability to verify cards before make Auth call
32
+ - Ability to save the card by token
33
+ - Ability to use saved cards for transaction using saved cards token
34
+
35
+ Workarea Platform Documentation
36
+ --------------------------------------------------------------------------------
37
+
38
+ See [https://developer.workarea.com](https://developer.workarea.com) for Workarea platform documentation.
39
+
40
+ License
41
+ --------------------------------------------------------------------------------
42
+
43
+ Workarea Usaepay is released under the [Business Software License](LICENSE)
@@ -0,0 +1,56 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+ RDoc::Task.new(:rdoc) do |rdoc|
9
+ rdoc.rdoc_dir = 'rdoc'
10
+ rdoc.title = 'Usaepay'
11
+ rdoc.options << '--line-numbers'
12
+ rdoc.rdoc_files.include('README.md')
13
+ rdoc.rdoc_files.include('lib/**/*.rb')
14
+ end
15
+
16
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
17
+ load 'rails/tasks/engine.rake'
18
+ load 'rails/tasks/statistics.rake'
19
+ load 'workarea/changelog.rake'
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |t|
23
+ t.libs << 'lib'
24
+ t.libs << 'test'
25
+ t.pattern = 'test/**/*_test.rb'
26
+ t.verbose = false
27
+ end
28
+ task default: :test
29
+
30
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
31
+ require 'workarea/usaepay/version'
32
+
33
+ desc "Release version #{Workarea::Usaepay::VERSION} of the gem"
34
+ task :release do
35
+ Rake::Task['workarea:changelog'].execute
36
+ system 'git add CHANGELOG.md'
37
+ system 'git commit -m "Update CHANGELOG"'
38
+
39
+ system "git tag -a v#{Workarea::Usaepay::VERSION} -m 'Tagging #{Workarea::Usaepay::VERSION}'"
40
+ system 'git push origin HEAD --follow-tags'
41
+
42
+ system "gem build workarea-usaepay.gemspec"
43
+ system "gem push workarea-usaepay-#{Workarea::Usaepay::VERSION}.gem"
44
+ system "rm workarea-usaepay-#{Workarea::Usaepay::VERSION}.gem"
45
+ end
46
+
47
+ desc 'Run the JavaScript tests'
48
+ ENV['TEASPOON_RAILS_ENV'] = File.expand_path('../test/dummy/config/environment', __FILE__)
49
+ task teaspoon: 'app:teaspoon'
50
+
51
+ desc 'Start a server at http://localhost:3000/teaspoon for JavaScript tests'
52
+ task :teaspoon_server do
53
+ Dir.chdir("test/dummy")
54
+ teaspoon_env = File.expand_path('../test/teaspoon_env.rb', __FILE__)
55
+ system "RAILS_ENV=test TEASPOON_ENV=#{teaspoon_env} rails s"
56
+ end
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,34 @@
1
+ module Workarea
2
+ decorate Payment::Authorize::CreditCard, with: :usaepay do #[2]
3
+ decorated do
4
+ include Payment::CreditCardData
5
+ delegate :address, to: :tender
6
+ end
7
+
8
+ def complete! #[3]
9
+ return unless Payment::StoreCreditCard.new(tender, options).save! #[4]
10
+
11
+ transaction.response = #[5][6]
12
+ handle_active_merchant_errors do #[7]
13
+ gateway.authorize( #[8]
14
+ transaction.amount.cents, #[9]
15
+ payment_source,
16
+ transaction_args #[10]
17
+ )
18
+ end
19
+
20
+ transaction.success?
21
+ end
22
+
23
+ def cancel! #[11]
24
+ return unless transaction.success? #[12]
25
+
26
+ transaction.cancellation = #[13][6]
27
+ handle_active_merchant_errors do #[7]
28
+ gateway.void( #[14]
29
+ transaction.response.authorization #[15]
30
+ )
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,29 @@
1
+ module Workarea
2
+ class Payment
3
+ module CreditCardData
4
+ def transaction_args
5
+ {
6
+ order_id: tender.payment.id,
7
+ billing_address: billing_address
8
+ }
9
+ end
10
+
11
+ def billing_address
12
+ {
13
+ name: "#{address.first_name} #{address.last_name}",
14
+ company: address.company,
15
+ address1: address.street,
16
+ city: address.city,
17
+ state: address.region,
18
+ country: address.country.try(:alpha2),
19
+ zip: address.postal_code,
20
+ phone: nil
21
+ }
22
+ end
23
+
24
+ def payment_source
25
+ tender.token.presence || tender.to_active_merchant
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ module Workarea
2
+ decorate Payment::StoreCreditCard, with: :payflow do
3
+ def perform!
4
+ return true if @credit_card.token.present?
5
+
6
+ response = handle_active_merchant_errors do
7
+ gateway.verify(@credit_card.to_active_merchant, {save_card: true})
8
+ end
9
+ @credit_card.token = response.params['token']
10
+ response.success?
11
+ end
12
+ end
13
+ end
File without changes
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('..', __dir__)
6
+ ENGINE_PATH = File.expand_path('../lib/workarea/usaepay/engine', __dir__)
7
+ APP_PATH = File.expand_path('../test/dummy/config/application', __dir__)
8
+
9
+ # Set up gems listed in the Gemfile.
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
11
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
12
+
13
+ require "rails"
14
+ # Pick the frameworks you want:
15
+ require "active_model/railtie"
16
+ require "active_job/railtie"
17
+ # require "active_record/railtie"
18
+ # require "active_storage/engine"
19
+ require "action_controller/railtie"
20
+ require "action_mailer/railtie"
21
+ require "action_view/railtie"
22
+ # require "action_cable/engine"
23
+ require "sprockets/railtie"
24
+ require "rails/test_unit/railtie"
25
+ require 'rails/engine/commands'
@@ -0,0 +1,5 @@
1
+ Workarea::Usaepay.auto_initialize_gateway
2
+
3
+ Workarea.configure do |config|
4
+ config.gateways.usa_epay = 'Workarea::UsaEpay::Gateway'
5
+ end
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,94 @@
1
+
2
+ module ActiveMerchant
3
+ module Billing
4
+ class UsaEpayCustom < UsaEpayTransactionGateway
5
+ attr_reader :key, :pin, :options
6
+ class_attribute :test_rest_endpoint, :production_rest_endpoint
7
+
8
+
9
+ def authorize(money, credit_card, options = {})
10
+ post = {}
11
+ add_amount(post, money)
12
+ add_invoice(post, options)
13
+
14
+ if credit_card.is_a? String
15
+ add_token(post, credit_card)
16
+ else
17
+ add_payment(post, credit_card)
18
+ add_address(post, credit_card, options)
19
+ unless credit_card.track_data.present?
20
+ add_customer_data(post, options)
21
+ end
22
+ end
23
+
24
+ add_split_payments(post, options)
25
+ add_recurring_fields(post, options)
26
+ add_custom_fields(post, options)
27
+ add_line_items(post, options)
28
+ add_test_mode(post, options)
29
+ add_save_card(post, options)
30
+ commit(:authorization, post)
31
+ end
32
+
33
+ def purchase(money, payment, options = {})
34
+ post = {}
35
+
36
+ add_amount(post, money)
37
+ add_invoice(post, options)
38
+
39
+ if payment.is_a? String
40
+ add_token(post, payment)
41
+ else
42
+ add_payment(post, payment, options)
43
+ unless payment.respond_to?(:track_data) && payment.track_data.present?
44
+ add_address(post, payment, options)
45
+ add_customer_data(post, options)
46
+ end
47
+ end
48
+
49
+ add_split_payments(post, options)
50
+ add_recurring_fields(post, options)
51
+ add_custom_fields(post, options)
52
+ add_line_items(post, options)
53
+ add_test_mode(post, options)
54
+ add_save_card(post, options)
55
+
56
+ payment.respond_to?(:routing_number) ? commit(:check_purchase, post) : commit(:purchase, post)
57
+ end
58
+
59
+ def add_token(post, credit_card)
60
+ post[:card] = credit_card
61
+ end
62
+
63
+ def add_save_card(post, options)
64
+ post[:saveCard] = (options[:save_card] ? 1 : 0) if options.has_key?(:save_card)
65
+ end
66
+
67
+ def parse(body)
68
+ fields = {}
69
+ for line in body.split('&')
70
+ key, value = *line.scan(%r{^(\w+)\=(.*)$}).flatten
71
+ fields[key] = CGI.unescape(value.to_s)
72
+ end
73
+ {
74
+ :status => fields['UMstatus'],
75
+ :auth_code => fields['UMauthCode'],
76
+ :ref_num => fields['UMrefNum'],
77
+ :batch => fields['UMbatch'],
78
+ :avs_result => fields['UMavsResult'],
79
+ :avs_result_code => fields['UMavsResultCode'],
80
+ :cvv2_result => fields['UMcvv2Result'],
81
+ :cvv2_result_code => fields['UMcvv2ResultCode'],
82
+ :vpas_result_code => fields['UMvpasResultCode'],
83
+ :result => fields['UMresult'],
84
+ :error => fields['UMerror'],
85
+ :error_code => fields['UMerrorcode'],
86
+ :acs_url => fields['UMacsurl'],
87
+ :payload => fields['UMpayload'],
88
+ :token => fields['UMcardRef']
89
+ }.delete_if { |k, v| v.nil? }
90
+ end
91
+
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,156 @@
1
+ module Workarea
2
+ module Storefront
3
+ module SystemTest
4
+ def setup_checkout_specs
5
+ create_supporting_data
6
+ add_product_to_cart
7
+ end
8
+
9
+ def create_supporting_data
10
+ create_tax_category(
11
+ name: 'Sales Tax',
12
+ code: '001',
13
+ rates: [{ percentage: 0.07, country: 'US', region: 'PA' }]
14
+ )
15
+
16
+ create_shipping_service(
17
+ name: 'Ground',
18
+ tax_code: '001',
19
+ rates: [{ price: 7.to_m }]
20
+ )
21
+
22
+ create_inventory(id: 'SKU', policy: 'standard', available: 5)
23
+
24
+ @product = create_product(
25
+ id: 'INT_PRODUCT',
26
+ name: 'Integration Product',
27
+ variants: [{ sku: 'SKU', tax_code: '001', regular: 5.to_m }]
28
+ )
29
+
30
+ create_user(email: 'bcrouse@workarea.com', password: 'W3bl1nc!')
31
+ end
32
+
33
+ def add_user_data
34
+ user = User.find_by_email('bcrouse@workarea.com')
35
+
36
+ user.auto_save_shipping_address(
37
+ first_name: 'Ben',
38
+ last_name: 'Crouse',
39
+ street: '22 S. 3rd St.',
40
+ city: 'Philadelphia',
41
+ region: 'PA',
42
+ postal_code: '19106',
43
+ country: 'US',
44
+ phone_number: '2159251800'
45
+ )
46
+
47
+ user.auto_save_billing_address(
48
+ first_name: 'Ben',
49
+ last_name: 'Crouse',
50
+ street: '1019 S. 47th St.',
51
+ city: 'Philadelphia',
52
+ region: 'PA',
53
+ postal_code: '19143',
54
+ country: 'US',
55
+ phone_number: '2159251800'
56
+ )
57
+
58
+ profile = Payment::Profile.lookup(PaymentReference.new(user))
59
+ profile.credit_cards.create!(
60
+ first_name: 'Ben',
61
+ last_name: 'Crouse',
62
+ number: '4111111111111111',
63
+ month: 1,
64
+ year: Time.current.year + 1,
65
+ cvv: '999'
66
+ )
67
+ end
68
+
69
+ def add_product_to_cart
70
+ product = Catalog::Product.find('INT_PRODUCT')
71
+ visit storefront.product_path(product)
72
+ click_button t('workarea.storefront.products.add_to_cart')
73
+ end
74
+
75
+ def start_guest_checkout
76
+ visit storefront.checkout_path
77
+ end
78
+
79
+ def start_user_checkout
80
+ visit storefront.checkout_path
81
+ click_link t('workarea.storefront.checkouts.login_title')
82
+
83
+ within '#login_form' do
84
+ fill_in 'email', with: 'bcrouse@workarea.com'
85
+ fill_in 'password', with: 'W3bl1nc!'
86
+ click_button t('workarea.storefront.users.login')
87
+ end
88
+ end
89
+
90
+ def fill_in_email
91
+ fill_in 'email', with: 'bcrouse-new-account@workarea.com'
92
+ end
93
+
94
+ def fill_in_shipping_address
95
+ fill_in 'shipping_address[first_name]', with: 'Ben'
96
+ fill_in 'shipping_address[last_name]', with: 'Crouse'
97
+ fill_in 'shipping_address[street]', with: '22 S. 3rd St.'
98
+ fill_in 'shipping_address[city]', with: 'Philadelphia'
99
+
100
+ if page.has_field?('shipping_address[region]')
101
+ fill_in 'shipping_address[region]', with: 'PA'
102
+ else
103
+ select 'Pennsylvania', from: 'shipping_address_region_select'
104
+ end
105
+
106
+ fill_in 'shipping_address[postal_code]', with: '19106'
107
+ fill_in 'shipping_address[phone_number]', with: '2159251800'
108
+ end
109
+
110
+ def fill_in_new_card_cvv
111
+ fill_in 'cvv[new_card]', with: '999'
112
+ end
113
+
114
+ def fill_in_credit_card
115
+ fill_in 'credit_card[number]', with: '4111111111111111'
116
+ next_year = (Time.current.year + 1).to_s
117
+ select next_year, from: 'credit_card[year]'
118
+ fill_in 'credit_card[cvv]', with: '999'
119
+ end
120
+
121
+ def fill_in_billing_address
122
+ fill_in 'billing_address[first_name]', with: 'Ben'
123
+ fill_in 'billing_address[last_name]', with: 'Crouse'
124
+ fill_in 'billing_address[street]', with: '1019 S. 47th St.'
125
+ fill_in 'billing_address[city]', with: 'Philadelphia'
126
+
127
+ if page.has_field?('billing_address[region]')
128
+ fill_in 'billing_address[region]', with: 'PA'
129
+ else
130
+ select 'Pennsylvania', from: 'billing_address_region_select'
131
+ end
132
+
133
+ fill_in 'billing_address[postal_code]', with: '19143'
134
+ fill_in 'billing_address[phone_number]', with: '2159251800'
135
+ end
136
+
137
+ def select_shipping_service
138
+ choose 'Ground'
139
+ end
140
+
141
+ def disable_analytics_dom_events
142
+ page.execute_script('WORKAREA.analytics.disableDomEvents();')
143
+ end
144
+
145
+ def find_analytics_events(for_event: nil)
146
+ all_events = page.evaluate_script('WORKAREA.analytics.events')
147
+
148
+ if for_event.blank?
149
+ all_events
150
+ else
151
+ all_events.select { |e| e['name'] == for_event }
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end