-
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");
url = yandexMoney.Wallet.buildObtainTokenUrl(clientId, redirectURI, scope);
-
After that, user fills Yandex.Money HTML form and user is redirected back to
REDIRECT_URI?code=CODE
.
-
You should immediately exchange CODE
with ACCESS_TOKEN
.
function tokenComplete(err, data) {
if(err) {
}
var access_token = data.access_token;
}
yandexMoney.Wallet.getAccessToken(clientId, code, redirectURI, clientSecret,
tokenComplete);
-
Now you can use Yandex.Money API.
var api = new yandexMoney.Wallet(access_token);
api.accountInfo(function infoComplete(err, data) {
if(err) {
}
var balance = data.balance;
var user_account = data.account;
});
api.operationHistory({ records: 3 }, function operationHisComplete(err, data) {
if(err) {
}
var opertaions = data.operations;
var first_title = operations[0].title;
});
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) {
}
if(data.status !== "success") {
}
var request_id = data.request_id;
api.processPayment({
"request_id": request_id
}, processComplete);
});
function processComplete(err, data) {
if(err) {
}
}