LiqPay
Enable quick payment processing at checkout with LiqPay
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:
1yarn add medusa-payment-liqpay
Configure the Paystack Plugin
Next, you need to enable the plugin in your Medusa server.
In Copy to clipboardmedusa-config.js
add the following to the Copy to clipboardplugins
array:
1234567891011const 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
1234567891011121314151617181920import 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",
For constructing data and signature object you can use official LiqPay Node.js SDK (it doesn't support Typescript though):
Copy to clipboardnpm install liqpay-sdk-nodejs
Next.js Payment Button Example
1234567891011121314151617181920import 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}`)
You can modify default function Copy to clipboardconvertToDecimal
from Copy to clipboard@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.
Copy to clipboardmedusa-payment-liqpay
handles refunding the given amount using LiqPay and marks the order in Medusa as refunded.
Configuration
Name Type Default Description public_key Copy to clipboardstring
Copy to clipboardundefined
Your LiqPay public key (the short one) private_key Copy to clipboardstring
Copy to clipboardundefined
Your LiqPay private key disable_retries Copy to clipboardboolean
Copy to clipboardfalse
Disable retries for 5xx and failed idempotent requests to LiqPay debug Copy to clipboardboolean
Copy to clipboardfalse
Enable debug mode for the plugin. If true, helpful debug information is logged to the console