workarea-payeezy 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +12 -0
  3. data/Gemfile +9 -0
  4. data/README.md +64 -0
  5. data/Rakefile +116 -0
  6. data/app/models/workarea/payment/authorize/credit_card.decorator +20 -0
  7. data/app/models/workarea/payment/credit_card_data.rb +28 -0
  8. data/app/models/workarea/payment/purchase/credit_card.decorator +20 -0
  9. data/app/models/workarea/payment/store_credit_card.decorator +20 -0
  10. data/bin/rails +20 -0
  11. data/config/initializers/workarea.rb +1 -0
  12. data/lib/active_merchant/billing/bogus_payeezy_gateway.rb +70 -0
  13. data/lib/workarea/payeezy.rb +49 -0
  14. data/lib/workarea/payeezy/engine.rb +8 -0
  15. data/lib/workarea/payeezy/version.rb +5 -0
  16. data/script/admin_ci +9 -0
  17. data/script/ci +11 -0
  18. data/script/core_ci +9 -0
  19. data/script/plugins_ci +9 -0
  20. data/script/storefront_ci +9 -0
  21. data/test/dummy/Rakefile +6 -0
  22. data/test/dummy/app/assets/config/manifest.js +4 -0
  23. data/test/dummy/app/assets/javascripts/application.js +13 -0
  24. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  25. data/test/dummy/app/controllers/application_controller.rb +3 -0
  26. data/test/dummy/app/helpers/application_helper.rb +2 -0
  27. data/test/dummy/app/jobs/application_job.rb +2 -0
  28. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  29. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  30. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  31. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  32. data/test/dummy/bin/bundle +3 -0
  33. data/test/dummy/bin/rails +4 -0
  34. data/test/dummy/bin/rake +4 -0
  35. data/test/dummy/bin/setup +30 -0
  36. data/test/dummy/bin/update +26 -0
  37. data/test/dummy/bin/yarn +11 -0
  38. data/test/dummy/config.ru +5 -0
  39. data/test/dummy/config/application.rb +30 -0
  40. data/test/dummy/config/boot.rb +5 -0
  41. data/test/dummy/config/cable.yml +10 -0
  42. data/test/dummy/config/environment.rb +5 -0
  43. data/test/dummy/config/environments/development.rb +51 -0
  44. data/test/dummy/config/environments/production.rb +88 -0
  45. data/test/dummy/config/environments/test.rb +44 -0
  46. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  47. data/test/dummy/config/initializers/assets.rb +14 -0
  48. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  49. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  50. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  51. data/test/dummy/config/initializers/inflections.rb +16 -0
  52. data/test/dummy/config/initializers/mime_types.rb +4 -0
  53. data/test/dummy/config/initializers/workarea.rb +5 -0
  54. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  55. data/test/dummy/config/locales/en.yml +33 -0
  56. data/test/dummy/config/puma.rb +56 -0
  57. data/test/dummy/config/routes.rb +5 -0
  58. data/test/dummy/config/secrets.yml +32 -0
  59. data/test/dummy/config/spring.rb +6 -0
  60. data/test/dummy/db/seeds.rb +2 -0
  61. data/test/dummy/package.json +5 -0
  62. data/test/models/workarea/payment/payeezy_integration_test.rb +185 -0
  63. data/test/support/workarea/payeezy_gateway_vcr_config.rb +34 -0
  64. data/test/support/workarea/workarea_3_2_backports.rb +57 -0
  65. data/test/teaspoon_env.rb +6 -0
  66. data/test/test_helper.rb +7 -0
  67. data/test/vcr_cassettes/payeezy/auth_capture.yml +193 -0
  68. data/test/vcr_cassettes/payeezy/auth_capture_refund.yml +251 -0
  69. data/test/vcr_cassettes/payeezy/auth_void.yml +193 -0
  70. data/test/vcr_cassettes/payeezy/purchase_refund.yml +193 -0
  71. data/test/vcr_cassettes/payeezy/purchase_void.yml +193 -0
  72. data/test/vcr_cassettes/payeezy/store_auth.yml +135 -0
  73. data/test/vcr_cassettes/payeezy/store_purchase.yml +135 -0
  74. data/workarea-payeezy.gemspec +18 -0
  75. metadata +143 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '09c03f2e7606f207bf6ff46d916d157f96386fcdf6c57731b162fa6552f4393b'
4
+ data.tar.gz: 7f7e656b8f53c4e0eb5ccfbf143bb3985664256e24ac13ca33446e924e06d464
5
+ SHA512:
6
+ metadata.gz: d3708af523508c2fdc1e030a317573a3142b9af60021699aa5f2f399ef01938c70a038d1e5a12cbcc526ddd57e83a95950c651fb2a90c159b65357613656ad09
7
+ data.tar.gz: 10b165829df4fc3d38657b933340c447cedff75ce19b056e7d97d82b14c96ee942338172320cffb42475b3d578effa1f25d5892aa53d90596a66c3402be2d706
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ Workarea Payeezy 1.0.0 (2018-04-24)
2
+ --------------------------------------------------------------------------------
3
+
4
+ * Payeezy payment processor integration
5
+
6
+ Integrate with Payeezy payment processor
7
+
8
+ PAYEZ-1
9
+ Eric Pigeon
10
+
11
+
12
+
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "workarea", source: "https://gems.weblinc.com"
6
+
7
+ group :test do
8
+ gem "simplecov", require: false
9
+ end
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ Workarea Payeezy
2
+ ================================================================================
3
+
4
+ Payeezy plugin for the Workarea platform.
5
+
6
+ ## Installing
7
+
8
+ ### Secrets
9
+
10
+ ```yaml
11
+ payeezy:
12
+ apikey:
13
+ apisecret:
14
+ token:
15
+ ta_token: transarmor token, https://globalgatewaye4.firstdata.com; found under the terminals tab, or use NOIW when using default sandbox merchant "Acme Sock"
16
+ test: # set to true when using sandbox account
17
+ ```
18
+
19
+ Getting Started
20
+ --------------------------------------------------------------------------------
21
+
22
+ This gem contains a rails engine that must be mounted onto a host Rails application.
23
+
24
+ To access Workarea gems and source code, you must be an employee of WebLinc or a licensed retailer or partner.
25
+
26
+ Workarea gems are hosted privately at https://gems.weblinc.com/.
27
+ You must have individual or team credentials to install gems from this server. Add your gems server credentials to Bundler:
28
+
29
+ bundle config gems.weblinc.com my_username:my_password
30
+
31
+ Or set the appropriate environment variable in a shell startup file:
32
+
33
+ export BUNDLE_GEMS__WEBLINC__COM='my_username:my_password'
34
+
35
+ Then add the gem to your application's Gemfile specifying the source:
36
+
37
+ # ...
38
+ gem 'workarea-payeezy', source: 'https://gems.weblinc.com'
39
+ # ...
40
+
41
+ Or use a source block:
42
+
43
+ # ...
44
+ source 'https://gems.weblinc.com' do
45
+ gem 'workarea-payeezy'
46
+ end
47
+ # ...
48
+
49
+ Update your application's bundle.
50
+
51
+ cd path/to/application
52
+ bundle
53
+
54
+ Workarea Platform Documentation
55
+ --------------------------------------------------------------------------------
56
+
57
+ See [http://developer.weblinc.com](http://developer.weblinc.com) for Workarea platform documentation.
58
+
59
+ Copyright & Licensing
60
+ --------------------------------------------------------------------------------
61
+
62
+ Copyright WebLinc 2018. All rights reserved.
63
+
64
+ For licensing, contact sales@workarea.com.
data/Rakefile ADDED
@@ -0,0 +1,116 @@
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 = "Payeezy"
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
+
20
+ require "rake/testtask"
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << "lib"
23
+ t.libs << "test"
24
+ t.pattern = "test/**/*_test.rb"
25
+ t.verbose = false
26
+ end
27
+ task default: :test
28
+
29
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
30
+ require "workarea/payeezy/version"
31
+
32
+ desc "Generate the changelog based on git history"
33
+ task :changelog, :from, :to do |t, args|
34
+ require "date"
35
+
36
+ from =
37
+ case
38
+ when args[:from].present?
39
+ args[:from]
40
+ when `git tag`.empty?
41
+ `git rev-list --max-parents=0 HEAD`.strip
42
+ else
43
+ `git describe --tags --abbrev=0`.strip
44
+ end
45
+ to = args[:to] || "HEAD"
46
+ log = `git log #{from}..#{to} --pretty=format:'%an|%B___'`
47
+
48
+ puts "Workarea Payeezy #{Workarea::Payeezy::VERSION} (#{Date.today})"
49
+ puts "-" * 80
50
+ puts
51
+
52
+ log.split(/___/).each do |commit|
53
+ pieces = commit.split("|").reverse
54
+ author = pieces.pop.strip
55
+ message = pieces.join.strip
56
+
57
+ next if message =~ /^\s*Merge pull request/
58
+ next if message =~ /No changelog/i
59
+
60
+ project_key = "PAYEZ"
61
+
62
+ if project_key.blank?
63
+ puts "To clean up your release notes, add your project's Jira key to the Changelog Rake task!"
64
+ else
65
+ ticket = message.scan(/#{project_key}-\d+/)[0]
66
+ next if ticket.nil?
67
+ next if message =~ /^\s*Merge branch/ && ticket.nil?
68
+ end
69
+
70
+ first_line = false
71
+
72
+ message.each_line do |line|
73
+ if !first_line
74
+ first_line = true
75
+ puts "* #{line}"
76
+ elsif line.strip.empty?
77
+ puts
78
+ else
79
+ puts " #{line}"
80
+ end
81
+ end
82
+
83
+ puts " #{author}"
84
+ puts
85
+ end
86
+ end
87
+
88
+ desc "Release version #{Workarea::Payeezy::VERSION} of the gem"
89
+ task :release do
90
+ host = "https://#{ENV['BUNDLE_GEMS__WEBLINC__COM']}@gems.weblinc.com"
91
+
92
+ system "touch CHANGELOG.md"
93
+ system 'echo "$(rake changelog)
94
+
95
+
96
+ $(cat CHANGELOG.md)" > CHANGELOG.md'
97
+ system 'git add CHANGELOG.md && git commit -m "Update changelog" && git push origin HEAD'
98
+
99
+ system "git tag -a v#{Workarea::Payeezy::VERSION} -m 'Tagging #{Workarea::Payeezy::VERSION}'"
100
+ system "git push --tags"
101
+
102
+ system "gem build workarea-payeezy.gemspec"
103
+ system "gem push workarea-payeezy-#{Workarea::Payeezy::VERSION}.gem --host #{host}"
104
+ system "rm workarea-payeezy-#{Workarea::Payeezy::VERSION}.gem"
105
+ end
106
+
107
+ desc "Run the JavaScript tests"
108
+ ENV["TEASPOON_RAILS_ENV"] = File.expand_path("../test/dummy/config/environment", __FILE__)
109
+ task teaspoon: "app:teaspoon"
110
+
111
+ desc "Start a server at http://localhost:3000/teaspoon for JavaScript tests"
112
+ task :teaspoon_server do
113
+ Dir.chdir("test/dummy")
114
+ teaspoon_env = File.expand_path("../test/teaspoon_env.rb", __FILE__)
115
+ system "RAILS_ENV=test TEASPOON_ENV=#{teaspoon_env} rails s"
116
+ end
@@ -0,0 +1,20 @@
1
+ module Workarea
2
+ decorate Payment::Authorize::CreditCard, with: :payeezy do
3
+ decorated do
4
+ include Payment::CreditCardData
5
+ delegate :address, to: :tender
6
+ end
7
+
8
+ def complete!
9
+ return unless Workarea::Payment::StoreCreditCard.new(tender, options).save!
10
+
11
+ transaction.response = handle_active_merchant_errors do
12
+ gateway.authorize(
13
+ transaction.amount.cents,
14
+ payment_source,
15
+ transaction_args
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ module Workarea
2
+ class Payment
3
+ module CreditCardData
4
+ def transaction_args
5
+ {
6
+ billing_address: billing_address
7
+ }
8
+ end
9
+
10
+ def billing_address
11
+ {
12
+ name: "#{address.first_name} #{address.last_name}",
13
+ company: address.company,
14
+ address1: address.street,
15
+ city: address.city,
16
+ state: address.region,
17
+ country: address.country.try(:alpha2),
18
+ zip: address.postal_code,
19
+ phone: nil
20
+ }
21
+ end
22
+
23
+ def payment_source
24
+ tender.token.presence || tender.to_active_merchant
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ module Workarea
2
+ decorate Payment::Purchase::CreditCard, with: :payeezy do
3
+ decorated do
4
+ include Payment::CreditCardData
5
+ delegate :address, to: :tender
6
+ end
7
+
8
+ def complete!
9
+ return unless Workarea::Payment::StoreCreditCard.new(tender, options).save!
10
+
11
+ transaction.response = handle_active_merchant_errors do
12
+ gateway.purchase(
13
+ transaction.amount.cents,
14
+ payment_source,
15
+ transaction_args
16
+ )
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module Workarea
2
+ decorate Payment::StoreCreditCard, with: :payeezy do
3
+ # Reaches out to the credit card gateway to store a new credit card
4
+ #
5
+ # @return [Boolean] the result of the gateway call
6
+ def perform!
7
+ return true if @credit_card.token.present?
8
+
9
+ response = handle_active_merchant_errors do
10
+ gateway.store(@credit_card.to_active_merchant, ta_token: Payeezy.ta_token)
11
+ end
12
+
13
+ if response.success?
14
+ @credit_card.token = response.authorization
15
+ end
16
+
17
+ response.success?
18
+ end
19
+ end
20
+ end
data/bin/rails ADDED
@@ -0,0 +1,20 @@
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("../..", __FILE__)
6
+ ENGINE_PATH = File.expand_path("../../lib/workarea/payeezy/engine", __FILE__)
7
+ APP_PATH = File.expand_path("../../test/dummy/config/application", __FILE__)
8
+
9
+ # Set up gems listed in the Gemfile.
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
11
+ require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
12
+
13
+ require "action_controller/railtie"
14
+ require "action_view/railtie"
15
+ require "action_mailer/railtie"
16
+ require "rails/test_unit/railtie"
17
+ require "sprockets/railtie"
18
+ require "teaspoon-mocha"
19
+
20
+ require "rails/engine/commands"
@@ -0,0 +1 @@
1
+ Workarea::Payeezy.configure_from_secrets
@@ -0,0 +1,70 @@
1
+ module ActiveMerchant
2
+ module Billing
3
+ class BogusPayeezyGateway < BogusGateway
4
+ NEXT_YEAR = 1.year.from_now.strftime("%y")
5
+ AUTHORIZATION = "Visa|Ben Crouse|01#{NEXT_YEAR}|9495846215171111"
6
+
7
+ def authorize(money, paysource, options = {})
8
+ if paysource.respond_to?(:emv?) && paysource.emv?
9
+ authorize_emv(money, paysource, options)
10
+ else
11
+ authorize_swipe(money, paysource, options)
12
+ end
13
+ end
14
+
15
+ def purchase(money, paysource, options = {})
16
+ if paysource.respond_to?(:emv?) && paysource.emv?
17
+ purchase_emv(money, paysource, options)
18
+ else
19
+ purchase_swipe(money, paysource, options)
20
+ end
21
+ end
22
+
23
+ def refund(money, reference, options = {})
24
+ money = amount(money)
25
+ case reference
26
+ when /1$/
27
+ raise Error, REFUND_ERROR_MESSAGE
28
+ when /2$/
29
+ Response.new(false, FAILURE_MESSAGE, { paid_amount: money, error: FAILURE_MESSAGE }, { test: true, error_code: STANDARD_ERROR_CODE[:processing_error] })
30
+ else
31
+ Response.new(true, SUCCESS_MESSAGE, { paid_amount: money }, { test: true })
32
+ end
33
+ end
34
+
35
+ def capture(money, reference, options = {})
36
+ money = amount(money)
37
+ case reference
38
+ when /1$/
39
+ raise Error, CAPTURE_ERROR_MESSAGE
40
+ when /2$/
41
+ Response.new(false, FAILURE_MESSAGE, { paid_amount: money, error: FAILURE_MESSAGE }, { test: true, error_code: STANDARD_ERROR_CODE[:processing_error] })
42
+ else
43
+ Response.new(true, SUCCESS_MESSAGE, { paid_amount: money }, { test: true })
44
+ end
45
+ end
46
+
47
+ def void(reference, options = {})
48
+ case reference
49
+ when /1$/
50
+ raise Error, VOID_ERROR_MESSAGE
51
+ when /2$/
52
+ Response.new(false, FAILURE_MESSAGE, { authorization: reference, error: FAILURE_MESSAGE }, { test: true, error_code: STANDARD_ERROR_CODE[:processing_error] })
53
+ else
54
+ Response.new(true, SUCCESS_MESSAGE, { authorization: reference }, { test: true })
55
+ end
56
+ end
57
+
58
+ def store(paysource, options = {})
59
+ case normalize(paysource)
60
+ when /1$/
61
+ Response.new(true, SUCCESS_MESSAGE, { billingid: "1" }, { test: true, authorization: AUTHORIZATION })
62
+ when /2$/
63
+ Response.new(false, FAILURE_MESSAGE, { billingid: nil, error: FAILURE_MESSAGE }, { test: true, error_code: STANDARD_ERROR_CODE[:processing_error] })
64
+ else
65
+ raise Error, error_message(paysource)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,49 @@
1
+ require "workarea"
2
+ require "workarea/storefront"
3
+ require "workarea/admin"
4
+
5
+ require "workarea/payeezy/engine"
6
+ require "workarea/payeezy/version"
7
+
8
+ module Workarea
9
+ module Payeezy
10
+ # Credentials for Payeezy from Rails secrets.
11
+ #
12
+ # @return [Hash]
13
+ def self.credentials
14
+ return {} unless Rails.application.secrets.payeezy.present?
15
+ Rails.application.secrets.payeezy.deep_symbolize_keys
16
+ end
17
+
18
+ def self.ta_token
19
+ credentials[:ta_token]
20
+ end
21
+
22
+ # Conditionally use the real gateway when secrets are present.
23
+ # Otherwise, use the bogus gateway.
24
+ #
25
+ # @return [ActiveMerchant::Billing::Gateway]
26
+ def self.gateway
27
+ Workarea.config.gateways.credit_card
28
+ end
29
+
30
+ def self.gateway=(gateway)
31
+ Workarea.config.gateways.credit_card = gateway
32
+ end
33
+
34
+ def self.configure_from_secrets
35
+ if credentials.present?
36
+ if ENV["HTTP_PROXY"].present?
37
+ uri = URI.parse(ENV["HTTP_PROXY"])
38
+ ActiveMerchant::Billing::PayeezyGateway.proxy_address = uri.host
39
+ ActiveMerchant::Billing::PayeezyGateway.proxy_port = uri.port
40
+ end
41
+
42
+ self.gateway = ActiveMerchant::Billing::PayeezyGateway.new credentials.slice(:apikey, :apisecret, :token)
43
+ else
44
+ require "active_merchant/billing/bogus_payeezy_gateway.rb"
45
+ self.gateway = ActiveMerchant::Billing::BogusPayeezyGateway.new
46
+ end
47
+ end
48
+ end
49
+ end