<?php
namespace LaunchPad\Bundle\LaunchPadBundle\Admin\Api\Controller;
use Doctrine\Common\Annotations\AnnotationException;
use LaunchPad\Bundle\LaunchPadBundle\Base\Entity\Transaction\Transaction;
use LaunchPad\Bundle\LaunchPadBundle\Base\Exception\MissingApiParamsException;
use LaunchPad\Bundle\LaunchPadBundle\Base\Service\McApiService;
use LaunchPad\Bundle\LaunchPadBundle\Base\Service\TransactionService;
use LaunchPad\Bundle\LaunchPadBundle\Base\Service\Translation\TranslationService;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\Exception\ExceptionInterface;
use OpenApi\Annotations as OA;
use LaunchPad\Bundle\LaunchPadBundle\Base\Service\TransactionWithThisIdDoesNotExist;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* Class TransactionController
* @package BoBoFin\Admin\Api\Controller
* @Route("/transaction", name="admin_")
*/
class TransactionController extends BaseAdminApiController
{
/** @var McApiService */
private $mcApiService;
/** @var TransactionService */
private $transactionService;
/**
* TransactionController constructor.
*
* @param TranslationService $translationService
* @param TransactionService $transactionService
* @param McApiService $mcApiService
*/
public function __construct(
TranslationService $translationService,
TransactionService $transactionService,
McApiService $mcApiService
) {
parent::__construct($translationService);
$this->mcApiService = $mcApiService;
$this->transactionService = $transactionService;
}
/**
* @Route("/mastercard/test", name="mc_api_test")
* @return JsonResponse
* @throws AnnotationException
* @throws ExceptionInterface
*/
public function testAction()
{
$test = $this->mcApiService->test();
// dump($test);die;
return $this->success();
}
/**
* @Route("/list", name="transaction_list")
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\Common\Annotations\AnnotationException
* @return JsonResponse
* @throws AnnotationException
* @throws ExceptionInterface
*/
public function getPaymentTransactionListAction()
{
$list = $this->paginatorService->getPaginated(
Transaction::class,
$this->data
);
return $this->success($list, null, ['transaction_data']);
}
/**
* @Route("/save", name="transaction_save")
* @param TransactionService $transactionService
* @return JsonResponse
* @throws AnnotationException
* @throws MissingApiParamsException
* @throws ExceptionInterface
*/
public function addOrEditTransaction(TransactionService $transactionService)
{
$this->requirePostParams(['account_id', 'user_id', 'category_id', 'merchant_id', 'country_id', 'payment_card_id', 'card_id', 'currency_id', 'original_currency_id', 'title', 'address', 'city', 'amount', 'original_amount', 'gps_latitude', 'gps_longitude', 'transaction_date', 'post_date']);
$this->transactionService->saveTransactionFromAdmin(
@$this->data['id'],
$this->data['account_id'],
$this->data['user_id'],
$this->data['category_id'],
$this->data['merchant_id'],
$this->data['country_id'],
$this->data['payment_card_id'],
$this->data['card_id'],
$this->data['currency_id'],
$this->data['original_currency_id'],
$this->data['title'],
$this->data['address'],
$this->data['city'],
$this->data['amount'],
$this->data['original_amount'],
$this->data['gps_latitude'],
$this->data['gps_longitude'],
$this->data['transaction_date'],
$this->data['post_date']
);
return $this->success();
}
/**
* @Route("/delete/{id}", name="transaction_delete")
* @param $id
* @return JsonResponse
* @throws AnnotationException
* @throws ExceptionInterface
*/
public function deleteTransactionAction($id, TransactionService $transactionService)
{
die('DISABLED');
$this->transactionService->deleteTransaction($id);
return $this->success();
}
/**
* @Route("/details", name="admin_transactions_details")
* @param TransactionService $transactionService
* @return JsonResponse
* @throws ExceptionInterface
* @throws AnnotationException
* @throws MissingApiParamsException
* @throws TransactionWithThisIdDoesNotExist
*/
public function getTransactionsDetailsAction(TransactionService $transactionService)
{
$this->requirePostParams(['id']);
$user = $this->transactionService->getTransactionByIdFromAdmin($this->data['id']);
return $this->success($user, null, ['transaction_data']);
$user = $transactionService->getTransactionByIdFromAdmin($this->data['id']);
return $this->success($user, null,
['transaction_data', 'user_data', 'account_data', 'payment_device_data', 'transaction_category_data', 'transaction_merchant_data', 'country_data', 'payment_card_data']
);
}
/**
* @Route("/mc-mandate/fx", name="transactions_mc_mandate_fx")
*
* @OA\Post(
* path="/transaction/mc-mandate/fx",
* operationId="getUserTransactionExport",
* tags={"Transaction"},
* summary="Get user transactions export",
* description="Export all user transactions",
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(
* type="object",
* @OA\Property(property="id", type="integer")
* )
* ),
* @OA\Response(
* response=200,
* description="Success Response",
* @OA\JsonContent(ref="#/components/schemas/SuccessResponse")
* )
* )
* @param Request $request
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\Common\Annotations\AnnotationException
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface
*/
public function getExchangeForFXTransaction()
{
$this->requirePostParams(['id']);
$response = $this->transactionService->getFxExchangeForTransaction($this->data['id']);
return $this->success($response, null, ['transaction_data', 'mc_fx_data', 'fx_fee_data']);
}
/**
* Get All Transactions
*
* @param TransactionService $transactionService
* @return mixed
* @throws \Doctrine\Common\Annotations\AnnotationException
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface
* @throws \Doctrine\ORM\NonUniqueResultException
* @Route("/all", name="transaction_all_admin")
*
* @OA\Post(
* path="/transaction/all",
* operationId="getTransactionsAction",
* tags={"Transaction "},
* summary="Transaction",
* description="Returns all number transaction",
* @OA\Response(
* response=200,
* description="Successful operation",
* @OA\JsonContent(ref="#/components/schemas/SuccessResponse")
* ),
* security={
* {"Bearer": {}}
* }
* )
*/
public function getTransactionsAction()
{
$transactions = $this->transactionService->getTransactions();
return $this->success($transactions, null, ['transaction_data']);
}
/**
* Get All Overtime Transactions Trend
*
* @param TransactionService $transactionService
* @return mixed
* @throws \Doctrine\Common\Annotations\AnnotationException
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface
* @throws \Doctrine\ORM\NonUniqueResultException
* @Route("/over-time/trend", name="transaction_overtime_trend")
*
* @OA\Post(
* path="/transaction/over-time/trend",
* operationId="getNumberOfTransactionsOverTimeTrendAction",
* tags={"Transaction "},
* summary="Transaction",
* description="Returns all number overtime transaction",
* @OA\Response(
* response=200,
* description="Successful operation",
* @OA\JsonContent(ref="#/components/schemas/SuccessResponse")
* ),
* security={
* {"Bearer": {}}
* }
* )
*/
public function getNumberOfTransactionsOverTimeTrendAction()
{
$transactions = $this->transactionService->getTotalNumberOvertimeTransactions(
@$this->data['startDate'], @$this->data['endDate']);
return $this->success($transactions, null, ['transaction_data']);
}
/**
* Get All Transactions By Category Trend
*
* @param TransactionService $transactionService
* @return mixed
* @throws \Doctrine\Common\Annotations\AnnotationException
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface
* @throws \Doctrine\ORM\NonUniqueResultException
* @Route("/category/trend", name="transaction_category_trend")
*
* @OA\Post(
* path="/transaction/category/trend",
* operationId="getTransactionsByCategoryAction",
* tags={"Transaction "},
* summary="Transaction",
* description="Returns all number transactions by category",
* @OA\Response(
* response=200,
* description="Successful operation",
* @OA\JsonContent(ref="#/components/schemas/SuccessResponse")
* ),
* security={
* {"Bearer": {}}
* }
* )
*/
public function getTransactionsByCategoryAction()
{
$transactions = $this->transactionService->getTransactionsByCategory(
@$this->data['startDate'],
@$this->data['endDate']);
return $this->success($transactions, null, ['transaction_data']);
}
/**
* Get All Transactions By Country Trend
*
* @param TransactionService $transactionService
* @return mixed
* @throws \Doctrine\Common\Annotations\AnnotationException
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface
* @throws \Doctrine\ORM\NonUniqueResultException
* @Route("/country/trend", name="transaction_country_trend")
*
* @OA\Post(
* path="/transaction/country/trend",
* operationId="getTransactionsPerCountryAction",
* tags={"Transaction "},
* summary="Transaction",
* description="Returns all number overtime transaction by country",
* @OA\Response(
* response=200,
* description="Successful operation",
* @OA\JsonContent(ref="#/components/schemas/SuccessResponse")
* ),
* security={
* {"Bearer": {}}
* }
* )
*/
public function getTransactionsPerCountryAction()
{
$transactions = $this->transactionService->getTransactionsByCountry(
@$this->data['startDate'],
@$this->data['endDate']);
return $this->success($transactions, null, ['transaction_data']);
}
/**
* Get Average Transactions Trend
*
* @param TransactionService $transactionService
* @return mixed
* @throws \Doctrine\Common\Annotations\AnnotationException
* @throws \Symfony\Component\Serializer\Exception\ExceptionInterface
* @throws \Doctrine\ORM\NonUniqueResultException
* @Route("/average/trend", name="transaction_average_trend")
*
* @OA\Post(
* path="/transaction/average/trend",
* operationId="getAverageTransactionsForPeriodsAction",
* tags={"Transaction "},
* summary="Transaction",
* description="Returns all avearge transaction",
* @OA\Response(
* response=200,
* description="Successful operation",
* @OA\JsonContent(ref="#/components/schemas/SuccessResponse")
* ),
* security={
* {"Bearer": {}}
* }
* )
*/
public function getAverageTransactionsForPeriodsAction()
{
$transactions = $this->transactionService->getAverageTransactionForPeriod(
@$this->data['startDate'],
@$this->data['endDate']);
return $this->success($transactions, null, ['transaction_data']);
}
}