solidus_braintree 3.3.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +7 -0
- data/.github/workflows/lint.yml +25 -0
- data/.github/workflows/test.yml +77 -0
- data/.rubocop.yml +5 -84
- data/.standard.yml +6 -0
- data/Gemfile +12 -17
- data/README.md +7 -5
- data/Rakefile +7 -7
- data/app/helpers/solidus_braintree/braintree_admin_helper.rb +4 -4
- data/app/models/solidus_braintree/avs_result.rb +34 -34
- data/app/models/solidus_braintree/base_record.rb +1 -1
- data/app/models/solidus_braintree/configuration.rb +11 -11
- data/app/models/solidus_braintree/gateway.rb +14 -16
- data/app/models/solidus_braintree/response.rb +9 -9
- data/app/models/solidus_braintree/source.rb +5 -5
- data/app/models/solidus_braintree/transaction.rb +2 -2
- data/app/models/solidus_braintree/transaction_address.rb +5 -5
- data/app/models/solidus_braintree/transaction_import.rb +2 -2
- data/app/{decorators/models/solidus_braintree/spree_store_decorator.rb → patches/models/solidus_braintree/spree_store_patch.rb} +1 -1
- data/app/{decorators/models/solidus_braintree/spree_user_decorator.rb → patches/models/solidus_braintree/spree_user_patch.rb} +2 -2
- data/bin/dummy-app +22 -3
- data/bin/rails-sandbox +4 -4
- data/bin/rspec +6 -0
- data/bin/sandbox +55 -31
- data/db/migrate/20161114231422_create_solidus_paypal_braintree_configurations.rb +2 -2
- data/db/migrate/20170508085402_add_not_null_constraint_to_sources_payment_type.rb +2 -2
- data/db/migrate/20230109080950_rename_solidus_paypal_braintree_source_type.rb +3 -3
- data/lib/controllers/api/solidus_braintree/client_tokens_controller.rb +2 -2
- data/lib/controllers/backend/solidus_braintree/configurations_controller.rb +4 -4
- data/lib/generators/solidus_braintree/install/install_generator.rb +48 -40
- data/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/checkouts_controller.rb +7 -7
- data/lib/generators/solidus_braintree/install/templates/app/controllers/solidus_braintree/transactions_controller.rb +7 -7
- data/lib/generators/solidus_braintree/install/templates/app/helpers/solidus_braintree/braintree_checkout_helper.rb +5 -5
- data/{app/decorators/controllers/solidus_braintree/admin_payments_controller_decorator.rb → lib/patches/backend/controllers/solidus_braintree/admin_payments_controller_patch.rb} +1 -1
- data/lib/solidus_braintree/engine.rb +13 -24
- data/lib/solidus_braintree/extension_configuration.rb +1 -1
- data/lib/solidus_braintree/request_protection.rb +2 -2
- data/lib/solidus_braintree/version.rb +1 -1
- data/lib/solidus_braintree.rb +8 -8
- data/lib/solidus_paypal_braintree.rb +2 -2
- data/mise.toml +2 -0
- data/solidus_braintree.gemspec +23 -22
- metadata +59 -147
- data/.circleci/config.yml +0 -79
- data/lib/views/backend_v1.2/spree/admin/payments/source_forms/_braintree.html.erb +0 -16
- data/lib/views/backend_v2.4/spree/admin/shared/preference_fields/_hash.html.erb +0 -12
- data/spec/controllers/solidus_braintree/checkouts_controller_spec.rb +0 -99
- data/spec/controllers/solidus_braintree/client_tokens_controller_spec.rb +0 -55
- data/spec/controllers/solidus_braintree/configurations_controller_spec.rb +0 -73
- data/spec/controllers/solidus_braintree/transactions_controller_spec.rb +0 -183
- data/spec/fixtures/cassettes/admin/invalid_credit_card.yml +0 -63
- data/spec/fixtures/cassettes/admin/resubmit_credit_card.yml +0 -352
- data/spec/fixtures/cassettes/admin/valid_credit_card.yml +0 -412
- data/spec/fixtures/cassettes/braintree/create_profile.yml +0 -71
- data/spec/fixtures/cassettes/braintree/generate_token.yml +0 -63
- data/spec/fixtures/cassettes/braintree/token.yml +0 -63
- data/spec/fixtures/cassettes/checkout/invalid_credit_card.yml +0 -63
- data/spec/fixtures/cassettes/checkout/resubmit_credit_card.yml +0 -216
- data/spec/fixtures/cassettes/checkout/update.yml +0 -71
- data/spec/fixtures/cassettes/checkout/valid_credit_card.yml +0 -171
- data/spec/fixtures/cassettes/checkout/valid_venmo_transaction.yml +0 -599
- data/spec/fixtures/cassettes/gateway/authorize/credit_card/address.yml +0 -86
- data/spec/fixtures/cassettes/gateway/authorize/merchant_account/EUR.yml +0 -154
- data/spec/fixtures/cassettes/gateway/authorize/paypal/EUR.yml +0 -90
- data/spec/fixtures/cassettes/gateway/authorize/paypal/address.yml +0 -90
- data/spec/fixtures/cassettes/gateway/authorize.yml +0 -86
- data/spec/fixtures/cassettes/gateway/authorized_transaction.yml +0 -73
- data/spec/fixtures/cassettes/gateway/cancel/missing.yml +0 -63
- data/spec/fixtures/cassettes/gateway/cancel/refunds.yml +0 -272
- data/spec/fixtures/cassettes/gateway/cancel/void.yml +0 -201
- data/spec/fixtures/cassettes/gateway/capture.yml +0 -141
- data/spec/fixtures/cassettes/gateway/complete.yml +0 -157
- data/spec/fixtures/cassettes/gateway/credit.yml +0 -208
- data/spec/fixtures/cassettes/gateway/customer.yml +0 -79
- data/spec/fixtures/cassettes/gateway/purchase.yml +0 -87
- data/spec/fixtures/cassettes/gateway/settled_transaction.yml +0 -140
- data/spec/fixtures/cassettes/gateway/void.yml +0 -137
- data/spec/fixtures/cassettes/source/bin.yml +0 -295
- data/spec/fixtures/cassettes/source/card_type.yml +0 -267
- data/spec/fixtures/cassettes/source/last4.yml +0 -267
- data/spec/fixtures/cassettes/transaction/import/valid/capture.yml +0 -224
- data/spec/fixtures/cassettes/transaction/import/valid.yml +0 -71
- data/spec/fixtures/views/carts/_cart_footer.html.erb +0 -18
- data/spec/helpers/solidus_braintree/braintree_admin_helper_spec.rb +0 -17
- data/spec/helpers/solidus_braintree/braintree_checkout_helper_spec.rb +0 -70
- data/spec/models/solidus_braintree/address_spec.rb +0 -71
- data/spec/models/solidus_braintree/avs_result_spec.rb +0 -317
- data/spec/models/solidus_braintree/gateway_spec.rb +0 -774
- data/spec/models/solidus_braintree/response_spec.rb +0 -280
- data/spec/models/solidus_braintree/source_spec.rb +0 -555
- data/spec/models/solidus_braintree/transaction_address_spec.rb +0 -235
- data/spec/models/solidus_braintree/transaction_import_spec.rb +0 -302
- data/spec/models/solidus_braintree/transaction_spec.rb +0 -86
- data/spec/models/spree/store_spec.rb +0 -14
- data/spec/requests/spree/api/orders_controller_spec.rb +0 -36
- data/spec/solidus_braintree_spec_helper.rb +0 -9
- data/spec/support/solidus_braintree/capybara.rb +0 -7
- data/spec/support/solidus_braintree/factories.rb +0 -55
- data/spec/support/solidus_braintree/gateway_helpers.rb +0 -29
- data/spec/support/solidus_braintree/order_ready_for_payment.rb +0 -44
- data/spec/support/solidus_braintree/order_walkthrough.rb +0 -87
- data/spec/support/solidus_braintree/vcr.rb +0 -38
- data/spec/support/solidus_braintree/with_prepended_view_fixtures.rb +0 -19
- data/spec/system/backend/configuration_spec.rb +0 -23
- data/spec/system/backend/new_payment_spec.rb +0 -136
- data/spec/system/frontend/braintree_credit_card_checkout_spec.rb +0 -199
- data/spec/system/frontend/paypal_checkout_spec.rb +0 -168
- data/spec/system/frontend/venmo_checkout_spec.rb +0 -193
data/.circleci/config.yml
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
version: 2.1
|
|
2
|
-
|
|
3
|
-
orbs:
|
|
4
|
-
browser-tools: circleci/browser-tools@1.1
|
|
5
|
-
|
|
6
|
-
# Always take the latest version of the orb, this allows us to
|
|
7
|
-
# run specs against Solidus supported versions only without the need
|
|
8
|
-
# to change this configuration every time a Solidus version is released
|
|
9
|
-
# or goes EOL.
|
|
10
|
-
solidusio_extensions: solidusio/extensions@volatile
|
|
11
|
-
|
|
12
|
-
commands:
|
|
13
|
-
test-with-starter-frontend:
|
|
14
|
-
steps:
|
|
15
|
-
- checkout
|
|
16
|
-
- browser-tools/install-chrome
|
|
17
|
-
- run:
|
|
18
|
-
name: Install libvips
|
|
19
|
-
command: |
|
|
20
|
-
sudo apt-get update
|
|
21
|
-
sudo apt-get install -yq libvips-dev
|
|
22
|
-
- solidusio_extensions/test-branch:
|
|
23
|
-
branch: main
|
|
24
|
-
command: |
|
|
25
|
-
export FRONTEND=starter
|
|
26
|
-
sudo gem update --system
|
|
27
|
-
gem install bundler rails:'~>7.2'
|
|
28
|
-
bundle exec rake
|
|
29
|
-
- solidusio_extensions/store-test-results
|
|
30
|
-
|
|
31
|
-
jobs:
|
|
32
|
-
run-specs-with-postgres:
|
|
33
|
-
executor:
|
|
34
|
-
name: solidusio_extensions/postgres
|
|
35
|
-
ruby_version: "3.2"
|
|
36
|
-
steps:
|
|
37
|
-
- test-with-starter-frontend
|
|
38
|
-
|
|
39
|
-
run-specs-with-mysql:
|
|
40
|
-
executor:
|
|
41
|
-
name: solidusio_extensions/mysql
|
|
42
|
-
ruby_version: "3.1"
|
|
43
|
-
steps:
|
|
44
|
-
- test-with-starter-frontend
|
|
45
|
-
|
|
46
|
-
run-specs-with-sqlite:
|
|
47
|
-
executor:
|
|
48
|
-
name: solidusio_extensions/sqlite
|
|
49
|
-
ruby_version: "3.1"
|
|
50
|
-
steps:
|
|
51
|
-
- test-with-starter-frontend
|
|
52
|
-
|
|
53
|
-
lint-code:
|
|
54
|
-
executor:
|
|
55
|
-
name: solidusio_extensions/sqlite-memory
|
|
56
|
-
ruby_version: "3.1"
|
|
57
|
-
steps:
|
|
58
|
-
- solidusio_extensions/lint-code
|
|
59
|
-
|
|
60
|
-
workflows:
|
|
61
|
-
"Run specs on supported Solidus versions":
|
|
62
|
-
jobs:
|
|
63
|
-
- run-specs-with-postgres
|
|
64
|
-
- run-specs-with-mysql
|
|
65
|
-
- run-specs-with-sqlite
|
|
66
|
-
- lint-code
|
|
67
|
-
|
|
68
|
-
"Weekly run specs against main":
|
|
69
|
-
triggers:
|
|
70
|
-
- schedule:
|
|
71
|
-
cron: "0 0 * * 4" # every Thursday
|
|
72
|
-
filters:
|
|
73
|
-
branches:
|
|
74
|
-
only:
|
|
75
|
-
- main
|
|
76
|
-
jobs:
|
|
77
|
-
- run-specs-with-postgres
|
|
78
|
-
- run-specs-with-mysql
|
|
79
|
-
- run-specs-with-sqlite
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
<% id = payment_method.id %>
|
|
2
|
-
|
|
3
|
-
<fieldset class="no-border-bottom braintree-hosted-fields" data-braintree-hosted-fields data-id="braintree" data-payment-method-id="<%= id %>">
|
|
4
|
-
<div class="field" data-hook="previous_cards">
|
|
5
|
-
<% if previous_cards.any? %>
|
|
6
|
-
<% previous_cards.each do |card| %>
|
|
7
|
-
<label><%= radio_button_tag :card, card.id, card == previous_cards.first %> <%= card.display_number %><br /></label>
|
|
8
|
-
<% end %>
|
|
9
|
-
<label><%= radio_button_tag :card, "new", false, { id: "card_new#{id}" } %> <%= I18n.t("spree.use_new_cc") %></label>
|
|
10
|
-
<% end %>
|
|
11
|
-
</div>
|
|
12
|
-
|
|
13
|
-
<div id="card_form<%= id %>" data-hook style="display: none;">
|
|
14
|
-
<%= render partial: "spree/shared/braintree_hosted_fields", locals: { payment_method: payment_method } %>
|
|
15
|
-
</div>
|
|
16
|
-
</fieldset>
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<% label = local_assigns[:label].presence %>
|
|
2
|
-
<% html_options = {class: 'input_hash fullwidth'}.update(local_assigns[:html_options] || {}) %>
|
|
3
|
-
|
|
4
|
-
<div class="field">
|
|
5
|
-
<% if local_assigns[:form] %>
|
|
6
|
-
<%= form.label attribute, label %>
|
|
7
|
-
<%= form.text_area attribute, html_options %>
|
|
8
|
-
<% else %>
|
|
9
|
-
<%= label_tag name, label %>
|
|
10
|
-
<%= text_area_tag name, value, html_options %>
|
|
11
|
-
<% end %>
|
|
12
|
-
</div>
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
require 'solidus_braintree_spec_helper'
|
|
2
|
-
require 'support/solidus_braintree/order_ready_for_payment'
|
|
3
|
-
|
|
4
|
-
RSpec.describe SolidusBraintree::CheckoutsController, type: :controller do
|
|
5
|
-
routes { SolidusBraintree::Engine.routes }
|
|
6
|
-
|
|
7
|
-
include_context 'when order is ready for payment'
|
|
8
|
-
|
|
9
|
-
describe 'PATCH update' do
|
|
10
|
-
subject(:patch_update) { patch :update, params: params }
|
|
11
|
-
|
|
12
|
-
let(:params) do
|
|
13
|
-
{
|
|
14
|
-
"state" => "payment",
|
|
15
|
-
"order" => {
|
|
16
|
-
"payments_attributes" => [
|
|
17
|
-
{
|
|
18
|
-
"payment_method_id" => payment_method.id,
|
|
19
|
-
"source_attributes" => {
|
|
20
|
-
"nonce" => "fake-paypal-billing-agreement-nonce",
|
|
21
|
-
"payment_type" => SolidusBraintree::Source::PAYPAL
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
],
|
|
25
|
-
"use_billing" => "1",
|
|
26
|
-
"use_postmates_shipping" => "0"
|
|
27
|
-
},
|
|
28
|
-
"reuse_credit" => "1",
|
|
29
|
-
"order_bill_address" => "",
|
|
30
|
-
"reuse_bill_address" => "1"
|
|
31
|
-
}
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
let!(:payment_method) do
|
|
35
|
-
create_gateway
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
before do
|
|
39
|
-
allow(controller).to receive(:try_spree_current_user) { user }
|
|
40
|
-
allow(controller).to receive(:spree_current_user) { user }
|
|
41
|
-
allow(controller).to receive(:current_order) { order }
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
context "when a payment is created successfully", vcr: {
|
|
45
|
-
cassette_name: 'checkout/update',
|
|
46
|
-
match_requests_on: [:braintree_uri]
|
|
47
|
-
} do
|
|
48
|
-
it 'creates a payment' do
|
|
49
|
-
expect { patch_update }.
|
|
50
|
-
to change { order.payments.count }.
|
|
51
|
-
from(0).
|
|
52
|
-
to(1)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it 'creates a payment source' do
|
|
56
|
-
expect { patch_update }.
|
|
57
|
-
to change(SolidusBraintree::Source, :count).
|
|
58
|
-
from(0).
|
|
59
|
-
to(1)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it 'assigns @order' do
|
|
63
|
-
patch_update
|
|
64
|
-
expect(assigns(:order)).to eq order
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
it "is successful" do
|
|
68
|
-
expect(patch_update).to be_successful
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it "renders 'ok'" do
|
|
72
|
-
expect(patch_update.body).to eql("ok")
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
context "when a payment is not created successfully" do
|
|
77
|
-
before do
|
|
78
|
-
allow_any_instance_of(::Spree::Payment).to receive(:save).and_return(false)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
# No idea why this is the case, but I'm just adding the tests here
|
|
82
|
-
it "is successful" do
|
|
83
|
-
expect(patch_update).to be_successful
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
it "renders 'not-ok'" do
|
|
87
|
-
expect(patch_update.body).to eq('not-ok')
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it "does not change the number of payments in the system" do
|
|
91
|
-
expect{ patch_update }.not_to(change(::Spree::Payment, :count))
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
it "does not change the number of sources in the system" do
|
|
95
|
-
expect{ patch_update }.not_to(change(SolidusBraintree::Source, :count))
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
require 'solidus_braintree_spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe SolidusBraintree::ClientTokensController do
|
|
4
|
-
routes { SolidusBraintree::Engine.routes }
|
|
5
|
-
|
|
6
|
-
cassette_options = { cassette_name: "braintree/token" }
|
|
7
|
-
describe "POST create", vcr: cassette_options do
|
|
8
|
-
let!(:gateway) { create_gateway }
|
|
9
|
-
let(:user) { create(:user) }
|
|
10
|
-
let(:json) { JSON.parse(response.body) }
|
|
11
|
-
|
|
12
|
-
before { user.generate_spree_api_key! }
|
|
13
|
-
|
|
14
|
-
context 'without a payment method id' do
|
|
15
|
-
subject(:response) do
|
|
16
|
-
post :create, params: { token: user.spree_api_key }
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "returns a client token", aggregate_failures: true do
|
|
20
|
-
expect(response).to have_http_status(:success)
|
|
21
|
-
expect(response.content_type).to include 'application/json'
|
|
22
|
-
expect(json["client_token"]).to be_present
|
|
23
|
-
expect(json["client_token"]).to be_a String
|
|
24
|
-
expect(json["payment_method_id"]).to eq gateway.id
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context "when there's two gateway's for different stores" do
|
|
28
|
-
let!(:store1) { create(:store, code: 'store_1') }
|
|
29
|
-
let!(:store2) { create(:store, code: 'store_2') }
|
|
30
|
-
let!(:gateway_for_store1) { create_gateway.tap{ |gw| store1.payment_methods << gw } }
|
|
31
|
-
let!(:gateway_for_store2) { create_gateway.tap{ |gw| store2.payment_methods << gw } }
|
|
32
|
-
|
|
33
|
-
it "returns the correct gateway for store1" do
|
|
34
|
-
allow_any_instance_of(described_class).to receive(:current_store).and_return store1
|
|
35
|
-
expect(json["payment_method_id"]).to eq gateway_for_store1.id
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "returns the correct gateway for store2" do
|
|
39
|
-
allow_any_instance_of(described_class).to receive(:current_store).and_return store2
|
|
40
|
-
expect(json["payment_method_id"]).to eq gateway_for_store2.id
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
context 'with a payment method id' do
|
|
46
|
-
subject(:response) do
|
|
47
|
-
post :create, params: { token: user.spree_api_key, payment_method_id: gateway.id }
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it 'uses the selected gateway' do
|
|
51
|
-
expect(json["payment_method_id"]).to eq gateway.id
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
require 'solidus_braintree_spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe SolidusBraintree::ConfigurationsController, type: :controller do
|
|
4
|
-
routes { SolidusBraintree::Engine.routes }
|
|
5
|
-
|
|
6
|
-
let!(:store_1) { create :store }
|
|
7
|
-
let!(:store_2) { create :store }
|
|
8
|
-
|
|
9
|
-
stub_authorization!
|
|
10
|
-
|
|
11
|
-
describe "GET #list" do
|
|
12
|
-
subject { get :list }
|
|
13
|
-
|
|
14
|
-
it "assigns all store's configurations as @configurations" do
|
|
15
|
-
subject
|
|
16
|
-
expect(assigns(:configurations)).
|
|
17
|
-
to eq [store_1.braintree_configuration, store_2.braintree_configuration]
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "renders the correct view" do
|
|
21
|
-
expect(subject).to render_template :list
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe "POST #update" do
|
|
26
|
-
subject { post :update, params: configurations_params }
|
|
27
|
-
|
|
28
|
-
let(:paypal_button_color) { 'blue' }
|
|
29
|
-
let(:configurations_params) do
|
|
30
|
-
{
|
|
31
|
-
configurations: {
|
|
32
|
-
configuration_fields: {
|
|
33
|
-
store_1.braintree_configuration.id.to_s => { paypal: true, apple_pay: true },
|
|
34
|
-
store_2.braintree_configuration.id.to_s => {
|
|
35
|
-
paypal: true,
|
|
36
|
-
apple_pay: false,
|
|
37
|
-
preferred_paypal_button_color: paypal_button_color
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
context "with valid parameters" do
|
|
45
|
-
it "updates the configuration" do
|
|
46
|
-
expect { subject }.to change { store_1.braintree_configuration.reload.paypal }.
|
|
47
|
-
from(false).to(true)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "displays a success message to the user" do
|
|
51
|
-
subject
|
|
52
|
-
expect(flash[:success]).to eq "Successfully updated Braintree configurations."
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "displays all configurations" do
|
|
56
|
-
expect(subject).to redirect_to action: :list
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
context "with invalid parameters" do
|
|
61
|
-
let(:paypal_button_color) { 'invalid-color' }
|
|
62
|
-
|
|
63
|
-
it "displays an error message to the user" do
|
|
64
|
-
subject
|
|
65
|
-
expect(flash[:error]).to eq "An error occurred while updating Braintree configurations."
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it "returns the user to the edit page" do
|
|
69
|
-
expect(subject).to redirect_to action: :list
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
require 'solidus_braintree_spec_helper'
|
|
2
|
-
|
|
3
|
-
RSpec.describe SolidusBraintree::TransactionsController, type: :controller do
|
|
4
|
-
routes { SolidusBraintree::Engine.routes }
|
|
5
|
-
|
|
6
|
-
let!(:country) { create :country }
|
|
7
|
-
let(:line_item) { create :line_item, price: 50 }
|
|
8
|
-
let(:order) do
|
|
9
|
-
Spree::Order.create!(
|
|
10
|
-
line_items: [line_item],
|
|
11
|
-
email: 'test@example.com',
|
|
12
|
-
bill_address: create(:address, country: country),
|
|
13
|
-
ship_address: create(:address, country: country),
|
|
14
|
-
user: create(:user)
|
|
15
|
-
)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
let(:payment_method) { create_gateway }
|
|
19
|
-
|
|
20
|
-
before do
|
|
21
|
-
allow(controller).to receive(:spree_current_user) { order.user }
|
|
22
|
-
allow(controller).to receive(:current_order) { order }
|
|
23
|
-
create :shipping_method, cost: 5
|
|
24
|
-
create :state, abbr: "WA", country: country
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
cassette_options = {
|
|
28
|
-
cassette_name: "transactions_controller/create",
|
|
29
|
-
match_requests_on: [:braintree_uri]
|
|
30
|
-
}
|
|
31
|
-
describe "POST create", vcr: cassette_options do
|
|
32
|
-
subject(:post_create) { post :create, params: params }
|
|
33
|
-
|
|
34
|
-
let!(:country) { create :country, iso: 'US' }
|
|
35
|
-
|
|
36
|
-
let(:params) do
|
|
37
|
-
{
|
|
38
|
-
transaction: {
|
|
39
|
-
nonce: "fake-valid-nonce",
|
|
40
|
-
payment_type: SolidusBraintree::Source::PAYPAL,
|
|
41
|
-
phone: "1112223333",
|
|
42
|
-
email: "batman@example.com",
|
|
43
|
-
address_attributes: {
|
|
44
|
-
name: "Wade Wilson",
|
|
45
|
-
address_line_1: "123 Fake Street",
|
|
46
|
-
city: "Seattle",
|
|
47
|
-
zip: "98101",
|
|
48
|
-
state_code: "WA",
|
|
49
|
-
country_code: "US"
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
payment_method_id: payment_method.id
|
|
53
|
-
}
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
before do
|
|
57
|
-
create :state, abbr: "WA", country: country
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
context "when import has invalid address" do
|
|
61
|
-
before { params[:transaction][:address_attributes][:city] = nil }
|
|
62
|
-
|
|
63
|
-
it "raises a validation error" do
|
|
64
|
-
expect { post_create }.to raise_error(
|
|
65
|
-
SolidusBraintree::TransactionsController::InvalidImportError,
|
|
66
|
-
"Import invalid: " \
|
|
67
|
-
"Address is invalid, " \
|
|
68
|
-
"Address City can't be blank"
|
|
69
|
-
)
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
context "when the transaction is valid", vcr: {
|
|
74
|
-
cassette_name: 'transaction/import/valid',
|
|
75
|
-
match_requests_on: [:braintree_uri]
|
|
76
|
-
} do
|
|
77
|
-
it "imports the payment" do
|
|
78
|
-
expect { post_create }.to change { order.payments.count }.by(1)
|
|
79
|
-
expect(order.payments.first.amount).to eq 55
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
context "when no end state is provided" do
|
|
83
|
-
it "advances the order to confirm" do
|
|
84
|
-
post_create
|
|
85
|
-
expect(order).to be_confirm
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
context "when end state provided is delivery" do
|
|
90
|
-
let(:params) { super().merge(state: 'delivery') }
|
|
91
|
-
|
|
92
|
-
it "advances the order to delivery" do
|
|
93
|
-
post_create
|
|
94
|
-
expect(order).to be_delivery
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
context "with provided address" do
|
|
99
|
-
it "creates a new address" do
|
|
100
|
-
# Creating the order also creates 3 addresses, we want to make sure
|
|
101
|
-
# the transaction import only creates 1 new one
|
|
102
|
-
order
|
|
103
|
-
expect { post_create }.to change(Spree::Address, :count).by(1)
|
|
104
|
-
expect(Spree::Address.last.address1).to eq "123 Fake Street"
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
context "without country ISO" do
|
|
109
|
-
before do
|
|
110
|
-
params[:transaction][:address_attributes][:country_code] = ""
|
|
111
|
-
params[:transaction][:address_attributes][:country_name] = "United States"
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
it "creates a new address, looking up the ISO by country name" do
|
|
115
|
-
order
|
|
116
|
-
expect { post_create }.to change(Spree::Address, :count).by(1)
|
|
117
|
-
expect(Spree::Address.last.country.iso).to eq "US"
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
context "without transaction address" do
|
|
122
|
-
before { params[:transaction].delete(:address_attributes) }
|
|
123
|
-
|
|
124
|
-
it "does not create a new address" do
|
|
125
|
-
order
|
|
126
|
-
expect { post_create }.not_to(change(Spree::Address, :count))
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
context "when format is HTML" do
|
|
131
|
-
context "when import! leaves the order in confirm" do
|
|
132
|
-
it "redirects the user to the confirm page" do
|
|
133
|
-
expect(post_create).to redirect_to '/checkout/confirm'
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
context "when import! completes the order" do
|
|
138
|
-
before { allow(order).to receive(:complete?).and_return(true) }
|
|
139
|
-
|
|
140
|
-
it "displays the order to the user" do
|
|
141
|
-
expect(post_create).to redirect_to "/orders/#{order.number}"
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
context "when format is JSON" do
|
|
147
|
-
before { params[:format] = :json }
|
|
148
|
-
|
|
149
|
-
it "has a successful response" do
|
|
150
|
-
post_create
|
|
151
|
-
expect(response).to be_successful
|
|
152
|
-
end
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
context "when the transaction is invalid" do
|
|
157
|
-
before { params[:transaction][:email] = nil }
|
|
158
|
-
|
|
159
|
-
context "when format is HTML" do
|
|
160
|
-
it "raises an error including the validation messages" do
|
|
161
|
-
expect { post_create }.to raise_error(
|
|
162
|
-
SolidusBraintree::TransactionsController::InvalidImportError,
|
|
163
|
-
"Import invalid: Email can't be blank"
|
|
164
|
-
)
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
context "when format is JSON" do
|
|
169
|
-
before { params[:format] = :json }
|
|
170
|
-
|
|
171
|
-
it "has a failed status" do
|
|
172
|
-
post_create
|
|
173
|
-
expect(response).to have_http_status :unprocessable_entity
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
it "returns the errors as JSON" do
|
|
177
|
-
post_create
|
|
178
|
-
expect(JSON.parse(response.body)["errors"]["email"]).to eq ["can't be blank"]
|
|
179
|
-
end
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
end
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
http_interactions:
|
|
3
|
-
- request:
|
|
4
|
-
method: post
|
|
5
|
-
uri: https://api.sandbox.braintreegateway.com/merchants/7rdg92j7bm7fk5h3/client_token
|
|
6
|
-
body:
|
|
7
|
-
encoding: UTF-8
|
|
8
|
-
string: |
|
|
9
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
10
|
-
<client-token>
|
|
11
|
-
<version type="integer">2</version>
|
|
12
|
-
</client-token>
|
|
13
|
-
headers:
|
|
14
|
-
Accept-Encoding:
|
|
15
|
-
- gzip
|
|
16
|
-
Accept:
|
|
17
|
-
- application/xml
|
|
18
|
-
User-Agent:
|
|
19
|
-
- Braintree Ruby Gem 2.98.0
|
|
20
|
-
X-Apiversion:
|
|
21
|
-
- '5'
|
|
22
|
-
Content-Type:
|
|
23
|
-
- application/xml
|
|
24
|
-
Authorization:
|
|
25
|
-
- Basic bXdqa2t4d2NwMzJja2huZjphOTI5OGY0M2IzMGM2OTlkYjMwNzJjYzRhMDBmN2Y0OQ==
|
|
26
|
-
response:
|
|
27
|
-
status:
|
|
28
|
-
code: 201
|
|
29
|
-
message: Created
|
|
30
|
-
headers:
|
|
31
|
-
Server:
|
|
32
|
-
- nginx
|
|
33
|
-
Date:
|
|
34
|
-
- Fri, 13 Sep 2019 14:27:11 GMT
|
|
35
|
-
Content-Type:
|
|
36
|
-
- application/xml; charset=utf-8
|
|
37
|
-
Transfer-Encoding:
|
|
38
|
-
- chunked
|
|
39
|
-
X-Authentication:
|
|
40
|
-
- server_to_server
|
|
41
|
-
Braintree-Service-Origin:
|
|
42
|
-
- clientauth
|
|
43
|
-
Vary:
|
|
44
|
-
- Accept-Encoding
|
|
45
|
-
Content-Encoding:
|
|
46
|
-
- gzip
|
|
47
|
-
Etag:
|
|
48
|
-
- W/"c95fd3caa086065297edd0aeeb8e6d55"
|
|
49
|
-
Cache-Control:
|
|
50
|
-
- max-age=0, private, must-revalidate
|
|
51
|
-
X-Request-Id:
|
|
52
|
-
- 51cbbac6-bce1-4f90-ab14-6d61a064e77b
|
|
53
|
-
X-Runtime:
|
|
54
|
-
- '0.200715'
|
|
55
|
-
Strict-Transport-Security:
|
|
56
|
-
- max-age=31536000; includeSubDomains
|
|
57
|
-
body:
|
|
58
|
-
encoding: ASCII-8BIT
|
|
59
|
-
string: !binary |-
|
|
60
|
-
H4sIAD+ne10AA3xWXXObOBR976/o9H13+QiZeCbtTkkAWzFyLEASegNEC0bCtLax4dfvBaeTZja7D57BSLr33HvPOeL+74tWH/vy56Het58/mX8an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