diff --git a/src/Crypt/ParamPosCrypt.php b/src/Crypt/ParamPosCrypt.php index 7dc1aba8..22f29bfd 100644 --- a/src/Crypt/ParamPosCrypt.php +++ b/src/Crypt/ParamPosCrypt.php @@ -75,16 +75,28 @@ public function check3DHash(AbstractPosAccount $posAccount, array $data): bool */ public function createHash(AbstractPosAccount $posAccount, array $requestData): string { - $map = [ - $requestData['G']['CLIENT_CODE'], - $requestData['GUID'], - $requestData['Taksit'] ?? '', - $requestData['Islem_Tutar'], - $requestData['Toplam_Tutar'], - $requestData['Siparis_ID'], -// $requestData['Hata_URL'] ?? '', //todo -// $requestData['Basarili_URL'] ?? '', - ]; + if (isset($requestData['Doviz_Kodu']) && '1000' !== $requestData['Doviz_Kodu']) { + // doviz odemeler icin farkli hash + $map = [ + $requestData['G']['CLIENT_CODE'], + $requestData['GUID'], + $requestData['Islem_Tutar'], + $requestData['Toplam_Tutar'], + $requestData['Siparis_ID'], + $requestData['Hata_URL'] ?? '', + $requestData['Basarili_URL'] ?? '', + ]; + } else { + // TRY odemeler icin hash + $map = [ + $requestData['G']['CLIENT_CODE'], + $requestData['GUID'], + $requestData['Taksit'] ?? '', + $requestData['Islem_Tutar'], + $requestData['Toplam_Tutar'], + $requestData['Siparis_ID'], + ]; + } $hashStr = \implode(static::HASH_SEPARATOR, $map); $hashStr = mb_convert_encoding($hashStr, 'ISO-8859-9'); diff --git a/src/DataMapper/RequestDataMapper/ParamPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/ParamPosRequestDataMapper.php index 02d53823..2a023cc9 100644 --- a/src/DataMapper/RequestDataMapper/ParamPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/ParamPosRequestDataMapper.php @@ -70,6 +70,16 @@ class ParamPosRequestDataMapper extends AbstractRequestDataMapper PosInterface::MODEL_NON_SECURE => 'NS', ]; + /** + * {@inheritdoc} + */ + protected array $currencyMappings = [ + PosInterface::CURRENCY_TRY => '1000', + PosInterface::CURRENCY_USD => '1001', + PosInterface::CURRENCY_EUR => '1002', + PosInterface::CURRENCY_GBP => '1003', + ]; + //todo /** @@ -79,8 +89,6 @@ class ParamPosRequestDataMapper extends AbstractRequestDataMapper */ public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array $order, string $txType, array $responseData): array { - $order = $this->preparePaymentOrder($order); - $requestData = $this->getRequestAccountData($posAccount) + [ 'UCD_MD' => (string) $responseData['md'], 'Islem_GUID' => (string) $responseData['islemGUID'], @@ -111,37 +119,30 @@ public function create3DEnrollmentCheckRequestData(AbstractPosAccount $posAccoun 'IPAdr' => (string) $order['ip'], 'Siparis_ID' => (string) $order['id'], 'Islem_Tutar' => $this->formatAmount($order['amount']), - 'Toplam_Tutar' => $this->formatAmount($order['amount']), //todo + 'Toplam_Tutar' => $this->formatAmount($order['amount']), //todo 'Basarili_URL' => (string) $order['success_url'], 'Hata_URL' => (string) $order['fail_url'], - //'Currency' => $this->mapCurrency($order['currency']), //todo 'Taksit' => $this->mapInstallment((int) $order['installment']), 'KK_Sahibi' => $creditCard->getHolderName(), 'KK_No' => $creditCard->getNumber(), 'KK_SK_Ay' => $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_MONTH_FORMAT), 'KK_SK_Yil' => $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_YEAR_FORMAT), 'KK_CVC' => $creditCard->getCvv(), - 'KK_Sahibi_GSM' => '', //optional olmasina ragmen hic gonderilmeyince hata aliniyor. - // 'Siparis_Aciklama' => '', - //'Ref_URL' => 'https://dev.param.com.tr/tr', -// 'Data1' => '', -// 'Data2' => '', -// 'Data3' => '', -// 'Data4' => '', -// 'Data5' => '', + 'KK_Sahibi_GSM' => '', //optional olmasina ragmen hic gonderilmeyince hata aliniyor. ]; + if (PosInterface::CURRENCY_TRY === $order['currency']) { + $requestData['Taksit'] = $this->mapInstallment((int) $order['installment']); + } else { + $requestData['Doviz_Kodu'] = $this->mapCurrency($order['currency']); + } + $requestData['Islem_Hash'] = $this->crypt->createHash($posAccount, $requestData); // todo // if (isset($order['recurring'])) { // $requestData += $this->createRecurringData($order['recurring']); // } -// return [ -// 'TP_WMD_UCD' => $requestData, -// '@xmlns' => 'https://turkpos.com.tr/', -// ]; - return $requestData; } @@ -157,23 +158,29 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount $order = $this->preparePaymentOrder($order); $requestData = $this->getRequestAccountData($posAccount) + [ - 'Islem_Guvenlik_Tip' => $this->secureTypeMappings[PosInterface::MODEL_NON_SECURE], //todo + 'Islem_Guvenlik_Tip' => $this->secureTypeMappings[PosInterface::MODEL_3D_SECURE], //todo 'Islem_ID' => $this->crypt->generateRandomString(), 'IPAdr' => (string) $order['ip'], 'Siparis_ID' => (string) $order['id'], - 'Islem_Tutar' => (string) $order['amount'], - 'Toplam_Tutar' => (string) $order['amount'], //todo + 'Islem_Tutar' => $this->formatAmount($order['amount']), + 'Toplam_Tutar' => $this->formatAmount($order['amount']), //todo 'Basarili_URL' => (string) $order['success_url'], 'Hata_URL' => (string) $order['fail_url'], - 'Currency' => $this->mapCurrency($order['currency']), 'Taksit' => $this->mapInstallment((int) $order['installment']), 'KK_Sahibi' => $creditCard->getHolderName(), 'KK_No' => $creditCard->getNumber(), 'KK_SK_Ay' => $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_MONTH_FORMAT), 'KK_SK_Yil' => $creditCard->getExpirationDate(self::CREDIT_CARD_EXP_YEAR_FORMAT), 'KK_CVC' => $creditCard->getCvv(), + 'KK_Sahibi_GSM' => '', //optional olmasina ragmen hic gonderilmeyince hata aliniyor. ]; + if (PosInterface::CURRENCY_TRY === $order['currency']) { + $requestData['Taksit'] = $this->mapInstallment((int) $order['installment']); + } else { + $requestData['Doviz_Kodu'] = $this->mapCurrency($order['currency']); + } + $requestData['Islem_Hash'] = $this->crypt->createHash($posAccount, $requestData); // todo // if (isset($order['recurring'])) { @@ -318,14 +325,20 @@ public function createHistoryRequestData(AbstractPosAccount $posAccount, array $ throw new NotImplementedException(); } - //todo - /** * {@inheritDoc} */ - public function create3DFormData(?AbstractPosAccount $posAccount, ?array $order, string $paymentModel, string $txType, ?string $gatewayURL = null, ?CreditCardInterface $creditCard = null, array $extraData = []): array + public function create3DFormData(?AbstractPosAccount $posAccount, ?array $order, string $paymentModel, string $txType, ?string $gatewayURL = null, ?CreditCardInterface $creditCard = null, array $extraData = []) { - throw new NotImplementedException(); + if (isset($extraData['UCD_URL'])) { + return [ + 'gateway' => $extraData['UCD_URL'], + 'method' => 'POST', + 'inputs' => [], + ]; + } + + return $extraData['UCD_HTML']; } //todo diff --git a/src/DataMapper/RequestDataMapper/RequestDataMapperInterface.php b/src/DataMapper/RequestDataMapper/RequestDataMapperInterface.php index a6228ac3..d0c4de14 100644 --- a/src/DataMapper/RequestDataMapper/RequestDataMapperInterface.php +++ b/src/DataMapper/RequestDataMapper/RequestDataMapperInterface.php @@ -71,11 +71,11 @@ public function getCrypt(): CryptInterface; * @param string $gatewayURL * @param CreditCardInterface|null $creditCard * - * @return array{gateway: string, method: 'POST'|'GET', inputs: array} + * @return array{gateway: string, method: 'POST'|'GET', inputs: array}|string * * @throws UnsupportedTransactionTypeException */ - public function create3DFormData(AbstractPosAccount $posAccount, array $order, string $paymentModel, string $txType, string $gatewayURL, ?CreditCardInterface $creditCard = null): array; + public function create3DFormData(AbstractPosAccount $posAccount, array $order, string $paymentModel, string $txType, string $gatewayURL, ?CreditCardInterface $creditCard = null); /** * @phpstan-param PosInterface::TX_TYPE_PAY_AUTH|PosInterface::TX_TYPE_PAY_PRE_AUTH $txType diff --git a/src/Gateways/ParamPos.php b/src/Gateways/ParamPos.php index 6ca4de61..eecb69a0 100644 --- a/src/Gateways/ParamPos.php +++ b/src/Gateways/ParamPos.php @@ -211,7 +211,7 @@ public function make3DHostPayment(Request $request, array $order, string $txType /** * @inheritDoc */ - public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null, bool $createWithoutCard = true): string + public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null, bool $createWithoutCard = true) //todo { $this->check3DFormInputs($paymentModel, $txType, $creditCard); @@ -223,14 +223,22 @@ public function get3DFormData(array $order, string $paymentModel, string $txType throw new \RuntimeException($data['soap:Fault']['faultstring']); } - $result = $data['TP_WMD_UCDResponse']['TP_WMD_UCDResult']; + $result = $data['TP_WMD_UCDResponse']['TP_WMD_UCDResult'] ?? $data['TP_Islem_Odeme_WDResponse']['TP_Islem_Odeme_WDResult'] ?? null; if ($result['Sonuc'] < 0) { $this->logger->error('soap error response', $result); throw new \RuntimeException($result['Sonuc_Str'], $result['Sonuc']); } - return $result['UCD_HTML']; + return $this->requestDataMapper->create3DFormData( + $this->account, + [], + $paymentModel, + $txType, + null, + null, + $result + ); } // todo @@ -421,7 +429,9 @@ private function registerPayment(array $order, string $paymentModel, string $txT $requestData = $event->getRequestData(); } - $requestData = $this->serializer->encode($requestData, 'TP_WMD_UCD'); //todo TP_WMD_UCD + $currency = $order['currency'] ?? PosInterface::CURRENCY_TRY; + $soapAction = PosInterface::CURRENCY_TRY === $currency ? 'TP_WMD_UCD' : 'TP_Islem_Odeme_WD'; + $requestData = $this->serializer->encode($requestData, $soapAction); //todo TP_WMD_UCD return $this->send( $requestData, diff --git a/tests/Unit/DataMapper/RequestDataMapper/ParamPosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/ParamPosRequestDataMapperTest.php index 7c317f9e..c1464016 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/ParamPosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/ParamPosRequestDataMapperTest.php @@ -88,8 +88,9 @@ public function testMapCurrency(): void $class = new \ReflectionObject($this->requestDataMapper); $method = $class->getMethod('mapCurrency'); $method->setAccessible(true); - $this->assertSame('949', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_TRY])); - $this->assertSame('978', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_EUR])); + $this->assertSame('1000', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_TRY])); + $this->assertSame('1001', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_USD])); + $this->assertSame('1002', $method->invokeArgs($this->requestDataMapper, [PosInterface::CURRENCY_EUR])); } /**