Skip to content

Commit

Permalink
Merge pull request #221 from mewebstudio/garanti-pos-history-support
Browse files Browse the repository at this point in the history
Garanti pos history support
  • Loading branch information
nuryagdym authored Jul 1, 2024
2 parents a907693 + 87ac777 commit 0f9459a
Show file tree
Hide file tree
Showing 16 changed files with 1,044 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sistemlerinin kullanılabilmesidir.
| EST V3 POS<br/><br/><sup>EstPos altyapının<br/>daha güvenli<br/>(sha512) hash<br/>algoritmasıyla<br/>uygulaması.</sup> | -----"----- | -----"----- | -----"----- |
| PayFlex MPI VPOS V4 | Ziraat<br/>Vakıfbank VPOS 7/24<br/>İşbank | NonSecure<br/>3DSecure<br/>Tekrarlanan Ödeme | İptal<br/>İade<br/>Durum sorgulama |
| PayFlex<br/>Common Payment V4<br/><sup>(Ortak Ödeme)</sup> | Ziraat<br/>Vakıfbank<br/>İşbank | NonSecure<br/>3DPay<br/>3DHost | İptal<br/>İade |
| Garanti Virtual POS | Garanti | NonSecure<br/>3DSecure<br/>3DPay<br/>3DHost<br/>Tekrarlanan Ödeme | İptal<br/>İade<br/>Durum sorgulama<br/>Sipariş Tarihçesini sorgulama |
| Garanti Virtual POS | Garanti | NonSecure<br/>3DSecure<br/>3DPay<br/>3DHost<br/>Tekrarlanan Ödeme | İptal<br/>İade<br/>Durum sorgulama<br/>Sipariş Tarihçesini sorgulama<br/>Geçmiş İşlemleri sorgulama |
| PosNet | YapıKredi | NonSecure<br/>3DSecure<br/> | İptal<br/>İade<br/>Durum sorgulama |
| PosNetV1<br/><sup>(JSON API)</sup> | Albaraka Türk | NonSecure<br/>3DSecure | İptal<br/>İade<br/>Durum sorgulama |
| PayFor | Finansbank<br/>Enpara | NonSecure<br/>3DSecure<br/>3DPay<br/>3DHost | İptal<br/>İade<br/>Durum sorgulama<br/>Sipariş Tarihçesini sorgulama<br/>Geçmiş İşlemleri sorgulama |
Expand Down
12 changes: 10 additions & 2 deletions docs/HISTORY-EXAMPLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ try {

require 'config.php';

function createHistoryOrder(string $gatewayClass, array $extraData): array
function createHistoryOrder(string $gatewayClass, array $extraData, string $ip): array
{
$order = [];
$txTime = new \DateTimeImmutable();
Expand All @@ -61,6 +61,14 @@ function createHistoryOrder(string $gatewayClass, array $extraData): array
'start_date' => $txTime->modify('-1 day'),
'end_date' => $txTime->modify('+1 day'),
];
} elseif (\Mews\Pos\Gateways\GarantiPos::class === $gatewayClass) {
$order = [
'ip' => $ip,
'page' => 1, //optional
// Başlangıç ve bitiş tarihleri arasında en fazla 30 gün olabilir
'start_date' => $txTime,
'end_date' => $txTime->modify('+1 day'),
];
} elseif (\Mews\Pos\Gateways\AkbankPos::class === $gatewayClass) {
$order = [
// Gün aralığı 1 günden fazla girilemez
Expand All @@ -76,7 +84,7 @@ function createHistoryOrder(string $gatewayClass, array $extraData): array
return $order;
}

$order = createHistoryOrder(get_class($pos), []);
$order = createHistoryOrder(get_class($pos), [], '127.0.0.1');

try {
$pos->history($order);
Expand Down
13 changes: 11 additions & 2 deletions examples/_common-codes/regular/history.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

function createHistoryOrder(string $gatewayClass, array $extraData): array
function createHistoryOrder(string $gatewayClass, array $extraData, string $ip): array
{
$order = [];
$txTime = new \DateTimeImmutable();
Expand All @@ -28,6 +28,15 @@ function createHistoryOrder(string $gatewayClass, array $extraData): array
'start_date' => $txTime->modify('-1 day'),
'end_date' => $txTime->modify('+1 day'),
];
} elseif (\Mews\Pos\Gateways\GarantiPos::class === $gatewayClass) {
$order = [
'ip' => $ip,
'currency' => \Mews\Pos\PosInterface::CURRENCY_USD,
'page' => 1, //optional
// Başlangıç ve bitiş tarihleri arasında en fazla 30 gün olabilir
'start_date' => $txTime,
'end_date' => $txTime->modify('+1 day'),
];
} elseif (\Mews\Pos\Gateways\AkbankPos::class === $gatewayClass) {
$order = [
// Gün aralığı 1 günden fazla girilemez
Expand All @@ -43,7 +52,7 @@ function createHistoryOrder(string $gatewayClass, array $extraData): array
return $order;
}

$order = createHistoryOrder(get_class($pos), []);
$order = createHistoryOrder(get_class($pos), [], $ip);
dump($order);

try {
Expand Down
3 changes: 3 additions & 0 deletions examples/garanti/regular/history.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

require '../../_common-codes/regular/history.php';
90 changes: 76 additions & 14 deletions src/DataMapper/RequestDataMapper/GarantiPosRequestDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Mews\Pos\Entity\Account\GarantiPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\Before3DFormHashCalculatedEvent;
use Mews\Pos\Exceptions\NotImplementedException;
use Mews\Pos\Gateways\GarantiPos;
use Mews\Pos\PosInterface;

Expand All @@ -32,7 +31,12 @@ class GarantiPosRequestDataMapper extends AbstractRequestDataMapper
/** @var string */
public const CREDIT_CARD_EXP_YEAR_FORMAT = 'y';

/** @var string */
/**
* MotoInd; işlemin MAilOrder bir işlem olup olmadığı bilgisinin gönderildiği alandır.
* Y (also E) ise işlem mail order bir işlemdir.
* N (also H) ise işlem ecommerce işlemidir.
* @var string
*/
private const MOTO = 'N';

/**
Expand All @@ -53,7 +57,8 @@ class GarantiPosRequestDataMapper extends AbstractRequestDataMapper
PosInterface::TX_TYPE_CANCEL => 'void',
PosInterface::TX_TYPE_REFUND => 'refund',
PosInterface::TX_TYPE_REFUND_PARTIAL => 'refund',
PosInterface::TX_TYPE_HISTORY => 'orderhistoryinq',
PosInterface::TX_TYPE_ORDER_HISTORY => 'orderhistoryinq',
PosInterface::TX_TYPE_HISTORY => 'orderlistinq',
PosInterface::TX_TYPE_STATUS => 'orderinq',
];

Expand All @@ -80,10 +85,10 @@ public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array
'Version' => self::API_VERSION,
'Terminal' => $this->getTerminalData($posAccount),
'Customer' => [
'IPAddress' => $responseData['customeripaddress'],
'IPAddress' => $responseData['customeripaddress'],
],
'Order' => [
'OrderID' => $responseData['orderid'],
'OrderID' => $responseData['orderid'],
],
'Transaction' => [
'Type' => $responseData['txntype'],
Expand Down Expand Up @@ -124,11 +129,11 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount
'Version' => self::API_VERSION,
'Terminal' => $this->getTerminalData($posAccount),
'Customer' => [
'IPAddress' => $order['ip'],
'IPAddress' => $order['ip'],
],
'Card' => $this->getCardData($creditCard),
'Order' => [
'OrderID' => $order['id'],
'OrderID' => $order['id'],
],
'Transaction' => [
'Type' => $this->mapTxType($txType),
Expand Down Expand Up @@ -163,7 +168,7 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $po
'Version' => self::API_VERSION,
'Terminal' => $this->getTerminalData($posAccount),
'Customer' => [
'IPAddress' => $order['ip'],
'IPAddress' => $order['ip'],
],
'Order' => [
'OrderID' => $order['id'],
Expand Down Expand Up @@ -195,7 +200,7 @@ public function createStatusRequestData(AbstractPosAccount $posAccount, array $o
'Version' => self::API_VERSION,
'Terminal' => $this->getTerminalData($posAccount),
'Customer' => [
'IPAddress' => $order['ip'],
'IPAddress' => $order['ip'],
],
'Order' => [
'OrderID' => $order['id'],
Expand Down Expand Up @@ -229,7 +234,7 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o
'Version' => self::API_VERSION,
'Terminal' => $this->getTerminalData($posAccount, true),
'Customer' => [
'IPAddress' => $order['ip'],
'IPAddress' => $order['ip'],
],
'Order' => [
'OrderID' => $order['id'],
Expand Down Expand Up @@ -264,7 +269,7 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o
'Version' => self::API_VERSION,
'Terminal' => $this->getTerminalData($posAccount, true),
'Customer' => [
'IPAddress' => $order['ip'],
'IPAddress' => $order['ip'],
],
'Order' => [
'OrderID' => $order['id'],
Expand Down Expand Up @@ -299,13 +304,13 @@ public function createOrderHistoryRequestData(AbstractPosAccount $posAccount, ar
'Version' => self::API_VERSION,
'Terminal' => $this->getTerminalData($posAccount),
'Customer' => [
'IPAddress' => $order['ip'],
'IPAddress' => $order['ip'],
],
'Order' => [
'OrderID' => $order['id'],
],
'Transaction' => [
'Type' => $this->mapTxType(PosInterface::TX_TYPE_HISTORY),
'Type' => $this->mapTxType(PosInterface::TX_TYPE_ORDER_HISTORY),
'InstallmentCnt' => $this->mapInstallment($order['installment']),
'Amount' => $this->formatAmount($order['amount']), //sabit olarak amount 100 gonderilecek
'CurrencyCode' => $this->mapCurrency($order['currency']),
Expand All @@ -320,11 +325,45 @@ public function createOrderHistoryRequestData(AbstractPosAccount $posAccount, ar
}

/**
* @param GarantiPosAccount $posAccount
* {@inheritDoc}
*/
public function createHistoryRequestData(AbstractPosAccount $posAccount, array $data = []): array
{
throw new NotImplementedException();
$order = $this->prepareHistoryOrder($data);

$result = [
'Mode' => $this->getMode(),
'Version' => self::API_VERSION,
'Terminal' => $this->getTerminalData($posAccount),
'Customer' => [
'IPAddress' => $order['ip'],
],
'Order' => [
'OrderID' => null,
'GroupID' => null,
'Description' => null,
// Başlangıç ve bitiş tarihleri arasında en fazla 30 gün olabilir
'StartDate' => $this->formatRequestDateTime($order['start_date']),
'EndDate' => $this->formatRequestDateTime($order['end_date']),
/**
* 500 adetten fazla işlem olması durumunda ListPageNum alanında diğer 500 lü grupların görüntülenmesi
* için sayfa numarası yazılır.
*/
'ListPageNum' => $order['page'],
],
'Transaction' => [
'Type' => $this->mapTxType(PosInterface::TX_TYPE_HISTORY),
'Amount' => $this->formatAmount(1), //sabit olarak amount 100 gonderilecek
'CurrencyCode' => $this->mapCurrency(PosInterface::CURRENCY_TRY),
'CardholderPresentCode' => '0',
'MotoInd' => self::MOTO,
],
];

$result['Terminal']['HashData'] = $this->crypt->createHash($posAccount, $result);

return $result;
}


Expand Down Expand Up @@ -463,6 +502,19 @@ protected function prepareOrderHistoryOrder(array $order): array
return $this->prepareStatusOrder($order);
}

/**
* @inheritDoc
*/
protected function prepareHistoryOrder(array $data): array
{
return [
'start_date' => $data['start_date'],
'end_date' => $data['end_date'],
'page' => $data['page'] ?? 1,
'ip' => $data['ip'],
];
}

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -574,4 +626,14 @@ private function createRecurringData(array $recurringData): array
'StartDate' => isset($recurringData['startDate']) ? $recurringData['startDate']->format('Ymd') : '',
];
}

/**
* @param \DateTimeInterface $dateTime
*
* @return string example 01/12/2010 11:11
*/
private function formatRequestDateTime(\DateTimeInterface $dateTime): string
{
return $dateTime->format('d/m/Y H:i');
}
}
Loading

0 comments on commit 0f9459a

Please sign in to comment.