php - Argument 1 passed to SymfonyComponentHttpFoundationResponse::setContent() must be of the type string or null, object given Laravel 8
Get the solution ↓↓↓I am using srmklive/paypal:~1.0 in my project i am getting this error Argument 1 passed to Symfony\Component\HttpFoundation\Response::setContent() must be of the type string or null, object given, called in C:\laragon\www\PaymentMethod\vendor\laravel\framework\src\Illuminate\Http\Response.php on line 72
i am trying to pass my data in the controller as such
public function pay()
{
$data = [];
$data['items'] = [
[
'name' => 'nikeshoes',
'price' => 200,
'desc' => 'nike shoes',
'qty' => 1
]
];
$data['invoice_id']=16;
$data['invoice_description'] = "Order #{$data['invoice_id']} Invoice";
$data['return_url'] = route('paymentapproval');
$data['cancel_url'] = route('cancel');
$data['total'] = 200;
$provider = new ExpressCheckout;
$response = $provider->setExpressCheckout($data);
$response = $provider->setExpressCheckout($data, true);
return redirect($response['paypal_link']);
}
public function cancel()
{
dd("something");
}
public function paymentapproval(Request $request)
{
$provider=new ExpressCheckout;
$response = $provider->getExpressCheckoutDetails($request->token);
// $response = $provider->doExpressCheckoutPayment($data, $token, $PayerID);
if (in_array(strtoupper($response['ACK']), ['SUCCESS', 'SUCCESSWITHWARNING'])) {
dd('Your payment was successfully. You can create success page here.');
}
dd('Something is wrong.');
}
i have also changed my paypal.php file inside the config folder
return [
'mode' => 'sandbox', // Can only be 'sandbox' Or 'live'. If empty or invalid, 'live' will be used.
'sandbox' => [
'username' => '', // Api Username
'password' => '', // Api Password
'secret' => '', // This refers to api signature
'certificate' => '', // Link to paypals cert file, storage_path('cert_key_pem.txt')
],
'live' => [
'username' => '', // Api Username
'password' => '', // Api Password
'secret' => '', // This refers to api signature
'certificate' => '', // Link to paypals cert file, storage_path('cert_key_pem.txt')
],
'payment_action' => 'Sale', // Can Only Be 'Sale', 'Authorization', 'Order'
'currency' => 'USD',
'notify_url' => 'https://api-m.sandbox.paypal.com', // Change this accordingly for your application.
];
inside my env file setting are
PAYPAL_MODE=sandbox
#PayPal Setting & API Credentials - sandbox
PAYPAL_SANDNOX_API_USERNAME=sb-crlzo6945665_api1.business.example.com
PAYPAL_SANDNOX_API_PASSWORD=password of the api
PAYPAL_SANDNOX_API_SECRET=api secret
PAYPAL_CURRENCY=MYR
don't know what is causing this error and how to remove it will be thank ful to u
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: string literal contains an unescaped line break
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.