Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #250 support for custom queries #251

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 47 additions & 26 deletions README.md

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
# Changelog
## [1.5.0] - 2024-11-11

### New Features
- [Custom Query](./CUSTOM-QUERY-EXAMPLE.md) desteği eklendi. (issue #250)

### Changed
- **VakifKatilimPos** - sipariş detay sorgusunda mapping iyileştirilmesi.

### Fixed
- Bazı gatewaylarin response'larında bankadan gelen verinin yer almaması.

## [1.4.0] - 2024-07-02

### New Features
Expand Down
85 changes: 85 additions & 0 deletions docs/CUSTOM-QUERY-EXAMPLE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@

### Custom Query

Kütüphanenin desteği olmadığı özel istekleri bu methodla yapabilirsiniz.

```sh
$ cp ./vendor/mews/pos/config/pos_test.php ./pos_test_ayarlar.php
```

**config.php (Ayar dosyası)**
```php
<?php
require './vendor/autoload.php';

// API kullanıcı bilgileri
// AccountFactory'de kullanılacak method Gateway'e göre değişir!!!
// /examples altındaki _config.php dosyalara bakınız
// (örn: /examples/tosla/regular/_config.php)
$account = \Mews\Pos\Factory\AccountFactory::createToslaPosAccount(
'tosla',
'424342224432',
'POS_rwrwwrwr',
'POS_4343223',
);
$eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();

try {
$config = require __DIR__.'/pos_test_ayarlar.php';

$pos = \Mews\Pos\Factory\PosFactory::createPosGateway($account, $config, $eventDispatcher);

// GarantiPos'u test ortamda test edebilmek için zorunlu.
$pos->setTestMode(true);
} catch (\Mews\Pos\Exceptions\BankNotFoundException | \Mews\Pos\Exceptions\BankClassNullException $e) {
var_dump($e));
exit;
}
```

**custom_query.php**
```php
<?php

require 'config.php';

/**
* requestData içinde API hesap bilgileri, hash verisi ve bazi sabit değerler
* eğer zaten bulunmuyorsa kütüphane otomatik ekler.
*/
$requestData = [
'bin' => 415956,
];

/** @var \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher */
$eventDispatcher->addListener(\Mews\Pos\Event\RequestDataPreparedEvent::class, function (\Mews\Pos\Event\RequestDataPreparedEvent $event) {
// dump($event->getRequestData()); //bankaya gonderilecek veri:
//
// // Burda istek banka API'na gonderilmeden once gonderilecek veriyi degistirebilirsiniz.
// // Ornek:
// if ($event->getTxType() === PosInterface::TX_TYPE_CUSTOM_QUERY) {
// $data = $event->getRequestData();
// $data['abcd'] = '1234';
// $event->setRequestData($data);
// }
});

try {
$pos->customQuery(
$requestData,

// URL optional, bazı gateway'lerde zorunlu.
// Default olarak configdeki query_api ya da payment_api kullanılır.
'https://prepentegrasyon.tosla.com/api/Payment/GetCommissionAndInstallmentInfo'
);
} catch (Exception $e) {
dd($e);
}

/**
* Bankadan dönen cevap array'e dönüştürülür,
* ancak diğer transaction'larda olduğu gibi mapping/normalization yapılmaz.
*/
$response = $pos->getResponse();
var_dump($response);
```
53 changes: 53 additions & 0 deletions examples/_common-codes/regular/custom_query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

use Mews\Pos\PosInterface;

$templateTitle = 'Custom Query';

require '_config.php';
$transaction = PosInterface::TX_TYPE_CUSTOM_QUERY;

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

[$requestData, $apiUrl] = getCustomRequestData();

dump($requestData, $apiUrl);

/** @var \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher */
$eventDispatcher->addListener(\Mews\Pos\Event\RequestDataPreparedEvent::class, function (\Mews\Pos\Event\RequestDataPreparedEvent $event) {
dump($event->getRequestData()); //bankaya gonderilecek veri:
//
// // Burda istek banka API'na gonderilmeden once gonderilecek veriyi degistirebilirsiniz.
// // Ornek:
// if ($event->getTxType() === PosInterface::TX_TYPE_CUSTOM_QUERY) {
// $data = $event->getRequestData();
// $data['abcd'] = '1234';
// $event->setRequestData($data);
// }
});


try {
/**
* requestData içinde API hesap bilgileri, hash verisi ve bazi sabit değerler
* eğer zaten bulunmuyorsa kütüphane otomatik ekler.
*/
$pos->customQuery(
$requestData,

// URL optional, bazı gateway'lerde zorunlu.
// Default olarak configdeki query_api ya da payment_api kullanılır.
$apiUrl
);
} catch (Exception $e) {
dd($e);
}

/**
* Bankadan dönen cevap array'e dönüştürülür,
* ancak diğer transaction'larda olduğu gibi mapping/normalization yapılmaz.
*/
$response = $pos->getResponse();

require '../../_templates/_simple_response_dump.php';
require '../../_templates/_footer.php';
7 changes: 6 additions & 1 deletion examples/_templates/_header.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
</nav>
</header>
<div id="wrapper">
<div class="container" style="max-width: 640px;">
<div class="container" style="max-width: 720px;">
<h2 class="text-center"><?= $templateTitle; ?></h2>
<hr>
<?php if (isset($posClass)): ?>
Expand Down Expand Up @@ -133,6 +133,11 @@
<a class="nav-link <?= $transaction === \Mews\Pos\PosInterface::TX_TYPE_HISTORY ? 'active' : ''; ?>" href="<?= $bankTestsUrl ?>/regular/history.php">History</a>
</li>
<?php endif; ?>
<?php if ($posClass::isSupportedTransaction(\Mews\Pos\PosInterface::TX_TYPE_CUSTOM_QUERY, \Mews\Pos\PosInterface::MODEL_NON_SECURE)): ?>
<li class="nav-item">
<a class="nav-link <?= $transaction === \Mews\Pos\PosInterface::TX_TYPE_CUSTOM_QUERY ? 'active' : ''; ?>" href="<?= $bankTestsUrl ?>/regular/custom_query.php">Custom Query</a>
</li>
<?php endif; ?>
</ul>
</div>
</div>
Expand Down
27 changes: 27 additions & 0 deletions examples/akbankpos/regular/custom_query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

require '../../_common-codes/regular/custom_query.php';

function getCustomRequestData(): array
{
return [
[
'txnCode' => '1020',
'order' => [
'orderTrackId' => 'ae15a6c8-467e-45de-b24c-b98821a42667',
],
'payByLink' => [
'linkTxnCode' => '3000',
'linkTransferType' => 'SMS',
'mobilePhoneNumber' => '5321234567',
],
'transaction' => [
'amount' => 1.00,
'currencyCode' => 949,
'motoInd' => 0,
'installCount' => 1,
],
],
null,
];
}
17 changes: 17 additions & 0 deletions examples/finansbank-payfor/regular/custom_query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

require '../../_common-codes/regular/custom_query.php';

function getCustomRequestData(): array
{
return [
[
'SecureType' => 'Inquiry',
'TxnType' => 'ParaPuanInquiry',
'Pan' => '4155650100416111',
'Expiry' => '0125',
'Cvv2' => '123',
],
null,
];
}
30 changes: 30 additions & 0 deletions examples/garanti/regular/custom_query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

require '../../_common-codes/regular/custom_query.php';

function getCustomRequestData(): array
{
return [
[
'Version' => 'v0.00',
'Customer' => [
'IPAddress' => '1.1.111.111',
'EmailAddress' => 'Cem@cem.com',
],
'Order' => [
'OrderID' => 'SISTD5A61F1682E745B28871872383ABBEB1',
'GroupID' => '',
'Description' => '',
],
'Transaction' => [
'Type' => 'bininq',
'Amount' => '1',
'BINInq' => [
'Group' => 'A',
'CardType' => 'A',
],
],
],
null,
];
}
13 changes: 13 additions & 0 deletions examples/interpos/regular/custom_query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

require '../../_common-codes/regular/custom_query.php';

function getCustomRequestData(): array
{
return [
[
'abc' => 'abc',
],
null,
];
}
13 changes: 13 additions & 0 deletions examples/kuveytpos/regular/custom_query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

require '../../_common-codes/regular/custom_query.php';

function getCustomRequestData(): array
{
return [
[
'abc' => 'abc',
],
null,
];
}
14 changes: 14 additions & 0 deletions examples/payflex-cp-v4/regular/custom_query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

require '../../_common-codes/regular/custom_query.php';

function getCustomRequestData(): array
{
return [
[
'abc' => 'abc',
],
null,
];
}

14 changes: 14 additions & 0 deletions examples/payflex-mpi-v4/regular/custom_query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

require '../../_common-codes/regular/custom_query.php';

function getCustomRequestData(): array
{
return [
[
'TransactionType' => 'CampaignSearch',
'TransactionId' => date('Ymd').strtoupper(substr(uniqid(sha1(time()), true), 0, 4)),
],
null,
];
}
18 changes: 18 additions & 0 deletions examples/payten/regular/custom_query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

require '../../_common-codes/regular/custom_query.php';

function getCustomRequestData(): array
{
return [
[
'Type' => 'Query',
'Number' => '4242424242424242',
'Expires' => '10.2028',
'Extra' => [
'IMECECARDQUERY' => null,
],
],
null,
];
}
29 changes: 29 additions & 0 deletions examples/posnet-v1/regular/custom_query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

require '../../_common-codes/regular/custom_query.php';

function getCustomRequestData(): array
{
return [
[
'MACParams' => 'MerchantNo:TerminalNo:CardNo:Cvc2:ExpireDate',
'CipheredData' => null,
'DealerData' => null,
'IsEncrypted' => 'N',
'PaymentFacilitatorData' => null,
'AdditionalInfoData' => null,
'CardInformationData' => [
'CardHolderName' => 'deneme deneme',
'CardNo' => '5400619360964581',
'Cvc2' => '056',
'ExpireDate' => '2001',
],
'IsMailOrder' => null,
'IsRecurring' => null,
'IsTDSecureMerchant' => 'Y',
'PaymentInstrumentType' => 'CARD',
'ThreeDSecureData' => null,
],
'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc/PointInquiry',
];
}
20 changes: 20 additions & 0 deletions examples/posnet-ykb/regular/custom_query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

require '../../_common-codes/regular/custom_query.php';

function getCustomRequestData(): array
{
return [
[
'pointUsage' => [
'amount' => '250',
'lpAmount' => '40',
'ccno' => '4048090000000001',
'currencyCode' => 'TL',
'expDate' => '2411',
'orderID' => 'PKPPislemleriNT000000001',
],
],
null,
];
}
13 changes: 13 additions & 0 deletions examples/tosla/regular/custom_query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

require '../../_common-codes/regular/custom_query.php';

function getCustomRequestData(): array
{
return [
[
'bin' => 415956,
],
'https://prepentegrasyon.tosla.com/api/Payment/GetCommissionAndInstallmentInfo',
];
}
Loading