Home > Blockchain >  Response::setContent(): Argument #1 ($content) must be of type ?string
Response::setContent(): Argument #1 ($content) must be of type ?string

Time:07-22

I want to make a Paypal payment, and I am working on Laravel version 9.20, but I have the following error.

Symfony\Component\HttpFoundation\Response::setContent(): Argument #1 ($content) must be of type ?string

When I attempt to reach the Payment Route, I don't know how to get rid of it. So, I'll put my code below. Can anyone help me? Thank you.

Controller

use Illuminate\Http\Request;
use Srmklive\PayPal\Services\ExpressCheckout;

class PaypalController extends Controller
{
    public function goPayment()
    {
        return view('products.welcome');
    }

    public function payment()
    {
        $data = [];
        $data['items'] = [
            [
                'name' => 'Apple',
                'price' => 100,
                'desc' => 'Macbook pro 14 inch',
                'qty' => 1
            ]
        ];

        $data['invoice_id'] = 1;
        $data['invoice_description'] = "Order #{$data['invoice_id']} Invoice";
        $data['return_url'] = route('payment.success');
        $data['cancel_url'] = route('payment.cancel');
        $data['total'] = 100;

        $provider = new ExpressCheckout;
        $response = $provider->setExpressCheckout($data);
        $response = $provider->setExpressCheckout($data, true);

        return redirect($response['paypal_link']);
    }

    public function cancel()
    {
        dd('Your payment is canceled.');
    }

    public function success(Request $request)
    {
        $provider = new ExpressCheckout;
        $response = $provider->getExpressCheckoutDetails($request->token);

        if (in_array(strtoupper($response['ACK']), ['SUCCESS', 'SUCCESSWITHWARNING'])) {
            dd('Your payment was successfully.');
        }

        dd('Please try again later.');
    }
}

Routes

Route::get('/', function () {
    return view('welcome');
});
Route::get('Payment', 'App\Http\Controllers\PaypalController@payment')
    ->name('payment');
Route::get('CancelPayment', 'App\Http\Controllers\PaypalController@CancelPayment')
    ->name('payment.cancel');
Route::get('Payment/success', 'App\Http\Controllers\PaypalController@Payment-success')
    ->name('payment.success');

CodePudding user response:

in your controller inside payment and success function/method just change $provider = new ExpressCheckout; to $provider = new ExpressCheckout();

  • Related