namespace Payment;
class CreditCard
{
/**
* Pays using given credit card.
*
* @param SaleOrder $order
* @param Card $card
*
* @return bool
*/
public function pay(SaleOrder $order, Card $card): bool
{
$sucess = $this->gateway->charge($order->total(), $card);
if (false === $sucess) {
$this->log->notice('Unable to charge given credit card');
return false;
}
$order->paid();
$this->log->info('Order paid');
return true;
}
// Some another methods
}<?php
namespace Payment;
class CreditCard
{
/**
* Pays using given credit card.
*
* @param SaleOrder $order
* @param Card $card
*
* @return bool
*/
public function pay(SaleOrder $order, Card $card): bool
{
return $this->gateway->charge($order->total(), $card);
}
// Some another methods
}namespace Aspect\Payment;
use Payment\CreditCard;
use Go\Aop\Aspect;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\Before;
/**
* Payment aspect
*/
class PaymentLogAspect implements Aspect
{
// ...
/**
* Method that will be called before pay method
*
* @param MethodInvocation $invocation Invocation
* @Before("execution(public CreditCard->pay(*))")
*/
public function beforePay(MethodInvocation $invocation)
{
$this->log->debug(
'Trying to pay order using given parameters',
$invocation->getArguments()
);
}
}