solidus_bolt 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +41 -0
- data/.gem_release.yml +5 -0
- data/.github/stale.yml +17 -0
- data/.github_changelog_generator +2 -0
- data/.gitignore +20 -0
- data/.rspec +2 -0
- data/.rubocop.yml +11 -0
- data/CHANGELOG.md +1 -0
- data/Gemfile +33 -0
- data/LICENSE +26 -0
- data/README.md +175 -0
- data/Rakefile +6 -0
- data/app/assets/images/bolt_logo_standard.png +0 -0
- data/app/assets/javascripts/authorize_account.js +74 -0
- data/app/assets/javascripts/solidus_bolt.js +91 -0
- data/app/assets/javascripts/spree/backend/solidus_bolt.js +4 -0
- data/app/assets/javascripts/spree/frontend/solidus_bolt.js +18 -0
- data/app/assets/stylesheets/spree/backend/solidus_bolt.css +4 -0
- data/app/assets/stylesheets/spree/frontend/solidus_bolt.css +4 -0
- data/app/controllers/solidus_bolt/accounts_controller.rb +17 -0
- data/app/controllers/solidus_bolt/base_controller.rb +21 -0
- data/app/controllers/solidus_bolt/webhooks_controller.rb +21 -0
- data/app/controllers/spree/admin/bolt_webhooks_controller.rb +34 -0
- data/app/controllers/spree/admin/bolts_controller.rb +43 -0
- data/app/decorators/controllers/solidus_bolt/spree_checkout_controller/add_addresses_to_bolt.rb +23 -0
- data/app/decorators/controllers/solidus_bolt/spree_checkout_controller/refresh_bolt_addresses.rb +17 -0
- data/app/decorators/controllers/solidus_bolt/spree_checkout_controller/refresh_bolt_payment_source.rb +17 -0
- data/app/decorators/models/solidus_bolt/address_decorator.rb +22 -0
- data/app/decorators/models/solidus_bolt/log_entry_decorator.rb +11 -0
- data/app/decorators/models/solidus_bolt/order_decorator.rb +44 -0
- data/app/decorators/models/solidus_bolt/payment_decorator.rb +11 -0
- data/app/decorators/omniauth/strategies/bolt_decorator.rb +16 -0
- data/app/jobs/solidus_bolt/add_address_job.rb +11 -0
- data/app/models/solidus_bolt/bolt_configuration.rb +74 -0
- data/app/models/solidus_bolt/gateway.rb +133 -0
- data/app/models/solidus_bolt/payment_method.rb +35 -0
- data/app/models/solidus_bolt/payment_source.rb +13 -0
- data/app/models/solidus_bolt.rb +7 -0
- data/app/overrides/spree/shared/_head/add_bolt_embed_script.html.erb.deface +6 -0
- data/app/services/solidus_bolt/accounts/add_address_service.rb +55 -0
- data/app/services/solidus_bolt/accounts/add_payment_method_service.rb +45 -0
- data/app/services/solidus_bolt/accounts/detail_service.rb +38 -0
- data/app/services/solidus_bolt/accounts/detect_account_service.rb +34 -0
- data/app/services/solidus_bolt/base_service.rb +55 -0
- data/app/services/solidus_bolt/oauth/token_service.rb +43 -0
- data/app/services/solidus_bolt/payments/capture_sync_service.rb +24 -0
- data/app/services/solidus_bolt/payments/credit_sync_service.rb +44 -0
- data/app/services/solidus_bolt/payments/void_sync_service.rb +18 -0
- data/app/services/solidus_bolt/server_error.rb +6 -0
- data/app/services/solidus_bolt/transactions/authorize_service.rb +72 -0
- data/app/services/solidus_bolt/transactions/base_service.rb +28 -0
- data/app/services/solidus_bolt/transactions/capture_service.rb +46 -0
- data/app/services/solidus_bolt/transactions/detail_service.rb +38 -0
- data/app/services/solidus_bolt/transactions/refund_service.rb +46 -0
- data/app/services/solidus_bolt/transactions/void_service.rb +44 -0
- data/app/services/solidus_bolt/users/refresh_access_token_service.rb +44 -0
- data/app/services/solidus_bolt/users/sync_addresses_service.rb +49 -0
- data/app/services/solidus_bolt/users/sync_payment_sources_service.rb +50 -0
- data/app/services/solidus_bolt/webhooks/create_service.rb +52 -0
- data/app/views/spree/admin/bolt_webhooks/new.html.erb +22 -0
- data/app/views/spree/admin/bolts/_configuration.html.erb +32 -0
- data/app/views/spree/admin/bolts/_form.html.erb +29 -0
- data/app/views/spree/admin/bolts/edit.html.erb +6 -0
- data/app/views/spree/admin/bolts/show.html.erb +21 -0
- data/app/views/spree/admin/payments/source_forms/_bolt.html.erb +1 -0
- data/app/views/spree/admin/payments/source_views/_bolt.html.erb +2 -0
- data/app/views/spree/api/payments/source_views/_bolt.json.jbuilder +4 -0
- data/app/views/spree/checkout/existing_payment/_bolt.html.erb +7 -0
- data/app/views/spree/checkout/payment/_bolt.html.erb +1 -0
- data/app/views/spree/shared/payment/_bolt.html.erb +19 -0
- data/app/webhooks/solidus_bolt/handlers/base_handler.rb +27 -0
- data/app/webhooks/solidus_bolt/handlers/capture_handler.rb +13 -0
- data/app/webhooks/solidus_bolt/handlers/credit_handler.rb +18 -0
- data/app/webhooks/solidus_bolt/handlers/void_handler.rb +11 -0
- data/app/webhooks/solidus_bolt/sorter.rb +33 -0
- data/bin/console +17 -0
- data/bin/rails +7 -0
- data/bin/rails-engine +13 -0
- data/bin/rails-sandbox +16 -0
- data/bin/rake +7 -0
- data/bin/sandbox +86 -0
- data/bin/setup +8 -0
- data/config/initializers/menu_items.rb +14 -0
- data/config/locales/en.yml +17 -0
- data/config/routes.rb +11 -0
- data/db/migrate/20220330094232_create_solidus_bolt_payment_sources.rb +16 -0
- data/db/migrate/20220413063328_create_solidus_bolt_bolt_configurations.rb +14 -0
- data/db/migrate/20220502005041_swap_url_for_env_boolean_in_bolt_configuration.rb +6 -0
- data/db/migrate/20220509102309_rework_solidus_bolt_payment_sources.rb +19 -0
- data/db/migrate/20220510075227_add_create_bolt_account_to_solidus_bolt_payment_source.rb +5 -0
- data/db/migrate/20220519233043_add_user_to_solidus_bolt_payment_source.rb +5 -0
- data/db/migrate/20220526005619_remove_user_id_from_solidus_bolt_payment_source.rb +5 -0
- data/db/migrate/20220530102107_rename_bolt_configuration_merchant_id_to_division_public_id.rb +5 -0
- data/db/migrate/20220531075527_update_bolt_configuration_environment_column_restrictions.rb +6 -0
- data/db/seeds.rb +30 -0
- data/lib/generators/solidus_bolt/install/install_generator.rb +78 -0
- data/lib/generators/solidus_bolt/install/templates/initializer.rb +8 -0
- data/lib/solidus_bolt/configuration.rb +19 -0
- data/lib/solidus_bolt/engine.rb +62 -0
- data/lib/solidus_bolt/testing_support/factories.rb +32 -0
- data/lib/solidus_bolt/version.rb +5 -0
- data/lib/solidus_bolt.rb +9 -0
- data/lib/tasks/db/seed/solidus_bolt.rake +14 -0
- data/lib/views/frontend/spree/shared/_login_bar_items.html.erb +18 -0
- data/solidus_bolt.gemspec +46 -0
- data/spec/decorators/models/solidus_bolt/address_decorator_spec.rb +24 -0
- data/spec/decorators/models/solidus_bolt/order_decorator_spec.rb +36 -0
- data/spec/decorators/models/solidus_bolt/payment_decorator_spec.rb +30 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_AddAddressService/_call/with_correct_access_token/receives_a_successful_response.yml +137 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_AddAddressService/_call/with_existing_address/skips_the_add_address_call.yml +82 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_AddAddressService/_call/with_wrong_access_token/gives_an_error.yml +55 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_AddPaymentMethodService/_call/with_correct_access_token/receives_a_successful_response.yml +186 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_AddPaymentMethodService/_call/with_wrong_access_token/gives_an_error.yml +179 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_DetailService/_call/with_correct_access_token/receives_a_successful_response.yml +55 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_DetailService/_call/with_wrong_access_token/gives_an_error.yml +55 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_DetectAccountService/_call/receives_the_correct_response.yml +50 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_DetectAccountService/_call/returns_status_200.yml +50 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Oauth_TokenService/_call/makes_the_API_call.yml +59 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_AuthorizeService/when_repeat_payment/_call/makes_the_API_call.yml +305 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_AuthorizeService/with_auto_capture/_call/makes_the_API_call.yml +307 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_AuthorizeService/without_auto_capture/_call/makes_the_API_call.yml +252 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_CaptureService/_call/makes_the_API_call.yml +242 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_DetailService/_call/makes_the_API_call.yml +244 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_RefundService/_call/makes_the_API_call.yml +296 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_VoidService/_call/makes_the_API_call.yml +242 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_VoidService/_call/when_transaction_id_is_missing/makes_the_API_call.yml +242 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_VoidService/_call/when_transaction_reference_is_missing/makes_the_API_call.yml +242 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Users_SyncAddressesService/_call/adds_the_bill_address_to_the_user.yml +165 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Users_SyncAddressesService/_call/adds_the_ship_address_to_the_user.yml +165 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Users_SyncPaymentSourcesService/_call/creates_a_new_payment_source_with_card_ID.yml +55 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Webhooks_CreateService/_call/with_all_event/returns_a_webhook_id.yml +54 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Webhooks_CreateService/_call/with_an_event/returns_a_webhook_id.yml +54 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_Webhooks_CreateService/_call/with_empty_event/raises_a_server_error.yml +57 -0
- data/spec/jobs/solidus_bolt/add_address_job_spec.rb +18 -0
- data/spec/models/solidus_bolt/bolt_configuration_spec.rb +173 -0
- data/spec/models/solidus_bolt/gateway_spec.rb +130 -0
- data/spec/models/solidus_bolt/payment_method_spec.rb +21 -0
- data/spec/models/solidus_bolt/payment_source_spec.rb +22 -0
- data/spec/requests/solidus_bolt/accounts_controller_spec.rb +41 -0
- data/spec/requests/solidus_bolt/webhooks_controller_spec.rb +122 -0
- data/spec/requests/spree/admin/bolt_spec.rb +71 -0
- data/spec/requests/spree/admin/bolt_webhook_spec.rb +35 -0
- data/spec/requests/spree/checkout_controller_spec.rb +117 -0
- data/spec/services/solidus_bolt/accounts/add_address_service_spec.rb +45 -0
- data/spec/services/solidus_bolt/accounts/add_payment_method_service_spec.rb +47 -0
- data/spec/services/solidus_bolt/accounts/detail_service_spec.rb +32 -0
- data/spec/services/solidus_bolt/accounts/detect_account_service_spec.rb +15 -0
- data/spec/services/solidus_bolt/base_service_spec.rb +49 -0
- data/spec/services/solidus_bolt/oauth/token_service_spec.rb +15 -0
- data/spec/services/solidus_bolt/payments/capture_sync_service_spec.rb +27 -0
- data/spec/services/solidus_bolt/payments/credit_sync_service_spec.rb +38 -0
- data/spec/services/solidus_bolt/payments/void_sync_service_spec.rb +25 -0
- data/spec/services/solidus_bolt/transactions/authorize_service_spec.rb +117 -0
- data/spec/services/solidus_bolt/transactions/base_service_spec.rb +38 -0
- data/spec/services/solidus_bolt/transactions/capture_service_spec.rb +37 -0
- data/spec/services/solidus_bolt/transactions/detail_service_spec.rb +31 -0
- data/spec/services/solidus_bolt/transactions/refund_service_spec.rb +42 -0
- data/spec/services/solidus_bolt/transactions/void_service_spec.rb +70 -0
- data/spec/services/solidus_bolt/users/refresh_access_token_service_spec.rb +45 -0
- data/spec/services/solidus_bolt/users/sync_addresses_service_spec.rb +74 -0
- data/spec/services/solidus_bolt/users/sync_payment_sources_service_spec.rb +25 -0
- data/spec/services/solidus_bolt/webhooks/create_service_spec.rb +33 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/support/bolt_configuration.rb +26 -0
- data/spec/support/bolt_helper.rb +66 -0
- data/spec/support/vcr.rb +29 -0
- data/spec/webhooks/solidus_bolt/handlers/base_handler_spec.rb +13 -0
- data/spec/webhooks/solidus_bolt/handlers/capture_handler_spec.rb +24 -0
- data/spec/webhooks/solidus_bolt/handlers/credit_handler_spec.rb +32 -0
- data/spec/webhooks/solidus_bolt/handlers/void_handler_spec.rb +19 -0
- data/spec/webhooks/solidus_bolt/sorter_spec.rb +39 -0
- metadata +492 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusBolt::Webhooks::CreateService, :vcr, :bolt_configuration do
|
6
|
+
describe '#call', vcr: true do
|
7
|
+
subject(:create) { described_class.call(url: 'https://solidus-test.com/webhook', event: event) }
|
8
|
+
|
9
|
+
context 'with an event' do
|
10
|
+
let(:event) { 'payment' }
|
11
|
+
|
12
|
+
it 'returns a webhook id' do
|
13
|
+
expect(create).to match hash_including('webhook_id')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'with "all" event' do
|
18
|
+
let(:event) { 'all' }
|
19
|
+
|
20
|
+
it 'returns a webhook id' do
|
21
|
+
expect(create).to match hash_including('webhook_id')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with empty event' do
|
26
|
+
let(:event) { '' }
|
27
|
+
|
28
|
+
it 'raises a server error' do
|
29
|
+
expect{ create }.to raise_error SolidusBolt::ServerError
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
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
|
+
require 'pry'
|
9
|
+
require 'vcr'
|
10
|
+
require 'webmock/rspec'
|
11
|
+
|
12
|
+
# Create the dummy app if it's still missing.
|
13
|
+
dummy_env = "#{__dir__}/dummy/config/environment.rb"
|
14
|
+
system 'bin/rake extension:test_app' unless File.exist? dummy_env
|
15
|
+
require dummy_env
|
16
|
+
|
17
|
+
# Requires factories and other useful helpers defined in spree_core.
|
18
|
+
require 'solidus_dev_support/rspec/feature_helper'
|
19
|
+
|
20
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
21
|
+
# in spec/support/ and its subdirectories.
|
22
|
+
Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f }
|
23
|
+
|
24
|
+
require 'spree/testing_support/order_walkthrough'
|
25
|
+
|
26
|
+
# Requires factories defined in lib/solidus_bolt/testing_support/factories.rb
|
27
|
+
SolidusDevSupport::TestingSupport::Factories.load_for(SolidusBolt::Engine)
|
28
|
+
|
29
|
+
RSpec.configure do |config|
|
30
|
+
config.infer_spec_type_from_file_location!
|
31
|
+
config.use_transactional_fixtures = false
|
32
|
+
config.include SolidusBolt::BoltHelper
|
33
|
+
|
34
|
+
if Spree.solidus_gem_version < Gem::Version.new('2.11')
|
35
|
+
config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.before(:example, :bolt_configuration) do
|
5
|
+
solidus_bolt_configuration = SolidusBolt::BoltConfiguration.fetch
|
6
|
+
|
7
|
+
solidus_bolt_configuration.bearer_token = ENV['BOLT_BEARER_TOKEN']
|
8
|
+
solidus_bolt_configuration.environment = 'sandbox'
|
9
|
+
solidus_bolt_configuration.merchant_public_id = ENV['BOLT_MERCHANT_PUBLIC_ID']
|
10
|
+
solidus_bolt_configuration.division_public_id = ENV['BOLT_DIVISION_PUBLIC_ID']
|
11
|
+
solidus_bolt_configuration.api_key = ENV['BOLT_API_KEY']
|
12
|
+
solidus_bolt_configuration.signing_secret = ENV['BOLT_SIGNING_SECRET']
|
13
|
+
solidus_bolt_configuration.publishable_key = ENV['BOLT_PUBLISHABLE_KEY']
|
14
|
+
|
15
|
+
solidus_bolt_configuration.save!
|
16
|
+
|
17
|
+
allow(SolidusBolt::BaseService).to receive(:generate_nonce).and_return('fakenonce')
|
18
|
+
allow(SolidusBolt::BoltHelper).to receive(:nonce).and_return('helpernonce')
|
19
|
+
allow(TweetNaCl).to receive(:crypto_box_keypair).and_return(
|
20
|
+
[
|
21
|
+
"\x8C\xEB\x1C^(\x99\n\xC9\xFE\x9D\xF5\xC5z\xD0E\xFBs\xA7\xD2p\x16\x81\xE7O\xF3\xB6[%B\xA2\xCC<",
|
22
|
+
"\x86(\x1D\x8B2s\x7F\xD0\xB1\xCC\"\x83\xE2Lqy4\xF6\x1D\xAA\xA1\xD5\e\x16#a\x1E\xF0F\xCF\xE1\t"
|
23
|
+
]
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusBolt
|
4
|
+
module BoltHelper
|
5
|
+
PUBLIC_KEY_URL = 'https://sandbox.bolttk.com/public_key'
|
6
|
+
TOKEN_URL = 'https://sandbox.bolttk.com/token'
|
7
|
+
|
8
|
+
def tokenize_credit_card(credit_card_number:, cvv:)
|
9
|
+
request_body = encrypt_request_body(credit_card_number, cvv)
|
10
|
+
response = make_request(request_body)
|
11
|
+
JSON.parse(decrypt_response_body(response))
|
12
|
+
end
|
13
|
+
|
14
|
+
def public_key
|
15
|
+
@public_key ||= HTTParty.get(URI.parse(PUBLIC_KEY_URL)).body
|
16
|
+
end
|
17
|
+
|
18
|
+
def nonce
|
19
|
+
@nonce ||= rand(10**24).to_s.rjust(24, '0')
|
20
|
+
end
|
21
|
+
|
22
|
+
def keys
|
23
|
+
@keys ||= TweetNaCl.crypto_box_keypair
|
24
|
+
end
|
25
|
+
|
26
|
+
def make_request(encrypted_request_body)
|
27
|
+
HTTParty.post(
|
28
|
+
TOKEN_URL,
|
29
|
+
{
|
30
|
+
body: JSON.dump(encrypted_request_body),
|
31
|
+
headers: {
|
32
|
+
'Content-Type' => 'application/json'
|
33
|
+
}
|
34
|
+
}
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def encrypt_request_body(credit_card_number, cvv)
|
39
|
+
message = { cc: credit_card_number, cvv: cvv }.to_json
|
40
|
+
|
41
|
+
payload = TweetNaCl.crypto_box(
|
42
|
+
message,
|
43
|
+
nonce,
|
44
|
+
Base64.decode64(public_key),
|
45
|
+
keys[1]
|
46
|
+
)
|
47
|
+
|
48
|
+
{
|
49
|
+
payload: Base64.encode64(payload),
|
50
|
+
nonce: Base64.encode64(nonce),
|
51
|
+
public_key: Base64.encode64(keys[0])
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def decrypt_response_body(response)
|
56
|
+
parsed_response = JSON.parse(response.body)
|
57
|
+
|
58
|
+
TweetNaCl.crypto_box_open(
|
59
|
+
Base64.decode64(parsed_response['payload']),
|
60
|
+
Base64.decode64(parsed_response['nonce']),
|
61
|
+
Base64.decode64(public_key),
|
62
|
+
keys[1]
|
63
|
+
)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/support/vcr.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
VCR.configure do |config|
|
4
|
+
config.ignore_localhost = true
|
5
|
+
config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
|
6
|
+
config.hook_into :webmock
|
7
|
+
config.configure_rspec_metadata!
|
8
|
+
|
9
|
+
config.filter_sensitive_data('<API_KEY>') do |interaction|
|
10
|
+
interaction.request.headers['X-API-KEY']&.first
|
11
|
+
end
|
12
|
+
|
13
|
+
config.filter_sensitive_data('<PUBLISHABLE_KEY>') do |interaction|
|
14
|
+
interaction.request.headers['X-Publishable-Key']&.first
|
15
|
+
end
|
16
|
+
|
17
|
+
config.filter_sensitive_data('<BEARER AUTHORIZATION>') do |interaction|
|
18
|
+
interaction.request.headers['Authorization']&.first
|
19
|
+
end
|
20
|
+
|
21
|
+
config.filter_sensitive_data('<PUBLISHABLE_KEY>') { SolidusBolt::BoltConfiguration.fetch.publishable_key }
|
22
|
+
config.filter_sensitive_data('<API_KEY>') { SolidusBolt::BoltConfiguration.fetch.api_key }
|
23
|
+
config.filter_sensitive_data('<DIVISION_ID>') { SolidusBolt::BoltConfiguration.fetch.division_public_id }
|
24
|
+
|
25
|
+
# Let's you set default VCR record mode with VCR_RECORDE_MODE=all for re-recording
|
26
|
+
# episodes. :once is VCR default
|
27
|
+
record_mode = ENV.fetch('VCR_RECORD_MODE', :once).to_sym
|
28
|
+
config.default_cassette_options = { record: record_mode }
|
29
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusBolt::Handlers::BaseHandler do
|
6
|
+
subject(:handler) { described_class.new({}) }
|
7
|
+
|
8
|
+
it { expect(described_class).to respond_to(:call).with(1).arguments }
|
9
|
+
|
10
|
+
it { expect(handler).to respond_to(:call).with(0).arguments }
|
11
|
+
|
12
|
+
it { expect { handler.call }.to raise_exception(NotImplementedError) }
|
13
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusBolt::Handlers::CaptureHandler do
|
6
|
+
subject(:capture) { described_class.call(params) }
|
7
|
+
|
8
|
+
let(:payment) { create(:bolt_payment, response_code: 'V2YW-NYNR-2MYM') }
|
9
|
+
let(:capture_amount) { 500 }
|
10
|
+
let(:params) { { data: { reference: payment.response_code, captures: [{ amount: { amount: capture_amount } }] } } }
|
11
|
+
|
12
|
+
before do
|
13
|
+
allow(SolidusBolt::Payments::CaptureSyncService).to receive(:call).with(
|
14
|
+
payment: payment, capture_amount: capture_amount
|
15
|
+
)
|
16
|
+
capture
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'calls the payment capture service' do
|
20
|
+
expect(SolidusBolt::Payments::CaptureSyncService).to have_received(:call).with(
|
21
|
+
payment: payment, capture_amount: capture_amount
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusBolt::Handlers::CreditHandler do
|
6
|
+
subject(:credit) { described_class.call(params) }
|
7
|
+
|
8
|
+
let(:transaction_id) { 'AAAA-BBBB-CCCC' }
|
9
|
+
let(:payment) { create(:bolt_payment, response_code: 'V2YW-NYNR-2MYM') }
|
10
|
+
let(:params) do
|
11
|
+
{
|
12
|
+
data: {
|
13
|
+
reference: transaction_id,
|
14
|
+
source_transaction: { reference: payment.response_code },
|
15
|
+
requested_refund_amount: { amount: 100 }
|
16
|
+
}
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
before do
|
21
|
+
allow(SolidusBolt::Payments::CreditSyncService).to receive(:call).with(
|
22
|
+
payment: payment, amount: 100, transaction_id: transaction_id
|
23
|
+
)
|
24
|
+
credit
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'calls the payment credit service' do
|
28
|
+
expect(SolidusBolt::Payments::CreditSyncService).to have_received(:call).with(
|
29
|
+
payment: payment, amount: 100, transaction_id: transaction_id
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusBolt::Handlers::VoidHandler do
|
6
|
+
subject(:void) { described_class.call(params) }
|
7
|
+
|
8
|
+
let(:payment) { create(:bolt_payment, response_code: 'V2YW-NYNR-2MYM') }
|
9
|
+
let(:params) { { data: { reference: payment.response_code } } }
|
10
|
+
|
11
|
+
before do
|
12
|
+
allow(SolidusBolt::Payments::VoidSyncService).to receive(:call).with(payment: payment)
|
13
|
+
void
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'calls the payment void service' do
|
17
|
+
expect(SolidusBolt::Payments::VoidSyncService).to have_received(:call).with(payment: payment)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusBolt::Sorter do
|
6
|
+
subject(:do_call) { described_class.call(params) }
|
7
|
+
|
8
|
+
let(:event_type) { 'EVENT.TYPE' }
|
9
|
+
let(:params) { { type: event_type, resource: {} } }
|
10
|
+
|
11
|
+
it { expect(described_class).to respond_to(:new).with(1).arguments }
|
12
|
+
|
13
|
+
it { expect(described_class).to respond_to(:call).with(1).arguments }
|
14
|
+
|
15
|
+
it { expect(described_class.new({})).to respond_to(:call).with(0).arguments }
|
16
|
+
|
17
|
+
describe '#call' do
|
18
|
+
context 'when the handler is not defined' do
|
19
|
+
it 'returns nil' do
|
20
|
+
expect(do_call).to be_nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when the handler is defined' do
|
25
|
+
let(:result) { 'result' }
|
26
|
+
let(:event_type) { 'BASE' }
|
27
|
+
let(:handler) { instance_double(SolidusBolt::Handlers::BaseHandler) }
|
28
|
+
|
29
|
+
before do
|
30
|
+
allow(SolidusBolt::Handlers::BaseHandler).to receive(:new).and_return(handler)
|
31
|
+
allow(handler).to receive(:call).and_return(result)
|
32
|
+
end
|
33
|
+
|
34
|
+
it { expect { do_call }.not_to raise_exception }
|
35
|
+
|
36
|
+
it { expect(do_call).to be result }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|