Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@meDavid
Last active August 31, 2023 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meDavid/e31ff7f92734cefd32c446d5068a7403 to your computer and use it in GitHub Desktop.
Save meDavid/e31ff7f92734cefd32c446d5068a7403 to your computer and use it in GitHub Desktop.
Create Card Guard listener
<?php
class CreateCardGuardListener implements EventSubscriberInterface
{
public function guardCreateCard(GuardEvent $event) {
/** @var CardApplication $cardApplication */
$cardApplication = $event->getSubject();
// By default block this transition.
$event->setBlocked(true);
// Only allow this transition if the requested limit is less then $200 or we have an approved credit limit.
if ($cardApplication->getRequestedCreditLimit() < 200 || $cardApplication->getRequestedCreditLimit() <= $cardApplication->getAppprovedCreditLimit()) {
$event->setBlocked(false);
}
}
/**
* Returns the events to which this class has subscribed.
*
* @return array
*/
public static function getSubscribedEvents() {
return [
'workflow.creditcard_application_flow.guard.create_card' => array('guardCreateCard'),
];
}
}
@gazever
Copy link

gazever commented Aug 31, 2023

Line 10 in the example should be $200 in the comment to match line 11 of the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment