A
A
Alexander Buki2018-12-08 10:40:27
Node.js
Alexander Buki, 2018-12-08 10:40:27

How to properly configure a server on node js to receive notifications about incoming payments Yandex Money (yandex money)?

Colleagues, good afternoon!
I re-read the Yandex Money documentation and looked through all the posts on this topic, but I can’t fully figure it out.
I am making a skeleton for a small telegram online store with the ability to pay by card through Yandex Money.
For now, I do everything manually directly from the code editor to check if it works.
Set up a wallet to send notifications when receiving a payment:
5c0b6e3b19197690852859.jpeg
Created an https server:

const express = require('express');
const app = express();
const https = require('https');
const fs = require('fs');
const port = 3000;
const options = {
    key: fs.readFileSync('./key.pem'),
    cert: fs.readFileSync('./cert.pem')
};

const Server = ()=>{
    app.post('/receive',(req, res)=>{
        console.log('you have got some incoming payment');
    res.status(200).send();
    });

    app.get('/',(req, res)=>{
        console.log('get request');
    res.status(200).send();
    });

    https.createServer(options, app)
        .listen(port, function () {
            console.log('Example app listening on port 3000!')
        });

I do a test on the same Yandex Money page:
5c0b71dd8252f655441706.jpeg
Everything is fine and the server catches the request:
5c0b7550f126c662830795.jpeg
As a result, I create a one-time application instance:
yandexMoney.ExternalPayment.getInstanceId(clientId,
    function getInstanceComplete(err, data) {
        if(err) {
            // process error
        }
        var instanceId = data.instance_id;
        // save it to DB
        console.log('data.instance_id: ', data.instance_id)

    });

After saving the application instance, I make a trial payment using the card:
var externalPayment = new yandexMoney.ExternalPayment(config.instanceId)

var options = {
     pattern_id: 'p2p',
    instance_id: config.instanceId,
    to: '4100145656XXXXX',
    amount: 5,
    message: 'testpayment',
    merchantArticleId: 123

};

externalPayment.request(options, function requestComplete(err, data) {
    if(err) {
        // process error
    }
    var requestId = data.request_id;
    console.log('data', data);
    externalPayment.process({"request_id": requestId,
        ext_auth_success_uri: 'https://t.me/kursy_naXXXXXX,
        ext_auth_fail_uri: 'https://t.me/kursy_naXXXXXX'

    }, function (err, data) {
        if(err) {
            // process error
        }
        // process data
        console.log('dataProcess', data)
    });
});

I receive a link and parameters for payment:
5c0b74a930fa1438771423.jpeg
I make a payment, but the notification does not come
. Maybe it's a secret word or something else.
I re-read the documentation and all the posts on the toaster, but I can’t figure out how to properly configure the server after all.
Tell me how to proceed or where you can find information.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question