Skip to content

Commit

Permalink
minor code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mustapayev committed Oct 2, 2024
1 parent d2bbf19 commit c765b17
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public function createHistoryRequestData(AbstractPosAccount $posAccount, array $
$requestData['report'] = [
'batchNumber' => $order['batch_num'],
];
} elseif (isset($order['start_date']) && isset($order['end_date'])) {
} elseif (isset($order['start_date'], $order['end_date'])) {
$requestData['report'] = [
'startDateTime' => $this->formatRequestDateTime($order['start_date']),
'endDateTime' => $this->formatRequestDateTime($order['end_date']),
Expand Down
5 changes: 4 additions & 1 deletion src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $po
'Total' => isset($order['amount']) ? (float) $this->formatAmount($order['amount']) : null,
];

if (isset($order['amount']) && isset($order['pre_auth_amount']) && $order['pre_auth_amount'] < $order['amount']) {
if (isset($order['amount'], $order['pre_auth_amount']) && $order['pre_auth_amount'] < $order['amount']) {
// when amount < pre_auth_amount then we need to send PREAMT value
$requestData['Extra']['PREAMT'] = $order['pre_auth_amount'];
}
Expand Down Expand Up @@ -271,9 +271,12 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
* @phpstan-param PosInterface::MODEL_3D_* $paymentModel
* @phpstan-param PosInterface::TX_TYPE_PAY_AUTH|PosInterface::TX_TYPE_PAY_PRE_AUTH $txType
*
* @param AbstractPosAccount $posAccount
* @param array<string, string|int|float|null> $order
* @param string $paymentModel
* @param string $txType
* @param string $gatewayURL
* @param CreditCardInterface|null $creditCard
*
* @return array{gateway: string, method: 'POST', inputs: array<string, string>}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ class PayFlexCPV4PosRequestDataMapper extends AbstractRequestDataMapper
PosInterface::LANG_EN => 'en-US',
];

/**
* {@inheritdoc}
*/
protected array $recurringOrderFrequencyMapping = [
'DAY' => 'Day',
'MONTH' => 'Month',
'YEAR' => 'Year',
];

/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
if ($creditCard instanceof CreditCardInterface) {
$inputs['CardHolderName'] = (string) $creditCard->getHolderName();
$inputs['CardNo'] = $creditCard->getNumber();
$inputs['ExpireDate'] = $creditCard->getExpireMonth(self::CREDIT_CARD_EXP_DATE_FORMAT);
$inputs['ExpireDate'] = $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT);
$inputs['Cvv'] = $creditCard->getCvv();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,13 @@ protected function prepareRefundOrder(array $order): array
*
* @inheritDoc
*/
protected function prepareHistoryOrder(array $order): array
protected function prepareHistoryOrder(array $data): array
{
return [
'start_date' => $order['start_date'],
'end_date' => $order['end_date'],
'page' => $order['page'] ?? 1,
'page_size' => $order['page_size'] ?? 10,
'start_date' => $data['start_date'],
'end_date' => $data['end_date'],
'page' => $data['page'] ?? 1,
'page_size' => $data['page_size'] ?? 10,
];
}

Expand Down
7 changes: 2 additions & 5 deletions src/Factory/RequestDataMapperFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class RequestDataMapperFactory
/**
* @param class-string $gatewayClass
* @param EventDispatcherInterface $eventDispatcher
* @param array<PosInterface::CURRENCY_*, string> $currencies
* @param CryptInterface $crypt
* @param array<PosInterface::CURRENCY_*, string> $currencies
*
* @return RequestDataMapperInterface
*/
Expand All @@ -65,15 +65,12 @@ public static function createGatewayRequestMapper(string $gatewayClass, EventDis
PosNet::class => PosNetRequestDataMapper::class,
PosNetV1Pos::class => PosNetV1PosRequestDataMapper::class,
PayFlexCPV4Pos::class => PayFlexCPV4PosRequestDataMapper::class,
PayFlexV4Pos::class => PayFlexV4PosRequestDataMapper::class,
];
if (isset($classMappings[$gatewayClass])) {
return new $classMappings[$gatewayClass]($eventDispatcher, $crypt, $currencies);
}

if (PayFlexV4Pos::class === $gatewayClass) {
return new PayFlexV4PosRequestDataMapper($eventDispatcher, $crypt, $currencies);
}

throw new DomainException('unsupported gateway');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,6 @@ public function testFormatAmount(): void
$this->assertSame('1000.00', $method->invokeArgs($this->requestDataMapper, [1000]));
}

/**
* @testWith ["MONTH", "Month"]
* ["Month", "Month"]
*/
public function testMapRecurringFrequency(string $frequency, string $expected): void
{
$class = new \ReflectionObject($this->requestDataMapper);
$method = $class->getMethod('mapRecurringFrequency');
$method->setAccessible(true);
$this->assertSame($expected, $method->invokeArgs($this->requestDataMapper, [$frequency]));
}

/**
* @return void
*/
Expand Down

0 comments on commit c765b17

Please sign in to comment.