solidus_bolt 0.1.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 742875df47de9e63b63e2abb6d986c8e6fda7b1f5298fc49be6e04d06cd5a050
4
- data.tar.gz: 8e3f173daca61cb9b03b63ee26d70e06ce0a5462c3803fc9c65150fa1da13cc7
3
+ metadata.gz: e25dd3c40e487372056178b18ffae03f5cddbd5b56756cf32874a7e0f761a5ac
4
+ data.tar.gz: 74bfbc7db9a0b6b9b47f501cbd67d6c141a9164549266eb99114a3de5a4de840
5
5
  SHA512:
6
- metadata.gz: a0f3cea501cbc8086af33a9d2871593d4e30e6495807ad2fad05f029711086ec8f2b2d3b6e44149fa838403536129d5a5038347a23a87ff99627a80e3274cd87
7
- data.tar.gz: 90901739f3d6cc165309ef2f0528f6f4897ac8598c8434e01322bbae208a5cd58f1154b6a2bddebd57e5b75808010961f3a710eac83f267df38400d6dcbbb248
6
+ metadata.gz: 6df41aae33da5dc6d3c070507fe0c7a19410ece8ffabfef114f8dca23a387b5f3cdadb0317ef1121051d95807b08717782db0e802290668e277f7ae492f4464e
7
+ data.tar.gz: 840b8836eaf726ab402b807bed737d536c14adaac70d24d0bba4a030afd58d8677d715ae54ddcd8a2167f3ab4a829a39dcf49e7aefb028064bfd8f539722c49a
data/README.md CHANGED
@@ -27,8 +27,6 @@ Many of the API calls handled by this gem use the variables set in Bolt Configur
27
27
 
28
28
  ```
29
29
  BOLT_ENVIRONMENT
30
- BOLT_MERCHANT_PUBLIC_ID
31
- BOLT_DIVISION_PUBLIC_ID
32
30
  BOLT_API_KEY
33
31
  BOLT_SIGNING_SECRET
34
32
  BOLT_PUBLISHABLE_KEY
@@ -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
- redirectToNextStep(frontend)
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')
@@ -75,6 +89,8 @@ document.addEventListener("DOMContentLoaded", async function () {
75
89
  if(boltContainer.dataset["boltUserSignedIn"] != "true") {
76
90
  accountCheckbox = boltEmbedded.create("account_checkbox");
77
91
  accountCheckbox.on("change", checked => createBoltAccount = checked);
92
+ } else {
93
+ createBoltAccount = true;
78
94
  }
79
95
  cardButton.addEventListener("click", () => {
80
96
  const submitButton = document.getElementById("bolt-submit-button")
@@ -30,8 +30,6 @@ module Spree
30
30
  .require(:solidus_bolt_bolt_configuration)
31
31
  .permit(
32
32
  :environment,
33
- :merchant_public_id,
34
- :division_public_id,
35
33
  :api_key,
36
34
  :signing_secret,
37
35
  :publishable_key
@@ -5,8 +5,10 @@ module SolidusBolt
5
5
  def bolt_cart
6
6
  {
7
7
  total_amount: display_total.cents,
8
+ tax_amount: display_tax_total.cents,
8
9
  order_reference: number,
9
10
  currency: currency,
11
+ shipments: bolt_shipments_payload,
10
12
  items: line_items.map do |line_item|
11
13
  {
12
14
  sku: line_item.sku,
@@ -35,6 +37,10 @@ module SolidusBolt
35
37
 
36
38
  private
37
39
 
40
+ def bolt_shipments_payload
41
+ shipments.map(&:bolt_shipment)
42
+ end
43
+
38
44
  def cents(float)
39
45
  (float * 100).to_i
40
46
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusBolt
4
+ module ShipmentDecorator
5
+ def bolt_shipment
6
+ {
7
+ shipping_address: order.ship_address.bolt_address(order.email),
8
+ reference: number,
9
+ cost: display_total.cents
10
+ }
11
+ end
12
+
13
+ Spree::Shipment.prepend(self)
14
+ end
15
+ 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
@@ -26,6 +26,12 @@ module SolidusBolt
26
26
  bolt_config.environment_url
27
27
  end
28
28
 
29
+ def try_void(payment)
30
+ return false unless payment.source.can_void?(payment)
31
+
32
+ gateway.void(payment.response_code, originator: payment)
33
+ end
34
+
29
35
  private
30
36
 
31
37
  def bolt_config
@@ -2,7 +2,7 @@
2
2
  <table class="index">
3
3
  <thead>
4
4
  <tr>
5
- <th><%= SolidusBolt::BoltConfiguration.human_attribute_name(:merchant_public_id) %></th>
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.merchant_public_id %></td>
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 />
@@ -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
@@ -2,9 +2,7 @@
2
2
 
3
3
  solidus_bolt_configuration = SolidusBolt::BoltConfiguration.fetch
4
4
 
5
- solidus_bolt_configuration.environment = ENV['BOLT_ENVIRONMENT']
6
- solidus_bolt_configuration.merchant_public_id = ENV['BOLT_MERCHANT_PUBLIC_ID']
7
- solidus_bolt_configuration.division_public_id = ENV['BOLT_DIVISION_PUBLIC_ID']
5
+ solidus_bolt_configuration.environment = ENV.fetch('BOLT_ENVIRONMENT', 'sandbox')
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolidusBolt
4
- VERSION = '0.1.0'
4
+ VERSION = '0.4.0'
5
5
  end
data/solidus_bolt.gemspec CHANGED
@@ -33,8 +33,7 @@ Gem::Specification.new do |spec|
33
33
  spec.add_dependency 'httparty'
34
34
  spec.add_dependency 'multi_json'
35
35
  spec.add_dependency 'omniauth-bolt'
36
- spec.add_dependency 'rails', ['>0.a', '< 7.a']
37
- spec.add_dependency 'solidus_auth_devise'
36
+ spec.add_dependency 'rails'
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,8 +7,10 @@ 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',
13
+ shipments: array_including(hash_including(:reference)),
12
14
  items: [{
13
15
  sku: order.line_items.first.sku,
14
16
  name: order.line_items.first.name,
@@ -16,7 +18,8 @@ RSpec.describe SolidusBolt::OrderDecorator do
16
18
  quantity: 1
17
19
  }]
18
20
  }
19
- expect(order.bolt_cart).to eq(result)
21
+
22
+ expect(order.bolt_cart).to match hash_including(result)
20
23
  end
21
24
  end
22
25
 
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe SolidusBolt::ShipmentDecorator do
4
+ describe '#bolt_shipment' do
5
+ subject(:bolt_shipment) { shipment.bolt_shipment }
6
+
7
+ let(:shipment) { create(:shipment, number: 'S000000001') }
8
+ let(:ship_address) { shipment.order.ship_address }
9
+
10
+ it 'is expected' do
11
+ expect(bolt_shipment).to match hash_including(
12
+ shipping_address: hash_including(postal_code: ship_address.zipcode, country_code: ship_address.country_iso),
13
+ reference: 'S000000001',
14
+ cost: 10_000
15
+ )
16
+ end
17
+ end
18
+ end
@@ -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,20 @@ 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
+ end
66
+
67
+ describe '#division_public_id' do
68
+ it 'returns the division_public_id' do
69
+ bolt_configuration = create(:bolt_configuration, publishable_key: 'abc.def.ghi')
70
+ expect(bolt_configuration.division_public_id).to eq('def')
71
+ end
72
+ end
73
+
64
74
  describe '#environment_url' do
65
75
  context 'when production envornment' do
66
76
  let(:config) { create(:bolt_configuration, environment: 'production') }
@@ -18,4 +18,29 @@ RSpec.describe SolidusBolt::PaymentMethod, type: :model do
18
18
  expect(described_class.new.partial_name).to eq 'bolt'
19
19
  end
20
20
  end
21
+
22
+ describe '#try_void' do
23
+ let(:payment) { create(:payment) }
24
+
25
+ context 'when the payment can be voided' do
26
+ subject(:try_void) { described_instance.try_void(payment) }
27
+
28
+ let(:described_instance) { described_class.new }
29
+ let(:response) { ActiveMerchant::Billing::Response.new(true, 'Transaction voided', {}, authorization: '123') }
30
+
31
+ before do
32
+ allow(payment.source).to receive(:can_void?).and_return(true)
33
+ allow(described_instance.gateway).to receive(:void).and_return(response)
34
+ end
35
+
36
+ it 'calls void on the gateway' do
37
+ try_void
38
+
39
+ expect(described_instance.gateway).to have_received(:void).with(
40
+ payment.response_code,
41
+ originator: payment
42
+ )
43
+ end
44
+ end
45
+ end
21
46
  end
@@ -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'
@@ -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(:create) { described_class.call(url: 'https://solidus-test.com/webhook', event: event) }
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(create).to match hash_including('webhook_id')
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(create).to match hash_including('webhook_id')
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{ create }.to raise_error SolidusBolt::ServerError
31
+ expect{ create_service }.to raise_error SolidusBolt::ServerError
30
32
  end
31
33
  end
32
34
  end
@@ -5,8 +5,6 @@ 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
10
  solidus_bolt_configuration.publishable_key = ENV['BOLT_PUBLISHABLE_KEY']
data/spec/support/vcr.rb CHANGED
@@ -20,7 +20,6 @@ VCR.configure do |config|
20
20
 
21
21
  config.filter_sensitive_data('<PUBLISHABLE_KEY>') { SolidusBolt::BoltConfiguration.fetch.publishable_key }
22
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
23
 
25
24
  # Let's you set default VCR record mode with VCR_RECORDE_MODE=all for re-recording
26
25
  # 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.1.0
4
+ version: 0.4.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-06-30 00:00:00.000000000 Z
13
+ date: 2022-07-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: coffee-rails
@@ -84,26 +84,6 @@ dependencies:
84
84
  version: '0'
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: rails
87
- requirement: !ruby/object:Gem::Requirement
88
- requirements:
89
- - - ">"
90
- - !ruby/object:Gem::Version
91
- version: 0.a
92
- - - "<"
93
- - !ruby/object:Gem::Version
94
- version: 7.a
95
- type: :runtime
96
- prerelease: false
97
- version_requirements: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - ">"
100
- - !ruby/object:Gem::Version
101
- version: 0.a
102
- - - "<"
103
- - !ruby/object:Gem::Version
104
- version: 7.a
105
- - !ruby/object:Gem::Dependency
106
- name: solidus_auth_devise
107
87
  requirement: !ruby/object:Gem::Requirement
108
88
  requirements:
109
89
  - - ">="
@@ -271,6 +251,7 @@ files:
271
251
  - app/decorators/models/solidus_bolt/log_entry_decorator.rb
272
252
  - app/decorators/models/solidus_bolt/order_decorator.rb
273
253
  - app/decorators/models/solidus_bolt/payment_decorator.rb
254
+ - app/decorators/models/solidus_bolt/shipment_decorator.rb
274
255
  - app/decorators/omniauth/strategies/bolt_decorator.rb
275
256
  - app/jobs/solidus_bolt/add_address_job.rb
276
257
  - app/models/solidus_bolt.rb
@@ -335,6 +316,7 @@ files:
335
316
  - db/migrate/20220530102107_rename_bolt_configuration_merchant_id_to_division_public_id.rb
336
317
  - db/migrate/20220531075527_update_bolt_configuration_environment_column_restrictions.rb
337
318
  - db/migrate/20220629131950_remove_bearer_token_on_solidus_bolt_bolt_configuration.rb
319
+ - db/migrate/20220725133701_remove_merchant_id_and_division_public_id_on_bolt_configuration.rb
338
320
  - db/seeds.rb
339
321
  - lib/generators/solidus_bolt/install/install_generator.rb
340
322
  - lib/generators/solidus_bolt/install/templates/initializer.rb
@@ -349,6 +331,7 @@ files:
349
331
  - spec/decorators/models/solidus_bolt/address_decorator_spec.rb
350
332
  - spec/decorators/models/solidus_bolt/order_decorator_spec.rb
351
333
  - spec/decorators/models/solidus_bolt/payment_decorator_spec.rb
334
+ - spec/decorators/models/solidus_bolt/shipment_decorator_spec.rb
352
335
  - spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_AddAddressService/_call/with_correct_access_token/receives_a_successful_response.yml
353
336
  - spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_AddAddressService/_call/with_existing_address/skips_the_add_address_call.yml
354
337
  - spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_AddAddressService/_call/with_wrong_access_token/gives_an_error.yml
@@ -442,6 +425,7 @@ test_files:
442
425
  - spec/decorators/models/solidus_bolt/address_decorator_spec.rb
443
426
  - spec/decorators/models/solidus_bolt/order_decorator_spec.rb
444
427
  - spec/decorators/models/solidus_bolt/payment_decorator_spec.rb
428
+ - spec/decorators/models/solidus_bolt/shipment_decorator_spec.rb
445
429
  - spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_AddAddressService/_call/with_correct_access_token/receives_a_successful_response.yml
446
430
  - spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_AddAddressService/_call/with_existing_address/skips_the_add_address_call.yml
447
431
  - spec/fixtures/vcr_cassettes/SolidusBolt_Accounts_AddAddressService/_call/with_wrong_access_token/gives_an_error.yml