189 lines
5.3 KiB
PHP
189 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Web\Controllers;
|
|
|
|
use Antadis\API\Front\Web\Controllers\Controller as BaeController;
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
//TODO: Create Models PayaplAccount and PayboxAccount instead of doing request (DELETE + SELECT)
|
|
//in the controller.
|
|
class AccountPaymentController extends BaeController
|
|
{
|
|
/**
|
|
* Return user accounts
|
|
*
|
|
* @return array(
|
|
* 'paypal' => [paypal_accounts]
|
|
* 'paybox' => [paybox_accounts]
|
|
* )
|
|
*/
|
|
public function list_accounts(Request $request) {
|
|
return array(
|
|
'paypal' => $this->list_paypal($request),
|
|
'paybox' => $this->list_paybox($request),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* List paypal accounts of the current connected user
|
|
*
|
|
* @return array() Paypal accounts
|
|
*/
|
|
public function list_paypal(Request $request)
|
|
{
|
|
return \Db::getInstance()->executes('
|
|
SELECT `id_paypal_agreement`, `email`, `name`, `city`, `date_add`
|
|
FROM `'._DB_PREFIX_.'paypal_customer_agreement`
|
|
WHERE `id_customer`= '.(int) $request->user()->id.'
|
|
');
|
|
}
|
|
|
|
/**
|
|
* List paybox accounts of the current connected user
|
|
*
|
|
* @return array() Paybox accounts
|
|
*/
|
|
public function list_paybox(Request $request)
|
|
{
|
|
return \Db::getInstance()->executes('
|
|
SELECT `id_paybox_card`, `value`, `date`, `payment_type`
|
|
FROM `'._DB_PREFIX_.'paybox_customer_agreement`
|
|
WHERE `id_customer`= '.(int) $request->user()->id.'
|
|
');
|
|
}
|
|
|
|
/**
|
|
* Delete paypal account by his id ($id_paypal)
|
|
*
|
|
* @param integer $id_paypal
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function delete_paypal(Request $request, $id_paypal) {
|
|
$id_customer = $this->getIdCustomerFromIdPaypal($id_paypal);
|
|
|
|
if ($id_customer !== (int)$request->user()->id) {
|
|
return $this->forbidden();
|
|
}
|
|
return $this->deletPaypalById($id_paypal) === true ?
|
|
array() : $this->server_error();
|
|
}
|
|
|
|
/**
|
|
* Delete paybox account by his id ($id_paybox_card)
|
|
*
|
|
* @param integer $id_paybox_card
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function delete_paybox(Request $request, $id_paybox_card) {
|
|
$id_customer = $this->getIdCustomerFromPaybox($id_paybox_card);
|
|
|
|
if ($id_customer !== (int)$request->user()->id) {
|
|
return $this->forbidden();
|
|
}
|
|
return $this->deletePayboxById($id_paybox_card) === true ?
|
|
array() : $this->server_error();
|
|
}
|
|
|
|
/**
|
|
* Delete paybox account by his id ($id_paybox_card)
|
|
*
|
|
* @param integer $id_paybox_card
|
|
*
|
|
* @return boolean Whether removal succeed or not
|
|
*/
|
|
protected function deletePayboxById($id_paybox_card) {
|
|
return \Db::getInstance()->execute('
|
|
DELETE FROM `'._DB_PREFIX_.'paybox_customer_agreement`
|
|
WHERE `id_paybox_card`= '.(int) $id_paybox_card
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Delete paypal account by his id ($id_paypal)
|
|
*
|
|
* @param integer $id_paypal
|
|
*
|
|
* @return boolean Whether removal succeed or not
|
|
*/
|
|
protected function deletPaypalById($id_paypal) {
|
|
return \Db::getInstance()->execute('
|
|
DELETE FROM `'._DB_PREFIX_.'paypal_customer_agreement`
|
|
WHERE `id_paypal_agreement`= '.(int) $id_paypal
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Returns id_customer which owns id_paypal
|
|
*
|
|
* @param integer $id_paypal
|
|
*
|
|
* @return integer $id_customer
|
|
*/
|
|
protected function getIdCustomerFromIdPaypal($id_paypal) {
|
|
return (int)\Db::getInstance()->getValue('
|
|
SELECT `id_customer`
|
|
FROM `'._DB_PREFIX_.'paypal_customer_agreement`
|
|
WHERE `id_paypal_agreement`= '.(int) $id_paypal.'
|
|
');
|
|
}
|
|
|
|
/**
|
|
* Returns id_customer which owns id_paypal
|
|
*
|
|
* @param integer $id_paypal
|
|
*
|
|
* @return integer $id_customer
|
|
*/
|
|
protected function getIdCustomerFromPaybox($id_paybox) {
|
|
return (int)\Db::getInstance()->getValue('
|
|
SELECT `id_customer`
|
|
FROM `'._DB_PREFIX_.'paybox_customer_agreement`
|
|
WHERE `id_paybox_card`= '.(int) $id_paybox.'
|
|
');
|
|
}
|
|
|
|
/**
|
|
* Returns paypal account from id_paypal
|
|
*
|
|
* @param integer $id_paypal
|
|
*
|
|
* @return array(
|
|
* 'id_paypal_agreement'
|
|
* 'email' => string,
|
|
* 'name' => string,
|
|
* 'city' => string,
|
|
* 'date_add' => string,
|
|
* )
|
|
*/
|
|
protected function get_paypal($id_paypal) {
|
|
return \Db::getInstance()->getRow('
|
|
SELECT `id_paypal_agreement`, `email`, `name`, `city`, `date_add`
|
|
FROM `'._DB_PREFIX_.'paypal_customer_agreement`
|
|
WHERE `id_paypal_agreement`= '.(int) $id_paypal.'
|
|
');
|
|
}
|
|
|
|
/**
|
|
* Returns paybox cards from id_paybox_card
|
|
*
|
|
* @param integer $id_paybox_card
|
|
*
|
|
* @return array(
|
|
* 'id_paybox_card'
|
|
* 'value' => string,
|
|
* 'date' => string,
|
|
* 'payment_type' => string,
|
|
* )
|
|
*/
|
|
protected function get_paybox($id_paybox_card) {
|
|
return \Db::getInstance()->getRow('
|
|
SELECT `id_paybox_card`, `value`, `date`, `payment_type`
|
|
FROM `'._DB_PREFIX_.'paybox_customer_agreement`
|
|
WHERE `id_paybox_cad` = '.(int)$id_paybox_card.'
|
|
');
|
|
}
|
|
}
|