diff --git a/src/Api/VerifyPurchaseApiHandler.php b/src/Api/VerifyPurchaseApiHandler.php index 5dd3dd1..d479b1d 100644 --- a/src/Api/VerifyPurchaseApiHandler.php +++ b/src/Api/VerifyPurchaseApiHandler.php @@ -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); diff --git a/src/Tests/Hermes/DeveloperNotificationReceivedHandlerTest.php b/src/Tests/Hermes/DeveloperNotificationReceivedHandlerTest.php index b3fba64..f6f5c30 100644 --- a/src/Tests/Hermes/DeveloperNotificationReceivedHandlerTest.php +++ b/src/Tests/Hermes/DeveloperNotificationReceivedHandlerTest.php @@ -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; @@ -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 { @@ -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); @@ -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( diff --git a/src/Tests/Hermes/DeveloperNotificationReceivedHandlerUpgradeTest.php b/src/Tests/Hermes/DeveloperNotificationReceivedHandlerUpgradeTest.php index 62b492a..86414e0 100644 --- a/src/Tests/Hermes/DeveloperNotificationReceivedHandlerUpgradeTest.php +++ b/src/Tests/Hermes/DeveloperNotificationReceivedHandlerUpgradeTest.php @@ -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( @@ -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); @@ -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;