J
J
jekanok2019-06-12 14:42:37
Node.js
jekanok, 2019-06-12 14:42:37

Why is Liqpay not a valid signature?

I am writing a module for payment on express I want to generate a button for payment I look at the dock, I write according to the example in the dock I generate a button, I go over and give an error "Sorry. An error has occurred. Invalid request signature",

const express = require("express");
const bodyParser = require('body-parser')
const cors = require("cors");
const sha1 = require('sha1');
const LiqPay = require("liqpay");
const public_key = "sandbox_i6056143995"; //fake
const private_key = "sandbox_FYJPFYbeddSheWm20U31UPdgZ6mnpmXnLsTGRem"; //fake
// const liqpay = new LiqPay(public_key, private_key);

const Base64 = require('js-base64').Base64;
const app = express();
app.use(cors())
app.use(bodyParser.urlencoded({
    extended: false
}))
app.use(bodyParser.json())
app.post('/pay', (req, res) => {
    const json_string = {
        "public_key": public_key,
        "version": "3",
        "action": "pay",
        "amount": req.body.amount,
        "currency": "UAH",
        "description": "test",
        "order_id": "000001",
        'result_url': 'http://192.168.56.1:8080/',
        'server_url': 'http://192.168.56.1:3000/order'
    }
    const json_strings = JSON.stringify(json_string);
    const data = Base64.encode(json_strings); // отримуємо об'єкт закодований в base64
    const sign_string = private_key + data + private_key;

    const signature = Base64.encode(sha1(sign_string))
    console.log(signature)


    res.send(`<form method="POST" action="https://www.liqpay.ua/api/3/checkout" accept-charset="utf-8"> 
        <input type="hidden" name="data" value="${data}"/>
        <input type="hidden" name="signature" value="${signature}"/> 
        <input type="submit" /> 
       </form>`)
})
app.listen(3000, () => {
    console.log('start')
})

//tell me why it doesn't work?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2019-06-12
@sim3x

0. signature - unique signature of each request

base64_encode(
  sha1( private_key + data + private_key) ),

1. Remove all secrets in env vars

A
Anakin_Skywalk, 2021-04-07
@Anakin_Skywalk

Good evening! tell me, did you find a solution to the problem?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question