A
A
Albert Ushakov2020-06-10 10:50:03
PHP
Albert Ushakov, 2020-06-10 10:50:03

Error 400. Request signature not correct UnitPay, how to solve?

I just can’t understand what is the error in the formation of the link and the signature, can anyone come across this problem with this payment system?
Here is the code for generating a link and a signature (I did not add keys from my account).

private function getUrl($sum, $user_id, $order_id)
    {
    $account = $user_id;
    $secretKey = 'Ключ для подписи';
    $desc = 'Оплата заказа ' . $order_id;
    $currency = 'RUB';
    $hashStr = hash('sha256', $account.'{up}'.$currency.'{up}'.$desc.'{up}'.$sum.'{up}'.$secretKey);
        return 'https://unitpay.ru/pay/111111-11111/card?sum=' . $sum . '&account=' . $account . '&desc=' . $desc . '&signature=' . $hashStr;
    }

A link like this is generated: https://unitpay.ru/pay/111111-11111/card?sum=500&a...
When switching, an error pops up Error 400. The request signature is not correct.
I've looked all over, I don't understand how to fix this, please help (

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Albert Ushakov, 2020-06-13
@fuck_ask

In general, I was compiling and digging, in the end I solved my problem, there were still a lot of errors, but I sort of fixed it.
It was 1. Due to the fact that RUB was indicated in the link and not in the key.
2. Order of adding parameters.
3. Description of the order, # <- the symbol did not skip this payment, I had to replace it with #. I tried to encrypt, but it did not work with the first character.
That's it, here's the working code:

private function getUrl($sum, $user_id, $order_id)
    {
    
    $desc = 'Оплата заказа №' . $order_id;

    $hashStr = hash('sha256', $order_id.'{up}'.$desc.'{up}'.$sum.'{up}'.Config::SECRET_KEY);
        return 'https://unitpay.ru/pay/'.Config::PUBLIC_KEY.'/card?account=' . $order_id . '&desc=' . $desc . '&sum=' . $sum . '&signature=' . $hashStr;
    }
Я тут вывожу ссылку на форму, вы можете по своему переделать.

K
Kirill Kuznetsov, 2020-06-10
@KuznetsovK

I don’t know about this system specifically, but when generating a request signature, the order of the arguments is usually important (in alphabetical order).
In addition, a 400 error may be due to the fact that the request is sent by the wrong method (GET instead of POST)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question