Bug 16129: Remove URL::Encode dependency
authorTomas Cohen Arazi <tomascohen@theke.io>
Tue, 22 Mar 2016 20:17:59 +0000 (17:17 -0300)
committerBrendan A Gallagher <brendan@bywatersolutions.com>
Fri, 1 Apr 2016 18:48:18 +0000 (18:48 +0000)
This patch makes the PayPal integration feature independent from the
URL::Encode library, which is absent in some supported distributions.

It uses the URI package which is already a Koha dependency.

To test:
- Apply the patch
- Notice there are no deps for URL::Encode
- Follow the steps from the original patch
=> SUCCESS: It works as expected
- Sign-off :-D

Note: I deleted the line in which $amount_to_pay was url-encoded, because that's
one of the things query_form does (and the variable is only used as a parameter to it).

Sponsored-by: ByWater Solutions
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Brendan A Gallagher <brendan@bywatersolutions.com>
C4/Installer/PerlDependencies.pm
opac/opac-account-pay-paypal-return.pl
opac/opac-account-pay.pl

index 5e2f22f..0d6363f 100644 (file)
@@ -777,11 +777,6 @@ our $PERL_DEPS = {
         'required' => '1',
         'min_ver'  => '1.10',
     },
-    'URL::Encode' => {
-        'usage'    => 'PayPal',
-        'required' => '0',
-        'min_ver'  => '0.03',
-    },
     'WWW::YouTube::Download' => {
         'usage'    => 'HTML5Media streaming from YouTube',
         'required' => '0',
index 1823d2f..64dcfdd 100755 (executable)
@@ -24,7 +24,7 @@ use utf8;
 use CGI;
 use HTTP::Request::Common;
 use LWP::UserAgent;
-use URL::Encode qw(url_params_mixed);
+use URI;
 
 use C4::Auth;
 use C4::Output;
@@ -85,10 +85,13 @@ my $response = $ua->request( POST $url, $nvp_params );
 
 my $error = q{};
 if ( $response->is_success ) {
-    my $params = url_params_mixed( $response->decoded_content );
 
-    if ( $params->{ACK} eq "Success" ) {
-        $amount = $params->{PAYMENTINFO_0_AMT};
+    my $urlencoded = $response->content;
+    my %params = URI->new( "?$urlencoded" )->query_form;
+
+
+    if ( $params{ACK} eq "Success" ) {
+        $amount = $params{PAYMENTINFO_0_AMT};
 
         my $accountlines_rs = Koha::Database->new()->schema()->resultset('Accountline');
         foreach my $accountlines_id ( @accountlines ) {
index 8dfdfcd..cb1545c 100755 (executable)
@@ -24,7 +24,6 @@ use Modern::Perl;
 use CGI;
 use HTTP::Request::Common;
 use LWP::UserAgent;
-use URL::Encode qw(url_encode url_params_mixed);
 use URI;
 
 use C4::Auth;
@@ -64,8 +63,6 @@ my $error = 0;
 if ( $payment_method eq 'paypal' ) {
     my $ua = LWP::UserAgent->new;
 
-    my $amount = url_encode($amount_to_pay);
-
     my $url =
       C4::Context->preference('PayPalSandboxMode')
       ? 'https://api-3t.sandbox.paypal.com/nvp'
@@ -74,7 +71,7 @@ if ( $payment_method eq 'paypal' ) {
     my $opac_base_url = C4::Context->preference('OPACBaseURL');
 
     my $return_url = URI->new( $opac_base_url . "/cgi-bin/koha/opac-account-pay-paypal-return.pl" );
-    $return_url->query_form( { amount => $amount, accountlines => \@accountlines } );
+    $return_url->query_form( { amount => $amount_to_pay, accountlines => \@accountlines } );
 
     my $cancel_url = URI->new( $opac_base_url . "/cgi-bin/koha/opac-account.pl" );
 
@@ -104,10 +101,12 @@ if ( $payment_method eq 'paypal' ) {
     my $response = $ua->request( POST $url, $nvp_params );
 
     if ( $response->is_success ) {
-        my $params = url_params_mixed( $response->decoded_content );
 
-        if ( $params->{ACK} eq "Success" ) {
-            my $token = $params->{TOKEN};
+        my $urlencoded = $response->content;
+        my %params = URI->new( "?$urlencoded" )->query_form;
+
+        if ( $params{ACK} eq "Success" ) {
+            my $token = $params{TOKEN};
 
             my $redirect_url =
               C4::Context->preference('PayPalSandboxMode')