diff --git a/FEATURES/191161 b/FEATURES/191161 new file mode 100644 index 0000000000000000000000000000000000000000..a09616fe17f53efb524b8f0a559e87a53085a976 --- /dev/null +++ b/FEATURES/191161 @@ -0,0 +1,10 @@ + '191161' => + ['Label' => $this->_('Prise en charge des paiements du SIGB Nanook en mode multi-sites'), + 'Desc' => '', + 'Image' => '', + 'Video' => '', + 'Category' => 'Payfip', + 'Right' => function($feature_description, $user) {return true;}, + 'Wiki' => 'https://wiki.bokeh-library-portal.org/index.php?title=Payfip', + 'Test' => '', + 'Date' => '2024-02-28'], \ No newline at end of file diff --git a/VERSIONS_WIP/191161 b/VERSIONS_WIP/191161 new file mode 100644 index 0000000000000000000000000000000000000000..349b622936a9aa5343e2ea86126726abfd266578 --- /dev/null +++ b/VERSIONS_WIP/191161 @@ -0,0 +1 @@ + - fonctionnalité #191161 : Payfip: paiements possibles avec plusieurs régies Nanook \ No newline at end of file diff --git a/application/modules/admin/controllers/PayfipController.php b/application/modules/admin/controllers/PayfipController.php index 6a687fda2d6409b8909fc2aaa8d8980c64c7696e..a78cb6a6b2f6247c4227fa9b9d9ca222b41e7b79 100644 --- a/application/modules/admin/controllers/PayfipController.php +++ b/application/modules/admin/controllers/PayfipController.php @@ -102,15 +102,15 @@ class Admin_PayfipController extends ZendAfi_Controller_Action { } - protected function _redirectToPayfip(bool $activate = false):bool { + protected function _redirectToPayfip(string $client_id, bool $go_to_production = false):bool { if (!$this->_isSuperAdmin()) return false; - $payment = Class_Payfip::buildForTest(); + $payment = Class_Payfip::buildForTest($client_id); $payment->setEmail((new Class_AdminVar_Payfip)->testuserMail()); $payment->save(); $client = new Class_WebService_Payfip_Client; - if ($activate) + if ($go_to_production) $client->activate(); if (!$url = $client->paymentUrlFor($payment)){ @@ -123,13 +123,18 @@ class Admin_PayfipController extends ZendAfi_Controller_Action { public function paymentTestAction() { - if (! $this->_redirectToPayfip()) + if (! $client_id = $this->_getParam('id')) + return $this->_redirectToReferer(); + + if (! $this->_redirectToPayfip($client_id)) return $this->_redirectToReferer(); } public function activateAction() { - if (! $this->_redirectToPayfip(true)) + if (! $client_id = $this->_getParam('id')) + return $this->_redirectToReferer(); + if (! $this->_redirectToPayfip($client_id, true)) return $this->_redirectToReferer(); } } diff --git a/application/modules/admin/views/scripts/payfip/view.phtml b/application/modules/admin/views/scripts/payfip/view.phtml index da8e7fb575bf14bbdd361eec18d2660ec5616c51..474d89df0d38a3956cc31c35fa1fbdd8675a7f1a 100644 --- a/application/modules/admin/views/scripts/payfip/view.phtml +++ b/application/modules/admin/views/scripts/payfip/view.phtml @@ -10,7 +10,7 @@ $description = (new Class_TableDescription('payfip_debts')) fn($detail) => $detail->getPrice()); echo $this->renderTable($description, - $this->payfip->getDebts()); + $this->payfip->getDebts(Class_Users::getIdentity()->getLogin())); echo $this->tag('h2', $this->_('Transaction le %s', diff --git a/cosmogramme/sql/patch/patch_460.php b/cosmogramme/sql/patch/patch_460.php new file mode 100644 index 0000000000000000000000000000000000000000..2c4fb0a617388f2c0501e10db6a84b786834979a --- /dev/null +++ b/cosmogramme/sql/patch/patch_460.php @@ -0,0 +1,10 @@ +<?php +$adapter = Zend_Db_Table_Abstract::getDefaultAdapter(); + +try { + $adapter->query( 'ALTER TABLE `payfip` ADD client_id varchar(255) default null'); + + if ($id = Class_AdminVar::get('PAYFIP_CLIENT_ID')) + $adapter->query('update payfip set client_id="'.$id.'" where client_id is null'); +} catch(Exception $e) { +} diff --git a/library/Class/AdminVar.php b/library/Class/AdminVar.php index 0cfe23f88f8315a8a732d7ab4f8993ba8884d3df..a7aab441367087b59238c60a7f8a5757e8f87fae 100644 --- a/library/Class/AdminVar.php +++ b/library/Class/AdminVar.php @@ -128,8 +128,8 @@ class Class_AdminVarLoader extends Storm_Model_Loader { if ( !$user = Class_Users::getIdentity()) return false; - return ( $payfip->isTestUser($user)) - || ($payfip->isDisplayed() && $payfip->isOnProduction()) ; + return ( $payfip->isTestUser($user->getLogin())) + || ($payfip->isDisplayed() && $payfip->isOneInProduction()) ; } diff --git a/library/Class/AdminVar/Payfip.php b/library/Class/AdminVar/Payfip.php index de5a098a6aa6125a7c06def932d8a569c12f86fe..94cb7044281a26fd474e2723520f0a73c3965485 100644 --- a/library/Class/AdminVar/Payfip.php +++ b/library/Class/AdminVar/Payfip.php @@ -40,7 +40,7 @@ class Class_AdminVar_Payfip { public function metas() : array { return [ - static::CLIENT_ID => (Class_AdminVar_Meta::newDefault($this->_('Numéro client')) + static::CLIENT_ID => (Class_AdminVar_Meta::newDefault($this->_('Numéro(s) client (séparés par des points virgules)')) ->bePrivate()), static::HIDDEN => (Class_AdminVar_Meta::newOnOff($this->_('Masquer les fonctionnalités de paiement et visualisation des prestations pour tous sauf les utilisateurs de test.'))), @@ -63,17 +63,24 @@ class Class_AdminVar_Payfip { public function isEnabled() : bool { - return (bool)$this->clientId(); + return (bool) $this->clientId(); } public function isOnTestMode(Class_Users $user) : bool { - return $this->isTestUser($user) + return $this->isTestUser($user->getLogin()) || $this->_isHidden() || !$this->isOnProduction(); } + public function displayDebtForLogin( string $login, string $payfip_id): bool { + return $this->isTestUser($login) + || ($this->isDisplayed() + && $this->isOnProductionFor($payfip_id)); + } + + protected function _isHidden() : bool { return !$this->isDisplayed(); } @@ -84,14 +91,76 @@ class Class_AdminVar_Payfip { } + public function checkForAllClients(Closure $closure): int { + if ( !$client_ids = (new Class_Adminvar_Payfip)->clientIds()) + return 0; + + $previous_status = 0; + + foreach($client_ids as $client_id) { + $status = $closure($client_id); + if(!$status) + return $previous_status; + if ($status <= $previous_status ) + continue; + $previous_status = $status; + } + return $previous_status; + } + + + public function activationStatus(?Class_Payfip $payment): int { + if(! $payment) + return Class_AdminVar_Payfip::MODE_TEST; + return ( $payment->getPaidOn() < Class_Payfip::addDaysToCurrentDateTime(-1)) + ? Class_AdminVar_Payfip::MODE_PROD + : Class_AdminVar_Payfip::MODE_PENDING; + } + + + public function cbActivationStatus(): int { + return $this->checkForAllClients(fn($client_id) =>$this->cbActivationStatusFor($client_id)); + } + + + public function transferActivationStatus(): int { + return $this->checkForAllClients(fn($client_id) =>$this->transferActivationStatusFor($client_id)); + } + + + public function cbActivationStatusFor(string $client_id) : int{ + return $this->activationStatus(Class_Payfip::findLastCbActivated($client_id)); + } + + + public function transferActivationStatusFor(string $client_id) : int{ + return $this->activationStatus(Class_Payfip::findLastTransferActivated($client_id)); + } + + + public function isOnProductionFor(string $client_id) :bool { + return $this->cbActivationStatusFor($client_id) == Class_AdminVar_Payfip::MODE_PROD || $this->transferActivationStatusFor( $client_id)== Class_AdminVar_Payfip::MODE_PROD; + } + + public function isOnProduction() :bool { return $this->isEnabled() - && ((Class_Payfip::cbActivationStatus() == Class_AdminVar_Payfip::MODE_PROD) || (Class_Payfip::transferActivationStatus()== Class_AdminVar_Payfip::MODE_PROD)); + && $this->checkForAllClients(fn ($client_id) => ( $this->cbActivationStatusFor($client_id) == Class_AdminVar_Payfip::MODE_PROD) || ( $this->transferActivationStatus( $client_id)== Class_AdminVar_Payfip::MODE_PROD)); } - public function isTestUser(Class_Users $user) : bool { - return in_array($user->getLogin(), + public function isOneInProduction() :bool { + if ( !$client_ids = (new Class_Adminvar_Payfip)->clientIds()) + return false; + + return $this->isEnabled() + && (count(array_filter( $client_ids, + fn ($client_id) => ( $this->isOnProductionFor($client_id))))>0); + } + + + public function isTestUser(string $login) : bool { + return in_array($login, explode(',', Class_AdminVar::get(static::TEST_USERS))); } @@ -102,7 +171,12 @@ class Class_AdminVar_Payfip { public function clientId() : string { - return Class_AdminVar::get(static::CLIENT_ID) ?? ''; + return current($this->clientIds()); + } + + + public function clientIds(): array { + return explode(';',Class_AdminVar::get(static::CLIENT_ID) ?? ''); } diff --git a/library/Class/Debt.php b/library/Class/Debt.php index c43c4e5713a2b7450e21d2fccd9893e2f603c7f9..9d3641eadabf4c68f199622305736e42148d73e2 100644 --- a/library/Class/Debt.php +++ b/library/Class/Debt.php @@ -24,12 +24,16 @@ class Class_Debt extends Storm_Model_Abstract { protected $_table_name = 'payfip_debt'; protected $_belongs_to = ['payfip' => ['model' => Class_Payfip::class]]; - public function getPrice() : float { return $this->getAmount()/100; } + public function getClientLabel(): string { + return ''; + } + + public function getHumanAmount() : string { return number_format($this->getPrice(), 2, '€', ''); } diff --git a/library/Class/Payfip.php b/library/Class/Payfip.php index add8d15f4d8f7701be71d9e784a69cad1db632df..ea74fefce12fa1e44e879ed074fc1163b80a203b 100644 --- a/library/Class/Payfip.php +++ b/library/Class/Payfip.php @@ -22,9 +22,13 @@ class PayfipLoader extends Storm_Model_Loader { use Trait_Translator; - public function newWith(Class_Users $user, string $amount, string $reference, array $debts ): Class_Payfip_PaymentResult { + public function newWith(string $client_id, Class_Users $user, string $amount, string $reference, array $debts ): Class_Payfip_PaymentResult { + if (! $client_id) + $client_id = (new Class_AdminVar_Payfip)->clientId(); + $payment = Class_Payfip::newInstance(['amount' => $amount, 'user' => $user, + 'client_id' => $client_id, 'reference' => $reference, 'debts' => $debts]); $payment->setObject($this->_('Paiement prestations %s', $payment->getReference())); @@ -44,8 +48,8 @@ class PayfipLoader extends Storm_Model_Loader { public function findAllResultUnknown() : array { - return Class_Payfip::findAllBy([ - 'result' => [Class_Payfip::RESULT_UNKNOWN, null]]) ; + return Class_Payfip::findAllBy([ + 'result' => [Class_Payfip::RESULT_UNKNOWN, null]]) ; } @@ -73,40 +77,22 @@ class PayfipLoader extends Storm_Model_Loader { } - - public function activationStatus(?Class_Payfip $payment) { - if(! $payment) - return Class_AdminVar_Payfip::MODE_TEST; - if ( $payment->getPaidOn() < Class_Payfip::addDaysToCurrentDateTime(-1)) - return Class_AdminVar_Payfip::MODE_PROD; - return Class_AdminVar_Payfip::MODE_PENDING; - } - - - public function cbActivationStatus() : int{ - return $this->activationStatus(static::findLastCbActivated()); - } - - - public function transferActivationStatus() : int{ - return $this->activationStatus(static::findLastTransferActivated()); - } - - - public function findLastActivated( string $result) :?Class_Payfip { - return Class_Payfip::findFirstBy(['result' => $result, + public function findLastActivated(string $client_id, string $result) :?Class_Payfip { + return Class_Payfip::findFirstBy([ + 'client_id' => $client_id, + 'result' => $result, 'type' => Class_WebService_Payfip_Client::SAISIE_GO_TO_PROD, 'order' => 'paid_on desc']); } - public function findLastCbActivated() : ?Class_Payfip { - return $this->findLastActivated(Class_Payfip::RESULT_PAYED_BY_CB); + public function findLastCbActivated(string $client_id): ?Class_Payfip { + return $this->findLastActivated($client_id, Class_Payfip::RESULT_PAYED_BY_CB); } - public function findLastTransferActivated() :?Class_Payfip { - return $this->findLastActivated(Class_Payfip::RESULT_PAYED_BY_TRANSFER); + public function findLastTransferActivated(string $client_id) :?Class_Payfip { + return $this->findLastActivated($client_id, Class_Payfip::RESULT_PAYED_BY_TRANSFER); } @@ -177,12 +163,12 @@ class PayfipLoader extends Storm_Model_Loader { } - public function buildForTest() : Class_Payfip { + public function buildForTest(string $client_id) :Class_Payfip { $last_test = Class_Payfip::findForTest(); $amount = (int)$last_test->getAmount() + 100; $reference = (int)$last_test->getReference() + 1; - $payment_response = Class_Payfip::newWith($last_test->getUser(),(string)$amount,(string)$reference, []); + $payment_response = Class_Payfip::newWith($client_id, $last_test->getUser(),(string)$amount,(string)$reference, []); return $payment_response->payfip(); } } @@ -216,6 +202,7 @@ class Class_Payfip extends Storm_Model_Abstract { $_default_attribute_values = ['type' => 'payfip-test', 'amount' => 0, 'id_op' => '', + 'client_id' =>'', 'result' => '', 'object' =>'', 'created_at' => '', @@ -341,7 +328,7 @@ class Class_Payfip extends Storm_Model_Abstract { protected function _updatePaymentResult( Class_Payfip_PaymentResult $payment_result) : self { - $payment_result->isValid() + $payment_result->isValid() ? $this->beSigbSynched() : $this->beSigbError($payment_result->error()); @@ -485,11 +472,11 @@ class Class_Payfip extends Storm_Model_Abstract { public function refreshAndIsResultUnknown() :bool { - $payfip_result = (new Class_WebService_Payfip_Client) - ->refresh($this); - if ( $payfip_result && ($payfip = $payfip_result->payfip()) ) - return $payfip->isResultUnknown(); - return true; + $payfip_result = (new Class_WebService_Payfip_Client) + ->refresh($this); + return $payfip_result && ($payfip = $payfip_result->payfip()) + ? $payfip->isResultUnknown() + : true; } @@ -504,7 +491,7 @@ class Class_Payfip extends Storm_Model_Abstract { return $special_class ? ['class' => $special_class] - : []; + : []; } diff --git a/library/Class/Payfip/DebtOrClientIdMissing.php b/library/Class/Payfip/DebtOrClientIdMissing.php new file mode 100644 index 0000000000000000000000000000000000000000..8dde8dc065e554f522874110814031af4e317b4c --- /dev/null +++ b/library/Class/Payfip/DebtOrClientIdMissing.php @@ -0,0 +1,28 @@ +<?php +/** + * Copyright (c) 2012-2023, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_Payfip_DebtOrClientIdMissing extends Class_Payfip_PaymentError { + + public function error() : string { + return $this->_('Pas de dette sélectionnée ou id client payfip absent.'); + } +} diff --git a/library/Class/TableDescription/Payments.php b/library/Class/TableDescription/Payments.php index 6df6833f92b0c556147d0c03287065d63612fa1b..28769e74ae4014bb2a4459756b3296d94b0de16f 100644 --- a/library/Class/TableDescription/Payments.php +++ b/library/Class/TableDescription/Payments.php @@ -91,7 +91,7 @@ class Class_TableDescription_Payments extends Class_TableDescription { $view = $canvas->getView(); $html=[]; - foreach ( $model->getDebts() as $debt) + foreach ( $model->getDebts(Class_Users::getIdentity()->getLogin()) as $debt) $html[] = $view->tag('li',sprintf('%s : %s '. $this->_('€'), $debt->getLabel(), $debt->getPrice())); diff --git a/library/Class/WebService/ActivityPub.php b/library/Class/WebService/ActivityPub.php index 27d8a12dfbfd2173bd20a2ebc12dd31225556b33..43df721de9ae35bef488c1d00241cc58ddef8c7a 100644 --- a/library/Class/WebService/ActivityPub.php +++ b/library/Class/WebService/ActivityPub.php @@ -583,7 +583,6 @@ class Class_WebService_ActivityPubResponse extends Class_WebService_ActivityPubM public function receive($response, $request_target) { $this->_response = $response; $this->_request_target = $request_target; - $this->_log('Received response with headers : ' . json_encode($response->getHeaders(), JSON_PRETTY_PRINT)); return $this; } diff --git a/library/Class/WebService/Payfip/Client.php b/library/Class/WebService/Payfip/Client.php index 3637bb1463bc3bd4d54378e9b9ce65dee31da2e5..3530cb4a2a42ef447d203fc75b4c43ae08a2d2c2 100644 --- a/library/Class/WebService/Payfip/Client.php +++ b/library/Class/WebService/Payfip/Client.php @@ -62,7 +62,7 @@ class Class_WebService_Payfip_Client { } - public function activate() : self{ + public function activate(): self { $this->_input_mode = static::SAISIE_GO_TO_PROD; return $this; } @@ -127,7 +127,7 @@ class Class_WebService_Payfip_Client { $result = $this->_doSoapCall( function(SoapClient $client, Class_Payfip $payment) { - $args = ['arg0' => array_merge($this->_getDefaultParams(), + $args = ['arg0' => array_merge($this->_getDefaultParams($payment->getClientId()), ['exer' => static::getCurrentYear(), 'objet' => $payment->getObject(), 'mel' => $payment->getEmail(), @@ -168,10 +168,10 @@ class Class_WebService_Payfip_Client { } - protected function _getDefaultParams() : array { + protected function _getDefaultParams($client_id) : array { return [ - 'numcli' => (new Class_AdminVar_Payfip)->clientId(), + 'numcli' => $client_id, 'objet' => 'Test', 'saisie' => $this->_input_mode, 'urlnotif' => Class_Url::absolute(['controller' => 'payfip', 'action' => 'notification'], diff --git a/library/Class/WebService/SIGB/Debt.php b/library/Class/WebService/SIGB/Debt.php index 80de5055b42ddb5f3406f063527a83b0e2e8939a..7e103cfaf15671e4e228891b8c3f70e3782025b7 100644 --- a/library/Class/WebService/SIGB/Debt.php +++ b/library/Class/WebService/SIGB/Debt.php @@ -25,7 +25,8 @@ class Class_WebService_SIGB_Debt { protected ?string $_label = null; protected ?int $_amount = null; protected ?string $_payment_id = null; - + protected ?string $_client_id = null; + protected string $_client_label = ''; public function setId(string $id) : self { $this->_id = $id; @@ -55,11 +56,34 @@ class Class_WebService_SIGB_Debt { } + public function setClientId(string $client_id): self { + $this->_client_id = $client_id; + return $this; + } + + + public function setClientLabel($label): self { + $this->_client_label = $label; + return $this; + } + + + public function getClientLabel(): string { + return $this->_client_label; + } + + public function getAmount() : int { return $this->_amount; } + public function getClientId(): string { + return $this->_client_id ?? + (new Class_AdminVar_Payfip)->clientId(); + } + + public function setPaymentId(string $payment_id) : self { $this->_payment_id = $payment_id; return $this; diff --git a/library/Class/WebService/SIGB/Emprunteur.php b/library/Class/WebService/SIGB/Emprunteur.php index c2afc8c0b75380288e707e2f85315e6fc791a8fe..aa07360a447512c7fa4cda87a6c28cf35803b013 100644 --- a/library/Class/WebService/SIGB/Emprunteur.php +++ b/library/Class/WebService/SIGB/Emprunteur.php @@ -983,14 +983,12 @@ class Class_WebService_SIGB_Emprunteur { public function numberOfDebts() : int { - return $this->_debts - ? count($this->_debts) - : 0; + return count($this->getDebts()); } public function getDebts() : array { - return $this->_debts; + return array_filter($this->_debts, fn($debt) => (new Class_AdminVar_Payfip)->displayDebtForLogin( Class_Users::getIdentity()->getLogin(), $debt->getClientId())); } diff --git a/library/Class/WebService/SIGB/Nanook/PatronInfoReader.php b/library/Class/WebService/SIGB/Nanook/PatronInfoReader.php index ec38204d30fad367408670eca3b549be100f85b6..dbe2b6dd559a8210b007a2049bac5ee21e1976eb 100644 --- a/library/Class/WebService/SIGB/Nanook/PatronInfoReader.php +++ b/library/Class/WebService/SIGB/Nanook/PatronInfoReader.php @@ -29,8 +29,9 @@ class Class_WebService_SIGB_Nanook_PatronInfoReader $_current_subscription, $_current_sending_channel; - protected ?Class_WebService_SIGB_Debt $_current_debt; + protected array $_payment_receivers = []; + protected ?Class_WebService_SIGB_Debt $_current_debt; /** * @return Class_WebService_SIGB_Nanook_PatronInfoReader @@ -65,23 +66,30 @@ class Class_WebService_SIGB_Nanook_PatronInfoReader } - public function startDebt(array $attribs) : void { + public function startDebt(array $attribs): self { $this->_current_debt = new Class_WebService_SIGB_Debt; + return $this; } - public function endDebt(string $data) : void { + public function endDebt(string $data): self { if (!$this->_current_debt) - return; + return $this; if ($this->_current_debt->isComplete()) $this->getEmprunteur()->addDebt($this->_current_debt); $this->_current_debt = null; + return $this; } - public function endId(string $data) : void { + public function endId(string $data): self { + if ($this->_xml_parser->inParents('paymentReceiver')) { + $this->_payment_receiver->id = (trim($data)); + return $this; + } + if ($this->_xml_parser->inParents('debt') && $this->_current_debt) $this->_current_debt->setId(trim($data)); @@ -89,17 +97,27 @@ class Class_WebService_SIGB_Nanook_PatronInfoReader if ($this->_xml_parser->inParents('sendingChannel') && $this->_current_sending_channel) $this->_current_sending_channel->setId($data); + + return $this; } - public function endLabel(string $data) : void { + public function endLabel(string $data): self { if ($this->_xml_parser->inParents('debt') - && $this->_current_debt) + && $this->_current_debt){ $this->_current_debt->setLabel(trim($data)); if ($this->_xml_parser->inParents('sendingChannel') && $this->_current_sending_channel) $this->_current_sending_channel->setLabel($data); + + return $this; + } + + if ($this->_xml_parser->inParents('paymentReceiver') + && $this->_payment_receiver) + $this->_payment_receiver->label = trim($data); + return $this; } @@ -110,115 +128,126 @@ class Class_WebService_SIGB_Nanook_PatronInfoReader } - public function endPaymentId(string $data) : void { + public function endPaymentReceiverId(string $data): self { + if ( !($this->_xml_parser->inParents('debt') + && $this->_current_debt)) + return $this; + if ( $map = array_filter($this->_payment_receivers, + fn($receiver)=> ($receiver->id == trim($data)))) { + $this->_current_debt->setClientId(reset($map)->client_id); + $this->_current_debt->setClientLabel(reset($map)->label); + } + return $this; + } + + + public function startPaymentReceiver() { + $this->_payment_receiver = new stdClass(); + } + + + public function endPayFipId(string $data): self { + $this->_payment_receiver->client_id = $data; + return $this; + } + + + public function endPaymentReceiver(string $data): self { + $this->_payment_receivers[] = $this->_payment_receiver; + return $this; + } + + + public function endPaymentId(string $data): self { if ($this->_xml_parser->inParents('debt') && $this->_current_debt) $this->_current_debt->setPaymentId($data); + return $this; } - /** - * @param $data string - */ - public function endEndDate($data) { + public function endEndDate(?string $data): self { if (!$data || ($data == 'null')) - return; - + return $this; return ($this->_xml_parser->inParents('subscriptions')) ? $this->_addSubscriptionEndDate($data) : $this->_addEmprunteurEndDate($data); } - protected function _addSubscriptionEndDate(string $data){ + protected function _addSubscriptionEndDate(string $data): self { if ($this->_current_subscription) $this->_current_subscription->setEndDate($data); + return $this; } - protected function _addEmprunteurEndDate(string $data){ + protected function _addEmprunteurEndDate(string $data):self { $this->getEmprunteur()->setEndDate($data); + return $this; } - /** - * @param $data string - */ - public function endMail($data) { + public function endMail(?string $data): self { if ($data && 'null' != $data) $this->getEmprunteur()->setEmail($data); + return $this; } - /** - * @param string $data - */ - public function endBarcode($data) { + public function endBarcode(?string $data): self { if ($this->_xml_parser->inParents('hold')) { $this->_currentHold->setCodeBarre($data); - return; + return $this; } $this->_emprunteur->setCodeBarres($data); + return $this; } - /** - * @param string $data - */ - public function endAddress($data) { + public function endAddress(?string $data): self { $this->_emprunteur->setAdresse($data); + return $this; } - /** - * @param string $data - */ - public function endTown($data) { + public function endTown(?string $data): self { $this->_emprunteur->setVille($data); + return $this; } - /** - * @param string $data - */ - public function endZipCode($data) { + public function endZipCode(?string $data): self { $this->_emprunteur->setCodePostal($data); + return $this; } - /** - * @param string $data - */ - public function endPhoneNumber($data) { + public function endPhoneNumber(?string $data): self { $this->_emprunteur->setTelephone($data); + return $this; } - /** - * @param string $data - */ - public function endDisplayOrder($data) { + public function endDisplayOrder(?string $data): self { $this->_emprunteur->setOrdre($data); + return $this; } - /** - * @param string $data - */ - public function endBirthDate($data) { - $this->_emprunteur->setDateNaissance($data); + public function endBirthDate(?string $data): self { + $this->_emprunteur->setDateNaissance($data ?? ''); + return $this; } - /** - * @param string $data - */ - public function endDueDate($data) { + public function endDueDate(?string $data): self { if ($this->_xml_parser->inParents('loan')) { $date = implode('/', array_reverse(explode('-', $data))); $this->_currentLoan->getExemplaire()->setDateRetour($date); } + return $this; } @@ -230,28 +259,22 @@ class Class_WebService_SIGB_Nanook_PatronInfoReader } - /** - * @param string $data - */ - public function endItemId($data) { + public function endItemId(?string $data): self { $this->_getCurrentOperation()->setId($data); $this->_getCurrentOperation()->getExemplaire()->setId($data); + return $this; } - /** - * @param string $data - */ - public function endBibId($data) { + public function endBibId(?string $data): self { $this->_getCurrentOperation()->getExemplaire()->setNoNotice($data); + return $this; } - /** - * @param string $data - */ - public function endLocationLabel($data) { + public function endLocationLabel(?string $data): self { $this->_getCurrentOperation()->getExemplaire()->setBibliotheque($data); + return $this; } @@ -366,7 +389,7 @@ class Class_WebService_SIGB_Nanook_PatronInfoReader public function startSubscription() { - $this->_newSubscription(); + $this->_newSubscription(); } @@ -405,6 +428,7 @@ class Class_WebService_SIGB_Nanook_PatronInfoReader $this->_addToSubscriptions(); } + protected function _addToSubscriptions(){ if ($this->_current_subscription){ $this->getEmprunteur()->getSubscriptions()->add($this->_current_subscription); diff --git a/library/Class/WebService/SIGB/Nanook/Service.php b/library/Class/WebService/SIGB/Nanook/Service.php index cc51b12be07799fa3fa53a9f2def1d6bb8ae4a0b..fec8f78e2ec3d283e25cd90cce29920458ef73ec 100644 --- a/library/Class/WebService/SIGB/Nanook/Service.php +++ b/library/Class/WebService/SIGB/Nanook/Service.php @@ -41,6 +41,7 @@ class Class_Webservice_SIGB_Nanook_Service 'DebtAmountError' => $this->_('Le montant total ne correspond pas au montant fourni'), 'DebtIdNotFound' => $this->_('Au moins une dette n\'a pas été trouvée'), 'StartPaymentTechnicalError' => $this->_('Une erreur inconnue est survenue'), + 'DebtsWithDifferentsPaymentsReceivers' => $this->_('Les paiements correspondent à des bibliothèques différentes. Merci d\'effectuer le paiement bibliothèque par bibliothèque.'), 'UnrecognizedPaymentStatus' => $this->_('Code d\'état du paiement inconnu'), 'UnrecognizedPaymentType' => $this->_('Code de type de paiement inconnu'), 'UnrecognizedPaymentDateFormat' => $this->_('La date de paiement n\'est pas au bon format'), @@ -569,6 +570,10 @@ class Class_Webservice_SIGB_Nanook_Service int $total_amount, array $debts) : Class_Payfip_PaymentResult { $total_amount = (string)$total_amount; + + if (empty($debts) || ( !$client_id = reset($debts)->getClientId())) + return new Class_Payfip_DebtOrClientIdMissing; + $datas = ['totalAmount' => (substr($total_amount, 0, strlen($total_amount)-2) . '.' . substr($total_amount, -2)), 'debtsIds' => array_map(fn($debt) => $debt->getId(), @@ -605,7 +610,7 @@ class Class_Webservice_SIGB_Nanook_Service 'amount' => $debt->getAmount()]), $debts); - return Class_Payfip::newWith($user, $total_amount, $payment_id, $debts); + return Class_Payfip::newWith($client_id, $user, $total_amount, $payment_id, $debts); } diff --git a/library/Class/WebService/SimpleWebClient.php b/library/Class/WebService/SimpleWebClient.php index 15b8eec8d1cfee2d8c4f9f645fc761b6e4d81a28..94f02eedd256a3c5d3f6fd70a1007c2d3e31892b 100644 --- a/library/Class/WebService/SimpleWebClient.php +++ b/library/Class/WebService/SimpleWebClient.php @@ -138,7 +138,7 @@ class Class_WebService_SimpleWebClient { public function postRawDataResponse($url, $datas, $encoding, $options = []) { - return $this->_postRawData($url, $datas, $encoding, $options); + return $this->postRawData($url, $datas, $encoding, $options); } diff --git a/library/ZendAfi/View/Helper/Admin/PayfipDashboard.php b/library/ZendAfi/View/Helper/Admin/PayfipDashboard.php index 2f96bb667dfe0cc99fe0e4e292d13d48c2d402ec..6b3cdbff53c5491bfc2b37656873a5d21ab991b6 100644 --- a/library/ZendAfi/View/Helper/Admin/PayfipDashboard.php +++ b/library/ZendAfi/View/Helper/Admin/PayfipDashboard.php @@ -22,17 +22,18 @@ class ZendAfi_View_Helper_Admin_PayfipDashboard extends ZendAfi_View_Helper_BaseHelper { public function getCBStatusMessage() : string{ - $status = Class_Payfip::cbActivationStatus(); - if ($status == Class_Adminvar_Payfip::MODE_PROD) + $status = (new Class_AdminVar_Payfip)->cbActivationStatus(); + + if ($status == Class_AdminVar_Payfip::MODE_PROD) return $this->_('Paiement CB : activé'); - if ($status == Class_Adminvar_Payfip::MODE_PENDING) + if ($status == Class_AdminVar_Payfip::MODE_PENDING) return $this->_('Paiement CB : en cours d\'activation'); return $this->_('Paiement CB : en TEST'); } public function getTransferStatusMessage() : string{ - $status = Class_Payfip::transferActivationStatus(); + $status = (new Class_AdminVar_Payfip)->transferActivationStatus(); if ($status == Class_Adminvar_Payfip::MODE_PROD) return $this->_('Paiement par prélèvement : activé'); @@ -50,12 +51,74 @@ class ZendAfi_View_Helper_Admin_PayfipDashboard extends ZendAfi_View_Helper_Base } + public function activationTransferButton( $client_id): string { + $status = (new Class_AdminVar_Payfip)->transferActivationStatusFor( $client_id); + if ($status == Class_Adminvar_Payfip::MODE_PROD) + return $this->view->statusButton($this->_('Paiement par prélèvement : activé'), $status); + + if ($status == Class_Adminvar_Payfip::MODE_PENDING) + return $this->view->statusButton($this->_('Paiement par prélèvement : en cours d\'activation'), $status); + return $this->view->button((new Class_Button) + ->setAttribs([ 'class' => 'digital_connectors_status']) + ->setText($this->_('Activer le paiement par prélèvement pour %s', $client_id)) + ->setUrl($this->view->absoluteUrl(['module' => 'admin', + 'controller' => 'payfip', + 'action' => 'activate', + 'id' => $client_id], + null, + true))); + } + + + public function activationCBButton($client_id): string { + $status = (new Class_AdminVar_Payfip)->cbActivationStatusFor( $client_id); + if ($status == Class_Adminvar_Payfip::MODE_PROD) + return $this->view->statusButton($this->_('Paiement par CB : activé'), $status); + + if ($status == Class_Adminvar_Payfip::MODE_PENDING) + return $this->view->statusButton($this->_('Paiement par CB : en cours d\'activation'), $status); + + return $this->view->button((new Class_Button) + ->setAttribs([ 'class' => 'digital_connectors_status']) + ->setText($this->_('Activer le paiement CB pour %s', $client_id)) + ->setUrl($this->view->absoluteUrl(['module' => 'admin', + 'controller' => 'payfip', + 'action' => 'activate', + 'id' => $client_id], + null, + true))); + } + + + public function displayStatusFor(string $client_id): string { + $is_super_admin = (ZendAfi_Auth_Others::getInstance()->isSuperAdminLogged()); + if ( ! $is_super_admin) + return ''; + $html = []; + + $html[] = $this->view->tag('h3', $this->_('STATUT Identifiant Payfip: '). $client_id); + $html[] = $this->view->button((new Class_Button) + ->setText($this->_('Tester un paiement pour %s', $client_id)) + ->setUrl($this->view->absoluteUrl(['module' => 'admin', + 'controller' => 'payfip', + 'action' => 'payment-test', + 'id' => $client_id], + null, + true))); + + $html[] = $this->activationTransferButton($client_id); + $html[] = $this->activationCBButton($client_id); + + return implode('</br>', $html); + } + + public function payfipDashboard() { $html = []; $html[] = $this->view->statusButton($this->getActivateMessage(),(new Class_AdminVar_Payfip)->isEnabled()); - $html[] = $this->view->statusButton($this->getCBStatusMessage(), Class_Payfip::cbActivationStatus()); - $html[] = $this->view->statusButton($this->getTransferStatusMessage(),Class_Payfip::transferActivationStatus()); + $html[] = $this->view->statusButton($this->getCBStatusMessage(), (new Class_AdminVar_Payfip)->cbActivationStatus()); + $html[] = $this->view->statusButton($this->getTransferStatusMessage(),(new Class_AdminVar_Payfip)->transferActivationStatus()); $html[] = $this->_tag('h3', $this->_('Paramétrage')); @@ -68,42 +131,15 @@ class ZendAfi_View_Helper_Admin_PayfipDashboard extends ZendAfi_View_Helper_Base if (Class_AdminVar::isPayfipEnabled()) $html[] = $this->_tag('h3', $this->_('')) . $this->view->renderTable(new Class_TableDescription_Batches('batchs'), - [new Class_Batch_Definition(new Class_Batch_Payfip())]); + [new Class_Batch_Definition(new Class_Batch_Payfip())]); $html[] = $this->_tag('h3', $this->_('Tests')); $html[] = $this->_tag('h4', $this->_('URL SOAP générée ')); - $html[] = $this->view->button((new Class_Button()) - ->setText($this->_('Tester un paiement')) - ->setUrl($this->view->absoluteUrl(['module' => 'admin', - 'controller' => 'payfip', - 'action' => 'payment-test'], - null, - true))); - $is_super_admin = (ZendAfi_Auth_Others::getInstance()->isSuperAdminLogged()); - if ($is_super_admin && !Class_Payfip::findLastCbActivated()) - $html[] = $this->view->button((new Class_Button()) - ->setAttribs([ 'class' => 'digital_connectors_status']) - ->setText($this->_('Activer le paiement CB')) - ->setUrl($this->view->absoluteUrl(['module' => 'admin', - 'controller' => 'payfip', - 'action' => 'activate'], - null, - true))); - - if ($is_super_admin && !Class_Payfip::findLastTransferActivated()) - $html[] = $this->view->button((new Class_Button()) - ->setAttribs([ 'class' => 'digital_connectors_status']) - ->setText($this->_('Activer le paiement par prélèvement')) - ->setUrl($this->view->absoluteUrl(['module' => 'admin', - 'controller' => 'payfip', - 'action' => 'activate'], - null, - true))); - - + foreach ((new Class_AdminVar_Payfip)->clientIds() as $client_id) + $html[] = $this->displayStatusFor($client_id); return implode($html); } } diff --git a/library/templates/Intonation/Library/View/Wrapper/Debts.php b/library/templates/Intonation/Library/View/Wrapper/Debts.php index 13b47ad89b38eb6c20a2479e9fbb559e500a94bd..443579ae7e28139a5828ddbb31abe9f2280d0e62 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Debts.php +++ b/library/templates/Intonation/Library/View/Wrapper/Debts.php @@ -34,10 +34,15 @@ class Intonation_Library_View_Wrapper_Debts protected function _badges() : array { + return [(new Intonation_Library_Badge) ->setTag('span') ->setClass('badge-info') - ->setText($this->_model->getHumanAmount())]; + ->setText($this->_model->getHumanAmount()), + (new Intonation_Library_Badge) + ->setTag('span') + ->setClass('badge-info') + ->setText($this->_model->getClientLabel())]; } diff --git a/library/templates/Intonation/Library/View/Wrapper/User/RichContent/Debts.php b/library/templates/Intonation/Library/View/Wrapper/User/RichContent/Debts.php index 1f41d0e2fe7267db634f0b1a0a69af6b076890de..5ddb89083b29c6dd2b7f8b517d5ba48e131c898f 100644 --- a/library/templates/Intonation/Library/View/Wrapper/User/RichContent/Debts.php +++ b/library/templates/Intonation/Library/View/Wrapper/User/RichContent/Debts.php @@ -84,7 +84,7 @@ class Intonation_Library_View_Wrapper_User_RichContent_Debts foreach ($payfips as $payfip) $debts = [...$debts, ...($filter($payfip) - ? $payfip->getDebts() + ? $payfip->getDebts( Class_Users::getIdentity()->getLogin()) : [])]; return (new Storm_Collection($debts)) diff --git a/library/templates/Intonation/View/User/BorrowerLinks.php b/library/templates/Intonation/View/User/BorrowerLinks.php index 9151cf7f8e783cf97d01a9374d3bc2bea2e1e15a..9c60523e0c0643e651816056eabe39e53884d952 100644 --- a/library/templates/Intonation/View/User/BorrowerLinks.php +++ b/library/templates/Intonation/View/User/BorrowerLinks.php @@ -130,6 +130,7 @@ class Intonation_View_User_BorrowerLinks extends ZendAfi_View_Helper_FicheAbonne protected function _renderNumberOfDebts() : Intonation_Library_Link { + $nb_debts = $this->_numberOfDebts(); return (new Intonation_Library_Link) ->setText($this->view->_plural($nb_debts, diff --git a/tests/db/UpgradeDBTest.php b/tests/db/UpgradeDBTest.php index b95da38f64dbdf936340574273e362aadad0ee90..b39ef3c1c032ebee6442ff505f645beacdf46fed 100644 --- a/tests/db/UpgradeDBTest.php +++ b/tests/db/UpgradeDBTest.php @@ -5610,3 +5610,40 @@ class UpgradeDB_459_Test extends UpgradeDBTestCase { $this->assertEquals('utf8mb4', $this->getCharacterSet($codif, 'libelle')); } } + + + + + +class UpgradeDB_460_Test extends UpgradeDBTestCase { + protected $_client_id; + public function prepare(){ + if (!$this->_client_id = Class_AdminVar::get('PAYFIP_CLIENT_ID')) + Class_AdminVar::set('PAYFIP_CLIENT_ID', 'TESTID'); + $this->query("insert into payfip(id_op, user_id, reference, amount,paid_on, result) values ('toto', + 336,'1234767889', 1634, '2023-06-01 12:00:28','C')"); + + $this->silentQuery('alter table payfip drop client_id;'); + } + + + public function tearDown() { + if (!$this->_client_id) + Class_AdminVar::set('PAYFIP_CLIENT_ID', '')->save(); + $this->query('delete from payfip where reference="1234767889" and id_op="toto";'); + parent::tearDown(); + } + + + /** @test */ + public function displayClientIdColumnInTablePayfipShouldExist() { + $this->assertFieldType('payfip','client_id', 'varchar(255)'); + } + + + /** @test */ + public function clientIdShouldBeSetForAllPayfip() { + $data = $this->query('select client_id from payfip')->fetch(); + $this->assertEquals(Class_AdminVar::get('PAYFIP_CLIENT_ID'), $data['client_id']); + } +} diff --git a/tests/scenarios/Payfip/PayfipDashboardTest.php b/tests/scenarios/Payfip/PayfipDashboardTest.php index 81d3a2546ec1678050bd2ddee8ba8978aeebd1d3..f7228baf360149c507badad185afecc8574181f0 100644 --- a/tests/scenarios/Payfip/PayfipDashboardTest.php +++ b/tests/scenarios/Payfip/PayfipDashboardTest.php @@ -22,11 +22,31 @@ require_once __DIR__ . '/PayfipFixtures.php'; abstract class PayfipDashboardTestCase extends Admin_AbstractControllerTestCase { use Trait_PayfipFixtures; + public function tearDown() { + $this->disablePayfip(); + parent::tearDown(); + } } +class PayfipDashboardDisplayWithInvalidClientIdsTest extends PayfipDashboardTestCase { + + public function setUp() { + parent::setUp(); + } + + + /** @test */ + public function pageTitleShouldBeTableauDeBordPayfip() { + Class_AdminVar::set(Class_AdminVar_Payfip::CLIENT_ID, '123000'); + $this->assertFalse((new Class_AdminVar_Payfip)->isOnProduction()); + } +} + + + class PayfipDashboardDisplayTest extends PayfipDashboardTestCase { public function setUp() { @@ -60,50 +80,61 @@ class PayfipDashboardDisplayTest extends PayfipDashboardTestCase { /** @test */ - public function buttonForTestingPaymentShouldBeDisplayed() { - $this->assertXPathContentContains('//button[contains(@data-url,"/payfip/payment-test")]', 'Tester un paiement'); + public function tableShouldContainsPayfipHidden() { + $this->assertXPathContentContains('//tr/td','PAYFIP_HIDDEN'); } /** @test */ - public function buttonForEnablingCBShouldBeDisplayed() { - $this->assertXPathContentContains('//button[contains(@data-url,"/admin/payfip/activate")]', 'Activer le paiement CB'); + public function tableShouldContainsPayfipTestLogins() { + $this->assertXPathContentContains('//tr/td','PAYFIP_TEST_USERS'); } /** @test */ - public function buttonForEnablingDebitShouldBeDisplayed() { - $this->assertXPathContentContains('//button[contains(@data-url,"/admin/payfip/activate")]', 'Activer le paiement par prélèvement'); + public function fieldsetSearchGroupShouldNotBeDisplayed() { + $this->assertNotXPath('//fieldset[@id="fieldset-search_group"]'); } /** @test */ - public function tableShouldContainsPayfipHidden() { - $this->assertXPathContentContains('//tr/td','PAYFIP_HIDDEN'); + public function tablePayfipTableShouldNotBeLoaded() { + $this->assertNotXPath('//table[@id="payfip-table"]'); } /** @test */ - public function tableShouldContainsPayfipTestLogins() { - $this->assertXPathContentContains('//tr/td','PAYFIP_TEST_USERS'); + public function batchTableShouldNotBeLoaded() { + $this->assertNotXPath('//table[@id="batchs"]'); + } +} + + + + +class PayfipDashboardEnabledDisplayTest extends PayfipDashboardTestCase { + public function setUp() { + parent::setUp(); + $this->enablePayfip(); + $this->dispatch('/admin/payfip/index'); } /** @test */ - public function fieldsetSearchGroupShouldNotBeDisplayed() { - $this->assertNotXPath('//fieldset[@id="fieldset-search_group"]'); + public function buttonForTestingPaymentShouldBeDisplayed() { + $this->assertXPathContentContains('//button[contains(@data-url,"/payfip/payment-test/id/123000")]', 'Tester un paiement'); } /** @test */ - public function tablePayfipTableShouldNotBeLoaded() { - $this->assertNotXPath('//table[@id="payfip-table"]'); + public function buttonForEnablingCBShouldBeDisplayed() { + $this->assertXPathContentContains('//button[contains(@data-url,"/admin/payfip/activate/id/123000")]', 'Activer le paiement CB'); } /** @test */ - public function batchTableShouldNotBeLoaded() { - $this->assertNotXPath('//table[@id="batchs"]'); + public function buttonForEnablingDebitShouldBeDisplayed() { + $this->assertXPathContentContains('//button[contains(@data-url,"/admin/payfip/activate/id/123000")]', 'Activer le paiement par prélèvement'); } } @@ -159,29 +190,28 @@ class PayfipDashboardActivationDisplayTest extends PayfipDashboardTestCase { protected $_payfip; public function setUp() { parent::setUp(); + $this->enablePayfip(); Class_Payfip::setTimeSource(new TimeSourceForTest('2023-02-02 11:21:38')); - $this->cbOnProduction('2023-02-02 10:00:00'); - $this->transferOnProduction('2023-02-02 10:00:00'); + $this->cbOnProduction('2023-02-02 10:00:00','123000'); + $this->transferOnProduction('2023-02-02 10:00:00','123000'); $this->group = $this->fixture(Class_UserGroup::class, ['id' => 1, 'protected' => false, 'libelle' => 'Testing Permissions Group']); - } /** @test */ public function buttonInformationCbActivationPending(){ $this->dispatch('/admin/payfip/index'); - $this->assertXPathContentContains('//button', 'Paiement CB : en cours d\'activation'); } /** @test */ public function buttonInformationCbActivated(){ - $this->cbOnProduction('2023-02-01 09:00:00'); + $this->cbOnProduction('2023-02-01 09:00:00','123000'); $this->dispatch('/admin/payfip/index'); $this->assertXPathContentContains('//button', 'Paiement CB : activé'); @@ -198,7 +228,7 @@ class PayfipDashboardActivationDisplayTest extends PayfipDashboardTestCase { /** @test */ public function buttonInformationTransferActivated(){ - $this->transferOnProduction('2023-02-01 10:00:00'); + $this->transferOnProduction('2023-02-01 10:00:00','123000'); $this->dispatch('/admin/payfip/index'); @@ -214,5 +244,75 @@ class PayfipDashboardActivationDisplayTest extends PayfipDashboardTestCase { $this->assertNotXPathContentContains('//button[contains(@data-url,"/admin/payfip/activate")]', 'Activer le paiement par prélèvement'); } +} + + + + +class PayfipDashboardActivationMultipleDisplayTest extends PayfipDashboardTestCase { + protected $_payfip; + public function setUp() { + parent::setUp(); + $this->enableMultiplePayfip(); + Class_Payfip::setTimeSource(new TimeSourceForTest('2023-02-02 11:21:38')); + + $this->group = $this->fixture(Class_UserGroup::class, + ['id' => 1, + 'protected' => false, + 'libelle' => 'Testing Permissions Group']); + } + + + /** @test */ + public function buttonInformationCbActivationPending(){ + $this->cbOnProduction('2023-02-02 10:00:00','123000'); + $this->cbOnProduction('2023-02-01 09:00:00','666'); + + $this->dispatch('/admin/payfip/index'); + $this->assertXPathContentContains('//button', 'Paiement CB : en cours d\'activation'); + } + + /** @test */ + public function buttonInformationCbActivated(){ + $this->cbOnProduction('2023-02-01 09:00:00','123000'); + $this->cbOnProduction('2023-02-01 09:00:00','666'); + $this->dispatch('/admin/payfip/index'); + + $this->assertXPathContentContains('//button', 'Paiement CB : activé'); + } + + + /** @test */ + public function buttonInformationTransferActivationPending(){ + $this->transferOnProduction('2023-02-02 10:00:00','123000'); + $this->transferOnProduction('2023-01-01 10:00:00','666'); + + $this->dispatch('/admin/payfip/index'); + + $this->assertXPathContentContains('//button', 'Paiement par prélèvement : en cours d\'activation'); + } + + + /** @test */ + public function buttonInformationTransferActivated(){ + $this->transferOnProduction('2023-02-01 10:00:00','123000'); + $this->transferOnProduction('2023-02-01 10:00:00','666'); + + $this->dispatch('/admin/payfip/index'); + + $this->assertXPathContentContains('//button', 'Paiement par prélèvement : activé'); + } + + + /** @test */ + public function unactivatedTransfertButtonShouldNotBeDisplayed() { + $this->transferOnProduction('2023-02-01 10:00:00','123000'); + $this->cbOnProduction('2023-02-02 09:00:00','666'); + $this->dispatch('/admin/payfip/index'); + + $this->assertXPathContentContains('//button[contains(@data-url,"/admin/payfip/activate")]', 'Activer le paiement CB'); + + $this->assertXPathContentContains('//button[contains(@data-url,"/admin/payfip/activate")]', 'Activer le paiement par prélèvement'); + } } diff --git a/tests/scenarios/Payfip/PayfipFixtures.php b/tests/scenarios/Payfip/PayfipFixtures.php index bae3342e9f74bb405bf9c243801992c1c1b93b97..69541e3d6e837927ddb87ad6b16fd3cf3d1ae94d 100644 --- a/tests/scenarios/Payfip/PayfipFixtures.php +++ b/tests/scenarios/Payfip/PayfipFixtures.php @@ -52,19 +52,33 @@ trait Trait_PayfipFixtures { } - public function cbOnProduction(string $date) { - if ($payment = Class_Payfip::find(600)) + public function setPayfipOnAir( $client_id) { + Class_WebService_Payfip_Client::setTimeSource(new TimeSourceForTest('2023-03-03 11:47:38')); + $this->cbOnProduction('2022-02-01 09:00:00', $client_id); + $this->transferOnProduction('2022-02-01 09:00:00', $client_id); + + } + + public function enableMultiplePayfip(bool $with_log=false) { + $this->enablePayfip($with_log); + Class_AdminVar::set(Class_AdminVar_Payfip::CLIENT_ID, '123000;666'); + } + + + public function cbOnProduction(string $date, int $client_id) { + if ($payment = Class_Payfip::find((int)$client_id)) $payment->delete(); $this->fixture(Class_Payfip::class, - ['id' => 600, + ['id' => (int) $client_id, + 'client_id' => $client_id, 'user' => Class_Users::getIdentity(), 'reference' => '1234781', 'paid_on' => $date, 'id_op' => 'toto', 'amount' => 1200, 'created_at' => Class_Payfip::getCurrentDateTime(), - 'type' =>'X', + 'type' => 'X', 'result' => Class_Payfip::RESULT_PAYED_BY_CB ]); return $this; @@ -72,21 +86,19 @@ trait Trait_PayfipFixtures { public function onTest() { - if ($payment = Class_Payfip::find(600)) - $payment->delete(); - if ($payment = Class_Payfip::find(601)) - $payment->delete(); + array_map(fn($payfip) => $payfip->delete(), Class_Payfip::findAll()); return $this; } - public function transferOnProduction(string $date) { - - if ($payment = Class_Payfip::find(601)) + public function transferOnProduction(string $date, int $client_id) { + $id = (int)$client_id +1; + if ($payment = Class_Payfip::find( $id)) $payment->delete(); return $this->fixture(Class_Payfip::class, - ['id' => 601, + ['id' => $id, + 'client_id' => $client_id, 'user' => Class_Users::getIdentity(), 'reference' => '1234782', 'paid_on' => $date, @@ -100,6 +112,9 @@ trait Trait_PayfipFixtures { public function disablePayfip() { + + $this->onTest(); + Class_AdminVar::set(Class_AdminVar_Payfip::TEST_USERS, ''); Class_AdminVar::set(Class_AdminVar_Payfip::CLIENT_ID, ''); Class_AdminVar::set(Class_AdminVar_Payfip::TESTUSER_MAIL, ''); Class_WebService_Payfip_Client::setSoapClient(null); @@ -107,7 +122,7 @@ trait Trait_PayfipFixtures { Class_Payfip::setTimeSource(null); Class_WebService_SIGB_Nanook_Service::shouldThrowError(false); - Class_AdminVar::set(Class_AdminVar_Payfip::HIDDEN, true); + Class_AdminVar::set(Class_AdminVar_Payfip::HIDDEN, false); return $this; } @@ -135,6 +150,7 @@ trait Trait_PayfipFixtures { public function getPaymentWithIdOp(int $id, Class_Users $user, string $id_op) : Class_Payfip { return $this->fixture(Class_Payfip::class, ['id' => $id, + 'client_id' => '123000', 'id_op' => $id_op, 'email' => $user->getMail(), 'user' => $user, diff --git a/tests/scenarios/Payfip/PayfipPermissionTest.php b/tests/scenarios/Payfip/PayfipPermissionTest.php index 98946df9c0a83f7c146f8014219604dbdb80bc29..dc6b49a1c0b141282fc8ad4ec32e2d8b8f272a17 100644 --- a/tests/scenarios/Payfip/PayfipPermissionTest.php +++ b/tests/scenarios/Payfip/PayfipPermissionTest.php @@ -34,6 +34,12 @@ class PayfipPermissionActivatedTest extends Admin_AbstractControllerTestCase { } + public function tearDown() { + $this->disablePayfip(); + parent::tearDown(); + } + + /** @test */ public function userGroupRightsShouldContainsPayfip() { $this->dispatch('admin/usergroup/edit/id/1'); diff --git a/tests/scenarios/Payfip/PayfipStartPaymentTest.php b/tests/scenarios/Payfip/PayfipStartPaymentTest.php index b997d7ab7bf2e8cbba2712ecf5491fc173a4e074..cffa190ca913c16c41c358c93455234d96f902d8 100644 --- a/tests/scenarios/Payfip/PayfipStartPaymentTest.php +++ b/tests/scenarios/Payfip/PayfipStartPaymentTest.php @@ -35,8 +35,8 @@ abstract class PayfipStartPaymentTestCase extends ModelTestCase { Class_AdminVar::set(Class_AdminVar_Payfip::HIDDEN, 0); Class_Payfip::setTimeSource(new TimeSourceForTest('2023-03-01 09:09:25')); $this->enablePayfip(true); - $this->cbOnProduction('2023-01-02 10:00:00'); - $this->transferOnProduction('2023-01-02 10:00:00'); + $this->cbOnProduction('2023-01-02 10:00:00','123000'); + $this->transferOnProduction('2023-01-02 10:00:00','123000'); $this->setupMockNanook($this->_nanook_client = new PayfipMockNanookClient); } @@ -87,6 +87,7 @@ class PayfipStartPaymentValidTest extends PayfipStartPaymentTestCase { ['reference', '20230109_090200'], ['user_id', 336], ['bib_id', 20], + ['client_id', '123000'], ['created_at', '2023-03-01 09:09:25'], ['library_name', 'Annecy'], ['email', 'user@server.io'], @@ -125,7 +126,88 @@ class PayfipStartPaymentValidTest extends PayfipStartPaymentTestCase { protected function _debtAt(int $pos) : Class_Debt { - return $this->_result->payfip()->getDebts()[$pos]; + return $this->_result->payfip()->getDebts('336')[$pos]; + } +} + + + + +class PayfipStartPaymentMultiSitesValidTest extends PayfipStartPaymentTestCase { + public function setUp() { + parent::setUp(); + $this->_nanook_client + ->onOpenUrl('/GetPatronInfo/patronId/336')->answerFile('patronInfoWithDebtsMultiSites.xml') + ->onOpenUrl('/AuthenticatePatron/')->answerFile('authenticatePatronSuccess.xml') + + ->onPostData('/StartPayment/patronId/336', + 'totalAmount=9.00&debtsIds=6236') + ->answerFile('startPaymentSuccess.xml') + ; + + $response = str_replace('{ID_OP}', + 'toto', + file_get_contents(__DIR__.'/creerPaiementSecuriseResponseOk.xml')); + + $this->_soap_client->onActionAnswers('creerPaiementSecurise', $response); + $user = Class_Users::find(336); + $this->_result = (new Class_User_Payment($user)) + ->start((new Class_Payfip_Debts)->valideForUser(['6236'], $user)); + } + + + /** @test */ + public function paymentShouldBeValid() { + $this->assertTrue($this->_result->isValid()); + } + + + public function payfipValues() : array { + return + [ + ['amount', 900], + ['reference', '20230109_090200'], + ['user_id', 336], + ['bib_id', 20], + ['created_at', '2023-03-01 09:09:25'], + ['library_name', 'Annecy'], + ['email', 'user@server.io'], + ['user_name', 'abonné'], + ['subscriber_id', 'L000383392992'], + ['sigb_last_error',''] + ]; + } + + + /** + * @test + * @dataProvider payfipValues + */ + public function payfipValueShouldBe($name, $value) { + $this->assertEquals($value, $this->_result->payfip()->callGetterByAttributeName($name)); + } + + + /** @test */ + public function firstDebtLabelValueShouldBeAbonnement() { + $this->assertEquals('Impression 100 crédits', $this->_debtAt(0)->getLabel()); + } + + + /** @test */ + public function firstDebtSigbIdShouldBe() { + $this->assertEquals('6236', $this->_debtAt(0)->getSigbId()); + } + + + /** @test */ + public function firstDebtAmountShouldBe9() { + $this->assertSame(900, $this->_debtAt(0)->getAmount()); + } + + + protected function _debtAt(int $pos) : Class_Debt { + return $this->_result->payfip()->getDebts('336')[$pos]; } } @@ -314,6 +396,17 @@ class PayfipStartPaymentErrorTest extends PayfipStartPaymentTestCase { $this->assertEquals($error_message, $result->error()); } + + + /** @test */ + public function noDebtsErrorshouldBeReturnIfNoDebts() { + $user = Class_Users::find(336); + $result = Class_Webservice_SIGB_Nanook::getService(['id_bib' => 20]) + ->startPayment($user, 6363, []); + + $this->assertEquals('Pas de dette sélectionnée ou id client payfip absent.', + $result->error()); + } } diff --git a/tests/scenarios/Payfip/PayfipSubscriberTest.php b/tests/scenarios/Payfip/PayfipSubscriberTest.php index 581bebf3711b0d68f710b970bb19b1b0c7e2c3de..8b14bd83593dce3c78e3d965552f7a99b48799b9 100644 --- a/tests/scenarios/Payfip/PayfipSubscriberTest.php +++ b/tests/scenarios/Payfip/PayfipSubscriberTest.php @@ -28,6 +28,7 @@ abstract class PayfipSubscriberTestCase extends AbstractControllerTestCase { parent::setUp(); Class_Payfip::setTimeSource(new TimeSourceForTest('2023-02-02 11:21:38')); $this->enablePayfip(true); + $this->_buildTemplateProfil(['id' => 78979, 'template' => 'CHILI']); $abonne = @@ -45,6 +46,8 @@ abstract class PayfipSubscriberTestCase extends AbstractControllerTestCase { public function tearDown() { $this->disablePayfip(); + Class_Profil::setCurrentProfil(Class_Profil::find(1)); + parent::tearDown(); } } @@ -57,7 +60,7 @@ class PayfipSubscriberGetPatronInfoNanookTest extends PayfipSubscriberTestCase { public function setUp() { parent::setUp(); - + $this->setPayfipOnAir('123000'); $web_client = new class() { public function open_url($url) : string { $map = ['/GetPatronInfo/patronId/336' => 'patronInfoWithDebts.xml', @@ -109,6 +112,207 @@ class PayfipSubscriberGetPatronInfoNanookTest extends PayfipSubscriberTestCase { +abstract class PayfipSubscriberMultipleSitesGetPatronInfoNanookTest extends PayfipSubscriberTestCase { + protected Class_WebService_SIGB_Emprunteur $_subscriber; + + public function setUp() { + parent::setUp(); + $this->_mockNanook(); + } + + + public function _mockNanook() { + + $web_client = new class() { + public function open_url($url) : string { + $map = ['/GetPatronInfo/patronId/336' => 'patronInfoWith2MultiSites.xml', + '/AuthenticatePatron/' => 'authenticatePatronSuccess.xml']; + + foreach($map as $url_part => $response_file) + if (false !== strpos($url, $url_part)) + return file_get_contents(__DIR__ . '/' . $response_file); + + throw new RuntimeException('Unkown url ' . $url); + } + }; + + $this->_subscriber = $this->setupMockNanook($web_client) + ->getNanookSubscriber(); + } +} + + + + +class PayfipSubscriberMultipleSitesWithOnePayfipEnableTest extends PayfipSubscriberMultipleSitesGetPatronInfoNanookTest { + public function setUp() { + parent::setUp(); + ZendAfi_Auth::getInstance()->logUser(Class_Users::find(336)); + $this->setPayfipOnAir('123000'); + } + + + /** @test */ + public function subscribeShouldHave1Debts() { + $this->assertEquals( 1, $this->_subscriber->numberOfDebts()); + } + + + public function debts() : array { + $debts = [ + ['6237', 'Impression 100 crédits', 900], + ]; + + return array_map(fn($position, $datas) => [$position, $datas], + array_keys($debts), $debts); + } + + + /** + * @test + * @dataProvider debts + */ + public function debtAtPositionDataShouldBe(int $position, array $datas) { + $debt = $this->_subscriber->getDebts()[$position]; + $this->assertEquals($datas[0], $debt->getId()); + $this->assertEquals($datas[1], $debt->getLabel()); + $this->assertEquals($datas[2], $debt->getAmount()); + } +} + + + + +class PayfipSubscriberMultipleSitesWithTwoPayfipEnableTest extends PayfipSubscriberMultipleSitesGetPatronInfoNanookTest { + public function setUp() { + parent::setUp(); + Class_AdminVar::set(Class_AdminVar_Payfip::CLIENT_ID, '123000;666'); + $this->setPayfipOnAir('123000'); + $this->setPayfipOnAir('666'); + $this->_mockNanook(); + } + + + /** @test */ + public function subscribeShouldHave2Debts() { + $this->assertEquals( 2, $this->_subscriber->numberOfDebts()); + } + + + public function debts() : array { + $debts = [ + ['6237', 'Impression 100 crédits', 900], + ['6238', 'Lettre retard',800], + ]; + + return array_map(fn($position, $datas) => [$position, $datas], + array_keys($debts), $debts); + } + + + /** + * @test + * @dataProvider debts + */ + public function debtAtPositionDataShouldBe(int $position, array $datas) { + $debt = $this->_subscriber->getDebts()[$position]; + $this->assertEquals($datas[0], $debt->getId()); + $this->assertEquals($datas[1], $debt->getLabel()); + $this->assertEquals($datas[2], $debt->getAmount()); + } +} + + + + +class PayfipSubscriberMultipleSitesWithTwoPayfipOneNotInproductionTest extends PayfipSubscriberMultipleSitesGetPatronInfoNanookTest { + public function setUp() { + parent::setUp(); + ZendAfi_Auth::getInstance()->logUser(Class_Users::find(336)); + $this->setPayfipOnAir(666); + Class_AdminVar::set(Class_AdminVar_Payfip::CLIENT_ID, '123000;666'); + + $this->_mockNanook(); + } + + + /** @test */ + public function subscribeShouldHave1Debts() { + $this->assertEquals( 1, $this->_subscriber->numberOfDebts()); + } + + + /** @test */ + public function subscribeAsTestUserShouldHave2Debts() { + Class_AdminVar::set(Class_AdminVar_Payfip::TEST_USERS, Class_Users::getIdentity()->getLogin()); + $this->assertEquals( 2, $this->_subscriber->numberOfDebts()); + } + + + public function debts() : array { + return [ + ['6238', 'Lettre retard',800] + ]; + } + + + /** + * @test + * @dataProvider debts + */ + public function debtAtPositionDataShouldBe( $id, $label, $amount) { + $debts = $this->_subscriber->getDebts(); + $debt= current($debts); + $this->assertEquals($id, $debt->getId()); + $this->assertEquals($label, $debt->getLabel()); + $this->assertEquals($amount, $debt->getAmount()); + } +} + + + +class PayfipSubscriberMultipleSitesWithTwoPayfipNotInproductionTest extends PayfipSubscriberMultipleSitesGetPatronInfoNanookTest { + public function setUp() { + parent::setUp(); + ZendAfi_Auth::getInstance()->logUser(Class_Users::find(336)); + Class_AdminVar::set(Class_AdminVar_Payfip::CLIENT_ID, '123000;666'); + Class_AdminVar::set(Class_AdminVar_Payfip::TEST_USERS, Class_Users::getIdentity()->getLogin()); + $this->_mockNanook(); + } + + + /** @test */ + public function subscribeShouldHave2Debts() { + $this->assertEquals( 2, $this->_subscriber->numberOfDebts()); + } + + + public function debts() : array { + $debts = [ + ['6237', 'Impression 100 crédits', 900], + ['6238', 'Lettre retard',800], + ]; + + return array_map(fn($position, $datas) => [$position, $datas], + array_keys($debts), $debts); + } + + + /** + * @test + * @dataProvider debts + */ + public function debtAtPositionDataShouldBe(int $position, array $datas) { + $debt = $this->_subscriber->getDebts()[$position]; + $this->assertEquals($datas[0], $debt->getId()); + $this->assertEquals($datas[1], $debt->getLabel()); + $this->assertEquals($datas[2], $debt->getAmount()); + } +} + + + + abstract class PayfipSubscriberLoginTestCase extends PayfipSubscriberTestCase { public function setUp() { @@ -153,8 +357,8 @@ abstract class PayfipSubscriberLoginTestCase extends PayfipSubscriberTestCase { $this->onTest(); if ($this->_adminvar_status=='PRODUCTION'){ - $this->cbOnProduction('2023-01-02 10:00:00'); - $this->transferOnProduction('2023-01-02 10:00:00'); + $this->cbOnProduction('2023-01-02 10:00:00','123000'); + $this->transferOnProduction('2023-01-02 10:00:00','123000'); } if (!empty($this->_adminvar_hidden)) @@ -310,7 +514,6 @@ class PayfipSubscriberCancelServicesTestCase extends PayfipSubscriberTestCase { 'paymentInfo' => ''])) ->answerFile('endPaymentResponseSuccess.xml'); - $this ->enablePayfip(true) ->setupMockNanook($this->_nanook_client); @@ -345,7 +548,6 @@ class PayfipSubscriberCancelServicesTestCase extends PayfipSubscriberTestCase { - class PayfipSubscriberBorrowerLinksTest extends PayfipSubscriberLoginTestCase { protected $_adminvar_status = 'PRODUCTION'; protected function _openUrl() : void { @@ -415,7 +617,6 @@ class PayfipSubscriberDisplayTest extends PayfipSubscriberLoginTestCase { Class_Users::getIdentity()->setIdSite(0)->save(); Class_Users::getIdentity()->setIdIntBib(0)->save(); $this->dispatch('/abonne/debts'); - $this->assertXPathContentContains('//p', 'nous contacter à myprofile@mybib.org'); } diff --git a/tests/scenarios/Payfip/PayfipTemplatesAbonneTest.php b/tests/scenarios/Payfip/PayfipTemplatesAbonneTest.php index 03c9e20f7962ce3a01470b52a4386ae12275b85b..53fd6c3c503389f641c6e0a64611b720e4d7505e 100644 --- a/tests/scenarios/Payfip/PayfipTemplatesAbonneTest.php +++ b/tests/scenarios/Payfip/PayfipTemplatesAbonneTest.php @@ -26,10 +26,8 @@ abstract class PayfipTemplatesAbonneTestCase extends AbstractControllerTestCase use Trait_PayfipFixtures; - protected MockMailTransport $_mail_transport; - public function setUp() { parent::setUp(); $this->_mail_transport = new MockMailTransport(); @@ -37,9 +35,13 @@ abstract class PayfipTemplatesAbonneTestCase extends AbstractControllerTestCase Class_AdminVar::set(Class_AdminVar_Payfip::HIDDEN, 0); Class_Payfip::setTimeSource(new TimeSourceForTest('2023-02-02 11:21:38')); - $this->cbOnProduction('2022-02-02 11:21:38'); - $this->transferOnProduction('2022-02-02 11:21:38'); + $this->activatePayfip(); + } + + protected function activatePayfip() { + $this->cbOnProduction('2022-02-02 11:21:38','123000'); + $this->transferOnProduction('2022-02-02 11:21:38','123000'); $gildor = $this->fixture(Class_Users::class, ['id' => 42, 'nom' => 'Achim Noan Nini', @@ -59,7 +61,12 @@ abstract class PayfipTemplatesAbonneTestCase extends AbstractControllerTestCase public function assertBeJournalize( $message) { $this->assertContains( $message, Class_Journal::lastOf(Class_Journal_WebclientType::MY_TYPE)->getDetail(Class_Journal_WebclientType::RESPONSE)->getValue()); + } + + public function tearDown() { + $this->disablePayfip(); + parent::tearDown(); } @@ -265,7 +272,6 @@ class PayfipTemplatesAbonneRefreshPayfipandIlsUpdatedTest extends PayfipTemplate 'amount' => 800]) ]]); - $response = file_get_contents(__DIR__.'/recupererDetailPaiementSecuriseCanceled.xml'); $this->_soap_client->onActionAnswers('recupererDetailPaiementSecurise', $response); @@ -283,13 +289,16 @@ class PayfipTemplatesAbonneRefreshPayfipandIlsUpdatedTest extends PayfipTemplate return file_get_contents(__DIR__ . '/' . $response_file); throw new RuntimeException('Unkown url ' . $url); } + + public function journalize( $bool) { return true; } + + public function postRawData() { return true; } - }; $this->setupMockNanook($web_client); @@ -312,8 +321,8 @@ abstract class PayfipTemplatesAbonneDebtsDisplayTestCase extends PayfipTemplates parent::setUp(); $this->enablePayfip(true); - $this->_buildTemplateProfil(['id' => 172]); + $this->_buildTemplateProfil(['id' => 111])->beCurrentProfil(); $user = $this->createUserForSite(336, 'hubert', $this->getBibAnnecy()); $this->setupMockNanook($this->_nanook_client = new PayfipMockNanookClient); $this->_nanook_client @@ -430,6 +439,103 @@ abstract class PayfipTemplatesAbonneDebtsDisplayTestCase extends PayfipTemplates +class PayfipTemplatesAbonneDebts2SitesDisplayTestCase extends PayfipTemplatesAbonneTestCase { + protected $_nanook_client; + + public function setUp() { + parent::setUp(); + } + + + protected function activatePayfip() { + $this->_buildTemplateProfil(['id' => 172]); + $cfg_accueil = ['modules' => [['division' => 4, + 'type_module' => 'LOGIN', + 'preferences' => []]]]; + + Class_Profil::getCurrentProfil() + ->setCfgAccueil($cfg_accueil) + ->assertSave(); + + Class_AdminVar::set(Class_AdminVar_Payfip::TEST_USERS, ''); + $this->enableMultiplePayfip(true); + $this->setPayfipOnAir('123000'); + $this->setPayfipOnAir('666'); + $user = $this->createUserForSite(336, 'hubert', $this->getBibAnnecy()); + $this->setupMockNanook($this->_nanook_client = new PayfipMockNanookClient); + $this->_nanook_client + ->onOpenUrl('/GetPatronInfo/patronId/336')->answerFile('patronInfoWith2MultiSites.xml') + ->onOpenUrl('/AuthenticatePatron/')->answerFile('authenticatePatronSuccess.xml'); + + ZendAfi_Auth::getInstance()->logUser($user); + } + + + /** @test */ + public function debtsShouldBeDisplayedOnLoginWidget() { + $this->dispatch('/index/index'); + $this->assertXPath('//a[@href="/abonne/debts"][@class="card-link account-booking"]/div[@class="d-inline button_text text-left"][text()="2 prestations à régler"]'); + } + + + /** @test */ + public function contentTableFifthRowSecondColumnShouldContains_BadgeAmount_2() { + $this->dispatch('/abonne/debts'); + + $this->assertXPath('//span[contains(@class, "badge_tag")]/span[contains(@class, "badge_text")][text()="9€00"]', $this->_response->getBody()); + $this->assertXPath('//span[contains(@class, "badge_tag")]/span[contains(@class, "badge_text")][text()="8€00"]', $this->_response->getBody()); + } +} + + + + +class PayfipTemplatesAbonneDebts2SitesOneAvailableDisplayTestCase extends PayfipTemplatesAbonneTestCase { + protected $_nanook_client; + + + protected function activatePayfip() { + $this->_buildTemplateProfil(['id' => 172]); + $cfg_accueil = ['modules' => [['division' => 4, + 'type_module' => 'LOGIN', + 'preferences' => []]]]; + + Class_Profil::getCurrentProfil() + ->setCfgAccueil($cfg_accueil) + ->assertSave(); + Class_AdminVar::set(Class_AdminVar_Payfip::TEST_USERS, ''); + $this->enableMultiplePayfip(true); + $this->setPayfipOnAir('666'); + $user = $this->createUserForSite(336, 'hubert', $this->getBibAnnecy()); + $this->setupMockNanook($this->_nanook_client = new PayfipMockNanookClient); + $this->_nanook_client + ->onOpenUrl('/GetPatronInfo/patronId/336')->answerFile('patronInfoWith2MultiSites.xml') + ->onOpenUrl('/AuthenticatePatron/')->answerFile('authenticatePatronSuccess.xml'); + + ZendAfi_Auth::getInstance()->logUser($user); + } + + + /** @test */ + public function debtsShouldBeDisplayedOnLoginWidget() { + $this->dispatch('/index/index'); + + $this->assertXPath('//a[@href="/abonne/debts"][@class="card-link account-booking"]/div[@class="d-inline button_text text-left"][text()="1 prestation à régler"]'); + } + + + /** @test */ + public function contentTableFifthRowSecondColumnShouldContains_BadgeAmount_2() { + $this->dispatch('/abonne/debts'); + + $this->assertNotXPath('//span[contains(@class, "badge_tag")]/span[contains(@class, "badge_text")][text()="9€00"]', $this->_response->getBody()); + $this->assertXPath('//span[contains(@class, "badge_tag")]/span[contains(@class, "badge_text")][text()="8€00"]', $this->_response->getBody()); + } +} + + + + class PayfipTemplatesAbonneDebtsHistoriqueTest extends PayfipTemplatesAbonneDebtsDisplayTestCase { const TABLE_PATH = '//table[contains(@class, "table")][@id="Class_Debt-historic"]/tbody/'; @@ -882,7 +988,7 @@ class PayfipTemplatesAbonneDebtsAPayerTest extends PayfipTemplatesAbonneDebtsDis } - /** @test */ + /** @test */ public function formFirstDebtAmountShouldBe10E() { $this->assertXPathContentContains('//form/div[1][@class="form_row_as_table row col-12 no-gutters m-0 p-0 py-2 border-top"]/div[2]', '10€12'); } @@ -894,13 +1000,13 @@ class PayfipTemplatesAbonneDebtsAPayerTest extends PayfipTemplatesAbonneDebtsDis } - /** @test */ + /** @test */ public function formSecondDebtShouldBeBoiterCasse() { $this->assertXPathContentContains('//form/div[2][@class="form_row_as_table row col-12 no-gutters m-0 p-0 py-2 border-top"]/div[1]', 'Boitier cassé'); } - /** @test */ + /** @test */ public function formSecondDebtAmountShouldBe1E5() { $this->assertXPathContentContains('//form/div[2][@class="form_row_as_table row col-12 no-gutters m-0 p-0 py-2 border-top"]/div[2]', '1€50'); } @@ -912,13 +1018,13 @@ class PayfipTemplatesAbonneDebtsAPayerTest extends PayfipTemplatesAbonneDebtsDis } - /** @test */ + /** @test */ public function formThirdDebtShouldBePhotocopies() { $this->assertXPathContentContains('//form/div[3][@class="form_row_as_table row col-12 no-gutters m-0 p-0 py-2 border-top"]/div[1]', 'Photocopies (10) (Quantité 6)'); } - /** @test */ + /** @test */ public function formThirdDebtAmountShouldBe6ETwentyTwoCents() { $this->assertXPathContentContains('//form/div[3][@class="form_row_as_table row col-12 no-gutters m-0 p-0 py-2 border-top"]/div[2]', '6€22'); } @@ -1010,8 +1116,8 @@ class PayfipTemplatesAbonneDebtsPayDispatchErrorTest public function shouldDisplayMandatoryEmail() { $this->setupMockNanook($this->_nanook_client = new PayfipMockNanookClient); Class_Payfip::deleteBy([]); - $this->cbOnProduction('2022-02-02 11:21:38'); - $this->transferOnProduction('2022-02-02 11:21:38'); + $this->cbOnProduction('2022-02-02 11:21:38','123000'); + $this->transferOnProduction('2022-02-02 11:21:38','123000'); $this->_nanook_client ->onOpenUrl('/GetPatronInfo/patronId/336')->answerFile('patronInfoWithDebts.xml') @@ -1043,8 +1149,8 @@ class PayfipTemplatesAbonneDebtsPayDispatchWithValidDebtsTest protected function _dispatch() : void { $this->setupMockNanook($this->_nanook_client = new PayfipMockNanookClient); Class_Payfip::deleteBy([]); - $this->cbOnProduction('2022-02-02 11:21:38'); - $this->transferOnProduction('2022-02-02 11:21:38'); + $this->cbOnProduction('2022-02-02 11:21:38','123000'); + $this->transferOnProduction('2022-02-02 11:21:38','123000'); $this->_nanook_client ->onOpenUrl('/GetPatronInfo/patronId/336')->answerFile('patronInfoWithDebts.xml') @@ -1235,6 +1341,7 @@ class PayfipTemplatesAbonneDebtsPayDispatchWithSigbErrorTest ['DebtAmountError', 'Le montant total ne correspond pas au montant fourni'], ['DebtIdNotFound', 'Au moins une dette n\'a pas été trouvée'], ['StartPaymentTechnicalError', 'Une erreur inconnue est survenue'], + ['DebtsWithDifferentsPaymentsReceivers', 'Les paiements correspondent à des bibliothèques différentes. Merci d\'effectuer le paiement bibliothèque par bibliothèque.'], ['XXX_UNKNOWN_ERROR', 'Erreur inconnue : XXX_UNKNOWN_ERROR'], ]; } @@ -1315,7 +1422,6 @@ class PayfipTemplatesAbonneDebtsPayDispatchWithPayfipStartErrorTest $this->assertEquals( null, Class_Payfip::findFirstBy(['id_op' => null])->getSigbLastError()); $this->assertEquals( 'Une erreur est survenue lors d\'une tentative de paiement vers Payfip<br/>Code de l\'erreur : {"label":"Le format du param\u00e8tre REFDET n\'est pas conforme","code":"R3","severity":"2"}. <br/>Message d\'erreur:', quoted_printable_decode($this->_mail_transport->getSentMails()[0]->getBodyHtml(true)) ); - } @@ -1354,7 +1460,7 @@ class PayfipTemplatesAbonneDebtsPayDispatchWithPayfipStartErrorTest public function urlShouldKeepInspectorGadgetParameter() { $this->dispatch('/abonne/debts/inspector_gadget/keep'); $this->assertXPathContentContains('//a/@href','debts/inspector_gadget/keep'); - } + } } @@ -1373,7 +1479,6 @@ abstract class PayfipTemplatesAbonneDebtsWithPayfipUnkownAndRefreshTestCase . '/recupererDetailPaiementSecurise' . $this->_recupererDetailStatus .'.xml')); - $this->_soap_client->onActionAnswers('recupererDetailPaiementSecurise', $response); $this->dispatch('/abonne/debts/historic-limit/all'); } @@ -1392,7 +1497,6 @@ class PayfipTemplatesAbonneDebtsIndexWithPayfipUnkownAndRefreshTest extends PayfipTemplatesAbonneDebtsWithPayfipUnkownAndRefreshTestCase { protected string $_recupererDetailStatus = 'Paid'; - /** @test */ public function prestationsEnCoursDePaiementShouldBeEmpty() { $this->assertNotXPath('//div[@class="col-12"]//h3[.="Prestations en cours de traitement"]/following-sibling::text()'); @@ -1430,7 +1534,6 @@ class PayfipTemplatesAbonneDebtsIndexWithPayfipUnkownAndRefreshWithErrorTest extends PayfipTemplatesAbonneDebtsDisplayTestCase { protected string $_recupererDetailStatus = 'Error'; - /** @test */ public function tableDebtCurrentLinesCountShouldBeFive() { $this->assertXPathCount('//table[@id="Class_Debt-current"]//tr', @@ -1452,7 +1555,7 @@ class PayfipTemplatesAbonneDebtsIndexWithPayfipUnkownAndRefreshWithErrorTest } - /** @test */ + /** @test */ public function journalShouldContainsError() { $this->assertContains('Payfip en erreur pour la transaction', Class_Journal::lastOf(Class_Journal_SoapCallType::MY_TYPE)->getDetail(Class_Journal_SoapCallType::DESCRIPTION)->getValue()); diff --git a/tests/scenarios/Payfip/PayfipWebserviceTest.php b/tests/scenarios/Payfip/PayfipWebserviceTest.php index e65b37a2dacb175cd40f2f90bda4708192f119a1..526518479be78370c19081aa3a8fb1d6acf4167f 100644 --- a/tests/scenarios/Payfip/PayfipWebserviceTest.php +++ b/tests/scenarios/Payfip/PayfipWebserviceTest.php @@ -119,7 +119,7 @@ class PayfipWebserviceActivationTest extends Admin_AbstractControllerTestCase { file_get_contents(__DIR__.'/creerPaiementSecuriseResponseOk.xml')); $this->_soap_client->onActionAnswers('creerPaiementSecurise', $response); - $this->dispatch('/admin/payfip/activate'); + $this->dispatch('/admin/payfip/activate/id/123000'); } @@ -173,9 +173,9 @@ class PayfipWebservicePaymentButtonTest extends Admin_AbstractControllerTestCase parent::setUp(); $this->enablePayfip(true); Class_Payfip::setTimeSource(new TimeSourceForTest('2023-02-02 11:21:38')); - $this->cbOnProduction('2023-02-02 10:00:00'); + $this->cbOnProduction('2023-02-02 10:00:00','123000'); Class_Payfip::setTimeSource(new TimeSourceForTest('2023-02-02 12:21:38')); - $this->transferOnProduction('2023-02-02 10:00:00'); + $this->transferOnProduction('2023-02-02 10:00:00','123000'); Class_AdminVar::set('PAYFIP_TESTUSER_MAIL', 'mypayfiptest@mymail.org'); $response = str_replace('{ID_OP}', @@ -183,7 +183,7 @@ class PayfipWebservicePaymentButtonTest extends Admin_AbstractControllerTestCase file_get_contents(__DIR__.'/creerPaiementSecuriseResponseOk.xml')); $this->_soap_client->onActionAnswers('creerPaiementSecurise', $response); - $this->dispatch('/admin/payfip/payment-test'); + $this->dispatch('/admin/payfip/payment-test/id/123000'); } @@ -229,9 +229,9 @@ class PayfipWebserviceCreateOkTest extends PayfipWebserviceActivatedTestCase { public function setUp() { parent::setUp(); Class_Payfip::setTimeSource(new TimeSourceForTest('2023-02-02 11:21:38')); - $this->cbOnProduction('2023-02-02 10:00:00'); + $this->cbOnProduction('2023-02-02 10:00:00','123000'); Class_Payfip::setTimeSource(new TimeSourceForTest('2023-02-02 12:21:38')); - $this->transferOnProduction('2023-02-02 10:00:00'); + $this->transferOnProduction('2023-02-02 10:00:00','123000'); $response = str_replace('{ID_OP}', 'toto', @@ -239,7 +239,7 @@ class PayfipWebserviceCreateOkTest extends PayfipWebserviceActivatedTestCase { $this->_soap_client->onActionAnswers('creerPaiementSecurise', $response); - $this->_payment = Class_Payfip::buildForTest(); + $this->_payment = Class_Payfip::buildForTest('123000'); Class_AdminVar::set('FORCE_HTTPS', 1); $this->_payment_url = (new Class_WebService_Payfip_Client)->paymentUrlFor($this->_payment); } @@ -309,7 +309,7 @@ class PayfipWebserviceCreateBadRefdetErrorTest extends PayfipWebserviceActivated $response = file_get_contents(__DIR__.'/creerPaiementSecuriseResponseBadRefdet.xml'); $this->_soap_client->onActionAnswers('creerPaiementSecurise', $response); - $this->_payment = Class_Payfip::buildForTest(); + $this->_payment = Class_Payfip::buildForTest('123000'); $this->_payment_url = (new Class_WebService_Payfip_Client)->paymentUrlFor($this->_payment); } diff --git a/tests/scenarios/Payfip/patronInfoWith2MultiSites.xml b/tests/scenarios/Payfip/patronInfoWith2MultiSites.xml new file mode 100644 index 0000000000000000000000000000000000000000..263a5da6879b2bcadc10e1053ee319348672b1fd --- /dev/null +++ b/tests/scenarios/Payfip/patronInfoWith2MultiSites.xml @@ -0,0 +1,95 @@ +<?xml version="1.0" encoding="UTF-8"?> +<GetPatronInfo> + <patronId>28434</patronId> + <siteId>20</siteId> + <barcode>336</barcode> + <cardType>Individuel</cardType> + <cardStatus>Carte active</cardStatus> + <notes> + </notes> + <newsletter>0</newsletter> + <alertPreviousLoanOnDocument>1</alertPreviousLoanOnDocument> + <noAnonymization>0</noAnonymization> + <loanForbidden>0</loanForbidden> + <holdForbidden>0</holdForbidden> + <parentalAuthorization>1</parentalAuthorization> + <multimediaAccess>0</multimediaAccess> + <lastName>TEST PAYFIP</lastName> + <firstName>Estelle</firstName> + <displayOrder>1</displayOrder> + <birthDate>2000-01-01</birthDate> + <phoneNumber> + </phoneNumber> + <mail> + </mail> + <endDate>2025-03-06</endDate> + <sendingChannels> + <sendingChannel> + <id>0</id> + <label>Indifférent</label> + <favorite>true</favorite> + </sendingChannel> + <sendingChannel> + <id>1</id> + <label>Courriel</label> + </sendingChannel> + <sendingChannel> + <id>2</id> + <label>SMS</label> + </sendingChannel> + <sendingChannel> + <id>3</id> + <label>Courrier</label> + </sendingChannel> + </sendingChannels> + <town> + </town> + <zipcode> + </zipcode> + <address> + </address> + <loans/> + <holds/> + <suggests/> + <subscriptions> + <subscription> + <rateId>1</rateId> + <rateLabel>Individuel</rateLabel> + <startDate>2024-03-06</startDate> + <endDate>2025-03-06</endDate> + </subscription> + </subscriptions> + <paymentsReceivers> + <paymentReceiver> + <id>2</id> + <label>Régie Mauléon</label> + <payFipId>123000</payFipId> + </paymentReceiver> + <paymentReceiver> + <id>1</id> + <label>Régie Bressuire</label> + <payFipId>666</payFipId> + </paymentReceiver> + </paymentsReceivers> + <debts> + <debt> + <id>6237</id> + <label>Impression 100 crédits</label> + <amount>9.00</amount> + <paymentReceiverId>2</paymentReceiverId> + </debt> + <debt> + <id>6238</id> + <label>Lettre retard</label> + <amount>8.00</amount> + <paymentReceiverId>1</paymentReceiverId> + </debt> + <debt> + <id>6234</id> + <label>Abonnement</label> + <amount>25.00</amount> + <paymentReceiverId>2</paymentReceiverId> + <paymentId>20240306a142957Test</paymentId> + </debt> + </debts> +</GetPatronInfo> diff --git a/tests/scenarios/Payfip/patronInfoWithDebts.xml b/tests/scenarios/Payfip/patronInfoWithDebts.xml index be01e988f6fbb3bdb65c05da931cd6c407f1bda1..646e2c2c811dced9a40b08b96fa0093011db5f68 100644 --- a/tests/scenarios/Payfip/patronInfoWithDebts.xml +++ b/tests/scenarios/Payfip/patronInfoWithDebts.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <GetPatronInfo> - <patronId>24453</patronId> + <patronId>28434</patronId> <siteId>3</siteId> <barcode>336</barcode> <cardType>Individuel</cardType> diff --git a/tests/scenarios/Payfip/patronInfoWithDebtsMultiSites.xml b/tests/scenarios/Payfip/patronInfoWithDebtsMultiSites.xml new file mode 100644 index 0000000000000000000000000000000000000000..2339e96ff6372a34c3f4fd8d2b3754c87226b915 --- /dev/null +++ b/tests/scenarios/Payfip/patronInfoWithDebtsMultiSites.xml @@ -0,0 +1,84 @@ +<?xml version="1.0" encoding="UTF-8"?> +<GetPatronInfo> + <patronId>28434</patronId> + <siteId>3</siteId> + <barcode>336</barcode> + <cardType>Individuel</cardType> + <cardStatus>Carte active</cardStatus> + <notes> + </notes> + <newsletter>0</newsletter> + <alertPreviousLoanOnDocument>1</alertPreviousLoanOnDocument> + <noAnonymization>0</noAnonymization> + <loanForbidden>0</loanForbidden> + <holdForbidden>0</holdForbidden> + <parentalAuthorization>1</parentalAuthorization> + <multimediaAccess>0</multimediaAccess> + <lastName>TEST PAYFIP</lastName> + <firstName>Estelle</firstName> + <displayOrder>1</displayOrder> + <birthDate>2000-01-01</birthDate> + <phoneNumber> + </phoneNumber> + <mail> + </mail> + <endDate>2025-03-06</endDate> + <sendingChannels> + <sendingChannel> + <id>0</id> + <label>Indifférent</label> + <favorite>true</favorite> + </sendingChannel> + <sendingChannel> + <id>1</id> + <label>Courriel</label> + </sendingChannel> + <sendingChannel> + <id>2</id> + <label>SMS</label> + </sendingChannel> + <sendingChannel> + <id>3</id> + <label>Courrier</label> + </sendingChannel> + </sendingChannels> + <town> + </town> + <zipcode> + </zipcode> + <address> + </address> + <loans/> + <holds/> + <suggests/> + <subscriptions> + <subscription> + <rateId>1</rateId> + <rateLabel>Individuel</rateLabel> + <startDate>2024-03-06</startDate> + <endDate>2025-03-06</endDate> + </subscription> + </subscriptions> + <paymentsReceivers> + <paymentReceiver> + <id>2</id> + <label>Régie Mauléon</label> + <payFipId>123000</payFipId> + </paymentReceiver> + </paymentsReceivers> + <debts> + <debt> + <id>6234</id> + <label>Abonnement</label> + <amount>25.00</amount> + <paymentReceiverId>2</paymentReceiverId> + <paymentId>20240306a142957Test</paymentId> + </debt> + <debt> + <id>6236</id> + <label>Impression 100 crédits</label> + <amount>9.00</amount> + <paymentReceiverId>2</paymentReceiverId> + </debt> + </debts> +</GetPatronInfo>