Spreadconnect
Print-on-demand with Spreadconnect
Spreadconnect for Medusa
Copy to clipboards4f-spreadconnect is a Medusa plugin developed by SHOP4FANS. It connects Medusa to Spreadconnect. It imports products, calculates shipping, submits paid orders, and records fulfillment and tracking updates.
Unofficial integration: This plugin is not affiliated with, endorsed by, or an official product of Spreadconnect. Spreadconnect is a third-party service.
This release requires Medusa 2.22.1 and Node.js 22.22.0 or later. Use the same Medusa version in the host application.
Install
1npm install s4f-spreadconnect@0.9.0
Create a stock location and a shipping profile in Medusa Admin. Use their IDs in the configuration below.
Register the plugin and fulfillment provider in Copy to clipboardmedusa-config.ts. Merge these entries with your existing configuration and providers.
1234567891011121314151617181920import { defineConfig, loadEnv } from "@medusajs/framework/utils";loadEnv(process.env.NODE_ENV || "development", process.cwd());export default defineConfig({plugins: [{resolve: "s4f-spreadconnect",options: {baseUrl: process.env.SPREADCONNECT_BASE_URL,token: process.env.SPREADCONNECT_TOKEN,medusaUrl: `${process.env.MEDUSA_BACKEND_URL}/spreadconnect/webhooks`,webhookSecret: process.env.SPREADCONNECT_WEBHOOK_SECRET,defaultCurrencyCode: "eur",defaultStockLocationId: process.env.SPREADCONNECT_DEFAULT_STOCK_LOCATION_ID,shippingProfileId: process.env.SPREADCONNECT_SHIPPING_PROFILE_ID,fulfillmentProviderId: "spreadconnect_spreadconnect",},},],
Required environment variables:
123456SPREADCONNECT_BASE_URL=https://...SPREADCONNECT_TOKEN=...SPREADCONNECT_WEBHOOK_SECRET=...SPREADCONNECT_DEFAULT_STOCK_LOCATION_ID=sloc_...SPREADCONNECT_SHIPPING_PROFILE_ID=sp_...MEDUSA_BACKEND_URL=http://localhost:9000
The token is configured separately for the plugin module and fulfillment provider because Medusa modules are isolated. The fulfillment provider does not inject the product/webhook module.
The default fulfillment provider ID is Copy to clipboardspreadconnect_spreadconnect: Medusa composes it from the provider's static identifier (Copy to clipboardspreadconnect) and configured ID (Copy to clipboardspreadconnect). If the provider is registered with a different Copy to clipboardid, set the resulting full ID in the plugin option Copy to clipboardfulfillmentProviderId.
Medusa fulfillment setup
Configure the following through Medusa Admin or the corresponding Admin APIs:
- Create or choose the Stock Location used for Spreadconnect.
- Enable Copy to clipboard
spreadconnect_spreadconnecton that Stock Location. - Create a Fulfillment Set for the location.
- Add a Service Zone covering the supported destination countries.
- Create or choose the Shipping Profile used by Spreadconnect products.
- Ensure imported Spreadconnect products use that Shipping Profile. Set Copy to clipboard
shippingProfileIdto make product imports assign it. - In the Service Zone, create two Shipping Options with price type Copy to clipboard
calculated, the Spreadconnect provider, and the same Shipping Profile.
The provider exposes exactly these fulfillment options:
12345678910111213141516[{id: "spreadconnect-standard",name: "Spreadconnect Standard",integration: "spreadconnect",preferred_type: "STANDARD",is_return: false,},{id: "spreadconnect-express",name: "Spreadconnect Express",integration: "spreadconnect",preferred_type: "EXPRESS",is_return: false,},];
Choose Copy to clipboardspreadconnect-standard for the Standard Shipping Option and Copy to clipboardspreadconnect-express for Express. The provider rejects mismatched IDs and Copy to clipboardpreferred_type values.
Activate the integration
- Set the environment variables shown above. Use your Spreadconnect API URL and token.
- Set Copy to clipboard
MEDUSA_BACKEND_URLto the public HTTPS backend URL. - Set a webhook secret. The plugin sends this secret when it registers subscriptions.
- Apply the plugin migrations with Copy to clipboard
npx medusa db:migrate. - Restart the backend and its worker processes.
- Open Spreadconnect in Medusa Admin.
- Select Register webhooks. Check each result. Retry if any registration fails.
- Create or update an article in Spreadconnect to send its product webhook.
- Assign the imported product to your sales channel and publish it in Medusa Admin.
Imports use Copy to clipboarddefaultCurrencyCode, which defaults to Copy to clipboardeur. Configure the same currency and appropriate tax settings in Medusa. Product prices use Spreadconnect Copy to clipboardd2cPrice values without conversion.
Product creation and updates set the product to draft. An update therefore removes a published product from the storefront until you publish it again. The plugin does not select sales channels.
The plugin receives product changes through webhooks. It does not perform an initial bulk catalog import.
Connect a storefront
Use the normal Medusa Store API or Medusa JS SDK. The storefront does not need Spreadconnect credentials or custom checkout endpoints.
Before you request shipping prices, save the customer email and shipping address on the cart. Include a phone number in the shipping address. Spreadconnect requires these fields. The cart region determines the currency.
1234567891011121314151617181920await sdk.store.cart.update(cart.id, {email: customerEmail,shipping_address: {first_name: firstName,last_name: lastName,address_1: street,city,postal_code: postalCode,country_code: countryCode,phone,},});const { shipping_options } = await sdk.store.fulfillment.listCartOptions({cart_id: cart.id,});const { shipping_option } = await sdk.store.fulfillment.calculate(optionId, {cart_id: cart.id,});
Backend workflow hooks read the saved cart email and currency. Do not pass them in shipping-method Copy to clipboarddata. Client values cannot override the saved cart values.
A storefront that omits phone numbers must collect and save a phone number before shipping calculation. Standard Medusa fields support this requirement. Product visibility still requires a published product, a sales channel, a linked stock location, and a matching publishable API key.
Each shipping calculation creates a temporary Spreadconnect order in state Copy to clipboardNEW, then cancels it. Standard and Express use separate calculations. Shipping prices use major currency units and include tax. Cancellation failures cause the calculation to fail after three attempts.
Stock updates and checkout checks
The job in Copy to clipboardsrc/jobs/spreadconnect-stock-sync.ts runs daily at Copy to clipboard0 3 * * *. The scheduler determines the time zone. Set your worker time zone explicitly if 03:00 must match a local time.
The job reads paginated stock from Spreadconnect and updates imported variants at Copy to clipboarddefaultStockLocationId. It changes inventory quantities only. It does not unpublish products or change sales channels.
Zero stock sets the inventory quantity to zero. Missing or invalid stock leaves the previous quantity unchanged. The job skips unsupported inventory links, including bundles, and logs the skipped count. If a later page fails, earlier batches remain saved. The next daily run checks them again.
Live stock checks also run when a customer:
- Creates a cart with items.
- Adds items to a cart.
- Changes a line-item quantity.
- Creates a payment session.
- Completes checkout.
The plugin reads stored variant data and combines quantities for each SKU. A cart cannot bypass the check through client metadata. Non-Spreadconnect products use normal Medusa inventory checks.
Insufficient stock returns Copy to clipboardspreadconnect_insufficient_stock. An API failure or invalid stock response returns Copy to clipboardspreadconnect_stock_check_failed. Both use Medusa's standard HTTP 400 error response. The storefront can display these errors through its normal cart and checkout error handling.
These checks do not reserve stock at Spreadconnect. Supplier stock can change after a check. Completed-cart retries remain idempotent and do not trigger a new stock check.
Orders and webhooks
The plugin handles these events:
Event Result Copy to clipboardArticle.added Create or update a draft product and its stock. Copy to clipboardArticle.updated Update or create a draft product and its stock. Copy to clipboardArticle.removed Delete the imported product. Copy to clipboardOrder.processed Create the native Medusa fulfillment for the submitted order. Copy to clipboardOrder.needs-action Write a warning for operator review. Copy to clipboardOrder.cancelled Cancel the matching fulfillment and Medusa order. Copy to clipboardShipment.sent Create the native Medusa shipment and tracking labels.
Copy to clipboardorder.placed and Copy to clipboardpayment.captured trigger payment reconciliation. Production starts only after the payment collection is complete and fully captured. Authorization or partial capture does not start production.
Submission sends a Copy to clipboardCONFIRMED Spreadconnect order with a stable Copy to clipboardmedusa:<order_id> reference. The plugin saves the remote order ID on the shipping method. Copy to clipboardOrder.processed creates the Medusa fulfillment later. Manual fulfillment requires an existing submission and does not create another production order.
Webhook delivery uses Copy to clipboardPOST /spreadconnect/webhooks. The endpoint verifies the Copy to clipboardX-SPRD-SIGNATURE HMAC and saves a database receipt before it returns Copy to clipboard202. It does not call Spreadconnect during acknowledgment.
A scheduled job processes up to 50 due receipts each minute. Failed processing uses increasing retry delays, up to one hour. Identical deliveries share one receipt. Order locks prevent duplicate fulfillment and shipment changes. Product imports share a lock to protect global options.
Keep a Medusa worker with scheduled jobs enabled. For multiple backend or worker processes, configure Medusa's shared locking provider, such as Redis. A process-local lock cannot coordinate separate processes.
Recovery and limits
Stock lookup failures keep the receipt pending. They do not disable inventory management or enable backorders. A retry completes partial product imports. An older pending article receipt is ignored when a newer receipt for that article has completed. This uses receipt time, not an upstream event sequence.
An uncertain production response records Copy to clipboardsubmission_unknown. The plugin does not submit again automatically, because the first request may have succeeded. Check the remote order using its external reference. A later processed webhook can attach the remote order and continue fulfillment. Resolve a request that never reached Spreadconnect before you clear its submission marker.
Shipment processing waits until the relevant remote items have shipped. It retries when a fulfillment or tracking data is not yet available. It does not mark quantities shipped at production submission.
A remote cancellation uses Medusa's order cancellation workflow. This can refund captured payments and cancels the whole Medusa order. Use separate orders for products whose cancellation must remain independent.
Returns are not supported. Cancel an existing fulfillment through Medusa's normal cancellation flow. If Spreadconnect refuses cancellation, the provider returns an error.
Receipts retain webhook payloads, which can contain customer information. Set a retention policy for completed receipts in your deployment. Pending receipts must remain available for retries.
Development
1234npm testnpm run test:coveragenpm run release:checknpm run test:install
Tests use anonymized Spreadconnect responses in Copy to clipboardtests/fixtures/spreadconnect. SDK replay tests pass captured response bodies through the installed SDK without remote API calls.
Copy to clipboardnpm run test:install installs the built tarball and its dependencies in a temporary project. It checks Medusa plugin discovery and loads the packaged backend entry points. This command requires access to the npm registry.
Run database tests against an isolated local database whose name contains Copy to clipboardtest:
1SPREADCONNECT_TEST_DATABASE_URL=postgres://localhost/spreadconnect_test npm run test:integration
The optional Copy to clipboardnpm run test:staging requires Copy to clipboardSPREADCONNECT_RUN_STAGING_CONTRACT=true, Copy to clipboardSPREADCONNECT_STAGING_BASE_URL, Copy to clipboardSPREADCONNECT_STAGING_TOKEN, and Copy to clipboardSPREADCONNECT_STAGING_ORDER_FIXTURE. The fixture must be a valid SDK Copy to clipboardCreateOrder JSON payload. This test creates and cancels quotes and creates a confirmed staging order. Use a staging account only.
Links and support
- Spreadconnect API documentation
- Spreadconnect website
- SHOP4FANS
- Plugin issues
- Plugin author: Konrad
License
This plugin uses the MIT License. Its dependencies retain their own licenses.
