Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[ljcom] r9564: LJSUP-6936 (Webmoney integration): check...

Committer: ailyin
LJSUP-6936 (Webmoney integration): checkpoint commit
A   trunk/cgi-bin/LJ/Client/WebMoney.pm
U   trunk/cgi-bin/LJ/Pay/Method/WebMoney.pm
U   trunk/cgi-bin/LJ/Pay/Payment.pm
U   trunk/ssldocs/shop/webmoney-callback.bml
U   trunk/templates/Shop/method/webmoney.tmpl
Added: trunk/cgi-bin/LJ/Client/WebMoney.pm
===================================================================
--- trunk/cgi-bin/LJ/Client/WebMoney.pm	                        (rev 0)
+++ trunk/cgi-bin/LJ/Client/WebMoney.pm	2010-09-30 06:32:14 UTC (rev 9564)
@@ -0,0 +1,71 @@
+package LJ::Client::WebMoney;
+use strict;
+use warnings;
+
+use XML::Simple qw();
+use WebMoney::WMSigner;
+
+sub call {
+    my ($class, $func, $xml) = @_;
+
+    $xml =~ s/\s+/ /g;
+    $xml =~ s/^\s+//g;
+    $xml =~ s/\s+$//g;
+
+    my $req = HTTP::Request->new;
+    $req->method('POST');
+    $req->uri("https://w3s.wmtransfer.com/asp/XML$func.asp");
+    $req->content($xml);
+
+    my $ua = LWP::UserAgent->new; #LJ::get_useragent( 'role' => 'webmoney-api' );
+    my $res = $ua->request($req);
+
+    unless ($res->is_success) {
+        warn 'webmoney connectivity error: ' . Data::Dumper::Dumper($res);
+        die 'webmoney connectivity error';
+    }
+
+    my $ret = $res->content;
+    return XML::Simple::XMLin($ret);
+}
+
+sub _sign {
+    my ($class, $str) = @_;
+
+    my $keyfile = $ENV{'LJHOME'} . '/bin/upgrading/webmoney-keyfiles/'
+                . $LJ::PAY_WEBMONEY_KEYFILE . '.kwm';
+
+    return WebMoney::WMSigner::sign(
+        $LJ::PAY_WEBMONEY_WMID,
+        $LJ::PAY_WEBMONEY_KEYFILE_PASSWORD,
+        $keyfile,
+        $str,
+    );
+}
+
+sub call_x7 {
+    my ($class, %params) = @_;
+
+    my $signature = $class->_sign(
+        $LJ::PAY_WEBMONEY_WMID .
+        $params{'test_wmid'} .
+        $params{'test_str'} .
+        $params{'test_sign'}
+    );
+
+    my $xml = qq{
+        <w3s.request>
+            <wmid>$LJ::PAY_WEBMONEY_WMID</wmid>
+            <sign>$signature</sign>
+            <testsign>
+                <wmid>$params{'test_wmid'}</wmid>
+                <plan>$params{'test_str'}</plan>
+                <sign>$params{'test_sign'}</sign>
+            </testsign>
+        </w3s.request>
+    };
+
+    return $class->call('ClassicAuth', $xml);
+}
+
+1;

Modified: trunk/cgi-bin/LJ/Pay/Method/WebMoney.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Method/WebMoney.pm	2010-09-30 02:39:04 UTC (rev 9563)
+++ trunk/cgi-bin/LJ/Pay/Method/WebMoney.pm	2010-09-30 06:32:14 UTC (rev 9564)
@@ -4,64 +4,12 @@
 use base qw(LJ::Pay::Method);
 
 use Digest::MD5 qw();
+use LJ::Client::WebMoney;
 
 sub code { 'webmoney' }
 
-sub checkout_should_redirect { 0 }
-
-sub checkout_render {
-    my ($class, $cart, $title, $body) = @_;
-
-    my $remote = LJ::get_remote();
-
-    # when a user checks out via webmoney we'll first display a confirmation
-    # page explaining what webmoney is and next steps they must follow. once
-    # the user confirms we'll redirect them to the appropriate URL
-
-    BML::set_language_scope('/pay/modify.bml');
-
-    my $amt = sprintf("%.02f", $cart->{amount});
-
-    $$title = $BML::ML{'.webmoney.title'};
-
-    my $format = BML::ml('.webmoney.whattodo.comment.format', {
-        orderid => $cart->get_cart_as_string,
-        user => $remote->user,
-    });
-
-    my $wmk_href = "wmk:payto?" .
-        "purse=$LJ::PAY_WEBMONEY_PURSE_ID&" .
-        "amount=$amt&" .
-        "desc=$format";
-
-    $$body =
-        "<?p <b>$BML::ML{'.webmoney.intro'}</b> p?>" .
-        "<?p $BML::ML{'.webmoney.whattodo'} p?>" .
-        "<ol>" .
-        "<li>" . BML::ml('.webmoney.whattodo.signin', {
-            'aopts' => "href='$LJ::PAY_WEBMONEY_SIGNUP_URL'"
-        }) . "</li>" .
-        "<li>" . BML::ml('.webmoney.whattodo.sendmoney', {
-            'amount' => "\$$amt WMZ",
-            'purseid' => $LJ::PAY_WEBMONEY_PURSE_ID
-        }) . "</li>" .
-        "<li>" . BML::ml('.webmoney.whattodo.comment', {
-            'orderid' => $cart->get_cart_as_string,
-            'sitename' => $LJ::SITENAMESHORT,
-        }) . "<br />" .
-        "\"$format\"." . " " .
-        BML::ml('.webmoney.whattodo.comment.format.link', {
-            aopts => "href='$wmk_href'"
-        }) . "</li>" .
-        "<li>$BML::ML{'.webmoney.whattodo.time'}</li>" .
-        "</ol>" .
-        "<?p $BML::ML{'.webmoney.thankyou'} p?>";
-
-    # redirection form
-    $$body .=
-        "<form method='get' action='$LJ::PAY_WEBMONEY_REDIR_URL' />" .
-        LJ::html_submit($BML::ML{'.btn.continue_webmoney'}) .
-        "</form>";
+sub suitable_for_additional_checks {
+    return LJ::is_enabled('webmoney');
 }
 
 sub get_page_params {
@@ -79,9 +27,14 @@
         'anum' => $cart->get_anum,
     );
 
+    my $form_action = BML::get_language() eq 'ru' ?
+        'https://merchant.webmoney.ru/lmi/payment.asp' :
+        'https://merchant.wmtransfer.com/lmi/payment.asp';
+
     return {
-        amt => $amt,
-        form_intro => $form_intro,
+        'amt'           => $amt,
+        'form_action'   => $form_action,
+        'form_intro'    => $form_intro,
     };
 }
 
@@ -92,6 +45,16 @@
         return uc(Digest::MD5::md5_hex($string)) eq $hash;
     }
 
+    if ($LJ::PAY_WEBMONEY_SIGN_METHOD eq 'SIGN') {
+        my $res = LJ::Client::WebMoney->call_x7(
+            'test_wmid' => '967909998006',
+            'test_str'  => $string,
+            'test_sign' => $hash,
+        );
+
+        return $res->{'testsign'}->{'res'} eq 'yes';
+    }
+
     warn "unsupported signature method $LJ::PAY_WEBMONEY_SIGN_METHOD";
     return;
 }

Modified: trunk/cgi-bin/LJ/Pay/Payment.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Payment.pm	2010-09-30 02:39:04 UTC (rev 9563)
+++ trunk/cgi-bin/LJ/Pay/Payment.pm	2010-09-30 06:32:14 UTC (rev 9564)
@@ -845,6 +845,16 @@
     }, undef, @binds, $self->get_payid);
 }
 
+sub mark_paid {
+    my ($self) = @_;
+
+    $self->update(
+        'used'      => 'N',
+        'mailed'    => 'N',
+        'daterecv'  => LJ::TimeUtil->mysql_time(),
+    );
+}
+
 ##############################################################################
 # Boolean methods
 #

Modified: trunk/ssldocs/shop/webmoney-callback.bml
===================================================================
--- trunk/ssldocs/shop/webmoney-callback.bml	2010-09-30 02:39:04 UTC (rev 9563)
+++ trunk/ssldocs/shop/webmoney-callback.bml	2010-09-30 06:32:14 UTC (rev 9564)
@@ -115,6 +115,8 @@
             foreach my $k (keys %payvars_map) {
                 $cart->payvar_add( $payvars_map{$k} => $form{$k} );
             }
+
+            $cart->mark_paid;
         }
     }
 }

Modified: trunk/templates/Shop/method/webmoney.tmpl
===================================================================
--- trunk/templates/Shop/method/webmoney.tmpl	2010-09-30 02:39:04 UTC (rev 9563)
+++ trunk/templates/Shop/method/webmoney.tmpl	2010-09-30 06:32:14 UTC (rev 9564)
@@ -1,5 +1,5 @@
 <div class="b-wmpay">
-<form action="https://merchant.webmoney.ru/lmi/payment.asp" method="post">
+<form action="<TMPL_VAR form_action>" method="post">
 <TMPL_VAR form_intro>
 
 <p>The cost of your order is <TMPL_VAR amt> WMZ.</p>

Tags: andy, bml, ljcom, pm, tmpl
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments