October 14th, 2009
Program extract of the bill in system WebMoney
So now the number of Internet – shops actively grows, and many of them sell the electronic goods (programs, patterns of sites) or render electronic services (conducting statistics of a site, a bulletin board, paid catalogues), and to get{start} to itself own Internet – shop it is possible. So now the number of Internet – shops actively grows, and many of them sell the electronic goods (programs, patterns of sites) or render electronic services (conducting statistics of a site, a bulletin board, paid catalogues), and to get{start} to itself own Internet – shop it is possible.
Also there is to that a weight of examples – there are many the fine sites, selling can be only one program or the electronic book. The site began with this http://www.zahodi-ka.ru, originally created by me for sale for the symbolical sum of a self-made toy. Sale has been organized as at all similar projects – on a page complex{difficult} process of payment which result should become a license key from a toy undersigned. Under indications of the counter of uploadings it was possible to understand, that a toy actively swing, however for half-year to me there has come only one letter with the similar maintenance{contents}: ” Give, please, a key from a toy. From you strongly will not decrease, if not you will receive superfluous 10 roubles “. (literally the text of the letter I shall not recollect, but there was something similar). I have certainly given a key, if ask, but the conclusion for itself has made, that nobody has bought just because to pay it was simple laziness.
So after that you, I hope, have understood all importance of creation of the convenient user interface. We now also shall engage in it, namely a spelling of the program, avtomatizirujuhhej process of payment of the goods and delivery to his{its} user. First it is necessary to present, as there will be a process and what the program for it is required to write.
Process:
* The user comes on page, enters the WMID (the identifier received at registration in system WebMoney), presses the button “to pay” and to him there comes the bill for payment.
* The user pays under the bill and passes under the link specified in parameters of the bill and receives the goods.
Hence it will need 2 programs:
* The program of data processing of the form and an extract of the bill on WMID the user.
* The program of check of payment of the bill and delivery of the goods.
For an extract of the bill on WMID the user it is necessary to execute following https search: https: // w3s.webmoney.ru/asp/Invoice.asp? SL=LoginOfStores and SP=PurseOfStores and CL=LoginOfCust and IN=OrderID and D=Desc and AD=InvAddress and A=Amount and E=Experation and P=Period and RN=RequestN and SS=SignStr (this inofrmacija is resulted on a site of system WebMoney, however if the problem{task} was solved so simply, I would not write this clause{article}). Now about each parameter is more detailed:
SL=LoginOfStores – the WM-identifier of a web-resource (simply register the new user in system WebMoney for reception of payments from a site and specify it{him} WMID);
SP=PurseOfStores – a purse of a Web-resource (number{room} of a purse on which payments – a purse of the user with WMID from the first item{point} will be made);
CL=LoginOfCust – the WM-identifier of the buyer (this parameter the user specifies, the program obtains the data from the form);
IN=OrderID – number{room} of the bill (number{room} of the order) on a Web-resource (in shop). Number{room} is generated by the program (1) independently and stored{kept} in base of a Web-resource (shop, service) – under this number{room} further will be will be defined{determined} a status of the bill (it is paid whether or not). (number{room} should be an integer);
D=Desc – the description of the goods for which the bill leaves. The parameter should be line from 0 up to 255 symbols;
AD=InvAddress – the address of delivery of the goods. The parameter should be line from 0 up to 255 symbols (we shall write here the link on which the user can receive the goods. It will be the link to the program (2) to which parameter IN=OrderID will be passed);
A=Amount – the sum of the bill. The given parameter is formed by the program (1). The parameter should be number with a floating point (a separator – a point);
E=Experation – validity of the bill in days (an integer from 0 up to 255);
P=Period – validity of the patronage of the transaction. The parameter is formed by the program (1.) (the maximal term of the patronage of the transaction at payment of the bill if to specify here 0 the bill will not have term of the patronage);
RN=RequestN – this parameter is unique growing number. The parameter is formed by the program (1) and should be always more than the same parameter specified in the previous search. It is the best way to form this parameter of the current year, month, day, hour, minute, second and the 100-th seconds. (should be integer 16-ti digit value);
SS=SignStr – digital the signature of search. He guarantees what your Web-resource has billed.
By preparation https search the Basic problem is formation SS=SignStr. Line PlanStr as the sum of parameters OrderID, LoginOfCust, PurseOfStores, Amount, Desc, InvAddress, Period, Experation, RequestN, described above and precisely in the same order first should be generated. After that it is necessary to make a line of digital signature SignStr of a line of signature PlanStr, for this purpose special module WMSigner to which on an input{entrance} line PlanStr moves is used, and he returns SignStr.
Initial codes of the module can be downloaded, perejdja under the link: http://download.webmoney.ru/WMSigner.zip, then the module should be compiled under that operational system on which your site works. It is possible to send this archive of administration of your hosting and to ask to compile, and it is possible to try success itself, for this purpose we shall create a file poehali.pl with the following code:
*!/usr/bin/perl
system (‘ g ++ cmdbase.cpp crypto.cpp md4.cpp rsalib1.cpp signer.cpp wmsigner.cpp ‘);
print “Content-type:text/html\n\n”;
print ” And nevertheless she spins! “;
Now we shall create a folder (well, for example wm) in the root of a site and we shall copy there our script and contents of archive WMSigner. Access rights to our script are necessary for putting 711. Now from a line of a browser it is necessary to start a script poehali.pl (to write down a line, for example http://www.zahodi-ka.ru/wm/poehali.pl) and to wait the answer of a script. If on the server there is compiler G ++ and necessary the module in a folder wm after start there is a file a.out which needs to be renamed in wmsigner (small letters).
When the module is available, it is possible to start a spelling of the program (1) which and will cause it{him}. In the documentation on a site of system WebMoney the call is carried out with the help of function open2, however such variant works not always, therefore we will cause with the help of function system. We shall create the program (we shall name her{it} wschet.pl):
*!/usr/bin/perl
sub dopprobelz * function of addition of a line in zero in the beginning
{my ($str) = _ [0];
my ($len) = _ [1]; my $delta = $ len-length ($str);
my $hwost = “;
for (my ($a) =0; $a <$delta; $a ++) {$hwost = $ hwost. ‘ 0 ‘;};
$str = $ hwost. $ str; return $str;
};
* Connection of modules
use FileHandle;
use IPC:: Open2;
use CGI;
use Socket;
use LWP:: UserAgent;
* The task of parameters of search
* Here specify the data
$OrderID = ‘ 999 ‘; * number{room} of the bill on your site
$PurseOfStores = ‘ Z406593169293 ‘; * a purse of a site
$LoginOfStores = ‘ 321373645120 ‘; * WMID a site
$LoginOfCust = ‘ 083872782699 ‘; * WMID the buyer, we shall set as a constant
$InvAddress = ‘ INVADDRESS ‘; * the address
$Amount = ‘ 10 ‘; *????? bills which the buyer should pay
$Desc = ‘ DESC ‘; * the description
$Period = ‘ 0 ‘; *??«¬ the patronage of the transaction
$Experation = ‘ 3 ‘; *??«¬ actions of the bill – 3 days
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =localtime (time ());
$RequestN = (1900 + $ year) .dopprobelz ($mon, 2);
$RequestN = $ RequestN.dopprobelz ($mday, 2) .dopprobelz ($hour, 2);
$RequestN = $ RequestN.dopprobelz ($min, 2) .dopprobelz ($sec, 2) .dopprobelz ($sec, 2);
$PlanStr = ” $ OrderID$LoginOfCust$PurseOfStores$Amount “;
$PlanStr = $ PlanStr. ” $ Desc$InvAddress$Period$Experation$RequestN “;
print ” Content-Type: text/html\n\n “;
print ” the Line of the signature \ $PlanStr: $PlanStr <br> <br> <br> “;
* A call of module WMSigner
pipe (IN, OUT); * creation of a liaison channel (you write in OUT, you read from IN)
OUT-> autoflush (1);
$pid = open (CHILD, ” | – “); * division into 2 processes
*??n??????? input doch. Percents with descriptor CHILD
if ($pid! = 0) {** if the given stream – the parent
close (OUT); * for Parent OUT it is not necessary, will write through CHILD
print CHILD $PlanStr. “\004\r\n “; * transfer of parameters to the descendant
close (CHILD); * transfer is finished, the descriptor is not necessary
$SignStr = $_ while (<IN>); * Data acquisition from a clone
close (IN);
waitpid ($pid, 0);
} else {**** if a clone (descendant)
close (IN);
open (STDOUT, “> and =OUT “); * replacement of a standard conclusion on deskr. OUT
close (OUT);
system (‘./wmsigner ‘); * start of module WMSigner (will return the data in OUT)
exit;};
print ” the Digital signature (it is returned WMSigner \’om): $SignStr <br> <br> <br> “;
$W3sUrl = ” https: // w3s.webmoney.ru/asp/Invoice.asp? SL = $ LoginOfStores and “;
$W3sUrl = $ W3sUrl. ” SP = $ PurseOfStores*CL = $ LoginOfCust*IN = $ OrderID*D = $ Desc and “;
$W3sUrl = $ W3sUrl. ” AD = $ InvAddress*A = $ Amount*E = $ Experation*P = $ Period and “;
$W3sUrl = $ W3sUrl. ” RN = $ RequestN*SS = $ SignStr “;
print ” HTTPS search to system: <br> “. $W3sUrl. ” <br> <br> <br> “;
$ua2 = LWP:: UserAgent-> new;
$res2 = $ ua2-> get ($W3sUrl);
$buf = $ res2-> content;
print ” the Answer of system: <br> “. $buf;
* Further it is necessary to make analysis of the buffer and recording of the bill for a database of shop
To this program it is necessary to put in a folder the compiled module WMSigner (access rights 711), a backup copy of keys (at start Keeper will request to create a backup copy kjuchej and to set the password for this copy, after creation copy a file *.kwm on a site to the program wschet.pl and rename it{him} in keys.kwm, expose to him access rights 440) and a file wmsigner.ini (access rights 440) following maintenance{contents}:
WMID
pass
./keys.kwm
Where WMID – the identifier of shop, pass – the password from a backup copy of keys./keys.kwm – a way to a file of keys.
Now we shall in details disassemble a way of start of the module wmsigner from our program. For a call of the module function system () which connects streams of input-output of caused process with streams VV of the program causing process is used, that is the data transferred{handed} to the causing program from the outside will receive and started system () process and the data returned by process will be deduced{removed} by function there, where also the data of the causing program (in our case in a browser of the user that is undesirable). For division of streams VV our program all over again creates a clone, then this clone causes process WMSigner and obtains from him{it} the data, and the basic program obtains the data already from the clone, process of creation of a clone and redefinition of his{its} standard descriptor of input on CHILD is realized with the help of function $pid = open (CHILD, ” | – “).
If the module will give out a mistake-3, know, that in wmsigner.ini you have specified the password not from a backup copy of keys or have copied not a backup copy of keys.
That’s all, now it is necessary to adapt only signs under the problem{task}, and in following clause{article} I shall tell as to organize check, whether the bill has been paid.