Built by
KreischerPanopticCategory
PaymentVersion
0.0.7
Last updated
Oct 22, 2024, 13:46:23 PM2 months agomedusa-payment-liqpay
medusa-payment-liqpay is a Medusa plugin that adds LiqPay as a payment provider to Medusa ecommerce stores.
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 clipboard
medusa-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
1234567891011121314151617181920212223242526272829import 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):
12### Next.js Payment Button Example
const LiqPayCheckout = ({
cart,
}: {
cart: Omit<Cart, "refundable_amount" | "refunded_total"> | null
}) => {
const [order, setOrder] = useState<Order|undefined>()
const [liqpayData, setLiqpayData] = useState (null)
const [liqpaySignature, setLiqpaySignature] = useState (null)
useEffect(() => {
if (cart?.total) {
const formData = new FormData()
formData.append("amount", Copy to clipboard
${convertToDecimal(cart?.total, cart?.region)}
)
formData.append("order_id", Copy to clipboard${cart?.id}
)1234567891011axios.post("/api/liqpay", formData).then((result) => {setLiqpayData(result.data.data)setLiqpaySignature(result.data.signature)}).catch((error) => {console.error("Error fetching LiqPay data:", error)})}
return (
<>
{
liqpayData && liqpaySignature ?
: null
}
12</>
}
export default LiqPayCheckout
```
You can modify default function
Copy to clipboard
convertToDecimal
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 clipboard
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 | 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 |