<?php

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

/**
 * Description of Paypal_tmodel
 *
 * @author CIEXT skeleton
 */
class Paypal_tmodel extends \Ciext\Model\AbstractTableModel
{

    protected $table = 'paypal';
    protected $pkey = 'id_paypal';

    public function __construct()
    {
        parent::__construct();
        
        // Add events
        $this->config->load('paypal/events');
        foreach ($this->config->item('paypal_events')['paypal/paypal_tmodel'] as $event) {
            $this->attach($this->load->library($event));
        }
    }
    public function fetch_by_invoice($invoice = '')
    {
        $res = $this->db
                ->select($this->select)
                ->where('t.invoice', $invoice)
                ->get($this->table . ' t')
                ->row_array();

        // Notify all observers
        $this->notify(__FUNCTION__, ['id' => $res[$this->pkey]]);

        return $res;
    }
}
