Working with a Symfony application using nusoap (is this the best method for integrating soap work with php / symfony?) To accept credit card payments.
I have simplified the example of my code below.
What I'm fighting is the best way to handle exceptions. The example below shows only 1 user exception (where should my user exceptions be in the symfony? Directory structure (Lib / exception?)). But what happens when there are several different types of exceptions that handle a specific error? It's not very elegant to have a try / catch block with 20 odd exceptions.
I am also not sure where I should rush and catch. I need to install some custom flashes in order to warn the user about any problems, so I believe that the trick should be done in the action controller, and not in the class that handles the soap call.
Can anyone advise where I can go wrong?
I hate dirty code / solutions and want to stick to the DRY principle as much as possible. I think I could also skip some of the symfony built-in functions that could help with this, but whenever I look, I usually find examples that are for symfony 1.2, I use 1.4.
Some examples would be great, thanks.
Library / soap_payment.class.php
class SoapPayment
{
public function charge()
{
try
{
$this->call();
}
catch (SoapPaymentClientFaultException $e)
{
}
}
private function call()
{
$this->client->call($this->options);
if ($this->client->hasFault())
{
throw new SoapPaymentClientFaultException();
}
}
}
Applications / interface / payment / action / actions.class.php
class paymentActions extends sfActions
{
public function executeCreate(sfWebRequest $request)
{
$soap_payment = new SoapPayment();
try
{
$soap_payment->charge();
}
catch (SoapPaymentClientFaultException $e)
{
$this->getUser()->setFlash('error', ...);
$this->getLogger()->err(...);
}
}
}