Giter Club home page Giter Club logo

node-qiwi-api's Introduction

node-qiwi-api

npm npm npm

Official documentation for Qiwi api.

Get started

Firstly, get access token at Qiwi.

npm install node-qiwi-api

You can use callback and promise based api.

Initialise new wallet instance with your access token:

var callbackQiwi = require('node-qiwi-api').callbackApi;
var asyncQiwi = require('node-qiwi-api').asyncApi;

var callbackWallet = new callbackQiwi(token);
var asyncWallet = new asyncQiwi(token);

Now you can get information about your wallet and make money transfers.

Next examples presented for callback api.

Identification data

wallet.getIdentificationData(wallet, (err, data) => {
  if(err) {
    /*hanle error*/
  }
  console.log(data);
})

wallet - wallet number without plus (+) and with prefix (79991234567)

Identify wallet

wallet.identifyWallet(wallet, requestOptions, (err, data) => {
  if(err) {
    /*hanle error*/
  }
  console.log(data);
})

wallet - wallet number without plus (+) and with prefix (79991234567)

requestOptions includes:

  • birthDate - Date of birth (YYYY-MM-DD)
  • firstName - First name
  • middleName - Middle name
  • lastName - Last name
  • passport - Serial and number of passport
  • snils - SNILS number
  • inn - INN number
  • oms - OMS number

Information about account

wallet.getAccountInfo((err, data) => {
  if(err) {
    /*hanle error*/
  }
  console.log(data);
})

Get accounts

wallet.getAccounts(wallet, (err, data) => {
  if(err) {
    /*hanle error*/
  }
  console.log(data);
})

wallet - wallet number without plus (+) and with prefix (79991234567)

Get possible account aliases

Return possible for creation at your wallet account aliases

wallet.getPossibleAccountAliases(wallet, (err, data) => {
  if(err) {
    /*hanle error*/
  }
  console.log(data);
})

wallet - wallet number without plus (+) and with prefix (79991234567)

Create account

Create account in new currency

wallet.createAccount(wallet, accountAlias, (err, data) => {
  if(err) {
    /*hanle error*/
  }
  console.log(data);
})

wallet - wallet number without plus (+) and with prefix (79991234567) accountAlias - Account alias, possible values: qw_wallet_rub, qw_wallet_kzt, qw_wallet_usd, qw_wallet_eur

If call was successfull as data you will have { success: true }, else { success: false }

Set default account

Set default account for all operations

wallet.setDefaultAccount(wallet, accountAlias, (err, data) => {
  if(err) {
    /*hanle error*/
  }
  console.log(data);
})

wallet - wallet number without plus (+) and with prefix (79991234567) accountAlias - Account alias, possible values: qw_wallet_rub, qw_wallet_kzt, qw_wallet_usd, qw_wallet_eur

If call was successfull as data you will have { success: true }, else { success: false }

Operation history

wallet.getOperationHistory(wallet, requestOptions, (err, data) => {
  if(err) {
    /*hanle error*/
  }
  console.log(data);
})

wallet - wallet number without plus (+) and with prefix (79991234567)

requestOptions includes:

  • rows - Amount of payments in response. Integer from 1 to 50. Required.
  • operation - Operation type. ALL - all operations, IN - incoming only, OUT - outgoing only, QIWI_CARD - just payments by QIWI cards (QVC, QVP). Default - ALL
  • sources - Payment source. Array of values. Allowable values: QW_RUB - ruble account of wallet, QW_USD - usd account of wallet, QW_EUR - euro account of wallet, CARD - added and not added to wallet cards, MK - account of mobile operator. If not presented, you will receive info from all sources
  • startDate - Start date (YYYY-MM-ddThh:mm:ssZ). By default equals yesterday date. Use only with endDate
  • endDate - End date (YYYY-MM-ddThh:mm:ssZ). By default equals current date. Use only with startDate
  • nextTxnDate - Transaction date (YYYY-MM-ddThh:mm:ssZ), (see nextTxnDate in response). Use only with nextTxnId
  • nextTxnId - Previous transaction number (see nextTxnId in response). Use only with nextTxnDate Maximum interval between startDate and endDate - 90 days.

As example - information about 25 outgoing payments can be get by next way:

wallet.getOperationHistory({rows: 25, operation: "OUT"}, (err, operations) => {
  /* some code */
})

Operations statistics

If you want to see statistics for summs of payments by period of time use this method. Example:

wallet.getOperationStatistics(wallet, requestOptions, (err, data) => {
  if(err) {
    /*hanle error*/
  }
  console.log(data);
})

wallet - wallet number without plus (+) and with prefix (79991234567)

requestOptions: operation, sources, startDate, endDate - Parameters are similar to getOperationHistory.

Get transaction info

Example:

wallet.getTransactionInfo(transactionId, (err, data) => {
  if(err) {
    /*hanle error*/
  }
  console.log(data);
})

Get transaction receipt

Example:

wallet.getReceipt(transactionId, requestOptions, (err, data) => {
  if(err) {
    /*hanle error*/
  }
  console.log(data);
})

requestOptions includes:

  • type - Transaction type from getOperationHistory
  • format - File format, see wallet.receiptFormat

Transfer to Qiwi wallet

wallet.toWallet({ amount: '0.01', comment: 'test', account: '+79261234567' }, (err, data) => {
  if(err) {
    /* handle err*/
    }
  console.log(data);
})
  • amount - Ammount of money
  • comment - Commentary for payment.
  • account - Receiver phone number (with international prefix)

Transfer to mobile phone

Similar to "transfer to qiwi wallet", but number without international prefix:

wallet.toMobilePhone({ amount: '0.01', comment: 'test', account: '9261234567' }, (err, data) => {
  if(err) {
    /* handle err*/
    }
  console.log(data);
})

Transfer to card

Similar to other transfers, but account is card number:

wallet.toCard({ amount: '0.01', comment: 'test', account: '5213********0000' }, (err, data) => {
  if(err) {
    /* handle err*/
    }
  console.log(data);
})

Transfer to bank account

wallet.toBank({ amount: '0.01', account: '5213********0000', account_type: '1', exp_date: 'MMYY' }, recipient, (err, data) => {
  if(err) {
    /* handle err*/
    }
  console.log(data);
})
  • ammount - Ammount of money
  • account - Receiver card/account number
  • account_type - Type of bank identificator.
    • for Alfa-bank (Альфа-Банк) - 1
    • for OTP Bank (АО ОТП БАНК) - 1
    • for Rosselhozbank (АО РОССЕЛЬХОЗБАНК) - 5
    • for Russian Standard (Русский Стандарт) - 1
    • for VTB (ВТБ ПАО) - 5
    • for Promsvyazbank (Промсвязьбанк) - 7
    • for Sberbank (ПАО Сбербанк) - 5
    • for Renessans Credit (Ренессанс Кредит) - 1
    • for Moscow Credit Bank (ПАО Московский кредитный банк) - 5
  • exp_date - Card expiration date (MMYY), as examlpe: 0218 - february 2018. Only for card transfer.
  • recipient -
    • 464 - Alfa-bank (Альфа-Банка)
    • 466 - Tinkoff Bank (Тинькофф Банк)
    • 804 - OTP Bank (АО ОТП БАНК)
    • 810 - Rosselhozbank (АО РОССЕЛЬХОЗБАНК)
    • 815 - Russian Standard (Русский Стандарт)
    • 816 - VTB (ВТБ ПАО)
    • 821 - Promsvyazbank (Промсвязьбанк)
    • 870 - Sberbank (ПАО Сбербанк)
    • 881 - Renessans Credit (Ренессанс Кредит)
    • 1135 - Moscow Credit Bank (ПАО Московский кредитный банк)

Get currency exchange rates

wallet.getCrossRates((err, data) => {
  if(err) {
    /* handle err*/
    }
  console.log(data);
})

Transfer by requisites

wallet.toCard(requestOptions, (err, data) => {
  if(err) {
    /* handle err*/
    }
  console.log(data);
})

requestOptions includes:

  • amount - Amount of money
  • account - Receiver account number
  • bankName - Receiver bank name
  • bik - Receiver bank bik
  • city - Receiver city
  • organizationName - Receiver organization name
  • inn - Receiver organization inn
  • kpp - Receiver organization kpp
  • nds - 'НДС не облагается' or 'В т.ч. НДС'
  • purpose - Purpose of payment
  • urgent - 0 or 1. Urgent pay need 10 minutes to complete. Available from 9.00 AM to 8.30 PM (09.00 - 20.30) by Moscow time (GMT+3). Service fee - 25 rubles
  • senderName - Sender name
  • senderMiddleName - Sender middle name
  • senderLastName - Sender last name

Convert currency at you wallet

wallet.convertCurrency({amount: 10, currency: wallet.currencyCode.KZT, account:'+79991234567'}, (err, data) => {
  if(err) {
    /* handle err*/
    }
  console.log(data);
})

requestOptions includes:

  • account - Phone number with plus and international prefix, as example +79991234567
  • currency - Currency code - 3 number by ISO-4217 (see wallet.currencyCode)
  • amount - Amount of money for calculate commission
  • comment - Commentary for payment.

Get invoices

wallet.getInvoices(requestOptions, (err, data) => {
  if(err) {
    /* handle err*/
    }
  console.log(data);
})

requestOptions includes:

  • rows - Amount of payments in response. Integer from 1 to 50. Required.
  • from - Date from
  • to - Date to
  • nextId - If present, method will return invoices from this id
  • nextDate - If present, method will return invoices created before this time

Pay invoice

wallet.payInvoice(invoiceId, currency, (err, data) => {
  if(err) {
    /* handle err*/
    }
  console.log(data);
})
  • invoiceId - Invoice id from getInvoices (bills[].id)
  • currency - Currency from getInvoices (bills[].sum.currency)

Cancel invoice

wallet.cancelInvoice(invoiceId, (err, data) => {
  if(err) {
    /* handle err*/
    }
  console.log(data);
})
  • invoiceId - Invoice id from getInvoices (bills[].id)

Check commission rates

wallet.checkOnlineCommission(recipient, requestOptions, (err, data) => {
  if(err) {
    /* handle err*/
    }
  console.log(data);
})

recipient - Allowable values stored in wallet.recipients

requestOptions includes:

  • account - Phone number with international prefix or card/account number, as example 79991234567
  • amount - Amount of money for calculate commission

Check operation commission

wallet.checkCommission(recipient, (err, data) => {
  if(err) {
    /* handle err*/
    }
  console.log(data);
})

data.content.terms.commission.ranges[i]:

  • recipient - Allowable values stored in wallet.recipients

Response contains:

  • bound - Payment amount, starting from which the condition applies
  • rate - Commission (absolute multiplier)
  • fixed - Fixed amount of commission

node-qiwi-api's People

Contributors

askucher avatar broderix avatar kazakovkirill avatar kwinso avatar nazarovsa avatar raywave avatar theradioguy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-qiwi-api's Issues

нет обработки ошибок node js падает с TypeError

Пришлось переписывать getOperationHistory в части отлова err от getAccountInfo.

TypeError: Cannot read property 'authInfo' of undefined
at /home/ubuntu/node/node_modules/node-qiwi-api/node-qiwi-api.js:75:73
at Request._callback (/home/ubuntu/node/node_modules/node-qiwi-api/node-qiwi-api.js:47:13)
at Request.self.callback (/home/ubuntu/node/node_modules/node-qiwi-api/node_modules/request/request.js:188:22)
at Request.emit (events.js:210:5)
at Request. (/home/ubuntu/node/node_modules/node-qiwi-api/node_modules/request/request.js:1171:10)
at Request.emit (events.js:210:5)
at IncomingMessage. (/home/ubuntu/node/node_modules/node-qiwi-api/node_modules/request/request.js:1091:12)
at Object.onceWrapper (events.js:299:28)
at IncomingMessage.emit (events.js:215:7)
at endReadableNT (_stream_readable.js:1184:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)

Wrong error catching method

When doing getTransactionInfo( tId ) - getting unhandled rejection:

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'data' of undefined
    at get (path\node_modules\node-qiwi-api\lib\asyncApi.js:724:34)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async init (path\index.js:101:13)

Which goes from this fn:

async function get(options) {
        options.headers = headers;
        try {
            var result = await axios.get(options.url, options);
            console.log(result)
            if (result.data.errorCode != undefined)
                throw result.data;

            return result.data;
        }
        catch (error) {
            throw error.response.data;
        }
    }

However if we check error object getting into catch part - it's completely normal response, with fields:

errorCode: 0,
error: null

So the error in comparing 0 with undefined, getting true here, then throwing error.
Line 718
The fix would be like this:

if (result.data.errorCode) {
    //
}

When it's 0 (false) it won't trigger if.
Any other err code will.

or

if (result.data.error != null) {
    //
}

Same error check method is used in lines
736
754
771
788

Also comparisons like this
error.message != undefined

on lines
703
677

May also cause problem at some point ( or at least it's senseless, because of the same reason described above )

Despite I didn't get any missthrows on these lines by now,
I recommend you to look into them more closely and probably change the same way.

Использование

Здравствуйте
Подскажите, пожалуйста, как использовать со своим номером телефона и апи ключем, куда их вписать? Задача стоит - авторизация и получение последних платежей

Non-closed parenthesis

Hello! I noticed what almost in every example given in https://www.npmjs.com/package/node-qiwi-api you forgot to close parenthesis, e. g. here:

Wallet.getAccountInfo((err, info) => {
  if(err) {
    /*hanle error*/
  }
  console.log(info);
}

Anyway, thank you very much for this module, it's useful for me and I believe not only for me.

payment

Russian:
Здравствуйте, ваш модуль имеет функцию, которая выводит информацию после получения средств на аккаунт?

English:
Hello, does your module have a function that displays information after receiving funds to your account?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.