I am trying to add some logic that can stop an order transaction from happening depending on values stored in the Order Model. Due to how my client wants the purchase page setup, I need to be able to do last-minute validating through the commerce/payments/pay
action, which I can intervene before it happens using the onBeforeGatewayRequestSend
event.
Below is a simplified version of what I'm trying to do. The issue I am having is accessing the Order Model, It looks like it isn't available in the $event
parameter - which is why the below doesn't work.
craft()->on('commerce_payments.onBeforeGatewayRequestSend', function($event) {
// This doesn't work. No 'order' param available.
$order = $event->params['order'];
/* logic using $order,
-- set $is_valid (boolean) */;
if(!$is_valid) {
$transaction = $event->params['transaction'];
$transaction->message = "This order is not yet complete.";
$event->performAction = false;
return $event;
}
});
Is it at all possible to get the order model inside of this hook? Or is this just not the right place to be doing this?