Skip to content

Commit

Permalink
param integration initial
Browse files Browse the repository at this point in the history
  • Loading branch information
mustapayev committed Dec 29, 2024
1 parent 2e04985 commit 126ed39
Show file tree
Hide file tree
Showing 15 changed files with 4,298 additions and 139 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"squizlabs/php_codesniffer": "^3.5",
"symfony/event-dispatcher": "^5.4",
"symfony/http-client": "^5.4",
"symfony/var-dumper": "^5.1"
"symfony/var-dumper": "^5.1",
"symfony/var-exporter": "^5.4"
},
"suggest": {
"ext-soap": "ParamPos kullanacaksanız veya KuveytPos ile iptal/iade gibi ödeme olmayan işlemleri yapacaksanız."
Expand Down
7 changes: 6 additions & 1 deletion config/pos_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
'name' => 'TURK Elektronik Para A.Ş',
'class' => Mews\Pos\Gateways\ParamPos::class,
'gateway_endpoints' => [
'payment_api' => 'https://testposws.param.com.tr/turkpos.ws/service_turkpos_prod.asmx',
//'payment_api' => 'https://testposws.param.com.tr/turkpos.ws/service_turkpos_prod.asmx',
//'payment_api' => 'https://test-dmz.param.com.tr/turkpos.ws/service_turkpos_test.asmx?wsdl',
// 'payment_api' => 'https://test-dmz.param.com.tr/turkpos.ws/service_turkpos_test.asmx?wsdl',
'payment_api' => 'https://test-dmz.param.com.tr/turkpos.ws/service_turkpos_test.asmx', //xml
//'payment_api' => 'https://test-dmz.param.com.tr:4443/turkpos.ws/service_turkpos_test.asmx?WSDL',
//prod: 'payment_api' => 'https://posws.param.com.tr/turkpos.ws/service_turkpos_prod.asmx?wsdl',
],
],
'payten_v3_hash' => [
Expand Down
8 changes: 5 additions & 3 deletions examples/_common-codes/3d/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
// ornegin /examples/finansbank-payfor/3d/_config.php
require '_config.php';

require '../../_templates/_header.php';

if ($request->getMethod() !== 'POST') {
echo new RedirectResponse($baseUrl.'index.php');
exit();
Expand Down Expand Up @@ -165,6 +163,10 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent): void {
try {
$formData = $pos->get3DFormData($order, $paymentModel, $transaction, $card, false);
//dd($formData);
if (is_string($formData)) {
echo $formData;
exit();
}
} catch (\InvalidArgumentException $e) {
// örneğin kart bilgisi sağlanmadığında bu exception'i alırsınız.
dd($e);
Expand Down Expand Up @@ -215,7 +217,7 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent): void {
// OZEL DURUMLAR ICIN KODLAR END
// ============================================================================================


require '../../_templates/_header.php';
$flowType = $request->get('payment_flow_type');
?>

Expand Down
20 changes: 15 additions & 5 deletions src/Crypt/ParamPosCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use Mews\Pos\Entity\Account\AbstractPosAccount;
use Mews\Pos\Exceptions\NotImplementedException;
use Symfony\Component\VarExporter\VarExporter;

class ParamPosCrypt extends AbstractCrypt
{
Expand Down Expand Up @@ -43,9 +44,18 @@ public function check3DHash(AbstractPosAccount $posAccount, array $data): bool
throw new \LogicException('Account storeKey eksik!');
}

$actualHash = $this->hashFromParams($posAccount->getStoreKey(), $data, 'HASHPARAMS', ':');
$hashParamsArr = [
'islemGUID',
'md',
'mdStatus',
'orderId',
];

$hashStr = $this->buildHashString($data, $hashParamsArr, '', $posAccount->getStoreKey());

$actualHash = $this->hashString($hashStr);

if ($data['HASH'] === $actualHash) {
if ($data['islemHash'] === $actualHash) {
$this->logger->debug('hash check is successful');

return true;
Expand All @@ -54,7 +64,7 @@ public function check3DHash(AbstractPosAccount $posAccount, array $data): bool
$this->logger->error('hash check failed', [
'data' => $data,
'generated_hash' => $actualHash,
'expected_hash' => $data['HASH'],
'expected_hash' => $data['islemHash'],
]);

return false;
Expand All @@ -72,8 +82,8 @@ public function createHash(AbstractPosAccount $posAccount, array $requestData):
$requestData['Islem_Tutar'],
$requestData['Toplam_Tutar'],
$requestData['Siparis_ID'],
$requestData['Hata_URL'] ?? '',
$requestData['Basarili_URL'] ?? '',
// $requestData['Hata_URL'] ?? '', //todo
// $requestData['Basarili_URL'] ?? '',
];

$hashStr = \implode(static::HASH_SEPARATOR, $map);
Expand Down
75 changes: 38 additions & 37 deletions src/DataMapper/RequestDataMapper/ParamPosRequestDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,21 @@ class ParamPosRequestDataMapper extends AbstractRequestDataMapper
/**
* {@inheritDoc}
*
* @param array{md: string, xid: string, eci: string, cavv: string} $responseData
* @param array{UCD_MD: string, Islem_GUID: string, Siparis_ID: string, cavv: string, G: array{CLIENT_CODE: string, CLIENT_USERNAME: string, CLIENT_PASSWORD: string}} $responseData
*/
public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array $order, string $txType, array $responseData): array
{
$order = $this->preparePaymentOrder($order);

$requestData = $this->getRequestAccountData($posAccount) + [
'Type' => $this->mapTxType($txType),
'IPAddress' => (string) $order['ip'],
'OrderId' => (string) $order['id'],
'Total' => (string) $order['amount'],
'Currency' => $this->mapCurrency($order['currency']),
'Taksit' => $this->mapInstallment((int) $order['installment']),
'Number' => $responseData['md'],
'PayerTxnId' => $responseData['xid'],
'PayerSecurityLevel' => $responseData['eci'],
'PayerAuthenticationCode' => $responseData['cavv'],
'Mode' => 'P',
'UCD_MD' => (string) $responseData['md'],

Check failure on line 85 in src/DataMapper/RequestDataMapper/ParamPosRequestDataMapper.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

Offset 'md' does not exist on array{UCD_MD: string, Islem_GUID: string, Siparis_ID: string, cavv: string, G: array{CLIENT_CODE: string, CLIENT_USERNAME: string, CLIENT_PASSWORD: string}}.

Check failure on line 85 in src/DataMapper/RequestDataMapper/ParamPosRequestDataMapper.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

Offset 'md' does not exist on array{UCD_MD: string, Islem_GUID: string, Siparis_ID: string, cavv: string, G: array{CLIENT_CODE: string, CLIENT_USERNAME: string, CLIENT_PASSWORD: string}}.
'Islem_GUID' => (string) $responseData['islemGUID'],

Check failure on line 86 in src/DataMapper/RequestDataMapper/ParamPosRequestDataMapper.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

Offset 'islemGUID' does not exist on array{UCD_MD: string, Islem_GUID: string, Siparis_ID: string, cavv: string, G: array{CLIENT_CODE: string, CLIENT_USERNAME: string, CLIENT_PASSWORD: string}}.

Check failure on line 86 in src/DataMapper/RequestDataMapper/ParamPosRequestDataMapper.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

Offset 'islemGUID' does not exist on array{UCD_MD: string, Islem_GUID: string, Siparis_ID: string, cavv: string, G: array{CLIENT_CODE: string, CLIENT_USERNAME: string, CLIENT_PASSWORD: string}}.
'Siparis_ID' => (string) $responseData['orderId'],

Check failure on line 87 in src/DataMapper/RequestDataMapper/ParamPosRequestDataMapper.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

Offset 'orderId' does not exist on array{UCD_MD: string, Islem_GUID: string, Siparis_ID: string, cavv: string, G: array{CLIENT_CODE: string, CLIENT_USERNAME: string, CLIENT_PASSWORD: string}}.

Check failure on line 87 in src/DataMapper/RequestDataMapper/ParamPosRequestDataMapper.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

Offset 'orderId' does not exist on array{UCD_MD: string, Islem_GUID: string, Siparis_ID: string, cavv: string, G: array{CLIENT_CODE: string, CLIENT_USERNAME: string, CLIENT_PASSWORD: string}}.
];

if (isset($order['recurring'])) {
$requestData += $this->createRecurringData($order['recurring']);
}
// //todo
// if (isset($order['recurring'])) {
// $requestData += $this->createRecurringData($order['recurring']);
// }

return $requestData;
}
Expand All @@ -118,17 +110,25 @@ public function create3DEnrollmentCheckRequestData(AbstractPosAccount $posAccoun
'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']),
//'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' => '',
];

$requestData['Islem_Hash'] = $this->crypt->createHash($posAccount, $requestData);
Expand All @@ -137,6 +137,11 @@ public function create3DEnrollmentCheckRequestData(AbstractPosAccount $posAccoun
// $requestData += $this->createRecurringData($order['recurring']);
// }

// return [
// 'TP_WMD_UCD' => $requestData,
// '@xmlns' => 'https://turkpos.com.tr/',
// ];

return $requestData;
}

Expand Down Expand Up @@ -318,25 +323,9 @@ public function createHistoryRequestData(AbstractPosAccount $posAccount, array $
/**
* {@inheritDoc}
*/
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 = null, ?CreditCardInterface $creditCard = null, array $extraData = []): array

Check failure on line 326 in src/DataMapper/RequestDataMapper/ParamPosRequestDataMapper.php

View workflow job for this annotation

GitHub Actions / test (7.4, prefer-stable)

Method Mews\Pos\DataMapper\RequestDataMapper\ParamPosRequestDataMapper::create3DFormData() has parameter $extraData with no value type specified in iterable type array.

Check failure on line 326 in src/DataMapper/RequestDataMapper/ParamPosRequestDataMapper.php

View workflow job for this annotation

GitHub Actions / test (8.0, prefer-stable)

Method Mews\Pos\DataMapper\RequestDataMapper\ParamPosRequestDataMapper::create3DFormData() has parameter $extraData with no value type specified in iterable type array.
{
$preparedOrder = $this->preparePaymentOrder($order);

$data = $this->create3DFormDataCommon($posAccount, $preparedOrder, $paymentModel, $txType, $gatewayURL, $creditCard);

$event = new Before3DFormHashCalculatedEvent(
$data['inputs'],
$posAccount->getBank(),
$txType,
$paymentModel,
EstPos::class
);
$this->eventDispatcher->dispatch($event);
$data['inputs'] = $event->getFormInputs();

$data['inputs']['hash'] = $this->crypt->create3DHash($posAccount, $data['inputs']);

return $data;
throw new NotImplementedException();
}

//todo
Expand Down Expand Up @@ -477,6 +466,18 @@ protected function mapCurrency(string $currency): string
return (string) $this->currencyMappings[$currency] ?? $currency;
}

/**
* 10.0 => 10,00
* 1000.5 => 1000,50
* @param float $amount
*
* @return string
*/
protected function formatAmount(float $amount): string
{
return \number_format($amount, 2, ',', '');
}

/**
* @param AbstractPosAccount $posAccount
*
Expand Down
Loading

0 comments on commit 126ed39

Please sign in to comment.