public function create(array $aData = [], $bReturnObject = false)
    {
        $oDb = Factory::service('Database');

        try {

            $oDb->trans_begin();

            if (empty($aData['ref'])) {
                $aData['ref'] = $this->generateValidRef();
            }

            $aData['token'] = $this->generateToken();

            if (array_key_exists('custom_data', $aData)) {
                $aData['custom_data'] = json_encode($aData['custom_data']);
            }

            $mPayment = parent::create($aData, $bReturnObject);

            if (!$mPayment) {
                throw new PaymentException('Failed to create payment.');
            }

            $oDb->trans_commit();
            $this->triggerEvent(
                Events::PAYMENT_CREATED,
                [$this->getPaymentForEvent($bReturnObject ? $mPayment->id : $mPayment)]
            );

            return $mPayment;

        } catch (\Exception $e) {
            $oDb->trans_rollback();
            $this->setError($e->getMessage());
            return false;
        }
    }