laravel Response::setContent():参数#1($content)必须是?string类型

ktca8awb  于 2023-11-20  发布在  其他
关注(0)|答案(1)|浏览(141)

我想进行Paypal付款,我正在使用Laravel 9.20版本,但我有以下错误。
Symfony\Component\HttpFoundation\Response::setContent():参数#1($content)必须是?string类型
当我试图到达付款路线,我不知道如何摆脱它。所以,我会把我的代码下面。有人可以帮助我吗?谢谢。

控制器

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.');
    }
}

字符串

路线

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');

5kgi1eie

5kgi1eie1#

在您的控制器内支付和成功的功能/方法只是改变

$provider = new ExpressCheckout;

字符串

$provider = new ExpressCheckout();

相关问题