From a05515e6dedf4b9c228f10142f68d0fa41586527 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 23 Jan 2014 15:18:29 -0500 Subject: [PATCH] Bug 11622 - Add ability to pay fees and fines from OPAC via PayPal This patch adds the ability for a logged in user to pay fines and fees from the OPAC via PayPal. Test Plan: 1) Apply the patches for bug 6427 2) Apply this patch 3) Create a paypal developer account 4) Create two test accounts, a Personal account and a Business account 5) Enable PayPal in Sandbox mode via the system preferences. 6) Enter the business account API credentials into the new system preferences. 7) Create a new patron, add some fines/fees 8) Log in as that patron in the OPAC 9) Choose to pay via PayPal, log in as the sandbox Personal account 10) Complete the transaction 11) Note the fee is now paid --- Koha/Accounts/CreditTypes.pm | 10 + .../prog/en/modules/admin/preferences/opac.pref | 30 ++ .../en/modules/opac-account-pay-return.tt | 392 +++++++++++++++++++ .../opac-tmpl/bootstrap/en/modules/opac-account.tt | 161 ++++++--- .../opac-tmpl/prog/en/includes/browser-strings.inc | 1 + .../prog/en/modules/opac-account-pay-return.tt | 396 ++++++++++++++++++++ .../opac-tmpl/prog/en/modules/opac-account.tt | 179 +++++++--- opac/opac-account-pay-paypal-return.pl | 121 ++++++ opac/opac-account-pay.pl | 127 +++++++ opac/opac-account.pl | 1 - 10 files changed, 1325 insertions(+), 93 deletions(-) create mode 100644 koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-account-pay-return.tt create mode 100644 koha-tmpl/opac-tmpl/prog/en/modules/opac-account-pay-return.tt create mode 100755 opac/opac-account-pay-paypal-return.pl create mode 100755 opac/opac-account-pay.pl diff --git a/Koha/Accounts/CreditTypes.pm b/Koha/Accounts/CreditTypes.pm index 3916c72..0a888f9 100644 --- a/Koha/Accounts/CreditTypes.pm +++ b/Koha/Accounts/CreditTypes.pm @@ -58,6 +58,8 @@ sub IsValid { || $string eq Koha::Accounts::CreditTypes::Credit() || $string eq Koha::Accounts::CreditTypes::Forgiven() ); + $is_valid ||= $string eq Koha::Accounts::CreditTypes::PayPal(); + unless ($is_valid) { $is_valid = Koha::Database->new()->schema->resultset('AuthorisedValue') @@ -108,6 +110,14 @@ sub Forgiven { return 'FORGIVEN'; } +=head2 PayPal + +=cut + +sub PayPal { + return 'PAYPAL'; +} + 1; =head1 AUTHOR diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index a75c7ef..027d8e6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -619,3 +619,33 @@ OPAC: - pref: PatronSelfRegistrationAdditionalInstructions type: textarea class: html + Payments: + - + - pref: EnablePayPalOpacPayments + default: 1 + choices: + yes: Allow + no: "Don't allow" + - "patrons to make payments from the OPAC via PayPal in" + - pref: PayPalSandboxMode + default: 1 + choices: + yes: "Sandbox" + no: "Production" + - "mode." + - + - "The email address to recieve PayPal payments is " + - pref: PayPalUser + class: long + - + - "The password for the PayPal account to recieve payments is " + - pref: PayPalPwd + class: long + - + - "The signature for the PayPal account to recieve payments is " + - pref: PayPalSignature + class: long + - + - "The patron should see the charge description as " + - pref: PayPalChargeDescription + class: long diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-account-pay-return.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-account-pay-return.tt new file mode 100644 index 0000000..c61a591 --- /dev/null +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-account-pay-return.tt @@ -0,0 +1,392 @@ +[% USE Koha %] +[% USE KohaDates %] +[% USE Currency %] + +[% INCLUDE 'doc-head-open.inc' %][% IF ( LibraryNameTitle ) %][% LibraryNameTitle %][% ELSE %]Koha online[% END %] catalog › Your fines and charges +[% INCLUDE 'doc-head-close.inc' %] +[% BLOCK cssinclude %][% END %] + + + + +[% INCLUDE 'masthead.inc' %] + +
+ + +
+
+
+ +
+
+
+ [% IF error %] +
+

Error: there was an problem processing your payment

+ + [% IF error == "PAYPAL_UNABLE_TO_CONNECT" %] +

Unable to connect to PayPal.

+

Please try again later.

+ [% ELSIF error == "PAYPAL_ERROR_PROCESSING" %] +

Unable to verify payment.

+

Please contact the library to verify your payment.

+ [% END %] +
+ [% ELSIF credit %] +
+

Payment applied: your payment of [% credit.amount_paid %] has been applied to your account

+
+ [% END %] + + Return to fine details +
+
+
+
+
+ +[% INCLUDE 'opac-bottom.inc' %] +[% INCLUDE 'datatables.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 %] 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 a1e2487..2c067e3 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-account.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-account.tt @@ -34,51 +34,79 @@

Account balance: [% borrower.account_balance | $Currency %]

-
-
- View payments - - - - - - - - - - - - - - - - - -
Fees
IDDescriptionTypeAmountOutsandingCreated onUpdated on
+
+
+
+ View payments + + + + + + + + + + + + + + + + + + +
Fees
IDDescriptionTypeAmountOutsandingCreated onUpdated onPay
+
+ +
+ View fees + + + + + + + + + + + + + + + + + +
Payments
IDNotesTypeAmountRemainingCreated onUpdated on
+
+ + [% IF Koha.Preference('EnablePayPalOpacPayments') %] +
+ Pay online + +
+ Amount to pay: + [% Currency.symbol() %] +
+ +
+
Payment method:
+ + +
+ +
+ +
+ +
+
+ [% END %]
- -
- View fees - - - - - - - - - - - - - - - - - -
Payments
IDNotesTypeAmountRemainingCreated onUpdated on
-
-
+ [% ELSE %]

You have no fines or charges

[% END %] @@ -121,7 +149,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 %] @@ -242,6 +287,28 @@ $(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 ) { @@ -321,7 +388,7 @@ function fnFormatDebitDetails( debitsTable, nTr ) { function fnFormatCreditDetails( creditsTable, nTr ) { var oData = creditsTable.fnGetData( nTr ); - var sOut = "