npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@weframetechsolutions/medusa-order-affiliate

v1.0.7

Published

Medusa Plugin To Handling Affiliate Commission On Each Order Payment

Downloads

438

Readme

This plugin allows you to integrate an affiliate system into your MedusaJS project. The plugin enables the creation and management of affiliate customers, allowing them to earn commissions based on order subtotals. It also includes PayPal integration for monthly payouts.

Features

  • Affiliate as Customer: Admin can mark a customer as an affiliate directly from the admin panel.
  • Commission Rate Management: Admin can set and update the commission rate for each affiliate customer.
  • Affiliate Activation/Deactivation: Admin can toggle the activeness of an affiliate customer.
  • Affiliate Commission Generation: Affiliates earn commissions once an order's payment status is set to 'captured.'
  • Commission Calculation: Commissions are based on the order's subtotal. For example, if an order includes two items priced at $10 and $20, the subtotal will be $30.
  • Payout Management: Affiliates must provide a payment email to receive payouts. Payouts are released monthly via PayPal.

Installation and Setup

To get started with the medusa-order-affiliate plugin, follow these steps:

1. Install the plugin:

npm install @weframetechsolutions/medusa-order-affiliate

2. Modify the medusa-config.js:

Add the plugin configuration to your medusa-config.js as described earlier, see.

3. (Optional) Seed your database:

Run the seed command if you want to add some pre-existing data.

npm run seed

4. Run Migrations:

This step is required as the plugin creates new fields in pre-existing entities and adds new entities.

npx medusa migrations run

5. Start the Medusa server:

Finally, start your Medusa server.

npm run dev

Configuration

After installing the plugin, you need to add it to your medusa-config.js file in the plugins section. The plugin requires several configuration options to function correctly:

{
  resolve: "@weframetechsolutions/medusa-order-affiliate",
  options: {
    enableUI: true, // Enable the admin UI for managing affiliates
    medusa_api_url: "http://127.0.0.1:9000", // The base API endpoint of your Medusa server
    paypal_client_id: "<your-paypal-client-id>", // PayPal Client ID from your developer account
    paypal_client_secret: "<your-paypal-client-secret>", // PayPal Client Secret from your developer account
    paypal_api_url: "https://api-m.sandbox.paypal.com", // PayPal API URL (default is set to the sandbox environment),
    storefront_url: "<storefront_url>" // For rendering the URL with affiliate code on affiliate details page.
  }
}

Important Notes

  • enableUI: This option is mandatory for the plugin to work properly. It enables the UI components necessary for managing affiliate customers in the Medusa admin panel.
  • medusa_api_url: The base API URL of your Medusa server is required for the plugin to communicate with your Medusa backend.
  • PayPal Integration:
    • Obtain your paypal_client_id and paypal_client_secret from your PayPal developer dashboard.
    • The paypal_api_url is set to the sandbox environment by default. Make sure to update it to the production URL (https://api.paypal.com) when deploying to a live environment.

Usage

Once the plugin is installed and configured:

  1. Affiliate Management:

    • Navigate to the Medusa admin panel.
    • Mark any customer as an affiliate.
    • Set or update their commission rate and activation status.
  2. Commission Generation:

    • Commissions are automatically generated when an order's payment status changes to 'captured.'
  3. Payouts:

    • Ensure that affiliates provide their payment email in their profile.
    • Payouts are released automatically at the end of each month.

How to uninstall

Revoke the migration

for i in {1..4}; do npx @medusajs/medusa-cli@latest migrations revert; done

Remove as package

npm remove @weframetechsolutions/medusa-order-affiliate

Comment or remove the plugin section

// {
//   resolve: "@weframetechsolutions/medusa-order-affiliate",
//   options: {
//     enableUI: true, // Enable the admin UI for managing affiliates
//     medusa_api_url: "http://127.0.0.1:9000", // The base API endpoint of your Medusa server
//     paypal_client_id: "<your-paypal-client-id>", // PayPal Client ID from your developer account
//     paypal_client_secret: "<your-paypal-client-secret>", // PayPal Client Secret from your developer account
//     paypal_api_url: "https://api-m.sandbox.paypal.com" // PayPal API URL (default is set to the sandbox environment)
//      storefront_url: "<storefront_url>" // For rendering the URL with affiliate code on affiliate details page.
//   }
// }

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page if you want to contribute.

License

This plugin is MIT licensed.