Custom Payment success() method error in Bagisto 2.3 – haveStockableItems() null
-
Hi community,
I’m working on creating a custom payment method in Bagisto. I had a working setup on Bagisto v2.2, but after upgrading to Bagisto v2.3 (latest version), I’m getting the following error during the success flow.
public function success() { $cart = Cart::getCart(); $data = (new OrderResource($cart))->jsonSerialize(); // new class in v2.2 $order = $this->orderRepository->create($data); $this->orderRepository->update(['status' => 'processing'], $order->id); if ($order->canInvoice()) { $this->invoiceRepository->create($this->prepareInvoiceData($order)); } Cart::deActivateCart(); session()->flash('order_id', $order->id); return redirect()->route('shop.checkout.onepage.success'); }
Error: Call to a member function haveStockableItems() on null
Error Path:
packages/Webkul/Sales/src/Transformers/OrderResource.php
This exact code was working fine in v2.2, but on v2.3, I’m seeing this error.
Any idea what has changed in OrderResource or cart/order handling that might be causing this?
Thanks in advance!
-
and here the redirect method if it help you to understand it better:
public function redirect() { $cart = Cart::getCart(); $billingAddress = $cart->billing_address; $MERCHANT_KEY = core()->getConfigData('sales.payment_methods.payu.payu_merchant_key'); $SALT = core()->getConfigData('sales.payment_methods.payu.salt_key'); if (core()->getConfigData('sales.payment_methods.payu.payu-website') == "Sandbox") : $PAYU_BASE_URL = "https://test.payu.in"; // For Sandbox Mode else : $PAYU_BASE_URL = "https://secure.payu.in"; // For Live Mode endif; $shipping_rate = $cart->selected_shipping_rate ? $cart->selected_shipping_rate->price : 0; // shipping rate $discount_amount = $cart->discount_amount; // discount amount $total_amount = ($cart->sub_total + $cart->tax_total + $shipping_rate) - $discount_amount; // total amount $posted = array( "key" => $MERCHANT_KEY, "txnid" => $cart->id . '_' . now()->format('YmdHis'), "amount" => $total_amount, "firstname" => $billingAddress->name, "email" => $billingAddress->email, "phone" => $billingAddress->phone, "surl" => route('payu.success'), "furl" => route('payu.failure'), "curl" => "cancel", "hash" => '', "productinfo" => 'Bagisto Order no ' . $cart->id, 'udf1' => '', 'udf2' => '', 'udf3' => '', 'udf4' => '', 'udf5' => '', 'salt' => $SALT ); /*** hash key generate */ $hash = $this->getHashKey($posted); $action = $PAYU_BASE_URL . '/_payment'; return view('payu::payu-redirect')->with(compact('MERCHANT_KEY', 'SALT', 'action', 'posted', 'hash')); }