Get transparent object-oriented interaction with WebMoney API.
If you just need to sign your requests to the API, use WebMoney Signer, a native PHP implementation of the WMSigner authentication module.
The library requires PHP 5.3 compiled with cURL extension (but you can override cURL dependencies).
Install Composer:
curl -sS https://getcomposer.org/installer | php
Add the php-webmoney dependency:
php composer.phar require baibaratsky/php-webmoney:0.18.*
There are more usage examples in the project wiki.
require_once(__DIR__ . '/vendor/autoload.php'); // Require autoload file generated by composer
use baibaratsky\WebMoney;
use baibaratsky\WebMoney\Api\X\X9\Request;
use baibaratsky\WebMoney\Api\X\X9\Response;
use baibaratsky\WebMoney\Request\Requester\CurlRequester;
use baibaratsky\WebMoney\Signer;
// If you don’t want to use the WM root certificate to protect against DNS spoofing, pass false to the CurlRequester constructor
$webMoney = new WebMoney\WebMoney(new CurlRequester);
$request = new Request;
$request->setSignerWmid('YOUR WMID');
$request->setRequestedWmid('REQUESTED WMID');
$key = 'FULL PATH TO THE KEY FILE';
// or key is a data string from DB, cache, etc.
// $key = getKeyData();
$request->sign(new Signer('YOUR WMID', $key, 'KEY FILE PASSWORD'));
// You can access the request XML: $request->getData()
if ($request->validate()) {
/** @var Response $response */
$response = $webMoney->request($request);
// The response from WebMoney is here: $response->getRawData()
if ($response->getReturnCode() === 0) {
echo $response->getPurseByName('Z000000000000')->getAmount();
} else {
echo 'Error: ' . $response->getReturnDescription();
}
}
In case of authentication with a Light certificate, pass Request::AUTH_LIGHT
to the request constructor
and use lightAuth()
instead of sign()
.
require_once(__DIR__ . '/vendor/autoload.php'); // Require autoload file generated by composer
use baibaratsky\WebMoney;
use baibaratsky\WebMoney\Api\X\X9\Request;
use baibaratsky\WebMoney\Api\X\X9\Response;
use baibaratsky\WebMoney\Request\Requester\CurlRequester;
// If you don’t want to use the WM root certificate to protect against DNS spoofing, pass false to the CurlRequester constructor
$webMoney = new WebMoney\WebMoney(new CurlRequester);
$request = new Request(Request::AUTH_LIGHT);
$request->setRequestedWmid('REQUESTED WMID');
$request->lightAuth('FULL PATH TO THE CERTIFICATE FILE', 'FULL PATH TO THE CERTIFICATE KEY', '(OPTIONAL) PASSWORD');
// You can access the request XML: $request->getData()
if ($request->validate()) {
/** @var Response $response */
$response = $webMoney->request($request);
// The response from WebMoney is here: $response->getRawData()
if ($response->getReturnCode() === 0) {
echo $response->getPurseByName('Z000000000000')->getAmount();
} else {
echo 'Error: ' . $response->getReturnDescription();
}
}