diff --git a/Civi/Paymentprocessingcore/DTO/RecurringContributionDTO.php b/Civi/Paymentprocessingcore/DTO/RecurringContributionDTO.php index a02f716..909fc7d 100644 --- a/Civi/Paymentprocessingcore/DTO/RecurringContributionDTO.php +++ b/Civi/Paymentprocessingcore/DTO/RecurringContributionDTO.php @@ -55,6 +55,11 @@ class RecurringContributionDTO { */ private int $frequencyInterval; + /** + * @var int|null + */ + private ?int $paymentInstrumentId; + /** * Private constructor — use fromApiResult() factory method. * @@ -76,6 +81,8 @@ class RecurringContributionDTO { * Frequency unit (day, week, month, year). * @param int $frequencyInterval * Frequency interval. + * @param int|null $paymentInstrumentId + * Payment instrument ID or NULL. */ private function __construct( int $id, @@ -86,7 +93,8 @@ private function __construct( ?int $campaignId, string $nextSchedContributionDate, string $frequencyUnit, - int $frequencyInterval + int $frequencyInterval, + ?int $paymentInstrumentId ) { $this->id = $id; $this->contactId = $contactId; @@ -97,6 +105,7 @@ private function __construct( $this->nextSchedContributionDate = $nextSchedContributionDate; $this->frequencyUnit = $frequencyUnit; $this->frequencyInterval = $frequencyInterval; + $this->paymentInstrumentId = $paymentInstrumentId; } /** @@ -148,6 +157,10 @@ public static function fromApiResult(array $record): self { ? (int) $record['campaign_id'] : NULL; + $paymentInstrumentId = isset($record['payment_instrument_id']) && is_numeric($record['payment_instrument_id']) + ? (int) $record['payment_instrument_id'] + : NULL; + return new self( (int) $id, (int) $contactId, @@ -157,7 +170,8 @@ public static function fromApiResult(array $record): self { $campaignId, (string) $nextSchedDate, (string) $frequencyUnit, - (int) $frequencyInterval + (int) $frequencyInterval, + $paymentInstrumentId ); } @@ -224,4 +238,11 @@ public function getFrequencyInterval(): int { return $this->frequencyInterval; } + /** + * Get the payment instrument ID, or NULL if not set. + */ + public function getPaymentInstrumentId(): ?int { + return $this->paymentInstrumentId; + } + } diff --git a/Civi/Paymentprocessingcore/Service/InstalmentGenerationService.php b/Civi/Paymentprocessingcore/Service/InstalmentGenerationService.php index 5c49bed..60793fa 100644 --- a/Civi/Paymentprocessingcore/Service/InstalmentGenerationService.php +++ b/Civi/Paymentprocessingcore/Service/InstalmentGenerationService.php @@ -149,7 +149,8 @@ public function getDueRecurringContributions(string $processorType, int $batchSi 'amount', 'currency', 'financial_type_id', - 'campaign_id' + 'campaign_id', + 'payment_instrument_id' ) ->addJoin( 'PaymentProcessor AS pp', @@ -258,6 +259,10 @@ public function createInstalment(RecurringContributionDTO $recur, string $receiv $createAction->addValue('campaign_id', $recur->getCampaignId()); } + if ($recur->getPaymentInstrumentId() !== NULL) { + $createAction->addValue('payment_instrument_id', $recur->getPaymentInstrumentId()); + } + $result = $createAction->execute()->first(); if (!is_array($result)) {