1. Go to this page and download the library: Download epmnzava/paypal-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
php
>
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Epmnzava\PaypalLaravel\PaypalLaravel as Paypal;
class TestController extends Controller
{
public function payments(Request $request){
$paypal_payments=new paypal;
$response=$paypal_payments->CreatePayment(int $amount, $tax, $shipping, $handling_fee, $description);
// You will need the order_id to reference the transaction hence save it from here.
$payment_id=$response["order_id"];
//the checkout link will lead the user you to paypal where he/she can approve the payment.
return redirect($response["checkout_link"]);
}
php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Epmnzava\PaypalLaravel\PaypalLaravel as Paypal;
class TestController extends Controller
{
public function paypal_redirect(Request $request){
$paypal=new Paypal;
// This will execute the approved payment notice that the redirected url comes back with PayerID which we reuse it
$response=$paypal->executePayment($request->paymentId,$request->PayerID);
if(json_decode($response)->state=="approved"){
// update your database and share the success message to the user.
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.