From 70ac89bb3807fd1b4c85b1a7e865740985358f43 Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Thu, 3 Oct 2024 13:45:35 +0200 Subject: [PATCH] Add GatewayTracking to CheckoutsPump --- src/Library/Benzina/Pump/CheckoutsPump.php | 44 ++++++++++++++++++---- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/src/Library/Benzina/Pump/CheckoutsPump.php b/src/Library/Benzina/Pump/CheckoutsPump.php index 4fc9842..f8e1c84 100644 --- a/src/Library/Benzina/Pump/CheckoutsPump.php +++ b/src/Library/Benzina/Pump/CheckoutsPump.php @@ -8,6 +8,7 @@ use App\Entity\GatewayChargeType; use App\Entity\GatewayCheckout; use App\Entity\GatewayCheckoutStatus; +use App\Entity\GatewayTracking; use App\Entity\Money; use App\Entity\Tipjar; use App\Library\Benzina\Pump\Trait\ArrayPumpTrait; @@ -27,9 +28,12 @@ class CheckoutsPump extends AbstractPump implements PumpInterface { use ArrayPumpTrait; use ProgressivePumpTrait; + public const TRACKING_TITLE_V3 = 'v3 Invest ID'; + public const TRACKING_TITLE_PAYMENT = 'v3 Invest Payment'; + public const TRACKING_TITLE_TRANSACTION = 'v3 Invest Transaction'; + public const TRACKING_TITLE_PREAPPROVAL = 'v3 Invest Preapproval'; private const PLATFORM_TIPJAR_NAME = 'platform'; - private const CHECKOUT_URL_DEFAULT = 'https://www.goteo.org/invest'; private const MAX_INT = 2147483647; @@ -115,8 +119,11 @@ public function process(mixed $data): void $checkout->setOrigin($user->getAccounting()); $checkout->setStatus($this->getCheckoutStatus($record)); $checkout->setGateway($this->getCheckoutGateway($record)); - $checkout->setGatewayReference($this->getCheckoutReference($record)); - $checkout->setCheckoutUrl(self::CHECKOUT_URL_DEFAULT); + + foreach ($this->getCheckoutTrackings($record) as $tracking) { + $checkout->addGatewayTracking($tracking); + } + $checkout->setMigrated(true); $checkout->setMigratedReference($record['id']); $checkout->setMetadata([ @@ -264,20 +271,41 @@ private function getCheckoutGateway(array $record): string } } - private function getCheckoutReference(array $record): string + /** + * @return GatewayTracking[] + */ + private function getCheckoutTrackings(array $record): array { + $v3Tracking = new GatewayTracking(); + $v3Tracking->setValue($record['id']); + $v3Tracking->setTitle(self::TRACKING_TITLE_V3); + + $trackings = [$v3Tracking]; + if (!empty($record['payment'])) { - return $record['payment']; + $payment = new GatewayTracking(); + $payment->setValue($record['payment']); + $payment->setTitle(self::TRACKING_TITLE_PAYMENT); + + $trackings[] = $payment; } if (!empty($record['transaction'])) { - return $record['transaction']; + $transaction = new GatewayTracking(); + $transaction->setValue($record['transaction']); + $transaction->setTitle(self::TRACKING_TITLE_TRANSACTION); + + $trackings[] = $transaction; } if (!empty($record['preapproval'])) { - return $record['preapproval']; + $preapproval = new GatewayTracking(); + $preapproval->setValue($record['preapproval']); + $preapproval->setTitle(self::TRACKING_TITLE_PREAPPROVAL); + + $trackings[] = $preapproval; } - return ''; + return $trackings; } }