Created
January 9, 2019 14:02
-
-
Save kolomiec-valeriy/b7a0e62229ac7c759abab11aaea62844 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Command; | |
use App\Entity\ApiUser; | |
use App\Entity\Subscription\BaseReceipt; | |
use App\Entity\Subscription\IAPAndroidReceipt; | |
use App\Subscription\AndroidSubscriptionManager; | |
use Monolog\Registry; | |
use Symfony\Bridge\Doctrine\RegistryInterface; | |
use Symfony\Component\Console\Command\Command; | |
use Symfony\Component\Console\Input\InputInterface; | |
use Symfony\Component\Console\Output\OutputInterface; | |
use Symfony\Component\Console\Style\SymfonyStyle; | |
class ChangeSubscriptionTypeForTrialUsersCommand extends Command | |
{ | |
/** @var Registry $doctrine */ | |
private $doctrine; | |
/** @var AndroidSubscriptionManager $androidManager */ | |
private $androidManager; | |
public function __construct(RegistryInterface $doctrine, AndroidSubscriptionManager $androidManager) | |
{ | |
$this->androidManager = $androidManager; | |
$this->doctrine = $doctrine; | |
parent::__construct(); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function configure() | |
{ | |
$this | |
->setName('receipts:check_trial') | |
->setDescription('Command set subscription type to paid for trial users.'); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
protected function execute(InputInterface $input, OutputInterface $output) | |
{ | |
$em = $this->doctrine->getManager(); | |
$io = new SymfonyStyle($input, $output); | |
$receipts = $em->getRepository(IAPAndroidReceipt::class)->findBy([ | |
'platform' => 'android', | |
'paymentState' => 2, | |
'valid' => false, | |
]); | |
$counter = 0; | |
/** @var IAPAndroidReceipt $receipt */ | |
foreach ($receipts as $receipt) { | |
$user = $em->getRepository(ApiUser::class)->find($receipt->getUserId()); | |
if ($user && !$user->isPaid()) { | |
$user->setSubscriptionType(ApiUser::SUBSCRIPTION_TYPE_PAID); | |
$receipt->setValid(true); | |
$this->androidManager->queue($receipt, $receipt->getExpirationAt()); | |
$counter++; | |
} | |
} | |
$em->flush(); | |
$io->success('Finish for ' . $counter . ' receipts.'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment