workarea-zipco 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. data/.eslintrc.json +35 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
  4. data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  6. data/.github/workflows/ci.yml +64 -0
  7. data/.gitignore +23 -0
  8. data/.rubocop.yml +2 -0
  9. data/.stylelintrc.json +8 -0
  10. data/CHANGELOG.md +17 -0
  11. data/Gemfile +17 -0
  12. data/README.md +51 -0
  13. data/Rakefile +59 -0
  14. data/app/assets/images/zipco/.keep +0 -0
  15. data/app/assets/stylesheets/workarea/storefront/zipco/components/_zipco_icon.scss +7 -0
  16. data/app/controllers/storefront/checkout/place_order_controller.decorator +11 -0
  17. data/app/controllers/storefront/zipco_controller.rb +96 -0
  18. data/app/controllers/storefront/zipco_landing_controller.rb +6 -0
  19. data/app/helpers/.keep +0 -0
  20. data/app/mailers/.keep +0 -0
  21. data/app/models/checkout.decorator +33 -0
  22. data/app/models/workarea/order.decorator +52 -0
  23. data/app/models/workarea/order/status/zip_referred.rb +13 -0
  24. data/app/models/workarea/payment.decorator +30 -0
  25. data/app/models/workarea/payment/authorize/zipco.rb +66 -0
  26. data/app/models/workarea/payment/capture/zipco.rb +58 -0
  27. data/app/models/workarea/payment/purchase/zipco.rb +66 -0
  28. data/app/models/workarea/payment/refund/zipco.rb +59 -0
  29. data/app/models/workarea/payment/tender/zipco.rb +13 -0
  30. data/app/models/workarea/search/admin/admin.decorator +7 -0
  31. data/app/services/workarea/zipco/checkout.rb +48 -0
  32. data/app/services/workarea/zipco/order.rb +188 -0
  33. data/app/services/workarea/zipco/setup.rb +37 -0
  34. data/app/view_models/workarea/storefront/checkout/payment_view_model.decorator +17 -0
  35. data/app/view_models/workarea/storefront/order_view_model.decorator +11 -0
  36. data/app/view_models/workarea/storefront/zipco_view_model.rb +18 -0
  37. data/app/views/workarea/admin/orders/tenders/_zipco.html.haml +4 -0
  38. data/app/views/workarea/storefront/checkouts/_zipco_payment.html.haml +10 -0
  39. data/app/views/workarea/storefront/order_mailer/tenders/_zipco.html.haml +4 -0
  40. data/app/views/workarea/storefront/order_mailer/tenders/_zipco.text.erb +1 -0
  41. data/app/views/workarea/storefront/orders/_zipco_order_message.html.haml +2 -0
  42. data/app/views/workarea/storefront/orders/tenders/_zipco.html.haml +6 -0
  43. data/app/views/workarea/storefront/zipco/_zipco_tagline.html.haml +4 -0
  44. data/app/views/workarea/storefront/zipco_landing/show.html.haml +4 -0
  45. data/bin/rails +25 -0
  46. data/config/initializers/appends.rb +24 -0
  47. data/config/initializers/workarea.rb +15 -0
  48. data/config/locales/en.yml +38 -0
  49. data/config/routes.rb +5 -0
  50. data/lib/workarea/zipco.rb +48 -0
  51. data/lib/workarea/zipco/bogus_gateway.rb +160 -0
  52. data/lib/workarea/zipco/engine.rb +10 -0
  53. data/lib/workarea/zipco/gateway.rb +113 -0
  54. data/lib/workarea/zipco/response.rb +29 -0
  55. data/lib/workarea/zipco/version.rb +5 -0
  56. data/test/dummy/.ruby-version +1 -0
  57. data/test/dummy/Rakefile +6 -0
  58. data/test/dummy/app/assets/config/manifest.js +3 -0
  59. data/test/dummy/app/assets/images/.keep +0 -0
  60. data/test/dummy/app/assets/javascripts/application.js +14 -0
  61. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  62. data/test/dummy/app/controllers/application_controller.rb +2 -0
  63. data/test/dummy/app/controllers/concerns/.keep +0 -0
  64. data/test/dummy/app/helpers/application_helper.rb +2 -0
  65. data/test/dummy/app/jobs/application_job.rb +2 -0
  66. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  67. data/test/dummy/app/models/concerns/.keep +0 -0
  68. data/test/dummy/app/views/layouts/application.html.erb +15 -0
  69. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  70. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  71. data/test/dummy/bin/bundle +3 -0
  72. data/test/dummy/bin/rails +4 -0
  73. data/test/dummy/bin/rake +4 -0
  74. data/test/dummy/bin/setup +28 -0
  75. data/test/dummy/bin/update +28 -0
  76. data/test/dummy/bin/yarn +11 -0
  77. data/test/dummy/config.ru +5 -0
  78. data/test/dummy/config/application.rb +34 -0
  79. data/test/dummy/config/boot.rb +5 -0
  80. data/test/dummy/config/environment.rb +5 -0
  81. data/test/dummy/config/environments/development.rb +52 -0
  82. data/test/dummy/config/environments/production.rb +83 -0
  83. data/test/dummy/config/environments/test.rb +45 -0
  84. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  85. data/test/dummy/config/initializers/assets.rb +14 -0
  86. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  87. data/test/dummy/config/initializers/content_security_policy.rb +25 -0
  88. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  89. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  90. data/test/dummy/config/initializers/inflections.rb +16 -0
  91. data/test/dummy/config/initializers/mime_types.rb +4 -0
  92. data/test/dummy/config/initializers/workarea.rb +5 -0
  93. data/test/dummy/config/initializers/wrap_parameters.rb +9 -0
  94. data/test/dummy/config/locales/en.yml +33 -0
  95. data/test/dummy/config/puma.rb +34 -0
  96. data/test/dummy/config/routes.rb +5 -0
  97. data/test/dummy/config/spring.rb +6 -0
  98. data/test/dummy/db/seeds.rb +2 -0
  99. data/test/dummy/lib/assets/.keep +0 -0
  100. data/test/dummy/log/.keep +0 -0
  101. data/test/integration/workarea/storefront/zipco_integration_test.rb +250 -0
  102. data/test/models/workarea/order/zipco_queries_test.rb +35 -0
  103. data/test/models/workarea/payment/zipco_payment_integration_test.rb +89 -0
  104. data/test/services/workarea/zipco/checkout_test.rb +43 -0
  105. data/test/services/workarea/zipco/order_test.rb +102 -0
  106. data/test/services/workarea/zipco/setup_test.rb +65 -0
  107. data/test/teaspoon_env.rb +6 -0
  108. data/test/test_helper.rb +10 -0
  109. data/test/view_models/workarea/storefront/zipco_view_model_test.rb +55 -0
  110. data/workarea-zipco.gemspec +19 -0
  111. metadata +167 -0
@@ -0,0 +1,160 @@
1
+ module Workarea
2
+ module Zipco
3
+ class BogusGateway
4
+ def create_order(order)
5
+ Response.new(response(create_order_body))
6
+ end
7
+
8
+ def capture(attrs, request_id = nil)
9
+ Response.new(response(capture_body))
10
+ end
11
+
12
+ def authorize(attrs, request_id = nil)
13
+ if attrs[:authority][:value] == "timeout_token"
14
+ Response.new(response(nil, 502))
15
+ else
16
+ Response.new(response(capture_body))
17
+ end
18
+ end
19
+
20
+ def purchase(attrs, request_id = nil)
21
+ Response.new(response(capture_body))
22
+ end
23
+
24
+ private
25
+
26
+ def response(body, status = 200)
27
+ response = Faraday.new do |builder|
28
+ builder.adapter :test do |stub|
29
+ stub.get("/v1/bogus") { |env| [ status, {}, body.to_json ] }
30
+ end
31
+ end
32
+ response.get("/v1/bogus")
33
+ end
34
+
35
+ def create_order_body
36
+ {
37
+ "id": "co_P9GOgSVE9qMnL0VA6Jy8z6",
38
+ "uri": "https://account.sandbox.zipmoney.com.au/?co=co_P9GOgSVE9qMnL0VA6Jy8z6&m=aa7bd4b9-f270-4eba-94b7-a64e95f6b13f",
39
+ "type": "standard",
40
+ "shopper": {
41
+ "title": "Mr",
42
+ "first_name": "John",
43
+ "last_name": "Smith",
44
+ "middle_name": "Joe",
45
+ "phone": "0400000000",
46
+ "email": "test@emailaddress.com",
47
+ "birth_date": "2017-10-10",
48
+ "gender": "Male",
49
+ "statistics": {
50
+ "account_created": "2015-09-09T19:58:47.697Z",
51
+ "sales_total_count": 0,
52
+ "sales_total_amount": 450,
53
+ "sales_avg_amount": 0,
54
+ "sales_max_amount": 0,
55
+ "refunds_total_amount": 0,
56
+ "previous_chargeback": false,
57
+ "currency": "AUD"
58
+ },
59
+ "billing_address": {
60
+ "line1": "10 Test st",
61
+ "city": "Sydney",
62
+ "state": "NSW",
63
+ "postal_code": "2000",
64
+ "country": "AU",
65
+ "first_name": "John",
66
+ "last_name": "Smith"
67
+ }
68
+ },
69
+ "order": {
70
+ "reference": "testcheckout1",
71
+ "amount": 200,
72
+ "currency": "AUD",
73
+ "shipping": {
74
+ "pickup": false,
75
+ "tracking": {
76
+ "uri": "http://tracking.com?code=CBX-343",
77
+ "number": "CBX-343",
78
+ "carrier": "tracking.com"
79
+ },
80
+ "address": {
81
+ "line1": "10 Test st",
82
+ "city": "Sydney",
83
+ "state": "NSW",
84
+ "postal_code": "2000",
85
+ "country": "AU"
86
+ }
87
+ },
88
+ "items": [
89
+ {
90
+ "name": "Awesome shoes",
91
+ "amount": 200,
92
+ "reference": "1",
93
+ "quantity": 1,
94
+ "type": "sku"
95
+ }
96
+ ]
97
+ },
98
+ "metadata": {
99
+ "name1": "value1"
100
+ },
101
+ "created": "2018-05-07T05:37:56.4794801Z",
102
+ "state": "created",
103
+ "config": {
104
+ "redirect_uri": "http://www.redirectsuccess.com/zipmoney/approved"
105
+ }
106
+ }
107
+ end
108
+
109
+ def capture_body
110
+ {
111
+ "id": "ch_AKS81QxsiKUSnr281pX7z4",
112
+ "reference": "nsadioghsdgoihsd",
113
+ "amount": 200,
114
+ "currency": "AUD",
115
+ "state": "authorised",
116
+ "captured_amount": 0,
117
+ "refunded_amount": 0,
118
+ "created_date": "2018-05-07T05:46:48.963Z",
119
+ "order": {
120
+ "reference": "refno1ononon",
121
+ "shipping": {
122
+ "pickup": false,
123
+ "tracking": {
124
+ "uri": "http://tracking.com?code=CBX-343",
125
+ "number": "CBX-343",
126
+ "carrier": "tracking.com"
127
+ },
128
+ "address": {
129
+ "line1": "10 Test st",
130
+ "city": "Sydney",
131
+ "state": "NSW",
132
+ "postal_code": "2000",
133
+ "country": "AU"
134
+ }
135
+ },
136
+ "items": [
137
+ {
138
+ "name": "veniam qui occaecat amet ipsum",
139
+ "amount": 200,
140
+ "reference": "1",
141
+ "quantity": 1,
142
+ "type": "sku",
143
+ "item_uri": "https://tatum.name"
144
+ }
145
+ ],
146
+ "cart_reference": "exercitation doloresdfsd"
147
+ },
148
+ "customer": {
149
+ "id": "14589",
150
+ "first_name": "John",
151
+ "last_name": "APPROVETEST",
152
+ "email": "tim@tmkcomputing.com.au"
153
+ },
154
+ "receipt_number": 155953,
155
+ "product": "zipPay"
156
+ }
157
+ end
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,10 @@
1
+ require 'workarea/zipco'
2
+
3
+ module Workarea
4
+ module Zipco
5
+ class Engine < ::Rails::Engine
6
+ include Workarea::Plugin
7
+ isolate_namespace Workarea::Zipco
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,113 @@
1
+ module Workarea
2
+ module Zipco
3
+ class Gateway
4
+ attr_reader :options
5
+
6
+ def initialize(options = {})
7
+ requires!(options, :secret_key, :api_version)
8
+ @options = options
9
+ end
10
+
11
+ def create_order(order)
12
+ response = connection.post do |req|
13
+ req.url "merchant/v1/checkouts"
14
+ req.body = order.to_json
15
+ end
16
+
17
+ Zipco::Response.new(response)
18
+ end
19
+
20
+ def authorize(attrs, request_key = nil)
21
+ response = connection.post do |req|
22
+ req.url "merchant/v1/charges"
23
+ req.body = attrs.to_json
24
+ req.headers["Idempotency-Key"] = request_key
25
+ end
26
+
27
+ Zipco::Response.new(response)
28
+ end
29
+ alias :purchase :authorize
30
+
31
+ def capture(charge_id, amount, request_key = nil)
32
+ body = {
33
+ amount: amount.to_f
34
+ }
35
+
36
+ response = connection.post do |req|
37
+ req.url "merchant/v1/charges/#{charge_id}/capture"
38
+ req.body = body.to_json
39
+ req.headers["Idempotency-Key"] = request_key
40
+ end
41
+
42
+ Zipco::Response.new(response)
43
+ end
44
+
45
+ def refund(charge_id, amount, request_key = nil)
46
+ reason = "Web Refund"
47
+ body = {
48
+ charge_id: charge_id,
49
+ reason: reason,
50
+ amount: amount.to_f
51
+ }
52
+
53
+ response = connection.post do |req|
54
+ req.url "merchant/v1/refunds"
55
+ req.body = body.to_json
56
+ req.headers["Idempotency-Key"] = request_key
57
+ end
58
+ Zipco::Response.new(response)
59
+ end
60
+
61
+ private
62
+
63
+ def connection
64
+ headers = {
65
+ "Content-Type" => "application/json",
66
+ "Accept" => "application/json",
67
+ "Authorization" => "Bearer #{secret_key}",
68
+ "zip-version" => api_version
69
+ }
70
+
71
+ request_timeouts = {
72
+ timeout: Workarea.config.zipco[:api_timeout],
73
+ open_timeout: Workarea.config.zipco[:open_timeout]
74
+ }
75
+
76
+ Faraday.new(url: rest_endpoint, headers: headers, request: request_timeouts)
77
+ end
78
+
79
+ def api_version
80
+ options[:api_version] || "2017-03-01"
81
+ end
82
+
83
+ def secret_key
84
+ options[:secret_key]
85
+ end
86
+
87
+ def test?
88
+ (options.has_key?(:test) ? options[:test] : true)
89
+ end
90
+
91
+ def rest_endpoint
92
+ if test?
93
+ "https://api.sandbox.zipmoney.com.au"
94
+ else
95
+ "https://api.zipmoney.com.au"
96
+ end
97
+ end
98
+
99
+ def requires!(hash, *params)
100
+ params.each do |param|
101
+ if param.is_a?(Array)
102
+ raise ArgumentError.new("Missing required parameter: #{param.first}") unless hash.has_key?(param.first)
103
+
104
+ valid_options = param[1..-1]
105
+ raise ArgumentError.new("Parameter: #{param.first} must be one of #{valid_options.to_sentence(words_connector: 'or')}") unless valid_options.include?(hash[param.first])
106
+ else
107
+ raise ArgumentError.new("Missing required parameter: #{param}") unless hash.has_key?(param)
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,29 @@
1
+ module Workarea
2
+ module Zipco
3
+ class Response
4
+ def initialize(response)
5
+ @response = response
6
+ end
7
+
8
+ def success?
9
+ @response.success?
10
+ end
11
+
12
+ def zipco_order_id
13
+ body["id"]
14
+ end
15
+
16
+ def redirect_uri
17
+ body["uri"]
18
+ end
19
+
20
+ def body
21
+ @body ||= JSON.parse(@response.body)
22
+ end
23
+
24
+ def status
25
+ @response.status
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module Workarea
2
+ module Zipco
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ 2.4.3
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,3 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../javascripts .js
3
+ //= link_directory ../stylesheets .css
File without changes
@@ -0,0 +1,14 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require rails-ujs
14
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
File without changes
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag 'application', media: 'all' %>
9
+ <%= javascript_include_tag 'application' %>
10
+ </head>
11
+
12
+ <body>
13
+ <%= yield %>
14
+ </body>
15
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../config/application', __dir__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fileutils'
3
+ include FileUtils
4
+
5
+ # path to your application root.
6
+ APP_ROOT = File.expand_path('..', __dir__)
7
+
8
+ def system!(*args)
9
+ system(*args) || abort("\n== Command #{args} failed ==")
10
+ end
11
+
12
+ chdir APP_ROOT do
13
+ # This script is a starting point to setup your application.
14
+ # Add necessary setup steps to this file.
15
+
16
+ puts '== Installing dependencies =='
17
+ system! 'gem install bundler --conservative'
18
+ system('bundle check') || system!('bundle install')
19
+
20
+ # Install JavaScript dependencies if using Yarn
21
+ # system('bin/yarn')
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system! 'bin/rails log:clear tmp:clear'
25
+
26
+ puts "\n== Restarting application server =="
27
+ system! 'bin/rails restart'
28
+ end