Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 $100 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'),
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment