-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds the order tracking service for Bolt API. This service calls the bolt order_tracking endpoint with updated data for Order Tracking. Refer: https://help.bolt.com/api-bolt/#tag/Orders/operation/trackOrder
- Loading branch information
1 parent
28bf922
commit 15c6f65
Showing
5 changed files
with
373 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
app/services/solidus_bolt/orders/track_shipment_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusBolt | ||
module Orders | ||
class TrackShipmentService < SolidusBolt::BaseService | ||
attr_reader :transaction_reference, :shipment | ||
|
||
def initialize(transaction_reference:, shipment:) | ||
@transaction_reference = transaction_reference | ||
@shipment = shipment | ||
super | ||
end | ||
|
||
def call | ||
track_shipment | ||
end | ||
|
||
private | ||
|
||
def track_shipment | ||
options = build_options | ||
handle_result( | ||
HTTParty.post( | ||
"#{api_base_url}/#{api_version}/merchant/track_shipment", | ||
options | ||
) | ||
) | ||
end | ||
|
||
def build_options | ||
order = shipment.order | ||
{ | ||
body: { | ||
transaction_reference: transaction_reference, | ||
tracking_number: shipment.tracking, | ||
carrier: shipment.shipping_method.name, | ||
items: order.bolt_items, | ||
is_non_bolt_order: false | ||
}.to_json, | ||
headers: { | ||
'X-Nonce' => generate_nonce, | ||
'Content-Type' => 'application/json' | ||
}.merge(authentication_header) | ||
} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
243 changes: 243 additions & 0 deletions
243
...xtures/vcr_cassettes/SolidusBolt_Orders_TrackShipmentService/_call/makes_the_API_call.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
spec/services/solidus_bolt/orders/track_shipment_service_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe SolidusBolt::Orders::TrackShipmentService, :vcr, :bolt_configuration do | ||
subject(:api) do | ||
described_class.new(transaction_reference: reference, shipment: shipment) | ||
end | ||
|
||
let(:transaction) do | ||
SolidusBolt::Transactions::AuthorizeService.call( | ||
order: order, credit_card: credit_card_payload, create_bolt_account: false, payment_method: payment_method | ||
) | ||
end | ||
let(:credit_card_payload) do | ||
tokenize_credit_card(credit_card_number: '4111111111111004', cvv: '111').merge( | ||
expiration: (Time.current + 1.year).strftime('%Y-%m'), | ||
token_type: 'bolt' | ||
) | ||
end | ||
let(:order) { create(:order_with_line_items) } | ||
let(:reference) { transaction['transaction']['reference'] } | ||
let(:payment_method) { create(:bolt_payment_method, preference_source: 'bolt_config_credentials') } | ||
let(:shipping_method) { create(:shipping_method, name: 'MockBoltShipping') } | ||
let(:shipment) { order.shipments.last } | ||
|
||
describe '#call', vcr: true do | ||
before do | ||
shipment.select_shipping_method(shipping_method) | ||
shipment.update(tracking: "MockBolt#{rand(1000..9999)}") | ||
end | ||
|
||
it 'makes the API call' do | ||
response = api.call | ||
|
||
expect(response).to be_nil | ||
end | ||
end | ||
end |