A type safe PayU client for NodeJS written in Typescript
npm install --save @ingameltd/payu
import { PayU, Order, Buyer, Product, Currency } from "@ingameltd/payu";
- clientId : Client ID from PayU
- clientSecret : client secret from panel
- merchantPosId : pos id from panel
- secondKey : second key from panel
const payU = new PayU(clientId, clientSecret, merchantPosId, secondKey, {
sandbox: false,
});
const result = await payU.createOrder({
notifyUrl: "https://my.shop.notify.com/notify",
customerIp: "127.0.0.1",
continueUrl: "https://myshop.com/order?id=abc",
description: "My order",
currencyCode: Currency.PLN,
totalAmount: 2000,
buyer: {
email: "buyer@email.com",
},
products: [
{ name: "mobile phone #1", quantity: 1, unitPrice: 1000 },
{ name: "mobile phone #2", quantity: 1, unitPrice: 1000 },
],
});
If your shop does not approve payments automatically, you need to capture them and confirm.
const result = await payU.captureOrder("payU order Id from notification");
To cancel an order before completed call this method.
const result = await payU.cancelOrder("payU order Id from notification");
To refund an order after completed call this method.
const result = await payU.refundOrder("payU order Id from notification", "reason");
To verify notification are valid cryptogrpically this method can be used.
const headers = req.headers;
const isValid = payU.verifyNotification(
headers["OpenPayu-Signature"],
JSON.stringify(req.body)
);
console.log(isValid);
To validate IPs are correct, use following method. It will automatically adjust to match your environment(production or sandbox)
const isIpValid = payU.isIpValid("127.0.0.1");