280 lines
8.0 KiB
PHP
280 lines
8.0 KiB
PHP
<?php
|
|
/**
|
|
* 1997-2016 Quadra Informatique
|
|
*
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This source file is subject to the Open Software License (OSL 3.0) that is available
|
|
* through the world-wide-web at this URL: http://www.opensource.org/licenses/OSL-3.0
|
|
* If you are unable to obtain it through the world-wide-web, please send an email
|
|
* to modules@quadra-informatique.fr so we can send you a copy immediately.
|
|
*
|
|
* @author Quadra Informatique <modules@quadra-informatique.fr>
|
|
* @copyright 1997-2016 Quadra Informatique
|
|
* @license http://www.opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
|
*/
|
|
|
|
class Be2billTransaction extends ObjectModel
|
|
{
|
|
|
|
const TYPE_PAYMENT = 'payment';
|
|
const TYPE_AUTHORIZATION = 'authorization';
|
|
const TYPE_CAPTURE = 'capture';
|
|
const TYPE_REFUND = 'refund';
|
|
|
|
/**
|
|
* Be2bill Transaction ID
|
|
* @var integer
|
|
*/
|
|
public $id_b2b_transaction;
|
|
|
|
/**
|
|
* Order ID
|
|
* @var integer
|
|
*/
|
|
public $id_order;
|
|
|
|
/**
|
|
* Order Slip ID
|
|
* @var integer
|
|
*/
|
|
public $id_order_slip;
|
|
|
|
/**
|
|
* TRANSACTIONID parameter send by the payment platform
|
|
* @var string
|
|
*/
|
|
public $transaction_id;
|
|
|
|
/**
|
|
* OPERATIONTYPE parameter send by the payment platform
|
|
* @var string
|
|
*/
|
|
public $transaction_type;
|
|
|
|
/**
|
|
* AMOUNT parameter send by the payment platform
|
|
* @var float
|
|
*/
|
|
public $amount;
|
|
|
|
/**
|
|
* AMOUNT parameter send by the payment platform
|
|
* @var float
|
|
*/
|
|
public $id_merchand_account;
|
|
|
|
/**
|
|
* Object creation date
|
|
* @var date
|
|
*/
|
|
public $date_add;
|
|
|
|
/**
|
|
* @see ObjectModel::$definition
|
|
*/
|
|
public static $definition = array(
|
|
'table' => 'b2b_transaction',
|
|
'primary' => 'id_b2b_transaction',
|
|
'fields' => array(
|
|
'id_order' => array(
|
|
'type' => self::TYPE_INT,
|
|
'validate' => 'isInt',
|
|
'required' => true
|
|
),
|
|
'id_order_slip' => array(
|
|
'type' => self::TYPE_INT,
|
|
'validate' => 'isInt',
|
|
),
|
|
'transaction_id' => array(
|
|
'type' => self::TYPE_STRING,
|
|
'validate' => 'isString',
|
|
'required' => true
|
|
),
|
|
'transaction_type' => array(
|
|
'type' => self::TYPE_STRING,
|
|
'validate' => 'isString',
|
|
'required' => true
|
|
),
|
|
'amount' => array(
|
|
'type' => self::TYPE_FLOAT,
|
|
'validate' => 'isFloat',
|
|
'required' => true
|
|
),
|
|
'id_merchand_account' => array(
|
|
'type' => self::TYPE_INT,
|
|
'validate' => 'isInt',
|
|
),
|
|
'date_add' => array(
|
|
'type' => self::TYPE_DATE,
|
|
'validate' => 'isDate')
|
|
)
|
|
);
|
|
|
|
/**
|
|
* Create Transaction table
|
|
* @return boolean
|
|
*/
|
|
public static function createBe2billTransactionTable()
|
|
{
|
|
$sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'b2b_transaction` (
|
|
`id_b2b_transaction` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
`id_order` INT(10) UNSIGNED NOT NULL,
|
|
`id_order_slip` INT(10) UNSIGNED DEFAULT 0,
|
|
`transaction_id` VARCHAR(25) NOT NULL,
|
|
`transaction_type` VARCHAR(25) NOT NULL,
|
|
`amount` DECIMAL(17,2) NOT NULL,
|
|
`id_merchand_account` INT(10) UNSIGNED NOT NULL,
|
|
`date_add` DATETIME NOT NULL,
|
|
PRIMARY KEY (`id_b2b_transaction`)
|
|
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8';
|
|
|
|
return Db::getInstance()->execute($sql);
|
|
}
|
|
|
|
/**
|
|
* Get transaction by TRANSACTIONID parameter
|
|
* @param string $transaction_id
|
|
* @return array|boolean
|
|
*/
|
|
public static function getByTransactionId($transaction_id)
|
|
{
|
|
return Db::getInstance()->getRow('
|
|
SELECT *
|
|
FROM `'._DB_PREFIX_.'b2b_transaction`
|
|
WHERE `transaction_id` = \''.pSQL($transaction_id).'\'
|
|
');
|
|
}
|
|
|
|
/**
|
|
* Get transaction by TRANSACTIONID parameter
|
|
* @param string $transaction_id
|
|
* @return array|boolean
|
|
*/
|
|
public static function getMerchandAccountIdByTransactionId($transaction_id)
|
|
{
|
|
return Db::getInstance()->getValue('
|
|
SELECT id_merchand_account
|
|
FROM `'._DB_PREFIX_.'b2b_transaction`
|
|
WHERE `transaction_id` = \''.pSQL($transaction_id).'\'
|
|
');
|
|
}
|
|
|
|
/**
|
|
* Get transaction by TRANSACTIONID parameter
|
|
* @param string $order_id
|
|
* @return array|boolean
|
|
*/
|
|
public static function getMerchandAccountIdByOrderId($order_id)
|
|
{
|
|
return Db::getInstance()->getValue('
|
|
SELECT id_merchand_account
|
|
FROM `'._DB_PREFIX_.'b2b_transaction`
|
|
WHERE `id_order` = \''.pSQL($order_id).'\'
|
|
');
|
|
}
|
|
|
|
/**
|
|
* Get refundable transaction for the order
|
|
* @param int $id_order
|
|
* @return array|boolean
|
|
*/
|
|
public static function getOrderRefundableTransaction($reference)
|
|
{
|
|
return Db::getInstance()->executeS('
|
|
SELECT bt.*
|
|
FROM `'._DB_PREFIX_.'b2b_transaction` bt
|
|
LEFT JOIN `'._DB_PREFIX_.'b2b_execcode_history` beh ON (bt.`id_b2b_transaction` = beh.`id_b2b_transaction`)
|
|
WHERE bt.`id_order` IN (
|
|
SELECT `id_order`
|
|
FROM `'._DB_PREFIX_.'orders`
|
|
WHERE `reference` = \''.pSQL($reference).'\'
|
|
)
|
|
AND (bt.`transaction_type` = \''.pSQL(self::TYPE_PAYMENT).'\'
|
|
OR bt.`transaction_type` = \''.pSQL(self::TYPE_CAPTURE).'\')
|
|
AND (beh.`id_b2b_execcode` = \'0000\'
|
|
OR beh.`id_b2b_execcode` IS NULL)
|
|
');
|
|
}
|
|
/**
|
|
* Get refundable slip for the order
|
|
* @param int $id_order, int $id_customer
|
|
* @return array|boolean
|
|
*/
|
|
public static function getOrderRefundableSlip($id_order, $id_customer)
|
|
{
|
|
if (!Validate::isUnsignedId($id_order) || !Validate::isUnsignedId($id_customer)) {
|
|
return false;
|
|
}
|
|
|
|
return Db::getInstance()->executeS('
|
|
SELECT *
|
|
FROM `'._DB_PREFIX_.'order_slip`
|
|
WHERE `id_customer` = '.(int)$id_customer.'
|
|
AND `id_order` = '.(int)$id_order.'
|
|
AND `id_order_slip` NOT IN (
|
|
SELECT bt.`id_order_slip`
|
|
FROM `'._DB_PREFIX_.'b2b_transaction` bt
|
|
LEFT JOIN `'._DB_PREFIX_.'b2b_execcode_history` beh ON (bt.`id_b2b_transaction` = beh.`id_b2b_transaction`)
|
|
WHERE bt.`id_order` = \''.pSQL($id_order).'\'
|
|
AND bt.`transaction_type` = \''.pSQL(self::TYPE_REFUND).'\'
|
|
AND beh.`id_b2b_execcode` = \'0000\'
|
|
)
|
|
ORDER BY `date_add` DESC
|
|
');
|
|
}
|
|
|
|
/**
|
|
* Get transaction by order ID where transaction type is refund
|
|
* @param int $id_order
|
|
* @return array|boolean
|
|
*/
|
|
public static function getOrderRefundedTransaction($id_order)
|
|
{
|
|
if (!Validate::isUnsignedId($id_order)) {
|
|
return false;
|
|
}
|
|
|
|
return Db::getInstance()->executeS('
|
|
SELECT *
|
|
FROM `'._DB_PREFIX_.'b2b_transaction`
|
|
WHERE `id_order` = \''.pSQL($id_order).'\'
|
|
AND `transaction_type` = \''.pSQL(self::TYPE_REFUND).'\'
|
|
');
|
|
}
|
|
|
|
/**
|
|
* Get transaction and execcode history by order reference
|
|
* @param string $reference
|
|
* @return array|boolean
|
|
*/
|
|
public static function getOrderTransactionHistory($reference)
|
|
{
|
|
return Db::getInstance()->executeS('
|
|
SELECT bt.*, be.`id_b2b_execcode` execcode, be.`message`
|
|
FROM `'._DB_PREFIX_.'b2b_transaction` bt
|
|
LEFT JOIN `'._DB_PREFIX_.'b2b_execcode_history` beh ON (bt.`id_b2b_transaction` = beh.`id_b2b_transaction`)
|
|
LEFT JOIN `'._DB_PREFIX_.'b2b_execcode` be ON (beh.`id_b2b_execcode` = be.`id_b2b_execcode`)
|
|
WHERE bt.`id_order` IN (
|
|
SELECT `id_order`
|
|
FROM `'._DB_PREFIX_.'orders`
|
|
WHERE `reference` = \''.pSQL($reference).'\'
|
|
)
|
|
ORDER BY beh.`date_add` ASC
|
|
');
|
|
}
|
|
|
|
/**
|
|
* Returns transaction array from old tables or false
|
|
* @param none
|
|
* @return boolean|string
|
|
*/
|
|
public static function getOldList()
|
|
{
|
|
return Db::getInstance()->executeS('
|
|
SELECT *
|
|
FROM `'._DB_PREFIX_.'be2bill_transaction`
|
|
');
|
|
}
|
|
}
|