workarea-afterpay 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d2341faa66d7dc64d2f2e35c09eb19e50d03510df064837d33e6e58b59d3e88
4
- data.tar.gz: ae475910f6cf7a6a7cca2064be7ebdd9054cc4d56f0a88342650cbc4546ab6f7
3
+ metadata.gz: 7f170109c4e7aadf5517d681dae21220ff6cbe1e35126ab58aa54180cd02884d
4
+ data.tar.gz: 900b3992335bbf4f70be4b1a521d6aa484b9a1a319fced02a44b257aa490f951
5
5
  SHA512:
6
- metadata.gz: b42ac45e815c6cfba6dece3000240245bca5264adb0517492a9ede0c1113a1610455aa8b1e98374de5aebbcefc5d667aadc4ee697374af5985fae06520a19b8a
7
- data.tar.gz: b02488f73667dcb0a76b33c1e899fb46e2617299837b46f9035e5434179c165d87cb36991c0f66c5d0fc957f03c4ec731f98d79c445469eb99ae9f0e3c37ce2d
6
+ metadata.gz: 92464c1f313772dfe084620492874c17fe712f957cdd0591da6a5fa3615e583e95a537f3fe10e75a600e03d2a5348818c88416408ee94c926198ecfbb729ee7f
7
+ data.tar.gz: 45a8347a3823439093570d7c8f85388b0a89ee685f79131a4bf15e3df00eec4f6a7366ab033a9674c213f71388b037087e2afd244a9ab77210611bd59d9b07a3
@@ -0,0 +1,54 @@
1
+ name: CI
2
+ on: [push]
3
+
4
+ jobs:
5
+ static_analysis:
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - uses: actions/checkout@v1
9
+ - uses: workarea-commerce/ci/bundler-audit@v1
10
+ - uses: workarea-commerce/ci/rubocop@v1
11
+
12
+ admin_tests:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v1
16
+ - uses: actions/setup-ruby@v1
17
+ with:
18
+ ruby-version: 2.6.x
19
+ - uses: workarea-commerce/ci/test@v1
20
+ with:
21
+ command: bin/rails app:workarea:test:admin
22
+
23
+ core_tests:
24
+ runs-on: ubuntu-latest
25
+ steps:
26
+ - uses: actions/checkout@v1
27
+ - uses: actions/setup-ruby@v1
28
+ with:
29
+ ruby-version: 2.6.x
30
+ - uses: workarea-commerce/ci/test@v1
31
+ with:
32
+ command: bin/rails app:workarea:test:core
33
+
34
+ storefront_tests:
35
+ runs-on: ubuntu-latest
36
+ steps:
37
+ - uses: actions/checkout@v1
38
+ - uses: actions/setup-ruby@v1
39
+ with:
40
+ ruby-version: 2.6.x
41
+ - uses: workarea-commerce/ci/test@v1
42
+ with:
43
+ command: bin/rails app:workarea:test:storefront
44
+
45
+ plugins_tests:
46
+ runs-on: ubuntu-latest
47
+ steps:
48
+ - uses: actions/checkout@v1
49
+ - uses: actions/setup-ruby@v1
50
+ with:
51
+ ruby-version: 2.6.x
52
+ - uses: workarea-commerce/ci/test@v1
53
+ with:
54
+ command: bin/rails app:workarea:test:plugins
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ inherit_from:
2
+ - https://raw.githubusercontent.com/workarea-commerce/workarea/master/.rubocop.yml
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ Workarea Afterpay 2.1.1 (2020-05-04)
2
+ --------------------------------------------------------------------------------
3
+
4
+ * Respect payment declined in authorize transactions
5
+
6
+
7
+ Ben Crouse
8
+
9
+ * Respect decline payment responses in capture and purchase operations
10
+
11
+ Fixes #3
12
+
13
+ Ben Crouse
14
+
15
+ * Add CI and rubocop linting
16
+
17
+
18
+ Jeff Yucis
19
+
20
+
21
+
1
22
  Workarea Afterpay 2.1.0 (2019-11-12)
2
23
  --------------------------------------------------------------------------------
3
24
 
data/Gemfile CHANGED
@@ -1,6 +1,5 @@
1
1
  source 'https://rubygems.org'
2
- git_source(:github) { |repo| "git@github.com:#{repo}.git" }
3
-
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
4
3
  # Declare your gem's dependencies in workarea-afterpay.gemspec.
5
4
  # Bundler will treat runtime dependencies like base dependencies, and
6
5
  # development dependencies will be added by default to the :development group.
@@ -14,4 +13,4 @@ gemspec
14
13
  # To use a debugger
15
14
  # gem 'byebug', group: [:development, :test]
16
15
 
17
- gem 'workarea'
16
+ gem 'workarea', github: 'workarea-commerce/workarea', branch: 'v3.5-stable'
data/Rakefile CHANGED
@@ -37,10 +37,9 @@ task :release do
37
37
  Rake::Task['workarea:changelog'].execute
38
38
  system 'git add CHANGELOG.md'
39
39
  system 'git commit -m "Update CHANGELOG"'
40
- system 'git push origin HEAD'
41
40
 
42
41
  system "git tag -a v#{Workarea::Afterpay::VERSION} -m 'Tagging #{Workarea::Afterpay::VERSION}'"
43
- system 'git push --tags'
42
+ system 'git push origin HEAD --follow-tags'
44
43
 
45
44
  system "gem build workarea-afterpay.gemspec"
46
45
  system "gem push workarea-afterpay-#{Workarea::Afterpay::VERSION}.gem"
@@ -8,7 +8,7 @@ module Workarea
8
8
 
9
9
  def complete!
10
10
  response = authorize
11
- if response.success?
11
+ if response.success? && response.body['status'] == 'APPROVED'
12
12
  transaction.response = ActiveMerchant::Billing::Response.new(
13
13
  true,
14
14
  I18n.t(
@@ -8,7 +8,7 @@ module Workarea
8
8
 
9
9
  def complete!
10
10
  response = capture
11
- if response.success?
11
+ if response.success? && response.body['status'] == 'APPROVED'
12
12
  transaction.response = ActiveMerchant::Billing::Response.new(
13
13
  true,
14
14
  I18n.t(
@@ -8,7 +8,7 @@ module Workarea
8
8
 
9
9
  def complete!
10
10
  response = purchase
11
- if response.success?
11
+ if response.success? && response.body['status'] == 'APPROVED'
12
12
  transaction.response = ActiveMerchant::Billing::Response.new(
13
13
  true,
14
14
  I18n.t(
@@ -1,7 +1,6 @@
1
1
  module Workarea
2
2
  module Afterpay
3
3
  class OrderBuilder
4
-
5
4
  module ProductUrl
6
5
  include Workarea::I18n::DefaultUrlOptions
7
6
  include Storefront::Engine.routes.url_helpers
@@ -1,7 +1,6 @@
1
1
  module Workarea
2
2
  module Storefront
3
3
  class AfterpayViewModel < ApplicationViewModel
4
-
5
4
  # Orders must be between the min and max order total to qualify.
6
5
  def order_total_in_range?
7
6
  return unless afterpay_configuration.present?
@@ -1,7 +1,6 @@
1
1
  module Workarea
2
2
  module Afterpay
3
3
  class BogusGateway
4
-
5
4
  def initialize(*)
6
5
  end
7
6
 
@@ -93,7 +92,11 @@ module Workarea
93
92
  end
94
93
 
95
94
  def capture(payment_id, amount, request_id)
96
- Response.new(response(payment_response_body, 200))
95
+ if payment_id == 'declined'
96
+ Response.new(response(payment_response_body(status: 'DECLINED'), 200))
97
+ else
98
+ Response.new(response(payment_response_body, 200))
99
+ end
97
100
  end
98
101
 
99
102
  def authorize(token, order_id = "", request_id)
@@ -101,6 +104,8 @@ module Workarea
101
104
  Response.new(response(capture_error_response_body, 402))
102
105
  elsif token == "timeout_token"
103
106
  Response.new(response(nil, 502))
107
+ elsif token == 'declined'
108
+ Response.new(response(payment_response_body(status: 'DECLINED'), 200))
104
109
  else
105
110
  Response.new(response(payment_response_body, 200))
106
111
  end
@@ -109,6 +114,8 @@ module Workarea
109
114
  def purchase(token, order_id = "", request_id)
110
115
  if token == "error_token"
111
116
  Response.new(response(capture_error_response_body, 402))
117
+ elsif token == 'declined'
118
+ Response.new(response(payment_response_body(status: 'DECLINED'), 200))
112
119
  else
113
120
  Response.new(response(payment_response_body, 200))
114
121
  end
@@ -153,11 +160,11 @@ module Workarea
153
160
  }
154
161
  end
155
162
 
156
- def payment_response_body
163
+ def payment_response_body(status: 'APPROVED')
157
164
  {
158
165
  "id": "12345678",
159
166
  "token": "q54l9qd907m6iqqqlcrm5tpbjjsnfo47vsm59gqrfnd2rqefk9hu",
160
- "status": "APPROVED",
167
+ "status": status,
161
168
  "created": "2015-07-14T10:08:14.123Z",
162
169
  "totalAmount": {
163
170
  "amount": "21.85",
@@ -1,5 +1,5 @@
1
1
  module Workarea
2
2
  module Afterpay
3
- VERSION = '2.1.0'.freeze
3
+ VERSION = '2.1.1'.freeze
4
4
  end
5
5
  end
@@ -2,7 +2,6 @@ require 'test_helper'
2
2
 
3
3
  module Workarea
4
4
  class AfterpayPaymentIntegrationTest < Workarea::TestCase
5
-
6
5
  def test_auth_capture
7
6
  transaction = tender.build_transaction(action: 'authorize')
8
7
  Payment::Purchase::Afterpay.new(tender, transaction).complete!
@@ -21,18 +20,59 @@ module Workarea
21
20
  assert(capture_transaction.valid?)
22
21
  end
23
22
 
23
+ def test_capture_decline
24
+ transaction = tender.build_transaction(action: 'authorize')
25
+ Payment::Authorize::Afterpay.new(tender, transaction).complete!
26
+
27
+ # To force a decline response from capture API
28
+ transaction.update!(
29
+ response: ActiveMerchant::Billing::Response.new(
30
+ true,
31
+ 'test',
32
+ transaction.response.params.merge('id' => 'declined')
33
+ )
34
+ )
35
+
36
+ capture = Payment::Capture.new(payment: payment)
37
+ capture.allocate_amounts!(total: 5.to_m)
38
+ assert(capture.valid?)
39
+ refute(capture.complete!)
40
+
41
+ capture_transaction = payment.reload.transactions.detect(&:capture?)
42
+ refute(capture_transaction.success?)
43
+ assert_equal('DECLINED', capture_transaction.response.params['status'])
44
+ end
45
+
24
46
  def test_auth
25
47
  transaction = tender.build_transaction(action: 'authorize')
26
48
  Payment::Authorize::Afterpay.new(tender, transaction).complete!
27
49
  assert(transaction.success?, 'expected transaction to be successful')
28
50
  end
29
51
 
52
+ def test_auth_decline
53
+ tender.token = 'declined'
54
+ transaction = tender.build_transaction(action: 'authorize')
55
+ Payment::Authorize::Afterpay.new(tender, transaction).complete!
56
+
57
+ refute(transaction.success?)
58
+ assert_equal('DECLINED', transaction.response.params['status'])
59
+ end
60
+
30
61
  def test_purchase
31
62
  transaction = tender.build_transaction(action: 'purchase')
32
63
  Payment::Purchase::Afterpay.new(tender, transaction).complete!
33
64
  assert(transaction.success?)
34
65
  end
35
66
 
67
+ def test_purchase_decline
68
+ tender.token = 'declined'
69
+ transaction = tender.build_transaction(action: 'purchase')
70
+ Payment::Purchase::Afterpay.new(tender, transaction).complete!
71
+
72
+ refute(transaction.success?)
73
+ assert_equal('DECLINED', transaction.response.params['status'])
74
+ end
75
+
36
76
  def test_auth_void
37
77
  transaction = tender.build_transaction(action: 'authorize')
38
78
  operation = Payment::Authorize::Afterpay.new(tender, transaction)
@@ -85,7 +125,8 @@ module Workarea
85
125
  payment.set_address(first_name: 'Ben', last_name: 'Crouse')
86
126
 
87
127
  payment.build_afterpay(
88
- token: '12345'
128
+ token: '12345',
129
+ amount: 5.to_m
89
130
  )
90
131
 
91
132
  payment.afterpay
@@ -3,7 +3,6 @@ require 'test_helper'
3
3
  module Workarea
4
4
  module Afterpay
5
5
  class OrderBuilderTest < Workarea::TestCase
6
-
7
6
  def test_build
8
7
  create_order_total_discount
9
8
  order = create_order
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workarea-afterpay
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Yucis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-12 00:00:00.000000000 Z
11
+ date: 2020-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: workarea
@@ -49,7 +49,9 @@ files:
49
49
  - ".github/ISSUE_TEMPLATE/bug_report.md"
50
50
  - ".github/ISSUE_TEMPLATE/documentation-request.md"
51
51
  - ".github/ISSUE_TEMPLATE/feature_request.md"
52
+ - ".github/workflows/ci.yml"
52
53
  - ".gitignore"
54
+ - ".rubocop.yml"
53
55
  - CHANGELOG.md
54
56
  - CODE_OF_CONDUCT.md
55
57
  - CONTRIBUTING.md
@@ -141,7 +143,6 @@ files:
141
143
  - test/dummy/config/initializers/inflections.rb
142
144
  - test/dummy/config/initializers/mime_types.rb
143
145
  - test/dummy/config/initializers/new_framework_defaults.rb
144
- - test/dummy/config/initializers/session_store.rb
145
146
  - test/dummy/config/initializers/workarea.rb
146
147
  - test/dummy/config/initializers/wrap_parameters.rb
147
148
  - test/dummy/config/locales/en.yml
@@ -182,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
183
  - !ruby/object:Gem::Version
183
184
  version: '0'
184
185
  requirements: []
185
- rubygems_version: 3.0.6
186
+ rubygems_version: 3.0.3
186
187
  signing_key:
187
188
  specification_version: 4
188
189
  summary: Workarea Commerce Platform Afterpay integration
@@ -1,3 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- Rails.application.config.session_store :cookie_store, key: '_dummy_session'