medusa-plugin-moneyworks
This plugin aims to make synchronization between MoneyWorks and medusajs as simple as possible.
Features
This plugin provides the following features
- Synchronize inventory quantity from MoneyWorks
- Synchronize SKU and barcode from MoneyWorks
- Run synchronization with scheduled jobs
- Emit event when invoice is ready
Getting Started
To use this plugin, install it with your package manager
1pnpm install @oak-digital/medusa-plugin-moneyworks
Add the plugin to the plugins array in your Copy to clipboard
medusa-config
12345678910111213141516171819202122const plugins = [// ...{resolve: "@oak-digital/medusa-plugin-moneyworks",options: {host: process.env.MW_HOST, // The hostname for your MoneyWorks datacentreport: process.env.MW_PORT, // The port for the REST api of your MoneyWorks datacentreusername: process.env.MW_USERNAME, // The server usernamepassword: process.env.MW_PASSWORD, // The server passworddataFile: process.env.MW_DATA_FILE, // The path to the datafile, should not be url encodeddataFileUsername: process.env.MW_DATA_FILE_USERNAME,dataFilePassword: process.env.MW_DATA_FILE_PASSWORD,scheduledSyncString: "0 0 2 ? * * *", // a cron string for when the sync should run, default "0 0 2 ? * * *"moneyworksSecret: process.env.MW_SECRET, // A secret to use to make endpoints under /moneyworks work. Should be discussed with moneyworks.invoiceForm: process.env.MW_INVOICE_FORM, // Which form to use for the generated invoice (Optional)defaultContra: process.env.MW_CONTRA, // The contra field to use for transactionshandlebars: Handlebars, // optional. If you want your own handlebars with helpers you can use this heretransactionNameCodeTemplate: 'WEB_{{ shipping_address.country_code }}', // optional A handlebars template for the namecode on the transaction. Defaults to "WEB_ORDER"transactionStockLocationTemplate: '{{ order.shipping_address.country_code }}' // optional a handlebars template for stock location on line items with the order (key: order) and the line item (key: item) as the context}}]
Synchronization
To make synchronization work, the barcode or SKU should be set on a variant.
The synchronization will sync inventory quantity, SKU and barcode.
Orders
Whenever an order is created in medusa it will be sent to MoneyWorks as a transaction.
Currently it is required to have a name in the names table of MoneyWorks with the namecode Copy to clipboard
WEB_ORDER
, which all transactions will be created to.Events
Copy to clipboardorder.invoice.ready
This event happens just after Copy to clipboard
order.placed
/moneyworks/invoice-ready
with the following fields.1234{orderId: number | string, // The display_id of the orderinvoiceId: number | string, // The id/sequencenumber of the invoice in moneyworks}
Event data:
1234{invoice: string, // The invoice pdf as a base64 encoded stringid: string, // The actual medusa order id (e.g. "order_...")}
This event can be used in a notification provider to send a notification with the invoice to the customer.
This can be used as a fallback to send an email to the customer, just without an invoice.
Copy to clipboardorder.invoice.failed
If the invoice could not be fetched from MoneyWorks, this event will be fired instead of Copy to clipboard
order.invoice.ready
Event data:
1234{id: string, // The medusa order idinvoiceId: number, // The sequencenumber of the invoice that failed from MoneyWorks}