📜 ⬆️ ⬇️

Automated acceptance of webmoney payments on your site.

0. Introduction

It's no secret that lately webmoney gained enough popularity to become one of the most convenient and affordable means for cashless payments via the Internet. Replenish the balance of your mobile, pay for the purchase of goods in the web store - all this can be done using webmoney.

I would like to tell you in several ways how you can arrange to receive payment for any goods or services on your website with electronic currency webmoney. This, by the way, is not as difficult as it might seem at first glance!

1. Merchant WebMoney Transfer
')
This is the tool that developers have provided to us to automate making payments. Merchant WebMoney Transfer is a set of interfaces for interacting with the WebMoney system. Below I will try to briefly describe them.

1.1 Web Merchant Interface is the easiest way to organize payment for webmoney, based on a specially formed form that simply sends the user and his data to the webmoney site, where he performs the basic actions to pay for funds.
All that is needed to receive payment in this way is to place on your site 3 pages - a page with a form for payment, a page of a successful payment and a page for a failed payment. Then you set up the server-side for payment processing once and enjoy the cash flow pouring into your pocket =) A more detailed description of this interface is available here: https://merchant.webmoney.ru/conf/guide_simple.asp .

1.2 Click & Buy Merchant Interface - This interface allows the buyer to pay webmoney with one click of the mouse using WM Keeper. The point is this: the customer clicks on a special webmoney link (of the wmk type: paylink ...) and the entire payment process takes place in WM Keeper. A more detailed description of this interface is available here https://merchant.webmoney.ru/conf/guide_pci.asp .

1.3 WM Automation Interface - Delicious =) This is a set of XML interfaces (15 pieces, from X1 to X15) based on requests to the webmoney web server using the https protocol in XML format using a special authentication module for WM Keeper Classic keys
or standard x.509 certificates (WM Keeper Light certificates). Using these interfaces, you can perform a wide range of actions in your wallet, for example:

- Bill the customer (X1)
- Receipt of history and verification of payment of bills (X4)
- Getting balance (X9)

and much more interesting. Actually, I would like to dwell on this interface, or rather, on this set of interfaces.

2.XML - the choice of professionals!

2.1 Task setting - Once I needed to implement the reception and issuance of WM on the site, automatically, with logging the movement of money, in order to avoid incidents. To ensure full automation of work, you need to use WM Automation Interface, since other types of interfaces will not give us the proper functionality.

2.2 Tool - We will not invent bicycles, but use a ready-made library called WMXI. She lives at my-tools.net/wmxi . For its successful operation, the server must meet the following requirements: BCMath or GMP, MHash or Hash, CURL, MBString, Enabled XML. To check whether your hosting meets these conditions, you can use the check.php utility from the WMXI suite.

2.3 Account statement. To begin with, let's carry out the simplest task: issuing an invoice from the store to a customer. For these purposes, an interface X1 is provided, and we will use it. However, one should not forget that invoice issuance does not guarantee that it will be paid =) So, it will be necessary to check the invoice payment later.

Here is the code itself:
<?php
//
include_once("wmxi/wmsigner.php");
include_once("wmxi/wmxi.php");
include_once("wmxi/wmxiparser.php");
// WMXI. :
// ,
//, . UTF-8
$wmxi = new WMXI(realpath("../WebMoneyCA.crt"), DOC_ENCODING);
//
// Webmoney Keeper Classic. :
//WMID -
//
// 164
//
$wmxi->Classic("000000000000", "password", "../keys/000000000000.kwm");
//
$parser = new WMXIParser();
//,
$response = $wmxi->X1(
$wm_transfer, // ; .
$_POST[wmid], //wmid
"Z999988887777", //
floatval($_POST[money]), //
" MYSITE.RU", // 0 255 ;
"http://mysite.ru", // 0 255 ;
0, // 0 255; 0 -
1 // 0 255; 0 -
);
// . :
//XML-
//, . UTF-8
$structure = $parser->Parse($response, DOC_ENCODING);
// .
// , =)
$transformed = $parser->Reindex($structure, true);
// == 0 ( )
if($structure["w3s.response"]["retval"] == 0)
{
$transformed["w3s.response"]["reqn"]; // WM
$transformed["w3s.response"]["invoice"]["orderid"]; // ,
echo " !";
}
else echo $structure["w3s.response"]["retdesc"]; // , .
?>


That's all =). Account issued, it remains only to wait for the money. Only in appearance it seems difficult, in fact, everything is super-simple!

2.4 Checking account status. The invoice is issued, and how to find out paid or not. This is where the X4 interface comes in. It allows you to get the history of invoices issued on the wallet, as well as check the payment of the invoice, which is what we need. Let's see how to do it:
<?php
//
include_once("wmxi/wmsigner.php");
include_once("wmxi/wmxi.php");
include_once("wmxi/wmxiparser.php");
// WMXI. :
// ,
//, . UTF-8
$wmxi = new WMXI(realpath("../WebMoneyCA.crt"), DOC_ENCODING);
//
// Webmoney Keeper Classic. :
//WMID -
//
// 164
//
$wmxi->Classic("000000000000", "password", "../keys/000000000000.kwm");
//
$parser = new WMXIParser();
//,
$response = $wmxi->X4(
"Z999988887777",//
0,// > 0, WM
$wm_transfer,// ;
date("Ymd H:i:s", time()-86400),//
date("Ymd H:i:s", time())//
);
// . :
//XML-
//, . UTF-8
$structure = $parser->Parse($response, DOC_ENCODING);
// .
// , =)
$transformed = $parser->Reindex($structure, true);
// == 0 ( )
if($structure["w3s.response"]["retval"] == 0)
{
$state = $transformed["w3s.response"]["outinvoices"]["outinvoice"]["state"];
switch($state)
{
case 0:
echo " ";
break;
case 1:
echo " ";
break;
case 2:
echo " ";
break;
case 3:
echo "";
break;
}
else echo $structure["w3s.response"]["retdesc"]; // , .
?>

That's all. It remains only to realize the accounting statement and payment of bills in your database, and a full-fledged web store is ready!

3.That is. I hope I’ve got an easy way to explain the principles of automatic work in WM accounts, despite the fact that this is my first article on programming. I will be glad to your questions, which I will be happy to answer!

Source: https://habr.com/ru/post/53805/


All Articles