solidus_bolt 0.2.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -2
- data/app/assets/javascripts/solidus_bolt.js +16 -2
- data/app/controllers/spree/admin/bolt_callback_urls_controller.rb +39 -0
- data/app/controllers/spree/admin/bolts_controller.rb +0 -2
- data/app/decorators/models/solidus_bolt/order_decorator.rb +1 -0
- data/app/models/solidus_bolt/bolt_configuration.rb +8 -0
- data/app/services/solidus_bolt/merchant_configuration/get_callback_urls_service.rb +36 -0
- data/app/services/solidus_bolt/merchant_configuration/set_callback_urls_service.rb +55 -0
- data/app/views/spree/admin/bolt_callback_urls/new.html.erb +24 -0
- data/app/views/spree/admin/bolts/_configuration.html.erb +2 -2
- data/app/views/spree/admin/bolts/_form.html.erb +0 -4
- data/app/views/spree/admin/bolts/show.html.erb +3 -0
- data/config/routes.rb +5 -0
- data/db/migrate/20220725133701_remove_merchant_id_and_division_public_id_on_bolt_configuration.rb +6 -0
- data/db/seeds.rb +0 -2
- data/lib/solidus_bolt/testing_support/factories.rb +1 -3
- data/lib/solidus_bolt/version.rb +1 -1
- data/lib/views/frontend/spree/shared/_login_bar_items.html.erb +1 -1
- data/solidus_bolt.gemspec +0 -1
- data/spec/decorators/models/solidus_bolt/order_decorator_spec.rb +1 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_MerchantConfiguration_GetCallbackUrlsService/_call/receives_the_correct_response.yml +54 -0
- data/spec/fixtures/vcr_cassettes/SolidusBolt_MerchantConfiguration_SetCallbackUrlsService/_call/receives_the_correct_response.yml +54 -0
- data/spec/models/solidus_bolt/bolt_configuration_spec.rb +24 -4
- data/spec/requests/spree/admin/bolt_spec.rb +0 -4
- data/spec/services/solidus_bolt/merchant_configuration/get_callback_urls_service_spec.rb +15 -0
- data/spec/services/solidus_bolt/merchant_configuration/set_callback_urls_service_spec.rb +20 -0
- data/spec/services/solidus_bolt/webhooks/create_service_spec.rb +6 -4
- data/spec/support/bolt_configuration.rb +1 -3
- data/spec/support/vcr.rb +1 -1
- metadata +15 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85a81224dbf00b809093c50581fa790f56f6389a85753a002eff55ed149ddbff
|
4
|
+
data.tar.gz: 84ee9afd0a6dd580df9d3ffcbe2550a3e957d5c43fafc209e42cd79965caf9c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed702363808663ef10223d943f670c2bc90b248be1f4953b9288b631b36ec9a40908d1c7d3b295bb6f5cbf27b92820845dbe49e8f51a3336a1da68372c247f18
|
7
|
+
data.tar.gz: 2398a99717a2d8f76b1b20c790062b5543d0f7323d90dc55637814bbeadac6d55c3078008a0213f2c6461630dd51362316d5d1b2a2c987fe37acac41cd4e34e8
|
data/README.md
CHANGED
@@ -16,6 +16,8 @@ const tokenize = async (paymentField, paymentMethodId, frontend) => {
|
|
16
16
|
if (result["token"]) {
|
17
17
|
updateOrder(result, paymentMethodId, frontend)
|
18
18
|
} else {
|
19
|
+
const submitButton = document.getElementById("bolt-submit-button")
|
20
|
+
submitButton.disabled = false;
|
19
21
|
console.log(`error ${result["type"]}: ${result["message"]}`);
|
20
22
|
}
|
21
23
|
});
|
@@ -29,6 +31,11 @@ const redirectToNextStep = (frontend) => {
|
|
29
31
|
}
|
30
32
|
}
|
31
33
|
|
34
|
+
async function getResponseText(response) {
|
35
|
+
const text = await response.text();
|
36
|
+
return text;
|
37
|
+
}
|
38
|
+
|
32
39
|
const updateOrder = async (card, paymentMethodId, frontend) => {
|
33
40
|
await fetch(`/api/checkouts/${Spree.current_order_id}`, {
|
34
41
|
method: 'PATCH',
|
@@ -37,6 +44,7 @@ const updateOrder = async (card, paymentMethodId, frontend) => {
|
|
37
44
|
'X-Spree-Order-Token': Spree.current_order_token
|
38
45
|
},
|
39
46
|
body: JSON.stringify({
|
47
|
+
'state': 'payment',
|
40
48
|
'order': {
|
41
49
|
'payments_attributes': [{
|
42
50
|
'payment_method_id': paymentMethodId,
|
@@ -53,8 +61,14 @@ const updateOrder = async (card, paymentMethodId, frontend) => {
|
|
53
61
|
}
|
54
62
|
})
|
55
63
|
})
|
56
|
-
.then(() => {
|
57
|
-
|
64
|
+
.then((response) => {
|
65
|
+
if(response.ok) {
|
66
|
+
redirectToNextStep(frontend)
|
67
|
+
} else {
|
68
|
+
getResponseText(response).then(text => {
|
69
|
+
console.error(text);
|
70
|
+
});
|
71
|
+
}
|
58
72
|
})
|
59
73
|
.catch((response) => {
|
60
74
|
console.log('Error updating order')
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
module Admin
|
5
|
+
class BoltCallbackUrlsController < Spree::Admin::BaseController
|
6
|
+
def new
|
7
|
+
callback_urls = SolidusBolt::MerchantConfiguration::GetCallbackUrlsService.call
|
8
|
+
|
9
|
+
@oauth_logout = callback_urls['callback_urls'].find { |c| c['type'] == 'oauth_logout' }['url']
|
10
|
+
@oauth_redirect = callback_urls['callback_urls'].find { |c| c['type'] == 'oauth_redirect' }['url']
|
11
|
+
end
|
12
|
+
|
13
|
+
def update
|
14
|
+
SolidusBolt::MerchantConfiguration::SetCallbackUrlsService.call(
|
15
|
+
oauth_logout: params[:bolt_callback_urls][:oauth_logout],
|
16
|
+
oauth_redirect: params[:bolt_callback_urls][:oauth_redirect]
|
17
|
+
)
|
18
|
+
flash[:success] = "Successfully updated callback urls."
|
19
|
+
|
20
|
+
redirect_to new_admin_bolt_callback_urls_path
|
21
|
+
rescue SolidusBolt::ServerError => e
|
22
|
+
flash[:error] = e.message
|
23
|
+
|
24
|
+
render :new
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def bolt_webhook_params
|
30
|
+
params
|
31
|
+
.require(:bolt_webhook)
|
32
|
+
.permit(
|
33
|
+
:event,
|
34
|
+
:webhook_url,
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -15,6 +15,14 @@ module SolidusBolt
|
|
15
15
|
|
16
16
|
validate :config_can_be_created, on: :create
|
17
17
|
|
18
|
+
def merchant_public_id
|
19
|
+
publishable_key&.split('.')&.first
|
20
|
+
end
|
21
|
+
|
22
|
+
def division_public_id
|
23
|
+
publishable_key&.split('.')&.second
|
24
|
+
end
|
25
|
+
|
18
26
|
def self.fetch
|
19
27
|
first_or_create
|
20
28
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusBolt
|
4
|
+
module MerchantConfiguration
|
5
|
+
class GetCallbackUrlsService < SolidusBolt::BaseService
|
6
|
+
attr_reader :oauth_redirect, :oauth_logout, :get_account
|
7
|
+
|
8
|
+
def call
|
9
|
+
get_callbacks
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def get_callbacks # rubocop:disable Naming/AccessorMethodName
|
15
|
+
url = "#{api_base_url}/#{api_version}/merchant/callbacks"
|
16
|
+
handle_result(
|
17
|
+
HTTParty.get(
|
18
|
+
url, headers: headers, query: query
|
19
|
+
)
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def query
|
24
|
+
{
|
25
|
+
division_id: @config.division_public_id
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def headers
|
30
|
+
{
|
31
|
+
'Content-Type' => 'application/json',
|
32
|
+
}.merge(authentication_header)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusBolt
|
4
|
+
module MerchantConfiguration
|
5
|
+
class SetCallbackUrlsService < SolidusBolt::BaseService
|
6
|
+
attr_reader :oauth_redirect, :oauth_logout, :get_account
|
7
|
+
|
8
|
+
def initialize(oauth_redirect: nil, oauth_logout: nil, get_account: nil)
|
9
|
+
@oauth_redirect = oauth_redirect
|
10
|
+
@oauth_logout = oauth_logout
|
11
|
+
@get_account = get_account
|
12
|
+
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
set_callbacks
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def set_callbacks
|
23
|
+
url = "#{api_base_url}/#{api_version}/merchant/callbacks"
|
24
|
+
handle_result(
|
25
|
+
HTTParty.post(
|
26
|
+
url, headers: headers, body: body.to_json
|
27
|
+
)
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def body
|
32
|
+
{
|
33
|
+
division_id: @config.division_public_id,
|
34
|
+
callback_urls: callback_urls
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def callback_urls
|
39
|
+
callback_urls = []
|
40
|
+
|
41
|
+
callback_urls << { type: 'oauth_redirect', url: oauth_redirect } if oauth_redirect.present?
|
42
|
+
callback_urls << { type: 'oauth_logout', url: oauth_logout } if oauth_logout.present?
|
43
|
+
callback_urls << { type: 'get_account', url: get_account } if get_account.present?
|
44
|
+
|
45
|
+
callback_urls
|
46
|
+
end
|
47
|
+
|
48
|
+
def headers
|
49
|
+
{
|
50
|
+
'Content-Type' => 'application/json',
|
51
|
+
}.merge(authentication_header)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<% admin_breadcrumb(plural_resource_name(SolidusBolt::BoltConfiguration)) %>
|
2
|
+
|
3
|
+
<%= form_for :bolt_callback_urls, url: admin_bolt_callback_urls_path, method: :patch do |f| %>
|
4
|
+
<fieldset class="form-group no-border-bottom no-border-top">
|
5
|
+
<div class="row">
|
6
|
+
<div id="general_fields" class="col-9">
|
7
|
+
<div class="row">
|
8
|
+
<div class="col-12">
|
9
|
+
<%= f.label :oauth_redirect %>
|
10
|
+
<%= f.text_field :oauth_redirect, class: 'fullwidth', value: @oauth_redirect || 'https://domain.com/webhooks/bolt' %>
|
11
|
+
</div>
|
12
|
+
<div class="col-12">
|
13
|
+
<%= f.label :oauth_logout %>
|
14
|
+
<%= f.text_field :oauth_logout, class: 'fullwidth', value: @oauth_logout || 'https://domain.com/webhooks/bolt' %>
|
15
|
+
</div>
|
16
|
+
</div>
|
17
|
+
<div class="row p-2 justify-content-center">
|
18
|
+
<%= f.submit 'Update', class: 'btn btn-primary', data: { disable_with: 'Creating..' } %>
|
19
|
+
<%= link_to 'Cancel', admin_bolt_path, class: 'button' %>
|
20
|
+
</div>
|
21
|
+
</div>
|
22
|
+
</div>
|
23
|
+
</fieldset>
|
24
|
+
<% end %>
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<table class="index">
|
3
3
|
<thead>
|
4
4
|
<tr>
|
5
|
-
<th><%= SolidusBolt::BoltConfiguration.human_attribute_name(:
|
5
|
+
<th><%= SolidusBolt::BoltConfiguration.human_attribute_name(:publishable_key) %></th>
|
6
6
|
<th><%= SolidusBolt::BoltConfiguration.human_attribute_name(:environment) %></th>
|
7
7
|
<th><%= SolidusBolt::BoltConfiguration.human_attribute_name(:created_at) %></th>
|
8
8
|
<th><%= SolidusBolt::BoltConfiguration.human_attribute_name(:updated_at) %></th>
|
@@ -11,7 +11,7 @@
|
|
11
11
|
</thead>
|
12
12
|
<tbody>
|
13
13
|
<tr>
|
14
|
-
<td><%= @bolt_configuration.
|
14
|
+
<td><%= @bolt_configuration.publishable_key %></td>
|
15
15
|
<td><%= @bolt_configuration.environment %></td>
|
16
16
|
<td>
|
17
17
|
<%= @bolt_configuration.created_at.to_s(:long) %>
|
@@ -6,10 +6,6 @@
|
|
6
6
|
<div class="col-12">
|
7
7
|
<%= f.label :environment %>
|
8
8
|
<%= f.select :environment, %w[production sandbox staging] %><br />
|
9
|
-
<%= f.label 'Merchant Public Id' %><br />
|
10
|
-
<%= f.text_field :merchant_public_id, class: 'fullwidth' %>
|
11
|
-
<%= f.label 'Division Public Id' %><br />
|
12
|
-
<%= f.text_field :division_public_id, class: 'fullwidth' %>
|
13
9
|
<%= f.label :api_key %><br />
|
14
10
|
<%= f.text_field :api_key, class: 'fullwidth' %>
|
15
11
|
<%= f.label :signing_secret %><br />
|
@@ -11,6 +11,9 @@
|
|
11
11
|
) %>
|
12
12
|
</li>
|
13
13
|
<% else %>
|
14
|
+
<li>
|
15
|
+
<%= link_to 'Configure Callbacks URLs', new_admin_bolt_callback_urls_path, class: 'btn btn-primary' %>
|
16
|
+
</li>
|
14
17
|
<li>
|
15
18
|
<%= link_to 'Configure Webhooks', new_admin_bolt_webhook_path, class: 'btn btn-primary' %>
|
16
19
|
</li>
|
data/config/routes.rb
CHANGED
@@ -4,8 +4,13 @@ Spree::Core::Engine.routes.draw do
|
|
4
4
|
namespace :admin do
|
5
5
|
resource :bolt, only: [:show, :edit, :update]
|
6
6
|
resource :bolt_webhook, only: [:new, :create]
|
7
|
+
resource :bolt_callback_urls, only: [:new, :update]
|
7
8
|
end
|
8
9
|
|
9
10
|
post '/webhooks/bolt', to: '/solidus_bolt/webhooks#update'
|
10
11
|
post '/api/accounts/bolt', to: '/solidus_bolt/accounts#create'
|
12
|
+
|
13
|
+
devise_scope :spree_user do
|
14
|
+
get '/bolt_logout', to: '/spree/user_sessions#destroy', as: 'bolt_logout'
|
15
|
+
end
|
11
16
|
end
|
data/db/migrate/20220725133701_remove_merchant_id_and_division_public_id_on_bolt_configuration.rb
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
class RemoveMerchantIdAndDivisionPublicIdOnBoltConfiguration < ActiveRecord::Migration[6.1]
|
2
|
+
def change
|
3
|
+
remove_column :solidus_bolt_bolt_configurations, :division_public_id, :string
|
4
|
+
remove_column :solidus_bolt_bolt_configurations, :merchant_public_id, :string
|
5
|
+
end
|
6
|
+
end
|
data/db/seeds.rb
CHANGED
@@ -3,8 +3,6 @@
|
|
3
3
|
solidus_bolt_configuration = SolidusBolt::BoltConfiguration.fetch
|
4
4
|
|
5
5
|
solidus_bolt_configuration.environment = ENV.fetch('BOLT_ENVIRONMENT', 'sandbox')
|
6
|
-
solidus_bolt_configuration.merchant_public_id = ENV['BOLT_MERCHANT_PUBLIC_ID']
|
7
|
-
solidus_bolt_configuration.division_public_id = ENV['BOLT_DIVISION_PUBLIC_ID']
|
8
6
|
solidus_bolt_configuration.api_key = ENV['BOLT_API_KEY']
|
9
7
|
solidus_bolt_configuration.signing_secret = ENV['BOLT_SIGNING_SECRET']
|
10
8
|
solidus_bolt_configuration.publishable_key = ENV['BOLT_PUBLISHABLE_KEY']
|
@@ -3,11 +3,9 @@
|
|
3
3
|
FactoryBot.define do
|
4
4
|
factory :bolt_configuration, class: SolidusBolt::BoltConfiguration do
|
5
5
|
environment { 'sandbox' }
|
6
|
-
merchant_public_id { SecureRandom.hex }
|
7
|
-
division_public_id { SecureRandom.hex }
|
8
6
|
api_key { SecureRandom.hex }
|
9
7
|
signing_secret { SecureRandom.hex }
|
10
|
-
publishable_key { SecureRandom.hex }
|
8
|
+
publishable_key { "#{SecureRandom.hex}.#{SecureRandom.hex}.#{SecureRandom.hex}" }
|
11
9
|
end
|
12
10
|
|
13
11
|
factory :bolt_payment_method, class: SolidusBolt::PaymentMethod do
|
data/lib/solidus_bolt/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
<% if spree_current_user %>
|
2
2
|
<li><%= link_to t('spree.my_account'), spree.account_path %></li>
|
3
|
-
<li
|
3
|
+
<li><div class="bolt-account-sso" data-logged-in="true"></div></li>
|
4
4
|
<% else %>
|
5
5
|
<li>
|
6
6
|
<div class="bolt-account-sso"></div>
|
data/solidus_bolt.gemspec
CHANGED
@@ -34,7 +34,6 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_dependency 'multi_json'
|
35
35
|
spec.add_dependency 'omniauth-bolt'
|
36
36
|
spec.add_dependency 'rails'
|
37
|
-
spec.add_dependency 'solidus_auth_devise'
|
38
37
|
spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 4']
|
39
38
|
spec.add_dependency 'solidus_social'
|
40
39
|
spec.add_dependency 'solidus_support', '~> 0.5'
|
@@ -7,6 +7,7 @@ RSpec.describe SolidusBolt::OrderDecorator do
|
|
7
7
|
it 'returns a hash with line items and price' do
|
8
8
|
result = {
|
9
9
|
total_amount: (order.total * 100).to_i,
|
10
|
+
tax_amount: (order.tax_total * 100).to_i,
|
10
11
|
order_reference: order.number,
|
11
12
|
currency: 'USD',
|
12
13
|
shipments: array_including(hash_including(:reference)),
|
@@ -0,0 +1,54 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api-sandbox.bolt.com/v1/merchant/callbacks?division_id=<DIVISION_PUBLIC_ID>
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Content-Type:
|
11
|
+
- application/json
|
12
|
+
X-Api-Key:
|
13
|
+
- "<API_KEY>"
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- "*/*"
|
18
|
+
User-Agent:
|
19
|
+
- Ruby
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Date:
|
26
|
+
- Wed, 27 Jul 2022 18:10:11 GMT
|
27
|
+
Content-Type:
|
28
|
+
- application/json; charset=UTF-8
|
29
|
+
Content-Length:
|
30
|
+
- '157'
|
31
|
+
Connection:
|
32
|
+
- keep-alive
|
33
|
+
Public-Key-Pins-Report-Only:
|
34
|
+
- max-age=2592000;pin-sha256="OGAVOYhLZd3ADKYGFZOED1c5m1ObMlRv9PyIWrO4Nd0=";pin-sha256="RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=";pin-sha256="IXHYSIdST+XY22J5ivybYkntMIfjA5P6pMKX2hWG1BE=";report-uri="https://77aa1bd121ef22d50247a23390ce6cff.report-uri.io/r/default/hpkp/reportOnly"
|
35
|
+
Set-Cookie:
|
36
|
+
- trk=f47ec1df-c6f5-460c-baf3-2ff506846dd2; Path=/; Max-Age=31536000; HttpOnly;
|
37
|
+
Secure; SameSite=None
|
38
|
+
Strict-Transport-Security:
|
39
|
+
- max-age=31536000; includeSubDomains; preload
|
40
|
+
X-Bolt-Api-Version:
|
41
|
+
- '2022-01-01'
|
42
|
+
X-Bolt-Trace-Id:
|
43
|
+
- Root=1-62e17f83-46d90f8f25fd210e0420dbdb
|
44
|
+
X-Device-Id:
|
45
|
+
- cc0e49b483c9bdb9dce4a6f35b9fcfb75194e19da94e18882fac74a192a8fc71
|
46
|
+
X-Envoy-Upstream-Service-Time:
|
47
|
+
- '29'
|
48
|
+
Server:
|
49
|
+
- envoy
|
50
|
+
body:
|
51
|
+
encoding: UTF-8
|
52
|
+
string: '{"callback_urls":[{"url":"http://localhost:3000/bolt_logout","type":"oauth_logout"},{"url":"http://localhost:3000/users/auth/bolt","type":"oauth_redirect"}]}'
|
53
|
+
recorded_at: Wed, 27 Jul 2022 18:10:11 GMT
|
54
|
+
recorded_with: VCR 6.1.0
|
@@ -0,0 +1,54 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api-sandbox.bolt.com/v1/merchant/callbacks
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"division_id":"Rq4qB1QajYLn","callback_urls":[{"type":"oauth_redirect","url":"http://localhost:3000/users/auth/bolt"},{"type":"oauth_logout","url":"http://localhost:3000//user/spree_user/logout"}]}'
|
9
|
+
headers:
|
10
|
+
Content-Type:
|
11
|
+
- application/json
|
12
|
+
X-Api-Key:
|
13
|
+
- "<API_KEY>"
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
Accept:
|
17
|
+
- "*/*"
|
18
|
+
User-Agent:
|
19
|
+
- Ruby
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Date:
|
26
|
+
- Tue, 26 Jul 2022 21:17:15 GMT
|
27
|
+
Content-Type:
|
28
|
+
- application/json; charset=UTF-8
|
29
|
+
Content-Length:
|
30
|
+
- '4'
|
31
|
+
Connection:
|
32
|
+
- keep-alive
|
33
|
+
Public-Key-Pins-Report-Only:
|
34
|
+
- max-age=2592000;pin-sha256="OGAVOYhLZd3ADKYGFZOED1c5m1ObMlRv9PyIWrO4Nd0=";pin-sha256="RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=";pin-sha256="IXHYSIdST+XY22J5ivybYkntMIfjA5P6pMKX2hWG1BE=";report-uri="https://77aa1bd121ef22d50247a23390ce6cff.report-uri.io/r/default/hpkp/reportOnly"
|
35
|
+
Set-Cookie:
|
36
|
+
- trk=ea8f518e-f41d-4b8c-9615-161bff916a0f; Path=/; Max-Age=31536000; HttpOnly;
|
37
|
+
Secure; SameSite=None
|
38
|
+
Strict-Transport-Security:
|
39
|
+
- max-age=31536000; includeSubDomains; preload
|
40
|
+
X-Bolt-Api-Version:
|
41
|
+
- '2022-01-01'
|
42
|
+
X-Bolt-Trace-Id:
|
43
|
+
- Root=1-62e059db-307d2def557ae7d63cda1f93
|
44
|
+
X-Device-Id:
|
45
|
+
- 65fb9d676354668c7128f58217c94230e32303007b66559078fee6aefb88e8a4
|
46
|
+
X-Envoy-Upstream-Service-Time:
|
47
|
+
- '37'
|
48
|
+
Server:
|
49
|
+
- envoy
|
50
|
+
body:
|
51
|
+
encoding: UTF-8
|
52
|
+
string: 'null'
|
53
|
+
recorded_at: Tue, 26 Jul 2022 21:17:15 GMT
|
54
|
+
recorded_with: VCR 6.1.0
|
@@ -5,8 +5,6 @@ RSpec.describe SolidusBolt::BoltConfiguration, type: :model do
|
|
5
5
|
[
|
6
6
|
'id',
|
7
7
|
'environment',
|
8
|
-
'merchant_public_id',
|
9
|
-
'division_public_id',
|
10
8
|
'api_key',
|
11
9
|
'signing_secret',
|
12
10
|
'publishable_key',
|
@@ -46,8 +44,6 @@ RSpec.describe SolidusBolt::BoltConfiguration, type: :model do
|
|
46
44
|
it 'is true for a record with empty fields' do
|
47
45
|
create(
|
48
46
|
:bolt_configuration,
|
49
|
-
merchant_public_id: '',
|
50
|
-
division_public_id: '',
|
51
47
|
api_key: '',
|
52
48
|
signing_secret: '',
|
53
49
|
publishable_key: ''
|
@@ -61,6 +57,30 @@ RSpec.describe SolidusBolt::BoltConfiguration, type: :model do
|
|
61
57
|
end
|
62
58
|
end
|
63
59
|
|
60
|
+
describe '#merchant_public_id' do
|
61
|
+
it 'returns the merchant_public_id' do
|
62
|
+
bolt_configuration = create(:bolt_configuration, publishable_key: 'abc.def.ghi')
|
63
|
+
expect(bolt_configuration.merchant_public_id).to eq('abc')
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns nil if publishable_key is nil' do
|
67
|
+
bolt_configuration = create(:bolt_configuration, publishable_key: nil)
|
68
|
+
expect(bolt_configuration.division_public_id).to be_nil
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#division_public_id' do
|
73
|
+
it 'returns the division_public_id' do
|
74
|
+
bolt_configuration = create(:bolt_configuration, publishable_key: 'abc.def.ghi')
|
75
|
+
expect(bolt_configuration.division_public_id).to eq('def')
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'returns nil if publishable_key is nil' do
|
79
|
+
bolt_configuration = create(:bolt_configuration, publishable_key: nil)
|
80
|
+
expect(bolt_configuration.division_public_id).to be_nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
64
84
|
describe '#environment_url' do
|
65
85
|
context 'when production envornment' do
|
66
86
|
let(:config) { create(:bolt_configuration, environment: 'production') }
|
@@ -6,8 +6,6 @@ RSpec.describe "Spree::Admin::Bolts", type: :request do
|
|
6
6
|
let(:bolt_configuration_params) {
|
7
7
|
{
|
8
8
|
environment: 'sandbox',
|
9
|
-
merchant_public_id: SecureRandom.hex,
|
10
|
-
division_public_id: SecureRandom.hex,
|
11
9
|
api_key: SecureRandom.hex,
|
12
10
|
signing_secret: SecureRandom.hex,
|
13
11
|
publishable_key: SecureRandom.hex
|
@@ -56,8 +54,6 @@ RSpec.describe "Spree::Admin::Bolts", type: :request do
|
|
56
54
|
|
57
55
|
updated_attributes = SolidusBolt::BoltConfiguration.fetch.attributes.slice(
|
58
56
|
'environment',
|
59
|
-
'merchant_public_id',
|
60
|
-
'division_public_id',
|
61
57
|
'api_key',
|
62
58
|
'signing_secret',
|
63
59
|
'publishable_key'
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusBolt::MerchantConfiguration::GetCallbackUrlsService, :vcr, :bolt_configuration do
|
6
|
+
subject(:api) { described_class.new }
|
7
|
+
|
8
|
+
describe '#call', vcr: true do
|
9
|
+
it 'receives the correct response' do
|
10
|
+
expect(api.call).to match hash_including(
|
11
|
+
'callback_urls' => array_including(hash_including('type', 'url'))
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe SolidusBolt::MerchantConfiguration::SetCallbackUrlsService, :vcr, :bolt_configuration do
|
6
|
+
subject(:api) { described_class.new(params) }
|
7
|
+
|
8
|
+
let(:params) {
|
9
|
+
{
|
10
|
+
oauth_redirect: 'http://localhost:3000/users/auth/bolt',
|
11
|
+
oauth_logout: 'http://localhost:3000//user/spree_user/logout'
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
describe '#call', vcr: true do
|
16
|
+
it 'receives the correct response' do
|
17
|
+
expect(api.call).to be_nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -4,13 +4,15 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
RSpec.describe SolidusBolt::Webhooks::CreateService, :vcr, :bolt_configuration do
|
6
6
|
describe '#call', vcr: true do
|
7
|
-
subject(:
|
7
|
+
subject(:create_service) { described_class.call(url: 'https://solidus-test.com/webhook', event: event) }
|
8
|
+
|
9
|
+
before { SolidusBolt::BoltConfiguration.fetch.update(publishable_key: 'abc.def.ghi') }
|
8
10
|
|
9
11
|
context 'with an event' do
|
10
12
|
let(:event) { 'payment' }
|
11
13
|
|
12
14
|
it 'returns a webhook id' do
|
13
|
-
expect(
|
15
|
+
expect(create_service).to match hash_including('webhook_id')
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
@@ -18,7 +20,7 @@ RSpec.describe SolidusBolt::Webhooks::CreateService, :vcr, :bolt_configuration d
|
|
18
20
|
let(:event) { 'all' }
|
19
21
|
|
20
22
|
it 'returns a webhook id' do
|
21
|
-
expect(
|
23
|
+
expect(create_service).to match hash_including('webhook_id')
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
@@ -26,7 +28,7 @@ RSpec.describe SolidusBolt::Webhooks::CreateService, :vcr, :bolt_configuration d
|
|
26
28
|
let(:event) { '' }
|
27
29
|
|
28
30
|
it 'raises a server error' do
|
29
|
-
expect{
|
31
|
+
expect{ create_service }.to raise_error SolidusBolt::ServerError
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
@@ -5,11 +5,9 @@ RSpec.configure do |config|
|
|
5
5
|
solidus_bolt_configuration = SolidusBolt::BoltConfiguration.fetch
|
6
6
|
|
7
7
|
solidus_bolt_configuration.environment = 'sandbox'
|
8
|
-
solidus_bolt_configuration.merchant_public_id = ENV['BOLT_MERCHANT_PUBLIC_ID']
|
9
|
-
solidus_bolt_configuration.division_public_id = ENV['BOLT_DIVISION_PUBLIC_ID']
|
10
8
|
solidus_bolt_configuration.api_key = ENV['BOLT_API_KEY']
|
11
9
|
solidus_bolt_configuration.signing_secret = ENV['BOLT_SIGNING_SECRET']
|
12
|
-
solidus_bolt_configuration.publishable_key = ENV['BOLT_PUBLISHABLE_KEY']
|
10
|
+
solidus_bolt_configuration.publishable_key = ENV['BOLT_PUBLISHABLE_KEY'] || 'abc.def.ghi'
|
13
11
|
|
14
12
|
solidus_bolt_configuration.save!
|
15
13
|
|
data/spec/support/vcr.rb
CHANGED
@@ -19,8 +19,8 @@ VCR.configure do |config|
|
|
19
19
|
end
|
20
20
|
|
21
21
|
config.filter_sensitive_data('<PUBLISHABLE_KEY>') { SolidusBolt::BoltConfiguration.fetch.publishable_key }
|
22
|
+
config.filter_sensitive_data('<DIVISION_PUBLIC_ID>') { SolidusBolt::BoltConfiguration.fetch.division_public_id }
|
22
23
|
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
24
|
|
25
25
|
# Let's you set default VCR record mode with VCR_RECORDE_MODE=all for re-recording
|
26
26
|
# episodes. :once is VCR default
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_bolt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- piyushswain
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-07-
|
13
|
+
date: 2022-07-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: coffee-rails
|
@@ -96,20 +96,6 @@ dependencies:
|
|
96
96
|
- - ">="
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
|
-
- !ruby/object:Gem::Dependency
|
100
|
-
name: solidus_auth_devise
|
101
|
-
requirement: !ruby/object:Gem::Requirement
|
102
|
-
requirements:
|
103
|
-
- - ">="
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
version: '0'
|
106
|
-
type: :runtime
|
107
|
-
prerelease: false
|
108
|
-
version_requirements: !ruby/object:Gem::Requirement
|
109
|
-
requirements:
|
110
|
-
- - ">="
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
version: '0'
|
113
99
|
- !ruby/object:Gem::Dependency
|
114
100
|
name: solidus_core
|
115
101
|
requirement: !ruby/object:Gem::Requirement
|
@@ -256,6 +242,7 @@ files:
|
|
256
242
|
- app/controllers/solidus_bolt/accounts_controller.rb
|
257
243
|
- app/controllers/solidus_bolt/base_controller.rb
|
258
244
|
- app/controllers/solidus_bolt/webhooks_controller.rb
|
245
|
+
- app/controllers/spree/admin/bolt_callback_urls_controller.rb
|
259
246
|
- app/controllers/spree/admin/bolt_webhooks_controller.rb
|
260
247
|
- app/controllers/spree/admin/bolts_controller.rb
|
261
248
|
- app/decorators/controllers/solidus_bolt/spree_checkout_controller/add_addresses_to_bolt.rb
|
@@ -279,6 +266,8 @@ files:
|
|
279
266
|
- app/services/solidus_bolt/accounts/detail_service.rb
|
280
267
|
- app/services/solidus_bolt/accounts/detect_account_service.rb
|
281
268
|
- app/services/solidus_bolt/base_service.rb
|
269
|
+
- app/services/solidus_bolt/merchant_configuration/get_callback_urls_service.rb
|
270
|
+
- app/services/solidus_bolt/merchant_configuration/set_callback_urls_service.rb
|
282
271
|
- app/services/solidus_bolt/oauth/token_service.rb
|
283
272
|
- app/services/solidus_bolt/payments/capture_sync_service.rb
|
284
273
|
- app/services/solidus_bolt/payments/credit_sync_service.rb
|
@@ -294,6 +283,7 @@ files:
|
|
294
283
|
- app/services/solidus_bolt/users/sync_addresses_service.rb
|
295
284
|
- app/services/solidus_bolt/users/sync_payment_sources_service.rb
|
296
285
|
- app/services/solidus_bolt/webhooks/create_service.rb
|
286
|
+
- app/views/spree/admin/bolt_callback_urls/new.html.erb
|
297
287
|
- app/views/spree/admin/bolt_webhooks/new.html.erb
|
298
288
|
- app/views/spree/admin/bolts/_configuration.html.erb
|
299
289
|
- app/views/spree/admin/bolts/_form.html.erb
|
@@ -330,6 +320,7 @@ files:
|
|
330
320
|
- db/migrate/20220530102107_rename_bolt_configuration_merchant_id_to_division_public_id.rb
|
331
321
|
- db/migrate/20220531075527_update_bolt_configuration_environment_column_restrictions.rb
|
332
322
|
- db/migrate/20220629131950_remove_bearer_token_on_solidus_bolt_bolt_configuration.rb
|
323
|
+
- db/migrate/20220725133701_remove_merchant_id_and_division_public_id_on_bolt_configuration.rb
|
333
324
|
- db/seeds.rb
|
334
325
|
- lib/generators/solidus_bolt/install/install_generator.rb
|
335
326
|
- lib/generators/solidus_bolt/install/templates/initializer.rb
|
@@ -354,6 +345,8 @@ files:
|
|
354
345
|
- spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_DetailService/_call/with_wrong_access_token/gives_an_error.yml
|
355
346
|
- spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_DetectAccountService/_call/receives_the_correct_response.yml
|
356
347
|
- spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_DetectAccountService/_call/returns_status_200.yml
|
348
|
+
- spec/fixtures/vcr_cassettes/SolidusBolt_MerchantConfiguration_GetCallbackUrlsService/_call/receives_the_correct_response.yml
|
349
|
+
- spec/fixtures/vcr_cassettes/SolidusBolt_MerchantConfiguration_SetCallbackUrlsService/_call/receives_the_correct_response.yml
|
357
350
|
- spec/fixtures/vcr_cassettes/SolidusBolt_Oauth_TokenService/_call/makes_the_API_call.yml
|
358
351
|
- spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_AuthorizeService/when_repeat_payment/_call/makes_the_API_call.yml
|
359
352
|
- spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_AuthorizeService/with_auto_capture/_call/makes_the_API_call.yml
|
@@ -385,6 +378,8 @@ files:
|
|
385
378
|
- spec/services/solidus_bolt/accounts/detail_service_spec.rb
|
386
379
|
- spec/services/solidus_bolt/accounts/detect_account_service_spec.rb
|
387
380
|
- spec/services/solidus_bolt/base_service_spec.rb
|
381
|
+
- spec/services/solidus_bolt/merchant_configuration/get_callback_urls_service_spec.rb
|
382
|
+
- spec/services/solidus_bolt/merchant_configuration/set_callback_urls_service_spec.rb
|
388
383
|
- spec/services/solidus_bolt/oauth/token_service_spec.rb
|
389
384
|
- spec/services/solidus_bolt/payments/capture_sync_service_spec.rb
|
390
385
|
- spec/services/solidus_bolt/payments/credit_sync_service_spec.rb
|
@@ -448,6 +443,8 @@ test_files:
|
|
448
443
|
- spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_DetailService/_call/with_wrong_access_token/gives_an_error.yml
|
449
444
|
- spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_DetectAccountService/_call/receives_the_correct_response.yml
|
450
445
|
- spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_DetectAccountService/_call/returns_status_200.yml
|
446
|
+
- spec/fixtures/vcr_cassettes/SolidusBolt_MerchantConfiguration_GetCallbackUrlsService/_call/receives_the_correct_response.yml
|
447
|
+
- spec/fixtures/vcr_cassettes/SolidusBolt_MerchantConfiguration_SetCallbackUrlsService/_call/receives_the_correct_response.yml
|
451
448
|
- spec/fixtures/vcr_cassettes/SolidusBolt_Oauth_TokenService/_call/makes_the_API_call.yml
|
452
449
|
- spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_AuthorizeService/when_repeat_payment/_call/makes_the_API_call.yml
|
453
450
|
- spec/fixtures/vcr_cassettes/SolidusBolt_Transactions_AuthorizeService/with_auto_capture/_call/makes_the_API_call.yml
|
@@ -479,6 +476,8 @@ test_files:
|
|
479
476
|
- spec/services/solidus_bolt/accounts/detail_service_spec.rb
|
480
477
|
- spec/services/solidus_bolt/accounts/detect_account_service_spec.rb
|
481
478
|
- spec/services/solidus_bolt/base_service_spec.rb
|
479
|
+
- spec/services/solidus_bolt/merchant_configuration/get_callback_urls_service_spec.rb
|
480
|
+
- spec/services/solidus_bolt/merchant_configuration/set_callback_urls_service_spec.rb
|
482
481
|
- spec/services/solidus_bolt/oauth/token_service_spec.rb
|
483
482
|
- spec/services/solidus_bolt/payments/capture_sync_service_spec.rb
|
484
483
|
- spec/services/solidus_bolt/payments/credit_sync_service_spec.rb
|