Skip to content

Commit

Permalink
Payment cards separation - first phase (write side + backwards compat…
Browse files Browse the repository at this point in the history
…ibility)

! Migration `migrate_payment_methods` could take a time, depending on the size of your `recurrent_payments` table. Consider to run it at off-peak times.
- Added new `payment_methods` table to be able to manage payment methods apart of the recurrent payments
- Breaking change: Method `RecurrentPaymentsRepository::add(...)` was renamed to `::addV1(...)`
- Deprecated usage of `cid` column within `recurrent_payments` table

remp/crm#3221
  • Loading branch information
burithetech committed Sep 30, 2024
1 parent d87a29b commit 5f85c1b
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/Commands/CreateMissingRecurrentPaymentsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Crm\GooglePlayBillingModule\Repositories\GooglePlaySubscriptionTypesRepository;
use Crm\PaymentsModule\Repositories\PaymentGatewaysRepository;
use Crm\PaymentsModule\Repositories\PaymentMetaRepository;
use Crm\PaymentsModule\Repositories\PaymentMethodsRepository;
use Crm\PaymentsModule\Repositories\PaymentsRepository;
use Crm\PaymentsModule\Repositories\RecurrentPaymentsRepository;
use Nette\Utils\DateTime;
Expand All @@ -21,13 +22,14 @@ class CreateMissingRecurrentPaymentsCommand extends Command
{

public function __construct(
private PaymentsRepository $paymentsRepository,
private PaymentGatewaysRepository $paymentGatewaysRepository,
private PaymentMetaRepository $paymentMetaRepository,
private RecurrentPaymentsRepository $recurrentPaymentsRepository,
private ApplicationConfig $applicationConfig,
private GooglePlaySubscriptionTypesRepository $googlePlaySubscriptionTypesRepository,
private DeveloperNotificationsRepository $developerNotificationsRepository,
private readonly PaymentsRepository $paymentsRepository,
private readonly PaymentGatewaysRepository $paymentGatewaysRepository,
private readonly PaymentMetaRepository $paymentMetaRepository,
private readonly RecurrentPaymentsRepository $recurrentPaymentsRepository,
private readonly ApplicationConfig $applicationConfig,
private readonly GooglePlaySubscriptionTypesRepository $googlePlaySubscriptionTypesRepository,
private readonly DeveloperNotificationsRepository $developerNotificationsRepository,
private readonly PaymentMethodsRepository $paymentMethodsRepository,
) {
parent::__construct();
}
Expand Down Expand Up @@ -202,12 +204,18 @@ private function createRecurrentFromPayment($payment, $recurrentToken, $googleSu

$chargeAt = $this->calculateChargeAt($payment);

$recurrent = $this->recurrentPaymentsRepository->add(
$paymentMethod = $this->paymentMethodsRepository->findOrAdd(
$payment->user->id,
$payment->payment_gateway->id,
$recurrentToken,
);

$recurrent = $this->recurrentPaymentsRepository->add(
$paymentMethod,
$payment,
$chargeAt,
null,
--$retries
--$retries,
);

if (isset($googleSubscriptionType->offer_periods) && $googleSubscriptionType->offer_periods === ($usedPeriods + 1)) {
Expand Down

0 comments on commit 5f85c1b

Please sign in to comment.