From 63b68a50ed89aa3c9811c3307934232dda80797f Mon Sep 17 00:00:00 2001 From: mustapayev Date: Sun, 13 Oct 2024 13:05:48 +0200 Subject: [PATCH] implemented response value formatters and mappers --- phpstan-baseline.neon | 5 - .../KuveytPosRequestValueFormatter.php | 16 +- .../KuveytPosRequestValueMapper.php | 3 - .../VakifKatilimPosRequestValueMapper.php | 10 - .../AbstractResponseDataMapper.php | 101 ++------- .../AkbankPosResponseDataMapper.php | 163 ++++---------- .../EstPosResponseDataMapper.php | 118 ++++------ .../GarantiPosResponseDataMapper.php | 212 +++++------------- .../InterPosResponseDataMapper.php | 27 +-- .../KuveytPosResponseDataMapper.php | 76 ++----- .../PayFlexCPV4PosResponseDataMapper.php | 12 +- .../PayFlexV4PosResponseDataMapper.php | 43 ++-- .../PayForPosResponseDataMapper.php | 51 +++-- .../PosNetResponseDataMapper.php | 42 ++-- .../PosNetV1PosResponseDataMapper.php | 91 ++------ .../ToslaPosResponseDataMapper.php | 75 ++----- .../VakifKatilimPosResponseDataMapper.php | 70 ++---- .../AbstractResponseValueFormatter.php | 34 +++ .../BasicResponseValueFormatter.php | 9 + .../BoaPosResponseValueFormatter.php | 20 ++ .../EstPosResponseValueFormatter.php | 22 ++ .../GarantiPosResponseValueFormatter.php | 38 ++++ .../InterPosResponseValueFormatter.php | 28 +++ .../PosNetResponseValueFormatter.php | 26 +++ .../ResponseValueFormatterInterface.php | 40 ++++ .../ToslaPosResponseValueFormatter.php | 26 +++ .../AbstractResponseValueMapper.php | 99 ++++++++ .../AkbankPosResponseValueMapper.php | 63 ++++++ .../BoaPosResponseValueMapper.php | 37 +++ .../EstPosResponseValueMapper.php | 54 +++++ .../GarantiPosResponseValueMapper.php | 151 +++++++++++++ .../InterPosResponseValueMapper.php | 9 + .../PayFlexCPV4PosResponseValueMapper.php | 9 + .../PayFlexV4PosResponseValueMapper.php | 19 ++ .../PayForPosResponseValueMapper.php | 10 + .../PosNetResponseValueMapper.php | 9 + .../PosNetV1PosResponseValueMapper.php | 43 ++++ .../ResponseValueMapperInterface.php | 46 ++++ .../ToslaPosResponseValueMapper.php | 34 +++ src/Factory/PosFactory.php | 21 +- src/Factory/ResponseDataMapperFactory.php | 22 +- src/Factory/ResponseValueFormatterFactory.php | 64 ++++++ src/Factory/ResponseValueMapperFactory.php | 101 +++++++++ .../KuveytPosRequestValueMapperTest.php | 2 +- .../AkbankPosResponseDataMapperTest.php | 15 +- .../EstPosResponseDataMapperTest.php | 15 +- .../GarantiPosResponseDataMapperTest.php | 15 +- .../InterPosResponseDataMapperTest.php | 13 +- .../KuveytPosResponseDataMapperTest.php | 26 +-- .../PayFlexCPV4PosResponseDataMapperTest.php | 15 +- .../PayFlexV4PosResponseDataMapperTest.php | 15 +- .../PayForPosResponseDataMapperTest.php | 15 +- .../PosNetResponseDataMapperTest.php | 15 +- .../PosNetV1PosResponseDataMapperTest.php | 15 +- .../ToslaPosResponseDataMapperTest.php | 15 +- .../VakifKatilimPosResponseDataMapperTest.php | 26 +-- .../BasicResponseValueFormatterTest.php | 108 +++++++++ .../BoaPosResponseValueFormatterTest.php | 38 ++++ .../EstPosResponseValueFormatterTest.php | 47 ++++ .../GarantiPosResponseValueFormatterTest.php | 70 ++++++ .../InterPosResponseValueFormatterTest.php | 47 ++++ .../PosNetResponseValueFormatterTest.php | 41 ++++ .../ToslaPosResponseValueFormatterTest.php | 45 ++++ .../AkbankPosResponseValueMapperTest.php | 121 ++++++++++ .../BoaPosResponseValueMapperTest.php | 117 ++++++++++ .../EstPosResponseValueMapperTest.php | 124 ++++++++++ .../GarantiPosResponseValueMapperTest.php | 138 ++++++++++++ .../InterPosResponseValueMapperTest.php | 70 ++++++ .../PayFlexCPV4PosResponseValueMapperTest.php | 86 +++++++ .../PayFlexV4PosResponseValueMapperTest.php | 100 +++++++++ .../PayForPosResponseValueMapperTest.php | 102 +++++++++ .../PosNetResponseValueMapperTest.php | 87 +++++++ .../PosNetV1PosResponseValueMapperTest.php | 110 +++++++++ .../ToslaPosResponseValueMapperTest.php | 106 +++++++++ .../Factory/RequestValueMapperFactoryTest.php | 9 +- .../Factory/ResponseDataMapperFactoryTest.php | 22 +- .../ResponseValueFormatterFactoryTest.php | 62 +++++ .../ResponseValueMapperFactoryTest.php | 76 +++++++ 78 files changed, 3181 insertions(+), 896 deletions(-) create mode 100644 src/DataMapper/ResponseValueFormatter/AbstractResponseValueFormatter.php create mode 100644 src/DataMapper/ResponseValueFormatter/BasicResponseValueFormatter.php create mode 100644 src/DataMapper/ResponseValueFormatter/BoaPosResponseValueFormatter.php create mode 100644 src/DataMapper/ResponseValueFormatter/EstPosResponseValueFormatter.php create mode 100644 src/DataMapper/ResponseValueFormatter/GarantiPosResponseValueFormatter.php create mode 100644 src/DataMapper/ResponseValueFormatter/InterPosResponseValueFormatter.php create mode 100644 src/DataMapper/ResponseValueFormatter/PosNetResponseValueFormatter.php create mode 100644 src/DataMapper/ResponseValueFormatter/ResponseValueFormatterInterface.php create mode 100644 src/DataMapper/ResponseValueFormatter/ToslaPosResponseValueFormatter.php create mode 100644 src/DataMapper/ResponseValueMapper/AbstractResponseValueMapper.php create mode 100644 src/DataMapper/ResponseValueMapper/AkbankPosResponseValueMapper.php create mode 100644 src/DataMapper/ResponseValueMapper/BoaPosResponseValueMapper.php create mode 100644 src/DataMapper/ResponseValueMapper/EstPosResponseValueMapper.php create mode 100644 src/DataMapper/ResponseValueMapper/GarantiPosResponseValueMapper.php create mode 100644 src/DataMapper/ResponseValueMapper/InterPosResponseValueMapper.php create mode 100644 src/DataMapper/ResponseValueMapper/PayFlexCPV4PosResponseValueMapper.php create mode 100644 src/DataMapper/ResponseValueMapper/PayFlexV4PosResponseValueMapper.php create mode 100644 src/DataMapper/ResponseValueMapper/PayForPosResponseValueMapper.php create mode 100644 src/DataMapper/ResponseValueMapper/PosNetResponseValueMapper.php create mode 100644 src/DataMapper/ResponseValueMapper/PosNetV1PosResponseValueMapper.php create mode 100644 src/DataMapper/ResponseValueMapper/ResponseValueMapperInterface.php create mode 100644 src/DataMapper/ResponseValueMapper/ToslaPosResponseValueMapper.php create mode 100644 src/Factory/ResponseValueFormatterFactory.php create mode 100644 src/Factory/ResponseValueMapperFactory.php create mode 100644 tests/Unit/DataMapper/ResponseValueFormatter/BasicResponseValueFormatterTest.php create mode 100644 tests/Unit/DataMapper/ResponseValueFormatter/BoaPosResponseValueFormatterTest.php create mode 100644 tests/Unit/DataMapper/ResponseValueFormatter/EstPosResponseValueFormatterTest.php create mode 100644 tests/Unit/DataMapper/ResponseValueFormatter/GarantiPosResponseValueFormatterTest.php create mode 100644 tests/Unit/DataMapper/ResponseValueFormatter/InterPosResponseValueFormatterTest.php create mode 100644 tests/Unit/DataMapper/ResponseValueFormatter/PosNetResponseValueFormatterTest.php create mode 100644 tests/Unit/DataMapper/ResponseValueFormatter/ToslaPosResponseValueFormatterTest.php create mode 100644 tests/Unit/DataMapper/ResponseValueMapper/AkbankPosResponseValueMapperTest.php create mode 100644 tests/Unit/DataMapper/ResponseValueMapper/BoaPosResponseValueMapperTest.php create mode 100644 tests/Unit/DataMapper/ResponseValueMapper/EstPosResponseValueMapperTest.php create mode 100644 tests/Unit/DataMapper/ResponseValueMapper/GarantiPosResponseValueMapperTest.php create mode 100644 tests/Unit/DataMapper/ResponseValueMapper/InterPosResponseValueMapperTest.php create mode 100644 tests/Unit/DataMapper/ResponseValueMapper/PayFlexCPV4PosResponseValueMapperTest.php create mode 100644 tests/Unit/DataMapper/ResponseValueMapper/PayFlexV4PosResponseValueMapperTest.php create mode 100644 tests/Unit/DataMapper/ResponseValueMapper/PayForPosResponseValueMapperTest.php create mode 100644 tests/Unit/DataMapper/ResponseValueMapper/PosNetResponseValueMapperTest.php create mode 100644 tests/Unit/DataMapper/ResponseValueMapper/PosNetV1PosResponseValueMapperTest.php create mode 100644 tests/Unit/DataMapper/ResponseValueMapper/ToslaPosResponseValueMapperTest.php create mode 100644 tests/Unit/Factory/ResponseValueFormatterFactoryTest.php create mode 100644 tests/Unit/Factory/ResponseValueMapperFactoryTest.php diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 1083f216..65676bbd 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -125,11 +125,6 @@ parameters: count: 1 path: src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php - - - message: "#^Property Mews\\\\Pos\\\\DataMapper\\\\ResponseDataMapper\\\\AbstractResponseDataMapper\\:\\:\\$secureTypeMappings \\(array\\\\) does not accept non\\-empty\\-array\\<1\\|2\\|3\\|string, '3d'\\|'3d_host'\\|'3d_pay'\\|'3d_pay_hosting'\\|'regular'\\>\\.$#" - count: 1 - path: src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php - - message: "#^Method Mews\\\\Pos\\\\Factory\\\\PosFactory\\:\\:createPosGateway\\(\\) should return Mews\\\\Pos\\\\PosInterface but returns object\\.$#" count: 1 diff --git a/src/DataMapper/RequestValueFormatter/KuveytPosRequestValueFormatter.php b/src/DataMapper/RequestValueFormatter/KuveytPosRequestValueFormatter.php index a5416b58..d6839b0b 100644 --- a/src/DataMapper/RequestValueFormatter/KuveytPosRequestValueFormatter.php +++ b/src/DataMapper/RequestValueFormatter/KuveytPosRequestValueFormatter.php @@ -10,6 +10,7 @@ class KuveytPosRequestValueFormatter implements RequestValueFormatterInterface * 0 => '0' * 1 => '0' * 2 => '2' + * * @inheritDoc */ public function formatInstallment(int $installment): string @@ -19,12 +20,9 @@ public function formatInstallment(int $installment): string /** - * Amount Formatter - * converts 100 to 10000, or 10.01 to 1001 - * - * @param float $amount + * example: 100 to 10000, or 10.01 to 1001 * - * @return int + * @inheritDoc */ public function formatAmount(float $amount): int { @@ -36,14 +34,14 @@ public function formatAmount(float $amount): int */ public function formatCardExpDate(\DateTimeInterface $expDate, string $fieldName): string { - if ('CardExpireDateMonth' === $fieldName) { - return $expDate->format('m'); - } - if ('CardExpireDateYear' === $fieldName) { return $expDate->format('y'); } + if ('CardExpireDateMonth' === $fieldName) { + return $expDate->format('m'); + } + throw new \InvalidArgumentException('Unsupported field name'); } diff --git a/src/DataMapper/RequestValueMapper/KuveytPosRequestValueMapper.php b/src/DataMapper/RequestValueMapper/KuveytPosRequestValueMapper.php index bbadd866..b0891481 100644 --- a/src/DataMapper/RequestValueMapper/KuveytPosRequestValueMapper.php +++ b/src/DataMapper/RequestValueMapper/KuveytPosRequestValueMapper.php @@ -18,9 +18,6 @@ class KuveytPosRequestValueMapper extends AbstractRequestValueMapper PosInterface::CURRENCY_TRY => '0949', PosInterface::CURRENCY_USD => '0840', PosInterface::CURRENCY_EUR => '0978', - PosInterface::CURRENCY_GBP => '0826', - PosInterface::CURRENCY_JPY => '0392', - PosInterface::CURRENCY_RUB => '0810', ]; /** diff --git a/src/DataMapper/RequestValueMapper/VakifKatilimPosRequestValueMapper.php b/src/DataMapper/RequestValueMapper/VakifKatilimPosRequestValueMapper.php index b688c01a..14c9072b 100644 --- a/src/DataMapper/RequestValueMapper/VakifKatilimPosRequestValueMapper.php +++ b/src/DataMapper/RequestValueMapper/VakifKatilimPosRequestValueMapper.php @@ -29,14 +29,4 @@ class VakifKatilimPosRequestValueMapper extends AbstractRequestValueMapper 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 d951330c..8bb79a5e 100644 --- a/src/DataMapper/ResponseDataMapper/AbstractResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/AbstractResponseDataMapper.php @@ -5,6 +5,8 @@ namespace Mews\Pos\DataMapper\ResponseDataMapper; +use Mews\Pos\DataMapper\ResponseValueFormatter\ResponseValueFormatterInterface; +use Mews\Pos\DataMapper\ResponseValueMapper\ResponseValueMapperInterface; use Mews\Pos\PosInterface; use Psr\Log\LoggerInterface; @@ -13,70 +15,28 @@ abstract class AbstractResponseDataMapper implements ResponseDataMapperInterface /** @var string */ public const PROCEDURE_SUCCESS_CODE = '00'; - protected LoggerInterface $logger; - - /** @var array */ - protected array $currencyMappings; + protected ResponseValueFormatterInterface $valueFormatter; - /** @var array> */ - protected array $txTypeMappings; + protected ResponseValueMapperInterface $valueMapper; - /** @var array */ - protected array $secureTypeMappings; + protected LoggerInterface $logger; /** - * @param array $currencyMappings - * @param array> $txTypeMappings - * @param array $secureTypeMappings - * @param LoggerInterface $logger + * @param ResponseValueFormatterInterface $valueFormatter + * @param ResponseValueMapperInterface $valueMapper + * @param LoggerInterface $logger */ - public function __construct(array $currencyMappings, array $txTypeMappings, array $secureTypeMappings, LoggerInterface $logger) + public function __construct( + ResponseValueFormatterInterface $valueFormatter, + ResponseValueMapperInterface $valueMapper, + LoggerInterface $logger + ) { $this->logger = $logger; - $this->currencyMappings = \array_flip($currencyMappings); - $this->txTypeMappings = $txTypeMappings; - $this->secureTypeMappings = \array_flip($secureTypeMappings); - } - - /** - * @return array> - */ - public function getTxTypeMappings(): array - { - return $this->txTypeMappings; - } - - /** - * @param string|int $txType - * - * @return PosInterface::TX_*|null - */ - public function mapTxType($txType): ?string - { - foreach ($this->txTypeMappings as $mappedTxType => $mapping) { - if (\is_array($mapping) && \in_array($txType, $mapping, true)) { - return $mappedTxType; - } - - if ($mapping === $txType) { - return $mappedTxType; - } - } - - return null; - } - - /** - * @param string|int $securityType - * - * @return PosInterface::MODEL_*|null - */ - public function mapSecurityType($securityType): ?string - { - return $this->secureTypeMappings[$securityType] ?? null; + $this->valueFormatter = $valueFormatter; + $this->valueMapper = $valueMapper; } - /** * @param string $mdStatus * @@ -84,37 +44,6 @@ public function mapSecurityType($securityType): ?string */ abstract protected function mapResponseTransactionSecurity(string $mdStatus): string; - /** - * "1000.01" => 1000.01 - * @param string $amount - * - * @return float - */ - protected function formatAmount(string $amount): float - { - return (float) $amount; - } - - /** - * @param string $currency currency code that is accepted by bank - * - * @return PosInterface::CURRENCY_*|string - */ - protected function mapCurrency(string $currency): string - { - return $this->currencyMappings[$currency] ?? $currency; - } - - /** - * @param string|null $installment - * - * @return int - */ - protected function mapInstallment(?string $installment): int - { - return (int) $installment; - } - /** * if 2 arrays has common keys, then non-null value preferred, * if both arrays has the non-null values for the same key then value of $arr2 is preferred. diff --git a/src/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapper.php index da1f8633..631d4e65 100644 --- a/src/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapper.php @@ -5,6 +5,8 @@ namespace Mews\Pos\DataMapper\ResponseDataMapper; +use Mews\Pos\DataMapper\ResponseValueMapper\AkbankPosResponseValueMapper; +use Mews\Pos\DataMapper\ResponseValueMapper\ResponseValueMapperInterface; use Mews\Pos\Exceptions\NotImplementedException; use Mews\Pos\PosInterface; @@ -26,35 +28,9 @@ class AkbankPosResponseDataMapper extends AbstractResponseDataMapper ]; /** - * N: Normal - * S: Şüpheli - * V: İptal - * R: Reversal - * @var array + * @var AkbankPosResponseValueMapper */ - private array $orderStatusMappings = [ - 'N' => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, - 'S' => PosInterface::PAYMENT_STATUS_ERROR, - 'V' => PosInterface::PAYMENT_STATUS_CANCELED, - 'R' => PosInterface::PAYMENT_STATUS_FULLY_REFUNDED, - - // status that are return on history request - 'Başarılı' => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, - 'Başarısız' => PosInterface::PAYMENT_STATUS_ERROR, - 'İptal' => PosInterface::PAYMENT_STATUS_CANCELED, - ]; - - /** - * @var array - */ - private array $recurringOrderStatusMappings = [ - 'S' => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, - 'W' => PosInterface::PAYMENT_STATUS_PAYMENT_PENDING, - // when fulfilled payment is canceled - 'V' => PosInterface::PAYMENT_STATUS_CANCELED, - // when unfulfilled payment is canceled - 'C' => PosInterface::PAYMENT_STATUS_CANCELED, - ]; + protected ResponseValueMapperInterface $valueMapper; /** * {@inheritDoc} @@ -78,12 +54,12 @@ public function mapPaymentResponse(array $rawPaymentResponseData, string $txType $mappedResponse = [ 'recurring_id' => $rawPaymentResponseData['order']['orderTrackId'] ?? null, - 'transaction_type' => $this->mapTxType($rawPaymentResponseData['txnCode']), + 'transaction_type' => $this->valueMapper->mapTxType($rawPaymentResponseData['txnCode']), 'currency' => $order['currency'], 'amount' => $order['amount'], 'installment_count' => isset($rawPaymentResponseData['order']['orderTrackId']) ? null : $order['installment'] ?? null, 'transaction_id' => null, - 'transaction_time' => self::TX_APPROVED === $status ? new \DateTimeImmutable($rawPaymentResponseData['txnDateTime']) : null, + 'transaction_time' => self::TX_APPROVED === $status ? $this->valueFormatter->formatDateTime($rawPaymentResponseData['txnDateTime'], $txType) : null, 'proc_return_code' => $procReturnCode, 'status' => $status, 'status_detail' => $this->getStatusDetail($procReturnCode), @@ -164,7 +140,7 @@ public function map3DPayResponseData(array $raw3DAuthResponseData, string $txTyp $defaultResponse['installment_count'] = $order['installment']; if (self::TX_APPROVED === $status) { - $defaultResponse['transaction_time'] = new \DateTimeImmutable($raw3DAuthResponseData['txnDateTime']); + $defaultResponse['transaction_time'] = $this->valueFormatter->formatDateTime($raw3DAuthResponseData['txnDateTime'], $txType); $defaultResponse['auth_code'] = $raw3DAuthResponseData['authCode']; $defaultResponse['batch_num'] = (int) $raw3DAuthResponseData['batchNumber']; $defaultResponse['ref_ret_num'] = $raw3DAuthResponseData['rrn']; @@ -415,27 +391,6 @@ protected function getProcReturnCode(array $response): ?string return $response['responseCode'] ?? null; } - /** - * @param string $amount - * - * @return float - */ - protected function formatAmount(string $amount): float - { - return (float) $amount; - } - - /** - * @param string|null $installment - * - * @return int - */ - protected function mapInstallment(?string $installment): int - { - return $installment > 1 ? (int) $installment : 0; - } - - /** * @param array $rawTx * @@ -443,6 +398,7 @@ protected function mapInstallment(?string $installment): int */ private function mapSingleOrderHistoryTransaction(array $rawTx): array { + $txType = PosInterface::TX_TYPE_ORDER_HISTORY; $rawTx = $this->emptyStringsToNull($rawTx); $transaction = $this->getDefaultOrderHistoryTxResponse(); $transaction['proc_return_code'] = $this->getProcReturnCode($rawTx); @@ -451,39 +407,39 @@ private function mapSingleOrderHistoryTransaction(array $rawTx): array } $transaction['status_detail'] = $this->getStatusDetail($transaction['proc_return_code']); - $transaction['currency'] = $this->mapCurrency($rawTx['currencyCode']); - $transaction['installment_count'] = $this->mapInstallment($rawTx['installCount']); - $transaction['transaction_type'] = $this->mapTxType($rawTx['txnCode']); - $transaction['first_amount'] = null === $rawTx['amount'] ? null : $this->formatAmount($rawTx['amount']); - $transaction['transaction_time'] = new \DateTimeImmutable($rawTx['txnDateTime']); + $transaction['currency'] = $this->valueMapper->mapCurrency($rawTx['currencyCode'], $txType); + $transaction['installment_count'] = $this->valueFormatter->formatInstallment($rawTx['installCount'], $txType); + $transaction['transaction_type'] = $this->valueMapper->mapTxType($rawTx['txnCode']); + $transaction['first_amount'] = null === $rawTx['amount'] ? null : $this->valueFormatter->formatAmount($rawTx['amount'], $txType); + $transaction['transaction_time'] = $this->valueFormatter->formatDateTime($rawTx['txnDateTime'], $txType); if (self::TX_APPROVED === $transaction['status']) { $transaction['masked_number'] = $rawTx['maskedCardNumber']; $transaction['ref_ret_num'] = $rawTx['rrn']; // batchNumber is not provided when payment is canceled $transaction['batch_num'] = $rawTx['batchNumber'] ?? null; - $transaction['order_status'] = $this->mapOrderStatus($rawTx['txnStatus'], $rawTx['preAuthStatus'] ?? null); + $transaction['order_status'] = $this->valueMapper->mapOrderStatus($rawTx['txnStatus'], $rawTx['preAuthStatus'] ?? null); $transaction['auth_code'] = $rawTx['authCode']; if (PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED === $transaction['order_status']) { if (\in_array( - $transaction['transaction_type'], - [ - PosInterface::TX_TYPE_PAY_AUTH, - PosInterface::TX_TYPE_PAY_POST_AUTH, - ], - true, - ) + $transaction['transaction_type'], + [ + PosInterface::TX_TYPE_PAY_AUTH, + PosInterface::TX_TYPE_PAY_POST_AUTH, + ], + true, + ) ) { - $transaction['capture_amount'] = null === $rawTx['amount'] ? null : $this->formatAmount($rawTx['amount']); + $transaction['capture_amount'] = null === $rawTx['amount'] ? null : $this->valueFormatter->formatAmount($rawTx['amount'], $txType); $transaction['capture'] = $transaction['first_amount'] === $transaction['capture_amount']; if ($transaction['capture']) { - $transaction['capture_time'] = new \DateTimeImmutable($rawTx['txnDateTime']); + $transaction['capture_time'] = $this->valueFormatter->formatDateTime($rawTx['txnDateTime'], $txType); } } elseif (PosInterface::TX_TYPE_PAY_PRE_AUTH === $transaction['transaction_type']) { - $transaction['capture_amount'] = null === $rawTx['preAuthCloseAmount'] ? null : $this->formatAmount($rawTx['preAuthCloseAmount']); + $transaction['capture_amount'] = null === $rawTx['preAuthCloseAmount'] ? null : $this->valueFormatter->formatAmount($rawTx['preAuthCloseAmount'], $txType); $transaction['capture'] = $transaction['first_amount'] === $transaction['capture_amount']; if ($transaction['capture']) { - $transaction['capture_time'] = new \DateTimeImmutable($rawTx['preAuthCloseDate']); + $transaction['capture_time'] = $this->valueFormatter->formatDateTime($rawTx['preAuthCloseDate'], $txType); } } } @@ -501,10 +457,11 @@ private function mapSingleOrderHistoryTransaction(array $rawTx): array */ private function mapSingleRecurringOrderHistoryTransaction(array $rawTx): array { + $txType = PosInterface::TX_TYPE_ORDER_HISTORY; $rawTx = $this->emptyStringsToNull($rawTx); $transaction = $this->getDefaultOrderHistoryTxResponse(); $transaction['proc_return_code'] = $this->getProcReturnCode($rawTx); - $transaction['order_status'] = $this->mapRecurringOrderStatus($rawTx['requestStatus']); + $transaction['order_status'] = $this->valueMapper->mapOrderStatus($rawTx['requestStatus'], null, true); if (null === $transaction['proc_return_code']) { // no proc return code since this is the pending payment $transaction['status'] = null; @@ -515,23 +472,23 @@ private function mapSingleRecurringOrderHistoryTransaction(array $rawTx): array $transaction['status_detail'] = $this->getStatusDetail($transaction['proc_return_code']); $transaction['recurring_order'] = $rawTx['recurringOrder']; $transaction['masked_number'] = $rawTx['maskedCardNumber']; - $transaction['currency'] = $this->mapCurrency($rawTx['currencyCode']); - $transaction['installment_count'] = $this->mapInstallment($rawTx['installCount']); - $transaction['transaction_type'] = $this->mapTxType($rawTx['txnCode']); - $transaction['first_amount'] = null === $rawTx['amount'] ? null : $this->formatAmount($rawTx['amount']); + $transaction['currency'] = $this->valueMapper->mapCurrency($rawTx['currencyCode'], $txType); + $transaction['installment_count'] = $this->valueFormatter->formatInstallment($rawTx['installCount'], $txType); + $transaction['transaction_type'] = $this->valueMapper->mapTxType($rawTx['txnCode']); + $transaction['first_amount'] = null === $rawTx['amount'] ? null : $this->valueFormatter->formatAmount($rawTx['amount'], $txType); if (self::TX_APPROVED === $transaction['status']) { $transaction['auth_code'] = $rawTx['authCode']; if (PosInterface::PAYMENT_STATUS_PAYMENT_PENDING !== $transaction['order_status']) { - $transaction['transaction_time'] = new \DateTimeImmutable($rawTx['txnDateTime']); + $transaction['transaction_time'] = $this->valueFormatter->formatDateTime($rawTx['txnDateTime'], $txType); } if (PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED === $transaction['order_status']) { $transaction['batch_num'] = $rawTx['batchNumber']; $transaction['ref_ret_num'] = $rawTx['rrn']; - $transaction['capture_amount'] = null === $rawTx['amount'] ? null : $this->formatAmount($rawTx['amount']); + $transaction['capture_amount'] = null === $rawTx['amount'] ? null : $this->valueFormatter->formatAmount($rawTx['amount'], $txType); $transaction['capture'] = $transaction['first_amount'] === $transaction['capture_amount']; - $transaction['capture_time'] = new \DateTimeImmutable($rawTx['txnDateTime']); + $transaction['capture_time'] = $this->valueFormatter->formatDateTime($rawTx['txnDateTime'], $txType); } } else { $transaction['error_code'] = $transaction['proc_return_code']; @@ -547,6 +504,7 @@ private function mapSingleRecurringOrderHistoryTransaction(array $rawTx): array */ private function mapSingleHistoryTransaction(array $rawTx): array { + $txType = PosInterface::TX_TYPE_HISTORY; $rawTx = $this->emptyStringsToNull($rawTx); $transaction = $this->getDefaultOrderHistoryTxResponse(); $transaction['proc_return_code'] = $this->getProcReturnCode($rawTx); @@ -557,11 +515,11 @@ private function mapSingleHistoryTransaction(array $rawTx): array $transaction['order_id'] = null; $transaction['status_detail'] = $this->getStatusDetail($transaction['proc_return_code']); - $transaction['currency'] = $this->mapCurrency($rawTx['currencyCode']); - $transaction['installment_count'] = $this->mapInstallment($rawTx['installmentCount']); - $transaction['transaction_type'] = $this->mapTxType($rawTx['txnCode']); - $transaction['first_amount'] = null === $rawTx['amount'] ? null : $this->formatAmount($rawTx['amount']); - $transaction['transaction_time'] = new \DateTimeImmutable($rawTx['txnDateTime']); + $transaction['currency'] = $this->valueMapper->mapCurrency($rawTx['currencyCode'], $txType); + $transaction['installment_count'] = $this->valueFormatter->formatInstallment($rawTx['installmentCount'], $txType); + $transaction['transaction_type'] = $this->valueMapper->mapTxType($rawTx['txnCode']); + $transaction['first_amount'] = null === $rawTx['amount'] ? null : $this->valueFormatter->formatAmount($rawTx['amount'], $txType); + $transaction['transaction_time'] = $this->valueFormatter->formatDateTime($rawTx['txnDateTime'], $txType); if (self::TX_APPROVED === $transaction['status']) { $transaction['order_id'] = $rawTx['orderId']; @@ -569,7 +527,7 @@ private function mapSingleHistoryTransaction(array $rawTx): array $transaction['ref_ret_num'] = $rawTx['rrn']; // batchNumber is not provided when payment is canceled $transaction['batch_num'] = $rawTx['batchNumber'] ?? null; - $transaction['order_status'] = $this->mapOrderStatus($rawTx['txnStatus'], $rawTx['preAuthStatus'] ?? null); + $transaction['order_status'] = $this->valueMapper->mapOrderStatus($rawTx['txnStatus'], $rawTx['preAuthStatus'] ?? null); $transaction['auth_code'] = $rawTx['authCode']; if (PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED === $transaction['order_status']) { if (\in_array( @@ -580,16 +538,16 @@ private function mapSingleHistoryTransaction(array $rawTx): array ], true, )) { - $transaction['capture_amount'] = null === $rawTx['amount'] ? null : $this->formatAmount($rawTx['amount']); + $transaction['capture_amount'] = null === $rawTx['amount'] ? null : $this->valueFormatter->formatAmount($rawTx['amount'], PosInterface::TX_TYPE_HISTORY); $transaction['capture'] = $transaction['first_amount'] === $transaction['capture_amount']; if ($transaction['capture']) { - $transaction['capture_time'] = new \DateTimeImmutable($rawTx['txnDateTime']); + $transaction['capture_time'] = $this->valueFormatter->formatDateTime($rawTx['txnDateTime'], $txType); } } elseif (PosInterface::TX_TYPE_PAY_PRE_AUTH === $transaction['transaction_type']) { - $transaction['capture_amount'] = null === $rawTx['preAuthCloseAmount'] ? null : $this->formatAmount($rawTx['preAuthCloseAmount']); + $transaction['capture_amount'] = null === $rawTx['preAuthCloseAmount'] ? null : $this->valueFormatter->formatAmount($rawTx['preAuthCloseAmount'], PosInterface::TX_TYPE_HISTORY); $transaction['capture'] = $transaction['first_amount'] === $transaction['capture_amount']; if ($transaction['capture']) { - $transaction['capture_time'] = new \DateTimeImmutable($rawTx['preAuthCloseDate']); + $transaction['capture_time'] = $this->valueFormatter->formatDateTime($rawTx['preAuthCloseDate'], $txType); } } } @@ -631,35 +589,4 @@ private function map3DResponseData(array $raw3DAuthResponseData, string $payment return $threeDResponse; } - - /** - * @param string $txStatus - * @param string|null $preAuthStatus - * - * @return string - */ - private function mapOrderStatus(string $txStatus, ?string $preAuthStatus): string - { - $orderStatus = $this->orderStatusMappings[$txStatus]; - /** - * preAuthStatus - * "O": Açık - * "C": Kapalı - */ - if (PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED === $orderStatus && 'O' === $preAuthStatus) { - return PosInterface::PAYMENT_STATUS_PRE_AUTH_COMPLETED; - } - - return $orderStatus; - } - - /** - * @param string $requestStatus - * - * @return string - */ - private function mapRecurringOrderStatus(string $requestStatus): string - { - return $this->recurringOrderStatusMappings[$requestStatus] ?? $requestStatus; - } } diff --git a/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php index abe05bee..13fd5e81 100644 --- a/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/EstPosResponseDataMapper.php @@ -35,29 +35,6 @@ class EstPosResponseDataMapper extends AbstractResponseDataMapper '99' => 'general_error', ]; - /** - * D : Başarısız işlem - * A : Otorizasyon, gün sonu kapanmadan - * C : Ön otorizasyon kapama, gün sonu kapanmadan - * PN : Bekleyen İşlem - * CNCL : İptal Edilmiş İşlem - * ERR : Hata Almış İşlem - * S : Satış - * R : Teknik İptal gerekiyor - * V : İptal - * @var array - */ - protected array $orderStatusMappings = [ - 'D' => PosInterface::PAYMENT_STATUS_ERROR, - 'ERR' => PosInterface::PAYMENT_STATUS_ERROR, - 'A' => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, - 'C' => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, - 'S' => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, - 'PN' => PosInterface::PAYMENT_STATUS_PAYMENT_PENDING, - 'CNCL' => PosInterface::PAYMENT_STATUS_CANCELED, - 'V' => PosInterface::PAYMENT_STATUS_CANCELED, - ]; - /** * @param PaymentStatusModel $rawPaymentResponseData * {@inheritDoc} @@ -87,7 +64,7 @@ public function mapPaymentResponse(array $rawPaymentResponseData, string $txType 'amount' => $order['amount'], 'group_id' => $rawPaymentResponseData['GroupId'], 'transaction_id' => $rawPaymentResponseData['TransId'], - 'transaction_time' => self::TX_APPROVED === $status ? new \DateTimeImmutable($extra['TRXDATE']) : null, + 'transaction_time' => self::TX_APPROVED === $status ? $this->valueFormatter->formatDateTime($extra['TRXDATE'], $txType) : null, 'auth_code' => $rawPaymentResponseData['AuthCode'] ?? null, 'ref_ret_num' => $rawPaymentResponseData['HostRefNum'], 'proc_return_code' => $procReturnCode, @@ -115,7 +92,7 @@ public function map3DPaymentData(array $raw3DAuthResponseData, ?array $rawPaymen 'provision_response' => $rawPaymentResponseData, ]); $raw3DAuthResponseData = $this->emptyStringsToNull($raw3DAuthResponseData); - $paymentModel = $this->mapSecurityType($raw3DAuthResponseData['storetype']); + $paymentModel = $this->valueMapper->mapSecureType($raw3DAuthResponseData['storetype'], $txType); $paymentResponseData = $this->getDefaultPaymentResponse($txType, $paymentModel); $mdStatus = $this->extractMdStatus($raw3DAuthResponseData); if (null !== $rawPaymentResponseData) { @@ -129,9 +106,9 @@ public function map3DPaymentData(array $raw3DAuthResponseData, ?array $rawPaymen 'masked_number' => $raw3DAuthResponseData['maskedCreditCard'], 'month' => $raw3DAuthResponseData['Ecom_Payment_Card_ExpDate_Month'], 'year' => $raw3DAuthResponseData['Ecom_Payment_Card_ExpDate_Year'], - 'amount' => null !== $raw3DAuthResponseData['amount'] ? $this->formatAmount($raw3DAuthResponseData['amount']) : null, - 'currency' => '*' === $raw3DAuthResponseData['currency'] ? null : $this->mapCurrency($raw3DAuthResponseData['currency']), - 'installment_count' => $this->mapInstallment($raw3DAuthResponseData['taksit']), + 'amount' => null !== $raw3DAuthResponseData['amount'] ? $this->valueFormatter->formatAmount($raw3DAuthResponseData['amount'], $txType) : null, + 'currency' => $this->valueMapper->mapCurrency($raw3DAuthResponseData['currency'], $txType), + 'installment_count' => $this->valueFormatter->formatInstallment($raw3DAuthResponseData['taksit'], $txType), 'eci' => null, 'tx_status' => null, 'cavv' => null, @@ -173,7 +150,7 @@ public function map3DPayResponseData(array $raw3DAuthResponseData, string $txTyp $status = self::TX_APPROVED; } - $paymentModel = $this->mapSecurityType($raw3DAuthResponseData['storetype']); + $paymentModel = $this->valueMapper->mapSecureType($raw3DAuthResponseData['storetype'], $txType); $defaultResponse = $this->getDefaultPaymentResponse($txType, $paymentModel); $response = [ @@ -185,9 +162,9 @@ public function map3DPayResponseData(array $raw3DAuthResponseData, string $txTyp 'masked_number' => $raw3DAuthResponseData['maskedCreditCard'], 'month' => $raw3DAuthResponseData['Ecom_Payment_Card_ExpDate_Month'], 'year' => $raw3DAuthResponseData['Ecom_Payment_Card_ExpDate_Year'], - 'amount' => $this->formatAmount($raw3DAuthResponseData['amount']), - 'currency' => $this->mapCurrency($raw3DAuthResponseData['currency']), - 'installment_count' => $this->mapInstallment($raw3DAuthResponseData['taksit']), + 'amount' => $this->valueFormatter->formatAmount($raw3DAuthResponseData['amount'], $txType), + 'currency' => $this->valueMapper->mapCurrency($raw3DAuthResponseData['currency'], $txType), + 'installment_count' => $this->valueFormatter->formatInstallment($raw3DAuthResponseData['taksit'], $txType), 'tx_status' => null, 'eci' => null, 'cavv' => null, @@ -200,7 +177,7 @@ public function map3DPayResponseData(array $raw3DAuthResponseData, string $txTyp $response['eci'] = $raw3DAuthResponseData['eci']; $response['cavv'] = $raw3DAuthResponseData['cavv']; $response['transaction_id'] = $raw3DAuthResponseData['TransId']; - $response['transaction_time'] = new \DateTimeImmutable($raw3DAuthResponseData['EXTRA_TRXDATE']); + $response['transaction_time'] = $this->valueFormatter->formatDateTime($raw3DAuthResponseData['EXTRA_TRXDATE'], $txType); $response['ref_ret_num'] = $raw3DAuthResponseData['HostRefNum']; $response['status_detail'] = $this->getStatusDetail($procReturnCode); $response['error_message'] = $raw3DAuthResponseData['ErrMsg']; @@ -222,7 +199,7 @@ public function map3DHostResponseData(array $raw3DAuthResponseData, string $txTy $status = self::TX_APPROVED; } - $paymentModel = $this->mapSecurityType($raw3DAuthResponseData['storetype']); + $paymentModel = $this->valueMapper->mapSecureType($raw3DAuthResponseData['storetype'], $txType); $defaultResponse = $this->getDefaultPaymentResponse($txType, $paymentModel); $response = [ @@ -230,9 +207,9 @@ public function map3DHostResponseData(array $raw3DAuthResponseData, string $txTy 'transaction_security' => null === $mdStatus ? null : $this->mapResponseTransactionSecurity($mdStatus), 'md_status' => $mdStatus, 'status' => $status, - 'amount' => $this->formatAmount($raw3DAuthResponseData['amount']), - 'currency' => $this->mapCurrency($raw3DAuthResponseData['currency']), - 'installment_count' => $this->mapInstallment($raw3DAuthResponseData['taksit']), + 'amount' => $this->valueFormatter->formatAmount($raw3DAuthResponseData['amount'], $txType), + 'currency' => $this->valueMapper->mapCurrency($raw3DAuthResponseData['currency'], $txType), + 'installment_count' => $this->valueFormatter->formatInstallment($raw3DAuthResponseData['taksit'], $txType), 'tx_status' => null, 'masked_number' => null, 'month' => null, @@ -356,6 +333,7 @@ public function mapCancelResponse(array $rawResponseData): array */ public function mapStatusResponse(array $rawResponseData): array { + $txType = PosInterface::TX_TYPE_STATUS; $rawResponseData = $this->emptyStringsToNull($rawResponseData); $procReturnCode = $this->getProcReturnCode($rawResponseData); $status = self::TX_DECLINED; @@ -382,17 +360,16 @@ public function mapStatusResponse(array $rawResponseData): array if (self::TX_APPROVED === $status) { $result['auth_code'] = $extra['AUTH_CODE']; $result['ref_ret_num'] = $extra['HOST_REF_NUM']; - $result['first_amount'] = $this->formatAmount($extra['ORIG_TRANS_AMT']); - $result['capture_amount'] = null !== $extra['CAPTURE_AMT'] ? $this->formatAmount($extra['CAPTURE_AMT']) : null; + $result['first_amount'] = $this->valueFormatter->formatAmount($extra['ORIG_TRANS_AMT'], $txType); + $result['capture_amount'] = null !== $extra['CAPTURE_AMT'] ? $this->valueFormatter->formatAmount($extra['CAPTURE_AMT'], $txType) : null; $result['masked_number'] = $extra['PAN']; $result['num_code'] = $extra['NUMCODE']; $result['capture'] = $result['first_amount'] === $result['capture_amount']; - $txType = 'S' === $extra['CHARGE_TYPE_CD'] ? PosInterface::TX_TYPE_PAY_AUTH : PosInterface::TX_TYPE_REFUND; - $result['transaction_type'] = $txType; - $result['order_status'] = $this->orderStatusMappings[$extra['TRANS_STAT']] ?? null; - $result['transaction_time'] = isset($extra['AUTH_DTTM']) ? new \DateTimeImmutable($extra['AUTH_DTTM']) : null; - $result['capture_time'] = isset($extra['CAPTURE_DTTM']) ? new \DateTimeImmutable($extra['CAPTURE_DTTM']) : null; - $result['cancel_time'] = isset($extra['VOID_DTTM']) ? new \DateTimeImmutable($extra['VOID_DTTM']) : null; + $result['transaction_type'] = $this->valueMapper->mapTxType($extra['CHARGE_TYPE_CD']); + $result['order_status'] = $this->valueMapper->mapOrderStatus($extra['TRANS_STAT']); + $result['transaction_time'] = isset($extra['AUTH_DTTM']) ? $this->valueFormatter->formatDateTime($extra['AUTH_DTTM'], $txType) : null; + $result['capture_time'] = isset($extra['CAPTURE_DTTM']) ? $this->valueFormatter->formatDateTime($extra['CAPTURE_DTTM'], $txType) : null; + $result['cancel_time'] = isset($extra['VOID_DTTM']) ? $this->valueFormatter->formatDateTime($extra['VOID_DTTM'], $txType) : null; } return $result; @@ -531,19 +508,6 @@ protected function getProcReturnCode(array $response): ?string return $response['ProcReturnCode'] ?? null; } - /** - * "100001" => 1000.01 odeme durum sorgulandiginda gelen amount format - * "1000.01" => 1000.01 odeme yapildiginda gelen amount format - * - * @param string $amount - * - * @return float - */ - protected function formatAmount(string $amount): float - { - return ((float) \str_replace('.', '', $amount)) / 100; - } - /** * @param array $rawTx * @@ -551,6 +515,7 @@ protected function formatAmount(string $amount): float */ private function mapSingleOrderHistoryTransaction(array $rawTx): array { + $txType = PosInterface::TX_TYPE_ORDER_HISTORY; $rawTx = $this->emptyStringsToNull($rawTx); $transaction = $this->getDefaultOrderHistoryTxResponse(); $transaction['auth_code'] = $rawTx[8]; @@ -561,15 +526,12 @@ private function mapSingleOrderHistoryTransaction(array $rawTx): array $transaction['status_detail'] = $this->getStatusDetail($transaction['proc_return_code']); $transaction['transaction_id'] = $rawTx[10]; - /** - * S: Auth/PreAuth/PostAuth - * C: Refund - */ - $transaction['transaction_type'] = 'S' === $rawTx[0] ? PosInterface::TX_TYPE_PAY_AUTH : PosInterface::TX_TYPE_REFUND; - $transaction['order_status'] = $this->orderStatusMappings[$rawTx[1]] ?? null; - $transaction['transaction_time'] = new \DateTimeImmutable($rawTx[4]); - $transaction['first_amount'] = null === $rawTx[2] ? null : $this->formatAmount($rawTx[2]); - $transaction['capture_amount'] = null === $rawTx[3] ? null : $this->formatAmount($rawTx[3]); + + $transaction['transaction_type'] = $this->valueMapper->mapTxType($rawTx[0]); + $transaction['order_status'] = $this->valueMapper->mapOrderStatus($rawTx[1]); + $transaction['transaction_time'] = $this->valueFormatter->formatDateTime($rawTx[4], $txType); + $transaction['first_amount'] = null === $rawTx[2] ? null : $this->valueFormatter->formatAmount($rawTx[2], PosInterface::TX_TYPE_ORDER_HISTORY); + $transaction['capture_amount'] = null === $rawTx[3] ? null : $this->valueFormatter->formatAmount($rawTx[3], PosInterface::TX_TYPE_ORDER_HISTORY); $transaction['capture'] = self::TX_APPROVED === $transaction['status'] && $transaction['first_amount'] === $transaction['capture_amount']; $transaction['ref_ret_num'] = $rawTx[7]; @@ -584,6 +546,7 @@ private function mapSingleOrderHistoryTransaction(array $rawTx): array */ private function mapSingleRecurringOrderStatus(array $extra, int $i): array { + $txType = PosInterface::TX_TYPE_STATUS; $procReturnCode = $extra[\sprintf('PROC_RET_CD_%d', $i)] ?? null; $status = self::TX_DECLINED; if (self::PROCEDURE_SUCCESS_CODE === $procReturnCode) { @@ -592,23 +555,32 @@ private function mapSingleRecurringOrderStatus(array $extra, int $i): array $status = null; } + $transStat = $extra[\sprintf('TRANS_STAT_%d', $i)]; + $chargeType = $extra[\sprintf('CHARGE_TYPE_CD_%d', $i)]; + $recurringOrder = [ 'order_id' => $extra[\sprintf('ORD_ID_%d', $i)], 'masked_number' => $extra[\sprintf('PAN_%d', $i)], - 'order_status' => $this->orderStatusMappings[$extra[\sprintf('TRANS_STAT_%d', $i)]] ?? null, + 'order_status' => null === $transStat ? null : $this->valueMapper->mapOrderStatus($transStat), // following fields are null until transaction is done for respective installment: 'auth_code' => $extra[\sprintf('AUTH_CODE_%d', $i)] ?? null, 'proc_return_code' => $procReturnCode, - 'transaction_type' => 'S' === $extra[\sprintf('CHARGE_TYPE_CD_%d', $i)] ? PosInterface::TX_TYPE_PAY_AUTH : PosInterface::TX_TYPE_REFUND, + 'transaction_type' => null === $chargeType ? null : $this->valueMapper->mapTxType($chargeType), 'status' => $status, 'status_detail' => $this->getStatusDetail($procReturnCode), - 'transaction_time' => isset($extra[\sprintf('AUTH_DTTM_%d', $i)]) ? new \DateTimeImmutable($extra[\sprintf('AUTH_DTTM_%d', $i)]) : null, - 'capture_time' => isset($extra[\sprintf('CAPTURE_DTTM_%d', $i)]) ? new \DateTimeImmutable($extra[\sprintf('CAPTURE_DTTM_%d', $i)]) : null, + 'transaction_time' => isset($extra[\sprintf('AUTH_DTTM_%d', $i)]) ? $this->valueFormatter->formatDateTime($extra[\sprintf('AUTH_DTTM_%d', $i)], $txType) : null, + 'capture_time' => isset($extra[\sprintf('CAPTURE_DTTM_%d', $i)]) ? $this->valueFormatter->formatDateTime($extra[\sprintf('CAPTURE_DTTM_%d', $i)], $txType) : null, 'transaction_id' => $extra[\sprintf('TRANS_ID_%d', $i)] ?? null, 'ref_ret_num' => $extra[\sprintf('HOST_REF_NUM_%d', $i)] ?? null, - 'first_amount' => isset($extra[\sprintf('ORIG_TRANS_AMT_%d', $i)]) ? $this->formatAmount($extra[\sprintf('ORIG_TRANS_AMT_%d', $i)]) : null, - 'capture_amount' => isset($extra[\sprintf('CAPTURE_AMT_%d', $i)]) ? $this->formatAmount($extra[\sprintf('CAPTURE_AMT_%d', $i)]) : null, + 'first_amount' => isset($extra[\sprintf('ORIG_TRANS_AMT_%d', $i)]) ? $this->valueFormatter->formatAmount( + $extra[\sprintf('ORIG_TRANS_AMT_%d', $i)], + $txType + ) : null, + 'capture_amount' => isset($extra[\sprintf('CAPTURE_AMT_%d', $i)]) ? $this->valueFormatter->formatAmount( + $extra[\sprintf('CAPTURE_AMT_%d', $i)], + $txType + ) : null, ]; diff --git a/src/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapper.php index c0b5491e..2117bca4 100644 --- a/src/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapper.php @@ -5,6 +5,8 @@ namespace Mews\Pos\DataMapper\ResponseDataMapper; +use Mews\Pos\DataMapper\ResponseValueMapper\GarantiPosResponseValueMapper; +use Mews\Pos\DataMapper\ResponseValueMapper\ResponseValueMapperInterface; use Mews\Pos\Exceptions\NotImplementedException; use Mews\Pos\PosInterface; @@ -13,6 +15,11 @@ */ class GarantiPosResponseDataMapper extends AbstractResponseDataMapper { + /** + * @var GarantiPosResponseValueMapper + */ + protected ResponseValueMapperInterface $valueMapper; + /** * Response Codes * @@ -64,7 +71,7 @@ public function mapPaymentResponse(array $rawPaymentResponseData, string $txType 'auth_code' => self::TX_APPROVED === $status ? $transaction['AuthCode'] : null, 'ref_ret_num' => self::TX_APPROVED === $status ? $transaction['RetrefNum'] : null, 'batch_num' => self::TX_APPROVED === $status ? $transaction['BatchNum'] : null, - 'transaction_time' => self::TX_APPROVED === $status ? new \DateTimeImmutable($provDate) : null, + 'transaction_time' => self::TX_APPROVED === $status ? $this->valueFormatter->formatDateTime($provDate, $txType) : null, 'proc_return_code' => $procReturnCode, 'status' => $status, 'currency' => $order['currency'], @@ -94,7 +101,11 @@ public function map3DPaymentData(array $raw3DAuthResponseData, ?array $rawPaymen 'provision_response' => $rawPaymentResponseData, ]); - $commonResult = $this->map3DCommonResponseData($raw3DAuthResponseData, PosInterface::MODEL_3D_SECURE); + $commonResult = $this->map3DCommonResponseData( + $raw3DAuthResponseData, + PosInterface::MODEL_3D_SECURE, + $txType + ); $mdStatus = $this->extractMdStatus($raw3DAuthResponseData); // todo refactor if ($this->is3dAuthSuccess($mdStatus)) { @@ -109,7 +120,7 @@ public function map3DPaymentData(array $raw3DAuthResponseData, ?array $rawPaymen } $paymentStatus = self::TX_DECLINED; - $paymentModel = $this->mapSecurityType($raw3DAuthResponseData['secure3dsecuritylevel']); + $paymentModel = $this->valueMapper->mapSecureType($raw3DAuthResponseData['secure3dsecuritylevel'], $txType); $defaultPaymentResponse = $this->getDefaultPaymentResponse($txType, $paymentModel); $mappedPaymentResponse = []; if (self::TX_APPROVED === $commonResult['status'] && null !== $rawPaymentResponseData) { @@ -127,7 +138,7 @@ public function map3DPaymentData(array $raw3DAuthResponseData, ?array $rawPaymen 'auth_code' => $transaction['AuthCode'] ?? null, 'ref_ret_num' => $transaction['RetrefNum'] ?? null, 'batch_num' => $transaction['BatchNum'] ?? null, - 'transaction_time' => self::TX_APPROVED === $paymentStatus ? new \DateTimeImmutable($provDate) : null, + 'transaction_time' => self::TX_APPROVED === $paymentStatus ? $this->valueFormatter->formatDateTime($provDate, $txType) : null, 'error_code' => self::TX_APPROVED === $paymentStatus ? null : $transaction['Response']['ReasonCode'], 'error_message' => self::TX_APPROVED === $paymentStatus ? null : $transaction['Response']['ErrorMsg'], 'all' => $rawPaymentResponseData, @@ -153,7 +164,11 @@ public function map3DPayResponseData(array $raw3DAuthResponseData, string $txTyp { $raw3DAuthResponseData = $this->emptyStringsToNull($raw3DAuthResponseData); - $threeDAuthResult = $this->map3DCommonResponseData($raw3DAuthResponseData, PosInterface::MODEL_3D_PAY); + $threeDAuthResult = $this->map3DCommonResponseData( + $raw3DAuthResponseData, + PosInterface::MODEL_3D_PAY, + $txType + ); $threeDAuthStatus = $threeDAuthResult['status']; $paymentStatus = self::TX_DECLINED; $procReturnCode = $raw3DAuthResponseData['procreturncode']; @@ -161,9 +176,9 @@ public function map3DPayResponseData(array $raw3DAuthResponseData, string $txTyp $paymentStatus = self::TX_APPROVED; } - $paymentModel = $this->mapSecurityType($raw3DAuthResponseData['secure3dsecuritylevel']); + $paymentModel = $this->valueMapper->mapSecureType($raw3DAuthResponseData['secure3dsecuritylevel'], $txType); /** @var PosInterface::TX_TYPE_PAY_AUTH|PosInterface::TX_TYPE_PAY_PRE_AUTH $txType */ - $txType = $this->mapTxType($raw3DAuthResponseData['txntype']) ?? $txType; + $txType = $this->valueMapper->mapTxType($raw3DAuthResponseData['txntype']) ?? $txType; $defaultPaymentResponse = $this->getDefaultPaymentResponse( $txType, $paymentModel @@ -249,6 +264,7 @@ public function mapStatusResponse(array $rawResponseData): array $rawResponseData = $this->emptyStringsToNull($rawResponseData); $procReturnCode = $this->getProcReturnCode($rawResponseData); $status = self::TX_DECLINED; + $txType = PosInterface::TX_TYPE_STATUS; if (self::PROCEDURE_SUCCESS_CODE === $procReturnCode) { $status = self::TX_APPROVED; } @@ -259,18 +275,13 @@ public function mapStatusResponse(array $rawResponseData): array $orderInqResult = $rawResponseData['Order']['OrderInqResult']; $defaultResponse = $this->getDefaultStatusResponse($rawResponseData); - $orderStatus = $orderInqResult['Status']; - if ('WAITINGPOSTAUTH' === $orderInqResult['Status']) { - $orderStatus = PosInterface::PAYMENT_STATUS_PRE_AUTH_COMPLETED; - } - $result = [ 'order_id' => $rawResponseData['Order']['OrderID'] ?? null, 'auth_code' => $orderInqResult['AuthCode'] ?? null, 'ref_ret_num' => $orderInqResult['RetrefNum'] ?? null, - 'installment_count' => $this->mapInstallment($orderInqResult['InstallmentCnt']), + 'installment_count' => $this->valueFormatter->formatInstallment($orderInqResult['InstallmentCnt'], $txType), 'proc_return_code' => $procReturnCode, - 'order_status' => $orderStatus, + 'order_status' => null !== $orderInqResult['Status'] ? $this->valueMapper->mapOrderStatus($orderInqResult['Status'], $txType) : null, 'status' => $status, 'status_detail' => $this->getStatusDetail($procReturnCode), 'error_code' => self::TX_APPROVED === $status ? null : $transaction['Response']['Code'], @@ -278,13 +289,13 @@ public function mapStatusResponse(array $rawResponseData): array ]; if (self::TX_APPROVED === $status) { $transTime = $orderInqResult['ProvDate'] ?? $orderInqResult['PreAuthDate']; - $result['transaction_time'] = $transTime === null ? null : new \DateTimeImmutable($transTime); - $result['capture_time'] = null !== $orderInqResult['AuthDate'] ? new \DateTimeImmutable($orderInqResult['AuthDate']) : null; + $result['transaction_time'] = $transTime === null ? null : $this->valueFormatter->formatDateTime($transTime, $txType); + $result['capture_time'] = null !== $orderInqResult['AuthDate'] ? $this->valueFormatter->formatDateTime($orderInqResult['AuthDate'], $txType) : null; $result['masked_number'] = $orderInqResult['CardNumberMasked']; $amount = $orderInqResult['AuthAmount']; - $result['capture_amount'] = null !== $amount ? $this->formatAmount($amount) : null; + $result['capture_amount'] = null !== $amount ? $this->valueFormatter->formatAmount($amount, $txType) : null; $firstAmount = $amount > 0 ? $amount : $orderInqResult['PreAuthAmount']; - $result['first_amount'] = null !== $firstAmount ? $this->formatAmount($firstAmount) : null; + $result['first_amount'] = null !== $firstAmount ? $this->valueFormatter->formatAmount($firstAmount, $txType) : null; $result['capture'] = $result['first_amount'] > 0 ? $result['capture_amount'] === $result['first_amount'] : null; } @@ -382,44 +393,16 @@ public function extractMdStatus(array $raw3DAuthResponseData): ?string return $raw3DAuthResponseData['mdstatus'] ?? null; } - /** - * @inheritDoc - */ - public function mapTxType($txType): ?string - { - $historyResponseTxTypes = [ - 'Satis' => PosInterface::TX_TYPE_PAY_AUTH, - 'On Otorizasyon' => PosInterface::TX_TYPE_PAY_PRE_AUTH, - 'On Otorizasyon Kapama' => PosInterface::TX_TYPE_PAY_POST_AUTH, - 'Iade' => PosInterface::TX_TYPE_REFUND, - 'Iptal' => PosInterface::TX_TYPE_CANCEL, - // ... Odul Sorgulama - ]; - - return $historyResponseTxTypes[$txType] ?? parent::mapTxType($txType); - } - - /** - * 100001 => 1000.01 - * @param string $amount - * - * @return float - */ - protected function formatAmount(string $amount): float - { - return ((float) $amount) / 100; - } - /** * returns mapped data of the common response data among all 3d models. - * @phpstan-param PosInterface::MODEL_3D_* $paymentModel * - * @param array $raw3DAuthResponseData - * @param string $paymentModel + * @param array $raw3DAuthResponseData + * @param PosInterface::MODEL_3D_* $paymentModel + * @param PosInterface::TX_TYPE_PAY_* $txType * * @return array */ - protected function map3DCommonResponseData(array $raw3DAuthResponseData, string $paymentModel): array + protected function map3DCommonResponseData(array $raw3DAuthResponseData, string $paymentModel, string $txType): array { $procReturnCode = $raw3DAuthResponseData['procreturncode']; $mdStatus = $this->extractMdStatus($raw3DAuthResponseData); @@ -436,15 +419,15 @@ protected function map3DCommonResponseData(array $raw3DAuthResponseData, string 'auth_code' => null, 'ref_ret_num' => null, 'transaction_security' => null === $mdStatus ? null : $this->mapResponseTransactionSecurity($mdStatus), - 'transaction_type' => $this->mapTxType($raw3DAuthResponseData['txntype']), + 'transaction_type' => $this->valueMapper->mapTxType($raw3DAuthResponseData['txntype']), 'proc_return_code' => $procReturnCode, 'md_status' => $mdStatus, 'status' => $status, 'status_detail' => $this->getStatusDetail($procReturnCode), 'masked_number' => null, - 'amount' => $this->formatAmount($raw3DAuthResponseData['txnamount']), - 'currency' => $this->mapCurrency($raw3DAuthResponseData['txncurrencycode']), - 'installment_count' => $this->mapInstallment($raw3DAuthResponseData['txninstallmentcount']), + 'amount' => $this->valueFormatter->formatAmount($raw3DAuthResponseData['txnamount'], $txType), + 'currency' => $this->valueMapper->mapCurrency($raw3DAuthResponseData['txncurrencycode'], $txType), + 'installment_count' => $this->valueFormatter->formatInstallment($raw3DAuthResponseData['txninstallmentcount'], $txType), 'tx_status' => null, 'eci' => null, 'cavv' => null, @@ -505,40 +488,6 @@ protected function getProcReturnCode(array $response): ?string return $response['Transaction']['Response']['Code'] ?? null; } - /** - * @inheritDoc - */ - protected function mapCurrency(string $currency): string - { - $historyResponseCurrencyMapping = [ - 'TL' => PosInterface::CURRENCY_TRY, - 'USD' => PosInterface::CURRENCY_USD, - 'EUR' => PosInterface::CURRENCY_EUR, - 'RUB' => PosInterface::CURRENCY_RUB, - 'JPY' => PosInterface::CURRENCY_JPY, - 'GBP' => PosInterface::CURRENCY_GBP, - ]; - - return $historyResponseCurrencyMapping[$currency] ?? parent::mapCurrency($currency); - } - - /** - * @inheritDoc - */ - protected function mapInstallment(?string $installment): int - { - if (null === $installment) { - return 0; - } - - // history response - if ('Pesin' === $installment || '1' === $installment) { - return 0; - } - - return parent::mapInstallment($installment); - } - /** * @param array $rawTx * @@ -546,6 +495,7 @@ protected function mapInstallment(?string $installment): int */ private function mapSingleOrderHistoryTransaction(array $rawTx): array { + $txType = PosInterface::TX_TYPE_ORDER_HISTORY; $procReturnCode = $rawTx['Status']; $status = self::TX_DECLINED; if (self::PROCEDURE_SUCCESS_CODE === $procReturnCode) { @@ -559,18 +509,20 @@ private function mapSingleOrderHistoryTransaction(array $rawTx): array $defaultResponse['status'] = $status; $defaultResponse['status_detail'] = $this->getStatusDetail($procReturnCode); $defaultResponse['error_code'] = self::TX_APPROVED === $status ? null : $procReturnCode; - $defaultResponse['transaction_type'] = $rawTx['Type'] === null ? null : $this->mapTxType($rawTx['Type']); + $defaultResponse['transaction_type'] = $rawTx['Type'] === null ? null : $this->valueMapper->mapTxType($rawTx['Type']); if (self::TX_APPROVED === $status) { - $transTime = $rawTx['ProvDate'] ?? $rawTx['PreAuthDate'] ?? $rawTx['AuthDate']; - $defaultResponse['transaction_time'] = new \DateTimeImmutable($transTime.'T000000'); - $defaultResponse['capture_time'] = null !== $rawTx['AuthDate'] ? new \DateTimeImmutable($rawTx['AuthDate'].'T000000') : null; + $transTime = $rawTx['ProvDate'] ?? $rawTx['PreAuthDate'] ?? $rawTx['AuthDate']; + if (null !== $transTime) { + $defaultResponse['transaction_time'] = $this->valueFormatter->formatDateTime($transTime, $txType); + } + $defaultResponse['capture_time'] = null !== $rawTx['AuthDate'] ? $this->valueFormatter->formatDateTime($rawTx['AuthDate'], $txType) : null; $amount = $rawTx['AuthAmount']; - $defaultResponse['capture_amount'] = null !== $amount ? $this->formatAmount($amount) : null; + $defaultResponse['capture_amount'] = null !== $amount ? $this->valueFormatter->formatAmount($amount, $txType) : null; $firstAmount = $amount > 0 ? $amount : $rawTx['PreAuthAmount']; - $defaultResponse['first_amount'] = null !== $firstAmount ? $this->formatAmount($firstAmount) : null; + $defaultResponse['first_amount'] = null !== $firstAmount ? $this->valueFormatter->formatAmount($firstAmount, $txType) : null; $defaultResponse['capture'] = $defaultResponse['first_amount'] > 0 ? $defaultResponse['capture_amount'] === $defaultResponse['first_amount'] : null; - $defaultResponse['currency'] = '0' !== $rawTx['CurrencyCode'] && null !== $rawTx['CurrencyCode'] ? $this->mapCurrency($rawTx['CurrencyCode']) : null; + $defaultResponse['currency'] = '0' !== $rawTx['CurrencyCode'] && null !== $rawTx['CurrencyCode'] ? $this->valueMapper->mapCurrency($rawTx['CurrencyCode'], $txType) : null; } return $defaultResponse; @@ -583,6 +535,7 @@ private function mapSingleOrderHistoryTransaction(array $rawTx): array */ private function mapSingleHistoryTransaction(array $rawTx): array { + $txType = PosInterface::TX_TYPE_HISTORY; $procReturnCode = $rawTx['ResponseCode']; $status = self::TX_DECLINED; if (self::PROCEDURE_SUCCESS_CODE === $procReturnCode) { @@ -595,23 +548,20 @@ private function mapSingleHistoryTransaction(array $rawTx): array $defaultResponse['order_id'] = $rawTx['OrderID']; $defaultResponse['batch_num'] = $rawTx['BatchNum']; $defaultResponse['proc_return_code'] = $procReturnCode; - $defaultResponse['transaction_type'] = null !== $rawTx['TrxType'] ? $this->mapTxType($rawTx['TrxType']) : null; - $defaultResponse['order_status'] = null !== $rawTx['Status'] ? $this->mapHistoryOrderStatus($rawTx['Status'], $defaultResponse['transaction_type']) : null; + $defaultResponse['transaction_type'] = null !== $rawTx['TrxType'] ? $this->valueMapper->mapTxType($rawTx['TrxType']) : null; + $defaultResponse['order_status'] = null !== $rawTx['Status'] ? $this->valueMapper->mapOrderStatus($rawTx['Status'], $txType, $defaultResponse['transaction_type']) : null; $defaultResponse['status'] = $status; $defaultResponse['status_detail'] = $this->getStatusDetail($procReturnCode); $defaultResponse['error_code'] = self::TX_APPROVED === $status ? null : $procReturnCode; $defaultResponse['error_message'] = self::TX_APPROVED === $status ? null : $rawTx['SysErrMsg']; - // 3D Secure => 3D - // 3D Pay => 3D - // NonSecure => '' - $defaultResponse['payment_model'] = '3D' === $rawTx['SafeType'] ? PosInterface::MODEL_3D_SECURE : PosInterface::MODEL_NON_SECURE; - $defaultResponse['transaction_time'] = null !== $rawTx['LastTrxDate'] ? new \DateTimeImmutable($rawTx['LastTrxDate']) : null; + $defaultResponse['payment_model'] = $this->valueMapper->mapSecureType($rawTx['SafeType'] ?? '', $txType); + $defaultResponse['transaction_time'] = null !== $rawTx['LastTrxDate'] ? $this->valueFormatter->formatDateTime($rawTx['LastTrxDate'], $txType) : null; if (self::TX_APPROVED === $status) { $defaultResponse['masked_number'] = $rawTx['CardNumberMasked']; - $defaultResponse['installment_count'] = $this->mapInstallment($rawTx['InstallmentCnt']); - $defaultResponse['currency'] = null !== $rawTx['CurrencyCode'] ? $this->mapCurrency($rawTx['CurrencyCode']) : null; - $defaultResponse['first_amount'] = null !== $rawTx['AuthAmount'] ? $this->formatAmount($rawTx['AuthAmount']) : null; + $defaultResponse['installment_count'] = $this->valueFormatter->formatInstallment($rawTx['InstallmentCnt'], $txType); + $defaultResponse['currency'] = null !== $rawTx['CurrencyCode'] ? $this->valueMapper->mapCurrency($rawTx['CurrencyCode'], $txType) : null; + $defaultResponse['first_amount'] = null !== $rawTx['AuthAmount'] ? $this->valueFormatter->formatAmount($rawTx['AuthAmount'], $txType) : null; if ($defaultResponse['order_status'] === PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED) { $defaultResponse['capture_amount'] = $defaultResponse['first_amount']; $defaultResponse['capture'] = $defaultResponse['first_amount'] > 0 ? $defaultResponse['capture_amount'] === $defaultResponse['first_amount'] : null; @@ -621,56 +571,4 @@ private function mapSingleHistoryTransaction(array $rawTx): array return $defaultResponse; } - - /** - * todo anlasilmayan durumlar: - * - "Status" => "Iptal", "TrxType" => "Satis" - * - "Status" => "Iptal", "TrxType" => "On Otorizasyon" - * - "Status" => "Iptal", "TrxType" => "Iptal" - * - "Status" => "Iptal", "TrxType" => "Iade" - * - * @param string $txStatus - * @param PosInterface::TX_TYPE_*|null $txType - * - * @return string|null - */ - private function mapHistoryOrderStatus(string $txStatus, ?string $txType): ?string - { - if (null === $txType) { - return null; - } - - // txStatus possible values: - // Basarili - // Basarisiz - // Iptal - // Onaylandi - - if ('Basarili' === $txStatus || 'Onaylandi' === $txStatus) { - if (PosInterface::TX_TYPE_CANCEL === $txType) { - return PosInterface::PAYMENT_STATUS_CANCELED; - } - - if (PosInterface::TX_TYPE_REFUND === $txType) { - // todo how can we decide if order is partially or fully refunded? - return PosInterface::PAYMENT_STATUS_FULLY_REFUNDED; - } - - if (PosInterface::TX_TYPE_PAY_AUTH === $txType || PosInterface::TX_TYPE_PAY_POST_AUTH === $txType) { - return PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED; - } - - if (PosInterface::TX_TYPE_PAY_PRE_AUTH === $txType) { - return PosInterface::PAYMENT_STATUS_PRE_AUTH_COMPLETED; - } - - return null; - } - - if ('Iptal' === $txStatus) { - return null; - } - - return PosInterface::PAYMENT_STATUS_ERROR; - } } diff --git a/src/DataMapper/ResponseDataMapper/InterPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/InterPosResponseDataMapper.php index 4e34446a..9047823c 100644 --- a/src/DataMapper/ResponseDataMapper/InterPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/InterPosResponseDataMapper.php @@ -55,7 +55,7 @@ public function mapPaymentResponse(array $rawPaymentResponseData, string $txType $result['all'] = $rawPaymentResponseData; if (self::TX_APPROVED === $status) { - $result['transaction_time'] = new \DateTimeImmutable($rawPaymentResponseData['TRXDATE'] ?? null); + $result['transaction_time'] = $this->valueFormatter->formatDateTime($rawPaymentResponseData['TRXDATE'] ?? 'now', $txType); } $this->logger->debug('mapped payment response', $result); @@ -161,6 +161,7 @@ public function mapCancelResponse($rawResponseData): array */ public function mapStatusResponse(array $rawResponseData): array { + $txType = PosInterface::TX_TYPE_STATUS; $rawResponseData = $this->emptyStringsToNull($rawResponseData); $procReturnCode = $this->getProcReturnCode($rawResponseData); $status = self::TX_DECLINED; @@ -177,7 +178,7 @@ public function mapStatusResponse(array $rawResponseData): array $defaultResponse['transaction_id'] = $rawResponseData['TransId']; $defaultResponse['error_code'] = self::TX_APPROVED !== $status ? $procReturnCode : null; $defaultResponse['error_message'] = self::TX_APPROVED !== $status ? $rawResponseData['ErrorMessage'] : null; - $defaultResponse['refund_amount'] = $rawResponseData['RefundedAmount'] > 0 ? $this->formatAmount($rawResponseData['RefundedAmount']) : null; + $defaultResponse['refund_amount'] = $rawResponseData['RefundedAmount'] > 0 ? $this->valueFormatter->formatAmount($rawResponseData['RefundedAmount'], $txType) : null; // todo success cevap ornegi bulundugunda guncellenecek: $defaultResponse['order_status'] = null; @@ -185,7 +186,7 @@ public function mapStatusResponse(array $rawResponseData): array $defaultResponse['capture'] = null; if ('' !== $rawResponseData['VoidDate'] && '1.1.0001 00:00:00' !== $rawResponseData['VoidDate']) { - $defaultResponse['cancel_time'] = new \DateTimeImmutable($rawResponseData['VoidDate']); + $defaultResponse['cancel_time'] = $this->valueFormatter->formatDateTime($rawResponseData['VoidDate'], $txType); } return $defaultResponse; @@ -264,18 +265,6 @@ protected function getProcReturnCode(array $response): ?string return $response['ProcReturnCode'] ?? null; } - /** - * 0 => 0.0 - * 1.056,2 => 1056.2 - * @param string $amount - * - * @return float - */ - protected function formatAmount(string $amount): float - { - return (float) \str_replace(',', '.', \str_replace('.', '', $amount)); - } - /** * @phpstan-param PosInterface::TX_TYPE_PAY_AUTH|PosInterface::TX_TYPE_PAY_PRE_AUTH $txType * @phpstan-param PosInterface::MODEL_3D_* $paymentModel @@ -313,7 +302,7 @@ private function map3DPaymentResponse(?array $rawPaymentResponseData, string $tx $result['all'] = $rawPaymentResponseData; if (self::TX_APPROVED === $result['status']) { - $result['transaction_time'] = new \DateTimeImmutable($rawPaymentResponseData['TRXDATE']); + $result['transaction_time'] = $this->valueFormatter->formatDateTime($rawPaymentResponseData['TRXDATE'], $txType); } $this->logger->debug('mapped payment response', $result); @@ -357,9 +346,9 @@ private function map3DCommonResponseData(array $raw3DAuthResponseData, ?array $r 'masked_number' => $raw3DAuthResponseData['Pan'], 'month' => null, 'year' => null, - 'amount' => $this->formatAmount($raw3DAuthResponseData['PurchAmount']), - 'currency' => $this->mapCurrency($raw3DAuthResponseData['Currency']), - 'transaction_time' => isset($raw3DAuthResponseData['TRXDATE']) ? new \DateTimeImmutable($raw3DAuthResponseData['TRXDATE']) : null, + 'amount' => $this->valueFormatter->formatAmount($raw3DAuthResponseData['PurchAmount'], $txType), + 'currency' => $this->valueMapper->mapCurrency($raw3DAuthResponseData['Currency'], $txType), + 'transaction_time' => isset($raw3DAuthResponseData['TRXDATE']) ? $this->valueFormatter->formatDateTime($raw3DAuthResponseData['TRXDATE'], $txType) : null, 'eci' => $raw3DAuthResponseData['Eci'], /** * TxnStat 3D doğrulama sonucunu belirtir : diff --git a/src/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapper.php index 7090184b..a0345cdc 100644 --- a/src/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapper.php @@ -22,18 +22,6 @@ class KuveytPosResponseDataMapper extends AbstractResponseDataMapper 'HashDataError' => 'invalid_transaction', ]; - /** - * Order Status Codes - * - * @var array - */ - protected array $orderStatusMappings = [ - 1 => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, - 4 => PosInterface::PAYMENT_STATUS_FULLY_REFUNDED, - 5 => PosInterface::PAYMENT_STATUS_PARTIALLY_REFUNDED, - 6 => PosInterface::PAYMENT_STATUS_CANCELED, - ]; - /** * {@inheritDoc} */ @@ -79,9 +67,9 @@ public function mapPaymentResponse(array $rawPaymentResponseData, string $txType $result['batch_num'] = $vPosMessage['BatchID']; // Stan: Pos bankası tarafında verilen referans işlem referans numarasıdır. $result['transaction_id'] = $rawPaymentResponseData['Stan']; - $result['amount'] = $this->formatAmount($vPosMessage['Amount']); - $result['currency'] = $this->mapCurrency($vPosMessage['CurrencyCode']); - $result['installment_count'] = $this->mapInstallment($vPosMessage['InstallmentCount']); + $result['amount'] = $this->valueFormatter->formatAmount($vPosMessage['Amount'], $txType); + $result['currency'] = $this->valueMapper->mapCurrency($vPosMessage['CurrencyCode'], $txType); + $result['installment_count'] = $this->valueFormatter->formatInstallment($vPosMessage['InstallmentCount'], $txType); $result['masked_number'] = $vPosMessage['CardNumber']; $result['transaction_time'] = new \DateTimeImmutable(); @@ -99,7 +87,7 @@ public function map3DPaymentData(array $raw3DAuthResponseData, ?array $rawPaymen '3d_auth_response' => $raw3DAuthResponseData, 'provision_response' => $rawPaymentResponseData, ]); - $threeDResponse = $this->map3DCommonResponseData($raw3DAuthResponseData); + $threeDResponse = $this->map3DCommonResponseData($raw3DAuthResponseData, $txType); /** @var PosInterface::TX_TYPE_PAY_AUTH|PosInterface::TX_TYPE_PAY_PRE_AUTH $txType */ $txType = $threeDResponse['transaction_type'] ?? $txType; if (null === $rawPaymentResponseData || [] === $rawPaymentResponseData) { @@ -141,6 +129,7 @@ public function map3DHostResponseData(array $raw3DAuthResponseData, string $txTy */ public function mapStatusResponse(array $rawResponseData): array { + $txType = PosInterface::TX_TYPE_STATUS; $rawResponseData = $this->emptyStringsToNull($rawResponseData); $status = self::TX_DECLINED; $data = $rawResponseData['GetMerchantOrderDetailResult']['Value']; @@ -168,28 +157,28 @@ public function mapStatusResponse(array $rawResponseData): array $defaultResponse['proc_return_code'] = $procReturnCode; if (self::TX_APPROVED === $status) { - $defaultResponse['order_status'] = $this->orderStatusMappings[$orderContract['LastOrderStatus']] ?? null; + $defaultResponse['order_status'] = $this->valueMapper->mapOrderStatus($orderContract['LastOrderStatus']); $defaultResponse['order_id'] = $orderContract['MerchantOrderId']; $defaultResponse['remote_order_id'] = (string) $orderContract['OrderId']; $defaultResponse['auth_code'] = $orderContract['ProvNumber']; $defaultResponse['ref_ret_num'] = $orderContract['RRN']; $defaultResponse['transaction_id'] = $orderContract['Stan']; - $defaultResponse['currency'] = $this->mapCurrency($orderContract['FEC']); + $defaultResponse['currency'] = $this->valueMapper->mapCurrency($orderContract['FEC'], $txType); $defaultResponse['first_amount'] = (float) $orderContract['FirstAmount']; $defaultResponse['masked_number'] = $orderContract['CardNumber']; - $defaultResponse['transaction_time'] = new \DateTimeImmutable($orderContract['OrderDate']); - $defaultResponse['installment_count'] = $this->mapInstallment($orderContract['InstallmentCount']); + $defaultResponse['transaction_time'] = $this->valueFormatter->formatDateTime($orderContract['OrderDate'], $txType); + $defaultResponse['installment_count'] = $this->valueFormatter->formatInstallment($orderContract['InstallmentCount'], $txType); if (PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED === $defaultResponse['order_status']) { $defaultResponse['capture_amount'] = null !== $orderContract['FirstAmount'] ? (float) $orderContract['FirstAmount'] : null; $defaultResponse['capture'] = $defaultResponse['first_amount'] > 0 && $defaultResponse['first_amount'] === $defaultResponse['capture_amount']; if ($defaultResponse['capture']) { - $defaultResponse['capture_time'] = new \DateTimeImmutable($orderContract['UpdateSystemDate']); + $defaultResponse['capture_time'] = $this->valueFormatter->formatDateTime($orderContract['UpdateSystemDate'], $txType); } } elseif (PosInterface::PAYMENT_STATUS_CANCELED === $defaultResponse['order_status']) { - $defaultResponse['cancel_time'] = new \DateTimeImmutable($orderContract['UpdateSystemDate']); + $defaultResponse['cancel_time'] = $this->valueFormatter->formatDateTime($orderContract['UpdateSystemDate'], $txType); } elseif (PosInterface::PAYMENT_STATUS_FULLY_REFUNDED === $defaultResponse['order_status']) { - $defaultResponse['refund_time'] = new \DateTimeImmutable($orderContract['UpdateSystemDate']); + $defaultResponse['refund_time'] = $this->valueFormatter->formatDateTime($orderContract['UpdateSystemDate'], $txType); } } @@ -247,7 +236,7 @@ public function mapRefundResponse(array $rawResponseData): array $result['order_id'] = $value['MerchantOrderId']; $result['remote_order_id'] = (string) $value['OrderId']; $result['status'] = $status; - $result['currency'] = $this->mapCurrency($value['CurrencyCode']); + $result['currency'] = $this->valueMapper->mapCurrency($value['CurrencyCode'], PosInterface::TX_TYPE_REFUND); if (self::TX_APPROVED === $status) { $result['auth_code'] = $value['ProvisionNumber']; @@ -305,7 +294,7 @@ public function mapCancelResponse(array $rawResponseData): array $result['order_id'] = $value['MerchantOrderId']; $result['remote_order_id'] = (string) $value['OrderId']; $result['status'] = $status; - $result['currency'] = $this->mapCurrency($value['CurrencyCode']); + $result['currency'] = $this->valueMapper->mapCurrency($value['CurrencyCode'], PosInterface::TX_TYPE_CANCEL); if (self::TX_APPROVED === $status) { $result['auth_code'] = $value['ProvisionNumber']; @@ -349,17 +338,6 @@ public function extractMdStatus(array $raw3DAuthResponseData): ?string return $this->getProcReturnCode($raw3DAuthResponseData); } - /** - * "101" => 1.01 - * @param string $amount - * - * @return float - */ - protected function formatAmount(string $amount): float - { - return (float) $amount / 100; - } - /** * Get ProcReturnCode * @@ -372,19 +350,6 @@ protected function getProcReturnCode(array $response): ?string return $response['ResponseCode'] ?? null; } - /** - * @param string $currency currency code that is accepted by bank - * - * @return PosInterface::CURRENCY_*|string - */ - protected function mapCurrency(string $currency): string - { - // 949 => 0949; for the request gateway wants 0949 code, but in response they send 949 code. - $currencyNormalized = str_pad($currency, 4, '0', STR_PAD_LEFT); - - return parent::mapCurrency($currencyNormalized); - } - /** * Get Status Detail Text * @@ -411,11 +376,12 @@ protected function mapResponseTransactionSecurity(string $mdStatus): string /** * returns mapped data of the common response data among all 3d models. * - * @param array $raw3DAuthResponseData + * @param array $raw3DAuthResponseData + * @param PosInterface::TX_TYPE_PAY_* $txType * * @return array */ - protected function map3DCommonResponseData(array $raw3DAuthResponseData): array + protected function map3DCommonResponseData(array $raw3DAuthResponseData, string $txType): array { $raw3DAuthResponseData = $this->emptyStringsToNull($raw3DAuthResponseData); $procReturnCode = $this->getProcReturnCode($raw3DAuthResponseData); @@ -437,7 +403,7 @@ protected function map3DCommonResponseData(array $raw3DAuthResponseData): array $default = [ 'order_id' => $orderId, 'transaction_security' => $this->mapResponseTransactionSecurity('todo'), - 'transaction_type' => isset($vPosMessage['TransactionType']) ? $this->mapTxType($vPosMessage['TransactionType']) : null, + 'transaction_type' => isset($vPosMessage['TransactionType']) ? $this->valueMapper->mapTxType($vPosMessage['TransactionType']) : null, 'proc_return_code' => $procReturnCode, 'md_status' => null, 'payment_model' => null, @@ -452,9 +418,9 @@ protected function map3DCommonResponseData(array $raw3DAuthResponseData): array ]; if (self::TX_APPROVED === $status) { - $default['payment_model'] = $this->mapSecurityType($vPosMessage['TransactionSecurity']); - $default['amount'] = $this->formatAmount($vPosMessage['Amount']); - $default['currency'] = $this->mapCurrency($vPosMessage['CurrencyCode']); + $default['payment_model'] = $this->valueMapper->mapSecureType($vPosMessage['TransactionSecurity'], $txType); + $default['amount'] = $this->valueFormatter->formatAmount($vPosMessage['Amount'], $txType); + $default['currency'] = $this->valueMapper->mapCurrency($vPosMessage['CurrencyCode'], $txType); $default['masked_number'] = $vPosMessage['CardNumber']; $default['batch_num'] = $vPosMessage['BatchID'] > 0 ? $vPosMessage['BatchID'] : null; } diff --git a/src/DataMapper/ResponseDataMapper/PayFlexCPV4PosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/PayFlexCPV4PosResponseDataMapper.php index 91fbd410..929726a9 100644 --- a/src/DataMapper/ResponseDataMapper/PayFlexCPV4PosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/PayFlexCPV4PosResponseDataMapper.php @@ -59,11 +59,11 @@ public function map3DPayResponseData(array $raw3DAuthResponseData, string $txTyp $paymentResponse['auth_code'] = $raw3DAuthResponseData['AuthCode']; $paymentResponse['ref_ret_num'] = $raw3DAuthResponseData['TransactionId']; $paymentResponse['order_id'] = $raw3DAuthResponseData['OrderID']; - $paymentResponse['currency'] = $this->mapCurrency($raw3DAuthResponseData['AmountCode']); - $paymentResponse['amount'] = $this->formatAmount($raw3DAuthResponseData['Amount']); - $paymentResponse['transaction_type'] = $this->mapTxType($raw3DAuthResponseData['TransactionType']); - $paymentResponse['installment_count'] = $this->mapInstallment($raw3DAuthResponseData['InstallmentCount']); - $paymentResponse['transaction_time'] = new \DateTimeImmutable($raw3DAuthResponseData['HostDate']); + $paymentResponse['currency'] = $this->valueMapper->mapCurrency($raw3DAuthResponseData['AmountCode'], $txType); + $paymentResponse['amount'] = $this->valueFormatter->formatAmount($raw3DAuthResponseData['Amount'], $txType); + $paymentResponse['transaction_type'] = $this->valueMapper->mapTxType($raw3DAuthResponseData['TransactionType']); + $paymentResponse['installment_count'] = $this->valueFormatter->formatInstallment($raw3DAuthResponseData['InstallmentCount'], $txType); + $paymentResponse['transaction_time'] = $this->valueFormatter->formatDateTime($raw3DAuthResponseData['HostDate'], $txType); } return $paymentResponse; @@ -138,7 +138,7 @@ public function mapPaymentResponse(array $rawPaymentResponseData, string $txType $commonResponse['auth_code'] = $rawPaymentResponseData['AuthCode']; $commonResponse['ref_ret_num'] = $rawPaymentResponseData['Rrn']; $commonResponse['order_id'] = $rawPaymentResponseData['OrderId']; - $commonResponse['transaction_type'] = $this->mapTxType($rawPaymentResponseData['TransactionType']); + $commonResponse['transaction_type'] = $this->valueMapper->mapTxType($rawPaymentResponseData['TransactionType']); $commonResponse['eci'] = $rawPaymentResponseData['ECI']; } diff --git a/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php index 59614cd2..09c822ca 100644 --- a/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapper.php @@ -7,7 +7,6 @@ use Mews\Pos\Exceptions\NotImplementedException; use Mews\Pos\PosInterface; -use Psr\Log\LoggerInterface; class PayFlexV4PosResponseDataMapper extends AbstractResponseDataMapper { @@ -28,23 +27,6 @@ class PayFlexV4PosResponseDataMapper extends AbstractResponseDataMapper '9065' => 'invalid_credentials', ]; - /** - * @param array $currencyMappings - * @param array> $txTypeMappings - * @param array $secureTypeMappings - * @param LoggerInterface $logger - */ - public function __construct(array $currencyMappings, array $txTypeMappings, array $secureTypeMappings, LoggerInterface $logger) - { - parent::__construct($currencyMappings, $txTypeMappings, $secureTypeMappings, $logger); - - $this->secureTypeMappings += [ - '1' => PosInterface::MODEL_NON_SECURE, - '2' => PosInterface::MODEL_3D_SECURE, - '3' => PosInterface::MODEL_3D_PAY, - ]; - } - /** * {@inheritdoc} */ @@ -70,9 +52,9 @@ public function map3DPaymentData(array $raw3DAuthResponseData, ?array $rawPaymen 'auth_code' => null, 'order_id' => $raw3DAuthResponseData['VerifyEnrollmentRequestId'], 'status' => $threeDAuthStatus, - 'currency' => $this->mapCurrency($raw3DAuthResponseData['PurchCurrency']), - 'amount' => $this->formatAmount($raw3DAuthResponseData['PurchAmount']), - 'installment_count' => $this->mapInstallment($raw3DAuthResponseData['InstallmentCount']), + 'currency' => $this->valueMapper->mapCurrency($raw3DAuthResponseData['PurchCurrency'], $txType), + 'amount' => $this->valueFormatter->formatAmount($raw3DAuthResponseData['PurchAmount'], $txType), + 'installment_count' => $this->valueFormatter->formatInstallment($raw3DAuthResponseData['InstallmentCount'], $txType), 'status_detail' => null, 'error_code' => self::TX_DECLINED === $threeDAuthStatus ? $raw3DAuthResponseData['ErrorCode'] : null, 'error_message' => self::TX_DECLINED === $threeDAuthStatus ? $raw3DAuthResponseData['ErrorMessage'] : null, @@ -143,6 +125,7 @@ public function mapCancelResponse($rawResponseData): array */ public function mapStatusResponse(array $rawResponseData): array { + $txType = PosInterface::TX_TYPE_STATUS; $rawResponseData = $this->emptyStringsToNull($rawResponseData); /** * @var array{ResponseCode: string, ResponseMessage: string, ResponseDateTime: string, Status: 'Success'|'Error'} $responseInfo @@ -183,9 +166,9 @@ public function mapStatusResponse(array $rawResponseData): array $defaultResponse['transaction_id'] = $txResultInfo['TransactionId']; $defaultResponse['ref_ret_num'] = $txResultInfo['Rrn']; $defaultResponse['order_status'] = $orderStatus; - $defaultResponse['transaction_type'] = $this->mapTxType($txResultInfo['TransactionType']); - $defaultResponse['currency'] = $this->mapCurrency($txResultInfo['AmountCode']); - $defaultResponse['first_amount'] = $this->formatAmount($txResultInfo['CurrencyAmount'] ?? $txResultInfo['Amount']); + $defaultResponse['transaction_type'] = $this->valueMapper->mapTxType($txResultInfo['TransactionType']); + $defaultResponse['currency'] = $this->valueMapper->mapCurrency($txResultInfo['AmountCode'], $txType); + $defaultResponse['first_amount'] = $this->valueFormatter->formatAmount($txResultInfo['CurrencyAmount'] ?? $txResultInfo['Amount'], $txType); $defaultResponse['capture_amount'] = null; $defaultResponse['status'] = self::PROCEDURE_SUCCESS_CODE === $orderProcCode ? self::TX_APPROVED : self::TX_DECLINED; $defaultResponse['error_code'] = self::PROCEDURE_SUCCESS_CODE !== $orderProcCode ? $txResultInfo['HostResultCode'] : null; @@ -203,13 +186,13 @@ public function mapPaymentResponse(array $rawPaymentResponseData, string $txType $rawPaymentResponseData = $this->emptyStringsToNull($rawPaymentResponseData); $commonResponse = $this->getCommonPaymentResponse($rawPaymentResponseData, $txType); $commonResponse['order_id'] = $rawPaymentResponseData['OrderId'] ?? null; - $commonResponse['currency'] = isset($rawPaymentResponseData['CurrencyCode']) ? $this->mapCurrency($rawPaymentResponseData['CurrencyCode']) : null; - $commonResponse['amount'] = isset($rawPaymentResponseData['TLAmount']) ? $this->formatAmount($rawPaymentResponseData['TLAmount']) : null; - $commonResponse['transaction_type'] = isset($rawPaymentResponseData['TransactionType']) ? $this->mapTxType($rawPaymentResponseData['TransactionType']) : null; + $commonResponse['currency'] = isset($rawPaymentResponseData['CurrencyCode']) ? $this->valueMapper->mapCurrency($rawPaymentResponseData['CurrencyCode'], $txType) : null; + $commonResponse['amount'] = isset($rawPaymentResponseData['TLAmount']) ? $this->valueFormatter->formatAmount($rawPaymentResponseData['TLAmount'], $txType) : null; + $commonResponse['transaction_type'] = isset($rawPaymentResponseData['TransactionType']) ? $this->valueMapper->mapTxType($rawPaymentResponseData['TransactionType']) : null; if (self::TX_APPROVED === $commonResponse['status']) { - $commonResponse['transaction_id'] = $rawPaymentResponseData['TransactionId']; - $txTime = $rawPaymentResponseData['HostDate']; + $commonResponse['transaction_id'] = $rawPaymentResponseData['TransactionId']; + $txTime = $rawPaymentResponseData['HostDate']; if (\strlen($txTime) === 10) { // ziraat is sending host date without year $txTime = date('Y').$txTime; } @@ -309,7 +292,7 @@ private function getCommonPaymentResponse(array $responseData, string $txType): $status = self::TX_APPROVED; } - $paymentModel = isset($responseData['ThreeDSecureType']) ? $this->mapSecurityType($responseData['ThreeDSecureType']) : null; + $paymentModel = isset($responseData['ThreeDSecureType']) ? $this->valueMapper->mapSecureType($responseData['ThreeDSecureType'], $txType) : null; $response = $this->getDefaultPaymentResponse($txType, $paymentModel); $response['proc_return_code'] = $resultCode; diff --git a/src/DataMapper/ResponseDataMapper/PayForPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/PayForPosResponseDataMapper.php index b9dde0cf..8d21c69c 100644 --- a/src/DataMapper/ResponseDataMapper/PayForPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/PayForPosResponseDataMapper.php @@ -92,13 +92,13 @@ public function map3DPaymentData(array $raw3DAuthResponseData, ?array $rawPaymen $threeDAuthStatus = $this->is3dAuthSuccess($mdStatus) ? self::TX_APPROVED : self::TX_DECLINED; $paymentResponseData = []; - $mapped3DResponseData = $this->map3DCommonResponseData($raw3DAuthResponseData); + $mapped3DResponseData = $this->map3DCommonResponseData($raw3DAuthResponseData, $txType); /** @var PosInterface::TX_TYPE_PAY_AUTH|PosInterface::TX_TYPE_PAY_PRE_AUTH $txType */ $txType = $mapped3DResponseData['transaction_type'] ?? $txType; /** @var PosInterface::MODEL_3D_* $paymentModel */ - $paymentModel = $this->mapSecurityType($raw3DAuthResponseData['SecureType']); + $paymentModel = $this->valueMapper->mapSecureType($raw3DAuthResponseData['SecureType'], $txType); if (self::TX_APPROVED === $threeDAuthStatus && null !== $rawPaymentResponseData) { $paymentResponseData = $this->map3DPaymentResponseCommon($rawPaymentResponseData, $txType, $paymentModel); } @@ -153,7 +153,7 @@ public function map3DPayResponseData(array $raw3DAuthResponseData, string $txTyp 'all' => $raw3DAuthResponseData, ]; - $commonThreeDResponseData = $this->map3DCommonResponseData($raw3DAuthResponseData); + $commonThreeDResponseData = $this->map3DCommonResponseData($raw3DAuthResponseData, $txType); /** @var PosInterface::TX_TYPE_PAY_AUTH|PosInterface::TX_TYPE_PAY_PRE_AUTH $txType */ $txType = $commonThreeDResponseData['transaction_type']; /** @var PosInterface::MODEL_3D_* $paymentModel */ @@ -220,6 +220,7 @@ public function mapCancelResponse($rawResponseData): array */ public function mapStatusResponse(array $rawResponseData): array { + $txType = PosInterface::TX_TYPE_STATUS; $rawResponseData = $this->emptyStringsToNull($rawResponseData); $procReturnCode = $this->getProcReturnCode($rawResponseData); @@ -233,9 +234,9 @@ public function mapStatusResponse(array $rawResponseData): array $defaultResponse['proc_return_code'] = $procReturnCode; $defaultResponse['order_id'] = $rawResponseData['OrderId']; $defaultResponse['org_order_id'] = $rawResponseData['OrgOrderId']; - $defaultResponse['installment_count'] = $this->mapInstallment($rawResponseData['InstallmentCount']); - $defaultResponse['transaction_type'] = $this->mapTxType($rawResponseData['TxnType']); - $defaultResponse['currency'] = $this->mapCurrency($rawResponseData['Currency']); + $defaultResponse['installment_count'] = $this->valueFormatter->formatInstallment($rawResponseData['InstallmentCount'], $txType); + $defaultResponse['transaction_type'] = $this->valueMapper->mapTxType($rawResponseData['TxnType']); + $defaultResponse['currency'] = $this->valueMapper->mapCurrency($rawResponseData['Currency'], $txType); $defaultResponse['status'] = $status; $defaultResponse['status_detail'] = $this->getStatusDetail($procReturnCode); @@ -245,8 +246,8 @@ public function mapStatusResponse(array $rawResponseData): array $defaultResponse['ref_ret_num'] = $rawResponseData['HostRefNum']; $defaultResponse['masked_number'] = $rawResponseData['CardMask']; - $defaultResponse['first_amount'] = $this->formatAmount($rawResponseData['PurchAmount']); - $defaultResponse['transaction_time'] = new \DateTimeImmutable($rawResponseData['InsertDatetime']); + $defaultResponse['first_amount'] = $this->valueFormatter->formatAmount($rawResponseData['PurchAmount'], $txType); + $defaultResponse['transaction_time'] = $this->valueFormatter->formatDateTime($rawResponseData['InsertDatetime'], $txType); $defaultResponse['capture'] = false; if (\in_array( $defaultResponse['transaction_type'], @@ -254,7 +255,7 @@ public function mapStatusResponse(array $rawResponseData): array true )) { $defaultResponse['capture'] = true; - $defaultResponse['capture_amount'] = $this->formatAmount($rawResponseData['PurchAmount']); + $defaultResponse['capture_amount'] = $this->valueFormatter->formatAmount($rawResponseData['PurchAmount'], $txType); $defaultResponse['capture_time'] = $defaultResponse['transaction_time']; $orderStatus = PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED; } @@ -263,11 +264,11 @@ public function mapStatusResponse(array $rawResponseData): array // ex: // VoidDate: 20240119 // VoidTime: 213405 - $defaultResponse['cancel_time'] = new \DateTimeImmutable($rawResponseData['VoidDate'].'T'.$rawResponseData['VoidTime']); + $defaultResponse['cancel_time'] = $this->valueFormatter->formatDateTime($rawResponseData['VoidDate'].'T'.$rawResponseData['VoidTime'], $txType); } if ($rawResponseData['RefundedAmount'] > 0) { - $defaultResponse['refund_amount'] = $this->formatAmount($rawResponseData['RefundedAmount']); + $defaultResponse['refund_amount'] = $this->valueFormatter->formatAmount($rawResponseData['RefundedAmount'], PosInterface::TX_TYPE_STATUS); } @@ -484,11 +485,12 @@ private function map3DPaymentResponseCommon(array $rawPaymentResponseData, strin /** * returns mapped data of the common response data among all 3d models. * - * @param array $raw3DAuthResponseData + * @param array $raw3DAuthResponseData + * @param PosInterface::TX_TYPE_PAY_* $txType * * @return array */ - private function map3DCommonResponseData(array $raw3DAuthResponseData): array + private function map3DCommonResponseData(array $raw3DAuthResponseData, string $txType): array { $procReturnCode = $this->getProcReturnCode($raw3DAuthResponseData); $mdStatus = $this->extractMdStatus($raw3DAuthResponseData); @@ -496,11 +498,11 @@ private function map3DCommonResponseData(array $raw3DAuthResponseData): array $result = [ 'transaction_security' => null, - 'transaction_type' => $this->mapTxType($raw3DAuthResponseData['TxnType']), - 'payment_model' => $this->mapSecurityType($raw3DAuthResponseData['SecureType']), + 'transaction_type' => $this->valueMapper->mapTxType($raw3DAuthResponseData['TxnType']), + 'payment_model' => $this->valueMapper->mapSecureType($raw3DAuthResponseData['SecureType'], $txType), 'masked_number' => $raw3DAuthResponseData['CardMask'], - 'amount' => $this->formatAmount($raw3DAuthResponseData['PurchAmount']), - 'currency' => $this->mapCurrency($raw3DAuthResponseData['Currency']), + 'amount' => $this->valueFormatter->formatAmount($raw3DAuthResponseData['PurchAmount'], $txType), + 'currency' => $this->valueMapper->mapCurrency($raw3DAuthResponseData['Currency'], $txType), 'tx_status' => $raw3DAuthResponseData['TxnResult'], 'md_status' => $mdStatus, 'md_error_code' => (self::TX_DECLINED === $threeDAuthStatus) ? $procReturnCode : null, @@ -510,8 +512,8 @@ private function map3DCommonResponseData(array $raw3DAuthResponseData): array ]; if (self::TX_APPROVED === $threeDAuthStatus) { - $result['installment_count'] = $this->mapInstallment($raw3DAuthResponseData['InstallmentCount']); - $result['transaction_time'] = new \DateTimeImmutable($raw3DAuthResponseData['TransactionDate']); + $result['installment_count'] = $this->valueFormatter->formatInstallment($raw3DAuthResponseData['InstallmentCount'], $txType); + $result['transaction_time'] = $this->valueFormatter->formatDateTime($raw3DAuthResponseData['TransactionDate'], $txType); $result['batch_num'] = $raw3DAuthResponseData['BatchNo']; } @@ -529,6 +531,7 @@ private function map3DCommonResponseData(array $raw3DAuthResponseData): array */ private function mapSingleOrderHistoryTransaction(array $rawTx): array { + $txType = PosInterface::TX_TYPE_ORDER_HISTORY; $procReturnCode = $this->getProcReturnCode($rawTx); $status = self::TX_DECLINED; if (self::PROCEDURE_SUCCESS_CODE === $procReturnCode) { @@ -541,16 +544,16 @@ private function mapSingleOrderHistoryTransaction(array $rawTx): array $defaultResponse['status'] = $status; $defaultResponse['status_detail'] = $this->getStatusDetail($procReturnCode); $defaultResponse['error_code'] = self::TX_APPROVED === $status ? null : $procReturnCode; - $defaultResponse['transaction_type'] = $this->mapTxType((string) $rawTx['TxnType']); - $defaultResponse['currency'] = null !== $rawTx['Currency'] ? $this->mapCurrency($rawTx['Currency']) : null; + $defaultResponse['transaction_type'] = $this->valueMapper->mapTxType((string) $rawTx['TxnType']); + $defaultResponse['currency'] = null !== $rawTx['Currency'] ? $this->valueMapper->mapCurrency($rawTx['Currency'], $txType) : null; if (self::TX_APPROVED === $status) { $orderStatus = null; $defaultResponse['auth_code'] = $rawTx['AuthCode'] ?? null; $defaultResponse['ref_ret_num'] = $rawTx['HostRefNum'] ?? null; $defaultResponse['masked_number'] = $rawTx['CardMask']; - $defaultResponse['first_amount'] = null !== $rawTx['PurchAmount'] ? $this->formatAmount($rawTx['PurchAmount']) : null; - $defaultResponse['transaction_time'] = null !== $rawTx['InsertDatetime'] ? new \DateTimeImmutable($rawTx['InsertDatetime']) : null; + $defaultResponse['first_amount'] = null !== $rawTx['PurchAmount'] ? $this->valueFormatter->formatAmount($rawTx['PurchAmount'], $txType) : null; + $defaultResponse['transaction_time'] = null !== $rawTx['InsertDatetime'] ? $this->valueFormatter->formatDateTime($rawTx['InsertDatetime'], $txType) : null; if (\in_array( $defaultResponse['transaction_type'], [PosInterface::TX_TYPE_PAY_AUTH, PosInterface::TX_TYPE_PAY_POST_AUTH], @@ -578,7 +581,7 @@ private function mapSingleOrderHistoryTransaction(array $rawTx): array */ private function mapSingleHistoryTransaction(array $rawTx): array { - $mappedTx = $this->mapSingleOrderHistoryTransaction($rawTx); + $mappedTx = $this->mapSingleOrderHistoryTransaction($rawTx); $mappedTx['order_id'] = $rawTx['OrderId']; return $mappedTx; diff --git a/src/DataMapper/ResponseDataMapper/PosNetResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/PosNetResponseDataMapper.php index fc4227ae..fef23b0f 100644 --- a/src/DataMapper/ResponseDataMapper/PosNetResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/PosNetResponseDataMapper.php @@ -78,7 +78,7 @@ public function mapPaymentResponse(array $rawPaymentResponseData, string $txType $defaultResponse['all'] = $rawPaymentResponseData; if (self::TX_APPROVED === $status) { - $defaultResponse['installment_count'] = $this->mapInstallment($rawPaymentResponseData['instInfo']['inst1']); + $defaultResponse['installment_count'] = $this->valueFormatter->formatInstallment($rawPaymentResponseData['instInfo']['inst1'], $txType); $defaultResponse['transaction_time'] = new \DateTimeImmutable(); } @@ -127,8 +127,8 @@ public function map3DPaymentData(array $raw3DAuthResponseData, ?array $rawPaymen 'order_id' => $order['id'], 'remote_order_id' => $oosResolveMerchantDataResponse['xid'] ?? null, 'transaction_security' => $transactionSecurity, - 'amount' => $this->formatAmount((string) $oosResolveMerchantDataResponse['amount']), - 'currency' => $this->mapCurrency((string) $oosResolveMerchantDataResponse['currency']), + 'amount' => $this->valueFormatter->formatAmount((string) $oosResolveMerchantDataResponse['amount'], $txType), + 'currency' => $this->valueMapper->mapCurrency((string) $oosResolveMerchantDataResponse['currency'], $txType), 'proc_return_code' => $procReturnCode, 'status' => $status, 'status_detail' => $this->getStatusDetail($procReturnCode), @@ -189,7 +189,7 @@ public function mapCancelResponse($rawResponseData): array $state = $rawResponseData['state'] ?? null; $transactionType = null; if (null !== $state) { - $transactionType = $this->mapTxType($state); + $transactionType = $this->valueMapper->mapTxType($state); } $results = [ @@ -212,10 +212,10 @@ public function mapCancelResponse($rawResponseData): array $txResults = []; if (null !== $transactionDetails) { $txResults = [ - 'auth_code' => $transactionDetails['authCode'] ?? null, - 'transaction_id' => null, - 'ref_ret_num' => $transactionDetails['hostlogkey'] ?? null, - 'date' => $transactionDetails['tranDate'] ?? null, + 'auth_code' => $transactionDetails['authCode'] ?? null, + 'transaction_id' => null, + 'ref_ret_num' => $transactionDetails['hostlogkey'] ?? null, + 'date' => $transactionDetails['tranDate'] ?? null, ]; } @@ -227,6 +227,7 @@ public function mapCancelResponse($rawResponseData): array */ public function mapStatusResponse(array $rawResponseData): array { + $txType = PosInterface::TX_TYPE_STATUS; $rawResponseData = $this->emptyStringsToNull($rawResponseData); $status = self::TX_DECLINED; $errorCode = $rawResponseData['respCode'] ?? null; @@ -244,14 +245,14 @@ public function mapStatusResponse(array $rawResponseData): array $transactionDetails = $rawResponseData['transactions']['transaction']; $txResults = [ - 'currency' => $this->mapCurrency($transactionDetails['currencyCode']), - 'first_amount' => $this->formatStatusAmount($transactionDetails['amount']), - 'transaction_type' => null === $transactionDetails['state'] ? null : $this->mapTxType($transactionDetails['state']), + 'currency' => $this->valueMapper->mapCurrency($transactionDetails['currencyCode'], $txType), + 'first_amount' => $this->valueFormatter->formatAmount($transactionDetails['amount'], $txType), + 'transaction_type' => null === $transactionDetails['state'] ? null : $this->valueMapper->mapTxType($transactionDetails['state']), 'order_id' => $transactionDetails['orderID'], 'auth_code' => $transactionDetails['authCode'] ?? null, 'ref_ret_num' => $transactionDetails['hostlogkey'] ?? null, // tranDate ex: 2019-10-10 11:21:14.281 - 'transaction_time' => isset($transactionDetails['tranDate']) ? new \DateTimeImmutable($transactionDetails['tranDate']) : null, + 'transaction_time' => isset($transactionDetails['tranDate']) ? $this->valueFormatter->formatDateTime($transactionDetails['tranDate'], $txType) : null, ]; } @@ -270,6 +271,7 @@ public function mapStatusResponse(array $rawResponseData): array */ public function mapOrderHistoryResponse(array $rawResponseData): array { + $txType = PosInterface::TX_TYPE_ORDER_HISTORY; $status = self::TX_DECLINED; $rawResponseData = $this->emptyStringsToNull($rawResponseData); $errorCode = $rawResponseData['respCode'] ?? null; @@ -297,9 +299,9 @@ public function mapOrderHistoryResponse(array $rawResponseData): array if (count($transactionDetails) > 1) { foreach ($transactionDetails as $key => $_transaction) { if ($key > 0) { - $currency = $this->mapCurrency($_transaction['currencyCode']); + $currency = $this->valueMapper->mapCurrency($_transaction['currencyCode'], $txType); $refunds[] = [ - 'amount' => (float) $_transaction['amount'], + 'amount' => $this->valueFormatter->formatAmount($_transaction['amount'], $txType), 'currency' => $currency, 'auth_code' => $_transaction['authCode'], 'date' => $_transaction['tranDate'], @@ -310,16 +312,16 @@ public function mapOrderHistoryResponse(array $rawResponseData): array } $txResults = [ - 'auth_code' => $authCode, - 'transaction_id' => null, - 'ref_ret_num' => $transactionDetails['hostlogkey'] ?? null, - 'date' => $transactionDetails['tranDate'] ?? null, + 'auth_code' => $authCode, + 'transaction_id' => null, + 'ref_ret_num' => $transactionDetails['hostlogkey'] ?? null, + 'date' => $transactionDetails['tranDate'] ?? null, ]; } $transactionType = null; if (null !== $state) { - $transactionType = $this->mapTxType($state); + $transactionType = $this->valueMapper->mapTxType($state); } $results = [ @@ -467,7 +469,7 @@ private function map3dPaymentResponseCommon(array $rawPaymentResponseData, strin $defaultResponse['error_message'] = $rawPaymentResponseData['respText'] ?? null; $defaultResponse['all'] = $rawPaymentResponseData; if (self::TX_APPROVED === $status) { - $defaultResponse['installment_count'] = $this->mapInstallment($rawPaymentResponseData['instInfo']['inst1']); + $defaultResponse['installment_count'] = $this->valueFormatter->formatInstallment($rawPaymentResponseData['instInfo']['inst1'], $txType); $defaultResponse['transaction_time'] = new \DateTimeImmutable(); } diff --git a/src/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapper.php index 3ce8f04b..68349699 100644 --- a/src/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapper.php @@ -7,7 +7,6 @@ use Mews\Pos\Exceptions\NotImplementedException; use Mews\Pos\PosInterface; -use Psr\Log\LoggerInterface; class PosNetV1PosResponseDataMapper extends AbstractResponseDataMapper { @@ -43,37 +42,6 @@ class PosNetV1PosResponseDataMapper extends AbstractResponseDataMapper '0444' => 'bank_call', ]; - /** - * @param array $currencyMappings - * @param array> $txTypeMappings - * @param array $secureTypeMappings - * @param LoggerInterface $logger - */ - public function __construct(array $currencyMappings, array $txTypeMappings, array $secureTypeMappings, LoggerInterface $logger) - { - parent::__construct($currencyMappings, $txTypeMappings, $secureTypeMappings, $logger); - - $this->currencyMappings += [ - '949' => PosInterface::CURRENCY_TRY, - '840' => PosInterface::CURRENCY_USD, - '978' => PosInterface::CURRENCY_EUR, - '826' => PosInterface::CURRENCY_GBP, - '392' => PosInterface::CURRENCY_JPY, - '643' => PosInterface::CURRENCY_RUB, - ]; - } - - /** - * Order Status Codes - * - * @var array - */ - protected array $orderStatusMappings = [ - PosInterface::TX_TYPE_PAY_AUTH => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, - PosInterface::TX_TYPE_CANCEL => PosInterface::PAYMENT_STATUS_CANCELED, - PosInterface::TX_TYPE_REFUND => PosInterface::PAYMENT_STATUS_FULLY_REFUNDED, - ]; - /** * {@inheritDoc} */ @@ -110,7 +78,10 @@ public function mapPaymentResponse(array $rawPaymentResponseData, string $txType 'all' => $rawPaymentResponseData, ]; if (self::TX_APPROVED === $status) { - $mappedResponse['installment_count'] = $this->mapInstallment($rawPaymentResponseData['InstallmentData']['InstallmentCount']); + $mappedResponse['installment_count'] = $this->valueFormatter->formatInstallment( + $rawPaymentResponseData['InstallmentData']['InstallmentCount'], + $txType + ); $mappedResponse['transaction_time'] = new \DateTimeImmutable(); } @@ -132,7 +103,7 @@ public function map3DPaymentData(array $raw3DAuthResponseData, ?array $rawPaymen $threeDAuthApproved = $this->is3dAuthSuccess($mdStatus); $transactionSecurity = null === $mdStatus ? null : $this->mapResponseTransactionSecurity($mdStatus); /** @var PosInterface::TX_TYPE_PAY_AUTH|PosInterface::TX_TYPE_PAY_PRE_AUTH $txType */ - $txType = $this->mapTxType($raw3DAuthResponseData['TranType']) ?? $txType; + $txType = $this->valueMapper->mapTxType($raw3DAuthResponseData['TranType']) ?? $txType; $threeDResponse = [ 'order_id' => $order['id'], @@ -140,11 +111,11 @@ public function map3DPaymentData(array $raw3DAuthResponseData, ?array $rawPaymen 'transaction_security' => $transactionSecurity, 'masked_number' => $raw3DAuthResponseData['CCPrefix'], // Kredi Kartı Numarası ön eki: 450634 'proc_return_code' => null, - 'currency' => isset($raw3DAuthResponseData['CurrencyCode']) ? $this->mapCurrency($raw3DAuthResponseData['CurrencyCode']) : null, + 'currency' => isset($raw3DAuthResponseData['CurrencyCode']) ? $this->valueMapper->mapCurrency($raw3DAuthResponseData['CurrencyCode'], $txType) : null, 'status' => self::TX_DECLINED, 'md_status' => $mdStatus, 'md_error_message' => $threeDAuthApproved ? null : $raw3DAuthResponseData['MdErrorMessage'], - 'amount' => $this->formatAmount($raw3DAuthResponseData['Amount']), + 'amount' => $this->valueFormatter->formatAmount($raw3DAuthResponseData['Amount'], $txType), '3d_all' => $raw3DAuthResponseData, ]; @@ -191,7 +162,7 @@ public function mapCancelResponse($rawResponseData): array return [ 'auth_code' => null, - 'transaction_id' => null, + 'transaction_id' => null, 'ref_ret_num' => null, 'group_id' => null, 'transaction_type' => null, @@ -209,6 +180,7 @@ public function mapCancelResponse($rawResponseData): array */ public function mapStatusResponse(array $rawResponseData): array { + $txType = PosInterface::TX_TYPE_STATUS; $rawResponseData = $this->emptyStringsToNull($rawResponseData); $status = self::TX_DECLINED; $procReturnCode = $this->getProcReturnCode($rawResponseData); @@ -242,18 +214,20 @@ public function mapStatusResponse(array $rawResponseData): array return $defaultResponse; } - $defaultResponse['first_amount'] = $this->formatStatusAmount($rawTx['Amount']); - $defaultResponse['transaction_time'] = new \DateTimeImmutable($rawTx['TransactionDate']); - $defaultResponse['currency'] = $this->mapCurrency($rawTx['CurrencyCode']); + $defaultResponse['first_amount'] = $this->valueFormatter->formatAmount($rawTx['Amount'], $txType); + $defaultResponse['transaction_time'] = $this->valueFormatter->formatDateTime($rawTx['TransactionDate'], $txType); + $defaultResponse['currency'] = $this->valueMapper->mapCurrency($rawTx['CurrencyCode'], $txType); $defaultResponse['masked_number'] = $rawTx['CardNo']; $defaultResponse['order_id'] = $rawTx['OrderId']; - $defaultResponse['transaction_type'] = $this->mapTxType($rawTx['TransactionType']); - $defaultResponse['order_status'] = $this->orderStatusMappings[$defaultResponse['transaction_type']] ?? null; + $defaultResponse['transaction_type'] = $this->valueMapper->mapTxType($rawTx['TransactionType']); + if (null !== $defaultResponse['transaction_type']) { + $defaultResponse['order_status'] = $this->valueMapper->mapOrderStatus($defaultResponse['transaction_type']); + } if (PosInterface::TX_TYPE_REFUND === $defaultResponse['transaction_type']) { - $defaultResponse['refund_time'] = new \DateTimeImmutable($rawTx['TransactionDate']); + $defaultResponse['refund_time'] = $this->valueFormatter->formatDateTime($rawTx['TransactionDate'], $txType); } elseif (PosInterface::TX_TYPE_CANCEL === $defaultResponse['transaction_type']) { - $defaultResponse['cancel_time'] = new \DateTimeImmutable($rawTx['TransactionDate']); + $defaultResponse['cancel_time'] = $this->valueFormatter->formatDateTime($rawTx['TransactionDate'], $txType); } } @@ -351,28 +325,6 @@ protected function getProcReturnCode(array $response): ?string return $response['ServiceResponseData']['ResponseCode'] ?? null; } - /** - * "100001" => 1000.01 - * @param string $amount - * - * @return float - */ - protected function formatAmount(string $amount): float - { - return ((int) $amount) / 100; - } - - /** - * "1,16" => 1.16 - * @param string $amount - * - * @return float - */ - protected function formatStatusAmount(string $amount): float - { - return (float) \str_replace(',', '.', \str_replace('.', '', $amount)); - } - /** * @phpstan-param PosInterface::TX_TYPE_PAY_AUTH|PosInterface::TX_TYPE_PAY_PRE_AUTH $txType * @phpstan-param PosInterface::MODEL_3D_* $paymentModel @@ -402,7 +354,7 @@ private function map3DPaymentResponseCommon(array $rawPaymentResponseData, strin } $mappedResponse = [ - 'transaction_id' => null, + 'transaction_id' => null, 'auth_code' => $rawPaymentResponseData['AuthCode'] ?? null, 'ref_ret_num' => $rawPaymentResponseData['ReferenceCode'] ?? null, 'proc_return_code' => $procReturnCode, @@ -414,7 +366,10 @@ private function map3DPaymentResponseCommon(array $rawPaymentResponseData, strin ]; if (self::TX_APPROVED === $status) { - $mappedResponse['installment_count'] = $this->mapInstallment($rawPaymentResponseData['InstallmentData']['InstallmentCount']); + $mappedResponse['installment_count'] = $this->valueFormatter->formatInstallment( + $rawPaymentResponseData['InstallmentData']['InstallmentCount'], + $txType + ); $mappedResponse['transaction_time'] = new \DateTimeImmutable(); } diff --git a/src/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapper.php index d2fbb912..2772a9d8 100644 --- a/src/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapper.php @@ -28,34 +28,6 @@ class ToslaPosResponseDataMapper extends AbstractResponseDataMapper 999 => 'general_error', ]; - /** - * Order Status Codes - * - * @var array - */ - protected array $orderStatusMappings = [ - 0 => PosInterface::PAYMENT_STATUS_ERROR, - 1 => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, - 2 => PosInterface::PAYMENT_STATUS_CANCELED, - 3 => PosInterface::PAYMENT_STATUS_PARTIALLY_REFUNDED, - 4 => PosInterface::PAYMENT_STATUS_FULLY_REFUNDED, - 5 => PosInterface::PAYMENT_STATUS_PRE_AUTH_COMPLETED, - ]; - - /** - * @param int $txType - * - * @return string - */ - public function mapTxType($txType): ?string - { - if (0 === $txType) { - return null; - } - - return parent::mapTxType((string) $txType); - } - /** * {@inheritDoc} */ @@ -116,7 +88,7 @@ public function map3DPayResponseData(array $raw3DAuthResponseData, string $txTyp $procReturnCode = $raw3DAuthResponseData['BankResponseCode']; $mdStatus = $this->extractMdStatus($raw3DAuthResponseData); - $transactionStatus = $this->orderStatusMappings[$raw3DAuthResponseData['RequestStatus']] ?? null; + $transactionStatus = $this->valueMapper->mapOrderStatus($raw3DAuthResponseData['RequestStatus']); if (self::PROCEDURE_SUCCESS_CODE === $procReturnCode && PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED === $transactionStatus && $this->is3dAuthSuccess($mdStatus) @@ -221,6 +193,7 @@ public function mapCancelResponse(array $rawResponseData): array */ public function mapStatusResponse(array $rawResponseData): array { + $txType = PosInterface::TX_TYPE_STATUS; $rawResponseData = $this->emptyStringsToNull($rawResponseData); $procReturnCode = $this->getProcReturnCode($rawResponseData); $errorCode = $rawResponseData['Code']; @@ -236,8 +209,8 @@ public function mapStatusResponse(array $rawResponseData): array $defaultResponse['auth_code'] = $rawResponseData['AuthCode']; $defaultResponse['transaction_id'] = $rawResponseData['TransactionId'] > 0 ? $rawResponseData['TransactionId'] : null; $defaultResponse['masked_number'] = $rawResponseData['CardNo']; - $defaultResponse['order_status'] = $this->orderStatusMappings[$rawResponseData['RequestStatus']] ?? $rawResponseData['RequestStatus']; - $defaultResponse['transaction_type'] = $this->mapTxType($rawResponseData['TransactionType']); + $defaultResponse['order_status'] = $this->valueMapper->mapOrderStatus($rawResponseData['RequestStatus']); + $defaultResponse['transaction_type'] = $this->valueMapper->mapTxType($rawResponseData['TransactionType']); $defaultResponse['status'] = $status; $defaultResponse['status_detail'] = $this->getStatusDetail($errorCode); @@ -250,17 +223,17 @@ public function mapStatusResponse(array $rawResponseData): array if (self::TX_APPROVED === $status) { $defaultResponse['installment_count'] = $rawResponseData['InstallmentCount']; if ($rawResponseData['Currency'] > 0) { - $defaultResponse['currency'] = $this->mapCurrency($rawResponseData['Currency']); + $defaultResponse['currency'] = $this->valueMapper->mapCurrency($rawResponseData['Currency'], $txType); // ex: 20231209154531 - $defaultResponse['transaction_time'] = new \DateTimeImmutable($rawResponseData['CreateDate']); - $defaultResponse['first_amount'] = $this->formatAmount($rawResponseData['Amount']); + $defaultResponse['transaction_time'] = $this->valueFormatter->formatDateTime($rawResponseData['CreateDate'], $txType); + $defaultResponse['first_amount'] = $this->valueFormatter->formatAmount($rawResponseData['Amount'], $txType); } - $defaultResponse['refund_amount'] = $rawResponseData['RefundedAmount'] > 0 ? $this->formatAmount($rawResponseData['RefundedAmount']) : null; + $defaultResponse['refund_amount'] = $rawResponseData['RefundedAmount'] > 0 ? $this->valueFormatter->formatAmount($rawResponseData['RefundedAmount'], $txType) : null; if (self::PROCEDURE_SUCCESS_CODE === $procReturnCode && $isPaymentTransaction) { $captureAmount = (float) $rawResponseData['MerchantCommissionAmount'] + (float) $rawResponseData['NetAmount']; - $defaultResponse['capture_amount'] = $this->formatAmount((string) $captureAmount); + $defaultResponse['capture_amount'] = $this->valueFormatter->formatAmount((string) $captureAmount, $txType); $defaultResponse['capture'] = $defaultResponse['first_amount'] <= $defaultResponse['capture_amount']; $defaultResponse['capture_time'] = $defaultResponse['transaction_time']; } @@ -371,17 +344,6 @@ protected function getProcReturnCode(array $response): ?string return $response['BankResponseCode'] ?? null; } - /** - * "100001" => 1000.01 - * @param string $amount - * - * @return float - */ - protected function formatAmount(string $amount): float - { - return ((float) $amount) / 100; - } - /** * @param array $rawResponseData * @@ -389,9 +351,10 @@ protected function formatAmount(string $amount): float */ public function mapSingleHistoryResponse(array $rawResponseData): array { - $procReturnCode = $this->getProcReturnCode($rawResponseData); - $errorCode = $rawResponseData['Code']; - $status = self::TX_DECLINED; + $txType = PosInterface::TX_TYPE_HISTORY; + $procReturnCode = $this->getProcReturnCode($rawResponseData); + $errorCode = $rawResponseData['Code']; + $status = self::TX_DECLINED; if (0 === $errorCode) { $status = self::TX_APPROVED; } @@ -403,8 +366,8 @@ public function mapSingleHistoryResponse(array $rawResponseData): array $defaultResponse['auth_code'] = $rawResponseData['AuthCode']; $defaultResponse['transaction_id'] = $rawResponseData['TransactionId'] > 0 ? $rawResponseData['TransactionId'] : null; $defaultResponse['masked_number'] = $rawResponseData['CardNo']; - $defaultResponse['order_status'] = $this->orderStatusMappings[$rawResponseData['RequestStatus']] ?? $rawResponseData['RequestStatus']; - $defaultResponse['transaction_type'] = $this->mapTxType($rawResponseData['TransactionType']); + $defaultResponse['order_status'] = $this->valueMapper->mapOrderStatus($rawResponseData['RequestStatus']); + $defaultResponse['transaction_type'] = $this->valueMapper->mapTxType($rawResponseData['TransactionType']); $defaultResponse['status'] = $status; $defaultResponse['status_detail'] = $this->getStatusDetail($errorCode); @@ -416,15 +379,15 @@ public function mapSingleHistoryResponse(array $rawResponseData): array if (self::TX_APPROVED === $status) { if ($rawResponseData['Currency'] > 0) { - $defaultResponse['currency'] = $this->mapCurrency($rawResponseData['Currency']); + $defaultResponse['currency'] = $this->valueMapper->mapCurrency($rawResponseData['Currency'], $txType); // ex: 20231209154531 - $defaultResponse['transaction_time'] = new \DateTimeImmutable($rawResponseData['CreateDate']); - $defaultResponse['first_amount'] = $this->formatAmount($rawResponseData['Amount']); + $defaultResponse['transaction_time'] = $this->valueFormatter->formatDateTime($rawResponseData['CreateDate'], $txType); + $defaultResponse['first_amount'] = $this->valueFormatter->formatAmount($rawResponseData['Amount'], $txType); } if (self::PROCEDURE_SUCCESS_CODE === $procReturnCode && $isPaymentTransaction) { $captureAmount = (float) $rawResponseData['MerchantCommissionAmount'] + (float) $rawResponseData['NetAmount']; - $defaultResponse['capture_amount'] = $this->formatAmount((string) $captureAmount); + $defaultResponse['capture_amount'] = $this->valueFormatter->formatAmount((string) $captureAmount, $txType); $defaultResponse['capture'] = $defaultResponse['first_amount'] <= $defaultResponse['capture_amount']; $defaultResponse['capture_time'] = $defaultResponse['transaction_time']; } diff --git a/src/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapper.php index cd114625..c00acee5 100644 --- a/src/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapper.php @@ -21,18 +21,6 @@ class VakifKatilimPosResponseDataMapper extends AbstractResponseDataMapper '51' => 'reject', ]; - /** - * Order Status Codes - * - * @var array - */ - protected array $orderStatusMappings = [ - 1 => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, - 4 => PosInterface::PAYMENT_STATUS_FULLY_REFUNDED, - 5 => PosInterface::PAYMENT_STATUS_PARTIALLY_REFUNDED, - 6 => PosInterface::PAYMENT_STATUS_CANCELED, - ]; - /** * {@inheritDoc} */ @@ -72,18 +60,18 @@ public function mapPaymentResponse(array $rawPaymentResponseData, string $txType $vPosMessage = $rawPaymentResponseData['VPosMessage']; // ProvisionNumber: Başarılı işlemlerde kart bankasının vermiş olduğu otorizasyon numarasıdır. - $result['auth_code'] = $rawPaymentResponseData['ProvisionNumber']; + $result['auth_code'] = $rawPaymentResponseData['ProvisionNumber']; // RRN: Pos bankası tarafında verilen referans işlem referans numarasıdır. $result['ref_ret_num'] = $rawPaymentResponseData['RRN']; $result['batch_num'] = $vPosMessage['BatchID']; // Stan: Pos bankası tarafında verilen referans işlem referans numarasıdır. $result['transaction_id'] = $rawPaymentResponseData['Stan']; $result['masked_number'] = $vPosMessage['CardNumber']; - $result['amount'] = $this->formatAmount($vPosMessage['Amount']); - $result['currency'] = $this->mapCurrency($vPosMessage['CurrencyCode']); - $result['installment_count'] = $this->mapInstallment($vPosMessage['InstallmentCount']); + $result['amount'] = $this->valueFormatter->formatAmount($vPosMessage['Amount'], $txType); + $result['currency'] = $this->valueMapper->mapCurrency($vPosMessage['CurrencyCode'], $txType); + $result['installment_count'] = $this->valueFormatter->formatInstallment($vPosMessage['InstallmentCount'], $txType); if ('0001-01-01T00:00:00' !== $rawPaymentResponseData['TransactionTime'] && '00010101T00:00:00' !== $rawPaymentResponseData['TransactionTime']) { - $result['transaction_time'] = new \DateTimeImmutable($rawPaymentResponseData['TransactionTime']); + $result['transaction_time'] = $this->valueFormatter->formatDateTime($rawPaymentResponseData['TransactionTime'], $txType); } else { $result['transaction_time'] = new \DateTimeImmutable(); } @@ -137,7 +125,7 @@ public function map3DPayResponseData(array $raw3DAuthResponseData, string $txTyp public function map3DHostResponseData(array $raw3DAuthResponseData, string $txType, array $order): array { $this->logger->debug('mapping 3D payment data', [ - '3d_auth_response' => $raw3DAuthResponseData, + '3d_auth_response' => $raw3DAuthResponseData, ]); $raw3DAuthResponseData = $this->emptyStringsToNull($raw3DAuthResponseData); @@ -363,17 +351,6 @@ public function extractMdStatus(array $raw3DAuthResponseData): ?string return $this->getProcReturnCode($raw3DAuthResponseData); } - /** - * "101" => 1.01 - * @param string $amount - * - * @return float - */ - protected function formatAmount(string $amount): float - { - return (float) $amount / 100; - } - /** * Get ProcReturnCode * @@ -386,19 +363,6 @@ protected function getProcReturnCode(array $response): ?string return $response['ResponseCode'] ?? null; } - /** - * @param string $currency currency code that is accepted by bank - * - * @return PosInterface::CURRENCY_*|string - */ - protected function mapCurrency(string $currency): string - { - // 949 => 0949; for the request gateway wants 0949 code, but in response they send 949 code. - $currencyNormalized = \str_pad($currency, 4, '0', STR_PAD_LEFT); - - return parent::mapCurrency($currencyNormalized); - } - /** * Get Status Detail Text * @@ -479,6 +443,7 @@ private function mapSingleHistoryTransaction(array $rawTx): array */ private function mapSingleOrderHistoryTransaction(array $rawTx): array { + $txType = PosInterface::TX_TYPE_ORDER_HISTORY; $procReturnCode = $this->getProcReturnCode($rawTx); $status = self::TX_DECLINED; if (self::PROCEDURE_SUCCESS_CODE === $procReturnCode) { @@ -492,19 +457,20 @@ private function mapSingleOrderHistoryTransaction(array $rawTx): array $defaultResponse['status_detail'] = $this->getStatusDetail($procReturnCode); $defaultResponse['error_code'] = self::TX_APPROVED === $status ? null : $procReturnCode; $defaultResponse['error_message'] = self::TX_APPROVED === $status ? null : $rawTx['ResponseExplain']; - $defaultResponse['currency'] = null !== $rawTx['FEC'] ? $this->mapCurrency($rawTx['FEC']) : null; - $defaultResponse['payment_model'] = null !== $rawTx['TransactionSecurity'] ? $this->mapSecurityType($rawTx['TransactionSecurity']) : null; + $defaultResponse['currency'] = null !== $rawTx['FEC'] ? $this->valueMapper->mapCurrency($rawTx['FEC'], $txType) : null; + $defaultResponse['payment_model'] = null !== $rawTx['TransactionSecurity'] ? $this->valueMapper->mapSecureType($rawTx['TransactionSecurity'], $txType) : null; $defaultResponse['ref_ret_num'] = $rawTx['RRN']; $defaultResponse['transaction_id'] = $rawTx['Stan']; - $defaultResponse['transaction_time'] = null !== $rawTx['OrderDate'] ? new \DateTimeImmutable($rawTx['OrderDate']) : null; + $defaultResponse['transaction_time'] = null !== $rawTx['OrderDate'] ? $this->valueFormatter->formatDateTime($rawTx['OrderDate'], $txType) : null; if (self::TX_APPROVED === $status) { $defaultResponse['auth_code'] = $rawTx['ProvNumber'] ?? null; - $defaultResponse['installment_count'] = $this->mapInstallment($rawTx['InstallmentCount']); + $defaultResponse['installment_count'] = $this->valueFormatter->formatInstallment($rawTx['InstallmentCount'], $txType); $defaultResponse['masked_number'] = $rawTx['CardNumber']; $defaultResponse['first_amount'] = (float) $rawTx['FirstAmount']; - $defaultResponse['order_status'] = $this->orderStatusMappings[$rawTx['LastOrderStatus']] ?? $rawTx['LastOrderStatusDescription']; - $initialOrderStatus = $this->orderStatusMappings[$rawTx['OrderStatus']] ?? null; + $rawLastOrderStatus = $rawTx['LastOrderStatus'] ?? $rawTx['LastOrderStatusDescription']; + $defaultResponse['order_status'] = null === $rawLastOrderStatus ? null : $this->valueMapper->mapOrderStatus($rawLastOrderStatus); + $initialOrderStatus = null === $rawTx['OrderStatus'] ? null : $this->valueMapper->mapOrderStatus($rawTx['OrderStatus']); if (PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED === $initialOrderStatus) { $defaultResponse['capture_amount'] = isset($rawTx['TranAmount']) ? (float) $rawTx['TranAmount'] : 0; @@ -572,11 +538,11 @@ private function map3DPaymentPaymentResponse(array $rawPaymentResponseData, stri $result['batch_num'] = $vPosMessage['BatchId']; $result['auth_code'] = $rawPaymentResponseData['ProvisionNumber'] ?? null; $result['masked_number'] = $vPosMessage['CardNumber'] ?? null; - $result['currency'] = isset($vPosMessage['CurrencyCode']) ? $this->mapCurrency($vPosMessage['CurrencyCode']) : $order['currency']; - $result['amount'] = $this->formatAmount($vPosMessage['Amount']); - $result['installment_count'] = $this->mapInstallment($vPosMessage['InstallmentCount']); + $result['currency'] = isset($vPosMessage['CurrencyCode']) ? $this->valueMapper->mapCurrency($vPosMessage['CurrencyCode'], $txType) : $order['currency']; + $result['amount'] = $this->valueFormatter->formatAmount($vPosMessage['Amount'], $txType); + $result['installment_count'] = $this->valueFormatter->formatInstallment($vPosMessage['InstallmentCount'], $txType); if ('0001-01-01T00:00:00' !== $rawPaymentResponseData['TransactionTime'] && '00010101T00:00:00' !== $rawPaymentResponseData['TransactionTime']) { - $result['transaction_time'] = new \DateTimeImmutable($rawPaymentResponseData['TransactionTime']); + $result['transaction_time'] = $this->valueFormatter->formatDateTime($rawPaymentResponseData['TransactionTime'], $txType); } else { $result['transaction_time'] = new \DateTimeImmutable(); } diff --git a/src/DataMapper/ResponseValueFormatter/AbstractResponseValueFormatter.php b/src/DataMapper/ResponseValueFormatter/AbstractResponseValueFormatter.php new file mode 100644 index 00000000..81d302b8 --- /dev/null +++ b/src/DataMapper/ResponseValueFormatter/AbstractResponseValueFormatter.php @@ -0,0 +1,34 @@ + 1 ? $inst : 0; + } + + /** + * @inheritDoc + */ + public function formatAmount($amount, string $txType): float + { + return (float) $amount; + } + + /** + * @inheritdoc + */ + public function formatDateTime(string $dateTime, string $txType): \DateTimeImmutable + { + return new \DateTimeImmutable($dateTime); + } +} diff --git a/src/DataMapper/ResponseValueFormatter/BasicResponseValueFormatter.php b/src/DataMapper/ResponseValueFormatter/BasicResponseValueFormatter.php new file mode 100644 index 00000000..3171323c --- /dev/null +++ b/src/DataMapper/ResponseValueFormatter/BasicResponseValueFormatter.php @@ -0,0 +1,9 @@ + 1.01 + * @inheritDoc + */ + public function formatAmount($amount, string $txType): float + { + return (float) $amount / 100; + } +} diff --git a/src/DataMapper/ResponseValueFormatter/EstPosResponseValueFormatter.php b/src/DataMapper/ResponseValueFormatter/EstPosResponseValueFormatter.php new file mode 100644 index 00000000..eeda04fe --- /dev/null +++ b/src/DataMapper/ResponseValueFormatter/EstPosResponseValueFormatter.php @@ -0,0 +1,22 @@ + 1000.01 + * @inheritDoc + */ + public function formatAmount($amount, string $txType): float + { + return ((float) $amount) / 100; + } +} diff --git a/src/DataMapper/ResponseValueFormatter/InterPosResponseValueFormatter.php b/src/DataMapper/ResponseValueFormatter/InterPosResponseValueFormatter.php new file mode 100644 index 00000000..0a705bb6 --- /dev/null +++ b/src/DataMapper/ResponseValueFormatter/InterPosResponseValueFormatter.php @@ -0,0 +1,28 @@ + 0.0 + * 1.056,2 => 1056.2 + * @inheritDoc + */ + public function formatAmount($amount, string $txType): float + { + return (float) \str_replace(',', '.', \str_replace('.', '', (string) $amount)); + } +} diff --git a/src/DataMapper/ResponseValueFormatter/PosNetResponseValueFormatter.php b/src/DataMapper/ResponseValueFormatter/PosNetResponseValueFormatter.php new file mode 100644 index 00000000..8365c0ff --- /dev/null +++ b/src/DataMapper/ResponseValueFormatter/PosNetResponseValueFormatter.php @@ -0,0 +1,26 @@ + 1.16 + return (float) \str_replace(',', '.', \str_replace('.', '', (string) $amount)); + } + + return ((int) $amount) / 100; + } +} diff --git a/src/DataMapper/ResponseValueFormatter/ResponseValueFormatterInterface.php b/src/DataMapper/ResponseValueFormatter/ResponseValueFormatterInterface.php new file mode 100644 index 00000000..2ec4c2de --- /dev/null +++ b/src/DataMapper/ResponseValueFormatter/ResponseValueFormatterInterface.php @@ -0,0 +1,40 @@ +|0 + */ + public function formatInstallment(?string $installment, string $txType): int; + + + /** + * formats purchase amount + * + * @param string|float $amount + * @param PosInterface::TX_TYPE_* $txType transaction type of the API request + * + * @return float + */ + public function formatAmount($amount, string $txType): float; + + /** + * @param string $dateTime + * @param PosInterface::TX_TYPE_* $txType transaction type of the API request + * + * @return \DateTimeImmutable formatted date time + */ + public function formatDateTime(string $dateTime, string $txType): \DateTimeImmutable; +} diff --git a/src/DataMapper/ResponseValueFormatter/ToslaPosResponseValueFormatter.php b/src/DataMapper/ResponseValueFormatter/ToslaPosResponseValueFormatter.php new file mode 100644 index 00000000..748e9407 --- /dev/null +++ b/src/DataMapper/ResponseValueFormatter/ToslaPosResponseValueFormatter.php @@ -0,0 +1,26 @@ + */ + protected array $currencyMappings = []; + + /** @var array> */ + protected array $txTypeMappings = []; + + /** @var array */ + protected array $secureTypeMappings = []; + + /** + * @var array + */ + protected array $orderStatusMappings = []; + + /** + * @param array $currencyMappings + * @param array> $txTypeMappings + * @param array $secureTypeMappings + */ + public function __construct( + array $currencyMappings, + array $txTypeMappings, + array $secureTypeMappings + ) + { + $this->currencyMappings = \array_flip($currencyMappings); + if ([] !== $txTypeMappings) { + $this->txTypeMappings = $txTypeMappings; + } + if ([] !== $secureTypeMappings) { + $this->secureTypeMappings = \array_flip($secureTypeMappings); + } + } + + /** + * @inheritDoc + */ + public function mapTxType($txType, ?string $paymentModel = null): ?string + { + if ([] === $this->txTypeMappings) { + throw new \LogicException('Transaction type mapping is not supported'); + } + + foreach ($this->txTypeMappings as $mappedTxType => $mapping) { + if (\is_array($mapping) && \in_array($txType, $mapping, true)) { + return $mappedTxType; + } + + if ($mapping === $txType) { + return $mappedTxType; + } + } + + return null; + } + + /** + * @inheritDoc + */ + public function mapSecureType(string $securityType, string $apiRequestTxType): ?string + { + if ([] === $this->secureTypeMappings) { + throw new \LogicException('Secure type mapping is not supported'); + } + + return $this->secureTypeMappings[$securityType] ?? null; + } + + /** + * @inheritDoc + */ + public function mapCurrency($currency, string $apiRequestTxType): ?string + { + return $this->currencyMappings[$currency] ?? null; + } + + /** + * @inheritDoc + */ + public function mapOrderStatus($orderStatus) + { + if ([] === $this->orderStatusMappings) { + throw new \LogicException('Order status mapping is not supported.'); + } + + return $this->orderStatusMappings[$orderStatus] ?? $orderStatus; + } +} diff --git a/src/DataMapper/ResponseValueMapper/AkbankPosResponseValueMapper.php b/src/DataMapper/ResponseValueMapper/AkbankPosResponseValueMapper.php new file mode 100644 index 00000000..0e4ef503 --- /dev/null +++ b/src/DataMapper/ResponseValueMapper/AkbankPosResponseValueMapper.php @@ -0,0 +1,63 @@ + + */ + protected array $orderStatusMappings = [ + 'N' => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, + 'S' => PosInterface::PAYMENT_STATUS_ERROR, + 'V' => PosInterface::PAYMENT_STATUS_CANCELED, + 'R' => PosInterface::PAYMENT_STATUS_FULLY_REFUNDED, + + // status that are return on history request + 'Başarılı' => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, + 'Başarısız' => PosInterface::PAYMENT_STATUS_ERROR, + 'İptal' => PosInterface::PAYMENT_STATUS_CANCELED, + ]; + + /** + * @var array + */ + private array $recurringOrderStatusMappings = [ + 'S' => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, + 'W' => PosInterface::PAYMENT_STATUS_PAYMENT_PENDING, + // when fulfilled payment is canceled + 'V' => PosInterface::PAYMENT_STATUS_CANCELED, + // when unfulfilled payment is canceled + 'C' => PosInterface::PAYMENT_STATUS_CANCELED, + ]; + + /** + * @inheritDoc + */ + public function mapOrderStatus($orderStatus, ?string $preAuthStatus = null, bool $isRecurringOrder = false) + { + if ($isRecurringOrder) { + return $this->recurringOrderStatusMappings[$orderStatus] ?? $orderStatus; + } + + $mappedOrderStatus = $this->orderStatusMappings[$orderStatus] ?? $orderStatus; + /** + * preAuthStatus + * "O": Açık + * "C": Kapalı + */ + if (PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED === $mappedOrderStatus && 'O' === $preAuthStatus) { + return PosInterface::PAYMENT_STATUS_PRE_AUTH_COMPLETED; + } + + return $mappedOrderStatus; + } +} diff --git a/src/DataMapper/ResponseValueMapper/BoaPosResponseValueMapper.php b/src/DataMapper/ResponseValueMapper/BoaPosResponseValueMapper.php new file mode 100644 index 00000000..22f711c2 --- /dev/null +++ b/src/DataMapper/ResponseValueMapper/BoaPosResponseValueMapper.php @@ -0,0 +1,37 @@ + PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, + 4 => PosInterface::PAYMENT_STATUS_FULLY_REFUNDED, + 5 => PosInterface::PAYMENT_STATUS_PARTIALLY_REFUNDED, + 6 => PosInterface::PAYMENT_STATUS_CANCELED, + ]; + + /** + * in '0949' or '949' formats + * @inheritDoc + */ + public function mapCurrency($currency, string $apiRequestTxType): ?string + { + // 949 => 0949; for the request gateway wants 0949 code, but in response they send 949 code. + $currencyNormalized = \str_pad((string) $currency, 4, '0', STR_PAD_LEFT); + + return parent::mapCurrency($currencyNormalized, $apiRequestTxType); + } +} diff --git a/src/DataMapper/ResponseValueMapper/EstPosResponseValueMapper.php b/src/DataMapper/ResponseValueMapper/EstPosResponseValueMapper.php new file mode 100644 index 00000000..df9f5a32 --- /dev/null +++ b/src/DataMapper/ResponseValueMapper/EstPosResponseValueMapper.php @@ -0,0 +1,54 @@ + + */ + private array $historyResponseTxTypeMappings = [ + /** + * S: Auth/PreAuth/PostAuth + * C: Refund + */ + 'S' => PosInterface::TX_TYPE_PAY_AUTH, + 'C' => PosInterface::TX_TYPE_REFUND, + ]; + + /** + * D : Başarısız işlem + * A : Otorizasyon, gün sonu kapanmadan + * C : Ön otorizasyon kapama, gün sonu kapanmadan + * PN : Bekleyen İşlem + * CNCL : İptal Edilmiş İşlem + * ERR : Hata Almış İşlem + * S : Satış + * R : Teknik İptal gerekiyor + * V : İptal + * @inheritdoc + */ + protected array $orderStatusMappings = [ + 'D' => PosInterface::PAYMENT_STATUS_ERROR, + 'ERR' => PosInterface::PAYMENT_STATUS_ERROR, + 'A' => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, + 'C' => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, + 'S' => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, + 'PN' => PosInterface::PAYMENT_STATUS_PAYMENT_PENDING, + 'CNCL' => PosInterface::PAYMENT_STATUS_CANCELED, + 'V' => PosInterface::PAYMENT_STATUS_CANCELED, + ]; + + /** + * @inheritDoc + */ + public function mapTxType($txType, ?string $paymentModel = null): ?string + { + return $this->historyResponseTxTypeMappings[$txType] ?? null; + } +} diff --git a/src/DataMapper/ResponseValueMapper/GarantiPosResponseValueMapper.php b/src/DataMapper/ResponseValueMapper/GarantiPosResponseValueMapper.php new file mode 100644 index 00000000..8525a1de --- /dev/null +++ b/src/DataMapper/ResponseValueMapper/GarantiPosResponseValueMapper.php @@ -0,0 +1,151 @@ + + */ + private array $historyResponseCurrencyMapping = [ + 'TL' => PosInterface::CURRENCY_TRY, + 'USD' => PosInterface::CURRENCY_USD, + 'EUR' => PosInterface::CURRENCY_EUR, + 'RUB' => PosInterface::CURRENCY_RUB, + 'JPY' => PosInterface::CURRENCY_JPY, + 'GBP' => PosInterface::CURRENCY_GBP, + ]; + + /** + * @var array + */ + private array $historyResponseTxTypes = [ + 'Satis' => PosInterface::TX_TYPE_PAY_AUTH, + 'On Otorizasyon' => PosInterface::TX_TYPE_PAY_PRE_AUTH, + 'On Otorizasyon Kapama' => PosInterface::TX_TYPE_PAY_POST_AUTH, + 'Iade' => PosInterface::TX_TYPE_REFUND, + 'Iptal' => PosInterface::TX_TYPE_CANCEL, + // ... Odul Sorgulama + ]; + + /** + * @inheritDoc + */ + public function mapTxType($txType, ?string $paymentModel = null): ?string + { + return $this->historyResponseTxTypes[$txType] ?? parent::mapTxType($txType, $paymentModel); + } + + /** + * @inheritDoc + */ + public function mapSecureType(string $securityType, string $apiRequestTxType): ?string + { + if (PosInterface::TX_TYPE_HISTORY === $apiRequestTxType) { + // mappings for the field SafeType of history response + // 3D Secure => 3D + // 3D Pay => 3D + // NonSecure => '' + if ('3D' === $securityType) { + return PosInterface::MODEL_3D_SECURE; + } + + if ('' === $securityType) { + return PosInterface::MODEL_NON_SECURE; + } + + return null; + } + + return parent::mapSecureType($securityType, $apiRequestTxType); + } + + /** + * @inheritDoc + */ + public function mapCurrency($currency, string $apiRequestTxType): ?string + { + if (PosInterface::TX_TYPE_HISTORY === $apiRequestTxType) { + return $this->historyResponseCurrencyMapping[$currency] ?? null; + } + + return parent::mapCurrency($currency, $apiRequestTxType); + } + + /** + * @param PosInterface::TX_TYPE_*|null $requestTxType request transaction type + * @param PosInterface::TX_TYPE_*|null $txType txType of the transaction that is being processed + * + * @inheritDoc + */ + public function mapOrderStatus($orderStatus, string $requestTxType = null, string $txType = null) + { + if (PosInterface::TX_TYPE_STATUS === $requestTxType) { + // todo ChargeType degere gore belki daha duzgun mapping edebiliriz. + // ChargeType hakkinda dokumantasyonda sadece su bilgi var: + // "İşlem tipinin gösterildiği alandır." + // Alabilicegi degerleri hakkinda bir bilgi bulunmamakta. + if ('WAITINGPOSTAUTH' === $orderStatus) { + return PosInterface::PAYMENT_STATUS_PRE_AUTH_COMPLETED; + } + if ('APPROVED' === $orderStatus) { + // how can we map this status? + return $orderStatus; + } + + return $orderStatus; + } + + if (PosInterface::TX_TYPE_HISTORY === $requestTxType) { + if (null === $txType) { + return $orderStatus; + } + + // $orderStatus possible values: + // Basarili + // Basarisiz + // Iptal + // Onaylandi + + if ('Basarili' === $orderStatus || 'Onaylandi' === $orderStatus) { + if (PosInterface::TX_TYPE_CANCEL === $txType) { + return PosInterface::PAYMENT_STATUS_CANCELED; + } + + if (PosInterface::TX_TYPE_REFUND === $txType) { + // todo how can we decide if order is partially or fully refunded? + return PosInterface::PAYMENT_STATUS_FULLY_REFUNDED; + } + + if (PosInterface::TX_TYPE_PAY_AUTH === $txType || PosInterface::TX_TYPE_PAY_POST_AUTH === $txType) { + return PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED; + } + + if (PosInterface::TX_TYPE_PAY_PRE_AUTH === $txType) { + return PosInterface::PAYMENT_STATUS_PRE_AUTH_COMPLETED; + } + + return $orderStatus; + } + + if ('Iptal' === $orderStatus) { + /** + * todo anlasilmayan durumlar: + * - "Status" => "Iptal", "TrxType" => "Satis" + * - "Status" => "Iptal", "TrxType" => "On Otorizasyon" + * - "Status" => "Iptal", "TrxType" => "Iptal" + * - "Status" => "Iptal", "TrxType" => "Iade" + */ + return $orderStatus; + } + + return PosInterface::PAYMENT_STATUS_ERROR; + } + + return $orderStatus; + } +} diff --git a/src/DataMapper/ResponseValueMapper/InterPosResponseValueMapper.php b/src/DataMapper/ResponseValueMapper/InterPosResponseValueMapper.php new file mode 100644 index 00000000..ff7f275d --- /dev/null +++ b/src/DataMapper/ResponseValueMapper/InterPosResponseValueMapper.php @@ -0,0 +1,9 @@ + PosInterface::MODEL_NON_SECURE, + '2' => PosInterface::MODEL_3D_SECURE, + '3' => PosInterface::MODEL_3D_PAY, + ]; +} diff --git a/src/DataMapper/ResponseValueMapper/PayForPosResponseValueMapper.php b/src/DataMapper/ResponseValueMapper/PayForPosResponseValueMapper.php new file mode 100644 index 00000000..375e868e --- /dev/null +++ b/src/DataMapper/ResponseValueMapper/PayForPosResponseValueMapper.php @@ -0,0 +1,10 @@ + + */ + private array $orderStatusCurrencyMappings = [ + '949' => PosInterface::CURRENCY_TRY, + '840' => PosInterface::CURRENCY_USD, + '978' => PosInterface::CURRENCY_EUR, + '826' => PosInterface::CURRENCY_GBP, + '392' => PosInterface::CURRENCY_JPY, + '643' => PosInterface::CURRENCY_RUB, + ]; + + /** + * @inheritDoc + */ + protected array $orderStatusMappings = [ + PosInterface::TX_TYPE_PAY_AUTH => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, + PosInterface::TX_TYPE_CANCEL => PosInterface::PAYMENT_STATUS_CANCELED, + PosInterface::TX_TYPE_REFUND => PosInterface::PAYMENT_STATUS_FULLY_REFUNDED, + ]; + + /** + * @inheritDoc + */ + public function mapCurrency($currency, string $apiRequestTxType): ?string + { + if (PosInterface::TX_TYPE_STATUS !== $apiRequestTxType) { + return $this->orderStatusCurrencyMappings[$currency] ?? null; + } + + return parent::mapCurrency($currency, $apiRequestTxType); + } +} diff --git a/src/DataMapper/ResponseValueMapper/ResponseValueMapperInterface.php b/src/DataMapper/ResponseValueMapper/ResponseValueMapperInterface.php new file mode 100644 index 00000000..9a6885a2 --- /dev/null +++ b/src/DataMapper/ResponseValueMapper/ResponseValueMapperInterface.php @@ -0,0 +1,46 @@ + PosInterface::PAYMENT_STATUS_ERROR, + 1 => PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED, + 2 => PosInterface::PAYMENT_STATUS_CANCELED, + 3 => PosInterface::PAYMENT_STATUS_PARTIALLY_REFUNDED, + 4 => PosInterface::PAYMENT_STATUS_FULLY_REFUNDED, + 5 => PosInterface::PAYMENT_STATUS_PRE_AUTH_COMPLETED, + ]; + + /** + * @inheritDoc + */ + public function mapTxType($txType, ?string $paymentModel = null): ?string + { + if (0 === $txType) { + return null; + } + + return parent::mapTxType((string) $txType); + } +} diff --git a/src/Factory/PosFactory.php b/src/Factory/PosFactory.php index f2bf34d6..e60ef4df 100644 --- a/src/Factory/PosFactory.php +++ b/src/Factory/PosFactory.php @@ -69,24 +69,27 @@ public static function createPosGateway( $logger->debug('creating gateway for bank', ['bank' => $posAccount->getBank()]); - $crypt = CryptFactory::createGatewayCrypt($class, $logger); - $valueMapper = RequestValueMapperFactory::createForGateway($class); - $valueFormatter = RequestValueFormatterFactory::createForGateway($class); - $requestDataMapper = RequestDataMapperFactory::createGatewayRequestMapper( + $crypt = CryptFactory::createGatewayCrypt($class, $logger); + $requestValueMapper = RequestValueMapperFactory::createForGateway($class); + $requestValueFormatter = RequestValueFormatterFactory::createForGateway($class); + $requestDataMapper = RequestDataMapperFactory::createGatewayRequestMapper( $class, - $valueMapper, - $valueFormatter, + $requestValueMapper, + $requestValueFormatter, $eventDispatcher, $crypt, ); - $responseDataMapper = ResponseDataMapperFactory::createGatewayResponseMapper($class, $valueMapper, $logger); - $serializer = SerializerFactory::createGatewaySerializer($class); + + $responseValueFormatter = ResponseValueFormatterFactory::createForGateway($class); + $responseValueMapper = ResponseValueMapperFactory::createForGateway($class, $requestValueMapper); + $responseDataMapper = ResponseDataMapperFactory::createGatewayResponseMapper($class, $responseValueFormatter, $responseValueMapper, $logger); + $serializer = SerializerFactory::createGatewaySerializer($class); // Create Bank Class Instance return new $class( $config['banks'][$posAccount->getBank()], $posAccount, - $valueMapper, + $requestValueMapper, $requestDataMapper, $responseDataMapper, $serializer, diff --git a/src/Factory/ResponseDataMapperFactory.php b/src/Factory/ResponseDataMapperFactory.php index fe7699cf..58fa5d40 100644 --- a/src/Factory/ResponseDataMapperFactory.php +++ b/src/Factory/ResponseDataMapperFactory.php @@ -6,7 +6,6 @@ namespace Mews\Pos\Factory; use DomainException; -use Mews\Pos\DataMapper\RequestValueMapper\RequestValueMapperInterface; use Mews\Pos\DataMapper\ResponseDataMapper\AkbankPosResponseDataMapper; use Mews\Pos\DataMapper\ResponseDataMapper\EstPosResponseDataMapper; use Mews\Pos\DataMapper\ResponseDataMapper\GarantiPosResponseDataMapper; @@ -20,6 +19,8 @@ use Mews\Pos\DataMapper\ResponseDataMapper\ResponseDataMapperInterface; use Mews\Pos\DataMapper\ResponseDataMapper\ToslaPosResponseDataMapper; use Mews\Pos\DataMapper\ResponseDataMapper\VakifKatilimPosResponseDataMapper; +use Mews\Pos\DataMapper\ResponseValueFormatter\ResponseValueFormatterInterface; +use Mews\Pos\DataMapper\ResponseValueMapper\ResponseValueMapperInterface; use Mews\Pos\Gateways\AkbankPos; use Mews\Pos\Gateways\EstPos; use Mews\Pos\Gateways\EstV3Pos; @@ -41,16 +42,18 @@ class ResponseDataMapperFactory { /** - * @param class-string $gatewayClass - * @param RequestValueMapperInterface $valueMapper - * @param LoggerInterface $logger + * @param class-string $gatewayClass + * @param ResponseValueFormatterInterface $valueFormatter + * @param ResponseValueMapperInterface $valueMapper + * @param LoggerInterface $logger * * @return ResponseDataMapperInterface */ public static function createGatewayResponseMapper( - string $gatewayClass, - RequestValueMapperInterface $valueMapper, - LoggerInterface $logger + string $gatewayClass, + ResponseValueFormatterInterface $valueFormatter, + ResponseValueMapperInterface $valueMapper, + LoggerInterface $logger ): ResponseDataMapperInterface { $classMappings = [ @@ -71,9 +74,8 @@ public static function createGatewayResponseMapper( if (isset($classMappings[$gatewayClass])) { return new $classMappings[$gatewayClass]( - $valueMapper->getCurrencyMappings(), - $valueMapper->getTxTypeMappings(), - $valueMapper->getSecureTypeMappings(), + $valueFormatter, + $valueMapper, $logger ); } diff --git a/src/Factory/ResponseValueFormatterFactory.php b/src/Factory/ResponseValueFormatterFactory.php new file mode 100644 index 00000000..aeea1068 --- /dev/null +++ b/src/Factory/ResponseValueFormatterFactory.php @@ -0,0 +1,64 @@ + BasicResponseValueFormatter::class, + EstPos::class => EstPosResponseValueFormatter::class, + EstV3Pos::class => EstPosResponseValueFormatter::class, + GarantiPos::class => GarantiPosResponseValueFormatter::class, + InterPos::class => InterPosResponseValueFormatter::class, + KuveytPos::class => BoaPosResponseValueFormatter::class, + PayFlexCPV4Pos::class => BasicResponseValueFormatter::class, + PayFlexV4Pos::class => BasicResponseValueFormatter::class, + PayForPos::class => BasicResponseValueFormatter::class, + PosNet::class => PosNetResponseValueFormatter::class, + PosNetV1Pos::class => PosNetResponseValueFormatter::class, + ToslaPos::class => ToslaPosResponseValueFormatter::class, + VakifKatilimPos::class => BoaPosResponseValueFormatter::class, + ]; + + if (isset($classMappings[$gatewayClass])) { + return new $classMappings[$gatewayClass](); + } + + throw new DomainException('unsupported gateway'); + } +} diff --git a/src/Factory/ResponseValueMapperFactory.php b/src/Factory/ResponseValueMapperFactory.php new file mode 100644 index 00000000..beec1e66 --- /dev/null +++ b/src/Factory/ResponseValueMapperFactory.php @@ -0,0 +1,101 @@ + AkbankPosResponseValueMapper::class, + EstPos::class => EstPosResponseValueMapper::class, + EstV3Pos::class => EstPosResponseValueMapper::class, + GarantiPos::class => GarantiPosResponseValueMapper::class, + InterPos::class => InterPosResponseValueMapper::class, + KuveytPos::class => BoaPosResponseValueMapper::class, + PayFlexCPV4Pos::class => PayFlexCPV4PosResponseValueMapper::class, + PayFlexV4Pos::class => PayFlexV4PosResponseValueMapper::class, + PayForPos::class => PayForPosResponseValueMapper::class, + PosNet::class => PosNetResponseValueMapper::class, + PosNetV1Pos::class => PosNetV1PosResponseValueMapper::class, + ToslaPos::class => ToslaPosResponseValueMapper::class, + VakifKatilimPos::class => BoaPosResponseValueMapper::class, + ]; + + if (!isset($classMappings[$gatewayClass])) { + throw new DomainException('unsupported gateway'); + } + + $secureTypeMappings = []; + $txTypeMappings = []; + + if (\in_array($classMappings[$gatewayClass], [ + AkbankPosResponseValueMapper::class, + GarantiPosResponseValueMapper::class, + BoaPosResponseValueMapper::class, + PayFlexCPV4PosResponseValueMapper::class, + PayFlexV4PosResponseValueMapper::class, + PayForPosResponseValueMapper::class, + PosNetResponseValueMapper::class, + PosNetV1PosResponseValueMapper::class, + ToslaPosResponseValueMapper::class, + ])) { + $txTypeMappings = $requestValueMapper->getTxTypeMappings(); + } + + if (\in_array($classMappings[$gatewayClass], [ + EstPosResponseValueMapper::class, + GarantiPosResponseValueMapper::class, + BoaPosResponseValueMapper::class, + PayForPosResponseValueMapper::class, + ], true)) { + $secureTypeMappings = $requestValueMapper->getSecureTypeMappings(); + } + + + return new $classMappings[$gatewayClass]( + $requestValueMapper->getCurrencyMappings(), + $txTypeMappings, + $secureTypeMappings, + ); + } +} diff --git a/tests/Unit/DataMapper/RequestValueMapper/KuveytPosRequestValueMapperTest.php b/tests/Unit/DataMapper/RequestValueMapper/KuveytPosRequestValueMapperTest.php index 304a959f..437c6fbd 100644 --- a/tests/Unit/DataMapper/RequestValueMapper/KuveytPosRequestValueMapperTest.php +++ b/tests/Unit/DataMapper/RequestValueMapper/KuveytPosRequestValueMapperTest.php @@ -84,7 +84,7 @@ public function testGetRecurringOrderFrequencyMappings(): void public function testGetCurrencyMappings(): void { - $this->assertCount(6, $this->valueMapper->getCurrencyMappings()); + $this->assertCount(3, $this->valueMapper->getCurrencyMappings()); } public function testGetTxTypeMappings(): void diff --git a/tests/Unit/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapperTest.php index a15a960d..76f78902 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapperTest.php @@ -7,6 +7,8 @@ use Mews\Pos\DataMapper\RequestValueMapper\AkbankPosRequestValueMapper; use Mews\Pos\DataMapper\ResponseDataMapper\AkbankPosResponseDataMapper; +use Mews\Pos\DataMapper\ResponseValueFormatter\BasicResponseValueFormatter; +use Mews\Pos\DataMapper\ResponseValueMapper\AkbankPosResponseValueMapper; use Mews\Pos\PosInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -29,12 +31,17 @@ protected function setUp(): void $this->logger = $this->createMock(LoggerInterface::class); - $requestValueMapper = new AkbankPosRequestValueMapper(); - - $this->responseDataMapper = new AkbankPosResponseDataMapper( + $requestValueMapper = new AkbankPosRequestValueMapper(); + $responseValueFormatter = new BasicResponseValueFormatter(); + $responseValueMapper = new AkbankPosResponseValueMapper( $requestValueMapper->getCurrencyMappings(), $requestValueMapper->getTxTypeMappings(), - $requestValueMapper->getSecureTypeMappings(), + $requestValueMapper->getSecureTypeMappings() + ); + + $this->responseDataMapper = new AkbankPosResponseDataMapper( + $responseValueFormatter, + $responseValueMapper, $this->logger ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php index e4b6c8e3..8fa1a57c 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/EstPosResponseDataMapperTest.php @@ -7,6 +7,8 @@ use Mews\Pos\DataMapper\RequestValueMapper\EstPosRequestValueMapper; use Mews\Pos\DataMapper\ResponseDataMapper\EstPosResponseDataMapper; +use Mews\Pos\DataMapper\ResponseValueFormatter\EstPosResponseValueFormatter; +use Mews\Pos\DataMapper\ResponseValueMapper\EstPosResponseValueMapper; use Mews\Pos\Exceptions\NotImplementedException; use Mews\Pos\PosInterface; use PHPUnit\Framework\MockObject\MockObject; @@ -30,12 +32,17 @@ protected function setUp(): void $this->logger = $this->createMock(LoggerInterface::class); - $requestValueMapper = new EstPosRequestValueMapper(); - - $this->responseDataMapper = new EstPosResponseDataMapper( + $requestValueMapper = new EstPosRequestValueMapper(); + $responseValueFormatter = new EstPosResponseValueFormatter(); + $responseValueMapper = new EstPosResponseValueMapper( $requestValueMapper->getCurrencyMappings(), $requestValueMapper->getTxTypeMappings(), - $requestValueMapper->getSecureTypeMappings(), + $requestValueMapper->getSecureTypeMappings() + ); + + $this->responseDataMapper = new EstPosResponseDataMapper( + $responseValueFormatter, + $responseValueMapper, $this->logger ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php index 717a0e66..c97775f7 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapperTest.php @@ -7,6 +7,8 @@ use Mews\Pos\DataMapper\RequestValueMapper\GarantiPosRequestValueMapper; use Mews\Pos\DataMapper\ResponseDataMapper\GarantiPosResponseDataMapper; +use Mews\Pos\DataMapper\ResponseValueFormatter\GarantiPosResponseValueFormatter; +use Mews\Pos\DataMapper\ResponseValueMapper\GarantiPosResponseValueMapper; use Mews\Pos\Exceptions\NotImplementedException; use Mews\Pos\PosInterface; use PHPUnit\Framework\MockObject\MockObject; @@ -30,12 +32,17 @@ protected function setUp(): void $this->logger = $this->createMock(LoggerInterface::class); - $requestValueMapper = new GarantiPosRequestValueMapper(); - - $this->responseDataMapper = new GarantiPosResponseDataMapper( + $requestValueMapper = new GarantiPosRequestValueMapper(); + $responseValueFormatter = new GarantiPosResponseValueFormatter(); + $responseValueMapper = new GarantiPosResponseValueMapper( $requestValueMapper->getCurrencyMappings(), $requestValueMapper->getTxTypeMappings(), - $requestValueMapper->getSecureTypeMappings(), + $requestValueMapper->getSecureTypeMappings() + ); + + $this->responseDataMapper = new GarantiPosResponseDataMapper( + $responseValueFormatter, + $responseValueMapper, $this->logger ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php index 62befe5b..c49e0370 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/InterPosResponseDataMapperTest.php @@ -7,6 +7,8 @@ use Mews\Pos\DataMapper\RequestValueMapper\InterPosRequestValueMapper; use Mews\Pos\DataMapper\ResponseDataMapper\InterPosResponseDataMapper; +use Mews\Pos\DataMapper\ResponseValueFormatter\InterPosResponseValueFormatter; +use Mews\Pos\DataMapper\ResponseValueMapper\InterPosResponseValueMapper; use Mews\Pos\Exceptions\NotImplementedException; use Mews\Pos\PosInterface; use PHPUnit\Framework\MockObject\MockObject; @@ -31,11 +33,16 @@ protected function setUp(): void $this->logger = $this->createMock(LoggerInterface::class); $requestValueMapper = new InterPosRequestValueMapper(); - - $this->responseDataMapper = new InterPosResponseDataMapper( + $responseValueFormatter = new InterPosResponseValueFormatter(); + $responseValueMapper = new InterPosResponseValueMapper( $requestValueMapper->getCurrencyMappings(), $requestValueMapper->getTxTypeMappings(), - $requestValueMapper->getSecureTypeMappings(), + $requestValueMapper->getSecureTypeMappings() + ); + + $this->responseDataMapper = new InterPosResponseDataMapper( + $responseValueFormatter, + $responseValueMapper, $this->logger ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapperTest.php index 9e838b29..c6a117b6 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/KuveytPosResponseDataMapperTest.php @@ -5,9 +5,12 @@ namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper; -use Mews\Pos\DataMapper\RequestValueMapper\KuveytPosRequestValueMapper; use Mews\Pos\DataMapper\ResponseDataMapper\KuveytPosResponseDataMapper; use Mews\Pos\Exceptions\NotImplementedException; +use Mews\Pos\Factory\RequestValueMapperFactory; +use Mews\Pos\Factory\ResponseValueFormatterFactory; +use Mews\Pos\Factory\ResponseValueMapperFactory; +use Mews\Pos\Gateways\KuveytPos; use Mews\Pos\PosInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -30,12 +33,13 @@ protected function setUp(): void $this->logger = $this->createMock(LoggerInterface::class); - $requestValueMapper = new KuveytPosRequestValueMapper(); + $requestValueMapper = RequestValueMapperFactory::createForGateway(KuveytPos::class); + $responseValueMapper = ResponseValueMapperFactory::createForGateway(KuveytPos::class, $requestValueMapper); + $responseValueFormatter = ResponseValueFormatterFactory::createForGateway(KuveytPos::class); $this->responseDataMapper = new KuveytPosResponseDataMapper( - $requestValueMapper->getCurrencyMappings(), - $requestValueMapper->getTxTypeMappings(), - $requestValueMapper->getSecureTypeMappings(), + $responseValueFormatter, + $responseValueMapper, $this->logger ); } @@ -65,18 +69,6 @@ public function testExtractMdStatus(array $responseData, ?string $expected): voi $this->assertSame($expected, $actual); } - /** - * @return void - */ - public function testFormatAmount(): void - { - $class = new \ReflectionObject($this->responseDataMapper); - $method = $class->getMethod('formatAmount'); - $method->setAccessible(true); - $this->assertSame(0.1, $method->invokeArgs($this->responseDataMapper, [10])); - $this->assertSame(1.01, $method->invokeArgs($this->responseDataMapper, [101])); - } - /** * @dataProvider paymentTestDataProvider */ diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexCPV4PosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexCPV4PosResponseDataMapperTest.php index 9a6fb46b..9dd70f83 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexCPV4PosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexCPV4PosResponseDataMapperTest.php @@ -8,6 +8,8 @@ use Generator; use Mews\Pos\DataMapper\RequestValueMapper\PayFlexCPV4PosRequestValueMapper; use Mews\Pos\DataMapper\ResponseDataMapper\PayFlexCPV4PosResponseDataMapper; +use Mews\Pos\DataMapper\ResponseValueFormatter\BasicResponseValueFormatter; +use Mews\Pos\DataMapper\ResponseValueMapper\PayFlexCPV4PosResponseValueMapper; use Mews\Pos\PosInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -30,12 +32,17 @@ protected function setUp(): void $this->logger = $this->createMock(LoggerInterface::class); - $requestValueMapper = new PayFlexCPV4PosRequestValueMapper(); - - $this->responseDataMapper = new PayFlexCPV4PosResponseDataMapper( + $requestValueMapper = new PayFlexCPV4PosRequestValueMapper(); + $responseValueFormatter = new BasicResponseValueFormatter(); + $responseValueMapper = new PayFlexCPV4PosResponseValueMapper( $requestValueMapper->getCurrencyMappings(), $requestValueMapper->getTxTypeMappings(), - $requestValueMapper->getSecureTypeMappings(), + $requestValueMapper->getSecureTypeMappings() + ); + + $this->responseDataMapper = new PayFlexCPV4PosResponseDataMapper( + $responseValueFormatter, + $responseValueMapper, $this->logger ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php index e344abc9..893a6daf 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/PayFlexV4PosResponseDataMapperTest.php @@ -7,6 +7,8 @@ use Mews\Pos\DataMapper\RequestValueMapper\PayFlexV4PosRequestValueMapper; use Mews\Pos\DataMapper\ResponseDataMapper\PayFlexV4PosResponseDataMapper; +use Mews\Pos\DataMapper\ResponseValueFormatter\BasicResponseValueFormatter; +use Mews\Pos\DataMapper\ResponseValueMapper\PayFlexV4PosResponseValueMapper; use Mews\Pos\Exceptions\NotImplementedException; use Mews\Pos\PosInterface; use PHPUnit\Framework\MockObject\MockObject; @@ -30,12 +32,17 @@ protected function setUp(): void $this->logger = $this->createMock(LoggerInterface::class); - $requestValueMapper = new PayFlexV4PosRequestValueMapper(); - - $this->responseDataMapper = new PayFlexV4PosResponseDataMapper( + $requestValueMapper = new PayFlexV4PosRequestValueMapper(); + $responseValueFormatter = new BasicResponseValueFormatter(); + $responseValueMapper = new PayFlexV4PosResponseValueMapper( $requestValueMapper->getCurrencyMappings(), $requestValueMapper->getTxTypeMappings(), - $requestValueMapper->getSecureTypeMappings(), + $requestValueMapper->getSecureTypeMappings() + ); + + $this->responseDataMapper = new PayFlexV4PosResponseDataMapper( + $responseValueFormatter, + $responseValueMapper, $this->logger ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php index e7d9d04a..3a5d5119 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/PayForPosResponseDataMapperTest.php @@ -7,6 +7,8 @@ use Mews\Pos\DataMapper\RequestValueMapper\PayForPosRequestValueMapper; use Mews\Pos\DataMapper\ResponseDataMapper\PayForPosResponseDataMapper; +use Mews\Pos\DataMapper\ResponseValueFormatter\BasicResponseValueFormatter; +use Mews\Pos\DataMapper\ResponseValueMapper\PayForPosResponseValueMapper; use Mews\Pos\PosInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -28,12 +30,17 @@ protected function setUp(): void parent::setUp(); $this->logger = $this->createMock(LoggerInterface::class); - $requestValueMapper = new PayForPosRequestValueMapper(); - - $this->responseDataMapper = new PayForPosResponseDataMapper( + $requestValueMapper = new PayForPosRequestValueMapper(); + $responseValueFormatter = new BasicResponseValueFormatter(); + $responseValueMapper = new PayForPosResponseValueMapper( $requestValueMapper->getCurrencyMappings(), $requestValueMapper->getTxTypeMappings(), - $requestValueMapper->getSecureTypeMappings(), + $requestValueMapper->getSecureTypeMappings() + ); + + $this->responseDataMapper = new PayForPosResponseDataMapper( + $responseValueFormatter, + $responseValueMapper, $this->logger ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PosNetResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PosNetResponseDataMapperTest.php index 7d37a9b7..7dcd22b3 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/PosNetResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/PosNetResponseDataMapperTest.php @@ -7,6 +7,8 @@ use Mews\Pos\DataMapper\RequestValueMapper\PosNetRequestValueMapper; use Mews\Pos\DataMapper\ResponseDataMapper\PosNetResponseDataMapper; +use Mews\Pos\DataMapper\ResponseValueFormatter\PosNetResponseValueFormatter; +use Mews\Pos\DataMapper\ResponseValueMapper\PosNetResponseValueMapper; use Mews\Pos\Exceptions\NotImplementedException; use Mews\Pos\PosInterface; use PHPUnit\Framework\MockObject\MockObject; @@ -29,12 +31,17 @@ protected function setUp(): void parent::setUp(); $this->logger = $this->createMock(LoggerInterface::class); - $requestValueMapper = new PosNetRequestValueMapper(); - - $this->responseDataMapper = new PosNetResponseDataMapper( + $requestValueMapper = new PosNetRequestValueMapper(); + $responseValueFormatter = new PosNetResponseValueFormatter(); + $responseValueMapper = new PosNetResponseValueMapper( $requestValueMapper->getCurrencyMappings(), $requestValueMapper->getTxTypeMappings(), - $requestValueMapper->getSecureTypeMappings(), + $requestValueMapper->getSecureTypeMappings() + ); + + $this->responseDataMapper = new PosNetResponseDataMapper( + $responseValueFormatter, + $responseValueMapper, $this->logger ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapperTest.php index 5976f1f8..a3e01689 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/PosNetV1PosResponseDataMapperTest.php @@ -7,6 +7,8 @@ use Mews\Pos\DataMapper\RequestValueMapper\PosNetV1PosRequestValueMapper; use Mews\Pos\DataMapper\ResponseDataMapper\PosNetV1PosResponseDataMapper; +use Mews\Pos\DataMapper\ResponseValueFormatter\PosNetResponseValueFormatter; +use Mews\Pos\DataMapper\ResponseValueMapper\PosNetV1PosResponseValueMapper; use Mews\Pos\Exceptions\NotImplementedException; use Mews\Pos\PosInterface; use PHPUnit\Framework\MockObject\MockObject; @@ -31,12 +33,17 @@ protected function setUp(): void $this->logger = $this->createMock(LoggerInterface::class); - $requestValueMapper = new PosNetV1PosRequestValueMapper(); - - $this->responseDataMapper = new PosNetV1PosResponseDataMapper( + $requestValueMapper = new PosNetV1PosRequestValueMapper(); + $responseValueFormatter = new PosNetResponseValueFormatter(); + $responseValueMapper = new PosNetV1PosResponseValueMapper( $requestValueMapper->getCurrencyMappings(), $requestValueMapper->getTxTypeMappings(), - $requestValueMapper->getSecureTypeMappings(), + $requestValueMapper->getSecureTypeMappings() + ); + + $this->responseDataMapper = new PosNetV1PosResponseDataMapper( + $responseValueFormatter, + $responseValueMapper, $this->logger ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapperTest.php index 3780a472..90fed074 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapperTest.php @@ -7,6 +7,8 @@ use Mews\Pos\DataMapper\RequestValueMapper\ToslaPosRequestValueMapper; use Mews\Pos\DataMapper\ResponseDataMapper\ToslaPosResponseDataMapper; +use Mews\Pos\DataMapper\ResponseValueFormatter\ToslaPosResponseValueFormatter; +use Mews\Pos\DataMapper\ResponseValueMapper\ToslaPosResponseValueMapper; use Mews\Pos\Exceptions\NotImplementedException; use Mews\Pos\PosInterface; use PHPUnit\Framework\MockObject\MockObject; @@ -30,12 +32,17 @@ protected function setUp(): void $this->logger = $this->createMock(LoggerInterface::class); - $requestValueMapper = new ToslaPosRequestValueMapper(); - - $this->responseDataMapper = new ToslaPosResponseDataMapper( + $requestValueMapper = new ToslaPosRequestValueMapper(); + $responseValueFormatter = new ToslaPosResponseValueFormatter(); + $responseValueMapper = new ToslaPosResponseValueMapper( $requestValueMapper->getCurrencyMappings(), $requestValueMapper->getTxTypeMappings(), - $requestValueMapper->getSecureTypeMappings(), + $requestValueMapper->getSecureTypeMappings() + ); + + $this->responseDataMapper = new ToslaPosResponseDataMapper( + $responseValueFormatter, + $responseValueMapper, $this->logger ); } diff --git a/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php b/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php index 249d4106..42f95105 100644 --- a/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php +++ b/tests/Unit/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapperTest.php @@ -5,9 +5,12 @@ namespace Mews\Pos\Tests\Unit\DataMapper\ResponseDataMapper; -use Mews\Pos\DataMapper\RequestValueMapper\VakifKatilimPosRequestValueMapper; use Mews\Pos\DataMapper\ResponseDataMapper\VakifKatilimPosResponseDataMapper; use Mews\Pos\Exceptions\NotImplementedException; +use Mews\Pos\Factory\RequestValueMapperFactory; +use Mews\Pos\Factory\ResponseValueFormatterFactory; +use Mews\Pos\Factory\ResponseValueMapperFactory; +use Mews\Pos\Gateways\VakifKatilimPos; use Mews\Pos\PosInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -29,12 +32,13 @@ protected function setUp(): void parent::setUp(); $this->logger = $this->createMock(LoggerInterface::class); - $requestValueMapper = new VakifKatilimPosRequestValueMapper(); + $requestValueMapper = RequestValueMapperFactory::createForGateway(VakifKatilimPos::class); + $responseValueMapper = ResponseValueMapperFactory::createForGateway(VakifKatilimPos::class, $requestValueMapper); + $responseValueFormatter = ResponseValueFormatterFactory::createForGateway(VakifKatilimPos::class); $this->responseDataMapper = new VakifKatilimPosResponseDataMapper( - $requestValueMapper->getCurrencyMappings(), - $requestValueMapper->getTxTypeMappings(), - $requestValueMapper->getSecureTypeMappings(), + $responseValueFormatter, + $responseValueMapper, $this->logger ); } @@ -64,18 +68,6 @@ public function testExtractMdStatus(array $responseData, ?string $expected): voi $this->assertSame($expected, $actual); } - /** - * @return void - */ - public function testFormatAmount(): void - { - $class = new \ReflectionObject($this->responseDataMapper); - $method = $class->getMethod('formatAmount'); - $method->setAccessible(true); - $this->assertSame(0.1, $method->invokeArgs($this->responseDataMapper, [10])); - $this->assertSame(1.01, $method->invokeArgs($this->responseDataMapper, [101])); - } - /** * @dataProvider paymentTestDataProvider */ diff --git a/tests/Unit/DataMapper/ResponseValueFormatter/BasicResponseValueFormatterTest.php b/tests/Unit/DataMapper/ResponseValueFormatter/BasicResponseValueFormatterTest.php new file mode 100644 index 00000000..55ca8d66 --- /dev/null +++ b/tests/Unit/DataMapper/ResponseValueFormatter/BasicResponseValueFormatterTest.php @@ -0,0 +1,108 @@ +formatter = new BasicResponseValueFormatter(); + } + + /** + * @dataProvider formatAmountProvider + */ + public function testFormatAmount(string $amount, string $txType, float $expected): void + { + $actual = $this->formatter->formatAmount($amount, $txType); + $this->assertSame($expected, $actual); + } + + /** + * @dataProvider formatInstallmentProvider + */ + public function testFormatInstallment(?string $installment, string $txType, int $expected): void + { + $actual = $this->formatter->formatInstallment($installment, $txType); + $this->assertSame($expected, $actual); + } + + /** + * @dataProvider formatDateTimeProvider + */ + public function testFormatDateTime(string $dateTime, string $expected): void + { + $actual = $this->formatter->formatDateTime($dateTime, ''); + $this->assertSame($expected, $actual->format('Y-m-d H:i:s')); + } + + public static function formatAmountProvider(): array + { + return [ + ['1.00', PosInterface::TX_TYPE_PAY_AUTH, 1.0], + ['1.00', '', 1.0], + ]; + } + + public static function formatInstallmentProvider(): array + { + return [ + ['1', PosInterface::TX_TYPE_PAY_AUTH, 0], + ['1', '', 0], + ['0', PosInterface::TX_TYPE_PAY_AUTH, 0], + ['0', '', 0], + [null, PosInterface::TX_TYPE_PAY_AUTH, 0], + [null, '', 0], + ]; + } + + public static function formatDateTimeProvider(): array + { + return [ + // AkbankPos txnDateTime, preAuthCloseDate + // KuveytPos OrderDate, UpdateSystemDate + // VakifKatilim OrderDate + ['2024-04-23T16:14:00.264', '2024-04-23 16:14:00'], + + // EstPos AUTH_DTTM, CAPTURE_DTTM, VOID_DTTM + // Garanti ProvDate, PreAuthDate + // PosNet tranDate + ['2022-10-30 12:29:53.773', '2022-10-30 12:29:53'], + + // Garanti LastTrxDate + ['2024-06-03 16:06:29', '2024-06-03 16:06:29'], + + // PosNetV1 TransactionDate => '2019-11-0813:58:37.909' + ['2019-11-0813:58:37.909', '2019-11-08 13:58:37'], + + // Garanti ProvDate + // EstPos TRXDATE, EXTRA_TRXDATE + ['20221101 13:14:19', '2022-11-01 13:14:19'], + + // PayFlexCPV4 HostDate + // ToslaPos CreateDate + ['20230309221037', '2023-03-09 22:10:37'], + + // InterPos TRXDATE, VoidDate + // PayForPos InsertDatetime, TransactionDate + ['09.08.2024 10:40:34', '2024-08-09 10:40:34'], + + // VakifKatilim TransactionTime + ['2019-08-16T10:54:23.81069', '2019-08-16 10:54:23'], + ['2024-07-01T13:15:47.2754872+03:00', '2024-07-01 13:15:47'], + ]; + } +} diff --git a/tests/Unit/DataMapper/ResponseValueFormatter/BoaPosResponseValueFormatterTest.php b/tests/Unit/DataMapper/ResponseValueFormatter/BoaPosResponseValueFormatterTest.php new file mode 100644 index 00000000..a9c4d0ce --- /dev/null +++ b/tests/Unit/DataMapper/ResponseValueFormatter/BoaPosResponseValueFormatterTest.php @@ -0,0 +1,38 @@ +formatter = new BoaPosResponseValueFormatter(); + } + + /** + * @dataProvider formatAmountProvider + */ + public function testFormatAmount(string $amount, string $txType, float $expected): void + { + $actual = $this->formatter->formatAmount($amount, $txType); + $this->assertSame($expected, $actual); + } + + public static function formatAmountProvider(): array + { + return [ + ['101', '', 1.01], + ]; + } +} diff --git a/tests/Unit/DataMapper/ResponseValueFormatter/EstPosResponseValueFormatterTest.php b/tests/Unit/DataMapper/ResponseValueFormatter/EstPosResponseValueFormatterTest.php new file mode 100644 index 00000000..0a318acb --- /dev/null +++ b/tests/Unit/DataMapper/ResponseValueFormatter/EstPosResponseValueFormatterTest.php @@ -0,0 +1,47 @@ +formatter = new EstPosResponseValueFormatter(); + } + + /** + * @dataProvider formatAmountProvider + */ + public function testFormatAmount(string $amount, string $txType, float $expected): void + { + $actual = $this->formatter->formatAmount($amount, $txType); + $this->assertSame($expected, $actual); + } + + public static function formatAmountProvider(): array + { + return [ + ['1.00', PosInterface::TX_TYPE_PAY_AUTH, 1.0], + ['1.00', PosInterface::TX_TYPE_PAY_PRE_AUTH, 1.0], + ['1.00', PosInterface::TX_TYPE_PAY_POST_AUTH, 1.0], + ['1.00', PosInterface::TX_TYPE_CANCEL, 1.0], + ['1.00', PosInterface::TX_TYPE_REFUND, 1.0], + ['1.00', PosInterface::TX_TYPE_REFUND_PARTIAL, 1.0], + ['1.00', '', 1.0], + ['1001', PosInterface::TX_TYPE_STATUS, 10.01], + ['1001', PosInterface::TX_TYPE_ORDER_HISTORY, 10.01], + ]; + } +} diff --git a/tests/Unit/DataMapper/ResponseValueFormatter/GarantiPosResponseValueFormatterTest.php b/tests/Unit/DataMapper/ResponseValueFormatter/GarantiPosResponseValueFormatterTest.php new file mode 100644 index 00000000..1f45bc67 --- /dev/null +++ b/tests/Unit/DataMapper/ResponseValueFormatter/GarantiPosResponseValueFormatterTest.php @@ -0,0 +1,70 @@ +formatter = new GarantiPosResponseValueFormatter(); + } + + /** + * @dataProvider formatAmountProvider + */ + public function testFormatAmount(string $amount, string $txType, float $expected): void + { + $actual = $this->formatter->formatAmount($amount, $txType); + $this->assertSame($expected, $actual); + } + + /** + * @dataProvider formatInstallmentProvider + */ + public function testFormatInstallment(?string $installment, string $txType, int $expected): void + { + $actual = $this->formatter->formatInstallment($installment, $txType); + $this->assertSame($expected, $actual); + } + + public static function formatInstallmentProvider(): array + { + return [ + ['1', PosInterface::TX_TYPE_PAY_AUTH, 0], + ['1', '', 0], + ['0', PosInterface::TX_TYPE_PAY_AUTH, 0], + ['0', '', 0], + [null, PosInterface::TX_TYPE_PAY_AUTH, 0], + [null, '', 0], + ['1', PosInterface::TX_TYPE_HISTORY, 0], + ['Pesin', PosInterface::TX_TYPE_HISTORY, 0], + ]; + } + + public static function formatAmountProvider(): array + { + return [ + ['1001', PosInterface::TX_TYPE_PAY_AUTH, 10.01], + ['1001', PosInterface::TX_TYPE_PAY_PRE_AUTH, 10.01], + ['1001', PosInterface::TX_TYPE_PAY_POST_AUTH, 10.01], + ['1001', PosInterface::TX_TYPE_CANCEL, 10.01], + ['1001', PosInterface::TX_TYPE_REFUND, 10.01], + ['1001', PosInterface::TX_TYPE_REFUND_PARTIAL, 10.01], + ['1001', PosInterface::TX_TYPE_STATUS, 10.01], + ['1001', PosInterface::TX_TYPE_ORDER_HISTORY, 10.01], + ['1001', '', 10.01], + ]; + } +} diff --git a/tests/Unit/DataMapper/ResponseValueFormatter/InterPosResponseValueFormatterTest.php b/tests/Unit/DataMapper/ResponseValueFormatter/InterPosResponseValueFormatterTest.php new file mode 100644 index 00000000..02586a30 --- /dev/null +++ b/tests/Unit/DataMapper/ResponseValueFormatter/InterPosResponseValueFormatterTest.php @@ -0,0 +1,47 @@ +formatter = new InterPosResponseValueFormatter(); + } + + /** + * @dataProvider formatAmountProvider + */ + public function testFormatAmount(string $amount, string $txType, float $expected): void + { + $actual = $this->formatter->formatAmount($amount, $txType); + $this->assertSame($expected, $actual); + } + + public function testFormatInstallment(): void + { + $this->expectException(\Mews\Pos\Exceptions\NotImplementedException::class); + $this->formatter->formatInstallment("2", PosInterface::TX_TYPE_PAY_AUTH); + } + + public static function formatAmountProvider(): array + { + return [ + ['0', '', 0.0], + ['1.056,2', '', 1056.2], + ['1,01', '', 1.01], + ]; + } +} diff --git a/tests/Unit/DataMapper/ResponseValueFormatter/PosNetResponseValueFormatterTest.php b/tests/Unit/DataMapper/ResponseValueFormatter/PosNetResponseValueFormatterTest.php new file mode 100644 index 00000000..6920aec0 --- /dev/null +++ b/tests/Unit/DataMapper/ResponseValueFormatter/PosNetResponseValueFormatterTest.php @@ -0,0 +1,41 @@ +formatter = new PosNetResponseValueFormatter(); + } + + /** + * @dataProvider formatAmountProvider + */ + public function testFormatAmount(string $amount, string $txType, float $expected): void + { + $actual = $this->formatter->formatAmount($amount, $txType); + $this->assertSame($expected, $actual); + } + + public static function formatAmountProvider(): array + { + return [ + ['101', '', 1.01], + ['10,1', PosInterface::TX_TYPE_STATUS, 10.1], + ['1.056,2', PosInterface::TX_TYPE_STATUS, 1056.2], + ]; + } +} diff --git a/tests/Unit/DataMapper/ResponseValueFormatter/ToslaPosResponseValueFormatterTest.php b/tests/Unit/DataMapper/ResponseValueFormatter/ToslaPosResponseValueFormatterTest.php new file mode 100644 index 00000000..bd6da8c6 --- /dev/null +++ b/tests/Unit/DataMapper/ResponseValueFormatter/ToslaPosResponseValueFormatterTest.php @@ -0,0 +1,45 @@ +formatter = new ToslaPosResponseValueFormatter(); + } + + /** + * @dataProvider formatAmountProvider + */ + public function testFormatAmount(string $amount, string $txType, float $expected): void + { + $actual = $this->formatter->formatAmount($amount, $txType); + $this->assertSame($expected, $actual); + } + + public function testFormatInstallment(): void + { + $this->expectException(\Mews\Pos\Exceptions\NotImplementedException::class); + $this->formatter->formatInstallment("2", PosInterface::TX_TYPE_PAY_AUTH); + } + + public static function formatAmountProvider(): array + { + return [ + ['1001', '', 10.01], + ]; + } +} diff --git a/tests/Unit/DataMapper/ResponseValueMapper/AkbankPosResponseValueMapperTest.php b/tests/Unit/DataMapper/ResponseValueMapper/AkbankPosResponseValueMapperTest.php new file mode 100644 index 00000000..dd979cb6 --- /dev/null +++ b/tests/Unit/DataMapper/ResponseValueMapper/AkbankPosResponseValueMapperTest.php @@ -0,0 +1,121 @@ +mapper = ResponseValueMapperFactory::createForGateway( + AkbankPos::class, + RequestValueMapperFactory::createForGateway(AkbankPos::class) + ); + } + + /** + * @dataProvider mapTxTypeDataProvider + */ + public function testMapTxType(string $txType, string $expected): void + { + $this->assertSame($expected, $this->mapper->mapTxType($txType)); + } + + /** + * @dataProvider mapOrderStatusDataProvider + */ + public function testMapOrderStatus( + string $orderStatus, + ?string $preAuthStatus, + bool $isRecurringOrder, + string $expected + ): void + { + $this->assertSame( + $expected, + $this->mapper->mapOrderStatus($orderStatus, $preAuthStatus, $isRecurringOrder) + ); + } + + /** + * @dataProvider mapCurrencyDataProvider + */ + public function testMapCurrency(int $currency, string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapCurrency($currency, $txType)); + } + + public function testMapSecureType(): void + { + $this->expectException(\LogicException::class); + $this->mapper->mapSecureType('3D', PosInterface::TX_TYPE_PAY_AUTH); + } + + + public static function mapCurrencyDataProvider(): array + { + return [ + [949, PosInterface::TX_TYPE_PAY_AUTH, PosInterface::CURRENCY_TRY], + [949, '', PosInterface::CURRENCY_TRY], + [840, '', PosInterface::CURRENCY_USD], + [978, '', PosInterface::CURRENCY_EUR], + [826, '', PosInterface::CURRENCY_GBP], + [392, '', PosInterface::CURRENCY_JPY], + [643, '', PosInterface::CURRENCY_RUB], + [1, '', null], + ]; + } + + + public static function mapTxTypeDataProvider(): array + { + return [ + ['1000', PosInterface::TX_TYPE_PAY_AUTH], + ['3000', PosInterface::TX_TYPE_PAY_AUTH], + ['1004', PosInterface::TX_TYPE_PAY_PRE_AUTH], + ['3004', PosInterface::TX_TYPE_PAY_PRE_AUTH], + ['1005', PosInterface::TX_TYPE_PAY_POST_AUTH], + ['1002', PosInterface::TX_TYPE_REFUND], + ['1003', PosInterface::TX_TYPE_CANCEL], + ['1010', PosInterface::TX_TYPE_ORDER_HISTORY], + ['1009', PosInterface::TX_TYPE_HISTORY], + ]; + } + + public static function mapOrderStatusDataProvider(): array + { + return [ + ['N', null, false, PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED], + ['N', 'O', false, PosInterface::PAYMENT_STATUS_PRE_AUTH_COMPLETED], + ['N', 'C', false, PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED], + ['S', null, false, PosInterface::PAYMENT_STATUS_ERROR], + ['V', null, false, PosInterface::PAYMENT_STATUS_CANCELED], + ['R', null, false, PosInterface::PAYMENT_STATUS_FULLY_REFUNDED], + ['Başarılı', null, false, PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED], + ['Başarısız', null, false, PosInterface::PAYMENT_STATUS_ERROR], + ['İptal', null, false, PosInterface::PAYMENT_STATUS_CANCELED], + ['S', null, true, PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED], + ['W', null, true, PosInterface::PAYMENT_STATUS_PAYMENT_PENDING], + ['V', null, true, PosInterface::PAYMENT_STATUS_CANCELED], + ['C', null, true, PosInterface::PAYMENT_STATUS_CANCELED], + ['blabla', null, true, 'blabla'], + ['blabla', null, false, 'blabla'], + ]; + } +} diff --git a/tests/Unit/DataMapper/ResponseValueMapper/BoaPosResponseValueMapperTest.php b/tests/Unit/DataMapper/ResponseValueMapper/BoaPosResponseValueMapperTest.php new file mode 100644 index 00000000..e7349af9 --- /dev/null +++ b/tests/Unit/DataMapper/ResponseValueMapper/BoaPosResponseValueMapperTest.php @@ -0,0 +1,117 @@ +mapper = ResponseValueMapperFactory::createForGateway( + KuveytPos::class, + RequestValueMapperFactory::createForGateway(KuveytPos::class) + ); + } + + /** + * @dataProvider mapTxTypeDataProvider + */ + public function testMapTxType(string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapTxType($txType)); + } + + /** + * @dataProvider mapOrderStatusDataProvider + */ + public function testMapOrderStatus( + $orderStatus, + $expected + ): void + { + $this->assertSame( + $expected, + $this->mapper->mapOrderStatus($orderStatus) + ); + } + + /** + * @dataProvider mapCurrencyDataProvider + */ + public function testMapCurrency(string $currency, string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapCurrency($currency, $txType)); + } + + /** + * @dataProvider mapSecureTypeDataProvider + */ + public function testMapSecureType(string $secureType, string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapSecureType($secureType, $txType)); + } + + public static function mapCurrencyDataProvider(): array + { + return [ + ['949', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::CURRENCY_TRY], + ['0949', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::CURRENCY_TRY], + ['949', '', PosInterface::CURRENCY_TRY], + ['0949', '', PosInterface::CURRENCY_TRY], + ['TRY', '', null], + ['840', '', PosInterface::CURRENCY_USD], + ['0840', '', PosInterface::CURRENCY_USD], + ['978', '', PosInterface::CURRENCY_EUR], + ['826', '', null], + ['392', '', null], + ]; + } + + public static function mapTxTypeDataProvider(): array + { + return [ + ['Sale', PosInterface::TX_TYPE_PAY_AUTH], + ['SaleReversal', PosInterface::TX_TYPE_CANCEL], + ['GetMerchantOrderDetail', PosInterface::TX_TYPE_STATUS], + ['Drawback', PosInterface::TX_TYPE_REFUND], + ['PartialDrawback', PosInterface::TX_TYPE_REFUND_PARTIAL], + ['', null], + ]; + } + + public static function mapOrderStatusDataProvider(): array + { + return [ + [1, PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED], + [4, PosInterface::PAYMENT_STATUS_FULLY_REFUNDED], + [5, PosInterface::PAYMENT_STATUS_PARTIALLY_REFUNDED], + [6, PosInterface::PAYMENT_STATUS_CANCELED], + [2, 2], + ['blabla', 'blabla'], + ]; + } + + public static function mapSecureTypeDataProvider(): array + { + return [ + ['3', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::MODEL_3D_SECURE], + ['0', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::MODEL_NON_SECURE], + ['1', PosInterface::TX_TYPE_PAY_AUTH, null], + ]; + } +} diff --git a/tests/Unit/DataMapper/ResponseValueMapper/EstPosResponseValueMapperTest.php b/tests/Unit/DataMapper/ResponseValueMapper/EstPosResponseValueMapperTest.php new file mode 100644 index 00000000..7a45ee3a --- /dev/null +++ b/tests/Unit/DataMapper/ResponseValueMapper/EstPosResponseValueMapperTest.php @@ -0,0 +1,124 @@ +mapper = ResponseValueMapperFactory::createForGateway( + EstV3Pos::class, + RequestValueMapperFactory::createForGateway(EstV3Pos::class) + ); + } + + /** + * @dataProvider mapTxTypeDataProvider + */ + public function testMapTxType(string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapTxType($txType)); + } + + /** + * @dataProvider mapOrderStatusDataProvider + */ + public function testMapOrderStatus( + string $orderStatus, + string $expected + ): void + { + $this->assertSame( + $expected, + $this->mapper->mapOrderStatus($orderStatus) + ); + } + + /** + * @dataProvider mapCurrencyDataProvider + */ + public function testMapCurrency(string $currency, string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapCurrency($currency, $txType)); + } + + /** + * @dataProvider mapSecureTypeDataProvider + */ + public function testMapSecureType(string $secureType, string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapSecureType($secureType, $txType)); + } + + public static function mapCurrencyDataProvider(): array + { + return [ + ['949', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::CURRENCY_TRY], + ['949', '', PosInterface::CURRENCY_TRY], + ['840', '', PosInterface::CURRENCY_USD], + ['978', '', PosInterface::CURRENCY_EUR], + ['826', '', PosInterface::CURRENCY_GBP], + ['392', '', PosInterface::CURRENCY_JPY], + ['643', '', PosInterface::CURRENCY_RUB], + ['TRY', '', null], + ]; + } + + + public static function mapTxTypeDataProvider(): array + { + return [ + ['S', PosInterface::TX_TYPE_PAY_AUTH], + ['C', PosInterface::TX_TYPE_REFUND], + ['', null], + ]; + } + + public static function mapOrderStatusDataProvider(): array + { + return [ + ['D', PosInterface::PAYMENT_STATUS_ERROR], + ['ERR', PosInterface::PAYMENT_STATUS_ERROR], + ['A', PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED], + ['C', PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED], + ['S', PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED], + ['PN', PosInterface::PAYMENT_STATUS_PAYMENT_PENDING], + ['CNCL', PosInterface::PAYMENT_STATUS_CANCELED], + ['V', PosInterface::PAYMENT_STATUS_CANCELED], + ['blabla', 'blabla'], + ]; + } + + + public static function mapSecureTypeDataProvider(): array + { + return [ + ['3d', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::MODEL_3D_SECURE], + ['3d', PosInterface::TX_TYPE_PAY_PRE_AUTH, PosInterface::MODEL_3D_SECURE], + ['3d', '', PosInterface::MODEL_3D_SECURE], + ['3d_pay', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::MODEL_3D_PAY], + ['3d_pay', '', PosInterface::MODEL_3D_PAY], + ['3d_pay_hosting', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::MODEL_3D_PAY_HOSTING], + ['3d_host', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::MODEL_3D_HOST], + ['regular', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::MODEL_NON_SECURE], + ['regular', PosInterface::TX_TYPE_PAY_POST_AUTH, PosInterface::MODEL_NON_SECURE], + ]; + } + +} diff --git a/tests/Unit/DataMapper/ResponseValueMapper/GarantiPosResponseValueMapperTest.php b/tests/Unit/DataMapper/ResponseValueMapper/GarantiPosResponseValueMapperTest.php new file mode 100644 index 00000000..2f4d8503 --- /dev/null +++ b/tests/Unit/DataMapper/ResponseValueMapper/GarantiPosResponseValueMapperTest.php @@ -0,0 +1,138 @@ +mapper = ResponseValueMapperFactory::createForGateway( + GarantiPos::class, + RequestValueMapperFactory::createForGateway(GarantiPos::class) + ); + } + + /** + * @dataProvider mapTxTypeDataProvider + */ + public function testMapTxType(string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapTxType($txType)); + } + + /** + * @dataProvider mapOrderStatusDataProvider + */ + public function testMapOrderStatus( + string $orderStatus, + ?string $requestTxType, + ?string $txType, + string $expected + ): void + { + $this->assertSame( + $expected, + $this->mapper->mapOrderStatus($orderStatus, $requestTxType, $txType) + ); + } + + /** + * @dataProvider mapCurrencyDataProvider + */ + public function testMapCurrency(string $currency, string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapCurrency($currency, $txType)); + } + + /** + * @dataProvider mapSecureTypeDataProvider + */ + public function testMapSecureType(string $secureType, string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapSecureType($secureType, $txType)); + } + + public static function mapCurrencyDataProvider(): array + { + return [ + ['949', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::CURRENCY_TRY], + ['TL', PosInterface::TX_TYPE_HISTORY, PosInterface::CURRENCY_TRY], + ['949', '', PosInterface::CURRENCY_TRY], + ['TRY', '', null], + ['840', '', PosInterface::CURRENCY_USD], + ['USD', PosInterface::TX_TYPE_HISTORY, PosInterface::CURRENCY_USD], + ['978', '', PosInterface::CURRENCY_EUR], + ['826', '', PosInterface::CURRENCY_GBP], + ['392', '', PosInterface::CURRENCY_JPY], + ['643', '', PosInterface::CURRENCY_RUB], + ]; + } + + + public static function mapTxTypeDataProvider(): array + { + return [ + ['Satis', PosInterface::TX_TYPE_PAY_AUTH], + ['sales', PosInterface::TX_TYPE_PAY_AUTH], + ['On Otorizasyon', PosInterface::TX_TYPE_PAY_PRE_AUTH], + ['On Otorizasyon Kapama', PosInterface::TX_TYPE_PAY_POST_AUTH], + ['Iade', PosInterface::TX_TYPE_REFUND], + ['refund', PosInterface::TX_TYPE_REFUND], + ['Iptal', PosInterface::TX_TYPE_CANCEL], + ['void', PosInterface::TX_TYPE_CANCEL], + ['', null], + ]; + } + + public static function mapOrderStatusDataProvider(): array + { + return [ + ['WAITINGPOSTAUTH', PosInterface::TX_TYPE_STATUS, null, PosInterface::PAYMENT_STATUS_PRE_AUTH_COMPLETED], + ['APPROVED', PosInterface::TX_TYPE_STATUS, null, 'APPROVED'], + ['blabla', PosInterface::TX_TYPE_STATUS, null, 'blabla'], + + ['Basarili', PosInterface::TX_TYPE_HISTORY, null, 'Basarili'], + ['blabla', PosInterface::TX_TYPE_HISTORY, null, 'blabla'], + + ['Basarili', PosInterface::TX_TYPE_HISTORY, PosInterface::TX_TYPE_CANCEL, PosInterface::PAYMENT_STATUS_CANCELED], + ['Onaylandi', PosInterface::TX_TYPE_HISTORY, PosInterface::TX_TYPE_CANCEL, PosInterface::PAYMENT_STATUS_CANCELED], + ['Basarili', PosInterface::TX_TYPE_HISTORY, PosInterface::TX_TYPE_REFUND, PosInterface::PAYMENT_STATUS_FULLY_REFUNDED], + ['Basarili', PosInterface::TX_TYPE_HISTORY, PosInterface::TX_TYPE_PAY_AUTH, PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED], + ['Basarili', PosInterface::TX_TYPE_HISTORY, PosInterface::TX_TYPE_PAY_POST_AUTH, PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED], + ['Basarili', PosInterface::TX_TYPE_HISTORY, PosInterface::TX_TYPE_PAY_PRE_AUTH, PosInterface::PAYMENT_STATUS_PRE_AUTH_COMPLETED], + ['Basarili', PosInterface::TX_TYPE_HISTORY, '', 'Basarili'], + ['Iptal', PosInterface::TX_TYPE_HISTORY, '', 'Iptal'], + ['', PosInterface::TX_TYPE_HISTORY, '', PosInterface::PAYMENT_STATUS_ERROR], + ['blabla', '', '', 'blabla'], + ]; + } + + + public static function mapSecureTypeDataProvider(): array + { + return [ + ['3D', PosInterface::TX_TYPE_HISTORY, PosInterface::MODEL_3D_SECURE], + ['', PosInterface::TX_TYPE_HISTORY, PosInterface::MODEL_NON_SECURE], + ['3D', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::MODEL_3D_SECURE], + ['3D', PosInterface::TX_TYPE_PAY_PRE_AUTH, PosInterface::MODEL_3D_SECURE], + ['3D_PAY', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::MODEL_3D_PAY], + ['3D_PAY', PosInterface::TX_TYPE_PAY_PRE_AUTH, PosInterface::MODEL_3D_PAY], + ]; + } +} diff --git a/tests/Unit/DataMapper/ResponseValueMapper/InterPosResponseValueMapperTest.php b/tests/Unit/DataMapper/ResponseValueMapper/InterPosResponseValueMapperTest.php new file mode 100644 index 00000000..bdcc7540 --- /dev/null +++ b/tests/Unit/DataMapper/ResponseValueMapper/InterPosResponseValueMapperTest.php @@ -0,0 +1,70 @@ +mapper = ResponseValueMapperFactory::createForGateway( + InterPos::class, + RequestValueMapperFactory::createForGateway(InterPos::class) + ); + } + + public function testMapTxType(): void + { + $this->expectException(\LogicException::class); + $this->mapper->mapTxType('Auth'); + } + + public function testMapOrderStatus(): void + { + $this->expectException(\LogicException::class); + $this->mapper->mapOrderStatus('S'); + } + + /** + * @dataProvider mapCurrencyDataProvider + */ + public function testMapCurrency(string $currency, string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapCurrency($currency, $txType)); + } + + public function testMapSecureType(): void + { + $this->expectException(\LogicException::class); + $this->mapper->mapSecureType('3DModel', PosInterface::TX_TYPE_PAY_AUTH); + } + + public static function mapCurrencyDataProvider(): array + { + return [ + ['949', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::CURRENCY_TRY], + ['949', '', PosInterface::CURRENCY_TRY], + ['840', '', PosInterface::CURRENCY_USD], + ['978', '', PosInterface::CURRENCY_EUR], + ['826', '', PosInterface::CURRENCY_GBP], + ['392', '', PosInterface::CURRENCY_JPY], + ['643', '', PosInterface::CURRENCY_RUB], + ['TRY', '', null], + ]; + } +} diff --git a/tests/Unit/DataMapper/ResponseValueMapper/PayFlexCPV4PosResponseValueMapperTest.php b/tests/Unit/DataMapper/ResponseValueMapper/PayFlexCPV4PosResponseValueMapperTest.php new file mode 100644 index 00000000..25d8d0fe --- /dev/null +++ b/tests/Unit/DataMapper/ResponseValueMapper/PayFlexCPV4PosResponseValueMapperTest.php @@ -0,0 +1,86 @@ +mapper = ResponseValueMapperFactory::createForGateway( + PayFlexCPV4Pos::class, + RequestValueMapperFactory::createForGateway(PayFlexCPV4Pos::class) + ); + } + + /** + * @dataProvider mapTxTypeDataProvider + */ + public function testMapTxType(string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapTxType($txType)); + } + + public function testMapOrderStatus(): void + { + $this->expectException(\LogicException::class); + $this->mapper->mapOrderStatus('S'); + } + + /** + * @dataProvider mapCurrencyDataProvider + */ + public function testMapCurrency(string $currency, string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapCurrency($currency, $txType)); + } + + public function testMapSecureType(): void + { + $this->expectException(\LogicException::class); + $this->mapper->mapSecureType('3D', PosInterface::TX_TYPE_PAY_AUTH); + } + + public static function mapCurrencyDataProvider(): array + { + return [ + ['949', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::CURRENCY_TRY], + ['949', '', PosInterface::CURRENCY_TRY], + ['TRY', '', null], + ['840', '', PosInterface::CURRENCY_USD], + ['978', '', PosInterface::CURRENCY_EUR], + ['826', '', PosInterface::CURRENCY_GBP], + ['392', '', PosInterface::CURRENCY_JPY], + ['643', '', PosInterface::CURRENCY_RUB], + ]; + } + + public static function mapTxTypeDataProvider(): array + { + return [ + ['Sale', PosInterface::TX_TYPE_PAY_AUTH], + ['Auth', PosInterface::TX_TYPE_PAY_PRE_AUTH], + ['Capture', PosInterface::TX_TYPE_PAY_POST_AUTH], + ['Cancel', PosInterface::TX_TYPE_CANCEL], + ['Refund', PosInterface::TX_TYPE_REFUND], + ['TxnHistory', PosInterface::TX_TYPE_HISTORY], + ['OrderInquiry', PosInterface::TX_TYPE_STATUS], + ['', null], + ]; + } +} diff --git a/tests/Unit/DataMapper/ResponseValueMapper/PayFlexV4PosResponseValueMapperTest.php b/tests/Unit/DataMapper/ResponseValueMapper/PayFlexV4PosResponseValueMapperTest.php new file mode 100644 index 00000000..5fd08256 --- /dev/null +++ b/tests/Unit/DataMapper/ResponseValueMapper/PayFlexV4PosResponseValueMapperTest.php @@ -0,0 +1,100 @@ +mapper = ResponseValueMapperFactory::createForGateway( + PayFlexV4Pos::class, + RequestValueMapperFactory::createForGateway(PayFlexV4Pos::class) + ); + } + + /** + * @dataProvider mapTxTypeDataProvider + */ + public function testMapTxType(string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapTxType($txType)); + } + + public function testMapOrderStatus(): void + { + $this->expectException(\LogicException::class); + $this->mapper->mapOrderStatus('S'); + } + + /** + * @dataProvider mapCurrencyDataProvider + */ + public function testMapCurrency(string $currency, string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapCurrency($currency, $txType)); + } + + /** + * @dataProvider mapSecureTypeDataProvider + */ + public function testMapSecureType(string $secureType, string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapSecureType($secureType, $txType)); + } + + public static function mapCurrencyDataProvider(): array + { + return [ + ['949', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::CURRENCY_TRY], + ['949', '', PosInterface::CURRENCY_TRY], + ['TRY', '', null], + ['840', '', PosInterface::CURRENCY_USD], + ['978', '', PosInterface::CURRENCY_EUR], + ['826', '', PosInterface::CURRENCY_GBP], + ['392', '', PosInterface::CURRENCY_JPY], + ['643', '', PosInterface::CURRENCY_RUB], + ]; + } + + public static function mapTxTypeDataProvider(): array + { + return [ + ['Sale', PosInterface::TX_TYPE_PAY_AUTH], + ['Auth', PosInterface::TX_TYPE_PAY_PRE_AUTH], + ['Capture', PosInterface::TX_TYPE_PAY_POST_AUTH], + ['Cancel', PosInterface::TX_TYPE_CANCEL], + ['Refund', PosInterface::TX_TYPE_REFUND], + ['status', PosInterface::TX_TYPE_STATUS], + ['', null], + ]; + } + + public static function mapSecureTypeDataProvider(): array + { + return [ + ['1', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::MODEL_NON_SECURE], + ['2', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::MODEL_3D_SECURE], + ['3', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::MODEL_3D_PAY], + ['1', '', PosInterface::MODEL_NON_SECURE], + ['2', '', PosInterface::MODEL_3D_SECURE], + ['3', '', PosInterface::MODEL_3D_PAY], + ['4', '', null], + ]; + } +} diff --git a/tests/Unit/DataMapper/ResponseValueMapper/PayForPosResponseValueMapperTest.php b/tests/Unit/DataMapper/ResponseValueMapper/PayForPosResponseValueMapperTest.php new file mode 100644 index 00000000..44c6c27c --- /dev/null +++ b/tests/Unit/DataMapper/ResponseValueMapper/PayForPosResponseValueMapperTest.php @@ -0,0 +1,102 @@ +mapper = ResponseValueMapperFactory::createForGateway( + PayForPos::class, + RequestValueMapperFactory::createForGateway(PayForPos::class) + ); + } + + /** + * @dataProvider mapTxTypeDataProvider + */ + public function testMapTxType(string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapTxType($txType)); + } + + public function testMapOrderStatus(): void + { + $this->expectException(\LogicException::class); + $this->mapper->mapOrderStatus('S'); + } + + /** + * @dataProvider mapCurrencyDataProvider + */ + public function testMapCurrency(string $currency, string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapCurrency($currency, $txType)); + } + + /** + * @dataProvider mapSecureTypeDataProvider + */ + public function testMapSecureType(string $secureType, string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapSecureType($secureType, $txType)); + } + + public static function mapCurrencyDataProvider(): array + { + return [ + ['949', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::CURRENCY_TRY], + ['949', '', PosInterface::CURRENCY_TRY], + ['840', '', PosInterface::CURRENCY_USD], + ['978', '', PosInterface::CURRENCY_EUR], + ['826', '', PosInterface::CURRENCY_GBP], + ['392', '', PosInterface::CURRENCY_JPY], + ['643', '', PosInterface::CURRENCY_RUB], + ['TRY', '', null], + ]; + } + + + public static function mapTxTypeDataProvider(): array + { + return [ + ['Auth', PosInterface::TX_TYPE_PAY_AUTH], + ['PreAuth', PosInterface::TX_TYPE_PAY_PRE_AUTH], + ['PostAuth', PosInterface::TX_TYPE_PAY_POST_AUTH], + ['Void', PosInterface::TX_TYPE_CANCEL], + ['Refund', PosInterface::TX_TYPE_REFUND], + ['TxnHistory', PosInterface::TX_TYPE_HISTORY], + ['OrderInquiry', PosInterface::TX_TYPE_STATUS], + ['blabla', null], + ]; + } + + + public static function mapSecureTypeDataProvider(): array + { + return [ + ['3DModel', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::MODEL_3D_SECURE], + ['3DModel', '', PosInterface::MODEL_3D_SECURE], + ['3DPay', '', PosInterface::MODEL_3D_PAY], + ['3DHost', '', PosInterface::MODEL_3D_HOST], + ['NonSecure', '', PosInterface::MODEL_NON_SECURE], + ['blabla', '', null], + ]; + } +} diff --git a/tests/Unit/DataMapper/ResponseValueMapper/PosNetResponseValueMapperTest.php b/tests/Unit/DataMapper/ResponseValueMapper/PosNetResponseValueMapperTest.php new file mode 100644 index 00000000..5b21e8f2 --- /dev/null +++ b/tests/Unit/DataMapper/ResponseValueMapper/PosNetResponseValueMapperTest.php @@ -0,0 +1,87 @@ +mapper = ResponseValueMapperFactory::createForGateway( + PosNet::class, + RequestValueMapperFactory::createForGateway(PosNet::class) + ); + } + + /** + * @dataProvider mapTxTypeDataProvider + */ + public function testMapTxType(string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapTxType($txType)); + } + + public function testMapOrderStatus(): void + { + $this->expectException(\LogicException::class); + $this->mapper->mapOrderStatus('S'); + } + + /** + * @dataProvider mapCurrencyDataProvider + */ + public function testMapCurrency(string $currency, string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapCurrency($currency, $txType)); + } + + public function testMapSecureType(): void + { + $this->expectException(\LogicException::class); + $this->mapper->mapSecureType('3DModel', PosInterface::TX_TYPE_PAY_AUTH); + } + + public static function mapCurrencyDataProvider(): array + { + return [ + ['TL', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::CURRENCY_TRY], + ['TL', '', PosInterface::CURRENCY_TRY], + ['US', '', PosInterface::CURRENCY_USD], + ['EU', '', PosInterface::CURRENCY_EUR], + ['GB', '', PosInterface::CURRENCY_GBP], + ['JP', '', PosInterface::CURRENCY_JPY], + ['RU', '', PosInterface::CURRENCY_RUB], + ['TRY', '', null], + ]; + } + + + public static function mapTxTypeDataProvider(): array + { + return [ + ['Sale', PosInterface::TX_TYPE_PAY_AUTH], + ['Auth', PosInterface::TX_TYPE_PAY_PRE_AUTH], + ['Capt', PosInterface::TX_TYPE_PAY_POST_AUTH], + ['reverse', PosInterface::TX_TYPE_CANCEL], + ['return', PosInterface::TX_TYPE_REFUND], + ['agreement', PosInterface::TX_TYPE_STATUS], + ['', null], + ['blabla', null], + ]; + } +} diff --git a/tests/Unit/DataMapper/ResponseValueMapper/PosNetV1PosResponseValueMapperTest.php b/tests/Unit/DataMapper/ResponseValueMapper/PosNetV1PosResponseValueMapperTest.php new file mode 100644 index 00000000..bcddc37f --- /dev/null +++ b/tests/Unit/DataMapper/ResponseValueMapper/PosNetV1PosResponseValueMapperTest.php @@ -0,0 +1,110 @@ +mapper = ResponseValueMapperFactory::createForGateway( + PosNetV1Pos::class, + RequestValueMapperFactory::createForGateway(PosNetV1Pos::class) + ); + } + + /** + * @dataProvider mapTxTypeDataProvider + */ + public function testMapTxType(string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapTxType($txType)); + } + + /** + * @dataProvider mapOrderStatusDataProvider + */ + public function testMapOrderStatus( + string $orderStatus, + string $expected + ): void + { + $this->assertSame( + $expected, + $this->mapper->mapOrderStatus($orderStatus) + ); + } + + /** + * @dataProvider mapCurrencyDataProvider + */ + public function testMapCurrency(string $currency, string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapCurrency($currency, $txType)); + } + + public function testMapSecureType(): void + { + $this->expectException(\LogicException::class); + $this->mapper->mapSecureType('3DModel', PosInterface::TX_TYPE_PAY_AUTH); + } + + public static function mapCurrencyDataProvider(): array + { + return [ + ['TL', PosInterface::TX_TYPE_STATUS, PosInterface::CURRENCY_TRY], + ['US', PosInterface::TX_TYPE_STATUS, PosInterface::CURRENCY_USD], + ['EU', PosInterface::TX_TYPE_STATUS, PosInterface::CURRENCY_EUR], + ['GB', PosInterface::TX_TYPE_STATUS, PosInterface::CURRENCY_GBP], + ['JP', PosInterface::TX_TYPE_STATUS, PosInterface::CURRENCY_JPY], + ['RU', PosInterface::TX_TYPE_STATUS, PosInterface::CURRENCY_RUB], + ['949', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::CURRENCY_TRY], + ['840', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::CURRENCY_USD], + ['978', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::CURRENCY_EUR], + ['826', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::CURRENCY_GBP], + ['392', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::CURRENCY_JPY], + ['643', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::CURRENCY_RUB], + ['TRY', '', null], + ]; + } + + + public static function mapTxTypeDataProvider(): array + { + return [ + ['Sale', PosInterface::TX_TYPE_PAY_AUTH], + ['Auth', PosInterface::TX_TYPE_PAY_PRE_AUTH], + ['Capture', PosInterface::TX_TYPE_PAY_POST_AUTH], + ['Reverse', PosInterface::TX_TYPE_CANCEL], + ['Return', PosInterface::TX_TYPE_REFUND], + ['TransactionInquiry', PosInterface::TX_TYPE_STATUS], + ['', null], + ['blabla', null], + ]; + } + + public static function mapOrderStatusDataProvider(): array + { + return [ + [PosInterface::TX_TYPE_PAY_AUTH, PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED], + [PosInterface::TX_TYPE_CANCEL, PosInterface::PAYMENT_STATUS_CANCELED], + [PosInterface::TX_TYPE_REFUND, PosInterface::PAYMENT_STATUS_FULLY_REFUNDED], + ['blabla', 'blabla'], + ]; + } +} diff --git a/tests/Unit/DataMapper/ResponseValueMapper/ToslaPosResponseValueMapperTest.php b/tests/Unit/DataMapper/ResponseValueMapper/ToslaPosResponseValueMapperTest.php new file mode 100644 index 00000000..759d0cf3 --- /dev/null +++ b/tests/Unit/DataMapper/ResponseValueMapper/ToslaPosResponseValueMapperTest.php @@ -0,0 +1,106 @@ +mapper = ResponseValueMapperFactory::createForGateway( + ToslaPos::class, + RequestValueMapperFactory::createForGateway(ToslaPos::class) + ); + } + + /** + * @dataProvider mapTxTypeDataProvider + */ + public function testMapTxType(string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapTxType($txType)); + } + + /** + * @dataProvider mapOrderStatusDataProvider + */ + public function testMapOrderStatus( + $orderStatus, + string $expected + ): void + { + $this->assertSame( + $expected, + $this->mapper->mapOrderStatus($orderStatus) + ); + } + + /** + * @dataProvider mapCurrencyDataProvider + */ + public function testMapCurrency(string $currency, string $txType, ?string $expected): void + { + $this->assertSame($expected, $this->mapper->mapCurrency($currency, $txType)); + } + + public function testMapSecureType(): void + { + $this->expectException(\LogicException::class); + $this->mapper->mapSecureType('3D', PosInterface::TX_TYPE_PAY_AUTH); + } + + public static function mapCurrencyDataProvider(): array + { + return [ + ['949', PosInterface::TX_TYPE_PAY_AUTH, PosInterface::CURRENCY_TRY], + ['949', '', PosInterface::CURRENCY_TRY], + ['840', '', PosInterface::CURRENCY_USD], + ['978', '', PosInterface::CURRENCY_EUR], + ['826', '', PosInterface::CURRENCY_GBP], + ['392', '', PosInterface::CURRENCY_JPY], + ['643', '', PosInterface::CURRENCY_RUB], + ['TRY', '', null], + ]; + } + + + public static function mapTxTypeDataProvider(): array + { + return [ + ['1', PosInterface::TX_TYPE_PAY_AUTH], + ['2', PosInterface::TX_TYPE_PAY_PRE_AUTH], + ['3', PosInterface::TX_TYPE_PAY_POST_AUTH], + ['4', PosInterface::TX_TYPE_CANCEL], + ['5', PosInterface::TX_TYPE_REFUND], + ['0', null], + ['', null], + ]; + } + + public static function mapOrderStatusDataProvider(): array + { + return [ + [0, PosInterface::PAYMENT_STATUS_ERROR], + [1, PosInterface::PAYMENT_STATUS_PAYMENT_COMPLETED], + [2, PosInterface::PAYMENT_STATUS_CANCELED], + [3, PosInterface::PAYMENT_STATUS_PARTIALLY_REFUNDED], + [4, PosInterface::PAYMENT_STATUS_FULLY_REFUNDED], + ['blabla', 'blabla'], + ]; + } +} diff --git a/tests/Unit/Factory/RequestValueMapperFactoryTest.php b/tests/Unit/Factory/RequestValueMapperFactoryTest.php index f2b5a725..33e0fee6 100644 --- a/tests/Unit/Factory/RequestValueMapperFactoryTest.php +++ b/tests/Unit/Factory/RequestValueMapperFactoryTest.php @@ -10,6 +10,7 @@ use Mews\Pos\DataMapper\RequestValueMapper\InterPosRequestValueMapper; use Mews\Pos\DataMapper\RequestValueMapper\KuveytPosRequestValueMapper; use Mews\Pos\DataMapper\RequestValueMapper\PayFlexCPV4PosRequestValueMapper; +use Mews\Pos\DataMapper\RequestValueMapper\PayFlexV4PosRequestValueMapper; use Mews\Pos\DataMapper\RequestValueMapper\PayForPosRequestValueMapper; use Mews\Pos\DataMapper\RequestValueMapper\PosNetRequestValueMapper; use Mews\Pos\DataMapper\RequestValueMapper\PosNetV1PosRequestValueMapper; @@ -23,6 +24,7 @@ use Mews\Pos\Gateways\InterPos; use Mews\Pos\Gateways\KuveytPos; use Mews\Pos\Gateways\PayFlexCPV4Pos; +use Mews\Pos\Gateways\PayFlexV4Pos; use Mews\Pos\Gateways\PayForPos; use Mews\Pos\Gateways\PosNet; use Mews\Pos\Gateways\PosNetV1Pos; @@ -55,18 +57,19 @@ public function testCreateForGateway(string $gatewayClass, string $expectedForma 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], + [PayFlexCPV4Pos::class, PayFlexCPV4PosRequestValueMapper::class], + [PayFlexV4Pos::class, PayFlexV4PosRequestValueMapper::class], [PayForPos::class, PayForPosRequestValueMapper::class], [PosNet::class, PosNetRequestValueMapper::class], [PosNetV1Pos::class, PosNetV1PosRequestValueMapper::class], - [PayFlexCPV4Pos::class, PayFlexCPV4PosRequestValueMapper::class], + [ToslaPos::class, ToslaPosRequestValueMapper::class], + [VakifKatilimPos::class, VakifKatilimPosRequestValueMapper::class], ]; } } diff --git a/tests/Unit/Factory/ResponseDataMapperFactoryTest.php b/tests/Unit/Factory/ResponseDataMapperFactoryTest.php index 384f01a2..8c53f8b4 100644 --- a/tests/Unit/Factory/ResponseDataMapperFactoryTest.php +++ b/tests/Unit/Factory/ResponseDataMapperFactoryTest.php @@ -5,8 +5,8 @@ namespace Mews\Pos\Tests\Unit\Factory; -use Mews\Pos\DataMapper\RequestDataMapper\RequestDataMapperInterface; -use Mews\Pos\DataMapper\RequestValueMapper\RequestValueMapperInterface; +use Mews\Pos\DataMapper\ResponseValueFormatter\ResponseValueFormatterInterface; +use Mews\Pos\DataMapper\ResponseValueMapper\ResponseValueMapperInterface; use Mews\Pos\Factory\ResponseDataMapperFactory; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; @@ -22,11 +22,13 @@ class ResponseDataMapperFactoryTest extends TestCase */ public function testCreateGatewayResponseMapper(string $gatewayClass, string $mapperClass): void { - $requestDataMapper = $this->createMock(RequestValueMapperInterface::class); - $logger = $this->createMock(LoggerInterface::class); - $mapper = ResponseDataMapperFactory::createGatewayResponseMapper( + $responseDataMapper = $this->createMock(ResponseValueMapperInterface::class); + $responseValueFormatter = $this->createMock(ResponseValueFormatterInterface::class); + $logger = $this->createMock(LoggerInterface::class); + $mapper = ResponseDataMapperFactory::createGatewayResponseMapper( $gatewayClass, - $requestDataMapper, + $responseValueFormatter, + $responseDataMapper, $logger ); $this->assertInstanceOf($mapperClass, $mapper); @@ -34,12 +36,14 @@ public function testCreateGatewayResponseMapper(string $gatewayClass, string $ma public function testCreateGatewayResponseMapperUnsupported(): void { - $requestDataMapper = $this->createMock(RequestValueMapperInterface::class); - $logger = $this->createMock(LoggerInterface::class); + $responseDataMapper = $this->createMock(ResponseValueMapperInterface::class); + $responseValueFormatter = $this->createMock(ResponseValueFormatterInterface::class); + $logger = $this->createMock(LoggerInterface::class); $this->expectException(\DomainException::class); ResponseDataMapperFactory::createGatewayResponseMapper( \stdClass::class, - $requestDataMapper, + $responseValueFormatter, + $responseDataMapper, $logger ); } diff --git a/tests/Unit/Factory/ResponseValueFormatterFactoryTest.php b/tests/Unit/Factory/ResponseValueFormatterFactoryTest.php new file mode 100644 index 00000000..7e1a091e --- /dev/null +++ b/tests/Unit/Factory/ResponseValueFormatterFactoryTest.php @@ -0,0 +1,62 @@ +assertInstanceOf($expectedFormatterClass, $formatter); + } + + public static function createForGatewayProvider(): array + { + return [ + [AkbankPos::class, BasicResponseValueFormatter::class], + [EstPos::class, EstPosResponseValueFormatter::class], + [EstV3Pos::class, EstPosResponseValueFormatter::class], + [GarantiPos::class, GarantiPosResponseValueFormatter::class], + [InterPos::class, InterPosResponseValueFormatter::class], + [KuveytPos::class, BoaPosResponseValueFormatter::class], + [PayFlexCPV4Pos::class, BasicResponseValueFormatter::class], + [PayFlexV4Pos::class, BasicResponseValueFormatter::class], + [PayForPos::class, BasicResponseValueFormatter::class], + [PosNet::class, PosNetResponseValueFormatter::class], + [PosNetV1Pos::class, PosNetResponseValueFormatter::class], + [ToslaPos::class, ToslaPosResponseValueFormatter::class], + [VakifKatilimPos::class, BoaPosResponseValueFormatter::class], + ]; + } +} diff --git a/tests/Unit/Factory/ResponseValueMapperFactoryTest.php b/tests/Unit/Factory/ResponseValueMapperFactoryTest.php new file mode 100644 index 00000000..54087f37 --- /dev/null +++ b/tests/Unit/Factory/ResponseValueMapperFactoryTest.php @@ -0,0 +1,76 @@ +factory = new ResponseValueMapperFactory(); + } + + /** + * @dataProvider gatewayClassDataProvider + */ + public function testCreateForGateway(string $gatewayClass, string $expectedFormatterClass): void + { + $requestValueMapper = $this->createMock(RequestValueMapperInterface::class); + $this->assertInstanceOf( + $expectedFormatterClass, + ResponseValueMapperFactory::createForGateway($gatewayClass, $requestValueMapper) + ); + } + + public static function gatewayClassDataProvider(): array + { + return [ + [AkbankPos::class, AkbankPosResponseValueMapper::class], + [EstPos::class, EstPosResponseValueMapper::class], + [EstV3Pos::class, EstPosResponseValueMapper::class], + [GarantiPos::class, GarantiPosResponseValueMapper::class], + [InterPos::class, InterPosResponseValueMapper::class], + [KuveytPos::class, BoaPosResponseValueMapper::class], + [PayForPos::class, PayForPosResponseValueMapper::class], + [PayFlexV4Pos::class, PayFlexV4PosResponseValueMapper::class], + [PayFlexCPV4Pos::class, PayFlexCPV4PosResponseValueMapper::class], + [PosNet::class, PosNetResponseValueMapper::class], + [PosNetV1Pos::class, PosNetV1PosResponseValueMapper::class], + [ToslaPos::class, ToslaPosResponseValueMapper::class], + [VakifKatilimPos::class, BoaPosResponseValueMapper::class], + ]; + } +}