1

I really need your help on this problem, since I don't understand how to fix it or where to start looking for an answer. Here's the thing:

I'm trying to integrate paypal into Laravel 8 with PHP 8. the package I'm using is the paypal/rest-api-sdk-php v1. I know this is deprecated but I have not found any other solution to get working the v2.

Well, whenever I try to create a payment with the method $payment->create($this->api_context) -by the way, you can check the how-to guiide where I got those examples from below-the process gives me an error saying the following

ErrorException Required parameter $path follows optional parameter $handlers

I know this is because of an optional parameter being called before a required one. but honestly I've been working on this for weeks and I still can't figure it out.

Here some evidence: error-screen: enter image description here

class PagoController (where all magic starts to fail)

class PagoController extends Controller

{ private $api_context;

public function __construct(){

    $paypal_config = Config::get('paypal');

    $this->api_context = new ApiContext(
        new OAuthTokenCredential(
            $paypal_config['client_id'],
            $paypal_config['secret']
        )
    );

    $this->api_context->setConfig($paypal_config['settings']);

    //dd($this->api_context);
}

public function pagarConPaypal(Request $request, $id_conciliacion){

    //Obtener valores de la conciliación
    $registro_pago = Conciliacion::where('id_conciliacion', '=', $id_conciliacion)->first();
    //dd($registro_pago);

//--Crea un nuevo pago

    $payer = new Payer();
    $payer->setPaymentMethod('paypal');

    $amount = new Amount();
    $amount->setTotal($registro_pago->monto);
    $amount->setCurrency('MXN');

    $transaction = new Transaction();
    $transaction->setAmount($amount);
    $transaction->setDescription($registro_pago->concepto);

    $callbackURL = url('/paypal/estado');
    $redirectUrls = new RedirectUrls();
    $redirectUrls->setReturnUrl($callbackURL)
        ->setCancelUrl($callbackURL);

    $payment = new Payment();
    $payment->setIntent('Sale')
        ->setPayer($payer)
        ->setTransactions(array($transaction))
        ->setRedirectUrls($redirectUrls);

    //dd($payment);

//--Aplica el pago creado
    try {
        $payment->create($this->api_context, null);
        // echo $payment;
        return redirect()->away($payment->getApprovalLink());
    }
    catch (PayPalConnectionException $ex) {
        // This will print the detailed information on the exception.
        //REALLY HELPFUL FOR DEBUGGING
        echo $ex->getData();
    }

Any help will be very appreciated. Thanks in advance

Nyalum Lacey
  • 133
  • 2
  • 13
  • "the package I'm using is the paypal/rest-api-sdk-php v1. I know this is deprecated but I have not found any other solution to get working the v2." Hmm? Use the current Checkout-PHP-SDK. What you are doing is deprecated and has no support. – Preston PHX Mar 11 '21 at 06:09
  • Is it ok if I install it when I just want the user to redirect to paypal to pay?. I want users to click on a button to pay, redirect them to paypal to authorize payment and execute the payment myself... Just asking since it's my first time using paypal for laravel – Nyalum Lacey Mar 12 '21 at 00:18

1 Answers1

2

Don't use the deprecated SDK, there is no support for it.

Ideally you also shouldn't use any redirects, as that is an old integration method, for old websites.

Here is the best way to proceed:

Preston PHX
  • 27,642
  • 4
  • 24
  • 44
  • Thank you so much. I've dealing with this issue for weeks!!! I think it's because I'm using PHP 8 and they have refactored that part – Nyalum Lacey Mar 12 '21 at 13:15