How We Won the Medusa Hackathon: Building the Paystack Plugin

This article was written by Femi Akinemi and Andrew Glago.

Medusa is an open-source composable commerce engine built with Node.js. Medusa enables developers to build scalable and sophisticated commerce setups with less effort and great developer experience.

Paystack allows African businesses to accept payments in local and foreign currencies from multiple local and global payment channels.

As our submission for the Medusa Hackathon, we created medusa-payments-paystack, a plugin that connects Paystack as a payment provider to Medusa ecommerce stores.

With our plugin, African business owners can create ecommerce stores on Medusa and accept payments in local currencies corresponding to the 236 million (2022) and counting ecommerce users in Africa.

Hackathon work experience

Working at Medusa Hackathon was a wonderful experience for both of us. We met on the Medusa Discord server and decided to work together on submissions for the hackathon.

We were both familiar with Paystack, as they operate in both of our countries (Ghana and Nigeria), and decided it would be useful to create a payments plugin integrated with Paystack to enable Medusa store purchases in our local currencies.

We decided on our high-level goals; Feature parity with existing Stripe paid plugin, high code coverage and a really good developer experience. Then we broke them down into measurable tasks and we split between each other and worked in smaller sprints.

We met regularly to capture progress and unblock each other where necessary. We had a great time working together and learned a lot from each other.

The experience of developing with Medusa

Our development process began with identifying and familiarizing with the Medusa user flow into which our payment plugin would be integrated. These turned out to be the checkout flow and admin order management system.

Users should be able to pay for items in the Medusa Store and store owners should be able to view order payments and issue refunds. Our plugin will handle everything.

We went to work to get acquainted with the APIs Medusa provides developers that will allow our plugin to perform the above tasks.

The Medusa docs were a godsend for us as first time users of the platform. There were docs for practically everything we needed and we found a dependency injection mechanism that allowed core Medusa services like the cart service (we use this to validate payment amount values) into useful plugins especially Gave.

After figuring out what needs to be done with Medusa’s end of things, we integrated paystack using paystack-api The package, a Node.js wrapper for the Paystack API, calls the relevant Paystack API endpoint appropriately.

What are the features of the plugin?

When you install and choose Paystack as your payment provider for your Medusa ecommerce store, you are guaranteed the following features:

Connect Medusa to Paystack

Using medusa-payment-paystack, you can easily integrate Paystack with Medusa, add Paystack as a payment provider in an area, and add Paystack to your checkout flow. provider_id Why Pestak? Payments made from your Medusa store to your Paystack business are automatically reflected on your admin panel. Refund too.

verify purchase

In the payment completion callback of your chosen flow, you can call the Medusa Complete Cart method. When you use the reference provided by medusa-payment-paystack, the transaction status is checked, verifies that the amount matches the cart total, and payments are made within medusa Marks the cart.

issue a refund

The admin dashboard allows you to reverse the captured payments made with Paystack.

Refunds will take place using medusa-payment-paystack, which marks the order in medusa as refunded using paystack.

In addition, all Paystack’s checkout flows (Popups, Redirects, APIs) are provided by the plugin.

how to use plugin

There are three main steps involved in adding support for Paystack payments to your Medusa store using the medusa-payments-paystack plugin:

  1. Adding Paystack as a Payment Provider to Your Medusa Server
    • It involves installing the plugin from npm using the command npm install medusa-payment-paystack
    • Adding a Plugin to Your Plugin List medusa.config.js
  2. Adding Paystack to the Area
    • In the Medusa Admin Dashboard, select the regions in which you want to enable Paystack and select Paystack option in it Payment Providers,
  3. Integrate into checkout flow
    • Use the context injected by the plugin into your payment session data when initiating a payment with Paystack.
    • Call Medusa’s complete cart method after the user has successfully completed the payment. The plugin will take it from there, reporting paid orders to Medusa, verifying amounts, and processing refunds if necessary.

We have created a video walking you through these steps which you can refer to:

conclusion

For more detailed steps on how to install Paystack plugin, you can visit the project’s README for detailed steps.

If you want to go straight into the code, check out medusa-paystack-demo – a demo Medusa store with Paystack configured as a payment provider medusa-payment-paystack,

If you have any issue or query related to Medusa, feel free to contact Medusa team via Discord.

Leave a Comment