Skip to content

Commit

Permalink
Merge pull request #214 from mewebstudio/refactoring-events-2
Browse files Browse the repository at this point in the history
Added additional data into dispatched events
  • Loading branch information
nuryagdym authored May 22, 2024
2 parents 0945dc9 + 9991f16 commit 255f328
Show file tree
Hide file tree
Showing 56 changed files with 2,170 additions and 1,962 deletions.
21 changes: 1 addition & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,26 +257,7 @@ $pos = \Mews\Pos\Factory\PosFactory::createPosGateway(

## Genel Kultur

### NonSecure, 3D Secure, 3DPay ve 3DHost ödeme modeller arasındaki farklar

- **3DSecure** - Bankaya göre farklı isimler verilebilir, örn. 3D Full.
Gateway'den (3D şifre girdiginiz sayfadan) döndükten sonra ödemeyi tamamlamak
için
banka gateway'ne 1 istek daha (_provizyon_ isteği) gönderir.
Bu isteği göndermeden ödeme **tamamlanmaz**.
- **3DPay** - Bankaya göre farklı isimler verilebilir, örn. 3D Half.
Gateway'den (3D şifre girdiginiz sayfadan) döndükten sonra ödeme bitmiş
sayılır.
3DSecure ödemede yapıldığı gibi ekstra provizyon istek gönderilmez.
- **3DHost** - Kredi kart girişi için kullanıcı bankanın sayfasına yönledirilir,
kredi kart bilgileri girdikten sonra bankanın 3D gateway sayfasına
yönlendirilir,
ordan da websitenize geri yönlendirilir. Yönlendirme sonucunda ödeme
tamanlanmış olur.
- **NonSecure** - Ödeme işlemi kullanıcı 3D onay işlemi yapmadan gerçekleşir.
- **NonSecure, 3DSecure ve 3DPay** - Ödemede kredi kart bilgisi websiteniz
tarafından alınır.
**3DHost** ödemede ise banka websayfasından alınır.
Ödeme modelleri hakkında bilgi edinmek istiyorsanız [bu makaleyi](https://medium.com/p/fa5cd016999c) inceleyebilirsiniz.

### Otorizasyon, Ön Otorizasyon, Ön Provizyon Kapama İşlemler arasındaki farklar

Expand Down
4 changes: 2 additions & 2 deletions docs/PRE-AUTH-POST-EXAMPLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ $order = createPostPayOrder(
/** @var \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher */
$eventDispatcher->addListener(
\Mews\Pos\Event\RequestDataPreparedEvent::class,
function (\Mews\Pos\Event\RequestDataPreparedEvent $event) use ($gatewayClass, $preAuthAmount, $postAuthAmount) {
if (\Mews\Pos\Gateways\EstPos::class === $gatewayClass || \Mews\Pos\Gateways\EstV3Pos::class === $gatewayClass) {
function (\Mews\Pos\Event\RequestDataPreparedEvent $event) use ($preAuthAmount, $postAuthAmount) {
if (\Mews\Pos\Gateways\EstPos::class === $event->getGatewayClass() || \Mews\Pos\Gateways\EstV3Pos::class === $event->getGatewayClass()) {
// ($preAuthAmount < $postAuthAmount) durumda API isteğe ekstra değerler eklenmesi gerekiyor.
if ($preAuthAmount < $postAuthAmount) {
$requestData = $event->getRequestData();
Expand Down
8 changes: 4 additions & 4 deletions docs/THREED-PAYMENT-EXAMPLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ try {
* Bu Event'i dinleyerek 3D formun hash verisi hesaplanmadan önce formun input array içireğini güncelleyebilirsiniz.
* Eğer ekleyeceğiniz veri hash hesaplamada kullanılmıyorsa Form verisi oluştuktan sonra da güncelleyebilirsiniz.
*/
$eventDispatcher->addListener(Before3DFormHashCalculatedEvent::class, function (Before3DFormHashCalculatedEvent $event) use ($pos): void {
if (get_class($pos) === \Mews\Pos\Gateways\EstPos::class || get_class($pos) === \Mews\Pos\Gateways\EstV3Pos::class) {
$eventDispatcher->addListener(Before3DFormHashCalculatedEvent::class, function (Before3DFormHashCalculatedEvent $event): void {
if ($event->getGatewayClass() === \Mews\Pos\Gateways\EstPos::class || $event->getGatewayClass() === \Mews\Pos\Gateways\EstV3Pos::class) {
/**
* Örnek 1: İşbank İmece Kart ile ödeme yaparken aşağıdaki verilerin eklenmesi gerekiyor:
$supportedPaymentModels = [
Expand Down Expand Up @@ -179,8 +179,8 @@ 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) {
function (RequestDataPreparedEvent $requestDataPreparedEvent): void {
if ($event->getGatewayClass() !== \Mews\Pos\Gateways\KuveytPos::class) {
return;
}
// KuveytPos TDV2.0.0 icin zorunlu eklenmesi gereken ekstra alanlar:
Expand Down
10 changes: 5 additions & 5 deletions examples/_common-codes/3d/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
// 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) {
function (RequestDataPreparedEvent $requestDataPreparedEvent): void {
if ($requestDataPreparedEvent->getGatewayClass() !== \Mews\Pos\Gateways\KuveytPos::class) {
return;
}
// KuveytPos TDV2.0.0 icin zorunlu eklenmesi gereken ekstra alanlar:
Expand Down Expand Up @@ -135,8 +135,8 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent) use ($pos): void {
* Bu Event'i dinleyerek 3D formun hash verisi hesaplanmadan önce formun input array içireğini güncelleyebilirsiniz.
* Eger ekleyeceginiz veri hash hesaplamada kullanilmiyorsa form verisi olusturduktan sonra da ekleyebilirsiniz.
*/
$eventDispatcher->addListener(Before3DFormHashCalculatedEvent::class, function (Before3DFormHashCalculatedEvent $event) use ($pos): void {
if (get_class($pos) === \Mews\Pos\Gateways\EstPos::class || get_class($pos) === \Mews\Pos\Gateways\EstV3Pos::class) {
$eventDispatcher->addListener(Before3DFormHashCalculatedEvent::class, function (Before3DFormHashCalculatedEvent $event): void {
if ($event->getGatewayClass() === \Mews\Pos\Gateways\EstPos::class || $event->getGatewayClass() === \Mews\Pos\Gateways\EstV3Pos::class) {
//Örnek 1: İşbank İmece Kart ile ödeme yaparken aşağıdaki verilerin eklenmesi gerekiyor:
// $supportedPaymentModels = [
// \Mews\Pos\PosInterface::MODEL_3D_PAY,
Expand All @@ -150,7 +150,7 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent) use ($pos): void {
// $event->setFormInputs($formInputs);
// }
}
if (get_class($pos) === \Mews\Pos\Gateways\EstV3Pos::class) {
if ($event->getGatewayClass() === \Mews\Pos\Gateways\EstV3Pos::class) {
// // Örnek 2: callbackUrl eklenmesi
// $formInputs = $event->getFormInputs();
// $formInputs['callbackUrl'] = $formInputs['failUrl'];
Expand Down
4 changes: 2 additions & 2 deletions examples/_common-codes/regular/post-auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ function createPostPayOrder(string $gatewayClass, array $lastResponse, string $i
/** @var \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher */
$eventDispatcher->addListener(
\Mews\Pos\Event\RequestDataPreparedEvent::class,
function (\Mews\Pos\Event\RequestDataPreparedEvent $event) use ($gatewayClass, $preAuthAmount, $postAuthAmount) {
if (\Mews\Pos\Gateways\EstPos::class === $gatewayClass || \Mews\Pos\Gateways\EstV3Pos::class === $gatewayClass) {
function (\Mews\Pos\Event\RequestDataPreparedEvent $event) use ($preAuthAmount, $postAuthAmount) {
if (\Mews\Pos\Gateways\EstPos::class === $event->getGatewayClass() || \Mews\Pos\Gateways\EstV3Pos::class === $event->getGatewayClass()) {
if ($preAuthAmount < $postAuthAmount) {
$requestData = $event->getRequestData();
$requestData['Extra']['PREAMT'] = $preAuthAmount;
Expand Down
6 changes: 3 additions & 3 deletions examples/_templates/_finish_non_secure_payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// OZEL DURUMLAR ICIN KODLAR START
// ============================================================================================
/** @var \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher */
$eventDispatcher->addListener(RequestDataPreparedEvent::class, function (RequestDataPreparedEvent $event) use ($pos) {
$eventDispatcher->addListener(RequestDataPreparedEvent::class, function (RequestDataPreparedEvent $event) {
// Burda istek banka API'na gonderilmeden once gonderilecek veriyi degistirebilirsiniz.
// Ornek:
// $data = $event->getRequestData();
Expand All @@ -38,13 +38,13 @@
* 5: Ekstre Erteleme
* 6: Özel Vade Farkı
*/
if ($pos instanceof \Mews\Pos\Gateways\PosNetV1Pos) {
if ($event->getGatewayClass() instanceof \Mews\Pos\Gateways\PosNetV1Pos) {
// Albaraka PosNet KOICode ekleme
// $data = $event->getRequestData();
// $data['KOICode'] = '1';
// $event->setRequestData($data);
}
if ($pos instanceof \Mews\Pos\Gateways\PosNet) {
if ($event->getGatewayClass() instanceof \Mews\Pos\Gateways\PosNet) {
// Yapikredi PosNet KOICode ekleme
// $data = $event->getRequestData();
// $data['sale']['koiCode'] = '1';
Expand Down
4 changes: 2 additions & 2 deletions examples/_templates/_payment_secure_response.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
// OZEL DURUMLAR ICIN KODLAR START
// ============================================================================================
/** @var \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher */
$eventDispatcher->addListener(RequestDataPreparedEvent::class, function (RequestDataPreparedEvent $event) use ($pos) {
$eventDispatcher->addListener(RequestDataPreparedEvent::class, function (RequestDataPreparedEvent $event) {
// Burda istek banka API'na gonderilmeden once gonderilecek veriyi degistirebilirsiniz.
// Ornek:
// $data = $event->getRequestData();
Expand All @@ -56,7 +56,7 @@
* 5: Ekstre Erteleme
* 6: Özel Vade Farkı
*/
if ($pos instanceof \Mews\Pos\Gateways\PosNetV1Pos && $event->getTxType() === PosInterface::TX_TYPE_PAY_AUTH) {
if ($event->getGatewayClass() instanceof \Mews\Pos\Gateways\PosNetV1Pos && $event->getTxType() === PosInterface::TX_TYPE_PAY_AUTH) {
// Albaraka PosNet KOICode ekleme
// $data = $event->getRequestData();
// $data['KOICode'] = '1';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\Before3DFormHashCalculatedEvent;
use Mews\Pos\Exceptions\NotImplementedException;
use Mews\Pos\Gateways\AkbankPos;
use Mews\Pos\PosInterface;

/**
Expand Down Expand Up @@ -394,7 +395,8 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
$data['inputs'],
$posAccount->getBank(),
$txType,
$paymentModel
$paymentModel,
AkbankPos::class
);
$this->eventDispatcher->dispatch($event);
$data['inputs'] = $event->getFormInputs();
Expand Down
9 changes: 8 additions & 1 deletion src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Mews\Pos\Event\Before3DFormHashCalculatedEvent;
use Mews\Pos\Exceptions\NotImplementedException;
use Mews\Pos\Exceptions\UnsupportedTransactionTypeException;
use Mews\Pos\Gateways\EstPos;
use Mews\Pos\PosInterface;

/**
Expand Down Expand Up @@ -243,7 +244,13 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Mews\Pos\Entity\Account\AbstractPosAccount;
use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\Before3DFormHashCalculatedEvent;
use Mews\Pos\Gateways\EstV3Pos;

/**
* Creates request data for EstPos Gateway requests that supports v3 Hash algorithm
Expand All @@ -27,7 +28,13 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s

$data['inputs']['hashAlgorithm'] = 'ver3';

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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 Down Expand Up @@ -359,7 +360,13 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
$inputs['cardcvv2'] = $creditCard->getCvv();
}

$event = new Before3DFormHashCalculatedEvent($inputs, $posAccount->getBank(), $txType, $paymentModel);
$event = new Before3DFormHashCalculatedEvent(
$inputs,
$posAccount->getBank(),
$txType,
$paymentModel,
GarantiPos::class
);
$this->eventDispatcher->dispatch($event);
$inputs = $event->getFormInputs();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Mews\Pos\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\Before3DFormHashCalculatedEvent;
use Mews\Pos\Exceptions\NotImplementedException;
use Mews\Pos\Gateways\InterPos;
use Mews\Pos\PosInterface;

/**
Expand Down Expand Up @@ -228,7 +229,13 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
$inputs['Cvv2'] = $creditCard->getCvv();
}

$event = new Before3DFormHashCalculatedEvent($inputs, $posAccount->getBank(), $txType, $paymentModel);
$event = new Before3DFormHashCalculatedEvent(
$inputs,
$posAccount->getBank(),
$txType,
$paymentModel,
InterPos::class
);
$this->eventDispatcher->dispatch($event);
$inputs = $event->getFormInputs();

Expand Down
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\Entity\Card\CreditCardInterface;
use Mews\Pos\Event\Before3DFormHashCalculatedEvent;
use Mews\Pos\Gateways\PayForPos;
use Mews\Pos\PosInterface;

/**
Expand Down Expand Up @@ -237,7 +238,13 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s
$inputs['Cvv2'] = $creditCard->getCvv();
}

$event = new Before3DFormHashCalculatedEvent($inputs, $posAccount->getBank(), $txType, $paymentModel);
$event = new Before3DFormHashCalculatedEvent(
$inputs,
$posAccount->getBank(),
$txType,
$paymentModel,
PayForPos::class
);
$this->eventDispatcher->dispatch($event);
$inputs = $event->getFormInputs();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Mews\Pos\Event\Before3DFormHashCalculatedEvent;
use Mews\Pos\Exceptions\NotImplementedException;
use Mews\Pos\Exceptions\UnsupportedTransactionTypeException;
use Mews\Pos\Gateways\PosNetV1Pos;
use Mews\Pos\PosInterface;

/**
Expand Down Expand Up @@ -386,7 +387,13 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s

$inputs += $cardData;

$event = new Before3DFormHashCalculatedEvent($inputs, $posAccount->getBank(), $txType, $paymentModel);
$event = new Before3DFormHashCalculatedEvent(
$inputs,
$posAccount->getBank(),
$txType,
$paymentModel,
PosNetV1Pos::class
);
$this->eventDispatcher->dispatch($event);
$inputs = $event->getFormInputs();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public function map3DPaymentData(array $raw3DAuthResponseData, ?array $rawPaymen
$defaultResponse['proc_return_code'] = $procReturnCode;
$defaultResponse['error_code'] = $raw3DAuthResponseData['respCode'];
$defaultResponse['error_message'] = $raw3DAuthResponseData['respText'];
$defaultResponse['3d_all'] = $raw3DAuthResponseData;

return $defaultResponse;
}
Expand Down
23 changes: 21 additions & 2 deletions src/Event/Before3DFormHashCalculatedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,32 @@ class Before3DFormHashCalculatedEvent
/** @var PosInterface::MODEL_3D_* */
private string $paymentModel;

/** @var class-string<PosInterface> */
private string $gatewayClass;

/**
* @phpstan-param PosInterface::TX_TYPE_PAY_* $txType
* @phpstan-param PosInterface::MODEL_3D_* $paymentModel
* @phpstan-param class-string<PosInterface> $gatewayClass
*
* @param array<string, string> $formInputs
* @param string $bank
* @param string $txType
* @param string $paymentModel
* @param string $gatewayClass
*/
public function __construct(array $formInputs, string $bank, string $txType, string $paymentModel)
{
public function __construct(
array $formInputs,
string $bank,
string $txType,
string $paymentModel,
string $gatewayClass
) {
$this->formInputs = $formInputs;
$this->bank = $bank;
$this->txType = $txType;
$this->paymentModel = $paymentModel;
$this->gatewayClass = $gatewayClass;
}

/**
Expand Down Expand Up @@ -85,4 +96,12 @@ public function setFormInputs(array $formInputs): self

return $this;
}

/**
* @return class-string<PosInterface>
*/
public function getGatewayClass(): string
{
return $this->gatewayClass;
}
}
Loading

0 comments on commit 255f328

Please sign in to comment.