@proboy I think using a common interface will fix the issue for you. Here is my plan:
interface PayableMethod
{
public function charge(int $amount, array $options = []);
}
// CashPayment utilize PayableMethod
class StripePayment implements PayableMethod
{
public function charge(int $amount, array $options = [])
{
// your code
}
}
// CashPayment utilize PayableMethod
class CashPayment implements PayableMethod
{
public function charge(int $amount, array $options = [])
{
// code for your cash payment
}
}
// In your controller
class PaymentController
{
private $paymentMethod;
// Utilize interface here so that you can interchange easily
public function __construct(PayableMethod $paymentMethod)
{
$this->paymentMethod = $paymentMethod;
}
public function charge(int $amount, array $options = [])
{
return $this->paymentMethod->charge($amount, $options);
}
}
``