From fee1ccb82a751160099da5f7bc78384cc83d3720 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 12 May 2024 13:26:33 +0200 Subject: [PATCH 1/9] examples - add success/fail url to order only for 3d payments --- docs/PRE-AUTH-POST-EXAMPLE.md | 19 ++++++++++++------- examples/_common-codes/3d-host/index.php | 3 ++- examples/_common-codes/3d/form.php | 3 ++- examples/_common-codes/regular/form.php | 3 ++- examples/_main_config.php | 21 ++++++++++++--------- tests/Functional/AkbankPosTest.php | 10 ++++++++-- tests/Functional/EstV3PosTest.php | 11 ++++++++--- tests/Functional/GarantiPosTest.php | 11 ++++++++--- tests/Functional/KuveytPosTest.php | 4 ++-- tests/Functional/PayForPosTest.php | 11 ++++++++--- tests/Functional/PaymentTestTrait.php | 13 +++++++++++-- tests/Functional/ToslaPosTest.php | 6 +++--- 12 files changed, 78 insertions(+), 37 deletions(-) diff --git a/docs/PRE-AUTH-POST-EXAMPLE.md b/docs/PRE-AUTH-POST-EXAMPLE.md index 4704daf5..18445fae 100644 --- a/docs/PRE-AUTH-POST-EXAMPLE.md +++ b/docs/PRE-AUTH-POST-EXAMPLE.md @@ -64,15 +64,20 @@ $order = [ 'amount' => 1.01, 'currency' => \Mews\Pos\PosInterface::CURRENCY_TRY, //optional. default: TRY 'installment' => 0, //0 ya da 1'den büyük değer, optional. default: 0 - - // Success ve Fail URL'ler farklı olabilir ama kütüphane success ve fail için aynı kod çalıştırır. - // success_url ve fail_url'lerin aynı olmasın fayda var çünkü bazı gateyway'ler tek bir URL kabul eder. - 'success_url' => 'https://example.com/response.php', - 'fail_url' => 'https://example.com/response.php', - - //lang degeri verilmezse account (EstPosAccount) dili kullanılacak + // lang degeri verilmezse account (EstPosAccount) dili kullanılacak 'lang' => \Mews\Pos\Gateways\PosInterface::LANG_TR, // Kullanıcının yönlendirileceği banka gateway sayfasının ve gateway'den dönen mesajların dili. ]; + if (in_array($paymentModel, [ + PosInterface::MODEL_3D_SECURE, + PosInterface::MODEL_3D_PAY, + PosInterface::MODEL_3D_HOST, + PosInterface::MODEL_3D_PAY_HOSTING, + ], true)) { + // Success ve Fail URL'ler farklı olabilir ama kütüphane success ve fail için aynı kod çalıştırır. + // success_url ve fail_url'lerin aynı olmasın fayda var çünkü bazı gateyway'ler tek bir URL kabul eder. + $order['success_url'] = 'https://example.com/response.php'; + $order['fail_url'] = 'https://example.com/response.php'; + } $session->set('order', $order); diff --git a/examples/_common-codes/3d-host/index.php b/examples/_common-codes/3d-host/index.php index 22a736ff..d2da1de6 100644 --- a/examples/_common-codes/3d-host/index.php +++ b/examples/_common-codes/3d-host/index.php @@ -10,8 +10,9 @@ require '../../_templates/_header.php'; -$order = getNewOrder( +$order = createPaymentOrder( $pos, + $paymentModel, $baseUrl, $ip, $request->get('currency', PosInterface::CURRENCY_TRY), diff --git a/examples/_common-codes/3d/form.php b/examples/_common-codes/3d/form.php index 725ef665..be911bf6 100644 --- a/examples/_common-codes/3d/form.php +++ b/examples/_common-codes/3d/form.php @@ -21,8 +21,9 @@ exit(); } $transaction = $request->get('tx', PosInterface::TX_TYPE_PAY_AUTH); -$order = getNewOrder( +$order = createPaymentOrder( $pos, + $paymentModel, $baseUrl, $ip, $request->get('currency', PosInterface::CURRENCY_TRY), diff --git a/examples/_common-codes/regular/form.php b/examples/_common-codes/regular/form.php index 39b73cd8..33397a9f 100644 --- a/examples/_common-codes/regular/form.php +++ b/examples/_common-codes/regular/form.php @@ -8,8 +8,9 @@ $transaction = $request->get('tx', PosInterface::TX_TYPE_PAY_AUTH); -$order = getNewOrder( +$order = createPaymentOrder( $pos, + $paymentModel, $baseUrl, $ip, $request->get('currency', PosInterface::CURRENCY_TRY), diff --git a/examples/_main_config.php b/examples/_main_config.php index 73f2798a..ab3f8768 100644 --- a/examples/_main_config.php +++ b/examples/_main_config.php @@ -107,8 +107,9 @@ function createCard(PosInterface $pos, array $card): \Mews\Pos\Entity\Card\Credi } } -function getNewOrder( +function createPaymentOrder( PosInterface $pos, + string $paymentModel, string $baseUrl, string $ip, string $currency = PosInterface::CURRENCY_TRY, @@ -116,10 +117,6 @@ function getNewOrder( bool $tekrarlanan = false, ?string $lang = null ): array { - - $successUrl = $baseUrl.'response.php'; - $failUrl = $baseUrl.'response.php'; - if ($tekrarlanan && get_class($pos) === AkbankPos::class) { // AkbankPos'ta recurring odemede orderTrackId/orderId en az 36 karakter olmasi gerekiyor $orderId = date('Ymd').strtoupper(substr(uniqid(sha1(time())), 0, 28)); @@ -133,12 +130,18 @@ function getNewOrder( 'currency' => $currency, 'installment' => $installment, 'ip' => filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) ? $ip : '127.0.0.1', - - // 3d, 3d_pay, 3d_host odemeler icin zorunlu - 'success_url' => $successUrl, // https://example.com/payment - 'fail_url' => $failUrl, // https://example.com/payment ]; + if (in_array($paymentModel, [ + PosInterface::MODEL_3D_SECURE, + PosInterface::MODEL_3D_PAY, + PosInterface::MODEL_3D_HOST, + PosInterface::MODEL_3D_PAY_HOSTING, + ], true)) { + $order['success_url'] = $baseUrl.'response.php'; + $order['fail_url'] = $baseUrl.'response.php'; + } + if ($lang) { //lang degeri verilmezse account (EstPosAccount) dili kullanilacak $order['lang'] = $lang; diff --git a/tests/Functional/AkbankPosTest.php b/tests/Functional/AkbankPosTest.php index bf83bb90..2fd8bbe7 100644 --- a/tests/Functional/AkbankPosTest.php +++ b/tests/Functional/AkbankPosTest.php @@ -65,7 +65,7 @@ protected function setUp(): void public function testNonSecurePaymentSuccess(): array { - $order = $this->createPaymentOrder(); + $order = $this->createPaymentOrder(PosInterface::MODEL_NON_SECURE); $this->eventDispatcher->addListener( RequestDataPreparedEvent::class, @@ -167,7 +167,12 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThro public function testNonSecurePrePaymentSuccess(): array { - $order = $this->createPaymentOrder(PosInterface::CURRENCY_TRY, 30.0, 3); + $order = $this->createPaymentOrder( + PosInterface::MODEL_NON_SECURE, + PosInterface::CURRENCY_TRY, + 30.0, + 3 + ); $eventIsThrown = false; $this->eventDispatcher->addListener( @@ -229,6 +234,7 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThro public function testNonSecurePaymentRecurringSuccess(): array { $order = $this->createPaymentOrder( + PosInterface::MODEL_NON_SECURE, PosInterface::CURRENCY_TRY, 5, 3, diff --git a/tests/Functional/EstV3PosTest.php b/tests/Functional/EstV3PosTest.php index 4d0e9e25..9edc31ac 100644 --- a/tests/Functional/EstV3PosTest.php +++ b/tests/Functional/EstV3PosTest.php @@ -62,7 +62,7 @@ protected function setUp(): void public function testNonSecurePaymentSuccess(): array { - $order = $this->createPaymentOrder(); + $order = $this->createPaymentOrder(PosInterface::MODEL_NON_SECURE); $eventIsThrown = false; $this->eventDispatcher->addListener( @@ -147,7 +147,12 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThro public function testNonSecurePrePaymentSuccess(): array { - $order = $this->createPaymentOrder(PosInterface::CURRENCY_TRY, 2.01, 3); + $order = $this->createPaymentOrder( + PosInterface::MODEL_NON_SECURE, + PosInterface::CURRENCY_TRY, + 2.01, + 3 + ); $eventIsThrown = false; $this->eventDispatcher->addListener( @@ -267,7 +272,7 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThro public function testGet3DFormData(): void { - $order = $this->createPaymentOrder(); + $order = $this->createPaymentOrder(PosInterface::MODEL_3D_SECURE); $eventIsThrown = false; $this->eventDispatcher->addListener( diff --git a/tests/Functional/GarantiPosTest.php b/tests/Functional/GarantiPosTest.php index a9395886..82c7771b 100644 --- a/tests/Functional/GarantiPosTest.php +++ b/tests/Functional/GarantiPosTest.php @@ -65,7 +65,7 @@ protected function setUp(): void public function testNonSecurePaymentSuccess(): array { - $order = $this->createPaymentOrder(); + $order = $this->createPaymentOrder(PosInterface::MODEL_NON_SECURE); $eventIsThrown = false; $this->eventDispatcher->addListener( @@ -148,7 +148,12 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThro public function testNonSecurePrePaymentSuccess(): array { - $order = $this->createPaymentOrder(PosInterface::CURRENCY_TRY, 1.91, 3); + $order = $this->createPaymentOrder( + PosInterface::MODEL_NON_SECURE, + PosInterface::CURRENCY_TRY, + 1.91, + 3 + ); $eventIsThrown = false; $this->eventDispatcher->addListener( @@ -207,7 +212,7 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThro public function testGet3DFormData(): void { - $order = $this->createPaymentOrder(); + $order = $this->createPaymentOrder(PosInterface::MODEL_3D_SECURE); $eventIsThrown = false; $this->eventDispatcher->addListener( diff --git a/tests/Functional/KuveytPosTest.php b/tests/Functional/KuveytPosTest.php index 7846545f..fb4cf3fe 100644 --- a/tests/Functional/KuveytPosTest.php +++ b/tests/Functional/KuveytPosTest.php @@ -62,7 +62,7 @@ protected function setUp(): void */ public function testCreate3DFormData(): void { - $order = $this->createPaymentOrder(); + $order = $this->createPaymentOrder(PosInterface::MODEL_3D_SECURE); $eventIsThrown = false; $this->eventDispatcher->addListener( @@ -142,7 +142,7 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThro public function testNonSecurePaymentSuccess(): array { - $order = $this->createPaymentOrder(); + $order = $this->createPaymentOrder(PosInterface::MODEL_NON_SECURE); $this->eventDispatcher->addListener( RequestDataPreparedEvent::class, diff --git a/tests/Functional/PayForPosTest.php b/tests/Functional/PayForPosTest.php index 7da81c8e..42bb67ec 100644 --- a/tests/Functional/PayForPosTest.php +++ b/tests/Functional/PayForPosTest.php @@ -61,7 +61,7 @@ protected function setUp(): void public function testNonSecurePaymentSuccess(): array { - $order = $this->createPaymentOrder(); + $order = $this->createPaymentOrder(PosInterface::MODEL_NON_SECURE); $eventIsThrown = false; $this->eventDispatcher->addListener( @@ -192,7 +192,12 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThro public function testNonSecurePrePaymentSuccess(): array { - $order = $this->createPaymentOrder(PosInterface::CURRENCY_TRY, 2.01, 3); + $order = $this->createPaymentOrder( + PosInterface::MODEL_NON_SECURE, + PosInterface::CURRENCY_TRY, + 2.01, + 3 + ); $eventIsThrown = false; $this->eventDispatcher->addListener( @@ -253,7 +258,7 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThro public function testGet3DFormData(): void { - $order = $this->createPaymentOrder(); + $order = $this->createPaymentOrder(PosInterface::MODEL_3D_SECURE); $eventIsThrown = false; $this->eventDispatcher->addListener( diff --git a/tests/Functional/PaymentTestTrait.php b/tests/Functional/PaymentTestTrait.php index 9c454f20..2f514b5b 100644 --- a/tests/Functional/PaymentTestTrait.php +++ b/tests/Functional/PaymentTestTrait.php @@ -16,6 +16,7 @@ trait PaymentTestTrait { private function createPaymentOrder( + string $paymentModel, string $currency = PosInterface::CURRENCY_TRY, float $amount = 1.01, int $installment = 0, @@ -35,10 +36,18 @@ private function createPaymentOrder( 'currency' => $currency, 'installment' => $installment, 'ip' => '127.0.0.1', - 'success_url' => 'http:localhost/response.php', - 'fail_url' => 'http:localhost/response.php', ]; + if (\in_array($paymentModel, [ + PosInterface::MODEL_3D_SECURE, + PosInterface::MODEL_3D_PAY, + PosInterface::MODEL_3D_HOST, + PosInterface::MODEL_3D_PAY_HOSTING, + ], true)) { + $order['success_url'] = 'http:localhost/response.php'; + $order['fail_url'] = 'http:localhost/response.php'; + } + if ($tekrarlanan) { // Desteleyen Gatewayler: GarantiPos, EstPos, EstV3Pos, PayFlexV4 diff --git a/tests/Functional/ToslaPosTest.php b/tests/Functional/ToslaPosTest.php index 5490e8f3..5c9f1bad 100644 --- a/tests/Functional/ToslaPosTest.php +++ b/tests/Functional/ToslaPosTest.php @@ -59,7 +59,7 @@ protected function setUp(): void public function testNonSecurePaymentSuccess(): array { - $order = $this->createPaymentOrder(); + $order = $this->createPaymentOrder(PosInterface::MODEL_NON_SECURE); $this->eventDispatcher->addListener( RequestDataPreparedEvent::class, @@ -168,7 +168,7 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThro public function testGet3DFormData(): void { - $order = $this->createPaymentOrder(); + $order = $this->createPaymentOrder(PosInterface::MODEL_3D_SECURE); $eventIsThrown = false; $this->eventDispatcher->addListener( @@ -190,7 +190,7 @@ function (RequestDataPreparedEvent $requestDataPreparedEvent) use (&$eventIsThro public function testPartialRefundSuccess(): array { - $order = $this->createPaymentOrder(); + $order = $this->createPaymentOrder(PosInterface::MODEL_NON_SECURE); $this->pos->payment( PosInterface::MODEL_NON_SECURE, From 8b095bdb28b2ed02e20584ffefcc164e70c87606 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 12 May 2024 13:55:58 +0200 Subject: [PATCH 2/9] refactor examples, tests, docs --- README.md | 36 ++- config/pos_test.php | 6 +- docs/CANCEL-EXAMPLE.md | 6 +- docs/HISTORY-EXAMPLE.md | 11 +- docs/NON-SECURE-PAYMENT-EXAMPLE.md | 3 +- docs/ORDER-HISTORY-EXAMPLE.md | 10 +- docs/PRE-AUTH-POST-EXAMPLE.md | 17 +- docs/REFUND-EXAMPLE.md | 7 +- docs/STATUS-EXAMPLE.md | 6 +- docs/THREED-PAYMENT-EXAMPLE.md | 27 +- ...URE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md | 4 +- examples/_common-codes/3d-host/index.php | 60 ++-- examples/_common-codes/3d/form.php | 278 ++++++++++-------- examples/_common-codes/regular/cancel.php | 3 +- examples/_common-codes/regular/history.php | 12 +- .../_common-codes/regular/order_history.php | 16 +- examples/_common-codes/regular/refund.php | 4 +- examples/_common-codes/regular/status.php | 3 +- examples/_templates/_credit_card_form.php | 4 +- .../_templates/_finish_non_secure_payment.php | 56 ++-- .../_finish_non_secure_post_auth_payment.php | 3 +- .../_templates/_payment_secure_response.php | 64 ++-- examples/payten/3d-host/_config.php | 2 +- examples/payten/3d-pay-hosting/_config.php | 2 +- examples/payten/3d-pay/_config.php | 2 +- examples/payten/3d/_config.php | 2 +- examples/payten/regular/_config.php | 2 +- examples/posnet-ykb/_payment_config.php | 15 +- src/Gateways/PayFlexV4Pos.php | 2 + tests/Functional/EstV3PosTest.php | 2 +- tests/Functional/KuveytPosTest.php | 2 +- tests/Functional/PaymentTestTrait.php | 2 +- .../EstV3PosRequestDataMapperTest.php | 2 +- 33 files changed, 369 insertions(+), 302 deletions(-) diff --git a/README.md b/README.md index 5a42f288..543489f8 100644 --- a/README.md +++ b/README.md @@ -10,21 +10,21 @@ sistemlerinin kullanılabilmesidir. ### Deskteklenen Payment Gateway'ler / Bankalar: -| Gateway | Desktekleyen
bankalar | Desteklenen
Ödeme Tipleri | Desteklenen Sorgular | -|-------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|---------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------| -| Tosla (AKÖde) | ? | NonSecure
3DPay
3DHost | İptal
İade
Durum sorgulama
Sipariş Tarihçesini sorgulama | -| AkbankPos | Akbank | NonSecure
3DSecur
3DPay
3DHost
Tekrarlanan Ödeme | İptal
İade
Sipariş Tarihçesini sorgulama
Geçmiş İşlemleri sorgulama | -| EST POS
(Asseco/Payten)
_deprecated_ | Akbank
TEB
İşbank
Şekerbank
Halkbank
Finansbank
Ziraat | NonSecure
3DSecure
3DPay
3DHost
3DPayHost
Tekrarlanan Ödeme | İptal
İade
Durum sorgulama
Sipariş Tarihçesini sorgulama | -| EST V3 POS

EstPos altyapının
daha güvenli
(sha512) hash
algoritmasıyla
uygulaması. | -----"----- | -----"----- | -----"----- | -| PayFlex MPI VPOS V4 | Ziraat
Vakıfbank
İşbank | NonSecure
3DSecure
Tekrarlanan Ödeme | İptal
İade
Durum sorgulama | -| PayFlex
Common Payment V4
(Ortak Ödeme) | Ziraat
Vakıfbank
İşbank | NonSecure
3DPay
3DHost | İptal
İade | -| Garanti Virtual POS | Garanti | NonSecure
3DSecure
3DPay
3DHost
Tekrarlanan Ödeme | İptal
İade
Durum sorgulama
Sipariş Tarihçesini sorgulama | -| PosNet | YapıKredi | NonSecure
3DSecure
| İptal
İade
Durum sorgulama | -| PosNetV1
(JSON API) | Albaraka Türk | NonSecure
3DSecure | İptal
İade
Durum sorgulama | -| PayFor | Finansbank
Enpara | NonSecure
3DSecure
3DPay
3DHost | İptal
İade
Durum sorgulama
Sipariş Tarihçesini sorgulama
Geçmiş İşlemleri sorgulama | -| InterPOS | Deniz bank | NonSecure
3DSecure
3DPay
3DHost | İptal
İade
Durum sorgulama | -| Kuveyt POS TDV2.0.0 | Kuveyt Türk | NonSecure
3DSecure | İptal
İade
Durum sorgulama
(SOAP API) | -| VakifKatilimPos
(test edilmesi gerekiyor) | Vakıf Katılım | NonSecure
3DSecure
3DHost | İptal
İade
Durum sorgulama
Sipariş Tarihçesini sorgulama
Geçmiş İşlemleri sorgulama | +| Gateway | Desktekleyen
bankalar | Desteklenen
Ödeme Tipleri | Desteklenen Sorgular | +|------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|---------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------| +| Tosla (AKÖde) | ? | NonSecure
3DPay
3DHost | İptal
İade
Durum sorgulama
Sipariş Tarihçesini sorgulama | +| AkbankPos | Akbank | NonSecure
3DSecur
3DPay
3DHost
Tekrarlanan Ödeme | İptal
İade
Sipariş Tarihçesini sorgulama
Geçmiş İşlemleri sorgulama | +| EST POS
(Asseco/Payten)
_deprecated_
| Akbank
TEB
İşbank
Şekerbank
Halkbank
Finansbank
Ziraat | NonSecure
3DSecure
3DPay
3DHost
3DPayHost
Tekrarlanan Ödeme | İptal
İade
Durum sorgulama
Sipariş Tarihçesini sorgulama | +| EST V3 POS

EstPos altyapının
daha güvenli
(sha512) hash
algoritmasıyla
uygulaması.
| -----"----- | -----"----- | -----"----- | +| PayFlex MPI VPOS V4 | Ziraat
Vakıfbank VPOS 7/24
İşbank | NonSecure
3DSecure
Tekrarlanan Ödeme | İptal
İade
Durum sorgulama | +| PayFlex
Common Payment V4
(Ortak Ödeme) | Ziraat
Vakıfbank
İşbank | NonSecure
3DPay
3DHost | İptal
İade | +| Garanti Virtual POS | Garanti | NonSecure
3DSecure
3DPay
3DHost
Tekrarlanan Ödeme | İptal
İade
Durum sorgulama
Sipariş Tarihçesini sorgulama | +| PosNet | YapıKredi | NonSecure
3DSecure
| İptal
İade
Durum sorgulama | +| PosNetV1
(JSON API) | Albaraka Türk | NonSecure
3DSecure | İptal
İade
Durum sorgulama | +| PayFor | Finansbank
Enpara | NonSecure
3DSecure
3DPay
3DHost | İptal
İade
Durum sorgulama
Sipariş Tarihçesini sorgulama
Geçmiş İşlemleri sorgulama | +| InterPOS | Deniz bank | NonSecure
3DSecure
3DPay
3DHost | İptal
İade
Durum sorgulama | +| Kuveyt POS TDV2.0.0 | Kuveyt Türk | NonSecure
3DSecure | İptal
İade
Durum sorgulama
(SOAP API) | +| VakifKatilimPos
(test edilmesi gerekiyor) | Vakıf Katılım | NonSecure
3DSecure
3DHost | İptal
İade
Durum sorgulama
Sipariş Tarihçesini sorgulama
Geçmiş İşlemleri sorgulama | ### Ana başlıklar @@ -316,12 +316,10 @@ $pos = \Mews\Pos\Factory\PosFactory::createPosGateway( 1. Makinenizde Docker kurulu olması gerekir. 2. Projenin root klasöründe `docker-compose up -d` komutu çalıştırınız. -3. ```sh - $ composer require mews/pos - ``` +3. docker container'de `composer install` çalıştırınız. **Note**: localhost port 80 boş olması gerekiyor. -Sorunsuz çalışması durumda kod örneklerine http://localhost/estpos/3d/index.php +Sorunsuz çalışması durumda kod örneklerine http://localhost/payten/3d/index.php şekilde erişebilirsiniz. http://localhost/ URL projenin `examples` klasörünün içine bakar. diff --git a/config/pos_test.php b/config/pos_test.php index 285837fc..cad0b698 100644 --- a/config/pos_test.php +++ b/config/pos_test.php @@ -11,9 +11,9 @@ 'gateway_3d_host' => 'https://virtualpospaymentgatewaypre.akbank.com/payhosting', ], ], - 'akbankv3' => [ + 'payten_v3_hash' => [ 'name' => 'AKBANK T.A.S.', - 'class' => Mews\Pos\Gateways\EstPos::class, + 'class' => Mews\Pos\Gateways\EstV3Pos::class, 'gateway_endpoints' => [ 'payment_api' => 'https://entegrasyon.asseco-see.com.tr/fim/api', 'gateway_3d' => 'https://entegrasyon.asseco-see.com.tr/fim/est3Dgate', @@ -114,7 +114,7 @@ 'query_api' => 'https://boatest.kuveytturk.com.tr/BOA.Integration.WCFService/BOA.Integration.VirtualPos/VirtualPosService.svc?wsdl', ], ], - 'vakif-katilim' => [ + 'vakif-katilim' => [ 'name' => 'Vakıf Katılım', 'class' => Mews\Pos\Gateways\VakifKatilimPos::class, 'gateway_endpoints' => [ diff --git a/docs/CANCEL-EXAMPLE.md b/docs/CANCEL-EXAMPLE.md index 5cc3961a..fbf764c2 100644 --- a/docs/CANCEL-EXAMPLE.md +++ b/docs/CANCEL-EXAMPLE.md @@ -11,7 +11,8 @@ $ cp ./vendor/mews/pos/config/pos_test.php ./pos_test_ayarlar.php require './vendor/autoload.php'; // API kullanıcı bilgileri -// AccountFactory'de kullanılacak method Gateway'e göre değişir. Örnek kodlara bakınız. +// AccountFactory'de kullanılacak method Gateway'e göre değişir!!! +// /examples altındaki örnek kodlara bakınız. $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', //pos config'deki ayarın index name'i 'yourClientID', @@ -69,8 +70,7 @@ function createCancelOrder(string $gatewayClass, array $lastResponse, string $ip $cancelOrder['transaction_id'] = $lastResponse['transaction_id']; } elseif (\Mews\Pos\Gateways\PosNetV1Pos::class === $gatewayClass || \Mews\Pos\Gateways\PosNet::class === $gatewayClass) { /** - * payment_model: - * siparis olusturulurken kullanilan odeme modeli + * payment_model: siparis olusturulurken kullanilan odeme modeli. * orderId'yi dogru şekilde formatlamak icin zorunlu. */ $cancelOrder['payment_model'] = $lastResponse['payment_model']; diff --git a/docs/HISTORY-EXAMPLE.md b/docs/HISTORY-EXAMPLE.md index 768e19a9..a3e5434f 100644 --- a/docs/HISTORY-EXAMPLE.md +++ b/docs/HISTORY-EXAMPLE.md @@ -11,7 +11,8 @@ $ cp ./vendor/mews/pos/config/pos_test.php ./pos_test_ayarlar.php require './vendor/autoload.php'; // API kullanıcı bilgileri -// AccountFactory'de kullanılacak method Gateway'e göre değişir. Örnek kodlara bakınız. +// AccountFactory'de kullanılacak method Gateway'e göre değişir!!! +// /examples altındaki örnek kodlara bakınız. $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', //pos config'deki ayarın index name'i 'yourClientID', @@ -45,15 +46,14 @@ require 'config.php'; function createHistoryOrder(string $gatewayClass, array $extraData): array { - $order = []; - + $order = []; + $txTime = new \DateTimeImmutable(); if (\Mews\Pos\Gateways\PayForPos::class === $gatewayClass) { $order = [ // odeme tarihi - 'transaction_date' => $extraData['transaction_date'] ?? new \DateTimeImmutable(), + 'transaction_date' => $extraData['transaction_date'] ?? $txTime, ]; } elseif (\Mews\Pos\Gateways\VakifKatilimPos::class === $gatewayClass) { - $txTime = new \DateTimeImmutable(); $order = [ 'page' => 1, 'page_size' => 20, @@ -61,7 +61,6 @@ function createHistoryOrder(string $gatewayClass, array $extraData): array 'end_date' => $txTime->modify('+1 day'), ]; } elseif (\Mews\Pos\Gateways\AkbankPos::class === $gatewayClass) { - $txTime = new \DateTimeImmutable(); $order = [ // Gün aralığı 1 günden fazla girilemez 'start_date' => $txTime->modify('-23 hour'), diff --git a/docs/NON-SECURE-PAYMENT-EXAMPLE.md b/docs/NON-SECURE-PAYMENT-EXAMPLE.md index 948ef404..42941560 100644 --- a/docs/NON-SECURE-PAYMENT-EXAMPLE.md +++ b/docs/NON-SECURE-PAYMENT-EXAMPLE.md @@ -14,7 +14,8 @@ $paymentModel = \Mews\Pos\PosInterface::MODEL_NON_SECURE; $transactionType = \Mews\Pos\PosInterface::TX_TYPE_PAY_AUTH; // API kullanıcı bilgileri -// AccountFactory'de kullanılacak method Gateway'e göre değişir. Örnek kodlara bakınız. +// AccountFactory'de kullanılacak method Gateway'e göre değişir!!! +// /examples altındaki örnek kodlara bakınız. $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', //pos config'deki ayarın index name'i 'yourClientID', diff --git a/docs/ORDER-HISTORY-EXAMPLE.md b/docs/ORDER-HISTORY-EXAMPLE.md index 064bbcd3..cb4230d9 100644 --- a/docs/ORDER-HISTORY-EXAMPLE.md +++ b/docs/ORDER-HISTORY-EXAMPLE.md @@ -11,7 +11,8 @@ $ cp ./vendor/mews/pos/config/pos_test.php ./pos_test_ayarlar.php require './vendor/autoload.php'; // API kullanıcı bilgileri -// AccountFactory'de kullanılacak method Gateway'e göre değişir. Örnek kodlara bakınız. +// AccountFactory'de kullanılacak method Gateway'e göre değişir!!! +// /examples altındaki örnek kodlara bakınız. $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', //pos config'deki ayarın index name'i 'yourClientID', @@ -94,7 +95,12 @@ $lastResponse = $session->get('last_response'); $order = createOrderHistoryOrder(get_class($pos), $lastResponse); -$pos->orderHistory($order); +try { + $pos->orderHistory($order); +} catch (\Error $e) { + var_dump($e); + exit; +} $response = $pos->getResponse(); var_dump($response); ``` diff --git a/docs/PRE-AUTH-POST-EXAMPLE.md b/docs/PRE-AUTH-POST-EXAMPLE.md index 18445fae..58017fd7 100644 --- a/docs/PRE-AUTH-POST-EXAMPLE.md +++ b/docs/PRE-AUTH-POST-EXAMPLE.md @@ -22,7 +22,8 @@ $paymentModel = \Mews\Pos\PosInterface::MODEL_3D_SECURE; $transactionType = \Mews\Pos\PosInterface::TX_TYPE_PAY_PRE_AUTH; // API kullanıcı bilgileri -// AccountFactory'de kullanılacak method Gateway'e göre değişir. Örnek kodlara bakınız. +// AccountFactory'de kullanılacak method Gateway'e göre değişir!!! +// /examples altındaki örnek kodlara bakınız. $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', //pos config'deki ayarın index name'i 'yourClientID', @@ -114,7 +115,7 @@ try { $transactionType, $card ); -} catch (\Throwable $e) { +} catch (\Exception|\Error $e) { var_dump($e); exit; } @@ -177,6 +178,9 @@ try { } catch (\Mews\Pos\Exceptions\HashMismatchException $e) { // Bankadan gelen verilerin bankaya ait olmadığında bu exception oluşur. // Banka API bilgileriniz hatalı ise de oluşur. +} catch (\Exception|\Error $e) { + var_dump($e); + exit; } ``` @@ -226,6 +230,9 @@ $order = createPostPayOrder( $postAuthAmount ); +// ============================================================================================ +// OZEL DURUMLAR ICIN KODLAR START +// ============================================================================================ /** @var \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher */ $eventDispatcher->addListener( \Mews\Pos\Event\RequestDataPreparedEvent::class, @@ -239,10 +246,14 @@ $eventDispatcher->addListener( } } }); +// ============================================================================================ +// OZEL DURUMLAR ICIN KODLAR END +// ============================================================================================ + try { $pos->payment($paymentModel, $order, $transaction); var_dump($response); -catch (\Exception $e) { +} catch (\Exception|\Error $e) { var_dump($e); exit; } diff --git a/docs/REFUND-EXAMPLE.md b/docs/REFUND-EXAMPLE.md index 704aa488..b7b529b5 100644 --- a/docs/REFUND-EXAMPLE.md +++ b/docs/REFUND-EXAMPLE.md @@ -11,7 +11,8 @@ $ cp ./vendor/mews/pos/config/pos_test.php ./pos_test_ayarlar.php require './vendor/autoload.php'; // API kullanıcı bilgileri -// AccountFactory'de kullanılacak method Gateway'e göre değişir. Örnek kodlara bakınız. +// AccountFactory'de kullanılacak method Gateway'e göre değişir!!! +// /examples altındaki örnek kodlara bakınız. $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', //pos config'deki ayarın index name'i 'yourClientID', @@ -59,7 +60,6 @@ function createRefundOrder(string $gatewayClass, array $lastResponse, string $ip $refundOrder['transaction_id'] = $lastResponse['transaction_id']; } elseif (\Mews\Pos\Gateways\VakifKatilimPos::class === $gatewayClass) { $refundOrder['remote_order_id'] = $lastResponse['remote_order_id']; // banka tarafındaki order id - $refundOrder['amount'] = $lastResponse['amount']; // on otorizasyon islemin iadesi icin PosInterface::TX_TYPE_PAY_PRE_AUTH saglanmasi gerekiyor $refundOrder['transaction_type'] = $lastResponse['transaction_type'] ?? PosInterface::TX_TYPE_PAY_AUTH; } elseif (\Mews\Pos\Gateways\PayFlexV4Pos::class === $gatewayClass || \Mews\Pos\Gateways\PayFlexCPV4Pos::class === $gatewayClass) { @@ -67,8 +67,7 @@ function createRefundOrder(string $gatewayClass, array $lastResponse, string $ip $refundOrder['transaction_id'] = $lastResponse['transaction_id']; } elseif (\Mews\Pos\Gateways\PosNetV1Pos::class === $gatewayClass || \Mews\Pos\Gateways\PosNet::class === $gatewayClass) { /** - * payment_model: - * siparis olusturulurken kullanilan odeme modeli + * payment_model: siparis olusturulurken kullanilan odeme modeli. * orderId'yi dogru şekilde formatlamak icin zorunlu. */ $refundOrder['payment_model'] = $lastResponse['payment_model']; diff --git a/docs/STATUS-EXAMPLE.md b/docs/STATUS-EXAMPLE.md index 08bdb785..1dbdc183 100644 --- a/docs/STATUS-EXAMPLE.md +++ b/docs/STATUS-EXAMPLE.md @@ -11,7 +11,8 @@ $ cp ./vendor/mews/pos/config/pos_test.php ./pos_test_ayarlar.php require './vendor/autoload.php'; // API kullanıcı bilgileri -// AccountFactory'de kullanılacak method Gateway'e göre değişir. Örnek kodlara bakınız. +// AccountFactory'de kullanılacak method Gateway'e göre değişir!!! +// /examples altındaki örnek kodlara bakınız. $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', //pos config'deki ayarın index name'i 'yourClientID', @@ -55,8 +56,7 @@ function createStatusOrder(string $gatewayClass, array $lastResponse, string $ip } if (\Mews\Pos\Gateways\PosNetV1Pos::class === $gatewayClass || \Mews\Pos\Gateways\PosNet::class === $gatewayClass) { /** - * payment_model: - * siparis olusturulurken kullanilan odeme modeli + * payment_model: siparis olusturulurken kullanilan odeme modeli. * orderId'yi dogru sekilde formatlamak icin zorunlu. */ $statusOrder['payment_model'] = $lastResponse['payment_model']; diff --git a/docs/THREED-PAYMENT-EXAMPLE.md b/docs/THREED-PAYMENT-EXAMPLE.md index 888f9e38..b1714a4a 100644 --- a/docs/THREED-PAYMENT-EXAMPLE.md +++ b/docs/THREED-PAYMENT-EXAMPLE.md @@ -30,7 +30,8 @@ $paymentModel = \Mews\Pos\PosInterface::MODEL_3D_SECURE; $transactionType = \Mews\Pos\PosInterface::TX_TYPE_PAY_AUTH; // API kullanıcı bilgileri -// AccountFactory'de kullanılacak method Gateway'e göre değişir. Örnek kodlara bakınız. +// AccountFactory'de kullanılacak method Gateway'e göre değişir!!! +// /examples altındaki örnek kodlara bakınız. $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', //pos config'deki ayarın index name'i 'yourClientID', @@ -99,10 +100,10 @@ if ($tekrarlanan = false) { // recurring payments $session->set('order', $order); // Kredi kartı bilgileri -try { $card = null; if (\Mews\Pos\PosInterface::MODEL_3D_HOST !== $paymentModel) { - $card = \Mews\Pos\Factory\CreditCardFactory::createForGateway( + try { + $card = \Mews\Pos\Factory\CreditCardFactory::createForGateway( $pos, $_POST['card_number'], $_POST['card_year'], @@ -126,6 +127,9 @@ if (\Mews\Pos\PosInterface::MODEL_3D_HOST !== $paymentModel) { } } +// ============================================================================================ +// OZEL DURUMLAR ICIN KODLAR START +// ============================================================================================ try { /** @var \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher */ $eventDispatcher->addListener(RequestDataPreparedEvent::class, function (RequestDataPreparedEvent $event) { @@ -211,10 +215,13 @@ try { $transactionType, $card ); -} catch (\Throwable $e) { +} catch (\Exception|\Error $e) { var_dump($e); exit; } +// ============================================================================================ +// OZEL DURUMLAR ICIN KODLAR END +// ============================================================================================ ``` ```html @@ -263,6 +270,10 @@ if (\Mews\Pos\PosInterface::MODEL_3D_HOST !== $paymentModel) { } } +// ============================================================================================ +// OZEL DURUMLAR ICIN KODLAR START +// ============================================================================================ + // //Isbank İMECE kart ile MODEL_3D_SECURE yöntemiyle ödeme için ekstra alanların eklenme örneği // $eventDispatcher->addListener(RequestDataPreparedEvent::class, function (RequestDataPreparedEvent $event) use ($paymentModel) { // if ($event->getTxType() === \Mews\Pos\PosInterface::TX_TYPE_PAY_AUTH && \Mews\Pos\PosInterface::MODEL_3D_SECURE === $paymentModel) { @@ -273,6 +284,11 @@ if (\Mews\Pos\PosInterface::MODEL_3D_HOST !== $paymentModel) { // } // }); +// ============================================================================================ +// OZEL DURUMLAR ICIN KODLAR END +// ============================================================================================ + + // Ödeme tamamlanıyor, try { $pos->payment( @@ -296,5 +312,8 @@ try { } catch (\Mews\Pos\Exceptions\HashMismatchException $e) { // Bankadan gelen verilerin bankaya ait olmadığında bu exception oluşur. // Banka API bilgileriniz hatalı ise de oluşur. +} catch (\Error $e) { + var_dump($e); + exit; } ``` diff --git a/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md b/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md index ccebf35c..75a50264 100644 --- a/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md +++ b/docs/THREED-SECURE-AND-PAY-PAYMENT-IN-MODALBOX-EXAMPLE.md @@ -28,8 +28,8 @@ $session->start(); $paymentModel = \Mews\Pos\PosInterface::MODEL_3D_SECURE; $transactionType = \Mews\Pos\PosInterface::TX_TYPE_PAY_AUTH; -// API kullanıcı bilgileri -// AccountFactory'de kullanılacak method Gateway'e göre değişir. Örnek kodlara bakınız. +// AccountFactory'de kullanılacak method Gateway'e göre değişir!!! +// /examples altındaki örnek kodlara bakınız. $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( 'akbank', //pos config'deki ayarın index name'i 'yourClientID', diff --git a/examples/_common-codes/3d-host/index.php b/examples/_common-codes/3d-host/index.php index d2da1de6..1e86d75a 100644 --- a/examples/_common-codes/3d-host/index.php +++ b/examples/_common-codes/3d-host/index.php @@ -22,38 +22,44 @@ ); $session->set('order', $order); -/** @var \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher */ -$eventDispatcher->addListener(RequestDataPreparedEvent::class, function (RequestDataPreparedEvent $event) { - /** - * Burda istek banka API'na gonderilmeden once gonderilecek veriyi degistirebilirsiniz. - * Ornek: - * if ($event->getTxType() === PosInterface::TX_TYPE_PAY_AUTH) { - * $data = $event->getRequestData(); - * $data['abcd'] = '1234'; - * $event->setRequestData($data); - * } - * - * Bu asamada bu Event sadece PosNet, PayFlexCPV4Pos, PayFlexV4Pos, KuveytPos gatewayler'de trigger edilir. - */ -}); +$formVerisiniOlusturmakIcinApiIstegiGonderenGatewayler = [ + \Mews\Pos\Gateways\PosNet::class, + \Mews\Pos\Gateways\KuveytPos::class, + \Mews\Pos\Gateways\ToslaPos::class, + \Mews\Pos\Gateways\VakifKatilimPos::class, + \Mews\Pos\Gateways\PayFlexV4Pos::class, + \Mews\Pos\Gateways\PayFlexCPV4Pos::class, +]; +if (in_array(get_class($pos), $formVerisiniOlusturmakIcinApiIstegiGonderenGatewayler, true)) { + /** @var \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher */ + $eventDispatcher->addListener(RequestDataPreparedEvent::class, function (RequestDataPreparedEvent $event) { +// // Burda istek banka API'na gonderilmeden once gonderilecek veriyi degistirebilirsiniz. +// // Ornek: +// if ($event->getTxType() === PosInterface::TX_TYPE_PAY_AUTH) { +// $data = $event->getRequestData(); +// $data['abcd'] = '1234'; +// $event->setRequestData($data); +// } + }); +} + /** * Bu Event'i dinleyerek 3D formun hash verisi hesaplanmadan önce formun input array içireğini güncelleyebilirsiniz. */ $eventDispatcher->addListener(Before3DFormHashCalculatedEvent::class, function (Before3DFormHashCalculatedEvent $event) { - /** - * Örneğin İşbank İmece Kart ile ödeme yaparken aşağıdaki verilerin eklenmesi gerekiyor: - * $supportedPaymentModels = [ - * \Mews\Pos\Gateways\PosInterface::MODEL_3D_PAY, - * \Mews\Pos\Gateways\PosInterface::MODEL_3D_PAY_HOSTING, - * \Mews\Pos\Gateways\PosInterface::MODEL_3D_HOST, - * ]; - * if ($event->getTxType() === PosInterface::TX_TYPE_PAY_AUTH && in_array($event->getPaymentModel(), $supportedPaymentModels, true)) { - * $formInputs = $event->getFormInputs(); - * $formInputs['IMCKOD'] = '9999'; // IMCKOD bilgisi bankadan alınmaktadır. - * $formInputs['FDONEM'] = '5'; // Ödemenin faizsiz ertelenmesini istediğiniz dönem sayısı. - * $event->setFormInputs($formInputs); - * }*/ + // Örneğin İşbank İmece Kart ile ödeme yaparken aşağıdaki verilerin eklenmesi gerekiyor: +// $supportedPaymentModels = [ +// \Mews\Pos\PosInterface::MODEL_3D_PAY, +// \Mews\Pos\PosInterface::MODEL_3D_PAY_HOSTING, +// \Mews\Pos\PosInterface::MODEL_3D_HOST, +// ]; +// if ($event->getTxType() === PosInterface::TX_TYPE_PAY_AUTH && in_array($event->getPaymentModel(), $supportedPaymentModels, true)) { +// $formInputs = $event->getFormInputs(); +// $formInputs['IMCKOD'] = '9999'; // IMCKOD bilgisi bankadan alınmaktadır. +// $formInputs['FDONEM'] = '5'; // Ödemenin faizsiz ertelenmesini istediğiniz dönem sayısı. +// $event->setFormInputs($formInputs); +// } }); try { diff --git a/examples/_common-codes/3d/form.php b/examples/_common-codes/3d/form.php index be911bf6..1d6e8eab 100644 --- a/examples/_common-codes/3d/form.php +++ b/examples/_common-codes/3d/form.php @@ -41,157 +41,175 @@ $session->set('card', $request->request->all()); } -try { - +// ============================================================================================ +// OZEL DURUMLAR ICIN KODLAR START +// ============================================================================================ + +$formVerisiniOlusturmakIcinApiIstegiGonderenGatewayler = [ + \Mews\Pos\Gateways\PosNet::class, + \Mews\Pos\Gateways\KuveytPos::class, + \Mews\Pos\Gateways\ToslaPos::class, + \Mews\Pos\Gateways\VakifKatilimPos::class, + \Mews\Pos\Gateways\PayFlexV4Pos::class, + \Mews\Pos\Gateways\PayFlexCPV4Pos::class, +]; +if (in_array(get_class($pos), $formVerisiniOlusturmakIcinApiIstegiGonderenGatewayler, true)) { /** @var \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher */ $eventDispatcher->addListener(RequestDataPreparedEvent::class, function (RequestDataPreparedEvent $event) { - /** - * Burda istek banka API'na gonderilmeden once gonderilecek veriyi degistirebilirsiniz. - * Ornek: - * if ($event->getTxType() === PosInterface::TX_TYPE_PAY_AUTH) { - * $data = $event->getRequestData(); - * $data['abcd'] = '1234'; - * $event->setRequestData($data); - * } - * - * Bu asamada bu Event sadece PosNet, PayFlexCPV4Pos, PayFlexV4Pos, KuveytPos, ToslaPos gatewayler'de trigger edilir. - */ - }); + //Burda istek banka API'na gonderilmeden once gonderilecek veriyi degistirebilirsiniz. + // Ornek: +// if ($event->getTxType() === PosInterface::TX_TYPE_PAY_AUTH) { +// $data = $event->getRequestData(); +// $data['abcd'] = '1234'; +// $event->setRequestData($data); +// } + }); +} - // 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', +// 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' => [ /** - * 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. + * Cc: Kullanılan kart ile ilişkili kart hamilinin cep telefonuna ait ülke kodu. 1-3 karakter uzunluğunda olmalıdır. */ - 'BillAddrState' => '40', + 'Cc' => '90', /** - * 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. + * Subscriber: Kullanılan kart ile ilişkili kart hamilinin cep telefonuna ait abone numarası. + * Maksimum 15 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', - ], + 'Subscriber' => '1234567899', ], - ]; - $requestData = $requestDataPreparedEvent->getRequestData(); - $requestData = array_merge_recursive($requestData, $additionalRequestDataForKuveyt); - $requestDataPreparedEvent->setRequestData($requestData); - }); + ], + ]; + $requestData = $requestDataPreparedEvent->getRequestData(); + $requestData = array_merge_recursive($requestData, $additionalRequestDataForKuveyt); + $requestDataPreparedEvent->setRequestData($requestData); + }); - /** - * Bu Event'i dinleyerek 3D formun hash verisi hesaplanmadan önce formun input array içireğini 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) { - /** - * Örnek 1: İşbank İmece Kart ile ödeme yaparken aşağıdaki verilerin eklenmesi gerekiyor: - $supportedPaymentModels = [ - \Mews\Pos\Gateways\PosInterface::MODEL_3D_PAY, - \Mews\Pos\Gateways\PosInterface::MODEL_3D_PAY_HOSTING, - \Mews\Pos\Gateways\PosInterface::MODEL_3D_HOST, - ]; - if ($event->getTxType() === PosInterface::TX_TYPE_PAY_AUTH && in_array($event->getPaymentModel(), $supportedPaymentModels, true)) { - $formInputs = $event->getFormInputs(); - $formInputs['IMCKOD'] = '9999'; // IMCKOD bilgisi bankadan alınmaktadır. - $formInputs['FDONEM'] = '5'; // Ödemenin faizsiz ertelenmesini istediğiniz dönem sayısı. - $event->setFormInputs($formInputs); - }*/ - } - if (get_class($pos) === \Mews\Pos\Gateways\EstV3Pos::class) { + /** + * 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) { + //Örnek 1: İşbank İmece Kart ile ödeme yaparken aşağıdaki verilerin eklenmesi gerekiyor: +// $supportedPaymentModels = [ +// \Mews\Pos\PosInterface::MODEL_3D_PAY, +// \Mews\Pos\PosInterface::MODEL_3D_PAY_HOSTING, +// \Mews\Pos\PosInterface::MODEL_3D_HOST, +// ]; +// if ($event->getTxType() === PosInterface::TX_TYPE_PAY_AUTH && in_array($event->getPaymentModel(), $supportedPaymentModels, true)) { +// $formInputs = $event->getFormInputs(); +// $formInputs['IMCKOD'] = '9999'; // IMCKOD bilgisi bankadan alınmaktadır. +// $formInputs['FDONEM'] = '5'; // Ödemenin faizsiz ertelenmesini istediğiniz dönem sayısı. +// $event->setFormInputs($formInputs); +// } + } + if (get_class($pos) === \Mews\Pos\Gateways\EstV3Pos::class) { // // Örnek 2: callbackUrl eklenmesi // $formInputs = $event->getFormInputs(); // $formInputs['callbackUrl'] = $formInputs['failUrl']; // $formInputs['refreshTime'] = '10'; // birim: saniye; callbackUrl sisteminin doğru çalışması için eklenmesi gereken parametre // $event->setFormInputs($formInputs); - } - }); - - + } + }); +// ============================================================================================ +// OZEL DURUMLAR ICIN KODLAR END +// ============================================================================================ +try { $formData = $pos->get3DFormData($order, $paymentModel, $transaction, $card); + //dd($formData); +} catch (\Throwable $e) { + dd($e); +} - /** - * PosNet vftCode - VFT Kampanya kodunu. Vade Farklı işlemler için kullanılacak olan kampanya kodunu belirler. - * Üye İşyeri için tanımlı olan kampanya kodu, İşyeri Yönetici Ekranlarına giriş - * yapıldıktan sonra, Üye İşyeri bilgileri sayfasından öğrenilebilinir. - */ - if ($pos instanceof \Mews\Pos\Gateways\PosNet) { - // YapiKredi - // $formData['inputs']['vftCode'] = 'xxx'; - } - if ($pos instanceof \Mews\Pos\Gateways\PosNetV1Pos) { - // Albaraka - // $formData['inputs']['VftCode'] = 'xxx'; - } +// ============================================================================================ +// OZEL DURUMLAR ICIN KODLAR START +// ============================================================================================ - /** - * KOICode - Joker Vadaa Kampanya Kodu. - * Degerler - 1: Ek Taksit 2: Taksit Atlatma 3: Ekstra Puan 4: Kontur Kazanım 5: Ekstre Erteleme 6: Özel Vade Farkı - * İşyeri, UseJokerVadaa alanını 1 yaparak bankanın joker vadaa sorgu ve müşteri joker vadaa - * kampanya seçim ekranının açılmasını ve Joker Vadaa kampanya seçiminin müşteriye bırakılmasını - * sağlayabilir. İşyeri, müşterilere ortak ödeme sayfasında kampanya sunulmasını istemiyorsa - * UseJokerVadaa alanını 0 set etmesi gerekir. - */ - if ($pos instanceof \Mews\Pos\Gateways\PosNetV1Pos) { - // Albaraka - // $formData['inputs']['UseJokerVadaa'] = '1'; - // $formData['inputs']['KOICode'] = 'xxx'; - } - if ($pos instanceof \Mews\Pos\Gateways\PosNet) { - // YapiKredi - // $formData['inputs']['useJokerVadaa'] = '1'; - } +/** + * PosNet vftCode - VFT Kampanya kodunu. Vade Farklı işlemler için kullanılacak olan kampanya kodunu belirler. + * Üye İşyeri için tanımlı olan kampanya kodu, İşyeri Yönetici Ekranlarına giriş + * yapıldıktan sonra, Üye İşyeri bilgileri sayfasından öğrenilebilinir. + */ +if ($pos instanceof \Mews\Pos\Gateways\PosNet) { + // YapiKredi + // $formData['inputs']['vftCode'] = 'xxx'; +} +if ($pos instanceof \Mews\Pos\Gateways\PosNetV1Pos) { + // Albaraka + // $formData['inputs']['VftCode'] = 'xxx'; +} - //dd($formData); -} catch (\Throwable $e) { - dd($e); +/** + * KOICode - Joker Vadaa Kampanya Kodu. + * Degerler - 1: Ek Taksit 2: Taksit Atlatma 3: Ekstra Puan 4: Kontur Kazanım 5: Ekstre Erteleme 6: Özel Vade Farkı + * İşyeri, UseJokerVadaa alanını 1 yaparak bankanın joker vadaa sorgu ve müşteri joker vadaa + * kampanya seçim ekranının açılmasını ve Joker Vadaa kampanya seçiminin müşteriye bırakılmasını + * sağlayabilir. İşyeri, müşterilere ortak ödeme sayfasında kampanya sunulmasını istemiyorsa + * UseJokerVadaa alanını 0 set etmesi gerekir. + */ +if ($pos instanceof \Mews\Pos\Gateways\PosNetV1Pos) { + // Albaraka + // $formData['inputs']['UseJokerVadaa'] = '1'; + // $formData['inputs']['KOICode'] = 'xxx'; } +if ($pos instanceof \Mews\Pos\Gateways\PosNet) { + // YapiKredi + // $formData['inputs']['useJokerVadaa'] = '1'; +} +// ============================================================================================ +// OZEL DURUMLAR ICIN KODLAR END +// ============================================================================================ + + $flowType = $request->get('payment_flow_type'); ?> diff --git a/examples/_common-codes/regular/cancel.php b/examples/_common-codes/regular/cancel.php index 6b230c23..f6067cfb 100644 --- a/examples/_common-codes/regular/cancel.php +++ b/examples/_common-codes/regular/cancel.php @@ -35,8 +35,7 @@ function createCancelOrder(string $gatewayClass, array $lastResponse, string $ip $cancelOrder['transaction_id'] = $lastResponse['transaction_id']; } elseif (\Mews\Pos\Gateways\PosNetV1Pos::class === $gatewayClass || \Mews\Pos\Gateways\PosNet::class === $gatewayClass) { /** - * payment_model: - * siparis olusturulurken kullanilan odeme modeli + * payment_model: siparis olusturulurken kullanilan odeme modeli. * orderId'yi dogru şekilde formatlamak icin zorunlu. */ $cancelOrder['payment_model'] = $lastResponse['payment_model']; diff --git a/examples/_common-codes/regular/history.php b/examples/_common-codes/regular/history.php index 8d4faca7..4cb080e1 100644 --- a/examples/_common-codes/regular/history.php +++ b/examples/_common-codes/regular/history.php @@ -1,7 +1,5 @@ $extraData['transaction_date'] ?? new \DateTimeImmutable(), + 'transaction_date' => $extraData['transaction_date'] ?? $txTime, ]; } elseif (\Mews\Pos\Gateways\VakifKatilimPos::class === $gatewayClass) { - $txTime = new \DateTimeImmutable(); $order = [ 'page' => 1, 'page_size' => 20, @@ -31,7 +28,6 @@ function createHistoryOrder(string $gatewayClass, array $extraData): array 'end_date' => $txTime->modify('+1 day'), ]; } elseif (\Mews\Pos\Gateways\AkbankPos::class === $gatewayClass) { - $txTime = new \DateTimeImmutable(); $order = [ // Gün aralığı 1 günden fazla girilemez 'start_date' => $txTime->modify('-23 hour'), diff --git a/examples/_common-codes/regular/order_history.php b/examples/_common-codes/regular/order_history.php index 2aa37669..bea76df5 100644 --- a/examples/_common-codes/regular/order_history.php +++ b/examples/_common-codes/regular/order_history.php @@ -1,11 +1,5 @@ $lastResponse['order_id'], ]; @@ -32,25 +26,25 @@ function createOrderHistoryOrder(string $gatewayClass, array $lastResponse): arr 'id' => $lastResponse['order_id'], ]; } - } elseif (ToslaPos::class === $gatewayClass) { + } elseif (\Mews\Pos\Gateways\ToslaPos::class === $gatewayClass) { $order = [ 'id' => $lastResponse['order_id'], 'transaction_date' => $lastResponse['transaction_time'], // odeme tarihi 'page' => 1, // optional, default: 1 'page_size' => 10, // optional, default: 10 ]; - } elseif (PayForPos::class === $gatewayClass) { + } elseif (\Mews\Pos\Gateways\PayForPos::class === $gatewayClass) { $order = [ 'id' => $lastResponse['order_id'], ]; - } elseif (GarantiPos::class === $gatewayClass) { + } elseif (\Mews\Pos\Gateways\GarantiPos::class === $gatewayClass) { $order = [ 'id' => $lastResponse['order_id'], 'currency' => $lastResponse['currency'], 'ip' => '127.0.0.1', ]; } elseif (\Mews\Pos\Gateways\VakifKatilimPos::class === $gatewayClass) { - /** @var DateTimeImmutable $txTime */ + /** @var \DateTimeImmutable $txTime */ $txTime = $lastResponse['transaction_time']; $order = [ 'auth_code' => $lastResponse['auth_code'], diff --git a/examples/_common-codes/regular/refund.php b/examples/_common-codes/regular/refund.php index 2d87af83..9d076c56 100644 --- a/examples/_common-codes/regular/refund.php +++ b/examples/_common-codes/regular/refund.php @@ -26,7 +26,6 @@ function createRefundOrder(string $gatewayClass, array $lastResponse, string $ip $refundOrder['transaction_id'] = $lastResponse['transaction_id']; } elseif (\Mews\Pos\Gateways\VakifKatilimPos::class === $gatewayClass) { $refundOrder['remote_order_id'] = $lastResponse['remote_order_id']; // banka tarafındaki order id - $refundOrder['amount'] = $lastResponse['amount']; // on otorizasyon islemin iadesi icin PosInterface::TX_TYPE_PAY_PRE_AUTH saglanmasi gerekiyor $refundOrder['transaction_type'] = $lastResponse['transaction_type'] ?? PosInterface::TX_TYPE_PAY_AUTH; } elseif (\Mews\Pos\Gateways\PayFlexV4Pos::class === $gatewayClass || \Mews\Pos\Gateways\PayFlexCPV4Pos::class === $gatewayClass) { @@ -34,8 +33,7 @@ function createRefundOrder(string $gatewayClass, array $lastResponse, string $ip $refundOrder['transaction_id'] = $lastResponse['transaction_id']; } elseif (\Mews\Pos\Gateways\PosNetV1Pos::class === $gatewayClass || \Mews\Pos\Gateways\PosNet::class === $gatewayClass) { /** - * payment_model: - * siparis olusturulurken kullanilan odeme modeli + * payment_model: siparis olusturulurken kullanilan odeme modeli. * orderId'yi dogru şekilde formatlamak icin zorunlu. */ $refundOrder['payment_model'] = $lastResponse['payment_model']; diff --git a/examples/_common-codes/regular/status.php b/examples/_common-codes/regular/status.php index b7c9ae51..38997781 100644 --- a/examples/_common-codes/regular/status.php +++ b/examples/_common-codes/regular/status.php @@ -22,8 +22,7 @@ function createStatusOrder(string $gatewayClass, array $lastResponse, string $ip } if (\Mews\Pos\Gateways\PosNetV1Pos::class === $gatewayClass || \Mews\Pos\Gateways\PosNet::class === $gatewayClass) { /** - * payment_model: - * siparis olusturulurken kullanilan odeme modeli + * payment_model: siparis olusturulurken kullanilan odeme modeli. * orderId'yi dogru sekilde formatlamak icin zorunlu. */ $statusOrder['payment_model'] = $lastResponse['payment_model']; diff --git a/examples/_templates/_credit_card_form.php b/examples/_templates/_credit_card_form.php index 3c105c08..05f7e871 100644 --- a/examples/_templates/_credit_card_form.php +++ b/examples/_templates/_credit_card_form.php @@ -64,7 +64,9 @@
diff --git a/examples/_templates/_finish_non_secure_payment.php b/examples/_templates/_finish_non_secure_payment.php index 3e699d60..e0957e2b 100644 --- a/examples/_templates/_finish_non_secure_payment.php +++ b/examples/_templates/_finish_non_secure_payment.php @@ -10,41 +10,51 @@ /** * alttaki script - * MODEL_NON_SECURE ve TX_TYPE_PAY_AUTH, TX_TYPE_PAY_PRE_AUTH odemede kullanicidan kredi karti alindiktan - * sonra odemeyi tamamlamak icin calisir. + * MODEL_NON_SECURE ve TX_TYPE_PAY_AUTH, TX_TYPE_PAY_PRE_AUTH odemede kullanicidan + * kredi karti alindiktan sonra odemeyi tamamlar. */ // non secure odemede POST ile kredi kart bilgileri gelmesi bekleniyor. if (($request->getMethod() !== 'POST')) { echo new RedirectResponse($baseUrl); exit(); } - -try { - /** @var \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher */ - $eventDispatcher->addListener(RequestDataPreparedEvent::class, function (RequestDataPreparedEvent $event) use ($pos) { +// ============================================================================================ +// OZEL DURUMLAR ICIN KODLAR START +// ============================================================================================ +/** @var \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher */ +$eventDispatcher->addListener(RequestDataPreparedEvent::class, function (RequestDataPreparedEvent $event) use ($pos) { // Burda istek banka API'na gonderilmeden once gonderilecek veriyi degistirebilirsiniz. // Ornek: // $data = $event->getRequestData(); // $data['abcd'] = '1234'; // $event->setRequestData($data); - /** - * KOICode - 1: Ek Taksit 2: Taksit Atlatma 3: Ekstra Puan 4: Kontur Kazanım 5: Ekstre Erteleme 6: Özel Vade Farkı - */ - if ($pos 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) { - // Yapikredi PosNet KOICode ekleme - // $data = $event->getRequestData(); - // $data['sale']['koiCode'] = '1'; - // $event->setRequestData($data); - } - }); - + /** + * KOICodes: + * 1:Ek Taksit + * 2: Taksit Atlatma + * 3: Ekstra Puan + * 4: Kontur Kazanım + * 5: Ekstre Erteleme + * 6: Özel Vade Farkı + */ + if ($pos 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) { + // Yapikredi PosNet KOICode ekleme + // $data = $event->getRequestData(); + // $data['sale']['koiCode'] = '1'; + // $event->setRequestData($data); + } +}); +// ============================================================================================ +// OZEL DURUMLAR ICIN KODLAR END +// ============================================================================================ +try { doPayment($pos, $paymentModel, $transaction, $order, $card); } catch (Exception $e) { dd($e); diff --git a/examples/_templates/_finish_non_secure_post_auth_payment.php b/examples/_templates/_finish_non_secure_post_auth_payment.php index 30ac3bc2..4dc75b82 100644 --- a/examples/_templates/_finish_non_secure_post_auth_payment.php +++ b/examples/_templates/_finish_non_secure_post_auth_payment.php @@ -11,9 +11,8 @@ /** * alttaki script - * MODEL_NON_SECURE ve TX_TYPE_PAY_POST_AUTH odemede ise kredi bilgileri olmadan Ön Otorizasyon İşlemi tamamlar. + * MODEL_NON_SECURE ve TX_TYPE_PAY_POST_AUTH odemede kredi kart bilgileri olmadan Ön Otorizasyon İşlemi tamamlar. */ -// non secure odemede POST ile kredi kart bilgileri gelmesi bekleniyor. if (PosInterface::TX_TYPE_PAY_POST_AUTH !== $transaction) { echo new RedirectResponse($baseUrl); exit(); diff --git a/examples/_templates/_payment_secure_response.php b/examples/_templates/_payment_secure_response.php index 249fbd0d..80b80fd7 100644 --- a/examples/_templates/_payment_secure_response.php +++ b/examples/_templates/_payment_secure_response.php @@ -20,7 +20,8 @@ // 3D odemelerde gatewayden genelde POST istek bekleniyor. if (($request->getMethod() !== 'POST') // PayFlex-CP GET request ile cevapliyor - && ($request->getMethod() === 'GET' && [] === $request->query->all()) + && ($request->getMethod() === 'GET' + && (get_class($pos) !== \Mews\Pos\Gateways\PayFlexCPV4Pos::class || [] === $request->query->all())) ) { echo new RedirectResponse($baseUrl); exit(); @@ -31,29 +32,37 @@ throw new Exception('Sipariş bulunamadı, session sıfırlanmış olabilir.'); } -try { - /** @var \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher */ - $eventDispatcher->addListener(RequestDataPreparedEvent::class, function (RequestDataPreparedEvent $event) use ($pos, $paymentModel) { +// ============================================================================================ +// OZEL DURUMLAR ICIN KODLAR START +// ============================================================================================ +/** @var \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher */ +$eventDispatcher->addListener(RequestDataPreparedEvent::class, function (RequestDataPreparedEvent $event) use ($pos) { // Burda istek banka API'na gonderilmeden once gonderilecek veriyi degistirebilirsiniz. // Ornek: // $data = $event->getRequestData(); // $data['abcd'] = '1234'; // $event->setRequestData($data); - /** - * Bu asamada bu Event genellikle 1 kere trigger edilir. - * Bir tek PosNet MODEL_3D_SECURE odemede 2 kere API call'i yapildigi icin bu event 2 kere trigger edilir. - */ + /** + * Bu asamada bu Event genellikle 1 kere trigger edilir. + * Bir tek PosNet MODEL_3D_SECURE odemede 2 kere API call'i yapildigi icin bu event 2 kere trigger edilir. + */ - /** - * KOICode - 1: Ek Taksit 2: Taksit Atlatma 3: Ekstra Puan 4: Kontur Kazanım 5: Ekstre Erteleme 6: Özel Vade Farkı - */ - if ($pos instanceof \Mews\Pos\Gateways\PosNetV1Pos && $event->getTxType() === PosInterface::TX_TYPE_PAY_AUTH) { - // Albaraka PosNet KOICode ekleme - // $data = $event->getRequestData(); - // $data['KOICode'] = '1'; - // $event->setRequestData($data); - } - }); + /** + * KOICodes + * 1: Ek Taksit + * 2: Taksit Atlatma + * 3: Ekstra Puan + * 4: Kontur Kazanım + * 5: Ekstre Erteleme + * 6: Özel Vade Farkı + */ + if ($pos instanceof \Mews\Pos\Gateways\PosNetV1Pos && $event->getTxType() === PosInterface::TX_TYPE_PAY_AUTH) { + // Albaraka PosNet KOICode ekleme + // $data = $event->getRequestData(); + // $data['KOICode'] = '1'; + // $event->setRequestData($data); + } +}); // //Isbank İMECE kart ile MODEL_3D_SECURE yöntemiyle ödeme için ekstra alanların eklenme örneği @@ -66,16 +75,21 @@ // } // }); - $card = null; - if (get_class($pos) === \Mews\Pos\Gateways\PayFlexV4Pos::class) { - // bu gateway için ödemeyi tamamlarken tekrar kart bilgisi lazım. - $savedCard = $session->get('card'); - $card = createCard($pos, $savedCard); - } +$card = null; +if (get_class($pos) === \Mews\Pos\Gateways\PayFlexV4Pos::class) { + // bu gateway için ödemeyi tamamlarken tekrar kart bilgisi lazım. + $savedCard = $session->get('card'); + $card = createCard($pos, $savedCard); +} +// ============================================================================================ +// OZEL DURUMLAR ICIN KODLAR END +// ============================================================================================ + +try { doPayment($pos, $paymentModel, $transaction, $order, $card); } catch (HashMismatchException $e) { dd($e); -} catch (Exception $e) { +} catch (\Exception|\Error $e) { dd($e); } $response = $pos->getResponse(); diff --git a/examples/payten/3d-host/_config.php b/examples/payten/3d-host/_config.php index 89b130bd..b1974014 100644 --- a/examples/payten/3d-host/_config.php +++ b/examples/payten/3d-host/_config.php @@ -7,7 +7,7 @@ $baseUrl = $bankTestsUrl.'/3d-host/'; //account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( - 'akbankv3', + 'payten_v3_hash', '700655000200', 'ISBANKAPI', 'ISBANK07', diff --git a/examples/payten/3d-pay-hosting/_config.php b/examples/payten/3d-pay-hosting/_config.php index 6fd88f13..30ec43d8 100644 --- a/examples/payten/3d-pay-hosting/_config.php +++ b/examples/payten/3d-pay-hosting/_config.php @@ -7,7 +7,7 @@ $baseUrl = $bankTestsUrl.'/3d-pay-hosting/'; //account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( - 'akbankv3', + 'payten_v3_hash', '700655000200', 'ISBANKAPI', 'ISBANK07', diff --git a/examples/payten/3d-pay/_config.php b/examples/payten/3d-pay/_config.php index cbd136ae..03b6bb5b 100644 --- a/examples/payten/3d-pay/_config.php +++ b/examples/payten/3d-pay/_config.php @@ -7,7 +7,7 @@ $baseUrl = $bankTestsUrl.'/3d-pay/'; //account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( - 'akbankv3', + 'payten_v3_hash', '700655000200', 'ISBANKAPI', 'ISBANK07', diff --git a/examples/payten/3d/_config.php b/examples/payten/3d/_config.php index ec82dd71..aa0e717e 100644 --- a/examples/payten/3d/_config.php +++ b/examples/payten/3d/_config.php @@ -7,7 +7,7 @@ $baseUrl = $bankTestsUrl.'/3d/'; //account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( - 'akbankv3', + 'payten_v3_hash', '700655000200', 'ISBANKAPI', 'ISBANK07', diff --git a/examples/payten/regular/_config.php b/examples/payten/regular/_config.php index 89480070..69c20756 100644 --- a/examples/payten/regular/_config.php +++ b/examples/payten/regular/_config.php @@ -7,7 +7,7 @@ $baseUrl = $bankTestsUrl.'/regular/'; //account bilgileri kendi account bilgilerinizle degistiriniz $account = \Mews\Pos\Factory\AccountFactory::createEstPosAccount( - 'akbankv3', + 'payten_v3_hash', '700655000200', 'ISBANKAPI', 'ISBANK07', diff --git a/examples/posnet-ykb/_payment_config.php b/examples/posnet-ykb/_payment_config.php index 5494f80d..1d5a9c18 100644 --- a/examples/posnet-ykb/_payment_config.php +++ b/examples/posnet-ykb/_payment_config.php @@ -1,19 +1,16 @@ [ - 'number' => '4543600299100712', - 'year' => '23', - 'month' => '11', - 'cvv' => '454', - 'name' => 'John Doe', - 'type' => CreditCardInterface::CARD_TYPE_VISA, + 'number' => '4048095010857528', + 'year' => '28', + 'month' => '05', + 'cvv' => '454', + 'name' => 'John Doe', ], ]; diff --git a/src/Gateways/PayFlexV4Pos.php b/src/Gateways/PayFlexV4Pos.php index 75811d98..c5f823ad 100644 --- a/src/Gateways/PayFlexV4Pos.php +++ b/src/Gateways/PayFlexV4Pos.php @@ -22,6 +22,8 @@ /** * PayFlex MPI ISD v4 gateway'i destekler (INNOVA BİLİŞİM ÇÖZÜMLERİ A.Ş) * Dokumanlar: http://sanalpos.innova.com.tr/ + * + * VakıfBank VPOS 7/24 */ class PayFlexV4Pos extends AbstractGateway { diff --git a/tests/Functional/EstV3PosTest.php b/tests/Functional/EstV3PosTest.php index 9edc31ac..19d61c89 100644 --- a/tests/Functional/EstV3PosTest.php +++ b/tests/Functional/EstV3PosTest.php @@ -36,7 +36,7 @@ protected function setUp(): void $config = require __DIR__.'/../../config/pos_test.php'; $account = AccountFactory::createEstPosAccount( - 'akbankv3', + 'payten_v3_hash', '700655000200', 'ISBANKAPI', 'ISBANK07', diff --git a/tests/Functional/KuveytPosTest.php b/tests/Functional/KuveytPosTest.php index fb4cf3fe..73f53561 100644 --- a/tests/Functional/KuveytPosTest.php +++ b/tests/Functional/KuveytPosTest.php @@ -19,7 +19,7 @@ class KuveytPosTest extends TestCase private EventDispatcher $eventDispatcher; - /** @var KuveytPosTest */ + /** @var \Mews\Pos\Gateways\KuveytPos */ private PosInterface $pos; private array $lastResponse; diff --git a/tests/Functional/PaymentTestTrait.php b/tests/Functional/PaymentTestTrait.php index 2f514b5b..b4c15be5 100644 --- a/tests/Functional/PaymentTestTrait.php +++ b/tests/Functional/PaymentTestTrait.php @@ -206,7 +206,7 @@ private function createOrderHistoryOrder(string $gatewayClass, array $lastRespon } elseif (\Mews\Pos\Gateways\AkbankPos::class === $gatewayClass) { if (isset($lastResponse['recurring_id'])) { $order = [ - 'id' => $lastResponse['order_id'], + 'id' => $lastResponse['order_id'], 'recurring_id' => $lastResponse['recurring_id'], ]; } else { diff --git a/tests/Unit/DataMapper/RequestDataMapper/EstV3PosRequestDataMapperTest.php b/tests/Unit/DataMapper/RequestDataMapper/EstV3PosRequestDataMapperTest.php index aa0e300a..36fd2a2f 100644 --- a/tests/Unit/DataMapper/RequestDataMapper/EstV3PosRequestDataMapperTest.php +++ b/tests/Unit/DataMapper/RequestDataMapper/EstV3PosRequestDataMapperTest.php @@ -38,7 +38,7 @@ protected function setUp(): void $config = require __DIR__.'/../../../../config/pos_test.php'; $this->account = AccountFactory::createEstPosAccount( - 'akbankv3', + 'payten_v3_hash', '190100000', 'ZIRAATAPI', 'ZIRAAT19', From e6296a34278002777bfab1d75c859dbf8cdcafff Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Mon, 13 May 2024 16:42:10 +0200 Subject: [PATCH 3/9] refactor - throw more specific exceptions --- .../RequestDataMapper/PosNetRequestDataMapper.php | 3 +-- src/Entity/Card/AbstractCreditCard.php | 3 ++- src/Gateways/KuveytPos.php | 4 +--- src/Gateways/PayFlexCPV4Pos.php | 2 +- src/Gateways/PayFlexV4Pos.php | 6 +++--- src/Gateways/PosNet.php | 3 +-- src/Serializer/KuveytPosSerializer.php | 9 +++++---- src/Serializer/PayFlexCPV4PosSerializer.php | 9 +++++---- src/Serializer/PayFlexV4PosSerializer.php | 12 ++++++------ src/Serializer/VakifKatilimPosSerializer.php | 5 ++--- tests/Unit/Serializer/KuveytPosSerializerTest.php | 7 +++---- .../Unit/Serializer/PayFlexCPV4PosSerializerTest.php | 8 ++++---- tests/Unit/Serializer/PayFlexV4PosSerializerTest.php | 4 ++-- 13 files changed, 36 insertions(+), 39 deletions(-) diff --git a/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php b/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php index 0efb11c8..8c99a03c 100644 --- a/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php @@ -5,7 +5,6 @@ namespace Mews\Pos\DataMapper\RequestDataMapper; -use Exception; use InvalidArgumentException; use Mews\Pos\Entity\Account\AbstractPosAccount; use Mews\Pos\Entity\Account\PosNetAccount; @@ -248,7 +247,7 @@ public function createOrderHistoryRequestData(AbstractPosAccount $posAccount, ar * * {@inheritDoc} * - * @throws Exception + * @throws InvalidArgumentException */ public function create3DFormData(AbstractPosAccount $posAccount, array $order, string $paymentModel, string $txType, string $gatewayURL, ?CreditCardInterface $creditCard = null, array $extraData = null): array { diff --git a/src/Entity/Card/AbstractCreditCard.php b/src/Entity/Card/AbstractCreditCard.php index 280f9f34..fa45a71e 100644 --- a/src/Entity/Card/AbstractCreditCard.php +++ b/src/Entity/Card/AbstractCreditCard.php @@ -37,12 +37,13 @@ abstract class AbstractCreditCard implements CreditCardInterface * @param string|null $cardHolderName * @param string|null $cardType examples values: 'visa', 'master', '1', '2' * + * @throws \LogicException */ public function __construct(string $number, DateTimeImmutable $expDate, string $cvv, ?string $cardHolderName = null, ?string $cardType = null) { $number = \preg_replace('/\s+/', '', $number); if (null === $number) { - throw new \Exception('Kredit numarası formatlanamadı!'); + throw new \LogicException('Kredit numarası formatlanamadı!'); } $this->number = $number; diff --git a/src/Gateways/KuveytPos.php b/src/Gateways/KuveytPos.php index fb0d1fb4..b289f257 100644 --- a/src/Gateways/KuveytPos.php +++ b/src/Gateways/KuveytPos.php @@ -23,7 +23,6 @@ use SoapClient; use SoapFault; use Symfony\Component\HttpFoundation\Request; -use Throwable; /** * Kuveyt banki desteleyen Gateway @@ -228,7 +227,6 @@ protected function send($contents, string $txType, string $paymentModel, string * @return array * * @throws SoapFault - * @throws Throwable */ private function sendSoapRequest(array $contents, string $txType, string $url): array { @@ -261,7 +259,7 @@ private function sendSoapRequest(array $contents, string $txType, string $url): $client = new SoapClient($url, $options); try { $result = $client->__soapCall($this->requestDataMapper->mapTxType($txType), ['parameters' => ['request' => $contents]]); - } catch (Throwable $throwable) { + } catch (SoapFault $throwable) { $this->logger->error('soap error response', [ 'message' => $throwable->getMessage(), ]); diff --git a/src/Gateways/PayFlexCPV4Pos.php b/src/Gateways/PayFlexCPV4Pos.php index 3809d38c..bc268094 100644 --- a/src/Gateways/PayFlexCPV4Pos.php +++ b/src/Gateways/PayFlexCPV4Pos.php @@ -167,7 +167,7 @@ public function get3DFormData(array $order, string $paymentModel, string $txType if (null !== $data['ErrorCode']) { $this->logger->error('payment register fail response', $data); - throw new Exception('İşlem gerçekleştirilemiyor'); + throw new \RuntimeException('İşlem gerçekleştirilemiyor'); } $this->logger->debug('preparing 3D form data'); diff --git a/src/Gateways/PayFlexV4Pos.php b/src/Gateways/PayFlexV4Pos.php index c5f823ad..79285b87 100644 --- a/src/Gateways/PayFlexV4Pos.php +++ b/src/Gateways/PayFlexV4Pos.php @@ -157,18 +157,18 @@ public function get3DFormData(array $order, string $paymentModel, string $txType */ if ('E' === $status) { $this->logger->error('enrollment fail response', $data); - throw new Exception($data['ErrorMessage'], $data['MessageErrorCode']); + throw new \RuntimeException($data['ErrorMessage'], $data['MessageErrorCode']); } if ('N' === $status) { //half secure olarak devam et yada satisi iptal et. $this->logger->error('enrollment fail response', $data); - throw new Exception('Kart 3-D Secure programına dâhil değil'); + throw new \RuntimeException('Kart 3-D Secure programına dâhil değil'); } if ('U' === $status) { $this->logger->error('enrollment fail response', $data); - throw new Exception('İşlem gerçekleştirilemiyor'); + throw new \RuntimeException('İşlem gerçekleştirilemiyor'); } $this->logger->debug('preparing 3D form data'); diff --git a/src/Gateways/PosNet.php b/src/Gateways/PosNet.php index b2998504..228c0517 100644 --- a/src/Gateways/PosNet.php +++ b/src/Gateways/PosNet.php @@ -5,7 +5,6 @@ namespace Mews\Pos\Gateways; -use Exception; use InvalidArgumentException; use LogicException; use Mews\Pos\DataMapper\RequestDataMapper\PosNetRequestDataMapper; @@ -157,7 +156,7 @@ public function get3DFormData(array $order, string $paymentModel, string $txType if ($this->responseDataMapper::PROCEDURE_SUCCESS_CODE !== $data['approved']) { $this->logger->error('enrollment fail response', $data); - throw new Exception($data['respText']); + throw new \RuntimeException($data['respText']); } $this->logger->debug('preparing 3D form data'); diff --git a/src/Serializer/KuveytPosSerializer.php b/src/Serializer/KuveytPosSerializer.php index a4deccae..365e41f3 100644 --- a/src/Serializer/KuveytPosSerializer.php +++ b/src/Serializer/KuveytPosSerializer.php @@ -5,13 +5,12 @@ namespace Mews\Pos\Serializer; -use DomainException; use DOMAttr; use DOMDocument; use DOMElement; use DOMNamedNodeMap; use DOMNodeList; -use Exception; +use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\Gateways\KuveytPos; use Mews\Pos\PosInterface; use Symfony\Component\Serializer\Encoder\JsonEncoder; @@ -54,7 +53,9 @@ public static function supports(string $gatewayClass): bool public function encode(array $data, string $txType) { if (PosInterface::TX_TYPE_HISTORY === $txType || PosInterface::TX_TYPE_ORDER_HISTORY === $txType) { - throw new DomainException(\sprintf('Serialization of the transaction %s is not supported', $txType)); + throw new UnsupportedTransactionTypeException( + \sprintf('Serialization of the transaction %s is not supported', $txType) + ); } if (\in_array($txType, $this->nonPaymentTransactions, true)) { @@ -81,7 +82,7 @@ public function decode(string $data, string $txType): array return $this->transformReceived3DFormData($data); } - throw new Exception($data, $notEncodableValueException->getCode(), $notEncodableValueException); + throw new \RuntimeException($data, $notEncodableValueException->getCode(), $notEncodableValueException); } } diff --git a/src/Serializer/PayFlexCPV4PosSerializer.php b/src/Serializer/PayFlexCPV4PosSerializer.php index 0dd91f23..6c61f97c 100644 --- a/src/Serializer/PayFlexCPV4PosSerializer.php +++ b/src/Serializer/PayFlexCPV4PosSerializer.php @@ -5,8 +5,7 @@ namespace Mews\Pos\Serializer; -use DomainException; -use Exception; +use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\Gateways\PayFlexCPV4Pos; use Mews\Pos\PosInterface; use Symfony\Component\Serializer\Encoder\XmlEncoder; @@ -44,7 +43,9 @@ public static function supports(string $gatewayClass): bool public function encode(array $data, string $txType) { if (PosInterface::TX_TYPE_HISTORY === $txType || PosInterface::TX_TYPE_ORDER_HISTORY === $txType || PosInterface::TX_TYPE_STATUS === $txType) { - throw new DomainException(\sprintf('Serialization of the transaction %s is not supported', $txType)); + throw new UnsupportedTransactionTypeException( + \sprintf('Serialization of the transaction %s is not supported', $txType) + ); } if (PosInterface::TX_TYPE_REFUND === $txType || PosInterface::TX_TYPE_CANCEL === $txType) { @@ -64,7 +65,7 @@ public function decode(string $data, ?string $txType = null): array } catch (NotEncodableValueException $notEncodableValueException) { if ($this->isHTML($data)) { // if something wrong server responds with HTML content - throw new Exception($data, $notEncodableValueException->getCode(), $notEncodableValueException); + throw new \RuntimeException($data, $notEncodableValueException->getCode(), $notEncodableValueException); } } diff --git a/src/Serializer/PayFlexV4PosSerializer.php b/src/Serializer/PayFlexV4PosSerializer.php index 3f7071b0..16b2f647 100644 --- a/src/Serializer/PayFlexV4PosSerializer.php +++ b/src/Serializer/PayFlexV4PosSerializer.php @@ -5,14 +5,12 @@ namespace Mews\Pos\Serializer; -use DomainException; -use Exception; +use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\Gateways\PayFlexV4Pos; use Mews\Pos\PosInterface; use Symfony\Component\Serializer\Encoder\XmlEncoder; use Symfony\Component\Serializer\Exception\NotEncodableValueException; use Symfony\Component\Serializer\Serializer; -use function strip_tags; class PayFlexV4PosSerializer implements SerializerInterface { @@ -45,7 +43,9 @@ public static function supports(string $gatewayClass): bool public function encode(array $data, string $txType): string { if (PosInterface::TX_TYPE_HISTORY === $txType || PosInterface::TX_TYPE_ORDER_HISTORY === $txType) { - throw new DomainException(\sprintf('Serialization of the transaction %s is not supported', $txType)); + throw new UnsupportedTransactionTypeException( + \sprintf('Serialization of the transaction %s is not supported', $txType) + ); } if (PosInterface::TX_TYPE_STATUS === $txType) { @@ -69,7 +69,7 @@ public function decode(string $data, ?string $txType = null): array } catch (NotEncodableValueException $notEncodableValueException) { if ($this->isHTML($data)) { // if something wrong server responds with HTML content - throw new Exception($data, $notEncodableValueException->getCode(), $notEncodableValueException); + throw new \RuntimeException($data, $notEncodableValueException->getCode(), $notEncodableValueException); } throw $notEncodableValueException; @@ -78,6 +78,6 @@ public function decode(string $data, ?string $txType = null): array private function isHTML(string $str): bool { - return $str !== strip_tags($str); + return $str !== \strip_tags($str); } } diff --git a/src/Serializer/VakifKatilimPosSerializer.php b/src/Serializer/VakifKatilimPosSerializer.php index 2397a200..6cbe0279 100644 --- a/src/Serializer/VakifKatilimPosSerializer.php +++ b/src/Serializer/VakifKatilimPosSerializer.php @@ -10,7 +10,6 @@ use DOMElement; use DOMNamedNodeMap; use DOMNodeList; -use Exception; use Mews\Pos\Gateways\VakifKatilimPos; use Symfony\Component\Serializer\Encoder\JsonEncoder; use Symfony\Component\Serializer\Encoder\XmlEncoder; @@ -63,7 +62,7 @@ public function decode(string $data, string $txType): array return $this->transformReceived3DFormData($data); } - throw new Exception($data, $notEncodableValueException->getCode(), $notEncodableValueException); + throw new \RuntimeException($data, $notEncodableValueException->getCode(), $notEncodableValueException); } } @@ -98,7 +97,7 @@ private function transformReceived3DFormData(string $response): array /** @var DOMElement|null $formNode */ $formNode = $dom->getElementsByTagName('form')->item(0); if (null === $formNode) { - throw new \Exception($response, 974); + throw new \RuntimeException($response, 974); } /** @var DOMNamedNodeMap $attributes */ diff --git a/tests/Unit/Serializer/KuveytPosSerializerTest.php b/tests/Unit/Serializer/KuveytPosSerializerTest.php index 039a7e6b..28e2288c 100644 --- a/tests/Unit/Serializer/KuveytPosSerializerTest.php +++ b/tests/Unit/Serializer/KuveytPosSerializerTest.php @@ -5,14 +5,13 @@ namespace Mews\Pos\Tests\Unit\Serializer; -use DomainException; use Generator; +use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\Gateways\KuveytPos; use Mews\Pos\PosInterface; use Mews\Pos\Serializer\KuveytPosSerializer; use Mews\Pos\Tests\Unit\DataMapper\RequestDataMapper\KuveytPosRequestDataMapperTest; use PHPUnit\Framework\TestCase; -use function iterator_to_array; /** * @covers \Mews\Pos\Serializer\KuveytPosSerializer @@ -50,10 +49,10 @@ public function testEncode(array $data, string $txType, $expected): void public function testEncodeException(): void { - $this->expectException(DomainException::class); + $this->expectException(UnsupportedTransactionTypeException::class); $this->serializer->encode(['abc' => 1], PosInterface::TX_TYPE_HISTORY); - $this->expectException(DomainException::class); + $this->expectException(UnsupportedTransactionTypeException::class); $this->serializer->encode(['abc' => 1], PosInterface::TX_TYPE_ORDER_HISTORY); } diff --git a/tests/Unit/Serializer/PayFlexCPV4PosSerializerTest.php b/tests/Unit/Serializer/PayFlexCPV4PosSerializerTest.php index edfe3b89..51613602 100644 --- a/tests/Unit/Serializer/PayFlexCPV4PosSerializerTest.php +++ b/tests/Unit/Serializer/PayFlexCPV4PosSerializerTest.php @@ -5,8 +5,8 @@ namespace Mews\Pos\Tests\Unit\Serializer; -use DomainException; use Generator; +use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\Gateways\PayFlexCPV4Pos; use Mews\Pos\PosInterface; use Mews\Pos\Serializer\PayFlexCPV4PosSerializer; @@ -68,13 +68,13 @@ public function testEncodeException(): void { $data = ['abc' => 1]; - $this->expectException(DomainException::class); + $this->expectException(UnsupportedTransactionTypeException::class); $this->serializer->encode($data, PosInterface::TX_TYPE_HISTORY); - $this->expectException(DomainException::class); + $this->expectException(UnsupportedTransactionTypeException::class); $this->serializer->encode($data, PosInterface::TX_TYPE_ORDER_HISTORY); - $this->expectException(DomainException::class); + $this->expectException(UnsupportedTransactionTypeException::class); $this->serializer->encode($data, PosInterface::TX_TYPE_STATUS); } diff --git a/tests/Unit/Serializer/PayFlexV4PosSerializerTest.php b/tests/Unit/Serializer/PayFlexV4PosSerializerTest.php index 488a5a9e..9c4a0742 100644 --- a/tests/Unit/Serializer/PayFlexV4PosSerializerTest.php +++ b/tests/Unit/Serializer/PayFlexV4PosSerializerTest.php @@ -5,8 +5,8 @@ namespace Mews\Pos\Tests\Unit\Serializer; -use DomainException; use Generator; +use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\Gateways\PayFlexV4Pos; use Mews\Pos\PosInterface; use Mews\Pos\Serializer\PayFlexV4PosSerializer; @@ -53,7 +53,7 @@ public function testEncodeException(string $txType): void { $data = ['abc' => 1]; - $this->expectException(DomainException::class); + $this->expectException(UnsupportedTransactionTypeException::class); $this->serializer->encode($data, $txType); } From cb04d26f89a72deac4fbe4dac58b06bd91d3fe21 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Mon, 13 May 2024 16:51:24 +0200 Subject: [PATCH 4/9] phpdocs add proper throws tags --- src/Client/HttpClient.php | 8 +++- src/Crypt/AbstractCrypt.php | 2 +- .../AkbankPosRequestDataMapper.php | 2 - .../EstPosRequestDataMapper.php | 3 ++ .../KuveytPosRequestDataMapper.php | 3 ++ .../PayFlexCPV4PosRequestDataMapper.php | 5 ++ .../PayFlexV4PosRequestDataMapper.php | 3 ++ .../PayForPosRequestDataMapper.php | 1 + .../PosNetRequestDataMapper.php | 3 ++ .../PosNetV1PosRequestDataMapper.php | 4 +- .../RequestDataMapperInterface.php | 18 +++++++ .../AkbankPosResponseDataMapper.php | 4 -- .../GarantiPosResponseDataMapper.php | 2 - .../PayForPosResponseDataMapper.php | 4 -- .../ToslaPosResponseDataMapper.php | 2 - .../VakifKatilimPosResponseDataMapper.php | 4 -- src/Factory/AccountFactory.php | 2 + src/Gateways/AbstractGateway.php | 3 ++ src/Gateways/AkbankPos.php | 2 + src/Gateways/KuveytPos.php | 18 ++++++- src/Gateways/PayFlexCPV4Pos.php | 9 +++- src/Gateways/PosNet.php | 4 ++ src/Gateways/PosNetV1Pos.php | 2 + src/Gateways/ToslaPos.php | 6 ++- src/Gateways/VakifKatilimPos.php | 9 +++- src/PosInterface.php | 47 +++++++++++++++++++ src/Serializer/SerializerInterface.php | 5 ++ 27 files changed, 145 insertions(+), 30 deletions(-) diff --git a/src/Client/HttpClient.php b/src/Client/HttpClient.php index e4560737..302625d6 100644 --- a/src/Client/HttpClient.php +++ b/src/Client/HttpClient.php @@ -5,12 +5,12 @@ namespace Mews\Pos\Client; +use Psr\Http\Client\ClientExceptionInterface; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamFactoryInterface; -use function http_build_query; /** * @phpstan-type PostPayload array{body?: array|string, headers?: array, form_params?: array} @@ -46,6 +46,8 @@ public function __construct( * @param array|null $payload * * @return ResponseInterface + * + * @throws ClientExceptionInterface */ public function post(string $path, ?array $payload = []): ResponseInterface { @@ -60,6 +62,8 @@ public function post(string $path, ?array $payload = []): ResponseInterface * @param array|null $payload * * @return ResponseInterface + * + * @throws ClientExceptionInterface */ private function send(string $method, string $path, ?array $payload = []): ResponseInterface { @@ -83,7 +87,7 @@ private function createRequest(string $method, string $url, ?array $payload = [] $body = null; if (isset($payload['form_params'])) { $request = $request->withHeader('Content-Type', 'application/x-www-form-urlencoded'); - $payload['body'] = http_build_query($payload['form_params']); + $payload['body'] = \http_build_query($payload['form_params']); } if (isset($payload['body'])) { diff --git a/src/Crypt/AbstractCrypt.php b/src/Crypt/AbstractCrypt.php index 56890914..4352161a 100644 --- a/src/Crypt/AbstractCrypt.php +++ b/src/Crypt/AbstractCrypt.php @@ -37,7 +37,7 @@ public function generateRandomString(int $length = 24): string $randomString = ''; for ($i = 0; $i < $length; ++$i) { - $randomString .= $characters[random_int(0, $charactersLength - 1)]; + $randomString .= $characters[\random_int(0, $charactersLength - 1)]; } return $randomString; diff --git a/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php index 8ee56068..c5edcd69 100644 --- a/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/AkbankPosRequestDataMapper.php @@ -565,8 +565,6 @@ private function createRecurringData(array $recurringData): array /** * @return \DateTimeImmutable - * - * @throws \Exception */ private function createDateTime(): \DateTimeImmutable { diff --git a/src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php index 17968500..3a923e0a 100644 --- a/src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/EstPosRequestDataMapper.php @@ -9,6 +9,7 @@ use Mews\Pos\Entity\Card\CreditCardInterface; use Mews\Pos\Event\Before3DFormHashCalculatedEvent; use Mews\Pos\Exceptions\NotImplementedException; +use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\PosInterface; /** @@ -268,6 +269,8 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s * @param string $txType * * @return array{gateway: string, method: 'POST', inputs: array} + * + * @throws UnsupportedTransactionTypeException */ protected function create3DFormDataCommon(AbstractPosAccount $posAccount, array $order, string $paymentModel, string $txType, string $gatewayURL, ?CreditCardInterface $creditCard = null): array { diff --git a/src/DataMapper/RequestDataMapper/KuveytPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/KuveytPosRequestDataMapper.php index a03f23a0..1f5dcc32 100644 --- a/src/DataMapper/RequestDataMapper/KuveytPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/KuveytPosRequestDataMapper.php @@ -11,6 +11,7 @@ use Mews\Pos\Entity\Account\KuveytPosAccount; use Mews\Pos\Entity\Card\CreditCardInterface; use Mews\Pos\Exceptions\NotImplementedException; +use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\PosInterface; /** @@ -116,6 +117,8 @@ public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array * @param CreditCardInterface|null $creditCard * * @return array + * + * @throws UnsupportedTransactionTypeException */ public function create3DEnrollmentCheckRequestData(KuveytPosAccount $kuveytPosAccount, array $order, string $paymentModel, string $txType, ?CreditCardInterface $creditCard = null): array { diff --git a/src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php index 32c39457..ec53fee0 100644 --- a/src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/PayFlexCPV4PosRequestDataMapper.php @@ -9,6 +9,7 @@ use Mews\Pos\Entity\Account\PayFlexAccount; use Mews\Pos\Entity\Card\CreditCardInterface; use Mews\Pos\Exceptions\NotImplementedException; +use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\PosInterface; /** @@ -97,6 +98,8 @@ public function create3DPaymentStatusRequestData(AbstractPosAccount $posAccount, * @param CreditCardInterface|null $creditCard * * @return array + * + * @throws UnsupportedTransactionTypeException */ public function create3DEnrollmentCheckRequestData(AbstractPosAccount $posAccount, array $order, string $txType, string $paymentModel, ?CreditCardInterface $creditCard = null): array { @@ -187,6 +190,8 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount * @return array{TransactionType: string, ReferenceTransactionId: string, * CurrencyAmount: string, CurrencyCode: string, ClientIp: string, * MerchantId: string, Password: string} + * + * @throws UnsupportedTransactionTypeException */ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $posAccount, array $order): array { diff --git a/src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php index a152c798..4c019ee2 100644 --- a/src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/PayFlexV4PosRequestDataMapper.php @@ -10,6 +10,7 @@ use Mews\Pos\Entity\Account\PayFlexAccount; use Mews\Pos\Entity\Card\CreditCardInterface; use Mews\Pos\Exceptions\NotImplementedException; +use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\PosInterface; /** @@ -165,6 +166,8 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount * MerchantId: string, * Password: string, * TerminalNo: string} + * + * @throws UnsupportedTransactionTypeException */ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $posAccount, array $order): array { diff --git a/src/DataMapper/RequestDataMapper/PayForPosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/PayForPosRequestDataMapper.php index b6d7470f..f95f2d5a 100644 --- a/src/DataMapper/RequestDataMapper/PayForPosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/PayForPosRequestDataMapper.php @@ -189,6 +189,7 @@ public function createOrderHistoryRequestData(AbstractPosAccount $posAccount, ar /** * @param array{transaction_date: \DateTimeInterface} $data + * * {@inheritDoc} */ public function createHistoryRequestData(AbstractPosAccount $posAccount, array $data = []): array diff --git a/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php b/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php index 8c99a03c..8a94bf64 100644 --- a/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/PosNetRequestDataMapper.php @@ -10,6 +10,7 @@ use Mews\Pos\Entity\Account\PosNetAccount; use Mews\Pos\Entity\Card\CreditCardInterface; use Mews\Pos\Exceptions\NotImplementedException; +use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\PosInterface; /** @@ -286,6 +287,8 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s * @param PosNetAccount $posAccount * @param array $order * @param string $txType + * + * @throws UnsupportedTransactionTypeException */ public function create3DEnrollmentCheckRequestData(AbstractPosAccount $posAccount, array $order, string $txType, CreditCardInterface $creditCard): array { diff --git a/src/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapper.php b/src/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapper.php index 35a48e6d..c087e039 100644 --- a/src/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapper.php +++ b/src/DataMapper/RequestDataMapper/PosNetV1PosRequestDataMapper.php @@ -5,13 +5,13 @@ namespace Mews\Pos\DataMapper\RequestDataMapper; -use Exception; use InvalidArgumentException; use Mews\Pos\Entity\Account\AbstractPosAccount; use Mews\Pos\Entity\Account\PosNetAccount; use Mews\Pos\Entity\Card\CreditCardInterface; use Mews\Pos\Event\Before3DFormHashCalculatedEvent; use Mews\Pos\Exceptions\NotImplementedException; +use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\PosInterface; /** @@ -341,7 +341,7 @@ public function createOrderHistoryRequestData(AbstractPosAccount $posAccount, ar * * {@inheritDoc} * - * @throws Exception + * @throws UnsupportedTransactionTypeException */ public function create3DFormData(AbstractPosAccount $posAccount, array $order, string $paymentModel, string $txType, string $gatewayURL, ?CreditCardInterface $creditCard = null, $extraData = null): array { diff --git a/src/DataMapper/RequestDataMapper/RequestDataMapperInterface.php b/src/DataMapper/RequestDataMapper/RequestDataMapperInterface.php index 90d8c13c..bdf3919c 100644 --- a/src/DataMapper/RequestDataMapper/RequestDataMapperInterface.php +++ b/src/DataMapper/RequestDataMapper/RequestDataMapperInterface.php @@ -71,6 +71,8 @@ public function getCrypt(): CryptInterface; * @param CreditCardInterface|null $creditCard * * @return array{gateway: string, method: 'POST'|'GET', inputs: array} + * + * @throws UnsupportedTransactionTypeException */ public function create3DFormData(AbstractPosAccount $posAccount, array $order, string $paymentModel, string $txType, string $gatewayURL, ?CreditCardInterface $creditCard = null): array; @@ -83,6 +85,8 @@ public function create3DFormData(AbstractPosAccount $posAccount, array $order, s * @param array $responseData gateway'den gelen cevap * * @return array + * + * @throws UnsupportedTransactionTypeException */ public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array $order, string $txType, array $responseData): array; @@ -95,6 +99,8 @@ public function create3DPaymentRequestData(AbstractPosAccount $posAccount, array * @param CreditCardInterface $creditCard * * @return array + * + * @throws UnsupportedTransactionTypeException */ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount, array $order, string $txType, CreditCardInterface $creditCard): array; @@ -103,6 +109,8 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount * @param array $order * * @return array + * + * @throws UnsupportedTransactionTypeException */ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $posAccount, array $order): array; @@ -111,6 +119,8 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $po * @param array $order * * @return array + * + * @throws UnsupportedTransactionTypeException */ public function createStatusRequestData(AbstractPosAccount $posAccount, array $order): array; @@ -119,6 +129,8 @@ public function createStatusRequestData(AbstractPosAccount $posAccount, array $o * @param array $order * * @return array + * + * @throws UnsupportedTransactionTypeException */ public function createCancelRequestData(AbstractPosAccount $posAccount, array $order): array; @@ -127,6 +139,8 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o * @param array $order * * @return array + * + * @throws UnsupportedTransactionTypeException */ public function createRefundRequestData(AbstractPosAccount $posAccount, array $order): array; @@ -135,6 +149,8 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o * @param array $order * * @return array + * + * @throws UnsupportedTransactionTypeException */ public function createOrderHistoryRequestData(AbstractPosAccount $posAccount, array $order): array; @@ -143,6 +159,8 @@ public function createOrderHistoryRequestData(AbstractPosAccount $posAccount, ar * @param array $data bankaya gore degisen ozel degerler * * @return array + * + * @throws UnsupportedTransactionTypeException */ public function createHistoryRequestData(AbstractPosAccount $posAccount, array $data = []): array; } diff --git a/src/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapper.php index b5d0c88f..da1f8633 100644 --- a/src/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/AkbankPosResponseDataMapper.php @@ -544,8 +544,6 @@ private function mapSingleRecurringOrderHistoryTransaction(array $rawTx): array * @param array $rawTx * * @return array - * - * @throws \Exception */ private function mapSingleHistoryTransaction(array $rawTx): array { @@ -609,8 +607,6 @@ private function mapSingleHistoryTransaction(array $rawTx): array * @param string $paymentModel * * @return array - * - * @throws \Exception */ private function map3DResponseData(array $raw3DAuthResponseData, string $paymentModel): array { diff --git a/src/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapper.php index 21ba6f3d..46979b18 100644 --- a/src/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/GarantiPosResponseDataMapper.php @@ -462,8 +462,6 @@ protected function getProcReturnCode(array $response): ?string * @param array $rawTx * * @return array - * - * @throws \Exception */ private function mapSingleOrderHistoryTransaction(array $rawTx): array { diff --git a/src/DataMapper/ResponseDataMapper/PayForPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/PayForPosResponseDataMapper.php index b61e32ae..c008253b 100644 --- a/src/DataMapper/ResponseDataMapper/PayForPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/PayForPosResponseDataMapper.php @@ -525,8 +525,6 @@ private function map3DCommonResponseData(array $raw3DAuthResponseData): array * @param array $rawTx * * @return array - * - * @throws \Exception */ private function mapSingleOrderHistoryTransaction(array $rawTx): array { @@ -576,8 +574,6 @@ private function mapSingleOrderHistoryTransaction(array $rawTx): array * @param array $rawTx * * @return array - * - * @throws \Exception */ private function mapSingleHistoryTransaction(array $rawTx): array { diff --git a/src/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapper.php index f3f9e57e..d2fbb912 100644 --- a/src/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/ToslaPosResponseDataMapper.php @@ -386,8 +386,6 @@ protected function formatAmount(string $amount): float * @param array $rawResponseData * * @return array - * - * @throws \Exception */ public function mapSingleHistoryResponse(array $rawResponseData): array { diff --git a/src/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapper.php b/src/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapper.php index 3e10b1df..0a8c79ef 100644 --- a/src/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapper.php +++ b/src/DataMapper/ResponseDataMapper/VakifKatilimPosResponseDataMapper.php @@ -452,8 +452,6 @@ protected function map3DCommonResponseData(array $raw3DAuthResponseData): array * @param array $rawTx * * @return array - * - * @throws \Exception */ private function mapSingleHistoryTransaction(array $rawTx): array { @@ -469,8 +467,6 @@ private function mapSingleHistoryTransaction(array $rawTx): array * @param array $rawTx * * @return array - * - * @throws \Exception */ private function mapSingleOrderHistoryTransaction(array $rawTx): array { diff --git a/src/Factory/AccountFactory.php b/src/Factory/AccountFactory.php index 8356cb7d..d6ab3f72 100644 --- a/src/Factory/AccountFactory.php +++ b/src/Factory/AccountFactory.php @@ -139,6 +139,8 @@ public static function createGarantiPosAccount(string $bank, string $merchantId, * @param non-empty-string|null $subMerchantId * * @return KuveytPosAccount + * + * @throws MissingAccountInfoException */ public static function createKuveytPosAccount(string $bank, string $merchantId, string $username, string $customerId, string $storeKey, string $model = PosInterface::MODEL_3D_SECURE, string $lang = PosInterface::LANG_TR, ?string $subMerchantId = null): KuveytPosAccount { diff --git a/src/Gateways/AbstractGateway.php b/src/Gateways/AbstractGateway.php index f20fd4d6..38746b75 100644 --- a/src/Gateways/AbstractGateway.php +++ b/src/Gateways/AbstractGateway.php @@ -16,6 +16,7 @@ use Mews\Pos\PosInterface; use Mews\Pos\Serializer\SerializerInterface; use Psr\EventDispatcher\EventDispatcherInterface; +use Psr\Http\Client\ClientExceptionInterface; use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\Request; @@ -500,6 +501,8 @@ public function getLanguages(): array * @param non-empty-string $url URL address of the API * * @return array + * + * @throws ClientExceptionInterface */ abstract protected function send($contents, string $txType, string $paymentModel, string $url): array; diff --git a/src/Gateways/AkbankPos.php b/src/Gateways/AkbankPos.php index b4cb318e..9bc5304e 100644 --- a/src/Gateways/AkbankPos.php +++ b/src/Gateways/AkbankPos.php @@ -174,6 +174,8 @@ public function status(array $order): PosInterface * @inheritDoc * * @return array + * + * @throws \RuntimeException thrown when we get HTTP 400 error */ protected function send($contents, string $txType, string $paymentModel, string $url): array { diff --git a/src/Gateways/KuveytPos.php b/src/Gateways/KuveytPos.php index b289f257..6e7cfec0 100644 --- a/src/Gateways/KuveytPos.php +++ b/src/Gateways/KuveytPos.php @@ -5,7 +5,6 @@ namespace Mews\Pos\Gateways; -use Exception; use InvalidArgumentException; use LogicException; use Mews\Pos\DataMapper\RequestDataMapper\KuveytPosRequestDataMapper; @@ -19,6 +18,7 @@ use Mews\Pos\Exceptions\UnsupportedPaymentModelException; use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\PosInterface; +use Psr\Http\Client\ClientExceptionInterface; use RuntimeException; use SoapClient; use SoapFault; @@ -64,6 +64,8 @@ public function getAccount(): AbstractPosAccount /** * @inheritDoc + * + * @throws UnsupportedTransactionTypeException */ public function getApiURL(string $txType = null, string $paymentModel = null, ?string $orderTxType = null): string { @@ -122,6 +124,8 @@ public function orderHistory(array $order): PosInterface /** * @inheritDoc + * + * @throws SoapFault */ public function get3DFormData(array $order, string $paymentModel, string $txType, CreditCardInterface $creditCard = null): array { @@ -141,6 +145,8 @@ public function makeRegularPostPayment(array $order): PosInterface /** * @inheritDoc + * + * @throws SoapFault */ public function make3DPayment(Request $request, array $order, string $txType, CreditCardInterface $creditCard = null): PosInterface { @@ -193,6 +199,9 @@ public function make3DPayment(Request $request, array $order, string $txType, Cr * @inheritDoc * * @return array + * + * @throws UnsupportedTransactionTypeException + * @throws SoapFault */ protected function send($contents, string $txType, string $paymentModel, string $url): array { @@ -227,6 +236,8 @@ protected function send($contents, string $txType, string $paymentModel, string * @return array * * @throws SoapFault + * @throws RuntimeException + * @throws UnsupportedTransactionTypeException */ private function sendSoapRequest(array $contents, string $txType, string $url): array { @@ -296,7 +307,10 @@ private function sendSoapRequest(array $contents, string $txType, string $url): * * @return array{gateway: string, method: 'POST', inputs: array} * - * @throws Exception + * @throws RuntimeException + * @throws UnsupportedTransactionTypeException + * @throws SoapFault + * @throws ClientExceptionInterface */ private function getCommon3DFormData(KuveytPosAccount $kuveytPosAccount, array $order, string $paymentModel, string $txType, string $gatewayURL, ?CreditCardInterface $creditCard = null): array { diff --git a/src/Gateways/PayFlexCPV4Pos.php b/src/Gateways/PayFlexCPV4Pos.php index bc268094..d7bb5107 100644 --- a/src/Gateways/PayFlexCPV4Pos.php +++ b/src/Gateways/PayFlexCPV4Pos.php @@ -5,7 +5,6 @@ namespace Mews\Pos\Gateways; -use Exception; use Mews\Pos\DataMapper\RequestDataMapper\PayFlexCPV4PosRequestDataMapper; use Mews\Pos\DataMapper\RequestDataMapper\RequestDataMapperInterface; use Mews\Pos\DataMapper\ResponseDataMapper\PayFlexCPV4PosResponseDataMapper; @@ -17,6 +16,7 @@ use Mews\Pos\Exceptions\UnsupportedPaymentModelException; use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\PosInterface; +use Psr\Http\Client\ClientExceptionInterface; use Symfony\Component\HttpFoundation\Request; /** @@ -69,6 +69,8 @@ public function make3DPayment(Request $request, array $order, string $txType, Cr /** * @inheritDoc + * + * @throws ClientExceptionInterface */ public function make3DPayPayment(Request $request, array $order, string $txType): PosInterface { @@ -127,6 +129,8 @@ public function make3DPayPayment(Request $request, array $order, string $txType) /** * @inheritDoc + * + * @throws ClientExceptionInterface */ public function make3DHostPayment(Request $request, array $order, string $txType): PosInterface { @@ -221,7 +225,8 @@ protected function send($contents, string $txType, string $paymentModel, string * * @return array{CommonPaymentUrl: string|null, PaymentToken: string|null, ErrorCode: string|null, ResponseMessage: string|null} * - * @throws Exception + * @throws UnsupportedTransactionTypeException + * @throws ClientExceptionInterface */ private function registerPayment(array $order, string $txType, string $paymentModel, CreditCardInterface $creditCard = null): array { diff --git a/src/Gateways/PosNet.php b/src/Gateways/PosNet.php index 228c0517..f6e052b5 100644 --- a/src/Gateways/PosNet.php +++ b/src/Gateways/PosNet.php @@ -19,6 +19,7 @@ use Mews\Pos\Exceptions\UnsupportedPaymentModelException; use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\PosInterface; +use Psr\Http\Client\ClientExceptionInterface; use Symfony\Component\HttpFoundation\Request; /** @@ -227,6 +228,9 @@ protected function send($contents, string $txType, string $paymentModel, string * @param CreditCardInterface $creditCard * * @return array{approved: string, respCode: string, respText: string, oosRequestDataResponse?: array{data1: string, data2: string, sign: string}} + * + * @throws UnsupportedTransactionTypeException + * @throws ClientExceptionInterface */ private function getOosTransactionData(array $order, string $txType, CreditCardInterface $creditCard): array { diff --git a/src/Gateways/PosNetV1Pos.php b/src/Gateways/PosNetV1Pos.php index bade0cd4..44514b15 100644 --- a/src/Gateways/PosNetV1Pos.php +++ b/src/Gateways/PosNetV1Pos.php @@ -57,6 +57,8 @@ public function getAccount(): AbstractPosAccount /** * @inheritDoc + * + * @throws UnsupportedTransactionTypeException */ public function getApiURL(string $txType = null, string $paymentModel = null, ?string $orderTxType = null): string { diff --git a/src/Gateways/ToslaPos.php b/src/Gateways/ToslaPos.php index c27861f7..48d67d8f 100644 --- a/src/Gateways/ToslaPos.php +++ b/src/Gateways/ToslaPos.php @@ -17,6 +17,7 @@ use Mews\Pos\Exceptions\UnsupportedPaymentModelException; use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\PosInterface; +use Psr\Http\Client\ClientExceptionInterface; use Symfony\Component\HttpFoundation\Request; /** @@ -65,6 +66,8 @@ public function getAccount(): AbstractPosAccount /** * @inheritDoc + * + * @throws UnsupportedTransactionTypeException */ public function getApiURL(string $txType = null, string $paymentModel = null, ?string $orderTxType = null): string { @@ -207,7 +210,8 @@ protected function send($contents, string $txType, string $paymentModel, string * * @return array * - * @throws \Exception + * @throws UnsupportedTransactionTypeException + * @throws ClientExceptionInterface */ private function registerPayment(array $order, string $paymentModel, string $txType): array { diff --git a/src/Gateways/VakifKatilimPos.php b/src/Gateways/VakifKatilimPos.php index 7af9b902..03fa51ac 100644 --- a/src/Gateways/VakifKatilimPos.php +++ b/src/Gateways/VakifKatilimPos.php @@ -5,7 +5,6 @@ namespace Mews\Pos\Gateways; -use Exception; use Mews\Pos\DataMapper\RequestDataMapper\RequestDataMapperInterface; use Mews\Pos\DataMapper\RequestDataMapper\VakifKatilimPosRequestDataMapper; use Mews\Pos\DataMapper\ResponseDataMapper\ResponseDataMapperInterface; @@ -17,6 +16,7 @@ use Mews\Pos\Exceptions\UnsupportedPaymentModelException; use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\PosInterface; +use Psr\Http\Client\ClientExceptionInterface; use Symfony\Component\HttpFoundation\Request; /** @@ -63,6 +63,8 @@ public function getAccount(): AbstractPosAccount /** * @inheritDoc + * + * @throws UnsupportedTransactionTypeException */ public function getApiURL(string $txType = null, string $paymentModel = null, ?string $orderTxType = null): string { @@ -151,6 +153,8 @@ public function make3DPayment(Request $request, array $order, string $txType, Cr * @inheritDoc * * @return array + * + * @throws UnsupportedTransactionTypeException */ protected function send($contents, string $txType, string $paymentModel, string $url = null): array { @@ -182,7 +186,8 @@ protected function send($contents, string $txType, string $paymentModel, string * * @return array{gateway: string, form_inputs: array} * - * @throws Exception + * @throws UnsupportedTransactionTypeException + * @throws ClientExceptionInterface */ private function sendEnrollmentRequest(KuveytPosAccount $kuveytPosAccount, array $order, string $paymentModel, string $txType, string $gatewayURL, ?CreditCardInterface $creditCard = null): array { diff --git a/src/PosInterface.php b/src/PosInterface.php index 251d9f35..6b149835 100644 --- a/src/PosInterface.php +++ b/src/PosInterface.php @@ -7,7 +7,10 @@ use Mews\Pos\Entity\Account\AbstractPosAccount; use Mews\Pos\Entity\Card\CreditCardInterface; +use Mews\Pos\Exceptions\HashMismatchException; use Mews\Pos\Exceptions\UnsupportedPaymentModelException; +use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; +use Psr\Http\Client\ClientExceptionInterface; use Symfony\Component\HttpFoundation\Request; /** @@ -111,6 +114,11 @@ interface PosInterface * @param CreditCardInterface|null $creditCard * * @return array{gateway: string, method: 'POST'|'GET', inputs: array} + * + * @throws \RuntimeException when request to the bank to get 3D form data failed + * @throws \LogicException when card data is not provided when it is required for the given payment model + * @throws UnsupportedTransactionTypeException + * @throws ClientExceptionInterface */ public function get3DFormData(array $order, string $paymentModel, string $txType, ?CreditCardInterface $creditCard = null): array; @@ -123,6 +131,10 @@ public function get3DFormData(array $order, string $paymentModel, string $txType * @param string $txType * * @return PosInterface + * + * @throws \LogicException + * @throws UnsupportedTransactionTypeException + * @throws ClientExceptionInterface */ public function makeRegularPayment(array $order, CreditCardInterface $creditCard, string $txType): PosInterface; @@ -132,6 +144,10 @@ public function makeRegularPayment(array $order, CreditCardInterface $creditCard * @param array $order * * @return PosInterface + * + * @throws UnsupportedPaymentModelException + * @throws UnsupportedTransactionTypeException + * @throws ClientExceptionInterface */ public function makeRegularPostPayment(array $order): PosInterface; @@ -145,6 +161,11 @@ public function makeRegularPostPayment(array $order): PosInterface; * @param CreditCardInterface|null $creditCard simdilik sadece PayFlexV4Pos icin card isteniyor. * * @return PosInterface + * + * @throws HashMismatchException + * @throws UnsupportedTransactionTypeException + * @throws UnsupportedPaymentModelException + * @throws ClientExceptionInterface */ public function make3DPayment(Request $request, array $order, string $txType, CreditCardInterface $creditCard = null): PosInterface; @@ -157,6 +178,10 @@ public function make3DPayment(Request $request, array $order, string $txType, Cr * @param string $txType * * @return PosInterface + * + * @throws HashMismatchException + * @throws UnsupportedTransactionTypeException + * @throws UnsupportedPaymentModelException */ public function make3DPayPayment(Request $request, array $order, string $txType): PosInterface; @@ -169,6 +194,10 @@ public function make3DPayPayment(Request $request, array $order, string $txType) * @param string $txType * * @return PosInterface + * + * @throws HashMismatchException + * @throws UnsupportedTransactionTypeException + * @throws UnsupportedPaymentModelException */ public function make3DHostPayment(Request $request, array $order, string $txType): PosInterface; @@ -188,6 +217,9 @@ public function make3DHostPayment(Request $request, array $order, string $txType * @return PosInterface * * @throws UnsupportedPaymentModelException + * @throws UnsupportedTransactionTypeException + * @throws \LogicException + * @throws ClientExceptionInterface */ public function payment(string $paymentModel, array $order, string $txType, ?CreditCardInterface $creditCard = null): PosInterface; @@ -197,6 +229,9 @@ public function payment(string $paymentModel, array $order, string $txType, ?Cre * @param array $order * * @return PosInterface + * + * @throws UnsupportedTransactionTypeException + * @throws ClientExceptionInterface */ public function refund(array $order): PosInterface; @@ -206,6 +241,9 @@ public function refund(array $order): PosInterface; * @param array $order * * @return PosInterface + * + * @throws UnsupportedTransactionTypeException + * @throws ClientExceptionInterface */ public function cancel(array $order): PosInterface; @@ -215,6 +253,9 @@ public function cancel(array $order): PosInterface; * @param array $order * * @return PosInterface + * + * @throws UnsupportedTransactionTypeException + * @throws ClientExceptionInterface */ public function status(array $order): PosInterface; @@ -224,6 +265,9 @@ public function status(array $order): PosInterface; * @param array $order * * @return PosInterface + * + * @throws UnsupportedTransactionTypeException + * @throws ClientExceptionInterface */ public function orderHistory(array $order): PosInterface; @@ -231,6 +275,9 @@ public function orderHistory(array $order): PosInterface; * @param array $data * * @return PosInterface + * + * @throws UnsupportedTransactionTypeException + * @throws ClientExceptionInterface */ public function history(array $data): PosInterface; diff --git a/src/Serializer/SerializerInterface.php b/src/Serializer/SerializerInterface.php index 77e236c9..bafcf0db 100644 --- a/src/Serializer/SerializerInterface.php +++ b/src/Serializer/SerializerInterface.php @@ -5,6 +5,7 @@ namespace Mews\Pos\Serializer; +use Mews\Pos\Exceptions\UnsupportedTransactionTypeException; use Mews\Pos\PosInterface; interface SerializerInterface @@ -23,6 +24,8 @@ public static function supports(string $gatewayClass): bool; * @param string $txType * * @return string|array returns XML/JSON string or $data itself when encoding is not needed + * + * @throws UnsupportedTransactionTypeException */ public function encode(array $data, string $txType); @@ -33,6 +36,8 @@ public function encode(array $data, string $txType); * @param string $txType * * @return array + * + * @throws \RuntimeException */ public function decode(string $data, string $txType): array; } From cf4b2ae48e92c9da7b339b18b4b42de0e67c8c2d Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Wed, 15 May 2024 10:17:17 +0200 Subject: [PATCH 5/9] PosFactory - throw error if wrong gateway class is provided --- src/Factory/PosFactory.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Factory/PosFactory.php b/src/Factory/PosFactory.php index 028d2bc8..87a17f6f 100644 --- a/src/Factory/PosFactory.php +++ b/src/Factory/PosFactory.php @@ -61,6 +61,12 @@ public static function createPosGateway( throw new BankClassNullException(); } + if (!\in_array(PosInterface::class, \class_implements($class), true)) { + throw new \InvalidArgumentException( + \sprintf('gateway class must be implementation of %s', PosInterface::class) + ); + } + $currencies = []; if (isset($config['currencies'])) { $currencies = $config['currencies']; From 4a360fab5f90d499255be507dad980b761dc2884 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Fri, 17 May 2024 10:24:10 +0200 Subject: [PATCH 6/9] add support for symfony 7 components --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 024a8f61..6a8a79b7 100644 --- a/composer.json +++ b/composer.json @@ -22,8 +22,8 @@ "psr/event-dispatcher-implementation": "*", "psr/http-client-implementation": "*", "psr/log": "^1.1 || ^2.0 || ^3.0", - "symfony/http-foundation": "^5.0 || ^6.0", - "symfony/serializer": "^5.0 || ^6.0" + "symfony/http-foundation": "^5.0 || ^6.0 || ^7.0", + "symfony/serializer": "^5.0 || ^6.0 || ^7.0" }, "autoload": { "psr-4": { From 66c8a9852cd0d275fa593f9361f2535018c41c80 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Fri, 17 May 2024 17:04:19 +0200 Subject: [PATCH 7/9] add support for symfony 4 components --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 6a8a79b7..116c0a9b 100644 --- a/composer.json +++ b/composer.json @@ -22,8 +22,8 @@ "psr/event-dispatcher-implementation": "*", "psr/http-client-implementation": "*", "psr/log": "^1.1 || ^2.0 || ^3.0", - "symfony/http-foundation": "^5.0 || ^6.0 || ^7.0", - "symfony/serializer": "^5.0 || ^6.0 || ^7.0" + "symfony/http-foundation": "^4.0 || ^5.0 || ^6.0 || ^7.0", + "symfony/serializer": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, "autoload": { "psr-4": { From be4de351e7a69e7e770cb1b2e79be8e78996065e Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 19 May 2024 18:58:07 +0200 Subject: [PATCH 8/9] README.md - added note about pos-bundle --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 543489f8..e3766135 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,11 @@ Son yapılan değişiklikler için [`CHANGELOG`](./docs/CHANGELOG.md). ### Kurulum +#### Frameworks +- **Symfony** kurulum için [mews/pos-bundle](https://github.com/mewebstudio/PosBundle) kullanabilirsiniz. + +#### Basic kurulum + ```sh $ composer require symfony/event-dispatcher mews/pos ``` From 95de568456873429cd14e5e02b5ba2031eef6710 Mon Sep 17 00:00:00 2001 From: Nuryagdy Mustapayev Date: Sun, 19 May 2024 18:58:26 +0200 Subject: [PATCH 9/9] CHANGELOG.md - 1.2 release --- docs/CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3b0e75ab..272c032f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,4 +1,13 @@ # Changelog +## [1.2.0] - 2024-05-19 + +### New Features +- **EstPos** TROY kart desteği eklendi. (issue #205) + +### Changed +- Symfony v4 ve v7 desteği eklendi +- Atılan exception'lar daha spesifik olacak şekilde refactor edildi. + ## [1.1.0] - 2024-04-26 ### New Features