Skip to content

Commit

Permalink
Payment cards separation - second phase
Browse files Browse the repository at this point in the history
- Refactored all references from deprecated `recurrent_payments.cid` to `payment_method.external_token`

remp/crm#3221
  • Loading branch information
burithetech committed Oct 1, 2024
1 parent 5f85c1b commit d0d82a8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/Api/VerifyPurchaseApiHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private function createPayment(

$activePurchaseTokenRecurrents = $this->recurrentPaymentsRepository
->getUserActiveRecurrentPayments($payment->user_id)
->where(['cid' => $purchaseTokenRow->purchase_token])
->where(['payment_method.external_token' => $purchaseTokenRow->purchase_token])
->fetchAll();
foreach ($activePurchaseTokenRecurrents as $rp) {
$this->recurrentPaymentsRepository->stoppedBySystem($rp->id);
Expand Down
39 changes: 12 additions & 27 deletions src/Tests/Hermes/DeveloperNotificationReceivedHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Crm\GooglePlayBillingModule\Tests\Hermes;

use Crm\ApplicationModule\Hermes\HermesMessage;
use Crm\ApplicationModule\Models\Config\ApplicationConfig;
use Crm\ApplicationModule\Repositories\ConfigCategoriesRepository;
use Crm\ApplicationModule\Repositories\ConfigsRepository;
use Crm\ApplicationModule\Seeders\ConfigsSeeder as ApplicationConfigsSeeder;
Expand Down Expand Up @@ -55,29 +54,17 @@ class DeveloperNotificationReceivedHandlerTest extends DatabaseTestCase
private ?ActiveRow $googlePlaySubscriptionTypeStandard = null;
private ?ActiveRow $user = null;

private DeveloperNotificationReceivedHandler $developerNotificationReceivedHandler;

private DeveloperNotificationsRepository $developerNotificationsRepository;

private GooglePlaySubscriptionTypesRepository $googlePlaySubscriptionTypesRepository;

private PurchaseTokensRepository $purchaseTokensRepository;

private PaymentsRepository $paymentsRepository;

private PaymentMetaRepository $paymentMetaRepository;

private SubscriptionTypesRepository $subscriptionTypesRepository;

private SubscriptionTypeBuilder $subscriptionTypeBuilder;

private SubscriptionsRepository $subscriptionsRepository;

private UsersRepository $usersRepository;

private RecurrentPaymentsRepository $recurrentPaymentsRepository;

private ApplicationConfig $applicationConfig;
private readonly DeveloperNotificationReceivedHandler $developerNotificationReceivedHandler;
private readonly DeveloperNotificationsRepository $developerNotificationsRepository;
private readonly GooglePlaySubscriptionTypesRepository $googlePlaySubscriptionTypesRepository;
private readonly PurchaseTokensRepository $purchaseTokensRepository;
private readonly PaymentsRepository $paymentsRepository;
private readonly PaymentMetaRepository $paymentMetaRepository;
private readonly SubscriptionTypesRepository $subscriptionTypesRepository;
private readonly SubscriptionTypeBuilder $subscriptionTypeBuilder;
private readonly SubscriptionsRepository $subscriptionsRepository;
private readonly UsersRepository $usersRepository;
private readonly RecurrentPaymentsRepository $recurrentPaymentsRepository;

protected function requiredRepositories(): array
{
Expand Down Expand Up @@ -121,8 +108,6 @@ public function setUp(): void
{
parent::setUp();

$this->applicationConfig = $this->inject(ApplicationConfig::class);

$this->developerNotificationReceivedHandler = $this->inject(DeveloperNotificationReceivedHandler::class);

$this->developerNotificationsRepository = $this->getRepository(DeveloperNotificationsRepository::class);
Expand Down Expand Up @@ -249,7 +234,7 @@ public function testSubscriptionPurchased()
// recurrent payment checks
$recurrent = $this->recurrentPaymentsRepository->recurrent($payment);
$this->assertEquals(RecurrentPaymentsRepository::STATE_ACTIVE, $recurrent->state);
$this->assertEquals($purchaseTokenFirstPurchase->purchase_token, $recurrent->cid);
$this->assertEquals($purchaseTokenFirstPurchase->purchase_token, $recurrent->payment_method->external_token);

// check payment meta against order id and purchase token
$this->assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function testSuccess()

$recurrent = $this->recurrentPaymentsRepository->recurrent($payment);
$this->assertEquals(RecurrentPaymentsRepository::STATE_ACTIVE, $recurrent->state);
$this->assertEquals($purchaseTokenFirstPurchase->purchase_token, $recurrent->cid);
$this->assertEquals($purchaseTokenFirstPurchase->purchase_token, $recurrent->payment_method->external_token);

// check payment meta against order id and purchase token
$this->assertEquals(
Expand Down Expand Up @@ -391,7 +391,7 @@ public function testSuccess()
// recurrent still active
$paymentFirstPurchaseRecurrent = $this->recurrentPaymentsRepository->recurrent($paymentFirstPurchase);
$this->assertEquals(RecurrentPaymentsRepository::STATE_ACTIVE, $paymentFirstPurchaseRecurrent->state);
$this->assertEquals($purchaseTokenFirstPurchase->purchase_token, $paymentFirstPurchaseRecurrent->cid);
$this->assertEquals($purchaseTokenFirstPurchase->purchase_token, $paymentFirstPurchaseRecurrent->payment_method->external_token);

// check new payment (upgrade) & meta against upgrade purchase
$this->assertEquals(PaymentsRepository::STATUS_PREPAID, $paymentUpgradePurchase->status);
Expand All @@ -411,7 +411,7 @@ public function testSuccess()

$paymentUpgradePurchaseRecurrent = $this->recurrentPaymentsRepository->recurrent($paymentUpgradePurchase);
$this->assertEquals(RecurrentPaymentsRepository::STATE_ACTIVE, $paymentUpgradePurchaseRecurrent->state);
$this->assertEquals($purchaseTokenUpgradePurchase->purchase_token, $paymentUpgradePurchaseRecurrent->cid);
$this->assertEquals($purchaseTokenUpgradePurchase->purchase_token, $paymentUpgradePurchaseRecurrent->payment_method->external_token);

// check subscriptions type & start/end times against Google play validation responses
$subscriptionFirstPurchase = $paymentFirstPurchase->subscription;
Expand Down

0 comments on commit d0d82a8

Please sign in to comment.