solidus_paypal_braintree 0.2.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +40 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/stale.yml +17 -0
  5. data/.gitignore +18 -0
  6. data/.rspec +2 -0
  7. data/.rubocop.yml +76 -0
  8. data/CHANGELOG.md +258 -0
  9. data/Gemfile +41 -0
  10. data/LICENSE +2 -2
  11. data/README.md +208 -48
  12. data/Rakefile +4 -28
  13. data/app/assets/config/solidus_paypal_braintree_manifest.js +1 -0
  14. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_blue_button_280x48.svg +19 -0
  15. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_blue_button_320x48.svg +19 -0
  16. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_blue_button_375x48.svg +19 -0
  17. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_white_button_280x48.svg +19 -0
  18. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_white_button_320x48.svg +19 -0
  19. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_white_button_375x48.svg +19 -0
  20. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_acceptance_mark.svg +15 -0
  21. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_button_280x48.svg +19 -0
  22. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_button_320x48.svg +19 -0
  23. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_button_375x48.svg +19 -0
  24. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_logo.svg +18 -0
  25. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_acceptance_mark.svg +20 -0
  26. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_button_280x48.svg +19 -0
  27. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_button_320x48.svg +19 -0
  28. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_button_375x48.svg +19 -0
  29. data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_logo.svg +18 -0
  30. data/app/assets/javascripts/solidus_paypal_braintree/checkout.js +32 -3
  31. data/app/assets/javascripts/solidus_paypal_braintree/client.js +58 -5
  32. data/app/assets/javascripts/solidus_paypal_braintree/constants.js +36 -5
  33. data/app/assets/javascripts/solidus_paypal_braintree/frontend.js +2 -0
  34. data/app/assets/javascripts/solidus_paypal_braintree/hosted_form.js +15 -5
  35. data/app/assets/javascripts/solidus_paypal_braintree/paypal_button.js +90 -26
  36. data/app/assets/javascripts/solidus_paypal_braintree/paypal_messaging.js +22 -0
  37. data/app/assets/javascripts/solidus_paypal_braintree/venmo_button.js +86 -0
  38. data/app/assets/javascripts/spree/backend/solidus_paypal_braintree.js +2 -2
  39. data/app/assets/javascripts/spree/frontend/paypal_button.js +15 -13
  40. data/app/assets/stylesheets/spree/frontend/solidus_paypal_braintree.css +12 -0
  41. data/app/decorators/controllers/solidus_paypal_braintree/admin_payments_controller_decorator.rb +11 -0
  42. data/app/decorators/controllers/solidus_paypal_braintree/checkout_controller_decorator.rb +11 -0
  43. data/app/decorators/controllers/solidus_paypal_braintree/client_tokens_controller.rb +41 -0
  44. data/app/decorators/controllers/solidus_paypal_braintree/orders_controller_decorator.rb +11 -0
  45. data/app/decorators/models/solidus_paypal_braintree/spree/store_decorator.rb +20 -0
  46. data/app/decorators/models/solidus_paypal_braintree/spree/user_decorator.rb +13 -0
  47. data/app/helpers/solidus_paypal_braintree/braintree_admin_helper.rb +23 -0
  48. data/app/helpers/solidus_paypal_braintree/braintree_checkout_helper.rb +60 -0
  49. data/app/models/application_record.rb +2 -0
  50. data/app/models/solidus_paypal_braintree/address.rb +64 -0
  51. data/app/models/solidus_paypal_braintree/avs_result.rb +69 -0
  52. data/app/models/solidus_paypal_braintree/configuration.rb +39 -3
  53. data/app/models/solidus_paypal_braintree/customer.rb +7 -3
  54. data/app/models/solidus_paypal_braintree/gateway.rb +150 -43
  55. data/app/models/solidus_paypal_braintree/response.rb +49 -21
  56. data/app/models/solidus_paypal_braintree/source.rb +70 -10
  57. data/app/models/solidus_paypal_braintree/transaction.rb +3 -2
  58. data/app/models/solidus_paypal_braintree/transaction_address.rb +36 -15
  59. data/app/models/solidus_paypal_braintree/transaction_import.rb +18 -12
  60. data/app/overrides/spree/payments/payment/add_paypal_funding_source_to_payment.rb +9 -0
  61. data/app/views/spree/api/payments/source_views/_paypal_braintree.json.jbuilder +3 -0
  62. data/app/views/spree/checkout/existing_payment/_paypal_braintree.html.erb +10 -0
  63. data/app/views/spree/shared/_apple_pay_button.html.erb +27 -0
  64. data/app/views/spree/shared/_braintree_errors.html.erb +16 -0
  65. data/app/views/spree/shared/_braintree_hosted_fields.html.erb +25 -8
  66. data/app/views/spree/shared/_paypal_braintree_head_scripts.html.erb +26 -0
  67. data/app/views/spree/shared/_paypal_cart_button.html.erb +38 -0
  68. data/app/views/spree/shared/_paypal_messaging.html.erb +13 -0
  69. data/app/views/spree/shared/_venmo_button.html.erb +33 -0
  70. data/bin/console +17 -0
  71. data/bin/rails +15 -0
  72. data/bin/setup +8 -0
  73. data/config/locales/en.yml +66 -0
  74. data/config/locales/it.yml +56 -0
  75. data/config/routes.rb +2 -0
  76. data/db/migrate/20160906201711_create_solidus_paypal_braintree_customers.rb +3 -1
  77. data/db/migrate/20161125172005_add_braintree_configuration_to_stores.rb +5 -7
  78. data/db/migrate/20170505193712_add_null_constraint_to_sources.rb +3 -1
  79. data/db/migrate/20190705115327_add_paypal_button_preferences_to_braintree_configurations.rb +5 -0
  80. data/db/migrate/20190911141712_add_3d_secure_to_braintree_configuration.rb +5 -0
  81. data/db/migrate/20211222170950_add_paypal_funding_source_to_solidus_paypal_braintree_sources.rb +5 -0
  82. data/db/migrate/20220104150301_add_venmo_to_braintree_configuration.rb +5 -0
  83. data/lib/controllers/backend/solidus_paypal_braintree/configurations_controller.rb +23 -5
  84. data/lib/controllers/frontend/solidus_paypal_braintree/checkouts_controller.rb +25 -21
  85. data/lib/controllers/frontend/solidus_paypal_braintree/transactions_controller.rb +56 -50
  86. data/lib/generators/solidus_paypal_braintree/install/install_generator.rb +7 -6
  87. data/lib/solidus_paypal_braintree/country_mapper.rb +4 -2
  88. data/lib/solidus_paypal_braintree/engine.rb +34 -22
  89. data/lib/solidus_paypal_braintree/factories.rb +41 -6
  90. data/lib/solidus_paypal_braintree/request_protection.rb +21 -0
  91. data/lib/solidus_paypal_braintree/version.rb +3 -1
  92. data/lib/solidus_paypal_braintree.rb +5 -1
  93. data/lib/views/backend/solidus_paypal_braintree/configurations/list.html.erb +38 -5
  94. data/lib/views/backend/spree/admin/payments/source_forms/_paypal_braintree.html.erb +2 -2
  95. data/lib/views/backend/spree/admin/payments/source_views/_paypal_braintree.html.erb +7 -2
  96. data/lib/views/backend/spree/admin/shared/preference_fields/_preference_select.html.erb +13 -0
  97. data/lib/views/backend_v1.2/spree/admin/payments/source_forms/_paypal_braintree.html.erb +2 -2
  98. data/lib/views/backend_v2.4/spree/admin/shared/preference_fields/_hash.html.erb +12 -0
  99. data/lib/views/frontend/solidus_paypal_braintree/payments/_payment.html.erb +12 -0
  100. data/lib/views/frontend/spree/checkout/payment/_paypal_braintree.html.erb +10 -77
  101. data/lib/views/frontend/spree/shared/_paypal_checkout_button.html.erb +32 -0
  102. data/solidus_paypal_braintree.gemspec +43 -0
  103. data/spec/controllers/solidus_paypal_braintree/checkouts_controller_spec.rb +99 -0
  104. data/spec/controllers/solidus_paypal_braintree/client_tokens_controller_spec.rb +55 -0
  105. data/spec/controllers/solidus_paypal_braintree/configurations_controller_spec.rb +73 -0
  106. data/spec/controllers/solidus_paypal_braintree/transactions_controller_spec.rb +183 -0
  107. data/spec/features/backend/configuration_spec.rb +23 -0
  108. data/spec/features/backend/new_payment_spec.rb +137 -0
  109. data/spec/features/frontend/braintree_credit_card_checkout_spec.rb +191 -0
  110. data/spec/features/frontend/paypal_checkout_spec.rb +166 -0
  111. data/spec/features/frontend/venmo_checkout_spec.rb +189 -0
  112. data/spec/fixtures/cassettes/admin/invalid_credit_card.yml +63 -0
  113. data/spec/fixtures/cassettes/admin/resubmit_credit_card.yml +352 -0
  114. data/spec/fixtures/cassettes/admin/valid_credit_card.yml +412 -0
  115. data/spec/fixtures/cassettes/braintree/create_profile.yml +71 -0
  116. data/spec/fixtures/cassettes/braintree/generate_token.yml +63 -0
  117. data/spec/fixtures/cassettes/braintree/token.yml +63 -0
  118. data/spec/fixtures/cassettes/checkout/invalid_credit_card.yml +63 -0
  119. data/spec/fixtures/cassettes/checkout/resubmit_credit_card.yml +216 -0
  120. data/spec/fixtures/cassettes/checkout/update.yml +71 -0
  121. data/spec/fixtures/cassettes/checkout/valid_credit_card.yml +156 -0
  122. data/spec/fixtures/cassettes/checkout/valid_venmo_transaction.yml +599 -0
  123. data/spec/fixtures/cassettes/gateway/authorize/credit_card/address.yml +86 -0
  124. data/spec/fixtures/cassettes/gateway/authorize/merchant_account/EUR.yml +154 -0
  125. data/spec/fixtures/cassettes/gateway/authorize/paypal/EUR.yml +90 -0
  126. data/spec/fixtures/cassettes/gateway/authorize/paypal/address.yml +90 -0
  127. data/spec/fixtures/cassettes/gateway/authorize.yml +86 -0
  128. data/spec/fixtures/cassettes/gateway/authorized_transaction.yml +73 -0
  129. data/spec/fixtures/cassettes/gateway/cancel/missing.yml +63 -0
  130. data/spec/fixtures/cassettes/gateway/cancel/refunds.yml +272 -0
  131. data/spec/fixtures/cassettes/gateway/cancel/void.yml +201 -0
  132. data/spec/fixtures/cassettes/gateway/capture.yml +141 -0
  133. data/spec/fixtures/cassettes/gateway/complete.yml +157 -0
  134. data/spec/fixtures/cassettes/gateway/credit.yml +208 -0
  135. data/spec/fixtures/cassettes/gateway/purchase.yml +87 -0
  136. data/spec/fixtures/cassettes/gateway/settled_transaction.yml +140 -0
  137. data/spec/fixtures/cassettes/gateway/void.yml +137 -0
  138. data/spec/fixtures/cassettes/source/card_type.yml +267 -0
  139. data/spec/fixtures/cassettes/source/last4.yml +267 -0
  140. data/spec/fixtures/cassettes/transaction/import/valid/capture.yml +224 -0
  141. data/spec/fixtures/cassettes/transaction/import/valid.yml +71 -0
  142. data/spec/fixtures/views/spree/orders/edit.html.erb +50 -0
  143. data/spec/helpers/solidus_paypal_braintree/braintree_admin_helper_spec.rb +17 -0
  144. data/spec/helpers/solidus_paypal_braintree/braintree_checkout_helper_spec.rb +70 -0
  145. data/spec/models/solidus_paypal_braintree/address_spec.rb +71 -0
  146. data/spec/models/solidus_paypal_braintree/avs_result_spec.rb +317 -0
  147. data/spec/models/solidus_paypal_braintree/gateway_spec.rb +692 -0
  148. data/spec/models/solidus_paypal_braintree/response_spec.rb +280 -0
  149. data/spec/models/solidus_paypal_braintree/source_spec.rb +499 -0
  150. data/spec/models/solidus_paypal_braintree/transaction_address_spec.rb +235 -0
  151. data/spec/models/solidus_paypal_braintree/transaction_import_spec.rb +300 -0
  152. data/spec/models/solidus_paypal_braintree/transaction_spec.rb +85 -0
  153. data/spec/models/spree/store_spec.rb +14 -0
  154. data/spec/requests/spree/api/orders_controller_spec.rb +36 -0
  155. data/spec/spec_helper.rb +29 -0
  156. data/spec/support/capybara.rb +7 -0
  157. data/spec/support/factories.rb +2 -0
  158. data/spec/support/gateway_helpers.rb +29 -0
  159. data/spec/support/order_ready_for_payment.rb +37 -0
  160. data/spec/support/vcr.rb +42 -0
  161. data/spec/support/views.rb +1 -0
  162. metadata +226 -166
  163. data/app/controllers/solidus_paypal_braintree/client_tokens_controller.rb +0 -21
  164. data/app/helpers/braintree_admin_helper.rb +0 -18
  165. data/app/models/spree/store_decorator.rb +0 -11
  166. data/app/overrides/admin_navigation_menu.rb +0 -6
  167. data/config/initializers/braintree.rb +0 -1
  168. data/lib/views/backend/solidus_paypal_braintree/configurations/_admin_tab.html.erb +0 -3
@@ -0,0 +1,280 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe SolidusPaypalBraintree::Response do
4
+ let(:failed_transaction) { nil }
5
+ let(:error) do
6
+ instance_double(
7
+ 'Braintree::ValidationError',
8
+ code: '12345',
9
+ message: "Cannot refund a transaction unless it is settled."
10
+ )
11
+ end
12
+
13
+ let(:error_result) do
14
+ instance_double(
15
+ 'Braintree::ErrorResult',
16
+ success?: false,
17
+ errors: [error],
18
+ transaction: failed_transaction,
19
+ params: { some: 'error' }
20
+ )
21
+ end
22
+
23
+ let(:error_response) do
24
+ described_class.build(error_result)
25
+ end
26
+
27
+ let(:successful_result) do
28
+ transaction = instance_double(
29
+ 'Braintree::Transaction',
30
+ status: 'ok',
31
+ id: 'abcdef',
32
+ avs_error_response_code: nil,
33
+ avs_street_address_response_code: 'M',
34
+ avs_postal_code_response_code: 'M',
35
+ cvv_response_code: 'I'
36
+ )
37
+
38
+ instance_double(
39
+ 'Braintree::SuccessfulResult',
40
+ success?: true,
41
+ transaction: transaction
42
+ )
43
+ end
44
+
45
+ let(:successful_response) do
46
+ described_class.build(successful_result)
47
+ end
48
+
49
+ describe '.new' do
50
+ it 'is private' do
51
+ expect { described_class.new }.to raise_error(/private method/)
52
+ end
53
+ end
54
+
55
+ describe '.build' do
56
+ it { expect(error_response).to be_a ActiveMerchant::Billing::Response }
57
+ it { expect(successful_response).to be_a ActiveMerchant::Billing::Response }
58
+ end
59
+
60
+ describe '#success?' do
61
+ it { expect(error_response.success?).to be false }
62
+ it { expect(successful_response.success?).to be true }
63
+ end
64
+
65
+ describe "#message" do
66
+ context "with a success response" do
67
+ subject { successful_response.message }
68
+
69
+ it { is_expected.to eq "ok" }
70
+ end
71
+
72
+ context "with an error response" do
73
+ subject { error_response.message }
74
+
75
+ context "with a Braintree error" do
76
+ it { is_expected.to eq "Cannot refund a transaction unless it is settled. (12345)" }
77
+ end
78
+
79
+ context "with a settlement_declined status" do
80
+ let(:error) { nil }
81
+ let(:failed_transaction) do
82
+ instance_double(
83
+ 'Braintree::Transaction',
84
+ id: 'abcdef',
85
+ status: "settlement_declined",
86
+ processor_settlement_response_code: "4001",
87
+ processor_settlement_response_text: "Settlement Declined",
88
+ avs_error_response_code: nil,
89
+ avs_street_address_response_code: nil,
90
+ avs_postal_code_response_code: nil,
91
+ cvv_response_code: nil
92
+ )
93
+ end
94
+
95
+ it { is_expected.to eq "Settlement Declined (4001)" }
96
+ end
97
+
98
+ context "with a gateway_rejected status" do
99
+ let(:error) { nil }
100
+ let(:failed_transaction) do
101
+ instance_double(
102
+ 'Braintree::Transaction',
103
+ id: 'abcdef',
104
+ status: "gateway_rejected",
105
+ gateway_rejection_reason: "cvv",
106
+ avs_error_response_code: nil,
107
+ avs_street_address_response_code: nil,
108
+ avs_postal_code_response_code: nil,
109
+ cvv_response_code: nil
110
+ )
111
+ end
112
+
113
+ it { is_expected.to eq "CVV check failed." }
114
+ end
115
+
116
+ context "with a processor_declined status" do
117
+ let(:error) { nil }
118
+ let(:failed_transaction) do
119
+ instance_double(
120
+ 'Braintree::Transaction',
121
+ id: 'abcdef',
122
+ status: "processor_declined",
123
+ processor_response_code: '2001',
124
+ processor_response_text: 'Insufficient Funds',
125
+ avs_error_response_code: nil,
126
+ avs_street_address_response_code: nil,
127
+ avs_postal_code_response_code: nil,
128
+ cvv_response_code: nil
129
+ )
130
+ end
131
+
132
+ it { is_expected.to eq "Insufficient Funds (2001)" }
133
+ end
134
+
135
+ context 'with other transaction status' do
136
+ let(:error) { nil }
137
+ let(:failed_transaction) do
138
+ instance_double(
139
+ 'Braintree::Transaction',
140
+ id: 'abcdef',
141
+ status: "authorization_expired",
142
+ avs_error_response_code: nil,
143
+ avs_street_address_response_code: nil,
144
+ avs_postal_code_response_code: nil,
145
+ cvv_response_code: nil
146
+ )
147
+ end
148
+
149
+ it { is_expected.to eq 'Payment authorization has expired.' }
150
+ end
151
+
152
+ context 'with other transaction status that is not translated' do
153
+ let(:error) { nil }
154
+ let(:failed_transaction) do
155
+ instance_double(
156
+ 'Braintree::Transaction',
157
+ id: 'abcdef',
158
+ status: "something_bad_happened",
159
+ avs_error_response_code: nil,
160
+ avs_street_address_response_code: nil,
161
+ avs_postal_code_response_code: nil,
162
+ cvv_response_code: nil
163
+ )
164
+ end
165
+
166
+ it { is_expected.to eq 'Something bad happened' }
167
+ end
168
+ end
169
+ end
170
+
171
+ describe '#avs_result' do
172
+ context 'with a successful result' do
173
+ subject { described_class.build(successful_result).avs_result }
174
+
175
+ it 'includes AVS response code' do
176
+ expect(subject['code']).to eq 'M'
177
+ end
178
+
179
+ it 'includes AVS response message' do
180
+ expect(subject['message']).to eq 'Street address and postal code match.'
181
+ end
182
+ end
183
+
184
+ context 'with an error result' do
185
+ subject { described_class.build(error_result).avs_result }
186
+
187
+ let(:failed_transaction) do
188
+ instance_double(
189
+ 'Braintree::Transaction',
190
+ id: 'abcdef',
191
+ avs_error_response_code: 'E',
192
+ avs_street_address_response_code: nil,
193
+ avs_postal_code_response_code: nil,
194
+ cvv_response_code: nil
195
+ )
196
+ end
197
+
198
+ it 'includes AVS response code' do
199
+ expect(subject['code']).to eq 'E'
200
+ end
201
+
202
+ it 'includes AVS response message' do
203
+ expect(subject['message']).to eq 'AVS data is invalid or AVS is not allowed for this card type.'
204
+ end
205
+
206
+ context 'without transaction' do
207
+ let(:failed_transaction) { nil }
208
+
209
+ it 'includes no AVS response' do
210
+ expect(subject['message']).to be_nil
211
+ expect(subject['code']).to be_nil
212
+ end
213
+ end
214
+ end
215
+ end
216
+
217
+ describe '#cvv_result' do
218
+ context 'with a successful result' do
219
+ subject { described_class.build(successful_result).cvv_result }
220
+
221
+ it 'does not include CVV response code' do
222
+ expect(subject['code']).to be_nil
223
+ end
224
+
225
+ it 'does not include CVV response message' do
226
+ expect(subject['message']).to be_nil
227
+ end
228
+ end
229
+
230
+ context 'with an error result' do
231
+ subject { described_class.build(error_result).cvv_result }
232
+
233
+ let(:failed_transaction) do
234
+ instance_double(
235
+ 'Braintree::Transaction',
236
+ id: 'abcdef',
237
+ avs_error_response_code: nil,
238
+ avs_street_address_response_code: nil,
239
+ avs_postal_code_response_code: nil,
240
+ cvv_response_code: 'N'
241
+ )
242
+ end
243
+
244
+ it 'includes CVV response code' do
245
+ expect(subject['code']).to eq 'N'
246
+ end
247
+
248
+ it 'includes CVV response message' do
249
+ expect(subject['message']).to eq 'CVV does not match'
250
+ end
251
+
252
+ context 'without transaction' do
253
+ let(:failed_transaction) { nil }
254
+
255
+ it 'includes no CVV response' do
256
+ expect(subject['message']).to be_nil
257
+ expect(subject['code']).to be_nil
258
+ end
259
+ end
260
+ end
261
+ end
262
+
263
+ describe '#params' do
264
+ context "with an error response" do
265
+ subject { error_response.params }
266
+
267
+ it 'includes request params' do
268
+ expect(subject).to eq({ 'some' => 'error' })
269
+ end
270
+ end
271
+ end
272
+
273
+ describe '#authorization' do
274
+ it 'is whatever the b.t. transaction id was' do
275
+ expect(successful_response.authorization).to eq 'abcdef'
276
+ end
277
+
278
+ it { expect(error_response.authorization).to be_nil }
279
+ end
280
+ end