gpupo/adyen-sdk

View on GitHub
bin/main

Summary

Maintainability
Test Coverage
#!/usr/bin/env php
<?php

/*
 * This file is part of gpupo/adyen-sdk
 *
 * (c) Gilmar Pupo <contact@gpupo.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * For more information, see
 * <https://opensource.gpupo.com/adyen-sdk/>.
 */

require __DIR__.'/../vendor/autoload.php';

use Gpupo\AdyenSdk\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Gpupo\AdyenSdk\Payment\Response\Decorator\BoletoDecorator;

$app = new Application('adyen-sdk', 1);
$app->findConfig([__DIR__.'/../']);

$transaction_create_parameters = [[
    'key'   => 'request_json_file',
]];

$app->register('payment:request')
    ->setDescription('Cria uma transação')
    ->setDefinition($app->factoryDefinition($transaction_create_parameters))
    ->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $transaction_create_parameters) {
        $list = $app->processInputParameters($transaction_create_parameters, $input, $output);
        $sdk = $app->factorySdk($list);
        $data = json_decode(file_get_contents($list['request_json_file']), true);
        $request = $sdk->createRequest($data);
        $manager = $sdk->factoryManager('Request');
        $transaction = $manager->submit($request);

        if ($transaction) {
            $output->writeln('<info>Successo!</info>');

            if($transaction instanceof BoletoDecorator) {
                $output->writeln('Linha digitável <info>'.$transaction->getBarCodeReference().'</info>');
                $output->writeln('Vencimento <info>'.$transaction->getExpirationDate().'</info>');
                $output->writeln('Url <info>'.$transaction->getUrl().'</info>');
            }
        } else {
            $output->writeln('<error>Erro na criação da transação</error>');
        }
    });

$app->run();