3 # Copyright ByWater Solutions 2015
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 use HTTP::Request::Common;
27 use URL::Encode qw(url_params_mixed);
37 unless ( C4::Context->preference('EnablePayPalOpacPayments') ) {
38 print $cgi->redirect("/cgi-bin/koha/errors/404.pl");
42 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
44 template_name => "opac-account-pay-return.tt",
52 my $token = $cgi->param('token');
53 my $payer_id = $cgi->param('PayerID');
54 my $amount = $cgi->param('amount');
55 my @accountlines = $cgi->param('accountlines');
57 my $ua = LWP::UserAgent->new;
60 C4::Context->preference('PayPalSandboxMode')
61 ? 'https://api-3t.sandbox.paypal.com/nvp'
62 : 'https://api-3t.paypal.com/nvp';
65 'USER' => C4::Context->preference('PayPalUser'),
66 'PWD' => C4::Context->preference('PayPalPwd'),
67 'SIGNATURE' => C4::Context->preference('PayPalSignature'),
69 # API Version and Operation
70 'METHOD' => 'DoExpressCheckoutPayment',
73 # API specifics for DoExpressCheckout
74 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
75 'PAYERID' => $payer_id,
77 'PAYMENTREQUEST_0_AMT' => $amount,
80 my $response = $ua->request( POST $url, $nvp_params );
82 if ( $response->is_success ) {
83 my $params = url_params_mixed( $response->decoded_content );
85 if ( $params->{ACK} eq "Success" ) {
86 $amount = $params->{PAYMENTINFO_0_AMT};
87 $template->param( amount => $amount );
89 my $accountlines_rs = Koha::Database->new()->schema()->resultset('Accountline');
90 foreach my $accountlines_id ( @accountlines ) {
91 my $accountline = $accountlines_rs->find( $accountlines_id );
92 makepayment( $accountlines_id, $borrowernumber, undef, $accountline->amountoutstanding, undef, undef, 'PayPal' );
96 $template->param( error => "PAYPAL_ERROR_PROCESSING" );
101 $template->param( error => "PAYPAL_UNABLE_TO_CONNECT" );
105 borrower => GetMemberDetails($borrowernumber),
109 output_html_with_http_headers( $cgi, $cookie, $template->output );