src/Model/Payment.php
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;
        }
    }
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;
        }
    }
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 ; } }
Create a new payment

@param  array   $aData         The data to create the payment with
@param  boolean $bReturnObject Whether to return the complete payment object

@return bool|mixed
@throws \Nails\Common\Exception\FactoryException
Create a new payment