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.
- checksums.yaml +5 -5
- data/.circleci/config.yml +40 -0
- data/.gem_release.yml +5 -0
- data/.github/stale.yml +17 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.rubocop.yml +76 -0
- data/CHANGELOG.md +258 -0
- data/Gemfile +41 -0
- data/LICENSE +2 -2
- data/README.md +208 -48
- data/Rakefile +4 -28
- data/app/assets/config/solidus_paypal_braintree_manifest.js +1 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_blue_button_280x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_blue_button_320x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_blue_button_375x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_white_button_280x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_white_button_320x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_active_white_button_375x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_acceptance_mark.svg +15 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_button_280x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_button_320x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_button_375x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_blue_logo.svg +18 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_acceptance_mark.svg +20 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_button_280x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_button_320x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_button_375x48.svg +19 -0
- data/app/assets/images/solidus_paypal_braintree/venmo/venmo_white_logo.svg +18 -0
- data/app/assets/javascripts/solidus_paypal_braintree/checkout.js +32 -3
- data/app/assets/javascripts/solidus_paypal_braintree/client.js +58 -5
- data/app/assets/javascripts/solidus_paypal_braintree/constants.js +36 -5
- data/app/assets/javascripts/solidus_paypal_braintree/frontend.js +2 -0
- data/app/assets/javascripts/solidus_paypal_braintree/hosted_form.js +15 -5
- data/app/assets/javascripts/solidus_paypal_braintree/paypal_button.js +90 -26
- data/app/assets/javascripts/solidus_paypal_braintree/paypal_messaging.js +22 -0
- data/app/assets/javascripts/solidus_paypal_braintree/venmo_button.js +86 -0
- data/app/assets/javascripts/spree/backend/solidus_paypal_braintree.js +2 -2
- data/app/assets/javascripts/spree/frontend/paypal_button.js +15 -13
- data/app/assets/stylesheets/spree/frontend/solidus_paypal_braintree.css +12 -0
- data/app/decorators/controllers/solidus_paypal_braintree/admin_payments_controller_decorator.rb +11 -0
- data/app/decorators/controllers/solidus_paypal_braintree/checkout_controller_decorator.rb +11 -0
- data/app/decorators/controllers/solidus_paypal_braintree/client_tokens_controller.rb +41 -0
- data/app/decorators/controllers/solidus_paypal_braintree/orders_controller_decorator.rb +11 -0
- data/app/decorators/models/solidus_paypal_braintree/spree/store_decorator.rb +20 -0
- data/app/decorators/models/solidus_paypal_braintree/spree/user_decorator.rb +13 -0
- data/app/helpers/solidus_paypal_braintree/braintree_admin_helper.rb +23 -0
- data/app/helpers/solidus_paypal_braintree/braintree_checkout_helper.rb +60 -0
- data/app/models/application_record.rb +2 -0
- data/app/models/solidus_paypal_braintree/address.rb +64 -0
- data/app/models/solidus_paypal_braintree/avs_result.rb +69 -0
- data/app/models/solidus_paypal_braintree/configuration.rb +39 -3
- data/app/models/solidus_paypal_braintree/customer.rb +7 -3
- data/app/models/solidus_paypal_braintree/gateway.rb +150 -43
- data/app/models/solidus_paypal_braintree/response.rb +49 -21
- data/app/models/solidus_paypal_braintree/source.rb +70 -10
- data/app/models/solidus_paypal_braintree/transaction.rb +3 -2
- data/app/models/solidus_paypal_braintree/transaction_address.rb +36 -15
- data/app/models/solidus_paypal_braintree/transaction_import.rb +18 -12
- data/app/overrides/spree/payments/payment/add_paypal_funding_source_to_payment.rb +9 -0
- data/app/views/spree/api/payments/source_views/_paypal_braintree.json.jbuilder +3 -0
- data/app/views/spree/checkout/existing_payment/_paypal_braintree.html.erb +10 -0
- data/app/views/spree/shared/_apple_pay_button.html.erb +27 -0
- data/app/views/spree/shared/_braintree_errors.html.erb +16 -0
- data/app/views/spree/shared/_braintree_hosted_fields.html.erb +25 -8
- data/app/views/spree/shared/_paypal_braintree_head_scripts.html.erb +26 -0
- data/app/views/spree/shared/_paypal_cart_button.html.erb +38 -0
- data/app/views/spree/shared/_paypal_messaging.html.erb +13 -0
- data/app/views/spree/shared/_venmo_button.html.erb +33 -0
- data/bin/console +17 -0
- data/bin/rails +15 -0
- data/bin/setup +8 -0
- data/config/locales/en.yml +66 -0
- data/config/locales/it.yml +56 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20160906201711_create_solidus_paypal_braintree_customers.rb +3 -1
- data/db/migrate/20161125172005_add_braintree_configuration_to_stores.rb +5 -7
- data/db/migrate/20170505193712_add_null_constraint_to_sources.rb +3 -1
- data/db/migrate/20190705115327_add_paypal_button_preferences_to_braintree_configurations.rb +5 -0
- data/db/migrate/20190911141712_add_3d_secure_to_braintree_configuration.rb +5 -0
- data/db/migrate/20211222170950_add_paypal_funding_source_to_solidus_paypal_braintree_sources.rb +5 -0
- data/db/migrate/20220104150301_add_venmo_to_braintree_configuration.rb +5 -0
- data/lib/controllers/backend/solidus_paypal_braintree/configurations_controller.rb +23 -5
- data/lib/controllers/frontend/solidus_paypal_braintree/checkouts_controller.rb +25 -21
- data/lib/controllers/frontend/solidus_paypal_braintree/transactions_controller.rb +56 -50
- data/lib/generators/solidus_paypal_braintree/install/install_generator.rb +7 -6
- data/lib/solidus_paypal_braintree/country_mapper.rb +4 -2
- data/lib/solidus_paypal_braintree/engine.rb +34 -22
- data/lib/solidus_paypal_braintree/factories.rb +41 -6
- data/lib/solidus_paypal_braintree/request_protection.rb +21 -0
- data/lib/solidus_paypal_braintree/version.rb +3 -1
- data/lib/solidus_paypal_braintree.rb +5 -1
- data/lib/views/backend/solidus_paypal_braintree/configurations/list.html.erb +38 -5
- data/lib/views/backend/spree/admin/payments/source_forms/_paypal_braintree.html.erb +2 -2
- data/lib/views/backend/spree/admin/payments/source_views/_paypal_braintree.html.erb +7 -2
- data/lib/views/backend/spree/admin/shared/preference_fields/_preference_select.html.erb +13 -0
- data/lib/views/backend_v1.2/spree/admin/payments/source_forms/_paypal_braintree.html.erb +2 -2
- data/lib/views/backend_v2.4/spree/admin/shared/preference_fields/_hash.html.erb +12 -0
- data/lib/views/frontend/solidus_paypal_braintree/payments/_payment.html.erb +12 -0
- data/lib/views/frontend/spree/checkout/payment/_paypal_braintree.html.erb +10 -77
- data/lib/views/frontend/spree/shared/_paypal_checkout_button.html.erb +32 -0
- data/solidus_paypal_braintree.gemspec +43 -0
- data/spec/controllers/solidus_paypal_braintree/checkouts_controller_spec.rb +99 -0
- data/spec/controllers/solidus_paypal_braintree/client_tokens_controller_spec.rb +55 -0
- data/spec/controllers/solidus_paypal_braintree/configurations_controller_spec.rb +73 -0
- data/spec/controllers/solidus_paypal_braintree/transactions_controller_spec.rb +183 -0
- data/spec/features/backend/configuration_spec.rb +23 -0
- data/spec/features/backend/new_payment_spec.rb +137 -0
- data/spec/features/frontend/braintree_credit_card_checkout_spec.rb +191 -0
- data/spec/features/frontend/paypal_checkout_spec.rb +166 -0
- data/spec/features/frontend/venmo_checkout_spec.rb +189 -0
- data/spec/fixtures/cassettes/admin/invalid_credit_card.yml +63 -0
- data/spec/fixtures/cassettes/admin/resubmit_credit_card.yml +352 -0
- data/spec/fixtures/cassettes/admin/valid_credit_card.yml +412 -0
- data/spec/fixtures/cassettes/braintree/create_profile.yml +71 -0
- data/spec/fixtures/cassettes/braintree/generate_token.yml +63 -0
- data/spec/fixtures/cassettes/braintree/token.yml +63 -0
- data/spec/fixtures/cassettes/checkout/invalid_credit_card.yml +63 -0
- data/spec/fixtures/cassettes/checkout/resubmit_credit_card.yml +216 -0
- data/spec/fixtures/cassettes/checkout/update.yml +71 -0
- data/spec/fixtures/cassettes/checkout/valid_credit_card.yml +156 -0
- data/spec/fixtures/cassettes/checkout/valid_venmo_transaction.yml +599 -0
- data/spec/fixtures/cassettes/gateway/authorize/credit_card/address.yml +86 -0
- data/spec/fixtures/cassettes/gateway/authorize/merchant_account/EUR.yml +154 -0
- data/spec/fixtures/cassettes/gateway/authorize/paypal/EUR.yml +90 -0
- data/spec/fixtures/cassettes/gateway/authorize/paypal/address.yml +90 -0
- data/spec/fixtures/cassettes/gateway/authorize.yml +86 -0
- data/spec/fixtures/cassettes/gateway/authorized_transaction.yml +73 -0
- data/spec/fixtures/cassettes/gateway/cancel/missing.yml +63 -0
- data/spec/fixtures/cassettes/gateway/cancel/refunds.yml +272 -0
- data/spec/fixtures/cassettes/gateway/cancel/void.yml +201 -0
- data/spec/fixtures/cassettes/gateway/capture.yml +141 -0
- data/spec/fixtures/cassettes/gateway/complete.yml +157 -0
- data/spec/fixtures/cassettes/gateway/credit.yml +208 -0
- data/spec/fixtures/cassettes/gateway/purchase.yml +87 -0
- data/spec/fixtures/cassettes/gateway/settled_transaction.yml +140 -0
- data/spec/fixtures/cassettes/gateway/void.yml +137 -0
- data/spec/fixtures/cassettes/source/card_type.yml +267 -0
- data/spec/fixtures/cassettes/source/last4.yml +267 -0
- data/spec/fixtures/cassettes/transaction/import/valid/capture.yml +224 -0
- data/spec/fixtures/cassettes/transaction/import/valid.yml +71 -0
- data/spec/fixtures/views/spree/orders/edit.html.erb +50 -0
- data/spec/helpers/solidus_paypal_braintree/braintree_admin_helper_spec.rb +17 -0
- data/spec/helpers/solidus_paypal_braintree/braintree_checkout_helper_spec.rb +70 -0
- data/spec/models/solidus_paypal_braintree/address_spec.rb +71 -0
- data/spec/models/solidus_paypal_braintree/avs_result_spec.rb +317 -0
- data/spec/models/solidus_paypal_braintree/gateway_spec.rb +692 -0
- data/spec/models/solidus_paypal_braintree/response_spec.rb +280 -0
- data/spec/models/solidus_paypal_braintree/source_spec.rb +499 -0
- data/spec/models/solidus_paypal_braintree/transaction_address_spec.rb +235 -0
- data/spec/models/solidus_paypal_braintree/transaction_import_spec.rb +300 -0
- data/spec/models/solidus_paypal_braintree/transaction_spec.rb +85 -0
- data/spec/models/spree/store_spec.rb +14 -0
- data/spec/requests/spree/api/orders_controller_spec.rb +36 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/support/capybara.rb +7 -0
- data/spec/support/factories.rb +2 -0
- data/spec/support/gateway_helpers.rb +29 -0
- data/spec/support/order_ready_for_payment.rb +37 -0
- data/spec/support/vcr.rb +42 -0
- data/spec/support/views.rb +1 -0
- metadata +226 -166
- data/app/controllers/solidus_paypal_braintree/client_tokens_controller.rb +0 -21
- data/app/helpers/braintree_admin_helper.rb +0 -18
- data/app/models/spree/store_decorator.rb +0 -11
- data/app/overrides/admin_navigation_menu.rb +0 -6
- data/config/initializers/braintree.rb +0 -1
- data/lib/views/backend/solidus_paypal_braintree/configurations/_admin_tab.html.erb +0 -3
@@ -0,0 +1,235 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SolidusPaypalBraintree::TransactionAddress do
|
4
|
+
describe "#valid?" do
|
5
|
+
subject { address.valid? }
|
6
|
+
|
7
|
+
let(:address) { described_class.new(valid_attributes) }
|
8
|
+
|
9
|
+
let(:valid_attributes) do
|
10
|
+
{
|
11
|
+
name: "Bruce Wayne",
|
12
|
+
address_line_1: "42 Spruce Lane",
|
13
|
+
city: "Gotham",
|
14
|
+
zip: "98201",
|
15
|
+
state_code: "WA",
|
16
|
+
country_code: "US"
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:country) { create :country, iso: 'US', states_required: true }
|
21
|
+
|
22
|
+
before do
|
23
|
+
create :state, abbr: "WA", country: country
|
24
|
+
end
|
25
|
+
|
26
|
+
it { is_expected.to be true }
|
27
|
+
|
28
|
+
context 'without country matches' do
|
29
|
+
let(:valid_attributes) { super().merge({ country_code: 'CA' }) }
|
30
|
+
|
31
|
+
it { is_expected.to be false }
|
32
|
+
end
|
33
|
+
|
34
|
+
context "without name" do
|
35
|
+
let(:valid_attributes) { super().except(:name) }
|
36
|
+
|
37
|
+
it { is_expected.to be false }
|
38
|
+
end
|
39
|
+
|
40
|
+
context "without address_line_1" do
|
41
|
+
let(:valid_attributes) { super().except(:address_line_1) }
|
42
|
+
|
43
|
+
it { is_expected.to be false }
|
44
|
+
end
|
45
|
+
|
46
|
+
context "without city" do
|
47
|
+
let(:valid_attributes) { super().except(:city) }
|
48
|
+
|
49
|
+
it { is_expected.to be false }
|
50
|
+
end
|
51
|
+
|
52
|
+
context "without zip" do
|
53
|
+
let(:valid_attributes) { super().except(:zip) }
|
54
|
+
|
55
|
+
it { is_expected.to be false }
|
56
|
+
end
|
57
|
+
|
58
|
+
context "without state_code" do
|
59
|
+
let(:valid_attributes) { super().except(:state_code) }
|
60
|
+
|
61
|
+
it { is_expected.to be false }
|
62
|
+
|
63
|
+
context "when country does not requires states" do
|
64
|
+
let(:country) { create :country, iso: 'US', states_required: false }
|
65
|
+
|
66
|
+
it { is_expected.to be true }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "without country_code" do
|
71
|
+
let(:valid_attributes) { super().except(:country_code) }
|
72
|
+
|
73
|
+
it { is_expected.to be true }
|
74
|
+
|
75
|
+
it "defaults to the US" do
|
76
|
+
subject
|
77
|
+
expect(address.country_code).to eq "us"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "with a one word name" do
|
82
|
+
let(:valid_attributes) { super().merge({ name: "Bruce" }) }
|
83
|
+
|
84
|
+
it { is_expected.to be true }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#attributes=" do
|
89
|
+
subject { described_class.new(attrs) }
|
90
|
+
|
91
|
+
context "when an ISO code is provided" do
|
92
|
+
let(:attrs) { { country_code: "US" } }
|
93
|
+
|
94
|
+
it "uses the ISO code provided" do
|
95
|
+
expect(subject.country_code).to eq "US"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "when the ISO code is blank" do
|
100
|
+
context "with a valid country name provided" do
|
101
|
+
before do
|
102
|
+
create :country, name: "canada", iso: "CA"
|
103
|
+
end
|
104
|
+
|
105
|
+
let(:attrs) { { country_name: "Canada" } }
|
106
|
+
|
107
|
+
it "looks up the ISO code by the country name" do
|
108
|
+
expect(subject.country_code).to eq "CA"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context "without valid country name" do
|
113
|
+
let(:attrs) { { country_name: "Neverland" } }
|
114
|
+
|
115
|
+
it "leaves the country code blank" do
|
116
|
+
expect(subject.country_code).to be_nil
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe '#spree_country' do
|
123
|
+
subject { described_class.new(country_code: country_code).spree_country }
|
124
|
+
|
125
|
+
before do
|
126
|
+
create :country, name: 'United States', iso: 'US'
|
127
|
+
end
|
128
|
+
|
129
|
+
['us', 'US'].each do |code|
|
130
|
+
let(:country_code) { code }
|
131
|
+
|
132
|
+
it 'looks up by iso' do
|
133
|
+
expect(subject.name).to eq 'United States'
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'when country does not exist' do
|
138
|
+
let(:country_code) { 'NA' }
|
139
|
+
|
140
|
+
it { is_expected.to be_nil }
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe '#spree_state' do
|
145
|
+
subject { described_class.new(country_code: 'US', state_code: state_code).spree_state }
|
146
|
+
|
147
|
+
let(:state_code) { 'newy' }
|
148
|
+
|
149
|
+
it { is_expected.to be_nil }
|
150
|
+
|
151
|
+
context 'when state exists' do
|
152
|
+
before do
|
153
|
+
us = create :country, iso: 'US'
|
154
|
+
create :state, abbr: 'NY', name: 'New York', country: us
|
155
|
+
end
|
156
|
+
|
157
|
+
['ny', ' ny', 'ny ', 'New York', 'new york', 'NY'].each do |code|
|
158
|
+
let(:state_code) { code }
|
159
|
+
|
160
|
+
it 'looks up the right state' do
|
161
|
+
expect(subject.abbr).to eq "NY"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'with no matching state' do
|
166
|
+
let(:state_code) { 'AL' }
|
167
|
+
|
168
|
+
it { is_expected.to be_nil }
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe '#should_match_state_model' do
|
174
|
+
subject { described_class.new(country_code: 'US').should_match_state_model? }
|
175
|
+
|
176
|
+
it { is_expected.to be_falsey }
|
177
|
+
|
178
|
+
context 'when country does not require states' do
|
179
|
+
before { create :country, iso: 'US', states_required: false }
|
180
|
+
|
181
|
+
it { is_expected.to be false }
|
182
|
+
end
|
183
|
+
|
184
|
+
context 'when country requires states' do
|
185
|
+
before { create :country, iso: 'US', states_required: true }
|
186
|
+
|
187
|
+
it { is_expected.to be true }
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe '#to_spree_address' do
|
192
|
+
subject { described_class.new(address_params).to_spree_address }
|
193
|
+
|
194
|
+
let(:address_params) do
|
195
|
+
{
|
196
|
+
country_code: 'US',
|
197
|
+
state_code: 'NY',
|
198
|
+
name: "Alfred"
|
199
|
+
}
|
200
|
+
end
|
201
|
+
let!(:us) { create :country, iso: 'US' }
|
202
|
+
|
203
|
+
it { is_expected.to be_a Spree::Address }
|
204
|
+
|
205
|
+
context 'when country exists with states' do
|
206
|
+
before do
|
207
|
+
create :state, country: us, abbr: 'NY', name: 'New York'
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'uses state model' do
|
211
|
+
expect(subject.state.name).to eq 'New York'
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
context 'when country exist with no states' do
|
216
|
+
it 'uses state_name' do
|
217
|
+
expect(subject.state).to be_nil
|
218
|
+
expect(subject.state_text).to eq 'NY'
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
unless SolidusSupport.combined_first_and_last_name_in_address?
|
223
|
+
context 'when using first_name and last_name' do
|
224
|
+
let(:address_params) { super().merge({ first_name: "Bruce", last_name: "Wayne" }) }
|
225
|
+
|
226
|
+
it 'displays a deprecation warning' do
|
227
|
+
expect(Spree::Deprecation).to receive(:warn).
|
228
|
+
with("first_name and last_name are deprecated. Use name instead.", any_args)
|
229
|
+
|
230
|
+
subject
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
@@ -0,0 +1,300 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SolidusPaypalBraintree::TransactionImport do
|
4
|
+
let(:order) { Spree::Order.new }
|
5
|
+
let!(:country) { create :country, iso: "US" }
|
6
|
+
let(:braintree_gateway) { SolidusPaypalBraintree::Gateway.new }
|
7
|
+
let(:transaction_address) { nil }
|
8
|
+
let(:transaction) do
|
9
|
+
SolidusPaypalBraintree::Transaction.new(
|
10
|
+
nonce: 'abcd1234',
|
11
|
+
payment_type: "ApplePayCard",
|
12
|
+
address: transaction_address,
|
13
|
+
payment_method: braintree_gateway,
|
14
|
+
email: "test@example.com",
|
15
|
+
phone: "123-456-6789"
|
16
|
+
)
|
17
|
+
end
|
18
|
+
let(:transaction_import) { described_class.new(order, transaction) }
|
19
|
+
|
20
|
+
describe "#valid?" do
|
21
|
+
subject { transaction_import.valid? }
|
22
|
+
|
23
|
+
it { is_expected.to be true }
|
24
|
+
|
25
|
+
context "with invalid transaction" do
|
26
|
+
let(:transaction) { SolidusPaypalBraintree::Transaction.new }
|
27
|
+
|
28
|
+
it { is_expected.to be false }
|
29
|
+
end
|
30
|
+
|
31
|
+
context "with invalid address" do
|
32
|
+
let(:transaction_address) do
|
33
|
+
SolidusPaypalBraintree::TransactionAddress.new(
|
34
|
+
name: "Bruce Wayne",
|
35
|
+
address_line_1: "42 Spruce Lane",
|
36
|
+
city: "Gotham",
|
37
|
+
state_code: "WA",
|
38
|
+
country_code: "US"
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
it { is_expected.to be false }
|
43
|
+
|
44
|
+
it "sets useful error messages" do
|
45
|
+
transaction_import.valid?
|
46
|
+
expect(transaction_import.errors.full_messages).
|
47
|
+
to eq ["Address is invalid", "Address zip can't be blank"]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#source' do
|
53
|
+
subject { described_class.new(order, transaction).source }
|
54
|
+
|
55
|
+
it { is_expected.to be_a SolidusPaypalBraintree::Source }
|
56
|
+
|
57
|
+
it 'takes the nonce from the transaction' do
|
58
|
+
expect(subject.nonce).to eq 'abcd1234'
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'takes the payment type from the transaction' do
|
62
|
+
expect(subject.payment_type).to eq 'ApplePayCard'
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'takes the payment method from the transaction' do
|
66
|
+
expect(subject.payment_method).to eq braintree_gateway
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'takes the paypal funding source from the transaction' do
|
70
|
+
transaction.paypal_funding_source = 'paypal'
|
71
|
+
|
72
|
+
expect(subject.paypal_funding_source).to eq('paypal')
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when order has a user' do
|
76
|
+
let(:user) { Spree.user_class.new }
|
77
|
+
let(:order) { Spree::Order.new user: user }
|
78
|
+
|
79
|
+
it 'associates user to the source' do
|
80
|
+
expect(subject.user).to eq user
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#user' do
|
86
|
+
subject { described_class.new(order, transaction).user }
|
87
|
+
|
88
|
+
it { is_expected.to be_nil }
|
89
|
+
|
90
|
+
context 'when order has a user' do
|
91
|
+
let(:user) { Spree.user_class.new }
|
92
|
+
let(:order) { Spree::Order.new user: user }
|
93
|
+
|
94
|
+
it { is_expected.to eq user }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#import!' do
|
99
|
+
subject { described_class.new(order, transaction).import!(end_state) }
|
100
|
+
|
101
|
+
let(:store) { create :store }
|
102
|
+
let(:variant) { create :variant }
|
103
|
+
let(:line_item) { Spree::LineItem.new(variant: variant, quantity: 1, price: 10) }
|
104
|
+
let(:address) { create :address, country: country }
|
105
|
+
let(:order) {
|
106
|
+
Spree::Order.create(
|
107
|
+
number: "R999999999",
|
108
|
+
store: store,
|
109
|
+
line_items: [line_item],
|
110
|
+
ship_address: address,
|
111
|
+
currency: 'USD',
|
112
|
+
total: 10,
|
113
|
+
email: 'test@example.com'
|
114
|
+
)
|
115
|
+
}
|
116
|
+
let(:payment_method) { create_gateway }
|
117
|
+
|
118
|
+
let(:country) { create :country, iso: 'US', states_required: true }
|
119
|
+
let(:transaction_address) { nil }
|
120
|
+
let(:end_state) { 'confirm' }
|
121
|
+
|
122
|
+
let(:transaction) do
|
123
|
+
SolidusPaypalBraintree::Transaction.new(
|
124
|
+
nonce: 'fake-valid-nonce',
|
125
|
+
payment_method: payment_method,
|
126
|
+
address: transaction_address,
|
127
|
+
payment_type: SolidusPaypalBraintree::Source::PAYPAL,
|
128
|
+
phone: '123-456-7890',
|
129
|
+
email: 'user@example.com'
|
130
|
+
)
|
131
|
+
end
|
132
|
+
|
133
|
+
before do
|
134
|
+
# create a shipping method so we can push through to the end
|
135
|
+
country
|
136
|
+
create :shipping_method, cost: 5
|
137
|
+
|
138
|
+
# ensure payments have the same number so VCR matches the request body
|
139
|
+
allow_any_instance_of(Spree::Payment).
|
140
|
+
to receive(:generate_identifier).
|
141
|
+
and_return("ABCD1234")
|
142
|
+
end
|
143
|
+
|
144
|
+
context "with passing validation", vcr: {
|
145
|
+
cassette_name: 'transaction/import/valid',
|
146
|
+
match_requests_on: [:braintree_uri]
|
147
|
+
} do
|
148
|
+
context "when order end state is confirm" do
|
149
|
+
it 'advances order to confirm state' do
|
150
|
+
subject
|
151
|
+
expect(order.state).to eq 'confirm'
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'has a payment for the cost of line items + shipment' do
|
155
|
+
subject
|
156
|
+
expect(order.payments.first.amount).to eq 15
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'is complete and capturable', aggregate_failures: true, vcr: {
|
160
|
+
cassette_name: 'transaction/import/valid/capture',
|
161
|
+
match_requests_on: [:braintree_uri]
|
162
|
+
} do
|
163
|
+
subject
|
164
|
+
order.complete
|
165
|
+
|
166
|
+
expect(order).to be_complete
|
167
|
+
expect(order.payments.first).to be_pending
|
168
|
+
|
169
|
+
order.payments.first.capture!
|
170
|
+
# need to reload, as capture will update the order
|
171
|
+
expect(order.reload).to be_paid
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
context "when order end state is delivery" do
|
176
|
+
let(:end_state) { 'delivery' }
|
177
|
+
|
178
|
+
it "advances the order to delivery" do
|
179
|
+
subject
|
180
|
+
expect(order.state).to eq 'delivery'
|
181
|
+
end
|
182
|
+
|
183
|
+
it "has a payment for the cost of line items" do
|
184
|
+
subject
|
185
|
+
expect(order.payments.first.amount).to eq 10
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context 'when transaction has address' do
|
190
|
+
let!(:new_york) { create :state, country: country, abbr: 'NY' }
|
191
|
+
|
192
|
+
let(:transaction_address) do
|
193
|
+
SolidusPaypalBraintree::TransactionAddress.new(
|
194
|
+
country_code: 'US',
|
195
|
+
name: 'Thaddeus Venture',
|
196
|
+
city: 'New York',
|
197
|
+
state_code: 'NY',
|
198
|
+
address_line_1: '350 5th Ave',
|
199
|
+
zip: '10118'
|
200
|
+
)
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'uses the new address', aggregate_failures: true do
|
204
|
+
subject
|
205
|
+
expect(order.shipping_address.address1).to eq '350 5th Ave'
|
206
|
+
expect(order.shipping_address.country).to eq country
|
207
|
+
expect(order.shipping_address.state).to eq new_york
|
208
|
+
end
|
209
|
+
|
210
|
+
context 'when transaction has paypal funding source' do
|
211
|
+
it 'saves it to the payment source' do
|
212
|
+
transaction.paypal_funding_source = 'paypal'
|
213
|
+
|
214
|
+
subject
|
215
|
+
|
216
|
+
source = SolidusPaypalBraintree::Source.last
|
217
|
+
expect(source.paypal_funding_source).to eq('paypal')
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
context 'with a tax category' do
|
222
|
+
before do
|
223
|
+
zone = Spree::Zone.create name: 'nyc tax'
|
224
|
+
zone.members << Spree::ZoneMember.new(zoneable: new_york)
|
225
|
+
create :tax_rate, zone: zone
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'includes the tax in the payment' do
|
229
|
+
subject
|
230
|
+
expect(order.payments.first.amount).to eq 16
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context 'with a less expensive tax category' do
|
235
|
+
before do
|
236
|
+
original_zone = Spree::Zone.create name: 'first address tax'
|
237
|
+
original_zone.members << Spree::ZoneMember.new(zoneable: address.state)
|
238
|
+
original_tax_rate = create :tax_rate, zone: original_zone, amount: 0.2
|
239
|
+
|
240
|
+
# new address is NY
|
241
|
+
ny_zone = Spree::Zone.create name: 'nyc tax'
|
242
|
+
ny_zone.members << Spree::ZoneMember.new(zoneable: new_york)
|
243
|
+
create :tax_rate, tax_categories: [original_tax_rate.tax_categories.first], zone: ny_zone, amount: 0.1
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'includes the lower tax in the payment' do
|
247
|
+
# so shipments and shipment cost is calculated before transaction import
|
248
|
+
order.next!; order.next!
|
249
|
+
# precondition
|
250
|
+
expect(order.additional_tax_total).to eq 2
|
251
|
+
expect(order.total).to eq 17
|
252
|
+
|
253
|
+
subject
|
254
|
+
expect(order.additional_tax_total).to eq 1
|
255
|
+
expect(order.payments.first.amount).to eq 16
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
context "when validation fails" do
|
262
|
+
let(:transaction_address) do
|
263
|
+
SolidusPaypalBraintree::TransactionAddress.new(
|
264
|
+
country_code: 'US',
|
265
|
+
name: 'Thaddeus Venture',
|
266
|
+
city: 'New York',
|
267
|
+
state_code: 'NY',
|
268
|
+
address_line_1: '350 5th Ave'
|
269
|
+
)
|
270
|
+
end
|
271
|
+
|
272
|
+
it "raises an error with the validation messages" do
|
273
|
+
expect { subject }.to raise_error(
|
274
|
+
SolidusPaypalBraintree::TransactionImport::InvalidImportError
|
275
|
+
)
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
context "with checkout flow", vcr: {
|
280
|
+
cassette_name: 'transaction/import/valid',
|
281
|
+
match_requests_on: [:braintree_uri]
|
282
|
+
} do
|
283
|
+
it "is not restarted by default" do
|
284
|
+
expect(order).not_to receive(:restart_checkout_flow)
|
285
|
+
subject
|
286
|
+
end
|
287
|
+
|
288
|
+
context "with restart_checkout: true" do
|
289
|
+
subject do
|
290
|
+
described_class.new(order, transaction).import!(end_state, restart_checkout: true)
|
291
|
+
end
|
292
|
+
|
293
|
+
it "is restarted" do
|
294
|
+
expect(order).to receive(:restart_checkout_flow)
|
295
|
+
subject
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SolidusPaypalBraintree::Transaction do
|
4
|
+
describe "#valid?" do
|
5
|
+
subject { transaction.valid? }
|
6
|
+
|
7
|
+
let(:valid_attributes) do
|
8
|
+
{
|
9
|
+
nonce: 'abcde-fghjkl-lmnop',
|
10
|
+
payment_method: SolidusPaypalBraintree::Gateway.new,
|
11
|
+
payment_type: 'ApplePayCard',
|
12
|
+
email: "test@example.com"
|
13
|
+
}
|
14
|
+
end
|
15
|
+
let(:valid_address_attributes) do
|
16
|
+
{
|
17
|
+
address_attributes: {
|
18
|
+
name: "Bruce Wayne",
|
19
|
+
address_line_1: "42 Spruce Lane",
|
20
|
+
city: "Gotham",
|
21
|
+
zip: "98201",
|
22
|
+
state_code: "WA",
|
23
|
+
country_code: "US"
|
24
|
+
}
|
25
|
+
}
|
26
|
+
end
|
27
|
+
let(:transaction) { described_class.new(valid_attributes) }
|
28
|
+
|
29
|
+
before do
|
30
|
+
create(:country, iso: "US")
|
31
|
+
end
|
32
|
+
|
33
|
+
it { is_expected.to be true }
|
34
|
+
|
35
|
+
context 'without nonce' do
|
36
|
+
let(:valid_attributes) { super().except(:nonce) }
|
37
|
+
|
38
|
+
it { is_expected.to be false }
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'without gateway' do
|
42
|
+
let(:valid_attributes) { super().except(:payment_method) }
|
43
|
+
|
44
|
+
it { is_expected.to be false }
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'with bad gateway' do
|
48
|
+
let(:valid_attributes) { super().merge(payment_method: Spree::PaymentMethod.new) }
|
49
|
+
|
50
|
+
it { is_expected.to be false }
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'without payment_type' do
|
54
|
+
let(:valid_attributes) { super().except(:payment_type) }
|
55
|
+
|
56
|
+
it { is_expected.to be false }
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'without email' do
|
60
|
+
let(:valid_attributes) { super().except(:email) }
|
61
|
+
|
62
|
+
it { is_expected.to be false }
|
63
|
+
end
|
64
|
+
|
65
|
+
context "with valid address" do
|
66
|
+
let(:valid_attributes) { super().merge(valid_address_attributes) }
|
67
|
+
|
68
|
+
it { is_expected.to be true }
|
69
|
+
end
|
70
|
+
|
71
|
+
context "with invalid address" do
|
72
|
+
let(:valid_attributes) { super().merge(valid_address_attributes) }
|
73
|
+
|
74
|
+
before { valid_address_attributes[:address_attributes][:zip] = nil }
|
75
|
+
|
76
|
+
it { is_expected.to be false }
|
77
|
+
|
78
|
+
it "sets useful error messages" do
|
79
|
+
transaction.valid?
|
80
|
+
expect(transaction.errors.full_messages).
|
81
|
+
to eq ["Address zip can't be blank"]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Store do
|
4
|
+
describe 'before_create :build_default_configuration' do
|
5
|
+
context 'when a braintree_configuration record already exists' do
|
6
|
+
it 'does not overwrite it' do
|
7
|
+
store = build(:store)
|
8
|
+
custom_braintree_configuration = store.build_braintree_configuration
|
9
|
+
store.save!
|
10
|
+
expect(store.braintree_configuration).to be custom_braintree_configuration
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Api::OrdersController, type: :request do
|
4
|
+
stub_authorization!
|
5
|
+
|
6
|
+
describe 'get show' do
|
7
|
+
let(:gateway) { create_gateway }
|
8
|
+
let(:order) { create(:order_with_line_items) }
|
9
|
+
let(:source) do
|
10
|
+
SolidusPaypalBraintree::Source.new(
|
11
|
+
nonce: 'fake-valid-nonce',
|
12
|
+
user: order.user,
|
13
|
+
payment_type: SolidusPaypalBraintree::Source::PAYPAL,
|
14
|
+
payment_method: gateway
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when using braintree as the payment' do
|
19
|
+
before do
|
20
|
+
allow_any_instance_of(Spree::Payment).to receive(:create_payment_profile).and_return(true)
|
21
|
+
|
22
|
+
order.payments.create!(
|
23
|
+
payment_method: gateway,
|
24
|
+
source: source,
|
25
|
+
amount: 55
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "can be rendered correctly" do
|
30
|
+
get "/api/orders/#{order.number}"
|
31
|
+
|
32
|
+
expect(response.status).to eq 200
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Configure Rails Environment
|
4
|
+
ENV['RAILS_ENV'] ||= 'test'
|
5
|
+
|
6
|
+
# Run Coverage report
|
7
|
+
require 'solidus_dev_support/rspec/coverage'
|
8
|
+
|
9
|
+
require File.expand_path('dummy/config/environment.rb', __dir__)
|
10
|
+
|
11
|
+
require 'rails-controller-testing'
|
12
|
+
Rails::Controller::Testing.install
|
13
|
+
|
14
|
+
# Requires factories and other useful helpers defined in spree_core.
|
15
|
+
require 'solidus_dev_support/rspec/feature_helper'
|
16
|
+
|
17
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
18
|
+
# in spec/support/ and its subdirectories.
|
19
|
+
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].sort.each { |f| require f }
|
20
|
+
|
21
|
+
# Requires factories defined in lib/solidus_paypal_braintree/factories.rb
|
22
|
+
require 'solidus_paypal_braintree/factories'
|
23
|
+
|
24
|
+
RSpec.configure do |config|
|
25
|
+
config.infer_spec_type_from_file_location!
|
26
|
+
config.use_transactional_fixtures = false
|
27
|
+
config.raise_errors_for_deprecations!
|
28
|
+
config.example_status_persistence_file_path = "./spec/examples.txt"
|
29
|
+
end
|