NodeJS Yandex.Money API SDK
Yandex.Money API pages: Ru, En
Requirements
- node >= 6.5
Getting started
Installation
npm install yandex-money-sdk-ext
Payments from the Yandex.Money wallet
Using Yandex.Money API requires following steps
- 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.
const YandexMoneySdk = ; const clientId = '/* yopur application ID */';const scope = 'account-info' 'operation-history' 'operation-details' 'payment-p2p' 'incoming-transfers' 'payment-shop';const redirectURI = 'https://localhost';const url = YandexMoneySdk;
-
After that, user fills Yandex.Money HTML form and user is redirected back to
REDIRECT_URI?code=CODE
. -
You should immediately exchange
CODE
withACCESS_TOKEN
.
const YandexMoneySdk = ;const api = ; const code = '/* code from query params */';api;
- Now you can use Yandex.Money API.
const api = access_token; // Get account info (https://tech.yandex.ru/money/doc/dg/reference/account-info-docpage/)api; // Fetch last 3 records of operation history (https://tech.yandex.ru/money/doc/dg/reference/operation-history-docpage/)api; // Make request payment and process itconst 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;
Payments from bank cards without authorization
- Fetch instantce-id (ussually only once for every client. You can store result in DB).
// Create api without access tokenconst api = ;api;
- Make request payment
const options = // pattern_id, etc..; YandexMoneySdk;
- Process the request with process-payment.
externalPayment;
Request options
Request options are optional, the defaults is:
const api = "access_token" url: 'https://money.yandex.ru' userAgent: 'Yandex.Money.SDK/NodeJS' proxy: '' // Optional proxy server like "http://username:password@localhost:3128";
Side notes
- Each API function recieves a callback in args
err
,data
andresponse
. Whereerr
is equal tonull
when status of response is2**
,data
is JSONed response andresponse
is a full server response(you can checkresponse.statusCode
for example).
Running tests
- Clone this repo, install deps and devDeps.
- Create
test/constants.js
usingtest/constants.js.sample
as a template. - Run
npm run test
and check the output.