Skip to content

Commit

Permalink
keep customer ip
Browse files Browse the repository at this point in the history
  • Loading branch information
konradkozaczenko committed May 23, 2024
1 parent c2ff604 commit 0b8eef0
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/Action/ConvertPaymentAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,9 @@ public function execute($request): void
/** @var PaymentInterface $payment */
$payment = $request->getSource();
$details = Model::ensureArrayObject($payment->getDetails());
$details->replace(
[
ModelFields::TOTAL_AMOUNT => $payment->getTotalAmount(),
ModelFields::CURRENCY => $payment->getCurrencyCode(),
ModelFields::EXT_ORDER_ID => $details->extOrderId() ?? $payment->getNumber(),
ModelFields::DESCRIPTION => $payment->getDescription(),
ModelFields::CLIENT_EMAIL => $payment->getClientEmail(),
ModelFields::CLIENT_ID => $payment->getClientId(),
ModelFields::CUSTOMER_IP => $this->userIpService->getIp(),
ModelFields::CREDIT_CARD_MASKED_NUMBER => $payment->getCreditCard() ? $payment->getCreditCard()->getMaskedNumber() : null,
ModelFields::VALIDITY_TIME => $details->validityTime() ?? self::DEFAULT_VALIDITY_TIME,
]
);

$this->replaceModelFields($details, $payment);

if ($payment instanceof Payment) {
$details->setConfigKey($payment->getConfigKey());

Expand Down Expand Up @@ -105,4 +95,28 @@ public function supports($request): bool
&& $request->getSource() instanceof PaymentInterface
&& 'array' === $request->getTo();
}

private function replaceModelFields(Model $details, PaymentInterface $payment): void
{
if (null === $details->customerIp()) {
$details->replace(
[
ModelFields::CUSTOMER_IP => $this->userIpService->getIp(),
]
);
}

$details->replace(
[
ModelFields::TOTAL_AMOUNT => $payment->getTotalAmount(),
ModelFields::CURRENCY => $payment->getCurrencyCode(),
ModelFields::EXT_ORDER_ID => $details->extOrderId() ?? $payment->getNumber(),
ModelFields::DESCRIPTION => $payment->getDescription(),
ModelFields::CLIENT_EMAIL => $payment->getClientEmail(),
ModelFields::CLIENT_ID => $payment->getClientId(),
ModelFields::CREDIT_CARD_MASKED_NUMBER => $payment->getCreditCard() ? $payment->getCreditCard()->getMaskedNumber() : null,
ModelFields::VALIDITY_TIME => $details->validityTime() ?? self::DEFAULT_VALIDITY_TIME,
]
);
}
}

0 comments on commit 0b8eef0

Please sign in to comment.