I'm integrating the PayPal Plus environment on our site. We are using the current version of PayPal PHP SDK (1.7.4) available on Github https://github.com/paypal/PayPal-PHP-SDK. We are using PHP 7.0.7 on IIS 10.
First we create a payment as explained in the integration guide. We receive a valid approval url from the payment (format: https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=...). I checked the url in the browser manually.
The payment is created in a controller and is given to the view.
Controller:
function showPaymentWall() {
$payment = $this->createPayment();
return view("payments.paypal.paymentWall",['payment'=>$payment, 'approval_url'=> $this->approvalUrl]);
}
The approval_url is set in the method createPayment.
Here is the code from the view:
@extends('layouts.master')
@section('title')
Upgrade
@endsection
@section('content')
<div class="container">
<div class="row">
<div class="form-group col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div>{{ $approval_url }}</div>
<div id="ppplus"></div>
</div>
</div>
</div>
@endsection
@section('scriptIndividualJSCode')
<script src="https://www.paypalobjects.com/webstatic/ppplus/ppplus.min.js" type="text/javascript"></script>
<script type="application/javascript">
var ppp = PAYPAL.apps.PPP({
"approvalUrl": "{{ $approval_url }}",
"placeholder": "ppplus",
"mode": "sandbox",
"country": "DE"
});
</script>
@endsection
As you can see the valid url is displayed before the ppplus container. So that it is clear, that the url is valid and correctly given by the controller. But when I visit the page, I always get this error:

When I check the reason via console it says "Invalid approval url".

Anybody an idea why or what I can check to get forward? Thanks in advance for any help!
I found the reason after a long search.
It comes out, that the & in the approval URL has to be replaced with &.
Then it worked. This can be done with the PHP function htmlspecialchars_decode() (see http://php.net/manual/de/function.htmlspecialchars-decode.php). Here is my code for the javascript part:
<script type="application/javascript">
var ppp = PAYPAL.apps.PPP({
"approvalUrl": "<?php echo htmlspecialchars_decode($approval_url); ?>",
"placeholder": "ppplus",
"mode": "sandbox",
"country": "DE",
"language": "de_DE"
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With