workarea-cyber_source 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +20 -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/.gitignore +14 -0
  7. data/.rails-rubocop.yml +140 -0
  8. data/.rubocop.yml +8 -0
  9. data/CHANGELOG.md +39 -0
  10. data/CODE_OF_CONDUCT.md +3 -0
  11. data/CONTRIBUTING.md +3 -0
  12. data/Gemfile +11 -0
  13. data/LICENSE +52 -0
  14. data/README.md +27 -0
  15. data/Rakefile +59 -0
  16. data/app/models/workarea/payment/authorize/credit_card.decorator +45 -0
  17. data/app/models/workarea/payment/capture/credit_card.decorator +14 -0
  18. data/app/models/workarea/payment/purchase/credit_card.decorator +48 -0
  19. data/app/models/workarea/payment/refund/credit_card.decorator +14 -0
  20. data/app/models/workarea/payment/store_credit_card.decorator +13 -0
  21. data/bin/rails +20 -0
  22. data/config/initializers/gateway.rb +1 -0
  23. data/lib/active_merchant/billing/bogus_cyber_source_gateway.rb +97 -0
  24. data/lib/active_merchant/billing/cyber_source_fix.rb +34 -0
  25. data/lib/workarea/cyber_source.rb +36 -0
  26. data/lib/workarea/cyber_source/engine.rb +8 -0
  27. data/lib/workarea/cyber_source/version.rb +5 -0
  28. data/test/dummy/Rakefile +6 -0
  29. data/test/dummy/bin/bundle +3 -0
  30. data/test/dummy/bin/rails +4 -0
  31. data/test/dummy/bin/rake +4 -0
  32. data/test/dummy/bin/setup +38 -0
  33. data/test/dummy/bin/update +29 -0
  34. data/test/dummy/bin/yarn +11 -0
  35. data/test/dummy/config.ru +5 -0
  36. data/test/dummy/config/application.rb +28 -0
  37. data/test/dummy/config/boot.rb +5 -0
  38. data/test/dummy/config/cable.yml +10 -0
  39. data/test/dummy/config/environment.rb +5 -0
  40. data/test/dummy/config/environments/development.rb +56 -0
  41. data/test/dummy/config/environments/production.rb +91 -0
  42. data/test/dummy/config/environments/test.rb +44 -0
  43. data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
  44. data/test/dummy/config/initializers/assets.rb +14 -0
  45. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  46. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  47. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  48. data/test/dummy/config/initializers/inflections.rb +16 -0
  49. data/test/dummy/config/initializers/mime_types.rb +4 -0
  50. data/test/dummy/config/initializers/workarea.rb +5 -0
  51. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  52. data/test/dummy/config/locales/en.yml +33 -0
  53. data/test/dummy/config/puma.rb +56 -0
  54. data/test/dummy/config/routes.rb +5 -0
  55. data/test/dummy/config/secrets.yml +32 -0
  56. data/test/dummy/config/spring.rb +6 -0
  57. data/test/dummy/db/seeds.rb +2 -0
  58. data/test/dummy/log/.keep +0 -0
  59. data/test/dummy/package.json +5 -0
  60. data/test/integration/workarea/cyber_source_integration_test.rb +191 -0
  61. data/test/models/workarea/payment/authorize/credit_card_test.decorator +68 -0
  62. data/test/models/workarea/payment/capture/credit_card_test.decorator +17 -0
  63. data/test/models/workarea/payment/purchase/credit_card_test.decorator +60 -0
  64. data/test/models/workarea/payment/refund/credit_card_test.decorator +17 -0
  65. data/test/models/workarea/payment/store_credit_card_test.decorator +15 -0
  66. data/test/support/workarea/cyber_source_support_vcr_config.rb +23 -0
  67. data/test/support/workarea/workarea_3_2_backports.rb +57 -0
  68. data/test/teaspoon_env.rb +6 -0
  69. data/test/test_helper.rb +11 -0
  70. data/test/vcr_cassettes/cyber_source/auth_capture.yml +254 -0
  71. data/test/vcr_cassettes/cyber_source/auth_capture_refund.yml +323 -0
  72. data/test/vcr_cassettes/cyber_source/auth_void.yml +250 -0
  73. data/test/vcr_cassettes/cyber_source/purchase_refund.yml +251 -0
  74. data/test/vcr_cassettes/cyber_source/purchase_void.yml +247 -0
  75. data/test/vcr_cassettes/cyber_source/store_auth.yml +179 -0
  76. data/test/vcr_cassettes/cyber_source/store_purchase.yml +180 -0
  77. data/workarea-cyber_source.gemspec +19 -0
  78. metadata +133 -0
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ mount Workarea::Core::Engine => "/"
3
+ mount Workarea::Admin::Engine => "/admin", as: "admin"
4
+ mount Workarea::Storefront::Engine => "/", as: "storefront"
5
+ end
@@ -0,0 +1,32 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rails secret` to generate a secure secret key.
9
+
10
+ # Make sure the secrets in this file are kept private
11
+ # if you're sharing your code publicly.
12
+
13
+ # Shared secrets are available across all environments.
14
+
15
+ # shared:
16
+ # api_key: a1B2c3D4e5F6
17
+
18
+ # Environmental secrets are only available for that specific environment.
19
+
20
+ development:
21
+ secret_key_base: d1e887ea8d9002168c32984e1482dc8b510069ccc81acdbfc4b81fe3ab90dc67acc561c3adcb882ad7f7d2aa2c4319d8335db386aa9e6cb995b91409c108ebf8
22
+
23
+ test:
24
+ secret_key_base: a37f41f01b2793e0352b2d89dee00a847e1afc6e4c97f9e62f60bc46641815da3ed1f30d03d61d6dea465159d8f8b78c3c6ae16cf949fd876fd840f15517f44b
25
+
26
+ # Do not keep production secrets in the unencrypted secrets file.
27
+ # Instead, either read values from the environment.
28
+ # Or, use `bin/rails secrets:setup` to configure encrypted secrets
29
+ # and move the `production:` environment over there.
30
+
31
+ production:
32
+ secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
@@ -0,0 +1,6 @@
1
+ %w(
2
+ .ruby-version
3
+ .rbenv-vars
4
+ tmp/restart.txt
5
+ tmp/caching-dev.txt
6
+ ).each { |path| Spring.watch(path) }
@@ -0,0 +1,2 @@
1
+ require "workarea/seeds"
2
+ Workarea::Seeds.run
File without changes
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "dummy",
3
+ "private": true,
4
+ "dependencies": {}
5
+ }
@@ -0,0 +1,191 @@
1
+ require "test_helper"
2
+
3
+ module Workarea
4
+ class CyberSourceIntegrationTest < Workarea::TestCase
5
+ include CyberSourceGatewayVCRConfig
6
+
7
+ def test_store_auth
8
+ VCR.use_cassette "cyber_source/store_auth" do
9
+ Payment::StoreCreditCard.new(tender).perform!
10
+
11
+ transaction = tender.build_transaction(action: "authorize", amount: 5.to_m)
12
+ operation = Payment::Authorize::CreditCard.new(tender, transaction)
13
+ operation.complete!
14
+ assert(transaction.success?)
15
+ transaction.save!
16
+
17
+ assert(tender.token.present?)
18
+ end
19
+ end
20
+
21
+ def test_store_purchase
22
+ VCR.use_cassette "cyber_source/store_purchase" do
23
+ Payment::StoreCreditCard.new(tender).perform!
24
+
25
+ transaction = tender.build_transaction(action: "purchase", amount: 5.to_m)
26
+ operation = Payment::Purchase::CreditCard.new(tender, transaction)
27
+ operation.complete!
28
+ assert(transaction.success?)
29
+ transaction.save!
30
+
31
+ assert(tender.token.present?)
32
+ end
33
+ end
34
+
35
+ def test_auth_capture
36
+ VCR.use_cassette "cyber_source/auth_capture" do
37
+ transaction = tender.build_transaction(action: "authorize", amount: 5.to_m)
38
+ operation = Payment::Authorize::CreditCard.new(tender, transaction)
39
+ operation.complete!
40
+ assert(transaction.success?, "expected authorization to be successful")
41
+ transaction.save!
42
+
43
+ assert(tender.token.present?)
44
+
45
+ capture = Payment::Capture.new(payment: payment)
46
+ capture.allocate_amounts!(total: 5.to_m)
47
+ assert(capture.valid?)
48
+ capture.complete!
49
+
50
+ capture_transaction = payment.transactions.detect(&:captures)
51
+ assert(capture_transaction.valid?)
52
+ end
53
+ end
54
+
55
+ def test_auth_void
56
+ VCR.use_cassette "cyber_source/auth_void" do
57
+ transaction = tender.build_transaction(action: "authorize", amount: 5.to_m)
58
+ operation = Payment::Authorize::CreditCard.new(tender, transaction)
59
+ operation.complete!
60
+ assert(transaction.success?)
61
+ transaction.save!
62
+
63
+ assert(tender.token.present?)
64
+
65
+ void = gateway.void(transaction.response.authorization)
66
+
67
+ assert(void.success?)
68
+ end
69
+ end
70
+
71
+ def test_purchase_void
72
+ VCR.use_cassette "cyber_source/purchase_void" do
73
+ transaction = tender.build_transaction(action: "purchase", amount: 5.to_m)
74
+ operation = Payment::Purchase::CreditCard.new(tender, transaction)
75
+ operation.complete!
76
+ assert(transaction.success?)
77
+ transaction.save!
78
+
79
+ assert(tender.token.present?)
80
+
81
+ void = gateway.void(transaction.response.authorization)
82
+
83
+ assert(void.success?)
84
+ end
85
+ end
86
+
87
+ def test_auth_capture_refund
88
+ VCR.use_cassette "cyber_source/auth_capture_refund" do
89
+ transaction = tender.build_transaction(action: "authorize", amount: 5.to_m)
90
+ operation = Payment::Authorize::CreditCard.new(tender, transaction)
91
+ operation.complete!
92
+ assert(transaction.success?)
93
+ transaction.save!
94
+
95
+ assert(tender.token.present?)
96
+
97
+ capture = Payment::Capture.new(payment: payment)
98
+ capture.allocate_amounts!(total: 5.to_m)
99
+ assert(capture.valid?)
100
+ capture.complete!
101
+
102
+ capture_transaction = payment.transactions.detect(&:captures)
103
+ assert(capture_transaction.valid?)
104
+
105
+ refund = Payment::Refund.new(payment: payment)
106
+ refund.allocate_amounts!(total: 5.to_m)
107
+
108
+ assert(refund.valid?)
109
+ refund.complete!
110
+
111
+ refund_transaction = payment.credit_card.transactions.refunds.first
112
+ assert(refund_transaction.valid?)
113
+ end
114
+ end
115
+
116
+ def test_purchase_refund
117
+ VCR.use_cassette "cyber_source/purchase_refund" do
118
+ transaction = tender.build_transaction(action: "purchase", amount: 5.to_m)
119
+ operation = Payment::Purchase::CreditCard.new(tender, transaction)
120
+ operation.complete!
121
+ assert(transaction.success?)
122
+ transaction.save!
123
+
124
+ assert(tender.token.present?)
125
+
126
+ refund = Payment::Refund.new(payment: payment)
127
+ refund.allocate_amounts!(total: 5.to_m)
128
+
129
+ assert(refund.valid?)
130
+ refund.complete!
131
+
132
+ refund_transaction = payment.credit_card.transactions.refunds.first
133
+ assert(refund_transaction.valid?)
134
+ end
135
+ end
136
+
137
+ private
138
+ def email
139
+ "bcrouse@weblinc.com"
140
+ end
141
+
142
+ def order
143
+ @order ||= Order.new(email: email)
144
+ end
145
+
146
+ def payment_profile
147
+ @payment_profile ||= Payment::Profile.lookup(
148
+ PaymentReference.new(nil, order)
149
+ )
150
+ end
151
+
152
+ def gateway
153
+ Workarea.config.gateways.credit_card
154
+ end
155
+
156
+ def payment
157
+ @payment ||=
158
+ begin
159
+ result = create_payment(
160
+ address: {
161
+ first_name: "Ben",
162
+ last_name: "Crouse",
163
+ street: "22 s. 3rd st.",
164
+ city: "Philadelphia",
165
+ region: "PA",
166
+ postal_code: "19106",
167
+ country: Country["US"]
168
+ }
169
+ )
170
+ result.profile = payment_profile
171
+ result
172
+ end
173
+ end
174
+
175
+ def tender
176
+ @tender ||=
177
+ begin
178
+ payment.set_address(first_name: "Ben", last_name: "Crouse")
179
+
180
+ payment.build_credit_card(
181
+ number: 4111111111111111,
182
+ month: 1,
183
+ year: Time.current.year + 1,
184
+ cvv: 999
185
+ )
186
+
187
+ payment.credit_card
188
+ end
189
+ end
190
+ end
191
+ end
@@ -0,0 +1,68 @@
1
+ module Workarea
2
+ decorate Payment::Authorize::CreditCardTest, with: :cyber_source do
3
+ def test_complete_does_nothing_if_gateway_storage_fails
4
+ # cyber_source authorizes and tokenizes in one call; nullifying this test
5
+ end
6
+
7
+ def test_cancel_voids_with_the_authorization_from_the_transaction
8
+ transaction.response = ActiveMerchant::Billing::Response.new(
9
+ true,
10
+ 'Message',
11
+ {},
12
+ { authorization: authorization }
13
+ )
14
+
15
+ operation = Payment::Authorize::CreditCard.new(tender, transaction)
16
+
17
+ original_void = operation.gateway.method(:void)
18
+ operation.gateway.expects(:void)
19
+ .with(authorization)
20
+ .returns(original_void.call(authorization))
21
+
22
+ operation.cancel!
23
+ end
24
+
25
+ def test_cancel_sets_cancellation_params_on_the_transaction
26
+ transaction.response = ActiveMerchant::Billing::Response.new(
27
+ true,
28
+ 'Message',
29
+ {},
30
+ { authorization: authorization }
31
+ )
32
+
33
+ operation = Payment::Authorize::CreditCard.new(tender, transaction)
34
+ operation.cancel!
35
+
36
+ assert_instance_of(
37
+ ActiveMerchant::Billing::Response,
38
+ transaction.cancellation
39
+ )
40
+ end
41
+
42
+ private
43
+
44
+ def tender
45
+ @tender ||=
46
+ begin
47
+ payment.set_address(
48
+ first_name: 'Ben',
49
+ last_name: 'Crouse',
50
+ street: '22 s 3rd st',
51
+ city: 'Philadelphia',
52
+ region: 'PA',
53
+ country: Country['US'],
54
+ postal_code: '19106'
55
+ )
56
+
57
+ payment.build_credit_card(
58
+ number: 4111111111111111,
59
+ month: 1,
60
+ year: Time.now.year + 1,
61
+ cvv: 999
62
+ )
63
+
64
+ payment.credit_card
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,17 @@
1
+ module Workarea
2
+ decorate Payment::Capture::CreditCardTest, with: :cyber_source do
3
+ private
4
+
5
+ def reference
6
+ @reference ||= Payment::Transaction.new(
7
+ amount: 5.to_m,
8
+ response: ActiveMerchant::Billing::Response.new(
9
+ true,
10
+ 'Message',
11
+ {},
12
+ { authorization: authorization }
13
+ )
14
+ )
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,60 @@
1
+ module Workarea
2
+ decorate Payment::Purchase::CreditCardTest, with: :cyber_source do
3
+ def test_complete_does_nothing_if_gateway_storage_fails
4
+ # cyber_source captures and tokenizes in one call; nullifying this test
5
+ end
6
+
7
+ def test_cancel_voids_with_the_authorization_from_the_transaction
8
+ transaction.response = ActiveMerchant::Billing::Response.new(
9
+ true,
10
+ 'Message',
11
+ {},
12
+ { authorization: authorization }
13
+ )
14
+
15
+ operation = Payment::Authorize::CreditCard.new(tender, transaction)
16
+
17
+ original_void = operation.gateway.method(:void)
18
+ operation.gateway.expects(:void)
19
+ .with(authorization)
20
+ .returns(original_void.call(authorization))
21
+
22
+ operation.cancel!
23
+ end
24
+
25
+ def test_cancel_sets_the_cancellation_params_on_the_transaction
26
+ transaction.response = ActiveMerchant::Billing::Response.new(
27
+ true,
28
+ 'Message',
29
+ {},
30
+ { authorization: authorization }
31
+ )
32
+
33
+ operation = Payment::Authorize::CreditCard.new(tender, transaction)
34
+ operation.cancel!
35
+
36
+ assert_instance_of(
37
+ ActiveMerchant::Billing::Response,
38
+ transaction.cancellation
39
+ )
40
+ end
41
+
42
+ private
43
+
44
+ def tender
45
+ @tender ||=
46
+ begin
47
+ payment.set_address(first_name: 'Ben', last_name: 'Crouse')
48
+
49
+ payment.build_credit_card(
50
+ number: 4111111111111111,
51
+ month: 1,
52
+ year: Time.now.year + 1,
53
+ cvv: 999
54
+ )
55
+
56
+ payment.credit_card
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,17 @@
1
+ module Workarea
2
+ decorate Payment::Refund::CreditCardTest, with: :cyber_source do
3
+ private
4
+
5
+ def reference
6
+ @reference ||= Payment::Transaction.new(
7
+ amount: 5.to_m,
8
+ response: ActiveMerchant::Billing::Response.new(
9
+ true,
10
+ 'Message',
11
+ {},
12
+ { authorization: authorization }
13
+ )
14
+ )
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ module Workarea
2
+ decorate Payment::StoreCreditCardTest, with: :cyber_source do
3
+ def test_save_persists_the_token
4
+ # cyber_source doesn't issue the same token for the same card
5
+ end
6
+
7
+ private
8
+
9
+ def credit_card
10
+ @credit_card ||= VCR.use_cassette 'cyber_source/store_without_token' do
11
+ create_saved_credit_card(number: '4111111111111111')
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module Workarea
2
+ module CyberSourceGatewayVCRConfig
3
+ def self.included(test)
4
+ test.setup :setup_gateway
5
+ test.teardown :reset_gateway
6
+ end
7
+
8
+ def setup_gateway
9
+ @_old_gateway = Workarea.config.gateways.credit_card
10
+ Workarea.config.gateways.credit_card = ActiveMerchant::Billing::CyberSourceGateway.new(
11
+ login: "a",
12
+ password: "b",
13
+ ignore_avs: true,
14
+ ignore_cvv: true,
15
+ test: true
16
+ )
17
+ end
18
+
19
+ def reset_gateway
20
+ Workarea.config.gateways.credit_card = @_old_gateway
21
+ end
22
+ end
23
+ end