npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yandex-money-sdk

v0.1.7

Published

SDK for working with yandex money API

Downloads

85

Readme

Build Status Coverage Status

NodeJS Yandex.Money API SDK

Requirements

  1. requests == 2.9.x

Links

  1. Yandex.Money API page: Ru, En

Getting started

Installation

Simply run npm install yandex-money-sdk

Payments from the Yandex.Money wallet

Using Yandex.Money API requires following steps

  1. Obtain token URL and redirect user's browser to Yandex.Money service. Note: client_id, redirect_uri, client_secret are constants that you get, when register app in Yandex.Money API.

    var yandexMoney = require("yandex-money-sdk");
    // scope is array(e.g. scope = ['account-info', 'operation-history'])
    url = yandexMoney.Wallet.buildObtainTokenUrl(clientId, redirectURI, scope);
    // redirect user to url
  2. After that, user fills Yandex.Money HTML form and user is redirected back to REDIRECT_URI?code=CODE.

  3. You should immediately exchange CODE with ACCESS_TOKEN.

    function tokenComplete(err, data) {
        if(err) {
            // process error
        }
        var access_token = data.access_token;
        // save it to DB, config, etc..
    }
    yandexMoney.Wallet.getAccessToken(clientId, code, redirectURI, clientSecret,
        tokenComplete);
  4. Now you can use Yandex.Money API.

    var api = new yandexMoney.Wallet(access_token);
    
    // get account info
    api.accountInfo(function infoComplete(err, data) {
        if(err) {
            // process error
        }
        // process data
        var balance = data.balance;
        var user_account = data.account;
        // etc..
    });
    
    // fetch last 3 records of operation history
    api.operationHistory({ records: 3 }, function operationHisComplete(err, data) {
        if(err) {
            // process error
        }
        // process data
        var opertaions = data.operations;
        var first_title = operations[0].title;
        // etc..
    });
    
    //make request payment and process it
    var options = {
        "pattern_id": "p2p",
        "to": "410011161616877",
        "amount_due": "0.02",
        "comment": "test payment comment from yandex-money-nodejs",
        "message": "test payment message from yandex-money-nodejs",
        "label": "testPayment",
        "test_payment": true,
        "test_result": "success"
    };
    api.requestPayment(options, function requestComplete(err, data) {
        if(err) {
            // process error
        }
        if(data.status !== "success") {
            // process failure
        }
        var request_id = data.request_id;
    
        api.processPayment({
            "request_id": request_id
            }, processComplete);
    });
    
    function processComplete(err, data) {
        if(err) {
            // process error
        }
        // process status
    }

Payments from bank cards without authorization

  1. Fetch instantce-id(ussually only once for every client. You can store result in DB).

    yandexMoney.ExternalPayment.getInstanceId(clientId,
            function getInstanceComplete(err, data) {
        if(err) {
            // process error
        }
        var instanceId = data.instance_id;
        // save it to DB
       
    });
  2. Make request payment

    var externalPayment = new yandexMoney.ExternalPayment(instanceId)
    
    var options = {
        // pattern_id, etc..
    };
    
    externalPayment.request(options, function requestComplete(err, data) {
        if(err) {
            // process error
        }
        var requestId = data.request_id;
    });
  3. Process the request with process-payment.

    externalPayment.process({"request_id": requestId}, function (err, data) {
        if(err) {
            // process error
        }
        // process data
    });

Side notes

  1. Each API function recieves a callback in args err, data and response. Where err is equal to null when status of response is 2**, data is JSONed response and response is a full server response(you can check response.statusCode for example).

Running tests

  1. Clone this repo, install deps and devDeps.
  2. Create test/constants.js using test/constants.js.sample as a template.
  3. Run npm run test and check the output.