diff --git a/examples/_templates/_credit_card_form.php b/examples/_templates/_credit_card_form.php
index b2e73f6f..1a3acb24 100644
--- a/examples/_templates/_credit_card_form.php
+++ b/examples/_templates/_credit_card_form.php
@@ -27,7 +27,7 @@
@@ -36,7 +36,7 @@
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index ccd9bdfb..1083f216 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -11,29 +11,29 @@ parameters:
path: src/Client/HttpClient.php
-
- message: "#^Parameter \\#1 \\$currency of method Mews\\\\Pos\\\\DataMapper\\\\RequestDataMapper\\\\AkbankPosRequestDataMapper\\:\\:mapCurrency\\(\\) expects 'EUR'\\|'GBP'\\|'JPY'\\|'RUB'\\|'TRY'\\|'USD', string given\\.$#"
- count: 5
- path: src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php
+ message: "#^Parameter \\#1 \\$amount of method Mews\\\\Pos\\\\DataMapper\\\\RequestValueFormatter\\\\RequestValueFormatterInterface\\:\\:formatAmount\\(\\) expects float, float\\|int\\|string\\|null given\\.$#"
+ count: 1
+ path: src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php
-
- message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
+ message: "#^Parameter \\#1 \\$currency of method Mews\\\\Pos\\\\DataMapper\\\\RequestValueMapper\\\\RequestValueMapperInterface\\:\\:mapCurrency\\(\\) expects 'EUR'\\|'GBP'\\|'JPY'\\|'RUB'\\|'TRY'\\|'USD', float\\|int\\|string\\|null given\\.$#"
count: 1
path: src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php
-
- message: "#^Parameter \\#1 \\$currency of method Mews\\\\Pos\\\\DataMapper\\\\RequestDataMapper\\\\EstPosRequestDataMapper\\:\\:mapCurrency\\(\\) expects 'EUR'\\|'GBP'\\|'JPY'\\|'RUB'\\|'TRY'\\|'USD', string given\\.$#"
+ message: "#^Parameter \\#1 \\$installment of method Mews\\\\Pos\\\\DataMapper\\\\RequestValueFormatter\\\\RequestValueFormatterInterface\\:\\:formatInstallment\\(\\) expects int\\<0, max\\>, float\\|int\\|string\\|null given\\.$#"
count: 1
path: src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php
-
- message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
- count: 1
- path: src/DataMapper/RequestDataMapper/GarantiPosRequestDataMapper.php
+ message: "#^Parameter \\#1 \\$cardType of method Mews\\\\Pos\\\\DataMapper\\\\RequestValueMapper\\\\RequestValueMapperInterface\\:\\:mapCardType\\(\\) expects 'amex'\\|'master'\\|'troy'\\|'visa', 'amex'\\|'master'\\|'troy'\\|'visa'\\|null given\\.$#"
+ count: 2
+ path: src/DataMapper/RequestDataMapper/InterPosRequestDataMapper.php
-
- message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
+ message: "#^Parameter \\#1 \\$cardType of method Mews\\\\Pos\\\\DataMapper\\\\RequestValueMapper\\\\RequestValueMapperInterface\\:\\:mapCardType\\(\\) expects 'amex'\\|'master'\\|'troy'\\|'visa', 'amex'\\|'master'\\|'troy'\\|'visa'\\|null given\\.$#"
count: 1
- path: src/DataMapper/RequestDataMapper/InterPosRequestDataMapper.php
+ path: src/DataMapper/RequestDataMapper/KuveytPosRequestDataMapper.php
-
message: "#^Default value of the parameter \\#7 \\$extraData \\(array\\{\\}\\) of method Mews\\\\Pos\\\\DataMapper\\\\RequestDataMapper\\\\PayFlexCPV4PosRequestDataMapper\\:\\:create3DFormData\\(\\) is incompatible with type array\\{CommonPaymentUrl\\: string, PaymentToken\\: string\\}\\.$#"
@@ -41,7 +41,7 @@ parameters:
path: src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php
-
- message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
+ message: "#^Parameter \\#1 \\$cardType of method Mews\\\\Pos\\\\DataMapper\\\\RequestValueMapper\\\\RequestValueMapperInterface\\:\\:mapCardType\\(\\) expects 'amex'\\|'master'\\|'troy'\\|'visa', 'amex'\\|'master'\\|'troy'\\|'visa'\\|null given\\.$#"
count: 1
path: src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php
@@ -51,12 +51,12 @@ parameters:
path: src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php
-
- message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
+ message: "#^Method Mews\\\\Pos\\\\DataMapper\\\\RequestDataMapper\\\\PayFlexV4PosRequestDataMapper\\:\\:create3DEnrollmentCheckRequestData\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php
-
- message: "#^Method Mews\\\\Pos\\\\DataMapper\\\\RequestDataMapper\\\\PayFlexV4PosRequestDataMapper\\:\\:create3DEnrollmentCheckRequestData\\(\\) return type has no value type specified in iterable type array\\.$#"
+ message: "#^Parameter \\#1 \\$cardType of method Mews\\\\Pos\\\\DataMapper\\\\RequestValueMapper\\\\RequestValueMapperInterface\\:\\:mapCardType\\(\\) expects 'amex'\\|'master'\\|'troy'\\|'visa', 'amex'\\|'master'\\|'troy'\\|'visa'\\|null given\\.$#"
count: 1
path: src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php
@@ -65,11 +65,6 @@ parameters:
count: 1
path: src/DataMapper/RequestDataMapper/PayForPosRequestDataMapper.php
- -
- message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
- count: 1
- path: src/DataMapper/RequestDataMapper/PayForPosRequestDataMapper.php
-
-
message: "#^Cannot assign offset 'authCode' to array\\\\|string\\.$#"
count: 1
@@ -95,11 +90,6 @@ parameters:
count: 1
path: src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php
- -
- message: "#^Method Mews\\\\Pos\\\\DataMapper\\\\RequestDataMapper\\\\PosNetRequestDataMapper\\:\\:create3DEnrollmentCheckRequestData\\(\\) return type has no value type specified in iterable type array\\.$#"
- count: 1
- path: src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php
-
-
message: "#^Method Mews\\\\Pos\\\\DataMapper\\\\RequestDataMapper\\\\PosNetV1PosRequestDataMapper\\:\\:create3DFormData\\(\\) has parameter \\$extraData with no type specified\\.$#"
count: 1
@@ -140,11 +130,6 @@ parameters:
count: 1
path: src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php
- -
- message: "#^Property Mews\\\\Pos\\\\DataMapper\\\\ResponseDataMapper\\\\AbstractResponseDataMapper\\:\\:\\$currencyMappings \\(array\\\\) does not accept non\\-empty\\-array\\<392\\|643\\|826\\|840\\|949\\|978\\|string, 'EUR'\\|'GBP'\\|'JPY'\\|'RUB'\\|'TRY'\\|'USD'\\>\\.$#"
- count: 1
- path: src/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapper.php
-
-
message: "#^Method Mews\\\\Pos\\\\Factory\\\\PosFactory\\:\\:createPosGateway\\(\\) should return Mews\\\\Pos\\\\PosInterface but returns object\\.$#"
count: 1
diff --git a/src/Crypt/CryptInterface.php b/src/Crypt/CryptInterface.php
index b2a6c5ab..c19d882e 100644
--- a/src/Crypt/CryptInterface.php
+++ b/src/Crypt/CryptInterface.php
@@ -30,8 +30,8 @@ public function check3DHash(AbstractPosAccount $posAccount, array $data): bool;
/**
* creates hash for 3D secure payments
*
- * @param AbstractPosAccount $posAccount
- * @param array $requestData
+ * @param AbstractPosAccount $posAccount
+ * @param array $requestData
*
* @return string
*/
diff --git a/src/Crypt/GarantiPosCrypt.php b/src/Crypt/GarantiPosCrypt.php
index dd05f99e..c371b9a1 100644
--- a/src/Crypt/GarantiPosCrypt.php
+++ b/src/Crypt/GarantiPosCrypt.php
@@ -29,7 +29,7 @@ public function create3DHash(AbstractPosAccount $posAccount, array $requestData)
$requestData['txntype'],
$requestData['txninstallmentcount'],
$posAccount->getStoreKey(),
- $this->createSecurityData($posAccount, $requestData['txntype']),
+ $this->createSecurityData($posAccount, (string) $requestData['txntype']),
];
return $this->hashStringUpperCase(implode(static::HASH_SEPARATOR, $map), self::HASH_ALGORITHM);
diff --git a/src/DataMapper/RequestDataMapper/AbstractRequestDataMapper.php b/src/DataMapper/RequestDataMapper/AbstractRequestDataMapper.php
index 044b255c..f8418b45 100644
--- a/src/DataMapper/RequestDataMapper/AbstractRequestDataMapper.php
+++ b/src/DataMapper/RequestDataMapper/AbstractRequestDataMapper.php
@@ -6,10 +6,9 @@
namespace Mews\Pos\DataMapper\RequestDataMapper;
use Mews\Pos\Crypt\CryptInterface;
+use Mews\Pos\DataMapper\RequestValueFormatter\RequestValueFormatterInterface;
+use Mews\Pos\DataMapper\RequestValueMapper\RequestValueMapperInterface;
use Mews\Pos\Entity\Account\AbstractPosAccount;
-use Mews\Pos\Entity\Card\CreditCardInterface;
-use Mews\Pos\Exceptions\UnsupportedTransactionTypeException;
-use Mews\Pos\PosInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
/**
@@ -18,64 +17,29 @@
abstract class AbstractRequestDataMapper implements RequestDataMapperInterface
{
protected EventDispatcherInterface $eventDispatcher;
-
- /** @var array */
- protected array $secureTypeMappings = [];
-
- /**
- * Transaction Types
- *
- * @var array>
- */
- protected array $txTypeMappings = [];
-
- /** @var array */
- protected array $cardTypeMapping = [];
-
- /** @var array */
- protected array $langMappings = [
- PosInterface::LANG_TR => 'tr',
- PosInterface::LANG_EN => 'en',
- ];
-
- /**
- * default olarak ISO 4217 kodlar tanimliyoruz.
- * fakat bazi banklar ISO standarti kullanmiyorlar.
- * Currency mapping
- *
- * @var non-empty-array
- */
- protected array $currencyMappings = [
- PosInterface::CURRENCY_TRY => '949',
- PosInterface::CURRENCY_USD => '840',
- PosInterface::CURRENCY_EUR => '978',
- PosInterface::CURRENCY_GBP => '826',
- PosInterface::CURRENCY_JPY => '392',
- PosInterface::CURRENCY_RUB => '643',
- ];
-
- /**
- * period mapping for recurring orders
- * @var array<'DAY'|'WEEK'|'MONTH'|'YEAR', string>
- */
- protected array $recurringOrderFrequencyMapping = [];
+ protected RequestValueMapperInterface $valueMapper;
+ protected RequestValueFormatterInterface $valueFormatter;
+ protected CryptInterface $crypt;
protected bool $testMode = false;
- protected CryptInterface $crypt;
-
/**
- * @param EventDispatcherInterface $eventDispatcher
- * @param CryptInterface $crypt
- * @param array $currencyMappings
+ * @param RequestValueMapperInterface $valueMapper
+ * @param RequestValueFormatterInterface $valueFormatter
+ * @param EventDispatcherInterface $eventDispatcher
+ * @param CryptInterface $crypt
*/
- public function __construct(EventDispatcherInterface $eventDispatcher, CryptInterface $crypt, array $currencyMappings = [])
+ public function __construct(
+ RequestValueMapperInterface $valueMapper,
+ RequestValueFormatterInterface $valueFormatter,
+ EventDispatcherInterface $eventDispatcher,
+ CryptInterface $crypt
+ )
{
+ $this->valueMapper = $valueMapper;
+ $this->valueFormatter = $valueFormatter;
$this->eventDispatcher = $eventDispatcher;
$this->crypt = $crypt;
- if ([] !== $currencyMappings) {
- $this->currencyMappings = $currencyMappings;
- }
}
/**
@@ -94,39 +58,6 @@ public function isTestMode(): bool
return $this->testMode;
}
- /**
- * @return array
- */
- public function getCardTypeMapping(): array
- {
- return $this->cardTypeMapping;
- }
-
- /**
- * @return array
- */
- public function getSecureTypeMappings(): array
- {
- return $this->secureTypeMappings;
- }
-
- /**
- * @return array>
- */
- public function getTxTypeMappings(): array
- {
- return $this->txTypeMappings;
- }
-
- /**
- * @return non-empty-array
- */
- public function getCurrencyMappings(): array
- {
- return $this->currencyMappings;
- }
-
-
/**
* @inheritDoc
*/
@@ -136,106 +67,8 @@ public function setTestMode(bool $testMode): void
}
/**
- * @phpstan-param PosInterface::TX_TYPE_* $txType
- * @phpstan-param PosInterface::MODEL_*|null $paymentModel
- *
- * @param string $txType
- * @param string|null $paymentModel
- *
- * @return string
- *
- * @throws UnsupportedTransactionTypeException
- */
- public function mapTxType(string $txType, ?string $paymentModel = null): string
- {
- if (!$this->isSupportedTxType($txType, $paymentModel)) {
- throw new UnsupportedTransactionTypeException();
- }
-
- if (\is_string($this->txTypeMappings[$txType])) {
- return $this->txTypeMappings[$txType];
- }
-
- return $this->txTypeMappings[$txType][$paymentModel];
- }
-
- /**
- * @phpstan-param PosInterface::TX_TYPE_* $txType
- * @phpstan-param PosInterface::MODEL_*|null $paymentModel
- *
- * @param string $txType
- * @param string|null $paymentModel
- *
- * @return bool
- */
- public function isSupportedTxType(string $txType, ?string $paymentModel = null): bool
- {
- if (!isset($this->txTypeMappings[$txType])) {
- return false;
- }
-
- if (\is_array($this->txTypeMappings[$txType])) {
- if (null === $paymentModel) {
- return false;
- }
-
- return isset($this->txTypeMappings[$txType][$paymentModel]);
- }
-
- return true;
- }
-
- /**
- * @return array<'DAY'|'WEEK'|'MONTH'|'YEAR', string>
- */
- public function getRecurringOrderFrequencyMapping(): array
- {
- return $this->recurringOrderFrequencyMapping;
- }
-
- /**
- * formats installment
- * @param int $installment
- *
- * @return string|int
- */
- abstract protected function mapInstallment(int $installment);
-
- /**
- * @phpstan-param PosInterface::CURRENCY_* $currency
- *
- * @param string $currency
- *
- * @return string|int currency code that is accepted by bank
- */
- protected function mapCurrency(string $currency)
- {
- return $this->currencyMappings[$currency] ?? $currency;
- }
-
- /**
- * @param float $amount
- *
- * @return int|string|float
- */
- protected function formatAmount(float $amount)
- {
- return $amount;
- }
-
- /**
- * @param string $period
- *
- * @return string
- */
- protected function mapRecurringFrequency(string $period): string
- {
- return $this->recurringOrderFrequencyMapping[$period] ?? $period;
- }
-
- /**
- * bank returns error messages for specified language value
- * usually accepted values are tr,en
+ * according to the language value the POS UI will be displayed in the selected language
+ * and error messages will be returned in the selected language
*
* @param AbstractPosAccount $posAccount
* @param array $order
@@ -244,11 +77,9 @@ protected function mapRecurringFrequency(string $period): string
*/
protected function getLang(AbstractPosAccount $posAccount, array $order): string
{
- if (isset($order['lang'])) {
- return $this->langMappings[$order['lang']];
- }
+ $lang = $order['lang'] ?? $posAccount->getLang();
- return $this->langMappings[$posAccount->getLang()];
+ return $this->valueMapper->mapLang($lang);
}
/**
diff --git a/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php
index f7820999..93793b5b 100644
--- a/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php
+++ b/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php
@@ -19,73 +19,9 @@
*/
class AkbankPosRequestDataMapper extends AbstractRequestDataMapper
{
- /** @var string */
- public const CREDIT_CARD_EXP_DATE_FORMAT = 'my';
public const API_VERSION = '1.00';
- /**
- * Not: Güvenli Ödeme 3D Model isteklerinde opsiyonel
- * {@inheritDoc}
- */
- protected array $txTypeMappings = [
- PosInterface::TX_TYPE_PAY_AUTH => [
- PosInterface::MODEL_NON_SECURE => '1000',
- PosInterface::MODEL_3D_SECURE => '3000',
- PosInterface::MODEL_3D_PAY => '3000',
- PosInterface::MODEL_3D_HOST => '3000',
- ],
- PosInterface::TX_TYPE_PAY_PRE_AUTH => [
- PosInterface::MODEL_NON_SECURE => '1004',
- PosInterface::MODEL_3D_SECURE => '3004',
- PosInterface::MODEL_3D_PAY => '3004',
- PosInterface::MODEL_3D_HOST => '3004',
- ],
- PosInterface::TX_TYPE_PAY_POST_AUTH => '1005',
- PosInterface::TX_TYPE_REFUND => '1002',
- PosInterface::TX_TYPE_REFUND_PARTIAL => '1002',
- PosInterface::TX_TYPE_CANCEL => '1003',
- PosInterface::TX_TYPE_ORDER_HISTORY => '1010',
- PosInterface::TX_TYPE_HISTORY => '1009',
- ];
-
- /**
- * {@inheritdoc}
- */
- protected array $recurringOrderFrequencyMapping = [
- 'DAY' => 'D',
- 'WEEK' => 'W',
- 'MONTH' => 'M',
- 'YEAR' => 'Y',
- ];
-
- /**
- * {@inheritdoc}
- */
- protected array $secureTypeMappings = [
- PosInterface::MODEL_3D_SECURE => '3D',
- PosInterface::MODEL_3D_PAY => '3D_PAY',
- PosInterface::MODEL_3D_HOST => '3D_PAY_HOSTING',
- PosInterface::MODEL_NON_SECURE => 'PAY_HOSTING',
- ];
-
- /** @var array */
- protected array $langMappings = [
- PosInterface::LANG_TR => 'TR',
- PosInterface::LANG_EN => 'EN',
- ];
-
- /**
- * @var non-empty-array
- */
- protected array $currencyMappings = [
- PosInterface::CURRENCY_TRY => 949,
- PosInterface::CURRENCY_USD => 840,
- PosInterface::CURRENCY_EUR => 978,
- PosInterface::CURRENCY_JPY => 392,
- PosInterface::CURRENCY_RUB => 643,
- ];
-
/**
* @param AkbankPosAccount $posAccount
*
@@ -97,17 +33,17 @@ public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array
return $this->getRequestAccountData($posAccount) + [
'version' => self::API_VERSION,
- 'txnCode' => $this->mapTxType($txType, PosInterface::MODEL_NON_SECURE),
- 'requestDateTime' => $this->formatRequestDateTime($order['transaction_time']),
+ 'txnCode' => $this->valueMapper->mapTxType($txType, PosInterface::MODEL_NON_SECURE),
+ 'requestDateTime' => $this->valueFormatter->formatDateTime($order['transaction_time'], 'requestDateTime'),
'randomNumber' => $this->crypt->generateRandomString(),
'order' => [
'orderId' => (string) $order['id'],
],
'transaction' => [
- 'amount' => $this->formatAmount($order['amount']),
- 'currencyCode' => $this->mapCurrency((string) $order['currency']),
+ 'amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'currencyCode' => $this->valueMapper->mapCurrency($order['currency']),
'motoInd' => 0,
- 'installCount' => $this->mapInstallment((int) $order['installment']),
+ 'installCount' => $this->valueFormatter->formatInstallment($order['installment']),
],
'secureTransaction' => [
'secureId' => $responseData['secureId'],
@@ -132,19 +68,19 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount
$requestData = $this->getRequestAccountData($posAccount) + [
'version' => self::API_VERSION,
- 'txnCode' => $this->mapTxType($txType, PosInterface::MODEL_NON_SECURE),
- 'requestDateTime' => $this->formatRequestDateTime($order['transaction_time']),
+ 'txnCode' => $this->valueMapper->mapTxType($txType, PosInterface::MODEL_NON_SECURE),
+ 'requestDateTime' => $this->valueFormatter->formatDateTime($order['transaction_time'], 'requestDateTime'),
'randomNumber' => $this->crypt->generateRandomString(),
'card' => [
'cardNumber' => $creditCard->getNumber(),
'cvv2' => $creditCard->getCvv(),
- 'expireDate' => $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT),
+ 'expireDate' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'expireDate'),
],
'transaction' => [
- 'amount' => $this->formatAmount($order['amount']),
- 'currencyCode' => $this->mapCurrency((string) $order['currency']),
+ 'amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'currencyCode' => $this->valueMapper->mapCurrency($order['currency']),
'motoInd' => 0,
- 'installCount' => $this->mapInstallment((int) $order['installment']),
+ 'installCount' => $this->valueFormatter->formatInstallment($order['installment']),
],
'customer' => [
'ipAddress' => $order['ip'],
@@ -180,15 +116,15 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $po
return $this->getRequestAccountData($posAccount) + [
'version' => self::API_VERSION,
- 'txnCode' => $this->mapTxType(PosInterface::TX_TYPE_PAY_POST_AUTH),
- 'requestDateTime' => $this->formatRequestDateTime($order['transaction_time']),
+ 'txnCode' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_PAY_POST_AUTH),
+ 'requestDateTime' => $this->valueFormatter->formatDateTime($order['transaction_time'], 'requestDateTime'),
'randomNumber' => $this->crypt->generateRandomString(),
'order' => [
'orderId' => (string) $order['id'],
],
'transaction' => [
- 'amount' => $this->formatAmount($order['amount']),
- 'currencyCode' => $this->mapCurrency((string) $order['currency']),
+ 'amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'currencyCode' => $this->valueMapper->mapCurrency($order['currency']),
],
'customer' => [
'ipAddress' => $order['ip'],
@@ -216,9 +152,9 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o
$order = $this->prepareCancelOrder($order);
$requestData = $this->getRequestAccountData($posAccount) + [
- 'txnCode' => $this->mapTxType(PosInterface::TX_TYPE_CANCEL),
+ 'txnCode' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_CANCEL),
'version' => self::API_VERSION,
- 'requestDateTime' => $this->formatRequestDateTime($order['transaction_time']),
+ 'requestDateTime' => $this->valueFormatter->formatDateTime($order['transaction_time'], 'requestDateTime'),
'randomNumber' => $this->crypt->generateRandomString(),
];
@@ -268,12 +204,12 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o
$requestData = $this->getRequestAccountData($posAccount) + [
'version' => self::API_VERSION,
- 'txnCode' => $this->mapTxType($refundTxType),
- 'requestDateTime' => $this->formatRequestDateTime($order['transaction_time']),
+ 'txnCode' => $this->valueMapper->mapTxType($refundTxType),
+ 'requestDateTime' => $this->valueFormatter->formatDateTime($order['transaction_time'], 'requestDateTime'),
'randomNumber' => $this->crypt->generateRandomString(),
'transaction' => [
- 'amount' => $this->formatAmount($order['amount']),
- 'currencyCode' => $this->mapCurrency((string) $order['currency']),
+ 'amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'currencyCode' => $this->valueMapper->mapCurrency($order['currency']),
],
];
@@ -309,8 +245,8 @@ public function createOrderHistoryRequestData(AbstractPosAccount $posAccount, ar
$result = $this->getRequestAccountData($posAccount) + [
'version' => self::API_VERSION,
- 'txnCode' => $this->mapTxType(PosInterface::TX_TYPE_ORDER_HISTORY, PosInterface::MODEL_NON_SECURE),
- 'requestDateTime' => $this->formatRequestDateTime($order['transaction_time']),
+ 'txnCode' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_ORDER_HISTORY, PosInterface::MODEL_NON_SECURE),
+ 'requestDateTime' => $this->valueFormatter->formatDateTime($order['transaction_time'], 'requestDateTime'),
'randomNumber' => $this->crypt->generateRandomString(),
'order' => [],
];
@@ -346,8 +282,8 @@ public function createHistoryRequestData(AbstractPosAccount $posAccount, array $
];
} elseif (isset($order['start_date'], $order['end_date'])) {
$requestData['report'] = [
- 'startDateTime' => $this->formatRequestDateTime($order['start_date']),
- 'endDateTime' => $this->formatRequestDateTime($order['end_date']),
+ 'startDateTime' => $this->valueFormatter->formatDateTime($order['start_date'], 'startDateTime'),
+ 'endDateTime' => $this->valueFormatter->formatDateTime($order['end_date'], 'endDateTime'),
];
}
@@ -364,19 +300,19 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
$order = $this->preparePaymentOrder($order);
$inputs = [
- 'paymentModel' => $this->secureTypeMappings[$paymentModel],
- 'txnCode' => $this->mapTxType($txType, $paymentModel),
+ 'paymentModel' => $this->valueMapper->mapSecureType($paymentModel),
+ 'txnCode' => $this->valueMapper->mapTxType($txType, $paymentModel),
'merchantSafeId' => $posAccount->getClientId(),
'terminalSafeId' => $posAccount->getTerminalId(),
'orderId' => (string) $order['id'],
'lang' => $this->getLang($posAccount, $order),
- 'amount' => (string) $order['amount'],
- 'currencyCode' => (string) $this->mapCurrency((string) $order['currency']),
- 'installCount' => (string) $this->mapInstallment((int) $order['installment']),
+ 'amount' => (string) $this->valueFormatter->formatAmount($order['amount']),
+ 'currencyCode' => (string) $this->valueMapper->mapCurrency($order['currency']),
+ 'installCount' => (string) $this->valueFormatter->formatInstallment($order['installment']),
'okUrl' => (string) $order['success_url'],
'failUrl' => (string) $order['fail_url'],
'randomNumber' => $this->crypt->generateRandomString(),
- 'requestDateTime' => $this->formatRequestDateTime($order['transaction_time']),
+ 'requestDateTime' => $this->valueFormatter->formatDateTime($order['transaction_time'], 'requestDateTime'),
];
if (null !== $posAccount->getSubMerchantId()) {
@@ -385,7 +321,7 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
if ($creditCard instanceof CreditCardInterface) {
$inputs['creditCard'] = $creditCard->getNumber();
- $inputs['expiredDate'] = $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT);
+ $inputs['expiredDate'] = $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'expiredDate');
$inputs['cvv'] = $creditCard->getCvv();
}
@@ -410,17 +346,6 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
return $data;
}
- /**
- * 0 => 1
- * 1 => 1
- * 2 => 2
- * @inheritDoc
- */
- protected function mapInstallment(int $installment): int
- {
- return \max($installment, 1);
- }
-
/**
* @inheritDoc
*/
@@ -496,16 +421,6 @@ protected function prepareCancelOrder(array $order): array
]);
}
- /**
- * @inheritDoc
- *
- * @return int
- */
- protected function mapCurrency(string $currency): int
- {
- return $this->currencyMappings[$currency];
- }
-
/**
* prepares history request
*
@@ -563,7 +478,7 @@ private function createRecurringData(array $recurringData): array
// Periyodik İşlem Frekansı
'frequencyInterval' => $recurringData['frequency'],
// D|W|M|Y
- 'frequencyCycle' => $this->mapRecurringFrequency($recurringData['frequencyType']),
+ 'frequencyCycle' => $this->valueMapper->mapRecurringFrequency($recurringData['frequencyType']),
'numberOfPayments' => $recurringData['installment'],
],
];
@@ -576,14 +491,4 @@ private function createDateTime(): \DateTimeImmutable
{
return new \DateTimeImmutable('now', new \DateTimeZone('Europe/Istanbul'));
}
-
- /**
- * @param DateTimeInterface $dateTime
- *
- * @return string example 2024-04-14T16:45:30.000
- */
- private function formatRequestDateTime(\DateTimeInterface $dateTime): string
- {
- return $dateTime->format('Y-m-d\TH:i:s').'.000';
- }
}
diff --git a/src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php
index cbb5cce1..5f31fa71 100644
--- a/src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php
+++ b/src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php
@@ -18,50 +18,6 @@
*/
class EstPosRequestDataMapper extends AbstractRequestDataMapper
{
- /** @var string */
- public const CREDIT_CARD_EXP_DATE_FORMAT = 'm/y';
-
- /** @var string */
- public const CREDIT_CARD_EXP_MONTH_FORMAT = 'm';
-
- /** @var string */
- public const CREDIT_CARD_EXP_YEAR_FORMAT = 'y';
-
- /**
- * {@inheritDoc}
- */
- protected array $txTypeMappings = [
- PosInterface::TX_TYPE_PAY_AUTH => 'Auth',
- PosInterface::TX_TYPE_PAY_PRE_AUTH => 'PreAuth',
- PosInterface::TX_TYPE_PAY_POST_AUTH => 'PostAuth',
- PosInterface::TX_TYPE_CANCEL => 'Void',
- PosInterface::TX_TYPE_REFUND => 'Credit',
- PosInterface::TX_TYPE_REFUND_PARTIAL => 'Credit',
- PosInterface::TX_TYPE_STATUS => 'ORDERSTATUS',
- PosInterface::TX_TYPE_HISTORY => 'ORDERHISTORY',
- ];
-
- /**
- * {@inheritdoc}
- */
- protected array $recurringOrderFrequencyMapping = [
- 'DAY' => 'D',
- 'WEEK' => 'W',
- 'MONTH' => 'M',
- 'YEAR' => 'Y',
- ];
-
- /**
- * {@inheritdoc}
- */
- protected array $secureTypeMappings = [
- PosInterface::MODEL_3D_SECURE => '3d',
- PosInterface::MODEL_3D_PAY => '3d_pay',
- PosInterface::MODEL_3D_PAY_HOSTING => '3d_pay_hosting',
- PosInterface::MODEL_3D_HOST => '3d_host',
- PosInterface::MODEL_NON_SECURE => 'regular',
- ];
-
/**
* {@inheritDoc}
*
@@ -72,12 +28,12 @@ public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array
$order = $this->preparePaymentOrder($order);
$requestData = $this->getRequestAccountData($posAccount) + [
- 'Type' => $this->mapTxType($txType),
+ 'Type' => $this->valueMapper->mapTxType($txType),
'IPAddress' => (string) $order['ip'],
'OrderId' => (string) $order['id'],
- 'Total' => (string) $order['amount'],
- 'Currency' => $this->mapCurrency($order['currency']),
- 'Taksit' => $this->mapInstallment((int) $order['installment']),
+ 'Total' => $this->valueFormatter->formatAmount($order['amount']),
+ 'Currency' => $this->valueMapper->mapCurrency($order['currency']),
+ 'Taksit' => $this->valueFormatter->formatInstallment($order['installment']),
'Number' => $responseData['md'],
'PayerTxnId' => $responseData['xid'],
'PayerSecurityLevel' => $responseData['eci'],
@@ -101,14 +57,14 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount
$order = $this->preparePaymentOrder($order);
$requestData = $this->getRequestAccountData($posAccount) + [
- 'Type' => $this->mapTxType($txType),
+ 'Type' => $this->valueMapper->mapTxType($txType),
'IPAddress' => (string) $order['ip'],
'OrderId' => (string) $order['id'],
- 'Total' => (string) $order['amount'],
- 'Currency' => $this->mapCurrency($order['currency']),
- 'Taksit' => $this->mapInstallment((int) $order['installment']),
+ 'Total' => (string) $this->valueFormatter->formatAmount($order['amount']),
+ 'Currency' => (string) $this->valueMapper->mapCurrency($order['currency']),
+ 'Taksit' => (string) $this->valueFormatter->formatInstallment($order['installment']),
'Number' => $creditCard->getNumber(),
- 'Expires' => $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT),
+ 'Expires' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'Expires'),
'Cvv2Val' => $creditCard->getCvv(),
'Mode' => 'P',
];
@@ -123,21 +79,21 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount
/**
* {@inheritDoc}
*
- * @return array{Type: string, OrderId: string, Name: string, Password: string, ClientId: string, Total: float|null}
+ * @return array{Type: string, OrderId: string, Name: string, Password: string, ClientId: string, Total: string|null}
*/
public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $posAccount, array $order): array
{
$order = $this->preparePostPaymentOrder($order);
$requestData = $this->getRequestAccountData($posAccount) + [
- 'Type' => $this->mapTxType(PosInterface::TX_TYPE_PAY_POST_AUTH),
+ 'Type' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_PAY_POST_AUTH),
'OrderId' => (string) $order['id'],
- 'Total' => isset($order['amount']) ? (float) $this->formatAmount($order['amount']) : null,
+ 'Total' => isset($order['amount']) ? (string) $this->valueFormatter->formatAmount($order['amount']) : null,
];
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'];
+ $requestData['Extra']['PREAMT'] = (string) $this->valueFormatter->formatAmount($order['pre_auth_amount']);
}
return $requestData;
@@ -150,7 +106,7 @@ public function createStatusRequestData(AbstractPosAccount $posAccount, array $o
{
$statusRequestData = $this->getRequestAccountData($posAccount) + [
'Extra' => [
- $this->mapTxType(PosInterface::TX_TYPE_STATUS) => 'QUERY',
+ $this->valueMapper->mapTxType(PosInterface::TX_TYPE_STATUS) => 'QUERY',
],
];
@@ -192,7 +148,7 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o
return $this->getRequestAccountData($posAccount) + [
'OrderId' => $order['id'],
- 'Type' => $this->mapTxType(PosInterface::TX_TYPE_CANCEL),
+ 'Type' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_CANCEL),
];
}
@@ -206,12 +162,12 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o
$requestData = [
'OrderId' => (string) $order['id'],
- 'Currency' => $this->mapCurrency($order['currency']),
- 'Type' => $this->mapTxType($refundTxType),
+ 'Currency' => (string) $this->valueMapper->mapCurrency($order['currency']),
+ 'Type' => $this->valueMapper->mapTxType($refundTxType),
];
if (isset($order['amount'])) {
- $requestData['Total'] = (string) $order['amount'];
+ $requestData['Total'] = (string) $this->valueFormatter->formatAmount($order['amount']);
}
return $this->getRequestAccountData($posAccount) + $requestData;
@@ -228,7 +184,7 @@ public function createOrderHistoryRequestData(AbstractPosAccount $posAccount, ar
$requestData = [
'OrderId' => (string) $order['id'],
'Extra' => [
- $this->mapTxType(PosInterface::TX_TYPE_HISTORY) => 'QUERY',
+ $this->valueMapper->mapTxType(PosInterface::TX_TYPE_HISTORY) => 'QUERY',
],
];
@@ -286,22 +242,22 @@ protected function create3DFormDataCommon(AbstractPosAccount $posAccount, array
{
$inputs = [
'clientid' => $posAccount->getClientId(),
- 'storetype' => $this->secureTypeMappings[$paymentModel],
- 'amount' => (string) $order['amount'],
+ 'storetype' => $this->valueMapper->mapSecureType($paymentModel),
+ 'amount' => (string) $this->valueFormatter->formatAmount($order['amount']),
'oid' => (string) $order['id'],
'okUrl' => (string) $order['success_url'],
'failUrl' => (string) $order['fail_url'],
'rnd' => $this->crypt->generateRandomString(),
'lang' => $this->getLang($posAccount, $order),
- 'currency' => $this->mapCurrency((string) $order['currency']),
- 'taksit' => $this->mapInstallment((int) $order['installment']),
- 'islemtipi' => $this->mapTxType($txType),
+ 'currency' => (string) $this->valueMapper->mapCurrency($order['currency']),
+ 'taksit' => (string) $this->valueFormatter->formatInstallment($order['installment']),
+ 'islemtipi' => $this->valueMapper->mapTxType($txType),
];
if ($creditCard instanceof CreditCardInterface) {
$inputs['pan'] = $creditCard->getNumber();
- $inputs['Ecom_Payment_Card_ExpDate_Month'] = $creditCard->getExpireMonth(self::CREDIT_CARD_EXP_MONTH_FORMAT);
- $inputs['Ecom_Payment_Card_ExpDate_Year'] = $creditCard->getExpireYear(self::CREDIT_CARD_EXP_YEAR_FORMAT);
+ $inputs['Ecom_Payment_Card_ExpDate_Month'] = $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'Ecom_Payment_Card_ExpDate_Month');
+ $inputs['Ecom_Payment_Card_ExpDate_Year'] = $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'Ecom_Payment_Card_ExpDate_Year');
$inputs['cv2'] = $creditCard->getCvv();
}
@@ -312,16 +268,6 @@ protected function create3DFormDataCommon(AbstractPosAccount $posAccount, array
];
}
- /**
- * 0 => ''
- * 1 => ''
- * 2 => '2'
- * @inheritDoc
- */
- protected function mapInstallment(int $installment): string
- {
- return $installment > 1 ? (string) $installment : '';
- }
/**
* @inheritDoc
@@ -369,16 +315,6 @@ protected function prepareOrderHistoryOrder(array $order): array
];
}
- /**
- * @inheritDoc
- *
- * @return string
- */
- protected function mapCurrency(string $currency): string
- {
- return (string) $this->currencyMappings[$currency] ?? $currency;
- }
-
/**
* @param AbstractPosAccount $posAccount
*
@@ -406,7 +342,7 @@ private function createRecurringData(array $recurringData): array
// Periyodik İşlem Frekansı
'OrderFrequencyInterval' => (string) $recurringData['frequency'],
// D|M|Y
- 'OrderFrequencyCycle' => $this->mapRecurringFrequency($recurringData['frequencyType']),
+ 'OrderFrequencyCycle' => $this->valueMapper->mapRecurringFrequency($recurringData['frequencyType']),
'TotalNumberPayments' => (string) $recurringData['installment'],
],
];
diff --git a/src/DataMapper/RequestDataMapper/EstV3PosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/EstV3PosRequestDataMapper.php
index 2c61d03e..b9d0ee55 100644
--- a/src/DataMapper/RequestDataMapper/EstV3PosRequestDataMapper.php
+++ b/src/DataMapper/RequestDataMapper/EstV3PosRequestDataMapper.php
@@ -23,7 +23,7 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
$data = $this->create3DFormDataCommon($posAccount, $order, $paymentModel, $txType, $gatewayURL, $creditCard);
- $data['inputs']['TranType'] = $this->mapTxType($txType);
+ $data['inputs']['TranType'] = $this->valueMapper->mapTxType($txType);
unset($data['inputs']['islemtipi']);
$data['inputs']['hashAlgorithm'] = 'ver3';
diff --git a/src/DataMapper/RequestDataMapper/GarantiPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/GarantiPosRequestDataMapper.php
index 21c333ba..b3900431 100644
--- a/src/DataMapper/RequestDataMapper/GarantiPosRequestDataMapper.php
+++ b/src/DataMapper/RequestDataMapper/GarantiPosRequestDataMapper.php
@@ -22,15 +22,6 @@ class GarantiPosRequestDataMapper extends AbstractRequestDataMapper
/** @var string */
public const API_VERSION = '512';
- /** @var string */
- public const CREDIT_CARD_EXP_DATE_FORMAT = 'my';
-
- /** @var string */
- public const CREDIT_CARD_EXP_MONTH_FORMAT = 'm';
-
- /** @var string */
- public const CREDIT_CARD_EXP_YEAR_FORMAT = 'y';
-
/**
* MotoInd; işlemin MAilOrder bir işlem olup olmadığı bilgisinin gönderildiği alandır.
* Y (also E) ise işlem mail order bir işlemdir.
@@ -39,35 +30,6 @@ class GarantiPosRequestDataMapper extends AbstractRequestDataMapper
*/
private const MOTO = 'N';
- /**
- * {@inheritDoc}
- */
- protected array $secureTypeMappings = [
- PosInterface::MODEL_3D_SECURE => '3D',
- PosInterface::MODEL_3D_PAY => '3D_PAY',
- ];
-
- /**
- * {@inheritDoc}
- */
- protected array $txTypeMappings = [
- PosInterface::TX_TYPE_PAY_AUTH => 'sales',
- PosInterface::TX_TYPE_PAY_PRE_AUTH => 'preauth',
- PosInterface::TX_TYPE_PAY_POST_AUTH => 'postauth',
- PosInterface::TX_TYPE_CANCEL => 'void',
- PosInterface::TX_TYPE_REFUND => 'refund',
- PosInterface::TX_TYPE_REFUND_PARTIAL => 'refund',
- PosInterface::TX_TYPE_ORDER_HISTORY => 'orderhistoryinq',
- PosInterface::TX_TYPE_HISTORY => 'orderlistinq',
- PosInterface::TX_TYPE_STATUS => 'orderinq',
- ];
-
- protected array $recurringOrderFrequencyMapping = [
- 'DAY' => 'D',
- 'WEEK' => 'W',
- 'MONTH' => 'M',
- ];
-
/** @var GarantiPosCrypt */
protected CryptInterface $crypt;
@@ -92,7 +54,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array
],
'Transaction' => [
'Type' => $responseData['txntype'],
- 'InstallmentCnt' => $this->mapInstallment($order['installment']),
+ 'InstallmentCnt' => $this->valueFormatter->formatInstallment($order['installment']),
'Amount' => $responseData['txnamount'],
'CurrencyCode' => $responseData['txncurrencycode'],
'CardholderPresentCode' => '13', //13 for 3D secure payment
@@ -136,10 +98,10 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount
'OrderID' => $order['id'],
],
'Transaction' => [
- 'Type' => $this->mapTxType($txType),
- 'InstallmentCnt' => $this->mapInstallment($order['installment']),
- 'Amount' => $this->formatAmount($order['amount']),
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
+ 'Type' => $this->valueMapper->mapTxType($txType),
+ 'InstallmentCnt' => $this->valueFormatter->formatInstallment($order['installment']),
+ 'Amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'CurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
'CardholderPresentCode' => '0',
'MotoInd' => self::MOTO,
],
@@ -174,9 +136,9 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $po
'OrderID' => $order['id'],
],
'Transaction' => [
- 'Type' => $this->mapTxType(PosInterface::TX_TYPE_PAY_POST_AUTH),
- 'Amount' => $this->formatAmount($order['amount']),
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
+ 'Type' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_PAY_POST_AUTH),
+ 'Amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'CurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
'OriginalRetrefNum' => $order['ref_ret_num'],
],
];
@@ -206,10 +168,10 @@ public function createStatusRequestData(AbstractPosAccount $posAccount, array $o
'OrderID' => $order['id'],
],
'Transaction' => [
- 'Type' => $this->mapTxType(PosInterface::TX_TYPE_STATUS),
- 'InstallmentCnt' => $this->mapInstallment($order['installment']),
- 'Amount' => $this->formatAmount($order['amount']), //sabit olarak amount 100 gonderilecek
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
+ 'Type' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_STATUS),
+ 'InstallmentCnt' => $this->valueFormatter->formatInstallment($order['installment']),
+ 'Amount' => $this->valueFormatter->formatAmount($order['amount']), //sabit olarak amount 100 gonderilecek
+ 'CurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
'CardholderPresentCode' => '0',
'MotoInd' => self::MOTO,
],
@@ -240,10 +202,10 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o
'OrderID' => $order['id'],
],
'Transaction' => [
- 'Type' => $this->mapTxType(PosInterface::TX_TYPE_CANCEL),
- 'InstallmentCnt' => $this->mapInstallment($order['installment']),
- 'Amount' => $this->formatAmount($order['amount']), //sabit olarak amount 100 gonderilecek
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
+ 'Type' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_CANCEL),
+ 'InstallmentCnt' => $this->valueFormatter->formatInstallment($order['installment']),
+ 'Amount' => $this->valueFormatter->formatAmount($order['amount']), //sabit olarak amount 100 gonderilecek
+ 'CurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
'CardholderPresentCode' => '0',
'MotoInd' => self::MOTO,
'OriginalRetrefNum' => $order['ref_ret_num'],
@@ -275,10 +237,10 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o
'OrderID' => $order['id'],
],
'Transaction' => [
- 'Type' => $this->mapTxType($refundTxType),
- 'InstallmentCnt' => $this->mapInstallment($order['installment']),
- 'Amount' => $this->formatAmount($order['amount']), //sabit olarak amount 100 gonderilecek,
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
+ 'Type' => $this->valueMapper->mapTxType($refundTxType),
+ 'InstallmentCnt' => $this->valueFormatter->formatInstallment($order['installment']),
+ 'Amount' => $this->valueFormatter->formatAmount($order['amount']), //sabit olarak amount 100 gonderilecek,
+ 'CurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
'CardholderPresentCode' => '0',
'MotoInd' => self::MOTO,
'OriginalRetrefNum' => $order['ref_ret_num'],
@@ -310,10 +272,10 @@ public function createOrderHistoryRequestData(AbstractPosAccount $posAccount, ar
'OrderID' => $order['id'],
],
'Transaction' => [
- 'Type' => $this->mapTxType(PosInterface::TX_TYPE_ORDER_HISTORY),
- 'InstallmentCnt' => $this->mapInstallment($order['installment']),
- 'Amount' => $this->formatAmount($order['amount']), //sabit olarak amount 100 gonderilecek
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
+ 'Type' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_ORDER_HISTORY),
+ 'InstallmentCnt' => $this->valueFormatter->formatInstallment($order['installment']),
+ 'Amount' => $this->valueFormatter->formatAmount($order['amount']), //sabit olarak amount 100 gonderilecek
+ 'CurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
'CardholderPresentCode' => '0',
'MotoInd' => self::MOTO,
],
@@ -344,8 +306,8 @@ public function createHistoryRequestData(AbstractPosAccount $posAccount, array $
'GroupID' => null,
'Description' => null,
// Başlangıç ve bitiş tarihleri arasında en fazla 30 gün olabilir
- 'StartDate' => $this->formatRequestDateTime($order['start_date']),
- 'EndDate' => $this->formatRequestDateTime($order['end_date']),
+ 'StartDate' => $this->valueFormatter->formatDateTime($order['start_date'], 'StartDate', PosInterface::TX_TYPE_HISTORY),
+ 'EndDate' => $this->valueFormatter->formatDateTime($order['end_date'], 'EndDate', PosInterface::TX_TYPE_HISTORY),
/**
* 500 adetten fazla işlem olması durumunda ListPageNum alanında diğer 500 lü grupların görüntülenmesi
* için sayfa numarası yazılır.
@@ -353,9 +315,9 @@ public function createHistoryRequestData(AbstractPosAccount $posAccount, array $
'ListPageNum' => $order['page'],
],
'Transaction' => [
- 'Type' => $this->mapTxType(PosInterface::TX_TYPE_HISTORY),
- 'Amount' => $this->formatAmount(1), //sabit olarak amount 100 gonderilecek
- 'CurrencyCode' => $this->mapCurrency(PosInterface::CURRENCY_TRY),
+ 'Type' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_HISTORY),
+ 'Amount' => $this->valueFormatter->formatAmount(1), //sabit olarak amount 100 gonderilecek
+ 'CurrencyCode' => $this->valueMapper->mapCurrency(PosInterface::CURRENCY_TRY),
'CardholderPresentCode' => '0',
'MotoInd' => self::MOTO,
],
@@ -376,17 +338,17 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
$order = $this->preparePaymentOrder($order);
$inputs = [
- 'secure3dsecuritylevel' => $this->secureTypeMappings[$paymentModel],
+ 'secure3dsecuritylevel' => $this->valueMapper->mapSecureType($paymentModel),
'mode' => $this->getMode(),
'apiversion' => self::API_VERSION,
'terminalprovuserid' => $posAccount->getUsername(),
'terminaluserid' => $posAccount->getUsername(),
'terminalmerchantid' => $posAccount->getClientId(),
'terminalid' => $posAccount->getTerminalId(),
- 'txntype' => $this->mapTxType($txType),
- 'txnamount' => (string) $this->formatAmount($order['amount']),
- 'txncurrencycode' => $this->mapCurrency($order['currency']),
- 'txninstallmentcount' => $this->mapInstallment($order['installment']),
+ 'txntype' => $this->valueMapper->mapTxType($txType),
+ 'txnamount' => (string) $this->valueFormatter->formatAmount($order['amount']),
+ 'txncurrencycode' => (string) $this->valueMapper->mapCurrency($order['currency']),
+ 'txninstallmentcount' => (string) $this->valueFormatter->formatInstallment($order['installment']),
'orderid' => (string) $order['id'],
'successurl' => (string) $order['success_url'],
'errorurl' => (string) $order['fail_url'],
@@ -395,8 +357,8 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
if ($creditCard instanceof CreditCardInterface) {
$inputs['cardnumber'] = $creditCard->getNumber();
- $inputs['cardexpiredatemonth'] = $creditCard->getExpireMonth(self::CREDIT_CARD_EXP_MONTH_FORMAT);
- $inputs['cardexpiredateyear'] = $creditCard->getExpireYear(self::CREDIT_CARD_EXP_YEAR_FORMAT);
+ $inputs['cardexpiredatemonth'] = $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'cardexpiredatemonth');
+ $inputs['cardexpiredateyear'] = $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'cardexpiredateyear');
$inputs['cardcvv2'] = $creditCard->getCvv();
}
@@ -419,40 +381,6 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
];
}
- /**
- * 0 => ''
- * 1 => ''
- * 2 => '2'
- * @inheritDoc
- */
- protected function mapInstallment(int $installment): string
- {
- return $installment > 1 ? (string) $installment : '';
- }
-
- /**
- * Amount Formatter
- * converts 100 to 10000, or 10.01 to 1001
- *
- * @param float $amount
- *
- * @return int
- */
- protected function formatAmount(float $amount): int
- {
- return (int) (\round($amount, 2) * 100);
- }
-
- /**
- * @inheritDoc
- *
- * @return string
- */
- protected function mapCurrency(string $currency): string
- {
- return (string) $this->currencyMappings[$currency] ?? $currency;
- }
-
/**
* @inheritDoc
*/
@@ -590,7 +518,7 @@ private function getCardData(CreditCardInterface $creditCard): array
{
return [
'Number' => $creditCard->getNumber(),
- 'ExpireDate' => $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT),
+ 'ExpireDate' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'ExpireDate'),
'CVV2' => $creditCard->getCvv(),
];
}
@@ -620,20 +548,11 @@ private function createRecurringData(array $recurringData): array
{
return [
'TotalPaymentNum' => (string) $recurringData['installment'], //kac kere tekrarlanacak
- 'FrequencyType' => $this->mapRecurringFrequency($recurringData['frequencyType']), //Monthly, weekly, daily
+ 'FrequencyType' => $this->valueMapper->mapRecurringFrequency($recurringData['frequencyType']), //Monthly, weekly, daily
'FrequencyInterval' => (string) $recurringData['frequency'],
'Type' => 'R', // R:Sabit Tutarli G:Degisken Tuta
+ //todo use formatter
'StartDate' => isset($recurringData['startDate']) ? $recurringData['startDate']->format('Ymd') : '',
];
}
-
- /**
- * @param \DateTimeInterface $dateTime
- *
- * @return string example 01/12/2010 11:11
- */
- private function formatRequestDateTime(\DateTimeInterface $dateTime): string
- {
- return $dateTime->format('d/m/Y H:i');
- }
}
diff --git a/src/DataMapper/RequestDataMapper/InterPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/InterPosRequestDataMapper.php
index fa7219ba..88b9bd82 100644
--- a/src/DataMapper/RequestDataMapper/InterPosRequestDataMapper.php
+++ b/src/DataMapper/RequestDataMapper/InterPosRequestDataMapper.php
@@ -17,50 +17,12 @@
*/
class InterPosRequestDataMapper extends AbstractRequestDataMapper
{
- /** @var string */
- public const CREDIT_CARD_EXP_DATE_FORMAT = 'my';
-
/**
* MOTO (Mail Order Telephone Order) 0 for false, 1 for true
* @var string
*/
protected const MOTO = '0';
- /**
- * {@inheritdoc}
- */
- protected array $secureTypeMappings = [
- PosInterface::MODEL_3D_SECURE => '3DModel',
- PosInterface::MODEL_3D_PAY => '3DPay',
- PosInterface::MODEL_3D_HOST => '3DHost',
- PosInterface::MODEL_NON_SECURE => 'NonSecure',
- ];
-
- /**
- * Transaction Types
- *
- * {@inheritdoc}
- */
- protected array $txTypeMappings = [
- PosInterface::TX_TYPE_PAY_AUTH => 'Auth',
- PosInterface::TX_TYPE_PAY_PRE_AUTH => 'PreAuth',
- PosInterface::TX_TYPE_PAY_POST_AUTH => 'PostAuth',
- PosInterface::TX_TYPE_CANCEL => 'Void',
- PosInterface::TX_TYPE_REFUND => 'Refund',
- PosInterface::TX_TYPE_REFUND_PARTIAL => 'Refund',
- PosInterface::TX_TYPE_STATUS => 'StatusHistory',
- ];
-
- /**
- * {@inheritdoc}
- */
- protected array $cardTypeMapping = [
- CreditCardInterface::CARD_TYPE_VISA => '0',
- CreditCardInterface::CARD_TYPE_MASTERCARD => '1',
- CreditCardInterface::CARD_TYPE_AMEX => '2',
- CreditCardInterface::CARD_TYPE_TROY => '3',
- ];
-
/**
* TODO tekrarlanan odemeler icin daha fazla bilgi lazim, Deniz bank dokumantasyonunda hic bir aciklama yok
* ornek kodlarda ise sadece bu alttaki 2 veriyi gondermis.
@@ -76,12 +38,12 @@ public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array
$order = $this->preparePaymentOrder($order);
return $this->getRequestAccountData($posAccount) + [
- 'TxnType' => $this->mapTxType($txType),
- 'SecureType' => $this->secureTypeMappings[PosInterface::MODEL_NON_SECURE],
+ 'TxnType' => $this->valueMapper->mapTxType($txType),
+ 'SecureType' => $this->valueMapper->mapSecureType(PosInterface::MODEL_NON_SECURE),
'OrderId' => (string) $order['id'],
- 'PurchAmount' => (string) $order['amount'],
- 'Currency' => $this->mapCurrency($order['currency']),
- 'InstallmentCount' => $this->mapInstallment($order['installment']),
+ 'PurchAmount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'Currency' => $this->valueMapper->mapCurrency($order['currency']),
+ 'InstallmentCount' => $this->valueFormatter->formatInstallment($order['installment']),
'MD' => $responseData['MD'],
'PayerTxnId' => $responseData['PayerTxnId'],
'Eci' => $responseData['Eci'],
@@ -99,17 +61,17 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount
$order = $this->preparePaymentOrder($order);
return $this->getRequestAccountData($posAccount) + [
- 'TxnType' => $this->mapTxType($txType),
- 'SecureType' => $this->secureTypeMappings[PosInterface::MODEL_NON_SECURE],
+ 'TxnType' => $this->valueMapper->mapTxType($txType),
+ 'SecureType' => $this->valueMapper->mapSecureType(PosInterface::MODEL_NON_SECURE),
'OrderId' => $order['id'],
- 'PurchAmount' => $order['amount'],
- 'Currency' => $this->mapCurrency($order['currency']),
- 'InstallmentCount' => $this->mapInstallment((int) $order['installment']),
+ 'PurchAmount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'Currency' => $this->valueMapper->mapCurrency($order['currency']),
+ 'InstallmentCount' => $this->valueFormatter->formatInstallment($order['installment']),
'MOTO' => self::MOTO,
'Lang' => $this->getLang($posAccount, $order),
- 'CardType' => $this->cardTypeMapping[$creditCard->getType()],
+ 'CardType' => $this->valueMapper->mapCardType($creditCard->getType()),
'Pan' => $creditCard->getNumber(),
- 'Expiry' => $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT),
+ 'Expiry' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'Expiry'),
'Cvv2' => $creditCard->getCvv(),
];
}
@@ -123,12 +85,12 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $po
$order = $this->preparePostPaymentOrder($order);
return $this->getRequestAccountData($posAccount) + [
- 'TxnType' => $this->mapTxType(PosInterface::TX_TYPE_PAY_POST_AUTH),
- 'SecureType' => $this->secureTypeMappings[PosInterface::MODEL_NON_SECURE],
+ 'TxnType' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_PAY_POST_AUTH),
+ 'SecureType' => $this->valueMapper->mapSecureType(PosInterface::MODEL_NON_SECURE),
'OrderId' => null,
'orgOrderId' => (string) $order['id'],
- 'PurchAmount' => (string) $order['amount'],
- 'Currency' => $this->mapCurrency($order['currency']),
+ 'PurchAmount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'Currency' => (string) $this->valueMapper->mapCurrency($order['currency']),
'MOTO' => self::MOTO,
];
}
@@ -144,8 +106,8 @@ public function createStatusRequestData(AbstractPosAccount $posAccount, array $o
return $this->getRequestAccountData($posAccount) + [
'OrderId' => null, //todo buraya hangi deger verilecek?
'orgOrderId' => (string) $order['id'],
- 'TxnType' => $this->mapTxType(PosInterface::TX_TYPE_STATUS),
- 'SecureType' => $this->secureTypeMappings[PosInterface::MODEL_NON_SECURE],
+ 'TxnType' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_STATUS),
+ 'SecureType' => $this->valueMapper->mapSecureType(PosInterface::MODEL_NON_SECURE),
'Lang' => $this->getLang($posAccount, $order),
];
}
@@ -161,8 +123,8 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o
return $this->getRequestAccountData($posAccount) + [
'OrderId' => null, //todo buraya hangi deger verilecek?
'orgOrderId' => (string) $order['id'],
- 'TxnType' => $this->mapTxType(PosInterface::TX_TYPE_CANCEL),
- 'SecureType' => $this->secureTypeMappings[PosInterface::MODEL_NON_SECURE],
+ 'TxnType' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_CANCEL),
+ 'SecureType' => $this->valueMapper->mapSecureType(PosInterface::MODEL_NON_SECURE),
'Lang' => $this->getLang($posAccount, $order),
];
}
@@ -178,9 +140,9 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o
return $this->getRequestAccountData($posAccount) + [
'OrderId' => null,
'orgOrderId' => (string) $order['id'],
- 'PurchAmount' => (string) $order['amount'],
- 'TxnType' => $this->mapTxType($refundTxType),
- 'SecureType' => $this->secureTypeMappings[PosInterface::MODEL_NON_SECURE],
+ 'PurchAmount' => (string) $this->valueFormatter->formatAmount($order['amount']),
+ 'TxnType' => $this->valueMapper->mapTxType($refundTxType),
+ 'SecureType' => $this->valueMapper->mapSecureType(PosInterface::MODEL_NON_SECURE),
'Lang' => $this->getLang($posAccount, $order),
'MOTO' => self::MOTO,
];
@@ -211,22 +173,22 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
$inputs = [
'ShopCode' => $posAccount->getClientId(),
- 'TxnType' => $this->mapTxType($txType),
- 'SecureType' => $this->secureTypeMappings[$paymentModel],
- 'PurchAmount' => $order['amount'],
+ 'TxnType' => $this->valueMapper->mapTxType($txType),
+ 'SecureType' => $this->valueMapper->mapSecureType($paymentModel),
+ 'PurchAmount' => $this->valueFormatter->formatAmount($order['amount']),
'OrderId' => $order['id'],
'OkUrl' => $order['success_url'],
'FailUrl' => $order['fail_url'],
'Rnd' => $this->crypt->generateRandomString(),
'Lang' => $this->getLang($posAccount, $order),
- 'Currency' => $this->mapCurrency($order['currency']),
- 'InstallmentCount' => $this->mapInstallment((int) $order['installment']),
+ 'Currency' => $this->valueMapper->mapCurrency($order['currency']),
+ 'InstallmentCount' => $this->valueFormatter->formatInstallment($order['installment']),
];
if ($creditCard instanceof CreditCardInterface) {
- $inputs['CardType'] = $this->cardTypeMapping[$creditCard->getType()];
+ $inputs['CardType'] = $this->valueMapper->mapCardType($creditCard->getType());
$inputs['Pan'] = $creditCard->getNumber();
- $inputs['Expiry'] = $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT);
+ $inputs['Expiry'] = $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'Expiry');
$inputs['Cvv2'] = $creditCard->getCvv();
}
@@ -249,27 +211,6 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
];
}
- /**
- * 0 => ''
- * 1 => ''
- * 2 => '2'
- * @inheritDoc
- */
- protected function mapInstallment(int $installment): string
- {
- return $installment > 1 ? (string) $installment : '';
- }
-
- /**
- * @inheritDoc
- *
- * @return string
- */
- protected function mapCurrency(string $currency): string
- {
- return (string) $this->currencyMappings[$currency] ?? $currency;
- }
-
/**
* @inheritDoc
*/
diff --git a/src/DataMapper/RequestDataMapper/KuveytPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/KuveytPosRequestDataMapper.php
index 12ba644e..65301f69 100644
--- a/src/DataMapper/RequestDataMapper/KuveytPosRequestDataMapper.php
+++ b/src/DataMapper/RequestDataMapper/KuveytPosRequestDataMapper.php
@@ -22,54 +22,6 @@ class KuveytPosRequestDataMapper extends AbstractRequestDataMapper
/** @var string */
public const API_VERSION = 'TDV2.0.0';
- /** @var string */
- public const CREDIT_CARD_EXP_YEAR_FORMAT = 'y';
-
- /** @var string */
- public const CREDIT_CARD_EXP_MONTH_FORMAT = 'm';
-
- /**
- * {@inheritdoc}
- */
- protected array $secureTypeMappings = [
- PosInterface::MODEL_3D_SECURE => '3',
- PosInterface::MODEL_NON_SECURE => '0',
- ];
-
- /**
- * {@inheritDoc}
- */
- protected array $txTypeMappings = [
- PosInterface::TX_TYPE_PAY_AUTH => 'Sale',
- PosInterface::TX_TYPE_CANCEL => 'SaleReversal',
- PosInterface::TX_TYPE_STATUS => 'GetMerchantOrderDetail',
- PosInterface::TX_TYPE_REFUND => 'Drawback',
- PosInterface::TX_TYPE_REFUND_PARTIAL => 'PartialDrawback',
- ];
-
- /**
- * {@inheritDoc}
- */
- protected array $cardTypeMapping = [
- CreditCardInterface::CARD_TYPE_VISA => 'Visa',
- CreditCardInterface::CARD_TYPE_MASTERCARD => 'MasterCard',
- CreditCardInterface::CARD_TYPE_TROY => 'Troy',
- ];
-
- /**
- * Currency mapping
- *
- * {@inheritdoc}
- */
- protected array $currencyMappings = [
- PosInterface::CURRENCY_TRY => '0949',
- PosInterface::CURRENCY_USD => '0840',
- PosInterface::CURRENCY_EUR => '0978',
- PosInterface::CURRENCY_GBP => '0826',
- PosInterface::CURRENCY_JPY => '0392',
- PosInterface::CURRENCY_RUB => '0810',
- ];
-
/** @var KuveytPosCrypt */
protected CryptInterface $crypt;
@@ -93,7 +45,7 @@ public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array
'Data' => $responseData['MD'],
],
],
- 'TransactionType' => $this->mapTxType($txType),
+ 'TransactionType' => $this->valueMapper->mapTxType($txType),
'InstallmentCount' => $responseData['VPosMessage']['InstallmentCount'],
'Amount' => $responseData['VPosMessage']['Amount'],
'DisplayAmount' => $responseData['VPosMessage']['Amount'],
@@ -127,13 +79,13 @@ public function create3DEnrollmentCheckRequestData(KuveytPosAccount $kuveytPosAc
$inputs = $this->getRequestAccountData($kuveytPosAccount) + [
'APIVersion' => self::API_VERSION,
- 'TransactionType' => $this->mapTxType($txType),
- 'TransactionSecurity' => $this->secureTypeMappings[$paymentModel],
- 'InstallmentCount' => $this->mapInstallment($order['installment']),
- 'Amount' => $this->formatAmount($order['amount']),
+ 'TransactionType' => $this->valueMapper->mapTxType($txType),
+ 'TransactionSecurity' => $this->valueMapper->mapSecureType($paymentModel),
+ 'InstallmentCount' => $this->valueFormatter->formatInstallment($order['installment']),
+ 'Amount' => $this->valueFormatter->formatAmount($order['amount']),
//DisplayAmount: Amount değeri ile aynı olacak şekilde gönderilmelidir.
- 'DisplayAmount' => $this->formatAmount($order['amount']),
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
+ 'DisplayAmount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'CurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
'MerchantOrderId' => $order['id'],
'OkUrl' => $order['success_url'],
'FailUrl' => $order['fail_url'],
@@ -144,10 +96,10 @@ public function create3DEnrollmentCheckRequestData(KuveytPosAccount $kuveytPosAc
if ($creditCard instanceof CreditCardInterface) {
$inputs['CardHolderName'] = $creditCard->getHolderName();
- $inputs['CardType'] = $this->cardTypeMapping[$creditCard->getType()];
+ $inputs['CardType'] = $this->valueMapper->mapCardType($creditCard->getType());
$inputs['CardNumber'] = $creditCard->getNumber();
- $inputs['CardExpireDateYear'] = $creditCard->getExpireYear(self::CREDIT_CARD_EXP_YEAR_FORMAT);
- $inputs['CardExpireDateMonth'] = $creditCard->getExpireMonth(self::CREDIT_CARD_EXP_MONTH_FORMAT);
+ $inputs['CardExpireDateYear'] = $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'CardExpireDateYear');
+ $inputs['CardExpireDateMonth'] = $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'CardExpireDateMonth');
$inputs['CardCVV2'] = $creditCard->getCvv();
}
@@ -176,17 +128,17 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount
$requestData = $this->getRequestAccountData($posAccount) + [
'APIVersion' => self::API_VERSION,
'HashData' => '',
- 'TransactionType' => $this->mapTxType($txType),
+ 'TransactionType' => $this->valueMapper->mapTxType($txType),
'TransactionSecurity' => '1',
'MerchantOrderId' => (string) $order['id'],
- 'Amount' => $this->formatAmount($order['amount']),
- 'DisplayAmount' => $this->formatAmount($order['amount']),
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
- 'InstallmentCount' => $this->mapInstallment($order['installment']),
+ 'Amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'DisplayAmount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'CurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
+ 'InstallmentCount' => $this->valueFormatter->formatInstallment($order['installment']),
'CardHolderName' => $creditCard->getHolderName(),
'CardNumber' => $creditCard->getNumber(),
- 'CardExpireDateYear' => $creditCard->getExpireYear(self::CREDIT_CARD_EXP_YEAR_FORMAT),
- 'CardExpireDateMonth' => $creditCard->getExpireMonth(self::CREDIT_CARD_EXP_MONTH_FORMAT),
+ 'CardExpireDateYear' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'CardExpireDateYear'),
+ 'CardExpireDateMonth' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'CardExpireDateMonth'),
'CardCVV2' => $creditCard->getCvv(),
];
@@ -225,23 +177,23 @@ public function createStatusRequestData(AbstractPosAccount $posAccount, array $o
* siparisi buluyor.
* Ancak bu degerler gonderilmediginde veya gecersiz (orn. null) gonderildiginde SOAP server hata donuyor.
*/
- 'StartDate' => $order['start_date']->format('Y-m-d\TH:i:s'),
- 'EndDate' => $order['end_date']->format('Y-m-d\TH:i:s'),
+ 'StartDate' => $this->valueFormatter->formatDateTime($order['start_date'], 'StartDate'),
+ 'EndDate' => $this->valueFormatter->formatDateTime($order['end_date'], 'EndDate'),
'TransactionType' => 0,
'VPosMessage' => $this->getRequestAccountData($posAccount) + [
'APIVersion' => self::API_VERSION,
'InstallmentMaturityCommisionFlag' => 0,
'HashData' => '',
'SubMerchantId' => 0,
- 'CardType' => $this->cardTypeMapping[CreditCardInterface::CARD_TYPE_VISA], // Default gönderilebilir.
+ 'CardType' => $this->valueMapper->mapCardType(CreditCardInterface::CARD_TYPE_VISA), //Default gönderilebilir.
'BatchID' => 0,
- 'TransactionType' => $this->mapTxType(PosInterface::TX_TYPE_STATUS),
+ 'TransactionType' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_STATUS),
'InstallmentCount' => 0,
'Amount' => 0,
'DisplayAmount' => 0,
'CancelAmount' => 0,
'MerchantOrderId' => $order['id'],
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
+ 'CurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
'FECAmount' => 0,
'QeryId' => 0,
'DebtId' => 0,
@@ -272,7 +224,7 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o
'LanguageId' => 0,
'CustomerId' => $posAccount->getCustomerId(),
'MailOrTelephoneOrder' => true,
- 'Amount' => $this->formatAmount($order['amount']),
+ 'Amount' => $this->valueFormatter->formatAmount($order['amount']),
'MerchantId' => $posAccount->getClientId(),
'OrderId' => $order['remote_order_id'],
'RRN' => $order['ref_ret_num'],
@@ -283,16 +235,16 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o
'InstallmentMaturityCommisionFlag' => 0,
'HashData' => '',
'SubMerchantId' => 0,
- 'CardType' => $this->cardTypeMapping[CreditCardInterface::CARD_TYPE_VISA], //Default gönderilebilir.
+ 'CardType' => $this->valueMapper->mapCardType(CreditCardInterface::CARD_TYPE_VISA), //Default gönderilebilir.
'BatchID' => 0,
- 'TransactionType' => $this->mapTxType(PosInterface::TX_TYPE_CANCEL),
+ 'TransactionType' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_CANCEL),
'InstallmentCount' => 0,
- 'Amount' => $this->formatAmount($order['amount']),
- 'DisplayAmount' => $this->formatAmount($order['amount']),
- 'CancelAmount' => $this->formatAmount($order['amount']),
+ 'Amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'DisplayAmount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'CancelAmount' => $this->valueFormatter->formatAmount($order['amount']),
'MerchantOrderId' => $order['id'],
'FECAmount' => 0,
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
+ 'CurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
'QeryId' => 0,
'DebtId' => 0,
'SurchargeAmount' => 0,
@@ -322,7 +274,7 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o
'LanguageId' => 0,
'CustomerId' => $posAccount->getCustomerId(),
'MailOrTelephoneOrder' => true,
- 'Amount' => $this->formatAmount($order['amount']),
+ 'Amount' => $this->valueFormatter->formatAmount($order['amount']),
'MerchantId' => $posAccount->getClientId(),
'OrderId' => $order['remote_order_id'],
'RRN' => $order['ref_ret_num'],
@@ -333,16 +285,16 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o
'InstallmentMaturityCommisionFlag' => 0,
'HashData' => '',
'SubMerchantId' => 0,
- 'CardType' => $this->cardTypeMapping[CreditCardInterface::CARD_TYPE_VISA], //Default gönderilebilir.
+ 'CardType' => $this->valueMapper->mapCardType(CreditCardInterface::CARD_TYPE_VISA), //Default gönderilebilir.
'BatchID' => 0,
- 'TransactionType' => $this->mapTxType($refundTxType),
+ 'TransactionType' => $this->valueMapper->mapTxType($refundTxType),
'InstallmentCount' => 0,
- 'Amount' => $this->formatAmount($order['amount']),
+ 'Amount' => $this->valueFormatter->formatAmount($order['amount']),
'DisplayAmount' => 0,
- 'CancelAmount' => $this->formatAmount($order['amount']),
+ 'CancelAmount' => $this->valueFormatter->formatAmount($order['amount']),
'MerchantOrderId' => $order['id'],
'FECAmount' => 0,
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
+ 'CurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
'QeryId' => 0,
'DebtId' => 0,
'SurchargeAmount' => 0,
@@ -388,30 +340,6 @@ public function createOrderHistoryRequestData(AbstractPosAccount $posAccount, ar
throw new NotImplementedException();
}
- /**
- * Amount Formatter
- * converts 100 to 10000, or 10.01 to 1001
- *
- * @param float $amount
- *
- * @return int
- */
- protected function formatAmount(float $amount): int
- {
- return (int) (\round($amount, 2) * 100);
- }
-
- /**
- * 0 => '0'
- * 1 => '0'
- * 2 => '2'
- * @inheritDoc
- */
- protected function mapInstallment(int $installment): string
- {
- return $installment > 1 ? (string) $installment : '0';
- }
-
/**
* @inheritDoc
*/
diff --git a/src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php
index 3c502961..12095b88 100644
--- a/src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php
+++ b/src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php
@@ -17,41 +17,6 @@
*/
class PayFlexCPV4PosRequestDataMapper extends AbstractRequestDataMapper
{
- /** @var string */
- public const CREDIT_CARD_EXP_DATE_LONG_FORMAT = 'Ym';
-
- /**
- * {@inheritDoc}
- */
- protected array $txTypeMappings = [
- PosInterface::TX_TYPE_PAY_AUTH => 'Sale',
- PosInterface::TX_TYPE_PAY_PRE_AUTH => 'Auth',
- PosInterface::TX_TYPE_PAY_POST_AUTH => 'Capture',
- PosInterface::TX_TYPE_CANCEL => 'Cancel',
- PosInterface::TX_TYPE_REFUND => 'Refund',
- PosInterface::TX_TYPE_REFUND_PARTIAL => 'Refund',
- PosInterface::TX_TYPE_HISTORY => 'TxnHistory',
- PosInterface::TX_TYPE_STATUS => 'OrderInquiry',
- ];
-
- /**
- * {@inheritdoc}
- */
- protected array $cardTypeMapping = [
- CreditCardInterface::CARD_TYPE_VISA => '100',
- CreditCardInterface::CARD_TYPE_MASTERCARD => '200',
- CreditCardInterface::CARD_TYPE_TROY => '300',
- CreditCardInterface::CARD_TYPE_AMEX => '400',
- ];
-
- /**
- * {@inheritdoc}
- */
- protected array $langMappings = [
- PosInterface::LANG_TR => 'tr-TR',
- PosInterface::LANG_EN => 'en-US',
- ];
-
/**
* {@inheritDoc}
*
@@ -101,9 +66,9 @@ public function create3DEnrollmentCheckRequestData(AbstractPosAccount $posAccoun
'HostMerchantId' => $posAccount->getClientId(),
'MerchantPassword' => $posAccount->getPassword(),
'HostTerminalId' => $posAccount->getTerminalId(),
- 'TransactionType' => $this->mapTxType($txType),
- 'AmountCode' => $this->mapCurrency($order['currency']),
- 'Amount' => $this->formatAmount($order['amount']),
+ 'TransactionType' => $this->valueMapper->mapTxType($txType),
+ 'AmountCode' => (string) $this->valueMapper->mapCurrency($order['currency']),
+ 'Amount' => (string) $this->valueFormatter->formatAmount($order['amount']),
'OrderID' => (string) $order['id'],
'IsSecure' => 'true', // Işlemin 3D yapılıp yapılmayacağına dair flag, alabileceği değerler: 'true', 'false'
/**
@@ -133,17 +98,17 @@ public function create3DEnrollmentCheckRequestData(AbstractPosAccount $posAccoun
if ($creditCard instanceof CreditCardInterface) {
$requestData += [
- 'BrandNumber' => $this->cardTypeMapping[$creditCard->getType()],
+ 'BrandNumber' => $this->valueMapper->mapCardType($creditCard->getType()),
'CVV' => $creditCard->getCvv(),
'PAN' => $creditCard->getNumber(),
- 'ExpireMonth' => $creditCard->getExpireMonth(),
- 'ExpireYear' => $creditCard->getExpireYear(),
+ 'ExpireMonth' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'ExpireMonth'),
+ 'ExpireYear' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'ExpireYear'),
'CardHoldersName' => (string) $creditCard->getHolderName(),
];
}
if ($order['installment']) {
- $requestData['InstallmentCount'] = $this->mapInstallment($order['installment']);
+ $requestData['InstallmentCount'] = (string) $this->valueFormatter->formatInstallment($order['installment']);
}
$requestData['HashedData'] = $this->crypt->create3DHash($posAccount, $requestData);
@@ -163,14 +128,14 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount
$order = $this->preparePaymentOrder($order);
return $this->getRequestAccountData($posAccount) + [
- 'TransactionType' => $this->mapTxType($txType),
+ 'TransactionType' => $this->valueMapper->mapTxType($txType),
'OrderId' => (string) $order['id'],
- 'CurrencyAmount' => $this->formatAmount($order['amount']),
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
+ 'CurrencyAmount' => (string) $this->valueFormatter->formatAmount($order['amount']),
+ 'CurrencyCode' => (string) $this->valueMapper->mapCurrency($order['currency']),
'ClientIp' => (string) $order['ip'],
'TransactionDeviceSource' => '0',
'Pan' => $creditCard->getNumber(),
- 'Expiry' => $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_DATE_LONG_FORMAT),
+ 'Expiry' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'Expiry'),
'Cvv' => $creditCard->getCvv(),
];
}
@@ -190,10 +155,10 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $po
$order = $this->preparePostPaymentOrder($order);
return $this->getRequestAccountData($posAccount) + [
- 'TransactionType' => $this->mapTxType(PosInterface::TX_TYPE_PAY_POST_AUTH),
+ 'TransactionType' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_PAY_POST_AUTH),
'ReferenceTransactionId' => (string) $order['id'],
- 'CurrencyAmount' => $this->formatAmount($order['amount']),
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
+ 'CurrencyAmount' => (string) $this->valueFormatter->formatAmount($order['amount']),
+ 'CurrencyCode' => (string) $this->valueMapper->mapCurrency($order['currency']),
'ClientIp' => (string) $order['ip'],
];
}
@@ -219,7 +184,7 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o
$order = $this->prepareCancelOrder($order);
return $this->getRequestAccountData($posAccount) + [
- 'TransactionType' => $this->mapTxType(PosInterface::TX_TYPE_CANCEL),
+ 'TransactionType' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_CANCEL),
'ReferenceTransactionId' => (string) $order['transaction_id'],
'ClientIp' => (string) $order['ip'],
];
@@ -238,10 +203,10 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o
$order = $this->prepareRefundOrder($order);
return $this->getRequestAccountData($posAccount) + [
- 'TransactionType' => $this->mapTxType($refundTxType),
+ 'TransactionType' => $this->valueMapper->mapTxType($refundTxType),
'ReferenceTransactionId' => (string) $order['transaction_id'],
'ClientIp' => (string) $order['ip'],
- 'CurrencyAmount' => $this->formatAmount($order['amount']),
+ 'CurrencyAmount' => (string) $this->valueFormatter->formatAmount($order['amount']),
];
}
@@ -287,39 +252,6 @@ public function create3DFormData(
];
}
- /**
- * Amount Formatter
- *
- * @param float $amount
- *
- * @return string ex: 10.1 => 10.10
- */
- protected function formatAmount(float $amount): string
- {
- return \number_format($amount, 2, '.', '');
- }
-
- /**
- * 0 => '0'
- * 1 => '0'
- * 2 => '2'
- * @inheritDoc
- */
- protected function mapInstallment(int $installment): string
- {
- return $installment > 1 ? (string) $installment : '0';
- }
-
- /**
- * @inheritDoc
- *
- * @return string
- */
- protected function mapCurrency(string $currency): string
- {
- return (string) $this->currencyMappings[$currency] ?? $currency;
- }
-
/**
* @inheritDoc
*/
diff --git a/src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php
index ea7eea68..bd0fd5e3 100644
--- a/src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php
+++ b/src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php
@@ -18,44 +18,6 @@
*/
class PayFlexV4PosRequestDataMapper extends AbstractRequestDataMapper
{
- /** @var string */
- public const CREDIT_CARD_EXP_DATE_LONG_FORMAT = 'Ym';
-
- /** @var string */
- public const CREDIT_CARD_EXP_DATE_FORMAT = 'ym';
-
- /**
- * {@inheritDoc}
- */
- protected array $txTypeMappings = [
- PosInterface::TX_TYPE_PAY_AUTH => 'Sale',
- PosInterface::TX_TYPE_PAY_PRE_AUTH => 'Auth',
- PosInterface::TX_TYPE_PAY_POST_AUTH => 'Capture',
- PosInterface::TX_TYPE_CANCEL => 'Cancel',
- PosInterface::TX_TYPE_REFUND => 'Refund',
- PosInterface::TX_TYPE_REFUND_PARTIAL => 'Refund',
- PosInterface::TX_TYPE_STATUS => 'status',
- ];
-
- /**
- * {@inheritdoc}
- */
- protected array $cardTypeMapping = [
- CreditCardInterface::CARD_TYPE_VISA => '100',
- CreditCardInterface::CARD_TYPE_MASTERCARD => '200',
- CreditCardInterface::CARD_TYPE_TROY => '300',
- CreditCardInterface::CARD_TYPE_AMEX => '400',
- ];
-
- /**
- * {@inheritdoc}
- */
- protected array $recurringOrderFrequencyMapping = [
- 'DAY' => 'Day',
- 'MONTH' => 'Month',
- 'YEAR' => 'Year',
- ];
-
/**
* @param PayFlexAccount $posAccount
* @param array{Eci: string, Cavv: string, VerifyEnrollmentRequestId: string} $responseData
@@ -71,10 +33,10 @@ public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array
$order = $this->preparePaymentOrder($order);
$requestData = $this->getRequestAccountData($posAccount) + [
- 'TransactionType' => $this->mapTxType($txType),
+ 'TransactionType' => $this->valueMapper->mapTxType($txType),
'TransactionId' => (string) $order['id'],
- 'CurrencyAmount' => $this->formatAmount($order['amount']),
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
+ 'CurrencyAmount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'CurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
'ECI' => $responseData['Eci'],
'CAVV' => $responseData['Cavv'],
'MpiTransactionId' => $responseData['VerifyEnrollmentRequestId'],
@@ -84,11 +46,11 @@ public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array
'CardHoldersName' => $creditCard->getHolderName(),
'Cvv' => $creditCard->getCvv(),
'Pan' => $creditCard->getNumber(),
- 'Expiry' => $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_DATE_LONG_FORMAT),
+ 'Expiry' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'Expiry'),
];
if ($order['installment']) {
- $requestData['NumberOfInstallments'] = $this->mapInstallment($order['installment']);
+ $requestData['NumberOfInstallments'] = $this->valueFormatter->formatInstallment($order['installment']);
}
return $requestData;
@@ -109,18 +71,18 @@ public function create3DEnrollmentCheckRequestData(AbstractPosAccount $posAccoun
'MerchantId' => $posAccount->getClientId(),
'MerchantPassword' => $posAccount->getPassword(),
'MerchantType' => $posAccount->getMerchantType(),
- 'PurchaseAmount' => $this->formatAmount($order['amount']),
+ 'PurchaseAmount' => $this->valueFormatter->formatAmount($order['amount']),
'VerifyEnrollmentRequestId' => $this->crypt->generateRandomString(),
- 'Currency' => $this->mapCurrency($order['currency']),
+ 'Currency' => $this->valueMapper->mapCurrency($order['currency']),
'SuccessUrl' => $order['success_url'],
'FailureUrl' => $order['fail_url'],
'Pan' => $creditCard->getNumber(),
- 'ExpiryDate' => $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT),
- 'BrandName' => $this->cardTypeMapping[$creditCard->getType()],
+ 'ExpiryDate' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'ExpiryDate'),
+ 'BrandName' => $this->valueMapper->mapCardType($creditCard->getType()),
'IsRecurring' => 'false',
];
if ($order['installment']) {
- $requestData['InstallmentCount'] = $this->mapInstallment($order['installment']);
+ $requestData['InstallmentCount'] = $this->valueFormatter->formatInstallment($order['installment']);
}
if ($posAccount->isSubBranch()) {
@@ -143,14 +105,14 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount
$order = $this->preparePaymentOrder($order);
return $this->getRequestAccountData($posAccount) + [
- 'TransactionType' => $this->mapTxType($txType),
+ 'TransactionType' => $this->valueMapper->mapTxType($txType),
'OrderId' => (string) $order['id'],
- 'CurrencyAmount' => $this->formatAmount($order['amount']),
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
+ 'CurrencyAmount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'CurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
'ClientIp' => (string) $order['ip'],
'TransactionDeviceSource' => '0',
'Pan' => $creditCard->getNumber(),
- 'Expiry' => $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_DATE_LONG_FORMAT),
+ 'Expiry' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'Expiry'),
'Cvv' => $creditCard->getCvv(),
];
}
@@ -175,10 +137,10 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $po
$order = $this->preparePostPaymentOrder($order);
return $this->getRequestAccountData($posAccount) + [
- 'TransactionType' => $this->mapTxType(PosInterface::TX_TYPE_PAY_POST_AUTH),
+ 'TransactionType' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_PAY_POST_AUTH),
'ReferenceTransactionId' => (string) $order['id'],
- 'CurrencyAmount' => $this->formatAmount($order['amount']),
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
+ 'CurrencyAmount' => (string) $this->valueFormatter->formatAmount($order['amount']),
+ 'CurrencyCode' => (string) $this->valueMapper->mapCurrency($order['currency']),
'ClientIp' => (string) $order['ip'],
];
}
@@ -223,7 +185,7 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o
return [
'MerchantId' => $posAccount->getClientId(),
'Password' => $posAccount->getPassword(),
- 'TransactionType' => $this->mapTxType(PosInterface::TX_TYPE_CANCEL),
+ 'TransactionType' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_CANCEL),
'ReferenceTransactionId' => (string) $order['transaction_id'],
'ClientIp' => (string) $order['ip'],
];
@@ -241,10 +203,10 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o
return [
'MerchantId' => $posAccount->getClientId(),
'Password' => $posAccount->getPassword(),
- 'TransactionType' => $this->mapTxType($refundTxType),
+ 'TransactionType' => $this->valueMapper->mapTxType($refundTxType),
'ReferenceTransactionId' => (string) $order['transaction_id'],
'ClientIp' => (string) $order['ip'],
- 'CurrencyAmount' => $this->formatAmount($order['amount']),
+ 'CurrencyAmount' => (string) $this->valueFormatter->formatAmount($order['amount']),
];
}
@@ -287,29 +249,6 @@ public function create3DFormData(?AbstractPosAccount $posAccount, ?array $order,
];
}
- /**
- * Amount Formatter
- *
- * @param float $amount
- *
- * @return string ex: 10.1 => 10.10
- */
- protected function formatAmount(float $amount): string
- {
- return \number_format($amount, 2, '.', '');
- }
-
- /**
- * 0 => '0'
- * 1 => '0'
- * 2 => '2'
- * @inheritDoc
- */
- protected function mapInstallment(int $installment): string
- {
- return $installment > 1 ? (string) $installment : '0';
- }
-
/**
* @inheritDoc
*/
@@ -369,16 +308,6 @@ protected function prepareCancelOrder(array $order): array
];
}
- /**
- * @inheritDoc
- *
- * @return string
- */
- protected function mapCurrency(string $currency): string
- {
- return (string) $this->currencyMappings[$currency] ?? $currency;
- }
-
/**
* @param PayFlexAccount $posAccount
*
@@ -403,13 +332,13 @@ private function createRecurringData(array $recurringData): array
return [
'IsRecurring' => 'true',
'RecurringFrequency' => (string) $recurringData['frequency'], // Periyodik İşlem Frekansı
- 'RecurringFrequencyType' => $this->mapRecurringFrequency($recurringData['frequencyType']), // Day|Month|Year
+ 'RecurringFrequencyType' => $this->valueMapper->mapRecurringFrequency($recurringData['frequencyType']), // Day|Month|Year
// recurring işlemin toplamda kaç kere tekrar edeceği bilgisini içerir
'RecurringInstallmentCount' => (string) $recurringData['installment'],
/**
* Bu alandaki tarih, kartın son kullanma tarihinden büyükse ACS sunucusu işlemi reddeder.
*/
- 'RecurringEndDate' => $recurringData['endDate']->format('Ymd'),
+ 'RecurringEndDate' => $this->valueFormatter->formatDateTime($recurringData['endDate'], 'RecurringEndDate'),
];
}
}
diff --git a/src/DataMapper/RequestDataMapper/PayForPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/PayForPosRequestDataMapper.php
index 7a03c07d..0451d552 100644
--- a/src/DataMapper/RequestDataMapper/PayForPosRequestDataMapper.php
+++ b/src/DataMapper/RequestDataMapper/PayForPosRequestDataMapper.php
@@ -28,31 +28,6 @@ class PayForPosRequestDataMapper extends AbstractRequestDataMapper
*/
public const MOTO = '0';
- /** @var string */
- public const CREDIT_CARD_EXP_DATE_FORMAT = 'my';
-
- /** {@inheritdoc} */
- protected array $secureTypeMappings = [
- PosInterface::MODEL_3D_SECURE => '3DModel',
- PosInterface::MODEL_3D_PAY => '3DPay',
- PosInterface::MODEL_3D_HOST => '3DHost',
- PosInterface::MODEL_NON_SECURE => 'NonSecure',
- ];
-
- /**
- * {@inheritDoc}
- */
- protected array $txTypeMappings = [
- PosInterface::TX_TYPE_PAY_AUTH => 'Auth',
- PosInterface::TX_TYPE_PAY_PRE_AUTH => 'PreAuth',
- PosInterface::TX_TYPE_PAY_POST_AUTH => 'PostAuth',
- PosInterface::TX_TYPE_CANCEL => 'Void',
- PosInterface::TX_TYPE_REFUND => 'Refund',
- PosInterface::TX_TYPE_REFUND_PARTIAL => 'Refund',
- PosInterface::TX_TYPE_HISTORY => 'TxnHistory',
- PosInterface::TX_TYPE_STATUS => 'OrderInquiry',
- ];
-
/**
* {@inheritDoc}
*
@@ -85,15 +60,15 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount
'MbrId' => self::MBR_ID,
'MOTO' => self::MOTO,
'OrderId' => (string) $order['id'],
- 'SecureType' => $this->secureTypeMappings[PosInterface::MODEL_NON_SECURE],
- 'TxnType' => $this->mapTxType($txType),
- 'PurchAmount' => (string) $order['amount'],
- 'Currency' => $this->mapCurrency($order['currency']),
- 'InstallmentCount' => $this->mapInstallment($order['installment']),
+ 'SecureType' => $this->valueMapper->mapSecureType(PosInterface::MODEL_NON_SECURE),
+ 'TxnType' => $this->valueMapper->mapTxType($txType),
+ 'PurchAmount' => (string) $this->valueFormatter->formatAmount($order['amount']),
+ 'Currency' => (string) $this->valueMapper->mapCurrency($order['currency']),
+ 'InstallmentCount' => (string) $this->valueFormatter->formatInstallment($order['installment']),
'Lang' => $this->getLang($posAccount, $order),
'CardHolderName' => $creditCard->getHolderName(),
'Pan' => $creditCard->getNumber(),
- 'Expiry' => $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT),
+ 'Expiry' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'Expiry'),
'Cvv2' => $creditCard->getCvv(),
];
}
@@ -109,10 +84,10 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $po
return $this->getRequestAccountData($posAccount) + [
'MbrId' => self::MBR_ID,
'OrgOrderId' => (string) $order['id'],
- 'SecureType' => $this->secureTypeMappings[PosInterface::MODEL_NON_SECURE],
- 'TxnType' => $this->mapTxType(PosInterface::TX_TYPE_PAY_POST_AUTH),
- 'PurchAmount' => (string) $order['amount'],
- 'Currency' => $this->mapCurrency($order['currency']),
+ 'SecureType' => $this->valueMapper->mapSecureType(PosInterface::MODEL_NON_SECURE),
+ 'TxnType' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_PAY_POST_AUTH),
+ 'PurchAmount' => (string) $this->valueFormatter->formatAmount($order['amount']),
+ 'Currency' => (string) $this->valueMapper->mapCurrency($order['currency']),
'Lang' => $this->getLang($posAccount, $order),
];
}
@@ -130,7 +105,7 @@ public function createStatusRequestData(AbstractPosAccount $posAccount, array $o
'OrgOrderId' => (string) $order['id'],
'SecureType' => 'Inquiry',
'Lang' => $this->getLang($posAccount, $order),
- 'TxnType' => $this->mapTxType(PosInterface::TX_TYPE_STATUS),
+ 'TxnType' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_STATUS),
];
}
@@ -145,9 +120,9 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o
return $this->getRequestAccountData($posAccount) + [
'MbrId' => self::MBR_ID,
'OrgOrderId' => (string) $order['id'],
- 'SecureType' => $this->secureTypeMappings[PosInterface::MODEL_NON_SECURE],
- 'TxnType' => $this->mapTxType(PosInterface::TX_TYPE_CANCEL),
- 'Currency' => $this->mapCurrency($order['currency']),
+ 'SecureType' => $this->valueMapper->mapSecureType(PosInterface::MODEL_NON_SECURE),
+ 'TxnType' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_CANCEL),
+ 'Currency' => (string) $this->valueMapper->mapCurrency($order['currency']),
'Lang' => $this->getLang($posAccount, $order),
];
}
@@ -162,12 +137,12 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o
return $this->getRequestAccountData($posAccount) + [
'MbrId' => self::MBR_ID,
- 'SecureType' => $this->secureTypeMappings[PosInterface::MODEL_NON_SECURE],
+ 'SecureType' => $this->valueMapper->mapSecureType(PosInterface::MODEL_NON_SECURE),
'Lang' => $this->getLang($posAccount, $order),
'OrgOrderId' => (string) $order['id'],
- 'TxnType' => $this->mapTxType($refundTxType),
- 'PurchAmount' => (string) $order['amount'],
- 'Currency' => $this->mapCurrency($order['currency']),
+ 'TxnType' => $this->valueMapper->mapTxType($refundTxType),
+ 'PurchAmount' => (string) $this->valueFormatter->formatAmount($order['amount']),
+ 'Currency' => (string) $this->valueMapper->mapCurrency($order['currency']),
];
}
@@ -182,7 +157,7 @@ public function createOrderHistoryRequestData(AbstractPosAccount $posAccount, ar
'MbrId' => self::MBR_ID,
'SecureType' => 'Report',
'OrderId' => $order['id'],
- 'TxnType' => $this->mapTxType(PosInterface::TX_TYPE_HISTORY),
+ 'TxnType' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_HISTORY),
'Lang' => $this->getLang($posAccount, $order),
];
@@ -201,8 +176,8 @@ public function createHistoryRequestData(AbstractPosAccount $posAccount, array $
$requestData = [
'MbrId' => self::MBR_ID,
'SecureType' => 'Report',
- 'ReqDate' => $data['transaction_date']->format('Ymd'),
- 'TxnType' => $this->mapTxType(PosInterface::TX_TYPE_HISTORY),
+ 'ReqDate' => $this->valueFormatter->formatDateTime($data['transaction_date'], 'ReqDate'),
+ 'TxnType' => $this->valueMapper->mapTxType(PosInterface::TX_TYPE_HISTORY),
'Lang' => $this->getLang($posAccount, $order),
];
@@ -222,11 +197,11 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
'UserCode' => $posAccount->getUsername(),
'OrderId' => (string) $order['id'],
'Lang' => $this->getLang($posAccount, $order),
- 'SecureType' => $this->secureTypeMappings[$paymentModel],
- 'TxnType' => $this->mapTxType($txType),
- 'PurchAmount' => (string) $order['amount'],
- 'InstallmentCount' => $this->mapInstallment($order['installment']),
- 'Currency' => $this->mapCurrency($order['currency']),
+ 'SecureType' => $this->valueMapper->mapSecureType($paymentModel),
+ 'TxnType' => $this->valueMapper->mapTxType($txType),
+ 'PurchAmount' => (string) $this->valueFormatter->formatAmount($order['amount']),
+ 'InstallmentCount' => (string) $this->valueFormatter->formatInstallment($order['installment']),
+ 'Currency' => (string) $this->valueMapper->mapCurrency($order['currency']),
'OkUrl' => (string) $order['success_url'],
'FailUrl' => (string) $order['fail_url'],
'Rnd' => $this->crypt->generateRandomString(),
@@ -235,7 +210,7 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
if ($creditCard instanceof CreditCardInterface) {
$inputs['CardHolderName'] = $creditCard->getHolderName() ?? '';
$inputs['Pan'] = $creditCard->getNumber();
- $inputs['Expiry'] = $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT);
+ $inputs['Expiry'] = $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'Expiry');
$inputs['Cvv2'] = $creditCard->getCvv();
}
@@ -258,17 +233,6 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
];
}
- /**
- * 0 => '0'
- * 1 => '0'
- * 2 => '2'
- * @inheritDoc
- */
- protected function mapInstallment(int $installment): string
- {
- return $installment > 1 ? (string) $installment : '0';
- }
-
/**
* @inheritDoc
*/
@@ -312,16 +276,6 @@ protected function prepareOrderHistoryOrder(array $order): array
];
}
- /**
- * @inheritDoc
- *
- * @return string
- */
- protected function mapCurrency(string $currency): string
- {
- return (string) $this->currencyMappings[$currency] ?? $currency;
- }
-
/**
* @param AbstractPosAccount $posAccount
*
diff --git a/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php b/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php
index d2d5a711..0d92811e 100644
--- a/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php
+++ b/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php
@@ -6,6 +6,8 @@
namespace Mews\Pos\DataMapper\RequestDataMapper;
use InvalidArgumentException;
+use Mews\Pos\DataMapper\RequestValueFormatter\PosNetRequestValueFormatter;
+use Mews\Pos\DataMapper\RequestValueFormatter\RequestValueFormatterInterface;
use Mews\Pos\Entity\Account\AbstractPosAccount;
use Mews\Pos\Entity\Account\PosNetAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
@@ -18,54 +20,10 @@
*/
class PosNetRequestDataMapper extends AbstractRequestDataMapper
{
- /** @var string */
- public const CREDIT_CARD_EXP_DATE_FORMAT = 'ym';
-
- /**
- * PosNet requires order id with specific length
- * @var int
- */
- private const ORDER_ID_LENGTH = 20;
-
- /**
- * order id total length including prefix;
- * @var int
- */
- private const ORDER_ID_TOTAL_LENGTH = 24;
-
- /** @var string */
- private const ORDER_ID_3D_PREFIX = 'TDSC';
-
- /** @var string */
- private const ORDER_ID_3D_PAY_PREFIX = ''; //?
-
- /** @var string */
- private const ORDER_ID_REGULAR_PREFIX = ''; //?
-
/**
- * {@inheritDoc}
+ * @var PosNetRequestValueFormatter
*/
- protected array $txTypeMappings = [
- PosInterface::TX_TYPE_PAY_AUTH => 'Sale',
- PosInterface::TX_TYPE_PAY_PRE_AUTH => 'Auth',
- PosInterface::TX_TYPE_PAY_POST_AUTH => 'Capt',
- PosInterface::TX_TYPE_CANCEL => 'reverse',
- PosInterface::TX_TYPE_REFUND => 'return',
- PosInterface::TX_TYPE_REFUND_PARTIAL => 'return',
- PosInterface::TX_TYPE_STATUS => 'agreement',
- ];
-
- /**
- * {@inheritDoc}
- */
- protected array $currencyMappings = [
- PosInterface::CURRENCY_TRY => 'TL',
- PosInterface::CURRENCY_USD => 'US',
- PosInterface::CURRENCY_EUR => 'EU',
- PosInterface::CURRENCY_GBP => 'GB',
- PosInterface::CURRENCY_JPY => 'JP',
- PosInterface::CURRENCY_RUB => 'RU',
- ];
+ protected RequestValueFormatterInterface $valueFormatter;
/**
* @param PosNetAccount $posAccount
@@ -78,9 +36,9 @@ public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array
$order = $this->preparePaymentOrder($order);
$mappedOrder = $order;
- $mappedOrder['id'] = self::formatOrderId($order['id']);
- $mappedOrder['amount'] = $this->formatAmount($order['amount']);
- $mappedOrder['currency'] = $this->mapCurrency($order['currency']);
+ $mappedOrder['id'] = $this->valueFormatter->formatOrderId($order['id']);
+ $mappedOrder['amount'] = $this->valueFormatter->formatAmount($order['amount']);
+ $mappedOrder['currency'] = $this->valueMapper->mapCurrency($order['currency']);
$hash = $this->crypt->create3DHash($posAccount, $mappedOrder);
@@ -110,13 +68,13 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount
'mid' => $posAccount->getClientId(),
'tid' => $posAccount->getTerminalId(),
'tranDateRequired' => '1',
- strtolower($this->mapTxType($txType)) => [
- 'orderID' => self::formatOrderId($order['id']),
- 'installment' => $this->mapInstallment($order['installment']),
- 'amount' => $this->formatAmount($order['amount']),
- 'currencyCode' => $this->mapCurrency($order['currency']),
+ strtolower($this->valueMapper->mapTxType($txType)) => [
+ 'orderID' => $this->valueFormatter->formatOrderId($order['id']),
+ 'installment' => $this->valueFormatter->formatInstallment($order['installment']),
+ 'amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'currencyCode' => $this->valueMapper->mapCurrency($order['currency']),
'ccno' => $creditCard->getNumber(),
- 'expDate' => $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT),
+ 'expDate' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'expDate'),
'cvc' => $creditCard->getCvv(),
],
];
@@ -135,11 +93,11 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $po
'mid' => $posAccount->getClientId(),
'tid' => $posAccount->getTerminalId(),
'tranDateRequired' => '1',
- \strtolower($this->mapTxType(PosInterface::TX_TYPE_PAY_POST_AUTH)) => [
+ \strtolower($this->valueMapper->mapTxType(PosInterface::TX_TYPE_PAY_POST_AUTH)) => [
'hostLogKey' => $order['ref_ret_num'],
- 'amount' => $this->formatAmount($order['amount']),
- 'currencyCode' => $this->mapCurrency($order['currency']),
- 'installment' => $this->mapInstallment($order['installment']),
+ 'amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'currencyCode' => $this->valueMapper->mapCurrency($order['currency']),
+ 'installment' => $this->valueFormatter->formatInstallment($order['installment']),
],
];
}
@@ -153,13 +111,13 @@ public function createStatusRequestData(AbstractPosAccount $posAccount, array $o
{
$order = $this->prepareStatusOrder($order);
- $txType = $this->mapTxType(PosInterface::TX_TYPE_STATUS);
+ $txType = $this->valueMapper->mapTxType(PosInterface::TX_TYPE_STATUS);
return [
'mid' => $posAccount->getClientId(),
'tid' => $posAccount->getTerminalId(),
$txType => [
- 'orderID' => self::mapOrderIdToPrefixedOrderId($order['id'], $order['payment_model']),
+ 'orderID' => $this->valueFormatter->formatOrderId($order['id'], PosInterface::TX_TYPE_STATUS, $order['payment_model']),
],
];
}
@@ -173,7 +131,7 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o
{
$order = $this->prepareCancelOrder($order);
- $txType = $this->mapTxType(PosInterface::TX_TYPE_CANCEL);
+ $txType = $this->valueMapper->mapTxType(PosInterface::TX_TYPE_CANCEL);
$requestData = [
'mid' => $posAccount->getClientId(),
'tid' => $posAccount->getTerminalId(),
@@ -191,7 +149,7 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o
if (isset($order['ref_ret_num'])) {
$requestData[$txType]['hostLogKey'] = $order['ref_ret_num'];
} else {
- $requestData[$txType]['orderID'] = self::mapOrderIdToPrefixedOrderId($order['id'], $order['payment_model']);
+ $requestData[$txType]['orderID'] = $this->valueFormatter->formatOrderId($order['id'], PosInterface::TX_TYPE_CANCEL, $order['payment_model']);
}
return $requestData;
@@ -206,21 +164,21 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o
{
$order = $this->prepareRefundOrder($order);
- $txType = $this->mapTxType($refundTxType);
+ $txType = $this->valueMapper->mapTxType($refundTxType);
$requestData = [
'mid' => $posAccount->getClientId(),
'tid' => $posAccount->getTerminalId(),
'tranDateRequired' => '1',
$txType => [
- 'amount' => $this->formatAmount($order['amount']),
- 'currencyCode' => $this->mapCurrency($order['currency']),
+ 'amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'currencyCode' => $this->valueMapper->mapCurrency($order['currency']),
],
];
if (isset($order['ref_ret_num'])) {
$requestData[$txType]['hostLogKey'] = $order['ref_ret_num'];
} else {
- $requestData[$txType]['orderID'] = self::mapOrderIdToPrefixedOrderId($order['id'], $order['payment_model']);
+ $requestData[$txType]['orderID'] = $this->valueFormatter->formatOrderId($order['id'], $refundTxType, $order['payment_model']);
}
return $requestData;
@@ -288,6 +246,9 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
* @param PosNetAccount $posAccount
* @param array $order
* @param string $txType
+ * @param CreditCardInterface $creditCard
+ *
+ * @return array|string>
*
* @throws UnsupportedTransactionTypeException
*/
@@ -295,6 +256,7 @@ public function create3DEnrollmentCheckRequestData(AbstractPosAccount $posAccoun
{
$order = $this->preparePaymentOrder($order);
+ // todo check if we can remove this code
if (null === $creditCard->getHolderName() && isset($order['name'])) {
$creditCard->setHolderName($order['name']);
}
@@ -305,14 +267,14 @@ public function create3DEnrollmentCheckRequestData(AbstractPosAccount $posAccoun
'oosRequestData' => [
'posnetid' => $posAccount->getPosNetId(),
'ccno' => $creditCard->getNumber(),
- 'expDate' => $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT),
+ 'expDate' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'expDate'),
'cvc' => $creditCard->getCvv(),
- 'amount' => $this->formatAmount($order['amount']),
- 'currencyCode' => $this->mapCurrency($order['currency']),
- 'installment' => $this->mapInstallment($order['installment']),
- 'XID' => self::formatOrderId($order['id']),
+ 'amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'currencyCode' => $this->valueMapper->mapCurrency($order['currency']),
+ 'installment' => $this->valueFormatter->formatInstallment($order['installment']),
+ 'XID' => $this->valueFormatter->formatOrderId($order['id']),
'cardHolderName' => $creditCard->getHolderName(),
- 'tranType' => $this->mapTxType($txType),
+ 'tranType' => $this->valueMapper->mapTxType($txType),
],
];
}
@@ -329,9 +291,9 @@ public function create3DResolveMerchantRequestData(AbstractPosAccount $posAccoun
$order = $this->preparePaymentOrder($order);
$mappedOrder = $order;
- $mappedOrder['id'] = self::formatOrderId($order['id']);
- $mappedOrder['amount'] = $this->formatAmount($order['amount']);
- $mappedOrder['currency'] = $this->mapCurrency($order['currency']);
+ $mappedOrder['id'] = $this->valueFormatter->formatOrderId($order['id']);
+ $mappedOrder['amount'] = $this->valueFormatter->formatAmount($order['amount']);
+ $mappedOrder['currency'] = $this->valueMapper->mapCurrency($order['currency']);
$hash = $this->crypt->create3DHash($posAccount, $mappedOrder);
@@ -347,86 +309,6 @@ public function create3DResolveMerchantRequestData(AbstractPosAccount $posAccoun
];
}
- /**
- * Get PrefixedOrderId
- * To check the status of an order or cancel/refund order Yapikredi
- * - requires the order length to be 24
- * - and order id prefix which is "TDSC" for 3D payments
- *
- * @param string $orderId
- * @param string $accountModel
- *
- * @return string
- */
- public static function mapOrderIdToPrefixedOrderId(string $orderId, string $accountModel): string
- {
- $prefix = self::ORDER_ID_REGULAR_PREFIX;
- if (PosInterface::MODEL_3D_SECURE === $accountModel) {
- $prefix = self::ORDER_ID_3D_PREFIX;
- } elseif (PosInterface::MODEL_3D_PAY === $accountModel) {
- $prefix = self::ORDER_ID_3D_PAY_PREFIX;
- }
-
- return $prefix.self::formatOrderId($orderId, self::ORDER_ID_TOTAL_LENGTH - strlen($prefix));
- }
-
-
- /**
- * formats order id by adding 0 pad to the left
- *
- * @param string $orderId
- * @param int|null $padLength
- *
- * @return string
- */
- public static function formatOrderId(string $orderId, int $padLength = null): string
- {
- if (null === $padLength) {
- $padLength = self::ORDER_ID_LENGTH;
- }
-
- if (\strlen($orderId) > $padLength) {
- throw new InvalidArgumentException(\sprintf(
- // Banka tarafindan belirlenen kisitlama
- "Saglanan siparis ID'nin (%s) uzunlugu %d karakter. Siparis ID %d karakterden uzun olamaz!",
- $orderId,
- \strlen($orderId),
- $padLength
- ));
- }
-
- return \str_pad($orderId, $padLength, '0', STR_PAD_LEFT);
- }
-
- /**
- * Get amount
- * formats 10.01 to 1001
- *
- * @param float $amount
- *
- * @return int
- */
- protected function formatAmount(float $amount): int
- {
- return (int) (\round($amount, 2) * 100);
- }
-
- /**
- * 0 => '00'
- * 1 => '00'
- * 2 => '02'
- * @inheritDoc
- */
- protected function mapInstallment(int $installment): string
- {
- if ($installment > 1) {
- return \str_pad((string) $installment, 2, '0', STR_PAD_LEFT);
- }
-
- return '00';
- }
-
-
/**
* @inheritDoc
*/
diff --git a/src/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapper.php
index a06d65b7..728410f4 100644
--- a/src/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapper.php
+++ b/src/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapper.php
@@ -5,7 +5,8 @@
namespace Mews\Pos\DataMapper\RequestDataMapper;
-use InvalidArgumentException;
+use Mews\Pos\DataMapper\RequestValueFormatter\PosNetV1PosRequestValueFormatter;
+use Mews\Pos\DataMapper\RequestValueFormatter\RequestValueFormatterInterface;
use Mews\Pos\Entity\Account\AbstractPosAccount;
use Mews\Pos\Entity\Account\PosNetAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
@@ -23,54 +24,10 @@ class PosNetV1PosRequestDataMapper extends AbstractRequestDataMapper
/** @var string */
public const API_VERSION = 'V100';
- /** @var string */
- public const CREDIT_CARD_EXP_DATE_FORMAT = 'ym';
-
- /**
- * PosNet requires order id with specific length
- * @var int
- */
- private const ORDER_ID_LENGTH = 20;
-
- /**
- * order id total length including prefix;
- * @var int
- */
- private const ORDER_ID_TOTAL_LENGTH = 24;
-
- /** @var string */
- private const ORDER_ID_3D_PREFIX = 'TDS_';
-
- /** @var string */
- private const ORDER_ID_3D_PAY_PREFIX = ''; //?
-
- /** @var string */
- private const ORDER_ID_REGULAR_PREFIX = ''; //?
-
/**
- * {@inheritDoc}
+ * @var PosNetV1PosRequestValueFormatter
*/
- protected array $txTypeMappings = [
- PosInterface::TX_TYPE_PAY_AUTH => 'Sale',
- PosInterface::TX_TYPE_PAY_PRE_AUTH => 'Auth',
- PosInterface::TX_TYPE_PAY_POST_AUTH => 'Capture',
- PosInterface::TX_TYPE_CANCEL => 'Reverse',
- PosInterface::TX_TYPE_REFUND => 'Return',
- PosInterface::TX_TYPE_REFUND_PARTIAL => 'Return',
- PosInterface::TX_TYPE_STATUS => 'TransactionInquiry',
- ];
-
- /**
- * {@inheritDoc}
- */
- protected array $currencyMappings = [
- PosInterface::CURRENCY_TRY => 'TL',
- PosInterface::CURRENCY_USD => 'US',
- PosInterface::CURRENCY_EUR => 'EU',
- PosInterface::CURRENCY_GBP => 'GB',
- PosInterface::CURRENCY_JPY => 'JP',
- PosInterface::CURRENCY_RUB => 'RU',
- ];
+ protected RequestValueFormatterInterface $valueFormatter;
/**
* @param PosNetAccount $posAccount
@@ -98,11 +55,11 @@ public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array
'MD' => $responseData['MD'],
],
'MACParams' => 'MerchantNo:TerminalNo:SecureTransactionId:CavvData:Eci:MdStatus',
- 'Amount' => $this->formatAmount($order['amount']),
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
+ 'Amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'CurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
'PointAmount' => 0,
- 'OrderId' => self::formatOrderId($order['id']),
- 'InstallmentCount' => $this->mapInstallment($order['installment']),
+ 'OrderId' => $this->valueFormatter->formatOrderId($order['id']),
+ 'InstallmentCount' => $this->valueFormatter->formatInstallment($order['installment']),
'InstallmentType' => 'N',
];
@@ -137,7 +94,7 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount
'AdditionalInfoData' => null,
'CardInformationData' => [
'CardNo' => $creditCard->getNumber(),
- 'ExpireDate' => $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT),
+ 'ExpireDate' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'ExpireDate'),
'Cvc2' => $creditCard->getCvv(),
'CardHolderName' => $creditCard->getHolderName(),
],
@@ -146,10 +103,10 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount
'IsTDSecureMerchant' => null,
'PaymentInstrumentType' => 'CARD',
'ThreeDSecureData' => null,
- 'Amount' => $this->formatAmount($order['amount']),
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
- 'OrderId' => self::formatOrderId($order['id']),
- 'InstallmentCount' => $this->mapInstallment($order['installment']),
+ 'Amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'CurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
+ 'OrderId' => $this->valueFormatter->formatOrderId($order['id']),
+ 'InstallmentCount' => $this->valueFormatter->formatInstallment($order['installment']),
'InstallmentType' => 'N',
'KOICode' => null,
'MerchantMessageData' => null,
@@ -188,10 +145,10 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $po
'DealerData' => null,
'IsEncrypted' => null,
'PaymentFacilitatorData' => null,
- 'Amount' => $this->formatAmount($order['amount']),
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
+ 'Amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'CurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
'ReferenceCode' => $order['ref_ret_num'],
- 'InstallmentCount' => $this->mapInstallment($order['installment']),
+ 'InstallmentCount' => $this->valueFormatter->formatInstallment($order['installment']),
'InstallmentType' => 'N',
];
@@ -227,7 +184,7 @@ public function createStatusRequestData(AbstractPosAccount $posAccount, array $o
'DealerData' => null,
'IsEncrypted' => 'N',
'PaymentFacilitatorData' => null,
- 'OrderId' => self::mapOrderIdToPrefixedOrderId($order['id'], $order['payment_model']),
+ 'OrderId' => $this->valueFormatter->formatOrderId($order['id'], PosInterface::TX_TYPE_STATUS, $order['payment_model']),
];
if (null === $posAccount->getStoreKey()) {
throw new \LogicException('Account storeKey eksik!');
@@ -259,13 +216,13 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o
'PaymentFacilitatorData' => null,
'ReferenceCode' => null,
'OrderId' => null,
- 'TransactionType' => $this->mapTxType($order['transaction_type']),
+ 'TransactionType' => $this->valueMapper->mapTxType($order['transaction_type']),
];
if (isset($order['ref_ret_num'])) {
$requestData['ReferenceCode'] = $order['ref_ret_num'];
} else {
- $requestData['OrderId'] = self::mapOrderIdToPrefixedOrderId($order['id'], $order['payment_model']);
+ $requestData['OrderId'] = $this->valueFormatter->formatOrderId($order['id'], PosInterface::TX_TYPE_CANCEL, $order['payment_model']);
}
if (null === $posAccount->getStoreKey()) {
@@ -298,18 +255,18 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o
'PaymentFacilitatorData' => null,
'ReferenceCode' => null,
'OrderId' => null,
- 'TransactionType' => $this->mapTxType($order['transaction_type']),
+ 'TransactionType' => $this->valueMapper->mapTxType($order['transaction_type']),
];
if (isset($order['ref_ret_num'])) {
$requestData['ReferenceCode'] = $order['ref_ret_num'];
} else {
- $requestData['OrderId'] = self::mapOrderIdToPrefixedOrderId($order['id'], $order['payment_model']);
+ $requestData['OrderId'] = $this->valueFormatter->formatOrderId($order['id'], $refundTxType, $order['payment_model']);
}
if ($order['payment_model'] === PosInterface::MODEL_NON_SECURE) {
- $requestData['Amount'] = $this->formatAmount($order['amount']);
- $requestData['CurrencyCode'] = $this->mapCurrency($order['currency']);
+ $requestData['Amount'] = $this->valueFormatter->formatAmount($order['amount']);
+ $requestData['CurrencyCode'] = $this->valueMapper->mapCurrency($order['currency']);
}
if (null === $posAccount->getStoreKey()) {
@@ -353,12 +310,12 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
'MerchantNo' => $posAccount->getClientId(),
'TerminalNo' => $posAccount->getTerminalId(),
'PosnetID' => $posAccount->getPosNetId(),
- 'TransactionType' => $this->mapTxType($txType),
- 'OrderId' => self::formatOrderId($order['id']),
- 'Amount' => (string) $this->formatAmount($order['amount']),
- 'CurrencyCode' => (string) $this->mapCurrency($order['currency']),
+ 'TransactionType' => $this->valueMapper->mapTxType($txType),
+ 'OrderId' => $this->valueFormatter->formatOrderId($order['id']),
+ 'Amount' => (string) $this->valueFormatter->formatAmount($order['amount']),
+ 'CurrencyCode' => (string) $this->valueMapper->mapCurrency($order['currency']),
'MerchantReturnURL' => (string) $order['success_url'],
- 'InstallmentCount' => $this->mapInstallment($order['installment']),
+ 'InstallmentCount' => $this->valueFormatter->formatInstallment($order['installment']),
'Language' => $this->getLang($posAccount, $order),
'TxnState' => 'INITIAL',
'OpenNewWindow' => '0',
@@ -369,7 +326,7 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
'CardNo' => $creditCard->getNumber(),
// Kod calisiyor ancak burda bir tutarsizlik var: ExpireDate vs ExpiredDate
// MacParams icinde ExpireDate olarak geciyor, gonderidigimizde ise ExpiredDate olarak istiyor.
- 'ExpiredDate' => $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT),
+ 'ExpiredDate' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'ExpiredDate'),
'Cvv' => $creditCard->getCvv(),
'CardHolderName' => (string) $creditCard->getHolderName(),
@@ -408,86 +365,6 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
];
}
- /**
- * Get PrefixedOrderId
- * To check the status of an order or cancel/refund order PosNet
- * - requires the order length to be 24
- * - and order id prefix which is "TDS_" for 3D payments
- *
- * @param string $orderId
- * @param string $accountModel
- *
- * @return string
- */
- public static function mapOrderIdToPrefixedOrderId(string $orderId, string $accountModel): string
- {
- $prefix = self::ORDER_ID_REGULAR_PREFIX;
- if (PosInterface::MODEL_3D_SECURE === $accountModel) {
- $prefix = self::ORDER_ID_3D_PREFIX;
- } elseif (PosInterface::MODEL_3D_PAY === $accountModel) {
- $prefix = self::ORDER_ID_3D_PAY_PREFIX;
- }
-
- return $prefix.self::formatOrderId($orderId, self::ORDER_ID_TOTAL_LENGTH - strlen($prefix));
- }
-
-
- /**
- * formats order id by adding 0 pad to the left
- *
- * @param string $orderId
- * @param int|null $padLength
- *
- * @return string
- */
- public static function formatOrderId(string $orderId, int $padLength = null): string
- {
- if (null === $padLength) {
- $padLength = self::ORDER_ID_LENGTH;
- }
-
- if (\strlen($orderId) > $padLength) {
- throw new InvalidArgumentException(\sprintf(
- // Banka tarafindan belirlenen kisitlama
- "Saglanan siparis ID'nin (%s) uzunlugu %d karakter. Siparis ID %d karakterden uzun olamaz!",
- $orderId,
- \strlen($orderId),
- $padLength
- ));
- }
-
- return \str_pad($orderId, $padLength, '0', STR_PAD_LEFT);
- }
-
- /**
- * Get amount
- * formats 10.01 to 1001
- *
- * @param float $amount
- *
- * @return int
- */
- protected function formatAmount(float $amount): int
- {
- return (int) (\round($amount, 2) * 100);
- }
-
- /**
- * 0 => '0'
- * 1 => '0'
- * 2 => '2'
- * @inheritDoc
- */
- protected function mapInstallment(int $installment): string
- {
- if ($installment > 1) {
- return (string) $installment;
- }
-
- return '0';
- }
-
-
/**
* @inheritDoc
*/
diff --git a/src/DataMapper/RequestDataMapper/RequestDataMapperInterface.php b/src/DataMapper/RequestDataMapper/RequestDataMapperInterface.php
index 9fe2a730..a92fb574 100644
--- a/src/DataMapper/RequestDataMapper/RequestDataMapperInterface.php
+++ b/src/DataMapper/RequestDataMapper/RequestDataMapperInterface.php
@@ -13,37 +13,6 @@
interface RequestDataMapperInterface
{
- /**
- * @return array
- */
- public function getTxTypeMappings(): array;
-
- /**
- * @phpstan-param PosInterface::TX_TYPE_* $txType
- *
- * @param string $txType
- *
- * @return string
- *
- * @throws UnsupportedTransactionTypeException
- */
- public function mapTxType(string $txType): string;
-
- /**
- * @return non-empty-array
- */
- public function getCurrencyMappings(): array;
-
- /**
- * @return non-empty-array
- */
- public function getSecureTypeMappings(): array;
-
- /**
- * @return array
- */
- public function getCardTypeMapping(): array;
-
/**
* @return bool
*/
diff --git a/src/DataMapper/RequestDataMapper/ToslaPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/ToslaPosRequestDataMapper.php
index 3fcddaae..f05902a9 100644
--- a/src/DataMapper/RequestDataMapper/ToslaPosRequestDataMapper.php
+++ b/src/DataMapper/RequestDataMapper/ToslaPosRequestDataMapper.php
@@ -16,26 +16,11 @@
*/
class ToslaPosRequestDataMapper extends AbstractRequestDataMapper
{
- /** @var string */
- public const CREDIT_CARD_EXP_DATE_FORMAT = 'm/y';
-
- /**
- * {@inheritDoc}
- */
- protected array $txTypeMappings = [
- PosInterface::TX_TYPE_PAY_AUTH => '1',
- PosInterface::TX_TYPE_PAY_PRE_AUTH => '2',
- PosInterface::TX_TYPE_PAY_POST_AUTH => '3',
- PosInterface::TX_TYPE_CANCEL => '4',
- PosInterface::TX_TYPE_REFUND => '5',
- PosInterface::TX_TYPE_REFUND_PARTIAL => '5',
- ];
-
/**
* @param ToslaPosAccount $posAccount
* @param array $order
*
- * @return array
+ * @return array
*/
public function create3DEnrollmentCheckRequestData(AbstractPosAccount $posAccount, array $order): array
{
@@ -44,11 +29,11 @@ public function create3DEnrollmentCheckRequestData(AbstractPosAccount $posAccoun
$requestData = [
'callbackUrl' => (string) $order['success_url'],
'orderId' => (string) $order['id'],
- 'amount' => $this->formatAmount($order['amount']),
- 'currency' => (int) $this->mapCurrency($order['currency']),
- 'installmentCount' => (int) $this->mapInstallment($order['installment']),
+ 'amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'currency' => $this->valueMapper->mapCurrency($order['currency']),
+ 'installmentCount' => $this->valueFormatter->formatInstallment($order['installment']),
'rnd' => $this->crypt->generateRandomString(),
- 'timeSpan' => $order['time_span'],
+ 'timeSpan' => $this->valueFormatter->formatDateTime($order['time_span'], 'timeSpan'),
];
$requestData['hash'] = $this->crypt->create3DHash($posAccount, $requestData);
@@ -73,14 +58,14 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount
$requestData = [
'orderId' => (string) $order['id'],
- 'amount' => $this->formatAmount($order['amount']),
- 'currency' => (int) $this->mapCurrency($order['currency']),
- 'installmentCount' => (int) $this->mapInstallment($order['installment']),
+ 'amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'currency' => $this->valueMapper->mapCurrency($order['currency']),
+ 'installmentCount' => $this->valueFormatter->formatInstallment($order['installment']),
'rnd' => $this->crypt->generateRandomString(),
- 'timeSpan' => $order['time_span'],
+ 'timeSpan' => $this->valueFormatter->formatDateTime($order['time_span'], 'timeSpan'),
'cardHolderName' => $creditCard->getHolderName(),
'cardNo' => $creditCard->getNumber(),
- 'expireDate' => $creditCard->getExpirationDate('my'),
+ 'expireDate' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'expireDate'),
'cvv' => $creditCard->getCvv(),
];
@@ -98,9 +83,9 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $po
$requestData = [
'orderId' => (string) $order['id'],
- 'amount' => $this->formatAmount($order['amount']),
+ 'amount' => $this->valueFormatter->formatAmount($order['amount']),
'rnd' => $this->crypt->generateRandomString(),
- 'timeSpan' => $order['time_span'],
+ 'timeSpan' => $this->valueFormatter->formatDateTime($order['time_span'], 'timeSpan'),
];
$requestData['hash'] = $this->crypt->createHash($posAccount, $requestData);
@@ -118,7 +103,7 @@ public function createStatusRequestData(AbstractPosAccount $posAccount, array $o
$requestData = [
'orderId' => (string) $order['id'],
'rnd' => $this->crypt->generateRandomString(),
- 'timeSpan' => $order['time_span'],
+ 'timeSpan' => $this->valueFormatter->formatDateTime($order['time_span'], 'timeSpan'),
];
$requestData['hash'] = $this->crypt->createHash($posAccount, $requestData);
@@ -136,7 +121,7 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o
$requestData = [
'orderId' => (string) $order['id'],
'rnd' => $this->crypt->generateRandomString(),
- 'timeSpan' => $order['time_span'],
+ 'timeSpan' => $this->valueFormatter->formatDateTime($order['time_span'], 'timeSpan'),
];
$requestData['hash'] = $this->crypt->createHash($posAccount, $requestData);
@@ -154,8 +139,8 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o
$requestData = [
'orderId' => (string) $order['id'],
'rnd' => $this->crypt->generateRandomString(),
- 'amount' => $this->formatAmount($order['amount']),
- 'timeSpan' => $order['time_span'],
+ 'amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'timeSpan' => $this->valueFormatter->formatDateTime($order['time_span'], 'timeSpan'),
];
$requestData['hash'] = $this->crypt->createHash($posAccount, $requestData);
@@ -171,11 +156,11 @@ public function createOrderHistoryRequestData(AbstractPosAccount $posAccount, ar
$order = $this->prepareOrderHistoryOrder($order);
$requestData = [
'orderId' => (string) $order['id'],
- 'transactionDate' => $order['transaction_date']->format('Ymd'),
+ 'transactionDate' => $this->valueFormatter->formatDateTime($order['transaction_date'], 'transactionDate'),
'page' => $order['page'],
'pageSize' => $order['page_size'],
'rnd' => $this->crypt->generateRandomString(),
- 'timeSpan' => $order['time_span'],
+ 'timeSpan' => $this->valueFormatter->formatDateTime($order['time_span'], 'timeSpan'),
];
$requestData['hash'] = $this->crypt->createHash($posAccount, $requestData);
@@ -211,7 +196,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->getExpirationDate(self::CREDIT_CARD_EXP_DATE_FORMAT);
+ $inputs['ExpireDate'] = $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'ExpireDate');
$inputs['Cvv'] = $creditCard->getCvv();
}
@@ -222,30 +207,6 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
];
}
- /**
- * 0 => '0'
- * 1 => '0'
- * 2 => '2'
- * @inheritDoc
- */
- protected function mapInstallment(int $installment): string
- {
- return $installment > 1 ? (string) $installment : '0';
- }
-
- /**
- * Get amount
- * formats 10.01 to 1001
- *
- * @param float $amount
- *
- * @return int
- */
- protected function formatAmount(float $amount): int
- {
- return (int) (\round($amount, 2) * 100);
- }
-
/**
* @inheritDoc
*/
@@ -332,13 +293,10 @@ private function getRequestAccountData(AbstractPosAccount $posAccount): array
}
/**
- * @return string ex: 20231209201121
+ * @return \DateTimeImmutable
*/
- private function newTimeSpan(): string
+ private function newTimeSpan(): \DateTimeImmutable
{
- $turkeyTimeZone = new \DateTimeZone('Europe/Istanbul');
- $turkeyTime = new \DateTime('now', $turkeyTimeZone);
-
- return $turkeyTime->format('YmdHis');
+ return new \DateTimeImmutable('now', new \DateTimeZone('Europe/Istanbul'));
}
}
diff --git a/src/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapper.php
index 1355302e..fbdbee32 100644
--- a/src/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapper.php
+++ b/src/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapper.php
@@ -20,34 +20,6 @@ class VakifKatilimPosRequestDataMapper extends AbstractRequestDataMapper
/** @var string */
public const API_VERSION = '1.0.0';
- /** @var string */
- public const CREDIT_CARD_EXP_YEAR_FORMAT = 'y';
-
- /** @var string */
- public const CREDIT_CARD_EXP_MONTH_FORMAT = 'm';
-
- /**
- * {@inheritdoc}
- */
- protected array $secureTypeMappings = [
- PosInterface::MODEL_3D_SECURE => '3',
- PosInterface::MODEL_NON_SECURE => '5',
- ];
-
- /**
- * Currency mapping
- *
- * {@inheritdoc}
- */
- protected array $currencyMappings = [
- PosInterface::CURRENCY_TRY => '0949',
- PosInterface::CURRENCY_USD => '0840',
- PosInterface::CURRENCY_EUR => '0978',
- PosInterface::CURRENCY_GBP => '0826',
- PosInterface::CURRENCY_JPY => '0392',
- PosInterface::CURRENCY_RUB => '0810',
- ];
-
/** @var KuveytPosCrypt */
protected CryptInterface $crypt;
@@ -74,10 +46,10 @@ public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array
],
],
],
- 'InstallmentCount' => $this->mapInstallment($order['installment']),
- 'Amount' => $this->formatAmount($order['amount']),
+ 'InstallmentCount' => $this->valueFormatter->formatInstallment($order['installment']),
+ 'Amount' => $this->valueFormatter->formatAmount($order['amount']),
'MerchantOrderId' => $responseData['MerchantOrderId'],
- 'TransactionSecurity' => $this->secureTypeMappings[PosInterface::MODEL_3D_SECURE],
+ 'TransactionSecurity' => $this->valueMapper->mapSecureType(PosInterface::MODEL_3D_SECURE),
];
$result['HashData'] = $this->crypt->create3DHash($posAccount, $result);
@@ -104,11 +76,11 @@ public function create3DEnrollmentCheckRequestData(KuveytPosAccount $kuveytPosAc
$inputs = $this->getRequestAccountData($kuveytPosAccount) + [
'APIVersion' => self::API_VERSION,
'HashPassword' => $this->crypt->hashString($kuveytPosAccount->getStoreKey() ?? ''),
- 'TransactionSecurity' => $this->secureTypeMappings[$paymentModel],
- 'InstallmentCount' => $this->mapInstallment($order['installment']),
- 'Amount' => $this->formatAmount($order['amount']),
- 'DisplayAmount' => $this->formatAmount($order['amount']),
- 'FECCurrencyCode' => $this->mapCurrency($order['currency']),
+ 'TransactionSecurity' => $this->valueMapper->mapSecureType($paymentModel),
+ 'InstallmentCount' => $this->valueFormatter->formatInstallment($order['installment']),
+ 'Amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'DisplayAmount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'FECCurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
'MerchantOrderId' => $order['id'],
'OkUrl' => $order['success_url'],
'FailUrl' => $order['fail_url'],
@@ -117,8 +89,8 @@ public function create3DEnrollmentCheckRequestData(KuveytPosAccount $kuveytPosAc
if ($creditCard instanceof CreditCardInterface) {
$inputs['CardHolderName'] = $creditCard->getHolderName();
$inputs['CardNumber'] = $creditCard->getNumber();
- $inputs['CardExpireDateYear'] = $creditCard->getExpireYear(self::CREDIT_CARD_EXP_YEAR_FORMAT);
- $inputs['CardExpireDateMonth'] = $creditCard->getExpireMonth(self::CREDIT_CARD_EXP_MONTH_FORMAT);
+ $inputs['CardExpireDateYear'] = $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'CardExpireDateYear');
+ $inputs['CardExpireDateMonth'] = $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'CardExpireDateMonth');
$inputs['CardCVV2'] = $creditCard->getCvv();
}
@@ -161,14 +133,14 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount
'APIVersion' => self::API_VERSION,
'HashPassword' => $this->crypt->hashString($posAccount->getStoreKey() ?? ''),
'MerchantOrderId' => $order['id'],
- 'InstallmentCount' => $this->mapInstallment($order['installment']),
- 'Amount' => $this->formatAmount($order['amount']),
- 'FECCurrencyCode' => $this->mapCurrency($order['currency']),
- 'CurrencyCode' => $this->mapCurrency($order['currency']),
- 'TransactionSecurity' => $this->secureTypeMappings[PosInterface::MODEL_NON_SECURE],
+ 'InstallmentCount' => $this->valueFormatter->formatInstallment($order['installment']),
+ 'Amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'FECCurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
+ 'CurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
+ 'TransactionSecurity' => $this->valueMapper->mapSecureType(PosInterface::MODEL_NON_SECURE),
'CardNumber' => $creditCard->getNumber(),
- 'CardExpireDateYear' => $creditCard->getExpireYear(self::CREDIT_CARD_EXP_YEAR_FORMAT),
- 'CardExpireDateMonth' => $creditCard->getExpireMonth(self::CREDIT_CARD_EXP_MONTH_FORMAT),
+ 'CardExpireDateYear' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'CardExpireDateYear'),
+ 'CardExpireDateMonth' => $this->valueFormatter->formatCardExpDate($creditCard->getExpirationDate(), 'CardExpireDateMonth'),
'CardCVV2' => $creditCard->getCvv(),
'CardHolderName' => $creditCard->getHolderName(),
];
@@ -211,7 +183,7 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o
];
if (!isset($order['transaction_type']) || PosInterface::TX_TYPE_PAY_PRE_AUTH !== $order['transaction_type']) {
- $result['Amount'] = $this->formatAmount($order['amount']);
+ $result['Amount'] = $this->valueFormatter->formatAmount($order['amount']);
}
$result['HashData'] = $this->crypt->createHash($posAccount, $result);
@@ -257,8 +229,8 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
'HashPassword' => $this->crypt->hashString($posAccount->getStoreKey() ?? ''),
'MerchantId' => $posAccount->getClientId(),
'MerchantOrderId' => (string) $order['id'],
- 'Amount' => $this->formatAmount($order['amount']),
- 'FECCurrencyCode' => $this->mapCurrency($order['currency']),
+ 'Amount' => $this->valueFormatter->formatAmount($order['amount']),
+ 'FECCurrencyCode' => $this->valueMapper->mapCurrency($order['currency']),
'OkUrl' => $order['success_url'],
'FailUrl' => $order['fail_url'],
'PaymentType' => '1',
@@ -285,8 +257,8 @@ public function createHistoryRequestData(AbstractPosAccount $posAccount, array $
/**
* Tarih aralığı maksimum 90 gün olabilir.
*/
- 'StartDate' => $data['start_date']->format('Y-m-d'),
- 'EndDate' => $data['end_date']->format('Y-m-d'),
+ 'StartDate' => $this->valueFormatter->formatDateTime($data['start_date'], 'StartDate', PosInterface::TX_TYPE_HISTORY),
+ 'EndDate' => $this->valueFormatter->formatDateTime($data['end_date'], 'EndDate', PosInterface::TX_TYPE_HISTORY),
'LowerLimit' => ($data['page'] - 1) * $data['page_size'],
'UpperLimit' => $data['page_size'],
'ProvNumber' => null,
@@ -310,8 +282,8 @@ public function createOrderHistoryRequestData(AbstractPosAccount $posAccount, ar
$order = $this->prepareOrderHistoryOrder($order);
$result = $this->getRequestAccountData($posAccount) + [
- 'StartDate' => $order['start_date']->format('Y-m-d'),
- 'EndDate' => $order['end_date']->format('Y-m-d'),
+ 'StartDate' => $this->valueFormatter->formatDateTime($order['start_date'], 'StartDate', PosInterface::TX_TYPE_ORDER_HISTORY),
+ 'EndDate' => $this->valueFormatter->formatDateTime($order['end_date'], 'EndDate', PosInterface::TX_TYPE_ORDER_HISTORY),
'LowerLimit' => 0,
'UpperLimit' => 100,
'ProvNumber' => $order['auth_code'],
@@ -325,30 +297,6 @@ public function createOrderHistoryRequestData(AbstractPosAccount $posAccount, ar
return $result;
}
- /**
- * Amount Formatter
- * converts 100 to 10000, or 10.01 to 1001
- *
- * @param float $amount
- *
- * @return int
- */
- protected function formatAmount(float $amount): int
- {
- return (int) (\round($amount, 2) * 100);
- }
-
- /**
- * 0 => '0'
- * 1 => '0'
- * 2 => '2'
- * @inheritDoc
- */
- protected function mapInstallment(int $installment): string
- {
- return $installment > 1 ? (string) $installment : '0';
- }
-
/**
* @inheritDoc
*/
diff --git a/src/DataMapper/RequestValueFormatter/AkbankPosRequestValueFormatter.php b/src/DataMapper/RequestValueFormatter/AkbankPosRequestValueFormatter.php
new file mode 100644
index 00000000..4b6e6a5e
--- /dev/null
+++ b/src/DataMapper/RequestValueFormatter/AkbankPosRequestValueFormatter.php
@@ -0,0 +1,47 @@
+ 1
+ * 1 => 1
+ * 2 => 2
+ * @inheritDoc
+ */
+ public function formatInstallment(int $installment): int
+ {
+ return \max($installment, 1);
+ }
+
+ /**
+ * @param float $amount
+ *
+ * @return float
+ */
+ public function formatAmount(float $amount): float
+ {
+ return $amount;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatCardExpDate(\DateTimeInterface $expDate, string $fieldName): string
+ {
+ return $expDate->format('my');
+ }
+
+ /**
+ * example 2024-04-14T16:45:30.000
+ *
+ * @inheritdoc
+ */
+ public function formatDateTime(\DateTimeInterface $dateTime, string $fieldName = null, string $txType = null): string
+ {
+ return $dateTime->format('Y-m-d\TH:i:s').'.000';
+ }
+}
diff --git a/src/DataMapper/RequestValueFormatter/EstPosRequestValueFormatter.php b/src/DataMapper/RequestValueFormatter/EstPosRequestValueFormatter.php
new file mode 100644
index 00000000..82159ad0
--- /dev/null
+++ b/src/DataMapper/RequestValueFormatter/EstPosRequestValueFormatter.php
@@ -0,0 +1,62 @@
+ ''
+ * 1 => ''
+ * 2 => '2'
+ *
+ * @inheritDoc
+ */
+ public function formatInstallment(int $installment): string
+ {
+ return $installment > 1 ? (string) $installment : '';
+ }
+
+
+ /**
+ * @inheritdoc
+ *
+ * @return string
+ */
+ public function formatAmount(float $amount): string
+ {
+ return (string) $amount;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatCardExpDate(\DateTimeInterface $expDate, string $fieldName): string
+ {
+ if ('Ecom_Payment_Card_ExpDate_Month' === $fieldName) {
+ return $expDate->format('m');
+ }
+
+ if ('Ecom_Payment_Card_ExpDate_Year' === $fieldName) {
+ return $expDate->format('y');
+ }
+
+ if ('Expires' === $fieldName) {
+ return $expDate->format('m/y');
+ }
+
+ throw new \InvalidArgumentException('Unsupported field name');
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatDateTime(\DateTimeInterface $dateTime, string $fieldName = null, string $txType = null): string
+ {
+ throw new NotImplementedException();
+ }
+}
diff --git a/src/DataMapper/RequestValueFormatter/GarantiPosRequestValueFormatter.php b/src/DataMapper/RequestValueFormatter/GarantiPosRequestValueFormatter.php
new file mode 100644
index 00000000..6f29831f
--- /dev/null
+++ b/src/DataMapper/RequestValueFormatter/GarantiPosRequestValueFormatter.php
@@ -0,0 +1,66 @@
+ ''
+ * 1 => ''
+ * 2 => '2'
+ * @inheritDoc
+ */
+ public function formatInstallment(int $installment): string
+ {
+ return $installment > 1 ? (string) $installment : '';
+ }
+
+
+ /**
+ * converts 100 to 10000, or 10.01 to 1001
+ *
+ * @inheritDoc
+ *
+ * @return int
+ */
+ public function formatAmount(float $amount): int
+ {
+ return (int) (\round($amount, 2) * 100);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatCardExpDate(\DateTimeInterface $expDate, string $fieldName): string
+ {
+ if ('cardexpiredatemonth' === $fieldName) {
+ return $expDate->format('m');
+ }
+
+ if ('cardexpiredateyear' === $fieldName) {
+ return $expDate->format('y');
+ }
+
+ if ('ExpireDate' === $fieldName) {
+ return $expDate->format('my');
+ }
+
+ throw new \InvalidArgumentException('Unsupported field name');
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatDateTime(\DateTimeInterface $dateTime, string $fieldName = null, string $txType = null): string
+ {
+ if (PosInterface::TX_TYPE_HISTORY === $txType && ('StartDate' === $fieldName || 'EndDate' === $fieldName)) {
+ return $dateTime->format('d/m/Y H:i');
+ }
+
+ return $dateTime->format('d/m/Y H:i');
+ }
+}
diff --git a/src/DataMapper/RequestValueFormatter/InterPosRequestValueFormatter.php b/src/DataMapper/RequestValueFormatter/InterPosRequestValueFormatter.php
new file mode 100644
index 00000000..39837be4
--- /dev/null
+++ b/src/DataMapper/RequestValueFormatter/InterPosRequestValueFormatter.php
@@ -0,0 +1,48 @@
+ ''
+ * 1 => ''
+ * 2 => '2'
+ * @inheritDoc
+ */
+ public function formatInstallment(int $installment): string
+ {
+ return $installment > 1 ? (string) $installment : '';
+ }
+
+
+ /**
+ * @inheritDoc
+ *
+ * @return string
+ */
+ public function formatAmount(float $amount): string
+ {
+ return (string) $amount;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatCardExpDate(\DateTimeInterface $expDate, string $fieldName): string
+ {
+ return $expDate->format('my');
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatDateTime(\DateTimeInterface $dateTime, string $fieldName = null, string $txType = null): string
+ {
+ throw new NotImplementedException();
+ }
+}
diff --git a/src/DataMapper/RequestValueFormatter/KuveytPosRequestValueFormatter.php b/src/DataMapper/RequestValueFormatter/KuveytPosRequestValueFormatter.php
new file mode 100644
index 00000000..a5416b58
--- /dev/null
+++ b/src/DataMapper/RequestValueFormatter/KuveytPosRequestValueFormatter.php
@@ -0,0 +1,57 @@
+ '0'
+ * 1 => '0'
+ * 2 => '2'
+ * @inheritDoc
+ */
+ public function formatInstallment(int $installment): string
+ {
+ return $installment > 1 ? (string) $installment : '0';
+ }
+
+
+ /**
+ * Amount Formatter
+ * converts 100 to 10000, or 10.01 to 1001
+ *
+ * @param float $amount
+ *
+ * @return int
+ */
+ public function formatAmount(float $amount): int
+ {
+ return (int) (\round($amount, 2) * 100);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatCardExpDate(\DateTimeInterface $expDate, string $fieldName): string
+ {
+ if ('CardExpireDateMonth' === $fieldName) {
+ return $expDate->format('m');
+ }
+
+ if ('CardExpireDateYear' === $fieldName) {
+ return $expDate->format('y');
+ }
+
+ throw new \InvalidArgumentException('Unsupported field name');
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatDateTime(\DateTimeInterface $dateTime, string $fieldName = null, string $txType = null): string
+ {
+ return $dateTime->format('Y-m-d\TH:i:s');
+ }
+}
diff --git a/src/DataMapper/RequestValueFormatter/PayFlexCPV4PosRequestValueFormatter.php b/src/DataMapper/RequestValueFormatter/PayFlexCPV4PosRequestValueFormatter.php
new file mode 100644
index 00000000..1e4df3c3
--- /dev/null
+++ b/src/DataMapper/RequestValueFormatter/PayFlexCPV4PosRequestValueFormatter.php
@@ -0,0 +1,61 @@
+ '0'
+ * 1 => '0'
+ * 2 => '2'
+ *
+ * @inheritDoc
+ */
+ public function formatInstallment(int $installment): string
+ {
+ return $installment > 1 ? (string) $installment : '0';
+ }
+
+
+ /**
+ * ex: 10.1 => 10.10
+ *
+ * @inheritDoc
+ */
+ public function formatAmount(float $amount): string
+ {
+ return \number_format($amount, 2, '.', '');
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatCardExpDate(\DateTimeInterface $expDate, string $fieldName): string
+ {
+ if ('ExpireMonth' === $fieldName) {
+ return $expDate->format('m');
+ }
+
+ if ('ExpireYear' === $fieldName) {
+ return $expDate->format('y');
+ }
+
+ if ('Expiry' === $fieldName) {
+ return $expDate->format('Ym');
+ }
+
+ throw new \InvalidArgumentException('Unsupported field name');
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatDateTime(\DateTimeInterface $dateTime, string $fieldName = null, string $txType = null): string
+ {
+ throw new NotImplementedException();
+ }
+}
diff --git a/src/DataMapper/RequestValueFormatter/PayFlexV4PosRequestValueFormatter.php b/src/DataMapper/RequestValueFormatter/PayFlexV4PosRequestValueFormatter.php
new file mode 100644
index 00000000..22dfdd62
--- /dev/null
+++ b/src/DataMapper/RequestValueFormatter/PayFlexV4PosRequestValueFormatter.php
@@ -0,0 +1,58 @@
+ '0'
+ * 1 => '0'
+ * 2 => '2'
+ *
+ * @inheritDoc
+ */
+ public function formatInstallment(int $installment): string
+ {
+ return $installment > 1 ? (string) $installment : '0';
+ }
+
+
+ /**
+ * ex: 10.1 => 10.10
+ *
+ * @inheritDoc
+ */
+ public function formatAmount(float $amount): string
+ {
+ return \number_format($amount, 2, '.', '');
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatCardExpDate(\DateTimeInterface $expDate, string $fieldName): string
+ {
+ if ('ExpiryDate' === $fieldName) {
+ return $expDate->format('ym');
+ }
+
+ if ('Expiry' === $fieldName) {
+ return $expDate->format('Ym');
+ }
+
+ throw new \InvalidArgumentException('Unsupported field name');
+ }
+
+ /**
+ * example 2024-04-14T16:45:30.000
+ *
+ * @inheritdoc
+ */
+ public function formatDateTime(\DateTimeInterface $dateTime, string $fieldName = null, string $txType = null): string
+ {
+ return $dateTime->format('Ymd');
+ }
+}
diff --git a/src/DataMapper/RequestValueFormatter/PayForPosRequestValueFormatter.php b/src/DataMapper/RequestValueFormatter/PayForPosRequestValueFormatter.php
new file mode 100644
index 00000000..b0f45368
--- /dev/null
+++ b/src/DataMapper/RequestValueFormatter/PayForPosRequestValueFormatter.php
@@ -0,0 +1,49 @@
+ '0'
+ * 1 => '0'
+ * 2 => '2'
+ *
+ * @inheritDoc
+ */
+ public function formatInstallment(int $installment): string
+ {
+ return $installment > 1 ? (string) $installment : '0';
+ }
+
+
+ /**
+ * 10.1 => "10.1"
+ *
+ * @inheritDoc
+ */
+ public function formatAmount(float $amount): string
+ {
+ return (string) $amount;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatCardExpDate(\DateTimeInterface $expDate, string $fieldName): string
+ {
+ return $expDate->format('my');
+ }
+
+ /**
+ * example 2024-04-14T16:45:30.000
+ *
+ * @inheritdoc
+ */
+ public function formatDateTime(\DateTimeInterface $dateTime, string $fieldName = null, string $txType = null): string
+ {
+ return $dateTime->format('Ymd');
+ }
+}
diff --git a/src/DataMapper/RequestValueFormatter/PosNetRequestValueFormatter.php b/src/DataMapper/RequestValueFormatter/PosNetRequestValueFormatter.php
new file mode 100644
index 00000000..c0e51ff6
--- /dev/null
+++ b/src/DataMapper/RequestValueFormatter/PosNetRequestValueFormatter.php
@@ -0,0 +1,121 @@
+ '00'
+ * 1 => '00'
+ * 2 => '02'
+ * @inheritDoc
+ */
+ public function formatInstallment(int $installment): string
+ {
+ if ($installment > 1) {
+ return \str_pad((string) $installment, 2, '0', STR_PAD_LEFT);
+ }
+
+ return '00';
+ }
+
+ /**
+ * formats 10.01 to 1001
+ *
+ * @inheritDoc
+ */
+ public function formatAmount(float $amount): int
+ {
+ return (int) (\round($amount, 2) * 100);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatCardExpDate(\DateTimeInterface $expDate, string $fieldName): string
+ {
+ return $expDate->format('ym');
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatDateTime(\DateTimeInterface $dateTime, string $fieldName = null, string $txType = null): string
+ {
+ throw new NotImplementedException();
+ }
+
+ /**
+ * formats order id by adding 0 pad to the left and adding prefix
+ *
+ * @param string $orderId
+ * @param PosInterface::TX_TYPE_*|null $txType
+ * @param PosInterface::MODEL_*|null $orderPaymentModel payment model of the order
+ *
+ * @return string
+ */
+ public function formatOrderId(string $orderId, ?string $txType = null, ?string $orderPaymentModel = null): string
+ {
+ $prefix = '';
+ $padLength = self::ORDER_ID_LENGTH;
+
+ if (\in_array($txType, [
+ PosInterface::TX_TYPE_STATUS,
+ PosInterface::TX_TYPE_REFUND,
+ PosInterface::TX_TYPE_REFUND_PARTIAL,
+ PosInterface::TX_TYPE_CANCEL,
+ ], true)) {
+ /**
+ * To check the status of an order or cancel/refund order Yapikredi
+ * - requires the order length to be 24
+ * - and order id prefix which is "TDSC" for 3D payments
+ */
+ $prefix = self::ORDER_ID_REGULAR_PREFIX;
+ $padLength = self::ORDER_ID_TOTAL_LENGTH;
+ if (PosInterface::MODEL_3D_SECURE === $orderPaymentModel) {
+ $prefix = self::ORDER_ID_3D_PREFIX;
+ } elseif (PosInterface::MODEL_3D_PAY === $orderPaymentModel) {
+ $prefix = self::ORDER_ID_3D_PAY_PREFIX;
+ }
+ }
+
+ if (\strlen($orderId) > $padLength) {
+ throw new \InvalidArgumentException(\sprintf(
+ // Banka tarafindan belirlenen kisitlama
+ "Saglanan siparis ID'nin (%s) uzunlugu %d karakter. Siparis ID %d karakterden uzun olamaz!",
+ $orderId,
+ \strlen($orderId),
+ $padLength
+ ));
+ }
+
+ return $prefix.\str_pad($orderId, $padLength - \strlen($prefix), '0', STR_PAD_LEFT);
+ }
+}
diff --git a/src/DataMapper/RequestValueFormatter/PosNetV1PosRequestValueFormatter.php b/src/DataMapper/RequestValueFormatter/PosNetV1PosRequestValueFormatter.php
new file mode 100644
index 00000000..181bcf93
--- /dev/null
+++ b/src/DataMapper/RequestValueFormatter/PosNetV1PosRequestValueFormatter.php
@@ -0,0 +1,125 @@
+ '0'
+ * 1 => '0'
+ * 2 => '2'
+ *
+ * @inheritDoc
+ */
+ public function formatInstallment(int $installment): string
+ {
+ if ($installment > 1) {
+ return (string) $installment;
+ }
+
+ return '0';
+ }
+
+ /**
+ * example: 10.01 to 1001
+ *
+ * @inheritDoc
+ */
+ public function formatAmount(float $amount): int
+ {
+ return (int) (\round($amount, 2) * 100);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatCardExpDate(\DateTimeInterface $expDate, string $fieldName): string
+ {
+ return $expDate->format('ym');
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatDateTime(\DateTimeInterface $dateTime, string $fieldName = null, string $txType = null): string
+ {
+ throw new NotImplementedException();
+ }
+
+ /**
+ * formats order id by adding 0 pad to the left and adding prefix
+ *
+ * @param string $orderId
+ * @param PosInterface::TX_TYPE_*|null $txType
+ * @param PosInterface::MODEL_*|null $orderPaymentModel payment model of the order
+ *
+ * @return string
+ */
+ public function formatOrderId(string $orderId, ?string $txType = null, ?string $orderPaymentModel = null): string
+ {
+ $prefix = '';
+ $padLength = self::ORDER_ID_LENGTH;
+
+ if (\in_array($txType, [
+ PosInterface::TX_TYPE_STATUS,
+ PosInterface::TX_TYPE_REFUND,
+ PosInterface::TX_TYPE_REFUND_PARTIAL,
+ PosInterface::TX_TYPE_CANCEL,
+ ], true)) {
+ /**
+ * To check the status of an order or cancel/refund order Yapikredi
+ * - requires the order length to be 24
+ * - and order id prefix which is "TDSC" for 3D payments
+ */
+ $prefix = self::ORDER_ID_REGULAR_PREFIX;
+ $padLength = self::ORDER_ID_TOTAL_LENGTH;
+ if (PosInterface::MODEL_3D_SECURE === $orderPaymentModel) {
+ $prefix = self::ORDER_ID_3D_PREFIX;
+ } elseif (PosInterface::MODEL_3D_PAY === $orderPaymentModel) {
+ $prefix = self::ORDER_ID_3D_PAY_PREFIX;
+
+ }
+ }
+
+ if (\strlen($orderId) > $padLength) {
+ throw new \InvalidArgumentException(\sprintf(
+ // Banka tarafindan belirlenen kisitlama
+ "Saglanan siparis ID'nin (%s) uzunlugu %d karakter. Siparis ID %d karakterden uzun olamaz!",
+ $orderId,
+ \strlen($orderId),
+ $padLength
+ ));
+ }
+
+ return $prefix.\str_pad($orderId, $padLength - strlen($prefix), '0', STR_PAD_LEFT);
+ }
+}
diff --git a/src/DataMapper/RequestValueFormatter/RequestValueFormatterInterface.php b/src/DataMapper/RequestValueFormatter/RequestValueFormatterInterface.php
new file mode 100644
index 00000000..84151fa7
--- /dev/null
+++ b/src/DataMapper/RequestValueFormatter/RequestValueFormatterInterface.php
@@ -0,0 +1,51 @@
+ $installment
+ *
+ * @return string|int
+ */
+ public function formatInstallment(int $installment);
+
+
+ /**
+ * formats purchase amount
+ *
+ * @param float $amount
+ *
+ * @return string|int|float
+ */
+ public function formatAmount(float $amount);
+
+ /**
+ * @param \DateTimeInterface $expDate
+ * @param string $fieldName request expiration date/month/year field name
+ *
+ * @return string formatted expiration month, year, or month and year
+ *
+ * @throws \InvalidArgumentException when unsupported field name
+ */
+ public function formatCardExpDate(\DateTimeInterface $expDate, string $fieldName): string;
+
+ /**
+ * @param \DateTimeInterface $dateTime
+ * @param string $fieldName request field name of the date
+ * @param PosInterface::TX_TYPE_*|null $txType
+ *
+ * @return string formatted date time
+ *
+ * @throws \InvalidArgumentException when unsupported field name
+ */
+ public function formatDateTime(\DateTimeInterface $dateTime, string $fieldName, string $txType = null): string;
+}
diff --git a/src/DataMapper/RequestValueFormatter/ToslaPosRequestValueFormatter.php b/src/DataMapper/RequestValueFormatter/ToslaPosRequestValueFormatter.php
new file mode 100644
index 00000000..b2897d8e
--- /dev/null
+++ b/src/DataMapper/RequestValueFormatter/ToslaPosRequestValueFormatter.php
@@ -0,0 +1,62 @@
+ '0'
+ * 1 => '0'
+ * 2 => '2'
+ *
+ * @inheritDoc
+ */
+ public function formatInstallment(int $installment): int
+ {
+ return $installment > 1 ? $installment : 0;
+ }
+
+
+ /**
+ * formats 10.01 to 1001
+ *
+ * @inheritDoc
+ */
+ public function formatAmount(float $amount): int
+ {
+ return (int) (\round($amount, 2) * 100);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatCardExpDate(\DateTimeInterface $expDate, string $fieldName): string
+ {
+ if ('ExpireDate' === $fieldName) {
+ return $expDate->format('m/y');
+ }
+
+ if ('expireDate' === $fieldName) {
+ return $expDate->format('my');
+ }
+
+ throw new \InvalidArgumentException('Unsupported field name');
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatDateTime(\DateTimeInterface $dateTime, string $fieldName = null, string $txType = null): string
+ {
+ if ('timeSpan' === $fieldName) {
+ return $dateTime->format('YmdHis');
+ }
+ if ('transactionDate' === $fieldName) {
+ return $dateTime->format('Ymd');
+ }
+
+ throw new \InvalidArgumentException('Unsupported field name');
+ }
+}
diff --git a/src/DataMapper/RequestValueFormatter/VakifKatilimPosRequestValueFormatter.php b/src/DataMapper/RequestValueFormatter/VakifKatilimPosRequestValueFormatter.php
new file mode 100644
index 00000000..5c411600
--- /dev/null
+++ b/src/DataMapper/RequestValueFormatter/VakifKatilimPosRequestValueFormatter.php
@@ -0,0 +1,59 @@
+ '0'
+ * 1 => '0'
+ * 2 => '2'
+ *
+ * @inheritDoc
+ */
+ public function formatInstallment(int $installment): string
+ {
+ return $installment > 1 ? (string) $installment : '0';
+ }
+
+
+ /**
+ * example: 100 to 10000, or 10.01 to 1001
+ *
+ * @inheritDoc
+ */
+ public function formatAmount(float $amount): int
+ {
+ return (int) (\round($amount, 2) * 100);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatCardExpDate(\DateTimeInterface $expDate, string $fieldName): string
+ {
+ if ('CardExpireDateYear' === $fieldName) {
+ return $expDate->format('y');
+ }
+
+ if ('CardExpireDateMonth' === $fieldName) {
+ return $expDate->format('m');
+ }
+
+ throw new \InvalidArgumentException('Unsupported field name');
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function formatDateTime(\DateTimeInterface $dateTime, string $fieldName = null, string $txType = null): string
+ {
+ if ('StartDate' === $fieldName || 'EndDate' === $fieldName) {
+ return $dateTime->format('Y-m-d');
+ }
+
+ throw new \InvalidArgumentException('Unsupported field name');
+ }
+}
diff --git a/src/DataMapper/RequestValueMapper/AbstractRequestValueMapper.php b/src/DataMapper/RequestValueMapper/AbstractRequestValueMapper.php
new file mode 100644
index 00000000..02d80dfb
--- /dev/null
+++ b/src/DataMapper/RequestValueMapper/AbstractRequestValueMapper.php
@@ -0,0 +1,195 @@
+ */
+ protected array $cardTypeMappings = [];
+
+ /**
+ * Transaction Types
+ *
+ * @var array>
+ */
+ protected array $txTypeMappings = [];
+
+ /**
+ * period mapping for recurring orders
+ * @var array<'DAY'|'WEEK'|'MONTH'|'YEAR', string>
+ */
+ protected array $recurringOrderFrequencyMappings = [];
+
+ /** @var array */
+ protected array $secureTypeMappings = [];
+
+ /** @var array */
+ protected array $langMappings = [];
+
+ /**
+ * by default we set ISO 4217 currency values.
+ * Some gateways may use different currency values.
+ *
+ * @var non-empty-array
+ */
+ protected array $currencyMappings = [
+ PosInterface::CURRENCY_TRY => '949',
+ PosInterface::CURRENCY_USD => '840',
+ PosInterface::CURRENCY_EUR => '978',
+ PosInterface::CURRENCY_GBP => '826',
+ PosInterface::CURRENCY_JPY => '392',
+ PosInterface::CURRENCY_RUB => '643',
+ ];
+
+ /**
+ * @return array>
+ */
+ public function getTxTypeMappings(): array
+ {
+ return $this->txTypeMappings;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function mapTxType(string $txType, ?string $paymentModel = null): string
+ {
+ if (!$this->isSupportedTxType($txType, $paymentModel)) {
+ throw new UnsupportedTransactionTypeException();
+ }
+
+ if (\is_string($this->txTypeMappings[$txType])) {
+ return $this->txTypeMappings[$txType];
+ }
+
+ return $this->txTypeMappings[$txType][$paymentModel];
+ }
+
+ /**
+ * @return array
+ */
+ public function getSecureTypeMappings(): array
+ {
+ return $this->secureTypeMappings;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function mapSecureType(string $paymentModel): string
+ {
+ if (0 === count($this->secureTypeMappings)) {
+ throw new \LogicException('Security type mappings are not supported.');
+ }
+
+ return $this->secureTypeMappings[$paymentModel];
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function mapCurrency(string $currency)
+ {
+ return $this->currencyMappings[$currency];
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getCurrencyMappings(): array
+ {
+ return $this->currencyMappings;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getRecurringOrderFrequencyMappings(): array
+ {
+ return $this->recurringOrderFrequencyMappings;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function mapRecurringFrequency(string $period): string
+ {
+ if (0 === count($this->recurringOrderFrequencyMappings)) {
+ throw new \LogicException('Recurring frequency mappings are not supported.');
+ }
+
+ return $this->recurringOrderFrequencyMappings[$period];
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function mapLang(string $lang): string
+ {
+ if (0 === count($this->langMappings)) {
+ throw new \LogicException('Language mappings are not supported.');
+ }
+
+ return $this->langMappings[$lang];
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getLangMappings(): array
+ {
+ return $this->langMappings;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getCardTypeMappings(): array
+ {
+ return $this->cardTypeMappings;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function mapCardType(string $cardType): string
+ {
+ if (0 === count($this->cardTypeMappings)) {
+ throw new \LogicException('Card type mappings are not supported.');
+ }
+
+ return $this->cardTypeMappings[$cardType];
+ }
+
+ /**
+ * @phpstan-param PosInterface::TX_TYPE_* $txType
+ * @phpstan-param PosInterface::MODEL_*|null $paymentModel
+ *
+ * @param string $txType
+ * @param string|null $paymentModel
+ *
+ * @return bool
+ */
+ protected function isSupportedTxType(string $txType, ?string $paymentModel = null): bool
+ {
+ if (!isset($this->txTypeMappings[$txType])) {
+ return false;
+ }
+
+ if (\is_array($this->txTypeMappings[$txType])) {
+ if (null === $paymentModel) {
+ return false;
+ }
+
+ return isset($this->txTypeMappings[$txType][$paymentModel]);
+ }
+
+ return true;
+ }
+}
diff --git a/src/DataMapper/RequestValueMapper/AkbankPosRequestValueMapper.php b/src/DataMapper/RequestValueMapper/AkbankPosRequestValueMapper.php
new file mode 100644
index 00000000..a0885008
--- /dev/null
+++ b/src/DataMapper/RequestValueMapper/AkbankPosRequestValueMapper.php
@@ -0,0 +1,72 @@
+ [
+ PosInterface::MODEL_NON_SECURE => '1000',
+ PosInterface::MODEL_3D_SECURE => '3000',
+ PosInterface::MODEL_3D_PAY => '3000',
+ PosInterface::MODEL_3D_HOST => '3000',
+ ],
+ PosInterface::TX_TYPE_PAY_PRE_AUTH => [
+ PosInterface::MODEL_NON_SECURE => '1004',
+ PosInterface::MODEL_3D_SECURE => '3004',
+ PosInterface::MODEL_3D_PAY => '3004',
+ PosInterface::MODEL_3D_HOST => '3004',
+ ],
+ PosInterface::TX_TYPE_PAY_POST_AUTH => '1005',
+ PosInterface::TX_TYPE_REFUND => '1002',
+ PosInterface::TX_TYPE_REFUND_PARTIAL => '1002',
+ PosInterface::TX_TYPE_CANCEL => '1003',
+ PosInterface::TX_TYPE_ORDER_HISTORY => '1010',
+ PosInterface::TX_TYPE_HISTORY => '1009',
+ ];
+
+ /**
+ * @var non-empty-array
+ */
+ protected array $currencyMappings = [
+ PosInterface::CURRENCY_TRY => 949,
+ PosInterface::CURRENCY_USD => 840,
+ PosInterface::CURRENCY_EUR => 978,
+ PosInterface::CURRENCY_GBP => 826,
+ PosInterface::CURRENCY_JPY => 392,
+ PosInterface::CURRENCY_RUB => 643,
+ ];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected array $recurringOrderFrequencyMappings = [
+ 'DAY' => 'D',
+ 'WEEK' => 'W',
+ 'MONTH' => 'M',
+ 'YEAR' => 'Y',
+ ];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected array $secureTypeMappings = [
+ PosInterface::MODEL_3D_SECURE => '3D',
+ PosInterface::MODEL_3D_PAY => '3D_PAY',
+ PosInterface::MODEL_3D_HOST => '3D_PAY_HOSTING',
+ PosInterface::MODEL_NON_SECURE => 'PAY_HOSTING',
+ ];
+
+ /** @var array */
+ protected array $langMappings = [
+ PosInterface::LANG_TR => 'TR',
+ PosInterface::LANG_EN => 'EN',
+ ];
+}
diff --git a/src/DataMapper/RequestValueMapper/EstPosRequestValueMapper.php b/src/DataMapper/RequestValueMapper/EstPosRequestValueMapper.php
new file mode 100644
index 00000000..a971399a
--- /dev/null
+++ b/src/DataMapper/RequestValueMapper/EstPosRequestValueMapper.php
@@ -0,0 +1,63 @@
+ 'tr',
+ PosInterface::LANG_EN => 'en',
+ ];
+
+ /**
+ * {@inheritDoc}
+ */
+ protected array $txTypeMappings = [
+ PosInterface::TX_TYPE_PAY_AUTH => 'Auth',
+ PosInterface::TX_TYPE_PAY_PRE_AUTH => 'PreAuth',
+ PosInterface::TX_TYPE_PAY_POST_AUTH => 'PostAuth',
+ PosInterface::TX_TYPE_CANCEL => 'Void',
+ PosInterface::TX_TYPE_REFUND => 'Credit',
+ PosInterface::TX_TYPE_REFUND_PARTIAL => 'Credit',
+ PosInterface::TX_TYPE_STATUS => 'ORDERSTATUS',
+ PosInterface::TX_TYPE_HISTORY => 'ORDERHISTORY',
+ ];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected array $recurringOrderFrequencyMappings = [
+ 'DAY' => 'D',
+ 'WEEK' => 'W',
+ 'MONTH' => 'M',
+ 'YEAR' => 'Y',
+ ];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected array $secureTypeMappings = [
+ PosInterface::MODEL_3D_SECURE => '3d',
+ PosInterface::MODEL_3D_PAY => '3d_pay',
+ PosInterface::MODEL_3D_PAY_HOSTING => '3d_pay_hosting',
+ PosInterface::MODEL_3D_HOST => '3d_host',
+ PosInterface::MODEL_NON_SECURE => 'regular',
+ ];
+
+ /**
+ * @inheritDoc
+ *
+ * @return string
+ */
+ public function mapCurrency(string $currency): string
+ {
+ return (string) $this->currencyMappings[$currency];
+ }
+}
diff --git a/src/DataMapper/RequestValueMapper/GarantiPosRequestValueMapper.php b/src/DataMapper/RequestValueMapper/GarantiPosRequestValueMapper.php
new file mode 100644
index 00000000..6253e454
--- /dev/null
+++ b/src/DataMapper/RequestValueMapper/GarantiPosRequestValueMapper.php
@@ -0,0 +1,42 @@
+ 'sales',
+ PosInterface::TX_TYPE_PAY_PRE_AUTH => 'preauth',
+ PosInterface::TX_TYPE_PAY_POST_AUTH => 'postauth',
+ PosInterface::TX_TYPE_CANCEL => 'void',
+ PosInterface::TX_TYPE_REFUND => 'refund',
+ PosInterface::TX_TYPE_REFUND_PARTIAL => 'refund',
+ PosInterface::TX_TYPE_ORDER_HISTORY => 'orderhistoryinq',
+ PosInterface::TX_TYPE_HISTORY => 'orderlistinq',
+ PosInterface::TX_TYPE_STATUS => 'orderinq',
+ ];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected array $recurringOrderFrequencyMappings = [
+ 'DAY' => 'D',
+ 'WEEK' => 'W',
+ 'MONTH' => 'M',
+ ];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected array $secureTypeMappings = [
+ PosInterface::MODEL_3D_SECURE => '3D',
+ PosInterface::MODEL_3D_PAY => '3D_PAY',
+ ];
+}
diff --git a/src/DataMapper/RequestValueMapper/InterPosRequestValueMapper.php b/src/DataMapper/RequestValueMapper/InterPosRequestValueMapper.php
new file mode 100644
index 00000000..d5cc4016
--- /dev/null
+++ b/src/DataMapper/RequestValueMapper/InterPosRequestValueMapper.php
@@ -0,0 +1,62 @@
+ 'tr',
+ PosInterface::LANG_EN => 'en',
+ ];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected array $cardTypeMappings = [
+ CreditCardInterface::CARD_TYPE_VISA => '0',
+ CreditCardInterface::CARD_TYPE_MASTERCARD => '1',
+ CreditCardInterface::CARD_TYPE_AMEX => '2',
+ CreditCardInterface::CARD_TYPE_TROY => '3',
+ ];
+
+ /**
+ * {@inheritDoc}
+ */
+ protected array $txTypeMappings = [
+ PosInterface::TX_TYPE_PAY_AUTH => 'Auth',
+ PosInterface::TX_TYPE_PAY_PRE_AUTH => 'PreAuth',
+ PosInterface::TX_TYPE_PAY_POST_AUTH => 'PostAuth',
+ PosInterface::TX_TYPE_CANCEL => 'Void',
+ PosInterface::TX_TYPE_REFUND => 'Refund',
+ PosInterface::TX_TYPE_REFUND_PARTIAL => 'Refund',
+ PosInterface::TX_TYPE_STATUS => 'StatusHistory',
+ ];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected array $secureTypeMappings = [
+ PosInterface::MODEL_3D_SECURE => '3DModel',
+ PosInterface::MODEL_3D_PAY => '3DPay',
+ PosInterface::MODEL_3D_HOST => '3DHost',
+ PosInterface::MODEL_NON_SECURE => 'NonSecure',
+ ];
+
+ /**
+ * @inheritDoc
+ *
+ * @return string
+ */
+ public function mapCurrency(string $currency): string
+ {
+ return (string) $this->currencyMappings[$currency];
+ }
+}
diff --git a/src/DataMapper/RequestValueMapper/KuveytPosRequestValueMapper.php b/src/DataMapper/RequestValueMapper/KuveytPosRequestValueMapper.php
new file mode 100644
index 00000000..bbadd866
--- /dev/null
+++ b/src/DataMapper/RequestValueMapper/KuveytPosRequestValueMapper.php
@@ -0,0 +1,63 @@
+ '0949',
+ PosInterface::CURRENCY_USD => '0840',
+ PosInterface::CURRENCY_EUR => '0978',
+ PosInterface::CURRENCY_GBP => '0826',
+ PosInterface::CURRENCY_JPY => '0392',
+ PosInterface::CURRENCY_RUB => '0810',
+ ];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected array $cardTypeMappings = [
+ CreditCardInterface::CARD_TYPE_VISA => 'Visa',
+ CreditCardInterface::CARD_TYPE_MASTERCARD => 'MasterCard',
+ CreditCardInterface::CARD_TYPE_TROY => 'Troy',
+ ];
+
+ /**
+ * {@inheritDoc}
+ */
+ protected array $txTypeMappings = [
+ PosInterface::TX_TYPE_PAY_AUTH => 'Sale',
+ PosInterface::TX_TYPE_CANCEL => 'SaleReversal',
+ PosInterface::TX_TYPE_STATUS => 'GetMerchantOrderDetail',
+ PosInterface::TX_TYPE_REFUND => 'Drawback',
+ PosInterface::TX_TYPE_REFUND_PARTIAL => 'PartialDrawback',
+ ];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected array $secureTypeMappings = [
+ PosInterface::MODEL_3D_SECURE => '3',
+ PosInterface::MODEL_NON_SECURE => '0',
+ ];
+
+ /**
+ * @inheritDoc
+ *
+ * @return string
+ */
+ public function mapCurrency(string $currency): string
+ {
+ return (string) $this->currencyMappings[$currency];
+ }
+}
diff --git a/src/DataMapper/RequestValueMapper/PayFlexCPV4PosRequestValueMapper.php b/src/DataMapper/RequestValueMapper/PayFlexCPV4PosRequestValueMapper.php
new file mode 100644
index 00000000..0124d9ae
--- /dev/null
+++ b/src/DataMapper/RequestValueMapper/PayFlexCPV4PosRequestValueMapper.php
@@ -0,0 +1,53 @@
+ '100',
+ CreditCardInterface::CARD_TYPE_MASTERCARD => '200',
+ CreditCardInterface::CARD_TYPE_TROY => '300',
+ CreditCardInterface::CARD_TYPE_AMEX => '400',
+ ];
+
+ /**
+ * {@inheritDoc}
+ */
+ protected array $txTypeMappings = [
+ PosInterface::TX_TYPE_PAY_AUTH => 'Sale',
+ PosInterface::TX_TYPE_PAY_PRE_AUTH => 'Auth',
+ PosInterface::TX_TYPE_PAY_POST_AUTH => 'Capture',
+ PosInterface::TX_TYPE_CANCEL => 'Cancel',
+ PosInterface::TX_TYPE_REFUND => 'Refund',
+ PosInterface::TX_TYPE_REFUND_PARTIAL => 'Refund',
+ PosInterface::TX_TYPE_HISTORY => 'TxnHistory',
+ PosInterface::TX_TYPE_STATUS => 'OrderInquiry',
+ ];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected array $langMappings = [
+ PosInterface::LANG_TR => 'tr-TR',
+ PosInterface::LANG_EN => 'en-US',
+ ];
+
+ /**
+ * @inheritDoc
+ *
+ * @return string
+ */
+ public function mapCurrency(string $currency): string
+ {
+ return (string) $this->currencyMappings[$currency];
+ }
+}
diff --git a/src/DataMapper/RequestValueMapper/PayFlexV4PosRequestValueMapper.php b/src/DataMapper/RequestValueMapper/PayFlexV4PosRequestValueMapper.php
new file mode 100644
index 00000000..22aab433
--- /dev/null
+++ b/src/DataMapper/RequestValueMapper/PayFlexV4PosRequestValueMapper.php
@@ -0,0 +1,53 @@
+ '100',
+ CreditCardInterface::CARD_TYPE_MASTERCARD => '200',
+ CreditCardInterface::CARD_TYPE_TROY => '300',
+ CreditCardInterface::CARD_TYPE_AMEX => '400',
+ ];
+
+ /**
+ * {@inheritDoc}
+ */
+ protected array $txTypeMappings = [
+ PosInterface::TX_TYPE_PAY_AUTH => 'Sale',
+ PosInterface::TX_TYPE_PAY_PRE_AUTH => 'Auth',
+ PosInterface::TX_TYPE_PAY_POST_AUTH => 'Capture',
+ PosInterface::TX_TYPE_CANCEL => 'Cancel',
+ PosInterface::TX_TYPE_REFUND => 'Refund',
+ PosInterface::TX_TYPE_REFUND_PARTIAL => 'Refund',
+ PosInterface::TX_TYPE_STATUS => 'status',
+ ];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected array $recurringOrderFrequencyMappings = [
+ 'DAY' => 'Day',
+ 'MONTH' => 'Month',
+ 'YEAR' => 'Year',
+ ];
+
+ /**
+ * @inheritDoc
+ *
+ * @return string
+ */
+ public function mapCurrency(string $currency): string
+ {
+ return (string) $this->currencyMappings[$currency];
+ }
+}
diff --git a/src/DataMapper/RequestValueMapper/PayForPosRequestValueMapper.php b/src/DataMapper/RequestValueMapper/PayForPosRequestValueMapper.php
new file mode 100644
index 00000000..74a8af0b
--- /dev/null
+++ b/src/DataMapper/RequestValueMapper/PayForPosRequestValueMapper.php
@@ -0,0 +1,50 @@
+ 'tr',
+ PosInterface::LANG_EN => 'en',
+ ];
+
+ /**
+ * {@inheritDoc}
+ */
+ protected array $txTypeMappings = [
+ PosInterface::TX_TYPE_PAY_AUTH => 'Auth',
+ PosInterface::TX_TYPE_PAY_PRE_AUTH => 'PreAuth',
+ PosInterface::TX_TYPE_PAY_POST_AUTH => 'PostAuth',
+ PosInterface::TX_TYPE_CANCEL => 'Void',
+ PosInterface::TX_TYPE_REFUND => 'Refund',
+ PosInterface::TX_TYPE_REFUND_PARTIAL => 'Refund',
+ PosInterface::TX_TYPE_HISTORY => 'TxnHistory',
+ PosInterface::TX_TYPE_STATUS => 'OrderInquiry',
+ ];
+
+ /** {@inheritdoc} */
+ protected array $secureTypeMappings = [
+ PosInterface::MODEL_3D_SECURE => '3DModel',
+ PosInterface::MODEL_3D_PAY => '3DPay',
+ PosInterface::MODEL_3D_HOST => '3DHost',
+ PosInterface::MODEL_NON_SECURE => 'NonSecure',
+ ];
+
+ /**
+ * @inheritDoc
+ *
+ * @return string
+ */
+ public function mapCurrency(string $currency): string
+ {
+ return (string) $this->currencyMappings[$currency];
+ }
+}
diff --git a/src/DataMapper/RequestValueMapper/PosNetRequestValueMapper.php b/src/DataMapper/RequestValueMapper/PosNetRequestValueMapper.php
new file mode 100644
index 00000000..d8eb6ad4
--- /dev/null
+++ b/src/DataMapper/RequestValueMapper/PosNetRequestValueMapper.php
@@ -0,0 +1,43 @@
+ 'tr',
+ PosInterface::LANG_EN => 'en',
+ ];
+
+ /**
+ * {@inheritDoc}
+ */
+ protected array $txTypeMappings = [
+ PosInterface::TX_TYPE_PAY_AUTH => 'Sale',
+ PosInterface::TX_TYPE_PAY_PRE_AUTH => 'Auth',
+ PosInterface::TX_TYPE_PAY_POST_AUTH => 'Capt',
+ PosInterface::TX_TYPE_CANCEL => 'reverse',
+ PosInterface::TX_TYPE_REFUND => 'return',
+ PosInterface::TX_TYPE_REFUND_PARTIAL => 'return',
+ PosInterface::TX_TYPE_STATUS => 'agreement',
+ ];
+
+ /**
+ * {@inheritDoc}
+ */
+ protected array $currencyMappings = [
+ PosInterface::CURRENCY_TRY => 'TL',
+ PosInterface::CURRENCY_USD => 'US',
+ PosInterface::CURRENCY_EUR => 'EU',
+ PosInterface::CURRENCY_GBP => 'GB',
+ PosInterface::CURRENCY_JPY => 'JP',
+ PosInterface::CURRENCY_RUB => 'RU',
+ ];
+}
diff --git a/src/DataMapper/RequestValueMapper/PosNetV1PosRequestValueMapper.php b/src/DataMapper/RequestValueMapper/PosNetV1PosRequestValueMapper.php
new file mode 100644
index 00000000..54a4de94
--- /dev/null
+++ b/src/DataMapper/RequestValueMapper/PosNetV1PosRequestValueMapper.php
@@ -0,0 +1,43 @@
+ 'tr',
+ PosInterface::LANG_EN => 'en',
+ ];
+
+ /**
+ * {@inheritDoc}
+ */
+ protected array $txTypeMappings = [
+ PosInterface::TX_TYPE_PAY_AUTH => 'Sale',
+ PosInterface::TX_TYPE_PAY_PRE_AUTH => 'Auth',
+ PosInterface::TX_TYPE_PAY_POST_AUTH => 'Capture',
+ PosInterface::TX_TYPE_CANCEL => 'Reverse',
+ PosInterface::TX_TYPE_REFUND => 'Return',
+ PosInterface::TX_TYPE_REFUND_PARTIAL => 'Return',
+ PosInterface::TX_TYPE_STATUS => 'TransactionInquiry',
+ ];
+
+ /**
+ * {@inheritDoc}
+ */
+ protected array $currencyMappings = [
+ PosInterface::CURRENCY_TRY => 'TL',
+ PosInterface::CURRENCY_USD => 'US',
+ PosInterface::CURRENCY_EUR => 'EU',
+ PosInterface::CURRENCY_GBP => 'GB',
+ PosInterface::CURRENCY_JPY => 'JP',
+ PosInterface::CURRENCY_RUB => 'RU',
+ ];
+}
diff --git a/src/DataMapper/RequestValueMapper/RequestValueMapperInterface.php b/src/DataMapper/RequestValueMapper/RequestValueMapperInterface.php
new file mode 100644
index 00000000..e527ec73
--- /dev/null
+++ b/src/DataMapper/RequestValueMapper/RequestValueMapperInterface.php
@@ -0,0 +1,92 @@
+>
+ */
+ public function getTxTypeMappings(): array;
+
+ /**
+ * @param PosInterface::TX_TYPE_* $txType
+ * @param PosInterface::MODEL_*|null $paymentModel
+ *
+ * @return string
+ *
+ * @throws UnsupportedTransactionTypeException
+ */
+ public function mapTxType(string $txType, ?string $paymentModel = null): string;
+
+ /**
+ * @param PosInterface::MODEL_* $paymentModel
+ *
+ * @return string
+ */
+ public function mapSecureType(string $paymentModel): string;
+
+ /**
+ * @return array
+ */
+ public function getSecureTypeMappings(): array;
+
+ /**
+ * @phpstan-param PosInterface::CURRENCY_* $currency
+ *
+ * @param string $currency
+ *
+ * @return string|int
+ */
+ public function mapCurrency(string $currency);
+
+ /**
+ * @return non-empty-array
+ */
+ public function getCurrencyMappings(): array;
+
+ /**
+ * @param PosInterface::LANG_* $lang
+ *
+ * @return string
+ */
+ public function mapLang(string $lang): string;
+
+ /**
+ * @return array
+ */
+ public function getLangMappings(): array;
+
+ /**
+ * @return array<'DAY'|'WEEK'|'MONTH'|'YEAR', string>
+ */
+ public function getRecurringOrderFrequencyMappings(): array;
+
+ /**
+ * @param string $period
+ *
+ * @return string
+ */
+ public function mapRecurringFrequency(string $period): string;
+
+ /**
+ * @return array
+ */
+ public function getCardTypeMappings(): array;
+
+ /**
+ * @param CreditCardInterface::CARD_TYPE_* $cardType
+ *
+ * @return string
+ */
+ public function mapCardType(string $cardType): string;
+}
diff --git a/src/DataMapper/RequestValueMapper/ToslaPosRequestValueMapper.php b/src/DataMapper/RequestValueMapper/ToslaPosRequestValueMapper.php
new file mode 100644
index 00000000..a0675cfa
--- /dev/null
+++ b/src/DataMapper/RequestValueMapper/ToslaPosRequestValueMapper.php
@@ -0,0 +1,32 @@
+ '1',
+ PosInterface::TX_TYPE_PAY_PRE_AUTH => '2',
+ PosInterface::TX_TYPE_PAY_POST_AUTH => '3',
+ PosInterface::TX_TYPE_CANCEL => '4',
+ PosInterface::TX_TYPE_REFUND => '5',
+ PosInterface::TX_TYPE_REFUND_PARTIAL => '5',
+ ];
+
+ /**
+ * @inheritDoc
+ *
+ * @return int
+ */
+ public function mapCurrency(string $currency): int
+ {
+ return (int) $this->currencyMappings[$currency];
+ }
+}
diff --git a/src/DataMapper/RequestValueMapper/VakifKatilimPosRequestValueMapper.php b/src/DataMapper/RequestValueMapper/VakifKatilimPosRequestValueMapper.php
new file mode 100644
index 00000000..b688c01a
--- /dev/null
+++ b/src/DataMapper/RequestValueMapper/VakifKatilimPosRequestValueMapper.php
@@ -0,0 +1,42 @@
+ '0949',
+ PosInterface::CURRENCY_USD => '0840',
+ PosInterface::CURRENCY_EUR => '0978',
+ PosInterface::CURRENCY_GBP => '0826',
+ PosInterface::CURRENCY_JPY => '0392',
+ PosInterface::CURRENCY_RUB => '0810',
+ ];
+
+ /**
+ * {@inheritdoc}
+ */
+ protected array $secureTypeMappings = [
+ PosInterface::MODEL_3D_SECURE => '3',
+ PosInterface::MODEL_NON_SECURE => '5',
+ ];
+
+ /**
+ * @inheritDoc
+ *
+ * @return string
+ */
+ public function mapCurrency(string $currency): string
+ {
+ return (string) $this->currencyMappings[$currency];
+ }
+}
diff --git a/src/DataMapper/ResponseDataMapper/AbstractResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/AbstractResponseDataMapper.php
index ba6f8031..849d94ba 100644
--- a/src/DataMapper/ResponseDataMapper/AbstractResponseDataMapper.php
+++ b/src/DataMapper/ResponseDataMapper/AbstractResponseDataMapper.php
@@ -15,7 +15,7 @@ abstract class AbstractResponseDataMapper implements ResponseDataMapperInterface
protected LoggerInterface $logger;
- /** @var array */
+ /** @var array */
protected array $currencyMappings;
/** @var array> */
@@ -25,10 +25,10 @@ abstract class AbstractResponseDataMapper implements ResponseDataMapperInterface
protected array $secureTypeMappings;
/**
- * @param array $currencyMappings
- * @param array $txTypeMappings
- * @param array $secureTypeMappings
- * @param LoggerInterface $logger
+ * @param array $currencyMappings
+ * @param array> $txTypeMappings
+ * @param array $secureTypeMappings
+ * @param LoggerInterface $logger
*/
public function __construct(array $currencyMappings, array $txTypeMappings, array $secureTypeMappings, LoggerInterface $logger)
{
diff --git a/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php
index fc36f6e2..59614cd2 100644
--- a/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php
+++ b/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php
@@ -29,10 +29,10 @@ class PayFlexV4PosResponseDataMapper extends AbstractResponseDataMapper
];
/**
- * @param array $currencyMappings
- * @param array $txTypeMappings
- * @param array $secureTypeMappings
- * @param LoggerInterface $logger
+ * @param array $currencyMappings
+ * @param array> $txTypeMappings
+ * @param array $secureTypeMappings
+ * @param LoggerInterface $logger
*/
public function __construct(array $currencyMappings, array $txTypeMappings, array $secureTypeMappings, LoggerInterface $logger)
{
diff --git a/src/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapper.php
index 7d1c0514..3ce8f04b 100644
--- a/src/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapper.php
+++ b/src/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapper.php
@@ -44,10 +44,10 @@ class PosNetV1PosResponseDataMapper extends AbstractResponseDataMapper
];
/**
- * @param array $currencyMappings
- * @param array $txTypeMappings
- * @param array $secureTypeMappings
- * @param LoggerInterface $logger
+ * @param array $currencyMappings
+ * @param array> $txTypeMappings
+ * @param array $secureTypeMappings
+ * @param LoggerInterface $logger
*/
public function __construct(array $currencyMappings, array $txTypeMappings, array $secureTypeMappings, LoggerInterface $logger)
{
diff --git a/src/Entity/Card/AbstractCreditCard.php b/src/Entity/Card/AbstractCreditCard.php
index fa45a71e..88b3f2d5 100644
--- a/src/Entity/Card/AbstractCreditCard.php
+++ b/src/Entity/Card/AbstractCreditCard.php
@@ -64,25 +64,9 @@ public function getNumber(): string
/**
* @inheritDoc
*/
- public function getExpireYear(string $format = 'y'): string
+ public function getExpirationDate(): \DateTimeImmutable
{
- return $this->expDate->format($format);
- }
-
- /**
- * @inheritDoc
- */
- public function getExpireMonth(string $format = 'm'): string
- {
- return $this->expDate->format($format);
- }
-
- /**
- * @inheritDoc
- */
- public function getExpirationDate(string $format = 'ym'): string
- {
- return $this->expDate->format($format);
+ return $this->expDate;
}
/**
diff --git a/src/Entity/Card/CreditCardInterface.php b/src/Entity/Card/CreditCardInterface.php
index b805ea4d..dbb6b80f 100644
--- a/src/Entity/Card/CreditCardInterface.php
+++ b/src/Entity/Card/CreditCardInterface.php
@@ -29,31 +29,9 @@ interface CreditCardInterface
public function getNumber(): string;
/**
- * returns exp year in 2 digit format
- *
- * @param string $format
- *
- * @return string
- */
- public function getExpireYear(string $format = 'y'): string;
-
- /**
- * returns exp year in 2 digit format. i.e '01' '02' '12'
- *
- * @param string $format
- *
- * @return string
- */
- public function getExpireMonth(string $format = 'm'): string;
-
- /**
- * returns card exp date month and year combined.
- *
- * @param string $format
- *
- * @return string
+ * @return \DateTimeImmutable
*/
- public function getExpirationDate(string $format = 'ym'): string;
+ public function getExpirationDate(): \DateTimeImmutable;
/**
* @return string
diff --git a/src/Factory/PosFactory.php b/src/Factory/PosFactory.php
index 87a17f6f..f2bf34d6 100644
--- a/src/Factory/PosFactory.php
+++ b/src/Factory/PosFactory.php
@@ -67,22 +67,26 @@ public static function createPosGateway(
);
}
- $currencies = [];
- if (isset($config['currencies'])) {
- $currencies = $config['currencies'];
- }
-
$logger->debug('creating gateway for bank', ['bank' => $posAccount->getBank()]);
$crypt = CryptFactory::createGatewayCrypt($class, $logger);
- $requestDataMapper = RequestDataMapperFactory::createGatewayRequestMapper($class, $eventDispatcher, $crypt, $currencies);
- $responseDataMapper = ResponseDataMapperFactory::createGatewayResponseMapper($class, $requestDataMapper, $logger);
+ $valueMapper = RequestValueMapperFactory::createForGateway($class);
+ $valueFormatter = RequestValueFormatterFactory::createForGateway($class);
+ $requestDataMapper = RequestDataMapperFactory::createGatewayRequestMapper(
+ $class,
+ $valueMapper,
+ $valueFormatter,
+ $eventDispatcher,
+ $crypt,
+ );
+ $responseDataMapper = ResponseDataMapperFactory::createGatewayResponseMapper($class, $valueMapper, $logger);
$serializer = SerializerFactory::createGatewaySerializer($class);
// Create Bank Class Instance
return new $class(
$config['banks'][$posAccount->getBank()],
$posAccount,
+ $valueMapper,
$requestDataMapper,
$responseDataMapper,
$serializer,
diff --git a/src/Factory/RequestDataMapperFactory.php b/src/Factory/RequestDataMapperFactory.php
index 72e81a54..dfd84302 100644
--- a/src/Factory/RequestDataMapperFactory.php
+++ b/src/Factory/RequestDataMapperFactory.php
@@ -21,6 +21,8 @@
use Mews\Pos\DataMapper\RequestDataMapper\RequestDataMapperInterface;
use Mews\Pos\DataMapper\RequestDataMapper\ToslaPosRequestDataMapper;
use Mews\Pos\DataMapper\RequestDataMapper\VakifKatilimPosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueFormatter\RequestValueFormatterInterface;
+use Mews\Pos\DataMapper\RequestValueMapper\RequestValueMapperInterface;
use Mews\Pos\Gateways\AkbankPos;
use Mews\Pos\Gateways\EstPos;
use Mews\Pos\Gateways\EstV3Pos;
@@ -34,7 +36,6 @@
use Mews\Pos\Gateways\PosNetV1Pos;
use Mews\Pos\Gateways\ToslaPos;
use Mews\Pos\Gateways\VakifKatilimPos;
-use Mews\Pos\PosInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
/**
@@ -43,14 +44,21 @@
class RequestDataMapperFactory
{
/**
- * @param class-string $gatewayClass
- * @param EventDispatcherInterface $eventDispatcher
- * @param CryptInterface $crypt
- * @param array $currencies
+ * @param class-string $gatewayClass
+ * @param RequestValueMapperInterface $valueMapper
+ * @param RequestValueFormatterInterface $valueFormatter
+ * @param EventDispatcherInterface $eventDispatcher
+ * @param CryptInterface $crypt
*
* @return RequestDataMapperInterface
*/
- public static function createGatewayRequestMapper(string $gatewayClass, EventDispatcherInterface $eventDispatcher, CryptInterface $crypt, array $currencies = []): RequestDataMapperInterface
+ public static function createGatewayRequestMapper(
+ string $gatewayClass,
+ RequestValueMapperInterface $valueMapper,
+ RequestValueFormatterInterface $valueFormatter,
+ EventDispatcherInterface $eventDispatcher,
+ CryptInterface $crypt
+ ): RequestDataMapperInterface
{
$classMappings = [
ToslaPos::class => ToslaPosRequestDataMapper::class,
@@ -68,7 +76,7 @@ public static function createGatewayRequestMapper(string $gatewayClass, EventDis
PayFlexV4Pos::class => PayFlexV4PosRequestDataMapper::class,
];
if (isset($classMappings[$gatewayClass])) {
- return new $classMappings[$gatewayClass]($eventDispatcher, $crypt, $currencies);
+ return new $classMappings[$gatewayClass]($valueMapper, $valueFormatter, $eventDispatcher, $crypt);
}
throw new DomainException('unsupported gateway');
diff --git a/src/Factory/RequestValueFormatterFactory.php b/src/Factory/RequestValueFormatterFactory.php
new file mode 100644
index 00000000..d0ba8585
--- /dev/null
+++ b/src/Factory/RequestValueFormatterFactory.php
@@ -0,0 +1,70 @@
+ ToslaPosRequestValueFormatter::class,
+ AkbankPos::class => AkbankPosRequestValueFormatter::class,
+ EstPos::class => EstPosRequestValueFormatter::class,
+ EstV3Pos::class => EstPosRequestValueFormatter::class,
+ GarantiPos::class => GarantiPosRequestValueFormatter::class,
+ InterPos::class => InterPosRequestValueFormatter::class,
+ KuveytPos::class => KuveytPosRequestValueFormatter::class,
+ VakifKatilimPos::class => VakifKatilimPosRequestValueFormatter::class,
+ PayForPos::class => PayForPosRequestValueFormatter::class,
+ PosNet::class => PosNetRequestValueFormatter::class,
+ PosNetV1Pos::class => PosNetV1PosRequestValueFormatter::class,
+ PayFlexCPV4Pos::class => PayFlexCPV4PosRequestValueFormatter::class,
+ PayFlexV4Pos::class => PayFlexV4PosRequestValueFormatter::class,
+ ];
+
+ if (isset($classMappings[$gatewayClass])) {
+ return new $classMappings[$gatewayClass]();
+ }
+
+ throw new DomainException('unsupported gateway');
+ }
+}
diff --git a/src/Factory/RequestValueMapperFactory.php b/src/Factory/RequestValueMapperFactory.php
new file mode 100644
index 00000000..524dc372
--- /dev/null
+++ b/src/Factory/RequestValueMapperFactory.php
@@ -0,0 +1,70 @@
+ ToslaPosRequestValueMapper::class,
+ AkbankPos::class => AkbankPosRequestValueMapper::class,
+ EstPos::class => EstPosRequestValueMapper::class,
+ EstV3Pos::class => EstPosRequestValueMapper::class,
+ GarantiPos::class => GarantiPosRequestValueMapper::class,
+ InterPos::class => InterPosRequestValueMapper::class,
+ KuveytPos::class => KuveytPosRequestValueMapper::class,
+ VakifKatilimPos::class => VakifKatilimPosRequestValueMapper::class,
+ PayForPos::class => PayForPosRequestValueMapper::class,
+ PosNet::class => PosNetRequestValueMapper::class,
+ PosNetV1Pos::class => PosNetV1PosRequestValueMapper::class,
+ PayFlexCPV4Pos::class => PayFlexCPV4PosRequestValueMapper::class,
+ PayFlexV4Pos::class => PayFlexV4PosRequestValueMapper::class,
+ ];
+
+ if (isset($classMappings[$gatewayClass])) {
+ return new $classMappings[$gatewayClass]();
+ }
+
+ throw new DomainException('unsupported gateway');
+ }
+}
diff --git a/src/Factory/ResponseDataMapperFactory.php b/src/Factory/ResponseDataMapperFactory.php
index 8a7f45da..29d97505 100644
--- a/src/Factory/ResponseDataMapperFactory.php
+++ b/src/Factory/ResponseDataMapperFactory.php
@@ -6,7 +6,7 @@
namespace Mews\Pos\Factory;
use DomainException;
-use Mews\Pos\DataMapper\RequestDataMapper\RequestDataMapperInterface;
+use Mews\Pos\DataMapper\RequestValueMapper\RequestValueMapperInterface;
use Mews\Pos\DataMapper\ResponseDataMapper\AkbankPosResponseDataMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\EstPosResponseDataMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\GarantiPosResponseDataMapper;
@@ -41,13 +41,17 @@
class ResponseDataMapperFactory
{
/**
- * @param class-string $gatewayClass
- * @param RequestDataMapperInterface $requestDataMapper
- * @param LoggerInterface $logger
+ * @param class-string $gatewayClass
+ * @param RequestValueMapperInterface $valueMapper
+ * @param LoggerInterface $logger
*
* @return ResponseDataMapperInterface
*/
- public static function createGatewayResponseMapper(string $gatewayClass, RequestDataMapperInterface $requestDataMapper, LoggerInterface $logger): ResponseDataMapperInterface
+ public static function createGatewayResponseMapper(
+ string $gatewayClass,
+ RequestValueMapperInterface $valueMapper,
+ LoggerInterface $logger
+ ): ResponseDataMapperInterface
{
$classMappings = [
ToslaPos::class => ToslaPosResponseDataMapper::class,
@@ -67,9 +71,9 @@ public static function createGatewayResponseMapper(string $gatewayClass, Request
if (isset($classMappings[$gatewayClass])) {
return new $classMappings[$gatewayClass](
- $requestDataMapper->getCurrencyMappings(),
- $requestDataMapper->getTxTypeMappings(),
- $requestDataMapper->getSecureTypeMappings(),
+ $valueMapper->getCurrencyMappings(),
+ $valueMapper->getTxTypeMappings(),
+ $valueMapper->getSecureTypeMappings(),
$logger
);
}
diff --git a/src/Gateways/AbstractGateway.php b/src/Gateways/AbstractGateway.php
index 4fd2b332..a9013544 100644
--- a/src/Gateways/AbstractGateway.php
+++ b/src/Gateways/AbstractGateway.php
@@ -8,6 +8,7 @@
use LogicException;
use Mews\Pos\Client\HttpClient;
use Mews\Pos\DataMapper\RequestDataMapper\RequestDataMapperInterface;
+use Mews\Pos\DataMapper\RequestValueMapper\RequestValueMapperInterface;
use Mews\Pos\DataMapper\ResponseDataMapper\ResponseDataMapperInterface;
use Mews\Pos\Entity\Account\AbstractPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
@@ -43,6 +44,8 @@ abstract class AbstractGateway implements PosInterface
protected HttpClient $client;
+ protected RequestValueMapperInterface $valueMapper;
+
protected RequestDataMapperInterface $requestDataMapper;
protected ResponseDataMapperInterface $responseDataMapper;
@@ -66,6 +69,7 @@ abstract class AbstractGateway implements PosInterface
public function __construct(
array $config,
AbstractPosAccount $posAccount,
+ RequestValueMapperInterface $valueMapper,
RequestDataMapperInterface $requestDataMapper,
ResponseDataMapperInterface $responseDataMapper,
SerializerInterface $serializer,
@@ -74,6 +78,7 @@ public function __construct(
LoggerInterface $logger
)
{
+ $this->valueMapper = $valueMapper;
$this->requestDataMapper = $requestDataMapper;
$this->responseDataMapper = $responseDataMapper;
$this->serializer = $serializer;
@@ -98,7 +103,7 @@ public function getResponse(): ?array
*/
public function getCurrencies(): array
{
- return \array_keys($this->requestDataMapper->getCurrencyMappings());
+ return \array_keys($this->valueMapper->getCurrencyMappings());
}
/**
@@ -538,7 +543,7 @@ public function setTestMode(bool $testMode): PosInterface
*/
public function getCardTypeMapping(): array
{
- return $this->requestDataMapper->getCardTypeMapping();
+ return $this->valueMapper->getCardTypeMappings();
}
/**
@@ -546,7 +551,7 @@ public function getCardTypeMapping(): array
*/
public function getLanguages(): array
{
- return [PosInterface::LANG_TR, PosInterface::LANG_EN];
+ return \array_keys($this->valueMapper->getLangMappings());
}
/**
diff --git a/src/Gateways/PosNetV1Pos.php b/src/Gateways/PosNetV1Pos.php
index d869868d..b238b88f 100644
--- a/src/Gateways/PosNetV1Pos.php
+++ b/src/Gateways/PosNetV1Pos.php
@@ -65,7 +65,7 @@ public function getAccount(): AbstractPosAccount
public function getApiURL(string $txType = null, string $paymentModel = null, ?string $orderTxType = null): string
{
if (null !== $txType) {
- return parent::getApiURL().'/'.$this->requestDataMapper->mapTxType($txType);
+ return parent::getApiURL().'/'.$this->valueMapper->mapTxType($txType);
}
throw new \InvalidArgumentException('Transaction type is required to generate API URL');
diff --git a/tests/Unit/DataMapper/RequestDataMapper/AkbankPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/AkbankPosRequestDataMapperTest.php
index 565386b8..f696b83e 100644
--- a/tests/Unit/DataMapper/RequestDataMapper/AkbankPosRequestDataMapperTest.php
+++ b/tests/Unit/DataMapper/RequestDataMapper/AkbankPosRequestDataMapperTest.php
@@ -7,10 +7,11 @@
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\AkbankPosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueFormatter\AkbankPosRequestValueFormatter;
+use Mews\Pos\DataMapper\RequestValueMapper\AkbankPosRequestValueMapper;
use Mews\Pos\Entity\Account\AkbankPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\Before3DFormHashCalculatedEvent;
-use Mews\Pos\Exceptions\UnsupportedTransactionTypeException;
use Mews\Pos\Factory\AccountFactory;
use Mews\Pos\Factory\CreditCardFactory;
use Mews\Pos\Gateways\AkbankPos;
@@ -41,6 +42,8 @@ class AkbankPosRequestDataMapperTest extends TestCase
/** @var MockObject|EventDispatcherInterface */
private EventDispatcherInterface $dispatcher;
+ private AkbankPosRequestValueFormatter $valueFormatter;
+ private AkbankPosRequestValueMapper $valueMapper;
protected function setUp(): void
{
@@ -73,62 +76,17 @@ protected function setUp(): void
'fail_url' => 'http:://localhost/fail',
];
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
- $this->crypt = $this->createMock(CryptInterface::class);
+ $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->crypt = $this->createMock(CryptInterface::class);
+ $this->valueFormatter = new AkbankPosRequestValueFormatter();
+ $this->valueMapper = new AkbankPosRequestValueMapper();
- $this->requestDataMapper = new AkbankPosRequestDataMapper($this->dispatcher, $this->crypt);
- }
-
- /**
- * @testWith ["pay", "3d", "3000"]
- * ["pre", "3d", "3004"]
- * ["pre", "regular", "1004"]
- */
- public function testMapTxType(string $txType, string $paymentModel, string $expected): void
- {
- $actual = $this->requestDataMapper->mapTxType($txType, $paymentModel);
- $this->assertSame($expected, $actual);
- }
-
- /**
- * @testWith ["1"]
- */
- public function testMapTxTypeException(string $txType): void
- {
- $this->expectException(UnsupportedTransactionTypeException::class);
- $this->requestDataMapper->mapTxType($txType);
- }
-
-
- /**
- * @return void
- */
- public function testMapCurrency(): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapCurrency');
- $method->setAccessible(true);
- $this->assertSame(949, $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_TRY]));
- $this->assertSame(978, $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_EUR]));
- }
-
- /**
- * @param string|int|null $installment
- * @param string|int $expected
- *
- * @testWith ["0", 1]
- * ["1", 1]
- * ["2", 2]
- * [2, 2]
- *
- * @return void
- */
- public function testMapInstallment($installment, $expected): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapInstallment');
- $method->setAccessible(true);
- $this->assertSame($expected, $method->invokeArgs($this->requestDataMapper, [$installment]));
+ $this->requestDataMapper = new AkbankPosRequestDataMapper(
+ $this->valueMapper,
+ $this->valueFormatter,
+ $this->dispatcher,
+ $this->crypt,
+ );
}
/**
diff --git a/tests/Unit/DataMapper/RequestDataMapper/EstPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/EstPosRequestDataMapperTest.php
index 72343c90..f31d5779 100644
--- a/tests/Unit/DataMapper/RequestDataMapper/EstPosRequestDataMapperTest.php
+++ b/tests/Unit/DataMapper/RequestDataMapper/EstPosRequestDataMapperTest.php
@@ -7,11 +7,12 @@
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\EstPosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueFormatter\EstPosRequestValueFormatter;
+use Mews\Pos\DataMapper\RequestValueMapper\EstPosRequestValueMapper;
use Mews\Pos\Entity\Account\AbstractPosAccount;
use Mews\Pos\Entity\Account\EstPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\Before3DFormHashCalculatedEvent;
-use Mews\Pos\Exceptions\UnsupportedTransactionTypeException;
use Mews\Pos\Factory\AccountFactory;
use Mews\Pos\Factory\CreditCardFactory;
use Mews\Pos\Gateways\EstPos;
@@ -37,9 +38,8 @@ class EstPosRequestDataMapperTest extends TestCase
/** @var EventDispatcherInterface & MockObject */
private EventDispatcherInterface $dispatcher;
-
- private array $order;
-
+ private EstPosRequestValueFormatter $valueFormatter;
+ private EstPosRequestValueMapper $valueMapper;
protected function setUp(): void
{
parent::setUp();
@@ -53,20 +53,17 @@ protected function setUp(): void
'TRPS0200'
);
- $this->order = [
- 'id' => 'order222',
- 'ip' => '127.0.0.1',
- 'amount' => '100.25',
- 'installment' => 0,
- 'currency' => PosInterface::CURRENCY_TRY,
- 'success_url' => 'https://domain.com/success',
- 'fail_url' => 'https://domain.com/fail_url',
- 'lang' => PosInterface::LANG_TR,
- ];
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
- $this->crypt = $this->createMock(CryptInterface::class);
+ $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->crypt = $this->createMock(CryptInterface::class);
+ $this->valueFormatter = new EstPosRequestValueFormatter();
+ $this->valueMapper = new EstPosRequestValueMapper();
- $this->requestDataMapper = new EstPosRequestDataMapper($this->dispatcher, $this->crypt);
+ $this->requestDataMapper = new EstPosRequestDataMapper(
+ $this->valueMapper,
+ $this->valueFormatter,
+ $this->dispatcher,
+ $this->crypt,
+ );
$this->card = CreditCardFactory::create(
'5555444433332222',
'22',
@@ -76,68 +73,6 @@ protected function setUp(): void
);
}
- /**
- * @testWith ["MONTH", "M"]
- * ["M", "M"]
- */
- 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
- */
- public function testMapCurrency(): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapCurrency');
- $method->setAccessible(true);
- $this->assertSame('949', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_TRY]));
- $this->assertSame('978', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_EUR]));
- }
-
- /**
- * @testWith ["pay", "Auth"]
- * ["pre", "PreAuth"]
- */
- public function testMapTxType(string $txType, string $expected): void
- {
- $actual = $this->requestDataMapper->mapTxType($txType);
- $this->assertSame($expected, $actual);
- }
-
- /**
- * @testWith ["Auth"]
- */
- public function testMapTxTypeException(string $txType): void
- {
- $this->expectException(UnsupportedTransactionTypeException::class);
- $this->requestDataMapper->mapTxType($txType);
- }
-
- /**
- * @param string|int|null $installment
- * @param string|int $expected
- *
- * @testWith ["0", ""]
- * ["1", ""]
- * ["2", "2"]
- * [2, "2"]
- *
- * @return void
- */
- public function testMapInstallment($installment, $expected): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapInstallment');
- $method->setAccessible(true);
- $this->assertSame($expected, $method->invokeArgs($this->requestDataMapper, [$installment]));
- }
-
/**
* @dataProvider postAuthRequestDataProvider
*/
@@ -472,7 +407,7 @@ public static function postAuthRequestDataProvider(): array
'ClientId' => '700655000200',
'Type' => 'PostAuth',
'OrderId' => '2020110828BC',
- 'Total' => 1.0,
+ 'Total' => '1',
],
],
'with_pre_auth_amount' => [
@@ -487,9 +422,9 @@ public static function postAuthRequestDataProvider(): array
'ClientId' => '700655000200',
'Type' => 'PostAuth',
'OrderId' => '2020110828BC',
- 'Total' => 1.1,
+ 'Total' => '1.1',
'Extra' => [
- 'PREAMT' => 1.0,
+ 'PREAMT' => '1',
],
],
],
diff --git a/tests/Unit/DataMapper/RequestDataMapper/EstV3PosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/EstV3PosRequestDataMapperTest.php
index 7aa128e2..d35f51f3 100644
--- a/tests/Unit/DataMapper/RequestDataMapper/EstV3PosRequestDataMapperTest.php
+++ b/tests/Unit/DataMapper/RequestDataMapper/EstV3PosRequestDataMapperTest.php
@@ -7,6 +7,8 @@
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\EstV3PosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueFormatter\EstPosRequestValueFormatter;
+use Mews\Pos\DataMapper\RequestValueMapper\EstPosRequestValueMapper;
use Mews\Pos\Entity\Account\EstPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\Before3DFormHashCalculatedEvent;
@@ -20,6 +22,7 @@
/**
* @covers \Mews\Pos\DataMapper\RequestDataMapper\EstV3PosRequestDataMapper
+ * @covers \Mews\Pos\DataMapper\RequestDataMapper\AbstractRequestDataMapper
*/
class EstV3PosRequestDataMapperTest extends TestCase
{
@@ -34,7 +37,8 @@ class EstV3PosRequestDataMapperTest extends TestCase
/** @var EventDispatcherInterface & MockObject */
private EventDispatcherInterface $dispatcher;
-
+ private EstPosRequestValueFormatter $valueFormatter;
+ private EstPosRequestValueMapper $valueMapper;
protected function setUp(): void
{
parent::setUp();
@@ -48,11 +52,19 @@ protected function setUp(): void
'123456'
);
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->crypt = $this->createMock(CryptInterface::class);
+ $this->valueFormatter = new EstPosRequestValueFormatter();
+ $this->valueMapper = new EstPosRequestValueMapper();
+
+ $this->requestDataMapper = new EstV3PosRequestDataMapper(
+ $this->valueMapper,
+ $this->valueFormatter,
+ $this->dispatcher,
+ $this->crypt
+ );
- $this->crypt = $this->createMock(CryptInterface::class);
- $this->requestDataMapper = new EstV3PosRequestDataMapper($this->dispatcher, $this->crypt);
- $this->card = CreditCardFactory::create('5555444433332222', '22', '01', '123', 'ahmet', CreditCardInterface::CARD_TYPE_VISA);
+ $this->card = CreditCardFactory::create('5555444433332222', '22', '01', '123', 'ahmet', CreditCardInterface::CARD_TYPE_VISA);
}
/**
diff --git a/tests/Unit/DataMapper/RequestDataMapper/GarantiPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/GarantiPosRequestDataMapperTest.php
index 40eea299..620ba559 100644
--- a/tests/Unit/DataMapper/RequestDataMapper/GarantiPosRequestDataMapperTest.php
+++ b/tests/Unit/DataMapper/RequestDataMapper/GarantiPosRequestDataMapperTest.php
@@ -7,10 +7,11 @@
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\GarantiPosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueFormatter\GarantiPosRequestValueFormatter;
+use Mews\Pos\DataMapper\RequestValueMapper\GarantiPosRequestValueMapper;
use Mews\Pos\Entity\Account\GarantiPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\Before3DFormHashCalculatedEvent;
-use Mews\Pos\Exceptions\UnsupportedTransactionTypeException;
use Mews\Pos\Factory\AccountFactory;
use Mews\Pos\Factory\CreditCardFactory;
use Mews\Pos\Gateways\GarantiPos;
@@ -37,6 +38,9 @@ class GarantiPosRequestDataMapperTest extends TestCase
/** @var CryptInterface & MockObject */
private CryptInterface $crypt;
+ private GarantiPosRequestValueFormatter $valueFormatter;
+ private GarantiPosRequestValueMapper $valueMapper;
+
protected function setUp(): void
{
parent::setUp();
@@ -53,75 +57,21 @@ protected function setUp(): void
'123qweASD/'
);
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
- $this->crypt = $this->createMock(CryptInterface::class);
- $this->requestDataMapper = new GarantiPosRequestDataMapper($this->dispatcher, $this->crypt);
- $this->requestDataMapper->setTestMode(true);
-
- $this->card = CreditCardFactory::create('5555444433332222', '22', '01', '123', 'ahmet');
- }
-
- /**
- * @testWith ["pay", "sales"]
- * ["pre", "preauth"]
- */
- public function testMapTxType(string $txType, string $expected): void
- {
- $actual = $this->requestDataMapper->mapTxType($txType);
- $this->assertSame($expected, $actual);
- }
-
- /**
- * @testWith ["sales"]
- */
- public function testMapTxTypeException(string $txType): void
- {
- $this->expectException(UnsupportedTransactionTypeException::class);
- $this->requestDataMapper->mapTxType($txType);
- }
+ $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->crypt = $this->createMock(CryptInterface::class);
+ $this->valueFormatter = new GarantiPosRequestValueFormatter();
+ $this->valueMapper = new GarantiPosRequestValueMapper();
- /**
- * @return void
- */
- public function testFormatAmount(): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('formatAmount');
- $method->setAccessible(true);
- $this->assertSame(100000, $method->invokeArgs($this->requestDataMapper, [1000]));
- $this->assertSame(100000, $method->invokeArgs($this->requestDataMapper, [1000.00]));
- $this->assertSame(100001, $method->invokeArgs($this->requestDataMapper, [1000.01]));
- }
+ $this->requestDataMapper = new GarantiPosRequestDataMapper(
+ $this->valueMapper,
+ $this->valueFormatter,
+ $this->dispatcher,
+ $this->crypt,
+ );
- /**
- * @return void
- */
- public function testMapCurrency(): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapCurrency');
- $method->setAccessible(true);
- $this->assertSame('949', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_TRY]));
- $this->assertSame('978', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_EUR]));
- }
+ $this->requestDataMapper->setTestMode(true);
- /**
- * @param string|int|null $installment
- * @param string|int $expected
- *
- * @testWith ["0", ""]
- * ["1", ""]
- * ["2", "2"]
- * [2, "2"]
- *
- * @return void
- */
- public function testMapInstallment($installment, $expected): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapInstallment');
- $method->setAccessible(true);
- $this->assertSame($expected, $method->invokeArgs($this->requestDataMapper, [$installment]));
+ $this->card = CreditCardFactory::create('5555444433332222', '22', '01', '123', 'ahmet');
}
/**
diff --git a/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php
index 76d20879..5101ad1e 100644
--- a/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php
+++ b/tests/Unit/DataMapper/RequestDataMapper/InterPosRequestDataMapperTest.php
@@ -7,10 +7,11 @@
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\InterPosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueFormatter\InterPosRequestValueFormatter;
+use Mews\Pos\DataMapper\RequestValueMapper\InterPosRequestValueMapper;
use Mews\Pos\Entity\Account\InterPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\Before3DFormHashCalculatedEvent;
-use Mews\Pos\Exceptions\UnsupportedTransactionTypeException;
use Mews\Pos\Factory\AccountFactory;
use Mews\Pos\Factory\CreditCardFactory;
use Mews\Pos\Gateways\InterPos;
@@ -37,6 +38,9 @@ class InterPosRequestDataMapperTest extends TestCase
/** @var EventDispatcherInterface & MockObject */
private EventDispatcherInterface $dispatcher;
+ private InterPosRequestValueFormatter $valueFormatter;
+ private InterPosRequestValueMapper $valueMapper;
+
protected function setUp(): void
{
parent::setUp();
@@ -55,61 +59,19 @@ protected function setUp(): void
$merchantPass
);
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
- $this->crypt = $this->createMock(CryptInterface::class);
- $this->requestDataMapper = new InterPosRequestDataMapper($this->dispatcher, $this->crypt);
-
- $this->card = CreditCardFactory::create('5555444433332222', '21', '12', '122', 'ahmet', CreditCardInterface::CARD_TYPE_VISA);
- }
-
- /**
- * @testWith ["pay", "Auth"]
- * ["pre", "PreAuth"]
- */
- public function testMapTxType(string $txType, string $expected): void
- {
- $actual = $this->requestDataMapper->mapTxType($txType);
- $this->assertSame($expected, $actual);
- }
-
- /**
- * @testWith ["PreAuth"]
- */
- public function testMapTxTypeException(string $txType): void
- {
- $this->expectException(UnsupportedTransactionTypeException::class);
- $this->requestDataMapper->mapTxType($txType);
- }
+ $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->crypt = $this->createMock(CryptInterface::class);
+ $this->valueFormatter = new InterPosRequestValueFormatter();
+ $this->valueMapper = new InterPosRequestValueMapper();
- /**
- * @return void
- */
- public function testMapCurrency(): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapCurrency');
- $method->setAccessible(true);
- $this->assertSame('949', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_TRY]));
- $this->assertSame('978', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_EUR]));
- }
+ $this->requestDataMapper = new InterPosRequestDataMapper(
+ $this->valueMapper,
+ $this->valueFormatter,
+ $this->dispatcher,
+ $this->crypt,
+ );
- /**
- * @param string|int|null $installment
- * @param string|int $expected
- *
- * @testWith ["0", ""]
- * ["1", ""]
- * ["2", "2"]
- * [2, "2"]
- *
- * @return void
- */
- public function testMapInstallment($installment, $expected): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapInstallment');
- $method->setAccessible(true);
- $this->assertSame($expected, $method->invokeArgs($this->requestDataMapper, [$installment]));
+ $this->card = CreditCardFactory::create('5555444433332222', '21', '12', '122', 'ahmet', CreditCardInterface::CARD_TYPE_VISA);
}
/**
diff --git a/tests/Unit/DataMapper/RequestDataMapper/KuveytPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/KuveytPosRequestDataMapperTest.php
index 000b1dca..33de8702 100644
--- a/tests/Unit/DataMapper/RequestDataMapper/KuveytPosRequestDataMapperTest.php
+++ b/tests/Unit/DataMapper/RequestDataMapper/KuveytPosRequestDataMapperTest.php
@@ -8,9 +8,10 @@
use Generator;
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\KuveytPosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueFormatter\KuveytPosRequestValueFormatter;
+use Mews\Pos\DataMapper\RequestValueMapper\KuveytPosRequestValueMapper;
use Mews\Pos\Entity\Account\KuveytPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
-use Mews\Pos\Exceptions\UnsupportedTransactionTypeException;
use Mews\Pos\Factory\AccountFactory;
use Mews\Pos\Factory\CreditCardFactory;
use Mews\Pos\PosInterface;
@@ -36,6 +37,9 @@ class KuveytPosRequestDataMapperTest extends TestCase
/** @var EventDispatcherInterface & MockObject */
private EventDispatcherInterface $dispatcher;
+ private KuveytPosRequestValueFormatter $valueFormatter;
+ private KuveytPosRequestValueMapper $valueMapper;
+
protected function setUp(): void
{
parent::setUp();
@@ -48,8 +52,6 @@ protected function setUp(): void
'Api123'
);
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
-
$this->card = CreditCardFactory::create(
'4155650100416111',
25,
@@ -59,71 +61,17 @@ protected function setUp(): void
CreditCardInterface::CARD_TYPE_VISA
);
- $this->crypt = $this->createMock(CryptInterface::class);
- $this->requestDataMapper = new KuveytPosRequestDataMapper($this->dispatcher, $this->crypt);
- }
-
- /**
- * @testWith ["pay", "Sale"]
- */
- public function testMapTxType(string $txType, string $expected): void
- {
- $actual = $this->requestDataMapper->mapTxType($txType);
- $this->assertSame($expected, $actual);
- }
-
- /**
- * @testWith ["Sale"]
- */
- public function testMapTxTypeException(string $txType): void
- {
- $this->expectException(UnsupportedTransactionTypeException::class);
- $this->requestDataMapper->mapTxType($txType);
- }
-
- /**
- * @return void
- */
- public function testFormatAmount(): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('formatAmount');
- $method->setAccessible(true);
- $this->assertSame(0, $method->invokeArgs($this->requestDataMapper, [0]));
- $this->assertSame(0, $method->invokeArgs($this->requestDataMapper, [0.0]));
- $this->assertSame(1025, $method->invokeArgs($this->requestDataMapper, [10.25]));
- $this->assertSame(1000, $method->invokeArgs($this->requestDataMapper, [10.00]));
- }
-
- /**
- * @return void
- */
- public function testMapCurrency(): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapCurrency');
- $method->setAccessible(true);
- $this->assertSame('0949', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_TRY]));
- $this->assertSame('0978', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_EUR]));
- }
+ $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->crypt = $this->createMock(CryptInterface::class);
+ $this->valueFormatter = new KuveytPosRequestValueFormatter();
+ $this->valueMapper = new KuveytPosRequestValueMapper();
- /**
- * @param string|int|null $installment
- * @param string|int $expected
- *
- * @testWith ["0", "0"]
- * ["1", "0"]
- * ["2", "2"]
- * [2, "2"]
- *
- * @return void
- */
- public function testMapInstallment($installment, $expected): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapInstallment');
- $method->setAccessible(true);
- $this->assertSame($expected, $method->invokeArgs($this->requestDataMapper, [$installment]));
+ $this->requestDataMapper = new KuveytPosRequestDataMapper(
+ $this->valueMapper,
+ $this->valueFormatter,
+ $this->dispatcher,
+ $this->crypt,
+ );
}
/**
diff --git a/tests/Unit/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapperTest.php
index 65302c3f..63eeeb45 100644
--- a/tests/Unit/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapperTest.php
+++ b/tests/Unit/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapperTest.php
@@ -7,11 +7,12 @@
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\PayFlexCPV4PosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueFormatter\PayFlexCPV4PosRequestValueFormatter;
+use Mews\Pos\DataMapper\RequestValueMapper\PayFlexCPV4PosRequestValueMapper;
use Mews\Pos\Entity\Account\AbstractPosAccount;
use Mews\Pos\Entity\Account\PayFlexAccount;
use Mews\Pos\Entity\Card\CreditCard;
use Mews\Pos\Entity\Card\CreditCardInterface;
-use Mews\Pos\Exceptions\UnsupportedTransactionTypeException;
use Mews\Pos\Factory\AccountFactory;
use Mews\Pos\Factory\CreditCardFactory;
use Mews\Pos\PosInterface;
@@ -35,6 +36,9 @@ class PayFlexCPV4PosRequestDataMapperTest extends TestCase
/** @var CryptInterface & MockObject */
private CryptInterface $crypt;
+ private PayFlexCPV4PosRequestValueFormatter $valueFormatter;
+ private PayFlexCPV4PosRequestValueMapper $valueMapper;
+
protected function setUp(): void
{
parent::setUp();
@@ -47,70 +51,17 @@ protected function setUp(): void
PosInterface::MODEL_3D_SECURE
);
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
- $this->crypt = $this->createMock(CryptInterface::class);
- $this->requestDataMapper = new PayFlexCPV4PosRequestDataMapper($this->dispatcher, $this->crypt);
- }
-
- /**
- * @testWith ["pay", "Sale"]
- * ["pre", "Auth"]
- */
- public function testMapTxType(string $txType, string $expected): void
- {
- $actual = $this->requestDataMapper->mapTxType($txType);
- $this->assertSame($expected, $actual);
- }
-
- /**
- * @testWith ["Sale"]
- */
- public function testMapTxTypeException(string $txType): void
- {
- $this->expectException(UnsupportedTransactionTypeException::class);
- $this->requestDataMapper->mapTxType($txType);
- }
-
- /**
- * @return void
- */
- public function testFormatAmount(): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('formatAmount');
- $method->setAccessible(true);
- $this->assertSame('1000.00', $method->invokeArgs($this->requestDataMapper, [1000]));
- }
+ $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->crypt = $this->createMock(CryptInterface::class);
+ $this->valueFormatter = new PayFlexCPV4PosRequestValueFormatter();
+ $this->valueMapper = new PayFlexCPV4PosRequestValueMapper();
- /**
- * @return void
- */
- public function testMapCurrency(): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapCurrency');
- $method->setAccessible(true);
- $this->assertSame('949', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_TRY]));
- $this->assertSame('978', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_EUR]));
- }
-
- /**
- * @param string|int|null $installment
- * @param string|int $expected
- *
- * @testWith ["0", "0"]
- * ["1", "0"]
- * ["2", "2"]
- * [2, "2"]
- *
- * @return void
- */
- public function testMapInstallment($installment, $expected): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapInstallment');
- $method->setAccessible(true);
- $this->assertSame($expected, $method->invokeArgs($this->requestDataMapper, [$installment]));
+ $this->requestDataMapper = new PayFlexCPV4PosRequestDataMapper(
+ $this->valueMapper,
+ $this->valueFormatter,
+ $this->dispatcher,
+ $this->crypt,
+ );
}
/**
diff --git a/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php
index d6248ae3..2da40a29 100644
--- a/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php
+++ b/tests/Unit/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapperTest.php
@@ -7,11 +7,12 @@
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\PayFlexV4PosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueFormatter\PayFlexV4PosRequestValueFormatter;
+use Mews\Pos\DataMapper\RequestValueMapper\PayFlexV4PosRequestValueMapper;
use Mews\Pos\Entity\Account\AbstractPosAccount;
use Mews\Pos\Entity\Account\PayFlexAccount;
use Mews\Pos\Entity\Card\CreditCard;
use Mews\Pos\Entity\Card\CreditCardInterface;
-use Mews\Pos\Exceptions\UnsupportedTransactionTypeException;
use Mews\Pos\Factory\AccountFactory;
use Mews\Pos\Factory\CreditCardFactory;
use Mews\Pos\PosInterface;
@@ -35,6 +36,9 @@ class PayFlexV4PosRequestDataMapperTest extends TestCase
/** @var EventDispatcherInterface & MockObject */
private EventDispatcherInterface $dispatcher;
+ private PayFlexV4PosRequestValueFormatter $valueFormatter;
+ private PayFlexV4PosRequestValueMapper $valueMapper;
+
protected function setUp(): void
{
parent::setUp();
@@ -47,82 +51,17 @@ protected function setUp(): void
PosInterface::MODEL_3D_SECURE
);
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
- $this->crypt = $this->createMock(CryptInterface::class);
- $this->requestDataMapper = new PayFlexV4PosRequestDataMapper($this->dispatcher, $this->crypt);
- }
-
- /**
- * @testWith ["pay", "Sale"]
- * ["pre", "Auth"]
- */
- public function testMapTxType(string $txType, string $expected): void
- {
- $actual = $this->requestDataMapper->mapTxType($txType);
- $this->assertSame($expected, $actual);
- }
-
- /**
- * @testWith ["Sale"]
- */
- public function testMapTxTypeException(string $txType): void
- {
- $this->expectException(UnsupportedTransactionTypeException::class);
- $this->requestDataMapper->mapTxType($txType);
- }
-
- /**
- * @return void
- */
- public function testFormatAmount(): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('formatAmount');
- $method->setAccessible(true);
- $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
- */
- public function testMapCurrency(): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapCurrency');
- $method->setAccessible(true);
- $this->assertSame('949', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_TRY]));
- $this->assertSame('978', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_EUR]));
- }
+ $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->crypt = $this->createMock(CryptInterface::class);
+ $this->valueFormatter = new PayFlexV4PosRequestValueFormatter();
+ $this->valueMapper = new PayFlexV4PosRequestValueMapper();
- /**
- * @param string|int|null $installment
- * @param string|int $expected
- *
- * @testWith ["0", "0"]
- * ["1", "0"]
- * ["2", "2"]
- * [2, "2"]
- *
- * @return void
- */
- public function testMapInstallment($installment, $expected): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapInstallment');
- $method->setAccessible(true);
- $this->assertSame($expected, $method->invokeArgs($this->requestDataMapper, [$installment]));
+ $this->requestDataMapper = new PayFlexV4PosRequestDataMapper(
+ $this->valueMapper,
+ $this->valueFormatter,
+ $this->dispatcher,
+ $this->crypt,
+ );
}
/**
diff --git a/tests/Unit/DataMapper/RequestDataMapper/PayForPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PayForPosRequestDataMapperTest.php
index f6c7407d..c4c821a8 100644
--- a/tests/Unit/DataMapper/RequestDataMapper/PayForPosRequestDataMapperTest.php
+++ b/tests/Unit/DataMapper/RequestDataMapper/PayForPosRequestDataMapperTest.php
@@ -7,11 +7,11 @@
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\PayForPosRequestDataMapper;
-use Mews\Pos\Entity\Account\AbstractPosAccount;
+use Mews\Pos\DataMapper\RequestValueFormatter\PayForPosRequestValueFormatter;
+use Mews\Pos\DataMapper\RequestValueMapper\PayForPosRequestValueMapper;
use Mews\Pos\Entity\Account\PayForAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\Before3DFormHashCalculatedEvent;
-use Mews\Pos\Exceptions\UnsupportedTransactionTypeException;
use Mews\Pos\Factory\AccountFactory;
use Mews\Pos\Factory\CreditCardFactory;
use Mews\Pos\Gateways\PayForPos;
@@ -38,6 +38,8 @@ class PayForPosRequestDataMapperTest extends TestCase
/** @var EventDispatcherInterface & MockObject */
private EventDispatcherInterface $dispatcher;
+ private PayForPosRequestValueFormatter $valueFormatter;
+ private PayForPosRequestValueMapper $valueMapper;
protected function setUp(): void
{
@@ -62,61 +64,19 @@ protected function setUp(): void
'lang' => PosInterface::LANG_TR,
];
- $this->crypt = $this->createMock(CryptInterface::class);
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->crypt = $this->createMock(CryptInterface::class);
+ $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->valueFormatter = new PayForPosRequestValueFormatter();
+ $this->valueMapper = new PayForPosRequestValueMapper();
- $this->requestDataMapper = new PayForPosRequestDataMapper($this->dispatcher, $this->crypt);
- $this->card = CreditCardFactory::create('5555444433332222', '22', '01', '123', 'ahmet');
- }
-
- /**
- * @testWith ["pay", "Auth"]
- * ["pre", "PreAuth"]
- */
- public function testMapTxType(string $txType, string $expected): void
- {
- $actual = $this->requestDataMapper->mapTxType($txType);
- $this->assertSame($expected, $actual);
- }
-
- /**
- * @testWith ["PreAuth"]
- */
- public function testMapTxTypeException(string $txType): void
- {
- $this->expectException(UnsupportedTransactionTypeException::class);
- $this->requestDataMapper->mapTxType($txType);
- }
-
- /**
- * @return void
- */
- public function testMapCurrency(): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapCurrency');
- $method->setAccessible(true);
- $this->assertSame('949', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_TRY]));
- $this->assertSame('978', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_EUR]));
- }
+ $this->requestDataMapper = new PayForPosRequestDataMapper(
+ $this->valueMapper,
+ $this->valueFormatter,
+ $this->dispatcher,
+ $this->crypt,
+ );
- /**
- * @param string|int|null $installment
- * @param string|int $expected
- *
- * @testWith ["0", "0"]
- * ["1", "0"]
- * ["2", "2"]
- * [2, "2"]
- *
- * @return void
- */
- public function testMapInstallment($installment, $expected): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapInstallment');
- $method->setAccessible(true);
- $this->assertSame($expected, $method->invokeArgs($this->requestDataMapper, [$installment]));
+ $this->card = CreditCardFactory::create('5555444433332222', '22', '01', '123', 'ahmet');
}
/**
diff --git a/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php
index 6aa18ec8..1b5f2c3f 100644
--- a/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php
+++ b/tests/Unit/DataMapper/RequestDataMapper/PosNetRequestDataMapperTest.php
@@ -8,9 +8,10 @@
use InvalidArgumentException;
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\PosNetRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueFormatter\PosNetRequestValueFormatter;
+use Mews\Pos\DataMapper\RequestValueMapper\PosNetRequestValueMapper;
use Mews\Pos\Entity\Account\PosNetAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
-use Mews\Pos\Exceptions\UnsupportedTransactionTypeException;
use Mews\Pos\Factory\AccountFactory;
use Mews\Pos\Factory\CreditCardFactory;
use Mews\Pos\PosInterface;
@@ -38,6 +39,9 @@ class PosNetRequestDataMapperTest extends TestCase
/** @var CryptInterface & MockObject */
private CryptInterface $crypt;
+ private PosNetRequestValueFormatter $valueFormatter;
+ private PosNetRequestValueMapper $valueMapper;
+
protected function setUp(): void
{
parent::setUp();
@@ -61,102 +65,19 @@ protected function setUp(): void
'lang' => PosInterface::LANG_TR,
];
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
- $this->crypt = $this->createMock(CryptInterface::class);
- $this->requestDataMapper = new PosNetRequestDataMapper($this->dispatcher, $this->crypt);
- $this->card = CreditCardFactory::create('5555444433332222', '22', '01', '123', 'ahmet');
- }
-
- /**
- * @testWith ["pay", "Sale"]
- * ["pre", "Auth"]
- */
- public function testMapTxType(string $txType, string $expected): void
- {
- $actual = $this->requestDataMapper->mapTxType($txType);
- $this->assertSame($expected, $actual);
- }
-
- /**
- * @testWith ["Auth"]
- */
- public function testMapTxTypeException(string $txType): void
- {
- $this->expectException(UnsupportedTransactionTypeException::class);
- $this->requestDataMapper->mapTxType($txType);
- }
-
- /**
- * @return void
- */
- public function testMapCurrency(): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapCurrency');
- $method->setAccessible(true);
- $this->assertSame('TL', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_TRY]));
- $this->assertSame('EU', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_EUR]));
- }
-
- /**
- * @return void
- */
- public function testFormatAmount(): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('formatAmount');
- $method->setAccessible(true);
- $this->assertSame(100000, $method->invokeArgs($this->requestDataMapper, [1000]));
- $this->assertSame(100000, $method->invokeArgs($this->requestDataMapper, [1000.00]));
- $this->assertSame(100001, $method->invokeArgs($this->requestDataMapper, [1000.01]));
- }
-
- /**
- * @param string|int|null $installment
- * @param string|int $expected
- *
- * @testWith ["0", "00"]
- * ["1", "00"]
- * ["2", "02"]
- * ["12", "12"]
- *
- * @return void
- */
- public function testMapInstallment($installment, $expected): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapInstallment');
- $method->setAccessible(true);
- $this->assertSame($expected, $method->invokeArgs($this->requestDataMapper, [$installment]));
- }
-
- /**
- * @return void
- */
- public function testMapOrderIdToPrefixedOrderId(): void
- {
- $this->assertSame('TDSC00000000000000000010', PosNetRequestDataMapper::mapOrderIdToPrefixedOrderId(10, PosInterface::MODEL_3D_SECURE));
- $this->assertSame('000000000000000000000010', PosNetRequestDataMapper::mapOrderIdToPrefixedOrderId(10, PosInterface::MODEL_3D_PAY));
- $this->assertSame('000000000000000000000010', PosNetRequestDataMapper::mapOrderIdToPrefixedOrderId(10, PosInterface::MODEL_NON_SECURE));
- }
+ $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->crypt = $this->createMock(CryptInterface::class);
+ $this->valueFormatter = new PosNetRequestValueFormatter();
+ $this->valueMapper = new PosNetRequestValueMapper();
- /**
- * @return void
- */
- public function testFormatOrderId(): void
- {
- $this->assertSame('0010', PosNetRequestDataMapper::formatOrderId(10, 4));
- $this->assertSame('12345', PosNetRequestDataMapper::formatOrderId(12345, 5));
- $this->assertSame('123456789012345566fm', PosNetRequestDataMapper::formatOrderId('123456789012345566fm'));
- }
+ $this->requestDataMapper = new PosNetRequestDataMapper(
+ $this->valueMapper,
+ $this->valueFormatter,
+ $this->dispatcher,
+ $this->crypt,
+ );
- /**
- * @return void
- */
- public function testFormatOrderIdFail(): void
- {
- $this->expectException(InvalidArgumentException::class);
- PosNetRequestDataMapper::formatOrderId('123456789012345566fml');
+ $this->card = CreditCardFactory::create('5555444433332222', '22', '01', '123', 'ahmet');
}
/**
diff --git a/tests/Unit/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapperTest.php
index 39f952d3..1fbd6600 100644
--- a/tests/Unit/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapperTest.php
+++ b/tests/Unit/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapperTest.php
@@ -5,13 +5,13 @@
namespace Mews\Pos\Tests\Unit\DataMapper\RequestDataMapper;
-use InvalidArgumentException;
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\PosNetV1PosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueFormatter\PosNetV1PosRequestValueFormatter;
+use Mews\Pos\DataMapper\RequestValueMapper\PosNetV1PosRequestValueMapper;
use Mews\Pos\Entity\Account\PosNetAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\Before3DFormHashCalculatedEvent;
-use Mews\Pos\Exceptions\UnsupportedTransactionTypeException;
use Mews\Pos\Factory\AccountFactory;
use Mews\Pos\Factory\CreditCardFactory;
use Mews\Pos\Gateways\PosNetV1Pos;
@@ -38,6 +38,9 @@ class PosNetV1PosRequestDataMapperTest extends TestCase
/** @var CryptInterface & MockObject */
private CryptInterface $crypt;
+ private PosNetV1PosRequestValueFormatter $valueFormatter;
+ private PosNetV1PosRequestValueMapper $valueMapper;
+
protected function setUp(): void
{
parent::setUp();
@@ -51,104 +54,19 @@ protected function setUp(): void
'10,10,10,10,10,10,10,10'
);
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
-
- $this->card = CreditCardFactory::create('5400619360964581', '20', '01', '056', 'ahmet');
-
- $this->crypt = $this->createMock(CryptInterface::class);
- $this->requestDataMapper = new PosNetV1PosRequestDataMapper($this->dispatcher, $this->crypt);
- }
-
- /**
- * @testWith ["pay", "Sale"]
- * ["pre", "Auth"]
- */
- public function testMapTxType(string $txType, string $expected): void
- {
- $actual = $this->requestDataMapper->mapTxType($txType);
- $this->assertSame($expected, $actual);
- }
-
- /**
- * @testWith ["Auth"]
- */
- public function testMapTxTypeException(string $txType): void
- {
- $this->expectException(UnsupportedTransactionTypeException::class);
- $this->requestDataMapper->mapTxType($txType);
- }
-
- /**
- * @return void
- */
- public function testMapCurrency(): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapCurrency');
- $method->setAccessible(true);
- $this->assertSame('TL', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_TRY]));
- $this->assertSame('EU', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_EUR]));
- }
-
- /**
- * @return void
- */
- public function testFormatAmount(): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('formatAmount');
- $method->setAccessible(true);
- $this->assertSame(100000, $method->invokeArgs($this->requestDataMapper, [1000]));
- $this->assertSame(100000, $method->invokeArgs($this->requestDataMapper, [1000.00]));
- $this->assertSame(100001, $method->invokeArgs($this->requestDataMapper, [1000.01]));
- }
-
- /**
- * @param string|int|null $installment
- * @param string|int $expected
- *
- * @testWith ["0", "0"]
- * ["1", "0"]
- * ["2", "2"]
- * ["12", "12"]
- *
- * @return void
- */
- public function testMapInstallment($installment, $expected): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapInstallment');
- $method->setAccessible(true);
- $this->assertSame($expected, $method->invokeArgs($this->requestDataMapper, [$installment]));
- }
-
- /**
- * @return void
- */
- public function testMapOrderIdToPrefixedOrderId(): void
- {
- $this->assertSame('TDS_00000000000000000010', $this->requestDataMapper::mapOrderIdToPrefixedOrderId(10, PosInterface::MODEL_3D_SECURE));
- $this->assertSame('000000000000000000000010', $this->requestDataMapper::mapOrderIdToPrefixedOrderId(10, PosInterface::MODEL_3D_PAY));
- $this->assertSame('000000000000000000000010', $this->requestDataMapper::mapOrderIdToPrefixedOrderId(10, PosInterface::MODEL_NON_SECURE));
- }
+ $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->crypt = $this->createMock(CryptInterface::class);
+ $this->valueFormatter = new PosNetV1PosRequestValueFormatter();
+ $this->valueMapper = new PosNetV1PosRequestValueMapper();
- /**
- * @return void
- */
- public function testFormatOrderId(): void
- {
- $this->assertSame('0010', $this->requestDataMapper::formatOrderId(10, 4));
- $this->assertSame('12345', $this->requestDataMapper::formatOrderId(12345, 5));
- $this->assertSame('123456789012345566fm', $this->requestDataMapper::formatOrderId('123456789012345566fm'));
- }
+ $this->requestDataMapper = new PosNetV1PosRequestDataMapper(
+ $this->valueMapper,
+ $this->valueFormatter,
+ $this->dispatcher,
+ $this->crypt,
+ );
- /**
- * @return void
- */
- public function testFormatOrderIdFail(): void
- {
- $this->expectException(InvalidArgumentException::class);
- $this->requestDataMapper::formatOrderId('123456789012345566fml');
+ $this->card = CreditCardFactory::create('5400619360964581', '20', '01', '056', 'ahmet');
}
/**
@@ -174,7 +92,7 @@ public function testCreateNonSecurePostAuthPaymentRequestData(array $order, arra
*/
public function testCreateNonSecurePaymentRequestData(array $order, array $expectedData): void
{
- $hashCalculationData = $expectedData;
+ $hashCalculationData = $expectedData;
unset($hashCalculationData['MAC']);
$this->crypt->expects(self::once())
@@ -192,7 +110,7 @@ public function testCreateNonSecurePaymentRequestData(array $order, array $expec
*/
public function testCreate3DPaymentRequestData(array $order, string $txType, array $responseData, array $expectedData): void
{
- $hashCalculationData = $expectedData;
+ $hashCalculationData = $expectedData;
unset($hashCalculationData['MAC']);
$this->crypt->expects(self::once())
@@ -219,7 +137,7 @@ public function testCreate3DFormData(array $order, string $txType, string $gatew
&& $paymentModel === $dispatchedEvent->getPaymentModel()
&& count($dispatchedEvent->getFormInputs()) > 3));
- $hashCalculationData = $expected['inputs'];
+ $hashCalculationData = $expected['inputs'];
unset($hashCalculationData['Mac']);
$this->crypt->expects(self::once())
@@ -244,7 +162,7 @@ public function testCreate3DFormData(array $order, string $txType, string $gatew
*/
public function testCreateStatusRequestData(array $order, array $expected): void
{
- $hashCalculationData = $expected;
+ $hashCalculationData = $expected;
unset($hashCalculationData['MAC']);
$this->crypt->expects(self::once())
@@ -261,7 +179,7 @@ public function testCreateStatusRequestData(array $order, array $expected): void
*/
public function testCreateRefundRequestData(array $order, string $txType, array $expected): void
{
- $hashCalculationData = $expected;
+ $hashCalculationData = $expected;
unset($hashCalculationData['MAC']);
$this->crypt->expects(self::once())
@@ -282,7 +200,7 @@ public function testCreateRefundRequestData(array $order, string $txType, array
*/
public function testCreateCancelRequestData(array $order, array $expected): void
{
- $hashCalculationData = $expected;
+ $hashCalculationData = $expected;
unset($hashCalculationData['MAC']);
$this->crypt->expects(self::once())
@@ -314,7 +232,7 @@ public function testCreateOrderHistoryRequestData(): void
*/
public static function threeDFormDataTestProvider(): iterable
{
- $order = [
+ $order = [
'id' => '620093100_024',
'amount' => 1.75,
'installment' => 0,
@@ -322,7 +240,7 @@ public static function threeDFormDataTestProvider(): iterable
'success_url' => 'https://domain.com/success',
'lang' => PosInterface::LANG_TR,
];
- $card = CreditCardFactory::create('5400619360964581', '20', '01', '056', 'ahmet');
+ $card = CreditCardFactory::create('5400619360964581', '20', '01', '056', 'ahmet');
$gatewayUrl = 'https://epostest.albarakaturk.com.tr/ALBSecurePaymentUI/SecureProcess/SecureVerification.aspx';
yield [
diff --git a/tests/Unit/DataMapper/RequestDataMapper/ToslaPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/ToslaPosRequestDataMapperTest.php
index 2556f59f..6f1f8ea2 100644
--- a/tests/Unit/DataMapper/RequestDataMapper/ToslaPosRequestDataMapperTest.php
+++ b/tests/Unit/DataMapper/RequestDataMapper/ToslaPosRequestDataMapperTest.php
@@ -7,9 +7,10 @@
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\ToslaPosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueFormatter\ToslaPosRequestValueFormatter;
+use Mews\Pos\DataMapper\RequestValueMapper\ToslaPosRequestValueMapper;
use Mews\Pos\Entity\Account\ToslaPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
-use Mews\Pos\Exceptions\UnsupportedTransactionTypeException;
use Mews\Pos\Factory\AccountFactory;
use Mews\Pos\Factory\CreditCardFactory;
use Mews\Pos\PosInterface;
@@ -35,6 +36,9 @@ class ToslaPosRequestDataMapperTest extends TestCase
private ToslaPosRequestDataMapper $requestDataMapper;
+ private ToslaPosRequestValueFormatter $valueFormatter;
+ private ToslaPosRequestValueMapper $valueMapper;
+
protected function setUp(): void
{
parent::setUp();
@@ -46,62 +50,19 @@ protected function setUp(): void
'POS_ENT_Test_001!*!*',
);
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
-
- $this->crypt = $this->createMock(CryptInterface::class);
- $this->requestDataMapper = new ToslaPosRequestDataMapper($this->dispatcher, $this->crypt);
- $this->card = CreditCardFactory::create('5555444433332222', '22', '01', '123', 'ahmet', CreditCardInterface::CARD_TYPE_VISA);
- }
+ $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->crypt = $this->createMock(CryptInterface::class);
+ $this->valueFormatter = new ToslaPosRequestValueFormatter();
+ $this->valueMapper = new ToslaPosRequestValueMapper();
- /**
- * @testWith ["pay", "1"]
- * ["pre", "2"]
- */
- public function testMapTxType(string $txType, string $expected): void
- {
- $actual = $this->requestDataMapper->mapTxType($txType);
- $this->assertSame($expected, $actual);
- }
-
- /**
- * @testWith ["1"]
- */
- public function testMapTxTypeException(string $txType): void
- {
- $this->expectException(UnsupportedTransactionTypeException::class);
- $this->requestDataMapper->mapTxType($txType);
- }
-
-
- /**
- * @return void
- */
- public function testMapCurrency(): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapCurrency');
- $method->setAccessible(true);
- $this->assertSame('949', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_TRY]));
- $this->assertSame('978', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_EUR]));
- }
+ $this->requestDataMapper = new ToslaPosRequestDataMapper(
+ $this->valueMapper,
+ $this->valueFormatter,
+ $this->dispatcher,
+ $this->crypt,
+ );
- /**
- * @param string|int|null $installment
- * @param string|int $expected
- *
- * @testWith ["0", "0"]
- * ["1", "0"]
- * ["2", "2"]
- * [2, "2"]
- *
- * @return void
- */
- public function testMapInstallment($installment, $expected): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapInstallment');
- $method->setAccessible(true);
- $this->assertSame($expected, $method->invokeArgs($this->requestDataMapper, [$installment]));
+ $this->card = CreditCardFactory::create('5555444433332222', '22', '01', '123', 'ahmet', CreditCardInterface::CARD_TYPE_VISA);
}
/**
@@ -275,7 +236,7 @@ public static function statusRequestDataProvider(): array
[
'order' => [
'id' => 'id-12',
- 'time_span' => '20231209215355',
+ 'time_span' => new \DateTimeImmutable('20231209215355'),
],
'expected' => [
'clientId' => '1000000494',
@@ -295,7 +256,7 @@ public static function cancelRequestDataProvider(): array
[
'order' => [
'id' => 'id-12',
- 'time_span' => '20231209215355',
+ 'time_span' => new \DateTimeImmutable('20231209215355'),
],
'expected' => [
'clientId' => '1000000494',
@@ -316,7 +277,7 @@ public static function refundRequestDataProvider(): array
'order' => [
'id' => 'id-12',
'amount' => 1.02,
- 'time_span' => '20231209215355',
+ 'time_span' => new \DateTimeImmutable('20231209215355'),
],
'tx_type' => PosInterface::TX_TYPE_REFUND,
'expected' => [
@@ -340,7 +301,7 @@ public static function paymentRegisterRequestDataProvider(): array
'installment' => 0,
'currency' => PosInterface::CURRENCY_TRY,
'success_url' => 'https://domain.com/success',
- 'time_span' => '20231209214708',
+ 'time_span' => new \DateTimeImmutable('20231209214708'),
];
return [
@@ -372,7 +333,7 @@ public static function nonSecurePaymentRequestDataProvider(): array
'installment' => 0,
'currency' => PosInterface::CURRENCY_TRY,
'success_url' => 'https://domain.com/success',
- 'time_span' => '20231209214708',
+ 'time_span' => new \DateTimeImmutable('20231209214708'),
];
return [
@@ -405,7 +366,7 @@ public static function nonSecurePaymentPostRequestDataProvider(): array
'order' => [
'id' => '2020110828BC',
'amount' => 1.10,
- 'time_span' => '20231209213944',
+ 'time_span' => new \DateTimeImmutable('20231209213944'),
],
'expected' => [
'clientId' => '1000000494',
@@ -426,7 +387,7 @@ public static function orderHistoryRequestDataProvider(): array
[
'order' => [
'id' => '2020110828BC',
- 'time_span' => '20231209215355',
+ 'time_span' => new \DateTimeImmutable('20231209215355'),
'transaction_date' => new \DateTime('2023-12-09 00:00:00'),
],
'expected' => [
@@ -444,7 +405,7 @@ public static function orderHistoryRequestDataProvider(): array
[
'order' => [
'id' => '2020110828BC',
- 'time_span' => '20231209215355',
+ 'time_span' => new \DateTimeImmutable('20231209215355'),
'page' => 2,
'page_size' => 5,
'transaction_date' => new \DateTime('2023-12-09 00:00:00'),
@@ -490,7 +451,7 @@ public static function threeDFormDataProvider(): array
'payment_model' => PosInterface::MODEL_3D_PAY,
'is_with_card' => true,
'gateway' => 'https://ent.akodepos.com/api/Payment/ProcessCardForm',
- 'expected' => [
+ 'expected' => [
'gateway' => 'https://ent.akodepos.com/api/Payment/ProcessCardForm',
'method' => 'POST',
'inputs' => [
diff --git a/tests/Unit/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapperTest.php
index a558f77f..faa5c475 100644
--- a/tests/Unit/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapperTest.php
+++ b/tests/Unit/DataMapper/RequestDataMapper/VakifKatilimPosRequestDataMapperTest.php
@@ -8,6 +8,8 @@
use Generator;
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\VakifKatilimPosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueFormatter\VakifKatilimPosRequestValueFormatter;
+use Mews\Pos\DataMapper\RequestValueMapper\VakifKatilimPosRequestValueMapper;
use Mews\Pos\Entity\Account\KuveytPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Factory\AccountFactory;
@@ -35,6 +37,9 @@ class VakifKatilimPosRequestDataMapperTest extends TestCase
/** @var CryptInterface & MockObject */
private CryptInterface $crypt;
+ private VakifKatilimPosRequestValueFormatter $valueFormatter;
+ private VakifKatilimPosRequestValueMapper $valueMapper;
+
protected function setUp(): void
{
parent::setUp();
@@ -55,54 +60,17 @@ protected function setUp(): void
'John Doe',
);
- $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
- $this->crypt = $this->createMock(CryptInterface::class);
- $this->requestDataMapper = new VakifKatilimPosRequestDataMapper($this->dispatcher, $this->crypt);
- }
+ $this->dispatcher = $this->createMock(EventDispatcherInterface::class);
+ $this->crypt = $this->createMock(CryptInterface::class);
+ $this->valueFormatter = new VakifKatilimPosRequestValueFormatter();
+ $this->valueMapper = new VakifKatilimPosRequestValueMapper();
- /**
- * @return void
- */
- public function testFormatAmount(): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('formatAmount');
- $method->setAccessible(true);
- $this->assertSame(0, $method->invokeArgs($this->requestDataMapper, [0]));
- $this->assertSame(0, $method->invokeArgs($this->requestDataMapper, [0.0]));
- $this->assertSame(1025, $method->invokeArgs($this->requestDataMapper, [10.25]));
- $this->assertSame(1000, $method->invokeArgs($this->requestDataMapper, [10.00]));
- }
-
- /**
- * @return void
- */
- public function testMapCurrency(): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapCurrency');
- $method->setAccessible(true);
- $this->assertSame('0949', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_TRY]));
- $this->assertSame('0978', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_EUR]));
- }
-
- /**
- * @param string|int|null $installment
- * @param string|int $expected
- *
- * @testWith ["0", "0"]
- * ["1", "0"]
- * ["2", "2"]
- * [2, "2"]
- *
- * @return void
- */
- public function testMapInstallment($installment, $expected): void
- {
- $class = new \ReflectionObject($this->requestDataMapper);
- $method = $class->getMethod('mapInstallment');
- $method->setAccessible(true);
- $this->assertSame($expected, $method->invokeArgs($this->requestDataMapper, [$installment]));
+ $this->requestDataMapper = new VakifKatilimPosRequestDataMapper(
+ $this->valueMapper,
+ $this->valueFormatter,
+ $this->dispatcher,
+ $this->crypt,
+ );
}
/**
@@ -333,7 +301,7 @@ public function testCreateStatusRequestData(array $order, array $expected): void
*/
public function testCreate3DPaymentRequestData(KuveytPosAccount $kuveytPosAccount, array $order, string $txType, array $responseData, array $expectedData): void
{
- $hashCalculationData = $expectedData;
+ $hashCalculationData = $expectedData;
$hashCalculationData['HashData'] = '';
$this->crypt->expects(self::once())
diff --git a/tests/Unit/DataMapper/RequestValueFormatter/AkbankPosRequestValueFormatterTest.php b/tests/Unit/DataMapper/RequestValueFormatter/AkbankPosRequestValueFormatterTest.php
new file mode 100644
index 00000000..2c334075
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueFormatter/AkbankPosRequestValueFormatterTest.php
@@ -0,0 +1,62 @@
+formatter = new AkbankPosRequestValueFormatter();
+ }
+
+ /**
+ * @testWith [0, 1]
+ * [1, 1]
+ * [2, 2]
+ */
+ public function testFormatInstallment($installment, int $expected): void
+ {
+ $actual = $this->formatter->formatInstallment($installment);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith [1.1, 1.1]
+ */
+ public function testFormatAmount(float $amount, $expected): void
+ {
+ $actual = $this->formatter->formatAmount($amount);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["expiredDate", "0424"]
+ * ["expireDate", "0424"]
+ * ["", "0424"]
+ */
+ public function testFormatCreditCardExpDate(string $fieldName, string $expected): void
+ {
+ $expDate = new \DateTime('2024-04-14T16:45:30.000');
+ $actual = $this->formatter->formatCardExpDate($expDate, $fieldName);
+ $this->assertSame($expected, $actual);
+ }
+
+ public function testFormatDateTime(): void
+ {
+ $dateTime = new \DateTime('2024-04-14T16:45:30.000');
+ $actual = $this->formatter->formatDateTime($dateTime);
+ $this->assertSame('2024-04-14T16:45:30.000', $actual);
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueFormatter/EstPosRequestValueFormatterTest.php b/tests/Unit/DataMapper/RequestValueFormatter/EstPosRequestValueFormatterTest.php
new file mode 100644
index 00000000..d82cf7dc
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueFormatter/EstPosRequestValueFormatterTest.php
@@ -0,0 +1,75 @@
+formatter = new EstPosRequestValueFormatter();
+ }
+
+ /**
+ * @testWith [0, ""]
+ * [1, ""]
+ * [2, "2"]
+ */
+ public function testFormatInstallment($installment, string $expected): void
+ {
+ $actual = $this->formatter->formatInstallment($installment);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith [1.1, "1.1"]
+ * [1.0, "1"]
+ */
+ public function testFormatAmount(float $amount, $expected): void
+ {
+ $actual = $this->formatter->formatAmount($amount);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["abc"]
+ * [""]
+ */
+ public function testFormatCreditCardExpDateUnSupportedField(string $fieldName): void
+ {
+ $expDate = new \DateTime('2024-04-14T16:45:30.000');
+ $this->expectException(\InvalidArgumentException::class);
+ $this->formatter->formatCardExpDate($expDate, $fieldName);
+ }
+
+ /**
+ * @testWith ["Ecom_Payment_Card_ExpDate_Month", "04"]
+ * ["Ecom_Payment_Card_ExpDate_Year", "24"]
+ * ["Expires", "04/24"]
+ */
+ public function testFormatCreditCardExpDate(string $fieldName, string $expected): void
+ {
+ $expDate = new \DateTime('2024-04-14T16:45:30.000');
+ $actual = $this->formatter->formatCardExpDate($expDate, $fieldName);
+ $this->assertSame($expected, $actual);
+ }
+
+ public function testFormatDateTime(): void
+ {
+ $dateTime = new \DateTime('2024-04-14T16:45:30.000');
+ $this->expectException(NotImplementedException::class);
+ $this->formatter->formatDateTime($dateTime);
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueFormatter/GarantiPosRequestValueFormatterTest.php b/tests/Unit/DataMapper/RequestValueFormatter/GarantiPosRequestValueFormatterTest.php
new file mode 100644
index 00000000..810fdfd1
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueFormatter/GarantiPosRequestValueFormatterTest.php
@@ -0,0 +1,101 @@
+formatter = new GarantiPosRequestValueFormatter();
+ }
+
+ /**
+ * @testWith [0, ""]
+ * [1, ""]
+ * [2, "2"]
+ */
+ public function testFormatInstallment($installment, string $expected): void
+ {
+ $actual = $this->formatter->formatInstallment($installment);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith [1.1, 110]
+ * [1.0, 100]
+ */
+ public function testFormatAmount(float $amount, $expected): void
+ {
+ $actual = $this->formatter->formatAmount($amount);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["abc"]
+ * [""]
+ */
+ public function testFormatCreditCardExpDateUnSupportedField(string $fieldName): void
+ {
+ $expDate = new \DateTime('2024-04-14T16:45:30.000');
+ $this->expectException(\InvalidArgumentException::class);
+ $this->formatter->formatCardExpDate($expDate, $fieldName);
+ }
+
+ /**
+ * @testWith ["cardexpiredatemonth", "04"]
+ * ["cardexpiredateyear", "24"]
+ * ["ExpireDate", "0424"]
+ */
+ public function testFormatCreditCardExpDate(string $fieldName, string $expected): void
+ {
+ $expDate = new \DateTime('2024-04-14T16:45:30.000');
+ $actual = $this->formatter->formatCardExpDate($expDate, $fieldName);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @dataProvider formatDateTimeDataProvider
+ */
+ public function testFormatDateTime(\DateTimeInterface $dateTime, ?string $fieldName, ?string $txType, string $expected): void
+ {
+ $actual = $this->formatter->formatDateTime($dateTime, $fieldName, $txType);
+ $this->assertSame($expected, $actual);
+ }
+
+ public static function formatDateTimeDataProvider(): array
+ {
+ return [
+ [
+ new \DateTime('2024-04-14T16:45:30.000'),
+ 'StartDate',
+ PosInterface::TX_TYPE_HISTORY,
+ '14/04/2024 16:45',
+ ],
+ [
+ new \DateTime('2024-04-14T16:45:30.000'),
+ 'EndDate',
+ PosInterface::TX_TYPE_HISTORY,
+ '14/04/2024 16:45',
+ ],
+ [
+ new \DateTime('2024-04-14T16:45:30.000'),
+ null,
+ null,
+ '14/04/2024 16:45',
+ ],
+ ];
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueFormatter/InterPosRequestValueFormatterTest.php b/tests/Unit/DataMapper/RequestValueFormatter/InterPosRequestValueFormatterTest.php
new file mode 100644
index 00000000..d2cccffd
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueFormatter/InterPosRequestValueFormatterTest.php
@@ -0,0 +1,63 @@
+formatter = new InterPosRequestValueFormatter();
+ }
+
+ /**
+ * @testWith [0, ""]
+ * [1, ""]
+ * [2, "2"]
+ */
+ public function testFormatInstallment($installment, string $expected): void
+ {
+ $actual = $this->formatter->formatInstallment($installment);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith [1.1, "1.1"]
+ * [1.0, "1"]
+ */
+ public function testFormatAmount(float $amount, $expected): void
+ {
+ $actual = $this->formatter->formatAmount($amount);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["", "0424"]
+ * ["Expiry", "0424"]
+ */
+ public function testFormatCreditCardExpDate(string $fieldName, string $expected): void
+ {
+ $expDate = new \DateTime('2024-04-14T16:45:30.000');
+ $actual = $this->formatter->formatCardExpDate($expDate, $fieldName);
+ $this->assertSame($expected, $actual);
+ }
+
+ public function testFormatDateTime(): void
+ {
+ $dateTime = new \DateTime('2024-04-14T16:45:30.000');
+ $this->expectException(NotImplementedException::class);
+ $this->formatter->formatDateTime($dateTime);
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueFormatter/KuveytPosRequestValueFormatterTest.php b/tests/Unit/DataMapper/RequestValueFormatter/KuveytPosRequestValueFormatterTest.php
new file mode 100644
index 00000000..9d7c1853
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueFormatter/KuveytPosRequestValueFormatterTest.php
@@ -0,0 +1,73 @@
+formatter = new KuveytPosRequestValueFormatter();
+ }
+
+ /**
+ * @testWith [0, "0"]
+ * [1, "0"]
+ * [2, "2"]
+ */
+ public function testFormatInstallment($installment, string $expected): void
+ {
+ $actual = $this->formatter->formatInstallment($installment);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith [1.1, 110]
+ * [1.0, 100]
+ */
+ public function testFormatAmount(float $amount, $expected): void
+ {
+ $actual = $this->formatter->formatAmount($amount);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["CardExpireDateMonth", "04"]
+ * ["CardExpireDateYear", "24"]
+ */
+ public function testFormatCreditCardExpDate(string $fieldName, string $expected): void
+ {
+ $expDate = new \DateTime('2024-04-14T16:45:30.000');
+ $actual = $this->formatter->formatCardExpDate($expDate, $fieldName);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["abc"]
+ * [""]
+ */
+ public function testFormatCreditCardExpDateUnSupportedField(string $fieldName): void
+ {
+ $expDate = new \DateTime('2024-04-14T16:45:30.000');
+ $this->expectException(\InvalidArgumentException::class);
+ $this->formatter->formatCardExpDate($expDate, $fieldName);
+ }
+
+ public function testFormatDateTime(): void
+ {
+ $dateTime = new \DateTime('2024-04-14T16:45:30.000');
+ $actual = $this->formatter->formatDateTime($dateTime);
+ $this->assertSame('2024-04-14T16:45:30', $actual);
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueFormatter/PayFlexCPV4PosRequestValueFormatterTest.php b/tests/Unit/DataMapper/RequestValueFormatter/PayFlexCPV4PosRequestValueFormatterTest.php
new file mode 100644
index 00000000..8efe1b50
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueFormatter/PayFlexCPV4PosRequestValueFormatterTest.php
@@ -0,0 +1,75 @@
+formatter = new PayFlexCPV4PosRequestValueFormatter();
+ }
+
+ /**
+ * @testWith [0, "0"]
+ * [1, "0"]
+ * [2, "2"]
+ */
+ public function testFormatInstallment($installment, string $expected): void
+ {
+ $actual = $this->formatter->formatInstallment($installment);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith [1, "1.00"]
+ * [1.1, "1.10"]
+ */
+ public function testFormatAmount(float $amount, $expected): void
+ {
+ $actual = $this->formatter->formatAmount($amount);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["abc"]
+ * [""]
+ */
+ public function testFormatCreditCardExpDateUnSupportedField(string $fieldName): void
+ {
+ $expDate = new \DateTime('2024-04-14T16:45:30.000');
+ $this->expectException(\InvalidArgumentException::class);
+ $this->formatter->formatCardExpDate($expDate, $fieldName);
+ }
+
+ /**
+ * @testWith ["ExpireMonth", "04"]
+ * ["ExpireYear", "24"]
+ * ["Expiry", "202404"]
+ */
+ public function testFormatCreditCardExpDate(string $fieldName, string $expected): void
+ {
+ $expDate = new \DateTime('2024-04-14T16:45:30.000');
+ $actual = $this->formatter->formatCardExpDate($expDate, $fieldName);
+ $this->assertSame($expected, $actual);
+ }
+
+ public function testFormatDateTime(): void
+ {
+ $dateTime = new \DateTime('2024-04-14T16:45:30.000');
+ $this->expectException(NotImplementedException::class);
+ $this->formatter->formatDateTime($dateTime);
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueFormatter/PayFlexV4PosRequestValueFormatterTest.php b/tests/Unit/DataMapper/RequestValueFormatter/PayFlexV4PosRequestValueFormatterTest.php
new file mode 100644
index 00000000..132d9d25
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueFormatter/PayFlexV4PosRequestValueFormatterTest.php
@@ -0,0 +1,73 @@
+formatter = new PayFlexV4PosRequestValueFormatter();
+ }
+
+ /**
+ * @testWith [0, "0"]
+ * [1, "0"]
+ * [2, "2"]
+ */
+ public function testFormatInstallment($installment, string $expected): void
+ {
+ $actual = $this->formatter->formatInstallment($installment);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith [1, "1.00"]
+ * [1.1, "1.10"]
+ */
+ public function testFormatAmount(float $amount, $expected): void
+ {
+ $actual = $this->formatter->formatAmount($amount);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["abc"]
+ * [""]
+ */
+ public function testFormatCreditCardExpDateUnSupportedField(string $fieldName): void
+ {
+ $expDate = new \DateTime('2024-04-14T16:45:30.000');
+ $this->expectException(\InvalidArgumentException::class);
+ $this->formatter->formatCardExpDate($expDate, $fieldName);
+ }
+
+ /**
+ * @testWith ["ExpiryDate", "2404"]
+ * ["Expiry", "202404"]
+ */
+ public function testFormatCreditCardExpDate(string $fieldName, string $expected): void
+ {
+ $expDate = new \DateTime('2024-04-14T16:45:30.000');
+ $actual = $this->formatter->formatCardExpDate($expDate, $fieldName);
+ $this->assertSame($expected, $actual);
+ }
+
+ public function testFormatDateTime(): void
+ {
+ $dateTime = new \DateTime('2024-04-14T16:45:30.000');
+ $actual = $this->formatter->formatDateTime($dateTime);
+ $this->assertSame('20240414', $actual);
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueFormatter/PayForPosRequestValueFormatterTest.php b/tests/Unit/DataMapper/RequestValueFormatter/PayForPosRequestValueFormatterTest.php
new file mode 100644
index 00000000..0f556bf3
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueFormatter/PayForPosRequestValueFormatterTest.php
@@ -0,0 +1,62 @@
+formatter = new PayForPosRequestValueFormatter();
+ }
+
+ /**
+ * @testWith [0, "0"]
+ * [1, "0"]
+ * [2, "2"]
+ */
+ public function testFormatInstallment($installment, string $expected): void
+ {
+ $actual = $this->formatter->formatInstallment($installment);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith [1.1, "1.1"]
+ * [1.0, "1"]
+ */
+ public function testFormatAmount(float $amount, $expected): void
+ {
+ $actual = $this->formatter->formatAmount($amount);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["", "0424"]
+ * ["abc", "0424"]
+ */
+ public function testFormatCreditCardExpDate(string $fieldName, string $expected): void
+ {
+ $expDate = new \DateTime('2024-04-14T16:45:30.000');
+ $actual = $this->formatter->formatCardExpDate($expDate, $fieldName);
+ $this->assertSame($expected, $actual);
+ }
+
+ public function testFormatDateTime(): void
+ {
+ $dateTime = new \DateTime('2024-04-14T16:45:30.000');
+ $actual = $this->formatter->formatDateTime($dateTime);
+ $this->assertSame('20240414', $actual);
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueFormatter/PosNetRequestValueFormatterTest.php b/tests/Unit/DataMapper/RequestValueFormatter/PosNetRequestValueFormatterTest.php
new file mode 100644
index 00000000..4610d874
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueFormatter/PosNetRequestValueFormatterTest.php
@@ -0,0 +1,91 @@
+formatter = new PosNetRequestValueFormatter();
+ }
+
+ /**
+ * @testWith [0, "00"]
+ * [1, "00"]
+ * [2, "02"]
+ * [12, "12"]
+ */
+ public function testFormatInstallment($installment, string $expected): void
+ {
+ $actual = $this->formatter->formatInstallment($installment);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith [1.1, 110]
+ * [1.0, 100]
+ */
+ public function testFormatAmount(float $amount, $expected): void
+ {
+ $actual = $this->formatter->formatAmount($amount);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @dataProvider formatOrderIdDataProvider
+ */
+ public function testFormatOrderId(string $orderId, ?string $txType, ?string $orderPaymentModel, string $expected): void
+ {
+ $actual = $this->formatter->formatOrderId($orderId, $txType, $orderPaymentModel);
+ $this->assertSame($expected, $actual);
+ }
+
+ public function testFormatOrderIdFail(): void
+ {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->formatter->formatOrderId('1234567890123456789AB');
+ }
+
+ /**
+ * @testWith ["Expiry", "2404"]
+ * ["", "2404"]
+ */
+ public function testFormatCreditCardExpDate(string $fieldName, string $expected): void
+ {
+ $expDate = new \DateTime('2024-04-14T16:45:30.000');
+ $actual = $this->formatter->formatCardExpDate($expDate, $fieldName);
+ $this->assertSame($expected, $actual);
+ }
+
+ public function testFormatDateTime(): void
+ {
+ $dateTime = new \DateTime('2024-04-14T16:45:30.000');
+ $this->expectException(NotImplementedException::class);
+ $this->formatter->formatDateTime($dateTime);
+ }
+
+ public static function formatOrderIdDataProvider(): array
+ {
+ return [
+ ['ABC123', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::MODEL_3D_SECURE, '00000000000000ABC123'],
+ ['ABC123', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::MODEL_NON_SECURE, '00000000000000ABC123'],
+ ['ABC123', PosInterface::TX_TYPE_STATUS, PosInterface::MODEL_3D_SECURE, 'TDSC00000000000000ABC123'],
+ ['ABC123', PosInterface::TX_TYPE_STATUS, PosInterface::MODEL_NON_SECURE, '000000000000000000ABC123'],
+ ['ABC123', PosInterface::TX_TYPE_STATUS, PosInterface::MODEL_3D_PAY, '000000000000000000ABC123'],
+ ];
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueFormatter/PosNetV1PosRequestValueFormatterTest.php b/tests/Unit/DataMapper/RequestValueFormatter/PosNetV1PosRequestValueFormatterTest.php
new file mode 100644
index 00000000..33197157
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueFormatter/PosNetV1PosRequestValueFormatterTest.php
@@ -0,0 +1,90 @@
+formatter = new PosNetV1PosRequestValueFormatter();
+ }
+
+ /**
+ * @testWith [0, "0"]
+ * [1, "0"]
+ * [2, "2"]
+ */
+ public function testFormatInstallment($installment, string $expected): void
+ {
+ $actual = $this->formatter->formatInstallment($installment);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith [1.1, 110]
+ * [1.0, 100]
+ */
+ public function testFormatAmount(float $amount, $expected): void
+ {
+ $actual = $this->formatter->formatAmount($amount);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @dataProvider formatOrderIdDataProvider
+ */
+ public function testFormatOrderId(string $orderId, ?string $txType, ?string $orderPaymentModel, string $expected): void
+ {
+ $actual = $this->formatter->formatOrderId($orderId, $txType, $orderPaymentModel);
+ $this->assertSame($expected, $actual);
+ }
+
+ public function testFormatOrderIdFail(): void
+ {
+ $this->expectException(\InvalidArgumentException::class);
+ $this->formatter->formatOrderId('1234567890123456789AB');
+ }
+
+ /**
+ * @testWith ["Expiry", "2404"]
+ * ["", "2404"]
+ */
+ public function testFormatCreditCardExpDate(string $fieldName, string $expected): void
+ {
+ $expDate = new \DateTime('2024-04-14T16:45:30.000');
+ $actual = $this->formatter->formatCardExpDate($expDate, $fieldName);
+ $this->assertSame($expected, $actual);
+ }
+
+ public function testFormatDateTime(): void
+ {
+ $dateTime = new \DateTime('2024-04-14T16:45:30.000');
+ $this->expectException(NotImplementedException::class);
+ $this->formatter->formatDateTime($dateTime);
+ }
+
+ public static function formatOrderIdDataProvider(): array
+ {
+ return [
+ ['ABC123', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::MODEL_3D_SECURE, '00000000000000ABC123'],
+ ['ABC123', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::MODEL_NON_SECURE, '00000000000000ABC123'],
+ ['ABC123', PosInterface::TX_TYPE_STATUS, PosInterface::MODEL_3D_SECURE, 'TDS_00000000000000ABC123'],
+ ['ABC123', PosInterface::TX_TYPE_STATUS, PosInterface::MODEL_NON_SECURE, '000000000000000000ABC123'],
+ ['ABC123', PosInterface::TX_TYPE_STATUS, PosInterface::MODEL_3D_PAY, '000000000000000000ABC123'],
+ ];
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueFormatter/ToslaPosRequestValueFormatterTest.php b/tests/Unit/DataMapper/RequestValueFormatter/ToslaPosRequestValueFormatterTest.php
new file mode 100644
index 00000000..8182f73c
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueFormatter/ToslaPosRequestValueFormatterTest.php
@@ -0,0 +1,101 @@
+formatter = new ToslaPosRequestValueFormatter();
+ }
+
+ /**
+ * @testWith [0, 0]
+ * [1, 0]
+ * [2, 2]
+ */
+ public function testFormatInstallment($installment, int $expected): void
+ {
+ $actual = $this->formatter->formatInstallment($installment);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith [1.1, 110]
+ * [1, 100]
+ */
+ public function testFormatAmount(float $amount, $expected): void
+ {
+ $actual = $this->formatter->formatAmount($amount);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["ExpireDate", "04/24"]
+ * ["expireDate", "0424"]
+ */
+ public function testFormatCreditCardExpDate(string $fieldName, string $expected): void
+ {
+ $expDate = new \DateTime('2024-04-14T16:45:30.000');
+ $actual = $this->formatter->formatCardExpDate($expDate, $fieldName);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["abc"]
+ * [""]
+ */
+ public function testFormatCreditCardExpDateUnSupportedField(string $fieldName): void
+ {
+ $expDate = new \DateTime('2024-04-14T16:45:30.000');
+ $this->expectException(\InvalidArgumentException::class);
+ $this->formatter->formatCardExpDate($expDate, $fieldName);
+ }
+
+ /**
+ * @dataProvider formatDateTimeDataProvider
+ */
+ public function testFormatDateTime(?string $fieldName, string $expected): void
+ {
+ $dateTime = new \DateTime('2024-04-14T16:45:30.000');
+ $actual = $this->formatter->formatDateTime($dateTime, $fieldName);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["abc"]
+ * [null]
+ * [""]
+ */
+ public function testFormatDateTimeUnsupportedField($fieldName): void
+ {
+ $dateTime = new \DateTime('2024-04-14T16:45:30.000');
+ $this->expectException(\InvalidArgumentException::class);
+ $this->formatter->formatDateTime($dateTime, $fieldName);
+ }
+
+ public static function formatDateTimeDataProvider(): array
+ {
+ return [
+ [
+ 'timeSpan',
+ '20240414164530',
+ ],
+ [
+ 'transactionDate',
+ '20240414',
+ ],
+ ];
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueFormatter/VakifKatilimPosRequestValueFormatterTest.php b/tests/Unit/DataMapper/RequestValueFormatter/VakifKatilimPosRequestValueFormatterTest.php
new file mode 100644
index 00000000..24105ab4
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueFormatter/VakifKatilimPosRequestValueFormatterTest.php
@@ -0,0 +1,107 @@
+formatter = new VakifKatilimPosRequestValueFormatter();
+ }
+
+ /**
+ * @testWith [0, "0"]
+ * [1, "0"]
+ * [2, "2"]
+ */
+ public function testFormatInstallment($installment, string $expected): void
+ {
+ $actual = $this->formatter->formatInstallment($installment);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith [1.1, 110]
+ * [1.0, 100]
+ */
+ public function testFormatAmount(float $amount, $expected): void
+ {
+ $actual = $this->formatter->formatAmount($amount);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["CardExpireDateMonth", "04"]
+ * ["CardExpireDateYear", "24"]
+ */
+ public function testFormatCreditCardExpDate(string $fieldName, string $expected): void
+ {
+ $expDate = new \DateTime('2024-04-14T16:45:30.000');
+ $actual = $this->formatter->formatCardExpDate($expDate, $fieldName);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["abc"]
+ * [""]
+ */
+ public function testFormatCreditCardExpDateUnSupportedField(string $fieldName): void
+ {
+ $expDate = new \DateTime('2024-04-14T16:45:30.000');
+ $this->expectException(\InvalidArgumentException::class);
+ $this->formatter->formatCardExpDate($expDate, $fieldName);
+ }
+
+ /**
+ * @dataProvider formatDateTimeDataProvider
+ */
+ public function testFormatDateTime(\DateTimeInterface $dateTime, ?string $fieldName, ?string $txType, string $expected): void
+ {
+ $actual = $this->formatter->formatDateTime($dateTime, $fieldName, $txType);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["abc"]
+ * [null]
+ * [""]
+ */
+ public function testFormatDateTimeUnsupportedField($fieldName): void
+ {
+ $dateTime = new \DateTime('2024-04-14T16:45:30.000');
+ $this->expectException(\InvalidArgumentException::class);
+ $this->formatter->formatDateTime($dateTime, $fieldName);
+ }
+
+
+ public static function formatDateTimeDataProvider(): array
+ {
+ return [
+ [
+ new \DateTime('2024-04-14T16:45:30.000'),
+ 'StartDate',
+ PosInterface::TX_TYPE_HISTORY,
+ '2024-04-14',
+ ],
+ [
+ new \DateTime('2024-04-14T16:45:30.000'),
+ 'EndDate',
+ PosInterface::TX_TYPE_HISTORY,
+ '2024-04-14',
+ ],
+ ];
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueMapper/AkbankPosRequestValueMapperTest.php b/tests/Unit/DataMapper/RequestValueMapper/AkbankPosRequestValueMapperTest.php
new file mode 100644
index 00000000..7a8c5217
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueMapper/AkbankPosRequestValueMapperTest.php
@@ -0,0 +1,135 @@
+valueMapper = new AkbankPosRequestValueMapper();
+ }
+
+ /**
+ * @dataProvider mapTxTypeDataProvider
+ */
+ public function testMapTxType(string $txType, string $paymentModel, string $expected): void
+ {
+ $actual = $this->valueMapper->mapTxType($txType, $paymentModel);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @dataProvider mapTxTypeUnsupportedDataProvider
+ */
+ public function testMapTxTypeException(string $txType): void
+ {
+ $this->expectException(UnsupportedTransactionTypeException::class);
+ $this->valueMapper->mapTxType($txType);
+ }
+
+ /**
+ * @dataProvider mapSecureTypeDataProvider
+ */
+ public function testMapSecureType(string $paymentModel, string $expected): void
+ {
+ $mappedSecureType = $this->valueMapper->mapSecureType($paymentModel);
+ $this->assertSame($expected, $mappedSecureType);
+ }
+
+ /**
+ * @testWith ["DAY", "D"]
+ * ["WEEK", "W"]
+ * ["MONTH", "M"]
+ * ["YEAR", "Y"]
+ */
+ public function testMapRecurringFrequency(string $frequency, string $expected): void
+ {
+ $this->assertSame($expected, $this->valueMapper->mapRecurringFrequency($frequency));
+ }
+
+ public function testMapLang(): void
+ {
+ $this->assertSame('TR', $this->valueMapper->mapLang(PosInterface::LANG_TR));
+ }
+
+ /**
+ * @return void
+ */
+ public function testMapCurrency(): void
+ {
+ $this->assertSame(949, $this->valueMapper->mapCurrency(PosInterface::CURRENCY_TRY));
+ $this->assertSame(978, $this->valueMapper->mapCurrency(PosInterface::CURRENCY_EUR));
+ }
+
+ public function testGetLangMappings(): void
+ {
+ $this->assertCount(2, $this->valueMapper->getLangMappings());
+ }
+
+ public function testGetRecurringOrderFrequencyMappings(): void
+ {
+ $this->assertCount(4, $this->valueMapper->getRecurringOrderFrequencyMappings());
+ }
+
+ public function testGetCurrencyMappings(): void
+ {
+ $this->assertCount(6, $this->valueMapper->getCurrencyMappings());
+ }
+
+ public function testGetTxTypeMappings(): void
+ {
+ $this->assertCount(8, $this->valueMapper->getTxTypeMappings());
+ }
+
+ public function testGetSecureTypeMappings()
+ {
+ $this->assertCount(4, $this->valueMapper->getSecureTypeMappings());
+ }
+
+ public function testGetCardTypeMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getCardTypeMappings());
+ }
+
+ public static function mapSecureTypeDataProvider(): array
+ {
+ return [
+ [PosInterface::MODEL_3D_SECURE, '3D'],
+ [PosInterface::MODEL_3D_PAY, '3D_PAY'],
+ [PosInterface::MODEL_3D_HOST, '3D_PAY_HOSTING'],
+ [PosInterface::MODEL_NON_SECURE, 'PAY_HOSTING'],
+ ];
+ }
+
+ public static function mapTxTypeDataProvider(): array
+ {
+ return [
+ [PosInterface::TX_TYPE_PAY_AUTH, PosInterface::MODEL_3D_SECURE, '3000'],
+ [PosInterface::TX_TYPE_PAY_PRE_AUTH, PosInterface::MODEL_3D_SECURE, '3004'],
+ [PosInterface::TX_TYPE_PAY_PRE_AUTH, PosInterface::MODEL_NON_SECURE, '1004'],
+ ];
+ }
+
+ public static function mapTxTypeUnsupportedDataProvider(): array
+ {
+ return [
+ ['3000', null],
+ [PosInterface::TX_TYPE_PAY_AUTH, null],
+ ];
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueMapper/EstPosRequestValueMapperTest.php b/tests/Unit/DataMapper/RequestValueMapper/EstPosRequestValueMapperTest.php
new file mode 100644
index 00000000..26c1b601
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueMapper/EstPosRequestValueMapperTest.php
@@ -0,0 +1,126 @@
+valueMapper = new EstPosRequestValueMapper();
+ }
+
+ /**
+ * @dataProvider mapTxTypeDataProvider
+ */
+ public function testMapTxType(string $txType, string $expected): void
+ {
+ $actual = $this->valueMapper->mapTxType($txType);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["Auth"]
+ */
+ public function testMapTxTypeException(string $txType): void
+ {
+ $this->expectException(UnsupportedTransactionTypeException::class);
+ $this->valueMapper->mapTxType($txType);
+ }
+
+ /**
+ * @dataProvider mapSecureTypeDataProvider
+ */
+ public function testMapSecureType(string $paymentModel, string $expected): void
+ {
+ $mappedSecureType = $this->valueMapper->mapSecureType($paymentModel);
+ $this->assertSame($expected, $mappedSecureType);
+ }
+
+ /**
+ * @testWith ["DAY", "D"]
+ * ["WEEK", "W"]
+ * ["MONTH", "M"]
+ * ["YEAR", "Y"]
+ */
+ public function testMapRecurringFrequency(string $frequency, string $expected): void
+ {
+ $this->assertSame($expected, $this->valueMapper->mapRecurringFrequency($frequency));
+ }
+
+ public function testMapLang(): void
+ {
+ $this->assertSame('tr', $this->valueMapper->mapLang(PosInterface::LANG_TR));
+ }
+
+ /**
+ * @return void
+ */
+ public function testMapCurrency(): void
+ {
+ $this->assertSame('949', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_TRY));
+ $this->assertSame('978', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_EUR));
+ }
+
+ public function testGetLangMappings(): void
+ {
+ $this->assertCount(2, $this->valueMapper->getLangMappings());
+ }
+
+ public function testGetRecurringOrderFrequencyMappings(): void
+ {
+ $this->assertCount(4, $this->valueMapper->getRecurringOrderFrequencyMappings());
+ }
+
+ public function testGetCurrencyMappings(): void
+ {
+ $this->assertCount(6, $this->valueMapper->getCurrencyMappings());
+ }
+
+ public function testGetTxTypeMappings(): void
+ {
+ $this->assertCount(8, $this->valueMapper->getTxTypeMappings());
+ }
+
+ public function testGetSecureTypeMappings()
+ {
+ $this->assertCount(5, $this->valueMapper->getSecureTypeMappings());
+ }
+
+ public function testGetCardTypeMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getCardTypeMappings());
+ }
+
+ public static function mapSecureTypeDataProvider(): array
+ {
+ return [
+ [PosInterface::MODEL_3D_SECURE, '3d'],
+ [PosInterface::MODEL_3D_PAY, '3d_pay'],
+ [PosInterface::MODEL_3D_HOST, '3d_host'],
+ [PosInterface::MODEL_NON_SECURE, 'regular'],
+ ];
+ }
+
+ public static function mapTxTypeDataProvider(): array
+ {
+ return [
+ [PosInterface::TX_TYPE_PAY_AUTH, 'Auth'],
+ [PosInterface::TX_TYPE_PAY_PRE_AUTH, 'PreAuth'],
+ [PosInterface::TX_TYPE_PAY_POST_AUTH, 'PostAuth'],
+ ];
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueMapper/GarantiPosRequestValueMapperTest.php b/tests/Unit/DataMapper/RequestValueMapper/GarantiPosRequestValueMapperTest.php
new file mode 100644
index 00000000..1b36e1c5
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueMapper/GarantiPosRequestValueMapperTest.php
@@ -0,0 +1,123 @@
+valueMapper = new GarantiPosRequestValueMapper();
+ }
+
+ /**
+ * @dataProvider mapTxTypeDataProvider
+ */
+ public function testMapTxType(string $txType, string $expected): void
+ {
+ $actual = $this->valueMapper->mapTxType($txType);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["sales"]
+ */
+ public function testMapTxTypeException(string $txType): void
+ {
+ $this->expectException(UnsupportedTransactionTypeException::class);
+ $this->valueMapper->mapTxType($txType);
+ }
+
+ /**
+ * @dataProvider mapSecureTypeDataProvider
+ */
+ public function testMapSecureType(string $paymentModel, string $expected): void
+ {
+ $mappedSecureType = $this->valueMapper->mapSecureType($paymentModel);
+ $this->assertSame($expected, $mappedSecureType);
+ }
+
+ /**
+ * @testWith ["DAY", "D"]
+ * ["WEEK", "W"]
+ * ["MONTH", "M"]
+ */
+ public function testMapRecurringFrequency(string $frequency, string $expected): void
+ {
+ $this->assertSame($expected, $this->valueMapper->mapRecurringFrequency($frequency));
+ }
+
+ public function testMapLang(): void
+ {
+ $this->expectException(\LogicException::class);
+ $this->valueMapper->mapLang(PosInterface::LANG_TR);
+ }
+
+ /**
+ * @return void
+ */
+ public function testMapCurrency(): void
+ {
+ $this->assertSame('949', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_TRY));
+ $this->assertSame('978', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_EUR));
+ }
+
+ public function testGetLangMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getLangMappings());
+ }
+
+ public function testGetRecurringOrderFrequencyMappings(): void
+ {
+ $this->assertCount(3, $this->valueMapper->getRecurringOrderFrequencyMappings());
+ }
+
+ public function testGetCurrencyMappings(): void
+ {
+ $this->assertCount(6, $this->valueMapper->getCurrencyMappings());
+ }
+
+ public function testGetTxTypeMappings(): void
+ {
+ $this->assertCount(9, $this->valueMapper->getTxTypeMappings());
+ }
+
+ public function testGetSecureTypeMappings()
+ {
+ $this->assertCount(2, $this->valueMapper->getSecureTypeMappings());
+ }
+
+ public function testGetCardTypeMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getCardTypeMappings());
+ }
+
+ public static function mapSecureTypeDataProvider(): array
+ {
+ return [
+ [PosInterface::MODEL_3D_SECURE, '3D'],
+ [PosInterface::MODEL_3D_PAY, '3D_PAY'],
+ ];
+ }
+
+ public static function mapTxTypeDataProvider(): array
+ {
+ return [
+ [PosInterface::TX_TYPE_PAY_AUTH, 'sales'],
+ [PosInterface::TX_TYPE_PAY_PRE_AUTH, 'preauth'],
+ ];
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueMapper/InterPosRequestValueMapperTest.php b/tests/Unit/DataMapper/RequestValueMapper/InterPosRequestValueMapperTest.php
new file mode 100644
index 00000000..7d40ab9a
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueMapper/InterPosRequestValueMapperTest.php
@@ -0,0 +1,140 @@
+valueMapper = new InterPosRequestValueMapper();
+ }
+
+ /**
+ * @dataProvider mapTxTypeDataProvider
+ */
+ public function testMapTxType(string $txType, string $expected): void
+ {
+ $actual = $this->valueMapper->mapTxType($txType);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["sales"]
+ */
+ public function testMapTxTypeException(string $txType): void
+ {
+ $this->expectException(UnsupportedTransactionTypeException::class);
+ $this->valueMapper->mapTxType($txType);
+ }
+
+ /**
+ * @dataProvider mapSecureTypeDataProvider
+ */
+ public function testMapSecureType(string $paymentModel, string $expected): void
+ {
+ $mappedSecureType = $this->valueMapper->mapSecureType($paymentModel);
+ $this->assertSame($expected, $mappedSecureType);
+ }
+
+ public function testMapRecurringFrequency(): void
+ {
+ $this->expectException(\LogicException::class);
+ $this->valueMapper->mapRecurringFrequency('DAY');
+ }
+
+ public function testMapLang(): void
+ {
+ $this->assertSame('tr', $this->valueMapper->mapLang(PosInterface::LANG_TR));
+ }
+
+ public function testMapCurrency(): void
+ {
+ $this->assertSame('949', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_TRY));
+ $this->assertSame('978', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_EUR));
+ }
+
+ /**
+ * @dataProvider mapCardTypeDataProvider
+ */
+ public function testMapCardType(string $cardType, string $expected): void
+ {
+ $this->assertSame($expected, $this->valueMapper->mapCardType($cardType));
+ }
+
+ public function testGetLangMappings(): void
+ {
+ $this->assertCount(2, $this->valueMapper->getLangMappings());
+ }
+
+ public function testGetRecurringOrderFrequencyMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getRecurringOrderFrequencyMappings());
+ }
+
+ public function testGetCurrencyMappings(): void
+ {
+ $this->assertCount(6, $this->valueMapper->getCurrencyMappings());
+ }
+
+ public function testGetTxTypeMappings(): void
+ {
+ $this->assertCount(7, $this->valueMapper->getTxTypeMappings());
+ }
+
+ public function testGetSecureTypeMappings()
+ {
+ $this->assertCount(4, $this->valueMapper->getSecureTypeMappings());
+ }
+
+ public function testGetCardTypeMappings(): void
+ {
+ $this->assertCount(4, $this->valueMapper->getCardTypeMappings());
+ }
+
+ public static function mapSecureTypeDataProvider(): array
+ {
+ return [
+ [PosInterface::MODEL_3D_SECURE, '3DModel'],
+ [PosInterface::MODEL_3D_PAY, '3DPay'],
+ [PosInterface::MODEL_NON_SECURE, 'NonSecure'],
+ ];
+ }
+
+ public static function mapTxTypeDataProvider(): array
+ {
+ return [
+ [PosInterface::TX_TYPE_PAY_AUTH, 'Auth'],
+ [PosInterface::TX_TYPE_PAY_PRE_AUTH, 'PreAuth'],
+ ];
+ }
+
+ public static function mapCardTypeDataProvider(): array
+ {
+ return [
+ [
+ CreditCardInterface::CARD_TYPE_VISA,
+ '0',
+ ],
+ [
+ CreditCardInterface::CARD_TYPE_MASTERCARD,
+ '1',
+ ],
+ ];
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueMapper/KuveytPosRequestValueMapperTest.php b/tests/Unit/DataMapper/RequestValueMapper/KuveytPosRequestValueMapperTest.php
new file mode 100644
index 00000000..304a959f
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueMapper/KuveytPosRequestValueMapperTest.php
@@ -0,0 +1,136 @@
+valueMapper = new KuveytPosRequestValueMapper();
+ }
+
+ /**
+ * @dataProvider mapTxTypeDataProvider
+ */
+ public function testMapTxType(string $txType, string $expected): void
+ {
+ $actual = $this->valueMapper->mapTxType($txType);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["Auth"]
+ */
+ public function testMapTxTypeException(string $txType): void
+ {
+ $this->expectException(UnsupportedTransactionTypeException::class);
+ $this->valueMapper->mapTxType($txType);
+ }
+
+ /**
+ * @dataProvider mapSecureTypeDataProvider
+ */
+ public function testMapSecureType(string $paymentModel, string $expected): void
+ {
+ $mappedSecureType = $this->valueMapper->mapSecureType($paymentModel);
+ $this->assertSame($expected, $mappedSecureType);
+ }
+
+ public function testMapRecurringFrequency(): void
+ {
+ $this->expectException(\LogicException::class);
+ $this->valueMapper->mapRecurringFrequency('DAY');
+ }
+
+ public function testMapLang(): void
+ {
+ $this->expectException(\LogicException::class);
+ $this->valueMapper->mapLang(PosInterface::LANG_TR);
+ }
+
+ /**
+ * @return void
+ */
+ public function testMapCurrency(): void
+ {
+ $this->assertSame('0949', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_TRY));
+ $this->assertSame('0978', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_EUR));
+ }
+
+ public function testGetLangMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getLangMappings());
+ }
+
+ public function testGetRecurringOrderFrequencyMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getRecurringOrderFrequencyMappings());
+ }
+
+ public function testGetCurrencyMappings(): void
+ {
+ $this->assertCount(6, $this->valueMapper->getCurrencyMappings());
+ }
+
+ public function testGetTxTypeMappings(): void
+ {
+ $this->assertCount(5, $this->valueMapper->getTxTypeMappings());
+ }
+
+ public function testGetSecureTypeMappings()
+ {
+ $this->assertCount(2, $this->valueMapper->getSecureTypeMappings());
+ }
+
+ public function testGetCardTypeMappings(): void
+ {
+ $this->assertCount(3, $this->valueMapper->getCardTypeMappings());
+ }
+
+ /**
+ * @dataProvider mapCardTypeDataProvider
+ */
+ public function testMapCardType(string $cardType, string $expected): void
+ {
+ $this->assertSame($expected, $this->valueMapper->mapCardType($cardType));
+ }
+
+ public static function mapSecureTypeDataProvider(): array
+ {
+ return [
+ [PosInterface::MODEL_3D_SECURE, '3'],
+ [PosInterface::MODEL_NON_SECURE, '0'],
+ ];
+ }
+
+ public static function mapTxTypeDataProvider(): array
+ {
+ return [
+ [PosInterface::TX_TYPE_PAY_AUTH, 'Sale'],
+ ];
+ }
+
+ public static function mapCardTypeDataProvider(): array
+ {
+ return [
+ [CreditCardInterface::CARD_TYPE_VISA, 'Visa'],
+ [CreditCardInterface::CARD_TYPE_MASTERCARD, 'MasterCard'],
+ [CreditCardInterface::CARD_TYPE_TROY, 'Troy'],
+ ];
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueMapper/PayFlexCPV4PosRequestValueMapperTest.php b/tests/Unit/DataMapper/RequestValueMapper/PayFlexCPV4PosRequestValueMapperTest.php
new file mode 100644
index 00000000..b4c3c651
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueMapper/PayFlexCPV4PosRequestValueMapperTest.php
@@ -0,0 +1,108 @@
+valueMapper = new PayFlexCPV4PosRequestValueMapper();
+ }
+
+ /**
+ * @dataProvider mapTxTypeDataProvider
+ */
+ public function testMapTxType(string $txType, string $expected): void
+ {
+ $actual = $this->valueMapper->mapTxType($txType);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["Auth"]
+ */
+ public function testMapTxTypeException(string $txType): void
+ {
+ $this->expectException(UnsupportedTransactionTypeException::class);
+ $this->valueMapper->mapTxType($txType);
+ }
+
+ public function testMapSecureType(): void
+ {
+ $this->expectException(\LogicException::class);
+ $this->valueMapper->mapSecureType(PosInterface::MODEL_3D_SECURE);
+ }
+
+ public function testMapRecurringFrequency(): void
+ {
+ $this->expectException(\LogicException::class);
+ $this->valueMapper->mapRecurringFrequency('DAY');
+ }
+
+ public function testMapLang(): void
+ {
+ $this->assertSame('tr-TR', $this->valueMapper->mapLang(PosInterface::LANG_TR));
+ }
+
+ /**
+ * @return void
+ */
+ public function testMapCurrency(): void
+ {
+ $this->assertSame('949', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_TRY));
+ $this->assertSame('978', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_EUR));
+ }
+
+ public function testGetLangMappings(): void
+ {
+ $this->assertCount(2, $this->valueMapper->getLangMappings());
+ }
+
+ public function testGetRecurringOrderFrequencyMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getRecurringOrderFrequencyMappings());
+ }
+
+ public function testGetCurrencyMappings(): void
+ {
+ $this->assertCount(6, $this->valueMapper->getCurrencyMappings());
+ }
+
+ public function testGetTxTypeMappings(): void
+ {
+ $this->assertCount(8, $this->valueMapper->getTxTypeMappings());
+ }
+
+ public function testGetSecureTypeMappings()
+ {
+ $this->assertCount(0, $this->valueMapper->getSecureTypeMappings());
+ }
+
+ public function testGetCardTypeMappings(): void
+ {
+ $this->assertCount(4, $this->valueMapper->getCardTypeMappings());
+ }
+
+ public static function mapTxTypeDataProvider(): array
+ {
+ return [
+ [PosInterface::TX_TYPE_PAY_AUTH, 'Sale'],
+ [PosInterface::TX_TYPE_PAY_PRE_AUTH, 'Auth'],
+ [PosInterface::TX_TYPE_PAY_POST_AUTH, 'Capture'],
+ ];
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueMapper/PayFlexV4PosRequestValueMapperTest.php b/tests/Unit/DataMapper/RequestValueMapper/PayFlexV4PosRequestValueMapperTest.php
new file mode 100644
index 00000000..84a40fac
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueMapper/PayFlexV4PosRequestValueMapperTest.php
@@ -0,0 +1,113 @@
+valueMapper = new PayFlexV4PosRequestValueMapper();
+ }
+
+ /**
+ * @dataProvider mapTxTypeDataProvider
+ */
+ public function testMapTxType(string $txType, string $expected): void
+ {
+ $actual = $this->valueMapper->mapTxType($txType);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["Auth"]
+ */
+ public function testMapTxTypeException(string $txType): void
+ {
+ $this->expectException(UnsupportedTransactionTypeException::class);
+ $this->valueMapper->mapTxType($txType);
+ }
+
+ public function testMapSecureType(): void
+ {
+ $this->expectException(\LogicException::class);
+ $this->valueMapper->mapSecureType(PosInterface::MODEL_3D_SECURE);
+ }
+
+ /**
+ * @testWith ["DAY", "Day"]
+ * ["MONTH", "Month"]
+ * ["YEAR", "Year"]
+ */
+ public function testMapRecurringFrequency(string $frequency, string $expected): void
+ {
+ $this->assertSame($expected, $this->valueMapper->mapRecurringFrequency($frequency));
+ }
+
+ public function testMapLang(): void
+ {
+ $this->expectException(\LogicException::class);
+ $this->valueMapper->mapLang(PosInterface::LANG_TR);
+ }
+
+ /**
+ * @return void
+ */
+ public function testMapCurrency(): void
+ {
+ $this->assertSame('949', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_TRY));
+ $this->assertSame('978', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_EUR));
+ }
+
+ public function testGetLangMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getLangMappings());
+ }
+
+ public function testGetRecurringOrderFrequencyMappings(): void
+ {
+ $this->assertCount(3, $this->valueMapper->getRecurringOrderFrequencyMappings());
+ }
+
+ public function testGetCurrencyMappings(): void
+ {
+ $this->assertCount(6, $this->valueMapper->getCurrencyMappings());
+ }
+
+ public function testGetTxTypeMappings(): void
+ {
+ $this->assertCount(7, $this->valueMapper->getTxTypeMappings());
+ }
+
+ public function testGetSecureTypeMappings()
+ {
+ $this->assertCount(0, $this->valueMapper->getSecureTypeMappings());
+ }
+
+ public function testGetCardTypeMappings(): void
+ {
+ $this->assertCount(4, $this->valueMapper->getCardTypeMappings());
+ }
+
+ public static function mapTxTypeDataProvider(): array
+ {
+ return [
+ [PosInterface::TX_TYPE_PAY_AUTH, 'Sale'],
+ [PosInterface::TX_TYPE_PAY_PRE_AUTH, 'Auth'],
+ [PosInterface::TX_TYPE_PAY_POST_AUTH, 'Capture'],
+ ];
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueMapper/PayForPosRequestValueMapperTest.php b/tests/Unit/DataMapper/RequestValueMapper/PayForPosRequestValueMapperTest.php
new file mode 100644
index 00000000..c8136d73
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueMapper/PayForPosRequestValueMapperTest.php
@@ -0,0 +1,121 @@
+valueMapper = new PayForPosRequestValueMapper();
+ }
+
+ /**
+ * @dataProvider mapTxTypeDataProvider
+ */
+ public function testMapTxType(string $txType, string $expected): void
+ {
+ $actual = $this->valueMapper->mapTxType($txType);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["Auth"]
+ */
+ public function testMapTxTypeException(string $txType): void
+ {
+ $this->expectException(UnsupportedTransactionTypeException::class);
+ $this->valueMapper->mapTxType($txType);
+ }
+
+ /**
+ * @dataProvider mapSecureTypeDataProvider
+ */
+ public function testMapSecureType(string $paymentModel, string $expected): void
+ {
+ $mappedSecureType = $this->valueMapper->mapSecureType($paymentModel);
+ $this->assertSame($expected, $mappedSecureType);
+ }
+
+ public function testMapRecurringFrequency(): void
+ {
+ $this->expectException(\LogicException::class);
+ $this->valueMapper->mapRecurringFrequency('DAY');
+ }
+
+ public function testMapLang(): void
+ {
+ $this->assertSame('tr', $this->valueMapper->mapLang(PosInterface::LANG_TR));
+ }
+
+ /**
+ * @return void
+ */
+ public function testMapCurrency(): void
+ {
+ $this->assertSame('949', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_TRY));
+ $this->assertSame('978', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_EUR));
+ }
+
+ public function testGetLangMappings(): void
+ {
+ $this->assertCount(2, $this->valueMapper->getLangMappings());
+ }
+
+ public function testGetRecurringOrderFrequencyMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getRecurringOrderFrequencyMappings());
+ }
+
+ public function testGetCurrencyMappings(): void
+ {
+ $this->assertCount(6, $this->valueMapper->getCurrencyMappings());
+ }
+
+ public function testGetTxTypeMappings(): void
+ {
+ $this->assertCount(8, $this->valueMapper->getTxTypeMappings());
+ }
+
+ public function testGetSecureTypeMappings()
+ {
+ $this->assertCount(4, $this->valueMapper->getSecureTypeMappings());
+ }
+
+ public function testGetCardTypeMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getCardTypeMappings());
+ }
+
+ public static function mapSecureTypeDataProvider(): array
+ {
+ return [
+ [PosInterface::MODEL_3D_SECURE, '3DModel'],
+ [PosInterface::MODEL_3D_PAY, '3DPay'],
+ [PosInterface::MODEL_3D_HOST, '3DHost'],
+ [PosInterface::MODEL_NON_SECURE, 'NonSecure'],
+ ];
+ }
+
+ public static function mapTxTypeDataProvider(): array
+ {
+ return [
+ [PosInterface::TX_TYPE_PAY_AUTH, 'Auth'],
+ [PosInterface::TX_TYPE_PAY_PRE_AUTH, 'PreAuth'],
+ [PosInterface::TX_TYPE_PAY_POST_AUTH, 'PostAuth'],
+ ];
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueMapper/PosNetRequestValueMapperTest.php b/tests/Unit/DataMapper/RequestValueMapper/PosNetRequestValueMapperTest.php
new file mode 100644
index 00000000..eba4e969
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueMapper/PosNetRequestValueMapperTest.php
@@ -0,0 +1,108 @@
+valueMapper = new PosNetRequestValueMapper();
+ }
+
+ /**
+ * @dataProvider mapTxTypeDataProvider
+ */
+ public function testMapTxType(string $txType, string $expected): void
+ {
+ $actual = $this->valueMapper->mapTxType($txType);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["Sale"]
+ */
+ public function testMapTxTypeException(string $txType): void
+ {
+ $this->expectException(UnsupportedTransactionTypeException::class);
+ $this->valueMapper->mapTxType($txType);
+ }
+
+ public function testMapSecureType(): void
+ {
+ $this->expectException(\LogicException::class);
+ $this->valueMapper->mapSecureType(PosInterface::MODEL_3D_SECURE);
+ }
+
+ public function testMapRecurringFrequency(): void
+ {
+ $this->expectException(\LogicException::class);
+ $this->valueMapper->mapRecurringFrequency('DAY');
+ }
+
+ public function testMapLang(): void
+ {
+ $this->assertSame('tr', $this->valueMapper->mapLang(PosInterface::LANG_TR));
+ }
+
+ /**
+ * @return void
+ */
+ public function testMapCurrency(): void
+ {
+ $this->assertSame('TL', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_TRY));
+ $this->assertSame('EU', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_EUR));
+ }
+
+ public function testGetLangMappings(): void
+ {
+ $this->assertCount(2, $this->valueMapper->getLangMappings());
+ }
+
+ public function testGetRecurringOrderFrequencyMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getRecurringOrderFrequencyMappings());
+ }
+
+ public function testGetCurrencyMappings(): void
+ {
+ $this->assertCount(6, $this->valueMapper->getCurrencyMappings());
+ }
+
+ public function testGetTxTypeMappings(): void
+ {
+ $this->assertCount(7, $this->valueMapper->getTxTypeMappings());
+ }
+
+ public function testGetSecureTypeMappings()
+ {
+ $this->assertCount(0, $this->valueMapper->getSecureTypeMappings());
+ }
+
+ public function testGetCardTypeMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getCardTypeMappings());
+ }
+
+ public static function mapTxTypeDataProvider(): array
+ {
+ return [
+ [PosInterface::TX_TYPE_PAY_AUTH, 'Sale'],
+ [PosInterface::TX_TYPE_PAY_PRE_AUTH, 'Auth'],
+ [PosInterface::TX_TYPE_PAY_POST_AUTH, 'Capt'],
+ ];
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueMapper/PosNetV1PosRequestValueMapperTest.php b/tests/Unit/DataMapper/RequestValueMapper/PosNetV1PosRequestValueMapperTest.php
new file mode 100644
index 00000000..e9f2eaf6
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueMapper/PosNetV1PosRequestValueMapperTest.php
@@ -0,0 +1,108 @@
+valueMapper = new PosNetV1PosRequestValueMapper();
+ }
+
+ /**
+ * @dataProvider mapTxTypeDataProvider
+ */
+ public function testMapTxType(string $txType, string $expected): void
+ {
+ $actual = $this->valueMapper->mapTxType($txType);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["Sale"]
+ */
+ public function testMapTxTypeException(string $txType): void
+ {
+ $this->expectException(UnsupportedTransactionTypeException::class);
+ $this->valueMapper->mapTxType($txType);
+ }
+
+ public function testMapSecureType(): void
+ {
+ $this->expectException(\LogicException::class);
+ $this->valueMapper->mapSecureType(PosInterface::MODEL_3D_SECURE);
+ }
+
+ public function testMapRecurringFrequency(): void
+ {
+ $this->expectException(\LogicException::class);
+ $this->valueMapper->mapRecurringFrequency('DAY');
+ }
+
+ public function testMapLang(): void
+ {
+ $this->assertSame('tr', $this->valueMapper->mapLang(PosInterface::LANG_TR));
+ }
+
+ /**
+ * @return void
+ */
+ public function testMapCurrency(): void
+ {
+ $this->assertSame('TL', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_TRY));
+ $this->assertSame('EU', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_EUR));
+ }
+
+ public function testGetLangMappings(): void
+ {
+ $this->assertCount(2, $this->valueMapper->getLangMappings());
+ }
+
+ public function testGetRecurringOrderFrequencyMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getRecurringOrderFrequencyMappings());
+ }
+
+ public function testGetCurrencyMappings(): void
+ {
+ $this->assertCount(6, $this->valueMapper->getCurrencyMappings());
+ }
+
+ public function testGetTxTypeMappings(): void
+ {
+ $this->assertCount(7, $this->valueMapper->getTxTypeMappings());
+ }
+
+ public function testGetSecureTypeMappings()
+ {
+ $this->assertCount(0, $this->valueMapper->getSecureTypeMappings());
+ }
+
+ public function testGetCardTypeMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getCardTypeMappings());
+ }
+
+ public static function mapTxTypeDataProvider(): array
+ {
+ return [
+ [PosInterface::TX_TYPE_PAY_AUTH, 'Sale'],
+ [PosInterface::TX_TYPE_PAY_PRE_AUTH, 'Auth'],
+ [PosInterface::TX_TYPE_PAY_POST_AUTH, 'Capture'],
+ ];
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueMapper/ToslaPosRequestValueMapperTest.php b/tests/Unit/DataMapper/RequestValueMapper/ToslaPosRequestValueMapperTest.php
new file mode 100644
index 00000000..efee86d3
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueMapper/ToslaPosRequestValueMapperTest.php
@@ -0,0 +1,109 @@
+valueMapper = new ToslaPosRequestValueMapper();
+ }
+
+ /**
+ * @dataProvider mapTxTypeDataProvider
+ */
+ public function testMapTxType(string $txType, string $paymentModel, string $expected): void
+ {
+ $actual = $this->valueMapper->mapTxType($txType, $paymentModel);
+ $this->assertSame($expected, $actual);
+ }
+
+ /**
+ * @testWith ["1"]
+ */
+ public function testMapTxTypeException(string $txType): void
+ {
+ $this->expectException(UnsupportedTransactionTypeException::class);
+ $this->valueMapper->mapTxType($txType);
+ }
+
+ public function testMapSecureType(): void
+ {
+ $this->expectException(\LogicException::class);
+ $this->valueMapper->mapSecureType(PosInterface::MODEL_3D_SECURE);
+ }
+
+ public function testMapRecurringFrequency(): void
+ {
+ $this->expectException(\LogicException::class);
+ $this->valueMapper->mapRecurringFrequency('DAY');
+ }
+
+ public function testMapLang(): void
+ {
+ $this->expectException(\LogicException::class);
+ $this->valueMapper->mapLang(PosInterface::LANG_TR);
+ }
+
+ /**
+ * @return void
+ */
+ public function testMapCurrency(): void
+ {
+ $this->assertSame(949, $this->valueMapper->mapCurrency(PosInterface::CURRENCY_TRY));
+ $this->assertSame(978, $this->valueMapper->mapCurrency(PosInterface::CURRENCY_EUR));
+ }
+
+ public function testGetLangMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getLangMappings());
+ }
+
+ public function testGetRecurringOrderFrequencyMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getRecurringOrderFrequencyMappings());
+ }
+
+ public function testGetCurrencyMappings(): void
+ {
+ $this->assertCount(6, $this->valueMapper->getCurrencyMappings());
+ }
+
+ public function testGetTxTypeMappings(): void
+ {
+ $this->assertCount(6, $this->valueMapper->getTxTypeMappings());
+ }
+
+ public function testGetSecureTypeMappings()
+ {
+ $this->assertCount(0, $this->valueMapper->getSecureTypeMappings());
+ }
+
+ public function testGetCardTypeMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getCardTypeMappings());
+ }
+
+ public static function mapTxTypeDataProvider(): array
+ {
+ return [
+ [PosInterface::TX_TYPE_PAY_AUTH, PosInterface::MODEL_3D_SECURE, '1'],
+ [PosInterface::TX_TYPE_PAY_PRE_AUTH, PosInterface::MODEL_3D_SECURE, '2'],
+ ];
+ }
+}
diff --git a/tests/Unit/DataMapper/RequestValueMapper/VakifKatilimPosRequestValueMapperTest.php b/tests/Unit/DataMapper/RequestValueMapper/VakifKatilimPosRequestValueMapperTest.php
new file mode 100644
index 00000000..ed609e4b
--- /dev/null
+++ b/tests/Unit/DataMapper/RequestValueMapper/VakifKatilimPosRequestValueMapperTest.php
@@ -0,0 +1,106 @@
+valueMapper = new VakifKatilimPosRequestValueMapper();
+ }
+
+ public function testMapTxType(): void
+ {
+ $this->expectException(UnsupportedTransactionTypeException::class);
+ $this->valueMapper->mapTxType(PosInterface::TX_TYPE_PAY_AUTH);
+ }
+
+ /**
+ * @dataProvider mapSecureTypeDataProvider
+ */
+ public function testMapSecureType(string $paymentModel, string $expected): void
+ {
+ $mappedSecureType = $this->valueMapper->mapSecureType($paymentModel);
+ $this->assertSame($expected, $mappedSecureType);
+ }
+
+ public function testMapRecurringFrequency(): void
+ {
+ $this->expectException(\LogicException::class);
+ $this->valueMapper->mapRecurringFrequency('DAY');
+ }
+
+ public function testMapLang(): void
+ {
+ $this->expectException(\LogicException::class);
+ $this->valueMapper->mapLang(PosInterface::LANG_TR);
+ }
+
+ /**
+ * @return void
+ */
+ public function testMapCurrency(): void
+ {
+ $this->assertSame('0949', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_TRY));
+ $this->assertSame('0978', $this->valueMapper->mapCurrency(PosInterface::CURRENCY_EUR));
+ }
+
+ public function testGetLangMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getLangMappings());
+ }
+
+ public function testGetRecurringOrderFrequencyMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getRecurringOrderFrequencyMappings());
+ }
+
+ public function testGetCurrencyMappings(): void
+ {
+ $this->assertCount(6, $this->valueMapper->getCurrencyMappings());
+ }
+
+ public function testGetTxTypeMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getTxTypeMappings());
+ }
+
+ public function testGetSecureTypeMappings()
+ {
+ $this->assertCount(2, $this->valueMapper->getSecureTypeMappings());
+ }
+
+ public function testGetCardTypeMappings(): void
+ {
+ $this->assertCount(0, $this->valueMapper->getCardTypeMappings());
+ }
+
+ public function testMapCardType(): void
+ {
+ $this->expectException(\LogicException::class);
+ $this->valueMapper->mapCardType(CreditCardInterface::CARD_TYPE_VISA);
+ }
+
+ public static function mapSecureTypeDataProvider(): array
+ {
+ return [
+ [PosInterface::MODEL_3D_SECURE, '3'],
+ [PosInterface::MODEL_NON_SECURE, '5'],
+ ];
+ }
+}
diff --git a/tests/Unit/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapperTest.php
index f0f22df9..54ffd8f0 100644
--- a/tests/Unit/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapperTest.php
+++ b/tests/Unit/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapperTest.php
@@ -5,13 +5,11 @@
namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper;
-use Mews\Pos\Crypt\CryptInterface;
-use Mews\Pos\DataMapper\RequestDataMapper\AkbankPosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueMapper\AkbankPosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\AkbankPosResponseDataMapper;
use Mews\Pos\PosInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
/**
@@ -31,15 +29,12 @@ protected function setUp(): void
$this->logger = $this->createMock(LoggerInterface::class);
- $requestDataMapper = new AkbankPosRequestDataMapper(
- $this->createMock(EventDispatcherInterface::class),
- $this->createMock(CryptInterface::class),
- );
+ $requestValueMapper = new AkbankPosRequestValueMapper();
$this->responseDataMapper = new AkbankPosResponseDataMapper(
- $requestDataMapper->getCurrencyMappings(),
- $requestDataMapper->getTxTypeMappings(),
- $requestDataMapper->getSecureTypeMappings(),
+ $requestValueMapper->getCurrencyMappings(),
+ $requestValueMapper->getTxTypeMappings(),
+ $requestValueMapper->getSecureTypeMappings(),
$this->logger
);
}
diff --git a/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php
index 5be978b7..48d7948f 100644
--- a/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php
+++ b/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php
@@ -5,13 +5,11 @@
namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper;
-use Mews\Pos\Crypt\CryptInterface;
-use Mews\Pos\DataMapper\RequestDataMapper\EstPosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueMapper\EstPosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\EstPosResponseDataMapper;
use Mews\Pos\PosInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
/**
@@ -31,16 +29,13 @@ protected function setUp(): void
$this->logger = $this->createMock(LoggerInterface::class);
- $requestDataMapper = new EstPosRequestDataMapper(
- $this->createMock(EventDispatcherInterface::class),
- $this->createMock(CryptInterface::class),
- );
+ $requestValueMapper = new EstPosRequestValueMapper();
$this->responseDataMapper = new EstPosResponseDataMapper(
- $requestDataMapper->getCurrencyMappings(),
- $requestDataMapper->getTxTypeMappings(),
- $requestDataMapper->getSecureTypeMappings(),
- $this->logger,
+ $requestValueMapper->getCurrencyMappings(),
+ $requestValueMapper->getTxTypeMappings(),
+ $requestValueMapper->getSecureTypeMappings(),
+ $this->logger
);
}
diff --git a/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php
index 09b42c06..4e2d1945 100644
--- a/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php
+++ b/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php
@@ -5,14 +5,12 @@
namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper;
-use Mews\Pos\Crypt\CryptInterface;
-use Mews\Pos\DataMapper\RequestDataMapper\GarantiPosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueMapper\GarantiPosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\GarantiPosResponseDataMapper;
use Mews\Pos\Exceptions\NotImplementedException;
use Mews\Pos\PosInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
/**
@@ -32,16 +30,13 @@ protected function setUp(): void
$this->logger = $this->createMock(LoggerInterface::class);
- $requestDataMapper = new GarantiPosRequestDataMapper(
- $this->createMock(EventDispatcherInterface::class),
- $this->createMock(CryptInterface::class),
- );
+ $requestValueMapper = new GarantiPosRequestValueMapper();
$this->responseDataMapper = new GarantiPosResponseDataMapper(
- $requestDataMapper->getCurrencyMappings(),
- $requestDataMapper->getTxTypeMappings(),
- $requestDataMapper->getSecureTypeMappings(),
- $this->logger,
+ $requestValueMapper->getCurrencyMappings(),
+ $requestValueMapper->getTxTypeMappings(),
+ $requestValueMapper->getSecureTypeMappings(),
+ $this->logger
);
}
diff --git a/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php
index 5516cf02..c2707ffa 100644
--- a/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php
+++ b/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php
@@ -5,14 +5,12 @@
namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper;
-use Mews\Pos\Crypt\CryptInterface;
-use Mews\Pos\DataMapper\RequestDataMapper\InterPosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueMapper\InterPosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\InterPosResponseDataMapper;
use Mews\Pos\Exceptions\NotImplementedException;
use Mews\Pos\PosInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
/**
@@ -32,16 +30,13 @@ protected function setUp(): void
$this->logger = $this->createMock(LoggerInterface::class);
- $requestDataMapper = new InterPosRequestDataMapper(
- $this->createMock(EventDispatcherInterface::class),
- $this->createMock(CryptInterface::class),
- );
+ $requestValueMapper = new InterPosRequestValueMapper();
$this->responseDataMapper = new InterPosResponseDataMapper(
- $requestDataMapper->getCurrencyMappings(),
- $requestDataMapper->getTxTypeMappings(),
- $requestDataMapper->getSecureTypeMappings(),
- $this->logger,
+ $requestValueMapper->getCurrencyMappings(),
+ $requestValueMapper->getTxTypeMappings(),
+ $requestValueMapper->getSecureTypeMappings(),
+ $this->logger
);
}
diff --git a/tests/Unit/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapperTest.php
index 8348bfea..27842ba2 100644
--- a/tests/Unit/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapperTest.php
+++ b/tests/Unit/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapperTest.php
@@ -5,14 +5,12 @@
namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper;
-use Mews\Pos\Crypt\CryptInterface;
-use Mews\Pos\DataMapper\RequestDataMapper\KuveytPosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueMapper\KuveytPosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\KuveytPosResponseDataMapper;
use Mews\Pos\Exceptions\NotImplementedException;
use Mews\Pos\PosInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
/**
@@ -32,15 +30,13 @@ protected function setUp(): void
$this->logger = $this->createMock(LoggerInterface::class);
- $requestDataMapper = new KuveytPosRequestDataMapper(
- $this->createMock(EventDispatcherInterface::class),
- $this->createMock(CryptInterface::class),
- );
+ $requestValueMapper = new KuveytPosRequestValueMapper();
+
$this->responseDataMapper = new KuveytPosResponseDataMapper(
- $requestDataMapper->getCurrencyMappings(),
- $requestDataMapper->getTxTypeMappings(),
- $requestDataMapper->getSecureTypeMappings(),
- $this->logger,
+ $requestValueMapper->getCurrencyMappings(),
+ $requestValueMapper->getTxTypeMappings(),
+ $requestValueMapper->getSecureTypeMappings(),
+ $this->logger
);
}
diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexCPV4PosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexCPV4PosResponseDataMapperTest.php
index 785933a5..99eedab5 100644
--- a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexCPV4PosResponseDataMapperTest.php
+++ b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexCPV4PosResponseDataMapperTest.php
@@ -6,13 +6,11 @@
namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper;
use Generator;
-use Mews\Pos\Crypt\CryptInterface;
-use Mews\Pos\DataMapper\RequestDataMapper\PayFlexCPV4PosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueMapper\PayFlexCPV4PosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\PayFlexCPV4PosResponseDataMapper;
use Mews\Pos\PosInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
/**
@@ -32,15 +30,13 @@ protected function setUp(): void
$this->logger = $this->createMock(LoggerInterface::class);
- $requestDataMapper = new PayFlexCPV4PosRequestDataMapper(
- $this->createMock(EventDispatcherInterface::class),
- $this->createMock(CryptInterface::class),
- );
+ $requestValueMapper = new PayFlexCPV4PosRequestValueMapper();
+
$this->responseDataMapper = new PayFlexCPV4PosResponseDataMapper(
- $requestDataMapper->getCurrencyMappings(),
- $requestDataMapper->getTxTypeMappings(),
- $requestDataMapper->getSecureTypeMappings(),
- $this->logger,
+ $requestValueMapper->getCurrencyMappings(),
+ $requestValueMapper->getTxTypeMappings(),
+ $requestValueMapper->getSecureTypeMappings(),
+ $this->logger
);
}
diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php
index ec6ed1a1..6ced4f45 100644
--- a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php
+++ b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php
@@ -5,14 +5,12 @@
namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper;
-use Mews\Pos\Crypt\CryptInterface;
-use Mews\Pos\DataMapper\RequestDataMapper\PayFlexV4PosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueMapper\PayFlexV4PosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\PayFlexV4PosResponseDataMapper;
use Mews\Pos\Exceptions\NotImplementedException;
use Mews\Pos\PosInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
/**
@@ -32,15 +30,13 @@ protected function setUp(): void
$this->logger = $this->createMock(LoggerInterface::class);
- $requestDataMapper = new PayFlexV4PosRequestDataMapper(
- $this->createMock(EventDispatcherInterface::class),
- $this->createMock(CryptInterface::class)
- );
+ $requestValueMapper = new PayFlexV4PosRequestValueMapper();
+
$this->responseDataMapper = new PayFlexV4PosResponseDataMapper(
- $requestDataMapper->getCurrencyMappings(),
- $requestDataMapper->getTxTypeMappings(),
- $requestDataMapper->getSecureTypeMappings(),
- $this->logger,
+ $requestValueMapper->getCurrencyMappings(),
+ $requestValueMapper->getTxTypeMappings(),
+ $requestValueMapper->getSecureTypeMappings(),
+ $this->logger
);
}
diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php
index 000e5383..cb7cda27 100644
--- a/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php
+++ b/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php
@@ -5,13 +5,11 @@
namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper;
-use Mews\Pos\Crypt\CryptInterface;
-use Mews\Pos\DataMapper\RequestDataMapper\PayForPosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueMapper\PayForPosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\PayForPosResponseDataMapper;
use Mews\Pos\PosInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
/**
@@ -30,15 +28,13 @@ protected function setUp(): void
parent::setUp();
$this->logger = $this->createMock(LoggerInterface::class);
- $requestDataMapper = new PayForPosRequestDataMapper(
- $this->createMock(EventDispatcherInterface::class),
- $this->createMock(CryptInterface::class),
- );
+ $requestValueMapper = new PayForPosRequestValueMapper();
+
$this->responseDataMapper = new PayForPosResponseDataMapper(
- $requestDataMapper->getCurrencyMappings(),
- $requestDataMapper->getTxTypeMappings(),
- $requestDataMapper->getSecureTypeMappings(),
- $this->logger,
+ $requestValueMapper->getCurrencyMappings(),
+ $requestValueMapper->getTxTypeMappings(),
+ $requestValueMapper->getSecureTypeMappings(),
+ $this->logger
);
}
diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PosNetResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PosNetResponseDataMapperTest.php
index 4d6e4cf7..c7bc9c1c 100644
--- a/tests/Unit/DataMapper/ResponseDataMapper/PosNetResponseDataMapperTest.php
+++ b/tests/Unit/DataMapper/ResponseDataMapper/PosNetResponseDataMapperTest.php
@@ -5,14 +5,12 @@
namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper;
-use Mews\Pos\Crypt\CryptInterface;
-use Mews\Pos\DataMapper\RequestDataMapper\PosNetRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueMapper\PosNetRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\PosNetResponseDataMapper;
use Mews\Pos\Exceptions\NotImplementedException;
use Mews\Pos\PosInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
/**
@@ -31,15 +29,13 @@ protected function setUp(): void
parent::setUp();
$this->logger = $this->createMock(LoggerInterface::class);
- $requestDataMapper = new PosNetRequestDataMapper(
- $this->createMock(EventDispatcherInterface::class),
- $this->createMock(CryptInterface::class),
- );
+ $requestValueMapper = new PosNetRequestValueMapper();
+
$this->responseDataMapper = new PosNetResponseDataMapper(
- $requestDataMapper->getCurrencyMappings(),
- $requestDataMapper->getTxTypeMappings(),
- $requestDataMapper->getSecureTypeMappings(),
- $this->logger,
+ $requestValueMapper->getCurrencyMappings(),
+ $requestValueMapper->getTxTypeMappings(),
+ $requestValueMapper->getSecureTypeMappings(),
+ $this->logger
);
}
diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapperTest.php
index 2377133b..f029e5ab 100644
--- a/tests/Unit/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapperTest.php
+++ b/tests/Unit/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapperTest.php
@@ -5,14 +5,12 @@
namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper;
-use Mews\Pos\Crypt\CryptInterface;
-use Mews\Pos\DataMapper\RequestDataMapper\PosNetV1PosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueMapper\PosNetV1PosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\PosNetV1PosResponseDataMapper;
use Mews\Pos\Exceptions\NotImplementedException;
use Mews\Pos\PosInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
/**
@@ -33,15 +31,13 @@ protected function setUp(): void
$this->logger = $this->createMock(LoggerInterface::class);
- $requestDataMapper = new PosNetV1PosRequestDataMapper(
- $this->createMock(EventDispatcherInterface::class),
- $this->createMock(CryptInterface::class),
- );
+ $requestValueMapper = new PosNetV1PosRequestValueMapper();
+
$this->responseDataMapper = new PosNetV1PosResponseDataMapper(
- $requestDataMapper->getCurrencyMappings(),
- $requestDataMapper->getTxTypeMappings(),
- $requestDataMapper->getSecureTypeMappings(),
- $this->logger,
+ $requestValueMapper->getCurrencyMappings(),
+ $requestValueMapper->getTxTypeMappings(),
+ $requestValueMapper->getSecureTypeMappings(),
+ $this->logger
);
}
diff --git a/tests/Unit/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapperTest.php
index b3531111..f3d863ad 100644
--- a/tests/Unit/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapperTest.php
+++ b/tests/Unit/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapperTest.php
@@ -5,14 +5,12 @@
namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper;
-use Mews\Pos\Crypt\CryptInterface;
-use Mews\Pos\DataMapper\RequestDataMapper\ToslaPosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueMapper\ToslaPosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\ToslaPosResponseDataMapper;
use Mews\Pos\Exceptions\NotImplementedException;
use Mews\Pos\PosInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
/**
@@ -32,16 +30,13 @@ protected function setUp(): void
$this->logger = $this->createMock(LoggerInterface::class);
- $requestDataMapper = new ToslaPosRequestDataMapper(
- $this->createMock(EventDispatcherInterface::class),
- $this->createMock(CryptInterface::class),
- );
+ $requestValueMapper = new ToslaPosRequestValueMapper();
$this->responseDataMapper = new ToslaPosResponseDataMapper(
- $requestDataMapper->getCurrencyMappings(),
- $requestDataMapper->getTxTypeMappings(),
- $requestDataMapper->getSecureTypeMappings(),
- $this->logger,
+ $requestValueMapper->getCurrencyMappings(),
+ $requestValueMapper->getTxTypeMappings(),
+ $requestValueMapper->getSecureTypeMappings(),
+ $this->logger
);
}
diff --git a/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php
index 7b8f7e7e..07e827be 100644
--- a/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php
+++ b/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php
@@ -5,14 +5,12 @@
namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper;
-use Mews\Pos\Crypt\CryptInterface;
-use Mews\Pos\DataMapper\RequestDataMapper\VakifKatilimPosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueMapper\VakifKatilimPosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\VakifKatilimPosResponseDataMapper;
use Mews\Pos\Exceptions\NotImplementedException;
use Mews\Pos\PosInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
-use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
/**
@@ -31,15 +29,13 @@ protected function setUp(): void
parent::setUp();
$this->logger = $this->createMock(LoggerInterface::class);
- $requestDataMapper = new VakifKatilimPosRequestDataMapper(
- $this->createMock(EventDispatcherInterface::class),
- $this->createMock(CryptInterface::class),
- );
+ $requestValueMapper = new VakifKatilimPosRequestValueMapper();
+
$this->responseDataMapper = new VakifKatilimPosResponseDataMapper(
- $requestDataMapper->getCurrencyMappings(),
- $requestDataMapper->getTxTypeMappings(),
- $requestDataMapper->getSecureTypeMappings(),
- $this->logger,
+ $requestValueMapper->getCurrencyMappings(),
+ $requestValueMapper->getTxTypeMappings(),
+ $requestValueMapper->getSecureTypeMappings(),
+ $this->logger
);
}
diff --git a/tests/Unit/Factory/CreditCardFactoryTest.php b/tests/Unit/Factory/CreditCardFactoryTest.php
index a4528435..e218085c 100644
--- a/tests/Unit/Factory/CreditCardFactoryTest.php
+++ b/tests/Unit/Factory/CreditCardFactoryTest.php
@@ -37,9 +37,7 @@ public function testCreateForGatewaySuccess(): void
);
$this->assertSame('4444555566667777', $card->getNumber());
- $this->assertSame('2022', $card->getExpireYear('Y'));
- $this->assertSame('02', $card->getExpireMonth('m'));
- $this->assertSame('202202', $card->getExpirationDate('Ym'));
+ $this->assertSame('202202', $card->getExpirationDate()->format('Ym'));
$this->assertSame('john', $card->getHolderName());
$this->assertSame('123', $card->getCvv());
}
diff --git a/tests/Unit/Factory/RequestValueFormatterFactoryTest.php b/tests/Unit/Factory/RequestValueFormatterFactoryTest.php
new file mode 100644
index 00000000..d70ed7d7
--- /dev/null
+++ b/tests/Unit/Factory/RequestValueFormatterFactoryTest.php
@@ -0,0 +1,72 @@
+factory = new RequestValueFormatterFactory();
+ }
+
+ /**
+ * @dataProvider gatewayClassDataProvider
+ */
+ public function testCreateForGateway(string $gatewayClass, string $expectedFormatterClass): void
+ {
+ $this->assertInstanceOf(
+ $expectedFormatterClass,
+ RequestValueFormatterFactory::createForGateway($gatewayClass)
+ );
+ }
+
+ public static function gatewayClassDataProvider(): array
+ {
+ return [
+ [ToslaPos::class, ToslaPosRequestValueFormatter::class],
+ [AkbankPos::class, AkbankPosRequestValueFormatter::class],
+ [EstPos::class, EstPosRequestValueFormatter::class],
+ [EstV3Pos::class, EstPosRequestValueFormatter::class],
+ [GarantiPos::class, GarantiPosRequestValueFormatter::class],
+ [InterPos::class, InterPosRequestValueFormatter::class],
+ [KuveytPos::class, KuveytPosRequestValueFormatter::class],
+ [VakifKatilimPos::class, VakifKatilimPosRequestValueFormatter::class],
+ [PayForPos::class, PayForPosRequestValueFormatter::class],
+ [PosNet::class, PosNetRequestValueFormatter::class],
+ [PosNetV1Pos::class, PosNetV1PosRequestValueFormatter::class],
+ [PayFlexCPV4Pos::class, PayFlexCPV4PosRequestValueFormatter::class],
+ ];
+ }
+}
diff --git a/tests/Unit/Factory/RequestValueMapperFactoryTest.php b/tests/Unit/Factory/RequestValueMapperFactoryTest.php
new file mode 100644
index 00000000..f2b5a725
--- /dev/null
+++ b/tests/Unit/Factory/RequestValueMapperFactoryTest.php
@@ -0,0 +1,72 @@
+factory = new RequestValueMapperFactory();
+ }
+
+ /**
+ * @dataProvider gatewayClassDataProvider
+ */
+ public function testCreateForGateway(string $gatewayClass, string $expectedFormatterClass): void
+ {
+ $this->assertInstanceOf(
+ $expectedFormatterClass,
+ RequestValueMapperFactory::createForGateway($gatewayClass)
+ );
+ }
+
+ public static function gatewayClassDataProvider(): array
+ {
+ return [
+ [ToslaPos::class, ToslaPosRequestValueMapper::class],
+ [AkbankPos::class, AkbankPosRequestValueMapper::class],
+ [EstPos::class, EstPosRequestValueMapper::class],
+ [EstV3Pos::class, EstPosRequestValueMapper::class],
+ [GarantiPos::class, GarantiPosRequestValueMapper::class],
+ [InterPos::class, InterPosRequestValueMapper::class],
+ [KuveytPos::class, KuveytPosRequestValueMapper::class],
+ [VakifKatilimPos::class, VakifKatilimPosRequestValueMapper::class],
+ [PayForPos::class, PayForPosRequestValueMapper::class],
+ [PosNet::class, PosNetRequestValueMapper::class],
+ [PosNetV1Pos::class, PosNetV1PosRequestValueMapper::class],
+ [PayFlexCPV4Pos::class, PayFlexCPV4PosRequestValueMapper::class],
+ ];
+ }
+}
diff --git a/tests/Unit/Gateways/AkbankPosTest.php b/tests/Unit/Gateways/AkbankPosTest.php
index 917ebb77..25a72a45 100644
--- a/tests/Unit/Gateways/AkbankPosTest.php
+++ b/tests/Unit/Gateways/AkbankPosTest.php
@@ -8,6 +8,7 @@
use Mews\Pos\Client\HttpClient;
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\RequestDataMapperInterface;
+use Mews\Pos\DataMapper\RequestValueMapper\AkbankPosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\ResponseDataMapperInterface;
use Mews\Pos\Entity\Account\AkbankPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
@@ -65,6 +66,7 @@ class AkbankPosTest extends TestCase
/** @var SerializerInterface & MockObject */
private MockObject $serializerMock;
+ private AkbankPosRequestValueMapper $requestValueMapper;
protected function setUp(): void
{
@@ -88,6 +90,7 @@ protected function setUp(): void
PosInterface::LANG_TR
);
+ $this->requestValueMapper = new AkbankPosRequestValueMapper();
$this->requestMapperMock = $this->createMock(RequestDataMapperInterface::class);
$this->responseMapperMock = $this->createMock(ResponseDataMapperInterface::class);
$this->serializerMock = $this->createMock(SerializerInterface::class);
@@ -103,6 +106,7 @@ protected function setUp(): void
$this->pos = new AkbankPos(
$this->config,
$this->account,
+ $this->requestValueMapper,
$this->requestMapperMock,
$this->responseMapperMock,
$this->serializerMock,
diff --git a/tests/Unit/Gateways/EstPosTest.php b/tests/Unit/Gateways/EstPosTest.php
index 8e793276..512dc7a5 100644
--- a/tests/Unit/Gateways/EstPosTest.php
+++ b/tests/Unit/Gateways/EstPosTest.php
@@ -8,6 +8,7 @@
use Mews\Pos\Client\HttpClient;
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\RequestDataMapperInterface;
+use Mews\Pos\DataMapper\RequestValueMapper\EstPosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\ResponseDataMapperInterface;
use Mews\Pos\Entity\Account\EstPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
@@ -67,6 +68,7 @@ class EstPosTest extends TestCase
private CreditCardInterface $card;
private array $order;
+ private EstPosRequestValueMapper $requestValueMapper;
protected function setUp(): void
{
@@ -100,6 +102,7 @@ protected function setUp(): void
'lang' => PosInterface::LANG_TR,
];
+ $this->requestValueMapper = new EstPosRequestValueMapper();
$this->requestMapperMock = $this->createMock(RequestDataMapperInterface::class);
$this->responseMapperMock = $this->createMock(ResponseDataMapperInterface::class);
$this->serializerMock = $this->createMock(SerializerInterface::class);
@@ -115,6 +118,7 @@ protected function setUp(): void
$this->pos = new EstPos(
$this->config,
$this->account,
+ $this->requestValueMapper,
$this->requestMapperMock,
$this->responseMapperMock,
$this->serializerMock,
@@ -141,10 +145,7 @@ protected function setUp(): void
*/
public function testInit(): void
{
- $this->requestMapperMock->expects(self::once())
- ->method('getCurrencyMappings')
- ->willReturn([PosInterface::CURRENCY_TRY => '949']);
- $this->assertSame([PosInterface::CURRENCY_TRY], $this->pos->getCurrencies());
+ $this->assertCount(count($this->requestValueMapper->getCurrencyMappings()), $this->pos->getCurrencies());
$this->assertSame($this->config, $this->pos->getConfig());
$this->assertSame($this->account, $this->pos->getAccount());
}
diff --git a/tests/Unit/Gateways/GarantiPosTest.php b/tests/Unit/Gateways/GarantiPosTest.php
index 7c226550..096f4cda 100644
--- a/tests/Unit/Gateways/GarantiPosTest.php
+++ b/tests/Unit/Gateways/GarantiPosTest.php
@@ -8,6 +8,7 @@
use Mews\Pos\Client\HttpClient;
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\RequestDataMapperInterface;
+use Mews\Pos\DataMapper\RequestValueMapper\GarantiPosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\ResponseDataMapperInterface;
use Mews\Pos\Entity\Account\GarantiPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
@@ -64,6 +65,7 @@ class GarantiPosTest extends TestCase
private PosInterface $pos;
private CreditCardInterface $card;
+ private GarantiPosRequestValueMapper $requestValueMapper;
protected function setUp(): void
{
@@ -90,6 +92,7 @@ protected function setUp(): void
'123qweASD/'
);
+ $this->requestValueMapper = new GarantiPosRequestValueMapper();
$this->requestMapperMock = $this->createMock(RequestDataMapperInterface::class);
$this->responseMapperMock = $this->createMock(ResponseDataMapperInterface::class);
$this->serializerMock = $this->createMock(SerializerInterface::class);
@@ -105,6 +108,7 @@ protected function setUp(): void
$this->pos = new GarantiPos(
$this->config,
$this->account,
+ $this->requestValueMapper,
$this->requestMapperMock,
$this->responseMapperMock,
$this->serializerMock,
@@ -131,10 +135,7 @@ protected function setUp(): void
*/
public function testInit(): void
{
- $this->requestMapperMock->expects(self::once())
- ->method('getCurrencyMappings')
- ->willReturn([PosInterface::CURRENCY_TRY => '949']);
- $this->assertSame([PosInterface::CURRENCY_TRY], $this->pos->getCurrencies());
+ $this->assertCount(count($this->requestValueMapper->getCurrencyMappings()), $this->pos->getCurrencies());
$this->assertSame($this->config, $this->pos->getConfig());
$this->assertSame($this->account, $this->pos->getAccount());
}
diff --git a/tests/Unit/Gateways/InterPosTest.php b/tests/Unit/Gateways/InterPosTest.php
index 45405d9b..82c561cc 100644
--- a/tests/Unit/Gateways/InterPosTest.php
+++ b/tests/Unit/Gateways/InterPosTest.php
@@ -7,6 +7,7 @@
use Mews\Pos\Client\HttpClient;
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\RequestDataMapperInterface;
+use Mews\Pos\DataMapper\RequestValueMapper\InterPosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\ResponseDataMapperInterface;
use Mews\Pos\Entity\Account\InterPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
@@ -65,6 +66,7 @@ class InterPosTest extends TestCase
private array $config;
private array $order;
+ private InterPosRequestValueMapper $requestValueMapper;
protected function setUp(): void
{
@@ -104,7 +106,7 @@ protected function setUp(): void
'lang' => PosInterface::LANG_TR,
];
-
+ $this->requestValueMapper = new InterPosRequestValueMapper();
$this->requestMapperMock = $this->createMock(RequestDataMapperInterface::class);
$this->responseMapperMock = $this->createMock(ResponseDataMapperInterface::class);
$this->serializerMock = $this->createMock(SerializerInterface::class);
@@ -120,6 +122,7 @@ protected function setUp(): void
$this->pos = new InterPos(
$this->config,
$this->account,
+ $this->requestValueMapper,
$this->requestMapperMock,
$this->responseMapperMock,
$this->serializerMock,
@@ -138,10 +141,7 @@ protected function setUp(): void
*/
public function testInit(): void
{
- $this->requestMapperMock->expects(self::once())
- ->method('getCurrencyMappings')
- ->willReturn([PosInterface::CURRENCY_TRY => '949']);
- $this->assertSame([PosInterface::CURRENCY_TRY], $this->pos->getCurrencies());
+ $this->assertCount(count($this->requestValueMapper->getCurrencyMappings()), $this->pos->getCurrencies());
$this->assertSame($this->config, $this->pos->getConfig());
$this->assertSame($this->account, $this->pos->getAccount());
}
diff --git a/tests/Unit/Gateways/KuveytPosTest.php b/tests/Unit/Gateways/KuveytPosTest.php
index 7e1eeaa9..5b89ab24 100644
--- a/tests/Unit/Gateways/KuveytPosTest.php
+++ b/tests/Unit/Gateways/KuveytPosTest.php
@@ -8,6 +8,7 @@
use Mews\Pos\Client\HttpClient;
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\KuveytPosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueMapper\KuveytPosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\ResponseDataMapperInterface;
use Mews\Pos\Entity\Account\KuveytPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
@@ -67,6 +68,7 @@ class KuveytPosTest extends TestCase
/** @var SerializerInterface & MockObject */
private MockObject $serializerMock;
+ private KuveytPosRequestValueMapper $requestValueMapper;
/**
* @return void
@@ -106,6 +108,7 @@ protected function setUp(): void
'lang' => PosInterface::LANG_TR,
];
+ $this->requestValueMapper = new KuveytPosRequestValueMapper();
$this->requestMapperMock = $this->createMock(KuveytPosRequestDataMapper::class);
$this->responseMapperMock = $this->createMock(ResponseDataMapperInterface::class);
$this->serializerMock = $this->createMock(SerializerInterface::class);
@@ -121,6 +124,7 @@ protected function setUp(): void
$this->pos = new KuveytPos(
$this->config,
$this->account,
+ $this->requestValueMapper,
$this->requestMapperMock,
$this->responseMapperMock,
$this->serializerMock,
@@ -147,10 +151,7 @@ protected function setUp(): void
*/
public function testInit(): void
{
- $this->requestMapperMock->expects(self::once())
- ->method('getCurrencyMappings')
- ->willReturn([PosInterface::CURRENCY_TRY => '949']);
- $this->assertSame([PosInterface::CURRENCY_TRY], $this->pos->getCurrencies());
+ $this->assertCount(count($this->requestValueMapper->getCurrencyMappings()), $this->pos->getCurrencies());
$this->assertSame($this->config, $this->pos->getConfig());
$this->assertSame($this->account, $this->pos->getAccount());
}
diff --git a/tests/Unit/Gateways/PayFlexCPV4PosTest.php b/tests/Unit/Gateways/PayFlexCPV4PosTest.php
index b039bcb8..295ee3f0 100644
--- a/tests/Unit/Gateways/PayFlexCPV4PosTest.php
+++ b/tests/Unit/Gateways/PayFlexCPV4PosTest.php
@@ -10,6 +10,7 @@
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\PayFlexCPV4PosRequestDataMapper;
use Mews\Pos\DataMapper\RequestDataMapper\RequestDataMapperInterface;
+use Mews\Pos\DataMapper\RequestValueMapper\PayFlexCPV4PosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\PayFlexCPV4PosResponseDataMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\ResponseDataMapperInterface;
use Mews\Pos\Entity\Account\PayFlexAccount;
@@ -70,6 +71,7 @@ class PayFlexCPV4PosTest extends TestCase
/** @var SerializerInterface & MockObject */
private MockObject $serializerMock;
+ private PayFlexCPV4PosRequestValueMapper $requestValueMapper;
protected function setUp(): void
{
@@ -104,6 +106,7 @@ protected function setUp(): void
'ip' => '127.0.0.1',
];
+ $this->requestValueMapper = new PayFlexCPV4PosRequestValueMapper();
$this->requestMapperMock = $this->createMock(PayFlexCPV4PosRequestDataMapper::class);
$this->responseMapperMock = $this->createMock(PayFlexCPV4PosResponseDataMapper::class);
$this->serializerMock = $this->createMock(SerializerInterface::class);
@@ -119,6 +122,7 @@ protected function setUp(): void
$this->pos = new PayFlexCPV4Pos(
$this->config,
$this->account,
+ $this->requestValueMapper,
$this->requestMapperMock,
$this->responseMapperMock,
$this->serializerMock,
@@ -137,10 +141,7 @@ protected function setUp(): void
*/
public function testInit(): void
{
- $this->requestMapperMock->expects(self::once())
- ->method('getCurrencyMappings')
- ->willReturn([PosInterface::CURRENCY_TRY => '949']);
- $this->assertSame([PosInterface::CURRENCY_TRY], $this->pos->getCurrencies());
+ $this->assertCount(count($this->requestValueMapper->getCurrencyMappings()), $this->pos->getCurrencies());
$this->assertSame($this->config, $this->pos->getConfig());
$this->assertSame($this->account, $this->pos->getAccount());
}
diff --git a/tests/Unit/Gateways/PayFlexV4PosTest.php b/tests/Unit/Gateways/PayFlexV4PosTest.php
index 1f359b55..9b6a13a1 100644
--- a/tests/Unit/Gateways/PayFlexV4PosTest.php
+++ b/tests/Unit/Gateways/PayFlexV4PosTest.php
@@ -10,6 +10,7 @@
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\PayFlexV4PosRequestDataMapper;
use Mews\Pos\DataMapper\RequestDataMapper\RequestDataMapperInterface;
+use Mews\Pos\DataMapper\RequestValueMapper\PayFlexV4PosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\ResponseDataMapperInterface;
use Mews\Pos\Entity\Account\PayFlexAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
@@ -69,6 +70,7 @@ class PayFlexV4PosTest extends TestCase
/** @var SerializerInterface & MockObject */
private MockObject $serializerMock;
+ private PayFlexV4PosRequestValueMapper $requestValueMapper;
protected function setUp(): void
{
@@ -103,6 +105,7 @@ protected function setUp(): void
'ip' => '127.0.0.1',
];
+ $this->requestValueMapper = new PayFlexV4PosRequestValueMapper();
$this->requestMapperMock = $this->createMock(PayFlexV4PosRequestDataMapper::class);
$this->responseMapperMock = $this->createMock(ResponseDataMapperInterface::class);
$this->serializerMock = $this->createMock(SerializerInterface::class);
@@ -118,6 +121,7 @@ protected function setUp(): void
$this->pos = new PayFlexV4Pos(
$this->config,
$this->account,
+ $this->requestValueMapper,
$this->requestMapperMock,
$this->responseMapperMock,
$this->serializerMock,
@@ -143,10 +147,7 @@ protected function setUp(): void
*/
public function testInit(): void
{
- $this->requestMapperMock->expects(self::once())
- ->method('getCurrencyMappings')
- ->willReturn([PosInterface::CURRENCY_TRY => '949']);
- $this->assertSame([PosInterface::CURRENCY_TRY], $this->pos->getCurrencies());
+ $this->assertCount(count($this->requestValueMapper->getCurrencyMappings()), $this->pos->getCurrencies());
$this->assertSame($this->config, $this->pos->getConfig());
$this->assertSame($this->account, $this->pos->getAccount());
}
diff --git a/tests/Unit/Gateways/PayForTest.php b/tests/Unit/Gateways/PayForTest.php
index 34577dd3..34b3e3b1 100644
--- a/tests/Unit/Gateways/PayForTest.php
+++ b/tests/Unit/Gateways/PayForTest.php
@@ -8,6 +8,7 @@
use Mews\Pos\Client\HttpClient;
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\RequestDataMapperInterface;
+use Mews\Pos\DataMapper\RequestValueMapper\PayForPosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\ResponseDataMapperInterface;
use Mews\Pos\Entity\Account\PayForAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
@@ -63,6 +64,7 @@ class PayForTest extends TestCase
private MockObject $serializerMock;
private CreditCardInterface $card;
+ private PayForPosRequestValueMapper $requestValueMapper;
protected function setUp(): void
{
@@ -87,6 +89,7 @@ protected function setUp(): void
'12345678'
);
+ $this->requestValueMapper = new PayForPosRequestValueMapper();
$this->requestMapperMock = $this->createMock(RequestDataMapperInterface::class);
$this->responseMapperMock = $this->createMock(ResponseDataMapperInterface::class);
$this->serializerMock = $this->createMock(SerializerInterface::class);
@@ -102,6 +105,7 @@ protected function setUp(): void
$this->pos = new PayForPos(
$this->config,
$this->account,
+ $this->requestValueMapper,
$this->requestMapperMock,
$this->responseMapperMock,
$this->serializerMock,
@@ -128,12 +132,9 @@ protected function setUp(): void
*/
public function testInit(): void
{
- $this->requestMapperMock->expects(self::once())
- ->method('getCurrencyMappings')
- ->willReturn([PosInterface::CURRENCY_TRY => '949']);
+ $this->assertCount(count($this->requestValueMapper->getCurrencyMappings()), $this->pos->getCurrencies());
$this->assertSame($this->config, $this->pos->getConfig());
$this->assertSame($this->account, $this->pos->getAccount());
- $this->assertSame([PosInterface::CURRENCY_TRY], $this->pos->getCurrencies());
$this->assertSame($this->config['gateway_endpoints']['gateway_3d_host'], $this->pos->get3DHostGatewayURL());
$this->assertSame($this->config['gateway_endpoints']['gateway_3d'], $this->pos->get3DGatewayURL());
$this->assertSame($this->config['gateway_endpoints']['payment_api'], $this->pos->getApiURL());
diff --git a/tests/Unit/Gateways/PosNetTest.php b/tests/Unit/Gateways/PosNetTest.php
index 9525d4f7..bf037db5 100644
--- a/tests/Unit/Gateways/PosNetTest.php
+++ b/tests/Unit/Gateways/PosNetTest.php
@@ -10,6 +10,7 @@
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\PosNetRequestDataMapper;
use Mews\Pos\DataMapper\RequestDataMapper\RequestDataMapperInterface;
+use Mews\Pos\DataMapper\RequestValueMapper\EstPosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\PosNetResponseDataMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\ResponseDataMapperInterface;
use Mews\Pos\Entity\Account\PosNetAccount;
@@ -70,6 +71,7 @@ class PosNetTest extends TestCase
/** @var SerializerInterface & MockObject */
private MockObject $serializerMock;
+ private EstPosRequestValueMapper $requestValueMapper;
protected function setUp(): void
{
@@ -103,6 +105,7 @@ protected function setUp(): void
'lang' => PosInterface::LANG_TR,
];
+ $this->requestValueMapper = new EstPosRequestValueMapper();
$this->requestMapperMock = $this->createMock(PosNetRequestDataMapper::class);
$this->responseMapperMock = $this->createMock(PosNetResponseDataMapper::class);
$this->serializerMock = $this->createMock(SerializerInterface::class);
@@ -118,6 +121,7 @@ protected function setUp(): void
$this->pos = new PosNet(
$this->config,
$this->account,
+ $this->requestValueMapper,
$this->requestMapperMock,
$this->responseMapperMock,
$this->serializerMock,
@@ -136,10 +140,7 @@ protected function setUp(): void
*/
public function testInit(): void
{
- $this->requestMapperMock->expects(self::once())
- ->method('getCurrencyMappings')
- ->willReturn([PosInterface::CURRENCY_TRY => '949']);
- $this->assertSame([PosInterface::CURRENCY_TRY], $this->pos->getCurrencies());
+ $this->assertCount(count($this->requestValueMapper->getCurrencyMappings()), $this->pos->getCurrencies());
$this->assertSame($this->config, $this->pos->getConfig());
$this->assertSame($this->account, $this->pos->getAccount());
}
diff --git a/tests/Unit/Gateways/PosNetV1PosTest.php b/tests/Unit/Gateways/PosNetV1PosTest.php
index 929b2872..359400b2 100644
--- a/tests/Unit/Gateways/PosNetV1PosTest.php
+++ b/tests/Unit/Gateways/PosNetV1PosTest.php
@@ -8,6 +8,7 @@
use Mews\Pos\Client\HttpClient;
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\RequestDataMapperInterface;
+use Mews\Pos\DataMapper\RequestValueMapper\PosNetV1PosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\ResponseDataMapperInterface;
use Mews\Pos\Entity\Account\PosNetAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
@@ -65,6 +66,7 @@ class PosNetV1PosTest extends TestCase
/** @var SerializerInterface & MockObject */
private MockObject $serializerMock;
+ private PosNetV1PosRequestValueMapper $requestValueMapper;
protected function setUp(): void
{
@@ -88,6 +90,7 @@ protected function setUp(): void
'10,10,10,10,10,10,10,10'
);
+ $this->requestValueMapper = new PosNetV1PosRequestValueMapper();
$this->requestMapperMock = $this->createMock(RequestDataMapperInterface::class);
$this->responseMapperMock = $this->createMock(ResponseDataMapperInterface::class);
$this->serializerMock = $this->createMock(SerializerInterface::class);
@@ -103,6 +106,7 @@ protected function setUp(): void
$this->pos = new PosNetV1Pos(
$this->config,
$this->account,
+ $this->requestValueMapper,
$this->requestMapperMock,
$this->responseMapperMock,
$this->serializerMock,
@@ -121,10 +125,7 @@ protected function setUp(): void
*/
public function testInit(): void
{
- $this->requestMapperMock->expects(self::once())
- ->method('getCurrencyMappings')
- ->willReturn([PosInterface::CURRENCY_TRY => '949']);
- $this->assertSame([PosInterface::CURRENCY_TRY], $this->pos->getCurrencies());
+ $this->assertCount(count($this->requestValueMapper->getCurrencyMappings()), $this->pos->getCurrencies());
$this->assertSame($this->config, $this->pos->getConfig());
$this->assertSame($this->account, $this->pos->getAccount());
}
@@ -134,18 +135,18 @@ public function testInit(): void
*/
public function testGetApiURL(string $txType, string $mappedTxType, string $expected): void
{
- $this->requestMapperMock->expects(self::once())
- ->method('mapTxType')
- ->with($txType)
- ->willReturn($mappedTxType);
+// $this->requestValueMapper->expects(self::once())
+// ->method('mapTxType')
+// ->with($txType)
+// ->willReturn($mappedTxType);
$this->assertSame($expected, $this->pos->getApiURL($txType));
}
public function testGetApiURLException(): void
{
- $this->requestMapperMock->expects(self::never())
- ->method('mapTxType');
+// $this->requestValueMapper->expects(self::never())
+// ->method('mapTxType');
$this->expectException(\InvalidArgumentException::class);
$this->pos->getApiURL();
@@ -215,10 +216,10 @@ public function testMake3DPayment(
'create3DPaymentRequestData',
];
if ($is3DSuccess) {
- $this->requestMapperMock->expects(self::once())
- ->method('mapTxType')
- ->with($txType)
- ->willReturn('Sale');
+// $this->requestMapperMock->expects(self::once())
+// ->method('mapTxType')
+// ->with($txType)
+// ->willReturn('Sale');
$this->requestMapperMock->expects(self::once())
->method('create3DPaymentRequestData')
->with($this->account, $order, $txType, $request->request->all())
@@ -226,7 +227,7 @@ public function testMake3DPayment(
$this->configureClientResponse(
$txType,
- 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc/Sale',
+ 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc/Auth',
$create3DPaymentRequestData,
'request-body',
'response-body',
@@ -316,10 +317,10 @@ public function testMakeRegularPayment(array $order, string $txType, string $map
$card = $this->card;
$requestData = ['createNonSecurePaymentRequestData'];
- $this->requestMapperMock->expects(self::once())
- ->method('mapTxType')
- ->with($txType)
- ->willReturn($mappedTxType);
+// $this->requestMapperMock->expects(self::once())
+// ->method('mapTxType')
+// ->with($txType)
+// ->willReturn($mappedTxType);
$this->requestMapperMock->expects(self::once())
->method('createNonSecurePaymentRequestData')
@@ -355,10 +356,10 @@ public function testMakeRegularPostAuthPayment(array $order, string $apiUrl): vo
$txType = PosInterface::TX_TYPE_PAY_POST_AUTH;
$requestData = ['createNonSecurePostAuthPaymentRequestData'];
- $this->requestMapperMock->expects(self::once())
- ->method('mapTxType')
- ->with($txType)
- ->willReturn('Capture');
+// $this->requestMapperMock->expects(self::once())
+// ->method('mapTxType')
+// ->with($txType)
+// ->willReturn('Capture');
$this->requestMapperMock->expects(self::once())
->method('createNonSecurePostAuthPaymentRequestData')
@@ -395,10 +396,10 @@ public function testStatusRequest(array $order, string $apiUrl): void
$txType = PosInterface::TX_TYPE_STATUS;
$requestData = ['createStatusRequestData'];
- $this->requestMapperMock->expects(self::once())
- ->method('mapTxType')
- ->with($txType)
- ->willReturn('TransactionInquiry');
+// $this->requestMapperMock->expects(self::once())
+// ->method('mapTxType')
+// ->with($txType)
+// ->willReturn('TransactionInquiry');
$this->requestMapperMock->expects(self::once())
->method('createStatusRequestData')
@@ -434,10 +435,10 @@ public function testCancelRequest(array $order, string $apiUrl): void
$txType = PosInterface::TX_TYPE_CANCEL;
$requestData = ['createCancelRequestData'];
- $this->requestMapperMock->expects(self::once())
- ->method('mapTxType')
- ->with($txType)
- ->willReturn('Reverse');
+// $this->requestMapperMock->expects(self::once())
+// ->method('mapTxType')
+// ->with($txType)
+// ->willReturn('Reverse');
$this->requestMapperMock->expects(self::once())
->method('createCancelRequestData')
@@ -472,11 +473,11 @@ public function testRefundRequest(array $order, string $apiUrl): void
$account = $this->pos->getAccount();
$txType = PosInterface::TX_TYPE_REFUND;
$requestData = ['createRefundRequestData'];
-
- $this->requestMapperMock->expects(self::once())
- ->method('mapTxType')
- ->with($txType)
- ->willReturn('Return');
+//
+// $this->requestMapperMock->expects(self::once())
+// ->method('mapTxType')
+// ->with($txType)
+// ->willReturn('Return');
$this->requestMapperMock->expects(self::once())
->method('createRefundRequestData')
diff --git a/tests/Unit/Gateways/ToslaPosTest.php b/tests/Unit/Gateways/ToslaPosTest.php
index 3a86ad52..fb0b629a 100644
--- a/tests/Unit/Gateways/ToslaPosTest.php
+++ b/tests/Unit/Gateways/ToslaPosTest.php
@@ -8,6 +8,7 @@
use Mews\Pos\Client\HttpClient;
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\ToslaPosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueMapper\ToslaPosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\ResponseDataMapperInterface;
use Mews\Pos\Entity\Account\ToslaPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
@@ -67,6 +68,7 @@ class ToslaPosTest extends TestCase
/** @var SerializerInterface & MockObject */
private MockObject $serializerMock;
+ private ToslaPosRequestValueMapper $requestValueMapper;
protected function setUp(): void
{
@@ -89,6 +91,7 @@ protected function setUp(): void
'POS_ENT_Test_001!*!*',
);
+ $this->requestValueMapper = new ToslaPosRequestValueMapper();
$this->requestMapperMock = $this->createMock(ToslaPosRequestDataMapper::class);
$this->responseMapperMock = $this->createMock(ResponseDataMapperInterface::class);
$this->serializerMock = $this->createMock(SerializerInterface::class);
@@ -104,6 +107,7 @@ protected function setUp(): void
$this->pos = new ToslaPos(
$this->config,
$this->account,
+ $this->requestValueMapper,
$this->requestMapperMock,
$this->responseMapperMock,
$this->serializerMock,
diff --git a/tests/Unit/Gateways/VakifKatilimTest.php b/tests/Unit/Gateways/VakifKatilimTest.php
index 336a7f4b..0a7112ed 100644
--- a/tests/Unit/Gateways/VakifKatilimTest.php
+++ b/tests/Unit/Gateways/VakifKatilimTest.php
@@ -8,6 +8,7 @@
use Mews\Pos\Client\HttpClient;
use Mews\Pos\Crypt\CryptInterface;
use Mews\Pos\DataMapper\RequestDataMapper\VakifKatilimPosRequestDataMapper;
+use Mews\Pos\DataMapper\RequestValueMapper\VakifKatilimPosRequestValueMapper;
use Mews\Pos\DataMapper\ResponseDataMapper\ResponseDataMapperInterface;
use Mews\Pos\Entity\Account\KuveytPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
@@ -66,6 +67,7 @@ class VakifKatilimTest extends TestCase
/** @var SerializerInterface & MockObject */
private MockObject $serializerMock;
+ private VakifKatilimPosRequestValueMapper $requestValueMapper;
/**
* @return void
@@ -102,6 +104,7 @@ protected function setUp(): void
'fail_url' => 'http://localhost/finansbank-payfor/3d/response.php',
];
+ $this->requestValueMapper = new VakifKatilimPosRequestValueMapper();
$this->requestMapperMock = $this->createMock(VakifKatilimPosRequestDataMapper::class);
$this->responseMapperMock = $this->createMock(ResponseDataMapperInterface::class);
$this->serializerMock = $this->createMock(SerializerInterface::class);
@@ -117,6 +120,7 @@ protected function setUp(): void
$this->pos = new VakifKatilimPos(
$this->config,
$this->account,
+ $this->requestValueMapper,
$this->requestMapperMock,
$this->responseMapperMock,
$this->serializerMock,
@@ -143,10 +147,7 @@ protected function setUp(): void
*/
public function testInit(): void
{
- $this->requestMapperMock->expects(self::once())
- ->method('getCurrencyMappings')
- ->willReturn([PosInterface::CURRENCY_TRY => '0949']);
- $this->assertSame([PosInterface::CURRENCY_TRY], $this->pos->getCurrencies());
+ $this->assertCount(count($this->requestValueMapper->getCurrencyMappings()), $this->pos->getCurrencies());
$this->assertSame($this->config, $this->pos->getConfig());
$this->assertSame($this->account, $this->pos->getAccount());
}