-
Notifications
You must be signed in to change notification settings - Fork 32
Andrei Baibaratsky edited this page Nov 26, 2015
·
7 revisions
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\X2;
$webMoney = new WebMoney(new CurlRequester);
$request = new X2\Request;
$request->setSignerWmid('YOUR WMID');
$request->setTransactionExternalId(1); // Unique ID of the transaction in your system
$request->setPayerPurse('YOUR PURSE');
$request->setPayeePurse('PAYEE PURSE');
$request->setAmount(10.23); // Payment amount
$request->setDescription('Test payment');
$request->sign(new Signer('YOUR WMID', 'FULL PATH TO KEY FILE', 'KEY FILE 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;
}
}