QIWI SDK
Typed QIWI Wallet SDK for NodeJS. Supported API's: Personal & P2P Bill Payments
👅 Язык
Весь JSDoc библиотеки на русском языке, как и большая часть документации.
Основной README.md
файл на английском потому что:
- NPM лучше индексирует текст на английском + хочется чтобы не русскоговорящие
люди, нашедшие эту библиотеку на NPM не пугались того, что всё на Русском.
- Английский - это язык из которого пошли программистские термины, в том числе те,
что нельзя перевести. (например: Contributing)
👉 Документация на Русском 🇷🇺 👈
Language: Русский | English
🍬 Why use this lib?
- Full. Covers the following APIs:
- Simple. All methods are named as in QIWI documentation and collected into subclasses. All methods have JSDoc comments.
- Reliable. The library is written in TypeScript and covered by tests.
- Secure. The library has only 1 dependency (axios) and is constantly scanned by Code QL and Snyk for vulnerabilities.
- Compatible. Code from version
1.1.0
(18 Jan. 2020) will work on version 4.0.0
(26 May 2022) with little changes. Also qiwi-sdk
provides classes to make migration from similar libs effortless.
- Powerful. Supports http & socks proxy out of the box, and rarely used APIs:
- Personal Webhooks;
- P2P payment method blocking;
- "Qiwi Master" Card API.
Express
integration out of the box
- Cross Platform. Works in browser
Language: Русский | English
📦 Installation
- Using
npm
npm i qiwi-sdk
- Using
Yarn
yarn add qiwi-sdk
- Using
pnpm
pnpm add qiwi-sdk
Language: Русский | English
🛠️ Usage
Import
From the library you can import all the APIs separately, because
use cases are different.
-
CommonJS (default for Node JS)
const { P2p, Wallet, Detector } = require("qiwi-sdk");
-
TypeScript or ES Modules
import { P2p, Wallet, Detector } from "qiwi-sdk";
Documentation
👉 View API Reference 👈
The table shows the currently implemented APIs.
Class (Legacy v2) is a compatible class only for those
who are upgrading from version 2. The rest are advised to use
the new version of the API - Class v3.
API Overview
To see detailed documentation on a class, click on its name.
Migration
- Migration from version 2 to 3;
- Migration from version 1 to 2 (just in case);
- Migration from
node-qiwi
; - Migration from
@qiwi/bill-payments-node-js-sdk
.
Instantiation
const { Wallet, P2p, Detector } = require("qiwi-sdk");
const wallet = Wallet.create(process.env.QIWI_TOKEN, process.env.QIWI_WALLET);
const p2p = P2p.create(process.env.QIWI_SECRET_KEY, process.env.QIWI_PUBLIC_KEY);
const detect = Detector.create();
const wallet = new Wallet({
token: process.env.QIWI_TOKEN,
walletId: process.env.QIWI_WALLET
});
const p2p = new P2p({
secretKey: process.env.QIWI_SECRET_KEY,
publicKey: process.env.QIWI_PUBLIC_KEY
});
const detect = new Detector();
Environment variables
The following environment variables were used in this example.
It's recommended to store all data for API access in environment
variables or in another protected place, but not in the code.
Examples
Getting info about wallet
const wallet = Wallet.create(process.env.QIWI_TOKEN);
wallet.personProfile.getCurrent().then(console.log);
Sending payment
const wallet = Wallet.create(process.env.QIWI_TOKEN);
wallet.payments.quickPay({
amount: 100,
account: "79123456789"
});
Using P2P
const p2p = P2p.create(process.env.QIWI_SECRET_KEY);
p2p.bills
.create({
amount: {
value: 1000,
currency: P2p.Currency.RUB
},
successUrl: "https://youtu.be/dQw4w9WgXcQ"
})
.then(console.log);
Using Proxy
const { SocksProxyAgent } = require("socks-proxy-agent");
const wallet = Wallet.create(process.env.QIWI_TOKEN);
wallet.agent = new SocksProxyAgent("socks://login:password@host:port");
wallet.agent = undefined;
Express integration
const p2p = P2p.create(process.env.QIWI_SECRET_KEY);
const app = express();
app.post(
"/webhook/qiwi",
p2p.notificationMiddleware({}, (req, res) => {
console.log(req.body);
})
);
app.use((error, req, res, next) => {
if (error instanceof P2pBillNotificationError) {
console.log(error);
}
return next();
});
Full examples
- 🥝 Getting info about wallet
- 📬 Sending payment
- 🛠️ Using P2P api
- 🔐 Getting wallet limits (using ESM)
- 🤖 Telegram bot with direct payments (by wallet phone number)
- 🖥️ Shop on Express
- 🌐 Using proxy
Language: Русский | English
🎩 About the Project
License
Distributed under the MIT License. See LICENSE.txt for more information.
Project Goals
Contributing
- ⁉️ Do not hesitate to create Issues
- 🛠️ If you want to contribute to code, follow
CONTRIBUTING.md
- 💸 Also please donate 👉 https://qiwi.com/n/ALEXXGRIB
- 🌟 Or give this repo a star, if you liked this lib
Support
You can write issue, or if i am slow to answer it, you can DM me in
Telegram: @AlexXanderGrib
💜 YooMoney package
Interested in P2P acquiring in Russia?
Check out my other SDK for YooMoney (formerly Yandex.Money) 👉 github.com/AlexXanderGrib/yoomoney-sdk
Language: Русский | English