Bug 23215: Remove traces of the PayPal feature

This patch removes the PayPal payments feature. It has been moved to
its' own plugin.

To test:
1. Apply this patches
2. Run:
   $ updatedatabase
=> SUCCESS: Database updates correctly
3. Run:
   $ koha-mysql kohadev
   > SELECT * FROM systempreferences WHERE variable LIKE 'paypal';
=> SUCCESS: No results
4. On the sysprefs, OPAC section
=> SUCCESS: No PayPal-related sysprefs show up
5. Add some charges to your patron
6. In the OPAC, log in and see your charges
=> SUCCESS: Nothing broken
7. Install the PayPal plugin [1] or any other payment plugin
8. Restart plack (mandatory for the PayPal plugin)
9. Set some random data in the config (or better, real sandbox testing
   data)
10. Go to the OPAC's account page and try to pay your debts (use the
    checkbox to select lines)
=> SUCCESS: The PayPal payment method shows, you can click the button,
    it fails due to bad config, but things work as expected.
11. Sign off :-D

[1] https://gitlab.com/thekesolutions/plugins/koha-plugin-pay-via-paypal/-/releases

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Tomas Cohen Arazi 2021-05-05 10:16:50 -03:00 committed by Jonathan Druart
parent 37a10f012b
commit 523b4533f8
8 changed files with 19 additions and 263 deletions

View File

@ -421,10 +421,6 @@ if ( C4::Context->preference('WebBasedSelfCheck')
);
}
if ( C4::Context->preference('EnablePayPalOpacPayments') ) {
$template->param( paypal_enabled => 1 );
}
# Test YAML system preferences
# FIXME: This is list of current YAML formatted prefs, should by type of preference
my @yaml_prefs = (

View File

@ -299,7 +299,7 @@
Contact your system administrator.
[% END %]
[% IF warnPrefBiblioAddsAuthorities || warnPrefEasyAnalyticalRecords || warnPrefAnonymousPatronOPACPrivacy || warnPrefAnonymousPatronAnonSuggestions || warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist || warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist || warnPrefKohaAdminEmailAddress || warnPrefOpacHiddenItems || invalid_yesno.count || warnNoActiveCurrency || AutoSelfCheckPatronDoesNotHaveSelfCheckPerm || AutoSelfCheckPatronHasTooManyPerm || warnStatisticsFieldsError || warnNoTemplateCaching || warnILLConfiguration || oauth2_missing_deps || bad_yaml_prefs || warnIssuingRules || config_bcrypt_settings_no_set || warnHiddenBiblionumbers.size || paypal_enabled %]
[% IF warnPrefBiblioAddsAuthorities || warnPrefEasyAnalyticalRecords || warnPrefAnonymousPatronOPACPrivacy || warnPrefAnonymousPatronAnonSuggestions || warnPrefAnonymousPatronOPACPrivacy_PatronDoesNotExist || warnPrefAnonymousPatronAnonSuggestions_PatronDoesNotExist || warnPrefKohaAdminEmailAddress || warnPrefOpacHiddenItems || invalid_yesno.count || warnNoActiveCurrency || AutoSelfCheckPatronDoesNotHaveSelfCheckPerm || AutoSelfCheckPatronHasTooManyPerm || warnStatisticsFieldsError || warnNoTemplateCaching || warnILLConfiguration || oauth2_missing_deps || bad_yaml_prefs || warnIssuingRules || config_bcrypt_settings_no_set || warnHiddenBiblionumbers.size %]
<h2>Warnings regarding the system configuration</h2>
<table>
<caption>Preferences and parameters</caption>
@ -403,13 +403,6 @@
[% END %]
</td></tr>
[% END %]
[% IF paypal_enabled %]
<tr><th scope="row"><strong>Warning</strong> </th><td>
You are using the PayPal functionality, which is now deprecated and replaced in favor of using payment plugins that can implement
different payment services. Please install the plugin and follow the migration instructions in order to keep enjoying the PayPal
integration. This feature will be removed from Koha in a short term.
</td></tr>
[% END %]
[% IF Koha.Preference('SearchEngine') == 'Elasticsearch' && elasticsearch_status.version.substr(0,1) < 6 %]
<tr><th scope="row"><strong>Deprecation warning</strong></th><td>
Elasticsearch version 5.x is not supported in Koha 20.11 and greater. Please upgrade your Elasticsearch cluster

View File

@ -142,19 +142,6 @@
<legend>Pay selected fines and charges</legend>
<span class="help-block"><h2>Payment method</h2></span>
[% IF Koha.Preference('EnablePayPalOpacPayments') %]
<div class="control-group">
<label class="radio">
<input type="radio" name="payment_method" id="payment_method-paypal" value="paypal" checked="checked" />
<!-- PayPal Logo -->
<a href="https://www.paypal.com/webapps/mpp/paypal-popup" title="How PayPal Works" class="paypal">
<img src="https://www.paypalobjects.com/webstatic/mktg/logo/AM_SbyPP_mc_vs_dc_ae.jpg" alt="PayPal Acceptance Mark" />
</a>
<!-- PayPal Logo -->
</label>
</div>
[% END %]
[% FOREACH p IN plugins %]
<div class="control-group">
<label class="radio">

View File

@ -34,14 +34,6 @@
[% IF error %]
<div id="error" class="alert alert-warning">
<p><strong>Error:</strong> there was a problem processing your payment</p>
[% IF error == "PAYPAL_UNABLE_TO_CONNECT" %]
<p>Unable to connect to PayPal.</p>
<p>Please try again later.</p>
[% ELSIF error == "PAYPAL_ERROR_PROCESSING" %]
<p>Unable to verify payment.</p>
<p>Please contact the library to verify your payment.</p>
[% END %]
</div>
[% END %]

View File

@ -4,7 +4,7 @@
[% USE KohaDates %]
[% USE AuthorisedValues %]
[% USE Price %]
[% SET ENABLE_OPAC_PAYMENTS = Koha.Preference('EnablePayPalOpacPayments') || plugins %]
[% SET ENABLE_OPAC_PAYMENTS = payment_methods %]
[% SET DISPLAY_PAYMENT_BLOCK = 0 %]
[% INCLUDE 'doc-head-open.inc' %]
<title>Your charges &rsaquo; [% IF ( LibraryNameTitle ) %][% LibraryNameTitle | html %][% ELSE %]Koha online[% END %] catalog</title>
@ -60,14 +60,6 @@
[% IF payment_error %]
<div id="error" class="alert alert-warning">
<p><strong>Error:</strong> there was a problem processing your payment</p>
[% IF payment_error == "PAYPAL_UNABLE_TO_CONNECT" %]
<p>Unable to connect to PayPal.</p>
<p>Please contact a librarian to verify your payment.</p>
[% ELSIF payment_error == "PAYPAL_ERROR_PROCESSING" %]
<p>Unable to verify payment.</p>
<p>Please contact a librarian to verify your payment.</p>
[% END %]
</div>
[% ELSIF payment %]
<div class="alert alert-info">
@ -119,11 +111,6 @@ $( document ).ready(function() {
//Start filtered
$('#filter_paid').click();
$(".paypal").on("click", function() {
window.open('https://www.paypal.com/webapps/mpp/paypal-popup','WIPaypal','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=1060, height=700');
return false;
});
$(".pay-online").removeClass("hidden");
$("#amount-to-pay-label").hide();

View File

@ -1,125 +0,0 @@
#!/usr/bin/perl
# Copyright ByWater Solutions 2015
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use utf8;
use CGI;
use HTTP::Request::Common;
use LWP::UserAgent;
use URI;
use C4::Auth;
use C4::Output;
use C4::Accounts;
use Koha::Acquisition::Currencies;
use Koha::Database;
use Koha::Patrons;
my $cgi = CGI->new;
unless ( C4::Context->preference('EnablePayPalOpacPayments') ) {
print $cgi->redirect("/cgi-bin/koha/errors/404.pl");
exit;
}
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
{
template_name => "opac-account-pay-return.tt",
query => $cgi,
type => "opac",
debug => 1,
}
);
my $active_currency = Koha::Acquisition::Currencies->get_active;
my $token = $cgi->param('token');
my $payer_id = $cgi->param('PayerID');
my $amount = $cgi->param('amount');
my @accountlines = $cgi->multi_param('accountlines');
my $ua = LWP::UserAgent->new;
my $url =
C4::Context->preference('PayPalSandboxMode')
? 'https://api-3t.sandbox.paypal.com/nvp'
: 'https://api-3t.paypal.com/nvp';
my $nvp_params = {
'USER' => C4::Context->preference('PayPalUser'),
'PWD' => C4::Context->preference('PayPalPwd'),
'SIGNATURE' => C4::Context->preference('PayPalSignature'),
# API Version and Operation
'METHOD' => 'DoExpressCheckoutPayment',
'VERSION' => '82.0',
# API specifics for DoExpressCheckout
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
'PAYERID' => $payer_id,
'TOKEN' => $token,
'PAYMENTREQUEST_0_AMT' => $amount,
'PAYMENTREQUEST_0_CURRENCYCODE' => $active_currency->currency,
};
my $response = $ua->request( POST $url, $nvp_params );
my $error = q{};
if ( $response->is_success ) {
my $urlencoded = $response->content;
my %params = URI->new( "?$urlencoded" )->query_form;
if ( $params{ACK} eq "Success" ) {
$amount = $params{PAYMENTINFO_0_AMT};
my $account = Koha::Account->new( { patron_id => $borrowernumber } );
my @lines = Koha::Account::Lines->search(
{
accountlines_id => { -in => \@accountlines }
}
);
$account->pay(
{
amount => $amount,
lines => \@lines,
note => 'PayPal',
interface => C4::Context->interface
}
);
}
else {
$error = "PAYPAL_ERROR_PROCESSING";
}
}
else {
$error = "PAYPAL_UNABLE_TO_CONNECT";
}
my $patron = Koha::Patrons->find( $borrowernumber );
$template->param(
borrower => $patron->unblessed,
accountview => 1
);
print $cgi->redirect("/cgi-bin/koha/opac-account.pl?payment=$amount&payment-error=$error");

View File

@ -37,18 +37,14 @@ my $cgi = CGI->new;
my $payment_method = $cgi->param('payment_method');
my @accountlines = $cgi->multi_param('accountline');
my $use_plugin;
if ( $payment_method ne 'paypal' ) {
$use_plugin = Koha::Plugins::Handler->run(
{
class => $payment_method,
method => 'opac_online_payment',
cgi => $cgi,
}
);
}
my $use_plugin = Koha::Plugins::Handler->run(
{ class => $payment_method,
method => 'opac_online_payment',
cgi => $cgi,
}
);
unless ( C4::Context->preference('EnablePayPalOpacPayments') || $use_plugin ) {
unless ( $use_plugin ) {
print $cgi->redirect("/cgi-bin/koha/errors/404.pl");
exit;
}
@ -70,84 +66,11 @@ $amount_to_pay = sprintf( "%.2f", $amount_to_pay );
my $active_currency = Koha::Acquisition::Currencies->get_active;
my $error = 0;
if ( $payment_method eq 'paypal' ) {
my $ua = LWP::UserAgent->new;
my $url =
C4::Context->preference('PayPalSandboxMode')
? 'https://api-3t.sandbox.paypal.com/nvp'
: 'https://api-3t.paypal.com/nvp';
my $opac_base_url =
C4::Context->preference('PayPalReturnURL') eq 'BaseURL'
? C4::Context->preference('OPACBaseURL')
: $cgi->url(-base=>1);
my $return_url = URI->new( $opac_base_url . "/cgi-bin/koha/opac-account-pay-paypal-return.pl" );
$return_url->query_form( { amount => $amount_to_pay, accountlines => \@accountlines } );
my $cancel_url = URI->new( $opac_base_url . "/cgi-bin/koha/opac-account.pl" );
my $nvp_params = {
'USER' => C4::Context->preference('PayPalUser'),
'PWD' => C4::Context->preference('PayPalPwd'),
'SIGNATURE' => C4::Context->preference('PayPalSignature'),
# API Version and Operation
'METHOD' => 'SetExpressCheckout',
'VERSION' => '82.0',
# API specifics for SetExpressCheckout
'NOSHIPPING' => 1,
'REQCONFIRMSHIPPING' => 0,
'ALLOWNOTE' => 0,
'BRANDNAME' => C4::Context->preference('LibraryName'),
'CANCELURL' => $cancel_url->as_string(),
'RETURNURL' => $return_url->as_string(),
'PAYMENTREQUEST_0_CURRENCYCODE' => $active_currency->currency,
'PAYMENTREQUEST_0_AMT' => $amount_to_pay,
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
'PAYMENTREQUEST_0_ALLOWEDPAYMENTMETHOD' => 'InstantPaymentOnly',
'PAYMENTREQUEST_0_DESC' => C4::Context->preference('PayPalChargeDescription'),
'SOLUTIONTYPE' => 'Sole',
};
my $response = $ua->request( POST $url, $nvp_params );
if ( $response->is_success ) {
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')
? "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token="
: "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
print $cgi->redirect( $redirect_url . $token );
}
else {
$template->param( error => "PAYPAL_ERROR_PROCESSING" );
$error = 1;
}
Koha::Plugins::Handler->run(
{
class => $payment_method,
method => 'opac_online_payment_begin',
cgi => $cgi,
}
else {
$template->param( error => "PAYPAL_UNABLE_TO_CONNECT" );
$error = 1;
}
output_html_with_http_headers( $cgi, $cookie, $template->output, undef, { force_no_caching => 1 } ) if $error;
}
else {
Koha::Plugins::Handler->run(
{
class => $payment_method,
method => 'opac_online_payment_begin',
cgi => $cgi,
}
);
}
);

View File

@ -89,7 +89,10 @@ if ( C4::Context->config("enable_plugins") ) {
});
# Only pass in plugins where opac online payment is enabled
@plugins = grep { $_->opac_online_payment } @plugins;
$template->param( plugins => \@plugins );
$template->param(
plugins => \@plugins,
payment_methods => scalar @plugins > 0
);
}
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };