https://github.com/ingameltd/payu
A typesafe PayU client for NodeJS
https://github.com/ingameltd/payu
ingame nodejs payu payu-nodejs typescript
Last synced: about 1 month ago
JSON representation
A typesafe PayU client for NodeJS
- Host: GitHub
- URL: https://github.com/ingameltd/payu
- Owner: ingameltd
- License: mit
- Created: 2020-05-22T11:48:33.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-07-03T11:56:29.000Z (11 months ago)
- Last Synced: 2025-04-11T20:57:56.496Z (about 1 month ago)
- Topics: ingame, nodejs, payu, payu-nodejs, typescript
- Language: TypeScript
- Homepage: https://ingameltd.github.io/payu/
- Size: 264 KB
- Stars: 11
- Watchers: 2
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PayU for NodeJS
  
A type safe PayU client for NodeJS written in Typescript
## Installation
```bash
npm install --save @ingameltd/payu
```## Usage
### Importing
```typescript
import { PayU, Order, Buyer, Product, Currency } from "@ingameltd/payu";
```### Initialization
- **clientId** : Client ID from PayU
- **clientSecret** : client secret from panel
- **merchantPosId** : pos id from panel
- **secondKey** : second key from panel```typescript
const payU = new PayU(clientId, clientSecret, merchantPosId, secondKey, {
sandbox: false,
});
```### Create an order
```typescript
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: "[email protected]",
},
products: [
{ name: "mobile phone #1", quantity: 1, unitPrice: 1000 },
{ name: "mobile phone #2", quantity: 1, unitPrice: 1000 },
],
});
```### Capture order
If your shop does not approve payments automatically, you need to capture them and confirm.
```typescript
const result = await payU.captureOrder("payU order Id from notification");
```### Cancel order
To cancel an order before completed call this method.
```typescript
const result = await payU.cancelOrder("payU order Id from notification");
```### Refund order
To refund an order after completed call this method.
```typescript
const result = await payU.refundOrder("payU order Id from notification", "reason");
```### Verify notification
To verify notification are valid cryptogrpically this method can be used.
```typescript
const headers = req.headers;const isValid = payU.verifyNotification(
headers["OpenPayu-Signature"],
JSON.stringify(req.body)
);console.log(isValid);
```### Validate IPs
To validate IPs are correct, use following method. It will automatically adjust to match
your environment(production or sandbox)```typescript
const isIpValid = payU.isIpValid("127.0.0.1");
```