parser

Написать ответ на текущее сообщение

 

 
   команды управления поиском

Класс для работы с Webmoney

Азат Разетдинов 14.12.2007 14:51

Таблица для хранения платежей:
CREATE TABLE `wmtransfer` (
 `wmtransfer_id` bigint(20) unsigned NOT NULL auto_increment,
 `invoice_id` bigint(20) unsigned NOT NULL default '0',
 `order_id` int(10) unsigned NOT NULL default '0',
 `dt` datetime NOT NULL default '0000-00-00 00:00:00',
 `sum` decimal(9,2) unsigned NOT NULL default '0.00',
 `mode` tinyint(1) unsigned NOT NULL default '0',
 `payee_purse` varchar(13) NOT NULL default '',
 `payer_purse` varchar(13) NOT NULL default '',
 `payer_wmid` varchar(12) NOT NULL default '',
 `paymer_number` varchar(255) NOT NULL default '0',
 `paymer_email` varchar(31) NOT NULL default '',
 `telepat_phone` varchar(31) NOT NULL default '',
 `telepat_order_id` varchar(255) NOT NULL default '0',
 PRIMARY KEY  (`wmtransfer_id`)
) TYPE=MyISAM
Собственно, класс. Причесывал для публикации вслепую, поэтому могут быть мелкие баги.
@CLASS
Webmoney



@auto[]
$tCheck[^table::create{name
LMI_PAYEE_PURSE
LMI_PAYMENT_AMOUNT
LMI_PAYMENT_NO
LMI_MODE
LMI_SYS_INVS_NO
LMI_SYS_TRANS_NO
LMI_SYS_TRANS_DATE
LMI_SECRET_KEY
LMI_PAYER_PURSE
LMI_PAYER_WM}]
#end @auto[]



@create[hParams]
$oSql[$hParams.oSql]
$sSecretKey[$hParams.sSecretKey]
#end @create[]



@getTransfer[hParams]
$result[^oSql.table{
	SELECT
		wmtransfer_id AS id,
		invoice_id,
		order_id,
		dt,
		sum,
		mode,
		payee_purse,
		payer_purse,
		payer_wmid,
		paymer_number,
		paymer_email,
		telepat_phone,
		telepat_order_id
	FROM
		wmtransfer
	WHERE
		1
		^if(def $hParams.transfer_id){
			AND wmtransfer_id = ^math:round(^hParams.transfer_id.double(0))
		}
}]
#end @getTransfer[]



@beforeInsert[hData][sHash]
$hData.LMI_SECRET_KEY[$sSecretKey]
$sHash[^math:md5[^tCheck.menu{$hData.[$tCheck.name]}]]
^hData.delete[LMI_SECRET_KEY]
^if($sHash ne ^hData.LMI_HASH.lower[]){
	^throw[Webmoney;$hData.LMI_HASH;Wrong hash, maybe hacking attempt]
}
#end @beforeInsert[]



@insertTransfer[hData]
^self.beforeInsert[$hData]
^oSql.void{
	INSERT IGNORE INTO wmtransfer (
		wmtransfer_id,
		invoice_id,
		order_id,
		dt,
		sum,
		mode,
		payee_purse,
		payer_purse,
		payer_wmid,
		paymer_number,
		paymer_email,
		telepat_phone,
		telepat_order_id
	) VALUES (
		^rem{ wmtransfer_id might exceed int limit }
		^math:round(^hData.LMI_SYS_TRANS_NO.double(0)),
		^math:round(^hData.LMI_SYS_INVS_NO.double(0)),
		^hData.LMI_PAYMENT_NO.int(0),
		'$hData.LMI_SYS_TRANS_DATE',
		^hData.LMI_PAYMENT_AMOUNT.double(0),
		^hData.LMI_MODE.int(0),
		'$hData.LMI_PAYEE_PURSE',
		'$hData.LMI_PAYER_PURSE',
		'$hData.LMI_PAYER_WM',
		'$hData.LMI_PAYMER_NUMBER',
		'$hData.LMI_PAYMER_EMAIL',
		'$hData.LMI_TELEPAT_PHONENUMBER',
		'$hData.LMI_TELEPAT_ORDERID'
	)
}
#end @insertTransfer[]



@beforeUpdate[hData]
^self.beforeInsert[$hData]
#end @beforeUpdate[]



@updateTransfer[hData]
^self.beforeUpdate[$hData]
^oSql.void{
	UPDATE
		wmtransfer
	SET
		invoice_id = ^math:round(^hData.LMI_SYS_INVS_NO.double(0)),
		order_id = ^hData.LMI_PAYMENT_NO.int(0),
		dt = '$hData.LMI_SYS_TRANS_DATE',
		sum = ^hData.LMI_PAYMENT_AMOUNT.double(0),
		mode = ^hData.LMI_MODE.int(0),
		payee_purse = '$hData.LMI_PAYEE_PURSE',
		payer_purse = '$hData.LMI_PAYER_PURSE',
		payer_wmid = '$hData.LMI_PAYER_WM',
		paymer_number = '$hData.LMI_PAYMER_NUMBER',
		paymer_email = '$hData.LMI_PAYMER_EMAIL',
		telepat_phone = '$hData.LMI_TELEPAT_PHONENUMBER',
		telepat_order_id = '$hData.LMI_TELEPAT_ORDERID'
	WHERE
		^rem{ wmtransfer_id might exceed int limit }
		wmtransfer_id = ^math:round(^hData.LMI_SYS_TRANS_NO.double(0))
}
#end @updateTransfer[]



@htmlWebmoneyForm[hData]
<form action='https://merchant.webmoney.ru/lmi/payment.asp' method='post'>
<input name='LMI_PAYEE_PURSE' type='hidden' value='$hData.payee_purse'/>
<input name='LMI_PAYMENT_AMOUNT' type='hidden' value='$hData.sum'/>
<input name='LMI_PAYMENT_NO' type='hidden' value='$hData.order_id'/>
<input name='LMI_PAYMENT_DESC' type='hidden' value='$hData.purpose'/>
<input name='LMI_SIM_MODE' type='hidden' value='$hData.mode'/>
<input name='LMI_SUCCESS_URL' type='hidden' value='$hData.success_url'/>
<input name='LMI_SUCCESS_METHOD' type='hidden' value='^if($hData.success_method eq GET){0;1}'/>
<input name='LMI_FAIL_URL' type='hidden' value='$hData.fail_url'/>
<input name='LMI_FAIL_METHOD' type='hidden' value='^if($hData.fail_method eq GET){0;1}'/>
<table class='form'>
<tr><td>Номер заказа:</td><td>$hData.order_id</td></tr>
<tr><td>Сумма для оплаты:</td><td>$hData.sum $hData.currency</td></tr>
<tr><td>Назначение платежа:</td><td>$hData.purpose</td></tr>
<tr><td></td><td><input type='submit' value='Далее &gt;&gt;'/></td></tr>
</table>
</form>
#end @htmlWebmoneyForm[]