Skip to content

Commit

Permalink
feat(WIP): add payment cancel command
Browse files Browse the repository at this point in the history
  • Loading branch information
syjust-alma committed Jan 17, 2023
1 parent 7db6959 commit 37d7ae7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"php" : ">=7.4",
"ext-ctype" : "*",
"ext-iconv" : "*",
"alma/alma-php-client" : "1.9.*",
"alma/alma-php-client" : "dev-feat/INT-1395-cancel-payment",
"symfony/console" : "5.3.*",
"symfony/dotenv" : "5.3.*",
"symfony/flex" : "^1.3.1",
Expand Down
45 changes: 45 additions & 0 deletions src/Command/AlmaPaymentCancelCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Command;

use Alma\API\RequestError;
use App\Command\Meta\AbstractWriteAlmaCommand;
use App\Command\Meta\DisplayOutputPaymentTrait;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class AlmaPaymentCancelCommand extends AbstractWriteAlmaCommand
{
use DisplayOutputPaymentTrait;
protected static $defaultName = 'alma:payment:cancel';
protected static $defaultDescription = 'Cancel an un-started payment';

protected function configure(): void
{
$this->configureOutputPaymentOptions();
$this
->addArgument(
'ID',
InputArgument::REQUIRED,
'the payment id formatted as payment_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx or only xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx if you prefer'
)
;
}

/**
* @throws RequestError
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$paymentId = $input->getArgument('ID');
$this->almaClient->payments->cancel($paymentId);

$io->success(sprintf("Payment '%s' successfully canceled", $paymentId));

return Command::SUCCESS;
}
}

0 comments on commit 37d7ae7

Please sign in to comment.