Bugzilla – Attachment 66841 Details for
Bug 19173
Make OPAC online payments pluggable
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19173 - Make OPAC online payments pluggable
Bug-19173---Make-OPAC-online-payments-pluggable.patch (text/plain), 11.97 KB, created by
Kyle M Hall (khall)
on 2017-09-05 11:38:52 UTC
(
hide
)
Description:
Bug 19173 - Make OPAC online payments pluggable
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2017-09-05 11:38:52 UTC
Size:
11.97 KB
patch
obsolete
>From 6c96585c19ec7148c18e92369bf40b17b24cbaa7 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Thu, 24 Aug 2017 06:55:49 -0400 >Subject: [PATCH] Bug 19173 - Make OPAC online payments pluggable > >While PayPal is fairly universal, there is a plethora of online >payment system that are far more localized, servicing a single >country ( e.g. Bug 18968 ) or even a single city! Instead of >adding support for each and every one of these payment options >directly into Koha, it makes more sense to add the ability to >create online payment plugins. > >Test Plan: >1) Apply this patch >2) Download and install the Kitchen Sink plugin version 2.1.1 or later > https://github.com/bywatersolutions/koha-plugin-kitchen-sink/releases >3) In the plugin options, enable the opac payments option >4) Create a patron with one or more fines >5) Log into the opac as that patron, note you now have the option > to pay online via KitchenSink ImaginaryPay >6) Make an online payment >7) Note the payment was processed correctly > >Sponsored-by: Washoe County Library System > >Signed-off-by: Kyle M Hall <kyle@gmail.com> > >Signed-off-by: Magnus Enger <magnus@libriotech.no> >Awesome enhancement! I know we want to add at least one Norwegian >payment service at some point. >I followed the test plan and everything works as advertised. Turning >off the "opac payments option" makes the option dissappear cleanly >from the OPAC. I have *not* looked at the code or done any >considerations about security. >--- > .../opac-tmpl/bootstrap/en/modules/opac-account.tt | 34 ++++++++------ > opac/opac-account-pay-return.pl | 54 ++++++++++++++++++++++ > opac/opac-account-pay.pl | 32 ++++++++++--- > opac/opac-account.pl | 11 +++++ > t/Koha/Plugin/Test.pm | 15 ++++++ > t/db_dependent/Plugins.t | 5 +- > 6 files changed, 129 insertions(+), 22 deletions(-) > create mode 100755 opac/opac-account-pay-return.pl > >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-account.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-account.tt >index 9c5ffad..a868d0f 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-account.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-account.tt >@@ -1,7 +1,7 @@ > [% USE Koha %] > [% USE KohaDates %] > [% USE Price %] >-[% SET ENABLE_OPAC_PAYMENTS = Koha.Preference('EnablePayPalOpacPayments') %] >+[% SET ENABLE_OPAC_PAYMENTS = Koha.Preference('EnablePayPalOpacPayments') || plugins %] > [% SET DISPLAY_PAYMENT_BLOCK = 0 %] > [% INCLUDE 'doc-head-open.inc' %] > <title>[% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog › Your fines and charges</title> >@@ -141,20 +141,24 @@ > <fieldset class="pay-online hidden"> > <legend>Pay selected fines and charges</legend> > <span class="help-block"><h3>Payment method</h3></span> >- <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" border="0" alt="PayPal Acceptance Mark"></a><!-- PayPal Logo --> >- </label> >- </div> >- <!-- look to the future >- <div class="control-group"> >- <label class="radio"> >- <input type="radio" name="payment_method" id="payment_method-paypal" value="paypal" checked="checked"> >- PayPal >- </label> >- </div> >- --> >+ >+ [% 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" border="0" alt="PayPal Acceptance Mark"></a><!-- PayPal Logo --> >+ </label> >+ </div> >+ [% END %] >+ >+ [% FOREACH p IN plugins %] >+ <div class="control-group"> >+ <label class="radio"> >+ <input type="radio" name="payment_method" id="payment_method-[% p.class %]" value="[% p.class %]" checked="checked"> >+ [% p.get_metadata.name %] >+ </label> >+ </div> >+ [% END %] > > <div class="control-group"> > <input type="hidden" id="payment-amount" name="payment_amount" value="0" /> >diff --git a/opac/opac-account-pay-return.pl b/opac/opac-account-pay-return.pl >new file mode 100755 >index 0000000..73c5f56 >--- /dev/null >+++ b/opac/opac-account-pay-return.pl >@@ -0,0 +1,54 @@ >+#!/usr/bin/perl >+ >+# Copyright ByWater Solutions 2017 >+# >+# 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, write to the Free Software Foundation, Inc., >+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. >+ >+use Modern::Perl; >+ >+use CGI; >+ >+use C4::Auth; >+use Koha::Plugins::Handler; >+ >+my $cgi = new CGI; >+ >+my ( $userid, $cookie, $sessionID, $flags ) = checkauth( $cgi, 0, {}, 'opac' ); >+ >+# Check for payment method in both POST and GET vars >+my $payment_method = $cgi->param('payment_method') || $cgi->url_param('payment_method'); >+ >+my $can_handle_payment = Koha::Plugins::Handler->run( >+ { >+ class => $payment_method, >+ method => 'opac_online_payment', >+ cgi => $cgi, >+ } >+); >+ >+if ($can_handle_payment) { >+ Koha::Plugins::Handler->run( >+ { >+ class => $payment_method, >+ method => 'opac_online_payment_end', >+ cgi => $cgi, >+ } >+ ); >+} >+else { >+ print $cgi->redirect("/cgi-bin/koha/errors/404.pl"); >+ exit; >+} >diff --git a/opac/opac-account-pay.pl b/opac/opac-account-pay.pl >index 6caebe2..6c8211d 100755 >--- a/opac/opac-account-pay.pl >+++ b/opac/opac-account-pay.pl >@@ -31,10 +31,24 @@ use C4::Output; > use C4::Context; > use Koha::Acquisition::Currencies; > use Koha::Database; >+use Koha::Plugins::Handler; > > my $cgi = new CGI; >+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, >+ } >+ ); >+} > >-unless ( C4::Context->preference('EnablePayPalOpacPayments') ) { >+unless ( C4::Context->preference('EnablePayPalOpacPayments') || $use_plugin ) { > print $cgi->redirect("/cgi-bin/koha/errors/404.pl"); > exit; > } >@@ -49,9 +63,6 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( > } > ); > >-my $payment_method = $cgi->param('payment_method'); >-my @accountlines = $cgi->multi_param('accountline'); >- > my $amount_to_pay = > Koha::Database->new()->schema()->resultset('Accountline')->search( { accountlines_id => { -in => \@accountlines } } ) > ->get_column('amountoutstanding')->sum(); >@@ -126,6 +137,15 @@ if ( $payment_method eq 'paypal' ) { > $template->param( error => "PAYPAL_UNABLE_TO_CONNECT" ); > $error = 1; > } >-} > >-output_html_with_http_headers( $cgi, $cookie, $template->output ) if $error; >+ output_html_with_http_headers( $cgi, $cookie, $template->output ) if $error; >+} >+else { >+ Koha::Plugins::Handler->run( >+ { >+ class => $payment_method, >+ method => 'opac_online_payment_begin', >+ cgi => $cgi, >+ } >+ ); >+} >diff --git a/opac/opac-account.pl b/opac/opac-account.pl >index 9888f88..29d73a8 100755 >--- a/opac/opac-account.pl >+++ b/opac/opac-account.pl >@@ -25,6 +25,7 @@ use C4::Members; > use C4::Auth; > use C4::Output; > use Koha::Patrons; >+use Koha::Plugins; > > my $query = new CGI; > my ( $template, $borrowernumber, $cookie ) = get_template_and_user( >@@ -77,4 +78,14 @@ $template->param( > payment_error => scalar $query->param('payment-error') || q{}, > ); > >+my $plugins_enabled = C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins"); >+if ( $plugins_enabled ) { >+ my @plugins = Koha::Plugins->new()->GetPlugins({ >+ method => 'opac_online_payment', >+ }); >+ # Only pass in plugins where opac online payment is enabled >+ @plugins = grep { $_->opac_online_payment } @plugins; >+ $template->param( plugins => \@plugins ); >+} >+ > output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; >diff --git a/t/Koha/Plugin/Test.pm b/t/Koha/Plugin/Test.pm >index 401ce3d..636554d 100644 >--- a/t/Koha/Plugin/Test.pm >+++ b/t/Koha/Plugin/Test.pm >@@ -43,6 +43,21 @@ sub to_marc { > return "Koha::Plugin::Test::to_marc"; > } > >+sub opac_online_payment { >+ my ( $self, $args ) = @_; >+ return "Koha::Plugin::Test::opac_online_payment"; >+} >+ >+sub opac_online_payment_begin { >+ my ( $self, $args ) = @_; >+ return "Koha::Plugin::Test::opac_online_payment_begin"; >+} >+ >+sub opac_online_payment_end { >+ my ( $self, $args ) = @_; >+ return "Koha::Plugin::Test::opac_online_payment_end"; >+} >+ > sub configure { > my ( $self, $args ) = @_; > return "Koha::Plugin::Test::configure";; >diff --git a/t/db_dependent/Plugins.t b/t/db_dependent/Plugins.t >index c9d24a7..dffcea7 100755 >--- a/t/db_dependent/Plugins.t >+++ b/t/db_dependent/Plugins.t >@@ -2,7 +2,7 @@ > > use Modern::Perl; > >-use Test::More tests => 28; >+use Test::More tests => 31; > use File::Basename; > use File::Temp qw( tempdir ); > use FindBin qw($Bin); >@@ -31,6 +31,9 @@ isa_ok( $plugin, "Koha::Plugins::Base", 'Test plugin parent class' ); > ok( $plugin->can('report'), 'Test plugin can report' ); > ok( $plugin->can('tool'), 'Test plugin can tool' ); > ok( $plugin->can('to_marc'), 'Test plugin can to_marc' ); >+ok( $plugin->can('opac_online_payment'), 'Test plugin can opac_online_payment' ); >+ok( $plugin->can('opac_online_payment_begin'), 'Test plugin can opac_online_payment_begin' ); >+ok( $plugin->can('opac_online_payment_end'), 'Test plugin can opac_online_payment_end' ); > ok( $plugin->can('configure'), 'Test plugin can configure' ); > ok( $plugin->can('install'), 'Test plugin can install' ); > ok( $plugin->can('uninstall'), 'Test plugin can install' ); >-- >2.10.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 19173
:
66414
|
66464
|
66472
|
66473
|
66474
|
66839
|
66840
|
66841
|
66842
|
67047
|
67048