Skip to content
Andrei Baibaratsky edited this page Jan 27, 2015 · 2 revisions

Links

Usage

require_once(__DIR__ . '/vendor/autoload.php'); // Require autoload file generated by composer

use baibaratsky\WebMoney\WebMoney;
use baibaratsky\WebMoney\Signer;
use baibaratsky\WebMoney\Request\Requester\CurlRequester;
use baibaratsky\WebMoney\Api\X\X19\Request;
use baibaratsky\WebMoney\Api\X\X19\Response;

$webMoney = new WebMoney(new CurlRequester);

$request = new Request;
$request->setSignerWmid('YOUR WMID');
$request->setOperationType(Request::TYPE_EMONEY);
$request->setOperationDirection(Request::DIRECTION_INPUT);
$request->setOperationPurseType(Request::PURSE_WMZ);
$request->setOperationAmount(123.45);
$request->setOrderId(18); // Order ID in your system
$request->setUserFirstName('John');
$request->setUserLastName('Snow');
$request->setUserEMoneyName(Request::EMONEY_PP);
$request->setUserEMoneyId('john.snow@example.com');

$request->sign(new Signer('YOUR WMID', 'FULL PATH TO KEY FILE', 'KEY FILE PASSWORD'));

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

    if ($response->getReturnCode() === 0) {
        echo 'OK';
    } else {
        echo 'Error: ' . $response->getReturnDescription();
    }
} else {
    echo 'Request errors: ' . PHP_EOL;
    foreach ($request->getErrors() as $error) {
        echo ' - ' . $error . PHP_EOL;
    }
}
Clone this wiki locally