|
<?php defined('SYSPATH') OR die('No direct access allowed.'); |
|
|
|
class VCard_Model_Transaction_Authorization extends VCard_ORM { |
|
|
|
protected $_table_columns = array( |
|
'id' => null, |
|
'ref_hash' => null, |
|
'trace' => null, |
|
'network' => null, |
|
'channel' => null, |
|
'card_id' => null, |
|
'card_currency' => null, |
|
'card_amount' => null, |
|
'transaction_type' => null, |
|
'transaction_currency' => null, |
|
'transaction_amount' => null, |
|
'terminal_id' => null, |
|
'merchant_id' => null, |
|
'merchant_name' => null, |
|
'merchant_category_code' => null, |
|
'insitution_code' => null, |
|
'response_code' => null, |
|
'description' => null, |
|
'settlment_date' => null, |
|
'response_balance' => null, |
|
'execution_time' => null, |
|
'reversal_response_code' => null, |
|
'reversal_description' => null, |
|
'reversal_settlement_date' => null, |
|
'date_reversal' => null, |
|
'date_added' => null, |
|
); |
|
|
|
/** |
|
* Returns transaction record |
|
* |
|
* @param string $hash Transaction Hash |
|
* @param object $user User Object |
|
* @param int $status Transaction Status |
|
* |
|
* @return object |
|
*/ |
|
public function get_record($hash, $card) |
|
{ |
|
return $this->where('ref_hash', '=', $hash) |
|
->where('user_id', '=', $card->id) |
|
->find(); |
|
} |
|
|
|
/** |
|
* Get Transaction's user ORM Object |
|
* |
|
* @return object |
|
*/ |
|
public function get_card() |
|
{ |
|
return (!$this->loaded()) ? false : ORM::factory('Card', $this->card_id); |
|
} |
|
|
|
/** |
|
* This function returns the topup and money transfer totals by a certain duration |
|
* plus the newly requested amount. |
|
* |
|
* @param string $duration Model_Card_Type::$_limits |
|
* @param int $card_id |
|
* @param float $amount the requested amount |
|
* |
|
* @return float Outstanding total |
|
*/ |
|
public static function get_transactions_total_by_duration($duration, $card_id, $amount = 0) |
|
{ |
|
$data = ORM::factory('Transaction_Authorization') |
|
->select(DB::Expr('sum(transaction_total) as total')) |
|
->where('card_id', '=', $card_id) |
|
->where(DB::Expr($duration.'(now())'),'=', DB::Expr($duration.'(date_added)')) |
|
->find(); |
|
$total = !empty($data->total) ? $data->total : 0; |
|
$total += $amount; |
|
|
|
return $total; |
|
} |
|
|
|
} |