Revision 358 (by ahitrov, 2013/06/11 08:56:08) Initial plugin import
<?xml version="1.0" encoding="UTF-8"?>
<MNT_RESPONSE>
	<MNT_ID><% $MNT_ID %></MNT_ID>
	<MNT_TRANSACTION_ID><% $MNT_TRANSACTION_ID %></MNT_TRANSACTION_ID>
	<MNT_RESULT_CODE><% $reply_code %></MNT_RESULT_CODE>
	<MNT_SIGNATURE><% $reply_md5 %></MNT_SIGNATURE>
<%doc>
        <MNT_ATTRIBUTES>
                <ATTRIBUTE>
                        <KEY></KEY>
                        <VALUE></VALUE>
                </ATTRIBUTE>
        </MNT_ATTRIBUTES>
</%doc>
</MNT_RESPONSE>
<%once>

    use Digest::MD5;

</%once>
<%args>

	$MNT_ID			=> undef
	$MNT_TRANSACTION_ID	=> undef
	$MNT_OPERATION_ID	=> undef
	$MNT_AMOUNT		=> ''
	$MNT_CURRENCY_CODE	=> undef
	$MNT_TEST_MODE		=> 0
	$MNT_SIGNATURE		=> undef
	$MNT_USER		=> undef
	$MNT_CORRACCOUNT	=> undef
	$MNT_CUSTOM1		=> undef
	$MNT_CUSTOM2		=> undef
	$MNT_CUSTOM3		=> undef

</%args>
<%init>

    warn Dumper \%ARGS		if $DEBUG;
    unless ( $MNT_ID && $MNT_TRANSACTION_ID && $MNT_OPERATION_ID && $MNT_AMOUNT && $MNT_CURRENCY_CODE ) {
	$m->out('FAIL');
	return;
    }

    my $str = $MNT_ID . $MNT_TRANSACTION_ID . $MNT_OPERATION_ID . $MNT_AMOUNT . $MNT_CURRENCY_CODE . $MNT_TEST_MODE . $state->{monetaru}->{moneta_sig_code};
    my $md5 = Digest::MD5::md5_hex ( $str );
    unless ( $MNT_SIGNATURE eq $md5 ) {
	$m->out('FAIL');
	return;
    }

    my $reply_code;
    my $last = $keeper->{monetaru}->check( $MNT_TRANSACTION_ID );
    if ( ref $last ) {
	my $sum = sprintf("%.2f", $last->sum);
	if ( $last->name eq 'cancel' ) {
		$reply_code = 500;
	} elsif ( $last->name eq 'suspend' ) {
		$reply_code = 500;
	}
    } else {
	$reply_code = 500;
    }

    unless ( $reply_code ) {
	my ($obj) = $keeper->get_documents(
			class	=> 'monetaru::Transaction',
			operation_id	=> $MNT_OPERATION_ID,
			order_id	=> $MNT_TRANSACTION_ID,
			limit	=> 1,
		);

	unless ( $obj ) {
		$obj = monetaru::Transaction->new( $keeper );
		$obj->status( $MNT_TEST_MODE || 0 );
		$obj->account_id( $MNT_ID );
		$obj->order_id( $MNT_TRANSACTION_ID );
		$obj->operation_id( $MNT_OPERATION_ID );
		$obj->sum( $MNT_AMOUNT );
		$obj->currency_code( $MNT_CURRENCY_CODE );
		$obj->account_user( $MNT_USER );
		$obj->account_corr( $MNT_CORRACCOUNT );
		$obj->payment_system( $ARGS{'paymentSystem.unitId'} );
		$obj->name( $MNT_CUSTOM1 );
		$obj->custom1( $MNT_CUSTOM1 );
		$obj->custom2( $MNT_CUSTOM2 );
		$obj->custom3( $MNT_CUSTOM3 );
		$obj->store;
	}
	if ( $obj->id ) {
		$reply_code = 200;
	} else {
		$reply_code = 100;
	}
    }

    $str = $reply_code . $MNT_ID . $MNT_TRANSACTION_ID . $state->{monetaru}->{moneta_sig_code};
    my $reply_md5 = Digest::MD5::md5_hex ( $str );

</%init>