Hi. I am trying to enable Paypal payments on Laravel 9 using league/omnipay omnipay/paypal package. However, I get the following error when calling the charge method:
"Omnipay\Common\Item::__construct(): Argument #1 ($parameters) must be of type ?array, string given, called in ...\vendor\omnipay\common\src\Common\ItemBag.php on line 72"
These are my __construct and charge methods:
public function __construct() {
$this->gateway = Omnipay::create('PayPal_Rest');
$this->gateway->setClientId(env('PAYPAL_CLIENT_ID'));
$this->gateway->setSecret(env('PAYPAL_CLIENT_SECRET'));
$this->gateway->setTestMode(true); // false in production server
}
public function charge(Request $request) {
if($request->method() == 'POST') {
try {
$response = $this->gateway->purchase(array(
'amount' => $request->input('amount'),
'items' => array(
'name' => $request->input('title'),
'price' => $request->input('amount'),
),
'currency' => env('PAYPAL_CURRENCY'),
'returnUrl' => url('success'),
'cancelUrl' => url('error'),
))->send();
if ($response->isRedirect()) {
$response->redirect();
}
else {
$response->getMessage();
}
} catch(Exception $e) {
return $e->getMessage();
}
}
}
I followed this tutorial: https://youtu.be/M9rk1ZB94u4 but can't get it to work.
Any idea on where is the array required as param?
Would appreciate any help.