-
-
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 1f4c78d
Showing
5 changed files
with
406 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusBolt | ||
module ShipmentDecorator | ||
def bolt_items | ||
line_items.map do |line_item| | ||
{ | ||
reference: line_item.sku, | ||
name: line_item.name, | ||
description: line_item.description, | ||
total_amount: { | ||
amount: line_item.total, | ||
currency: line_item.currency, | ||
currency_symbol: currency_symbol | ||
}, | ||
unit_price: { | ||
amount: line_item.price, | ||
currency: line_item.currency, | ||
currency_symbol: currency_symbol | ||
}, | ||
tax_amount: { | ||
amount: line_item.additional_tax_total, | ||
currency: line_item.currency, | ||
currency_symbol: currency_symbol | ||
}, | ||
quantity: line_item.quantity, | ||
sku: line_item.sku | ||
} | ||
end | ||
end | ||
|
||
private | ||
|
||
def currency_symbol | ||
Monetize.from_string(order.total, order.currency).symbol | ||
end | ||
|
||
Spree::Shipment.prepend(self) | ||
end | ||
end |
47 changes: 47 additions & 0 deletions
47
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,47 @@ | ||
# 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 | ||
{ | ||
body: { | ||
transaction_reference: transaction_reference, | ||
tracking_number: shipment.tracking, | ||
carrier: shipment.shipping_method.name, | ||
items: shipment.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 |
37 changes: 37 additions & 0 deletions
37
spec/decorators/models/solidus_bolt/shipment_decorator_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,37 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe SolidusBolt::ShipmentDecorator do | ||
let(:payment_method) { create(:bolt_payment_method) } | ||
let(:payment_source) { create(:bolt_payment_source) } | ||
let(:payment) do | ||
create( | ||
:payment, | ||
state: 'completed', | ||
source_id: payment_source.id, | ||
source_type: SolidusBolt::PaymentSource, | ||
payment_method_id: payment_method.id, | ||
response_code: 'Doctor Strange' | ||
) | ||
end | ||
let(:order) { payment.order } | ||
|
||
describe '#bolt_items' do | ||
it 'returns an array' do | ||
create(:shipment, order: order, id: rand(1..10), tracking: 'MockBolt1678') | ||
order.shipments.reload | ||
shipment = order.shipments.last | ||
items = shipment.bolt_items | ||
|
||
expect(items).to be_a(Array) | ||
end | ||
|
||
it 'lists all line_items' do | ||
create(:shipment, order: order, id: rand(1..10), tracking: 'MockBolt1678') | ||
order.shipments.reload | ||
shipment = order.shipments.last | ||
items = shipment.bolt_items | ||
|
||
expect(items.count).to eq(order.line_items.count) | ||
end | ||
end | ||
end |
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.
Oops, something went wrong.