From e4c8af4f358fca3bc1ae17deb7e2cd9a45a76d64 Mon Sep 17 00:00:00 2001 From: David Kuhn Date: Thu, 8 Nov 2018 08:58:37 -0800 Subject: [PATCH] Bug 21701: Have PayPal optionally return to originating OPAC url rather than OPACBaseURL This enhancement will allow a library to choose whether to use the alias of the current OPAC or the value of OPACBaseURL as the return url when making payments via PayPal. To test: Note: you need to have PayPal enabled on your system (either Sandbox mode or Live) and be using an alias URL for your OPAC. 1. Apply the patch. 2. With the option "PayPalReturnURL" set to "OPACBaseURL", log into a card via the OPAC and start the process to pay in PayPal (you can either complete the payment or cancel from the PayPal page). When you are returned to the OPAC, the domain will be the value of OPACBaseURL. 3. With the option "PayPalReturnURL" set to "OPAC's alias", repeat the above sequence to make a payment in PayPal. When you are returned to the OPAC, the domain will be your current alias. Signed-off-by: Brendan Gallagher Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize --- .../atomicupdate/bug_21701_PayPalReturnURL.perl | 14 ++++++++++++++ installer/data/mysql/sysprefs.sql | 1 + .../prog/en/modules/admin/preferences/opac.pref | 7 +++++++ opac/opac-account-pay.pl | 5 ++++- 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 installer/data/mysql/atomicupdate/bug_21701_PayPalReturnURL.perl diff --git a/installer/data/mysql/atomicupdate/bug_21701_PayPalReturnURL.perl b/installer/data/mysql/atomicupdate/bug_21701_PayPalReturnURL.perl new file mode 100644 index 0000000000..d62dbc1c0c --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_21701_PayPalReturnURL.perl @@ -0,0 +1,14 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + # you can use $dbh here like: + # $dbh->do("INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES ('PayPalReturnURL','BaseURL','BaseURL|OPACAlias','Specify whether PayPal will return to the url specified in the OPACBaseURL option or to the OPAC\'s alias url.','Choice')" ); + + # or perform some test and warn + # if( !column_exists( 'biblio', 'biblionumber' ) ) { + # warn "There is something wrong"; + # } + + # Always end with this (adjust the bug info) + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 21701 - PayPal return URL option)\n"; +} diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index f6d16368db..bb6618f3ff 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -482,6 +482,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('PatronQuickAddFields', '', NULL , 'A list of fields separated by "|" to be displayed along with mandatory fields in the patron quick add form if chosen at patron entry', 'Free' ), ('PayPalChargeDescription', 'Koha fee payment', NULL , 'This preference defines what the user will see the charge listed as in PayPal', 'Free'), ('PayPalPwd', '', NULL , 'Your PayPal API password', 'Free'), +('PayPalReturnURL','BaseURL','BaseURL|OPACAlias','Specify whether PayPal will return to the url specified in the OPACBaseURL option or to the OPAC\'s alias url.','Choice'), ('PayPalSandboxMode', '1', NULL , 'If enabled, the system will use PayPal''s sandbox server for testing, rather than the production server.', 'YesNo'), ('PayPalSignature', '', NULL , 'Your PayPal API signature', 'Free'), ('PayPalUser', '', NULL , 'Your PayPal API username ( email address )', 'Free'), 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 d455164a0d..0ffe05b44d 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 @@ -893,3 +893,10 @@ OPAC: - "The patron should see the charge description as " - pref: PayPalChargeDescription class: long + - + - "After payment or cancellation, PayPal should return to the " + - pref: PayPalReturnURL + default: BaseURL + choices: + BaseURL: "OPACBaseURL" + OPACAlias: "OPAC's alias" diff --git a/opac/opac-account-pay.pl b/opac/opac-account-pay.pl index a4598bda38..470e4430c6 100755 --- a/opac/opac-account-pay.pl +++ b/opac/opac-account-pay.pl @@ -79,7 +79,10 @@ if ( $payment_method eq 'paypal' ) { ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp'; - my $opac_base_url = C4::Context->preference('OPACBaseURL'); + 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 } ); -- 2.39.5