Skip to content

Commit 8e1117e

Browse files
committed
correction tests fonctionnels liés à Paybox
Les tests fonctionnels qui appellait paybox ne passaient plus, par exemple https://github.com/afup/web/actions/runs/29336322441/job/87099244889?pr=2317 Cela pour deux raisons. La première, il y a maintenant une seconde étape, un autre formulaire à valider avant de saisir le numéro de carte. Et ensuite la seconde, qui ne concernait que le scénario "Scenario: Accès à l'adhésion entreprise" Paybox nous renvoyait une erreur : "An error occurred while creating or updating row in fappel". A priori car le cmd envoyé dans ce cas n'était pas unique. On ajoute donc un élement unique à la fin et le supprime dans le callback pour ne pas inteférer avec son parsing.
1 parent cf4adaf commit 8e1117e

5 files changed

Lines changed: 31 additions & 5 deletions

File tree

sources/AppBundle/Controller/Website/Membership/PayboxCallbackAction.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,26 @@ public function __invoke(Request $request): Response
4848
$etat = MembershipFeePaymentStatus::Rejected;
4949
}
5050

51+
$cmd = $payboxResponse->getCmd();
52+
53+
// cf payboxfactory, on a un suffixe pour gérer l'unicité et éviter une erreur "An error occurred while creating or updating row in fappel"
54+
$suffixPos = strpos($cmd, '__');
55+
if (false !== $suffixPos) {
56+
$cleanedCmd = substr($cmd, 0, $suffixPos);
57+
}
58+
5159
if ($etat == MembershipFeePaymentStatus::Paid) {
52-
$account = $this->onlinePaymentHandler->getAccountFromCmd($payboxResponse->getCmd());
60+
$account = $this->onlinePaymentHandler->getAccountFromCmd($cleanedCmd);
5361
$lastCotisation = $this->membershipFeeService->getLatestByUserTypeAndId(MemberType::from($account['type']), $account['id']);
5462

5563
if (!$lastCotisation instanceof MembershipFee && $account['type'] == MemberType::MemberPhysical->value) {
5664
$user = $this->userRepository->get($account['id']);
5765
$this->eventDispatcher->dispatch(new NewMemberEvent($user));
5866
}
5967

60-
$this->onlinePaymentHandler->validerReglementEnLigne($payboxResponse->getCmd(), round($payboxResponse->getTotal() / 100, 2), $payboxResponse->getAuthorizationId(), $payboxResponse->getTransactionId());
61-
$this->membershipFeeMailer->notifierReglementEnLigneAuTresorier($payboxResponse->getCmd(), round($payboxResponse->getTotal() / 100, 2), $payboxResponse->getAuthorizationId(), $payboxResponse->getTransactionId());
62-
$this->audit->log("Ajout de la cotisation " . $payboxResponse->getCmd() . " via Paybox.");
68+
$this->onlinePaymentHandler->validerReglementEnLigne($cleanedCmd, round($payboxResponse->getTotal() / 100, 2), $payboxResponse->getAuthorizationId(), $payboxResponse->getTransactionId());
69+
$this->membershipFeeMailer->notifierReglementEnLigneAuTresorier($cleanedCmd, round($payboxResponse->getTotal() / 100, 2), $payboxResponse->getAuthorizationId(), $payboxResponse->getTransactionId());
70+
$this->audit->log("Ajout de la cotisation " . $cleanedCmd. " via Paybox.");
6371
}
6472
return new Response();
6573
}

sources/AppBundle/Payment/PayboxFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function createPayboxForSubscription($facture, $montant, $email, PayboxBi
3434

3535
$paybox
3636
->setTotal((int) $montant * 100) // Total de la commande, en centimes d'euros
37-
->setCmd($facture) // Référence de la commande
37+
->setCmd($facture . '__' . uniqid()) // Référence de la commande + un suffixe pour gérer l'unicité et éviter une erreur "An error occurred while creating or updating row in fappel" sur paybox notamment en environnement de test
3838
->setPorteur($email) // Email du client final (Le porteur de la carte)
3939
->setUrlRetourEffectue($this->router->generate('membership_payment_redirect', ['type' => 'success'], RouterInterface::ABSOLUTE_URL))
4040
->setUrlRetourRefuse($this->router->generate('membership_payment_redirect', ['type' => 'refused'], RouterInterface::ABSOLUTE_URL))

tests/behat/bootstrap/FormContext.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ public function submitFormWithName(string $formName): void
2525
$form->submit();
2626
}
2727

28+
#[Then('I submit the form with id :formId')]
29+
public function submitFormWithId(string $formId): void
30+
{
31+
$form = $this->minkContext->getSession()->getPage()->find('xpath', "//form[@id='$formId']");
32+
33+
if (null === $form) {
34+
throw new ExpectationException(
35+
sprintf('The form of id "%s" not found', $formId),
36+
$this->minkContext->getSession()->getDriver(),
37+
);
38+
}
39+
40+
$form->submit();
41+
}
42+
2843
#[Then('The :field field should only contain the follow values :expectedValuesJson')]
2944
public function selectHasValues(string $field, string $expectedValuesJson): void
3045
{

tests/behat/features/EventPages/Ticketing.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Feature: Event pages - Ticketing
3232
When I press "Régler par carte"
3333
# Pour suivre la redirection POST de Paybox
3434
And I submit the form with name "PAYBOX"
35+
And I submit the form with id "payment_page_redirect_form"
3536
When I fill in "NUMERO_CARTE" with "1111222233334444"
3637
And I select "12" from "MOIS_VALIDITE"
3738
And I select "26" from "AN_VALIDITE"

tests/behat/features/PublicSite/Register.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Feature: Site Public - Register
4646
When I press "Régler par carte"
4747
# Pour suivre la redirection POST de Paybox
4848
And I submit the form with name "PAYBOX"
49+
And I submit the form with id "payment_page_redirect_form"
4950
When I fill in "NUMERO_CARTE" with "1111222233334444"
5051
And I select "12" from "MOIS_VALIDITE"
5152
And I select "26" from "AN_VALIDITE"
@@ -85,6 +86,7 @@ Feature: Site Public - Register
8586
When I press "Régler par carte"
8687
# Pour suivre la redirection POST de Paybox
8788
And I submit the form with name "PAYBOX"
89+
And I submit the form with id "payment_page_redirect_form"
8890
When I fill in "NUMERO_CARTE" with "1111222233334444"
8991
And I select "12" from "MOIS_VALIDITE"
9092
And I select "26" from "AN_VALIDITE"

0 commit comments

Comments
 (0)