Skip to content

Commit

Permalink
issue #172 - upgrade KuveytPos version to TDV2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nuryagdym committed Mar 29, 2024
1 parent 94a88c3 commit cec6841
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 13 deletions.
4 changes: 2 additions & 2 deletions config/pos_production.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@
'name' => 'kuveyt-pos',
'class' => Mews\Pos\Gateways\KuveytPos::class,
'gateway_endpoints' => [
'payment_api' => 'https://boa.kuveytturk.com.tr/sanalposservice/Home/ThreeDModelProvisionGate',
'gateway_3d' => 'https://boa.kuveytturk.com.tr/sanalposservice/Home/ThreeDModelPayGate',
'payment_api' => 'https://sanalpos.kuveytturk.com.tr/ServiceGateWay/Home/ThreeDModelProvisionGate',
'gateway_3d' => 'https://sanalpos.kuveytturk.com.tr/ServiceGateWay/Home/ThreeDModelPayGate',
'query_api' => 'https://boa.kuveytturk.com.tr/BOA.Integration.WCFService/BOA.Integration.VirtualPos/VirtualPosService.svc?wsdl',
],
],
Expand Down
33 changes: 33 additions & 0 deletions docs/THREED-PAYMENT-EXAMPLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,39 @@ try {
}
});

// KuveytVos TDV2.0.0 icin ozel biri durum
$eventDispatcher->addListener(
RequestDataPreparedEvent::class,
function (RequestDataPreparedEvent $requestDataPreparedEvent) use ($pos): void {
if (get_class($pos) !== \Mews\Pos\Gateways\KuveytPos::class) {
return;
}
// KuveytPos TDV2.0.0 icin zorunlu eklenmesi gereken ekstra alanlar:
$additionalRequestDataForKuveyt = [
'DeviceData' => [
//2 karakter olmalıdır. 01-Mobil, 02-Web Browser için kullanılmalıdır.
'DeviceChannel' => '02',
],
'CardHolderData' => [
'BillAddrCity' => 'İstanbul',
// ISO 3166-1 sayısal üç haneli ülke kodu standardı kullanılmalıdır.
'BillAddrCountry' => '792',
'BillAddrLine1' => 'XXX Mahallesi XXX Caddesi No 55 Daire 1',
'BillAddrPostCode' => '34000',
// ISO 3166-2'de tanımlı olan il/eyalet kodu olmalıdır.
'BillAddrState' => '40',
'Email' => 'xxxxx@gmail.com',
'MobilePhone' => [
'Cc' => '90',
'Subscriber' => '1234567899',
],
],
];
$requestData = $requestDataPreparedEvent->getRequestData();
$requestData = array_merge($requestData, $additionalRequestDataForKuveyt);
$requestDataPreparedEvent->setRequestData($requestData);
});

$formData = $pos->get3DFormData(
$order,
$paymentModel,
Expand Down
65 changes: 65 additions & 0 deletions examples/_common-codes/3d/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,71 @@
*/
});

// KuveytVos TDV2.0.0 icin ozel biri durum
$eventDispatcher->addListener(
RequestDataPreparedEvent::class,
function (RequestDataPreparedEvent $requestDataPreparedEvent) use ($pos): void {
if (get_class($pos) !== \Mews\Pos\Gateways\KuveytPos::class) {
return;
}
// KuveytPos TDV2.0.0 icin zorunlu eklenmesi gereken ekstra alanlar:
$additionalRequestDataForKuveyt = [
'DeviceData' => [
/**
* DeviceChannel : DeviceData alanı içerisinde gönderilmesi beklenen işlemin yapıldığı cihaz bilgisi.
* 2 karakter olmalıdır. 01-Mobil, 02-Web Browser için kullanılmalıdır.
*/
'DeviceChannel' => '02',
],
'CardHolderData' => [
/**
* BillAddrCity: Kullanılan kart ile ilişkili kart hamilinin fatura adres şehri.
* Maksimum 50 karakter uzunluğunda olmalıdır.
*/
'BillAddrCity' => 'İstanbul',
/**
* BillAddrCountry Kullanılan kart ile ilişkili kart hamilinin fatura adresindeki ülke kodu.
* Maksimum 3 karakter uzunluğunda olmalıdır.
* ISO 3166-1 sayısal üç haneli ülke kodu standardı kullanılmalıdır.
*/
'BillAddrCountry' => '792',
/**
* BillAddrLine1: Kullanılan kart ile ilişkili kart hamilinin teslimat adresinde yer alan sokak vb. bilgileri içeren açık adresi.
* Maksimum 150 karakter uzunluğunda olmalıdır.
*/
'BillAddrLine1' => 'XXX Mahallesi XXX Caddesi No 55 Daire 1',
/**
* BillAddrPostCode: Kullanılan kart ile ilişkili kart hamilinin fatura adresindeki posta kodu.
*/
'BillAddrPostCode' => '34000',
/**
* BillAddrState: CardHolderData alanı içerisinde gönderilmesi beklenen ödemede kullanılan kart ile ilişkili kart hamilinin fatura adresindeki il veya eyalet bilgisi kodu.
* ISO 3166-2'de tanımlı olan il/eyalet kodu olmalıdır.
*/
'BillAddrState' => '40',
/**
* Email: Kullanılan kart ile ilişkili kart hamilinin iş yerinde oluşturduğu hesapta kullandığı email adresi.
* Maksimum 254 karakter uzunluğunda olmalıdır.
*/
'Email' => 'xxxxx@gmail.com',
'MobilePhone' => [
/**
* Cc: Kullanılan kart ile ilişkili kart hamilinin cep telefonuna ait ülke kodu. 1-3 karakter uzunluğunda olmalıdır.
*/
'Cc' => '90',
/**
* Subscriber: Kullanılan kart ile ilişkili kart hamilinin cep telefonuna ait abone numarası.
* Maksimum 15 karakter uzunluğunda olmalıdır.
*/
'Subscriber' => '1234567899',
],
],
];
$requestData = $requestDataPreparedEvent->getRequestData();
$requestData = array_merge($requestData, $additionalRequestDataForKuveyt);
$requestDataPreparedEvent->setRequestData($requestData);
});

/**
* Bu Event'i dinleyerek 3D formun hash verisi hesaplanmadan önce formun input array içireğini güncelleyebilirsiniz.
*/
Expand Down
4 changes: 2 additions & 2 deletions examples/kuveytpos/3d/_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
$account = \Mews\Pos\Factory\AccountFactory::createKuveytPosAccount(
'kuveytpos',
'496',
'apiuser1',
'apitest',
'400235',
'Api1232',
'api123',
PosInterface::MODEL_3D_SECURE
);

Expand Down
9 changes: 5 additions & 4 deletions examples/kuveytpos/_payment_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

$testCards = [
'visa1' => [
'number' => '4155650100416111',
//Kart Doğrulama Şifresi: 123456
'number' => '5188961939192544',
'year' => '25',
'month' => '1',
'cvv' => '123',
'month' => '06',
'cvv' => '929',
'name' => 'John Doe',
'type' => CreditCardInterface::CARD_TYPE_VISA,
'type' => CreditCardInterface::CARD_TYPE_MASTERCARD,
],
];
13 changes: 8 additions & 5 deletions src/DataMapper/RequestDataMapper/KuveytPosRequestDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class KuveytPosRequestDataMapper extends AbstractRequestDataMapper
{
/** @var string */
public const API_VERSION = '1.0.0';
public const API_VERSION = 'TDV2.0.0';

/** @var string */
public const CREDIT_CARD_EXP_YEAR_FORMAT = 'y';
Expand All @@ -39,10 +39,10 @@ class KuveytPosRequestDataMapper extends AbstractRequestDataMapper
* {@inheritDoc}
*/
protected array $txTypeMappings = [
PosInterface::TX_TYPE_PAY_AUTH => 'Sale',
PosInterface::TX_TYPE_CANCEL => 'SaleReversal',
PosInterface::TX_TYPE_STATUS => 'GetMerchantOrderDetail',
PosInterface::TX_TYPE_REFUND => 'PartialDrawback', // Also there is a "Drawback"
PosInterface::TX_TYPE_PAY_AUTH => 'Sale',
PosInterface::TX_TYPE_CANCEL => 'SaleReversal',
PosInterface::TX_TYPE_STATUS => 'GetMerchantOrderDetail',
PosInterface::TX_TYPE_REFUND => 'PartialDrawback', // Also there is a "Drawback"
];

/**
Expand Down Expand Up @@ -133,6 +133,9 @@ public function create3DEnrollmentCheckRequestData(KuveytPosAccount $kuveytPosAc
'MerchantOrderId' => $order['id'],
'OkUrl' => $order['success_url'],
'FailUrl' => $order['fail_url'],
'DeviceData' => [
'ClientIP' => $order['ip'],
],
];

if ($creditCard instanceof CreditCardInterface) {
Expand Down
141 changes: 141 additions & 0 deletions tests/Functional/KuveytPosTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?php
/**
* @license MIT
*/

use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\RequestDataPreparedEvent;
use Mews\Pos\Factory\CreditCardFactory;
use Mews\Pos\Factory\PosFactory;
use Mews\Pos\PosInterface;
use Monolog\Test\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcher;

class KuveytPosTest extends TestCase
{
use \Mews\Pos\Tests\Functional\PaymentTestTrait;

private CreditCardInterface $card;

private EventDispatcher $eventDispatcher;

/** @var KuveytPosTest */
private PosInterface $pos;

private array $lastResponse;

protected function setUp(): void
{
parent::setUp();

$config = require __DIR__.'/../../config/pos_test.php';

$account = \Mews\Pos\Factory\AccountFactory::createKuveytPosAccount(
'kuveytpos',
'496',
'apitest',
'400235',
'api123',
PosInterface::MODEL_3D_SECURE
);

$this->eventDispatcher = new EventDispatcher();

$this->pos = PosFactory::createPosGateway($account, $config, $this->eventDispatcher);

$this->pos->setTestMode(true);

$this->card = CreditCardFactory::createForGateway(
$this->pos,
'5188961939192544',
'25',
'06',
'929',
'John Doe',
CreditCardInterface::CARD_TYPE_MASTERCARD
);
}

/**
* NOT: sadece Turkiye IPsiyle istek gonderince cevap alabiliyoruz.
* @return void
*/
public function testCreate3DFormData(): void
{
$order = $this->createPaymentOrder();

$eventIsThrown = false;
$this->eventDispatcher->addListener(
RequestDataPreparedEvent::class,
function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThrown): void {
$eventIsThrown = true;
$additionalRequestDataForKuveyt = [
'DeviceData' => [
/**
* DeviceChannel : DeviceData alanı içerisinde gönderilmesi beklenen işlemin yapıldığı cihaz bilgisi.
* 2 karakter olmalıdır. 01-Mobil, 02-Web Browser için kullanılmalıdır.
*/
'DeviceChannel' => '02',
],
'CardHolderData' => [
/**
* BillAddrCity: Kullanılan kart ile ilişkili kart hamilinin fatura adres şehri.
* Maksimum 50 karakter uzunluğunda olmalıdır.
*/
'BillAddrCity' => 'İstanbul',
/**
* BillAddrCountry Kullanılan kart ile ilişkili kart hamilinin fatura adresindeki ülke kodu.
* Maksimum 3 karakter uzunluğunda olmalıdır.
* ISO 3166-1 sayısal üç haneli ülke kodu standardı kullanılmalıdır.
*/
'BillAddrCountry' => '792',
/**
* BillAddrLine1: Kullanılan kart ile ilişkili kart hamilinin teslimat adresinde yer alan sokak vb. bilgileri içeren açık adresi.
* Maksimum 150 karakter uzunluğunda olmalıdır.
*/
'BillAddrLine1' => 'XXX Mahallesi XXX Caddesi No 55 Daire 1',
/**
* BillAddrPostCode: Kullanılan kart ile ilişkili kart hamilinin fatura adresindeki posta kodu.
*/
'BillAddrPostCode' => '34000',
/**
* BillAddrState: CardHolderData alanı içerisinde gönderilmesi beklenen ödemede kullanılan kart ile ilişkili kart hamilinin fatura adresindeki il veya eyalet bilgisi kodu.
* ISO 3166-2'de tanımlı olan il/eyalet kodu olmalıdır.
*/
'BillAddrState' => '40',
/**
* Email: Kullanılan kart ile ilişkili kart hamilinin iş yerinde oluşturduğu hesapta kullandığı email adresi.
* Maksimum 254 karakter uzunluğunda olmalıdır.
*/
'Email' => 'xxxxx@gmail.com',
'MobilePhone' => [
/**
* Cc: Kullanılan kart ile ilişkili kart hamilinin cep telefonuna ait ülke kodu. 1-3 karakter uzunluğunda olmalıdır.
*/
'Cc' => '90',
/**
* Subscriber: Kullanılan kart ile ilişkili kart hamilinin cep telefonuna ait abone numarası.
* Maksimum 15 karakter uzunluğunda olmalıdır.
*/
'Subscriber' => '1234567899',
],
],
];
$requestData = $requestDataPreparedEvent->getRequestData();
$requestData = array_merge($requestData, $additionalRequestDataForKuveyt);
$requestDataPreparedEvent->setRequestData($requestData);
$this->assertSame(PosInterface::TX_TYPE_PAY_AUTH, $requestDataPreparedEvent->getTxType());
});

$formData = $this->pos->get3DFormData(
$order,
PosInterface::MODEL_3D_SECURE,
PosInterface::TX_TYPE_PAY_AUTH,
$this->card,
);

$this->assertIsArray($formData);
$this->assertNotEmpty($formData);
$this->assertTrue($eventIsThrown);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ public static function create3DEnrollmentCheckRequestDataDataProvider(): array
'CardExpireDateYear' => '25',
'CardExpireDateMonth' => '01',
'CardCVV2' => '123',
'DeviceData' => [
'ClientIP' => '127.0.0.1',
],
],
],
];
Expand Down

0 comments on commit cec6841

Please sign in to comment.