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

medusa-payment-liqpay

v0.0.7

Published

medusa-payment-liqpay is a Medusa plugin that adds LiqPay as a payment provider to Medusa ecommerce stores

Downloads

66

Readme

medusa-payment-liqpay

medusa-payment-liqpay is a Medusa plugin that adds LiqPay as a payment provider to Medusa ecommerce stores.

Medusa Website | Medusa Repository | LiqPay

WARNING

  • Work in Progress. NOT FULLY TESTED YET Use at your own risk.

Features

  • Adds LiqPay as one of available Payment Processors for Medusa.js

Setup

Prerequisites

Medusa Server

If you don’t have a Medusa server installed yet, you must follow the quickstart guide first.

Install the LiqPay Plugin

In the root of your Medusa server, run the following command to install the Paystack plugin:

yarn add medusa-payment-liqpay

Configure the Paystack Plugin

Next, you need to enable the plugin in your Medusa server.

In medusa-config.js add the following to the plugins array:

const plugins = [
  // other plugins
  {
    resolve: `medusa-payment-liqpay`,
    /** @type {import("medusa-payment-liqpay").PluginOptions} */
    options: {
      public_key: "<LIQPAY_PUBLIC_KEY>",
      private_key: "<LIQPAY_PRIVATE_KEY>",
    },
  },
];

The full list of configuration options you can pass to the plugin can be found in Config


Admin Setup

This step is required for you to be able to use LiqPay as a payment provider in your storefront.

Admin Prerequisites

If you don’t have a Medusa admin installed, make sure to follow the guide on how to install it before continuing with this section.

Add LiqPay to Regions

You can refer to this documentation in the user guide to learn how to add a payment provider like LiqPay to a region.


Storefront Setup

Next.js API Route Example

import LiqPay from "@lib/util/liqpay"
import { NextResponse } from "next/server"

const liqpay = new LiqPay(
  process.env.LIQPAY_PUBLIC_KEY!,
  process.env.LIQPAY_PRIVATE_KEY!
)

export async function POST(request: Request) {
  try {
    const formData = await request.formData()
    const data = {
      version: 3,
      public_key: process.env.LIQPAY_PUBLIC_KEY!,
      action: "pay",
      amount: Number.parseFloat(formData.get("amount") as string),
      currency: "UAH",
      description: "Оплата замовлення Medusa Store",
      order_id: formData.get("order_id"),
      language: "uk",
      result_url: "<your_storefront_success_url>",
      server_url: "https://<my_medusa_store_url>/liqpay/webhook",
    }
    return NextResponse.json(liqpay.constructObject(data))
  } catch (error) {
    console.error("LiqPay API Error:", error)
    return NextResponse.json({ error })
  }
}

For constructing data and signature object you can use official LiqPay Node.js SDK (it doesn't support Typescript though):

npm install liqpay-sdk-nodejs

Next.js Payment Button Example

import axios from "axios"
import { Cart, Order } from "@medusajs/medusa"
import { useEffect, useState } from "react"
import {convertToDecimal} from '@lib/util/prices'

const LiqPayCheckout = ({
  cart,
}: {
  cart: Omit<Cart, "refundable_amount" | "refunded_total"> | null
}) => {
  const [order, setOrder] = useState<Order|undefined>()
  const [liqpayData, setLiqpayData] = useState<string | null>(null)
  const [liqpaySignature, setLiqpaySignature] = useState<string | null>(null)
  
  useEffect(() => {
      if (cart?.total) {
        const formData = new FormData()
        formData.append("amount", `${convertToDecimal(cart?.total, cart?.region)}`)
        formData.append("order_id", `${cart?.id}`)
  
        axios
          .post("/api/liqpay", formData)
          .then((result) => {
            setLiqpayData(result.data.data)
            setLiqpaySignature(result.data.signature)
          })
          .catch((error) => {
            console.error("Error fetching LiqPay data:", error)
          })
      }
  }, [cart])

  return (
    <>
      {
        liqpayData && liqpaySignature ?
        <form
        method="POST"
        action="https://www.liqpay.ua/api/3/checkout"
        accept-charset="utf-8"
        className="w-full flex justify-end"
      >
        <input type="hidden" name="data" value={liqpayData || ""} />
        <input type="hidden" name="signature" value={liqpaySignature || ""} />
        <button
          //@ts-ignore
          type="image"
          className="w-1/2 shadow-none bg-[#4EA525] hover:bg-[#4EA52590] rounded-xl h-[32px] text-white transition-all duration-300 mt-6"
        >
          Перейти до оплати
        </button>
      </form>
      : null
      }
      
    </>
  )
}

export default LiqPayCheckout

You can modify default function convertToDecimal from @lib/util/prices in default Storefront to convert Medusa.js amount to suitable for LiqPay API consumption.


Refund Payments

You can refund captured payments made with LiqPay from the Admin dashboard.

medusa-payment-liqpay handles refunding the given amount using LiqPay and marks the order in Medusa as refunded.


Configuration

| Name | Type | Default | Description | | --------------- | --------- | ----------- | --------------------------------------------------------------------------------------------- | | public_key | string | undefined | Your LiqPay public key (the short one)
| private_key | string | undefined | Your LiqPay private key | | disable_retries | boolean | false | Disable retries for 5xx and failed idempotent requests to LiqPay | | debug | boolean | false | Enable debug mode for the plugin. If true, helpful debug information is logged to the console |