Skip to content

Commit

Permalink
param integration initial
Browse files Browse the repository at this point in the history
  • Loading branch information
mustapayev committed Jan 5, 2025
1 parent af5a9c4 commit f12b10b
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 43 deletions.
32 changes: 22 additions & 10 deletions src/Crypt/ParamPosCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
63 changes: 38 additions & 25 deletions src/DataMapper/RequestDataMapper/ParamPosRequestDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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'],
Expand Down Expand Up @@ -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;
}

Expand All @@ -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'])) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ public function getCrypt(): CryptInterface;
* @param string $gatewayURL
* @param CreditCardInterface|null $creditCard
*
* @return array{gateway: string, method: 'POST'|'GET', inputs: array<string, string>}
* @return array{gateway: string, method: 'POST'|'GET', inputs: array<string, string>}|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
Expand Down
18 changes: 14 additions & 4 deletions src/Gateways/ParamPos.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}

/**
Expand Down

0 comments on commit f12b10b

Please sign in to comment.