Bug 21701: Have PayPal optionally return to originating OPAC url rather than OPACBaseURL
authorDavid Kuhn <techservspec@gmail.com>
Thu, 8 Nov 2018 16:58:37 +0000 (08:58 -0800)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 8 Oct 2019 13:42:38 +0000 (14:42 +0100)
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 <brendan@bywatersolutions.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

installer/data/mysql/atomicupdate/bug_21701_PayPalReturnURL.perl [new file with mode: 0644]
installer/data/mysql/sysprefs.sql
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref
opac/opac-account-pay.pl

diff --git a/installer/data/mysql/atomicupdate/bug_21701_PayPalReturnURL.perl b/installer/data/mysql/atomicupdate/bug_21701_PayPalReturnURL.perl
new file mode 100644 (file)
index 0000000..d62dbc1
--- /dev/null
@@ -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";
+}
index f6d1636..bb6618f 100644 (file)
@@ -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'),
index d455164..0ffe05b 100644 (file)
@@ -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"
index a4598bd..470e443 100755 (executable)
@@ -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 } );