baibaratsky / php-webmoney

WebMoney API PHP Library
Other
73 stars 32 forks source link

Payment error: signature is incorrect. #73

Closed nelli7 closed 8 years ago

nelli7 commented 9 years ago

Hello! I am trying to use X2 interface of web money. I did as written here https://github.com/baibaratsky/php-webmoney/wiki/X2 , I only wrote my parametrs such as wmid, purse, path to key file, etc, but got this error: Payment error: signature is incorrect. Could you please tell me how to fix this error, where to look?) I saw this too: https://github.com/baibaratsky/php-webmoney/issues/63, but id did not help me.

chuprik commented 9 years ago

please show your code

nelli7 commented 9 years ago

Here it is:

use baibaratsky\WebMoney\WebMoney;
use baibaratsky\WebMoney\Signer;
use baibaratsky\WebMoney\Request\Requester\CurlRequester;
use baibaratsky\WebMoney\Api\X\X2;

$webMoney = new WebMoney(new CurlRequester);

$request = new X2\Request;
$request->setSignerWmid('mywmid');
$request->setTransactionExternalId(1); // Unique ID of the transaction in your system
$request->setPayerPurse('mypurse');
$request->setPayeePurse('payeepurse');
$request->setAmount(0.01); // Payment amount
$request->setDescription('Test payment');
$request->setInvoiceId(0);

$request->sign(new Signer('mywmid', (\Yii::$app->basePath).'/do_not_touch/my.kwm', 'my_password'));

if ($request->validate()) {
    /** @var X2\Response $response */
    $response = $webMoney->request($request);

    if ($response->getReturnCode() === 0) {
        echo 'Successful payment, transaction id: ' . $response->getTransactionId();
    } else {
        echo 'Payment error: ' . $response->getReturnDescription();
    }
} else {
    echo 'Request errors: ' . PHP_EOL;
    foreach ($request->getErrors() as $error) {
        echo ' - ' . $error . PHP_EOL;
    }
}
baibaratsky commented 9 years ago

@nelli7, do you use the key file password or the password you use to log in to WM?

nelli7 commented 9 years ago

@baibaratsky , I am using the password for my key file (kwm)

baibaratsky commented 9 years ago

Is it the first time when you try to use X2 with this account? This error can appear if you already have requests made before, with greater request numbers than the library generates.

Also please double check if the payer purse belongs to WMID and both aren’t mistyped. WM returns this error in many cases, not only when the signature is wrong.

nelli7 commented 9 years ago

It is the first time, I have not succeeded even once.I rewrited code a few times... When I tried to do like described here http://wiki.webmoney.ru/projects/webmoney/wiki/%D0%98%D0%BD%D1%82%D0%B5%D1%80%D1%84%D0%B5%D0%B9%D1%81_X2 the answer was:cURL error number:60 cURL error:SSL certificate problem: unable to get local issuer certificate. Could it be a problem?

chuprik commented 9 years ago

the latter problem may be related to an wrong configuration of curl (for example: used version of ssl).

about main problem:

nelli7 commented 9 years ago

$response->getRawData() shows this: 144491272682877-14signature is incorrect. planstr=1444912726828771999Z414407734014Z6444698386320.010Test payment0 step=5

$request->setTransactionExternalId(1); - I tried different values.. like 1999 or 39245263580205

chuprik commented 9 years ago

@baibaratsky do you remember what you fixed for https://github.com/baibaratsky/php-webmoney/issues/63#issuecomment-87891793 ?

baibaratsky commented 9 years ago

@kotchuprik see this commit 110a883011a18c77d79c4d3414938b7e88a949e9

chuprik commented 9 years ago

@nelli7 I have looked your signature string and code again... I have an question — Why invoiceId is 0? invoiceId is wminvid in WM docs.

Please read this:

trans\wminvid Invoice number (in the WebMoney system) An integer > 0; 0 means that the transfer is made without an invoice. Maximum is 2^32 -1;

And read this (the latter comment)

baibaratsky commented 9 years ago

@kotchuprik

0 means that the transfer is made without an invoice

It’s ok.

nelli7 commented 9 years ago

I used TransactionExternalId with values 1, 2 too.. I set setInvoiceId(12) , but got the same mistake. If the problem was in key file, I guess I would get another error earlier?

baibaratsky commented 9 years ago

@nelli7 You could try to generate a new key file in Keeper. I have reports from some users that it can solve some problems.

nelli7 commented 9 years ago

Thank you for your help, if I solve the problem I will write solution here.

baibaratsky commented 9 years ago

I think you need to contact the WM support to discover what does this error really mean.

nelli7 commented 9 years ago

WM support couldn't help unfortunately. I tried to display this: $request->sign(new Signer('392452635802', (\Yii::$app->basePath).'/folder/my.kwm', 'password')); echo $request->sign(new Signer('392452635802', (\Yii::$app->basePath).'/folder/my.kwm', 'password'))."kkk";

But it is empty. Should it be like this?

chuprik commented 9 years ago

sign() doesn't has any return value.

try:

$request->sign(new Signer('392452635802', (\Yii::$app->basePath).'/folder/my.kwm', 'password'));
var_export($request);

and will see signature value

nelli7 commented 9 years ago

Thank you! Here is the answer: baibaratsky\WebMoney\Api\X\X2\Request::__set_state(array( 'signerWmid' => '392452635802', 'transactionExternalId' => 1, 'payerPurse' => 'Z414407734014', 'payeePurse' => 'Z644469838632', 'amount' => 0.01, 'protectionPeriod' => 0, 'protectionCode' => NULL, 'description' => 'Test payment', 'invoiceId' => 0, 'onlyAuth' => 1, 'authType' => 'classic', 'requestNumber' => '144549645411097', 'url' => 'https://w3s.webmoney.ru/asp/XMLTrans.asp', 'errors' => array ( ), 'signature' => '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', ))

'signature' => '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'

Many 0, I suppose it is not good?

baibaratsky commented 9 years ago

For sure. Are BCMath and GMP set up correctly?

WebMoney Signer requires PHP 5.3 compiled with BCMath support. GMP can increase the performance, but is not required.

nelli7 commented 9 years ago

GMP wasn't set up, now both modules are set up and work, I called a few functions to check if they work, but still I have got these 000000...

baibaratsky commented 9 years ago
$signer = new Signer('392452635802', (\Yii::$app->basePath).'/folder/my.kwm', 'password');
var_export($signer);

What’s in output?

baibaratsky commented 9 years ago

@nelli7 please don't post your output, just say, are there big numbers or lots of nulls?

nelli7 commented 9 years ago

@baibaratsky , output is just one NULL and Payment error: signature is incorrect..

baibaratsky commented 9 years ago

var_export($signer); returns NULL? So, you need to check the installation of php-wmsigner (should be installed automatically by Composer).

nelli7 commented 9 years ago

I checked, it was installed, I've updated it, but there was nothing to install or update..

baibaratsky commented 9 years ago

There's something wrong with your installation or php configuration, I think. $signer shouldn't be NULL, it should contain an object.

nelli7 commented 9 years ago

I installed php like this sudo apt-get install php5-fpm php5-mysql , but I do not know how to configurate it then...

baibaratsky commented 9 years ago

You have to find out why a Signer object is not created.

baibaratsky commented 9 years ago

@nelli7 how are you doing? Is the issue still relevant?