card action
This commit is contained in:
@ -5,6 +5,8 @@ namespace kernel\app_modules\card\services;
|
||||
use DragonCode\CardNumber\CardNumber;
|
||||
use DragonCode\CardNumber\Factories\BankFactory;
|
||||
use DragonCode\CardNumber\Formatters\BankFormatter;
|
||||
use kernel\app_modules\card\models\CardTransaction;
|
||||
use kernel\app_modules\card\models\forms\CreateCardTransactionForm;
|
||||
use kernel\helpers\Debug;
|
||||
use kernel\app_modules\card\models\Card;
|
||||
use kernel\FormModel;
|
||||
@ -14,10 +16,12 @@ use kernel\modules\user\models\User;
|
||||
class CardService
|
||||
{
|
||||
protected CardFileService $cardFileService;
|
||||
protected CardTransactionService $cardTransactionService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->cardFileService = new CardFileService();
|
||||
$this->cardTransactionService = new CardTransactionService();
|
||||
}
|
||||
|
||||
public function create(FormModel $form_model): false|Card
|
||||
@ -28,7 +32,7 @@ class CardService
|
||||
$model->payment_type = $form_model->getItem('payment_type') ?? 2;
|
||||
$model->bank_id = $form_model->getItem('bank_id') ?? 232;
|
||||
$model->info = $form_model->getItem('info') ?? 42;
|
||||
$model->program = $form_model->getItem('program') ?? 71;
|
||||
$model->card_program_id = $form_model->getItem('card_program_id') ?? 71;
|
||||
$model->balance = $form_model->getItem('balance') ?? 0;
|
||||
$model->cvc = $form_model->getItem('cvc') ?? 101;
|
||||
$model->pin = $form_model->getItem('pin') ?? 1111;
|
||||
@ -56,7 +60,7 @@ class CardService
|
||||
$card->payment_type = $form_model->getItem('payment_type');
|
||||
$card->bank_id = $form_model->getItem('bank_id');
|
||||
$card->info = $form_model->getItem('info');
|
||||
$card->program = $form_model->getItem('program');
|
||||
$card->card_program_id = $form_model->getItem('card_program_id');
|
||||
$card->balance = $form_model->getItem('balance');
|
||||
$card->cvc = $form_model->getItem('cvc');
|
||||
$card->pin = $form_model->getItem('pin');
|
||||
@ -81,12 +85,44 @@ class CardService
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function addMoneyToCard(Card $card, int $amount): CardTransaction
|
||||
{
|
||||
$transactionForm = new CreateCardTransactionForm();
|
||||
$transactionForm->load([
|
||||
'from' => 1001,
|
||||
'to' => $card->id,
|
||||
'amount' => $amount,
|
||||
'type' => 1,
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
$transactionService = new CardTransactionService();
|
||||
|
||||
return $transactionService->create($transactionForm);
|
||||
}
|
||||
|
||||
public static function withdrawMoneyFromCard(Card $card, int $amount): CardTransaction
|
||||
{
|
||||
$transactionForm = new CreateCardTransactionForm();
|
||||
$transactionForm->load([
|
||||
'from' => $card->id,
|
||||
'to' => 1001,
|
||||
'amount' => $amount,
|
||||
'type' => 1,
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
$transactionService = new CardTransactionService();
|
||||
|
||||
return $transactionService->create($transactionForm);
|
||||
}
|
||||
|
||||
public static function createCardPNG(Card $card): false|string
|
||||
{
|
||||
if ($card->cardTemplate) {
|
||||
$formatter = BankFormatter::create();
|
||||
|
||||
$customer = BankFactory::create()->paymentType($card->payment_type)->bank($card->bank_id, $card->info, $card->program)->client($card->id);
|
||||
$customer = BankFactory::create()->paymentType($card->payment_type)->bank($card->bank_id, $card->info, $card->card_program_id)->client($card->id);
|
||||
|
||||
$cardNumber = CardNumber::generate($customer, $formatter);
|
||||
//Card
|
||||
@ -110,6 +146,16 @@ class CardService
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getCardById(int $id)
|
||||
{
|
||||
$card = Card::find($id);
|
||||
if ($card) {
|
||||
return $card;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function userHasCard(int $userId): bool
|
||||
{
|
||||
$card = Card::where("user_id", $userId)->first();
|
||||
|
Reference in New Issue
Block a user