solidus_bactracs 3.1.2 → 3.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +95 -17
- data/app/jobs/solidus_bactracs/api/schedule_shipment_syncs_job.rb +7 -6
- data/lib/solidus_bactracs/api/request_runner.rb +8 -7
- data/lib/solidus_bactracs/console_harness.rb +53 -0
- data/lib/solidus_bactracs/version.rb +1 -1
- metadata +3 -3
- data/lib/solidus_backtracs/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7cb6d0004776ee5cac5518a2198a429c36247c0ca0b86e80f49d33e540831f0
|
4
|
+
data.tar.gz: b40f84c4a7d9a9922dd1d7ce3137ae34f452a760cd33c6884cf9017955fd75c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d38e0f27a7d2bc598e9f97ed3eb9b96385656bc7553bbd93be0de225075e7d94a2ddd842aa4d095293c37eda0270fa45ad6907f7b21f23d33326895cca696e41
|
7
|
+
data.tar.gz: 8ae9d6ebe1e723a006ffc8c99613c42de004096439d8dce5ea4ef0dabb36972f5d23a25d1118d82d419d08c0391e535b4435febdc7e601c231a111960b7de4be
|
data/README.md
CHANGED
@@ -31,6 +31,7 @@ used by the extension.
|
|
31
31
|
This extension can integrate with Bactracs via SOAP-based XML API integration. The gem currently makes SOAP 1.1 format calls, though the API support SOAP 1.2
|
32
32
|
|
33
33
|
|
34
|
+
|
34
35
|
### XML integration
|
35
36
|
|
36
37
|
The [XML integration](https://help.bactracs.com/hc/en-us/articles/360025856192-Custom-Store-Development-Guide)
|
@@ -42,29 +43,27 @@ created and updated shipments in your Solidus store.
|
|
42
43
|
⛔️ This section is outdated and inaccurate.
|
43
44
|
|
44
45
|
In order to enable the XML integration, make sure to configure the relevant section of the
|
45
|
-
configuration initializer, and configure your
|
46
|
+
configuration initializer, and configure your Bactracs/Andlor site accordingly:
|
46
47
|
|
47
48
|
- **Username**: the username defined in your configuration.
|
48
49
|
- **Password**: the password defined in your configuration.
|
49
50
|
- **URL to custom page**: `https://yourdomain.com/bactracs.xml`.
|
50
51
|
|
51
|
-
You can also configure your
|
52
|
+
You can also configure your Bactracs/Andlor site to pull the XML feed automatically on a recurring
|
52
53
|
basis, or manually by clicking the "Refresh stores" button.
|
53
54
|
|
54
|
-
There are five shipment states for an order (= shipment) in
|
55
|
-
necessarily align with Solidus, but you can configure
|
55
|
+
There are five shipment states for an order (= shipment) in Bactracs. These states do not
|
56
|
+
necessarily align with Solidus, but you can configure Bactracs to create a mapping for your
|
56
57
|
specific needs. Here's the recommended mapping:
|
57
58
|
|
58
|
-
Bactracs
|
59
|
+
Bactracs RMA Type | Bactracs status | Solidus status
|
59
60
|
------------------------|--------------------|---------------
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
Type 1 | `unpaid` | `pending`
|
62
|
+
Type W | `paid` | `ready`
|
63
|
+
Type 3 | `shipped` | `shipped`
|
64
|
+
Type 4 | `cancelled` | `cancelled`
|
65
|
+
|
65
66
|
|
66
|
-
Once you've configured the XML integration in your app and ShipStation, there's nothing else you
|
67
|
-
need to do. ShipStation will
|
68
67
|
|
69
68
|
#### XML integration: Usage
|
70
69
|
|
@@ -74,23 +73,23 @@ There's nothing you need to do. Once properly configured, the integration just w
|
|
74
73
|
|
75
74
|
There are a few gotchas you need to be aware of:
|
76
75
|
|
77
|
-
- If you change the shipping method of an order in
|
76
|
+
- If you change the shipping method of an order in Bactracs, the change will not be reflected in
|
78
77
|
Solidus and the tracking link might not work properly.
|
79
78
|
- When `bactracs_capture_at_notification` is enabled, any errors during payment capture will
|
80
79
|
prevent the update of the shipment's tracking number.
|
81
80
|
|
82
81
|
### API integration
|
83
82
|
|
84
|
-
The [API integration](https://www.bactracs.com/docs/api/) works by calling the
|
83
|
+
The [API integration](https://www.bactracs.com/docs/api/) works by calling the Bactracs API
|
85
84
|
to sync all of your shipments continuously.
|
86
85
|
|
87
|
-
Because
|
86
|
+
Because Bactracs has very low rate limits (i.e., 40 reqs/minute at the time of writing), the
|
88
87
|
API integration does not send an API request for every single shipment update, as you would expect
|
89
88
|
from a traditional API integration.
|
90
89
|
|
91
90
|
Instead, a background job runs on a recurring basis and batches together all the shipments that need
|
92
|
-
to be created or updated in ShipStation. These shipments are then sent
|
93
|
-
to
|
91
|
+
to be created or updated in ShipStation. These shipments are then sent one at a time
|
92
|
+
to Bactracs [RMA creation endpoint](https://www.bactracs.com/docs/api/orders/create-update-multiple-orders/).
|
94
93
|
|
95
94
|
This allows us to work around Bactracs's rate limit and sync up to 4000 shipments/minute.
|
96
95
|
|
@@ -145,6 +144,85 @@ This is a problem that is faced by all recurring jobs. The solution is two-fold:
|
|
145
144
|
|
146
145
|
## Development
|
147
146
|
|
147
|
+
Because of the object abstractions in this gem, some find it difficult to test API responses vis the console. To ease such console work, a 'console harness' was developed that provides several affordances to exploratory development.
|
148
|
+
|
149
|
+
Create a new harness in the console via
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
h = SolidusBactracs::ConsoleHarness.new
|
153
|
+
```
|
154
|
+
|
155
|
+
#### `.try_one`
|
156
|
+
|
157
|
+
The easiest way to test the API, seeing both the output of the shipment when serialized as a XML SOAP request, and the result from the Bactracs API.
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
h.try_one
|
161
|
+
```
|
162
|
+
|
163
|
+
or try a few
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
h.try_batch(4)
|
167
|
+
```
|
168
|
+
|
169
|
+
maybe you have a shipment with particular issues, e.g. shipment number `H123456789`
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
h.shipment_number('H123456789')
|
173
|
+
|
174
|
+
h.try_one(h.shipment_number('H123456789'))
|
175
|
+
```
|
176
|
+
|
177
|
+
`.shipment_number` retries that shipment from the scope of available `h.shipments`.
|
178
|
+
|
179
|
+
#### `.refresh`
|
180
|
+
|
181
|
+
If that was successful, you may find your list of shipments has one or more shipments that are already synced
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
h.shipments.size # => 7
|
185
|
+
h.refresh
|
186
|
+
h.shipments.size # => 6
|
187
|
+
```
|
188
|
+
|
189
|
+
#### `.cursor`
|
190
|
+
|
191
|
+
You can set where in the recordset you want to continue trying from
|
192
|
+
|
193
|
+
```
|
194
|
+
h.cursor = 5
|
195
|
+
h.try_one
|
196
|
+
```
|
197
|
+
|
198
|
+
#### `.batch`
|
199
|
+
|
200
|
+
You can also change the default batch size
|
201
|
+
|
202
|
+
```
|
203
|
+
h.batch = 10
|
204
|
+
h.try_batch
|
205
|
+
# output from 10 runs, if not errors occur
|
206
|
+
```
|
207
|
+
|
208
|
+
#### deep objects
|
209
|
+
|
210
|
+
Several deeply-nested objects are exposed for convenience
|
211
|
+
|
212
|
+
* runner
|
213
|
+
* syncer
|
214
|
+
* sync (job)
|
215
|
+
|
216
|
+
```
|
217
|
+
h.serialize(shipment)
|
218
|
+
# see the output of serialization
|
219
|
+
|
220
|
+
h.runner.authenticated_call(shipment: h.shipments[0], serializer: h.syncer.client.shipment_serializer)
|
221
|
+
```
|
222
|
+
|
223
|
+
Remember that you can monkey patch code in the console, to test the improvement the harness or the gem itself.
|
224
|
+
|
225
|
+
|
148
226
|
### Testing the extension
|
149
227
|
|
150
228
|
|
@@ -21,16 +21,17 @@ module SolidusBactracs
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def query_shipments
|
24
|
-
shipments = SolidusBactracs::Shipment::PendingApiSyncQuery.apply(
|
25
|
-
|
24
|
+
shipments = SolidusBactracs::Shipment::PendingApiSyncQuery.apply(all_elegible_shipments)
|
25
|
+
end
|
26
|
+
|
27
|
+
def all_elegible_shipments(skus: SolidusBactracs.config.shippable_skus, state: :ready)
|
28
|
+
::Spree::Shipment
|
26
29
|
.joins(inventory_units: [:variant])
|
27
|
-
.where("spree_variants.sku" =>
|
28
|
-
.where("spree_shipments.state" =>
|
30
|
+
.where("spree_variants.sku" => skus)
|
31
|
+
.where("spree_shipments.state" => state)
|
29
32
|
.where(bactracs_synced_at: nil)
|
30
33
|
.distinct
|
31
|
-
)
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
36
|
-
|
@@ -13,18 +13,18 @@ module SolidusBactracs
|
|
13
13
|
@retries = SolidusBactracs.configuration.api_retries
|
14
14
|
end
|
15
15
|
|
16
|
-
def authenticated_call(
|
16
|
+
def authenticated_call(serializer: nil, shipment: nil, method: :post, path: '/webservices/rma/rmaservice.asmx', count: 0)
|
17
17
|
if count <= @retries
|
18
18
|
sguid = authenticate! rescue nil
|
19
19
|
|
20
20
|
if !sguid.presence
|
21
21
|
clear_cache
|
22
22
|
count += 1
|
23
|
-
self.authenticated_call(method:
|
23
|
+
self.authenticated_call(method: method, path: path, serializer: serializer, shipment: shipment, count: count)
|
24
24
|
else
|
25
25
|
params = serializer.call(shipment, sguid)
|
26
26
|
|
27
|
-
rma_response = call(method:
|
27
|
+
rma_response = call(method: method, path: path, params: params)
|
28
28
|
if create_rma_success?(rma_response)
|
29
29
|
Rails.logger.info({ event: 'success CreateRMA', rma: shipment.number, response: parse_rma_creation_response(rma_response, "Message")})
|
30
30
|
shipment_synced(shipment)
|
@@ -35,11 +35,12 @@ module SolidusBactracs
|
|
35
35
|
clear_cache
|
36
36
|
count += 1
|
37
37
|
Rails.logger.warn({ event: 'bactracs failed CreateRMA', error: parse_rma_creation_response(rma_response, "Message")})
|
38
|
-
self.authenticated_call(method:
|
38
|
+
self.authenticated_call(method: method, path: path, serializer: serializer, shipment: shipment, count: count)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
else
|
42
42
|
shipment_sync_failed(shipment)
|
43
|
+
return false
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
@@ -77,7 +78,7 @@ module SolidusBactracs
|
|
77
78
|
@response = nil
|
78
79
|
end
|
79
80
|
|
80
|
-
def authenticate!
|
81
|
+
def authenticate!
|
81
82
|
unless @username.present? || @password.present? || @api_base.present?
|
82
83
|
raise "Credentials not defined for Authentication"
|
83
84
|
end
|
@@ -110,13 +111,13 @@ module SolidusBactracs
|
|
110
111
|
|
111
112
|
def rma_exists?(response)
|
112
113
|
if parse_rma_creation_response(response, "Message").match(/rma .* already exists/)
|
113
|
-
Rails.logger.warn({ event: 'bactracs failed CreateRMA', error: parse_rma_creation_response(
|
114
|
+
Rails.logger.warn({ event: 'bactracs failed CreateRMA', error: parse_rma_creation_response(response, "Message")})
|
114
115
|
return true
|
115
116
|
end
|
116
117
|
end
|
117
118
|
|
118
119
|
def shipment_synced(shipment)
|
119
|
-
shipment.
|
120
|
+
shipment.update_attribute(:bactracs_synced_at, Time.zone.now)
|
120
121
|
|
121
122
|
::Spree::Event.fire(
|
122
123
|
'solidus_bactracs.api.sync_completed',
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module SolidusBactracs
|
2
|
+
class ConsoleHarness
|
3
|
+
attr_reader :runner, :syncer, :sync, :shipments, :shipments_elegible
|
4
|
+
|
5
|
+
attr_accessor :cursor, :batch
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@runner = SolidusBactracs::Api::RequestRunner.new
|
9
|
+
@syncer = SolidusBactracs::Api::BatchSyncer.from_config
|
10
|
+
@sync = SolidusBactracs::Api::ScheduleShipmentSyncsJob.new
|
11
|
+
@shipments = SolidusBactracs::Api::ScheduleShipmentSyncsJob.new.query_shipments
|
12
|
+
@shipments_elegible = SolidusBactracs::Api::ScheduleShipmentSyncsJob.new.all_elegible_shipments
|
13
|
+
@cursor = 0
|
14
|
+
@batch = 4
|
15
|
+
end
|
16
|
+
|
17
|
+
def refresh
|
18
|
+
@shipments = SolidusBactracs::Api::ScheduleShipmentSyncsJob.new.query_shipments
|
19
|
+
end
|
20
|
+
|
21
|
+
def shipment(id)
|
22
|
+
@shipments.find_by(id: id)
|
23
|
+
end
|
24
|
+
|
25
|
+
def shipment_number(ship_number)
|
26
|
+
@shipments.find_by(number: ship_number)
|
27
|
+
end
|
28
|
+
|
29
|
+
def serialize(shipment)
|
30
|
+
# SolidusShipstation::Api::ApplianceShipmentSerializer.new(shipment)
|
31
|
+
@syncer.client.shipment_serializer.call(shipment, @runner.authenticate!)
|
32
|
+
end
|
33
|
+
|
34
|
+
def try_one(a_shipment = nil)
|
35
|
+
puts "trying shipment #{(shipment = a_shipment || @shipments[@cursor]).id}"
|
36
|
+
# resp = @runner.call(:post, '/orders/createorders', [serialize(shipment)])
|
37
|
+
resp = @runner.authenticated_call(shipment: shipment, serializer: @syncer.client.shipment_serializer)
|
38
|
+
if resp
|
39
|
+
@cursor += 1
|
40
|
+
return resp
|
41
|
+
end
|
42
|
+
ensure
|
43
|
+
puts resp
|
44
|
+
end
|
45
|
+
|
46
|
+
def try_batch(batch_size=nil)
|
47
|
+
b = [batch_size.to_i, @batch].max
|
48
|
+
b.times do
|
49
|
+
break unless try_one
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_bactracs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zeryab Ali
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-09-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -171,7 +171,6 @@ files:
|
|
171
171
|
- lib/bactracs_service.rb
|
172
172
|
- lib/generators/solidus_bactracs/install/install_generator.rb
|
173
173
|
- lib/generators/solidus_bactracs/install/templates/initializer.rb
|
174
|
-
- lib/solidus_backtracs/version.rb
|
175
174
|
- lib/solidus_bactracs.rb
|
176
175
|
- lib/solidus_bactracs/api/batch_syncer.rb
|
177
176
|
- lib/solidus_bactracs/api/client.rb
|
@@ -181,6 +180,7 @@ files:
|
|
181
180
|
- lib/solidus_bactracs/api/shipment_serializer.rb
|
182
181
|
- lib/solidus_bactracs/api/threshold_verifier.rb
|
183
182
|
- lib/solidus_bactracs/configuration.rb
|
183
|
+
- lib/solidus_bactracs/console_harness.rb
|
184
184
|
- lib/solidus_bactracs/engine.rb
|
185
185
|
- lib/solidus_bactracs/errors.rb
|
186
186
|
- lib/solidus_bactracs/shipment_notice.rb
|