solidus_foudra 0.1.0
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 +7 -0
- data/.gitignore +24 -0
- data/.rspec +2 -0
- data/.rubocop.yml +12 -0
- data/Gemfile +25 -0
- data/LICENSE +201 -0
- data/README.md +241 -0
- data/Rakefile +7 -0
- data/bin/console +17 -0
- data/bin/rails +7 -0
- data/bin/rails-engine +13 -0
- data/bin/rails-sandbox +16 -0
- data/bin/rake +7 -0
- data/bin/sandbox +85 -0
- data/bin/setup +8 -0
- data/config/locales/en.yml +5 -0
- data/lib/solidus_foudra/client.rb +234 -0
- data/lib/solidus_foudra/configuration.rb +87 -0
- data/lib/solidus_foudra/engine.rb +23 -0
- data/lib/solidus_foudra/markdown.rb +83 -0
- data/lib/solidus_foudra/redact.rb +18 -0
- data/lib/solidus_foudra/testing_support/factories.rb +4 -0
- data/lib/solidus_foudra/version.rb +8 -0
- data/lib/solidus_foudra/webhook_signature.rb +48 -0
- data/lib/solidus_foudra.rb +45 -0
- data/solidus_foudra.gemspec +40 -0
- metadata +131 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 6f2704edbaf930feef8685b15230447fc9d363db7f6c8e5299133fe113f92551
|
|
4
|
+
data.tar.gz: 643c18b9fe0b3473d80638998832334fe8c29fde61f759073af88909017eec5e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 2d721dffa038fb58660cfc61da2e25cc1f17f9c312ebcb68f3fc789dcf5be91c9416f2633847113e8fc0bd3463504f686c0f904adb7253b699e0dc110c2982fe
|
|
7
|
+
data.tar.gz: 0b07959ea4cd4c4d09ab1a511704775a50f64bd69c21863512cdc443b917fad04d60b6aabed2a2aaacbc7dbeee729ee8d0a531f604d638646a73e1ba33cc4e1c
|
data/.gitignore
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
\#*
|
|
3
|
+
*~
|
|
4
|
+
.#*
|
|
5
|
+
.DS_Store
|
|
6
|
+
.idea
|
|
7
|
+
.project
|
|
8
|
+
.sass-cache
|
|
9
|
+
coverage
|
|
10
|
+
Gemfile.lock
|
|
11
|
+
Gemfile-local
|
|
12
|
+
tmp
|
|
13
|
+
nbproject
|
|
14
|
+
pkg
|
|
15
|
+
*.swp
|
|
16
|
+
spec/dummy
|
|
17
|
+
spec/examples.txt
|
|
18
|
+
/sandbox
|
|
19
|
+
.rvmrc
|
|
20
|
+
.ruby-version
|
|
21
|
+
.ruby-gemset
|
|
22
|
+
vendor/bundle
|
|
23
|
+
.bundle
|
|
24
|
+
log/*.log
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require:
|
|
2
|
+
- solidus_dev_support/rubocop
|
|
3
|
+
|
|
4
|
+
AllCops:
|
|
5
|
+
NewCops: disable
|
|
6
|
+
SuggestExtensions: false
|
|
7
|
+
# Shorthand hash syntax (`customer_id:`) and anonymous block args need 3.1.
|
|
8
|
+
TargetRubyVersion: 3.1
|
|
9
|
+
Exclude:
|
|
10
|
+
- spec/dummy/**/*
|
|
11
|
+
- vendor/**/*
|
|
12
|
+
- bin/**/*
|
data/Gemfile
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
# The versions Kalopa's shop runs. The extension itself asks only for
|
|
6
|
+
# solidus_core ~> 4.6 (the gemspec); this is the test app's Solidus.
|
|
7
|
+
gem "solidus", ENV.fetch("SOLIDUS_VERSION", "~> 4.6.2")
|
|
8
|
+
|
|
9
|
+
rails_version = ENV.fetch("RAILS_VERSION", "7.1")
|
|
10
|
+
gem "rails", "~> #{rails_version}.0"
|
|
11
|
+
|
|
12
|
+
case ENV.fetch("DB", nil)
|
|
13
|
+
when "postgresql"
|
|
14
|
+
gem "pg"
|
|
15
|
+
else
|
|
16
|
+
gem "sqlite3", (rails_version < "7.2") ? "~> 1.4" : "~> 2.0"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# json 3 dropped the quirks_mode option Rails 7.1's ActiveSupport passes.
|
|
20
|
+
gem "json", "< 3"
|
|
21
|
+
|
|
22
|
+
gemspec
|
|
23
|
+
|
|
24
|
+
# A local Gemfile for things only one developer wants, e.g. pry-byebug.
|
|
25
|
+
send(:eval_gemfile, "Gemfile-local") if File.exist? "Gemfile-local"
|
data/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
# Foudra MRP integration with Solidus
|
|
2
|
+
|
|
3
|
+
Connects a [Solidus](https://solidus.io) shop to [Foudra MRP](https://foudra.com).
|
|
4
|
+
The shop sells; Foudra makes, stocks and ships.
|
|
5
|
+
|
|
6
|
+
| Direction | What | How |
|
|
7
|
+
|---|---|---|
|
|
8
|
+
| Solidus → Foudra | A completed order becomes a Foudra **sales order** on the shop's channel, with its **customer** (found by the shop's user id or email, or created). Cancelling the order cancels it in Foudra. | `order_finalized` / `order_canceled` on `Spree::Bus` → ActiveJob |
|
|
9
|
+
| Foudra → Solidus | **Stock**: each variant's count on hand is Foudra's *available* quantity for its part. | `stock.changed`, `sales_order.created`/`.cancelled` webhooks, nightly pass |
|
|
10
|
+
| Foudra → Solidus | **Products and prices**: each part listed on the channel is a product; its price is the listing's; unlisted means discontinued. | `listing.changed` webhook, nightly pass, `rake solidus_foudra:import` |
|
|
11
|
+
| Foudra → Solidus | **Shipping**: a Foudra shipment that has left ships the Solidus units, with its tracking number, so Solidus emails the customer as usual. | `shipment.shipped` / `shipment.updated` webhooks, nightly pass |
|
|
12
|
+
|
|
13
|
+
## Who owns what
|
|
14
|
+
|
|
15
|
+
Foudra's rule: **Foudra owns the physical facts, never money.** So:
|
|
16
|
+
|
|
17
|
+
- **Foudra owns** stock, what is listed for sale, and shipping. The shop shows
|
|
18
|
+
Foudra's available stock, never its own idea of it, and ships what Foudra
|
|
19
|
+
says left. Don't ship in the Solidus admin: Foudra wouldn't know.
|
|
20
|
+
- **Solidus owns** the storefront, the checkout, payments, tax, promotions and
|
|
21
|
+
customers' accounts. Prices on a Foudra sales order are information (what the
|
|
22
|
+
customer was charged per unit, before order-level promotions), never booked.
|
|
23
|
+
- **Prices** flow from Foudra's listing to the shop because that is where they
|
|
24
|
+
are kept, but the shop still charges.
|
|
25
|
+
- **Content** (name, description, image) is Foudra's when a product is created,
|
|
26
|
+
and the shop's afterwards, unless `sync_content = true`.
|
|
27
|
+
- **Nothing is deleted.** Unlisting a part in Foudra discontinues the product;
|
|
28
|
+
cancelling an order in Solidus cancels what hasn't shipped in Foudra.
|
|
29
|
+
|
|
30
|
+
## Installing
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
# Gemfile
|
|
34
|
+
gem "solidus_foudra"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
bundle install
|
|
39
|
+
bin/rails generate solidus_foudra:install # initializer, migrations, route
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
The generator:
|
|
43
|
+
|
|
44
|
+
- writes `config/initializers/solidus_foudra.rb`;
|
|
45
|
+
- adds `mount SolidusFoudra::Engine, at: "/foudra"` to `config/routes.rb`, so
|
|
46
|
+
the webhook is `POST https://<your shop>/foudra/webhooks`;
|
|
47
|
+
- copies two migrations: `solidus_foudra_webhook_events` (de-duplication) and
|
|
48
|
+
`spree_variants.foudra_part_number`, `spree_orders.foudra_customer_id`,
|
|
49
|
+
`spree_orders.foudra_sales_order_id`.
|
|
50
|
+
|
|
51
|
+
Jobs run on your ActiveJob adapter (Sidekiq, Resque, …). Run the nightly pass
|
|
52
|
+
from cron (or a Kubernetes CronJob): `bin/rails solidus_foudra:sync`, or
|
|
53
|
+
schedule `SolidusFoudra::FullSyncJob` with your job scheduler.
|
|
54
|
+
|
|
55
|
+
## Configuration
|
|
56
|
+
|
|
57
|
+
```ruby
|
|
58
|
+
SolidusFoudra.configure do |config|
|
|
59
|
+
config.base_url = "https://acme.foudra.com" # the company's own subdomain
|
|
60
|
+
config.api_key = ENV["FOUDRA_API_KEY"] # never commit it
|
|
61
|
+
config.webhook_secret = ENV["FOUDRA_WEBHOOK_SECRET"] # never commit it
|
|
62
|
+
config.channel = "SHOP" # the Foudra channel that is this shop
|
|
63
|
+
config.stock_location = nil # a stock location's name or id; nil = the default
|
|
64
|
+
config.part_number_column = :foudra_part_number # the spree_variants column with the part number
|
|
65
|
+
config.sync_content = false # true: Foudra's name/description/image always win
|
|
66
|
+
config.send_orders_since = nil # nightly re-send of missed orders; set to go-live time
|
|
67
|
+
config.wanted_after_days = 0 # sales order wanted date = order date + this
|
|
68
|
+
config.queue = :default # ActiveJob queue
|
|
69
|
+
config.markdown_renderer = nil # optional ->(markdown) { html }
|
|
70
|
+
end
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Nothing is sent or synced until `base_url`, `api_key` and `channel` are set.
|
|
74
|
+
The key and secret come from the environment or `Rails.application.credentials`
|
|
75
|
+
(`foudra.api_key`, `foudra.webhook_secret`).
|
|
76
|
+
|
|
77
|
+
**The part number** joins a variant to a Foudra part. It is Foudra's canonical
|
|
78
|
+
dashed number (`902-40169-00`), kept in `part_number_column`, and need not be
|
|
79
|
+
the SKU. A variant without one is the shop's own business: its lines are left
|
|
80
|
+
off Foudra's sales orders and its stock isn't touched.
|
|
81
|
+
|
|
82
|
+
## What Foudra must have
|
|
83
|
+
|
|
84
|
+
1. **A channel** for the shop (Foudra → Sales channels), its code in `config.channel`.
|
|
85
|
+
2. **An API key** (Foudra → API keys) with the **write** scope, made by a user
|
|
86
|
+
who is at least a **planner** (customers and sales orders need it).
|
|
87
|
+
3. **A webhook** (Foudra → Webhooks, admins):
|
|
88
|
+
- URL: `https://<your shop>/foudra/webhooks`
|
|
89
|
+
- Events: `stock.changed`, `sales_order.created`, `sales_order.cancelled`,
|
|
90
|
+
`shipment.shipped`, `shipment.updated`, `listing.changed`.
|
|
91
|
+
- Copy the signing secret shown once into `webhook_secret`.
|
|
92
|
+
- **Send test** should answer 204 (a `ping`; nothing is done with it).
|
|
93
|
+
4. **Listings**: each part the shop sells, listed on the channel with a price
|
|
94
|
+
(the part's Listings page, or `PUT /api/channels/{code}/listings/{part}`).
|
|
95
|
+
|
|
96
|
+
Check it all with `bin/rails solidus_foudra:status`.
|
|
97
|
+
|
|
98
|
+
## How it works
|
|
99
|
+
|
|
100
|
+
### Orders in
|
|
101
|
+
|
|
102
|
+
`order_finalized` queues `SendOrderJob`, which:
|
|
103
|
+
|
|
104
|
+
1. waits (retries) until the order is committed as complete;
|
|
105
|
+
2. builds a line per line item whose variant has a part number, naming the
|
|
106
|
+
part by `part_number` (Foudra resolves it; an unknown one refuses the order
|
|
107
|
+
with 422, logged);
|
|
108
|
+
3. finds the customer: a signed-in shopper by their Spree user id, which
|
|
109
|
+
Foudra keeps as the customer's ref on the channel
|
|
110
|
+
(`GET /api/customers?channel=&channel_ref=`), then anyone by the order's
|
|
111
|
+
email (`GET /api/customers?email=`, adding the user id to a customer found
|
|
112
|
+
that way); else creates one with the bill-to name, phone, addresses and the
|
|
113
|
+
user id as its channel ref. An existing customer's details are never changed;
|
|
114
|
+
4. `POST /api/sales-orders` with `channel`, `channel_order_ref` = the order
|
|
115
|
+
number (Foudra makes one order per pair, so a repeat is harmless),
|
|
116
|
+
`customer_reference` = the order number, ship-to from the ship address,
|
|
117
|
+
the order date as ordered and wanted date, the currency and unit prices;
|
|
118
|
+
5. remembers the Foudra customer and sales order ids on `spree_orders`.
|
|
119
|
+
|
|
120
|
+
`order_canceled` queues `CancelOrderJob`: `POST /api/sales-orders/{id}/cancel`.
|
|
121
|
+
Foudra cancels what hasn't shipped; an order that has all shipped is left
|
|
122
|
+
(409, logged).
|
|
123
|
+
|
|
124
|
+
Every write carries an `Idempotency-Key` (`solidus_foudra:order:<number>`,
|
|
125
|
+
`solidus_foudra:cancel:<number>`, `solidus_foudra:customer:<digest of the body>`:
|
|
126
|
+
Foudra refuses one key with two different bodies, so a customer's key changes
|
|
127
|
+
with their details).
|
|
128
|
+
|
|
129
|
+
### Webhooks
|
|
130
|
+
|
|
131
|
+
`POST /foudra/webhooks` checks `X-Foudra-Signature` (`t=<unix>,v1=<hex
|
|
132
|
+
HMAC-SHA256 of "<t>.<body>">`, keyed with the signing secret, over the raw
|
|
133
|
+
body; constant-time compare; `t` within 5 minutes), records the event id
|
|
134
|
+
(a repeat is answered 204 and dropped), queues a job with **only the ids** the
|
|
135
|
+
event names, and answers 204. The job re-fetches everything from the API: an
|
|
136
|
+
event is a nudge, never data.
|
|
137
|
+
|
|
138
|
+
| Event | Does |
|
|
139
|
+
|---|---|
|
|
140
|
+
| `stock.changed` | Re-fetch the part, set the stock |
|
|
141
|
+
| `sales_order.created`, `.cancelled` | Re-fetch each line's part, set the stock (committed stock moved) |
|
|
142
|
+
| `listing.changed` (on our channel) | Re-fetch that part's listing (`?part_id=`) and the part, create/update/discontinue the product |
|
|
143
|
+
| `shipment.shipped`, `.updated` | Re-fetch the shipment and its sales order, ship the Solidus units or correct the tracking |
|
|
144
|
+
| `ping`, anything else | Nothing |
|
|
145
|
+
|
|
146
|
+
### Stock
|
|
147
|
+
|
|
148
|
+
Available = Foudra's on hand less what open orders commit, rounded down, never
|
|
149
|
+
below zero, set as the count on hand at the configured stock location
|
|
150
|
+
(`StockItem#set_count_on_hand`, which also fills backorders). Variants that
|
|
151
|
+
don't track inventory are left alone.
|
|
152
|
+
|
|
153
|
+
### Products
|
|
154
|
+
|
|
155
|
+
For each listing on the channel:
|
|
156
|
+
|
|
157
|
+
- **Listed, no variant with its number**: a new product (master only), SKU =
|
|
158
|
+
the part number, name, description (Foudra's Markdown rendered to HTML), the
|
|
159
|
+
part's own first image (never its category's), price = the listing's,
|
|
160
|
+
available now. Not created without a price in the shop's currency, nor when
|
|
161
|
+
a deleted variant had that number, nor when another variant has that SKU.
|
|
162
|
+
- **Listed, a variant has its number**: adopted. Price set (in the shop's
|
|
163
|
+
currency, the default price and its VAT prices; in another currency, a price
|
|
164
|
+
in that currency), discontinuation cleared; name, description and image only
|
|
165
|
+
with `sync_content`.
|
|
166
|
+
- **Unlisted, or the part archived** (`part_is_active` false): the product is
|
|
167
|
+
discontinued, unless another of its variants is still listed (Solidus
|
|
168
|
+
discontinues products, not variants: logged).
|
|
169
|
+
- The shop's SKU is written back as the listing's `channel_part_number`, so
|
|
170
|
+
Foudra shows the listing as pushed.
|
|
171
|
+
|
|
172
|
+
### Shipping
|
|
173
|
+
|
|
174
|
+
A shipped Foudra shipment on this channel ships, in the Solidus order whose
|
|
175
|
+
number is its `channel_order_ref`, as many not-yet-shipped units of each line's
|
|
176
|
+
part as Foudra shipped, through `Spree::OrderShipping#ship`: one carton per
|
|
177
|
+
Solidus shipment, `external_number` = the Foudra shipment's number, `tracking`
|
|
178
|
+
= its tracking number. Solidus then sends its shipped email. A repeat finds the
|
|
179
|
+
carton by `external_number` and only corrects the tracking (no second email).
|
|
180
|
+
Units Solidus still has as backordered wait for the stock update first.
|
|
181
|
+
|
|
182
|
+
### The nightly pass
|
|
183
|
+
|
|
184
|
+
`rake solidus_foudra:sync` (or `FullSyncJob`): products, stock (every part, 100
|
|
185
|
+
a page), shipments of sent orders not yet shipped here (last 60 days), orders
|
|
186
|
+
since `send_orders_since` that never reached Foudra, and pruning de-duplication
|
|
187
|
+
rows older than 30 days. Each step is independent.
|
|
188
|
+
|
|
189
|
+
### Failures
|
|
190
|
+
|
|
191
|
+
Foudra being busy or down (429, 5xx, network) is retried three times in the
|
|
192
|
+
request, then by ActiveJob with growing pauses for about two and a half hours.
|
|
193
|
+
A refusal (401/402/403, 422, an unknown part number) is logged and dropped:
|
|
194
|
+
retrying won't fix it. Logs never contain the API key or a customer's email or
|
|
195
|
+
address.
|
|
196
|
+
|
|
197
|
+
## Rake tasks
|
|
198
|
+
|
|
199
|
+
| Task | Does |
|
|
200
|
+
|---|---|
|
|
201
|
+
| `solidus_foudra:status` | Shows the configuration (not the secrets) and checks the channel and listings |
|
|
202
|
+
| `solidus_foudra:import` | First import: products for every listing, then stock |
|
|
203
|
+
| `solidus_foudra:sync` | The nightly pass |
|
|
204
|
+
|
|
205
|
+
## Needs from Foudra
|
|
206
|
+
|
|
207
|
+
Delivered by Foudra on 2026-11-23 and used: `listing.changed`, `part_number`
|
|
208
|
+
on sales order lines, `GET /api/parts?part_number=`, one listing by
|
|
209
|
+
`?part_id=` (with `part_is_active`), and customers' ids in channels.
|
|
210
|
+
Foudra's [shops contract](https://foudra.com/developers/shops) describes them.
|
|
211
|
+
|
|
212
|
+
Still open:
|
|
213
|
+
|
|
214
|
+
- **Available stock per channel.** `available` on a part counts every one of
|
|
215
|
+
Foudra's locations; a figure counting only the locations that stock the shop
|
|
216
|
+
waits on an owner decision in Foudra's plan.
|
|
217
|
+
- **No event when committed stock changes on an edited order line**
|
|
218
|
+
(`PUT /api/sales-orders/{id}/lines/{line}`): the shop's figure catches up at
|
|
219
|
+
the nightly pass. `sales_order.created` and `.cancelled` are used as nudges.
|
|
220
|
+
|
|
221
|
+
## Development
|
|
222
|
+
|
|
223
|
+
```sh
|
|
224
|
+
source ~/.rvm/scripts/rvm && rvm use 3.2.3
|
|
225
|
+
bundle config set --local path vendor/bundle
|
|
226
|
+
bundle install
|
|
227
|
+
bin/rake extension:test_app # builds spec/dummy (SQLite)
|
|
228
|
+
bundle exec rspec
|
|
229
|
+
bundle exec rubocop
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Licence
|
|
233
|
+
|
|
234
|
+
Copyright (c) 2026, Kalopa Robotics Limited.
|
|
235
|
+
|
|
236
|
+
Licensed under the [Apache License, Version 2.0](LICENSE). You may not use this
|
|
237
|
+
gem except in compliance with the License. Unless required by applicable law or
|
|
238
|
+
agreed to in writing, software distributed under the License is distributed on
|
|
239
|
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
240
|
+
or implied. See the License for the specific language governing permissions and
|
|
241
|
+
limitations under the License.
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
|
|
5
|
+
require "bundler/setup"
|
|
6
|
+
require "solidus_foudra"
|
|
7
|
+
|
|
8
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
9
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
10
|
+
$LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"])
|
|
11
|
+
|
|
12
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
13
|
+
# require "pry"
|
|
14
|
+
# Pry.start
|
|
15
|
+
|
|
16
|
+
require "irb"
|
|
17
|
+
IRB.start(__FILE__)
|
data/bin/rails
ADDED
data/bin/rails-engine
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
|
3
|
+
# installed from the root of your application.
|
|
4
|
+
|
|
5
|
+
ENGINE_ROOT = File.expand_path('..', __dir__)
|
|
6
|
+
ENGINE_PATH = File.expand_path('../lib/solidus_foudra/engine', __dir__)
|
|
7
|
+
|
|
8
|
+
# Set up gems listed in the Gemfile.
|
|
9
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
|
10
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
|
11
|
+
|
|
12
|
+
require 'rails/all'
|
|
13
|
+
require 'rails/engine/commands'
|
data/bin/rails-sandbox
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
app_root = "sandbox"
|
|
4
|
+
|
|
5
|
+
unless File.exist? "#{app_root}/bin/rails"
|
|
6
|
+
warn "Creating the sandbox app..."
|
|
7
|
+
Dir.chdir "#{__dir__}/.." do
|
|
8
|
+
system "#{__dir__}/sandbox" or begin
|
|
9
|
+
warn "Automatic creation of the sandbox app failed"
|
|
10
|
+
exit 1
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
Dir.chdir app_root
|
|
16
|
+
exec "bin/rails", *ARGV
|