+[% INCLUDE 'opac-bottom.inc' %]
+
+[% INCLUDE 'datatables.inc' %]
+[% INCLUDE 'browser-strings.inc' %]
+
+
+
+[% BLOCK jsinclude %][% END %]
+
+[% BLOCK format_data %]
+ [% FOREACH key IN data.result_source.columns %]
+ [% IF key.match('^amount') %]
+ "[% key %]": "[% data.$key FILTER $Currency %]",
+ "[% key %]_unformatted": "[% data.$key %]",
+ [% ELSIF key.match('_on$') %]
+ "[% key %]": "[% data.$key | $KohaDates %]",
+ "[% key %]_unformatted": "[% data.$key %]",
+ [% ELSE %]
+ "[% key %]": "[% data.$key %]",
+ [% END %]
+ [% END %]
+[% END %]
--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-account.tt
+++ a/koha-tmpl/opac-tmpl/prog/en/modules/opac-account.tt
@@ -23,51 +23,79 @@
-
-
View payments
-
-
-
- Fees |
-
-
- |
- ID |
- Description |
- Type |
- Amount |
- Outsanding |
- Created on |
- Updated on |
-
-
-
-
+
+
[% ELSE %]
You have no fines or charges
[% END %]
@@ -122,7 +150,24 @@ $(document).ready(function() {
{ "mDataProp": "amount_original" },
{ "mDataProp": "amount_outstanding" },
{ "mDataProp": "created_on" },
- { "mDataProp": "updated_on" }
+ { "mDataProp": "updated_on" },
+ {
+ /* Payment selection checkboxes */
+ [% UNLESS Koha.Preference('EnablePayPalOpacPayments') %]
+ "bVisible": false,
+ [% END %]
+ "mDataProp": null,
+ "sDefaultContent": "",
+ "fnRender": function ( o, val ) {
+ return val;
+ },
+ "mRender": function ( data, type, full ) {
+ if ( full.amount_outstanding_unformatted > 0 ) {
+ return "
"
+ + "
";
+ }
+ }
+ },
],
"aaData": [
[% FOREACH d IN debits %]
@@ -205,7 +250,24 @@ $(document).ready(function() {
{ "mDataProp": "amount_paid" },
{ "mDataProp": "amount_remaining" },
{ "mDataProp": "created_on" },
- { "mDataProp": "updated_on" }
+ { "mDataProp": "updated_on" },
+ {
+ /* Payment selection checkboxes */
+ [% UNLESS Koha.Preference('EnablePayPalOpacPayments') %]
+ "bVisible": false,
+ [% END %]
+ "mDataProp": null,
+ "sDefaultContent": "",
+ "fnRender": function ( o, val ) {
+ return val;
+ },
+ "mRender": function ( data, type, full ) {
+ if ( full.amount_outstanding_unformatted > 0 ) {
+ return "
"
+ + "
";
+ }
+ }
+ },
],
"aaData": [
[% FOREACH c IN credits %]
@@ -248,6 +310,29 @@ $(document).ready(function() {
}
} );
+ // Allow only numbers in ammount to pay
+ $('#amount_to_pay').keypress(function(event) {
+ end = $(this).val().split('.')[1];
+ if (typeof end === 'undefined') {
+ end = '';
+ }
+
+ if ( ( ( event.which != 46 || $(this).val().indexOf('.') != -1 ) && ( event.which < 48 || event.which > 57 ) ) || ( end.length > 1 ) ) {
+ event.preventDefault();
+ }
+ });
+
+ // Update the "amount to pay" field whenever a fee checkbox is changed
+ // Note, this is just a payment suggestion and can be changed to any amount
+ $(".pay-checkbox" ).change(function() {
+ var sum = 0;
+ $("input[name='debit_id']:checked" ).each(function(i,n){
+ sum += parseFloat( $( "#amount_outstanding_" + $(this).val() ).val() );
+ });
+ $('#amount_to_pay').val( sum.toFixed(2) );
+ });
+
+
} );
function fnFormatDebitDetails( debitsTable, nTr ) {
@@ -384,8 +469,10 @@ function fnFormatCreditDetails( creditsTable, nTr ) {
[% FOREACH key IN data.result_source.columns %]
[% IF key.match('^amount') %]
"[% key %]": "[% data.$key FILTER $Currency %]",
+ "[% key %]_unformatted": "[% data.$key %]",
[% ELSIF key.match('_on$') %]
"[% key %]": "[% data.$key | $KohaDates %]",
+ "[% key %]_unformatted": "[% data.$key %]",
[% ELSE %]
"[% key %]": "[% data.$key %]",
[% END %]
--- a/opac/opac-account-pay-paypal-return.pl
+++ a/opac/opac-account-pay-paypal-return.pl
@@ -0,0 +1,121 @@
+#!/usr/bin/perl
+
+# Copyright Katipo Communications 2002
+# Copyright Biblibre 2007,2010
+#
+# 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 strict;
+use warnings;
+use utf8;
+
+use CGI;
+use HTTP::Request::Common;
+use LWP::UserAgent;
+use URL::Encode qw(url_params_mixed);
+
+use C4::Auth;
+use C4::Output;
+use C4::Members;
+use Koha::Database;
+use Koha::Accounts qw(AddCredit);
+use Koha::Accounts::CreditTypes;
+
+my $cgi = new CGI;
+
+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",
+ authnotrequired => 0,
+ flagsrequired => { borrow => 1 },
+ debug => 1,
+ }
+);
+
+my $token = $cgi->param('token');
+my $payer_id = $cgi->param('PayerID');
+my $amount = $cgi->param('amount');
+my @debit_id = $cgi->param('debit_id');
+
+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,
+};
+
+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" ) {
+ $amount = $params->{PAYMENTINFO_0_AMT};
+
+ my $borrower =
+ Koha::Database->new()->schema->resultset('Borrower')
+ ->find($borrowernumber);
+
+ my $credit = AddCredit(
+ {
+ borrower => $borrower,
+ amount => $amount,
+ type => Koha::Accounts::CreditTypes::PayPal,
+ debit_id => \@debit_id,
+ }
+ );
+
+ $template->param( credit => $credit );
+
+ }
+ else {
+ $template->param( error => "PAYPAL_ERROR_PROCESSING" );
+ }
+
+}
+else {
+ $template->param( error => "PAYPAL_UNABLE_TO_CONNECT" );
+}
+
+$template->param(
+ borrower => GetMemberDetails($borrowernumber),
+ accountview => 1
+);
+
+output_html_with_http_headers( $cgi, $cookie, $template->output );
--- a/opac/opac-account-pay.pl
+++ a/opac/opac-account-pay.pl
@@ -0,0 +1,127 @@
+#!/usr/bin/perl
+
+# Copyright Katipo Communications 2002
+# Copyright Biblibre 2007,2010
+#
+# 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 strict;
+use warnings;
+use utf8;
+
+use CGI;
+use HTTP::Request::Common;
+use LWP::UserAgent;
+use URL::Encode qw(url_encode url_params_mixed);
+use URI;
+
+use C4::Auth;
+
+my $cgi = new CGI;
+
+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",
+ authnotrequired => 0,
+ flagsrequired => { borrow => 1 },
+ debug => 1,
+ }
+);
+
+my $amount_to_pay = $cgi->param('amount_to_pay');
+my $payment_method = $cgi->param('payment_method');
+my @debit_id = $cgi->param('debit_id');
+
+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'
+ : 'https://api-3t.paypal.com/nvp';
+
+ my $opac_base_url = C4::Context->preference('OPACBaseURL');
+
+ my $return_url =
+ URI->new( "http://"
+ . $opac_base_url
+ . "/cgi-bin/koha/opac-account-pay-paypal-return.pl" );
+ $return_url->query_form( { amount => $amount, debit_id => \@debit_id } );
+
+ my $cancel_url =
+ URI->new( "http://" . $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_AMT' => $amount_to_pay,
+ 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
+ 'PAYMENTREQUEST_0_ALLOWEDPAYMENTMETHOD' => 'InstantPaymentOnly',
+ 'PAYMENTREQUEST_0_DESC' =>
+ C4::Context->preference('PayPalChargeDescription'),
+ };
+
+ 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 $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;
+ }
+
+ }
+ else {
+ $template->param( error => "PAYPAL_UNABLE_TO_CONNECT" );
+ $error = 1;
+ }
+}
+
+output_html_with_http_headers( $cgi, $cookie, $template->output ) if $error;
--- a/opac/opac-account.pl
+++ a/opac/opac-account.pl
@@ -21,7 +21,6 @@
use strict;
use CGI;
use C4::Members;
-use C4::Circulation;
use C4::Auth;
use C4::Output;
use warnings;
--