From da052b3d10d71cb1256693fbd3166caaa4b53f41 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 22 Mar 2016 17:17:59 -0300 Subject: [PATCH] Bug 16129: Remove URL::Encode dependency 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 Signed-off-by: Martin Renvoize Signed-off-by: Brendan A Gallagher --- C4/Installer/PerlDependencies.pm | 5 ----- opac/opac-account-pay-paypal-return.pl | 11 +++++++---- opac/opac-account-pay.pl | 13 ++++++------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/C4/Installer/PerlDependencies.pm b/C4/Installer/PerlDependencies.pm index 5e2f22f23b..0d6363f606 100644 --- a/C4/Installer/PerlDependencies.pm +++ b/C4/Installer/PerlDependencies.pm @@ -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', diff --git a/opac/opac-account-pay-paypal-return.pl b/opac/opac-account-pay-paypal-return.pl index 1823d2ffe6..64dcfddb07 100755 --- a/opac/opac-account-pay-paypal-return.pl +++ b/opac/opac-account-pay-paypal-return.pl @@ -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 ) { diff --git a/opac/opac-account-pay.pl b/opac/opac-account-pay.pl index 8dfdfcdb12..cb1545c223 100755 --- a/opac/opac-account-pay.pl +++ b/opac/opac-account-pay.pl @@ -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') -- 2.39.5